Annotation of loncom/interface/loncommon.pm, revision 1.1355
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1355 ! raeburn 4: # $Id: loncommon.pm,v 1.1354 2021/02/18 15:41:10 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.1349 raeburn 4896: sub css_links {
4897: my ($currsymb,$level) = @_;
4898: my ($links,@symbs,%cssrefs,%httpref);
4899: if ($level eq 'map') {
4900: my $navmap = Apache::lonnavmaps::navmap->new();
4901: if (ref($navmap)) {
4902: my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb);
4903: my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0);
4904: foreach my $res (@resources) {
4905: if (ref($res) && $res->symb()) {
4906: push(@symbs,$res->symb());
4907: }
4908: }
4909: }
4910: } else {
4911: @symbs = ($currsymb);
4912: }
4913: foreach my $symb (@symbs) {
4914: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb);
4915: if ($css_href =~ /\S/) {
4916: unless ($css_href =~ m{https?://}) {
4917: my $url = (&Apache::lonnet::decode_symb($symb))[-1];
4918: my $proburl = &Apache::lonnet::clutter($url);
4919: my ($probdir) = ($proburl =~ m{(.+)/[^/]+$});
4920: unless ($css_href =~ m{^/}) {
4921: $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
4922: }
4923: if ($css_href =~ m{^/(res|uploaded)/}) {
4924: unless (($httpref{'httpref.'.$css_href}) ||
4925: (&Apache::lonnet::is_on_map($css_href))) {
4926: my $thisurl = $proburl;
4927: if ($env{'httpref.'.$proburl}) {
4928: $thisurl = $env{'httpref.'.$proburl};
4929: }
4930: $httpref{'httpref.'.$css_href} = $thisurl;
4931: }
4932: }
4933: }
4934: $cssrefs{$css_href} = 1;
4935: }
4936: }
4937: if (keys(%httpref)) {
4938: &Apache::lonnet::appenv(\%httpref);
4939: }
4940: if (keys(%cssrefs)) {
4941: foreach my $css_href (keys(%cssrefs)) {
4942: next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
4943: $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
4944: }
4945: }
4946: return $links;
4947: }
4948:
1.112 bowersj2 4949: =pod
4950:
1.648 raeburn 4951: =item * &get_student_answers()
1.112 bowersj2 4952:
4953: show a snapshot of how student was answering problem
4954:
4955: =cut
4956:
1.11 albertel 4957: sub get_student_answers {
1.100 sakharuk 4958: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4959: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4960: my (%moreenv);
1.11 albertel 4961: my @elements=('symb','courseid','domain','username');
4962: foreach my $element (@elements) {
1.186 albertel 4963: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4964: }
1.186 albertel 4965: $moreenv{'grade_target'}='answer';
4966: %moreenv=(%form,%moreenv);
1.497 raeburn 4967: $feedurl = &Apache::lonnet::clutter($feedurl);
4968: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4969: return $userview;
1.1 albertel 4970: }
1.116 albertel 4971:
4972: =pod
4973:
4974: =item * &submlink()
4975:
1.242 albertel 4976: Inputs: $text $uname $udom $symb $target
1.116 albertel 4977:
4978: Returns: A link to grades.pm such as to see the SUBM view of a student
4979:
4980: =cut
4981:
4982: ###############################################
4983: sub submlink {
1.242 albertel 4984: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4985: if (!($uname && $udom)) {
4986: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4987: &Apache::lonnet::whichuser($symb);
1.116 albertel 4988: if (!$symb) { $symb=$cursymb; }
4989: }
1.254 matthew 4990: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4991: $symb=&escape($symb);
1.960 bisitz 4992: if ($target) { $target=" target=\"$target\""; }
4993: return
4994: '<a href="/adm/grades?command=submission'.
4995: '&symb='.$symb.
4996: '&student='.$uname.
4997: '&userdom='.$udom.'"'.
4998: $target.'>'.$text.'</a>';
1.242 albertel 4999: }
5000: ##############################################
5001:
5002: =pod
5003:
5004: =item * &pgrdlink()
5005:
5006: Inputs: $text $uname $udom $symb $target
5007:
5008: Returns: A link to grades.pm such as to see the PGRD view of a student
5009:
5010: =cut
5011:
5012: ###############################################
5013: sub pgrdlink {
5014: my $link=&submlink(@_);
5015: $link=~s/(&command=submission)/$1&showgrading=yes/;
5016: return $link;
5017: }
5018: ##############################################
5019:
5020: =pod
5021:
5022: =item * &pprmlink()
5023:
5024: Inputs: $text $uname $udom $symb $target
5025:
5026: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 5027: student and a specific resource
1.242 albertel 5028:
5029: =cut
5030:
5031: ###############################################
5032: sub pprmlink {
5033: my ($text,$uname,$udom,$symb,$target)=@_;
5034: if (!($uname && $udom)) {
5035: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5036: &Apache::lonnet::whichuser($symb);
1.242 albertel 5037: if (!$symb) { $symb=$cursymb; }
5038: }
1.254 matthew 5039: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5040: $symb=&escape($symb);
1.242 albertel 5041: if ($target) { $target="target=\"$target\""; }
1.595 albertel 5042: return '<a href="/adm/parmset?command=set&'.
5043: 'symb='.$symb.'&uname='.$uname.
5044: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 5045: }
5046: ##############################################
1.37 matthew 5047:
1.112 bowersj2 5048: =pod
5049:
5050: =back
5051:
5052: =cut
5053:
1.37 matthew 5054: ###############################################
1.51 www 5055:
5056:
5057: sub timehash {
1.687 raeburn 5058: my ($thistime) = @_;
5059: my $timezone = &Apache::lonlocal::gettimezone();
5060: my $dt = DateTime->from_epoch(epoch => $thistime)
5061: ->set_time_zone($timezone);
5062: my $wday = $dt->day_of_week();
5063: if ($wday == 7) { $wday = 0; }
5064: return ( 'second' => $dt->second(),
5065: 'minute' => $dt->minute(),
5066: 'hour' => $dt->hour(),
5067: 'day' => $dt->day_of_month(),
5068: 'month' => $dt->month(),
5069: 'year' => $dt->year(),
5070: 'weekday' => $wday,
5071: 'dayyear' => $dt->day_of_year(),
5072: 'dlsav' => $dt->is_dst() );
1.51 www 5073: }
5074:
1.370 www 5075: sub utc_string {
5076: my ($date)=@_;
1.371 www 5077: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 5078: }
5079:
1.51 www 5080: sub maketime {
5081: my %th=@_;
1.687 raeburn 5082: my ($epoch_time,$timezone,$dt);
5083: $timezone = &Apache::lonlocal::gettimezone();
5084: eval {
5085: $dt = DateTime->new( year => $th{'year'},
5086: month => $th{'month'},
5087: day => $th{'day'},
5088: hour => $th{'hour'},
5089: minute => $th{'minute'},
5090: second => $th{'second'},
5091: time_zone => $timezone,
5092: );
5093: };
5094: if (!$@) {
5095: $epoch_time = $dt->epoch;
5096: if ($epoch_time) {
5097: return $epoch_time;
5098: }
5099: }
1.51 www 5100: return POSIX::mktime(
5101: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 5102: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 5103: }
5104:
5105: #########################################
1.51 www 5106:
5107: sub findallcourses {
1.482 raeburn 5108: my ($roles,$uname,$udom) = @_;
1.355 albertel 5109: my %roles;
5110: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 5111: my %courses;
1.51 www 5112: my $now=time;
1.482 raeburn 5113: if (!defined($uname)) {
5114: $uname = $env{'user.name'};
5115: }
5116: if (!defined($udom)) {
5117: $udom = $env{'user.domain'};
5118: }
5119: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 5120: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 5121: if (!%roles) {
5122: %roles = (
5123: cc => 1,
1.907 raeburn 5124: co => 1,
1.482 raeburn 5125: in => 1,
5126: ep => 1,
5127: ta => 1,
5128: cr => 1,
5129: st => 1,
5130: );
5131: }
5132: foreach my $entry (keys(%roleshash)) {
5133: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
5134: if ($trole =~ /^cr/) {
5135: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
5136: } else {
5137: next if (!exists($roles{$trole}));
5138: }
5139: if ($tend) {
5140: next if ($tend < $now);
5141: }
5142: if ($tstart) {
5143: next if ($tstart > $now);
5144: }
1.1058 raeburn 5145: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 5146: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5147: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5148: if ($secpart eq '') {
5149: ($cnum,$role) = split(/_/,$cnumpart);
5150: $sec = 'none';
1.1058 raeburn 5151: $value .= $cnum.'/';
1.482 raeburn 5152: } else {
5153: $cnum = $cnumpart;
5154: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5155: $value .= $cnum.'/'.$sec;
5156: }
5157: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5158: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5159: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5160: }
5161: } else {
5162: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5163: }
1.482 raeburn 5164: }
5165: } else {
5166: foreach my $key (keys(%env)) {
1.483 albertel 5167: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5168: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5169: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5170: next if ($role eq 'ca' || $role eq 'aa');
5171: next if (%roles && !exists($roles{$role}));
5172: my ($starttime,$endtime)=split(/\./,$env{$key});
5173: my $active=1;
5174: if ($starttime) {
5175: if ($now<$starttime) { $active=0; }
5176: }
5177: if ($endtime) {
5178: if ($now>$endtime) { $active=0; }
5179: }
5180: if ($active) {
1.1058 raeburn 5181: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5182: if ($sec eq '') {
5183: $sec = 'none';
1.1058 raeburn 5184: } else {
5185: $value .= $sec;
5186: }
5187: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5188: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5189: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5190: }
5191: } else {
5192: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5193: }
1.474 raeburn 5194: }
5195: }
1.51 www 5196: }
5197: }
1.474 raeburn 5198: return %courses;
1.51 www 5199: }
1.37 matthew 5200:
1.54 www 5201: ###############################################
1.474 raeburn 5202:
5203: sub blockcheck {
1.1347 raeburn 5204: my ($setters,$activity,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.490 raeburn 5205:
1.1189 raeburn 5206: if (defined($udom) && defined($uname)) {
5207: # If uname and udom are for a course, check for blocks in the course.
5208: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5209: my ($startblock,$endblock,$triggerblock) =
1.1347 raeburn 5210: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1189 raeburn 5211: return ($startblock,$endblock,$triggerblock);
5212: }
5213: } else {
1.490 raeburn 5214: $udom = $env{'user.domain'};
5215: $uname = $env{'user.name'};
5216: }
5217:
1.502 raeburn 5218: my $startblock = 0;
5219: my $endblock = 0;
1.1062 raeburn 5220: my $triggerblock = '';
1.482 raeburn 5221: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 5222:
1.490 raeburn 5223: # If uname is for a user, and activity is course-specific, i.e.,
5224: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5225:
1.490 raeburn 5226: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 5227: $activity eq 'groups' || $activity eq 'printout' ||
1.1346 raeburn 5228: $activity eq 'search' || $activity eq 'reinit' ||
5229: $activity eq 'alert') &&
1.1189 raeburn 5230: ($env{'request.course.id'})) {
1.490 raeburn 5231: foreach my $key (keys(%live_courses)) {
5232: if ($key ne $env{'request.course.id'}) {
5233: delete($live_courses{$key});
5234: }
5235: }
5236: }
5237:
5238: my $otheruser = 0;
5239: my %own_courses;
5240: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5241: # Resource belongs to user other than current user.
5242: $otheruser = 1;
5243: # Gather courses for current user
5244: %own_courses =
5245: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5246: }
5247:
5248: # Gather active course roles - course coordinator, instructor,
5249: # exam proctor, ta, student, or custom role.
1.474 raeburn 5250:
5251: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5252: my ($cdom,$cnum);
5253: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5254: $cdom = $env{'course.'.$course.'.domain'};
5255: $cnum = $env{'course.'.$course.'.num'};
5256: } else {
1.490 raeburn 5257: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5258: }
5259: my $no_ownblock = 0;
5260: my $no_userblock = 0;
1.533 raeburn 5261: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5262: # Check if current user has 'evb' priv for this
5263: if (defined($own_courses{$course})) {
5264: foreach my $sec (keys(%{$own_courses{$course}})) {
5265: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5266: if ($sec ne 'none') {
5267: $checkrole .= '/'.$sec;
5268: }
5269: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5270: $no_ownblock = 1;
5271: last;
5272: }
5273: }
5274: }
5275: # if they have 'evb' priv and are currently not playing student
5276: next if (($no_ownblock) &&
5277: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5278: }
1.474 raeburn 5279: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5280: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5281: if ($sec ne 'none') {
1.482 raeburn 5282: $checkrole .= '/'.$sec;
1.474 raeburn 5283: }
1.490 raeburn 5284: if ($otheruser) {
5285: # Resource belongs to user other than current user.
5286: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5287: my (%allroles,%userroles);
5288: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5289: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5290: my ($trole,$tdom,$tnum,$tsec);
5291: if ($entry =~ /^cr/) {
5292: ($trole,$tdom,$tnum,$tsec) =
5293: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5294: } else {
5295: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5296: }
5297: my ($spec,$area,$trest);
5298: $area = '/'.$tdom.'/'.$tnum;
5299: $trest = $tnum;
5300: if ($tsec ne '') {
5301: $area .= '/'.$tsec;
5302: $trest .= '/'.$tsec;
5303: }
5304: $spec = $trole.'.'.$area;
5305: if ($trole =~ /^cr/) {
5306: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5307: $tdom,$spec,$trest,$area);
5308: } else {
5309: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5310: $tdom,$spec,$trest,$area);
5311: }
5312: }
1.1276 raeburn 5313: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5314: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5315: if ($1) {
5316: $no_userblock = 1;
5317: last;
5318: }
1.486 raeburn 5319: }
5320: }
1.490 raeburn 5321: } else {
5322: # Resource belongs to current user
5323: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5324: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5325: $no_ownblock = 1;
5326: last;
5327: }
1.474 raeburn 5328: }
5329: }
5330: # if they have the evb priv and are currently not playing student
1.482 raeburn 5331: next if (($no_ownblock) &&
1.491 albertel 5332: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5333: next if ($no_userblock);
1.474 raeburn 5334:
1.1303 raeburn 5335: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5336: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5337:
1.1062 raeburn 5338: my ($start,$end,$trigger) =
1.1347 raeburn 5339: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 5340: if (($start != 0) &&
5341: (($startblock == 0) || ($startblock > $start))) {
5342: $startblock = $start;
1.1062 raeburn 5343: if ($trigger ne '') {
5344: $triggerblock = $trigger;
5345: }
1.502 raeburn 5346: }
5347: if (($end != 0) &&
5348: (($endblock == 0) || ($endblock < $end))) {
5349: $endblock = $end;
1.1062 raeburn 5350: if ($trigger ne '') {
5351: $triggerblock = $trigger;
5352: }
1.502 raeburn 5353: }
1.490 raeburn 5354: }
1.1062 raeburn 5355: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5356: }
5357:
5358: sub get_blocks {
1.1347 raeburn 5359: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 5360: my $startblock = 0;
5361: my $endblock = 0;
1.1062 raeburn 5362: my $triggerblock = '';
1.490 raeburn 5363: my $course = $cdom.'_'.$cnum;
5364: $setters->{$course} = {};
5365: $setters->{$course}{'staff'} = [];
5366: $setters->{$course}{'times'} = [];
1.1062 raeburn 5367: $setters->{$course}{'triggers'} = [];
5368: my (@blockers,%triggered);
5369: my $now = time;
5370: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5371: if ($activity eq 'docs') {
1.1348 raeburn 5372: my ($blocked,$nosymbcache,$noenccheck);
1.1347 raeburn 5373: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
5374: $blocked = 1;
5375: $nosymbcache = 1;
1.1348 raeburn 5376: $noenccheck = 1;
1.1347 raeburn 5377: }
1.1348 raeburn 5378: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 5379: foreach my $block (@blockers) {
5380: if ($block =~ /^firstaccess____(.+)$/) {
5381: my $item = $1;
5382: my $type = 'map';
5383: my $timersymb = $item;
5384: if ($item eq 'course') {
5385: $type = 'course';
5386: } elsif ($item =~ /___\d+___/) {
5387: $type = 'resource';
5388: } else {
5389: $timersymb = &Apache::lonnet::symbread($item);
5390: }
5391: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5392: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5393: $triggered{$block} = {
5394: start => $start,
5395: end => $end,
5396: type => $type,
5397: };
5398: }
5399: }
5400: } else {
5401: foreach my $block (keys(%commblocks)) {
5402: if ($block =~ m/^(\d+)____(\d+)$/) {
5403: my ($start,$end) = ($1,$2);
5404: if ($start <= time && $end >= time) {
5405: if (ref($commblocks{$block}) eq 'HASH') {
5406: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5407: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5408: unless(grep(/^\Q$block\E$/,@blockers)) {
5409: push(@blockers,$block);
5410: }
5411: }
5412: }
5413: }
5414: }
5415: } elsif ($block =~ /^firstaccess____(.+)$/) {
5416: my $item = $1;
5417: my $timersymb = $item;
5418: my $type = 'map';
5419: if ($item eq 'course') {
5420: $type = 'course';
5421: } elsif ($item =~ /___\d+___/) {
5422: $type = 'resource';
5423: } else {
5424: $timersymb = &Apache::lonnet::symbread($item);
5425: }
5426: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5427: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5428: if ($start && $end) {
5429: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 5430: if (ref($commblocks{$block}) eq 'HASH') {
5431: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5432: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5433: unless(grep(/^\Q$block\E$/,@blockers)) {
5434: push(@blockers,$block);
5435: $triggered{$block} = {
5436: start => $start,
5437: end => $end,
5438: type => $type,
5439: };
5440: }
5441: }
5442: }
1.1062 raeburn 5443: }
5444: }
1.490 raeburn 5445: }
1.1062 raeburn 5446: }
5447: }
5448: }
5449: foreach my $blocker (@blockers) {
5450: my ($staff_name,$staff_dom,$title,$blocks) =
5451: &parse_block_record($commblocks{$blocker});
5452: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5453: my ($start,$end,$triggertype);
5454: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5455: ($start,$end) = ($1,$2);
5456: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5457: $start = $triggered{$blocker}{'start'};
5458: $end = $triggered{$blocker}{'end'};
5459: $triggertype = $triggered{$blocker}{'type'};
5460: }
5461: if ($start) {
5462: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5463: if ($triggertype) {
5464: push(@{$$setters{$course}{'triggers'}},$triggertype);
5465: } else {
5466: push(@{$$setters{$course}{'triggers'}},0);
5467: }
5468: if ( ($startblock == 0) || ($startblock > $start) ) {
5469: $startblock = $start;
5470: if ($triggertype) {
5471: $triggerblock = $blocker;
1.474 raeburn 5472: }
5473: }
1.1062 raeburn 5474: if ( ($endblock == 0) || ($endblock < $end) ) {
5475: $endblock = $end;
5476: if ($triggertype) {
5477: $triggerblock = $blocker;
5478: }
5479: }
1.474 raeburn 5480: }
5481: }
1.1062 raeburn 5482: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5483: }
5484:
5485: sub parse_block_record {
5486: my ($record) = @_;
5487: my ($setuname,$setudom,$title,$blocks);
5488: if (ref($record) eq 'HASH') {
5489: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5490: $title = &unescape($record->{'event'});
5491: $blocks = $record->{'blocks'};
5492: } else {
5493: my @data = split(/:/,$record,3);
5494: if (scalar(@data) eq 2) {
5495: $title = $data[1];
5496: ($setuname,$setudom) = split(/@/,$data[0]);
5497: } else {
5498: ($setuname,$setudom,$title) = @data;
5499: }
5500: $blocks = { 'com' => 'on' };
5501: }
5502: return ($setuname,$setudom,$title,$blocks);
5503: }
5504:
1.854 kalberla 5505: sub blocking_status {
1.1347 raeburn 5506: my ($activity,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 5507: my %setters;
1.890 droeschl 5508:
1.1061 raeburn 5509: # check for active blocking
1.1062 raeburn 5510: my ($startblock,$endblock,$triggerblock) =
1.1347 raeburn 5511: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 5512: my $blocked = 0;
5513: if ($startblock && $endblock) {
5514: $blocked = 1;
5515: }
1.890 droeschl 5516:
1.1061 raeburn 5517: # caller just wants to know whether a block is active
5518: if (!wantarray) { return $blocked; }
5519:
5520: # build a link to a popup window containing the details
5521: my $querystring = "?activity=$activity";
1.1351 raeburn 5522: # $uname and $udom decide whose portfolio (or information page) the user is trying to look at
5523: if (($activity eq 'port') || ($activity eq 'about') || ($activity eq 'passwd')) {
1.1232 raeburn 5524: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5525: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5526: } elsif ($activity eq 'docs') {
1.1347 raeburn 5527: my $showurl = &Apache::lonenc::check_encrypt($url);
5528: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
5529: if ($symb) {
5530: my $showsymb = &Apache::lonenc::check_encrypt($symb);
5531: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
5532: }
1.1062 raeburn 5533: }
1.1061 raeburn 5534:
5535: my $output .= <<'END_MYBLOCK';
5536: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5537: var options = "width=" + w + ",height=" + h + ",";
5538: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5539: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5540: var newWin = window.open(url, wdwName, options);
5541: newWin.focus();
5542: }
1.890 droeschl 5543: END_MYBLOCK
1.854 kalberla 5544:
1.1061 raeburn 5545: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5546:
1.1061 raeburn 5547: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5548: my $text = &mt('Communication Blocked');
1.1217 raeburn 5549: my $class = 'LC_comblock';
1.1062 raeburn 5550: if ($activity eq 'docs') {
5551: $text = &mt('Content Access Blocked');
1.1217 raeburn 5552: $class = '';
1.1063 raeburn 5553: } elsif ($activity eq 'printout') {
5554: $text = &mt('Printing Blocked');
1.1232 raeburn 5555: } elsif ($activity eq 'passwd') {
5556: $text = &mt('Password Changing Blocked');
1.1345 raeburn 5557: } elsif ($activity eq 'grades') {
5558: $text = &mt('Gradebook Blocked');
1.1346 raeburn 5559: } elsif ($activity eq 'search') {
5560: $text = &mt('Search Blocked');
1.1282 raeburn 5561: } elsif ($activity eq 'alert') {
5562: $text = &mt('Checking Critical Messages Blocked');
5563: } elsif ($activity eq 'reinit') {
5564: $text = &mt('Checking Course Update Blocked');
1.1351 raeburn 5565: } elsif ($activity eq 'about') {
5566: $text = &mt('Access to User Information Pages Blocked');
1.1062 raeburn 5567: }
1.1061 raeburn 5568: $output .= <<"END_BLOCK";
1.1217 raeburn 5569: <div class='$class'>
1.869 kalberla 5570: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5571: title='$text'>
5572: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5573: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5574: title='$text'>$text</a>
1.867 kalberla 5575: </div>
5576:
5577: END_BLOCK
1.474 raeburn 5578:
1.1061 raeburn 5579: return ($blocked, $output);
1.854 kalberla 5580: }
1.490 raeburn 5581:
1.60 matthew 5582: ###############################################
5583:
1.682 raeburn 5584: sub check_ip_acc {
1.1201 raeburn 5585: my ($acc,$clientip)=@_;
1.682 raeburn 5586: &Apache::lonxml::debug("acc is $acc");
5587: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5588: return 1;
5589: }
1.1339 raeburn 5590: my ($ip,$allowed);
5591: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5592: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5593: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5594: } else {
1.1350 raeburn 5595: my $remote_ip = &Apache::lonnet::get_requestor_ip();
5596: $ip = $remote_ip || $env{'request.host'} || $clientip;
1.1339 raeburn 5597: }
1.682 raeburn 5598:
5599: my $name;
1.1219 raeburn 5600: my %access = (
5601: allowfrom => 1,
5602: denyfrom => 0,
5603: );
5604: my @allows;
5605: my @denies;
5606: foreach my $item (split(',',$acc)) {
5607: $item =~ s/^\s*//;
5608: $item =~ s/\s*$//;
5609: my $pattern;
5610: if ($item =~ /^\!(.+)$/) {
5611: push(@denies,$1);
5612: } else {
5613: push(@allows,$item);
5614: }
5615: }
5616: my $numdenies = scalar(@denies);
5617: my $numallows = scalar(@allows);
5618: my $count = 0;
5619: foreach my $pattern (@denies,@allows) {
5620: $count ++;
5621: my $acctype = 'allowfrom';
5622: if ($count <= $numdenies) {
5623: $acctype = 'denyfrom';
5624: }
1.682 raeburn 5625: if ($pattern =~ /\*$/) {
5626: #35.8.*
5627: $pattern=~s/\*//;
1.1219 raeburn 5628: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5629: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5630: #35.8.3.[34-56]
5631: my $low=$2;
5632: my $high=$3;
5633: $pattern=$1;
5634: if ($ip =~ /^\Q$pattern\E/) {
5635: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5636: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5637: }
5638: } elsif ($pattern =~ /^\*/) {
5639: #*.msu.edu
5640: $pattern=~s/\*//;
5641: if (!defined($name)) {
5642: use Socket;
5643: my $netaddr=inet_aton($ip);
5644: ($name)=gethostbyaddr($netaddr,AF_INET);
5645: }
1.1219 raeburn 5646: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5647: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5648: #127.0.0.1
1.1219 raeburn 5649: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5650: } else {
5651: #some.name.com
5652: if (!defined($name)) {
5653: use Socket;
5654: my $netaddr=inet_aton($ip);
5655: ($name)=gethostbyaddr($netaddr,AF_INET);
5656: }
1.1219 raeburn 5657: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5658: }
5659: if ($allowed =~ /^(0|1)$/) { last; }
5660: }
5661: if ($allowed eq '') {
5662: if ($numdenies && !$numallows) {
5663: $allowed = 1;
5664: } else {
5665: $allowed = 0;
1.682 raeburn 5666: }
5667: }
5668: return $allowed;
5669: }
5670:
5671: ###############################################
5672:
1.60 matthew 5673: =pod
5674:
1.112 bowersj2 5675: =head1 Domain Template Functions
5676:
5677: =over 4
5678:
5679: =item * &determinedomain()
1.60 matthew 5680:
5681: Inputs: $domain (usually will be undef)
5682:
1.63 www 5683: Returns: Determines which domain should be used for designs
1.60 matthew 5684:
5685: =cut
1.54 www 5686:
1.60 matthew 5687: ###############################################
1.63 www 5688: sub determinedomain {
5689: my $domain=shift;
1.531 albertel 5690: if (! $domain) {
1.60 matthew 5691: # Determine domain if we have not been given one
1.893 raeburn 5692: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5693: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5694: if ($env{'request.role.domain'}) {
5695: $domain=$env{'request.role.domain'};
1.60 matthew 5696: }
5697: }
1.63 www 5698: return $domain;
5699: }
5700: ###############################################
1.517 raeburn 5701:
1.518 albertel 5702: sub devalidate_domconfig_cache {
5703: my ($udom)=@_;
5704: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5705: }
5706:
5707: # ---------------------- Get domain configuration for a domain
5708: sub get_domainconf {
5709: my ($udom) = @_;
5710: my $cachetime=1800;
5711: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5712: if (defined($cached)) { return %{$result}; }
5713:
5714: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5715: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5716: my (%designhash,%legacy);
1.518 albertel 5717: if (keys(%domconfig) > 0) {
5718: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5719: if (keys(%{$domconfig{'login'}})) {
5720: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5721: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5722: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5723: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5724: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5725: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5726: if ($key eq 'loginvia') {
5727: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5728: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5729: $designhash{$udom.'.login.loginvia'} = $server;
5730: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5731:
5732: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5733: } else {
5734: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5735: }
1.948 raeburn 5736: }
1.1208 raeburn 5737: } elsif ($key eq 'headtag') {
5738: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5739: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5740: }
1.946 raeburn 5741: }
1.1208 raeburn 5742: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5743: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5744: }
1.946 raeburn 5745: }
5746: }
5747: }
5748: } else {
5749: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5750: $designhash{$udom.'.login.'.$key.'_'.$img} =
5751: $domconfig{'login'}{$key}{$img};
5752: }
1.699 raeburn 5753: }
5754: } else {
5755: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5756: }
1.632 raeburn 5757: }
5758: } else {
5759: $legacy{'login'} = 1;
1.518 albertel 5760: }
1.632 raeburn 5761: } else {
5762: $legacy{'login'} = 1;
1.518 albertel 5763: }
5764: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5765: if (keys(%{$domconfig{'rolecolors'}})) {
5766: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5767: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5768: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5769: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5770: }
1.518 albertel 5771: }
5772: }
1.632 raeburn 5773: } else {
5774: $legacy{'rolecolors'} = 1;
1.518 albertel 5775: }
1.632 raeburn 5776: } else {
5777: $legacy{'rolecolors'} = 1;
1.518 albertel 5778: }
1.948 raeburn 5779: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5780: if ($domconfig{'autoenroll'}{'co-owners'}) {
5781: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5782: }
5783: }
1.632 raeburn 5784: if (keys(%legacy) > 0) {
5785: my %legacyhash = &get_legacy_domconf($udom);
5786: foreach my $item (keys(%legacyhash)) {
5787: if ($item =~ /^\Q$udom\E\.login/) {
5788: if ($legacy{'login'}) {
5789: $designhash{$item} = $legacyhash{$item};
5790: }
5791: } else {
5792: if ($legacy{'rolecolors'}) {
5793: $designhash{$item} = $legacyhash{$item};
5794: }
1.518 albertel 5795: }
5796: }
5797: }
1.632 raeburn 5798: } else {
5799: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5800: }
5801: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5802: $cachetime);
5803: return %designhash;
5804: }
5805:
1.632 raeburn 5806: sub get_legacy_domconf {
5807: my ($udom) = @_;
5808: my %legacyhash;
5809: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5810: my $designfile = $designdir.'/'.$udom.'.tab';
5811: if (-e $designfile) {
1.1317 raeburn 5812: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5813: while (my $line = <$fh>) {
5814: next if ($line =~ /^\#/);
5815: chomp($line);
5816: my ($key,$val)=(split(/\=/,$line));
5817: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5818: }
5819: close($fh);
5820: }
5821: }
1.1026 raeburn 5822: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5823: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5824: }
5825: return %legacyhash;
5826: }
5827:
1.63 www 5828: =pod
5829:
1.112 bowersj2 5830: =item * &domainlogo()
1.63 www 5831:
5832: Inputs: $domain (usually will be undef)
5833:
5834: Returns: A link to a domain logo, if the domain logo exists.
5835: If the domain logo does not exist, a description of the domain.
5836:
5837: =cut
1.112 bowersj2 5838:
1.63 www 5839: ###############################################
5840: sub domainlogo {
1.517 raeburn 5841: my $domain = &determinedomain(shift);
1.518 albertel 5842: my %designhash = &get_domainconf($domain);
1.517 raeburn 5843: # See if there is a logo
5844: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5845: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5846: if ($imgsrc =~ m{^/(adm|res)/}) {
5847: if ($imgsrc =~ m{^/res/}) {
5848: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5849: &Apache::lonnet::repcopy($local_name);
5850: }
5851: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5852: }
5853: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5854: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5855: return &Apache::lonnet::domain($domain,'description');
1.59 www 5856: } else {
1.60 matthew 5857: return '';
1.59 www 5858: }
5859: }
1.63 www 5860: ##############################################
5861:
5862: =pod
5863:
1.112 bowersj2 5864: =item * &designparm()
1.63 www 5865:
5866: Inputs: $which parameter; $domain (usually will be undef)
5867:
5868: Returns: value of designparamter $which
5869:
5870: =cut
1.112 bowersj2 5871:
1.397 albertel 5872:
1.400 albertel 5873: ##############################################
1.397 albertel 5874: sub designparm {
5875: my ($which,$domain)=@_;
5876: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5877: return $env{'environment.color.'.$which};
1.96 www 5878: }
1.63 www 5879: $domain=&determinedomain($domain);
1.1016 raeburn 5880: my %domdesign;
5881: unless ($domain eq 'public') {
5882: %domdesign = &get_domainconf($domain);
5883: }
1.520 raeburn 5884: my $output;
1.517 raeburn 5885: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5886: $output = $domdesign{$domain.'.'.$which};
1.63 www 5887: } else {
1.520 raeburn 5888: $output = $defaultdesign{$which};
5889: }
5890: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5891: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5892: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5893: if ($output =~ m{^/res/}) {
5894: my $local_name = &Apache::lonnet::filelocation('',$output);
5895: &Apache::lonnet::repcopy($local_name);
5896: }
1.520 raeburn 5897: $output = &lonhttpdurl($output);
5898: }
1.63 www 5899: }
1.520 raeburn 5900: return $output;
1.63 www 5901: }
1.59 www 5902:
1.822 bisitz 5903: ##############################################
5904: =pod
5905:
1.832 bisitz 5906: =item * &authorspace()
5907:
1.1028 raeburn 5908: Inputs: $url (usually will be undef).
1.832 bisitz 5909:
1.1132 raeburn 5910: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5911: directory being viewed (or for which action is being taken).
5912: If $url is provided, and begins /priv/<domain>/<uname>
5913: the path will be that portion of the $context argument.
5914: Otherwise the path will be for the author space of the current
5915: user when the current role is author, or for that of the
5916: co-author/assistant co-author space when the current role
5917: is co-author or assistant co-author.
1.832 bisitz 5918:
5919: =cut
5920:
5921: sub authorspace {
1.1028 raeburn 5922: my ($url) = @_;
5923: if ($url ne '') {
5924: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5925: return $1;
5926: }
5927: }
1.832 bisitz 5928: my $caname = '';
1.1024 www 5929: my $cadom = '';
1.1028 raeburn 5930: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5931: ($cadom,$caname) =
1.832 bisitz 5932: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5933: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5934: $caname = $env{'user.name'};
1.1024 www 5935: $cadom = $env{'user.domain'};
1.832 bisitz 5936: }
1.1028 raeburn 5937: if (($caname ne '') && ($cadom ne '')) {
5938: return "/priv/$cadom/$caname/";
5939: }
5940: return;
1.832 bisitz 5941: }
5942:
5943: ##############################################
5944: =pod
5945:
1.822 bisitz 5946: =item * &head_subbox()
5947:
5948: Inputs: $content (contains HTML code with page functions, etc.)
5949:
5950: Returns: HTML div with $content
5951: To be included in page header
5952:
5953: =cut
5954:
5955: sub head_subbox {
5956: my ($content)=@_;
5957: my $output =
1.993 raeburn 5958: '<div class="LC_head_subbox">'
1.822 bisitz 5959: .$content
5960: .'</div>'
5961: }
5962:
5963: ##############################################
5964: =pod
5965:
5966: =item * &CSTR_pageheader()
5967:
1.1026 raeburn 5968: Input: (optional) filename from which breadcrumb trail is built.
5969: In most cases no input as needed, as $env{'request.filename'}
5970: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5971:
5972: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5973: To be included on Authoring Space pages
1.822 bisitz 5974:
5975: =cut
5976:
5977: sub CSTR_pageheader {
1.1026 raeburn 5978: my ($trailfile) = @_;
5979: if ($trailfile eq '') {
5980: $trailfile = $env{'request.filename'};
5981: }
5982:
5983: # this is for resources; directories have customtitle, and crumbs
5984: # and select recent are created in lonpubdir.pm
5985:
5986: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5987: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5988: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5989: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5990: $formaction =~ s{/+}{/}g;
1.822 bisitz 5991:
5992: my $parentpath = '';
5993: my $lastitem = '';
5994: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5995: $parentpath = $1;
5996: $lastitem = $2;
5997: } else {
5998: $lastitem = $thisdisfn;
5999: }
1.921 bisitz 6000:
1.1246 raeburn 6001: my ($crsauthor,$title);
6002: if (($env{'request.course.id'}) &&
6003: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 6004: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 6005: $crsauthor = 1;
6006: $title = &mt('Course Authoring Space');
6007: } else {
6008: $title = &mt('Authoring Space');
6009: }
6010:
1.1314 raeburn 6011: my ($target,$crumbtarget) = (' target="_top"','_top'); #FIXME lonpubdir: target="_parent"
1.1313 raeburn 6012: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1.1314 raeburn 6013: $target = '';
6014: $crumbtarget = '';
1.1313 raeburn 6015: }
6016:
1.921 bisitz 6017: my $output =
1.822 bisitz 6018: '<div>'
6019: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 6020: .'<b>'.$title.'</b> '
1.1314 raeburn 6021: .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
6022: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 6023:
6024: if ($lastitem) {
6025: $output .=
6026: '<span class="LC_filename">'
6027: .$lastitem
6028: .'</span>';
6029: }
1.1245 raeburn 6030:
1.1246 raeburn 6031: if ($crsauthor) {
6032: $output .= '</form>'.&Apache::lonmenu::constspaceform();
6033: } else {
6034: $output .=
6035: '<br />'
1.1314 raeburn 6036: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.1246 raeburn 6037: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
6038: .'</form>'
6039: .&Apache::lonmenu::constspaceform();
6040: }
6041: $output .= '</div>';
1.921 bisitz 6042:
6043: return $output;
1.822 bisitz 6044: }
6045:
1.60 matthew 6046: ###############################################
6047: ###############################################
6048:
6049: =pod
6050:
1.112 bowersj2 6051: =back
6052:
1.549 albertel 6053: =head1 HTML Helpers
1.112 bowersj2 6054:
6055: =over 4
6056:
6057: =item * &bodytag()
1.60 matthew 6058:
6059: Returns a uniform header for LON-CAPA web pages.
6060:
6061: Inputs:
6062:
1.112 bowersj2 6063: =over 4
6064:
6065: =item * $title, A title to be displayed on the page.
6066:
6067: =item * $function, the current role (can be undef).
6068:
6069: =item * $addentries, extra parameters for the <body> tag.
6070:
6071: =item * $bodyonly, if defined, only return the <body> tag.
6072:
6073: =item * $domain, if defined, force a given domain.
6074:
6075: =item * $forcereg, if page should register as content page (relevant for
1.86 www 6076: text interface only)
1.60 matthew 6077:
1.814 bisitz 6078: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
6079: navigational links
1.317 albertel 6080:
1.338 albertel 6081: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
6082:
1.460 albertel 6083: =item * $args, optional argument valid values are
6084: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 6085: use_absolute -> for external resource or syllabus, this will
6086: contain https://<hostname> if server uses
6087: https (as per hosts.tab), but request is for http
6088: hostname -> hostname, from $r->hostname().
1.460 albertel 6089:
1.1096 raeburn 6090: =item * $advtoolsref, optional argument, ref to an array containing
6091: inlineremote items to be added in "Functions" menu below
6092: breadcrumbs.
6093:
1.1316 raeburn 6094: =item * $ltiscope, optional argument, will be one of: resource, map or
6095: course, if LON-CAPA is in LTI Provider context. Value is
6096: the scope of use, i.e., launch was for access to a single, a map
6097: or the entire course.
6098:
6099: =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6100: context, this will contain the URL for the landing item in
6101: the course, after launch from an LTI Consumer
6102:
1.1318 raeburn 6103: =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6104: context, this will contain a reference to hash of items
6105: to be included in the page header and/or inline menu.
6106:
1.112 bowersj2 6107: =back
6108:
1.60 matthew 6109: Returns: A uniform header for LON-CAPA web pages.
6110: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6111: If $bodyonly is undef or zero, an html string containing a <body> tag and
6112: other decorations will be returned.
6113:
6114: =cut
6115:
1.54 www 6116: sub bodytag {
1.831 bisitz 6117: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1318 raeburn 6118: $no_nav_bar,$bgcolor,$args,$advtoolsref,$ltiscope,$ltiuri,$ltimenu)=@_;
1.339 albertel 6119:
1.954 raeburn 6120: my $public;
6121: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6122: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6123: $public = 1;
6124: }
1.460 albertel 6125: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 6126: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 6127: my $hostname = $args->{'hostname'};
1.339 albertel 6128:
1.183 matthew 6129: $function = &get_users_function() if (!$function);
1.339 albertel 6130: my $img = &designparm($function.'.img',$domain);
6131: my $font = &designparm($function.'.font',$domain);
6132: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6133:
1.803 bisitz 6134: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6135: 'bgcolor' => $pgbg,
1.339 albertel 6136: 'text' => $font,
6137: 'alink' => &designparm($function.'.alink',$domain),
6138: 'vlink' => &designparm($function.'.vlink',$domain),
6139: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6140: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6141:
1.63 www 6142: # role and realm
1.1178 raeburn 6143: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6144: if ($realm) {
6145: $realm = '/'.$realm;
6146: }
1.378 raeburn 6147: if ($role eq 'ca') {
1.479 albertel 6148: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6149: $realm = &plainname($rname,$rdom);
1.378 raeburn 6150: }
1.55 www 6151: # realm
1.258 albertel 6152: if ($env{'request.course.id'}) {
1.378 raeburn 6153: if ($env{'request.role'} !~ /^cr/) {
6154: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 6155: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 6156: if ($env{'request.role.desc'}) {
6157: $role = $env{'request.role.desc'};
6158: } else {
6159: $role = &mt('Helpdesk[_1]',' '.$2);
6160: }
1.1257 raeburn 6161: } else {
6162: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6163: }
1.898 raeburn 6164: if ($env{'request.course.sec'}) {
6165: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
6166: }
1.359 albertel 6167: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 6168: } else {
6169: $role = &Apache::lonnet::plaintext($role);
1.54 www 6170: }
1.433 albertel 6171:
1.359 albertel 6172: if (!$realm) { $realm=' '; }
1.330 albertel 6173:
1.438 albertel 6174: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6175:
1.101 www 6176: # construct main body tag
1.359 albertel 6177: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6178: &Apache::lontexconvert::init_math_support();
1.252 albertel 6179:
1.1131 raeburn 6180: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6181:
1.1130 raeburn 6182: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6183: return $bodytag;
1.1130 raeburn 6184: }
1.359 albertel 6185:
1.954 raeburn 6186: if ($public) {
1.433 albertel 6187: undef($role);
6188: }
1.1318 raeburn 6189:
6190: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
6191: if (ref($ltimenu) eq 'HASH') {
6192: unless ($ltimenu->{'role'}) {
6193: undef($role);
6194: }
6195: unless ($ltimenu->{'coursetitle'}) {
6196: $realm=' ';
6197: }
6198: }
6199: }
6200:
1.762 bisitz 6201: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6202: #
6203: # Extra info if you are the DC
6204: my $dc_info = '';
6205: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
6206: $env{'course.'.$env{'request.course.id'}.
6207: '.domain'}.'/'})) {
6208: my $cid = $env{'request.course.id'};
1.917 raeburn 6209: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6210: $dc_info =~ s/\s+$//;
1.359 albertel 6211: }
6212:
1.1237 raeburn 6213: my $crstype;
6214: if ($env{'request.course.id'}) {
6215: $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
6216: } elsif ($args->{'crstype'}) {
6217: $crstype = $args->{'crstype'};
6218: }
6219: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
6220: undef($role);
6221: } else {
1.1242 raeburn 6222: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 6223: }
1.853 droeschl 6224:
1.903 droeschl 6225: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6226:
6227: # if ($env{'request.state'} eq 'construct') {
6228: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6229: # }
6230:
1.1130 raeburn 6231: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 6232: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6233:
1.1318 raeburn 6234: unless ($args->{'no_primary_menu'}) {
6235: my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu);
1.359 albertel 6236:
1.1318 raeburn 6237: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6238: if ($dc_info) {
6239: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6240: }
6241: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6242: <em>$realm</em> $dc_info</div>|;
6243: return $bodytag;
6244: }
1.894 droeschl 6245:
1.1318 raeburn 6246: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6247: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6248: }
1.916 droeschl 6249:
1.1318 raeburn 6250: $bodytag .= $right;
1.852 droeschl 6251:
1.1318 raeburn 6252: if ($dc_info) {
6253: $dc_info = &dc_courseid_toggle($dc_info);
6254: }
6255: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6256: }
1.916 droeschl 6257:
1.1169 raeburn 6258: #if directed to not display the secondary menu, don't.
1.1168 raeburn 6259: if ($args->{'no_secondary_menu'}) {
6260: return $bodytag;
6261: }
1.1169 raeburn 6262: #don't show menus for public users
1.954 raeburn 6263: if (!$public){
1.1318 raeburn 6264: unless ($args->{'no_inline_menu'}) {
6265: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
6266: $args->{'no_primary_menu'});
6267: }
1.903 droeschl 6268: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6269: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6270: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6271: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1316 raeburn 6272: $args->{'bread_crumbs'},'','',$hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6273: } elsif ($forcereg) {
6274: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1258 raeburn 6275: $args->{'group'},
1.1274 raeburn 6276: $args->{'hide_buttons'},
1.1316 raeburn 6277: $hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6278: } else {
6279: $bodytag .=
6280: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6281: $forcereg,$args->{'group'},
6282: $args->{'bread_crumbs'},
1.1274 raeburn 6283: $advtoolsref,'',$hostname);
1.920 raeburn 6284: }
1.903 droeschl 6285: }else{
6286: # this is to seperate menu from content when there's no secondary
6287: # menu. Especially needed for public accessible ressources.
6288: $bodytag .= '<hr style="clear:both" />';
6289: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6290: }
1.903 droeschl 6291:
1.235 raeburn 6292: return $bodytag;
1.182 matthew 6293: }
6294:
1.917 raeburn 6295: sub dc_courseid_toggle {
6296: my ($dc_info) = @_;
1.980 raeburn 6297: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6298: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6299: &mt('(More ...)').'</a></span>'.
6300: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6301: }
6302:
1.330 albertel 6303: sub make_attr_string {
6304: my ($register,$attr_ref) = @_;
6305:
6306: if ($attr_ref && !ref($attr_ref)) {
6307: die("addentries Must be a hash ref ".
6308: join(':',caller(1))." ".
6309: join(':',caller(0))." ");
6310: }
6311:
6312: if ($register) {
1.339 albertel 6313: my ($on_load,$on_unload);
6314: foreach my $key (keys(%{$attr_ref})) {
6315: if (lc($key) eq 'onload') {
6316: $on_load.=$attr_ref->{$key}.';';
6317: delete($attr_ref->{$key});
6318:
6319: } elsif (lc($key) eq 'onunload') {
6320: $on_unload.=$attr_ref->{$key}.';';
6321: delete($attr_ref->{$key});
6322: }
6323: }
1.953 droeschl 6324: $attr_ref->{'onload'} = $on_load;
6325: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6326: }
1.339 albertel 6327:
1.330 albertel 6328: my $attr_string;
1.1159 raeburn 6329: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6330: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6331: }
6332: return $attr_string;
6333: }
6334:
6335:
1.182 matthew 6336: ###############################################
1.251 albertel 6337: ###############################################
6338:
6339: =pod
6340:
6341: =item * &endbodytag()
6342:
6343: Returns a uniform footer for LON-CAPA web pages.
6344:
1.635 raeburn 6345: Inputs: 1 - optional reference to an args hash
6346: If in the hash, key for noredirectlink has a value which evaluates to true,
6347: a 'Continue' link is not displayed if the page contains an
6348: internal redirect in the <head></head> section,
6349: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6350:
6351: =cut
6352:
6353: sub endbodytag {
1.635 raeburn 6354: my ($args) = @_;
1.1080 raeburn 6355: my $endbodytag;
6356: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6357: $endbodytag='</body>';
6358: }
1.315 albertel 6359: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6360: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6361: $endbodytag=
6362: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6363: &mt('Continue').'</a>'.
6364: $endbodytag;
6365: }
1.315 albertel 6366: }
1.251 albertel 6367: return $endbodytag;
6368: }
6369:
1.352 albertel 6370: =pod
6371:
6372: =item * &standard_css()
6373:
6374: Returns a style sheet
6375:
6376: Inputs: (all optional)
6377: domain -> force to color decorate a page for a specific
6378: domain
6379: function -> force usage of a specific rolish color scheme
6380: bgcolor -> override the default page bgcolor
6381:
6382: =cut
6383:
1.343 albertel 6384: sub standard_css {
1.345 albertel 6385: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6386: $function = &get_users_function() if (!$function);
6387: my $img = &designparm($function.'.img', $domain);
6388: my $tabbg = &designparm($function.'.tabbg', $domain);
6389: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6390: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6391: #second colour for later usage
1.345 albertel 6392: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6393: my $pgbg_or_bgcolor =
6394: $bgcolor ||
1.352 albertel 6395: &designparm($function.'.pgbg', $domain);
1.382 albertel 6396: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6397: my $alink = &designparm($function.'.alink', $domain);
6398: my $vlink = &designparm($function.'.vlink', $domain);
6399: my $link = &designparm($function.'.link', $domain);
6400:
1.602 albertel 6401: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6402: my $mono = 'monospace';
1.850 bisitz 6403: my $data_table_head = $sidebg;
6404: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6405: my $data_table_dark = '#E0E0E0';
1.470 banghart 6406: my $data_table_darker = '#CCCCCC';
1.349 albertel 6407: my $data_table_highlight = '#FFFF00';
1.352 albertel 6408: my $mail_new = '#FFBB77';
6409: my $mail_new_hover = '#DD9955';
6410: my $mail_read = '#BBBB77';
6411: my $mail_read_hover = '#999944';
6412: my $mail_replied = '#AAAA88';
6413: my $mail_replied_hover = '#888855';
6414: my $mail_other = '#99BBBB';
6415: my $mail_other_hover = '#669999';
1.391 albertel 6416: my $table_header = '#DDDDDD';
1.489 raeburn 6417: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6418: my $lg_border_color = '#C8C8C8';
1.952 onken 6419: my $button_hover = '#BF2317';
1.392 albertel 6420:
1.608 albertel 6421: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6422: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6423: : '0 3px 0 4px';
1.448 albertel 6424:
1.523 albertel 6425:
1.343 albertel 6426: return <<END;
1.947 droeschl 6427:
6428: /* needed for iframe to allow 100% height in FF */
6429: body, html {
6430: margin: 0;
6431: padding: 0 0.5%;
6432: height: 99%; /* to avoid scrollbars */
6433: }
6434:
1.795 www 6435: body {
1.911 bisitz 6436: font-family: $sans;
6437: line-height:130%;
6438: font-size:0.83em;
6439: color:$font;
1.795 www 6440: }
6441:
1.959 onken 6442: a:focus,
6443: a:focus img {
1.795 www 6444: color: red;
6445: }
1.698 harmsja 6446:
1.911 bisitz 6447: form, .inline {
6448: display: inline;
1.795 www 6449: }
1.721 harmsja 6450:
1.795 www 6451: .LC_right {
1.911 bisitz 6452: text-align:right;
1.795 www 6453: }
6454:
6455: .LC_middle {
1.911 bisitz 6456: vertical-align:middle;
1.795 www 6457: }
1.721 harmsja 6458:
1.1130 raeburn 6459: .LC_floatleft {
6460: float: left;
6461: }
6462:
6463: .LC_floatright {
6464: float: right;
6465: }
6466:
1.911 bisitz 6467: .LC_400Box {
6468: width:400px;
6469: }
1.721 harmsja 6470:
1.947 droeschl 6471: .LC_iframecontainer {
6472: width: 98%;
6473: margin: 0;
6474: position: fixed;
6475: top: 8.5em;
6476: bottom: 0;
6477: }
6478:
6479: .LC_iframecontainer iframe{
6480: border: none;
6481: width: 100%;
6482: height: 100%;
6483: }
6484:
1.778 bisitz 6485: .LC_filename {
6486: font-family: $mono;
6487: white-space:pre;
1.921 bisitz 6488: font-size: 120%;
1.778 bisitz 6489: }
6490:
6491: .LC_fileicon {
6492: border: none;
6493: height: 1.3em;
6494: vertical-align: text-bottom;
6495: margin-right: 0.3em;
6496: text-decoration:none;
6497: }
6498:
1.1008 www 6499: .LC_setting {
6500: text-decoration:underline;
6501: }
6502:
1.350 albertel 6503: .LC_error {
6504: color: red;
6505: }
1.795 www 6506:
1.1097 bisitz 6507: .LC_warning {
6508: color: darkorange;
6509: }
6510:
1.457 albertel 6511: .LC_diff_removed {
1.733 bisitz 6512: color: red;
1.394 albertel 6513: }
1.532 albertel 6514:
6515: .LC_info,
1.457 albertel 6516: .LC_success,
6517: .LC_diff_added {
1.350 albertel 6518: color: green;
6519: }
1.795 www 6520:
1.802 bisitz 6521: div.LC_confirm_box {
6522: background-color: #FAFAFA;
6523: border: 1px solid $lg_border_color;
6524: margin-right: 0;
6525: padding: 5px;
6526: }
6527:
6528: div.LC_confirm_box .LC_error img,
6529: div.LC_confirm_box .LC_success img {
6530: vertical-align: middle;
6531: }
6532:
1.1242 raeburn 6533: .LC_maxwidth {
6534: max-width: 100%;
6535: height: auto;
6536: }
6537:
1.1243 raeburn 6538: .LC_textsize_mobile {
6539: \@media only screen and (max-device-width: 480px) {
6540: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6541: }
6542: }
6543:
1.440 albertel 6544: .LC_icon {
1.771 droeschl 6545: border: none;
1.790 droeschl 6546: vertical-align: middle;
1.771 droeschl 6547: }
6548:
1.543 albertel 6549: .LC_docs_spacer {
6550: width: 25px;
6551: height: 1px;
1.771 droeschl 6552: border: none;
1.543 albertel 6553: }
1.346 albertel 6554:
1.532 albertel 6555: .LC_internal_info {
1.735 bisitz 6556: color: #999999;
1.532 albertel 6557: }
6558:
1.794 www 6559: .LC_discussion {
1.1050 www 6560: background: $data_table_dark;
1.911 bisitz 6561: border: 1px solid black;
6562: margin: 2px;
1.794 www 6563: }
6564:
6565: .LC_disc_action_left {
1.1050 www 6566: background: $sidebg;
1.911 bisitz 6567: text-align: left;
1.1050 www 6568: padding: 4px;
6569: margin: 2px;
1.794 www 6570: }
6571:
6572: .LC_disc_action_right {
1.1050 www 6573: background: $sidebg;
1.911 bisitz 6574: text-align: right;
1.1050 www 6575: padding: 4px;
6576: margin: 2px;
1.794 www 6577: }
6578:
6579: .LC_disc_new_item {
1.911 bisitz 6580: background: white;
6581: border: 2px solid red;
1.1050 www 6582: margin: 4px;
6583: padding: 4px;
1.794 www 6584: }
6585:
6586: .LC_disc_old_item {
1.911 bisitz 6587: background: white;
1.1050 www 6588: margin: 4px;
6589: padding: 4px;
1.794 www 6590: }
6591:
1.458 albertel 6592: table.LC_pastsubmission {
6593: border: 1px solid black;
6594: margin: 2px;
6595: }
6596:
1.924 bisitz 6597: table#LC_menubuttons {
1.345 albertel 6598: width: 100%;
6599: background: $pgbg;
1.392 albertel 6600: border: 2px;
1.402 albertel 6601: border-collapse: separate;
1.803 bisitz 6602: padding: 0;
1.345 albertel 6603: }
1.392 albertel 6604:
1.801 tempelho 6605: table#LC_title_bar a {
6606: color: $fontmenu;
6607: }
1.836 bisitz 6608:
1.807 droeschl 6609: table#LC_title_bar {
1.819 tempelho 6610: clear: both;
1.836 bisitz 6611: display: none;
1.807 droeschl 6612: }
6613:
1.795 www 6614: table#LC_title_bar,
1.933 droeschl 6615: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6616: table#LC_title_bar.LC_with_remote {
1.359 albertel 6617: width: 100%;
1.392 albertel 6618: border-color: $pgbg;
6619: border-style: solid;
6620: border-width: $border;
1.379 albertel 6621: background: $pgbg;
1.801 tempelho 6622: color: $fontmenu;
1.392 albertel 6623: border-collapse: collapse;
1.803 bisitz 6624: padding: 0;
1.819 tempelho 6625: margin: 0;
1.359 albertel 6626: }
1.795 www 6627:
1.933 droeschl 6628: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6629: margin: 0;
6630: padding: 0;
1.933 droeschl 6631: position: relative;
6632: list-style: none;
1.913 droeschl 6633: }
1.933 droeschl 6634: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6635: display: inline;
6636: }
1.933 droeschl 6637:
6638: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6639: padding: 0;
1.933 droeschl 6640: margin: 0;
6641: float: left;
1.913 droeschl 6642: }
1.933 droeschl 6643: .LC_breadcrumb_tools_tools {
6644: padding: 0;
6645: margin: 0;
1.913 droeschl 6646: float: right;
6647: }
6648:
1.1240 raeburn 6649: .LC_placement_prog {
6650: padding-right: 20px;
6651: font-weight: bold;
6652: font-size: 90%;
6653: }
6654:
1.359 albertel 6655: table#LC_title_bar td {
6656: background: $tabbg;
6657: }
1.795 www 6658:
1.911 bisitz 6659: table#LC_menubuttons img {
1.803 bisitz 6660: border: none;
1.346 albertel 6661: }
1.795 www 6662:
1.842 droeschl 6663: .LC_breadcrumbs_component {
1.911 bisitz 6664: float: right;
6665: margin: 0 1em;
1.357 albertel 6666: }
1.842 droeschl 6667: .LC_breadcrumbs_component img {
1.911 bisitz 6668: vertical-align: middle;
1.777 tempelho 6669: }
1.795 www 6670:
1.1243 raeburn 6671: .LC_breadcrumbs_hoverable {
6672: background: $sidebg;
6673: }
6674:
1.383 albertel 6675: td.LC_table_cell_checkbox {
6676: text-align: center;
6677: }
1.795 www 6678:
6679: .LC_fontsize_small {
1.911 bisitz 6680: font-size: 70%;
1.705 tempelho 6681: }
6682:
1.844 bisitz 6683: #LC_breadcrumbs {
1.911 bisitz 6684: clear:both;
6685: background: $sidebg;
6686: border-bottom: 1px solid $lg_border_color;
6687: line-height: 2.5em;
1.933 droeschl 6688: overflow: hidden;
1.911 bisitz 6689: margin: 0;
6690: padding: 0;
1.995 raeburn 6691: text-align: left;
1.819 tempelho 6692: }
1.862 bisitz 6693:
1.1098 bisitz 6694: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6695: clear:both;
6696: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6697: border: 1px solid $sidebg;
1.1098 bisitz 6698: margin: 0 0 10px 0;
1.966 bisitz 6699: padding: 3px;
1.995 raeburn 6700: text-align: left;
1.822 bisitz 6701: }
6702:
1.795 www 6703: .LC_fontsize_medium {
1.911 bisitz 6704: font-size: 85%;
1.705 tempelho 6705: }
6706:
1.795 www 6707: .LC_fontsize_large {
1.911 bisitz 6708: font-size: 120%;
1.705 tempelho 6709: }
6710:
1.346 albertel 6711: .LC_menubuttons_inline_text {
6712: color: $font;
1.698 harmsja 6713: font-size: 90%;
1.701 harmsja 6714: padding-left:3px;
1.346 albertel 6715: }
6716:
1.934 droeschl 6717: .LC_menubuttons_inline_text img{
6718: vertical-align: middle;
6719: }
6720:
1.1051 www 6721: li.LC_menubuttons_inline_text img {
1.951 onken 6722: cursor:pointer;
1.1002 droeschl 6723: text-decoration: none;
1.951 onken 6724: }
6725:
1.526 www 6726: .LC_menubuttons_link {
6727: text-decoration: none;
6728: }
1.795 www 6729:
1.522 albertel 6730: .LC_menubuttons_category {
1.521 www 6731: color: $font;
1.526 www 6732: background: $pgbg;
1.521 www 6733: font-size: larger;
6734: font-weight: bold;
6735: }
6736:
1.346 albertel 6737: td.LC_menubuttons_text {
1.911 bisitz 6738: color: $font;
1.346 albertel 6739: }
1.706 harmsja 6740:
1.346 albertel 6741: .LC_current_location {
6742: background: $tabbg;
6743: }
1.795 www 6744:
1.1286 raeburn 6745: td.LC_zero_height {
6746: line-height: 0;
6747: cellpadding: 0;
6748: }
6749:
1.938 bisitz 6750: table.LC_data_table {
1.347 albertel 6751: border: 1px solid #000000;
1.402 albertel 6752: border-collapse: separate;
1.426 albertel 6753: border-spacing: 1px;
1.610 albertel 6754: background: $pgbg;
1.347 albertel 6755: }
1.795 www 6756:
1.422 albertel 6757: .LC_data_table_dense {
6758: font-size: small;
6759: }
1.795 www 6760:
1.507 raeburn 6761: table.LC_nested_outer {
6762: border: 1px solid #000000;
1.589 raeburn 6763: border-collapse: collapse;
1.803 bisitz 6764: border-spacing: 0;
1.507 raeburn 6765: width: 100%;
6766: }
1.795 www 6767:
1.879 raeburn 6768: table.LC_innerpickbox,
1.507 raeburn 6769: table.LC_nested {
1.803 bisitz 6770: border: none;
1.589 raeburn 6771: border-collapse: collapse;
1.803 bisitz 6772: border-spacing: 0;
1.507 raeburn 6773: width: 100%;
6774: }
1.795 www 6775:
1.911 bisitz 6776: table.LC_data_table tr th,
6777: table.LC_calendar tr th,
1.879 raeburn 6778: table.LC_prior_tries tr th,
6779: table.LC_innerpickbox tr th {
1.349 albertel 6780: font-weight: bold;
6781: background-color: $data_table_head;
1.801 tempelho 6782: color:$fontmenu;
1.701 harmsja 6783: font-size:90%;
1.347 albertel 6784: }
1.795 www 6785:
1.879 raeburn 6786: table.LC_innerpickbox tr th,
6787: table.LC_innerpickbox tr td {
6788: vertical-align: top;
6789: }
6790:
1.711 raeburn 6791: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6792: background-color: #CCCCCC;
1.711 raeburn 6793: font-weight: bold;
6794: text-align: left;
6795: }
1.795 www 6796:
1.912 bisitz 6797: table.LC_data_table tr.LC_odd_row > td {
6798: background-color: $data_table_light;
6799: padding: 2px;
6800: vertical-align: top;
6801: }
6802:
1.809 bisitz 6803: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6804: background-color: $data_table_light;
1.912 bisitz 6805: vertical-align: top;
6806: }
6807:
6808: table.LC_data_table tr.LC_even_row > td {
6809: background-color: $data_table_dark;
1.425 albertel 6810: padding: 2px;
1.900 bisitz 6811: vertical-align: top;
1.347 albertel 6812: }
1.795 www 6813:
1.809 bisitz 6814: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6815: background-color: $data_table_dark;
1.900 bisitz 6816: vertical-align: top;
1.347 albertel 6817: }
1.795 www 6818:
1.425 albertel 6819: table.LC_data_table tr.LC_data_table_highlight td {
6820: background-color: $data_table_darker;
6821: }
1.795 www 6822:
1.639 raeburn 6823: table.LC_data_table tr td.LC_leftcol_header {
6824: background-color: $data_table_head;
6825: font-weight: bold;
6826: }
1.795 www 6827:
1.451 albertel 6828: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6829: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6830: font-weight: bold;
6831: font-style: italic;
6832: text-align: center;
6833: padding: 8px;
1.347 albertel 6834: }
1.795 www 6835:
1.1114 raeburn 6836: table.LC_data_table tr.LC_empty_row td,
6837: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6838: background-color: $sidebg;
6839: }
6840:
6841: table.LC_nested tr.LC_empty_row td {
6842: background-color: #FFFFFF;
6843: }
6844:
1.890 droeschl 6845: table.LC_caption {
6846: }
6847:
1.507 raeburn 6848: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6849: padding: 4ex
6850: }
1.795 www 6851:
1.507 raeburn 6852: table.LC_nested_outer tr th {
6853: font-weight: bold;
1.801 tempelho 6854: color:$fontmenu;
1.507 raeburn 6855: background-color: $data_table_head;
1.701 harmsja 6856: font-size: small;
1.507 raeburn 6857: border-bottom: 1px solid #000000;
6858: }
1.795 www 6859:
1.507 raeburn 6860: table.LC_nested_outer tr td.LC_subheader {
6861: background-color: $data_table_head;
6862: font-weight: bold;
6863: font-size: small;
6864: border-bottom: 1px solid #000000;
6865: text-align: right;
1.451 albertel 6866: }
1.795 www 6867:
1.507 raeburn 6868: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6869: background-color: #CCCCCC;
1.451 albertel 6870: font-weight: bold;
6871: font-size: small;
1.507 raeburn 6872: text-align: center;
6873: }
1.795 www 6874:
1.589 raeburn 6875: table.LC_nested tr.LC_info_row td.LC_left_item,
6876: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6877: text-align: left;
1.451 albertel 6878: }
1.795 www 6879:
1.507 raeburn 6880: table.LC_nested td {
1.735 bisitz 6881: background-color: #FFFFFF;
1.451 albertel 6882: font-size: small;
1.507 raeburn 6883: }
1.795 www 6884:
1.507 raeburn 6885: table.LC_nested_outer tr th.LC_right_item,
6886: table.LC_nested tr.LC_info_row td.LC_right_item,
6887: table.LC_nested tr.LC_odd_row td.LC_right_item,
6888: table.LC_nested tr td.LC_right_item {
1.451 albertel 6889: text-align: right;
6890: }
6891:
1.507 raeburn 6892: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6893: background-color: #EEEEEE;
1.451 albertel 6894: }
6895:
1.473 raeburn 6896: table.LC_createuser {
6897: }
6898:
6899: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6900: font-size: small;
1.473 raeburn 6901: }
6902:
6903: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6904: background-color: #CCCCCC;
1.473 raeburn 6905: font-weight: bold;
6906: text-align: center;
6907: }
6908:
1.349 albertel 6909: table.LC_calendar {
6910: border: 1px solid #000000;
6911: border-collapse: collapse;
1.917 raeburn 6912: width: 98%;
1.349 albertel 6913: }
1.795 www 6914:
1.349 albertel 6915: table.LC_calendar_pickdate {
6916: font-size: xx-small;
6917: }
1.795 www 6918:
1.349 albertel 6919: table.LC_calendar tr td {
6920: border: 1px solid #000000;
6921: vertical-align: top;
1.917 raeburn 6922: width: 14%;
1.349 albertel 6923: }
1.795 www 6924:
1.349 albertel 6925: table.LC_calendar tr td.LC_calendar_day_empty {
6926: background-color: $data_table_dark;
6927: }
1.795 www 6928:
1.779 bisitz 6929: table.LC_calendar tr td.LC_calendar_day_current {
6930: background-color: $data_table_highlight;
1.777 tempelho 6931: }
1.795 www 6932:
1.938 bisitz 6933: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6934: background-color: $mail_new;
6935: }
1.795 www 6936:
1.938 bisitz 6937: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6938: background-color: $mail_new_hover;
6939: }
1.795 www 6940:
1.938 bisitz 6941: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6942: background-color: $mail_read;
6943: }
1.795 www 6944:
1.938 bisitz 6945: /*
6946: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6947: background-color: $mail_read_hover;
6948: }
1.938 bisitz 6949: */
1.795 www 6950:
1.938 bisitz 6951: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6952: background-color: $mail_replied;
6953: }
1.795 www 6954:
1.938 bisitz 6955: /*
6956: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6957: background-color: $mail_replied_hover;
6958: }
1.938 bisitz 6959: */
1.795 www 6960:
1.938 bisitz 6961: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6962: background-color: $mail_other;
6963: }
1.795 www 6964:
1.938 bisitz 6965: /*
6966: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6967: background-color: $mail_other_hover;
6968: }
1.938 bisitz 6969: */
1.494 raeburn 6970:
1.777 tempelho 6971: table.LC_data_table tr > td.LC_browser_file,
6972: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6973: background: #AAEE77;
1.389 albertel 6974: }
1.795 www 6975:
1.777 tempelho 6976: table.LC_data_table tr > td.LC_browser_file_locked,
6977: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6978: background: #FFAA99;
1.387 albertel 6979: }
1.795 www 6980:
1.777 tempelho 6981: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6982: background: #888888;
1.779 bisitz 6983: }
1.795 www 6984:
1.777 tempelho 6985: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6986: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6987: background: #F8F866;
1.777 tempelho 6988: }
1.795 www 6989:
1.696 bisitz 6990: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6991: background: #E0E8FF;
1.387 albertel 6992: }
1.696 bisitz 6993:
1.707 bisitz 6994: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6995: /* background: #77FF77; */
1.707 bisitz 6996: }
1.795 www 6997:
1.707 bisitz 6998: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6999: border-right: 8px solid #FFFF77;
1.707 bisitz 7000: }
1.795 www 7001:
1.707 bisitz 7002: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 7003: border-right: 8px solid #FFAA77;
1.707 bisitz 7004: }
1.795 www 7005:
1.707 bisitz 7006: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 7007: border-right: 8px solid #FF7777;
1.707 bisitz 7008: }
1.795 www 7009:
1.707 bisitz 7010: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 7011: border-right: 8px solid #AAFF77;
1.707 bisitz 7012: }
1.795 www 7013:
1.707 bisitz 7014: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 7015: border-right: 8px solid #11CC55;
1.707 bisitz 7016: }
7017:
1.388 albertel 7018: span.LC_current_location {
1.701 harmsja 7019: font-size:larger;
1.388 albertel 7020: background: $pgbg;
7021: }
1.387 albertel 7022:
1.1029 www 7023: span.LC_current_nav_location {
7024: font-weight:bold;
7025: background: $sidebg;
7026: }
7027:
1.395 albertel 7028: span.LC_parm_menu_item {
7029: font-size: larger;
7030: }
1.795 www 7031:
1.395 albertel 7032: span.LC_parm_scope_all {
7033: color: red;
7034: }
1.795 www 7035:
1.395 albertel 7036: span.LC_parm_scope_folder {
7037: color: green;
7038: }
1.795 www 7039:
1.395 albertel 7040: span.LC_parm_scope_resource {
7041: color: orange;
7042: }
1.795 www 7043:
1.395 albertel 7044: span.LC_parm_part {
7045: color: blue;
7046: }
1.795 www 7047:
1.911 bisitz 7048: span.LC_parm_folder,
7049: span.LC_parm_symb {
1.395 albertel 7050: font-size: x-small;
7051: font-family: $mono;
7052: color: #AAAAAA;
7053: }
7054:
1.977 bisitz 7055: ul.LC_parm_parmlist li {
7056: display: inline-block;
7057: padding: 0.3em 0.8em;
7058: vertical-align: top;
7059: width: 150px;
7060: border-top:1px solid $lg_border_color;
7061: }
7062:
1.795 www 7063: td.LC_parm_overview_level_menu,
7064: td.LC_parm_overview_map_menu,
7065: td.LC_parm_overview_parm_selectors,
7066: td.LC_parm_overview_restrictions {
1.396 albertel 7067: border: 1px solid black;
7068: border-collapse: collapse;
7069: }
1.795 www 7070:
1.1285 raeburn 7071: span.LC_parm_recursive,
7072: td.LC_parm_recursive {
7073: font-weight: bold;
7074: font-size: smaller;
7075: }
7076:
1.396 albertel 7077: table.LC_parm_overview_restrictions td {
7078: border-width: 1px 4px 1px 4px;
7079: border-style: solid;
7080: border-color: $pgbg;
7081: text-align: center;
7082: }
1.795 www 7083:
1.396 albertel 7084: table.LC_parm_overview_restrictions th {
7085: background: $tabbg;
7086: border-width: 1px 4px 1px 4px;
7087: border-style: solid;
7088: border-color: $pgbg;
7089: }
1.795 www 7090:
1.398 albertel 7091: table#LC_helpmenu {
1.803 bisitz 7092: border: none;
1.398 albertel 7093: height: 55px;
1.803 bisitz 7094: border-spacing: 0;
1.398 albertel 7095: }
7096:
7097: table#LC_helpmenu fieldset legend {
7098: font-size: larger;
7099: }
1.795 www 7100:
1.397 albertel 7101: table#LC_helpmenu_links {
7102: width: 100%;
7103: border: 1px solid black;
7104: background: $pgbg;
1.803 bisitz 7105: padding: 0;
1.397 albertel 7106: border-spacing: 1px;
7107: }
1.795 www 7108:
1.397 albertel 7109: table#LC_helpmenu_links tr td {
7110: padding: 1px;
7111: background: $tabbg;
1.399 albertel 7112: text-align: center;
7113: font-weight: bold;
1.397 albertel 7114: }
1.396 albertel 7115:
1.795 www 7116: table#LC_helpmenu_links a:link,
7117: table#LC_helpmenu_links a:visited,
1.397 albertel 7118: table#LC_helpmenu_links a:active {
7119: text-decoration: none;
7120: color: $font;
7121: }
1.795 www 7122:
1.397 albertel 7123: table#LC_helpmenu_links a:hover {
7124: text-decoration: underline;
7125: color: $vlink;
7126: }
1.396 albertel 7127:
1.417 albertel 7128: .LC_chrt_popup_exists {
7129: border: 1px solid #339933;
7130: margin: -1px;
7131: }
1.795 www 7132:
1.417 albertel 7133: .LC_chrt_popup_up {
7134: border: 1px solid yellow;
7135: margin: -1px;
7136: }
1.795 www 7137:
1.417 albertel 7138: .LC_chrt_popup {
7139: border: 1px solid #8888FF;
7140: background: #CCCCFF;
7141: }
1.795 www 7142:
1.421 albertel 7143: table.LC_pick_box {
7144: border-collapse: separate;
7145: background: white;
7146: border: 1px solid black;
7147: border-spacing: 1px;
7148: }
1.795 www 7149:
1.421 albertel 7150: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7151: background: $sidebg;
1.421 albertel 7152: font-weight: bold;
1.900 bisitz 7153: text-align: left;
1.740 bisitz 7154: vertical-align: top;
1.421 albertel 7155: width: 184px;
7156: padding: 8px;
7157: }
1.795 www 7158:
1.579 raeburn 7159: table.LC_pick_box td.LC_pick_box_value {
7160: text-align: left;
7161: padding: 8px;
7162: }
1.795 www 7163:
1.579 raeburn 7164: table.LC_pick_box td.LC_pick_box_select {
7165: text-align: left;
7166: padding: 8px;
7167: }
1.795 www 7168:
1.424 albertel 7169: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7170: padding: 0;
1.421 albertel 7171: height: 1px;
7172: background: black;
7173: }
1.795 www 7174:
1.421 albertel 7175: table.LC_pick_box td.LC_pick_box_submit {
7176: text-align: right;
7177: }
1.795 www 7178:
1.579 raeburn 7179: table.LC_pick_box td.LC_evenrow_value {
7180: text-align: left;
7181: padding: 8px;
7182: background-color: $data_table_light;
7183: }
1.795 www 7184:
1.579 raeburn 7185: table.LC_pick_box td.LC_oddrow_value {
7186: text-align: left;
7187: padding: 8px;
7188: background-color: $data_table_light;
7189: }
1.795 www 7190:
1.579 raeburn 7191: span.LC_helpform_receipt_cat {
7192: font-weight: bold;
7193: }
1.795 www 7194:
1.424 albertel 7195: table.LC_group_priv_box {
7196: background: white;
7197: border: 1px solid black;
7198: border-spacing: 1px;
7199: }
1.795 www 7200:
1.424 albertel 7201: table.LC_group_priv_box td.LC_pick_box_title {
7202: background: $tabbg;
7203: font-weight: bold;
7204: text-align: right;
7205: width: 184px;
7206: }
1.795 www 7207:
1.424 albertel 7208: table.LC_group_priv_box td.LC_groups_fixed {
7209: background: $data_table_light;
7210: text-align: center;
7211: }
1.795 www 7212:
1.424 albertel 7213: table.LC_group_priv_box td.LC_groups_optional {
7214: background: $data_table_dark;
7215: text-align: center;
7216: }
1.795 www 7217:
1.424 albertel 7218: table.LC_group_priv_box td.LC_groups_functionality {
7219: background: $data_table_darker;
7220: text-align: center;
7221: font-weight: bold;
7222: }
1.795 www 7223:
1.424 albertel 7224: table.LC_group_priv td {
7225: text-align: left;
1.803 bisitz 7226: padding: 0;
1.424 albertel 7227: }
7228:
7229: .LC_navbuttons {
7230: margin: 2ex 0ex 2ex 0ex;
7231: }
1.795 www 7232:
1.423 albertel 7233: .LC_topic_bar {
7234: font-weight: bold;
7235: background: $tabbg;
1.918 wenzelju 7236: margin: 1em 0em 1em 2em;
1.805 bisitz 7237: padding: 3px;
1.918 wenzelju 7238: font-size: 1.2em;
1.423 albertel 7239: }
1.795 www 7240:
1.423 albertel 7241: .LC_topic_bar span {
1.918 wenzelju 7242: left: 0.5em;
7243: position: absolute;
1.423 albertel 7244: vertical-align: middle;
1.918 wenzelju 7245: font-size: 1.2em;
1.423 albertel 7246: }
1.795 www 7247:
1.423 albertel 7248: table.LC_course_group_status {
7249: margin: 20px;
7250: }
1.795 www 7251:
1.423 albertel 7252: table.LC_status_selector td {
7253: vertical-align: top;
7254: text-align: center;
1.424 albertel 7255: padding: 4px;
7256: }
1.795 www 7257:
1.599 albertel 7258: div.LC_feedback_link {
1.616 albertel 7259: clear: both;
1.829 kalberla 7260: background: $sidebg;
1.779 bisitz 7261: width: 100%;
1.829 kalberla 7262: padding-bottom: 10px;
7263: border: 1px $tabbg solid;
1.833 kalberla 7264: height: 22px;
7265: line-height: 22px;
7266: padding-top: 5px;
7267: }
7268:
7269: div.LC_feedback_link img {
7270: height: 22px;
1.867 kalberla 7271: vertical-align:middle;
1.829 kalberla 7272: }
7273:
1.911 bisitz 7274: div.LC_feedback_link a {
1.829 kalberla 7275: text-decoration: none;
1.489 raeburn 7276: }
1.795 www 7277:
1.867 kalberla 7278: div.LC_comblock {
1.911 bisitz 7279: display:inline;
1.867 kalberla 7280: color:$font;
7281: font-size:90%;
7282: }
7283:
7284: div.LC_feedback_link div.LC_comblock {
7285: padding-left:5px;
7286: }
7287:
7288: div.LC_feedback_link div.LC_comblock a {
7289: color:$font;
7290: }
7291:
1.489 raeburn 7292: span.LC_feedback_link {
1.858 bisitz 7293: /* background: $feedback_link_bg; */
1.599 albertel 7294: font-size: larger;
7295: }
1.795 www 7296:
1.599 albertel 7297: span.LC_message_link {
1.858 bisitz 7298: /* background: $feedback_link_bg; */
1.599 albertel 7299: font-size: larger;
7300: position: absolute;
7301: right: 1em;
1.489 raeburn 7302: }
1.421 albertel 7303:
1.515 albertel 7304: table.LC_prior_tries {
1.524 albertel 7305: border: 1px solid #000000;
7306: border-collapse: separate;
7307: border-spacing: 1px;
1.515 albertel 7308: }
1.523 albertel 7309:
1.515 albertel 7310: table.LC_prior_tries td {
1.524 albertel 7311: padding: 2px;
1.515 albertel 7312: }
1.523 albertel 7313:
7314: .LC_answer_correct {
1.795 www 7315: background: lightgreen;
7316: color: darkgreen;
7317: padding: 6px;
1.523 albertel 7318: }
1.795 www 7319:
1.523 albertel 7320: .LC_answer_charged_try {
1.797 www 7321: background: #FFAAAA;
1.795 www 7322: color: darkred;
7323: padding: 6px;
1.523 albertel 7324: }
1.795 www 7325:
1.779 bisitz 7326: .LC_answer_not_charged_try,
1.523 albertel 7327: .LC_answer_no_grade,
7328: .LC_answer_late {
1.795 www 7329: background: lightyellow;
1.523 albertel 7330: color: black;
1.795 www 7331: padding: 6px;
1.523 albertel 7332: }
1.795 www 7333:
1.523 albertel 7334: .LC_answer_previous {
1.795 www 7335: background: lightblue;
7336: color: darkblue;
7337: padding: 6px;
1.523 albertel 7338: }
1.795 www 7339:
1.779 bisitz 7340: .LC_answer_no_message {
1.777 tempelho 7341: background: #FFFFFF;
7342: color: black;
1.795 www 7343: padding: 6px;
1.779 bisitz 7344: }
1.795 www 7345:
1.1334 raeburn 7346: .LC_answer_unknown,
7347: .LC_answer_warning {
1.779 bisitz 7348: background: orange;
7349: color: black;
1.795 www 7350: padding: 6px;
1.777 tempelho 7351: }
1.795 www 7352:
1.529 albertel 7353: span.LC_prior_numerical,
7354: span.LC_prior_string,
7355: span.LC_prior_custom,
7356: span.LC_prior_reaction,
7357: span.LC_prior_math {
1.925 bisitz 7358: font-family: $mono;
1.523 albertel 7359: white-space: pre;
7360: }
7361:
1.525 albertel 7362: span.LC_prior_string {
1.925 bisitz 7363: font-family: $mono;
1.525 albertel 7364: white-space: pre;
7365: }
7366:
1.523 albertel 7367: table.LC_prior_option {
7368: width: 100%;
7369: border-collapse: collapse;
7370: }
1.795 www 7371:
1.911 bisitz 7372: table.LC_prior_rank,
1.795 www 7373: table.LC_prior_match {
1.528 albertel 7374: border-collapse: collapse;
7375: }
1.795 www 7376:
1.528 albertel 7377: table.LC_prior_option tr td,
7378: table.LC_prior_rank tr td,
7379: table.LC_prior_match tr td {
1.524 albertel 7380: border: 1px solid #000000;
1.515 albertel 7381: }
7382:
1.855 bisitz 7383: .LC_nobreak {
1.544 albertel 7384: white-space: nowrap;
1.519 raeburn 7385: }
7386:
1.576 raeburn 7387: span.LC_cusr_emph {
7388: font-style: italic;
7389: }
7390:
1.633 raeburn 7391: span.LC_cusr_subheading {
7392: font-weight: normal;
7393: font-size: 85%;
7394: }
7395:
1.861 bisitz 7396: div.LC_docs_entry_move {
1.859 bisitz 7397: border: 1px solid #BBBBBB;
1.545 albertel 7398: background: #DDDDDD;
1.861 bisitz 7399: width: 22px;
1.859 bisitz 7400: padding: 1px;
7401: margin: 0;
1.545 albertel 7402: }
7403:
1.861 bisitz 7404: table.LC_data_table tr > td.LC_docs_entry_commands,
7405: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7406: font-size: x-small;
7407: }
1.795 www 7408:
1.861 bisitz 7409: .LC_docs_entry_parameter {
7410: white-space: nowrap;
7411: }
7412:
1.544 albertel 7413: .LC_docs_copy {
1.545 albertel 7414: color: #000099;
1.544 albertel 7415: }
1.795 www 7416:
1.544 albertel 7417: .LC_docs_cut {
1.545 albertel 7418: color: #550044;
1.544 albertel 7419: }
1.795 www 7420:
1.544 albertel 7421: .LC_docs_rename {
1.545 albertel 7422: color: #009900;
1.544 albertel 7423: }
1.795 www 7424:
1.544 albertel 7425: .LC_docs_remove {
1.545 albertel 7426: color: #990000;
7427: }
7428:
1.1284 raeburn 7429: .LC_docs_alias {
7430: color: #440055;
7431: }
7432:
1.1286 raeburn 7433: .LC_domprefs_email,
1.1284 raeburn 7434: .LC_docs_alias_name,
1.547 albertel 7435: .LC_docs_reinit_warn,
7436: .LC_docs_ext_edit {
7437: font-size: x-small;
7438: }
7439:
1.545 albertel 7440: table.LC_docs_adddocs td,
7441: table.LC_docs_adddocs th {
7442: border: 1px solid #BBBBBB;
7443: padding: 4px;
7444: background: #DDDDDD;
1.543 albertel 7445: }
7446:
1.584 albertel 7447: table.LC_sty_begin {
7448: background: #BBFFBB;
7449: }
1.795 www 7450:
1.584 albertel 7451: table.LC_sty_end {
7452: background: #FFBBBB;
7453: }
7454:
1.589 raeburn 7455: table.LC_double_column {
1.803 bisitz 7456: border-width: 0;
1.589 raeburn 7457: border-collapse: collapse;
7458: width: 100%;
7459: padding: 2px;
7460: }
7461:
7462: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7463: top: 2px;
1.589 raeburn 7464: left: 2px;
7465: width: 47%;
7466: vertical-align: top;
7467: }
7468:
7469: table.LC_double_column tr td.LC_right_col {
7470: top: 2px;
1.779 bisitz 7471: right: 2px;
1.589 raeburn 7472: width: 47%;
7473: vertical-align: top;
7474: }
7475:
1.591 raeburn 7476: div.LC_left_float {
7477: float: left;
7478: padding-right: 5%;
1.597 albertel 7479: padding-bottom: 4px;
1.591 raeburn 7480: }
7481:
7482: div.LC_clear_float_header {
1.597 albertel 7483: padding-bottom: 2px;
1.591 raeburn 7484: }
7485:
7486: div.LC_clear_float_footer {
1.597 albertel 7487: padding-top: 10px;
1.591 raeburn 7488: clear: both;
7489: }
7490:
1.597 albertel 7491: div.LC_grade_show_user {
1.941 bisitz 7492: /* border-left: 5px solid $sidebg; */
7493: border-top: 5px solid #000000;
7494: margin: 50px 0 0 0;
1.936 bisitz 7495: padding: 15px 0 5px 10px;
1.597 albertel 7496: }
1.795 www 7497:
1.936 bisitz 7498: div.LC_grade_show_user_odd_row {
1.941 bisitz 7499: /* border-left: 5px solid #000000; */
7500: }
7501:
7502: div.LC_grade_show_user div.LC_Box {
7503: margin-right: 50px;
1.597 albertel 7504: }
7505:
7506: div.LC_grade_submissions,
7507: div.LC_grade_message_center,
1.936 bisitz 7508: div.LC_grade_info_links {
1.597 albertel 7509: margin: 5px;
7510: width: 99%;
7511: background: #FFFFFF;
7512: }
1.795 www 7513:
1.597 albertel 7514: div.LC_grade_submissions_header,
1.936 bisitz 7515: div.LC_grade_message_center_header {
1.705 tempelho 7516: font-weight: bold;
7517: font-size: large;
1.597 albertel 7518: }
1.795 www 7519:
1.597 albertel 7520: div.LC_grade_submissions_body,
1.936 bisitz 7521: div.LC_grade_message_center_body {
1.597 albertel 7522: border: 1px solid black;
7523: width: 99%;
7524: background: #FFFFFF;
7525: }
1.795 www 7526:
1.613 albertel 7527: table.LC_scantron_action {
7528: width: 100%;
7529: }
1.795 www 7530:
1.613 albertel 7531: table.LC_scantron_action tr th {
1.698 harmsja 7532: font-weight:bold;
7533: font-style:normal;
1.613 albertel 7534: }
1.795 www 7535:
1.779 bisitz 7536: .LC_edit_problem_header,
1.614 albertel 7537: div.LC_edit_problem_footer {
1.705 tempelho 7538: font-weight: normal;
7539: font-size: medium;
1.602 albertel 7540: margin: 2px;
1.1060 bisitz 7541: background-color: $sidebg;
1.600 albertel 7542: }
1.795 www 7543:
1.600 albertel 7544: div.LC_edit_problem_header,
1.602 albertel 7545: div.LC_edit_problem_header div,
1.614 albertel 7546: div.LC_edit_problem_footer,
7547: div.LC_edit_problem_footer div,
1.602 albertel 7548: div.LC_edit_problem_editxml_header,
7549: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7550: z-index: 100;
1.600 albertel 7551: }
1.795 www 7552:
1.600 albertel 7553: div.LC_edit_problem_header_title {
1.705 tempelho 7554: font-weight: bold;
7555: font-size: larger;
1.602 albertel 7556: background: $tabbg;
7557: padding: 3px;
1.1060 bisitz 7558: margin: 0 0 5px 0;
1.602 albertel 7559: }
1.795 www 7560:
1.602 albertel 7561: table.LC_edit_problem_header_title {
7562: width: 100%;
1.600 albertel 7563: background: $tabbg;
1.602 albertel 7564: }
7565:
1.1205 golterma 7566: div.LC_edit_actionbar {
7567: background-color: $sidebg;
1.1218 droeschl 7568: margin: 0;
7569: padding: 0;
7570: line-height: 200%;
1.602 albertel 7571: }
1.795 www 7572:
1.1218 droeschl 7573: div.LC_edit_actionbar div{
7574: padding: 0;
7575: margin: 0;
7576: display: inline-block;
1.600 albertel 7577: }
1.795 www 7578:
1.1124 bisitz 7579: .LC_edit_opt {
7580: padding-left: 1em;
7581: white-space: nowrap;
7582: }
7583:
1.1152 golterma 7584: .LC_edit_problem_latexhelper{
7585: text-align: right;
7586: }
7587:
7588: #LC_edit_problem_colorful div{
7589: margin-left: 40px;
7590: }
7591:
1.1205 golterma 7592: #LC_edit_problem_codemirror div{
7593: margin-left: 0px;
7594: }
7595:
1.911 bisitz 7596: img.stift {
1.803 bisitz 7597: border-width: 0;
7598: vertical-align: middle;
1.677 riegler 7599: }
1.680 riegler 7600:
1.923 bisitz 7601: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7602: vertical-align: top;
1.777 tempelho 7603: }
1.795 www 7604:
1.716 raeburn 7605: div.LC_createcourse {
1.911 bisitz 7606: margin: 10px 10px 10px 10px;
1.716 raeburn 7607: }
7608:
1.917 raeburn 7609: .LC_dccid {
1.1130 raeburn 7610: float: right;
1.917 raeburn 7611: margin: 0.2em 0 0 0;
7612: padding: 0;
7613: font-size: 90%;
7614: display:none;
7615: }
7616:
1.897 wenzelju 7617: ol.LC_primary_menu a:hover,
1.721 harmsja 7618: ol#LC_MenuBreadcrumbs a:hover,
7619: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7620: ul#LC_secondary_menu a:hover,
1.721 harmsja 7621: .LC_FormSectionClearButton input:hover
1.795 www 7622: ul.LC_TabContent li:hover a {
1.952 onken 7623: color:$button_hover;
1.911 bisitz 7624: text-decoration:none;
1.693 droeschl 7625: }
7626:
1.779 bisitz 7627: h1 {
1.911 bisitz 7628: padding: 0;
7629: line-height:130%;
1.693 droeschl 7630: }
1.698 harmsja 7631:
1.911 bisitz 7632: h2,
7633: h3,
7634: h4,
7635: h5,
7636: h6 {
7637: margin: 5px 0 5px 0;
7638: padding: 0;
7639: line-height:130%;
1.693 droeschl 7640: }
1.795 www 7641:
7642: .LC_hcell {
1.911 bisitz 7643: padding:3px 15px 3px 15px;
7644: margin: 0;
7645: background-color:$tabbg;
7646: color:$fontmenu;
7647: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7648: }
1.795 www 7649:
1.840 bisitz 7650: .LC_Box > .LC_hcell {
1.911 bisitz 7651: margin: 0 -10px 10px -10px;
1.835 bisitz 7652: }
7653:
1.721 harmsja 7654: .LC_noBorder {
1.911 bisitz 7655: border: 0;
1.698 harmsja 7656: }
1.693 droeschl 7657:
1.721 harmsja 7658: .LC_FormSectionClearButton input {
1.911 bisitz 7659: background-color:transparent;
7660: border: none;
7661: cursor:pointer;
7662: text-decoration:underline;
1.693 droeschl 7663: }
1.763 bisitz 7664:
7665: .LC_help_open_topic {
1.911 bisitz 7666: color: #FFFFFF;
7667: background-color: #EEEEFF;
7668: margin: 1px;
7669: padding: 4px;
7670: border: 1px solid #000033;
7671: white-space: nowrap;
7672: /* vertical-align: middle; */
1.759 neumanie 7673: }
1.693 droeschl 7674:
1.911 bisitz 7675: dl,
7676: ul,
7677: div,
7678: fieldset {
7679: margin: 10px 10px 10px 0;
7680: /* overflow: hidden; */
1.693 droeschl 7681: }
1.795 www 7682:
1.1211 raeburn 7683: article.geogebraweb div {
7684: margin: 0;
7685: }
7686:
1.838 bisitz 7687: fieldset > legend {
1.911 bisitz 7688: font-weight: bold;
7689: padding: 0 5px 0 5px;
1.838 bisitz 7690: }
7691:
1.813 bisitz 7692: #LC_nav_bar {
1.911 bisitz 7693: float: left;
1.995 raeburn 7694: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7695: margin: 0 0 2px 0;
1.807 droeschl 7696: }
7697:
1.916 droeschl 7698: #LC_realm {
7699: margin: 0.2em 0 0 0;
7700: padding: 0;
7701: font-weight: bold;
7702: text-align: center;
1.995 raeburn 7703: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7704: }
7705:
1.911 bisitz 7706: #LC_nav_bar em {
7707: font-weight: bold;
7708: font-style: normal;
1.807 droeschl 7709: }
7710:
1.897 wenzelju 7711: ol.LC_primary_menu {
1.934 droeschl 7712: margin: 0;
1.1076 raeburn 7713: padding: 0;
1.807 droeschl 7714: }
7715:
1.852 droeschl 7716: ol#LC_PathBreadcrumbs {
1.911 bisitz 7717: margin: 0;
1.693 droeschl 7718: }
7719:
1.897 wenzelju 7720: ol.LC_primary_menu li {
1.1076 raeburn 7721: color: RGB(80, 80, 80);
7722: vertical-align: middle;
7723: text-align: left;
7724: list-style: none;
1.1205 golterma 7725: position: relative;
1.1076 raeburn 7726: float: left;
1.1205 golterma 7727: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7728: line-height: 1.5em;
1.1076 raeburn 7729: }
7730:
1.1205 golterma 7731: ol.LC_primary_menu li a,
7732: ol.LC_primary_menu li p {
1.1076 raeburn 7733: display: block;
7734: margin: 0;
7735: padding: 0 5px 0 10px;
7736: text-decoration: none;
7737: }
7738:
1.1205 golterma 7739: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7740: display: inline-block;
7741: width: 95%;
7742: text-align: left;
7743: }
7744:
7745: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7746: display: inline-block;
7747: width: 5%;
7748: float: right;
7749: text-align: right;
7750: font-size: 70%;
7751: }
7752:
7753: ol.LC_primary_menu ul {
1.1076 raeburn 7754: display: none;
1.1205 golterma 7755: width: 15em;
1.1076 raeburn 7756: background-color: $data_table_light;
1.1205 golterma 7757: position: absolute;
7758: top: 100%;
1.1076 raeburn 7759: }
7760:
1.1205 golterma 7761: ol.LC_primary_menu ul ul {
7762: left: 100%;
7763: top: 0;
7764: }
7765:
7766: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7767: display: block;
7768: position: absolute;
7769: margin: 0;
7770: padding: 0;
1.1078 raeburn 7771: z-index: 2;
1.1076 raeburn 7772: }
7773:
7774: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7775: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7776: font-size: 90%;
1.911 bisitz 7777: vertical-align: top;
1.1076 raeburn 7778: float: none;
1.1079 raeburn 7779: border-left: 1px solid black;
7780: border-right: 1px solid black;
1.1205 golterma 7781: /* A dark bottom border to visualize different menu options;
7782: overwritten in the create_submenu routine for the last border-bottom of the menu */
7783: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7784: }
7785:
1.1205 golterma 7786: ol.LC_primary_menu li li p:hover {
7787: color:$button_hover;
7788: text-decoration:none;
7789: background-color:$data_table_dark;
1.1076 raeburn 7790: }
7791:
7792: ol.LC_primary_menu li li a:hover {
7793: color:$button_hover;
7794: background-color:$data_table_dark;
1.693 droeschl 7795: }
7796:
1.1205 golterma 7797: /* Font-size equal to the size of the predecessors*/
7798: ol.LC_primary_menu li:hover li li {
7799: font-size: 100%;
7800: }
7801:
1.897 wenzelju 7802: ol.LC_primary_menu li img {
1.911 bisitz 7803: vertical-align: bottom;
1.934 droeschl 7804: height: 1.1em;
1.1077 raeburn 7805: margin: 0.2em 0 0 0;
1.693 droeschl 7806: }
7807:
1.897 wenzelju 7808: ol.LC_primary_menu a {
1.911 bisitz 7809: color: RGB(80, 80, 80);
7810: text-decoration: none;
1.693 droeschl 7811: }
1.795 www 7812:
1.949 droeschl 7813: ol.LC_primary_menu a.LC_new_message {
7814: font-weight:bold;
7815: color: darkred;
7816: }
7817:
1.975 raeburn 7818: ol.LC_docs_parameters {
7819: margin-left: 0;
7820: padding: 0;
7821: list-style: none;
7822: }
7823:
7824: ol.LC_docs_parameters li {
7825: margin: 0;
7826: padding-right: 20px;
7827: display: inline;
7828: }
7829:
1.976 raeburn 7830: ol.LC_docs_parameters li:before {
7831: content: "\\002022 \\0020";
7832: }
7833:
7834: li.LC_docs_parameters_title {
7835: font-weight: bold;
7836: }
7837:
7838: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7839: content: "";
7840: }
7841:
1.897 wenzelju 7842: ul#LC_secondary_menu {
1.1107 raeburn 7843: clear: right;
1.911 bisitz 7844: color: $fontmenu;
7845: background: $tabbg;
7846: list-style: none;
7847: padding: 0;
7848: margin: 0;
7849: width: 100%;
1.995 raeburn 7850: text-align: left;
1.1107 raeburn 7851: float: left;
1.808 droeschl 7852: }
7853:
1.897 wenzelju 7854: ul#LC_secondary_menu li {
1.911 bisitz 7855: font-weight: bold;
7856: line-height: 1.8em;
1.1107 raeburn 7857: border-right: 1px solid black;
7858: float: left;
7859: }
7860:
7861: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7862: background-color: $data_table_light;
7863: }
7864:
7865: ul#LC_secondary_menu li a {
1.911 bisitz 7866: padding: 0 0.8em;
1.1107 raeburn 7867: }
7868:
7869: ul#LC_secondary_menu li ul {
7870: display: none;
7871: }
7872:
7873: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7874: display: block;
7875: position: absolute;
7876: margin: 0;
7877: padding: 0;
7878: list-style:none;
7879: float: none;
7880: background-color: $data_table_light;
7881: z-index: 2;
7882: margin-left: -1px;
7883: }
7884:
7885: ul#LC_secondary_menu li ul li {
7886: font-size: 90%;
7887: vertical-align: top;
7888: border-left: 1px solid black;
1.911 bisitz 7889: border-right: 1px solid black;
1.1119 raeburn 7890: background-color: $data_table_light;
1.1107 raeburn 7891: list-style:none;
7892: float: none;
7893: }
7894:
7895: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7896: background-color: $data_table_dark;
1.807 droeschl 7897: }
7898:
1.847 tempelho 7899: ul.LC_TabContent {
1.911 bisitz 7900: display:block;
7901: background: $sidebg;
7902: border-bottom: solid 1px $lg_border_color;
7903: list-style:none;
1.1020 raeburn 7904: margin: -1px -10px 0 -10px;
1.911 bisitz 7905: padding: 0;
1.693 droeschl 7906: }
7907:
1.795 www 7908: ul.LC_TabContent li,
7909: ul.LC_TabContentBigger li {
1.911 bisitz 7910: float:left;
1.741 harmsja 7911: }
1.795 www 7912:
1.897 wenzelju 7913: ul#LC_secondary_menu li a {
1.911 bisitz 7914: color: $fontmenu;
7915: text-decoration: none;
1.693 droeschl 7916: }
1.795 www 7917:
1.721 harmsja 7918: ul.LC_TabContent {
1.952 onken 7919: min-height:20px;
1.721 harmsja 7920: }
1.795 www 7921:
7922: ul.LC_TabContent li {
1.911 bisitz 7923: vertical-align:middle;
1.959 onken 7924: padding: 0 16px 0 10px;
1.911 bisitz 7925: background-color:$tabbg;
7926: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7927: border-left: solid 1px $font;
1.721 harmsja 7928: }
1.795 www 7929:
1.847 tempelho 7930: ul.LC_TabContent .right {
1.911 bisitz 7931: float:right;
1.847 tempelho 7932: }
7933:
1.911 bisitz 7934: ul.LC_TabContent li a,
7935: ul.LC_TabContent li {
7936: color:rgb(47,47,47);
7937: text-decoration:none;
7938: font-size:95%;
7939: font-weight:bold;
1.952 onken 7940: min-height:20px;
7941: }
7942:
1.959 onken 7943: ul.LC_TabContent li a:hover,
7944: ul.LC_TabContent li a:focus {
1.952 onken 7945: color: $button_hover;
1.959 onken 7946: background:none;
7947: outline:none;
1.952 onken 7948: }
7949:
7950: ul.LC_TabContent li:hover {
7951: color: $button_hover;
7952: cursor:pointer;
1.721 harmsja 7953: }
1.795 www 7954:
1.911 bisitz 7955: ul.LC_TabContent li.active {
1.952 onken 7956: color: $font;
1.911 bisitz 7957: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7958: border-bottom:solid 1px #FFFFFF;
7959: cursor: default;
1.744 ehlerst 7960: }
1.795 www 7961:
1.959 onken 7962: ul.LC_TabContent li.active a {
7963: color:$font;
7964: background:#FFFFFF;
7965: outline: none;
7966: }
1.1047 raeburn 7967:
7968: ul.LC_TabContent li.goback {
7969: float: left;
7970: border-left: none;
7971: }
7972:
1.870 tempelho 7973: #maincoursedoc {
1.911 bisitz 7974: clear:both;
1.870 tempelho 7975: }
7976:
7977: ul.LC_TabContentBigger {
1.911 bisitz 7978: display:block;
7979: list-style:none;
7980: padding: 0;
1.870 tempelho 7981: }
7982:
1.795 www 7983: ul.LC_TabContentBigger li {
1.911 bisitz 7984: vertical-align:bottom;
7985: height: 30px;
7986: font-size:110%;
7987: font-weight:bold;
7988: color: #737373;
1.841 tempelho 7989: }
7990:
1.957 onken 7991: ul.LC_TabContentBigger li.active {
7992: position: relative;
7993: top: 1px;
7994: }
7995:
1.870 tempelho 7996: ul.LC_TabContentBigger li a {
1.911 bisitz 7997: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7998: height: 30px;
7999: line-height: 30px;
8000: text-align: center;
8001: display: block;
8002: text-decoration: none;
1.958 onken 8003: outline: none;
1.741 harmsja 8004: }
1.795 www 8005:
1.870 tempelho 8006: ul.LC_TabContentBigger li.active a {
1.911 bisitz 8007: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
8008: color:$font;
1.744 ehlerst 8009: }
1.795 www 8010:
1.870 tempelho 8011: ul.LC_TabContentBigger li b {
1.911 bisitz 8012: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
8013: display: block;
8014: float: left;
8015: padding: 0 30px;
1.957 onken 8016: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 8017: }
8018:
1.956 onken 8019: ul.LC_TabContentBigger li:hover b {
8020: color:$button_hover;
8021: }
8022:
1.870 tempelho 8023: ul.LC_TabContentBigger li.active b {
1.911 bisitz 8024: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
8025: color:$font;
1.957 onken 8026: border: 0;
1.741 harmsja 8027: }
1.693 droeschl 8028:
1.870 tempelho 8029:
1.862 bisitz 8030: ul.LC_CourseBreadcrumbs {
8031: background: $sidebg;
1.1020 raeburn 8032: height: 2em;
1.862 bisitz 8033: padding-left: 10px;
1.1020 raeburn 8034: margin: 0;
1.862 bisitz 8035: list-style-position: inside;
8036: }
8037:
1.911 bisitz 8038: ol#LC_MenuBreadcrumbs,
1.862 bisitz 8039: ol#LC_PathBreadcrumbs {
1.911 bisitz 8040: padding-left: 10px;
8041: margin: 0;
1.933 droeschl 8042: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 8043: }
8044:
1.911 bisitz 8045: ol#LC_MenuBreadcrumbs li,
8046: ol#LC_PathBreadcrumbs li,
1.862 bisitz 8047: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 8048: display: inline;
1.933 droeschl 8049: white-space: normal;
1.693 droeschl 8050: }
8051:
1.823 bisitz 8052: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 8053: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 8054: text-decoration: none;
8055: font-size:90%;
1.693 droeschl 8056: }
1.795 www 8057:
1.969 droeschl 8058: ol#LC_MenuBreadcrumbs h1 {
8059: display: inline;
8060: font-size: 90%;
8061: line-height: 2.5em;
8062: margin: 0;
8063: padding: 0;
8064: }
8065:
1.795 www 8066: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 8067: text-decoration:none;
8068: font-size:100%;
8069: font-weight:bold;
1.693 droeschl 8070: }
1.795 www 8071:
1.840 bisitz 8072: .LC_Box {
1.911 bisitz 8073: border: solid 1px $lg_border_color;
8074: padding: 0 10px 10px 10px;
1.746 neumanie 8075: }
1.795 www 8076:
1.1020 raeburn 8077: .LC_DocsBox {
8078: border: solid 1px $lg_border_color;
8079: padding: 0 0 10px 10px;
8080: }
8081:
1.795 www 8082: .LC_AboutMe_Image {
1.911 bisitz 8083: float:left;
8084: margin-right:10px;
1.747 neumanie 8085: }
1.795 www 8086:
8087: .LC_Clear_AboutMe_Image {
1.911 bisitz 8088: clear:left;
1.747 neumanie 8089: }
1.795 www 8090:
1.721 harmsja 8091: dl.LC_ListStyleClean dt {
1.911 bisitz 8092: padding-right: 5px;
8093: display: table-header-group;
1.693 droeschl 8094: }
8095:
1.721 harmsja 8096: dl.LC_ListStyleClean dd {
1.911 bisitz 8097: display: table-row;
1.693 droeschl 8098: }
8099:
1.721 harmsja 8100: .LC_ListStyleClean,
8101: .LC_ListStyleSimple,
8102: .LC_ListStyleNormal,
1.795 www 8103: .LC_ListStyleSpecial {
1.911 bisitz 8104: /* display:block; */
8105: list-style-position: inside;
8106: list-style-type: none;
8107: overflow: hidden;
8108: padding: 0;
1.693 droeschl 8109: }
8110:
1.721 harmsja 8111: .LC_ListStyleSimple li,
8112: .LC_ListStyleSimple dd,
8113: .LC_ListStyleNormal li,
8114: .LC_ListStyleNormal dd,
8115: .LC_ListStyleSpecial li,
1.795 www 8116: .LC_ListStyleSpecial dd {
1.911 bisitz 8117: margin: 0;
8118: padding: 5px 5px 5px 10px;
8119: clear: both;
1.693 droeschl 8120: }
8121:
1.721 harmsja 8122: .LC_ListStyleClean li,
8123: .LC_ListStyleClean dd {
1.911 bisitz 8124: padding-top: 0;
8125: padding-bottom: 0;
1.693 droeschl 8126: }
8127:
1.721 harmsja 8128: .LC_ListStyleSimple dd,
1.795 www 8129: .LC_ListStyleSimple li {
1.911 bisitz 8130: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8131: }
8132:
1.721 harmsja 8133: .LC_ListStyleSpecial li,
8134: .LC_ListStyleSpecial dd {
1.911 bisitz 8135: list-style-type: none;
8136: background-color: RGB(220, 220, 220);
8137: margin-bottom: 4px;
1.693 droeschl 8138: }
8139:
1.721 harmsja 8140: table.LC_SimpleTable {
1.911 bisitz 8141: margin:5px;
8142: border:solid 1px $lg_border_color;
1.795 www 8143: }
1.693 droeschl 8144:
1.721 harmsja 8145: table.LC_SimpleTable tr {
1.911 bisitz 8146: padding: 0;
8147: border:solid 1px $lg_border_color;
1.693 droeschl 8148: }
1.795 www 8149:
8150: table.LC_SimpleTable thead {
1.911 bisitz 8151: background:rgb(220,220,220);
1.693 droeschl 8152: }
8153:
1.721 harmsja 8154: div.LC_columnSection {
1.911 bisitz 8155: display: block;
8156: clear: both;
8157: overflow: hidden;
8158: margin: 0;
1.693 droeschl 8159: }
8160:
1.721 harmsja 8161: div.LC_columnSection>* {
1.911 bisitz 8162: float: left;
8163: margin: 10px 20px 10px 0;
8164: overflow:hidden;
1.693 droeschl 8165: }
1.721 harmsja 8166:
1.795 www 8167: table em {
1.911 bisitz 8168: font-weight: bold;
8169: font-style: normal;
1.748 schulted 8170: }
1.795 www 8171:
1.779 bisitz 8172: table.LC_tableBrowseRes,
1.795 www 8173: table.LC_tableOfContent {
1.911 bisitz 8174: border:none;
8175: border-spacing: 1px;
8176: padding: 3px;
8177: background-color: #FFFFFF;
8178: font-size: 90%;
1.753 droeschl 8179: }
1.789 droeschl 8180:
1.911 bisitz 8181: table.LC_tableOfContent {
8182: border-collapse: collapse;
1.789 droeschl 8183: }
8184:
1.771 droeschl 8185: table.LC_tableBrowseRes a,
1.768 schulted 8186: table.LC_tableOfContent a {
1.911 bisitz 8187: background-color: transparent;
8188: text-decoration: none;
1.753 droeschl 8189: }
8190:
1.795 www 8191: table.LC_tableOfContent img {
1.911 bisitz 8192: border: none;
8193: height: 1.3em;
8194: vertical-align: text-bottom;
8195: margin-right: 0.3em;
1.753 droeschl 8196: }
1.757 schulted 8197:
1.795 www 8198: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8199: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8200: }
8201:
1.795 www 8202: a#LC_content_toolbar_everything {
1.911 bisitz 8203: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8204: }
8205:
1.795 www 8206: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8207: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8208: }
8209:
1.795 www 8210: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8211: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8212: }
8213:
1.795 www 8214: a#LC_content_toolbar_changefolder {
1.911 bisitz 8215: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8216: }
8217:
1.795 www 8218: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8219: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8220: }
8221:
1.1043 raeburn 8222: a#LC_content_toolbar_edittoplevel {
8223: background-image:url(/res/adm/pages/edittoplevel.gif);
8224: }
8225:
1.795 www 8226: ul#LC_toolbar li a:hover {
1.911 bisitz 8227: background-position: bottom center;
1.757 schulted 8228: }
8229:
1.795 www 8230: ul#LC_toolbar {
1.911 bisitz 8231: padding: 0;
8232: margin: 2px;
8233: list-style:none;
8234: position:relative;
8235: background-color:white;
1.1082 raeburn 8236: overflow: auto;
1.757 schulted 8237: }
8238:
1.795 www 8239: ul#LC_toolbar li {
1.911 bisitz 8240: border:1px solid white;
8241: padding: 0;
8242: margin: 0;
8243: float: left;
8244: display:inline;
8245: vertical-align:middle;
1.1082 raeburn 8246: white-space: nowrap;
1.911 bisitz 8247: }
1.757 schulted 8248:
1.783 amueller 8249:
1.795 www 8250: a.LC_toolbarItem {
1.911 bisitz 8251: display:block;
8252: padding: 0;
8253: margin: 0;
8254: height: 32px;
8255: width: 32px;
8256: color:white;
8257: border: none;
8258: background-repeat:no-repeat;
8259: background-color:transparent;
1.757 schulted 8260: }
8261:
1.915 droeschl 8262: ul.LC_funclist {
8263: margin: 0;
8264: padding: 0.5em 1em 0.5em 0;
8265: }
8266:
1.933 droeschl 8267: ul.LC_funclist > li:first-child {
8268: font-weight:bold;
8269: margin-left:0.8em;
8270: }
8271:
1.915 droeschl 8272: ul.LC_funclist + ul.LC_funclist {
8273: /*
8274: left border as a seperator if we have more than
8275: one list
8276: */
8277: border-left: 1px solid $sidebg;
8278: /*
8279: this hides the left border behind the border of the
8280: outer box if element is wrapped to the next 'line'
8281: */
8282: margin-left: -1px;
8283: }
8284:
1.843 bisitz 8285: ul.LC_funclist li {
1.915 droeschl 8286: display: inline;
1.782 bisitz 8287: white-space: nowrap;
1.915 droeschl 8288: margin: 0 0 0 25px;
8289: line-height: 150%;
1.782 bisitz 8290: }
8291:
1.974 wenzelju 8292: .LC_hidden {
8293: display: none;
8294: }
8295:
1.1030 www 8296: .LCmodal-overlay {
8297: position:fixed;
8298: top:0;
8299: right:0;
8300: bottom:0;
8301: left:0;
8302: height:100%;
8303: width:100%;
8304: margin:0;
8305: padding:0;
8306: background:#999;
8307: opacity:.75;
8308: filter: alpha(opacity=75);
8309: -moz-opacity: 0.75;
8310: z-index:101;
8311: }
8312:
8313: * html .LCmodal-overlay {
8314: position: absolute;
8315: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8316: }
8317:
8318: .LCmodal-window {
8319: position:fixed;
8320: top:50%;
8321: left:50%;
8322: margin:0;
8323: padding:0;
8324: z-index:102;
8325: }
8326:
8327: * html .LCmodal-window {
8328: position:absolute;
8329: }
8330:
8331: .LCclose-window {
8332: position:absolute;
8333: width:32px;
8334: height:32px;
8335: right:8px;
8336: top:8px;
8337: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8338: text-indent:-99999px;
8339: overflow:hidden;
8340: cursor:pointer;
8341: }
8342:
1.1335 raeburn 8343: pre.LC_wordwrap {
8344: white-space: pre-wrap;
8345: white-space: -moz-pre-wrap;
8346: white-space: -pre-wrap;
8347: white-space: -o-pre-wrap;
8348: word-wrap: break-word;
8349: }
8350:
1.1100 raeburn 8351: /*
1.1231 damieng 8352: styles used for response display
8353: */
8354: div.LC_radiofoil, div.LC_rankfoil {
8355: margin: .5em 0em .5em 0em;
8356: }
8357: table.LC_itemgroup {
8358: margin-top: 1em;
8359: }
8360:
8361: /*
1.1100 raeburn 8362: styles used by TTH when "Default set of options to pass to tth/m
8363: when converting TeX" in course settings has been set
8364:
8365: option passed: -t
8366:
8367: */
8368:
8369: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8370: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8371: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8372: td div.norm {line-height:normal;}
8373:
8374: /*
8375: option passed -y3
8376: */
8377:
8378: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8379: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8380: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8381:
1.1230 damieng 8382: /*
8383: sections with roles, for content only
8384: */
8385: section[class^="role-"] {
8386: padding-left: 10px;
8387: padding-right: 5px;
8388: margin-top: 8px;
8389: margin-bottom: 8px;
8390: border: 1px solid #2A4;
8391: border-radius: 5px;
8392: box-shadow: 0px 1px 1px #BBB;
8393: }
8394: section[class^="role-"]>h1 {
8395: position: relative;
8396: margin: 0px;
8397: padding-top: 10px;
8398: padding-left: 40px;
8399: }
8400: section[class^="role-"]>h1:before {
8401: position: absolute;
8402: left: -5px;
8403: top: 5px;
8404: }
8405: section.role-activity>h1:before {
8406: content:url('/adm/daxe/images/section_icons/activity.png');
8407: }
8408: section.role-advice>h1:before {
8409: content:url('/adm/daxe/images/section_icons/advice.png');
8410: }
8411: section.role-bibliography>h1:before {
8412: content:url('/adm/daxe/images/section_icons/bibliography.png');
8413: }
8414: section.role-citation>h1:before {
8415: content:url('/adm/daxe/images/section_icons/citation.png');
8416: }
8417: section.role-conclusion>h1:before {
8418: content:url('/adm/daxe/images/section_icons/conclusion.png');
8419: }
8420: section.role-definition>h1:before {
8421: content:url('/adm/daxe/images/section_icons/definition.png');
8422: }
8423: section.role-demonstration>h1:before {
8424: content:url('/adm/daxe/images/section_icons/demonstration.png');
8425: }
8426: section.role-example>h1:before {
8427: content:url('/adm/daxe/images/section_icons/example.png');
8428: }
8429: section.role-explanation>h1:before {
8430: content:url('/adm/daxe/images/section_icons/explanation.png');
8431: }
8432: section.role-introduction>h1:before {
8433: content:url('/adm/daxe/images/section_icons/introduction.png');
8434: }
8435: section.role-method>h1:before {
8436: content:url('/adm/daxe/images/section_icons/method.png');
8437: }
8438: section.role-more_information>h1:before {
8439: content:url('/adm/daxe/images/section_icons/more_information.png');
8440: }
8441: section.role-objectives>h1:before {
8442: content:url('/adm/daxe/images/section_icons/objectives.png');
8443: }
8444: section.role-prerequisites>h1:before {
8445: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8446: }
8447: section.role-remark>h1:before {
8448: content:url('/adm/daxe/images/section_icons/remark.png');
8449: }
8450: section.role-reminder>h1:before {
8451: content:url('/adm/daxe/images/section_icons/reminder.png');
8452: }
8453: section.role-summary>h1:before {
8454: content:url('/adm/daxe/images/section_icons/summary.png');
8455: }
8456: section.role-syntax>h1:before {
8457: content:url('/adm/daxe/images/section_icons/syntax.png');
8458: }
8459: section.role-warning>h1:before {
8460: content:url('/adm/daxe/images/section_icons/warning.png');
8461: }
8462:
1.1269 raeburn 8463: #LC_minitab_header {
8464: float:left;
8465: width:100%;
8466: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8467: font-size:93%;
8468: line-height:normal;
8469: margin: 0.5em 0 0.5em 0;
8470: }
8471: #LC_minitab_header ul {
8472: margin:0;
8473: padding:10px 10px 0;
8474: list-style:none;
8475: }
8476: #LC_minitab_header li {
8477: float:left;
8478: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8479: margin:0;
8480: padding:0 0 0 9px;
8481: }
8482: #LC_minitab_header a {
8483: display:block;
8484: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8485: padding:5px 15px 4px 6px;
8486: }
8487: #LC_minitab_header #LC_current_minitab {
8488: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8489: }
8490: #LC_minitab_header #LC_current_minitab a {
8491: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8492: padding-bottom:5px;
8493: }
8494:
8495:
1.343 albertel 8496: END
8497: }
8498:
1.306 albertel 8499: =pod
8500:
8501: =item * &headtag()
8502:
8503: Returns a uniform footer for LON-CAPA web pages.
8504:
1.307 albertel 8505: Inputs: $title - optional title for the head
8506: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8507: $args - optional arguments
1.319 albertel 8508: force_register - if is true call registerurl so the remote is
8509: informed
1.415 albertel 8510: redirect -> array ref of
8511: 1- seconds before redirect occurs
8512: 2- url to redirect to
8513: 3- whether the side effect should occur
1.315 albertel 8514: (side effect of setting
8515: $env{'internal.head.redirect'} to the url
8516: redirected too)
1.352 albertel 8517: domain -> force to color decorate a page for a specific
8518: domain
8519: function -> force usage of a specific rolish color scheme
8520: bgcolor -> override the default page bgcolor
1.460 albertel 8521: no_auto_mt_title
8522: -> prevent &mt()ing the title arg
1.464 albertel 8523:
1.306 albertel 8524: =cut
8525:
8526: sub headtag {
1.313 albertel 8527: my ($title,$head_extra,$args) = @_;
1.306 albertel 8528:
1.363 albertel 8529: my $function = $args->{'function'} || &get_users_function();
8530: my $domain = $args->{'domain'} || &determinedomain();
8531: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8532: my $httphost = $args->{'use_absolute'};
1.418 albertel 8533: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8534: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8535: #time(),
1.418 albertel 8536: $env{'environment.color.timestamp'},
1.363 albertel 8537: $function,$domain,$bgcolor);
8538:
1.369 www 8539: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8540:
1.308 albertel 8541: my $result =
8542: '<head>'.
1.1160 raeburn 8543: &font_settings($args);
1.319 albertel 8544:
1.1188 raeburn 8545: my $inhibitprint;
8546: if ($args->{'print_suppress'}) {
8547: $inhibitprint = &print_suppression();
8548: }
1.1064 raeburn 8549:
1.461 albertel 8550: if (!$args->{'frameset'}) {
8551: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8552: }
1.962 droeschl 8553: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8554: $result .= Apache::lonxml::display_title();
1.319 albertel 8555: }
1.436 albertel 8556: if (!$args->{'no_nav_bar'}
8557: && !$args->{'only_body'}
8558: && !$args->{'frameset'}) {
1.1154 raeburn 8559: $result .= &help_menu_js($httphost);
1.1032 www 8560: $result.=&modal_window();
1.1038 www 8561: $result.=&togglebox_script();
1.1034 www 8562: $result.=&wishlist_window();
1.1041 www 8563: $result.=&LCprogressbarUpdate_script();
1.1034 www 8564: } else {
8565: if ($args->{'add_modal'}) {
8566: $result.=&modal_window();
8567: }
8568: if ($args->{'add_wishlist'}) {
8569: $result.=&wishlist_window();
8570: }
1.1038 www 8571: if ($args->{'add_togglebox'}) {
8572: $result.=&togglebox_script();
8573: }
1.1041 www 8574: if ($args->{'add_progressbar'}) {
8575: $result.=&LCprogressbarUpdate_script();
8576: }
1.436 albertel 8577: }
1.314 albertel 8578: if (ref($args->{'redirect'})) {
1.414 albertel 8579: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8580: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8581: if (!$inhibit_continue) {
8582: $env{'internal.head.redirect'} = $url;
8583: }
1.313 albertel 8584: $result.=<<ADDMETA
8585: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8586: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8587: ADDMETA
1.1210 raeburn 8588: } else {
8589: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8590: my $requrl = $env{'request.uri'};
8591: if ($requrl eq '') {
8592: $requrl = $ENV{'REQUEST_URI'};
8593: $requrl =~ s/\?.+$//;
8594: }
8595: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8596: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8597: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8598: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8599: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8600: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1340 raeburn 8601: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1352 raeburn 8602: my ($offload,$offloadoth);
1.1210 raeburn 8603: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8604: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1340 raeburn 8605: $offload = 1;
1.1353 raeburn 8606: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8607: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8608: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8609: $offloadoth = 1;
8610: $dom_in_use = $env{'user.domain'};
8611: }
8612: }
1.1340 raeburn 8613: }
8614: }
8615: unless ($offload) {
8616: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8617: if ($domdefs{'offloadoth'}{$lonhost}) {
8618: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8619: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8620: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8621: $offload = 1;
1.1352 raeburn 8622: $offloadoth = 1;
1.1340 raeburn 8623: $dom_in_use = $env{'user.domain'};
8624: }
1.1210 raeburn 8625: }
1.1340 raeburn 8626: }
8627: }
8628: }
8629: if ($offload) {
8630: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
1.1352 raeburn 8631: if (($newserver eq '') && ($offloadoth)) {
8632: my @domains = &Apache::lonnet::current_machine_domains();
8633: if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
8634: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
8635: }
8636: }
1.1340 raeburn 8637: if (($newserver) && ($newserver ne $lonhost)) {
8638: my $numsec = 5;
8639: my $timeout = $numsec * 1000;
8640: my ($newurl,$locknum,%locks,$msg);
8641: if ($env{'request.role.adv'}) {
8642: ($locknum,%locks) = &Apache::lonnet::get_locks();
8643: }
8644: my $disable_submit = 0;
8645: if ($requrl =~ /$LONCAPA::assess_re/) {
8646: $disable_submit = 1;
8647: }
8648: if ($locknum) {
8649: my @lockinfo = sort(values(%locks));
1.1354 raeburn 8650: $msg = &mt('Once the following tasks are complete:')." \n".
1.1340 raeburn 8651: join(", ",sort(values(%locks)))."\n";
8652: if (&show_course()) {
8653: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
8654: } else {
8655: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
1.1210 raeburn 8656: }
1.1340 raeburn 8657: } else {
8658: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8659: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8660: }
8661: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8662: $newurl = '/adm/switchserver?otherserver='.$newserver;
8663: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8664: $newurl .= '&role='.$env{'request.role'};
8665: }
8666: if ($env{'request.symb'}) {
8667: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8668: if ($shownsymb =~ m{^/enc/}) {
8669: my $reqdmajor = 2;
8670: my $reqdminor = 11;
8671: my $reqdsubminor = 3;
8672: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8673: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8674: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8675: if (($major eq '' && $minor eq '') ||
8676: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8677: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8678: ($reqdsubminor > $subminor))))) {
8679: undef($shownsymb);
8680: }
1.1210 raeburn 8681: }
1.1340 raeburn 8682: if ($shownsymb) {
8683: &js_escape(\$shownsymb);
8684: $newurl .= '&symb='.$shownsymb;
1.1210 raeburn 8685: }
1.1340 raeburn 8686: } else {
8687: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8688: &js_escape(\$shownurl);
8689: $newurl .= '&origurl='.$shownurl;
1.1210 raeburn 8690: }
1.1340 raeburn 8691: }
8692: &js_escape(\$msg);
8693: $result.=<<OFFLOAD
1.1210 raeburn 8694: <meta http-equiv="pragma" content="no-cache" />
8695: <script type="text/javascript">
1.1215 raeburn 8696: // <![CDATA[
1.1210 raeburn 8697: function LC_Offload_Now() {
8698: var dest = "$newurl";
8699: if (dest != '') {
8700: window.location.href="$newurl";
8701: }
8702: }
1.1214 raeburn 8703: \$(document).ready(function () {
8704: window.alert('$msg');
8705: if ($disable_submit) {
1.1210 raeburn 8706: \$(".LC_hwk_submit").prop("disabled", true);
8707: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8708: }
8709: setTimeout('LC_Offload_Now()', $timeout);
8710: });
1.1215 raeburn 8711: // ]]>
1.1210 raeburn 8712: </script>
8713: OFFLOAD
8714: }
8715: }
8716: }
8717: }
8718: }
1.313 albertel 8719: }
1.306 albertel 8720: if (!defined($title)) {
8721: $title = 'The LearningOnline Network with CAPA';
8722: }
1.460 albertel 8723: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8724: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8725: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8726: if (!$args->{'frameset'}) {
8727: $result .= ' /';
8728: }
8729: $result .= '>'
1.1064 raeburn 8730: .$inhibitprint
1.414 albertel 8731: .$head_extra;
1.1242 raeburn 8732: my $clientmobile;
8733: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8734: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8735: } else {
8736: $clientmobile = $env{'browser.mobile'};
8737: }
8738: if ($clientmobile) {
1.1137 raeburn 8739: $result .= '
8740: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8741: <meta name="apple-mobile-web-app-capable" content="yes" />';
8742: }
1.1278 raeburn 8743: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8744: return $result.'</head>';
1.306 albertel 8745: }
8746:
8747: =pod
8748:
1.340 albertel 8749: =item * &font_settings()
8750:
8751: Returns neccessary <meta> to set the proper encoding
8752:
1.1160 raeburn 8753: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8754:
8755: =cut
8756:
8757: sub font_settings {
1.1160 raeburn 8758: my ($args) = @_;
1.340 albertel 8759: my $headerstring='';
1.1160 raeburn 8760: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8761: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8762: $headerstring.=
8763: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8764: if (!$args->{'frameset'}) {
8765: $headerstring.= ' /';
8766: }
8767: $headerstring .= '>'."\n";
1.340 albertel 8768: }
8769: return $headerstring;
8770: }
8771:
1.341 albertel 8772: =pod
8773:
1.1064 raeburn 8774: =item * &print_suppression()
8775:
8776: In course context returns css which causes the body to be blank when media="print",
8777: if printout generation is unavailable for the current resource.
8778:
8779: This could be because:
8780:
8781: (a) printstartdate is in the future
8782:
8783: (b) printenddate is in the past
8784:
8785: (c) there is an active exam block with "printout"
8786: functionality blocked
8787:
8788: Users with pav, pfo or evb privileges are exempt.
8789:
8790: Inputs: none
8791:
8792: =cut
8793:
8794:
8795: sub print_suppression {
8796: my $noprint;
8797: if ($env{'request.course.id'}) {
8798: my $scope = $env{'request.course.id'};
8799: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8800: (&Apache::lonnet::allowed('pfo',$scope))) {
8801: return;
8802: }
8803: if ($env{'request.course.sec'} ne '') {
8804: $scope .= "/$env{'request.course.sec'}";
8805: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8806: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8807: return;
1.1064 raeburn 8808: }
8809: }
8810: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8811: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8812: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8813: if ($blocked) {
8814: my $checkrole = "cm./$cdom/$cnum";
8815: if ($env{'request.course.sec'} ne '') {
8816: $checkrole .= "/$env{'request.course.sec'}";
8817: }
8818: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8819: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8820: $noprint = 1;
8821: }
8822: }
8823: unless ($noprint) {
8824: my $symb = &Apache::lonnet::symbread();
8825: if ($symb ne '') {
8826: my $navmap = Apache::lonnavmaps::navmap->new();
8827: if (ref($navmap)) {
8828: my $res = $navmap->getBySymb($symb);
8829: if (ref($res)) {
8830: if (!$res->resprintable()) {
8831: $noprint = 1;
8832: }
8833: }
8834: }
8835: }
8836: }
8837: if ($noprint) {
8838: return <<"ENDSTYLE";
8839: <style type="text/css" media="print">
8840: body { display:none }
8841: </style>
8842: ENDSTYLE
8843: }
8844: }
8845: return;
8846: }
8847:
8848: =pod
8849:
1.341 albertel 8850: =item * &xml_begin()
8851:
8852: Returns the needed doctype and <html>
8853:
8854: Inputs: none
8855:
8856: =cut
8857:
8858: sub xml_begin {
1.1168 raeburn 8859: my ($is_frameset) = @_;
1.341 albertel 8860: my $output='';
8861:
8862: if ($env{'browser.mathml'}) {
8863: $output='<?xml version="1.0"?>'
8864: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8865: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8866:
8867: # .'<!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">] >'
8868: .'<!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">'
8869: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8870: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8871: } elsif ($is_frameset) {
8872: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8873: '<html>'."\n";
1.341 albertel 8874: } else {
1.1168 raeburn 8875: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8876: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8877: }
8878: return $output;
8879: }
1.340 albertel 8880:
8881: =pod
8882:
1.306 albertel 8883: =item * &start_page()
8884:
8885: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8886:
1.648 raeburn 8887: Inputs:
8888:
8889: =over 4
8890:
8891: $title - optional title for the page
8892:
8893: $head_extra - optional extra HTML to incude inside the <head>
8894:
8895: $args - additional optional args supported are:
8896:
8897: =over 8
8898:
8899: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8900: arg on
1.814 bisitz 8901: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8902: add_entries -> additional attributes to add to the <body>
8903: domain -> force to color decorate a page for a
1.317 albertel 8904: specific domain
1.648 raeburn 8905: function -> force usage of a specific rolish color
1.317 albertel 8906: scheme
1.648 raeburn 8907: redirect -> see &headtag()
8908: bgcolor -> override the default page bg color
8909: js_ready -> return a string ready for being used in
1.317 albertel 8910: a javascript writeln
1.648 raeburn 8911: html_encode -> return a string ready for being used in
1.320 albertel 8912: a html attribute
1.648 raeburn 8913: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8914: $forcereg arg
1.648 raeburn 8915: frameset -> if true will start with a <frameset>
1.330 albertel 8916: rather than <body>
1.648 raeburn 8917: skip_phases -> hash ref of
1.338 albertel 8918: head -> skip the <html><head> generation
8919: body -> skip all <body> generation
1.648 raeburn 8920: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8921: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8922: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 8923: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8924: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 8925: group -> includes the current group, if page is for a
1.1274 raeburn 8926: specific group
8927: use_absolute -> for request for external resource or syllabus, this
8928: will contain https://<hostname> if server uses
8929: https (as per hosts.tab), but request is for http
8930: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8931:
1.648 raeburn 8932: =back
1.460 albertel 8933:
1.648 raeburn 8934: =back
1.562 albertel 8935:
1.306 albertel 8936: =cut
8937:
8938: sub start_page {
1.309 albertel 8939: my ($title,$head_extra,$args) = @_;
1.318 albertel 8940: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8941:
1.315 albertel 8942: $env{'internal.start_page'}++;
1.1318 raeburn 8943: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu);
1.964 droeschl 8944:
1.338 albertel 8945: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8946: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8947: }
1.1316 raeburn 8948:
8949: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 8950: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
8951: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
8952: $args->{'no_primary_menu'} = 1;
8953: }
8954: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
8955: $args->{'no_inline_menu'} = 1;
8956: }
8957: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
8958: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
8959: }
8960: } else {
8961: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8962: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
8963: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
8964: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
8965: $args->{'no_primary_menu'} = 1;
8966: }
8967: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
8968: $args->{'no_inline_menu'} = 1;
8969: }
8970: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
8971: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
8972: }
8973: }
8974: }
1.1316 raeburn 8975: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
8976: $env{'course.'.$env{'request.course.id'}.'.domain'},
8977: $env{'course.'.$env{'request.course.id'}.'.num'});
8978: }
1.338 albertel 8979:
8980: if (! exists($args->{'skip_phases'}{'body'}) ) {
8981: if ($args->{'frameset'}) {
8982: my $attr_string = &make_attr_string($args->{'force_register'},
8983: $args->{'add_entries'});
8984: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8985: } else {
8986: $result .=
8987: &bodytag($title,
8988: $args->{'function'}, $args->{'add_entries'},
8989: $args->{'only_body'}, $args->{'domain'},
8990: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8991: $args->{'bgcolor'}, $args,
1.1318 raeburn 8992: \@advtools,$ltiscope,$ltiuri,\%ltimenu);
1.831 bisitz 8993: }
1.330 albertel 8994: }
1.338 albertel 8995:
1.315 albertel 8996: if ($args->{'js_ready'}) {
1.713 kaisler 8997: $result = &js_ready($result);
1.315 albertel 8998: }
1.320 albertel 8999: if ($args->{'html_encode'}) {
1.713 kaisler 9000: $result = &html_encode($result);
9001: }
9002:
1.813 bisitz 9003: # Preparation for new and consistent functionlist at top of screen
9004: # if ($args->{'functionlist'}) {
9005: # $result .= &build_functionlist();
9006: #}
9007:
1.964 droeschl 9008: # Don't add anything more if only_body wanted or in const space
9009: return $result if $args->{'only_body'}
9010: || $env{'request.state'} eq 'construct';
1.813 bisitz 9011:
9012: #Breadcrumbs
1.758 kaisler 9013: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
9014: &Apache::lonhtmlcommon::clear_breadcrumbs();
9015: #if any br links exists, add them to the breadcrumbs
9016: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
9017: foreach my $crumb (@{$args->{'bread_crumbs'}}){
9018: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
9019: }
9020: }
1.1096 raeburn 9021: # if @advtools array contains items add then to the breadcrumbs
9022: if (@advtools > 0) {
9023: &Apache::lonmenu::advtools_crumbs(@advtools);
9024: }
1.1272 raeburn 9025: my $menulink;
9026: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
9027: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 9028: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 9029: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
9030: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
9031: (!$env{'request.role.adv'}))) {
9032: $menulink = 0;
9033: } else {
9034: undef($menulink);
9035: }
1.758 kaisler 9036: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
9037: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 9038: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 9039: } else {
1.1272 raeburn 9040: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 9041: }
1.320 albertel 9042: }
1.315 albertel 9043: return $result;
1.306 albertel 9044: }
9045:
9046: sub end_page {
1.315 albertel 9047: my ($args) = @_;
9048: $env{'internal.end_page'}++;
1.330 albertel 9049: my $result;
1.335 albertel 9050: if ($args->{'discussion'}) {
9051: my ($target,$parser);
9052: if (ref($args->{'discussion'})) {
9053: ($target,$parser) =($args->{'discussion'}{'target'},
9054: $args->{'discussion'}{'parser'});
9055: }
9056: $result .= &Apache::lonxml::xmlend($target,$parser);
9057: }
1.330 albertel 9058: if ($args->{'frameset'}) {
9059: $result .= '</frameset>';
9060: } else {
1.635 raeburn 9061: $result .= &endbodytag($args);
1.330 albertel 9062: }
1.1080 raeburn 9063: unless ($args->{'notbody'}) {
9064: $result .= "\n</html>";
9065: }
1.330 albertel 9066:
1.315 albertel 9067: if ($args->{'js_ready'}) {
1.317 albertel 9068: $result = &js_ready($result);
1.315 albertel 9069: }
1.335 albertel 9070:
1.320 albertel 9071: if ($args->{'html_encode'}) {
9072: $result = &html_encode($result);
9073: }
1.335 albertel 9074:
1.315 albertel 9075: return $result;
9076: }
9077:
1.1034 www 9078: sub wishlist_window {
9079: return(<<'ENDWISHLIST');
1.1046 raeburn 9080: <script type="text/javascript">
1.1034 www 9081: // <![CDATA[
9082: // <!-- BEGIN LON-CAPA Internal
9083: function set_wishlistlink(title, path) {
9084: if (!title) {
9085: title = document.title;
9086: title = title.replace(/^LON-CAPA /,'');
9087: }
1.1175 raeburn 9088: title = encodeURIComponent(title);
1.1203 raeburn 9089: title = title.replace("'","\\\'");
1.1034 www 9090: if (!path) {
9091: path = location.pathname;
9092: }
1.1175 raeburn 9093: path = encodeURIComponent(path);
1.1203 raeburn 9094: path = path.replace("'","\\\'");
1.1034 www 9095: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
9096: 'wishlistNewLink','width=560,height=350,scrollbars=0');
9097: }
9098: // END LON-CAPA Internal -->
9099: // ]]>
9100: </script>
9101: ENDWISHLIST
9102: }
9103:
1.1030 www 9104: sub modal_window {
9105: return(<<'ENDMODAL');
1.1046 raeburn 9106: <script type="text/javascript">
1.1030 www 9107: // <![CDATA[
9108: // <!-- BEGIN LON-CAPA Internal
9109: var modalWindow = {
9110: parent:"body",
9111: windowId:null,
9112: content:null,
9113: width:null,
9114: height:null,
9115: close:function()
9116: {
9117: $(".LCmodal-window").remove();
9118: $(".LCmodal-overlay").remove();
9119: },
9120: open:function()
9121: {
9122: var modal = "";
9123: modal += "<div class=\"LCmodal-overlay\"></div>";
9124: 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;\">";
9125: modal += this.content;
9126: modal += "</div>";
9127:
9128: $(this.parent).append(modal);
9129:
9130: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
9131: $(".LCclose-window").click(function(){modalWindow.close();});
9132: $(".LCmodal-overlay").click(function(){modalWindow.close();});
9133: }
9134: };
1.1140 raeburn 9135: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 9136: {
1.1266 raeburn 9137: source = source.replace(/'/g,"'");
1.1030 www 9138: modalWindow.windowId = "myModal";
9139: modalWindow.width = width;
9140: modalWindow.height = height;
1.1196 raeburn 9141: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9142: modalWindow.open();
1.1208 raeburn 9143: };
1.1030 www 9144: // END LON-CAPA Internal -->
9145: // ]]>
9146: </script>
9147: ENDMODAL
9148: }
9149:
9150: sub modal_link {
1.1140 raeburn 9151: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9152: unless ($width) { $width=480; }
9153: unless ($height) { $height=400; }
1.1031 www 9154: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 9155: unless ($transparency) { $transparency='true'; }
9156:
1.1074 raeburn 9157: my $target_attr;
9158: if (defined($target)) {
9159: $target_attr = 'target="'.$target.'"';
9160: }
9161: return <<"ENDLINK";
1.1336 raeburn 9162: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 9163: ENDLINK
1.1030 www 9164: }
9165:
1.1032 www 9166: sub modal_adhoc_script {
9167: my ($funcname,$width,$height,$content)=@_;
9168: return (<<ENDADHOC);
1.1046 raeburn 9169: <script type="text/javascript">
1.1032 www 9170: // <![CDATA[
9171: var $funcname = function()
9172: {
9173: modalWindow.windowId = "myModal";
9174: modalWindow.width = $width;
9175: modalWindow.height = $height;
9176: modalWindow.content = '$content';
9177: modalWindow.open();
9178: };
9179: // ]]>
9180: </script>
9181: ENDADHOC
9182: }
9183:
1.1041 www 9184: sub modal_adhoc_inner {
9185: my ($funcname,$width,$height,$content)=@_;
9186: my $innerwidth=$width-20;
9187: $content=&js_ready(
1.1140 raeburn 9188: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
9189: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9190: $content.
1.1041 www 9191: &end_scrollbox().
1.1140 raeburn 9192: &end_page()
1.1041 www 9193: );
9194: return &modal_adhoc_script($funcname,$width,$height,$content);
9195: }
9196:
9197: sub modal_adhoc_window {
9198: my ($funcname,$width,$height,$content,$linktext)=@_;
9199: return &modal_adhoc_inner($funcname,$width,$height,$content).
9200: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9201: }
9202:
9203: sub modal_adhoc_launch {
9204: my ($funcname,$width,$height,$content)=@_;
9205: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9206: <script type="text/javascript">
9207: // <![CDATA[
9208: $funcname();
9209: // ]]>
9210: </script>
9211: ENDLAUNCH
9212: }
9213:
9214: sub modal_adhoc_close {
9215: return (<<ENDCLOSE);
9216: <script type="text/javascript">
9217: // <![CDATA[
9218: modalWindow.close();
9219: // ]]>
9220: </script>
9221: ENDCLOSE
9222: }
9223:
1.1038 www 9224: sub togglebox_script {
9225: return(<<ENDTOGGLE);
9226: <script type="text/javascript">
9227: // <![CDATA[
9228: function LCtoggleDisplay(id,hidetext,showtext) {
9229: link = document.getElementById(id + "link").childNodes[0];
9230: with (document.getElementById(id).style) {
9231: if (display == "none" ) {
9232: display = "inline";
9233: link.nodeValue = hidetext;
9234: } else {
9235: display = "none";
9236: link.nodeValue = showtext;
9237: }
9238: }
9239: }
9240: // ]]>
9241: </script>
9242: ENDTOGGLE
9243: }
9244:
1.1039 www 9245: sub start_togglebox {
9246: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9247: unless ($heading) { $heading=''; } else { $heading.=' '; }
9248: unless ($showtext) { $showtext=&mt('show'); }
9249: unless ($hidetext) { $hidetext=&mt('hide'); }
9250: unless ($headerbg) { $headerbg='#FFFFFF'; }
9251: return &start_data_table().
9252: &start_data_table_header_row().
9253: '<td bgcolor="'.$headerbg.'">'.$heading.
9254: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9255: $showtext.'\')">'.$showtext.'</a>]</td>'.
9256: &end_data_table_header_row().
9257: '<tr id="'.$id.'" style="display:none""><td>';
9258: }
9259:
9260: sub end_togglebox {
9261: return '</td></tr>'.&end_data_table();
9262: }
9263:
1.1041 www 9264: sub LCprogressbar_script {
1.1302 raeburn 9265: my ($id,$number_to_do)=@_;
9266: if ($number_to_do) {
9267: return(<<ENDPROGRESS);
1.1041 www 9268: <script type="text/javascript">
9269: // <![CDATA[
1.1045 www 9270: \$('#progressbar$id').progressbar({
1.1041 www 9271: value: 0,
9272: change: function(event, ui) {
9273: var newVal = \$(this).progressbar('option', 'value');
9274: \$('.pblabel', this).text(LCprogressTxt);
9275: }
9276: });
9277: // ]]>
9278: </script>
9279: ENDPROGRESS
1.1302 raeburn 9280: } else {
9281: return(<<ENDPROGRESS);
9282: <script type="text/javascript">
9283: // <![CDATA[
9284: \$('#progressbar$id').progressbar({
9285: value: false,
9286: create: function(event, ui) {
9287: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9288: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9289: }
9290: });
9291: // ]]>
9292: </script>
9293: ENDPROGRESS
9294: }
1.1041 www 9295: }
9296:
9297: sub LCprogressbarUpdate_script {
9298: return(<<ENDPROGRESSUPDATE);
9299: <style type="text/css">
9300: .ui-progressbar { position:relative; }
1.1302 raeburn 9301: .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 9302: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9303: </style>
9304: <script type="text/javascript">
9305: // <![CDATA[
1.1045 www 9306: var LCprogressTxt='---';
9307:
1.1302 raeburn 9308: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9309: LCprogressTxt=progresstext;
1.1302 raeburn 9310: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9311: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9312: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 9313: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9314: } else {
9315: \$('#progressbar'+id).progressbar('value',percent);
9316: }
1.1041 www 9317: }
9318: // ]]>
9319: </script>
9320: ENDPROGRESSUPDATE
9321: }
9322:
1.1042 www 9323: my $LClastpercent;
1.1045 www 9324: my $LCidcnt;
9325: my $LCcurrentid;
1.1042 www 9326:
1.1041 www 9327: sub LCprogressbar {
1.1302 raeburn 9328: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9329: $LClastpercent=0;
1.1045 www 9330: $LCidcnt++;
9331: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 9332: my ($starting,$content);
9333: if ($number_to_do) {
9334: $starting=&mt('Starting');
9335: $content=(<<ENDPROGBAR);
9336: $preamble
1.1045 www 9337: <div id="progressbar$LCcurrentid">
1.1041 www 9338: <span class="pblabel">$starting</span>
9339: </div>
9340: ENDPROGBAR
1.1302 raeburn 9341: } else {
9342: $starting=&mt('Loading...');
9343: $LClastpercent='false';
9344: $content=(<<ENDPROGBAR);
9345: $preamble
9346: <div id="progressbar$LCcurrentid">
9347: <div class="progress-label">$starting</div>
9348: </div>
9349: ENDPROGBAR
9350: }
9351: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9352: }
9353:
9354: sub LCprogressbarUpdate {
1.1302 raeburn 9355: my ($r,$val,$text,$number_to_do)=@_;
9356: if ($number_to_do) {
9357: unless ($val) {
9358: if ($LClastpercent) {
9359: $val=$LClastpercent;
9360: } else {
9361: $val=0;
9362: }
9363: }
9364: if ($val<0) { $val=0; }
9365: if ($val>100) { $val=0; }
9366: $LClastpercent=$val;
9367: unless ($text) { $text=$val.'%'; }
9368: } else {
9369: $val = 'false';
1.1042 www 9370: }
1.1041 www 9371: $text=&js_ready($text);
1.1044 www 9372: &r_print($r,<<ENDUPDATE);
1.1041 www 9373: <script type="text/javascript">
9374: // <![CDATA[
1.1302 raeburn 9375: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9376: // ]]>
9377: </script>
9378: ENDUPDATE
1.1035 www 9379: }
9380:
1.1042 www 9381: sub LCprogressbarClose {
9382: my ($r)=@_;
9383: $LClastpercent=0;
1.1044 www 9384: &r_print($r,<<ENDCLOSE);
1.1042 www 9385: <script type="text/javascript">
9386: // <![CDATA[
1.1045 www 9387: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9388: // ]]>
9389: </script>
9390: ENDCLOSE
1.1044 www 9391: }
9392:
9393: sub r_print {
9394: my ($r,$to_print)=@_;
9395: if ($r) {
9396: $r->print($to_print);
9397: $r->rflush();
9398: } else {
9399: print($to_print);
9400: }
1.1042 www 9401: }
9402:
1.320 albertel 9403: sub html_encode {
9404: my ($result) = @_;
9405:
1.322 albertel 9406: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9407:
9408: return $result;
9409: }
1.1044 www 9410:
1.317 albertel 9411: sub js_ready {
9412: my ($result) = @_;
9413:
1.323 albertel 9414: $result =~ s/[\n\r]/ /xmsg;
9415: $result =~ s/\\/\\\\/xmsg;
9416: $result =~ s/'/\\'/xmsg;
1.372 albertel 9417: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9418:
9419: return $result;
9420: }
9421:
1.315 albertel 9422: sub validate_page {
9423: if ( exists($env{'internal.start_page'})
1.316 albertel 9424: && $env{'internal.start_page'} > 1) {
9425: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9426: $env{'internal.start_page'}.' '.
1.316 albertel 9427: $ENV{'request.filename'});
1.315 albertel 9428: }
9429: if ( exists($env{'internal.end_page'})
1.316 albertel 9430: && $env{'internal.end_page'} > 1) {
9431: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9432: $env{'internal.end_page'}.' '.
1.316 albertel 9433: $env{'request.filename'});
1.315 albertel 9434: }
9435: if ( exists($env{'internal.start_page'})
9436: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9437: &Apache::lonnet::logthis('start_page called without end_page '.
9438: $env{'request.filename'});
1.315 albertel 9439: }
9440: if ( ! exists($env{'internal.start_page'})
9441: && exists($env{'internal.end_page'})) {
1.316 albertel 9442: &Apache::lonnet::logthis('end_page called without start_page'.
9443: $env{'request.filename'});
1.315 albertel 9444: }
1.306 albertel 9445: }
1.315 albertel 9446:
1.996 www 9447:
9448: sub start_scrollbox {
1.1140 raeburn 9449: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9450: unless ($outerwidth) { $outerwidth='520px'; }
9451: unless ($width) { $width='500px'; }
9452: unless ($height) { $height='200px'; }
1.1075 raeburn 9453: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9454: if ($id ne '') {
1.1140 raeburn 9455: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9456: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9457: }
1.1075 raeburn 9458: if ($bgcolor ne '') {
9459: $tdcol = "background-color: $bgcolor;";
9460: }
1.1137 raeburn 9461: my $nicescroll_js;
9462: if ($env{'browser.mobile'}) {
1.1140 raeburn 9463: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9464: }
9465: return <<"END";
9466: $nicescroll_js
9467:
9468: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9469: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9470: END
9471: }
9472:
9473: sub end_scrollbox {
9474: return '</div></td></tr></table>';
9475: }
9476:
9477: sub nicescroll_javascript {
9478: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9479: my %options;
9480: if (ref($cursor) eq 'HASH') {
9481: %options = %{$cursor};
9482: }
9483: unless ($options{'railalign'} =~ /^left|right$/) {
9484: $options{'railalign'} = 'left';
9485: }
9486: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9487: my $function = &get_users_function();
9488: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9489: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9490: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9491: }
1.1140 raeburn 9492: }
9493: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9494: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9495: $options{'cursoropacity'}='1.0';
9496: }
1.1140 raeburn 9497: } else {
9498: $options{'cursoropacity'}='1.0';
9499: }
9500: if ($options{'cursorfixedheight'} eq 'none') {
9501: delete($options{'cursorfixedheight'});
9502: } else {
9503: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9504: }
9505: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9506: delete($options{'railoffset'});
9507: }
9508: my @niceoptions;
9509: while (my($key,$value) = each(%options)) {
9510: if ($value =~ /^\{.+\}$/) {
9511: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9512: } else {
1.1140 raeburn 9513: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9514: }
1.1140 raeburn 9515: }
9516: my $nicescroll_js = '
1.1137 raeburn 9517: $(document).ready(
1.1140 raeburn 9518: function() {
9519: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9520: }
1.1137 raeburn 9521: );
9522: ';
1.1140 raeburn 9523: if ($framecheck) {
9524: $nicescroll_js .= '
9525: function expand_div(caller) {
9526: if (top === self) {
9527: document.getElementById("'.$id.'").style.width = "auto";
9528: document.getElementById("'.$id.'").style.height = "auto";
9529: } else {
9530: try {
9531: if (parent.frames) {
9532: if (parent.frames.length > 1) {
9533: var framesrc = parent.frames[1].location.href;
9534: var currsrc = framesrc.replace(/\#.*$/,"");
9535: if ((caller == "search") || (currsrc == "'.$location.'")) {
9536: document.getElementById("'.$id.'").style.width = "auto";
9537: document.getElementById("'.$id.'").style.height = "auto";
9538: }
9539: }
9540: }
9541: } catch (e) {
9542: return;
9543: }
1.1137 raeburn 9544: }
1.1140 raeburn 9545: return;
1.996 www 9546: }
1.1140 raeburn 9547: ';
9548: }
9549: if ($needjsready) {
9550: $nicescroll_js = '
9551: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9552: } else {
9553: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9554: }
9555: return $nicescroll_js;
1.996 www 9556: }
9557:
1.318 albertel 9558: sub simple_error_page {
1.1150 bisitz 9559: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 9560: my %displayargs;
1.1151 raeburn 9561: if (ref($args) eq 'HASH') {
9562: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 9563: if ($args->{'only_body'}) {
9564: $displayargs{'only_body'} = 1;
9565: }
9566: if ($args->{'no_nav_bar'}) {
9567: $displayargs{'no_nav_bar'} = 1;
9568: }
1.1151 raeburn 9569: } else {
9570: $msg = &mt($msg);
9571: }
1.1150 bisitz 9572:
1.318 albertel 9573: my $page =
1.1304 raeburn 9574: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 9575: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9576: &Apache::loncommon::end_page();
9577: if (ref($r)) {
9578: $r->print($page);
1.327 albertel 9579: return;
1.318 albertel 9580: }
9581: return $page;
9582: }
1.347 albertel 9583:
9584: {
1.610 albertel 9585: my @row_count;
1.961 onken 9586:
9587: sub start_data_table_count {
9588: unshift(@row_count, 0);
9589: return;
9590: }
9591:
9592: sub end_data_table_count {
9593: shift(@row_count);
9594: return;
9595: }
9596:
1.347 albertel 9597: sub start_data_table {
1.1018 raeburn 9598: my ($add_class,$id) = @_;
1.422 albertel 9599: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9600: my $table_id;
9601: if (defined($id)) {
9602: $table_id = ' id="'.$id.'"';
9603: }
1.961 onken 9604: &start_data_table_count();
1.1018 raeburn 9605: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9606: }
9607:
9608: sub end_data_table {
1.961 onken 9609: &end_data_table_count();
1.389 albertel 9610: return '</table>'."\n";;
1.347 albertel 9611: }
9612:
9613: sub start_data_table_row {
1.974 wenzelju 9614: my ($add_class, $id) = @_;
1.610 albertel 9615: $row_count[0]++;
9616: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9617: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9618: $id = (' id="'.$id.'"') unless ($id eq '');
9619: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9620: }
1.471 banghart 9621:
9622: sub continue_data_table_row {
1.974 wenzelju 9623: my ($add_class, $id) = @_;
1.610 albertel 9624: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9625: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9626: $id = (' id="'.$id.'"') unless ($id eq '');
9627: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9628: }
1.347 albertel 9629:
9630: sub end_data_table_row {
1.389 albertel 9631: return '</tr>'."\n";;
1.347 albertel 9632: }
1.367 www 9633:
1.421 albertel 9634: sub start_data_table_empty_row {
1.707 bisitz 9635: # $row_count[0]++;
1.421 albertel 9636: return '<tr class="LC_empty_row" >'."\n";;
9637: }
9638:
9639: sub end_data_table_empty_row {
9640: return '</tr>'."\n";;
9641: }
9642:
1.367 www 9643: sub start_data_table_header_row {
1.389 albertel 9644: return '<tr class="LC_header_row">'."\n";;
1.367 www 9645: }
9646:
9647: sub end_data_table_header_row {
1.389 albertel 9648: return '</tr>'."\n";;
1.367 www 9649: }
1.890 droeschl 9650:
9651: sub data_table_caption {
9652: my $caption = shift;
9653: return "<caption class=\"LC_caption\">$caption</caption>";
9654: }
1.347 albertel 9655: }
9656:
1.548 albertel 9657: =pod
9658:
9659: =item * &inhibit_menu_check($arg)
9660:
9661: Checks for a inhibitmenu state and generates output to preserve it
9662:
9663: Inputs: $arg - can be any of
9664: - undef - in which case the return value is a string
9665: to add into arguments list of a uri
9666: - 'input' - in which case the return value is a HTML
9667: <form> <input> field of type hidden to
9668: preserve the value
9669: - a url - in which case the return value is the url with
9670: the neccesary cgi args added to preserve the
9671: inhibitmenu state
9672: - a ref to a url - no return value, but the string is
9673: updated to include the neccessary cgi
9674: args to preserve the inhibitmenu state
9675:
9676: =cut
9677:
9678: sub inhibit_menu_check {
9679: my ($arg) = @_;
9680: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9681: if ($arg eq 'input') {
9682: if ($env{'form.inhibitmenu'}) {
9683: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9684: } else {
9685: return
9686: }
9687: }
9688: if ($env{'form.inhibitmenu'}) {
9689: if (ref($arg)) {
9690: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9691: } elsif ($arg eq '') {
9692: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9693: } else {
9694: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9695: }
9696: }
9697: if (!ref($arg)) {
9698: return $arg;
9699: }
9700: }
9701:
1.251 albertel 9702: ###############################################
1.182 matthew 9703:
9704: =pod
9705:
1.549 albertel 9706: =back
9707:
9708: =head1 User Information Routines
9709:
9710: =over 4
9711:
1.405 albertel 9712: =item * &get_users_function()
1.182 matthew 9713:
9714: Used by &bodytag to determine the current users primary role.
9715: Returns either 'student','coordinator','admin', or 'author'.
9716:
9717: =cut
9718:
9719: ###############################################
9720: sub get_users_function {
1.815 tempelho 9721: my $function = 'norole';
1.818 tempelho 9722: if ($env{'request.role'}=~/^(st)/) {
9723: $function='student';
9724: }
1.907 raeburn 9725: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9726: $function='coordinator';
9727: }
1.258 albertel 9728: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9729: $function='admin';
9730: }
1.826 bisitz 9731: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9732: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9733: $function='author';
9734: }
9735: return $function;
1.54 www 9736: }
1.99 www 9737:
9738: ###############################################
9739:
1.233 raeburn 9740: =pod
9741:
1.821 raeburn 9742: =item * &show_course()
9743:
9744: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9745: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9746:
9747: Inputs:
9748: None
9749:
9750: Outputs:
9751: Scalar: 1 if 'Course' to be used, 0 otherwise.
9752:
9753: =cut
9754:
9755: ###############################################
9756: sub show_course {
9757: my $course = !$env{'user.adv'};
9758: if (!$env{'user.adv'}) {
9759: foreach my $env (keys(%env)) {
9760: next if ($env !~ m/^user\.priv\./);
9761: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9762: $course = 0;
9763: last;
9764: }
9765: }
9766: }
9767: return $course;
9768: }
9769:
9770: ###############################################
9771:
9772: =pod
9773:
1.542 raeburn 9774: =item * &check_user_status()
1.274 raeburn 9775:
9776: Determines current status of supplied role for a
9777: specific user. Roles can be active, previous or future.
9778:
9779: Inputs:
9780: user's domain, user's username, course's domain,
1.375 raeburn 9781: course's number, optional section ID.
1.274 raeburn 9782:
9783: Outputs:
9784: role status: active, previous or future.
9785:
9786: =cut
9787:
9788: sub check_user_status {
1.412 raeburn 9789: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9790: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9791: my @uroles = keys(%userinfo);
1.274 raeburn 9792: my $srchstr;
9793: my $active_chk = 'none';
1.412 raeburn 9794: my $now = time;
1.274 raeburn 9795: if (@uroles > 0) {
1.908 raeburn 9796: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9797: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9798: } else {
1.412 raeburn 9799: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9800: }
9801: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9802: my $role_end = 0;
9803: my $role_start = 0;
9804: $active_chk = 'active';
1.412 raeburn 9805: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9806: $role_end = $1;
9807: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9808: $role_start = $1;
1.274 raeburn 9809: }
9810: }
9811: if ($role_start > 0) {
1.412 raeburn 9812: if ($now < $role_start) {
1.274 raeburn 9813: $active_chk = 'future';
9814: }
9815: }
9816: if ($role_end > 0) {
1.412 raeburn 9817: if ($now > $role_end) {
1.274 raeburn 9818: $active_chk = 'previous';
9819: }
9820: }
9821: }
9822: }
9823: return $active_chk;
9824: }
9825:
9826: ###############################################
9827:
9828: =pod
9829:
1.405 albertel 9830: =item * &get_sections()
1.233 raeburn 9831:
9832: Determines all the sections for a course including
9833: sections with students and sections containing other roles.
1.419 raeburn 9834: Incoming parameters:
9835:
9836: 1. domain
9837: 2. course number
9838: 3. reference to array containing roles for which sections should
9839: be gathered (optional).
9840: 4. reference to array containing status types for which sections
9841: should be gathered (optional).
9842:
9843: If the third argument is undefined, sections are gathered for any role.
9844: If the fourth argument is undefined, sections are gathered for any status.
9845: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9846:
1.374 raeburn 9847: Returns section hash (keys are section IDs, values are
9848: number of users in each section), subject to the
1.419 raeburn 9849: optional roles filter, optional status filter
1.233 raeburn 9850:
9851: =cut
9852:
9853: ###############################################
9854: sub get_sections {
1.419 raeburn 9855: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9856: if (!defined($cdom) || !defined($cnum)) {
9857: my $cid = $env{'request.course.id'};
9858:
9859: return if (!defined($cid));
9860:
9861: $cdom = $env{'course.'.$cid.'.domain'};
9862: $cnum = $env{'course.'.$cid.'.num'};
9863: }
9864:
9865: my %sectioncount;
1.419 raeburn 9866: my $now = time;
1.240 albertel 9867:
1.1118 raeburn 9868: my $check_students = 1;
9869: my $only_students = 0;
9870: if (ref($possible_roles) eq 'ARRAY') {
9871: if (grep(/^st$/,@{$possible_roles})) {
9872: if (@{$possible_roles} == 1) {
9873: $only_students = 1;
9874: }
9875: } else {
9876: $check_students = 0;
9877: }
9878: }
9879:
9880: if ($check_students) {
1.276 albertel 9881: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9882: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9883: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9884: my $start_index = &Apache::loncoursedata::CL_START();
9885: my $end_index = &Apache::loncoursedata::CL_END();
9886: my $status;
1.366 albertel 9887: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9888: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9889: $data->[$status_index],
9890: $data->[$start_index],
9891: $data->[$end_index]);
9892: if ($stu_status eq 'Active') {
9893: $status = 'active';
9894: } elsif ($end < $now) {
9895: $status = 'previous';
9896: } elsif ($start > $now) {
9897: $status = 'future';
9898: }
9899: if ($section ne '-1' && $section !~ /^\s*$/) {
9900: if ((!defined($possible_status)) || (($status ne '') &&
9901: (grep/^\Q$status\E$/,@{$possible_status}))) {
9902: $sectioncount{$section}++;
9903: }
1.240 albertel 9904: }
9905: }
9906: }
1.1118 raeburn 9907: if ($only_students) {
9908: return %sectioncount;
9909: }
1.240 albertel 9910: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9911: foreach my $user (sort(keys(%courseroles))) {
9912: if ($user !~ /^(\w{2})/) { next; }
9913: my ($role) = ($user =~ /^(\w{2})/);
9914: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9915: my ($section,$status);
1.240 albertel 9916: if ($role eq 'cr' &&
9917: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9918: $section=$1;
9919: }
9920: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9921: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9922: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9923: if ($end == -1 && $start == -1) {
9924: next; #deleted role
9925: }
9926: if (!defined($possible_status)) {
9927: $sectioncount{$section}++;
9928: } else {
9929: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9930: $status = 'active';
9931: } elsif ($end < $now) {
9932: $status = 'future';
9933: } elsif ($start > $now) {
9934: $status = 'previous';
9935: }
9936: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9937: $sectioncount{$section}++;
9938: }
9939: }
1.233 raeburn 9940: }
1.366 albertel 9941: return %sectioncount;
1.233 raeburn 9942: }
9943:
1.274 raeburn 9944: ###############################################
1.294 raeburn 9945:
9946: =pod
1.405 albertel 9947:
9948: =item * &get_course_users()
9949:
1.275 raeburn 9950: Retrieves usernames:domains for users in the specified course
9951: with specific role(s), and access status.
9952:
9953: Incoming parameters:
1.277 albertel 9954: 1. course domain
9955: 2. course number
9956: 3. access status: users must have - either active,
1.275 raeburn 9957: previous, future, or all.
1.277 albertel 9958: 4. reference to array of permissible roles
1.288 raeburn 9959: 5. reference to array of section restrictions (optional)
9960: 6. reference to results object (hash of hashes).
9961: 7. reference to optional userdata hash
1.609 raeburn 9962: 8. reference to optional statushash
1.630 raeburn 9963: 9. flag if privileged users (except those set to unhide in
9964: course settings) should be excluded
1.609 raeburn 9965: Keys of top level results hash are roles.
1.275 raeburn 9966: Keys of inner hashes are username:domain, with
9967: values set to access type.
1.288 raeburn 9968: Optional userdata hash returns an array with arguments in the
9969: same order as loncoursedata::get_classlist() for student data.
9970:
1.609 raeburn 9971: Optional statushash returns
9972:
1.288 raeburn 9973: Entries for end, start, section and status are blank because
9974: of the possibility of multiple values for non-student roles.
9975:
1.275 raeburn 9976: =cut
1.405 albertel 9977:
1.275 raeburn 9978: ###############################################
1.405 albertel 9979:
1.275 raeburn 9980: sub get_course_users {
1.630 raeburn 9981: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9982: my %idx = ();
1.419 raeburn 9983: my %seclists;
1.288 raeburn 9984:
9985: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9986: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9987: $idx{end} = &Apache::loncoursedata::CL_END();
9988: $idx{start} = &Apache::loncoursedata::CL_START();
9989: $idx{id} = &Apache::loncoursedata::CL_ID();
9990: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9991: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9992: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9993:
1.290 albertel 9994: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9995: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9996: my $now = time;
1.277 albertel 9997: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9998: my $match = 0;
1.412 raeburn 9999: my $secmatch = 0;
1.419 raeburn 10000: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 10001: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 10002: if ($section eq '') {
10003: $section = 'none';
10004: }
1.291 albertel 10005: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10006: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10007: $secmatch = 1;
10008: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 10009: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10010: $secmatch = 1;
10011: }
10012: } else {
1.419 raeburn 10013: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 10014: $secmatch = 1;
10015: }
1.290 albertel 10016: }
1.412 raeburn 10017: if (!$secmatch) {
10018: next;
10019: }
1.419 raeburn 10020: }
1.275 raeburn 10021: if (defined($$types{'active'})) {
1.288 raeburn 10022: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 10023: push(@{$$users{st}{$student}},'active');
1.288 raeburn 10024: $match = 1;
1.275 raeburn 10025: }
10026: }
10027: if (defined($$types{'previous'})) {
1.609 raeburn 10028: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 10029: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 10030: $match = 1;
1.275 raeburn 10031: }
10032: }
10033: if (defined($$types{'future'})) {
1.609 raeburn 10034: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 10035: push(@{$$users{st}{$student}},'future');
1.288 raeburn 10036: $match = 1;
1.275 raeburn 10037: }
10038: }
1.609 raeburn 10039: if ($match) {
10040: push(@{$seclists{$student}},$section);
10041: if (ref($userdata) eq 'HASH') {
10042: $$userdata{$student} = $$classlist{$student};
10043: }
10044: if (ref($statushash) eq 'HASH') {
10045: $statushash->{$student}{'st'}{$section} = $status;
10046: }
1.288 raeburn 10047: }
1.275 raeburn 10048: }
10049: }
1.412 raeburn 10050: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 10051: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10052: my $now = time;
1.609 raeburn 10053: my %displaystatus = ( previous => 'Expired',
10054: active => 'Active',
10055: future => 'Future',
10056: );
1.1121 raeburn 10057: my (%nothide,@possdoms);
1.630 raeburn 10058: if ($hidepriv) {
10059: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
10060: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
10061: if ($user !~ /:/) {
10062: $nothide{join(':',split(/[\@]/,$user))}=1;
10063: } else {
10064: $nothide{$user} = 1;
10065: }
10066: }
1.1121 raeburn 10067: my @possdoms = ($cdom);
10068: if ($coursehash{'checkforpriv'}) {
10069: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
10070: }
1.630 raeburn 10071: }
1.439 raeburn 10072: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 10073: my $match = 0;
1.412 raeburn 10074: my $secmatch = 0;
1.439 raeburn 10075: my $status;
1.412 raeburn 10076: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 10077: $user =~ s/:$//;
1.439 raeburn 10078: my ($end,$start) = split(/:/,$coursepersonnel{$person});
10079: if ($end == -1 || $start == -1) {
10080: next;
10081: }
10082: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
10083: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 10084: my ($uname,$udom) = split(/:/,$user);
10085: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10086: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10087: $secmatch = 1;
10088: } elsif ($usec eq '') {
1.420 albertel 10089: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10090: $secmatch = 1;
10091: }
10092: } else {
10093: if (grep(/^\Q$usec\E$/,@{$sections})) {
10094: $secmatch = 1;
10095: }
10096: }
10097: if (!$secmatch) {
10098: next;
10099: }
1.288 raeburn 10100: }
1.419 raeburn 10101: if ($usec eq '') {
10102: $usec = 'none';
10103: }
1.275 raeburn 10104: if ($uname ne '' && $udom ne '') {
1.630 raeburn 10105: if ($hidepriv) {
1.1121 raeburn 10106: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 10107: (!$nothide{$uname.':'.$udom})) {
10108: next;
10109: }
10110: }
1.503 raeburn 10111: if ($end > 0 && $end < $now) {
1.439 raeburn 10112: $status = 'previous';
10113: } elsif ($start > $now) {
10114: $status = 'future';
10115: } else {
10116: $status = 'active';
10117: }
1.277 albertel 10118: foreach my $type (keys(%{$types})) {
1.275 raeburn 10119: if ($status eq $type) {
1.420 albertel 10120: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 10121: push(@{$$users{$role}{$user}},$type);
10122: }
1.288 raeburn 10123: $match = 1;
10124: }
10125: }
1.419 raeburn 10126: if (($match) && (ref($userdata) eq 'HASH')) {
10127: if (!exists($$userdata{$uname.':'.$udom})) {
10128: &get_user_info($udom,$uname,\%idx,$userdata);
10129: }
1.420 albertel 10130: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 10131: push(@{$seclists{$uname.':'.$udom}},$usec);
10132: }
1.609 raeburn 10133: if (ref($statushash) eq 'HASH') {
10134: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
10135: }
1.275 raeburn 10136: }
10137: }
10138: }
10139: }
1.290 albertel 10140: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10141: if ((defined($cdom)) && (defined($cnum))) {
10142: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10143: if ( defined($csettings{'internal.courseowner'}) ) {
10144: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10145: next if ($owner eq '');
10146: my ($ownername,$ownerdom);
10147: if ($owner =~ /^([^:]+):([^:]+)$/) {
10148: $ownername = $1;
10149: $ownerdom = $2;
10150: } else {
10151: $ownername = $owner;
10152: $ownerdom = $cdom;
10153: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10154: }
10155: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10156: if (defined($userdata) &&
1.609 raeburn 10157: !exists($$userdata{$owner})) {
10158: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10159: if (!grep(/^none$/,@{$seclists{$owner}})) {
10160: push(@{$seclists{$owner}},'none');
10161: }
10162: if (ref($statushash) eq 'HASH') {
10163: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10164: }
1.290 albertel 10165: }
1.279 raeburn 10166: }
10167: }
10168: }
1.419 raeburn 10169: foreach my $user (keys(%seclists)) {
10170: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10171: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10172: }
1.275 raeburn 10173: }
10174: return;
10175: }
10176:
1.288 raeburn 10177: sub get_user_info {
10178: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10179: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10180: &plainname($uname,$udom,'lastname');
1.291 albertel 10181: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10182: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10183: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10184: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10185: return;
10186: }
1.275 raeburn 10187:
1.472 raeburn 10188: ###############################################
10189:
10190: =pod
10191:
10192: =item * &get_user_quota()
10193:
1.1134 raeburn 10194: Retrieves quota assigned for storage of user files.
10195: Default is to report quota for portfolio files.
1.472 raeburn 10196:
10197: Incoming parameters:
10198: 1. user's username
10199: 2. user's domain
1.1134 raeburn 10200: 3. quota name - portfolio, author, or course
1.1136 raeburn 10201: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 10202: 4. crstype - official, unofficial, textbook, placement or community,
10203: if quota name is course
1.472 raeburn 10204:
10205: Returns:
1.1163 raeburn 10206: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10207: 2. (Optional) Type of setting: custom or default
10208: (individually assigned or default for user's
10209: institutional status).
10210: 3. (Optional) - User's institutional status (e.g., faculty, staff
10211: or student - types as defined in localenroll::inst_usertypes
10212: for user's domain, which determines default quota for user.
10213: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10214:
10215: If a value has been stored in the user's environment,
1.536 raeburn 10216: it will return that, otherwise it returns the maximal default
1.1134 raeburn 10217: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10218:
10219: =cut
10220:
10221: ###############################################
10222:
10223:
10224: sub get_user_quota {
1.1136 raeburn 10225: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10226: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10227: if (!defined($udom)) {
10228: $udom = $env{'user.domain'};
10229: }
10230: if (!defined($uname)) {
10231: $uname = $env{'user.name'};
10232: }
10233: if (($udom eq '' || $uname eq '') ||
10234: ($udom eq 'public') && ($uname eq 'public')) {
10235: $quota = 0;
1.536 raeburn 10236: $quotatype = 'default';
10237: $defquota = 0;
1.472 raeburn 10238: } else {
1.536 raeburn 10239: my $inststatus;
1.1134 raeburn 10240: if ($quotaname eq 'course') {
10241: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10242: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10243: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10244: } else {
10245: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10246: $quota = $cenv{'internal.uploadquota'};
10247: }
1.536 raeburn 10248: } else {
1.1134 raeburn 10249: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10250: if ($quotaname eq 'author') {
10251: $quota = $env{'environment.authorquota'};
10252: } else {
10253: $quota = $env{'environment.portfolioquota'};
10254: }
10255: $inststatus = $env{'environment.inststatus'};
10256: } else {
10257: my %userenv =
10258: &Apache::lonnet::get('environment',['portfolioquota',
10259: 'authorquota','inststatus'],$udom,$uname);
10260: my ($tmp) = keys(%userenv);
10261: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10262: if ($quotaname eq 'author') {
10263: $quota = $userenv{'authorquota'};
10264: } else {
10265: $quota = $userenv{'portfolioquota'};
10266: }
10267: $inststatus = $userenv{'inststatus'};
10268: } else {
10269: undef(%userenv);
10270: }
10271: }
10272: }
10273: if ($quota eq '' || wantarray) {
10274: if ($quotaname eq 'course') {
10275: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 10276: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 10277: ($crstype eq 'community') || ($crstype eq 'textbook') ||
10278: ($crstype eq 'placement')) {
1.1136 raeburn 10279: $defquota = $domdefs{$crstype.'quota'};
10280: }
10281: if ($defquota eq '') {
10282: $defquota = 500;
10283: }
1.1134 raeburn 10284: } else {
10285: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10286: }
10287: if ($quota eq '') {
10288: $quota = $defquota;
10289: $quotatype = 'default';
10290: } else {
10291: $quotatype = 'custom';
10292: }
1.472 raeburn 10293: }
10294: }
1.536 raeburn 10295: if (wantarray) {
10296: return ($quota,$quotatype,$settingstatus,$defquota);
10297: } else {
10298: return $quota;
10299: }
1.472 raeburn 10300: }
10301:
10302: ###############################################
10303:
10304: =pod
10305:
10306: =item * &default_quota()
10307:
1.536 raeburn 10308: Retrieves default quota assigned for storage of user portfolio files,
10309: given an (optional) user's institutional status.
1.472 raeburn 10310:
10311: Incoming parameters:
1.1142 raeburn 10312:
1.472 raeburn 10313: 1. domain
1.536 raeburn 10314: 2. (Optional) institutional status(es). This is a : separated list of
10315: status types (e.g., faculty, staff, student etc.)
10316: which apply to the user for whom the default is being retrieved.
10317: If the institutional status string in undefined, the domain
1.1134 raeburn 10318: default quota will be returned.
10319: 3. quota name - portfolio, author, or course
10320: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10321:
10322: Returns:
1.1142 raeburn 10323:
1.1163 raeburn 10324: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10325: 2. (Optional) institutional type which determined the value of the
10326: default quota.
1.472 raeburn 10327:
10328: If a value has been stored in the domain's configuration db,
10329: it will return that, otherwise it returns 20 (for backwards
10330: compatibility with domains which have not set up a configuration
1.1163 raeburn 10331: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10332:
1.536 raeburn 10333: If the user's status includes multiple types (e.g., staff and student),
10334: the largest default quota which applies to the user determines the
10335: default quota returned.
10336:
1.472 raeburn 10337: =cut
10338:
10339: ###############################################
10340:
10341:
10342: sub default_quota {
1.1134 raeburn 10343: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10344: my ($defquota,$settingstatus);
10345: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10346: ['quotas'],$udom);
1.1134 raeburn 10347: my $key = 'defaultquota';
10348: if ($quotaname eq 'author') {
10349: $key = 'authorquota';
10350: }
1.622 raeburn 10351: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10352: if ($inststatus ne '') {
1.765 raeburn 10353: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10354: foreach my $item (@statuses) {
1.1134 raeburn 10355: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10356: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10357: if ($defquota eq '') {
1.1134 raeburn 10358: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10359: $settingstatus = $item;
1.1134 raeburn 10360: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10361: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10362: $settingstatus = $item;
10363: }
10364: }
1.1134 raeburn 10365: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10366: if ($quotahash{'quotas'}{$item} ne '') {
10367: if ($defquota eq '') {
10368: $defquota = $quotahash{'quotas'}{$item};
10369: $settingstatus = $item;
10370: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10371: $defquota = $quotahash{'quotas'}{$item};
10372: $settingstatus = $item;
10373: }
1.536 raeburn 10374: }
10375: }
10376: }
10377: }
10378: if ($defquota eq '') {
1.1134 raeburn 10379: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10380: $defquota = $quotahash{'quotas'}{$key}{'default'};
10381: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10382: $defquota = $quotahash{'quotas'}{'default'};
10383: }
1.536 raeburn 10384: $settingstatus = 'default';
1.1139 raeburn 10385: if ($defquota eq '') {
10386: if ($quotaname eq 'author') {
10387: $defquota = 500;
10388: }
10389: }
1.536 raeburn 10390: }
10391: } else {
10392: $settingstatus = 'default';
1.1134 raeburn 10393: if ($quotaname eq 'author') {
10394: $defquota = 500;
10395: } else {
10396: $defquota = 20;
10397: }
1.536 raeburn 10398: }
10399: if (wantarray) {
10400: return ($defquota,$settingstatus);
1.472 raeburn 10401: } else {
1.536 raeburn 10402: return $defquota;
1.472 raeburn 10403: }
10404: }
10405:
1.1135 raeburn 10406: ###############################################
10407:
10408: =pod
10409:
1.1136 raeburn 10410: =item * &excess_filesize_warning()
1.1135 raeburn 10411:
10412: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 10413: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 10414: space to be exceeded.
1.1136 raeburn 10415:
10416: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 10417: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 10418:
1.1165 raeburn 10419: Inputs: 7
1.1136 raeburn 10420: 1. username or coursenum
1.1135 raeburn 10421: 2. domain
1.1136 raeburn 10422: 3. context ('author' or 'course')
1.1135 raeburn 10423: 4. filename of file for which action is being requested
10424: 5. filesize (kB) of file
10425: 6. action being taken: copy or upload.
1.1237 raeburn 10426: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 10427:
10428: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 10429: otherwise return null.
10430:
10431: =back
1.1135 raeburn 10432:
10433: =cut
10434:
1.1136 raeburn 10435: sub excess_filesize_warning {
1.1165 raeburn 10436: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 10437: my $current_disk_usage = 0;
1.1165 raeburn 10438: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 10439: if ($context eq 'author') {
10440: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10441: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10442: } else {
10443: foreach my $subdir ('docs','supplemental') {
10444: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10445: }
10446: }
1.1135 raeburn 10447: $disk_quota = int($disk_quota * 1000);
10448: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 10449: return '<p class="LC_warning">'.
1.1135 raeburn 10450: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 10451: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10452: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 10453: $disk_quota,$current_disk_usage).
10454: '</p>';
10455: }
10456: return;
10457: }
10458:
10459: ###############################################
10460:
10461:
1.1136 raeburn 10462:
10463:
1.384 raeburn 10464: sub get_secgrprole_info {
10465: my ($cdom,$cnum,$needroles,$type) = @_;
10466: my %sections_count = &get_sections($cdom,$cnum);
10467: my @sections = (sort {$a <=> $b} keys(%sections_count));
10468: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10469: my @groups = sort(keys(%curr_groups));
10470: my $allroles = [];
10471: my $rolehash;
10472: my $accesshash = {
10473: active => 'Currently has access',
10474: future => 'Will have future access',
10475: previous => 'Previously had access',
10476: };
10477: if ($needroles) {
10478: $rolehash = {'all' => 'all'};
1.385 albertel 10479: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10480: if (&Apache::lonnet::error(%user_roles)) {
10481: undef(%user_roles);
10482: }
10483: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10484: my ($role)=split(/\:/,$item,2);
10485: if ($role eq 'cr') { next; }
10486: if ($role =~ /^cr/) {
10487: $$rolehash{$role} = (split('/',$role))[3];
10488: } else {
10489: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10490: }
10491: }
10492: foreach my $key (sort(keys(%{$rolehash}))) {
10493: push(@{$allroles},$key);
10494: }
10495: push (@{$allroles},'st');
10496: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10497: }
10498: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10499: }
10500:
1.555 raeburn 10501: sub user_picker {
1.1279 raeburn 10502: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10503: my $currdom = $dom;
1.1253 raeburn 10504: my @alldoms = &Apache::lonnet::all_domains();
10505: if (@alldoms == 1) {
10506: my %domsrch = &Apache::lonnet::get_dom('configuration',
10507: ['directorysrch'],$alldoms[0]);
10508: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10509: my $showdom = $domdesc;
10510: if ($showdom eq '') {
10511: $showdom = $dom;
10512: }
10513: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10514: if ((!$domsrch{'directorysrch'}{'available'}) &&
10515: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10516: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10517: }
10518: }
10519: }
1.555 raeburn 10520: my %curr_selected = (
10521: srchin => 'dom',
1.580 raeburn 10522: srchby => 'lastname',
1.555 raeburn 10523: );
10524: my $srchterm;
1.625 raeburn 10525: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10526: if ($srch->{'srchby'} ne '') {
10527: $curr_selected{'srchby'} = $srch->{'srchby'};
10528: }
10529: if ($srch->{'srchin'} ne '') {
10530: $curr_selected{'srchin'} = $srch->{'srchin'};
10531: }
10532: if ($srch->{'srchtype'} ne '') {
10533: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10534: }
10535: if ($srch->{'srchdomain'} ne '') {
10536: $currdom = $srch->{'srchdomain'};
10537: }
10538: $srchterm = $srch->{'srchterm'};
10539: }
1.1222 damieng 10540: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10541: 'usr' => 'Search criteria',
1.563 raeburn 10542: 'doma' => 'Domain/institution to search',
1.558 albertel 10543: 'uname' => 'username',
10544: 'lastname' => 'last name',
1.555 raeburn 10545: 'lastfirst' => 'last name, first name',
1.558 albertel 10546: 'crs' => 'in this course',
1.576 raeburn 10547: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10548: 'alc' => 'all LON-CAPA',
1.573 raeburn 10549: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10550: 'exact' => 'is',
10551: 'contains' => 'contains',
1.569 raeburn 10552: 'begins' => 'begins with',
1.1222 damieng 10553: );
10554: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10555: 'youm' => "You must include some text to search for.",
10556: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10557: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10558: 'yomc' => "You must choose a domain when using an institutional directory search.",
10559: 'ymcd' => "You must choose a domain when using a domain search.",
10560: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10561: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10562: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10563: );
1.1222 damieng 10564: &html_escape(\%html_lt);
10565: &js_escape(\%js_lt);
1.1255 raeburn 10566: my $domform;
1.1277 raeburn 10567: my $allow_blank = 1;
1.1255 raeburn 10568: if ($fixeddom) {
1.1277 raeburn 10569: $allow_blank = 0;
10570: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 10571: } else {
1.1287 raeburn 10572: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 10573: my ($trusted,$untrusted);
1.1287 raeburn 10574: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 10575: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 10576: } elsif ($context eq 'author') {
1.1288 raeburn 10577: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 10578: } elsif ($context eq 'domain') {
1.1288 raeburn 10579: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 10580: }
1.1288 raeburn 10581: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 10582: }
1.563 raeburn 10583: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10584:
10585: my @srchins = ('crs','dom','alc','instd');
10586:
10587: foreach my $option (@srchins) {
10588: # FIXME 'alc' option unavailable until
10589: # loncreateuser::print_user_query_page()
10590: # has been completed.
10591: next if ($option eq 'alc');
1.880 raeburn 10592: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10593: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 10594: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10595: if ($curr_selected{'srchin'} eq $option) {
10596: $srchinsel .= '
1.1222 damieng 10597: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10598: } else {
10599: $srchinsel .= '
1.1222 damieng 10600: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10601: }
1.555 raeburn 10602: }
1.563 raeburn 10603: $srchinsel .= "\n </select>\n";
1.555 raeburn 10604:
10605: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10606: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10607: if ($curr_selected{'srchby'} eq $option) {
10608: $srchbysel .= '
1.1222 damieng 10609: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10610: } else {
10611: $srchbysel .= '
1.1222 damieng 10612: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10613: }
10614: }
10615: $srchbysel .= "\n </select>\n";
10616:
10617: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10618: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10619: if ($curr_selected{'srchtype'} eq $option) {
10620: $srchtypesel .= '
1.1222 damieng 10621: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10622: } else {
10623: $srchtypesel .= '
1.1222 damieng 10624: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10625: }
10626: }
10627: $srchtypesel .= "\n </select>\n";
10628:
1.558 albertel 10629: my ($newuserscript,$new_user_create);
1.994 raeburn 10630: my $context_dom = $env{'request.role.domain'};
10631: if ($context eq 'requestcrs') {
10632: if ($env{'form.coursedom'} ne '') {
10633: $context_dom = $env{'form.coursedom'};
10634: }
10635: }
1.556 raeburn 10636: if ($forcenewuser) {
1.576 raeburn 10637: if (ref($srch) eq 'HASH') {
1.994 raeburn 10638: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10639: if ($cancreate) {
10640: $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>';
10641: } else {
1.799 bisitz 10642: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10643: my %usertypetext = (
10644: official => 'institutional',
10645: unofficial => 'non-institutional',
10646: );
1.799 bisitz 10647: $new_user_create = '<p class="LC_warning">'
10648: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10649: .' '
10650: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10651: ,'<a href="'.$helplink.'">','</a>')
10652: .'</p><br />';
1.627 raeburn 10653: }
1.576 raeburn 10654: }
10655: }
10656:
1.556 raeburn 10657: $newuserscript = <<"ENDSCRIPT";
10658:
1.570 raeburn 10659: function setSearch(createnew,callingForm) {
1.556 raeburn 10660: if (createnew == 1) {
1.570 raeburn 10661: for (var i=0; i<callingForm.srchby.length; i++) {
10662: if (callingForm.srchby.options[i].value == 'uname') {
10663: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10664: }
10665: }
1.570 raeburn 10666: for (var i=0; i<callingForm.srchin.length; i++) {
10667: if ( callingForm.srchin.options[i].value == 'dom') {
10668: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10669: }
10670: }
1.570 raeburn 10671: for (var i=0; i<callingForm.srchtype.length; i++) {
10672: if (callingForm.srchtype.options[i].value == 'exact') {
10673: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10674: }
10675: }
1.570 raeburn 10676: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10677: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10678: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10679: }
10680: }
10681: }
10682: }
10683: ENDSCRIPT
1.558 albertel 10684:
1.556 raeburn 10685: }
10686:
1.555 raeburn 10687: my $output = <<"END_BLOCK";
1.556 raeburn 10688: <script type="text/javascript">
1.824 bisitz 10689: // <![CDATA[
1.570 raeburn 10690: function validateEntry(callingForm) {
1.558 albertel 10691:
1.556 raeburn 10692: var checkok = 1;
1.558 albertel 10693: var srchin;
1.570 raeburn 10694: for (var i=0; i<callingForm.srchin.length; i++) {
10695: if ( callingForm.srchin[i].checked ) {
10696: srchin = callingForm.srchin[i].value;
1.558 albertel 10697: }
10698: }
10699:
1.570 raeburn 10700: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10701: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10702: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10703: var srchterm = callingForm.srchterm.value;
10704: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10705: var msg = "";
10706:
10707: if (srchterm == "") {
10708: checkok = 0;
1.1222 damieng 10709: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10710: }
10711:
1.569 raeburn 10712: if (srchtype== 'begins') {
10713: if (srchterm.length < 2) {
10714: checkok = 0;
1.1222 damieng 10715: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10716: }
10717: }
10718:
1.556 raeburn 10719: if (srchtype== 'contains') {
10720: if (srchterm.length < 3) {
10721: checkok = 0;
1.1222 damieng 10722: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10723: }
10724: }
10725: if (srchin == 'instd') {
10726: if (srchdomain == '') {
10727: checkok = 0;
1.1222 damieng 10728: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10729: }
10730: }
10731: if (srchin == 'dom') {
10732: if (srchdomain == '') {
10733: checkok = 0;
1.1222 damieng 10734: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10735: }
10736: }
10737: if (srchby == 'lastfirst') {
10738: if (srchterm.indexOf(",") == -1) {
10739: checkok = 0;
1.1222 damieng 10740: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10741: }
10742: if (srchterm.indexOf(",") == srchterm.length -1) {
10743: checkok = 0;
1.1222 damieng 10744: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10745: }
10746: }
10747: if (checkok == 0) {
1.1222 damieng 10748: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10749: return;
10750: }
10751: if (checkok == 1) {
1.570 raeburn 10752: callingForm.submit();
1.556 raeburn 10753: }
10754: }
10755:
10756: $newuserscript
10757:
1.824 bisitz 10758: // ]]>
1.556 raeburn 10759: </script>
1.558 albertel 10760:
10761: $new_user_create
10762:
1.555 raeburn 10763: END_BLOCK
1.558 albertel 10764:
1.876 raeburn 10765: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10766: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10767: $domform.
10768: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10769: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10770: $srchbysel.
10771: $srchtypesel.
10772: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10773: $srchinsel.
10774: &Apache::lonhtmlcommon::row_closure(1).
10775: &Apache::lonhtmlcommon::end_pick_box().
10776: '<br />';
1.1253 raeburn 10777: return ($output,1);
1.555 raeburn 10778: }
10779:
1.612 raeburn 10780: sub user_rule_check {
1.615 raeburn 10781: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10782: my ($response,%inst_response);
1.612 raeburn 10783: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10784: if (keys(%{$usershash}) > 1) {
10785: my (%by_username,%by_id,%userdoms);
10786: my $checkid;
10787: if (ref($checks) eq 'HASH') {
10788: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10789: $checkid = 1;
10790: }
10791: }
10792: foreach my $user (keys(%{$usershash})) {
10793: my ($uname,$udom) = split(/:/,$user);
10794: if ($checkid) {
10795: if (ref($usershash->{$user}) eq 'HASH') {
10796: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10797: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10798: $userdoms{$udom} = 1;
1.1227 raeburn 10799: if (ref($inst_results) eq 'HASH') {
10800: $inst_results->{$uname.':'.$udom} = {};
10801: }
1.1226 raeburn 10802: }
10803: }
10804: } else {
10805: $by_username{$udom}{$uname} = 1;
10806: $userdoms{$udom} = 1;
1.1227 raeburn 10807: if (ref($inst_results) eq 'HASH') {
10808: $inst_results->{$uname.':'.$udom} = {};
10809: }
1.1226 raeburn 10810: }
10811: }
10812: foreach my $udom (keys(%userdoms)) {
10813: if (!$got_rules->{$udom}) {
10814: my %domconfig = &Apache::lonnet::get_dom('configuration',
10815: ['usercreation'],$udom);
10816: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10817: foreach my $item ('username','id') {
10818: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10819: $$curr_rules{$udom}{$item} =
10820: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10821: }
10822: }
10823: }
10824: $got_rules->{$udom} = 1;
10825: }
1.612 raeburn 10826: }
1.1226 raeburn 10827: if ($checkid) {
10828: foreach my $udom (keys(%by_id)) {
10829: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10830: if ($outcome eq 'ok') {
1.1227 raeburn 10831: foreach my $id (keys(%{$by_id{$udom}})) {
10832: my $uname = $by_id{$udom}{$id};
10833: $inst_response{$uname.':'.$udom} = $outcome;
10834: }
1.1226 raeburn 10835: if (ref($results) eq 'HASH') {
10836: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10837: if (exists($inst_response{$uname.':'.$udom})) {
10838: $inst_response{$uname.':'.$udom} = $outcome;
10839: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10840: }
1.1226 raeburn 10841: }
10842: }
10843: }
1.612 raeburn 10844: }
1.615 raeburn 10845: } else {
1.1226 raeburn 10846: foreach my $udom (keys(%by_username)) {
10847: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10848: if ($outcome eq 'ok') {
1.1227 raeburn 10849: foreach my $uname (keys(%{$by_username{$udom}})) {
10850: $inst_response{$uname.':'.$udom} = $outcome;
10851: }
1.1226 raeburn 10852: if (ref($results) eq 'HASH') {
10853: foreach my $uname (keys(%{$results})) {
10854: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10855: }
10856: }
10857: }
10858: }
1.612 raeburn 10859: }
1.1226 raeburn 10860: } elsif (keys(%{$usershash}) == 1) {
10861: my $user = (keys(%{$usershash}))[0];
10862: my ($uname,$udom) = split(/:/,$user);
10863: if (($udom ne '') && ($uname ne '')) {
10864: if (ref($usershash->{$user}) eq 'HASH') {
10865: if (ref($checks) eq 'HASH') {
10866: if (defined($checks->{'username'})) {
10867: ($inst_response{$user},%{$inst_results->{$user}}) =
10868: &Apache::lonnet::get_instuser($udom,$uname);
10869: } elsif (defined($checks->{'id'})) {
10870: if ($usershash->{$user}->{'id'} ne '') {
10871: ($inst_response{$user},%{$inst_results->{$user}}) =
10872: &Apache::lonnet::get_instuser($udom,undef,
10873: $usershash->{$user}->{'id'});
10874: } else {
10875: ($inst_response{$user},%{$inst_results->{$user}}) =
10876: &Apache::lonnet::get_instuser($udom,$uname);
10877: }
1.585 raeburn 10878: }
1.1226 raeburn 10879: } else {
10880: ($inst_response{$user},%{$inst_results->{$user}}) =
10881: &Apache::lonnet::get_instuser($udom,$uname);
10882: return;
10883: }
10884: if (!$got_rules->{$udom}) {
10885: my %domconfig = &Apache::lonnet::get_dom('configuration',
10886: ['usercreation'],$udom);
10887: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10888: foreach my $item ('username','id') {
10889: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10890: $$curr_rules{$udom}{$item} =
10891: $domconfig{'usercreation'}{$item.'_rule'};
10892: }
10893: }
10894: }
10895: $got_rules->{$udom} = 1;
1.585 raeburn 10896: }
10897: }
1.1226 raeburn 10898: } else {
10899: return;
10900: }
10901: } else {
10902: return;
10903: }
10904: foreach my $user (keys(%{$usershash})) {
10905: my ($uname,$udom) = split(/:/,$user);
10906: next if (($udom eq '') || ($uname eq ''));
10907: my $id;
1.1227 raeburn 10908: if (ref($inst_results) eq 'HASH') {
10909: if (ref($inst_results->{$user}) eq 'HASH') {
10910: $id = $inst_results->{$user}->{'id'};
10911: }
10912: }
10913: if ($id eq '') {
10914: if (ref($usershash->{$user})) {
10915: $id = $usershash->{$user}->{'id'};
10916: }
1.585 raeburn 10917: }
1.612 raeburn 10918: foreach my $item (keys(%{$checks})) {
10919: if (ref($$curr_rules{$udom}) eq 'HASH') {
10920: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10921: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10922: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10923: $$curr_rules{$udom}{$item});
1.612 raeburn 10924: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10925: if ($rule_check{$rule}) {
10926: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10927: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10928: if (ref($inst_results) eq 'HASH') {
10929: if (ref($inst_results->{$user}) eq 'HASH') {
10930: if (keys(%{$inst_results->{$user}}) == 0) {
10931: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10932: } elsif ($item eq 'id') {
10933: if ($inst_results->{$user}->{'id'} eq '') {
10934: $$alerts{$item}{$udom}{$uname} = 1;
10935: }
1.615 raeburn 10936: }
1.612 raeburn 10937: }
10938: }
1.615 raeburn 10939: }
10940: last;
1.585 raeburn 10941: }
10942: }
10943: }
10944: }
10945: }
10946: }
10947: }
10948: }
1.612 raeburn 10949: return;
10950: }
10951:
10952: sub user_rule_formats {
10953: my ($domain,$domdesc,$curr_rules,$check) = @_;
10954: my %text = (
10955: 'username' => 'Usernames',
10956: 'id' => 'IDs',
10957: );
10958: my $output;
10959: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10960: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10961: if (@{$ruleorder} > 0) {
1.1102 raeburn 10962: $output = '<br />'.
10963: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10964: '<span class="LC_cusr_emph">','</span>',$domdesc).
10965: ' <ul>';
1.612 raeburn 10966: foreach my $rule (@{$ruleorder}) {
10967: if (ref($curr_rules) eq 'ARRAY') {
10968: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10969: if (ref($rules->{$rule}) eq 'HASH') {
10970: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10971: $rules->{$rule}{'desc'}.'</li>';
10972: }
10973: }
10974: }
10975: }
10976: $output .= '</ul>';
10977: }
10978: }
10979: return $output;
10980: }
10981:
10982: sub instrule_disallow_msg {
1.615 raeburn 10983: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10984: my $response;
10985: my %text = (
10986: item => 'username',
10987: items => 'usernames',
10988: match => 'matches',
10989: do => 'does',
10990: action => 'a username',
10991: one => 'one',
10992: );
10993: if ($count > 1) {
10994: $text{'item'} = 'usernames';
10995: $text{'match'} ='match';
10996: $text{'do'} = 'do';
10997: $text{'action'} = 'usernames',
10998: $text{'one'} = 'ones';
10999: }
11000: if ($checkitem eq 'id') {
11001: $text{'items'} = 'IDs';
11002: $text{'item'} = 'ID';
11003: $text{'action'} = 'an ID';
1.615 raeburn 11004: if ($count > 1) {
11005: $text{'item'} = 'IDs';
11006: $text{'action'} = 'IDs';
11007: }
1.612 raeburn 11008: }
1.674 bisitz 11009: $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 11010: if ($mode eq 'upload') {
11011: if ($checkitem eq 'username') {
11012: $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'}.");
11013: } elsif ($checkitem eq 'id') {
1.674 bisitz 11014: $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 11015: }
1.669 raeburn 11016: } elsif ($mode eq 'selfcreate') {
11017: if ($checkitem eq 'id') {
11018: $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.");
11019: }
1.615 raeburn 11020: } else {
11021: if ($checkitem eq 'username') {
11022: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
11023: } elsif ($checkitem eq 'id') {
11024: $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.");
11025: }
1.612 raeburn 11026: }
11027: return $response;
1.585 raeburn 11028: }
11029:
1.624 raeburn 11030: sub personal_data_fieldtitles {
11031: my %fieldtitles = &Apache::lonlocal::texthash (
11032: id => 'Student/Employee ID',
11033: permanentemail => 'E-mail address',
11034: lastname => 'Last Name',
11035: firstname => 'First Name',
11036: middlename => 'Middle Name',
11037: generation => 'Generation',
11038: gen => 'Generation',
1.765 raeburn 11039: inststatus => 'Affiliation',
1.624 raeburn 11040: );
11041: return %fieldtitles;
11042: }
11043:
1.642 raeburn 11044: sub sorted_inst_types {
11045: my ($dom) = @_;
1.1185 raeburn 11046: my ($usertypes,$order);
11047: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11048: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
11049: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
11050: $order = $domdefaults{'inststatus'}{'inststatusorder'};
11051: } else {
11052: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
11053: }
1.642 raeburn 11054: my $othertitle = &mt('All users');
11055: if ($env{'request.course.id'}) {
1.668 raeburn 11056: $othertitle = &mt('Any users');
1.642 raeburn 11057: }
11058: my @types;
11059: if (ref($order) eq 'ARRAY') {
11060: @types = @{$order};
11061: }
11062: if (@types == 0) {
11063: if (ref($usertypes) eq 'HASH') {
11064: @types = sort(keys(%{$usertypes}));
11065: }
11066: }
11067: if (keys(%{$usertypes}) > 0) {
11068: $othertitle = &mt('Other users');
11069: }
11070: return ($othertitle,$usertypes,\@types);
11071: }
11072:
1.645 raeburn 11073: sub get_institutional_codes {
11074: my ($settings,$allcourses,$LC_code) = @_;
11075: # Get complete list of course sections to update
11076: my @currsections = ();
11077: my @currxlists = ();
11078: my $coursecode = $$settings{'internal.coursecode'};
11079:
11080: if ($$settings{'internal.sectionnums'} ne '') {
11081: @currsections = split(/,/,$$settings{'internal.sectionnums'});
11082: }
11083:
11084: if ($$settings{'internal.crosslistings'} ne '') {
11085: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
11086: }
11087:
11088: if (@currxlists > 0) {
11089: foreach (@currxlists) {
11090: if (m/^([^:]+):(\w*)$/) {
11091: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 11092: push(@{$allcourses},$1);
1.645 raeburn 11093: $$LC_code{$1} = $2;
11094: }
11095: }
11096: }
11097: }
11098:
11099: if (@currsections > 0) {
11100: foreach (@currsections) {
11101: if (m/^(\w+):(\w*)$/) {
11102: my $sec = $coursecode.$1;
11103: my $lc_sec = $2;
11104: unless (grep/^$sec$/,@{$allcourses}) {
1.1263 raeburn 11105: push(@{$allcourses},$sec);
1.645 raeburn 11106: $$LC_code{$sec} = $lc_sec;
11107: }
11108: }
11109: }
11110: }
11111: return;
11112: }
11113:
1.971 raeburn 11114: sub get_standard_codeitems {
11115: return ('Year','Semester','Department','Number','Section');
11116: }
11117:
1.112 bowersj2 11118: =pod
11119:
1.780 raeburn 11120: =head1 Slot Helpers
11121:
11122: =over 4
11123:
11124: =item * sorted_slots()
11125:
1.1040 raeburn 11126: Sorts an array of slot names in order of an optional sort key,
11127: default sort is by slot start time (earliest first).
1.780 raeburn 11128:
11129: Inputs:
11130:
11131: =over 4
11132:
11133: slotsarr - Reference to array of unsorted slot names.
11134:
11135: slots - Reference to hash of hash, where outer hash keys are slot names.
11136:
1.1040 raeburn 11137: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
11138:
1.549 albertel 11139: =back
11140:
1.780 raeburn 11141: Returns:
11142:
11143: =over 4
11144:
1.1040 raeburn 11145: sorted - An array of slot names sorted by a specified sort key
11146: (default sort key is start time of the slot).
1.780 raeburn 11147:
11148: =back
11149:
11150: =cut
11151:
11152:
11153: sub sorted_slots {
1.1040 raeburn 11154: my ($slotsarr,$slots,$sortkey) = @_;
11155: if ($sortkey eq '') {
11156: $sortkey = 'starttime';
11157: }
1.780 raeburn 11158: my @sorted;
11159: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11160: @sorted =
11161: sort {
11162: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11163: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11164: }
11165: if (ref($slots->{$a})) { return -1;}
11166: if (ref($slots->{$b})) { return 1;}
11167: return 0;
11168: } @{$slotsarr};
11169: }
11170: return @sorted;
11171: }
11172:
1.1040 raeburn 11173: =pod
11174:
11175: =item * get_future_slots()
11176:
11177: Inputs:
11178:
11179: =over 4
11180:
11181: cnum - course number
11182:
11183: cdom - course domain
11184:
11185: now - current UNIX time
11186:
11187: symb - optional symb
11188:
11189: =back
11190:
11191: Returns:
11192:
11193: =over 4
11194:
11195: sorted_reservable - ref to array of student_schedulable slots currently
11196: reservable, ordered by end date of reservation period.
11197:
11198: reservable_now - ref to hash of student_schedulable slots currently
11199: reservable.
11200:
11201: Keys in inner hash are:
11202: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11203: (b) endreserve: end date of reservation period.
11204: (c) uniqueperiod: start,end dates when slot is to be uniquely
11205: selected.
1.1040 raeburn 11206:
11207: sorted_future - ref to array of student_schedulable slots reservable in
11208: the future, ordered by start date of reservation period.
11209:
11210: future_reservable - ref to hash of student_schedulable slots reservable
11211: in the future.
11212:
11213: Keys in inner hash are:
11214: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11215: (b) startreserve: start date of reservation period.
11216: (c) uniqueperiod: start,end dates when slot is to be uniquely
11217: selected.
1.1040 raeburn 11218:
11219: =back
11220:
11221: =cut
11222:
11223: sub get_future_slots {
11224: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 11225: my $map;
11226: if ($symb) {
11227: ($map) = &Apache::lonnet::decode_symb($symb);
11228: }
1.1040 raeburn 11229: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11230: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11231: foreach my $slot (keys(%slots)) {
11232: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11233: if ($symb) {
1.1229 raeburn 11234: if ($slots{$slot}->{'symb'} ne '') {
11235: my $canuse;
11236: my %oksymbs;
11237: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
11238: map { $oksymbs{$_} = 1; } @slotsymbs;
11239: if ($oksymbs{$symb}) {
11240: $canuse = 1;
11241: } else {
11242: foreach my $item (@slotsymbs) {
11243: if ($item =~ /\.(page|sequence)$/) {
11244: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
11245: if (($map ne '') && ($map eq $sloturl)) {
11246: $canuse = 1;
11247: last;
11248: }
11249: }
11250: }
11251: }
11252: next unless ($canuse);
11253: }
1.1040 raeburn 11254: }
11255: if (($slots{$slot}->{'starttime'} > $now) &&
11256: ($slots{$slot}->{'endtime'} > $now)) {
11257: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11258: my $userallowed = 0;
11259: if ($slots{$slot}->{'allowedsections'}) {
11260: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11261: if (!defined($env{'request.role.sec'})
11262: && grep(/^No section assigned$/,@allowed_sec)) {
11263: $userallowed=1;
11264: } else {
11265: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11266: $userallowed=1;
11267: }
11268: }
11269: unless ($userallowed) {
11270: if (defined($env{'request.course.groups'})) {
11271: my @groups = split(/:/,$env{'request.course.groups'});
11272: foreach my $group (@groups) {
11273: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11274: $userallowed=1;
11275: last;
11276: }
11277: }
11278: }
11279: }
11280: }
11281: if ($slots{$slot}->{'allowedusers'}) {
11282: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11283: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11284: if (grep(/^\Q$user\E$/,@allowed_users)) {
11285: $userallowed = 1;
11286: }
11287: }
11288: next unless($userallowed);
11289: }
11290: my $startreserve = $slots{$slot}->{'startreserve'};
11291: my $endreserve = $slots{$slot}->{'endreserve'};
11292: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 11293: my $uniqueperiod;
11294: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11295: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11296: }
1.1040 raeburn 11297: if (($startreserve < $now) &&
11298: (!$endreserve || $endreserve > $now)) {
11299: my $lastres = $endreserve;
11300: if (!$lastres) {
11301: $lastres = $slots{$slot}->{'starttime'};
11302: }
11303: $reservable_now{$slot} = {
11304: symb => $symb,
1.1250 raeburn 11305: endreserve => $lastres,
11306: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11307: };
11308: } elsif (($startreserve > $now) &&
11309: (!$endreserve || $endreserve > $startreserve)) {
11310: $future_reservable{$slot} = {
11311: symb => $symb,
1.1250 raeburn 11312: startreserve => $startreserve,
11313: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11314: };
11315: }
11316: }
11317: }
11318: my @unsorted_reservable = keys(%reservable_now);
11319: if (@unsorted_reservable > 0) {
11320: @sorted_reservable =
11321: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11322: }
11323: my @unsorted_future = keys(%future_reservable);
11324: if (@unsorted_future > 0) {
11325: @sorted_future =
11326: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11327: }
11328: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11329: }
1.780 raeburn 11330:
11331: =pod
11332:
1.1057 foxr 11333: =back
11334:
1.549 albertel 11335: =head1 HTTP Helpers
11336:
11337: =over 4
11338:
1.648 raeburn 11339: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11340:
1.258 albertel 11341: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11342: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11343: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11344:
11345: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11346: $possible_names is an ref to an array of form element names. As an example:
11347: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11348: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11349:
11350: =cut
1.1 albertel 11351:
1.6 albertel 11352: sub get_unprocessed_cgi {
1.25 albertel 11353: my ($query,$possible_names)= @_;
1.26 matthew 11354: # $Apache::lonxml::debug=1;
1.356 albertel 11355: foreach my $pair (split(/&/,$query)) {
11356: my ($name, $value) = split(/=/,$pair);
1.369 www 11357: $name = &unescape($name);
1.25 albertel 11358: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11359: $value =~ tr/+/ /;
11360: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11361: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11362: }
1.16 harris41 11363: }
1.6 albertel 11364: }
11365:
1.112 bowersj2 11366: =pod
11367:
1.648 raeburn 11368: =item * &cacheheader()
1.112 bowersj2 11369:
11370: returns cache-controlling header code
11371:
11372: =cut
11373:
1.7 albertel 11374: sub cacheheader {
1.258 albertel 11375: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11376: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11377: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11378: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11379: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11380: return $output;
1.7 albertel 11381: }
11382:
1.112 bowersj2 11383: =pod
11384:
1.648 raeburn 11385: =item * &no_cache($r)
1.112 bowersj2 11386:
11387: specifies header code to not have cache
11388:
11389: =cut
11390:
1.9 albertel 11391: sub no_cache {
1.216 albertel 11392: my ($r) = @_;
11393: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11394: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11395: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11396: $r->no_cache(1);
11397: $r->header_out("Expires" => $date);
11398: $r->header_out("Pragma" => "no-cache");
1.123 www 11399: }
11400:
11401: sub content_type {
1.181 albertel 11402: my ($r,$type,$charset) = @_;
1.299 foxr 11403: if ($r) {
11404: # Note that printout.pl calls this with undef for $r.
11405: &no_cache($r);
11406: }
1.258 albertel 11407: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11408: unless ($charset) {
11409: $charset=&Apache::lonlocal::current_encoding;
11410: }
11411: if ($charset) { $type.='; charset='.$charset; }
11412: if ($r) {
11413: $r->content_type($type);
11414: } else {
11415: print("Content-type: $type\n\n");
11416: }
1.9 albertel 11417: }
1.25 albertel 11418:
1.112 bowersj2 11419: =pod
11420:
1.648 raeburn 11421: =item * &add_to_env($name,$value)
1.112 bowersj2 11422:
1.258 albertel 11423: adds $name to the %env hash with value
1.112 bowersj2 11424: $value, if $name already exists, the entry is converted to an array
11425: reference and $value is added to the array.
11426:
11427: =cut
11428:
1.25 albertel 11429: sub add_to_env {
11430: my ($name,$value)=@_;
1.258 albertel 11431: if (defined($env{$name})) {
11432: if (ref($env{$name})) {
1.25 albertel 11433: #already have multiple values
1.258 albertel 11434: push(@{ $env{$name} },$value);
1.25 albertel 11435: } else {
11436: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11437: my $first=$env{$name};
11438: undef($env{$name});
11439: push(@{ $env{$name} },$first,$value);
1.25 albertel 11440: }
11441: } else {
1.258 albertel 11442: $env{$name}=$value;
1.25 albertel 11443: }
1.31 albertel 11444: }
1.149 albertel 11445:
11446: =pod
11447:
1.648 raeburn 11448: =item * &get_env_multiple($name)
1.149 albertel 11449:
1.258 albertel 11450: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11451: values may be defined and end up as an array ref.
11452:
11453: returns an array of values
11454:
11455: =cut
11456:
11457: sub get_env_multiple {
11458: my ($name) = @_;
11459: my @values;
1.258 albertel 11460: if (defined($env{$name})) {
1.149 albertel 11461: # exists is it an array
1.258 albertel 11462: if (ref($env{$name})) {
11463: @values=@{ $env{$name} };
1.149 albertel 11464: } else {
1.258 albertel 11465: $values[0]=$env{$name};
1.149 albertel 11466: }
11467: }
11468: return(@values);
11469: }
11470:
1.1249 damieng 11471: # Looks at given dependencies, and returns something depending on the context.
11472: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11473: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11474: # For all other contexts, returns ($output, $counter, $numpathchg).
11475: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11476: # $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.
11477: # $numpathchg: integer with the number of cleaned up dependency paths.
11478: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11479: # \%mapping: hash reference clean path -> original path for all dependencies.
11480: # @param {string} actionurl - The path to the handler, indicative of the context.
11481: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11482: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11483: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11484: # @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)
11485: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11486: sub ask_for_embedded_content {
1.1249 damieng 11487: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11488: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11489: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11490: %currsubfile,%unused,$rem);
1.1071 raeburn 11491: my $counter = 0;
11492: my $numnew = 0;
1.987 raeburn 11493: my $numremref = 0;
11494: my $numinvalid = 0;
11495: my $numpathchg = 0;
11496: my $numexisting = 0;
1.1071 raeburn 11497: my $numunused = 0;
11498: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11499: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11500: my $heading = &mt('Upload embedded files');
11501: my $buttontext = &mt('Upload');
11502:
1.1249 damieng 11503: # fills these variables based on the context:
11504: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11505: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11506: if ($env{'request.course.id'}) {
1.1123 raeburn 11507: if ($actionurl eq '/adm/dependencies') {
11508: $navmap = Apache::lonnavmaps::navmap->new();
11509: }
11510: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11511: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11512: }
1.1123 raeburn 11513: if (($actionurl eq '/adm/portfolio') ||
11514: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11515: my $current_path='/';
11516: if ($env{'form.currentpath'}) {
11517: $current_path = $env{'form.currentpath'};
11518: }
11519: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11520: $udom = $cdom;
11521: $uname = $cnum;
1.984 raeburn 11522: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11523: } else {
11524: $udom = $env{'user.domain'};
11525: $uname = $env{'user.name'};
11526: $url = '/userfiles/portfolio';
11527: }
1.987 raeburn 11528: $toplevel = $url.'/';
1.984 raeburn 11529: $url .= $current_path;
11530: $getpropath = 1;
1.987 raeburn 11531: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11532: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11533: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11534: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11535: $toplevel = $url;
1.984 raeburn 11536: if ($rest ne '') {
1.987 raeburn 11537: $url .= $rest;
11538: }
11539: } elsif ($actionurl eq '/adm/coursedocs') {
11540: if (ref($args) eq 'HASH') {
1.1071 raeburn 11541: $url = $args->{'docs_url'};
11542: $toplevel = $url;
1.1084 raeburn 11543: if ($args->{'context'} eq 'paste') {
11544: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11545: ($path) =
11546: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11547: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11548: $fileloc =~ s{^/}{};
11549: }
1.1071 raeburn 11550: }
1.1084 raeburn 11551: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11552: if ($env{'request.course.id'} ne '') {
11553: if (ref($args) eq 'HASH') {
11554: $url = $args->{'docs_url'};
11555: $title = $args->{'docs_title'};
1.1126 raeburn 11556: $toplevel = $url;
11557: unless ($toplevel =~ m{^/}) {
11558: $toplevel = "/$url";
11559: }
1.1085 raeburn 11560: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11561: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11562: $path = $1;
11563: } else {
11564: ($path) =
11565: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11566: }
1.1195 raeburn 11567: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11568: $fileloc = $toplevel;
11569: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11570: my ($udom,$uname,$fname) =
11571: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11572: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11573: } else {
11574: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11575: }
1.1071 raeburn 11576: $fileloc =~ s{^/}{};
11577: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11578: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11579: }
1.987 raeburn 11580: }
1.1123 raeburn 11581: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11582: $udom = $cdom;
11583: $uname = $cnum;
11584: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11585: $toplevel = $url;
11586: $path = $url;
11587: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11588: $fileloc =~ s{^/}{};
1.987 raeburn 11589: }
1.1249 damieng 11590:
11591: # parses the dependency paths to get some info
11592: # fills $newfiles, $mapping, $subdependencies, $dependencies
11593: # $newfiles: hash URL -> 1 for new files or external URLs
11594: # (will be completed later)
11595: # $mapping:
11596: # for external URLs: external URL -> external URL
11597: # for relative paths: clean path -> original path
11598: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11599: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11600: foreach my $file (keys(%{$allfiles})) {
11601: my $embed_file;
11602: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11603: $embed_file = $1;
11604: } else {
11605: $embed_file = $file;
11606: }
1.1158 raeburn 11607: my ($absolutepath,$cleaned_file);
11608: if ($embed_file =~ m{^\w+://}) {
11609: $cleaned_file = $embed_file;
1.1147 raeburn 11610: $newfiles{$cleaned_file} = 1;
11611: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11612: } else {
1.1158 raeburn 11613: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11614: if ($embed_file =~ m{^/}) {
11615: $absolutepath = $embed_file;
11616: }
1.1147 raeburn 11617: if ($cleaned_file =~ m{/}) {
11618: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11619: $path = &check_for_traversal($path,$url,$toplevel);
11620: my $item = $fname;
11621: if ($path ne '') {
11622: $item = $path.'/'.$fname;
11623: $subdependencies{$path}{$fname} = 1;
11624: } else {
11625: $dependencies{$item} = 1;
11626: }
11627: if ($absolutepath) {
11628: $mapping{$item} = $absolutepath;
11629: } else {
11630: $mapping{$item} = $embed_file;
11631: }
11632: } else {
11633: $dependencies{$embed_file} = 1;
11634: if ($absolutepath) {
1.1147 raeburn 11635: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11636: } else {
1.1147 raeburn 11637: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11638: }
11639: }
1.984 raeburn 11640: }
11641: }
1.1249 damieng 11642:
11643: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11644: # and lists
11645: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11646: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11647: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11648: # the path had to be cleaned up
11649: # $existing: hash clean path -> 1 if the file exists
11650: # $numexisting: number of keys in $existing
11651: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11652: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11653: # dependency subdirectories that are
11654: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11655: my $dirptr = 16384;
1.984 raeburn 11656: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11657: $currsubfile{$path} = {};
1.1123 raeburn 11658: if (($actionurl eq '/adm/portfolio') ||
11659: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11660: my ($sublistref,$listerror) =
11661: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11662: if (ref($sublistref) eq 'ARRAY') {
11663: foreach my $line (@{$sublistref}) {
11664: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11665: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11666: }
1.984 raeburn 11667: }
1.987 raeburn 11668: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11669: if (opendir(my $dir,$url.'/'.$path)) {
11670: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11671: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11672: }
1.1084 raeburn 11673: } elsif (($actionurl eq '/adm/dependencies') ||
11674: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11675: ($args->{'context'} eq 'paste')) ||
11676: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11677: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11678: my $dir;
11679: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11680: $dir = $fileloc;
11681: } else {
11682: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11683: }
1.1071 raeburn 11684: if ($dir ne '') {
11685: my ($sublistref,$listerror) =
11686: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11687: if (ref($sublistref) eq 'ARRAY') {
11688: foreach my $line (@{$sublistref}) {
11689: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11690: undef,$mtime)=split(/\&/,$line,12);
11691: unless (($testdir&$dirptr) ||
11692: ($file_name =~ /^\.\.?$/)) {
11693: $currsubfile{$path}{$file_name} = [$size,$mtime];
11694: }
11695: }
11696: }
11697: }
1.984 raeburn 11698: }
11699: }
11700: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11701: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11702: my $item = $path.'/'.$file;
11703: unless ($mapping{$item} eq $item) {
11704: $pathchanges{$item} = 1;
11705: }
11706: $existing{$item} = 1;
11707: $numexisting ++;
11708: } else {
11709: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11710: }
11711: }
1.1071 raeburn 11712: if ($actionurl eq '/adm/dependencies') {
11713: foreach my $path (keys(%currsubfile)) {
11714: if (ref($currsubfile{$path}) eq 'HASH') {
11715: foreach my $file (keys(%{$currsubfile{$path}})) {
11716: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11717: next if (($rem ne '') &&
11718: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11719: (ref($navmap) &&
11720: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11721: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11722: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11723: $unused{$path.'/'.$file} = 1;
11724: }
11725: }
11726: }
11727: }
11728: }
1.984 raeburn 11729: }
1.1249 damieng 11730:
11731: # fills $currfile, hash file name -> 1 or [$size,$mtime]
11732: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 11733: my %currfile;
1.1123 raeburn 11734: if (($actionurl eq '/adm/portfolio') ||
11735: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11736: my ($dirlistref,$listerror) =
11737: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11738: if (ref($dirlistref) eq 'ARRAY') {
11739: foreach my $line (@{$dirlistref}) {
11740: my ($file_name,$rest) = split(/\&/,$line,2);
11741: $currfile{$file_name} = 1;
11742: }
1.984 raeburn 11743: }
1.987 raeburn 11744: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11745: if (opendir(my $dir,$url)) {
1.987 raeburn 11746: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11747: map {$currfile{$_} = 1;} @dir_list;
11748: }
1.1084 raeburn 11749: } elsif (($actionurl eq '/adm/dependencies') ||
11750: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11751: ($args->{'context'} eq 'paste')) ||
11752: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11753: if ($env{'request.course.id'} ne '') {
11754: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11755: if ($dir ne '') {
11756: my ($dirlistref,$listerror) =
11757: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11758: if (ref($dirlistref) eq 'ARRAY') {
11759: foreach my $line (@{$dirlistref}) {
11760: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11761: $size,undef,$mtime)=split(/\&/,$line,12);
11762: unless (($testdir&$dirptr) ||
11763: ($file_name =~ /^\.\.?$/)) {
11764: $currfile{$file_name} = [$size,$mtime];
11765: }
11766: }
11767: }
11768: }
11769: }
1.984 raeburn 11770: }
1.1249 damieng 11771: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
11772: # are not in subdirectories, using $currfile
1.984 raeburn 11773: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11774: if (exists($currfile{$file})) {
1.987 raeburn 11775: unless ($mapping{$file} eq $file) {
11776: $pathchanges{$file} = 1;
11777: }
11778: $existing{$file} = 1;
11779: $numexisting ++;
11780: } else {
1.984 raeburn 11781: $newfiles{$file} = 1;
11782: }
11783: }
1.1071 raeburn 11784: foreach my $file (keys(%currfile)) {
11785: unless (($file eq $filename) ||
11786: ($file eq $filename.'.bak') ||
11787: ($dependencies{$file})) {
1.1085 raeburn 11788: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11789: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11790: next if (($rem ne '') &&
11791: (($env{"httpref.$rem".$file} ne '') ||
11792: (ref($navmap) &&
11793: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11794: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11795: ($navmap->getResourceByUrl($rem.$1)))))));
11796: }
1.1085 raeburn 11797: }
1.1071 raeburn 11798: $unused{$file} = 1;
11799: }
11800: }
1.1249 damieng 11801:
11802: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 11803: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11804: ($args->{'context'} eq 'paste')) {
11805: $counter = scalar(keys(%existing));
11806: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11807: return ($output,$counter,$numpathchg,\%existing);
11808: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11809: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11810: $counter = scalar(keys(%existing));
11811: $numpathchg = scalar(keys(%pathchanges));
11812: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11813: }
1.1249 damieng 11814:
11815: # returns HTML otherwise, with dependency results and to ask for more uploads
11816:
11817: # $upload_output: missing dependencies (with upload form)
11818: # $modify_output: uploaded dependencies (in use)
11819: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 11820: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11821: if ($actionurl eq '/adm/dependencies') {
11822: next if ($embed_file =~ m{^\w+://});
11823: }
1.660 raeburn 11824: $upload_output .= &start_data_table_row().
1.1123 raeburn 11825: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11826: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11827: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11828: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11829: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11830: }
1.1123 raeburn 11831: $upload_output .= '</td>';
1.1071 raeburn 11832: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11833: $upload_output.='<td align="right">'.
11834: '<span class="LC_info LC_fontsize_medium">'.
11835: &mt("URL points to web address").'</span>';
1.987 raeburn 11836: $numremref++;
1.660 raeburn 11837: } elsif ($args->{'error_on_invalid_names'}
11838: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11839: $upload_output.='<td align="right"><span class="LC_warning">'.
11840: &mt('Invalid characters').'</span>';
1.987 raeburn 11841: $numinvalid++;
1.660 raeburn 11842: } else {
1.1123 raeburn 11843: $upload_output .= '<td>'.
11844: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11845: $embed_file,\%mapping,
1.1071 raeburn 11846: $allfiles,$codebase,'upload');
11847: $counter ++;
11848: $numnew ++;
1.987 raeburn 11849: }
11850: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11851: }
11852: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11853: if ($actionurl eq '/adm/dependencies') {
11854: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11855: $modify_output .= &start_data_table_row().
11856: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11857: '<img src="'.&icon($embed_file).'" border="0" />'.
11858: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11859: '<td>'.$size.'</td>'.
11860: '<td>'.$mtime.'</td>'.
11861: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11862: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11863: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11864: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11865: &embedded_file_element('upload_embedded',$counter,
11866: $embed_file,\%mapping,
11867: $allfiles,$codebase,'modify').
11868: '</div></td>'.
11869: &end_data_table_row()."\n";
11870: $counter ++;
11871: } else {
11872: $upload_output .= &start_data_table_row().
1.1123 raeburn 11873: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11874: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11875: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11876: &Apache::loncommon::end_data_table_row()."\n";
11877: }
11878: }
11879: my $delidx = $counter;
11880: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11881: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11882: $delete_output .= &start_data_table_row().
11883: '<td><img src="'.&icon($oldfile).'" />'.
11884: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11885: '<td>'.$size.'</td>'.
11886: '<td>'.$mtime.'</td>'.
11887: '<td><label><input type="checkbox" name="del_upload_dep" '.
11888: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11889: &embedded_file_element('upload_embedded',$delidx,
11890: $oldfile,\%mapping,$allfiles,
11891: $codebase,'delete').'</td>'.
11892: &end_data_table_row()."\n";
11893: $numunused ++;
11894: $delidx ++;
1.987 raeburn 11895: }
11896: if ($upload_output) {
11897: $upload_output = &start_data_table().
11898: $upload_output.
11899: &end_data_table()."\n";
11900: }
1.1071 raeburn 11901: if ($modify_output) {
11902: $modify_output = &start_data_table().
11903: &start_data_table_header_row().
11904: '<th>'.&mt('File').'</th>'.
11905: '<th>'.&mt('Size (KB)').'</th>'.
11906: '<th>'.&mt('Modified').'</th>'.
11907: '<th>'.&mt('Upload replacement?').'</th>'.
11908: &end_data_table_header_row().
11909: $modify_output.
11910: &end_data_table()."\n";
11911: }
11912: if ($delete_output) {
11913: $delete_output = &start_data_table().
11914: &start_data_table_header_row().
11915: '<th>'.&mt('File').'</th>'.
11916: '<th>'.&mt('Size (KB)').'</th>'.
11917: '<th>'.&mt('Modified').'</th>'.
11918: '<th>'.&mt('Delete?').'</th>'.
11919: &end_data_table_header_row().
11920: $delete_output.
11921: &end_data_table()."\n";
11922: }
1.987 raeburn 11923: my $applies = 0;
11924: if ($numremref) {
11925: $applies ++;
11926: }
11927: if ($numinvalid) {
11928: $applies ++;
11929: }
11930: if ($numexisting) {
11931: $applies ++;
11932: }
1.1071 raeburn 11933: if ($counter || $numunused) {
1.987 raeburn 11934: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11935: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11936: $state.'<h3>'.$heading.'</h3>';
11937: if ($actionurl eq '/adm/dependencies') {
11938: if ($numnew) {
11939: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11940: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11941: $upload_output.'<br />'."\n";
11942: }
11943: if ($numexisting) {
11944: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11945: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11946: $modify_output.'<br />'."\n";
11947: $buttontext = &mt('Save changes');
11948: }
11949: if ($numunused) {
11950: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11951: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11952: $delete_output.'<br />'."\n";
11953: $buttontext = &mt('Save changes');
11954: }
11955: } else {
11956: $output .= $upload_output.'<br />'."\n";
11957: }
11958: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11959: $counter.'" />'."\n";
11960: if ($actionurl eq '/adm/dependencies') {
11961: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11962: $numnew.'" />'."\n";
11963: } elsif ($actionurl eq '') {
1.987 raeburn 11964: $output .= '<input type="hidden" name="phase" value="three" />';
11965: }
11966: } elsif ($applies) {
11967: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11968: if ($applies > 1) {
11969: $output .=
1.1123 raeburn 11970: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11971: if ($numremref) {
11972: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11973: }
11974: if ($numinvalid) {
11975: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11976: }
11977: if ($numexisting) {
11978: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11979: }
11980: $output .= '</ul><br />';
11981: } elsif ($numremref) {
11982: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11983: } elsif ($numinvalid) {
11984: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11985: } elsif ($numexisting) {
11986: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11987: }
11988: $output .= $upload_output.'<br />';
11989: }
11990: my ($pathchange_output,$chgcount);
1.1071 raeburn 11991: $chgcount = $counter;
1.987 raeburn 11992: if (keys(%pathchanges) > 0) {
11993: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11994: if ($counter) {
1.987 raeburn 11995: $output .= &embedded_file_element('pathchange',$chgcount,
11996: $embed_file,\%mapping,
1.1071 raeburn 11997: $allfiles,$codebase,'change');
1.987 raeburn 11998: } else {
11999: $pathchange_output .=
12000: &start_data_table_row().
12001: '<td><input type ="checkbox" name="namechange" value="'.
12002: $chgcount.'" checked="checked" /></td>'.
12003: '<td>'.$mapping{$embed_file}.'</td>'.
12004: '<td>'.$embed_file.
12005: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 12006: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 12007: '</td>'.&end_data_table_row();
1.660 raeburn 12008: }
1.987 raeburn 12009: $numpathchg ++;
12010: $chgcount ++;
1.660 raeburn 12011: }
12012: }
1.1127 raeburn 12013: if (($counter) || ($numunused)) {
1.987 raeburn 12014: if ($numpathchg) {
12015: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
12016: $numpathchg.'" />'."\n";
12017: }
12018: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12019: ($actionurl eq '/adm/imsimport')) {
12020: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
12021: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
12022: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 12023: } elsif ($actionurl eq '/adm/dependencies') {
12024: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 12025: }
1.1123 raeburn 12026: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 12027: } elsif ($numpathchg) {
12028: my %pathchange = ();
12029: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
12030: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12031: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 12032: }
1.987 raeburn 12033: }
1.1071 raeburn 12034: return ($output,$counter,$numpathchg);
1.987 raeburn 12035: }
12036:
1.1147 raeburn 12037: =pod
12038:
12039: =item * clean_path($name)
12040:
12041: Performs clean-up of directories, subdirectories and filename in an
12042: embedded object, referenced in an HTML file which is being uploaded
12043: to a course or portfolio, where
12044: "Upload embedded images/multimedia files if HTML file" checkbox was
12045: checked.
12046:
12047: Clean-up is similar to replacements in lonnet::clean_filename()
12048: except each / between sub-directory and next level is preserved.
12049:
12050: =cut
12051:
12052: sub clean_path {
12053: my ($embed_file) = @_;
12054: $embed_file =~s{^/+}{};
12055: my @contents;
12056: if ($embed_file =~ m{/}) {
12057: @contents = split(/\//,$embed_file);
12058: } else {
12059: @contents = ($embed_file);
12060: }
12061: my $lastidx = scalar(@contents)-1;
12062: for (my $i=0; $i<=$lastidx; $i++) {
12063: $contents[$i]=~s{\\}{/}g;
12064: $contents[$i]=~s/\s+/\_/g;
12065: $contents[$i]=~s{[^/\w\.\-]}{}g;
12066: if ($i == $lastidx) {
12067: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
12068: }
12069: }
12070: if ($lastidx > 0) {
12071: return join('/',@contents);
12072: } else {
12073: return $contents[0];
12074: }
12075: }
12076:
1.987 raeburn 12077: sub embedded_file_element {
1.1071 raeburn 12078: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 12079: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
12080: (ref($codebase) eq 'HASH'));
12081: my $output;
1.1071 raeburn 12082: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 12083: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
12084: }
12085: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
12086: &escape($embed_file).'" />';
12087: unless (($context eq 'upload_embedded') &&
12088: ($mapping->{$embed_file} eq $embed_file)) {
12089: $output .='
12090: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
12091: }
12092: my $attrib;
12093: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
12094: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
12095: }
12096: $output .=
12097: "\n\t\t".
12098: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
12099: $attrib.'" />';
12100: if (exists($codebase->{$mapping->{$embed_file}})) {
12101: $output .=
12102: "\n\t\t".
12103: '<input name="codebase_'.$num.'" type="hidden" value="'.
12104: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 12105: }
1.987 raeburn 12106: return $output;
1.660 raeburn 12107: }
12108:
1.1071 raeburn 12109: sub get_dependency_details {
12110: my ($currfile,$currsubfile,$embed_file) = @_;
12111: my ($size,$mtime,$showsize,$showmtime);
12112: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
12113: if ($embed_file =~ m{/}) {
12114: my ($path,$fname) = split(/\//,$embed_file);
12115: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
12116: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
12117: }
12118: } else {
12119: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
12120: ($size,$mtime) = @{$currfile->{$embed_file}};
12121: }
12122: }
12123: $showsize = $size/1024.0;
12124: $showsize = sprintf("%.1f",$showsize);
12125: if ($mtime > 0) {
12126: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
12127: }
12128: }
12129: return ($showsize,$showmtime);
12130: }
12131:
12132: sub ask_embedded_js {
12133: return <<"END";
12134: <script type="text/javascript"">
12135: // <![CDATA[
12136: function toggleBrowse(counter) {
12137: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
12138: var fileid = document.getElementById('embedded_item_'+counter);
12139: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12140: if (chkboxid.checked == true) {
12141: uploaddivid.style.display='block';
12142: } else {
12143: uploaddivid.style.display='none';
12144: fileid.value = '';
12145: }
12146: }
12147: // ]]>
12148: </script>
12149:
12150: END
12151: }
12152:
1.661 raeburn 12153: sub upload_embedded {
12154: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12155: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12156: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12157: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12158: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12159: my $orig_uploaded_filename =
12160: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12161: foreach my $type ('orig','ref','attrib','codebase') {
12162: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12163: $env{'form.embedded_'.$type.'_'.$i} =
12164: &unescape($env{'form.embedded_'.$type.'_'.$i});
12165: }
12166: }
1.661 raeburn 12167: my ($path,$fname) =
12168: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12169: # no path, whole string is fname
12170: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12171: $fname = &Apache::lonnet::clean_filename($fname);
12172: # See if there is anything left
12173: next if ($fname eq '');
12174:
12175: # Check if file already exists as a file or directory.
12176: my ($state,$msg);
12177: if ($context eq 'portfolio') {
12178: my $port_path = $dirpath;
12179: if ($group ne '') {
12180: $port_path = "groups/$group/$port_path";
12181: }
1.987 raeburn 12182: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12183: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12184: $dir_root,$port_path,$disk_quota,
12185: $current_disk_usage,$uname,$udom);
12186: if ($state eq 'will_exceed_quota'
1.984 raeburn 12187: || $state eq 'file_locked') {
1.661 raeburn 12188: $output .= $msg;
12189: next;
12190: }
12191: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12192: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12193: if ($state eq 'exists') {
12194: $output .= $msg;
12195: next;
12196: }
12197: }
12198: # Check if extension is valid
12199: if (($fname =~ /\.(\w+)$/) &&
12200: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 12201: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12202: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12203: next;
12204: } elsif (($fname =~ /\.(\w+)$/) &&
12205: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12206: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12207: next;
12208: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 12209: $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 12210: next;
12211: }
12212: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 12213: my $subdir = $path;
12214: $subdir =~ s{/+$}{};
1.661 raeburn 12215: if ($context eq 'portfolio') {
1.984 raeburn 12216: my $result;
12217: if ($state eq 'existingfile') {
12218: $result=
12219: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 12220: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12221: } else {
1.984 raeburn 12222: $result=
12223: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12224: $dirpath.
1.1123 raeburn 12225: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12226: if ($result !~ m|^/uploaded/|) {
12227: $output .= '<span class="LC_error">'
12228: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12229: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12230: .'</span><br />';
12231: next;
12232: } else {
1.987 raeburn 12233: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12234: $path.$fname.'</span>').'<br />';
1.984 raeburn 12235: }
1.661 raeburn 12236: }
1.1123 raeburn 12237: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 12238: my $extendedsubdir = $dirpath.'/'.$subdir;
12239: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12240: my $result =
1.1126 raeburn 12241: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12242: if ($result !~ m|^/uploaded/|) {
12243: $output .= '<span class="LC_error">'
12244: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12245: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12246: .'</span><br />';
12247: next;
12248: } else {
12249: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12250: $path.$fname.'</span>').'<br />';
1.1125 raeburn 12251: if ($context eq 'syllabus') {
12252: &Apache::lonnet::make_public_indefinitely($result);
12253: }
1.987 raeburn 12254: }
1.661 raeburn 12255: } else {
12256: # Save the file
12257: my $target = $env{'form.embedded_item_'.$i};
12258: my $fullpath = $dir_root.$dirpath.'/'.$path;
12259: my $dest = $fullpath.$fname;
12260: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12261: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12262: my $count;
12263: my $filepath = $dir_root;
1.1027 raeburn 12264: foreach my $subdir (@parts) {
12265: $filepath .= "/$subdir";
12266: if (!-e $filepath) {
1.661 raeburn 12267: mkdir($filepath,0770);
12268: }
12269: }
12270: my $fh;
12271: if (!open($fh,'>'.$dest)) {
12272: &Apache::lonnet::logthis('Failed to create '.$dest);
12273: $output .= '<span class="LC_error">'.
1.1071 raeburn 12274: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12275: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12276: '</span><br />';
12277: } else {
12278: if (!print $fh $env{'form.embedded_item_'.$i}) {
12279: &Apache::lonnet::logthis('Failed to write to '.$dest);
12280: $output .= '<span class="LC_error">'.
1.1071 raeburn 12281: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12282: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12283: '</span><br />';
12284: } else {
1.987 raeburn 12285: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12286: $url.'</span>').'<br />';
12287: unless ($context eq 'testbank') {
12288: $footer .= &mt('View embedded file: [_1]',
12289: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12290: }
12291: }
12292: close($fh);
12293: }
12294: }
12295: if ($env{'form.embedded_ref_'.$i}) {
12296: $pathchange{$i} = 1;
12297: }
12298: }
12299: if ($output) {
12300: $output = '<p>'.$output.'</p>';
12301: }
12302: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12303: $returnflag = 'ok';
1.1071 raeburn 12304: my $numpathchgs = scalar(keys(%pathchange));
12305: if ($numpathchgs > 0) {
1.987 raeburn 12306: if ($context eq 'portfolio') {
12307: $output .= '<p>'.&mt('or').'</p>';
12308: } elsif ($context eq 'testbank') {
1.1071 raeburn 12309: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12310: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12311: $returnflag = 'modify_orightml';
12312: }
12313: }
1.1071 raeburn 12314: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12315: }
12316:
12317: sub modify_html_form {
12318: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12319: my $end = 0;
12320: my $modifyform;
12321: if ($context eq 'upload_embedded') {
12322: return unless (ref($pathchange) eq 'HASH');
12323: if ($env{'form.number_embedded_items'}) {
12324: $end += $env{'form.number_embedded_items'};
12325: }
12326: if ($env{'form.number_pathchange_items'}) {
12327: $end += $env{'form.number_pathchange_items'};
12328: }
12329: if ($end) {
12330: for (my $i=0; $i<$end; $i++) {
12331: if ($i < $env{'form.number_embedded_items'}) {
12332: next unless($pathchange->{$i});
12333: }
12334: $modifyform .=
12335: &start_data_table_row().
12336: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12337: 'checked="checked" /></td>'.
12338: '<td>'.$env{'form.embedded_ref_'.$i}.
12339: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12340: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12341: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12342: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12343: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12344: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12345: '<td>'.$env{'form.embedded_orig_'.$i}.
12346: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12347: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12348: &end_data_table_row();
1.1071 raeburn 12349: }
1.987 raeburn 12350: }
12351: } else {
12352: $modifyform = $pathchgtable;
12353: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12354: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12355: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12356: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12357: }
12358: }
12359: if ($modifyform) {
1.1071 raeburn 12360: if ($actionurl eq '/adm/dependencies') {
12361: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12362: }
1.987 raeburn 12363: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12364: '<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".
12365: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12366: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12367: '</ol></p>'."\n".'<p>'.
12368: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12369: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12370: &start_data_table()."\n".
12371: &start_data_table_header_row().
12372: '<th>'.&mt('Change?').'</th>'.
12373: '<th>'.&mt('Current reference').'</th>'.
12374: '<th>'.&mt('Required reference').'</th>'.
12375: &end_data_table_header_row()."\n".
12376: $modifyform.
12377: &end_data_table().'<br />'."\n".$hiddenstate.
12378: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12379: '</form>'."\n";
12380: }
12381: return;
12382: }
12383:
12384: sub modify_html_refs {
1.1123 raeburn 12385: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12386: my $container;
12387: if ($context eq 'portfolio') {
12388: $container = $env{'form.container'};
12389: } elsif ($context eq 'coursedoc') {
12390: $container = $env{'form.primaryurl'};
1.1071 raeburn 12391: } elsif ($context eq 'manage_dependencies') {
12392: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12393: $container = "/$container";
1.1123 raeburn 12394: } elsif ($context eq 'syllabus') {
12395: $container = $url;
1.987 raeburn 12396: } else {
1.1027 raeburn 12397: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12398: }
12399: my (%allfiles,%codebase,$output,$content);
12400: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 12401: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12402: if (wantarray) {
12403: return ('',0,0);
12404: } else {
12405: return;
12406: }
12407: }
12408: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12409: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12410: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12411: if (wantarray) {
12412: return ('',0,0);
12413: } else {
12414: return;
12415: }
12416: }
1.987 raeburn 12417: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12418: if ($content eq '-1') {
12419: if (wantarray) {
12420: return ('',0,0);
12421: } else {
12422: return;
12423: }
12424: }
1.987 raeburn 12425: } else {
1.1071 raeburn 12426: unless ($container =~ /^\Q$dir_root\E/) {
12427: if (wantarray) {
12428: return ('',0,0);
12429: } else {
12430: return;
12431: }
12432: }
1.1317 raeburn 12433: if (open(my $fh,'<',$container)) {
1.987 raeburn 12434: $content = join('', <$fh>);
12435: close($fh);
12436: } else {
1.1071 raeburn 12437: if (wantarray) {
12438: return ('',0,0);
12439: } else {
12440: return;
12441: }
1.987 raeburn 12442: }
12443: }
12444: my ($count,$codebasecount) = (0,0);
12445: my $mm = new File::MMagic;
12446: my $mime_type = $mm->checktype_contents($content);
12447: if ($mime_type eq 'text/html') {
12448: my $parse_result =
12449: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12450: \%codebase,\$content);
12451: if ($parse_result eq 'ok') {
12452: foreach my $i (@changes) {
12453: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12454: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12455: if ($allfiles{$ref}) {
12456: my $newname = $orig;
12457: my ($attrib_regexp,$codebase);
1.1006 raeburn 12458: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12459: if ($attrib_regexp =~ /:/) {
12460: $attrib_regexp =~ s/\:/|/g;
12461: }
12462: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12463: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12464: $count += $numchg;
1.1123 raeburn 12465: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 12466: delete($allfiles{$ref});
1.987 raeburn 12467: }
12468: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12469: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12470: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12471: $codebasecount ++;
12472: }
12473: }
12474: }
1.1123 raeburn 12475: my $skiprewrites;
1.987 raeburn 12476: if ($count || $codebasecount) {
12477: my $saveresult;
1.1071 raeburn 12478: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12479: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12480: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12481: if ($url eq $container) {
12482: my ($fname) = ($container =~ m{/([^/]+)$});
12483: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12484: $count,'<span class="LC_filename">'.
1.1071 raeburn 12485: $fname.'</span>').'</p>';
1.987 raeburn 12486: } else {
12487: $output = '<p class="LC_error">'.
12488: &mt('Error: update failed for: [_1].',
12489: '<span class="LC_filename">'.
12490: $container.'</span>').'</p>';
12491: }
1.1123 raeburn 12492: if ($context eq 'syllabus') {
12493: unless ($saveresult eq 'ok') {
12494: $skiprewrites = 1;
12495: }
12496: }
1.987 raeburn 12497: } else {
1.1317 raeburn 12498: if (open(my $fh,'>',$container)) {
1.987 raeburn 12499: print $fh $content;
12500: close($fh);
12501: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12502: $count,'<span class="LC_filename">'.
12503: $container.'</span>').'</p>';
1.661 raeburn 12504: } else {
1.987 raeburn 12505: $output = '<p class="LC_error">'.
12506: &mt('Error: could not update [_1].',
12507: '<span class="LC_filename">'.
12508: $container.'</span>').'</p>';
1.661 raeburn 12509: }
12510: }
12511: }
1.1123 raeburn 12512: if (($context eq 'syllabus') && (!$skiprewrites)) {
12513: my ($actionurl,$state);
12514: $actionurl = "/public/$udom/$uname/syllabus";
12515: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12516: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12517: \%codebase,
12518: {'context' => 'rewrites',
12519: 'ignore_remote_references' => 1,});
12520: if (ref($mapping) eq 'HASH') {
12521: my $rewrites = 0;
12522: foreach my $key (keys(%{$mapping})) {
12523: next if ($key =~ m{^https?://});
12524: my $ref = $mapping->{$key};
12525: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12526: my $attrib;
12527: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12528: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12529: }
12530: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12531: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12532: $rewrites += $numchg;
12533: }
12534: }
12535: if ($rewrites) {
12536: my $saveresult;
12537: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12538: if ($url eq $container) {
12539: my ($fname) = ($container =~ m{/([^/]+)$});
12540: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12541: $count,'<span class="LC_filename">'.
12542: $fname.'</span>').'</p>';
12543: } else {
12544: $output .= '<p class="LC_error">'.
12545: &mt('Error: could not update links in [_1].',
12546: '<span class="LC_filename">'.
12547: $container.'</span>').'</p>';
12548:
12549: }
12550: }
12551: }
12552: }
1.987 raeburn 12553: } else {
12554: &logthis('Failed to parse '.$container.
12555: ' to modify references: '.$parse_result);
1.661 raeburn 12556: }
12557: }
1.1071 raeburn 12558: if (wantarray) {
12559: return ($output,$count,$codebasecount);
12560: } else {
12561: return $output;
12562: }
1.661 raeburn 12563: }
12564:
12565: sub check_for_existing {
12566: my ($path,$fname,$element) = @_;
12567: my ($state,$msg);
12568: if (-d $path.'/'.$fname) {
12569: $state = 'exists';
12570: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12571: } elsif (-e $path.'/'.$fname) {
12572: $state = 'exists';
12573: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12574: }
12575: if ($state eq 'exists') {
12576: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12577: }
12578: return ($state,$msg);
12579: }
12580:
12581: sub check_for_upload {
12582: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12583: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12584: my $filesize = length($env{'form.'.$element});
12585: if (!$filesize) {
12586: my $msg = '<span class="LC_error">'.
12587: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12588: '<span class="LC_filename">'.$fname.'</span>',
12589: $filesize).'<br />'.
1.1007 raeburn 12590: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12591: '</span>';
12592: return ('zero_bytes',$msg);
12593: }
12594: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12595: my $getpropath = 1;
1.1021 raeburn 12596: my ($dirlistref,$listerror) =
12597: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12598: my $found_file = 0;
12599: my $locked_file = 0;
1.991 raeburn 12600: my @lockers;
12601: my $navmap;
12602: if ($env{'request.course.id'}) {
12603: $navmap = Apache::lonnavmaps::navmap->new();
12604: }
1.1021 raeburn 12605: if (ref($dirlistref) eq 'ARRAY') {
12606: foreach my $line (@{$dirlistref}) {
12607: my ($file_name,$rest)=split(/\&/,$line,2);
12608: if ($file_name eq $fname){
12609: $file_name = $path.$file_name;
12610: if ($group ne '') {
12611: $file_name = $group.$file_name;
12612: }
12613: $found_file = 1;
12614: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12615: foreach my $lock (@lockers) {
12616: if (ref($lock) eq 'ARRAY') {
12617: my ($symb,$crsid) = @{$lock};
12618: if ($crsid eq $env{'request.course.id'}) {
12619: if (ref($navmap)) {
12620: my $res = $navmap->getBySymb($symb);
12621: foreach my $part (@{$res->parts()}) {
12622: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12623: unless (($slot_status == $res->RESERVED) ||
12624: ($slot_status == $res->RESERVED_LOCATION)) {
12625: $locked_file = 1;
12626: }
1.991 raeburn 12627: }
1.1021 raeburn 12628: } else {
12629: $locked_file = 1;
1.991 raeburn 12630: }
12631: } else {
12632: $locked_file = 1;
12633: }
12634: }
1.1021 raeburn 12635: }
12636: } else {
12637: my @info = split(/\&/,$rest);
12638: my $currsize = $info[6]/1000;
12639: if ($currsize < $filesize) {
12640: my $extra = $filesize - $currsize;
12641: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12642: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12643: &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 12644: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12645: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12646: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12647: return ('will_exceed_quota',$msg);
12648: }
1.984 raeburn 12649: }
12650: }
1.661 raeburn 12651: }
12652: }
12653: }
12654: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12655: my $msg = '<p class="LC_warning">'.
12656: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12657: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12658: return ('will_exceed_quota',$msg);
12659: } elsif ($found_file) {
12660: if ($locked_file) {
1.1179 bisitz 12661: my $msg = '<p class="LC_warning">';
1.661 raeburn 12662: $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 12663: $msg .= '</p>';
1.661 raeburn 12664: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12665: return ('file_locked',$msg);
12666: } else {
1.1179 bisitz 12667: my $msg = '<p class="LC_error">';
1.984 raeburn 12668: $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 12669: $msg .= '</p>';
1.984 raeburn 12670: return ('existingfile',$msg);
1.661 raeburn 12671: }
12672: }
12673: }
12674:
1.987 raeburn 12675: sub check_for_traversal {
12676: my ($path,$url,$toplevel) = @_;
12677: my @parts=split(/\//,$path);
12678: my $cleanpath;
12679: my $fullpath = $url;
12680: for (my $i=0;$i<@parts;$i++) {
12681: next if ($parts[$i] eq '.');
12682: if ($parts[$i] eq '..') {
12683: $fullpath =~ s{([^/]+/)$}{};
12684: } else {
12685: $fullpath .= $parts[$i].'/';
12686: }
12687: }
12688: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12689: $cleanpath = $1;
12690: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12691: my $curr_toprel = $1;
12692: my @parts = split(/\//,$curr_toprel);
12693: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12694: my @urlparts = split(/\//,$url_toprel);
12695: my $doubledots;
12696: my $startdiff = -1;
12697: for (my $i=0; $i<@urlparts; $i++) {
12698: if ($startdiff == -1) {
12699: unless ($urlparts[$i] eq $parts[$i]) {
12700: $startdiff = $i;
12701: $doubledots .= '../';
12702: }
12703: } else {
12704: $doubledots .= '../';
12705: }
12706: }
12707: if ($startdiff > -1) {
12708: $cleanpath = $doubledots;
12709: for (my $i=$startdiff; $i<@parts; $i++) {
12710: $cleanpath .= $parts[$i].'/';
12711: }
12712: }
12713: }
12714: $cleanpath =~ s{(/)$}{};
12715: return $cleanpath;
12716: }
1.31 albertel 12717:
1.1053 raeburn 12718: sub is_archive_file {
12719: my ($mimetype) = @_;
12720: if (($mimetype eq 'application/octet-stream') ||
12721: ($mimetype eq 'application/x-stuffit') ||
12722: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12723: return 1;
12724: }
12725: return;
12726: }
12727:
12728: sub decompress_form {
1.1065 raeburn 12729: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12730: my %lt = &Apache::lonlocal::texthash (
12731: this => 'This file is an archive file.',
1.1067 raeburn 12732: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12733: itsc => 'Its contents are as follows:',
1.1053 raeburn 12734: youm => 'You may wish to extract its contents.',
12735: extr => 'Extract contents',
1.1067 raeburn 12736: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12737: proa => 'Process automatically?',
1.1053 raeburn 12738: yes => 'Yes',
12739: no => 'No',
1.1067 raeburn 12740: fold => 'Title for folder containing movie',
12741: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12742: );
1.1065 raeburn 12743: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12744: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12745: my $info = &list_archive_contents($fileloc,\@paths);
12746: if (@paths) {
12747: foreach my $path (@paths) {
12748: $path =~ s{^/}{};
1.1067 raeburn 12749: if ($path =~ m{^([^/]+)/$}) {
12750: $topdir = $1;
12751: }
1.1065 raeburn 12752: if ($path =~ m{^([^/]+)/}) {
12753: $toplevel{$1} = $path;
12754: } else {
12755: $toplevel{$path} = $path;
12756: }
12757: }
12758: }
1.1067 raeburn 12759: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12760: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12761: "$topdir/media/",
12762: "$topdir/media/$topdir.mp4",
12763: "$topdir/media/FirstFrame.png",
12764: "$topdir/media/player.swf",
12765: "$topdir/media/swfobject.js",
12766: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12767: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12768: "$topdir/$topdir.mp4",
12769: "$topdir/$topdir\_config.xml",
12770: "$topdir/$topdir\_controller.swf",
12771: "$topdir/$topdir\_embed.css",
12772: "$topdir/$topdir\_First_Frame.png",
12773: "$topdir/$topdir\_player.html",
12774: "$topdir/$topdir\_Thumbnails.png",
12775: "$topdir/playerProductInstall.swf",
12776: "$topdir/scripts/",
12777: "$topdir/scripts/config_xml.js",
12778: "$topdir/scripts/handlebars.js",
12779: "$topdir/scripts/jquery-1.7.1.min.js",
12780: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12781: "$topdir/scripts/modernizr.js",
12782: "$topdir/scripts/player-min.js",
12783: "$topdir/scripts/swfobject.js",
12784: "$topdir/skins/",
12785: "$topdir/skins/configuration_express.xml",
12786: "$topdir/skins/express_show/",
12787: "$topdir/skins/express_show/player-min.css",
12788: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12789: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12790: "$topdir/$topdir.mp4",
12791: "$topdir/$topdir\_config.xml",
12792: "$topdir/$topdir\_controller.swf",
12793: "$topdir/$topdir\_embed.css",
12794: "$topdir/$topdir\_First_Frame.png",
12795: "$topdir/$topdir\_player.html",
12796: "$topdir/$topdir\_Thumbnails.png",
12797: "$topdir/playerProductInstall.swf",
12798: "$topdir/scripts/",
12799: "$topdir/scripts/config_xml.js",
12800: "$topdir/scripts/techsmith-smart-player.min.js",
12801: "$topdir/skins/",
12802: "$topdir/skins/configuration_express.xml",
12803: "$topdir/skins/express_show/",
12804: "$topdir/skins/express_show/spritesheet.min.css",
12805: "$topdir/skins/express_show/spritesheet.png",
12806: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12807: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12808: if (@diffs == 0) {
1.1164 raeburn 12809: $is_camtasia = 6;
12810: } else {
1.1197 raeburn 12811: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12812: if (@diffs == 0) {
12813: $is_camtasia = 8;
1.1197 raeburn 12814: } else {
12815: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12816: if (@diffs == 0) {
12817: $is_camtasia = 8;
12818: }
1.1164 raeburn 12819: }
1.1067 raeburn 12820: }
12821: }
12822: my $output;
12823: if ($is_camtasia) {
12824: $output = <<"ENDCAM";
12825: <script type="text/javascript" language="Javascript">
12826: // <![CDATA[
12827:
12828: function camtasiaToggle() {
12829: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12830: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12831: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12832: document.getElementById('camtasia_titles').style.display='block';
12833: } else {
12834: document.getElementById('camtasia_titles').style.display='none';
12835: }
12836: }
12837: }
12838: return;
12839: }
12840:
12841: // ]]>
12842: </script>
12843: <p>$lt{'camt'}</p>
12844: ENDCAM
1.1065 raeburn 12845: } else {
1.1067 raeburn 12846: $output = '<p>'.$lt{'this'};
12847: if ($info eq '') {
12848: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12849: } else {
12850: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12851: '<div><pre>'.$info.'</pre></div>';
12852: }
1.1065 raeburn 12853: }
1.1067 raeburn 12854: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12855: my $duplicates;
12856: my $num = 0;
12857: if (ref($dirlist) eq 'ARRAY') {
12858: foreach my $item (@{$dirlist}) {
12859: if (ref($item) eq 'ARRAY') {
12860: if (exists($toplevel{$item->[0]})) {
12861: $duplicates .=
12862: &start_data_table_row().
12863: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12864: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12865: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12866: 'value="1" />'.&mt('Yes').'</label>'.
12867: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12868: '<td>'.$item->[0].'</td>';
12869: if ($item->[2]) {
12870: $duplicates .= '<td>'.&mt('Directory').'</td>';
12871: } else {
12872: $duplicates .= '<td>'.&mt('File').'</td>';
12873: }
12874: $duplicates .= '<td>'.$item->[3].'</td>'.
12875: '<td>'.
12876: &Apache::lonlocal::locallocaltime($item->[4]).
12877: '</td>'.
12878: &end_data_table_row();
12879: $num ++;
12880: }
12881: }
12882: }
12883: }
12884: my $itemcount;
12885: if (@paths > 0) {
12886: $itemcount = scalar(@paths);
12887: } else {
12888: $itemcount = 1;
12889: }
1.1067 raeburn 12890: if ($is_camtasia) {
12891: $output .= $lt{'auto'}.'<br />'.
12892: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12893: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12894: $lt{'yes'}.'</label> <label>'.
12895: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12896: $lt{'no'}.'</label></span><br />'.
12897: '<div id="camtasia_titles" style="display:block">'.
12898: &Apache::lonhtmlcommon::start_pick_box().
12899: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12900: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12901: &Apache::lonhtmlcommon::row_closure().
12902: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12903: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12904: &Apache::lonhtmlcommon::row_closure(1).
12905: &Apache::lonhtmlcommon::end_pick_box().
12906: '</div>';
12907: }
1.1065 raeburn 12908: $output .=
12909: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12910: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12911: "\n";
1.1065 raeburn 12912: if ($duplicates ne '') {
12913: $output .= '<p><span class="LC_warning">'.
12914: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12915: &start_data_table().
12916: &start_data_table_header_row().
12917: '<th>'.&mt('Overwrite?').'</th>'.
12918: '<th>'.&mt('Name').'</th>'.
12919: '<th>'.&mt('Type').'</th>'.
12920: '<th>'.&mt('Size').'</th>'.
12921: '<th>'.&mt('Last modified').'</th>'.
12922: &end_data_table_header_row().
12923: $duplicates.
12924: &end_data_table().
12925: '</p>';
12926: }
1.1067 raeburn 12927: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12928: if (ref($hiddenelements) eq 'HASH') {
12929: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12930: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12931: }
12932: }
12933: $output .= <<"END";
1.1067 raeburn 12934: <br />
1.1053 raeburn 12935: <input type="submit" name="decompress" value="$lt{'extr'}" />
12936: </form>
12937: $noextract
12938: END
12939: return $output;
12940: }
12941:
1.1065 raeburn 12942: sub decompression_utility {
12943: my ($program) = @_;
12944: my @utilities = ('tar','gunzip','bunzip2','unzip');
12945: my $location;
12946: if (grep(/^\Q$program\E$/,@utilities)) {
12947: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12948: '/usr/sbin/') {
12949: if (-x $dir.$program) {
12950: $location = $dir.$program;
12951: last;
12952: }
12953: }
12954: }
12955: return $location;
12956: }
12957:
12958: sub list_archive_contents {
12959: my ($file,$pathsref) = @_;
12960: my (@cmd,$output);
12961: my $needsregexp;
12962: if ($file =~ /\.zip$/) {
12963: @cmd = (&decompression_utility('unzip'),"-l");
12964: $needsregexp = 1;
12965: } elsif (($file =~ m/\.tar\.gz$/) ||
12966: ($file =~ /\.tgz$/)) {
12967: @cmd = (&decompression_utility('tar'),"-ztf");
12968: } elsif ($file =~ /\.tar\.bz2$/) {
12969: @cmd = (&decompression_utility('tar'),"-jtf");
12970: } elsif ($file =~ m|\.tar$|) {
12971: @cmd = (&decompression_utility('tar'),"-tf");
12972: }
12973: if (@cmd) {
12974: undef($!);
12975: undef($@);
12976: if (open(my $fh,"-|", @cmd, $file)) {
12977: while (my $line = <$fh>) {
12978: $output .= $line;
12979: chomp($line);
12980: my $item;
12981: if ($needsregexp) {
12982: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12983: } else {
12984: $item = $line;
12985: }
12986: if ($item ne '') {
12987: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12988: push(@{$pathsref},$item);
12989: }
12990: }
12991: }
12992: close($fh);
12993: }
12994: }
12995: return $output;
12996: }
12997:
1.1053 raeburn 12998: sub decompress_uploaded_file {
12999: my ($file,$dir) = @_;
13000: &Apache::lonnet::appenv({'cgi.file' => $file});
13001: &Apache::lonnet::appenv({'cgi.dir' => $dir});
13002: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
13003: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
13004: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
13005: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
13006: my $decompressed = $env{'cgi.decompressed'};
13007: &Apache::lonnet::delenv('cgi.file');
13008: &Apache::lonnet::delenv('cgi.dir');
13009: &Apache::lonnet::delenv('cgi.decompressed');
13010: return ($decompressed,$result);
13011: }
13012:
1.1055 raeburn 13013: sub process_decompression {
13014: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 13015: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
13016: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13017: &mt('Unexpected file path.').'</p>'."\n";
13018: }
13019: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
13020: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13021: &mt('Unexpected course context.').'</p>'."\n";
13022: }
1.1293 raeburn 13023: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 13024: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13025: &mt('Filename contained unexpected characters.').'</p>'."\n";
13026: }
1.1055 raeburn 13027: my ($dir,$error,$warning,$output);
1.1180 raeburn 13028: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 13029: $error = &mt('Filename not a supported archive file type.').
13030: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 13031: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
13032: } else {
13033: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13034: if ($docuhome eq 'no_host') {
13035: $error = &mt('Could not determine home server for course.');
13036: } else {
13037: my @ids=&Apache::lonnet::current_machine_ids();
13038: my $currdir = "$dir_root/$destination";
13039: if (grep(/^\Q$docuhome\E$/,@ids)) {
13040: $dir = &LONCAPA::propath($docudom,$docuname).
13041: "$dir_root/$destination";
13042: } else {
13043: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
13044: "$dir_root/$docudom/$docuname/$destination";
13045: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
13046: $error = &mt('Archive file not found.');
13047: }
13048: }
1.1065 raeburn 13049: my (@to_overwrite,@to_skip);
13050: if ($env{'form.archive_overwrite_total'} > 0) {
13051: my $total = $env{'form.archive_overwrite_total'};
13052: for (my $i=0; $i<$total; $i++) {
13053: if ($env{'form.archive_overwrite_'.$i} == 1) {
13054: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
13055: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
13056: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
13057: }
13058: }
13059: }
13060: my $numskip = scalar(@to_skip);
1.1292 raeburn 13061: my $numoverwrite = scalar(@to_overwrite);
13062: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 13063: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
13064: } elsif ($dir eq '') {
1.1055 raeburn 13065: $error = &mt('Directory containing archive file unavailable.');
13066: } elsif (!$error) {
1.1065 raeburn 13067: my ($decompressed,$display);
1.1292 raeburn 13068: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 13069: my $tempdir = time.'_'.$$.int(rand(10000));
13070: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 13071: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
13072: ($decompressed,$display) =
13073: &decompress_uploaded_file($file,"$dir/$tempdir");
13074: foreach my $item (@to_skip) {
13075: if (($item ne '') && ($item !~ /\.\./)) {
13076: if (-f "$dir/$tempdir/$item") {
13077: unlink("$dir/$tempdir/$item");
13078: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 13079: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 13080: }
13081: }
13082: }
13083: foreach my $item (@to_overwrite) {
13084: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
13085: if (($item ne '') && ($item !~ /\.\./)) {
13086: if (-f "$dir/$item") {
13087: unlink("$dir/$item");
13088: } elsif (-d "$dir/$item") {
1.1300 raeburn 13089: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 13090: }
13091: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
13092: }
1.1065 raeburn 13093: }
13094: }
1.1292 raeburn 13095: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 13096: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 13097: }
1.1065 raeburn 13098: }
13099: } else {
13100: ($decompressed,$display) =
13101: &decompress_uploaded_file($file,$dir);
13102: }
1.1055 raeburn 13103: if ($decompressed eq 'ok') {
1.1065 raeburn 13104: $output = '<p class="LC_info">'.
13105: &mt('Files extracted successfully from archive.').
13106: '</p>'."\n";
1.1055 raeburn 13107: my ($warning,$result,@contents);
13108: my ($newdirlistref,$newlisterror) =
13109: &Apache::lonnet::dirlist($currdir,$docudom,
13110: $docuname,1);
13111: my (%is_dir,%changes,@newitems);
13112: my $dirptr = 16384;
1.1065 raeburn 13113: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 13114: foreach my $dir_line (@{$newdirlistref}) {
13115: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 13116: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 13117: push(@newitems,$item);
13118: if ($dirptr&$testdir) {
13119: $is_dir{$item} = 1;
13120: }
13121: $changes{$item} = 1;
13122: }
13123: }
13124: }
13125: if (keys(%changes) > 0) {
13126: foreach my $item (sort(@newitems)) {
13127: if ($changes{$item}) {
13128: push(@contents,$item);
13129: }
13130: }
13131: }
13132: if (@contents > 0) {
1.1067 raeburn 13133: my $wantform;
13134: unless ($env{'form.autoextract_camtasia'}) {
13135: $wantform = 1;
13136: }
1.1056 raeburn 13137: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 13138: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13139: $currdir,\%is_dir,
13140: \%children,\%parent,
1.1056 raeburn 13141: \@contents,\%dirorder,
13142: \%titles,$wantform);
1.1055 raeburn 13143: if ($datatable ne '') {
13144: $output .= &archive_options_form('decompressed',$datatable,
13145: $count,$hiddenelem);
1.1065 raeburn 13146: my $startcount = 6;
1.1055 raeburn 13147: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13148: \%titles,\%children);
1.1055 raeburn 13149: }
1.1067 raeburn 13150: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 13151: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13152: my %displayed;
13153: my $total = 1;
13154: $env{'form.archive_directory'} = [];
13155: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13156: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13157: $path =~ s{/$}{};
13158: my $item;
13159: if ($path ne '') {
13160: $item = "$path/$titles{$i}";
13161: } else {
13162: $item = $titles{$i};
13163: }
13164: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13165: if ($item eq $contents[0]) {
13166: push(@{$env{'form.archive_directory'}},$i);
13167: $env{'form.archive_'.$i} = 'display';
13168: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13169: $displayed{'folder'} = $i;
1.1164 raeburn 13170: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13171: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13172: $env{'form.archive_'.$i} = 'display';
13173: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13174: $displayed{'web'} = $i;
13175: } else {
1.1164 raeburn 13176: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13177: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13178: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13179: push(@{$env{'form.archive_directory'}},$i);
13180: }
13181: $env{'form.archive_'.$i} = 'dependency';
13182: }
13183: $total ++;
13184: }
13185: for (my $i=1; $i<$total; $i++) {
13186: next if ($i == $displayed{'web'});
13187: next if ($i == $displayed{'folder'});
13188: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13189: }
13190: $env{'form.phase'} = 'decompress_cleanup';
13191: $env{'form.archivedelete'} = 1;
13192: $env{'form.archive_count'} = $total-1;
13193: $output .=
13194: &process_extracted_files('coursedocs',$docudom,
13195: $docuname,$destination,
13196: $dir_root,$hiddenelem);
13197: }
1.1055 raeburn 13198: } else {
13199: $warning = &mt('No new items extracted from archive file.');
13200: }
13201: } else {
13202: $output = $display;
13203: $error = &mt('An error occurred during extraction from the archive file.');
13204: }
13205: }
13206: }
13207: }
13208: if ($error) {
13209: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13210: $error.'</p>'."\n";
13211: }
13212: if ($warning) {
13213: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13214: }
13215: return $output;
13216: }
13217:
13218: sub get_extracted {
1.1056 raeburn 13219: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13220: $titles,$wantform) = @_;
1.1055 raeburn 13221: my $count = 0;
13222: my $depth = 0;
13223: my $datatable;
1.1056 raeburn 13224: my @hierarchy;
1.1055 raeburn 13225: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13226: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13227: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13228: foreach my $item (@{$contents}) {
13229: $count ++;
1.1056 raeburn 13230: @{$dirorder->{$count}} = @hierarchy;
13231: $titles->{$count} = $item;
1.1055 raeburn 13232: &archive_hierarchy($depth,$count,$parent,$children);
13233: if ($wantform) {
13234: $datatable .= &archive_row($is_dir->{$item},$item,
13235: $currdir,$depth,$count);
13236: }
13237: if ($is_dir->{$item}) {
13238: $depth ++;
1.1056 raeburn 13239: push(@hierarchy,$count);
13240: $parent->{$depth} = $count;
1.1055 raeburn 13241: $datatable .=
13242: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13243: \$depth,\$count,\@hierarchy,$dirorder,
13244: $children,$parent,$titles,$wantform);
1.1055 raeburn 13245: $depth --;
1.1056 raeburn 13246: pop(@hierarchy);
1.1055 raeburn 13247: }
13248: }
13249: return ($count,$datatable);
13250: }
13251:
13252: sub recurse_extracted_archive {
1.1056 raeburn 13253: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13254: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13255: my $result='';
1.1056 raeburn 13256: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13257: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13258: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13259: return $result;
13260: }
13261: my $dirptr = 16384;
13262: my ($newdirlistref,$newlisterror) =
13263: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13264: if (ref($newdirlistref) eq 'ARRAY') {
13265: foreach my $dir_line (@{$newdirlistref}) {
13266: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13267: unless ($item =~ /^\.+$/) {
13268: $$count ++;
1.1056 raeburn 13269: @{$dirorder->{$$count}} = @{$hierarchy};
13270: $titles->{$$count} = $item;
1.1055 raeburn 13271: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13272:
1.1055 raeburn 13273: my $is_dir;
13274: if ($dirptr&$testdir) {
13275: $is_dir = 1;
13276: }
13277: if ($wantform) {
13278: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13279: }
13280: if ($is_dir) {
13281: $$depth ++;
1.1056 raeburn 13282: push(@{$hierarchy},$$count);
13283: $parent->{$$depth} = $$count;
1.1055 raeburn 13284: $result .=
13285: &recurse_extracted_archive("$currdir/$item",$docudom,
13286: $docuname,$depth,$count,
1.1056 raeburn 13287: $hierarchy,$dirorder,$children,
13288: $parent,$titles,$wantform);
1.1055 raeburn 13289: $$depth --;
1.1056 raeburn 13290: pop(@{$hierarchy});
1.1055 raeburn 13291: }
13292: }
13293: }
13294: }
13295: return $result;
13296: }
13297:
13298: sub archive_hierarchy {
13299: my ($depth,$count,$parent,$children) =@_;
13300: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13301: if (exists($parent->{$depth})) {
13302: $children->{$parent->{$depth}} .= $count.':';
13303: }
13304: }
13305: return;
13306: }
13307:
13308: sub archive_row {
13309: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13310: my ($name) = ($item =~ m{([^/]+)$});
13311: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13312: 'display' => 'Add as file',
1.1055 raeburn 13313: 'dependency' => 'Include as dependency',
13314: 'discard' => 'Discard',
13315: );
13316: if ($is_dir) {
1.1059 raeburn 13317: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13318: }
1.1056 raeburn 13319: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13320: my $offset = 0;
1.1055 raeburn 13321: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13322: $offset ++;
1.1065 raeburn 13323: if ($action ne 'display') {
13324: $offset ++;
13325: }
1.1055 raeburn 13326: $output .= '<td><span class="LC_nobreak">'.
13327: '<label><input type="radio" name="archive_'.$count.
13328: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13329: my $text = $choices{$action};
13330: if ($is_dir) {
13331: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13332: if ($action eq 'display') {
1.1059 raeburn 13333: $text = &mt('Add as folder');
1.1055 raeburn 13334: }
1.1056 raeburn 13335: } else {
13336: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13337:
13338: }
13339: $output .= ' /> '.$choices{$action}.'</label></span>';
13340: if ($action eq 'dependency') {
13341: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13342: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13343: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13344: '<option value=""></option>'."\n".
13345: '</select>'."\n".
13346: '</div>';
1.1059 raeburn 13347: } elsif ($action eq 'display') {
13348: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13349: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13350: '</div>';
1.1055 raeburn 13351: }
1.1056 raeburn 13352: $output .= '</td>';
1.1055 raeburn 13353: }
13354: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13355: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13356: for (my $i=0; $i<$depth; $i++) {
13357: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13358: }
13359: if ($is_dir) {
13360: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13361: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13362: } else {
13363: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13364: }
13365: $output .= ' '.$name.'</td>'."\n".
13366: &end_data_table_row();
13367: return $output;
13368: }
13369:
13370: sub archive_options_form {
1.1065 raeburn 13371: my ($form,$display,$count,$hiddenelem) = @_;
13372: my %lt = &Apache::lonlocal::texthash(
13373: perm => 'Permanently remove archive file?',
13374: hows => 'How should each extracted item be incorporated in the course?',
13375: cont => 'Content actions for all',
13376: addf => 'Add as folder/file',
13377: incd => 'Include as dependency for a displayed file',
13378: disc => 'Discard',
13379: no => 'No',
13380: yes => 'Yes',
13381: save => 'Save',
13382: );
13383: my $output = <<"END";
13384: <form name="$form" method="post" action="">
13385: <p><span class="LC_nobreak">$lt{'perm'}
13386: <label>
13387: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13388: </label>
13389:
13390: <label>
13391: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13392: </span>
13393: </p>
13394: <input type="hidden" name="phase" value="decompress_cleanup" />
13395: <br />$lt{'hows'}
13396: <div class="LC_columnSection">
13397: <fieldset>
13398: <legend>$lt{'cont'}</legend>
13399: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13400: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13401: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13402: </fieldset>
13403: </div>
13404: END
13405: return $output.
1.1055 raeburn 13406: &start_data_table()."\n".
1.1065 raeburn 13407: $display."\n".
1.1055 raeburn 13408: &end_data_table()."\n".
13409: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13410: $hiddenelem.
1.1065 raeburn 13411: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13412: '</form>';
13413: }
13414:
13415: sub archive_javascript {
1.1056 raeburn 13416: my ($startcount,$numitems,$titles,$children) = @_;
13417: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13418: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13419: my $scripttag = <<START;
13420: <script type="text/javascript">
13421: // <![CDATA[
13422:
13423: function checkAll(form,prefix) {
13424: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13425: for (var i=0; i < form.elements.length; i++) {
13426: var id = form.elements[i].id;
13427: if ((id != '') && (id != undefined)) {
13428: if (idstr.test(id)) {
13429: if (form.elements[i].type == 'radio') {
13430: form.elements[i].checked = true;
1.1056 raeburn 13431: var nostart = i-$startcount;
1.1059 raeburn 13432: var offset = nostart%7;
13433: var count = (nostart-offset)/7;
1.1056 raeburn 13434: dependencyCheck(form,count,offset);
1.1055 raeburn 13435: }
13436: }
13437: }
13438: }
13439: }
13440:
13441: function propagateCheck(form,count) {
13442: if (count > 0) {
1.1059 raeburn 13443: var startelement = $startcount + ((count-1) * 7);
13444: for (var j=1; j<6; j++) {
13445: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13446: var item = startelement + j;
13447: if (form.elements[item].type == 'radio') {
13448: if (form.elements[item].checked) {
13449: containerCheck(form,count,j);
13450: break;
13451: }
1.1055 raeburn 13452: }
13453: }
13454: }
13455: }
13456: }
13457:
13458: numitems = $numitems
1.1056 raeburn 13459: var titles = new Array(numitems);
13460: var parents = new Array(numitems);
1.1055 raeburn 13461: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13462: parents[i] = new Array;
1.1055 raeburn 13463: }
1.1059 raeburn 13464: var maintitle = '$maintitle';
1.1055 raeburn 13465:
13466: START
13467:
1.1056 raeburn 13468: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13469: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13470: for (my $i=0; $i<@contents; $i ++) {
13471: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13472: }
13473: }
13474:
1.1056 raeburn 13475: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13476: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13477: }
13478:
1.1055 raeburn 13479: $scripttag .= <<END;
13480:
13481: function containerCheck(form,count,offset) {
13482: if (count > 0) {
1.1056 raeburn 13483: dependencyCheck(form,count,offset);
1.1059 raeburn 13484: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13485: form.elements[item].checked = true;
13486: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13487: if (parents[count].length > 0) {
13488: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13489: containerCheck(form,parents[count][j],offset);
13490: }
13491: }
13492: }
13493: }
13494: }
13495:
13496: function dependencyCheck(form,count,offset) {
13497: if (count > 0) {
1.1059 raeburn 13498: var chosen = (offset+$startcount)+7*(count-1);
13499: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13500: var currtype = form.elements[depitem].type;
13501: if (form.elements[chosen].value == 'dependency') {
13502: document.getElementById('arc_depon_'+count).style.display='block';
13503: form.elements[depitem].options.length = 0;
13504: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13505: for (var i=1; i<=numitems; i++) {
13506: if (i == count) {
13507: continue;
13508: }
1.1059 raeburn 13509: var startelement = $startcount + (i-1) * 7;
13510: for (var j=1; j<6; j++) {
13511: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13512: var item = startelement + j;
13513: if (form.elements[item].type == 'radio') {
13514: if (form.elements[item].checked) {
13515: if (form.elements[item].value == 'display') {
13516: var n = form.elements[depitem].options.length;
13517: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13518: }
13519: }
13520: }
13521: }
13522: }
13523: }
13524: } else {
13525: document.getElementById('arc_depon_'+count).style.display='none';
13526: form.elements[depitem].options.length = 0;
13527: form.elements[depitem].options[0] = new Option('Select','',true,true);
13528: }
1.1059 raeburn 13529: titleCheck(form,count,offset);
1.1056 raeburn 13530: }
13531: }
13532:
13533: function propagateSelect(form,count,offset) {
13534: if (count > 0) {
1.1065 raeburn 13535: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13536: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13537: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13538: if (parents[count].length > 0) {
13539: for (var j=0; j<parents[count].length; j++) {
13540: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13541: }
13542: }
13543: }
13544: }
13545: }
1.1056 raeburn 13546:
13547: function containerSelect(form,count,offset,picked) {
13548: if (count > 0) {
1.1065 raeburn 13549: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13550: if (form.elements[item].type == 'radio') {
13551: if (form.elements[item].value == 'dependency') {
13552: if (form.elements[item+1].type == 'select-one') {
13553: for (var i=0; i<form.elements[item+1].options.length; i++) {
13554: if (form.elements[item+1].options[i].value == picked) {
13555: form.elements[item+1].selectedIndex = i;
13556: break;
13557: }
13558: }
13559: }
13560: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13561: if (parents[count].length > 0) {
13562: for (var j=0; j<parents[count].length; j++) {
13563: containerSelect(form,parents[count][j],offset,picked);
13564: }
13565: }
13566: }
13567: }
13568: }
13569: }
13570: }
13571:
1.1059 raeburn 13572: function titleCheck(form,count,offset) {
13573: if (count > 0) {
13574: var chosen = (offset+$startcount)+7*(count-1);
13575: var depitem = $startcount + ((count-1) * 7) + 2;
13576: var currtype = form.elements[depitem].type;
13577: if (form.elements[chosen].value == 'display') {
13578: document.getElementById('arc_title_'+count).style.display='block';
13579: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13580: document.getElementById('archive_title_'+count).value=maintitle;
13581: }
13582: } else {
13583: document.getElementById('arc_title_'+count).style.display='none';
13584: if (currtype == 'text') {
13585: document.getElementById('archive_title_'+count).value='';
13586: }
13587: }
13588: }
13589: return;
13590: }
13591:
1.1055 raeburn 13592: // ]]>
13593: </script>
13594: END
13595: return $scripttag;
13596: }
13597:
13598: sub process_extracted_files {
1.1067 raeburn 13599: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13600: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 13601: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13602: my @ids=&Apache::lonnet::current_machine_ids();
13603: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13604: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13605: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13606: if (grep(/^\Q$docuhome\E$/,@ids)) {
13607: $prefix = &LONCAPA::propath($docudom,$docuname);
13608: $pathtocheck = "$dir_root/$destination";
13609: $dir = $dir_root;
13610: $ishome = 1;
13611: } else {
13612: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13613: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 13614: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13615: }
13616: my $currdir = "$dir_root/$destination";
13617: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13618: if ($env{'form.folderpath'}) {
13619: my @items = split('&',$env{'form.folderpath'});
13620: $folders{'0'} = $items[-2];
1.1099 raeburn 13621: if ($env{'form.folderpath'} =~ /\:1$/) {
13622: $containers{'0'}='page';
13623: } else {
13624: $containers{'0'}='sequence';
13625: }
1.1055 raeburn 13626: }
13627: my @archdirs = &get_env_multiple('form.archive_directory');
13628: if ($numitems) {
13629: for (my $i=1; $i<=$numitems; $i++) {
13630: my $path = $env{'form.archive_content_'.$i};
13631: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13632: my $item = $1;
13633: $toplevelitems{$item} = $i;
13634: if (grep(/^\Q$i\E$/,@archdirs)) {
13635: $is_dir{$item} = 1;
13636: }
13637: }
13638: }
13639: }
1.1067 raeburn 13640: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13641: if (keys(%toplevelitems) > 0) {
13642: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13643: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13644: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13645: }
1.1066 raeburn 13646: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13647: if ($numitems) {
13648: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13649: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13650: my $path = $env{'form.archive_content_'.$i};
13651: if ($path =~ /^\Q$pathtocheck\E/) {
13652: if ($env{'form.archive_'.$i} eq 'discard') {
13653: if ($prefix ne '' && $path ne '') {
13654: if (-e $prefix.$path) {
1.1066 raeburn 13655: if ((@archdirs > 0) &&
13656: (grep(/^\Q$i\E$/,@archdirs))) {
13657: $todeletedir{$prefix.$path} = 1;
13658: } else {
13659: $todelete{$prefix.$path} = 1;
13660: }
1.1055 raeburn 13661: }
13662: }
13663: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13664: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13665: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13666: $docstitle = $env{'form.archive_title_'.$i};
13667: if ($docstitle eq '') {
13668: $docstitle = $title;
13669: }
1.1055 raeburn 13670: $outer = 0;
1.1056 raeburn 13671: if (ref($dirorder{$i}) eq 'ARRAY') {
13672: if (@{$dirorder{$i}} > 0) {
13673: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13674: if ($env{'form.archive_'.$item} eq 'display') {
13675: $outer = $item;
13676: last;
13677: }
13678: }
13679: }
13680: }
13681: my ($errtext,$fatal) =
13682: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13683: '/'.$folders{$outer}.'.'.
13684: $containers{$outer});
13685: next if ($fatal);
13686: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13687: if ($context eq 'coursedocs') {
1.1056 raeburn 13688: $mapinner{$i} = time;
1.1055 raeburn 13689: $folders{$i} = 'default_'.$mapinner{$i};
13690: $containers{$i} = 'sequence';
13691: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13692: $folders{$i}.'.'.$containers{$i};
13693: my $newidx = &LONCAPA::map::getresidx();
13694: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13695: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13696: push(@LONCAPA::map::order,$newidx);
13697: my ($outtext,$errtext) =
13698: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13699: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13700: '.'.$containers{$outer},1,1);
1.1056 raeburn 13701: $newseqid{$i} = $newidx;
1.1067 raeburn 13702: unless ($errtext) {
1.1294 raeburn 13703: $result .= '<li>'.&mt('Folder: [_1] added to course',
13704: &HTML::Entities::encode($docstitle,'<>&"')).
13705: '</li>'."\n";
1.1067 raeburn 13706: }
1.1055 raeburn 13707: }
13708: } else {
13709: if ($context eq 'coursedocs') {
13710: my $newidx=&LONCAPA::map::getresidx();
13711: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13712: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13713: $title;
1.1294 raeburn 13714: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
13715: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13716: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13717: }
13718: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13719: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13720: }
13721: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13722: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13723: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13724: unless ($ishome) {
13725: my $fetch = "$newdest{$i}/$title";
13726: $fetch =~ s/^\Q$prefix$dir\E//;
13727: $prompttofetch{$fetch} = 1;
13728: }
1.1292 raeburn 13729: }
1.1067 raeburn 13730: }
1.1294 raeburn 13731: $LONCAPA::map::resources[$newidx]=
13732: $docstitle.':'.$url.':false:normal:res';
13733: push(@LONCAPA::map::order, $newidx);
13734: my ($outtext,$errtext)=
13735: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13736: $docuname.'/'.$folders{$outer}.
13737: '.'.$containers{$outer},1,1);
13738: unless ($errtext) {
13739: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13740: $result .= '<li>'.&mt('File: [_1] added to course',
13741: &HTML::Entities::encode($docstitle,'<>&"')).
13742: '</li>'."\n";
13743: }
1.1067 raeburn 13744: }
1.1294 raeburn 13745: } else {
13746: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13747: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 13748: }
1.1055 raeburn 13749: }
13750: }
1.1086 raeburn 13751: }
13752: } else {
1.1294 raeburn 13753: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13754: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 13755: }
13756: }
13757: for (my $i=1; $i<=$numitems; $i++) {
13758: next unless ($env{'form.archive_'.$i} eq 'dependency');
13759: my $path = $env{'form.archive_content_'.$i};
13760: if ($path =~ /^\Q$pathtocheck\E/) {
13761: my ($title) = ($path =~ m{/([^/]+)$});
13762: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13763: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13764: if (ref($dirorder{$i}) eq 'ARRAY') {
13765: my ($itemidx,$fullpath,$relpath);
13766: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13767: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13768: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13769: if ($dirorder{$i}->[$j] eq $container) {
13770: $itemidx = $j;
1.1056 raeburn 13771: }
13772: }
1.1086 raeburn 13773: }
13774: if ($itemidx eq '') {
13775: $itemidx = 0;
13776: }
13777: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13778: if ($mapinner{$referrer{$i}}) {
13779: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13780: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13781: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13782: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13783: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13784: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13785: if (!-e $fullpath) {
13786: mkdir($fullpath,0755);
1.1056 raeburn 13787: }
13788: }
1.1086 raeburn 13789: } else {
13790: last;
1.1056 raeburn 13791: }
1.1086 raeburn 13792: }
13793: }
13794: } elsif ($newdest{$referrer{$i}}) {
13795: $fullpath = $newdest{$referrer{$i}};
13796: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13797: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13798: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13799: last;
13800: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13801: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13802: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13803: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13804: if (!-e $fullpath) {
13805: mkdir($fullpath,0755);
1.1056 raeburn 13806: }
13807: }
1.1086 raeburn 13808: } else {
13809: last;
1.1056 raeburn 13810: }
1.1055 raeburn 13811: }
13812: }
1.1086 raeburn 13813: if ($fullpath ne '') {
13814: if (-e "$prefix$path") {
1.1292 raeburn 13815: unless (rename("$prefix$path","$fullpath/$title")) {
13816: $warning .= &mt('Failed to rename dependency').'<br />';
13817: }
1.1086 raeburn 13818: }
13819: if (-e "$fullpath/$title") {
13820: my $showpath;
13821: if ($relpath ne '') {
13822: $showpath = "$relpath/$title";
13823: } else {
13824: $showpath = "/$title";
13825: }
1.1294 raeburn 13826: $result .= '<li>'.&mt('[_1] included as a dependency',
13827: &HTML::Entities::encode($showpath,'<>&"')).
13828: '</li>'."\n";
1.1292 raeburn 13829: unless ($ishome) {
13830: my $fetch = "$fullpath/$title";
13831: $fetch =~ s/^\Q$prefix$dir\E//;
13832: $prompttofetch{$fetch} = 1;
13833: }
1.1086 raeburn 13834: }
13835: }
1.1055 raeburn 13836: }
1.1086 raeburn 13837: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13838: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 13839: &HTML::Entities::encode($path,'<>&"'),
13840: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13841: '<br />';
1.1055 raeburn 13842: }
13843: } else {
1.1294 raeburn 13844: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 13845: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13846: }
13847: }
13848: if (keys(%todelete)) {
13849: foreach my $key (keys(%todelete)) {
13850: unlink($key);
1.1066 raeburn 13851: }
13852: }
13853: if (keys(%todeletedir)) {
13854: foreach my $key (keys(%todeletedir)) {
13855: rmdir($key);
13856: }
13857: }
13858: foreach my $dir (sort(keys(%is_dir))) {
13859: if (($pathtocheck ne '') && ($dir ne '')) {
13860: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13861: }
13862: }
1.1067 raeburn 13863: if ($result ne '') {
13864: $output .= '<ul>'."\n".
13865: $result."\n".
13866: '</ul>';
13867: }
13868: unless ($ishome) {
13869: my $replicationfail;
13870: foreach my $item (keys(%prompttofetch)) {
13871: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13872: unless ($fetchresult eq 'ok') {
13873: $replicationfail .= '<li>'.$item.'</li>'."\n";
13874: }
13875: }
13876: if ($replicationfail) {
13877: $output .= '<p class="LC_error">'.
13878: &mt('Course home server failed to retrieve:').'<ul>'.
13879: $replicationfail.
13880: '</ul></p>';
13881: }
13882: }
1.1055 raeburn 13883: } else {
13884: $warning = &mt('No items found in archive.');
13885: }
13886: if ($error) {
13887: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13888: $error.'</p>'."\n";
13889: }
13890: if ($warning) {
13891: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13892: }
13893: return $output;
13894: }
13895:
1.1066 raeburn 13896: sub cleanup_empty_dirs {
13897: my ($path) = @_;
13898: if (($path ne '') && (-d $path)) {
13899: if (opendir(my $dirh,$path)) {
13900: my @dircontents = grep(!/^\./,readdir($dirh));
13901: my $numitems = 0;
13902: foreach my $item (@dircontents) {
13903: if (-d "$path/$item") {
1.1111 raeburn 13904: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13905: if (-e "$path/$item") {
13906: $numitems ++;
13907: }
13908: } else {
13909: $numitems ++;
13910: }
13911: }
13912: if ($numitems == 0) {
13913: rmdir($path);
13914: }
13915: closedir($dirh);
13916: }
13917: }
13918: return;
13919: }
13920:
1.41 ng 13921: =pod
1.45 matthew 13922:
1.1162 raeburn 13923: =item * &get_folder_hierarchy()
1.1068 raeburn 13924:
13925: Provides hierarchy of names of folders/sub-folders containing the current
13926: item,
13927:
13928: Inputs: 3
13929: - $navmap - navmaps object
13930:
13931: - $map - url for map (either the trigger itself, or map containing
13932: the resource, which is the trigger).
13933:
13934: - $showitem - 1 => show title for map itself; 0 => do not show.
13935:
13936: Outputs: 1 @pathitems - array of folder/subfolder names.
13937:
13938: =cut
13939:
13940: sub get_folder_hierarchy {
13941: my ($navmap,$map,$showitem) = @_;
13942: my @pathitems;
13943: if (ref($navmap)) {
13944: my $mapres = $navmap->getResourceByUrl($map);
13945: if (ref($mapres)) {
13946: my $pcslist = $mapres->map_hierarchy();
13947: if ($pcslist ne '') {
13948: my @pcs = split(/,/,$pcslist);
13949: foreach my $pc (@pcs) {
13950: if ($pc == 1) {
1.1129 raeburn 13951: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13952: } else {
13953: my $res = $navmap->getByMapPc($pc);
13954: if (ref($res)) {
13955: my $title = $res->compTitle();
13956: $title =~ s/\W+/_/g;
13957: if ($title ne '') {
13958: push(@pathitems,$title);
13959: }
13960: }
13961: }
13962: }
13963: }
1.1071 raeburn 13964: if ($showitem) {
13965: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 13966: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13967: } else {
13968: my $maptitle = $mapres->compTitle();
13969: $maptitle =~ s/\W+/_/g;
13970: if ($maptitle ne '') {
13971: push(@pathitems,$maptitle);
13972: }
1.1068 raeburn 13973: }
13974: }
13975: }
13976: }
13977: return @pathitems;
13978: }
13979:
13980: =pod
13981:
1.1015 raeburn 13982: =item * &get_turnedin_filepath()
13983:
13984: Determines path in a user's portfolio file for storage of files uploaded
13985: to a specific essayresponse or dropbox item.
13986:
13987: Inputs: 3 required + 1 optional.
13988: $symb is symb for resource, $uname and $udom are for current user (required).
13989: $caller is optional (can be "submission", if routine is called when storing
13990: an upoaded file when "Submit Answer" button was pressed).
13991:
13992: Returns array containing $path and $multiresp.
13993: $path is path in portfolio. $multiresp is 1 if this resource contains more
13994: than one file upload item. Callers of routine should append partid as a
13995: subdirectory to $path in cases where $multiresp is 1.
13996:
13997: Called by: homework/essayresponse.pm and homework/structuretags.pm
13998:
13999: =cut
14000:
14001: sub get_turnedin_filepath {
14002: my ($symb,$uname,$udom,$caller) = @_;
14003: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
14004: my $turnindir;
14005: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
14006: $turnindir = $userhash{'turnindir'};
14007: my ($path,$multiresp);
14008: if ($turnindir eq '') {
14009: if ($caller eq 'submission') {
14010: $turnindir = &mt('turned in');
14011: $turnindir =~ s/\W+/_/g;
14012: my %newhash = (
14013: 'turnindir' => $turnindir,
14014: );
14015: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
14016: }
14017: }
14018: if ($turnindir ne '') {
14019: $path = '/'.$turnindir.'/';
14020: my ($multipart,$turnin,@pathitems);
14021: my $navmap = Apache::lonnavmaps::navmap->new();
14022: if (defined($navmap)) {
14023: my $mapres = $navmap->getResourceByUrl($map);
14024: if (ref($mapres)) {
14025: my $pcslist = $mapres->map_hierarchy();
14026: if ($pcslist ne '') {
14027: foreach my $pc (split(/,/,$pcslist)) {
14028: my $res = $navmap->getByMapPc($pc);
14029: if (ref($res)) {
14030: my $title = $res->compTitle();
14031: $title =~ s/\W+/_/g;
14032: if ($title ne '') {
1.1149 raeburn 14033: if (($pc > 1) && (length($title) > 12)) {
14034: $title = substr($title,0,12);
14035: }
1.1015 raeburn 14036: push(@pathitems,$title);
14037: }
14038: }
14039: }
14040: }
14041: my $maptitle = $mapres->compTitle();
14042: $maptitle =~ s/\W+/_/g;
14043: if ($maptitle ne '') {
1.1149 raeburn 14044: if (length($maptitle) > 12) {
14045: $maptitle = substr($maptitle,0,12);
14046: }
1.1015 raeburn 14047: push(@pathitems,$maptitle);
14048: }
14049: unless ($env{'request.state'} eq 'construct') {
14050: my $res = $navmap->getBySymb($symb);
14051: if (ref($res)) {
14052: my $partlist = $res->parts();
14053: my $totaluploads = 0;
14054: if (ref($partlist) eq 'ARRAY') {
14055: foreach my $part (@{$partlist}) {
14056: my @types = $res->responseType($part);
14057: my @ids = $res->responseIds($part);
14058: for (my $i=0; $i < scalar(@ids); $i++) {
14059: if ($types[$i] eq 'essay') {
14060: my $partid = $part.'_'.$ids[$i];
14061: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
14062: $totaluploads ++;
14063: }
14064: }
14065: }
14066: }
14067: if ($totaluploads > 1) {
14068: $multiresp = 1;
14069: }
14070: }
14071: }
14072: }
14073: } else {
14074: return;
14075: }
14076: } else {
14077: return;
14078: }
14079: my $restitle=&Apache::lonnet::gettitle($symb);
14080: $restitle =~ s/\W+/_/g;
14081: if ($restitle eq '') {
14082: $restitle = ($resurl =~ m{/[^/]+$});
14083: if ($restitle eq '') {
14084: $restitle = time;
14085: }
14086: }
1.1149 raeburn 14087: if (length($restitle) > 12) {
14088: $restitle = substr($restitle,0,12);
14089: }
1.1015 raeburn 14090: push(@pathitems,$restitle);
14091: $path .= join('/',@pathitems);
14092: }
14093: return ($path,$multiresp);
14094: }
14095:
14096: =pod
14097:
1.464 albertel 14098: =back
1.41 ng 14099:
1.112 bowersj2 14100: =head1 CSV Upload/Handling functions
1.38 albertel 14101:
1.41 ng 14102: =over 4
14103:
1.648 raeburn 14104: =item * &upfile_store($r)
1.41 ng 14105:
14106: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 14107: needs $env{'form.upfile'}
1.41 ng 14108: returns $datatoken to be put into hidden field
14109:
14110: =cut
1.31 albertel 14111:
14112: sub upfile_store {
14113: my $r=shift;
1.258 albertel 14114: $env{'form.upfile'}=~s/\r/\n/gs;
14115: $env{'form.upfile'}=~s/\f/\n/gs;
14116: $env{'form.upfile'}=~s/\n+/\n/gs;
14117: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 14118:
1.1299 raeburn 14119: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
14120: '_enroll_'.$env{'request.course.id'}.'_'.
14121: time.'_'.$$);
14122: return if ($datatoken eq '');
14123:
1.31 albertel 14124: {
1.158 raeburn 14125: my $datafile = $r->dir_config('lonDaemons').
14126: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14127: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 14128: print $fh $env{'form.upfile'};
1.158 raeburn 14129: close($fh);
14130: }
1.31 albertel 14131: }
14132: return $datatoken;
14133: }
14134:
1.56 matthew 14135: =pod
14136:
1.1290 raeburn 14137: =item * &load_tmp_file($r,$datatoken)
1.41 ng 14138:
14139: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 14140: $datatoken is the name to assign to the temporary file.
1.258 albertel 14141: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14142:
14143: =cut
1.31 albertel 14144:
14145: sub load_tmp_file {
1.1290 raeburn 14146: my ($r,$datatoken) = @_;
14147: return if ($datatoken eq '');
1.31 albertel 14148: my @studentdata=();
14149: {
1.158 raeburn 14150: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 14151: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14152: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14153: @studentdata=<$fh>;
14154: close($fh);
14155: }
1.31 albertel 14156: }
1.258 albertel 14157: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14158: }
14159:
1.1290 raeburn 14160: sub valid_datatoken {
14161: my ($datatoken) = @_;
1.1325 raeburn 14162: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1290 raeburn 14163: return $datatoken;
14164: }
14165: return;
14166: }
14167:
1.56 matthew 14168: =pod
14169:
1.648 raeburn 14170: =item * &upfile_record_sep()
1.41 ng 14171:
14172: Separate uploaded file into records
14173: returns array of records,
1.258 albertel 14174: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14175:
14176: =cut
1.31 albertel 14177:
14178: sub upfile_record_sep {
1.258 albertel 14179: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14180: } else {
1.248 albertel 14181: my @records;
1.258 albertel 14182: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14183: if ($line=~/^\s*$/) { next; }
14184: push(@records,$line);
14185: }
14186: return @records;
1.31 albertel 14187: }
14188: }
14189:
1.56 matthew 14190: =pod
14191:
1.648 raeburn 14192: =item * &record_sep($record)
1.41 ng 14193:
1.258 albertel 14194: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14195:
14196: =cut
14197:
1.263 www 14198: sub takeleft {
14199: my $index=shift;
14200: return substr('0000'.$index,-4,4);
14201: }
14202:
1.31 albertel 14203: sub record_sep {
14204: my $record=shift;
14205: my %components=();
1.258 albertel 14206: if ($env{'form.upfiletype'} eq 'xml') {
14207: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14208: my $i=0;
1.356 albertel 14209: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14210: $field=~s/^(\"|\')//;
14211: $field=~s/(\"|\')$//;
1.263 www 14212: $components{&takeleft($i)}=$field;
1.31 albertel 14213: $i++;
14214: }
1.258 albertel 14215: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14216: my $i=0;
1.356 albertel 14217: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14218: $field=~s/^(\"|\')//;
14219: $field=~s/(\"|\')$//;
1.263 www 14220: $components{&takeleft($i)}=$field;
1.31 albertel 14221: $i++;
14222: }
14223: } else {
1.561 www 14224: my $separator=',';
1.480 banghart 14225: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14226: $separator=';';
1.480 banghart 14227: }
1.31 albertel 14228: my $i=0;
1.561 www 14229: # the character we are looking for to indicate the end of a quote or a record
14230: my $looking_for=$separator;
14231: # do not add the characters to the fields
14232: my $ignore=0;
14233: # we just encountered a separator (or the beginning of the record)
14234: my $just_found_separator=1;
14235: # store the field we are working on here
14236: my $field='';
14237: # work our way through all characters in record
14238: foreach my $character ($record=~/(.)/g) {
14239: if ($character eq $looking_for) {
14240: if ($character ne $separator) {
14241: # Found the end of a quote, again looking for separator
14242: $looking_for=$separator;
14243: $ignore=1;
14244: } else {
14245: # Found a separator, store away what we got
14246: $components{&takeleft($i)}=$field;
14247: $i++;
14248: $just_found_separator=1;
14249: $ignore=0;
14250: $field='';
14251: }
14252: next;
14253: }
14254: # single or double quotation marks after a separator indicate beginning of a quote
14255: # we are now looking for the end of the quote and need to ignore separators
14256: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14257: $looking_for=$character;
14258: next;
14259: }
14260: # ignore would be true after we reached the end of a quote
14261: if ($ignore) { next; }
14262: if (($just_found_separator) && ($character=~/\s/)) { next; }
14263: $field.=$character;
14264: $just_found_separator=0;
1.31 albertel 14265: }
1.561 www 14266: # catch the very last entry, since we never encountered the separator
14267: $components{&takeleft($i)}=$field;
1.31 albertel 14268: }
14269: return %components;
14270: }
14271:
1.144 matthew 14272: ######################################################
14273: ######################################################
14274:
1.56 matthew 14275: =pod
14276:
1.648 raeburn 14277: =item * &upfile_select_html()
1.41 ng 14278:
1.144 matthew 14279: Return HTML code to select a file from the users machine and specify
14280: the file type.
1.41 ng 14281:
14282: =cut
14283:
1.144 matthew 14284: ######################################################
14285: ######################################################
1.31 albertel 14286: sub upfile_select_html {
1.144 matthew 14287: my %Types = (
14288: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14289: semisv => &mt('Semicolon separated values'),
1.144 matthew 14290: space => &mt('Space separated'),
14291: tab => &mt('Tabulator separated'),
14292: # xml => &mt('HTML/XML'),
14293: );
14294: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14295: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14296: foreach my $type (sort(keys(%Types))) {
14297: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14298: }
14299: $Str .= "</select>\n";
14300: return $Str;
1.31 albertel 14301: }
14302:
1.301 albertel 14303: sub get_samples {
14304: my ($records,$toget) = @_;
14305: my @samples=({});
14306: my $got=0;
14307: foreach my $rec (@$records) {
14308: my %temp = &record_sep($rec);
14309: if (! grep(/\S/, values(%temp))) { next; }
14310: if (%temp) {
14311: $samples[$got]=\%temp;
14312: $got++;
14313: if ($got == $toget) { last; }
14314: }
14315: }
14316: return \@samples;
14317: }
14318:
1.144 matthew 14319: ######################################################
14320: ######################################################
14321:
1.56 matthew 14322: =pod
14323:
1.648 raeburn 14324: =item * &csv_print_samples($r,$records)
1.41 ng 14325:
14326: Prints a table of sample values from each column uploaded $r is an
14327: Apache Request ref, $records is an arrayref from
14328: &Apache::loncommon::upfile_record_sep
14329:
14330: =cut
14331:
1.144 matthew 14332: ######################################################
14333: ######################################################
1.31 albertel 14334: sub csv_print_samples {
14335: my ($r,$records) = @_;
1.662 bisitz 14336: my $samples = &get_samples($records,5);
1.301 albertel 14337:
1.594 raeburn 14338: $r->print(&mt('Samples').'<br />'.&start_data_table().
14339: &start_data_table_header_row());
1.356 albertel 14340: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14341: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14342: $r->print(&end_data_table_header_row());
1.301 albertel 14343: foreach my $hash (@$samples) {
1.594 raeburn 14344: $r->print(&start_data_table_row());
1.356 albertel 14345: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14346: $r->print('<td>');
1.356 albertel 14347: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14348: $r->print('</td>');
14349: }
1.594 raeburn 14350: $r->print(&end_data_table_row());
1.31 albertel 14351: }
1.594 raeburn 14352: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14353: }
14354:
1.144 matthew 14355: ######################################################
14356: ######################################################
14357:
1.56 matthew 14358: =pod
14359:
1.648 raeburn 14360: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14361:
14362: Prints a table to create associations between values and table columns.
1.144 matthew 14363:
1.41 ng 14364: $r is an Apache Request ref,
14365: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14366: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14367:
14368: =cut
14369:
1.144 matthew 14370: ######################################################
14371: ######################################################
1.31 albertel 14372: sub csv_print_select_table {
14373: my ($r,$records,$d) = @_;
1.301 albertel 14374: my $i=0;
14375: my $samples = &get_samples($records,1);
1.144 matthew 14376: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14377: &start_data_table().&start_data_table_header_row().
1.144 matthew 14378: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14379: '<th>'.&mt('Column').'</th>'.
14380: &end_data_table_header_row()."\n");
1.356 albertel 14381: foreach my $array_ref (@$d) {
14382: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14383: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14384:
1.875 bisitz 14385: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14386: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14387: $r->print('<option value="none"></option>');
1.356 albertel 14388: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14389: $r->print('<option value="'.$sample.'"'.
14390: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14391: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14392: }
1.594 raeburn 14393: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14394: $i++;
14395: }
1.594 raeburn 14396: $r->print(&end_data_table());
1.31 albertel 14397: $i--;
14398: return $i;
14399: }
1.56 matthew 14400:
1.144 matthew 14401: ######################################################
14402: ######################################################
14403:
1.56 matthew 14404: =pod
1.31 albertel 14405:
1.648 raeburn 14406: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14407:
14408: Prints a table of sample values from the upload and can make associate samples to internal names.
14409:
14410: $r is an Apache Request ref,
14411: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14412: $d is an array of 2 element arrays (internal name, displayed name)
14413:
14414: =cut
14415:
1.144 matthew 14416: ######################################################
14417: ######################################################
1.31 albertel 14418: sub csv_samples_select_table {
14419: my ($r,$records,$d) = @_;
14420: my $i=0;
1.144 matthew 14421: #
1.662 bisitz 14422: my $max_samples = 5;
14423: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14424: $r->print(&start_data_table().
14425: &start_data_table_header_row().'<th>'.
14426: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14427: &end_data_table_header_row());
1.301 albertel 14428:
14429: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14430: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14431: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14432: foreach my $option (@$d) {
14433: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14434: $r->print('<option value="'.$value.'"'.
1.253 albertel 14435: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14436: $display.'</option>');
1.31 albertel 14437: }
14438: $r->print('</select></td><td>');
1.662 bisitz 14439: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14440: if (defined($samples->[$line]{$key})) {
14441: $r->print($samples->[$line]{$key}."<br />\n");
14442: }
14443: }
1.594 raeburn 14444: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14445: $i++;
14446: }
1.594 raeburn 14447: $r->print(&end_data_table());
1.31 albertel 14448: $i--;
14449: return($i);
1.115 matthew 14450: }
14451:
1.144 matthew 14452: ######################################################
14453: ######################################################
14454:
1.115 matthew 14455: =pod
14456:
1.648 raeburn 14457: =item * &clean_excel_name($name)
1.115 matthew 14458:
14459: Returns a replacement for $name which does not contain any illegal characters.
14460:
14461: =cut
14462:
1.144 matthew 14463: ######################################################
14464: ######################################################
1.115 matthew 14465: sub clean_excel_name {
14466: my ($name) = @_;
14467: $name =~ s/[:\*\?\/\\]//g;
14468: if (length($name) > 31) {
14469: $name = substr($name,0,31);
14470: }
14471: return $name;
1.25 albertel 14472: }
1.84 albertel 14473:
1.85 albertel 14474: =pod
14475:
1.648 raeburn 14476: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14477:
14478: Returns either 1 or undef
14479:
14480: 1 if the part is to be hidden, undef if it is to be shown
14481:
14482: Arguments are:
14483:
14484: $id the id of the part to be checked
14485: $symb, optional the symb of the resource to check
14486: $udom, optional the domain of the user to check for
14487: $uname, optional the username of the user to check for
14488:
14489: =cut
1.84 albertel 14490:
14491: sub check_if_partid_hidden {
14492: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14493: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14494: $symb,$udom,$uname);
1.141 albertel 14495: my $truth=1;
14496: #if the string starts with !, then the list is the list to show not hide
14497: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14498: my @hiddenlist=split(/,/,$hiddenparts);
14499: foreach my $checkid (@hiddenlist) {
1.141 albertel 14500: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14501: }
1.141 albertel 14502: return !$truth;
1.84 albertel 14503: }
1.127 matthew 14504:
1.138 matthew 14505:
14506: ############################################################
14507: ############################################################
14508:
14509: =pod
14510:
1.157 matthew 14511: =back
14512:
1.138 matthew 14513: =head1 cgi-bin script and graphing routines
14514:
1.157 matthew 14515: =over 4
14516:
1.648 raeburn 14517: =item * &get_cgi_id()
1.138 matthew 14518:
14519: Inputs: none
14520:
14521: Returns an id which can be used to pass environment variables
14522: to various cgi-bin scripts. These environment variables will
14523: be removed from the users environment after a given time by
14524: the routine &Apache::lonnet::transfer_profile_to_env.
14525:
14526: =cut
14527:
14528: ############################################################
14529: ############################################################
1.152 albertel 14530: my $uniq=0;
1.136 matthew 14531: sub get_cgi_id {
1.154 albertel 14532: $uniq=($uniq+1)%100000;
1.280 albertel 14533: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14534: }
14535:
1.127 matthew 14536: ############################################################
14537: ############################################################
14538:
14539: =pod
14540:
1.648 raeburn 14541: =item * &DrawBarGraph()
1.127 matthew 14542:
1.138 matthew 14543: Facilitates the plotting of data in a (stacked) bar graph.
14544: Puts plot definition data into the users environment in order for
14545: graph.png to plot it. Returns an <img> tag for the plot.
14546: The bars on the plot are labeled '1','2',...,'n'.
14547:
14548: Inputs:
14549:
14550: =over 4
14551:
14552: =item $Title: string, the title of the plot
14553:
14554: =item $xlabel: string, text describing the X-axis of the plot
14555:
14556: =item $ylabel: string, text describing the Y-axis of the plot
14557:
14558: =item $Max: scalar, the maximum Y value to use in the plot
14559: If $Max is < any data point, the graph will not be rendered.
14560:
1.140 matthew 14561: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14562: they are plotted. If undefined, default values will be used.
14563:
1.178 matthew 14564: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14565:
1.138 matthew 14566: =item @Values: An array of array references. Each array reference holds data
14567: to be plotted in a stacked bar chart.
14568:
1.239 matthew 14569: =item If the final element of @Values is a hash reference the key/value
14570: pairs will be added to the graph definition.
14571:
1.138 matthew 14572: =back
14573:
14574: Returns:
14575:
14576: An <img> tag which references graph.png and the appropriate identifying
14577: information for the plot.
14578:
1.127 matthew 14579: =cut
14580:
14581: ############################################################
14582: ############################################################
1.134 matthew 14583: sub DrawBarGraph {
1.178 matthew 14584: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14585: #
14586: if (! defined($colors)) {
14587: $colors = ['#33ff00',
14588: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14589: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14590: ];
14591: }
1.228 matthew 14592: my $extra_settings = {};
14593: if (ref($Values[-1]) eq 'HASH') {
14594: $extra_settings = pop(@Values);
14595: }
1.127 matthew 14596: #
1.136 matthew 14597: my $identifier = &get_cgi_id();
14598: my $id = 'cgi.'.$identifier;
1.129 matthew 14599: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14600: return '';
14601: }
1.225 matthew 14602: #
14603: my @Labels;
14604: if (defined($labels)) {
14605: @Labels = @$labels;
14606: } else {
14607: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 14608: push(@Labels,$i+1);
1.225 matthew 14609: }
14610: }
14611: #
1.129 matthew 14612: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14613: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14614: my %ValuesHash;
14615: my $NumSets=1;
14616: foreach my $array (@Values) {
14617: next if (! ref($array));
1.136 matthew 14618: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14619: join(',',@$array);
1.129 matthew 14620: }
1.127 matthew 14621: #
1.136 matthew 14622: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14623: if ($NumBars < 3) {
14624: $width = 120+$NumBars*32;
1.220 matthew 14625: $xskip = 1;
1.225 matthew 14626: $bar_width = 30;
14627: } elsif ($NumBars < 5) {
14628: $width = 120+$NumBars*20;
14629: $xskip = 1;
14630: $bar_width = 20;
1.220 matthew 14631: } elsif ($NumBars < 10) {
1.136 matthew 14632: $width = 120+$NumBars*15;
14633: $xskip = 1;
14634: $bar_width = 15;
14635: } elsif ($NumBars <= 25) {
14636: $width = 120+$NumBars*11;
14637: $xskip = 5;
14638: $bar_width = 8;
14639: } elsif ($NumBars <= 50) {
14640: $width = 120+$NumBars*8;
14641: $xskip = 5;
14642: $bar_width = 4;
14643: } else {
14644: $width = 120+$NumBars*8;
14645: $xskip = 5;
14646: $bar_width = 4;
14647: }
14648: #
1.137 matthew 14649: $Max = 1 if ($Max < 1);
14650: if ( int($Max) < $Max ) {
14651: $Max++;
14652: $Max = int($Max);
14653: }
1.127 matthew 14654: $Title = '' if (! defined($Title));
14655: $xlabel = '' if (! defined($xlabel));
14656: $ylabel = '' if (! defined($ylabel));
1.369 www 14657: $ValuesHash{$id.'.title'} = &escape($Title);
14658: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14659: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14660: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14661: $ValuesHash{$id.'.NumBars'} = $NumBars;
14662: $ValuesHash{$id.'.NumSets'} = $NumSets;
14663: $ValuesHash{$id.'.PlotType'} = 'bar';
14664: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14665: $ValuesHash{$id.'.height'} = $height;
14666: $ValuesHash{$id.'.width'} = $width;
14667: $ValuesHash{$id.'.xskip'} = $xskip;
14668: $ValuesHash{$id.'.bar_width'} = $bar_width;
14669: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14670: #
1.228 matthew 14671: # Deal with other parameters
14672: while (my ($key,$value) = each(%$extra_settings)) {
14673: $ValuesHash{$id.'.'.$key} = $value;
14674: }
14675: #
1.646 raeburn 14676: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14677: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14678: }
14679:
14680: ############################################################
14681: ############################################################
14682:
14683: =pod
14684:
1.648 raeburn 14685: =item * &DrawXYGraph()
1.137 matthew 14686:
1.138 matthew 14687: Facilitates the plotting of data in an XY graph.
14688: Puts plot definition data into the users environment in order for
14689: graph.png to plot it. Returns an <img> tag for the plot.
14690:
14691: Inputs:
14692:
14693: =over 4
14694:
14695: =item $Title: string, the title of the plot
14696:
14697: =item $xlabel: string, text describing the X-axis of the plot
14698:
14699: =item $ylabel: string, text describing the Y-axis of the plot
14700:
14701: =item $Max: scalar, the maximum Y value to use in the plot
14702: If $Max is < any data point, the graph will not be rendered.
14703:
14704: =item $colors: Array ref containing the hex color codes for the data to be
14705: plotted in. If undefined, default values will be used.
14706:
14707: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14708:
14709: =item $Ydata: Array ref containing Array refs.
1.185 www 14710: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14711:
14712: =item %Values: hash indicating or overriding any default values which are
14713: passed to graph.png.
14714: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14715:
14716: =back
14717:
14718: Returns:
14719:
14720: An <img> tag which references graph.png and the appropriate identifying
14721: information for the plot.
14722:
1.137 matthew 14723: =cut
14724:
14725: ############################################################
14726: ############################################################
14727: sub DrawXYGraph {
14728: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14729: #
14730: # Create the identifier for the graph
14731: my $identifier = &get_cgi_id();
14732: my $id = 'cgi.'.$identifier;
14733: #
14734: $Title = '' if (! defined($Title));
14735: $xlabel = '' if (! defined($xlabel));
14736: $ylabel = '' if (! defined($ylabel));
14737: my %ValuesHash =
14738: (
1.369 www 14739: $id.'.title' => &escape($Title),
14740: $id.'.xlabel' => &escape($xlabel),
14741: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14742: $id.'.y_max_value'=> $Max,
14743: $id.'.labels' => join(',',@$Xlabels),
14744: $id.'.PlotType' => 'XY',
14745: );
14746: #
14747: if (defined($colors) && ref($colors) eq 'ARRAY') {
14748: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14749: }
14750: #
14751: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14752: return '';
14753: }
14754: my $NumSets=1;
1.138 matthew 14755: foreach my $array (@{$Ydata}){
1.137 matthew 14756: next if (! ref($array));
14757: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14758: }
1.138 matthew 14759: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14760: #
14761: # Deal with other parameters
14762: while (my ($key,$value) = each(%Values)) {
14763: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14764: }
14765: #
1.646 raeburn 14766: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14767: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14768: }
14769:
14770: ############################################################
14771: ############################################################
14772:
14773: =pod
14774:
1.648 raeburn 14775: =item * &DrawXYYGraph()
1.138 matthew 14776:
14777: Facilitates the plotting of data in an XY graph with two Y axes.
14778: Puts plot definition data into the users environment in order for
14779: graph.png to plot it. Returns an <img> tag for the plot.
14780:
14781: Inputs:
14782:
14783: =over 4
14784:
14785: =item $Title: string, the title of the plot
14786:
14787: =item $xlabel: string, text describing the X-axis of the plot
14788:
14789: =item $ylabel: string, text describing the Y-axis of the plot
14790:
14791: =item $colors: Array ref containing the hex color codes for the data to be
14792: plotted in. If undefined, default values will be used.
14793:
14794: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14795:
14796: =item $Ydata1: The first data set
14797:
14798: =item $Min1: The minimum value of the left Y-axis
14799:
14800: =item $Max1: The maximum value of the left Y-axis
14801:
14802: =item $Ydata2: The second data set
14803:
14804: =item $Min2: The minimum value of the right Y-axis
14805:
14806: =item $Max2: The maximum value of the left Y-axis
14807:
14808: =item %Values: hash indicating or overriding any default values which are
14809: passed to graph.png.
14810: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14811:
14812: =back
14813:
14814: Returns:
14815:
14816: An <img> tag which references graph.png and the appropriate identifying
14817: information for the plot.
1.136 matthew 14818:
14819: =cut
14820:
14821: ############################################################
14822: ############################################################
1.137 matthew 14823: sub DrawXYYGraph {
14824: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14825: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14826: #
14827: # Create the identifier for the graph
14828: my $identifier = &get_cgi_id();
14829: my $id = 'cgi.'.$identifier;
14830: #
14831: $Title = '' if (! defined($Title));
14832: $xlabel = '' if (! defined($xlabel));
14833: $ylabel = '' if (! defined($ylabel));
14834: my %ValuesHash =
14835: (
1.369 www 14836: $id.'.title' => &escape($Title),
14837: $id.'.xlabel' => &escape($xlabel),
14838: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14839: $id.'.labels' => join(',',@$Xlabels),
14840: $id.'.PlotType' => 'XY',
14841: $id.'.NumSets' => 2,
1.137 matthew 14842: $id.'.two_axes' => 1,
14843: $id.'.y1_max_value' => $Max1,
14844: $id.'.y1_min_value' => $Min1,
14845: $id.'.y2_max_value' => $Max2,
14846: $id.'.y2_min_value' => $Min2,
1.136 matthew 14847: );
14848: #
1.137 matthew 14849: if (defined($colors) && ref($colors) eq 'ARRAY') {
14850: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14851: }
14852: #
14853: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14854: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14855: return '';
14856: }
14857: my $NumSets=1;
1.137 matthew 14858: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14859: next if (! ref($array));
14860: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14861: }
14862: #
14863: # Deal with other parameters
14864: while (my ($key,$value) = each(%Values)) {
14865: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14866: }
14867: #
1.646 raeburn 14868: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14869: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14870: }
14871:
14872: ############################################################
14873: ############################################################
14874:
14875: =pod
14876:
1.157 matthew 14877: =back
14878:
1.139 matthew 14879: =head1 Statistics helper routines?
14880:
14881: Bad place for them but what the hell.
14882:
1.157 matthew 14883: =over 4
14884:
1.648 raeburn 14885: =item * &chartlink()
1.139 matthew 14886:
14887: Returns a link to the chart for a specific student.
14888:
14889: Inputs:
14890:
14891: =over 4
14892:
14893: =item $linktext: The text of the link
14894:
14895: =item $sname: The students username
14896:
14897: =item $sdomain: The students domain
14898:
14899: =back
14900:
1.157 matthew 14901: =back
14902:
1.139 matthew 14903: =cut
14904:
14905: ############################################################
14906: ############################################################
14907: sub chartlink {
14908: my ($linktext, $sname, $sdomain) = @_;
14909: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14910: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14911: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14912: '">'.$linktext.'</a>';
1.153 matthew 14913: }
14914:
14915: #######################################################
14916: #######################################################
14917:
14918: =pod
14919:
14920: =head1 Course Environment Routines
1.157 matthew 14921:
14922: =over 4
1.153 matthew 14923:
1.648 raeburn 14924: =item * &restore_course_settings()
1.153 matthew 14925:
1.648 raeburn 14926: =item * &store_course_settings()
1.153 matthew 14927:
14928: Restores/Store indicated form parameters from the course environment.
14929: Will not overwrite existing values of the form parameters.
14930:
14931: Inputs:
14932: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14933:
14934: a hash ref describing the data to be stored. For example:
14935:
14936: %Save_Parameters = ('Status' => 'scalar',
14937: 'chartoutputmode' => 'scalar',
14938: 'chartoutputdata' => 'scalar',
14939: 'Section' => 'array',
1.373 raeburn 14940: 'Group' => 'array',
1.153 matthew 14941: 'StudentData' => 'array',
14942: 'Maps' => 'array');
14943:
14944: Returns: both routines return nothing
14945:
1.631 raeburn 14946: =back
14947:
1.153 matthew 14948: =cut
14949:
14950: #######################################################
14951: #######################################################
14952: sub store_course_settings {
1.496 albertel 14953: return &store_settings($env{'request.course.id'},@_);
14954: }
14955:
14956: sub store_settings {
1.153 matthew 14957: # save to the environment
14958: # appenv the same items, just to be safe
1.300 albertel 14959: my $udom = $env{'user.domain'};
14960: my $uname = $env{'user.name'};
1.496 albertel 14961: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14962: my %SaveHash;
14963: my %AppHash;
14964: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14965: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14966: my $envname = 'environment.'.$basename;
1.258 albertel 14967: if (exists($env{'form.'.$setting})) {
1.153 matthew 14968: # Save this value away
14969: if ($type eq 'scalar' &&
1.258 albertel 14970: (! exists($env{$envname}) ||
14971: $env{$envname} ne $env{'form.'.$setting})) {
14972: $SaveHash{$basename} = $env{'form.'.$setting};
14973: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14974: } elsif ($type eq 'array') {
14975: my $stored_form;
1.258 albertel 14976: if (ref($env{'form.'.$setting})) {
1.153 matthew 14977: $stored_form = join(',',
14978: map {
1.369 www 14979: &escape($_);
1.258 albertel 14980: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14981: } else {
14982: $stored_form =
1.369 www 14983: &escape($env{'form.'.$setting});
1.153 matthew 14984: }
14985: # Determine if the array contents are the same.
1.258 albertel 14986: if ($stored_form ne $env{$envname}) {
1.153 matthew 14987: $SaveHash{$basename} = $stored_form;
14988: $AppHash{$envname} = $stored_form;
14989: }
14990: }
14991: }
14992: }
14993: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14994: $udom,$uname);
1.153 matthew 14995: if ($put_result !~ /^(ok|delayed)/) {
14996: &Apache::lonnet::logthis('unable to save form parameters, '.
14997: 'got error:'.$put_result);
14998: }
14999: # Make sure these settings stick around in this session, too
1.646 raeburn 15000: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 15001: return;
15002: }
15003:
15004: sub restore_course_settings {
1.499 albertel 15005: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 15006: }
15007:
15008: sub restore_settings {
15009: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15010: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 15011: next if (exists($env{'form.'.$setting}));
1.496 albertel 15012: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 15013: '.'.$setting;
1.258 albertel 15014: if (exists($env{$envname})) {
1.153 matthew 15015: if ($type eq 'scalar') {
1.258 albertel 15016: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 15017: } elsif ($type eq 'array') {
1.258 albertel 15018: $env{'form.'.$setting} = [
1.153 matthew 15019: map {
1.369 www 15020: &unescape($_);
1.258 albertel 15021: } split(',',$env{$envname})
1.153 matthew 15022: ];
15023: }
15024: }
15025: }
1.127 matthew 15026: }
15027:
1.618 raeburn 15028: #######################################################
15029: #######################################################
15030:
15031: =pod
15032:
15033: =head1 Domain E-mail Routines
15034:
15035: =over 4
15036:
1.648 raeburn 15037: =item * &build_recipient_list()
1.618 raeburn 15038:
1.1144 raeburn 15039: Build recipient lists for following types of e-mail:
1.766 raeburn 15040: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 15041: (d) Help requests, (e) Course requests needing approval, (f) loncapa
15042: module change checking, student/employee ID conflict checks, as
15043: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
15044: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 15045:
15046: Inputs:
1.619 raeburn 15047: defmail (scalar - email address of default recipient),
1.1144 raeburn 15048: mailing type (scalar: errormail, packagesmail, helpdeskmail,
15049: requestsmail, updatesmail, or idconflictsmail).
15050:
1.619 raeburn 15051: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 15052:
1.619 raeburn 15053: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 15054: i.e., predates configuration by DC via domainprefs.pm
15055:
15056: $requname username of requester (if mailing type is helpdeskmail)
15057:
15058: $requdom domain of requester (if mailing type is helpdeskmail)
15059:
15060: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
15061:
1.618 raeburn 15062:
1.655 raeburn 15063: Returns: comma separated list of addresses to which to send e-mail.
15064:
15065: =back
1.618 raeburn 15066:
15067: =cut
15068:
15069: ############################################################
15070: ############################################################
15071: sub build_recipient_list {
1.1297 raeburn 15072: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 15073: my @recipients;
1.1270 raeburn 15074: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 15075: my %domconfig =
1.1270 raeburn 15076: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 15077: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 15078: if (exists($domconfig{'contacts'}{$mailing})) {
15079: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
15080: my @contacts = ('adminemail','supportemail');
15081: foreach my $item (@contacts) {
15082: if ($domconfig{'contacts'}{$mailing}{$item}) {
15083: my $addr = $domconfig{'contacts'}{$item};
15084: if (!grep(/^\Q$addr\E$/,@recipients)) {
15085: push(@recipients,$addr);
15086: }
1.619 raeburn 15087: }
1.1270 raeburn 15088: }
15089: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
15090: if ($mailing eq 'helpdeskmail') {
15091: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
15092: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
15093: my @ok_bccs;
15094: foreach my $bcc (@bccs) {
15095: $bcc =~ s/^\s+//g;
15096: $bcc =~ s/\s+$//g;
15097: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15098: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15099: push(@ok_bccs,$bcc);
15100: }
15101: }
15102: }
15103: if (@ok_bccs > 0) {
15104: $allbcc = join(', ',@ok_bccs);
15105: }
15106: }
15107: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 15108: }
15109: }
1.766 raeburn 15110: } elsif ($origmail ne '') {
1.1270 raeburn 15111: $lastresort = $origmail;
1.618 raeburn 15112: }
1.1297 raeburn 15113: if ($mailing eq 'helpdeskmail') {
15114: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
15115: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
15116: my ($inststatus,$inststatus_checked);
15117: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
15118: ($env{'user.domain'} ne 'public')) {
15119: $inststatus_checked = 1;
15120: $inststatus = $env{'environment.inststatus'};
15121: }
15122: unless ($inststatus_checked) {
15123: if (($requname ne '') && ($requdom ne '')) {
15124: if (($requname =~ /^$match_username$/) &&
15125: ($requdom =~ /^$match_domain$/) &&
15126: (&Apache::lonnet::domain($requdom))) {
15127: my $requhome = &Apache::lonnet::homeserver($requname,
15128: $requdom);
15129: unless ($requhome eq 'no_host') {
15130: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
15131: $inststatus = $userenv{'inststatus'};
15132: $inststatus_checked = 1;
15133: }
15134: }
15135: }
15136: }
15137: unless ($inststatus_checked) {
15138: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15139: my %srch = (srchby => 'email',
15140: srchdomain => $defdom,
15141: srchterm => $reqemail,
15142: srchtype => 'exact');
15143: my %srch_results = &Apache::lonnet::usersearch(\%srch);
15144: foreach my $uname (keys(%srch_results)) {
15145: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15146: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15147: $inststatus_checked = 1;
15148: last;
15149: }
15150: }
15151: unless ($inststatus_checked) {
15152: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15153: if ($dirsrchres eq 'ok') {
15154: foreach my $uname (keys(%srch_results)) {
15155: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15156: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15157: $inststatus_checked = 1;
15158: last;
15159: }
15160: }
15161: }
15162: }
15163: }
15164: }
15165: if ($inststatus ne '') {
15166: foreach my $status (split(/\:/,$inststatus)) {
15167: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15168: my @contacts = ('adminemail','supportemail');
15169: foreach my $item (@contacts) {
15170: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15171: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15172: if (!grep(/^\Q$addr\E$/,@recipients)) {
15173: push(@recipients,$addr);
15174: }
15175: }
15176: }
15177: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15178: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15179: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15180: my @ok_bccs;
15181: foreach my $bcc (@bccs) {
15182: $bcc =~ s/^\s+//g;
15183: $bcc =~ s/\s+$//g;
15184: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15185: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15186: push(@ok_bccs,$bcc);
15187: }
15188: }
15189: }
15190: if (@ok_bccs > 0) {
15191: $allbcc = join(', ',@ok_bccs);
15192: }
15193: }
15194: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15195: last;
15196: }
15197: }
15198: }
15199: }
15200: }
1.619 raeburn 15201: } elsif ($origmail ne '') {
1.1270 raeburn 15202: $lastresort = $origmail;
15203: }
1.1297 raeburn 15204: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 15205: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15206: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15207: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15208: my %what = (
15209: perlvar => 1,
15210: );
15211: my $primary = &Apache::lonnet::domain($defdom,'primary');
15212: if ($primary) {
15213: my $gotaddr;
15214: my ($result,$returnhash) =
15215: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15216: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15217: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15218: $lastresort = $returnhash->{'lonSupportEMail'};
15219: $gotaddr = 1;
15220: }
15221: }
15222: unless ($gotaddr) {
15223: my $uintdom = &Apache::lonnet::internet_dom($primary);
15224: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15225: unless ($uintdom eq $intdom) {
15226: my %domconfig =
15227: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15228: if (ref($domconfig{'contacts'}) eq 'HASH') {
15229: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15230: my @contacts = ('adminemail','supportemail');
15231: foreach my $item (@contacts) {
15232: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15233: my $addr = $domconfig{'contacts'}{$item};
15234: if (!grep(/^\Q$addr\E$/,@recipients)) {
15235: push(@recipients,$addr);
15236: }
15237: }
15238: }
15239: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15240: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15241: }
15242: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15243: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15244: my @ok_bccs;
15245: foreach my $bcc (@bccs) {
15246: $bcc =~ s/^\s+//g;
15247: $bcc =~ s/\s+$//g;
15248: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15249: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15250: push(@ok_bccs,$bcc);
15251: }
15252: }
15253: }
15254: if (@ok_bccs > 0) {
15255: $allbcc = join(', ',@ok_bccs);
15256: }
15257: }
15258: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15259: }
15260: }
15261: }
15262: }
15263: }
15264: }
1.618 raeburn 15265: }
1.688 raeburn 15266: if (defined($defmail)) {
15267: if ($defmail ne '') {
15268: push(@recipients,$defmail);
15269: }
1.618 raeburn 15270: }
15271: if ($otheremails) {
1.619 raeburn 15272: my @others;
15273: if ($otheremails =~ /,/) {
15274: @others = split(/,/,$otheremails);
1.618 raeburn 15275: } else {
1.619 raeburn 15276: push(@others,$otheremails);
15277: }
15278: foreach my $addr (@others) {
15279: if (!grep(/^\Q$addr\E$/,@recipients)) {
15280: push(@recipients,$addr);
15281: }
1.618 raeburn 15282: }
15283: }
1.1298 raeburn 15284: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 15285: if ((!@recipients) && ($lastresort ne '')) {
15286: push(@recipients,$lastresort);
15287: }
15288: } elsif ($lastresort ne '') {
15289: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15290: push(@recipients,$lastresort);
15291: }
15292: }
1.1271 raeburn 15293: my $recipientlist = join(',',@recipients);
1.1270 raeburn 15294: if (wantarray) {
15295: return ($recipientlist,$allbcc,$addtext);
15296: } else {
15297: return $recipientlist;
15298: }
1.618 raeburn 15299: }
15300:
1.127 matthew 15301: ############################################################
15302: ############################################################
1.154 albertel 15303:
1.655 raeburn 15304: =pod
15305:
1.1224 musolffc 15306: =over 4
15307:
1.1223 musolffc 15308: =item * &mime_email()
15309:
15310: Sends an email with a possible attachment
15311:
15312: Inputs:
15313:
15314: =over 4
15315:
15316: from - Sender's email address
15317:
1.1343 raeburn 15318: replyto - Reply-To email address
15319:
1.1223 musolffc 15320: to - Email address of recipient
15321:
15322: subject - Subject of email
15323:
15324: body - Body of email
15325:
15326: cc_string - Carbon copy email address
15327:
15328: bcc - Blind carbon copy email address
15329:
15330: attachment_path - Path of file to be attached
15331:
15332: file_name - Name of file to be attached
15333:
15334: attachment_text - The body of an attachment of type "TEXT"
15335:
15336: =back
15337:
15338: =back
15339:
15340: =cut
15341:
15342: ############################################################
15343: ############################################################
15344:
15345: sub mime_email {
1.1343 raeburn 15346: my ($from,$replyto,$to,$subject,$body,$cc_string,$bcc,$attachment_path,
15347: $file_name,$attachment_text) = @_;
15348:
1.1223 musolffc 15349: my $msg = MIME::Lite->new(
15350: From => $from,
15351: To => $to,
15352: Subject => $subject,
15353: Type =>'TEXT',
15354: Data => $body,
15355: );
1.1343 raeburn 15356: if ($replyto ne '') {
15357: $msg->add("Reply-To" => $replyto);
15358: }
1.1223 musolffc 15359: if ($cc_string ne '') {
15360: $msg->add("Cc" => $cc_string);
15361: }
15362: if ($bcc ne '') {
15363: $msg->add("Bcc" => $bcc);
15364: }
15365: $msg->attr("content-type" => "text/plain");
15366: $msg->attr("content-type.charset" => "UTF-8");
15367: # Attach file if given
15368: if ($attachment_path) {
15369: unless ($file_name) {
15370: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
15371: }
15372: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
15373: $msg->attach(Type => $type,
15374: Path => $attachment_path,
15375: Filename => $file_name
15376: );
15377: # Otherwise attach text if given
15378: } elsif ($attachment_text) {
15379: $msg->attach(Type => 'TEXT',
15380: Data => $attachment_text);
15381: }
15382: # Send it
15383: $msg->send('sendmail');
15384: }
15385:
15386: ############################################################
15387: ############################################################
15388:
15389: =pod
15390:
1.655 raeburn 15391: =head1 Course Catalog Routines
15392:
15393: =over 4
15394:
15395: =item * &gather_categories()
15396:
15397: Converts category definitions - keys of categories hash stored in
15398: coursecategories in configuration.db on the primary library server in a
15399: domain - to an array. Also generates javascript and idx hash used to
15400: generate Domain Coordinator interface for editing Course Categories.
15401:
15402: Inputs:
1.663 raeburn 15403:
1.655 raeburn 15404: categories (reference to hash of category definitions).
1.663 raeburn 15405:
1.655 raeburn 15406: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15407: categories and subcategories).
1.663 raeburn 15408:
1.655 raeburn 15409: idx (reference to hash of counters used in Domain Coordinator interface for
15410: editing Course Categories).
1.663 raeburn 15411:
1.655 raeburn 15412: jsarray (reference to array of categories used to create Javascript arrays for
15413: Domain Coordinator interface for editing Course Categories).
15414:
15415: Returns: nothing
15416:
15417: Side effects: populates cats, idx and jsarray.
15418:
15419: =cut
15420:
15421: sub gather_categories {
15422: my ($categories,$cats,$idx,$jsarray) = @_;
15423: my %counters;
15424: my $num = 0;
15425: foreach my $item (keys(%{$categories})) {
15426: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15427: if ($container eq '' && $depth == 0) {
15428: $cats->[$depth][$categories->{$item}] = $cat;
15429: } else {
15430: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15431: }
15432: my ($escitem,$tail) = split(/:/,$item,2);
15433: if ($counters{$tail} eq '') {
15434: $counters{$tail} = $num;
15435: $num ++;
15436: }
15437: if (ref($idx) eq 'HASH') {
15438: $idx->{$item} = $counters{$tail};
15439: }
15440: if (ref($jsarray) eq 'ARRAY') {
15441: push(@{$jsarray->[$counters{$tail}]},$item);
15442: }
15443: }
15444: return;
15445: }
15446:
15447: =pod
15448:
15449: =item * &extract_categories()
15450:
15451: Used to generate breadcrumb trails for course categories.
15452:
15453: Inputs:
1.663 raeburn 15454:
1.655 raeburn 15455: categories (reference to hash of category definitions).
1.663 raeburn 15456:
1.655 raeburn 15457: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15458: categories and subcategories).
1.663 raeburn 15459:
1.655 raeburn 15460: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15461:
1.655 raeburn 15462: allitems (reference to hash - key is category key
15463: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15464:
1.655 raeburn 15465: idx (reference to hash of counters used in Domain Coordinator interface for
15466: editing Course Categories).
1.663 raeburn 15467:
1.655 raeburn 15468: jsarray (reference to array of categories used to create Javascript arrays for
15469: Domain Coordinator interface for editing Course Categories).
15470:
1.665 raeburn 15471: subcats (reference to hash of arrays containing all subcategories within each
15472: category, -recursive)
15473:
1.1321 raeburn 15474: maxd (reference to hash used to hold max depth for all top-level categories).
15475:
1.655 raeburn 15476: Returns: nothing
15477:
15478: Side effects: populates trails and allitems hash references.
15479:
15480: =cut
15481:
15482: sub extract_categories {
1.1321 raeburn 15483: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 15484: if (ref($categories) eq 'HASH') {
15485: &gather_categories($categories,$cats,$idx,$jsarray);
15486: if (ref($cats->[0]) eq 'ARRAY') {
15487: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15488: my $name = $cats->[0][$i];
15489: my $item = &escape($name).'::0';
15490: my $trailstr;
15491: if ($name eq 'instcode') {
15492: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15493: } elsif ($name eq 'communities') {
15494: $trailstr = &mt('Communities');
1.1239 raeburn 15495: } elsif ($name eq 'placement') {
15496: $trailstr = &mt('Placement Tests');
1.655 raeburn 15497: } else {
15498: $trailstr = $name;
15499: }
15500: if ($allitems->{$item} eq '') {
15501: push(@{$trails},$trailstr);
15502: $allitems->{$item} = scalar(@{$trails})-1;
15503: }
15504: my @parents = ($name);
15505: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15506: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15507: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15508: if (ref($subcats) eq 'HASH') {
15509: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15510: }
1.1321 raeburn 15511: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 15512: }
15513: } else {
15514: if (ref($subcats) eq 'HASH') {
15515: $subcats->{$item} = [];
1.655 raeburn 15516: }
1.1321 raeburn 15517: if (ref($maxd) eq 'HASH') {
15518: $maxd->{$name} = 1;
15519: }
1.655 raeburn 15520: }
15521: }
15522: }
15523: }
15524: return;
15525: }
15526:
15527: =pod
15528:
1.1162 raeburn 15529: =item * &recurse_categories()
1.655 raeburn 15530:
15531: Recursively used to generate breadcrumb trails for course categories.
15532:
15533: Inputs:
1.663 raeburn 15534:
1.655 raeburn 15535: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15536: categories and subcategories).
1.663 raeburn 15537:
1.655 raeburn 15538: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15539:
15540: category (current course category, for which breadcrumb trail is being generated).
15541:
15542: trails (reference to array of breadcrumb trails for each category).
15543:
1.655 raeburn 15544: allitems (reference to hash - key is category key
15545: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15546:
1.655 raeburn 15547: parents (array containing containers directories for current category,
15548: back to top level).
15549:
15550: Returns: nothing
15551:
15552: Side effects: populates trails and allitems hash references
15553:
15554: =cut
15555:
15556: sub recurse_categories {
1.1321 raeburn 15557: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 15558: my $shallower = $depth - 1;
15559: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
15560: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
15561: my $name = $cats->[$depth]{$category}[$k];
15562: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15563: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15564: if ($allitems->{$item} eq '') {
15565: push(@{$trails},$trailstr);
15566: $allitems->{$item} = scalar(@{$trails})-1;
15567: }
15568: my $deeper = $depth+1;
15569: push(@{$parents},$category);
1.665 raeburn 15570: if (ref($subcats) eq 'HASH') {
15571: my $subcat = &escape($name).':'.$category.':'.$depth;
15572: for (my $j=@{$parents}; $j>=0; $j--) {
15573: my $higher;
15574: if ($j > 0) {
15575: $higher = &escape($parents->[$j]).':'.
15576: &escape($parents->[$j-1]).':'.$j;
15577: } else {
15578: $higher = &escape($parents->[$j]).'::'.$j;
15579: }
15580: push(@{$subcats->{$higher}},$subcat);
15581: }
15582: }
15583: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 15584: $subcats,$maxd);
1.655 raeburn 15585: pop(@{$parents});
15586: }
15587: } else {
15588: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15589: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15590: if ($allitems->{$item} eq '') {
15591: push(@{$trails},$trailstr);
15592: $allitems->{$item} = scalar(@{$trails})-1;
15593: }
1.1321 raeburn 15594: if (ref($maxd) eq 'HASH') {
15595: if ($depth > $maxd->{$parents->[0]}) {
15596: $maxd->{$parents->[0]} = $depth;
15597: }
15598: }
1.655 raeburn 15599: }
15600: return;
15601: }
15602:
1.663 raeburn 15603: =pod
15604:
1.1162 raeburn 15605: =item * &assign_categories_table()
1.663 raeburn 15606:
15607: Create a datatable for display of hierarchical categories in a domain,
15608: with checkboxes to allow a course to be categorized.
15609:
15610: Inputs:
15611:
15612: cathash - reference to hash of categories defined for the domain (from
15613: configuration.db)
15614:
15615: currcat - scalar with an & separated list of categories assigned to a course.
15616:
1.919 raeburn 15617: type - scalar contains course type (Course or Community).
15618:
1.1260 raeburn 15619: disabled - scalar (optional) contains disabled="disabled" if input elements are
15620: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15621:
1.663 raeburn 15622: Returns: $output (markup to be displayed)
15623:
15624: =cut
15625:
15626: sub assign_categories_table {
1.1259 raeburn 15627: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15628: my $output;
15629: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 15630: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
15631: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 15632: $maxdepth = scalar(@cats);
15633: if (@cats > 0) {
15634: my $itemcount = 0;
15635: if (ref($cats[0]) eq 'ARRAY') {
15636: my @currcategories;
15637: if ($currcat ne '') {
15638: @currcategories = split('&',$currcat);
15639: }
1.919 raeburn 15640: my $table;
1.663 raeburn 15641: for (my $i=0; $i<@{$cats[0]}; $i++) {
15642: my $parent = $cats[0][$i];
1.919 raeburn 15643: next if ($parent eq 'instcode');
15644: if ($type eq 'Community') {
15645: next unless ($parent eq 'communities');
1.1239 raeburn 15646: } elsif ($type eq 'Placement') {
15647: next unless ($parent eq 'placement');
1.919 raeburn 15648: } else {
1.1239 raeburn 15649: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 15650: }
1.663 raeburn 15651: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15652: my $item = &escape($parent).'::0';
15653: my $checked = '';
15654: if (@currcategories > 0) {
15655: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15656: $checked = ' checked="checked"';
1.663 raeburn 15657: }
15658: }
1.919 raeburn 15659: my $parent_title = $parent;
15660: if ($parent eq 'communities') {
15661: $parent_title = &mt('Communities');
1.1239 raeburn 15662: } elsif ($parent eq 'placement') {
15663: $parent_title = &mt('Placement Tests');
1.919 raeburn 15664: }
15665: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15666: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15667: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15668: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15669: my $depth = 1;
15670: push(@path,$parent);
1.1259 raeburn 15671: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15672: pop(@path);
1.919 raeburn 15673: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15674: $itemcount ++;
15675: }
1.919 raeburn 15676: if ($itemcount) {
15677: $output = &Apache::loncommon::start_data_table().
15678: $table.
15679: &Apache::loncommon::end_data_table();
15680: }
1.663 raeburn 15681: }
15682: }
15683: }
15684: return $output;
15685: }
15686:
15687: =pod
15688:
1.1162 raeburn 15689: =item * &assign_category_rows()
1.663 raeburn 15690:
15691: Create a datatable row for display of nested categories in a domain,
15692: with checkboxes to allow a course to be categorized,called recursively.
15693:
15694: Inputs:
15695:
15696: itemcount - track row number for alternating colors
15697:
15698: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15699: categories and subcategories.
15700:
15701: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15702:
15703: parent - parent of current category item
15704:
15705: path - Array containing all categories back up through the hierarchy from the
15706: current category to the top level.
15707:
15708: currcategories - reference to array of current categories assigned to the course
15709:
1.1260 raeburn 15710: disabled - scalar (optional) contains disabled="disabled" if input elements are
15711: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15712:
1.663 raeburn 15713: Returns: $output (markup to be displayed).
15714:
15715: =cut
15716:
15717: sub assign_category_rows {
1.1259 raeburn 15718: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15719: my ($text,$name,$item,$chgstr);
15720: if (ref($cats) eq 'ARRAY') {
15721: my $maxdepth = scalar(@{$cats});
15722: if (ref($cats->[$depth]) eq 'HASH') {
15723: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15724: my $numchildren = @{$cats->[$depth]{$parent}};
15725: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 15726: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15727: for (my $j=0; $j<$numchildren; $j++) {
15728: $name = $cats->[$depth]{$parent}[$j];
15729: $item = &escape($name).':'.&escape($parent).':'.$depth;
15730: my $deeper = $depth+1;
15731: my $checked = '';
15732: if (ref($currcategories) eq 'ARRAY') {
15733: if (@{$currcategories} > 0) {
15734: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15735: $checked = ' checked="checked"';
1.663 raeburn 15736: }
15737: }
15738: }
1.664 raeburn 15739: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15740: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15741: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15742: '<input type="hidden" name="catname" value="'.$name.'" />'.
15743: '</td><td>';
1.663 raeburn 15744: if (ref($path) eq 'ARRAY') {
15745: push(@{$path},$name);
1.1259 raeburn 15746: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15747: pop(@{$path});
15748: }
15749: $text .= '</td></tr>';
15750: }
15751: $text .= '</table></td>';
15752: }
15753: }
15754: }
15755: return $text;
15756: }
15757:
1.1181 raeburn 15758: =pod
15759:
15760: =back
15761:
15762: =cut
15763:
1.655 raeburn 15764: ############################################################
15765: ############################################################
15766:
15767:
1.443 albertel 15768: sub commit_customrole {
1.664 raeburn 15769: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15770: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15771: ($start?', '.&mt('starting').' '.localtime($start):'').
15772: ($end?', ending '.localtime($end):'').': <b>'.
15773: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15774: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15775: '</b><br />';
15776: return $output;
15777: }
15778:
15779: sub commit_standardrole {
1.1116 raeburn 15780: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15781: my ($output,$logmsg,$linefeed);
15782: if ($context eq 'auto') {
15783: $linefeed = "\n";
15784: } else {
15785: $linefeed = "<br />\n";
15786: }
1.443 albertel 15787: if ($three eq 'st') {
1.541 raeburn 15788: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 15789: $one,$two,$sec,$context,$credits);
1.541 raeburn 15790: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15791: ($result eq 'unknown_course') || ($result eq 'refused')) {
15792: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15793: } else {
1.541 raeburn 15794: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15795: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15796: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15797: if ($context eq 'auto') {
15798: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15799: } else {
15800: $output .= '<b>'.$result.'</b>'.$linefeed.
15801: &mt('Add to classlist').': <b>ok</b>';
15802: }
15803: $output .= $linefeed;
1.443 albertel 15804: }
15805: } else {
15806: $output = &mt('Assigning').' '.$three.' in '.$url.
15807: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15808: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15809: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15810: if ($context eq 'auto') {
15811: $output .= $result.$linefeed;
15812: } else {
15813: $output .= '<b>'.$result.'</b>'.$linefeed;
15814: }
1.443 albertel 15815: }
15816: return $output;
15817: }
15818:
15819: sub commit_studentrole {
1.1116 raeburn 15820: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15821: $credits) = @_;
1.626 raeburn 15822: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15823: if ($context eq 'auto') {
15824: $linefeed = "\n";
15825: } else {
15826: $linefeed = '<br />'."\n";
15827: }
1.443 albertel 15828: if (defined($one) && defined($two)) {
15829: my $cid=$one.'_'.$two;
15830: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15831: my $secchange = 0;
15832: my $expire_role_result;
15833: my $modify_section_result;
1.628 raeburn 15834: if ($oldsec ne '-1') {
15835: if ($oldsec ne $sec) {
1.443 albertel 15836: $secchange = 1;
1.628 raeburn 15837: my $now = time;
1.443 albertel 15838: my $uurl='/'.$cid;
15839: $uurl=~s/\_/\//g;
15840: if ($oldsec) {
15841: $uurl.='/'.$oldsec;
15842: }
1.626 raeburn 15843: $oldsecurl = $uurl;
1.628 raeburn 15844: $expire_role_result =
1.652 raeburn 15845: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15846: if ($env{'request.course.sec'} ne '') {
15847: if ($expire_role_result eq 'refused') {
15848: my @roles = ('st');
15849: my @statuses = ('previous');
15850: my @roledoms = ($one);
15851: my $withsec = 1;
15852: my %roleshash =
15853: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15854: \@statuses,\@roles,\@roledoms,$withsec);
15855: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15856: my ($oldstart,$oldend) =
15857: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15858: if ($oldend > 0 && $oldend <= $now) {
15859: $expire_role_result = 'ok';
15860: }
15861: }
15862: }
15863: }
1.443 albertel 15864: $result = $expire_role_result;
15865: }
15866: }
15867: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 15868: $modify_section_result =
15869: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15870: undef,undef,undef,$sec,
15871: $end,$start,'','',$cid,
15872: '',$context,$credits);
1.443 albertel 15873: if ($modify_section_result =~ /^ok/) {
15874: if ($secchange == 1) {
1.628 raeburn 15875: if ($sec eq '') {
15876: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15877: } else {
15878: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15879: }
1.443 albertel 15880: } elsif ($oldsec eq '-1') {
1.628 raeburn 15881: if ($sec eq '') {
15882: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15883: } else {
15884: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15885: }
1.443 albertel 15886: } else {
1.628 raeburn 15887: if ($sec eq '') {
15888: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15889: } else {
15890: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15891: }
1.443 albertel 15892: }
15893: } else {
1.1115 raeburn 15894: if ($secchange) {
1.628 raeburn 15895: $$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;
15896: } else {
15897: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15898: }
1.443 albertel 15899: }
15900: $result = $modify_section_result;
15901: } elsif ($secchange == 1) {
1.628 raeburn 15902: if ($oldsec eq '') {
1.1103 raeburn 15903: $$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 15904: } else {
15905: $$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;
15906: }
1.626 raeburn 15907: if ($expire_role_result eq 'refused') {
15908: my $newsecurl = '/'.$cid;
15909: $newsecurl =~ s/\_/\//g;
15910: if ($sec ne '') {
15911: $newsecurl.='/'.$sec;
15912: }
15913: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15914: if ($sec eq '') {
15915: $$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;
15916: } else {
15917: $$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;
15918: }
15919: }
15920: }
1.443 albertel 15921: }
15922: } else {
1.626 raeburn 15923: $$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 15924: $result = "error: incomplete course id\n";
15925: }
15926: return $result;
15927: }
15928:
1.1108 raeburn 15929: sub show_role_extent {
15930: my ($scope,$context,$role) = @_;
15931: $scope =~ s{^/}{};
15932: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15933: push(@courseroles,'co');
15934: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15935: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15936: $scope =~ s{/}{_};
15937: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15938: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15939: my ($audom,$auname) = split(/\//,$scope);
15940: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15941: &Apache::loncommon::plainname($auname,$audom).'</span>');
15942: } else {
15943: $scope =~ s{/$}{};
15944: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15945: &Apache::lonnet::domain($scope,'description').'</span>');
15946: }
15947: }
15948:
1.443 albertel 15949: ############################################################
15950: ############################################################
15951:
1.566 albertel 15952: sub check_clone {
1.578 raeburn 15953: my ($args,$linefeed) = @_;
1.566 albertel 15954: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15955: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15956: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1344 raeburn 15957: my $clonetitle;
15958: my @clonemsg;
1.566 albertel 15959: my $can_clone = 0;
1.944 raeburn 15960: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15961: if ($lctype ne 'community') {
15962: $lctype = 'course';
15963: }
1.566 albertel 15964: if ($clonehome eq 'no_host') {
1.944 raeburn 15965: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 15966: push(@clonemsg,({
15967: mt => 'No new community created.',
15968: args => [],
15969: },
15970: {
15971: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
15972: args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
15973: }));
1.908 raeburn 15974: } else {
1.1344 raeburn 15975: push(@clonemsg,({
15976: mt => 'No new course created.',
15977: args => [],
15978: },
15979: {
15980: mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
15981: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
15982: }));
15983: }
1.566 albertel 15984: } else {
15985: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1344 raeburn 15986: $clonetitle = $clonedesc{'description'};
1.944 raeburn 15987: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15988: if ($clonedesc{'type'} ne 'Community') {
1.1344 raeburn 15989: push(@clonemsg,({
15990: mt => 'No new community created.',
15991: args => [],
15992: },
15993: {
15994: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
15995: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
15996: }));
15997: return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 15998: }
15999: }
1.1262 raeburn 16000: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 16001: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 16002: $can_clone = 1;
16003: } else {
1.1221 raeburn 16004: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 16005: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 16006: if ($clonehash{'cloners'} eq '') {
16007: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
16008: if ($domdefs{'canclone'}) {
16009: unless ($domdefs{'canclone'} eq 'none') {
16010: if ($domdefs{'canclone'} eq 'domain') {
16011: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
16012: $can_clone = 1;
16013: }
16014: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16015: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
16016: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
16017: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
16018: $can_clone = 1;
16019: }
16020: }
16021: }
16022: }
1.578 raeburn 16023: } else {
1.1221 raeburn 16024: my @cloners = split(/,/,$clonehash{'cloners'});
16025: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 16026: $can_clone = 1;
1.1221 raeburn 16027: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 16028: $can_clone = 1;
1.1225 raeburn 16029: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
16030: $can_clone = 1;
1.1221 raeburn 16031: }
16032: unless ($can_clone) {
1.1225 raeburn 16033: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16034: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 16035: my (%gotdomdefaults,%gotcodedefaults);
16036: foreach my $cloner (@cloners) {
16037: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
16038: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
16039: my (%codedefaults,@code_order);
16040: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
16041: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
16042: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
16043: }
16044: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
16045: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
16046: }
16047: } else {
16048: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
16049: \%codedefaults,
16050: \@code_order);
16051: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
16052: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
16053: }
16054: if (@code_order > 0) {
16055: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
16056: $cloner,$clonehash{'internal.coursecode'},
16057: $args->{'crscode'})) {
16058: $can_clone = 1;
16059: last;
16060: }
16061: }
16062: }
16063: }
16064: }
1.1225 raeburn 16065: }
16066: }
16067: unless ($can_clone) {
16068: my $ccrole = 'cc';
16069: if ($args->{'crstype'} eq 'Community') {
16070: $ccrole = 'co';
16071: }
16072: my %roleshash =
16073: &Apache::lonnet::get_my_roles($args->{'ccuname'},
16074: $args->{'ccdomain'},
16075: 'userroles',['active'],[$ccrole],
16076: [$args->{'clonedomain'}]);
16077: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
16078: $can_clone = 1;
16079: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
16080: $args->{'ccuname'},$args->{'ccdomain'})) {
16081: $can_clone = 1;
1.1221 raeburn 16082: }
16083: }
16084: unless ($can_clone) {
16085: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16086: push(@clonemsg,({
16087: mt => 'No new community created.',
16088: args => [],
16089: },
16090: {
16091: 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]).',
16092: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16093: }));
1.942 raeburn 16094: } else {
1.1344 raeburn 16095: push(@clonemsg,({
16096: mt => 'No new course created.',
16097: args => [],
16098: },
16099: {
16100: 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]).',
16101: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16102: }));
1.1221 raeburn 16103: }
1.566 albertel 16104: }
1.578 raeburn 16105: }
1.566 albertel 16106: }
1.1344 raeburn 16107: return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16108: }
16109:
1.444 albertel 16110: sub construct_course {
1.1262 raeburn 16111: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1344 raeburn 16112: $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
16113: my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 16114: my $linefeed = '<br />'."\n";
16115: if ($context eq 'auto') {
16116: $linefeed = "\n";
16117: }
1.566 albertel 16118:
16119: #
16120: # Are we cloning?
16121: #
1.1344 raeburn 16122: my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16123: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1344 raeburn 16124: ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 16125: if (!$can_clone) {
1.1344 raeburn 16126: return (0,$outcome,$clonemsgref);
1.566 albertel 16127: }
16128: }
16129:
1.444 albertel 16130: #
16131: # Open course
16132: #
1.1239 raeburn 16133: my $showncrstype;
16134: if ($args->{'crstype'} eq 'Placement') {
16135: $showncrstype = 'placement test';
16136: } else {
16137: $showncrstype = lc($args->{'crstype'});
16138: }
1.444 albertel 16139: my %cenv=();
16140: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
16141: $args->{'cdescr'},
16142: $args->{'curl'},
16143: $args->{'course_home'},
16144: $args->{'nonstandard'},
16145: $args->{'crscode'},
16146: $args->{'ccuname'}.':'.
16147: $args->{'ccdomain'},
1.882 raeburn 16148: $args->{'crstype'},
1.1344 raeburn 16149: $cnum,$context,$category,
16150: $callercontext);
1.444 albertel 16151:
16152: # Note: The testing routines depend on this being output; see
16153: # Utils::Course. This needs to at least be output as a comment
16154: # if anyone ever decides to not show this, and Utils::Course::new
16155: # will need to be suitably modified.
1.1344 raeburn 16156: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16157: $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16158: } else {
16159: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16160: }
1.943 raeburn 16161: if ($$courseid =~ /^error:/) {
1.1344 raeburn 16162: return (0,$outcome,$clonemsgref);
1.943 raeburn 16163: }
16164:
1.444 albertel 16165: #
16166: # Check if created correctly
16167: #
1.479 albertel 16168: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 16169: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 16170: if ($crsuhome eq 'no_host') {
1.1344 raeburn 16171: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16172: $outcome .= &mt_user($user_lh,
16173: 'Course creation failed, unrecognized course home server.');
16174: } else {
16175: $outcome .= &mt('Course creation failed, unrecognized course home server.');
16176: }
16177: $outcome .= $linefeed;
16178: return (0,$outcome,$clonemsgref);
1.943 raeburn 16179: }
1.541 raeburn 16180: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 16181:
1.444 albertel 16182: #
1.566 albertel 16183: # Do the cloning
16184: #
1.1344 raeburn 16185: my @clonemsg;
1.566 albertel 16186: if ($can_clone && $cloneid) {
1.1344 raeburn 16187: push(@clonemsg,
16188: {
16189: mt => 'Created [_1] by cloning from [_2]',
16190: args => [$showncrstype,$clonetitle],
16191: });
1.566 albertel 16192: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 16193: # Copy all files
1.1344 raeburn 16194: my @info =
16195: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
16196: $args->{'dateshift'},$args->{'crscode'},
16197: $args->{'ccuname'}.':'.$args->{'ccdomain'},
16198: $args->{'tinyurls'});
16199: if (@info) {
16200: push(@clonemsg,@info);
16201: }
1.444 albertel 16202: # Restore URL
1.566 albertel 16203: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16204: # Restore title
1.566 albertel 16205: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16206: # Restore creation date, creator and creation context.
16207: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16208: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16209: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16210: # Mark as cloned
1.566 albertel 16211: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16212: # Need to clone grading mode
16213: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16214: $cenv{'grading'}=$newenv{'grading'};
16215: # Do not clone these environment entries
16216: &Apache::lonnet::del('environment',
16217: ['default_enrollment_start_date',
16218: 'default_enrollment_end_date',
16219: 'question.email',
16220: 'policy.email',
16221: 'comment.email',
16222: 'pch.users.denied',
1.725 raeburn 16223: 'plc.users.denied',
16224: 'hidefromcat',
1.1121 raeburn 16225: 'checkforpriv',
1.1355 ! raeburn 16226: 'categories'],
1.638 www 16227: $$crsudom,$$crsunum);
1.1170 raeburn 16228: if ($args->{'textbook'}) {
16229: $cenv{'internal.textbook'} = $args->{'textbook'};
16230: }
1.444 albertel 16231: }
1.566 albertel 16232:
1.444 albertel 16233: #
16234: # Set environment (will override cloned, if existing)
16235: #
16236: my @sections = ();
16237: my @xlists = ();
16238: if ($args->{'crstype'}) {
16239: $cenv{'type'}=$args->{'crstype'};
16240: }
16241: if ($args->{'crsid'}) {
16242: $cenv{'courseid'}=$args->{'crsid'};
16243: }
16244: if ($args->{'crscode'}) {
16245: $cenv{'internal.coursecode'}=$args->{'crscode'};
16246: }
16247: if ($args->{'crsquota'} ne '') {
16248: $cenv{'internal.coursequota'}=$args->{'crsquota'};
16249: } else {
16250: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
16251: }
16252: if ($args->{'ccuname'}) {
16253: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
16254: ':'.$args->{'ccdomain'};
16255: } else {
16256: $cenv{'internal.courseowner'} = $args->{'curruser'};
16257: }
1.1116 raeburn 16258: if ($args->{'defaultcredits'}) {
16259: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
16260: }
1.444 albertel 16261: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
16262: if ($args->{'crssections'}) {
16263: $cenv{'internal.sectionnums'} = '';
16264: if ($args->{'crssections'} =~ m/,/) {
16265: @sections = split/,/,$args->{'crssections'};
16266: } else {
16267: $sections[0] = $args->{'crssections'};
16268: }
16269: if (@sections > 0) {
16270: foreach my $item (@sections) {
16271: my ($sec,$gp) = split/:/,$item;
16272: my $class = $args->{'crscode'}.$sec;
16273: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16274: $cenv{'internal.sectionnums'} .= $item.',';
16275: unless ($addcheck eq 'ok') {
1.1263 raeburn 16276: push(@badclasses,$class);
1.444 albertel 16277: }
16278: }
16279: $cenv{'internal.sectionnums'} =~ s/,$//;
16280: }
16281: }
16282: # do not hide course coordinator from staff listing,
16283: # even if privileged
16284: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 16285: # add course coordinator's domain to domains to check for privileged users
16286: # if different to course domain
16287: if ($$crsudom ne $args->{'ccdomain'}) {
16288: $cenv{'checkforpriv'} = $args->{'ccdomain'};
16289: }
1.444 albertel 16290: # add crosslistings
16291: if ($args->{'crsxlist'}) {
16292: $cenv{'internal.crosslistings'}='';
16293: if ($args->{'crsxlist'} =~ m/,/) {
16294: @xlists = split/,/,$args->{'crsxlist'};
16295: } else {
16296: $xlists[0] = $args->{'crsxlist'};
16297: }
16298: if (@xlists > 0) {
16299: foreach my $item (@xlists) {
16300: my ($xl,$gp) = split/:/,$item;
16301: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
16302: $cenv{'internal.crosslistings'} .= $item.',';
16303: unless ($addcheck eq 'ok') {
1.1263 raeburn 16304: push(@badclasses,$xl);
1.444 albertel 16305: }
16306: }
16307: $cenv{'internal.crosslistings'} =~ s/,$//;
16308: }
16309: }
16310: if ($args->{'autoadds'}) {
16311: $cenv{'internal.autoadds'}=$args->{'autoadds'};
16312: }
16313: if ($args->{'autodrops'}) {
16314: $cenv{'internal.autodrops'}=$args->{'autodrops'};
16315: }
16316: # check for notification of enrollment changes
16317: my @notified = ();
16318: if ($args->{'notify_owner'}) {
16319: if ($args->{'ccuname'} ne '') {
16320: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
16321: }
16322: }
16323: if ($args->{'notify_dc'}) {
16324: if ($uname ne '') {
1.630 raeburn 16325: push(@notified,$uname.':'.$udom);
1.444 albertel 16326: }
16327: }
16328: if (@notified > 0) {
16329: my $notifylist;
16330: if (@notified > 1) {
16331: $notifylist = join(',',@notified);
16332: } else {
16333: $notifylist = $notified[0];
16334: }
16335: $cenv{'internal.notifylist'} = $notifylist;
16336: }
16337: if (@badclasses > 0) {
16338: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 16339: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16340: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16341: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16342: );
1.1264 raeburn 16343: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16344: &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 16345: if ($context eq 'auto') {
16346: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 16347: } else {
1.566 albertel 16348: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 16349: }
16350: foreach my $item (@badclasses) {
1.541 raeburn 16351: if ($context eq 'auto') {
1.1261 raeburn 16352: $outcome .= " - $item\n";
1.541 raeburn 16353: } else {
1.1261 raeburn 16354: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16355: }
1.1261 raeburn 16356: }
16357: if ($context eq 'auto') {
16358: $outcome .= $linefeed;
16359: } else {
16360: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 16361: }
1.444 albertel 16362: }
16363: if ($args->{'no_end_date'}) {
16364: $args->{'endaccess'} = 0;
16365: }
16366: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16367: $cenv{'internal.autoend'}=$args->{'enrollend'};
16368: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16369: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16370: if ($args->{'showphotos'}) {
16371: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16372: }
16373: $cenv{'internal.authtype'} = $args->{'authtype'};
16374: $cenv{'internal.autharg'} = $args->{'autharg'};
16375: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16376: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16377: 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');
16378: if ($context eq 'auto') {
16379: $outcome .= $krb_msg;
16380: } else {
1.566 albertel 16381: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16382: }
16383: $outcome .= $linefeed;
1.444 albertel 16384: }
16385: }
16386: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16387: if ($args->{'setpolicy'}) {
16388: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16389: }
16390: if ($args->{'setcontent'}) {
16391: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16392: }
1.1251 raeburn 16393: if ($args->{'setcomment'}) {
16394: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16395: }
1.444 albertel 16396: }
16397: if ($args->{'reshome'}) {
16398: $cenv{'reshome'}=$args->{'reshome'}.'/';
16399: $cenv{'reshome'}=~s/\/+$/\//;
16400: }
16401: #
16402: # course has keyed access
16403: #
16404: if ($args->{'setkeys'}) {
16405: $cenv{'keyaccess'}='yes';
16406: }
16407: # if specified, key authority is not course, but user
16408: # only active if keyaccess is yes
16409: if ($args->{'keyauth'}) {
1.487 albertel 16410: my ($user,$domain) = split(':',$args->{'keyauth'});
16411: $user = &LONCAPA::clean_username($user);
16412: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16413: if ($user ne '' && $domain ne '') {
1.487 albertel 16414: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16415: }
16416: }
16417:
1.1166 raeburn 16418: #
1.1167 raeburn 16419: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 16420: #
16421: if ($args->{'uniquecode'}) {
16422: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16423: if ($code) {
16424: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 16425: my %crsinfo =
16426: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16427: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16428: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16429: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16430: }
1.1166 raeburn 16431: if (ref($coderef)) {
16432: $$coderef = $code;
16433: }
16434: }
16435: }
16436:
1.444 albertel 16437: if ($args->{'disresdis'}) {
16438: $cenv{'pch.roles.denied'}='st';
16439: }
16440: if ($args->{'disablechat'}) {
16441: $cenv{'plc.roles.denied'}='st';
16442: }
16443:
16444: # Record we've not yet viewed the Course Initialization Helper for this
16445: # course
16446: $cenv{'course.helper.not.run'} = 1;
16447: #
16448: # Use new Randomseed
16449: #
16450: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16451: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16452: #
16453: # The encryption code and receipt prefix for this course
16454: #
16455: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16456: $cenv{'internal.encpref'}=100+int(9*rand(99));
16457: #
16458: # By default, use standard grading
16459: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16460:
1.541 raeburn 16461: $outcome .= $linefeed.&mt('Setting environment').': '.
16462: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16463: #
16464: # Open all assignments
16465: #
16466: if ($args->{'openall'}) {
1.1341 raeburn 16467: my $opendate = time;
16468: if ($args->{'openallfrom'} =~ /^\d+$/) {
16469: $opendate = $args->{'openallfrom'};
16470: }
1.444 albertel 16471: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1341 raeburn 16472: my %storecontent = ($storeunder => $opendate,
1.444 albertel 16473: $storeunder.'.type' => 'date_start');
1.1341 raeburn 16474: $outcome .= &mt('All assignments open starting [_1]',
16475: &Apache::lonlocal::locallocaltime($opendate)).': '.
16476: &Apache::lonnet::cput
16477: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16478: }
16479: #
16480: # Set first page
16481: #
16482: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16483: || ($cloneid)) {
1.445 albertel 16484: use LONCAPA::map;
1.444 albertel 16485: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16486:
16487: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16488: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16489:
1.444 albertel 16490: $outcome .= ($fatal?$errtext:'read ok').' - ';
16491: my $title; my $url;
16492: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16493: $title=&mt('Syllabus');
1.444 albertel 16494: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16495: } else {
1.963 raeburn 16496: $title=&mt('Table of Contents');
1.444 albertel 16497: $url='/adm/navmaps';
16498: }
1.445 albertel 16499:
16500: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16501: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16502:
16503: if ($errtext) { $fatal=2; }
1.541 raeburn 16504: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16505: }
1.566 albertel 16506:
1.1237 raeburn 16507: #
16508: # Set params for Placement Tests
16509: #
1.1239 raeburn 16510: if ($args->{'crstype'} eq 'Placement') {
16511: my %storecontent;
16512: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
16513: my %defaults = (
16514: buttonshide => { value => 'yes',
16515: type => 'string_yesno',},
16516: type => { value => 'randomizetry',
16517: type => 'string_questiontype',},
16518: maxtries => { value => 1,
16519: type => 'int_pos',},
16520: problemstatus => { value => 'no',
16521: type => 'string_problemstatus',},
16522: );
16523: foreach my $key (keys(%defaults)) {
16524: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
16525: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
16526: }
1.1237 raeburn 16527: &Apache::lonnet::cput
16528: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
16529: }
16530:
1.1344 raeburn 16531: return (1,$outcome,\@clonemsg);
1.444 albertel 16532: }
16533:
1.1166 raeburn 16534: sub make_unique_code {
16535: my ($cdom,$cnum) = @_;
16536: # get lock on uniquecodes db
16537: my $lockhash = {
16538: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16539: ':'.$env{'user.domain'},
16540: };
16541: my $tries = 0;
16542: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16543: my ($code,$error);
16544:
16545: while (($gotlock ne 'ok') && ($tries<3)) {
16546: $tries ++;
16547: sleep 1;
16548: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16549: }
16550: if ($gotlock eq 'ok') {
16551: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
16552: my $gotcode;
16553: my $attempts = 0;
16554: while ((!$gotcode) && ($attempts < 100)) {
16555: $code = &generate_code();
16556: if (!exists($currcodes{$code})) {
16557: $gotcode = 1;
16558: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
16559: $error = 'nostore';
16560: }
16561: }
16562: $attempts ++;
16563: }
16564: my @del_lock = ($cnum."\0".'uniquecodes');
16565: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
16566: } else {
16567: $error = 'nolock';
16568: }
16569: return ($code,$error);
16570: }
16571:
16572: sub generate_code {
16573: my $code;
16574: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
16575: for (my $i=0; $i<6; $i++) {
16576: my $lettnum = int (rand 2);
16577: my $item = '';
16578: if ($lettnum) {
16579: $item = $letts[int( rand(18) )];
16580: } else {
16581: $item = 1+int( rand(8) );
16582: }
16583: $code .= $item;
16584: }
16585: return $code;
16586: }
16587:
1.444 albertel 16588: ############################################################
16589: ############################################################
16590:
1.1237 raeburn 16591: # Community, Course and Placement Test
1.378 raeburn 16592: sub course_type {
16593: my ($cid) = @_;
16594: if (!defined($cid)) {
16595: $cid = $env{'request.course.id'};
16596: }
1.404 albertel 16597: if (defined($env{'course.'.$cid.'.type'})) {
16598: return $env{'course.'.$cid.'.type'};
1.378 raeburn 16599: } else {
16600: return 'Course';
1.377 raeburn 16601: }
16602: }
1.156 albertel 16603:
1.406 raeburn 16604: sub group_term {
16605: my $crstype = &course_type();
16606: my %names = (
16607: 'Course' => 'group',
1.865 raeburn 16608: 'Community' => 'group',
1.1237 raeburn 16609: 'Placement' => 'group',
1.406 raeburn 16610: );
16611: return $names{$crstype};
16612: }
16613:
1.902 raeburn 16614: sub course_types {
1.1310 raeburn 16615: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 16616: my %typename = (
16617: official => 'Official course',
16618: unofficial => 'Unofficial course',
16619: community => 'Community',
1.1165 raeburn 16620: textbook => 'Textbook course',
1.1237 raeburn 16621: placement => 'Placement test',
1.1310 raeburn 16622: lti => 'LTI provider',
1.902 raeburn 16623: );
16624: return (\@types,\%typename);
16625: }
16626:
1.156 albertel 16627: sub icon {
16628: my ($file)=@_;
1.505 albertel 16629: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 16630: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 16631: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 16632: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
16633: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
16634: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16635: $curfext.".gif") {
16636: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16637: $curfext.".gif";
16638: }
16639: }
1.249 albertel 16640: return &lonhttpdurl($iconname);
1.154 albertel 16641: }
1.84 albertel 16642:
1.575 albertel 16643: sub lonhttpdurl {
1.692 www 16644: #
16645: # Had been used for "small fry" static images on separate port 8080.
16646: # Modify here if lightweight http functionality desired again.
16647: # Currently eliminated due to increasing firewall issues.
16648: #
1.575 albertel 16649: my ($url)=@_;
1.692 www 16650: return $url;
1.215 albertel 16651: }
16652:
1.213 albertel 16653: sub connection_aborted {
16654: my ($r)=@_;
16655: $r->print(" ");$r->rflush();
16656: my $c = $r->connection;
16657: return $c->aborted();
16658: }
16659:
1.221 foxr 16660: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 16661: # strings as 'strings'.
16662: sub escape_single {
1.221 foxr 16663: my ($input) = @_;
1.223 albertel 16664: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16665: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16666: return $input;
16667: }
1.223 albertel 16668:
1.222 foxr 16669: # Same as escape_single, but escape's "'s This
16670: # can be used for "strings"
16671: sub escape_double {
16672: my ($input) = @_;
16673: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16674: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16675: return $input;
16676: }
1.223 albertel 16677:
1.222 foxr 16678: # Escapes the last element of a full URL.
16679: sub escape_url {
16680: my ($url) = @_;
1.238 raeburn 16681: my @urlslices = split(/\//, $url,-1);
1.369 www 16682: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 16683: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16684: }
1.462 albertel 16685:
1.820 raeburn 16686: sub compare_arrays {
16687: my ($arrayref1,$arrayref2) = @_;
16688: my (@difference,%count);
16689: @difference = ();
16690: %count = ();
16691: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16692: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16693: foreach my $element (keys(%count)) {
16694: if ($count{$element} == 1) {
16695: push(@difference,$element);
16696: }
16697: }
16698: }
16699: return @difference;
16700: }
16701:
1.1322 raeburn 16702: sub lon_status_items {
16703: my %defaults = (
16704: E => 100,
16705: W => 4,
16706: N => 1,
1.1324 raeburn 16707: U => 5,
1.1322 raeburn 16708: threshold => 200,
16709: sysmail => 2500,
16710: );
16711: my %names = (
16712: E => 'Errors',
16713: W => 'Warnings',
16714: N => 'Notices',
1.1324 raeburn 16715: U => 'Unsent',
1.1322 raeburn 16716: );
16717: return (\%defaults,\%names);
16718: }
16719:
1.817 bisitz 16720: # -------------------------------------------------------- Initialize user login
1.462 albertel 16721: sub init_user_environment {
1.463 albertel 16722: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16723: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16724:
16725: my $public=($username eq 'public' && $domain eq 'public');
16726:
1.1062 raeburn 16727: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16728: my $now=time;
16729:
16730: if ($public) {
16731: my $max_public=100;
16732: my $oldest;
16733: my $oldest_time=0;
16734: for(my $next=1;$next<=$max_public;$next++) {
16735: if (-e $lonids."/publicuser_$next.id") {
16736: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16737: if ($mtime<$oldest_time || !$oldest_time) {
16738: $oldest_time=$mtime;
16739: $oldest=$next;
16740: }
16741: } else {
16742: $cookie="publicuser_$next";
16743: last;
16744: }
16745: }
16746: if (!$cookie) { $cookie="publicuser_$oldest"; }
16747: } else {
1.1275 raeburn 16748: # See if old ID present, if so, remove if this isn't a robot,
16749: # killing any existing non-robot sessions
1.463 albertel 16750: if (!$args->{'robot'}) {
16751: opendir(DIR,$lonids);
16752: while ($filename=readdir(DIR)) {
16753: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 16754: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
16755: &GDBM_READER(),0640)) {
1.1295 raeburn 16756: my $linkedfile;
1.1320 raeburn 16757: if (exists($oldenv{'user.linkedenv'})) {
16758: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 16759: }
1.1320 raeburn 16760: untie(%oldenv);
16761: if (unlink("$lonids/$filename")) {
16762: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
16763: if (-l "$lonids/$linkedfile.id") {
16764: unlink("$lonids/$linkedfile.id");
16765: }
1.1295 raeburn 16766: }
16767: }
16768: } else {
16769: unlink($lonids.'/'.$filename);
16770: }
1.463 albertel 16771: }
1.462 albertel 16772: }
1.463 albertel 16773: closedir(DIR);
1.1204 raeburn 16774: # If there is a undeleted lockfile for the user's paste buffer remove it.
16775: my $namespace = 'nohist_courseeditor';
16776: my $lockingkey = 'paste'."\0".'locked_num';
16777: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16778: $domain,$username);
16779: if (exists($lockhash{$lockingkey})) {
16780: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16781: unless ($delresult eq 'ok') {
16782: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16783: }
16784: }
1.462 albertel 16785: }
16786: # Give them a new cookie
1.463 albertel 16787: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16788: : $now.$$.int(rand(10000)));
1.463 albertel 16789: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16790:
16791: # Initialize roles
16792:
1.1062 raeburn 16793: ($userroles,$firstaccenv,$timerintenv) =
16794: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16795: }
16796: # ------------------------------------ Check browser type and MathML capability
16797:
1.1194 raeburn 16798: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16799: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16800:
16801: # ------------------------------------------------------------- Get environment
16802:
16803: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16804: my ($tmp) = keys(%userenv);
1.1275 raeburn 16805: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 16806: undef(%userenv);
16807: }
16808: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16809: $form->{'interface'}=$userenv{'interface'};
16810: }
16811: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16812:
16813: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16814: foreach my $option ('interface','localpath','localres') {
16815: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16816: }
16817: # --------------------------------------------------------- Write first profile
16818:
16819: {
1.1350 raeburn 16820: my $ip = &Apache::lonnet::get_requestor_ip($r);
1.462 albertel 16821: my %initial_env =
16822: ("user.name" => $username,
16823: "user.domain" => $domain,
16824: "user.home" => $authhost,
16825: "browser.type" => $clientbrowser,
16826: "browser.version" => $clientversion,
16827: "browser.mathml" => $clientmathml,
16828: "browser.unicode" => $clientunicode,
16829: "browser.os" => $clientos,
1.1137 raeburn 16830: "browser.mobile" => $clientmobile,
1.1141 raeburn 16831: "browser.info" => $clientinfo,
1.1194 raeburn 16832: "browser.osversion" => $clientosversion,
1.462 albertel 16833: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16834: "request.course.fn" => '',
16835: "request.course.uri" => '',
16836: "request.course.sec" => '',
16837: "request.role" => 'cm',
16838: "request.role.adv" => $env{'user.adv'},
1.1350 raeburn 16839: "request.host" => $ip,);
1.462 albertel 16840:
16841: if ($form->{'localpath'}) {
16842: $initial_env{"browser.localpath"} = $form->{'localpath'};
16843: $initial_env{"browser.localres"} = $form->{'localres'};
16844: }
16845:
16846: if ($form->{'interface'}) {
16847: $form->{'interface'}=~s/\W//gs;
16848: $initial_env{"browser.interface"} = $form->{'interface'};
16849: $env{'browser.interface'}=$form->{'interface'};
16850: }
16851:
1.1157 raeburn 16852: if ($form->{'iptoken'}) {
16853: my $lonhost = $r->dir_config('lonHostID');
16854: $initial_env{"user.noloadbalance"} = $lonhost;
16855: $env{'user.noloadbalance'} = $lonhost;
16856: }
16857:
1.1268 raeburn 16858: if ($form->{'noloadbalance'}) {
16859: my @hosts = &Apache::lonnet::current_machine_ids();
16860: my $hosthere = $form->{'noloadbalance'};
16861: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16862: $initial_env{"user.noloadbalance"} = $hosthere;
16863: $env{'user.noloadbalance'} = $hosthere;
16864: }
16865: }
16866:
1.1016 raeburn 16867: unless ($domain eq 'public') {
1.1273 raeburn 16868: my %is_adv = ( is_adv => $env{'user.adv'} );
16869: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
16870:
16871: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16872: $userenv{'availabletools.'.$tool} =
16873: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16874: undef,\%userenv,\%domdef,\%is_adv);
16875: }
1.980 raeburn 16876:
1.1311 raeburn 16877: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 16878: $userenv{'canrequest.'.$crstype} =
16879: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16880: 'reload','requestcourses',
16881: \%userenv,\%domdef,\%is_adv);
16882: }
1.724 raeburn 16883:
1.1273 raeburn 16884: $userenv{'canrequest.author'} =
16885: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16886: 'reload','requestauthor',
1.980 raeburn 16887: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 16888: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16889: $domain,$username);
16890: my $reqstatus = $reqauthor{'author_status'};
16891: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16892: if (ref($reqauthor{'author'}) eq 'HASH') {
16893: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16894: $reqauthor{'author'}{'timestamp'};
16895: }
1.1092 raeburn 16896: }
1.1287 raeburn 16897: my ($types,$typename) = &course_types();
16898: if (ref($types) eq 'ARRAY') {
16899: my @options = ('approval','validate','autolimit');
16900: my $optregex = join('|',@options);
16901: my (%willtrust,%trustchecked);
16902: foreach my $type (@{$types}) {
16903: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
16904: if ($dom_str ne '') {
16905: my $updatedstr = '';
16906: my @possdomains = split(',',$dom_str);
16907: foreach my $entry (@possdomains) {
16908: my ($extdom,$extopt) = split(':',$entry);
16909: unless ($trustchecked{$extdom}) {
16910: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
16911: $trustchecked{$extdom} = 1;
16912: }
16913: if ($willtrust{$extdom}) {
16914: $updatedstr .= $entry.',';
16915: }
16916: }
16917: $updatedstr =~ s/,$//;
16918: if ($updatedstr) {
16919: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
16920: } else {
16921: delete($userenv{'reqcrsotherdom.'.$type});
16922: }
16923: }
16924: }
16925: }
1.1092 raeburn 16926: }
1.462 albertel 16927: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16928:
1.462 albertel 16929: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16930: &GDBM_WRCREAT(),0640)) {
16931: &_add_to_env(\%disk_env,\%initial_env);
16932: &_add_to_env(\%disk_env,\%userenv,'environment.');
16933: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16934: if (ref($firstaccenv) eq 'HASH') {
16935: &_add_to_env(\%disk_env,$firstaccenv);
16936: }
16937: if (ref($timerintenv) eq 'HASH') {
16938: &_add_to_env(\%disk_env,$timerintenv);
16939: }
1.463 albertel 16940: if (ref($args->{'extra_env'})) {
16941: &_add_to_env(\%disk_env,$args->{'extra_env'});
16942: }
1.462 albertel 16943: untie(%disk_env);
16944: } else {
1.705 tempelho 16945: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16946: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16947: return 'error: '.$!;
16948: }
16949: }
16950: $env{'request.role'}='cm';
16951: $env{'request.role.adv'}=$env{'user.adv'};
16952: $env{'browser.type'}=$clientbrowser;
16953:
16954: return $cookie;
16955:
16956: }
16957:
16958: sub _add_to_env {
16959: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16960: if (ref($env_data) eq 'HASH') {
16961: while (my ($key,$value) = each(%$env_data)) {
16962: $idf->{$prefix.$key} = $value;
16963: $env{$prefix.$key} = $value;
16964: }
1.462 albertel 16965: }
16966: }
16967:
1.685 tempelho 16968: # --- Get the symbolic name of a problem and the url
16969: sub get_symb {
16970: my ($request,$silent) = @_;
1.726 raeburn 16971: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16972: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16973: if ($symb eq '') {
16974: if (!$silent) {
1.1071 raeburn 16975: if (ref($request)) {
16976: $request->print("Unable to handle ambiguous references:$url:.");
16977: }
1.685 tempelho 16978: return ();
16979: }
16980: }
16981: &Apache::lonenc::check_decrypt(\$symb);
16982: return ($symb);
16983: }
16984:
16985: # --------------------------------------------------------------Get annotation
16986:
16987: sub get_annotation {
16988: my ($symb,$enc) = @_;
16989:
16990: my $key = $symb;
16991: if (!$enc) {
16992: $key =
16993: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16994: }
16995: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16996: return $annotation{$key};
16997: }
16998:
16999: sub clean_symb {
1.731 raeburn 17000: my ($symb,$delete_enc) = @_;
1.685 tempelho 17001:
17002: &Apache::lonenc::check_decrypt(\$symb);
17003: my $enc = $env{'request.enc'};
1.731 raeburn 17004: if ($delete_enc) {
1.730 raeburn 17005: delete($env{'request.enc'});
17006: }
1.685 tempelho 17007:
17008: return ($symb,$enc);
17009: }
1.462 albertel 17010:
1.1181 raeburn 17011: ############################################################
17012: ############################################################
17013:
17014: =pod
17015:
17016: =head1 Routines for building display used to search for courses
17017:
17018:
17019: =over 4
17020:
17021: =item * &build_filters()
17022:
17023: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 17024: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
17025: and quotacheck.pl
17026:
1.1181 raeburn 17027:
17028: Inputs:
17029:
17030: filterlist - anonymous array of fields to include as potential filters
17031:
17032: crstype - course type
17033:
17034: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
17035: to pop-open a course selector (will contain "extra element").
17036:
17037: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
17038:
17039: filter - anonymous hash of criteria and their values
17040:
17041: action - form action
17042:
17043: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
17044:
1.1182 raeburn 17045: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 17046:
17047: cloneruname - username of owner of new course who wants to clone
17048:
17049: clonerudom - domain of owner of new course who wants to clone
17050:
17051: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
17052:
17053: codetitlesref - reference to array of titles of components in institutional codes (official courses)
17054:
17055: codedom - domain
17056:
17057: formname - value of form element named "form".
17058:
17059: fixeddom - domain, if fixed.
17060:
17061: prevphase - value to assign to form element named "phase" when going back to the previous screen
17062:
17063: cnameelement - name of form element in form on opener page which will receive title of selected course
17064:
17065: cnumelement - name of form element in form on opener page which will receive courseID of selected course
17066:
17067: cdomelement - name of form element in form on opener page which will receive domain of selected course
17068:
17069: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
17070:
17071: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
17072:
17073: clonewarning - warning message about missing information for intended course owner when DC creates a course
17074:
1.1182 raeburn 17075:
1.1181 raeburn 17076: Returns: $output - HTML for display of search criteria, and hidden form elements.
17077:
1.1182 raeburn 17078:
1.1181 raeburn 17079: Side Effects: None
17080:
17081: =cut
17082:
17083: # ---------------------------------------------- search for courses based on last activity etc.
17084:
17085: sub build_filters {
17086: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
17087: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
17088: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
17089: $cnameelement,$cnumelement,$cdomelement,$setroles,
17090: $clonetext,$clonewarning) = @_;
1.1182 raeburn 17091: my ($list,$jscript);
1.1181 raeburn 17092: my $onchange = 'javascript:updateFilters(this)';
17093: my ($domainselectform,$sincefilterform,$createdfilterform,
17094: $ownerdomselectform,$persondomselectform,$instcodeform,
17095: $typeselectform,$instcodetitle);
17096: if ($formname eq '') {
17097: $formname = $caller;
17098: }
17099: foreach my $item (@{$filterlist}) {
17100: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
17101: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
17102: if ($item eq 'domainfilter') {
17103: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
17104: } elsif ($item eq 'coursefilter') {
17105: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
17106: } elsif ($item eq 'ownerfilter') {
17107: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17108: } elsif ($item eq 'ownerdomfilter') {
17109: $filter->{'ownerdomfilter'} =
17110: &LONCAPA::clean_domain($filter->{$item});
17111: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
17112: 'ownerdomfilter',1);
17113: } elsif ($item eq 'personfilter') {
17114: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17115: } elsif ($item eq 'persondomfilter') {
17116: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
17117: 'persondomfilter',1);
17118: } else {
17119: $filter->{$item} =~ s/\W//g;
17120: }
17121: if (!$filter->{$item}) {
17122: $filter->{$item} = '';
17123: }
17124: }
17125: if ($item eq 'domainfilter') {
17126: my $allow_blank = 1;
17127: if ($formname eq 'portform') {
17128: $allow_blank=0;
17129: } elsif ($formname eq 'studentform') {
17130: $allow_blank=0;
17131: }
17132: if ($fixeddom) {
17133: $domainselectform = '<input type="hidden" name="domainfilter"'.
17134: ' value="'.$codedom.'" />'.
17135: &Apache::lonnet::domain($codedom,'description');
17136: } else {
17137: $domainselectform = &select_dom_form($filter->{$item},
17138: 'domainfilter',
17139: $allow_blank,'',$onchange);
17140: }
17141: } else {
17142: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
17143: }
17144: }
17145:
17146: # last course activity filter and selection
17147: $sincefilterform = &timebased_select_form('sincefilter',$filter);
17148:
17149: # course created filter and selection
17150: if (exists($filter->{'createdfilter'})) {
17151: $createdfilterform = &timebased_select_form('createdfilter',$filter);
17152: }
17153:
1.1239 raeburn 17154: my $prefix = $crstype;
17155: if ($crstype eq 'Placement') {
17156: $prefix = 'Placement Test'
17157: }
1.1181 raeburn 17158: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 17159: 'cac' => "$prefix Activity",
17160: 'ccr' => "$prefix Created",
17161: 'cde' => "$prefix Title",
17162: 'cdo' => "$prefix Domain",
1.1181 raeburn 17163: 'ins' => 'Institutional Code',
17164: 'inc' => 'Institutional Categorization',
1.1239 raeburn 17165: 'cow' => "$prefix Owner/Co-owner",
17166: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 17167: 'cog' => 'Type',
17168: );
17169:
17170: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17171: my $typeval = 'Course';
17172: if ($crstype eq 'Community') {
17173: $typeval = 'Community';
1.1239 raeburn 17174: } elsif ($crstype eq 'Placement') {
17175: $typeval = 'Placement';
1.1181 raeburn 17176: }
17177: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
17178: } else {
17179: $typeselectform = '<select name="type" size="1"';
17180: if ($onchange) {
17181: $typeselectform .= ' onchange="'.$onchange.'"';
17182: }
17183: $typeselectform .= '>'."\n";
1.1237 raeburn 17184: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 17185: my $shown;
17186: if ($posstype eq 'Placement') {
17187: $shown = &mt('Placement Test');
17188: } else {
17189: $shown = &mt($posstype);
17190: }
1.1181 raeburn 17191: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 17192: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 17193: }
17194: $typeselectform.="</select>";
17195: }
17196:
17197: my ($cloneableonlyform,$cloneabletitle);
17198: if (exists($filter->{'cloneableonly'})) {
17199: my $cloneableon = '';
17200: my $cloneableoff = ' checked="checked"';
17201: if ($filter->{'cloneableonly'}) {
17202: $cloneableon = $cloneableoff;
17203: $cloneableoff = '';
17204: }
17205: $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>';
17206: if ($formname eq 'ccrs') {
1.1187 bisitz 17207: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 17208: } else {
17209: $cloneabletitle = &mt('Cloneable by you');
17210: }
17211: }
17212: my $officialjs;
17213: if ($crstype eq 'Course') {
17214: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 17215: # if (($fixeddom) || ($formname eq 'requestcrs') ||
17216: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
17217: if ($codedom) {
1.1181 raeburn 17218: $officialjs = 1;
17219: ($instcodeform,$jscript,$$numtitlesref) =
17220: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
17221: $officialjs,$codetitlesref);
17222: if ($jscript) {
1.1182 raeburn 17223: $jscript = '<script type="text/javascript">'."\n".
17224: '// <![CDATA['."\n".
17225: $jscript."\n".
17226: '// ]]>'."\n".
17227: '</script>'."\n";
1.1181 raeburn 17228: }
17229: }
17230: if ($instcodeform eq '') {
17231: $instcodeform =
17232: '<input type="text" name="instcodefilter" size="10" value="'.
17233: $list->{'instcodefilter'}.'" />';
17234: $instcodetitle = $lt{'ins'};
17235: } else {
17236: $instcodetitle = $lt{'inc'};
17237: }
17238: if ($fixeddom) {
17239: $instcodetitle .= '<br />('.$codedom.')';
17240: }
17241: }
17242: }
17243: my $output = qq|
17244: <form method="post" name="filterpicker" action="$action">
17245: <input type="hidden" name="form" value="$formname" />
17246: |;
17247: if ($formname eq 'modifycourse') {
17248: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
17249: '<input type="hidden" name="prevphase" value="'.
17250: $prevphase.'" />'."\n";
1.1198 musolffc 17251: } elsif ($formname eq 'quotacheck') {
17252: $output .= qq|
17253: <input type="hidden" name="sortby" value="" />
17254: <input type="hidden" name="sortorder" value="" />
17255: |;
17256: } else {
1.1181 raeburn 17257: my $name_input;
17258: if ($cnameelement ne '') {
17259: $name_input = '<input type="hidden" name="cnameelement" value="'.
17260: $cnameelement.'" />';
17261: }
17262: $output .= qq|
1.1182 raeburn 17263: <input type="hidden" name="cnumelement" value="$cnumelement" />
17264: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 17265: $name_input
17266: $roleelement
17267: $multelement
17268: $typeelement
17269: |;
17270: if ($formname eq 'portform') {
17271: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
17272: }
17273: }
17274: if ($fixeddom) {
17275: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
17276: }
17277: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
17278: if ($sincefilterform) {
17279: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
17280: .$sincefilterform
17281: .&Apache::lonhtmlcommon::row_closure();
17282: }
17283: if ($createdfilterform) {
17284: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17285: .$createdfilterform
17286: .&Apache::lonhtmlcommon::row_closure();
17287: }
17288: if ($domainselectform) {
17289: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
17290: .$domainselectform
17291: .&Apache::lonhtmlcommon::row_closure();
17292: }
17293: if ($typeselectform) {
17294: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17295: $output .= $typeselectform;
17296: } else {
17297: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
17298: .$typeselectform
17299: .&Apache::lonhtmlcommon::row_closure();
17300: }
17301: }
17302: if ($instcodeform) {
17303: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
17304: .$instcodeform
17305: .&Apache::lonhtmlcommon::row_closure();
17306: }
17307: if (exists($filter->{'ownerfilter'})) {
17308: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
17309: '<table><tr><td>'.&mt('Username').'<br />'.
17310: '<input type="text" name="ownerfilter" size="20" value="'.
17311: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17312: $ownerdomselectform.'</td></tr></table>'.
17313: &Apache::lonhtmlcommon::row_closure();
17314: }
17315: if (exists($filter->{'personfilter'})) {
17316: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
17317: '<table><tr><td>'.&mt('Username').'<br />'.
17318: '<input type="text" name="personfilter" size="20" value="'.
17319: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17320: $persondomselectform.'</td></tr></table>'.
17321: &Apache::lonhtmlcommon::row_closure();
17322: }
17323: if (exists($filter->{'coursefilter'})) {
17324: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
17325: .'<input type="text" name="coursefilter" size="25" value="'
17326: .$list->{'coursefilter'}.'" />'
17327: .&Apache::lonhtmlcommon::row_closure();
17328: }
17329: if ($cloneableonlyform) {
17330: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
17331: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
17332: }
17333: if (exists($filter->{'descriptfilter'})) {
17334: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
17335: .'<input type="text" name="descriptfilter" size="40" value="'
17336: .$list->{'descriptfilter'}.'" />'
17337: .&Apache::lonhtmlcommon::row_closure(1);
17338: }
17339: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
17340: '<input type="hidden" name="updater" value="" />'."\n".
17341: '<input type="submit" name="gosearch" value="'.
17342: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
17343: return $jscript.$clonewarning.$output;
17344: }
17345:
17346: =pod
17347:
17348: =item * &timebased_select_form()
17349:
1.1182 raeburn 17350: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 17351: filter e.g., Course Activity, Course Created, when searching for courses
17352: or communities
17353:
17354: Inputs:
17355:
17356: item - name of form element (sincefilter or createdfilter)
17357:
17358: filter - anonymous hash of criteria and their values
17359:
17360: Returns: HTML for a select box contained a blank, then six time selections,
17361: with value set in incoming form variables currently selected.
17362:
17363: Side Effects: None
17364:
17365: =cut
17366:
17367: sub timebased_select_form {
17368: my ($item,$filter) = @_;
17369: if (ref($filter) eq 'HASH') {
17370: $filter->{$item} =~ s/[^\d-]//g;
17371: if (!$filter->{$item}) { $filter->{$item}=-1; }
17372: return &select_form(
17373: $filter->{$item},
17374: $item,
17375: { '-1' => '',
17376: '86400' => &mt('today'),
17377: '604800' => &mt('last week'),
17378: '2592000' => &mt('last month'),
17379: '7776000' => &mt('last three months'),
17380: '15552000' => &mt('last six months'),
17381: '31104000' => &mt('last year'),
17382: 'select_form_order' =>
17383: ['-1','86400','604800','2592000','7776000',
17384: '15552000','31104000']});
17385: }
17386: }
17387:
17388: =pod
17389:
17390: =item * &js_changer()
17391:
17392: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 17393: when course type or domain is changed, and also to hide 'Searching ...' on
17394: page load completion for page showing search result.
1.1181 raeburn 17395:
17396: Inputs: None
17397:
1.1183 raeburn 17398: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 17399:
17400: Side Effects: None
17401:
17402: =cut
17403:
17404: sub js_changer {
17405: return <<ENDJS;
17406: <script type="text/javascript">
17407: // <![CDATA[
17408: function updateFilters(caller) {
17409: if (typeof(caller) != "undefined") {
17410: document.filterpicker.updater.value = caller.name;
17411: }
17412: document.filterpicker.submit();
17413: }
1.1183 raeburn 17414:
17415: function hideSearching() {
17416: if (document.getElementById('searching')) {
17417: document.getElementById('searching').style.display = 'none';
17418: }
17419: return;
17420: }
17421:
1.1181 raeburn 17422: // ]]>
17423: </script>
17424:
17425: ENDJS
17426: }
17427:
17428: =pod
17429:
1.1182 raeburn 17430: =item * &search_courses()
17431:
17432: Process selected filters form course search form and pass to lonnet::courseiddump
17433: to retrieve a hash for which keys are courseIDs which match the selected filters.
17434:
17435: Inputs:
17436:
17437: dom - domain being searched
17438:
17439: type - course type ('Course' or 'Community' or '.' if any).
17440:
17441: filter - anonymous hash of criteria and their values
17442:
17443: numtitles - for institutional codes - number of categories
17444:
17445: cloneruname - optional username of new course owner
17446:
17447: clonerudom - optional domain of new course owner
17448:
1.1221 raeburn 17449: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 17450: (used when DC is using course creation form)
17451:
17452: codetitles - reference to array of titles of components in institutional codes (official courses).
17453:
1.1221 raeburn 17454: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17455: (and so can clone automatically)
17456:
17457: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17458:
17459: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17460: courses to clone
1.1182 raeburn 17461:
17462: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17463:
17464:
17465: Side Effects: None
17466:
17467: =cut
17468:
17469:
17470: sub search_courses {
1.1221 raeburn 17471: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17472: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 17473: my (%courses,%showcourses,$cloner);
17474: if (($filter->{'ownerfilter'} ne '') ||
17475: ($filter->{'ownerdomfilter'} ne '')) {
17476: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17477: $filter->{'ownerdomfilter'};
17478: }
17479: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17480: if (!$filter->{$item}) {
17481: $filter->{$item}='.';
17482: }
17483: }
17484: my $now = time;
17485: my $timefilter =
17486: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17487: my ($createdbefore,$createdafter);
17488: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17489: $createdbefore = $now;
17490: $createdafter = $now-$filter->{'createdfilter'};
17491: }
17492: my ($instcodefilter,$regexpok);
17493: if ($numtitles) {
17494: if ($env{'form.official'} eq 'on') {
17495: $instcodefilter =
17496: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17497: $regexpok = 1;
17498: } elsif ($env{'form.official'} eq 'off') {
17499: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17500: unless ($instcodefilter eq '') {
17501: $regexpok = -1;
17502: }
17503: }
17504: } else {
17505: $instcodefilter = $filter->{'instcodefilter'};
17506: }
17507: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17508: if ($type eq '') { $type = '.'; }
17509:
17510: if (($clonerudom ne '') && ($cloneruname ne '')) {
17511: $cloner = $cloneruname.':'.$clonerudom;
17512: }
17513: %courses = &Apache::lonnet::courseiddump($dom,
17514: $filter->{'descriptfilter'},
17515: $timefilter,
17516: $instcodefilter,
17517: $filter->{'combownerfilter'},
17518: $filter->{'coursefilter'},
17519: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 17520: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 17521: $filter->{'cloneableonly'},
17522: $createdbefore,$createdafter,undef,
1.1221 raeburn 17523: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 17524: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17525: my $ccrole;
17526: if ($type eq 'Community') {
17527: $ccrole = 'co';
17528: } else {
17529: $ccrole = 'cc';
17530: }
17531: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17532: $filter->{'persondomfilter'},
17533: 'userroles',undef,
17534: [$ccrole,'in','ad','ep','ta','cr'],
17535: $dom);
17536: foreach my $role (keys(%rolehash)) {
17537: my ($cnum,$cdom,$courserole) = split(':',$role);
17538: my $cid = $cdom.'_'.$cnum;
17539: if (exists($courses{$cid})) {
17540: if (ref($courses{$cid}) eq 'HASH') {
17541: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17542: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 17543: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 17544: }
17545: } else {
17546: $courses{$cid}{roles} = [$courserole];
17547: }
17548: $showcourses{$cid} = $courses{$cid};
17549: }
17550: }
17551: }
17552: %courses = %showcourses;
17553: }
17554: return %courses;
17555: }
17556:
17557: =pod
17558:
1.1181 raeburn 17559: =back
17560:
1.1207 raeburn 17561: =head1 Routines for version requirements for current course.
17562:
17563: =over 4
17564:
17565: =item * &check_release_required()
17566:
17567: Compares required LON-CAPA version with version on server, and
17568: if required version is newer looks for a server with the required version.
17569:
17570: Looks first at servers in user's owen domain; if none suitable, looks at
17571: servers in course's domain are permitted to host sessions for user's domain.
17572:
17573: Inputs:
17574:
17575: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17576:
17577: $courseid - Course ID of current course
17578:
17579: $rolecode - User's current role in course (for switchserver query string).
17580:
17581: $required - LON-CAPA version needed by course (format: Major.Minor).
17582:
17583:
17584: Returns:
17585:
17586: $switchserver - query string tp append to /adm/switchserver call (if
17587: current server's LON-CAPA version is too old.
17588:
17589: $warning - Message is displayed if no suitable server could be found.
17590:
17591: =cut
17592:
17593: sub check_release_required {
17594: my ($loncaparev,$courseid,$rolecode,$required) = @_;
17595: my ($switchserver,$warning);
17596: if ($required ne '') {
17597: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
17598: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17599: if ($reqdmajor ne '' && $reqdminor ne '') {
17600: my $otherserver;
17601: if (($major eq '' && $minor eq '') ||
17602: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
17603: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
17604: my $switchlcrev =
17605: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
17606: $userdomserver);
17607: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17608: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
17609: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
17610: my $cdom = $env{'course.'.$courseid.'.domain'};
17611: if ($cdom ne $env{'user.domain'}) {
17612: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
17613: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
17614: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17615: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
17616: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
17617: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
17618: my $canhost =
17619: &Apache::lonnet::can_host_session($env{'user.domain'},
17620: $coursedomserver,
17621: $remoterev,
17622: $udomdefaults{'remotesessions'},
17623: $defdomdefaults{'hostedsessions'});
17624:
17625: if ($canhost) {
17626: $otherserver = $coursedomserver;
17627: } else {
17628: $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.");
17629: }
17630: } else {
17631: $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).");
17632: }
17633: } else {
17634: $otherserver = $userdomserver;
17635: }
17636: }
17637: if ($otherserver ne '') {
17638: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
17639: }
17640: }
17641: }
17642: return ($switchserver,$warning);
17643: }
17644:
17645: =pod
17646:
17647: =item * &check_release_result()
17648:
17649: Inputs:
17650:
17651: $switchwarning - Warning message if no suitable server found to host session.
17652:
17653: $switchserver - query string to append to /adm/switchserver containing lonHostID
17654: and current role.
17655:
17656: Returns: HTML to display with information about requirement to switch server.
17657: Either displaying warning with link to Roles/Courses screen or
17658: display link to switchserver.
17659:
1.1181 raeburn 17660: =cut
17661:
1.1207 raeburn 17662: sub check_release_result {
17663: my ($switchwarning,$switchserver) = @_;
17664: my $output = &start_page('Selected course unavailable on this server').
17665: '<p class="LC_warning">';
17666: if ($switchwarning) {
17667: $output .= $switchwarning.'<br /><a href="/adm/roles">';
17668: if (&show_course()) {
17669: $output .= &mt('Display courses');
17670: } else {
17671: $output .= &mt('Display roles');
17672: }
17673: $output .= '</a>';
17674: } elsif ($switchserver) {
17675: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
17676: '<br />'.
17677: '<a href="/adm/switchserver?'.$switchserver.'">'.
17678: &mt('Switch Server').
17679: '</a>';
17680: }
17681: $output .= '</p>'.&end_page();
17682: return $output;
17683: }
17684:
17685: =pod
17686:
17687: =item * &needs_coursereinit()
17688:
17689: Determine if course contents stored for user's session needs to be
17690: refreshed, because content has changed since "Big Hash" last tied.
17691:
17692: Check for change is made if time last checked is more than 10 minutes ago
17693: (by default).
17694:
17695: Inputs:
17696:
17697: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17698:
17699: $interval (optional) - Time which may elapse (in s) between last check for content
17700: change in current course. (default: 600 s).
17701:
17702: Returns: an array; first element is:
17703:
17704: =over 4
17705:
17706: 'switch' - if content updates mean user's session
17707: needs to be switched to a server running a newer LON-CAPA version
17708:
17709: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
17710: on current server hosting user's session
17711:
17712: '' - if no action required.
17713:
17714: =back
17715:
17716: If first item element is 'switch':
17717:
17718: second item is $switchwarning - Warning message if no suitable server found to host session.
17719:
17720: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
17721: and current role.
17722:
17723: otherwise: no other elements returned.
17724:
17725: =back
17726:
17727: =cut
17728:
17729: sub needs_coursereinit {
17730: my ($loncaparev,$interval) = @_;
17731: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
17732: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17733: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17734: my $now = time;
17735: if ($interval eq '') {
17736: $interval = 600;
17737: }
17738: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 17739: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1283 raeburn 17740: my $blocked = &blocking_status('reinit',$cnum,$cdom,undef,1);
1.1282 raeburn 17741: if ($blocked) {
17742: return ();
17743: }
1.1207 raeburn 17744: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17745: if ($lastchange > $env{'request.course.tied'}) {
17746: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17747: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17748: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17749: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17750: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17751: $curr_reqd_hash{'internal.releaserequired'}});
17752: my ($switchserver,$switchwarning) =
17753: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17754: $curr_reqd_hash{'internal.releaserequired'});
17755: if ($switchwarning ne '' || $switchserver ne '') {
17756: return ('switch',$switchwarning,$switchserver);
17757: }
17758: }
17759: }
17760: return ('update');
17761: }
17762: }
17763: return ();
17764: }
1.1181 raeburn 17765:
1.1083 raeburn 17766: sub update_content_constraints {
1.1326 raeburn 17767: my ($cdom,$cnum,$chome,$cid,$keeporder) = @_;
1.1083 raeburn 17768: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17769: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 17770: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 17771: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 17772: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 17773: if ($item eq 'resourcetag') {
17774: if ($name eq 'responsetype') {
17775: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17776: }
1.1307 raeburn 17777: } elsif ($item eq 'course') {
17778: if ($name eq 'courserestype') {
17779: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
17780: }
1.1083 raeburn 17781: }
17782: }
17783: my $navmap = Apache::lonnavmaps::navmap->new();
17784: if (defined($navmap)) {
1.1307 raeburn 17785: my (%allresponses,%allcrsrestypes);
17786: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
17787: if ($res->is_tool()) {
17788: if ($allcrsrestypes{'exttool'}) {
17789: $allcrsrestypes{'exttool'} ++;
17790: } else {
17791: $allcrsrestypes{'exttool'} = 1;
17792: }
17793: next;
17794: }
1.1083 raeburn 17795: my %responses = $res->responseTypes();
17796: foreach my $key (keys(%responses)) {
17797: next unless(exists($checkresponsetypes{$key}));
17798: $allresponses{$key} += $responses{$key};
17799: }
17800: }
17801: foreach my $key (keys(%allresponses)) {
17802: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17803: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17804: ($reqdmajor,$reqdminor) = ($major,$minor);
17805: }
17806: }
1.1307 raeburn 17807: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 17808: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 17809: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17810: ($reqdmajor,$reqdminor) = ($major,$minor);
17811: }
17812: }
1.1083 raeburn 17813: undef($navmap);
17814: }
1.1326 raeburn 17815: my (@resources,@order,@resparms,@zombies);
17816: if ($keeporder) {
17817: use LONCAPA::map;
17818: @resources = @LONCAPA::map::resources;
17819: @order = @LONCAPA::map::order;
17820: @resparms = @LONCAPA::map::resparms;
17821: @zombies = @LONCAPA::map::zombies;
17822: }
1.1308 raeburn 17823: my $suppmap = 'supplemental.sequence';
17824: my ($suppcount,$supptools,$errors) = (0,0,0);
17825: ($suppcount,$supptools,$errors) = &recurse_supplemental($cnum,$cdom,$suppmap,
17826: $suppcount,$supptools,$errors);
1.1326 raeburn 17827: if ($keeporder) {
17828: @LONCAPA::map::resources = @resources;
17829: @LONCAPA::map::order = @order;
17830: @LONCAPA::map::resparms = @resparms;
17831: @LONCAPA::map::zombies = @zombies;
17832: }
1.1308 raeburn 17833: if ($supptools) {
17834: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
17835: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17836: ($reqdmajor,$reqdminor) = ($major,$minor);
17837: }
17838: }
1.1083 raeburn 17839: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17840: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17841: }
17842: return;
17843: }
17844:
1.1110 raeburn 17845: sub allmaps_incourse {
17846: my ($cdom,$cnum,$chome,$cid) = @_;
17847: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17848: $cid = $env{'request.course.id'};
17849: $cdom = $env{'course.'.$cid.'.domain'};
17850: $cnum = $env{'course.'.$cid.'.num'};
17851: $chome = $env{'course.'.$cid.'.home'};
17852: }
17853: my %allmaps = ();
17854: my $lastchange =
17855: &Apache::lonnet::get_coursechange($cdom,$cnum);
17856: if ($lastchange > $env{'request.course.tied'}) {
17857: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17858: unless ($ferr) {
1.1326 raeburn 17859: &update_content_constraints($cdom,$cnum,$chome,$cid,1);
1.1110 raeburn 17860: }
17861: }
17862: my $navmap = Apache::lonnavmaps::navmap->new();
17863: if (defined($navmap)) {
17864: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17865: $allmaps{$res->src()} = 1;
17866: }
17867: }
17868: return \%allmaps;
17869: }
17870:
1.1083 raeburn 17871: sub parse_supplemental_title {
17872: my ($title) = @_;
17873:
17874: my ($foldertitle,$renametitle);
17875: if ($title =~ /&&&/) {
17876: $title = &HTML::Entites::decode($title);
17877: }
17878: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17879: $renametitle=$4;
17880: my ($time,$uname,$udom) = ($1,$2,$3);
17881: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17882: my $name = &plainname($uname,$udom);
17883: $name = &HTML::Entities::encode($name,'"<>&\'');
17884: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17885: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17886: $name.': <br />'.$foldertitle;
17887: }
17888: if (wantarray) {
17889: return ($title,$foldertitle,$renametitle);
17890: }
17891: return $title;
17892: }
17893:
1.1143 raeburn 17894: sub recurse_supplemental {
1.1308 raeburn 17895: my ($cnum,$cdom,$suppmap,$numfiles,$numexttools,$errors) = @_;
1.1143 raeburn 17896: if ($suppmap) {
17897: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17898: if ($fatal) {
17899: $errors ++;
17900: } else {
17901: if ($#LONCAPA::map::resources > 0) {
17902: foreach my $res (@LONCAPA::map::resources) {
17903: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17904: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 17905: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1308 raeburn 17906: ($numfiles,$numexttools,$errors) = &recurse_supplemental($cnum,$cdom,$1,
17907: $numfiles,$numexttools,$errors);
1.1143 raeburn 17908: } else {
1.1308 raeburn 17909: if ($src =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
17910: $numexttools ++;
17911: }
1.1143 raeburn 17912: $numfiles ++;
17913: }
17914: }
17915: }
17916: }
17917: }
17918: }
1.1308 raeburn 17919: return ($numfiles,$numexttools,$errors);
1.1143 raeburn 17920: }
17921:
1.1101 raeburn 17922: sub symb_to_docspath {
1.1267 raeburn 17923: my ($symb,$navmapref) = @_;
17924: return unless ($symb && ref($navmapref));
1.1101 raeburn 17925: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17926: if ($resurl=~/\.(sequence|page)$/) {
17927: $mapurl=$resurl;
17928: } elsif ($resurl eq 'adm/navmaps') {
17929: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17930: }
17931: my $mapresobj;
1.1267 raeburn 17932: unless (ref($$navmapref)) {
17933: $$navmapref = Apache::lonnavmaps::navmap->new();
17934: }
17935: if (ref($$navmapref)) {
17936: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 17937: }
17938: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17939: my $type=$2;
17940: my $path;
17941: if (ref($mapresobj)) {
17942: my $pcslist = $mapresobj->map_hierarchy();
17943: if ($pcslist ne '') {
17944: foreach my $pc (split(/,/,$pcslist)) {
17945: next if ($pc <= 1);
1.1267 raeburn 17946: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 17947: if (ref($res)) {
17948: my $thisurl = $res->src();
17949: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17950: my $thistitle = $res->title();
17951: $path .= '&'.
17952: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 17953: &escape($thistitle).
1.1101 raeburn 17954: ':'.$res->randompick().
17955: ':'.$res->randomout().
17956: ':'.$res->encrypted().
17957: ':'.$res->randomorder().
17958: ':'.$res->is_page();
17959: }
17960: }
17961: }
17962: $path =~ s/^\&//;
17963: my $maptitle = $mapresobj->title();
17964: if ($mapurl eq 'default') {
1.1129 raeburn 17965: $maptitle = 'Main Content';
1.1101 raeburn 17966: }
17967: $path .= (($path ne '')? '&' : '').
17968: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17969: &escape($maptitle).
1.1101 raeburn 17970: ':'.$mapresobj->randompick().
17971: ':'.$mapresobj->randomout().
17972: ':'.$mapresobj->encrypted().
17973: ':'.$mapresobj->randomorder().
17974: ':'.$mapresobj->is_page();
17975: } else {
17976: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17977: my $ispage = (($type eq 'page')? 1 : '');
17978: if ($mapurl eq 'default') {
1.1129 raeburn 17979: $maptitle = 'Main Content';
1.1101 raeburn 17980: }
17981: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17982: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 17983: }
17984: unless ($mapurl eq 'default') {
17985: $path = 'default&'.
1.1146 raeburn 17986: &escape('Main Content').
1.1101 raeburn 17987: ':::::&'.$path;
17988: }
17989: return $path;
17990: }
17991:
1.1094 raeburn 17992: sub captcha_display {
1.1327 raeburn 17993: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 17994: my ($output,$error);
1.1234 raeburn 17995: my ($captcha,$pubkey,$privkey,$version) =
1.1327 raeburn 17996: &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 17997: if ($captcha eq 'original') {
1.1094 raeburn 17998: $output = &create_captcha();
17999: unless ($output) {
1.1172 raeburn 18000: $error = 'captcha';
1.1094 raeburn 18001: }
18002: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 18003: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 18004: unless ($output) {
1.1172 raeburn 18005: $error = 'recaptcha';
1.1094 raeburn 18006: }
18007: }
1.1234 raeburn 18008: return ($output,$error,$captcha,$version);
1.1094 raeburn 18009: }
18010:
18011: sub captcha_response {
1.1327 raeburn 18012: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 18013: my ($captcha_chk,$captcha_error);
1.1327 raeburn 18014: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 18015: if ($captcha eq 'original') {
1.1094 raeburn 18016: ($captcha_chk,$captcha_error) = &check_captcha();
18017: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 18018: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 18019: } else {
18020: $captcha_chk = 1;
18021: }
18022: return ($captcha_chk,$captcha_error);
18023: }
18024:
18025: sub get_captcha_config {
1.1327 raeburn 18026: my ($context,$lonhost,$dom_in_effect) = @_;
1.1234 raeburn 18027: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 18028: my $hostname = &Apache::lonnet::hostname($lonhost);
18029: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
18030: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 18031: if ($context eq 'usercreation') {
18032: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
18033: if (ref($domconfig{$context}) eq 'HASH') {
18034: $hashtocheck = $domconfig{$context}{'cancreate'};
18035: if (ref($hashtocheck) eq 'HASH') {
18036: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
18037: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
18038: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
18039: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
18040: }
18041: if ($privkey && $pubkey) {
18042: $captcha = 'recaptcha';
1.1234 raeburn 18043: $version = $hashtocheck->{'recaptchaversion'};
18044: if ($version ne '2') {
18045: $version = 1;
18046: }
1.1095 raeburn 18047: } else {
18048: $captcha = 'original';
18049: }
18050: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
18051: $captcha = 'original';
18052: }
1.1094 raeburn 18053: }
1.1095 raeburn 18054: } else {
18055: $captcha = 'captcha';
18056: }
18057: } elsif ($context eq 'login') {
18058: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
18059: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
18060: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
18061: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 18062: if ($privkey && $pubkey) {
18063: $captcha = 'recaptcha';
1.1234 raeburn 18064: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
18065: if ($version ne '2') {
18066: $version = 1;
18067: }
1.1095 raeburn 18068: } else {
18069: $captcha = 'original';
1.1094 raeburn 18070: }
1.1095 raeburn 18071: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
18072: $captcha = 'original';
1.1094 raeburn 18073: }
1.1327 raeburn 18074: } elsif ($context eq 'passwords') {
18075: if ($dom_in_effect) {
18076: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
18077: if ($passwdconf{'captcha'} eq 'recaptcha') {
18078: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
18079: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
18080: $privkey = $passwdconf{'recaptchakeys'}{'private'};
18081: }
18082: if ($privkey && $pubkey) {
18083: $captcha = 'recaptcha';
18084: $version = $passwdconf{'recaptchaversion'};
18085: if ($version ne '2') {
18086: $version = 1;
18087: }
18088: } else {
18089: $captcha = 'original';
18090: }
18091: } elsif ($passwdconf{'captcha'} ne 'notused') {
18092: $captcha = 'original';
18093: }
18094: }
18095: }
1.1234 raeburn 18096: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 18097: }
18098:
18099: sub create_captcha {
18100: my %captcha_params = &captcha_settings();
18101: my ($output,$maxtries,$tries) = ('',10,0);
18102: while ($tries < $maxtries) {
18103: $tries ++;
18104: my $captcha = Authen::Captcha->new (
18105: output_folder => $captcha_params{'output_dir'},
18106: data_folder => $captcha_params{'db_dir'},
18107: );
18108: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
18109:
18110: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
18111: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
18112: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 18113: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
18114: '<br />'.
18115: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 18116: last;
18117: }
18118: }
1.1323 raeburn 18119: if ($output eq '') {
18120: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
18121: }
1.1094 raeburn 18122: return $output;
18123: }
18124:
18125: sub captcha_settings {
18126: my %captcha_params = (
18127: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
18128: www_output_dir => "/captchaspool",
18129: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
18130: numchars => '5',
18131: );
18132: return %captcha_params;
18133: }
18134:
18135: sub check_captcha {
18136: my ($captcha_chk,$captcha_error);
18137: my $code = $env{'form.code'};
18138: my $md5sum = $env{'form.crypt'};
18139: my %captcha_params = &captcha_settings();
18140: my $captcha = Authen::Captcha->new(
18141: output_folder => $captcha_params{'output_dir'},
18142: data_folder => $captcha_params{'db_dir'},
18143: );
1.1109 raeburn 18144: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 18145: my %captcha_hash = (
18146: 0 => 'Code not checked (file error)',
18147: -1 => 'Failed: code expired',
18148: -2 => 'Failed: invalid code (not in database)',
18149: -3 => 'Failed: invalid code (code does not match crypt)',
18150: );
18151: if ($captcha_chk != 1) {
18152: $captcha_error = $captcha_hash{$captcha_chk}
18153: }
18154: return ($captcha_chk,$captcha_error);
18155: }
18156:
18157: sub create_recaptcha {
1.1234 raeburn 18158: my ($pubkey,$version) = @_;
18159: if ($version >= 2) {
18160: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
18161: } else {
18162: my $use_ssl;
18163: if ($ENV{'SERVER_PORT'} == 443) {
18164: $use_ssl = 1;
18165: }
18166: my $captcha = Captcha::reCAPTCHA->new;
18167: return $captcha->get_options_setter({theme => 'white'})."\n".
18168: $captcha->get_html($pubkey,undef,$use_ssl).
18169: &mt('If the text is hard to read, [_1] will replace them.',
18170: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
18171: '<br /><br />';
18172: }
1.1094 raeburn 18173: }
18174:
18175: sub check_recaptcha {
1.1234 raeburn 18176: my ($privkey,$version) = @_;
1.1094 raeburn 18177: my $captcha_chk;
1.1350 raeburn 18178: my $ip = &Apache::lonnet::get_requestor_ip();
1.1234 raeburn 18179: if ($version >= 2) {
18180: my %info = (
18181: secret => $privkey,
18182: response => $env{'form.g-recaptcha-response'},
1.1350 raeburn 18183: remoteip => $ip,
1.1234 raeburn 18184: );
1.1280 raeburn 18185: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
18186: $request->content(join('&',map {
18187: my $name = escape($_);
18188: "$name=" . ( ref($info{$_}) eq 'ARRAY'
18189: ? join("&$name=", map {escape($_) } @{$info{$_}})
18190: : &escape($info{$_}) );
18191: } keys(%info)));
18192: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 18193: if ($response->is_success) {
18194: my $data = JSON::DWIW->from_json($response->decoded_content);
18195: if (ref($data) eq 'HASH') {
18196: if ($data->{'success'}) {
18197: $captcha_chk = 1;
18198: }
18199: }
18200: }
18201: } else {
18202: my $captcha = Captcha::reCAPTCHA->new;
18203: my $captcha_result =
18204: $captcha->check_answer(
18205: $privkey,
1.1350 raeburn 18206: $ip,
1.1234 raeburn 18207: $env{'form.recaptcha_challenge_field'},
18208: $env{'form.recaptcha_response_field'},
18209: );
18210: if ($captcha_result->{is_valid}) {
18211: $captcha_chk = 1;
18212: }
1.1094 raeburn 18213: }
18214: return $captcha_chk;
18215: }
18216:
1.1174 raeburn 18217: sub emailusername_info {
1.1244 raeburn 18218: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 18219: my %titles = &Apache::lonlocal::texthash (
18220: lastname => 'Last Name',
18221: firstname => 'First Name',
18222: institution => 'School/college/university',
18223: location => "School's city, state/province, country",
18224: web => "School's web address",
18225: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 18226: id => 'Student/Employee ID',
1.1174 raeburn 18227: );
18228: return (\@fields,\%titles);
18229: }
18230:
1.1161 raeburn 18231: sub cleanup_html {
18232: my ($incoming) = @_;
18233: my $outgoing;
18234: if ($incoming ne '') {
18235: $outgoing = $incoming;
18236: $outgoing =~ s/;/;/g;
18237: $outgoing =~ s/\#/#/g;
18238: $outgoing =~ s/\&/&/g;
18239: $outgoing =~ s/</</g;
18240: $outgoing =~ s/>/>/g;
18241: $outgoing =~ s/\(/(/g;
18242: $outgoing =~ s/\)/)/g;
18243: $outgoing =~ s/"/"/g;
18244: $outgoing =~ s/'/'/g;
18245: $outgoing =~ s/\$/$/g;
18246: $outgoing =~ s{/}{/}g;
18247: $outgoing =~ s/=/=/g;
18248: $outgoing =~ s/\\/\/g
18249: }
18250: return $outgoing;
18251: }
18252:
1.1190 musolffc 18253: # Checks for critical messages and returns a redirect url if one exists.
18254: # $interval indicates how often to check for messages.
1.1282 raeburn 18255: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 18256: sub critical_redirect {
1.1282 raeburn 18257: my ($interval,$context) = @_;
1.1190 musolffc 18258: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 18259: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
18260: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18261: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18262: my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
18263: if ($blocked) {
18264: my $checkrole = "cm./$cdom/$cnum";
18265: if ($env{'request.course.sec'} ne '') {
18266: $checkrole .= "/$env{'request.course.sec'}";
18267: }
18268: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
18269: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
18270: return;
18271: }
18272: }
18273: }
1.1190 musolffc 18274: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
18275: $env{'user.name'});
18276: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 18277: my $redirecturl;
1.1190 musolffc 18278: if ($what[0]) {
18279: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
18280: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 18281: my $url=&Apache::lonnet::absolute_url().$redirecturl;
18282: return (1, $url);
1.1190 musolffc 18283: }
1.1191 raeburn 18284: }
18285: }
18286: return ();
1.1190 musolffc 18287: }
18288:
1.1174 raeburn 18289: # Use:
18290: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
18291: #
18292: ##################################################
18293: # password associated functions #
18294: ##################################################
18295: sub des_keys {
18296: # Make a new key for DES encryption.
18297: # Each key has two parts which are returned separately.
18298: # Please note: Each key must be passed through the &hex function
18299: # before it is output to the web browser. The hex versions cannot
18300: # be used to decrypt.
18301: my @hexstr=('0','1','2','3','4','5','6','7',
18302: '8','9','a','b','c','d','e','f');
18303: my $lkey='';
18304: for (0..7) {
18305: $lkey.=$hexstr[rand(15)];
18306: }
18307: my $ukey='';
18308: for (0..7) {
18309: $ukey.=$hexstr[rand(15)];
18310: }
18311: return ($lkey,$ukey);
18312: }
18313:
18314: sub des_decrypt {
18315: my ($key,$cyphertext) = @_;
18316: my $keybin=pack("H16",$key);
18317: my $cypher;
18318: if ($Crypt::DES::VERSION>=2.03) {
18319: $cypher=new Crypt::DES $keybin;
18320: } else {
18321: $cypher=new DES $keybin;
18322: }
1.1233 raeburn 18323: my $plaintext='';
18324: my $cypherlength = length($cyphertext);
18325: my $numchunks = int($cypherlength/32);
18326: for (my $j=0; $j<$numchunks; $j++) {
18327: my $start = $j*32;
18328: my $cypherblock = substr($cyphertext,$start,32);
18329: my $chunk =
18330: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
18331: $chunk .=
18332: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
18333: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
18334: $plaintext .= $chunk;
18335: }
1.1174 raeburn 18336: return $plaintext;
18337: }
18338:
1.1344 raeburn 18339: sub get_requested_shorturls {
1.1309 raeburn 18340: my ($cdom,$cnum,$navmap) = @_;
18341: return unless (ref($navmap));
1.1344 raeburn 18342: my ($numnew,$errors);
1.1309 raeburn 18343: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
18344: if (@toshorten) {
18345: my (%maps,%resources,%titles);
18346: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
18347: 'shorturls',$cdom,$cnum);
18348: if (keys(%resources)) {
1.1344 raeburn 18349: my %tocreate;
1.1309 raeburn 18350: foreach my $item (sort {$a <=> $b} (@toshorten)) {
18351: my $symb = $resources{$item};
18352: if ($symb) {
18353: $tocreate{$cnum.'&'.$symb} = 1;
18354: }
18355: }
1.1344 raeburn 18356: if (keys(%tocreate)) {
18357: ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
18358: \%tocreate);
18359: }
1.1309 raeburn 18360: }
1.1344 raeburn 18361: }
18362: return ($numnew,$errors);
18363: }
18364:
18365: sub make_short_symbs {
18366: my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
18367: my ($numnew,@errors);
18368: if (ref($tocreateref) eq 'HASH') {
18369: my %tocreate = %{$tocreateref};
1.1309 raeburn 18370: if (keys(%tocreate)) {
18371: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
18372: my $su = Short::URL->new(no_vowels => 1);
18373: my $init = '';
18374: my (%newunique,%addcourse,%courseonly,%failed);
18375: # get lock on tiny db
18376: my $now = time;
1.1344 raeburn 18377: if ($lockuser eq '') {
18378: $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
18379: }
1.1309 raeburn 18380: my $lockhash = {
1.1344 raeburn 18381: "lock\0$now" => $lockuser,
1.1309 raeburn 18382: };
18383: my $tries = 0;
18384: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18385: my ($code,$error);
18386: while (($gotlock ne 'ok') && ($tries<3)) {
18387: $tries ++;
18388: sleep 1;
1.1319 raeburn 18389: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 18390: }
18391: if ($gotlock eq 'ok') {
18392: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
18393: \%addcourse,\%courseonly,\%failed);
18394: if (keys(%failed)) {
18395: my $numfailed = scalar(keys(%failed));
18396: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
18397: }
18398: if (keys(%newunique)) {
18399: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
18400: if ($putres eq 'ok') {
18401: $numnew = scalar(keys(%newunique));
18402: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
18403: unless ($newputres eq 'ok') {
18404: push(@errors,&mt('error: could not store course look-up of short URLs'));
18405: }
18406: } else {
18407: push(@errors,&mt('error: could not store unique six character URLs'));
18408: }
18409: }
18410: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
18411: unless ($dellockres eq 'ok') {
18412: push(@errors,&mt('error: could not release lockfile'));
18413: }
18414: } else {
18415: push(@errors,&mt('error: could not obtain lockfile'));
18416: }
18417: if (keys(%courseonly)) {
18418: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
18419: if ($result ne 'ok') {
18420: push(@errors,&mt('error: could not update course look-up of short URLs'));
18421: }
18422: }
18423: }
18424: }
18425: return ($numnew,\@errors);
18426: }
18427:
18428: sub shorten_symbs {
18429: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
18430: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
18431: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
18432: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
18433: my (%possibles,%collisions);
18434: foreach my $key (keys(%{$tocreate})) {
18435: my $num = String::CRC32::crc32($key);
18436: my $tiny = $su->encode($num,$init);
18437: if ($tiny) {
18438: $possibles{$tiny} = $key;
18439: }
18440: }
18441: if (!$init) {
18442: $init = 1;
18443: } else {
18444: $init ++;
18445: }
18446: if (keys(%possibles)) {
18447: my @posstiny = keys(%possibles);
18448: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
18449: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
18450: if (keys(%currtiny)) {
18451: foreach my $key (keys(%currtiny)) {
18452: next if ($currtiny{$key} eq '');
18453: if ($currtiny{$key} eq $possibles{$key}) {
18454: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
18455: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18456: $courseonly->{$tsymb} = $key;
18457: }
18458: } else {
18459: $collisions{$possibles{$key}} = 1;
18460: }
18461: delete($possibles{$key});
18462: }
18463: }
18464: foreach my $key (keys(%possibles)) {
18465: $newunique->{$key} = $possibles{$key};
18466: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
18467: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18468: $addcourse->{$tsymb} = $key;
18469: }
18470: }
18471: }
18472: if (keys(%collisions)) {
18473: if ($init <5) {
18474: if (!$init) {
18475: $init = 1;
18476: } else {
18477: $init ++;
18478: }
18479: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
18480: $newunique,$addcourse,$courseonly,$failed);
18481: } else {
18482: foreach my $key (keys(%collisions)) {
18483: $failed->{$key} = 1;
18484: }
18485: }
18486: }
18487: return $init;
18488: }
18489:
1.1328 raeburn 18490: sub is_nonframeable {
1.1329 raeburn 18491: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
18492: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
1.1330 raeburn 18493: return if (($remprotocol eq '') || ($remhost eq ''));
1.1329 raeburn 18494:
18495: $remprotocol = lc($remprotocol);
18496: $remhost = lc($remhost);
18497: my $remport = 80;
18498: if ($remprotocol eq 'https') {
18499: $remport = 443;
18500: }
1.1330 raeburn 18501: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
1.1329 raeburn 18502: if ($cached) {
18503: unless ($nocache) {
18504: if ($result) {
18505: return 1;
18506: } else {
18507: return 0;
18508: }
18509: }
18510: }
1.1328 raeburn 18511: my $uselink;
18512: my $request = new HTTP::Request('HEAD',$url);
18513: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
18514: if ($response->is_success()) {
18515: my $secpolicy = lc($response->header('content-security-policy'));
18516: my $xframeop = lc($response->header('x-frame-options'));
18517: $secpolicy =~ s/^\s+|\s+$//g;
18518: $xframeop =~ s/^\s+|\s+$//g;
18519: if (($secpolicy ne '') || ($xframeop ne '')) {
1.1329 raeburn 18520: my $remotehost = $remprotocol.'://'.$remhost;
1.1328 raeburn 18521: my ($origin,$protocol,$port);
18522: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
18523: $port = $ENV{'SERVER_PORT'};
18524: } else {
18525: $port = 80;
18526: }
18527: if ($absolute eq '') {
18528: $protocol = 'http:';
18529: if ($port == 443) {
18530: $protocol = 'https:';
18531: }
18532: $origin = $protocol.'//'.lc($hostname);
18533: } else {
18534: $origin = lc($absolute);
18535: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
18536: }
18537: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
18538: my $framepolicy = $1;
18539: $framepolicy =~ s/^\s+|\s+$//g;
18540: my @policies = split(/\s+/,$framepolicy);
18541: if (@policies) {
18542: if (grep(/^\Q'none'\E$/,@policies)) {
18543: $uselink = 1;
18544: } else {
18545: $uselink = 1;
18546: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
18547: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
18548: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
18549: undef($uselink);
18550: }
18551: if ($uselink) {
18552: if (grep(/^\Q'self'\E$/,@policies)) {
18553: if (($origin ne '') && ($remotehost eq $origin)) {
18554: undef($uselink);
18555: }
18556: }
18557: }
18558: if ($uselink) {
18559: my @possok;
18560: if ($ip ne '') {
18561: push(@possok,$ip);
18562: }
18563: my $hoststr = '';
18564: foreach my $part (reverse(split(/\./,$hostname))) {
18565: if ($hoststr eq '') {
18566: $hoststr = $part;
18567: } else {
18568: $hoststr = "$part.$hoststr";
18569: }
18570: if ($hoststr eq $hostname) {
18571: push(@possok,$hostname);
18572: } else {
18573: push(@possok,"*.$hoststr");
18574: }
18575: }
18576: if (@possok) {
18577: foreach my $poss (@possok) {
18578: last if (!$uselink);
18579: foreach my $policy (@policies) {
18580: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
18581: undef($uselink);
18582: last;
18583: }
18584: }
18585: }
18586: }
18587: }
18588: }
18589: }
18590: } elsif ($xframeop ne '') {
18591: $uselink = 1;
18592: my @policies = split(/\s*,\s*/,$xframeop);
18593: if (@policies) {
18594: unless (grep(/^deny$/,@policies)) {
18595: if ($origin ne '') {
18596: if (grep(/^sameorigin$/,@policies)) {
18597: if ($remotehost eq $origin) {
18598: undef($uselink);
18599: }
18600: }
18601: if ($uselink) {
18602: foreach my $policy (@policies) {
18603: if ($policy =~ /^allow-from\s*(.+)$/) {
18604: my $allowfrom = $1;
18605: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
18606: undef($uselink);
18607: last;
18608: }
18609: }
18610: }
18611: }
18612: }
18613: }
18614: }
18615: }
18616: }
18617: }
1.1329 raeburn 18618: if ($nocache) {
18619: if ($cached) {
18620: my $devalidate;
18621: if ($uselink && !$result) {
18622: $devalidate = 1;
18623: } elsif (!$uselink && $result) {
18624: $devalidate = 1;
18625: }
18626: if ($devalidate) {
18627: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
18628: }
18629: }
18630: } else {
18631: if ($uselink) {
18632: $result = 1;
18633: } else {
18634: $result = 0;
18635: }
18636: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
18637: }
1.1328 raeburn 18638: return $uselink;
18639: }
18640:
1.112 bowersj2 18641: 1;
18642: __END__;
1.41 ng 18643:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>