Annotation of loncom/interface/loncommon.pm, revision 1.1357
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1357 ! raeburn 4: # $Id: loncommon.pm,v 1.1356 2021/04/11 18:05:43 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.1357 ! 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.1357 ! raeburn 6152: my ($cid,$sec);
1.258 albertel 6153: if ($env{'request.course.id'}) {
1.1357 ! raeburn 6154: $cid = $env{'request.course.id'};
! 6155: if ($env{'request.course.sec'}) {
! 6156: $sec = $env{'request.course.sec'};
! 6157: }
! 6158: } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
! 6159: if (&Apache::lonnet::is_course($1,$2)) {
! 6160: $cid = $1.'_'.$2;
! 6161: $sec = $3;
! 6162: }
! 6163: }
! 6164: if ($cid) {
1.378 raeburn 6165: if ($env{'request.role'} !~ /^cr/) {
6166: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 6167: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 6168: if ($env{'request.role.desc'}) {
6169: $role = $env{'request.role.desc'};
6170: } else {
6171: $role = &mt('Helpdesk[_1]',' '.$2);
6172: }
1.1257 raeburn 6173: } else {
6174: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6175: }
1.1357 ! raeburn 6176: if ($sec) {
! 6177: $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
1.898 raeburn 6178: }
1.1357 ! raeburn 6179: $realm = $env{'course.'.$cid.'.description'};
1.378 raeburn 6180: } else {
6181: $role = &Apache::lonnet::plaintext($role);
1.54 www 6182: }
1.433 albertel 6183:
1.359 albertel 6184: if (!$realm) { $realm=' '; }
1.330 albertel 6185:
1.438 albertel 6186: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6187:
1.101 www 6188: # construct main body tag
1.359 albertel 6189: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6190: &Apache::lontexconvert::init_math_support();
1.252 albertel 6191:
1.1131 raeburn 6192: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6193:
1.1130 raeburn 6194: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6195: return $bodytag;
1.1130 raeburn 6196: }
1.359 albertel 6197:
1.954 raeburn 6198: if ($public) {
1.433 albertel 6199: undef($role);
6200: }
1.1318 raeburn 6201:
1.1357 ! raeburn 6202: if (($cid) && ($env{'request.lti.login'})) {
1.1318 raeburn 6203: if (ref($ltimenu) eq 'HASH') {
6204: unless ($ltimenu->{'role'}) {
6205: undef($role);
6206: }
6207: unless ($ltimenu->{'coursetitle'}) {
6208: $realm=' ';
6209: }
6210: }
6211: }
6212:
1.762 bisitz 6213: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6214: #
6215: # Extra info if you are the DC
6216: my $dc_info = '';
1.1357 ! raeburn 6217: if (($env{'user.adv'}) && ($env{'request.course.id'}) &&
! 6218: (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
1.917 raeburn 6219: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6220: $dc_info =~ s/\s+$//;
1.359 albertel 6221: }
6222:
1.1237 raeburn 6223: my $crstype;
1.1357 ! raeburn 6224: if ($cid) {
! 6225: $crstype = $env{'course.'.$cid.'.type'};
1.1237 raeburn 6226: } elsif ($args->{'crstype'}) {
6227: $crstype = $args->{'crstype'};
6228: }
6229: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
6230: undef($role);
6231: } else {
1.1242 raeburn 6232: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 6233: }
1.853 droeschl 6234:
1.903 droeschl 6235: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6236:
6237: # if ($env{'request.state'} eq 'construct') {
6238: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6239: # }
6240:
1.1130 raeburn 6241: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 6242: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6243:
1.1318 raeburn 6244: unless ($args->{'no_primary_menu'}) {
6245: my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu);
1.359 albertel 6246:
1.1318 raeburn 6247: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6248: if ($dc_info) {
6249: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6250: }
6251: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6252: <em>$realm</em> $dc_info</div>|;
6253: return $bodytag;
6254: }
1.894 droeschl 6255:
1.1318 raeburn 6256: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6257: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6258: }
1.916 droeschl 6259:
1.1318 raeburn 6260: $bodytag .= $right;
1.852 droeschl 6261:
1.1318 raeburn 6262: if ($dc_info) {
6263: $dc_info = &dc_courseid_toggle($dc_info);
6264: }
6265: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6266: }
1.916 droeschl 6267:
1.1169 raeburn 6268: #if directed to not display the secondary menu, don't.
1.1168 raeburn 6269: if ($args->{'no_secondary_menu'}) {
6270: return $bodytag;
6271: }
1.1169 raeburn 6272: #don't show menus for public users
1.954 raeburn 6273: if (!$public){
1.1318 raeburn 6274: unless ($args->{'no_inline_menu'}) {
6275: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
6276: $args->{'no_primary_menu'});
6277: }
1.903 droeschl 6278: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6279: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6280: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6281: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1316 raeburn 6282: $args->{'bread_crumbs'},'','',$hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6283: } elsif ($forcereg) {
6284: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1258 raeburn 6285: $args->{'group'},
1.1274 raeburn 6286: $args->{'hide_buttons'},
1.1316 raeburn 6287: $hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6288: } else {
6289: $bodytag .=
6290: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6291: $forcereg,$args->{'group'},
6292: $args->{'bread_crumbs'},
1.1274 raeburn 6293: $advtoolsref,'',$hostname);
1.920 raeburn 6294: }
1.903 droeschl 6295: }else{
6296: # this is to seperate menu from content when there's no secondary
6297: # menu. Especially needed for public accessible ressources.
6298: $bodytag .= '<hr style="clear:both" />';
6299: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6300: }
1.903 droeschl 6301:
1.235 raeburn 6302: return $bodytag;
1.182 matthew 6303: }
6304:
1.917 raeburn 6305: sub dc_courseid_toggle {
6306: my ($dc_info) = @_;
1.980 raeburn 6307: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6308: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6309: &mt('(More ...)').'</a></span>'.
6310: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6311: }
6312:
1.330 albertel 6313: sub make_attr_string {
6314: my ($register,$attr_ref) = @_;
6315:
6316: if ($attr_ref && !ref($attr_ref)) {
6317: die("addentries Must be a hash ref ".
6318: join(':',caller(1))." ".
6319: join(':',caller(0))." ");
6320: }
6321:
6322: if ($register) {
1.339 albertel 6323: my ($on_load,$on_unload);
6324: foreach my $key (keys(%{$attr_ref})) {
6325: if (lc($key) eq 'onload') {
6326: $on_load.=$attr_ref->{$key}.';';
6327: delete($attr_ref->{$key});
6328:
6329: } elsif (lc($key) eq 'onunload') {
6330: $on_unload.=$attr_ref->{$key}.';';
6331: delete($attr_ref->{$key});
6332: }
6333: }
1.953 droeschl 6334: $attr_ref->{'onload'} = $on_load;
6335: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6336: }
1.339 albertel 6337:
1.330 albertel 6338: my $attr_string;
1.1159 raeburn 6339: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6340: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6341: }
6342: return $attr_string;
6343: }
6344:
6345:
1.182 matthew 6346: ###############################################
1.251 albertel 6347: ###############################################
6348:
6349: =pod
6350:
6351: =item * &endbodytag()
6352:
6353: Returns a uniform footer for LON-CAPA web pages.
6354:
1.635 raeburn 6355: Inputs: 1 - optional reference to an args hash
6356: If in the hash, key for noredirectlink has a value which evaluates to true,
6357: a 'Continue' link is not displayed if the page contains an
6358: internal redirect in the <head></head> section,
6359: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6360:
6361: =cut
6362:
6363: sub endbodytag {
1.635 raeburn 6364: my ($args) = @_;
1.1080 raeburn 6365: my $endbodytag;
6366: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6367: $endbodytag='</body>';
6368: }
1.315 albertel 6369: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6370: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6371: $endbodytag=
6372: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6373: &mt('Continue').'</a>'.
6374: $endbodytag;
6375: }
1.315 albertel 6376: }
1.251 albertel 6377: return $endbodytag;
6378: }
6379:
1.352 albertel 6380: =pod
6381:
6382: =item * &standard_css()
6383:
6384: Returns a style sheet
6385:
6386: Inputs: (all optional)
6387: domain -> force to color decorate a page for a specific
6388: domain
6389: function -> force usage of a specific rolish color scheme
6390: bgcolor -> override the default page bgcolor
6391:
6392: =cut
6393:
1.343 albertel 6394: sub standard_css {
1.345 albertel 6395: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6396: $function = &get_users_function() if (!$function);
6397: my $img = &designparm($function.'.img', $domain);
6398: my $tabbg = &designparm($function.'.tabbg', $domain);
6399: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6400: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6401: #second colour for later usage
1.345 albertel 6402: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6403: my $pgbg_or_bgcolor =
6404: $bgcolor ||
1.352 albertel 6405: &designparm($function.'.pgbg', $domain);
1.382 albertel 6406: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6407: my $alink = &designparm($function.'.alink', $domain);
6408: my $vlink = &designparm($function.'.vlink', $domain);
6409: my $link = &designparm($function.'.link', $domain);
6410:
1.602 albertel 6411: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6412: my $mono = 'monospace';
1.850 bisitz 6413: my $data_table_head = $sidebg;
6414: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6415: my $data_table_dark = '#E0E0E0';
1.470 banghart 6416: my $data_table_darker = '#CCCCCC';
1.349 albertel 6417: my $data_table_highlight = '#FFFF00';
1.352 albertel 6418: my $mail_new = '#FFBB77';
6419: my $mail_new_hover = '#DD9955';
6420: my $mail_read = '#BBBB77';
6421: my $mail_read_hover = '#999944';
6422: my $mail_replied = '#AAAA88';
6423: my $mail_replied_hover = '#888855';
6424: my $mail_other = '#99BBBB';
6425: my $mail_other_hover = '#669999';
1.391 albertel 6426: my $table_header = '#DDDDDD';
1.489 raeburn 6427: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6428: my $lg_border_color = '#C8C8C8';
1.952 onken 6429: my $button_hover = '#BF2317';
1.392 albertel 6430:
1.608 albertel 6431: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6432: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6433: : '0 3px 0 4px';
1.448 albertel 6434:
1.523 albertel 6435:
1.343 albertel 6436: return <<END;
1.947 droeschl 6437:
6438: /* needed for iframe to allow 100% height in FF */
6439: body, html {
6440: margin: 0;
6441: padding: 0 0.5%;
6442: height: 99%; /* to avoid scrollbars */
6443: }
6444:
1.795 www 6445: body {
1.911 bisitz 6446: font-family: $sans;
6447: line-height:130%;
6448: font-size:0.83em;
6449: color:$font;
1.795 www 6450: }
6451:
1.959 onken 6452: a:focus,
6453: a:focus img {
1.795 www 6454: color: red;
6455: }
1.698 harmsja 6456:
1.911 bisitz 6457: form, .inline {
6458: display: inline;
1.795 www 6459: }
1.721 harmsja 6460:
1.795 www 6461: .LC_right {
1.911 bisitz 6462: text-align:right;
1.795 www 6463: }
6464:
6465: .LC_middle {
1.911 bisitz 6466: vertical-align:middle;
1.795 www 6467: }
1.721 harmsja 6468:
1.1130 raeburn 6469: .LC_floatleft {
6470: float: left;
6471: }
6472:
6473: .LC_floatright {
6474: float: right;
6475: }
6476:
1.911 bisitz 6477: .LC_400Box {
6478: width:400px;
6479: }
1.721 harmsja 6480:
1.947 droeschl 6481: .LC_iframecontainer {
6482: width: 98%;
6483: margin: 0;
6484: position: fixed;
6485: top: 8.5em;
6486: bottom: 0;
6487: }
6488:
6489: .LC_iframecontainer iframe{
6490: border: none;
6491: width: 100%;
6492: height: 100%;
6493: }
6494:
1.778 bisitz 6495: .LC_filename {
6496: font-family: $mono;
6497: white-space:pre;
1.921 bisitz 6498: font-size: 120%;
1.778 bisitz 6499: }
6500:
6501: .LC_fileicon {
6502: border: none;
6503: height: 1.3em;
6504: vertical-align: text-bottom;
6505: margin-right: 0.3em;
6506: text-decoration:none;
6507: }
6508:
1.1008 www 6509: .LC_setting {
6510: text-decoration:underline;
6511: }
6512:
1.350 albertel 6513: .LC_error {
6514: color: red;
6515: }
1.795 www 6516:
1.1097 bisitz 6517: .LC_warning {
6518: color: darkorange;
6519: }
6520:
1.457 albertel 6521: .LC_diff_removed {
1.733 bisitz 6522: color: red;
1.394 albertel 6523: }
1.532 albertel 6524:
6525: .LC_info,
1.457 albertel 6526: .LC_success,
6527: .LC_diff_added {
1.350 albertel 6528: color: green;
6529: }
1.795 www 6530:
1.802 bisitz 6531: div.LC_confirm_box {
6532: background-color: #FAFAFA;
6533: border: 1px solid $lg_border_color;
6534: margin-right: 0;
6535: padding: 5px;
6536: }
6537:
6538: div.LC_confirm_box .LC_error img,
6539: div.LC_confirm_box .LC_success img {
6540: vertical-align: middle;
6541: }
6542:
1.1242 raeburn 6543: .LC_maxwidth {
6544: max-width: 100%;
6545: height: auto;
6546: }
6547:
1.1243 raeburn 6548: .LC_textsize_mobile {
6549: \@media only screen and (max-device-width: 480px) {
6550: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6551: }
6552: }
6553:
1.440 albertel 6554: .LC_icon {
1.771 droeschl 6555: border: none;
1.790 droeschl 6556: vertical-align: middle;
1.771 droeschl 6557: }
6558:
1.543 albertel 6559: .LC_docs_spacer {
6560: width: 25px;
6561: height: 1px;
1.771 droeschl 6562: border: none;
1.543 albertel 6563: }
1.346 albertel 6564:
1.532 albertel 6565: .LC_internal_info {
1.735 bisitz 6566: color: #999999;
1.532 albertel 6567: }
6568:
1.794 www 6569: .LC_discussion {
1.1050 www 6570: background: $data_table_dark;
1.911 bisitz 6571: border: 1px solid black;
6572: margin: 2px;
1.794 www 6573: }
6574:
6575: .LC_disc_action_left {
1.1050 www 6576: background: $sidebg;
1.911 bisitz 6577: text-align: left;
1.1050 www 6578: padding: 4px;
6579: margin: 2px;
1.794 www 6580: }
6581:
6582: .LC_disc_action_right {
1.1050 www 6583: background: $sidebg;
1.911 bisitz 6584: text-align: right;
1.1050 www 6585: padding: 4px;
6586: margin: 2px;
1.794 www 6587: }
6588:
6589: .LC_disc_new_item {
1.911 bisitz 6590: background: white;
6591: border: 2px solid red;
1.1050 www 6592: margin: 4px;
6593: padding: 4px;
1.794 www 6594: }
6595:
6596: .LC_disc_old_item {
1.911 bisitz 6597: background: white;
1.1050 www 6598: margin: 4px;
6599: padding: 4px;
1.794 www 6600: }
6601:
1.458 albertel 6602: table.LC_pastsubmission {
6603: border: 1px solid black;
6604: margin: 2px;
6605: }
6606:
1.924 bisitz 6607: table#LC_menubuttons {
1.345 albertel 6608: width: 100%;
6609: background: $pgbg;
1.392 albertel 6610: border: 2px;
1.402 albertel 6611: border-collapse: separate;
1.803 bisitz 6612: padding: 0;
1.345 albertel 6613: }
1.392 albertel 6614:
1.801 tempelho 6615: table#LC_title_bar a {
6616: color: $fontmenu;
6617: }
1.836 bisitz 6618:
1.807 droeschl 6619: table#LC_title_bar {
1.819 tempelho 6620: clear: both;
1.836 bisitz 6621: display: none;
1.807 droeschl 6622: }
6623:
1.795 www 6624: table#LC_title_bar,
1.933 droeschl 6625: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6626: table#LC_title_bar.LC_with_remote {
1.359 albertel 6627: width: 100%;
1.392 albertel 6628: border-color: $pgbg;
6629: border-style: solid;
6630: border-width: $border;
1.379 albertel 6631: background: $pgbg;
1.801 tempelho 6632: color: $fontmenu;
1.392 albertel 6633: border-collapse: collapse;
1.803 bisitz 6634: padding: 0;
1.819 tempelho 6635: margin: 0;
1.359 albertel 6636: }
1.795 www 6637:
1.933 droeschl 6638: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6639: margin: 0;
6640: padding: 0;
1.933 droeschl 6641: position: relative;
6642: list-style: none;
1.913 droeschl 6643: }
1.933 droeschl 6644: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6645: display: inline;
6646: }
1.933 droeschl 6647:
6648: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6649: padding: 0;
1.933 droeschl 6650: margin: 0;
6651: float: left;
1.913 droeschl 6652: }
1.933 droeschl 6653: .LC_breadcrumb_tools_tools {
6654: padding: 0;
6655: margin: 0;
1.913 droeschl 6656: float: right;
6657: }
6658:
1.1240 raeburn 6659: .LC_placement_prog {
6660: padding-right: 20px;
6661: font-weight: bold;
6662: font-size: 90%;
6663: }
6664:
1.359 albertel 6665: table#LC_title_bar td {
6666: background: $tabbg;
6667: }
1.795 www 6668:
1.911 bisitz 6669: table#LC_menubuttons img {
1.803 bisitz 6670: border: none;
1.346 albertel 6671: }
1.795 www 6672:
1.842 droeschl 6673: .LC_breadcrumbs_component {
1.911 bisitz 6674: float: right;
6675: margin: 0 1em;
1.357 albertel 6676: }
1.842 droeschl 6677: .LC_breadcrumbs_component img {
1.911 bisitz 6678: vertical-align: middle;
1.777 tempelho 6679: }
1.795 www 6680:
1.1243 raeburn 6681: .LC_breadcrumbs_hoverable {
6682: background: $sidebg;
6683: }
6684:
1.383 albertel 6685: td.LC_table_cell_checkbox {
6686: text-align: center;
6687: }
1.795 www 6688:
6689: .LC_fontsize_small {
1.911 bisitz 6690: font-size: 70%;
1.705 tempelho 6691: }
6692:
1.844 bisitz 6693: #LC_breadcrumbs {
1.911 bisitz 6694: clear:both;
6695: background: $sidebg;
6696: border-bottom: 1px solid $lg_border_color;
6697: line-height: 2.5em;
1.933 droeschl 6698: overflow: hidden;
1.911 bisitz 6699: margin: 0;
6700: padding: 0;
1.995 raeburn 6701: text-align: left;
1.819 tempelho 6702: }
1.862 bisitz 6703:
1.1098 bisitz 6704: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6705: clear:both;
6706: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6707: border: 1px solid $sidebg;
1.1098 bisitz 6708: margin: 0 0 10px 0;
1.966 bisitz 6709: padding: 3px;
1.995 raeburn 6710: text-align: left;
1.822 bisitz 6711: }
6712:
1.795 www 6713: .LC_fontsize_medium {
1.911 bisitz 6714: font-size: 85%;
1.705 tempelho 6715: }
6716:
1.795 www 6717: .LC_fontsize_large {
1.911 bisitz 6718: font-size: 120%;
1.705 tempelho 6719: }
6720:
1.346 albertel 6721: .LC_menubuttons_inline_text {
6722: color: $font;
1.698 harmsja 6723: font-size: 90%;
1.701 harmsja 6724: padding-left:3px;
1.346 albertel 6725: }
6726:
1.934 droeschl 6727: .LC_menubuttons_inline_text img{
6728: vertical-align: middle;
6729: }
6730:
1.1051 www 6731: li.LC_menubuttons_inline_text img {
1.951 onken 6732: cursor:pointer;
1.1002 droeschl 6733: text-decoration: none;
1.951 onken 6734: }
6735:
1.526 www 6736: .LC_menubuttons_link {
6737: text-decoration: none;
6738: }
1.795 www 6739:
1.522 albertel 6740: .LC_menubuttons_category {
1.521 www 6741: color: $font;
1.526 www 6742: background: $pgbg;
1.521 www 6743: font-size: larger;
6744: font-weight: bold;
6745: }
6746:
1.346 albertel 6747: td.LC_menubuttons_text {
1.911 bisitz 6748: color: $font;
1.346 albertel 6749: }
1.706 harmsja 6750:
1.346 albertel 6751: .LC_current_location {
6752: background: $tabbg;
6753: }
1.795 www 6754:
1.1286 raeburn 6755: td.LC_zero_height {
6756: line-height: 0;
6757: cellpadding: 0;
6758: }
6759:
1.938 bisitz 6760: table.LC_data_table {
1.347 albertel 6761: border: 1px solid #000000;
1.402 albertel 6762: border-collapse: separate;
1.426 albertel 6763: border-spacing: 1px;
1.610 albertel 6764: background: $pgbg;
1.347 albertel 6765: }
1.795 www 6766:
1.422 albertel 6767: .LC_data_table_dense {
6768: font-size: small;
6769: }
1.795 www 6770:
1.507 raeburn 6771: table.LC_nested_outer {
6772: border: 1px solid #000000;
1.589 raeburn 6773: border-collapse: collapse;
1.803 bisitz 6774: border-spacing: 0;
1.507 raeburn 6775: width: 100%;
6776: }
1.795 www 6777:
1.879 raeburn 6778: table.LC_innerpickbox,
1.507 raeburn 6779: table.LC_nested {
1.803 bisitz 6780: border: none;
1.589 raeburn 6781: border-collapse: collapse;
1.803 bisitz 6782: border-spacing: 0;
1.507 raeburn 6783: width: 100%;
6784: }
1.795 www 6785:
1.911 bisitz 6786: table.LC_data_table tr th,
6787: table.LC_calendar tr th,
1.879 raeburn 6788: table.LC_prior_tries tr th,
6789: table.LC_innerpickbox tr th {
1.349 albertel 6790: font-weight: bold;
6791: background-color: $data_table_head;
1.801 tempelho 6792: color:$fontmenu;
1.701 harmsja 6793: font-size:90%;
1.347 albertel 6794: }
1.795 www 6795:
1.879 raeburn 6796: table.LC_innerpickbox tr th,
6797: table.LC_innerpickbox tr td {
6798: vertical-align: top;
6799: }
6800:
1.711 raeburn 6801: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6802: background-color: #CCCCCC;
1.711 raeburn 6803: font-weight: bold;
6804: text-align: left;
6805: }
1.795 www 6806:
1.912 bisitz 6807: table.LC_data_table tr.LC_odd_row > td {
6808: background-color: $data_table_light;
6809: padding: 2px;
6810: vertical-align: top;
6811: }
6812:
1.809 bisitz 6813: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6814: background-color: $data_table_light;
1.912 bisitz 6815: vertical-align: top;
6816: }
6817:
6818: table.LC_data_table tr.LC_even_row > td {
6819: background-color: $data_table_dark;
1.425 albertel 6820: padding: 2px;
1.900 bisitz 6821: vertical-align: top;
1.347 albertel 6822: }
1.795 www 6823:
1.809 bisitz 6824: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6825: background-color: $data_table_dark;
1.900 bisitz 6826: vertical-align: top;
1.347 albertel 6827: }
1.795 www 6828:
1.425 albertel 6829: table.LC_data_table tr.LC_data_table_highlight td {
6830: background-color: $data_table_darker;
6831: }
1.795 www 6832:
1.639 raeburn 6833: table.LC_data_table tr td.LC_leftcol_header {
6834: background-color: $data_table_head;
6835: font-weight: bold;
6836: }
1.795 www 6837:
1.451 albertel 6838: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6839: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6840: font-weight: bold;
6841: font-style: italic;
6842: text-align: center;
6843: padding: 8px;
1.347 albertel 6844: }
1.795 www 6845:
1.1114 raeburn 6846: table.LC_data_table tr.LC_empty_row td,
6847: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6848: background-color: $sidebg;
6849: }
6850:
6851: table.LC_nested tr.LC_empty_row td {
6852: background-color: #FFFFFF;
6853: }
6854:
1.890 droeschl 6855: table.LC_caption {
6856: }
6857:
1.507 raeburn 6858: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6859: padding: 4ex
6860: }
1.795 www 6861:
1.507 raeburn 6862: table.LC_nested_outer tr th {
6863: font-weight: bold;
1.801 tempelho 6864: color:$fontmenu;
1.507 raeburn 6865: background-color: $data_table_head;
1.701 harmsja 6866: font-size: small;
1.507 raeburn 6867: border-bottom: 1px solid #000000;
6868: }
1.795 www 6869:
1.507 raeburn 6870: table.LC_nested_outer tr td.LC_subheader {
6871: background-color: $data_table_head;
6872: font-weight: bold;
6873: font-size: small;
6874: border-bottom: 1px solid #000000;
6875: text-align: right;
1.451 albertel 6876: }
1.795 www 6877:
1.507 raeburn 6878: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6879: background-color: #CCCCCC;
1.451 albertel 6880: font-weight: bold;
6881: font-size: small;
1.507 raeburn 6882: text-align: center;
6883: }
1.795 www 6884:
1.589 raeburn 6885: table.LC_nested tr.LC_info_row td.LC_left_item,
6886: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6887: text-align: left;
1.451 albertel 6888: }
1.795 www 6889:
1.507 raeburn 6890: table.LC_nested td {
1.735 bisitz 6891: background-color: #FFFFFF;
1.451 albertel 6892: font-size: small;
1.507 raeburn 6893: }
1.795 www 6894:
1.507 raeburn 6895: table.LC_nested_outer tr th.LC_right_item,
6896: table.LC_nested tr.LC_info_row td.LC_right_item,
6897: table.LC_nested tr.LC_odd_row td.LC_right_item,
6898: table.LC_nested tr td.LC_right_item {
1.451 albertel 6899: text-align: right;
6900: }
6901:
1.507 raeburn 6902: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6903: background-color: #EEEEEE;
1.451 albertel 6904: }
6905:
1.473 raeburn 6906: table.LC_createuser {
6907: }
6908:
6909: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6910: font-size: small;
1.473 raeburn 6911: }
6912:
6913: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6914: background-color: #CCCCCC;
1.473 raeburn 6915: font-weight: bold;
6916: text-align: center;
6917: }
6918:
1.349 albertel 6919: table.LC_calendar {
6920: border: 1px solid #000000;
6921: border-collapse: collapse;
1.917 raeburn 6922: width: 98%;
1.349 albertel 6923: }
1.795 www 6924:
1.349 albertel 6925: table.LC_calendar_pickdate {
6926: font-size: xx-small;
6927: }
1.795 www 6928:
1.349 albertel 6929: table.LC_calendar tr td {
6930: border: 1px solid #000000;
6931: vertical-align: top;
1.917 raeburn 6932: width: 14%;
1.349 albertel 6933: }
1.795 www 6934:
1.349 albertel 6935: table.LC_calendar tr td.LC_calendar_day_empty {
6936: background-color: $data_table_dark;
6937: }
1.795 www 6938:
1.779 bisitz 6939: table.LC_calendar tr td.LC_calendar_day_current {
6940: background-color: $data_table_highlight;
1.777 tempelho 6941: }
1.795 www 6942:
1.938 bisitz 6943: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6944: background-color: $mail_new;
6945: }
1.795 www 6946:
1.938 bisitz 6947: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6948: background-color: $mail_new_hover;
6949: }
1.795 www 6950:
1.938 bisitz 6951: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6952: background-color: $mail_read;
6953: }
1.795 www 6954:
1.938 bisitz 6955: /*
6956: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6957: background-color: $mail_read_hover;
6958: }
1.938 bisitz 6959: */
1.795 www 6960:
1.938 bisitz 6961: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6962: background-color: $mail_replied;
6963: }
1.795 www 6964:
1.938 bisitz 6965: /*
6966: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6967: background-color: $mail_replied_hover;
6968: }
1.938 bisitz 6969: */
1.795 www 6970:
1.938 bisitz 6971: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6972: background-color: $mail_other;
6973: }
1.795 www 6974:
1.938 bisitz 6975: /*
6976: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6977: background-color: $mail_other_hover;
6978: }
1.938 bisitz 6979: */
1.494 raeburn 6980:
1.777 tempelho 6981: table.LC_data_table tr > td.LC_browser_file,
6982: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6983: background: #AAEE77;
1.389 albertel 6984: }
1.795 www 6985:
1.777 tempelho 6986: table.LC_data_table tr > td.LC_browser_file_locked,
6987: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6988: background: #FFAA99;
1.387 albertel 6989: }
1.795 www 6990:
1.777 tempelho 6991: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6992: background: #888888;
1.779 bisitz 6993: }
1.795 www 6994:
1.777 tempelho 6995: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6996: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6997: background: #F8F866;
1.777 tempelho 6998: }
1.795 www 6999:
1.696 bisitz 7000: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 7001: background: #E0E8FF;
1.387 albertel 7002: }
1.696 bisitz 7003:
1.707 bisitz 7004: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 7005: /* background: #77FF77; */
1.707 bisitz 7006: }
1.795 www 7007:
1.707 bisitz 7008: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 7009: border-right: 8px solid #FFFF77;
1.707 bisitz 7010: }
1.795 www 7011:
1.707 bisitz 7012: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 7013: border-right: 8px solid #FFAA77;
1.707 bisitz 7014: }
1.795 www 7015:
1.707 bisitz 7016: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 7017: border-right: 8px solid #FF7777;
1.707 bisitz 7018: }
1.795 www 7019:
1.707 bisitz 7020: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 7021: border-right: 8px solid #AAFF77;
1.707 bisitz 7022: }
1.795 www 7023:
1.707 bisitz 7024: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 7025: border-right: 8px solid #11CC55;
1.707 bisitz 7026: }
7027:
1.388 albertel 7028: span.LC_current_location {
1.701 harmsja 7029: font-size:larger;
1.388 albertel 7030: background: $pgbg;
7031: }
1.387 albertel 7032:
1.1029 www 7033: span.LC_current_nav_location {
7034: font-weight:bold;
7035: background: $sidebg;
7036: }
7037:
1.395 albertel 7038: span.LC_parm_menu_item {
7039: font-size: larger;
7040: }
1.795 www 7041:
1.395 albertel 7042: span.LC_parm_scope_all {
7043: color: red;
7044: }
1.795 www 7045:
1.395 albertel 7046: span.LC_parm_scope_folder {
7047: color: green;
7048: }
1.795 www 7049:
1.395 albertel 7050: span.LC_parm_scope_resource {
7051: color: orange;
7052: }
1.795 www 7053:
1.395 albertel 7054: span.LC_parm_part {
7055: color: blue;
7056: }
1.795 www 7057:
1.911 bisitz 7058: span.LC_parm_folder,
7059: span.LC_parm_symb {
1.395 albertel 7060: font-size: x-small;
7061: font-family: $mono;
7062: color: #AAAAAA;
7063: }
7064:
1.977 bisitz 7065: ul.LC_parm_parmlist li {
7066: display: inline-block;
7067: padding: 0.3em 0.8em;
7068: vertical-align: top;
7069: width: 150px;
7070: border-top:1px solid $lg_border_color;
7071: }
7072:
1.795 www 7073: td.LC_parm_overview_level_menu,
7074: td.LC_parm_overview_map_menu,
7075: td.LC_parm_overview_parm_selectors,
7076: td.LC_parm_overview_restrictions {
1.396 albertel 7077: border: 1px solid black;
7078: border-collapse: collapse;
7079: }
1.795 www 7080:
1.1285 raeburn 7081: span.LC_parm_recursive,
7082: td.LC_parm_recursive {
7083: font-weight: bold;
7084: font-size: smaller;
7085: }
7086:
1.396 albertel 7087: table.LC_parm_overview_restrictions td {
7088: border-width: 1px 4px 1px 4px;
7089: border-style: solid;
7090: border-color: $pgbg;
7091: text-align: center;
7092: }
1.795 www 7093:
1.396 albertel 7094: table.LC_parm_overview_restrictions th {
7095: background: $tabbg;
7096: border-width: 1px 4px 1px 4px;
7097: border-style: solid;
7098: border-color: $pgbg;
7099: }
1.795 www 7100:
1.398 albertel 7101: table#LC_helpmenu {
1.803 bisitz 7102: border: none;
1.398 albertel 7103: height: 55px;
1.803 bisitz 7104: border-spacing: 0;
1.398 albertel 7105: }
7106:
7107: table#LC_helpmenu fieldset legend {
7108: font-size: larger;
7109: }
1.795 www 7110:
1.397 albertel 7111: table#LC_helpmenu_links {
7112: width: 100%;
7113: border: 1px solid black;
7114: background: $pgbg;
1.803 bisitz 7115: padding: 0;
1.397 albertel 7116: border-spacing: 1px;
7117: }
1.795 www 7118:
1.397 albertel 7119: table#LC_helpmenu_links tr td {
7120: padding: 1px;
7121: background: $tabbg;
1.399 albertel 7122: text-align: center;
7123: font-weight: bold;
1.397 albertel 7124: }
1.396 albertel 7125:
1.795 www 7126: table#LC_helpmenu_links a:link,
7127: table#LC_helpmenu_links a:visited,
1.397 albertel 7128: table#LC_helpmenu_links a:active {
7129: text-decoration: none;
7130: color: $font;
7131: }
1.795 www 7132:
1.397 albertel 7133: table#LC_helpmenu_links a:hover {
7134: text-decoration: underline;
7135: color: $vlink;
7136: }
1.396 albertel 7137:
1.417 albertel 7138: .LC_chrt_popup_exists {
7139: border: 1px solid #339933;
7140: margin: -1px;
7141: }
1.795 www 7142:
1.417 albertel 7143: .LC_chrt_popup_up {
7144: border: 1px solid yellow;
7145: margin: -1px;
7146: }
1.795 www 7147:
1.417 albertel 7148: .LC_chrt_popup {
7149: border: 1px solid #8888FF;
7150: background: #CCCCFF;
7151: }
1.795 www 7152:
1.421 albertel 7153: table.LC_pick_box {
7154: border-collapse: separate;
7155: background: white;
7156: border: 1px solid black;
7157: border-spacing: 1px;
7158: }
1.795 www 7159:
1.421 albertel 7160: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7161: background: $sidebg;
1.421 albertel 7162: font-weight: bold;
1.900 bisitz 7163: text-align: left;
1.740 bisitz 7164: vertical-align: top;
1.421 albertel 7165: width: 184px;
7166: padding: 8px;
7167: }
1.795 www 7168:
1.579 raeburn 7169: table.LC_pick_box td.LC_pick_box_value {
7170: text-align: left;
7171: padding: 8px;
7172: }
1.795 www 7173:
1.579 raeburn 7174: table.LC_pick_box td.LC_pick_box_select {
7175: text-align: left;
7176: padding: 8px;
7177: }
1.795 www 7178:
1.424 albertel 7179: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7180: padding: 0;
1.421 albertel 7181: height: 1px;
7182: background: black;
7183: }
1.795 www 7184:
1.421 albertel 7185: table.LC_pick_box td.LC_pick_box_submit {
7186: text-align: right;
7187: }
1.795 www 7188:
1.579 raeburn 7189: table.LC_pick_box td.LC_evenrow_value {
7190: text-align: left;
7191: padding: 8px;
7192: background-color: $data_table_light;
7193: }
1.795 www 7194:
1.579 raeburn 7195: table.LC_pick_box td.LC_oddrow_value {
7196: text-align: left;
7197: padding: 8px;
7198: background-color: $data_table_light;
7199: }
1.795 www 7200:
1.579 raeburn 7201: span.LC_helpform_receipt_cat {
7202: font-weight: bold;
7203: }
1.795 www 7204:
1.424 albertel 7205: table.LC_group_priv_box {
7206: background: white;
7207: border: 1px solid black;
7208: border-spacing: 1px;
7209: }
1.795 www 7210:
1.424 albertel 7211: table.LC_group_priv_box td.LC_pick_box_title {
7212: background: $tabbg;
7213: font-weight: bold;
7214: text-align: right;
7215: width: 184px;
7216: }
1.795 www 7217:
1.424 albertel 7218: table.LC_group_priv_box td.LC_groups_fixed {
7219: background: $data_table_light;
7220: text-align: center;
7221: }
1.795 www 7222:
1.424 albertel 7223: table.LC_group_priv_box td.LC_groups_optional {
7224: background: $data_table_dark;
7225: text-align: center;
7226: }
1.795 www 7227:
1.424 albertel 7228: table.LC_group_priv_box td.LC_groups_functionality {
7229: background: $data_table_darker;
7230: text-align: center;
7231: font-weight: bold;
7232: }
1.795 www 7233:
1.424 albertel 7234: table.LC_group_priv td {
7235: text-align: left;
1.803 bisitz 7236: padding: 0;
1.424 albertel 7237: }
7238:
7239: .LC_navbuttons {
7240: margin: 2ex 0ex 2ex 0ex;
7241: }
1.795 www 7242:
1.423 albertel 7243: .LC_topic_bar {
7244: font-weight: bold;
7245: background: $tabbg;
1.918 wenzelju 7246: margin: 1em 0em 1em 2em;
1.805 bisitz 7247: padding: 3px;
1.918 wenzelju 7248: font-size: 1.2em;
1.423 albertel 7249: }
1.795 www 7250:
1.423 albertel 7251: .LC_topic_bar span {
1.918 wenzelju 7252: left: 0.5em;
7253: position: absolute;
1.423 albertel 7254: vertical-align: middle;
1.918 wenzelju 7255: font-size: 1.2em;
1.423 albertel 7256: }
1.795 www 7257:
1.423 albertel 7258: table.LC_course_group_status {
7259: margin: 20px;
7260: }
1.795 www 7261:
1.423 albertel 7262: table.LC_status_selector td {
7263: vertical-align: top;
7264: text-align: center;
1.424 albertel 7265: padding: 4px;
7266: }
1.795 www 7267:
1.599 albertel 7268: div.LC_feedback_link {
1.616 albertel 7269: clear: both;
1.829 kalberla 7270: background: $sidebg;
1.779 bisitz 7271: width: 100%;
1.829 kalberla 7272: padding-bottom: 10px;
7273: border: 1px $tabbg solid;
1.833 kalberla 7274: height: 22px;
7275: line-height: 22px;
7276: padding-top: 5px;
7277: }
7278:
7279: div.LC_feedback_link img {
7280: height: 22px;
1.867 kalberla 7281: vertical-align:middle;
1.829 kalberla 7282: }
7283:
1.911 bisitz 7284: div.LC_feedback_link a {
1.829 kalberla 7285: text-decoration: none;
1.489 raeburn 7286: }
1.795 www 7287:
1.867 kalberla 7288: div.LC_comblock {
1.911 bisitz 7289: display:inline;
1.867 kalberla 7290: color:$font;
7291: font-size:90%;
7292: }
7293:
7294: div.LC_feedback_link div.LC_comblock {
7295: padding-left:5px;
7296: }
7297:
7298: div.LC_feedback_link div.LC_comblock a {
7299: color:$font;
7300: }
7301:
1.489 raeburn 7302: span.LC_feedback_link {
1.858 bisitz 7303: /* background: $feedback_link_bg; */
1.599 albertel 7304: font-size: larger;
7305: }
1.795 www 7306:
1.599 albertel 7307: span.LC_message_link {
1.858 bisitz 7308: /* background: $feedback_link_bg; */
1.599 albertel 7309: font-size: larger;
7310: position: absolute;
7311: right: 1em;
1.489 raeburn 7312: }
1.421 albertel 7313:
1.515 albertel 7314: table.LC_prior_tries {
1.524 albertel 7315: border: 1px solid #000000;
7316: border-collapse: separate;
7317: border-spacing: 1px;
1.515 albertel 7318: }
1.523 albertel 7319:
1.515 albertel 7320: table.LC_prior_tries td {
1.524 albertel 7321: padding: 2px;
1.515 albertel 7322: }
1.523 albertel 7323:
7324: .LC_answer_correct {
1.795 www 7325: background: lightgreen;
7326: color: darkgreen;
7327: padding: 6px;
1.523 albertel 7328: }
1.795 www 7329:
1.523 albertel 7330: .LC_answer_charged_try {
1.797 www 7331: background: #FFAAAA;
1.795 www 7332: color: darkred;
7333: padding: 6px;
1.523 albertel 7334: }
1.795 www 7335:
1.779 bisitz 7336: .LC_answer_not_charged_try,
1.523 albertel 7337: .LC_answer_no_grade,
7338: .LC_answer_late {
1.795 www 7339: background: lightyellow;
1.523 albertel 7340: color: black;
1.795 www 7341: padding: 6px;
1.523 albertel 7342: }
1.795 www 7343:
1.523 albertel 7344: .LC_answer_previous {
1.795 www 7345: background: lightblue;
7346: color: darkblue;
7347: padding: 6px;
1.523 albertel 7348: }
1.795 www 7349:
1.779 bisitz 7350: .LC_answer_no_message {
1.777 tempelho 7351: background: #FFFFFF;
7352: color: black;
1.795 www 7353: padding: 6px;
1.779 bisitz 7354: }
1.795 www 7355:
1.1334 raeburn 7356: .LC_answer_unknown,
7357: .LC_answer_warning {
1.779 bisitz 7358: background: orange;
7359: color: black;
1.795 www 7360: padding: 6px;
1.777 tempelho 7361: }
1.795 www 7362:
1.529 albertel 7363: span.LC_prior_numerical,
7364: span.LC_prior_string,
7365: span.LC_prior_custom,
7366: span.LC_prior_reaction,
7367: span.LC_prior_math {
1.925 bisitz 7368: font-family: $mono;
1.523 albertel 7369: white-space: pre;
7370: }
7371:
1.525 albertel 7372: span.LC_prior_string {
1.925 bisitz 7373: font-family: $mono;
1.525 albertel 7374: white-space: pre;
7375: }
7376:
1.523 albertel 7377: table.LC_prior_option {
7378: width: 100%;
7379: border-collapse: collapse;
7380: }
1.795 www 7381:
1.911 bisitz 7382: table.LC_prior_rank,
1.795 www 7383: table.LC_prior_match {
1.528 albertel 7384: border-collapse: collapse;
7385: }
1.795 www 7386:
1.528 albertel 7387: table.LC_prior_option tr td,
7388: table.LC_prior_rank tr td,
7389: table.LC_prior_match tr td {
1.524 albertel 7390: border: 1px solid #000000;
1.515 albertel 7391: }
7392:
1.855 bisitz 7393: .LC_nobreak {
1.544 albertel 7394: white-space: nowrap;
1.519 raeburn 7395: }
7396:
1.576 raeburn 7397: span.LC_cusr_emph {
7398: font-style: italic;
7399: }
7400:
1.633 raeburn 7401: span.LC_cusr_subheading {
7402: font-weight: normal;
7403: font-size: 85%;
7404: }
7405:
1.861 bisitz 7406: div.LC_docs_entry_move {
1.859 bisitz 7407: border: 1px solid #BBBBBB;
1.545 albertel 7408: background: #DDDDDD;
1.861 bisitz 7409: width: 22px;
1.859 bisitz 7410: padding: 1px;
7411: margin: 0;
1.545 albertel 7412: }
7413:
1.861 bisitz 7414: table.LC_data_table tr > td.LC_docs_entry_commands,
7415: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7416: font-size: x-small;
7417: }
1.795 www 7418:
1.861 bisitz 7419: .LC_docs_entry_parameter {
7420: white-space: nowrap;
7421: }
7422:
1.544 albertel 7423: .LC_docs_copy {
1.545 albertel 7424: color: #000099;
1.544 albertel 7425: }
1.795 www 7426:
1.544 albertel 7427: .LC_docs_cut {
1.545 albertel 7428: color: #550044;
1.544 albertel 7429: }
1.795 www 7430:
1.544 albertel 7431: .LC_docs_rename {
1.545 albertel 7432: color: #009900;
1.544 albertel 7433: }
1.795 www 7434:
1.544 albertel 7435: .LC_docs_remove {
1.545 albertel 7436: color: #990000;
7437: }
7438:
1.1284 raeburn 7439: .LC_docs_alias {
7440: color: #440055;
7441: }
7442:
1.1286 raeburn 7443: .LC_domprefs_email,
1.1284 raeburn 7444: .LC_docs_alias_name,
1.547 albertel 7445: .LC_docs_reinit_warn,
7446: .LC_docs_ext_edit {
7447: font-size: x-small;
7448: }
7449:
1.545 albertel 7450: table.LC_docs_adddocs td,
7451: table.LC_docs_adddocs th {
7452: border: 1px solid #BBBBBB;
7453: padding: 4px;
7454: background: #DDDDDD;
1.543 albertel 7455: }
7456:
1.584 albertel 7457: table.LC_sty_begin {
7458: background: #BBFFBB;
7459: }
1.795 www 7460:
1.584 albertel 7461: table.LC_sty_end {
7462: background: #FFBBBB;
7463: }
7464:
1.589 raeburn 7465: table.LC_double_column {
1.803 bisitz 7466: border-width: 0;
1.589 raeburn 7467: border-collapse: collapse;
7468: width: 100%;
7469: padding: 2px;
7470: }
7471:
7472: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7473: top: 2px;
1.589 raeburn 7474: left: 2px;
7475: width: 47%;
7476: vertical-align: top;
7477: }
7478:
7479: table.LC_double_column tr td.LC_right_col {
7480: top: 2px;
1.779 bisitz 7481: right: 2px;
1.589 raeburn 7482: width: 47%;
7483: vertical-align: top;
7484: }
7485:
1.591 raeburn 7486: div.LC_left_float {
7487: float: left;
7488: padding-right: 5%;
1.597 albertel 7489: padding-bottom: 4px;
1.591 raeburn 7490: }
7491:
7492: div.LC_clear_float_header {
1.597 albertel 7493: padding-bottom: 2px;
1.591 raeburn 7494: }
7495:
7496: div.LC_clear_float_footer {
1.597 albertel 7497: padding-top: 10px;
1.591 raeburn 7498: clear: both;
7499: }
7500:
1.597 albertel 7501: div.LC_grade_show_user {
1.941 bisitz 7502: /* border-left: 5px solid $sidebg; */
7503: border-top: 5px solid #000000;
7504: margin: 50px 0 0 0;
1.936 bisitz 7505: padding: 15px 0 5px 10px;
1.597 albertel 7506: }
1.795 www 7507:
1.936 bisitz 7508: div.LC_grade_show_user_odd_row {
1.941 bisitz 7509: /* border-left: 5px solid #000000; */
7510: }
7511:
7512: div.LC_grade_show_user div.LC_Box {
7513: margin-right: 50px;
1.597 albertel 7514: }
7515:
7516: div.LC_grade_submissions,
7517: div.LC_grade_message_center,
1.936 bisitz 7518: div.LC_grade_info_links {
1.597 albertel 7519: margin: 5px;
7520: width: 99%;
7521: background: #FFFFFF;
7522: }
1.795 www 7523:
1.597 albertel 7524: div.LC_grade_submissions_header,
1.936 bisitz 7525: div.LC_grade_message_center_header {
1.705 tempelho 7526: font-weight: bold;
7527: font-size: large;
1.597 albertel 7528: }
1.795 www 7529:
1.597 albertel 7530: div.LC_grade_submissions_body,
1.936 bisitz 7531: div.LC_grade_message_center_body {
1.597 albertel 7532: border: 1px solid black;
7533: width: 99%;
7534: background: #FFFFFF;
7535: }
1.795 www 7536:
1.613 albertel 7537: table.LC_scantron_action {
7538: width: 100%;
7539: }
1.795 www 7540:
1.613 albertel 7541: table.LC_scantron_action tr th {
1.698 harmsja 7542: font-weight:bold;
7543: font-style:normal;
1.613 albertel 7544: }
1.795 www 7545:
1.779 bisitz 7546: .LC_edit_problem_header,
1.614 albertel 7547: div.LC_edit_problem_footer {
1.705 tempelho 7548: font-weight: normal;
7549: font-size: medium;
1.602 albertel 7550: margin: 2px;
1.1060 bisitz 7551: background-color: $sidebg;
1.600 albertel 7552: }
1.795 www 7553:
1.600 albertel 7554: div.LC_edit_problem_header,
1.602 albertel 7555: div.LC_edit_problem_header div,
1.614 albertel 7556: div.LC_edit_problem_footer,
7557: div.LC_edit_problem_footer div,
1.602 albertel 7558: div.LC_edit_problem_editxml_header,
7559: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7560: z-index: 100;
1.600 albertel 7561: }
1.795 www 7562:
1.600 albertel 7563: div.LC_edit_problem_header_title {
1.705 tempelho 7564: font-weight: bold;
7565: font-size: larger;
1.602 albertel 7566: background: $tabbg;
7567: padding: 3px;
1.1060 bisitz 7568: margin: 0 0 5px 0;
1.602 albertel 7569: }
1.795 www 7570:
1.602 albertel 7571: table.LC_edit_problem_header_title {
7572: width: 100%;
1.600 albertel 7573: background: $tabbg;
1.602 albertel 7574: }
7575:
1.1205 golterma 7576: div.LC_edit_actionbar {
7577: background-color: $sidebg;
1.1218 droeschl 7578: margin: 0;
7579: padding: 0;
7580: line-height: 200%;
1.602 albertel 7581: }
1.795 www 7582:
1.1218 droeschl 7583: div.LC_edit_actionbar div{
7584: padding: 0;
7585: margin: 0;
7586: display: inline-block;
1.600 albertel 7587: }
1.795 www 7588:
1.1124 bisitz 7589: .LC_edit_opt {
7590: padding-left: 1em;
7591: white-space: nowrap;
7592: }
7593:
1.1152 golterma 7594: .LC_edit_problem_latexhelper{
7595: text-align: right;
7596: }
7597:
7598: #LC_edit_problem_colorful div{
7599: margin-left: 40px;
7600: }
7601:
1.1205 golterma 7602: #LC_edit_problem_codemirror div{
7603: margin-left: 0px;
7604: }
7605:
1.911 bisitz 7606: img.stift {
1.803 bisitz 7607: border-width: 0;
7608: vertical-align: middle;
1.677 riegler 7609: }
1.680 riegler 7610:
1.923 bisitz 7611: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7612: vertical-align: top;
1.777 tempelho 7613: }
1.795 www 7614:
1.716 raeburn 7615: div.LC_createcourse {
1.911 bisitz 7616: margin: 10px 10px 10px 10px;
1.716 raeburn 7617: }
7618:
1.917 raeburn 7619: .LC_dccid {
1.1130 raeburn 7620: float: right;
1.917 raeburn 7621: margin: 0.2em 0 0 0;
7622: padding: 0;
7623: font-size: 90%;
7624: display:none;
7625: }
7626:
1.897 wenzelju 7627: ol.LC_primary_menu a:hover,
1.721 harmsja 7628: ol#LC_MenuBreadcrumbs a:hover,
7629: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7630: ul#LC_secondary_menu a:hover,
1.721 harmsja 7631: .LC_FormSectionClearButton input:hover
1.795 www 7632: ul.LC_TabContent li:hover a {
1.952 onken 7633: color:$button_hover;
1.911 bisitz 7634: text-decoration:none;
1.693 droeschl 7635: }
7636:
1.779 bisitz 7637: h1 {
1.911 bisitz 7638: padding: 0;
7639: line-height:130%;
1.693 droeschl 7640: }
1.698 harmsja 7641:
1.911 bisitz 7642: h2,
7643: h3,
7644: h4,
7645: h5,
7646: h6 {
7647: margin: 5px 0 5px 0;
7648: padding: 0;
7649: line-height:130%;
1.693 droeschl 7650: }
1.795 www 7651:
7652: .LC_hcell {
1.911 bisitz 7653: padding:3px 15px 3px 15px;
7654: margin: 0;
7655: background-color:$tabbg;
7656: color:$fontmenu;
7657: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7658: }
1.795 www 7659:
1.840 bisitz 7660: .LC_Box > .LC_hcell {
1.911 bisitz 7661: margin: 0 -10px 10px -10px;
1.835 bisitz 7662: }
7663:
1.721 harmsja 7664: .LC_noBorder {
1.911 bisitz 7665: border: 0;
1.698 harmsja 7666: }
1.693 droeschl 7667:
1.721 harmsja 7668: .LC_FormSectionClearButton input {
1.911 bisitz 7669: background-color:transparent;
7670: border: none;
7671: cursor:pointer;
7672: text-decoration:underline;
1.693 droeschl 7673: }
1.763 bisitz 7674:
7675: .LC_help_open_topic {
1.911 bisitz 7676: color: #FFFFFF;
7677: background-color: #EEEEFF;
7678: margin: 1px;
7679: padding: 4px;
7680: border: 1px solid #000033;
7681: white-space: nowrap;
7682: /* vertical-align: middle; */
1.759 neumanie 7683: }
1.693 droeschl 7684:
1.911 bisitz 7685: dl,
7686: ul,
7687: div,
7688: fieldset {
7689: margin: 10px 10px 10px 0;
7690: /* overflow: hidden; */
1.693 droeschl 7691: }
1.795 www 7692:
1.1211 raeburn 7693: article.geogebraweb div {
7694: margin: 0;
7695: }
7696:
1.838 bisitz 7697: fieldset > legend {
1.911 bisitz 7698: font-weight: bold;
7699: padding: 0 5px 0 5px;
1.838 bisitz 7700: }
7701:
1.813 bisitz 7702: #LC_nav_bar {
1.911 bisitz 7703: float: left;
1.995 raeburn 7704: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7705: margin: 0 0 2px 0;
1.807 droeschl 7706: }
7707:
1.916 droeschl 7708: #LC_realm {
7709: margin: 0.2em 0 0 0;
7710: padding: 0;
7711: font-weight: bold;
7712: text-align: center;
1.995 raeburn 7713: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7714: }
7715:
1.911 bisitz 7716: #LC_nav_bar em {
7717: font-weight: bold;
7718: font-style: normal;
1.807 droeschl 7719: }
7720:
1.897 wenzelju 7721: ol.LC_primary_menu {
1.934 droeschl 7722: margin: 0;
1.1076 raeburn 7723: padding: 0;
1.807 droeschl 7724: }
7725:
1.852 droeschl 7726: ol#LC_PathBreadcrumbs {
1.911 bisitz 7727: margin: 0;
1.693 droeschl 7728: }
7729:
1.897 wenzelju 7730: ol.LC_primary_menu li {
1.1076 raeburn 7731: color: RGB(80, 80, 80);
7732: vertical-align: middle;
7733: text-align: left;
7734: list-style: none;
1.1205 golterma 7735: position: relative;
1.1076 raeburn 7736: float: left;
1.1205 golterma 7737: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7738: line-height: 1.5em;
1.1076 raeburn 7739: }
7740:
1.1205 golterma 7741: ol.LC_primary_menu li a,
7742: ol.LC_primary_menu li p {
1.1076 raeburn 7743: display: block;
7744: margin: 0;
7745: padding: 0 5px 0 10px;
7746: text-decoration: none;
7747: }
7748:
1.1205 golterma 7749: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7750: display: inline-block;
7751: width: 95%;
7752: text-align: left;
7753: }
7754:
7755: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7756: display: inline-block;
7757: width: 5%;
7758: float: right;
7759: text-align: right;
7760: font-size: 70%;
7761: }
7762:
7763: ol.LC_primary_menu ul {
1.1076 raeburn 7764: display: none;
1.1205 golterma 7765: width: 15em;
1.1076 raeburn 7766: background-color: $data_table_light;
1.1205 golterma 7767: position: absolute;
7768: top: 100%;
1.1076 raeburn 7769: }
7770:
1.1205 golterma 7771: ol.LC_primary_menu ul ul {
7772: left: 100%;
7773: top: 0;
7774: }
7775:
7776: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7777: display: block;
7778: position: absolute;
7779: margin: 0;
7780: padding: 0;
1.1078 raeburn 7781: z-index: 2;
1.1076 raeburn 7782: }
7783:
7784: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7785: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7786: font-size: 90%;
1.911 bisitz 7787: vertical-align: top;
1.1076 raeburn 7788: float: none;
1.1079 raeburn 7789: border-left: 1px solid black;
7790: border-right: 1px solid black;
1.1205 golterma 7791: /* A dark bottom border to visualize different menu options;
7792: overwritten in the create_submenu routine for the last border-bottom of the menu */
7793: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7794: }
7795:
1.1205 golterma 7796: ol.LC_primary_menu li li p:hover {
7797: color:$button_hover;
7798: text-decoration:none;
7799: background-color:$data_table_dark;
1.1076 raeburn 7800: }
7801:
7802: ol.LC_primary_menu li li a:hover {
7803: color:$button_hover;
7804: background-color:$data_table_dark;
1.693 droeschl 7805: }
7806:
1.1205 golterma 7807: /* Font-size equal to the size of the predecessors*/
7808: ol.LC_primary_menu li:hover li li {
7809: font-size: 100%;
7810: }
7811:
1.897 wenzelju 7812: ol.LC_primary_menu li img {
1.911 bisitz 7813: vertical-align: bottom;
1.934 droeschl 7814: height: 1.1em;
1.1077 raeburn 7815: margin: 0.2em 0 0 0;
1.693 droeschl 7816: }
7817:
1.897 wenzelju 7818: ol.LC_primary_menu a {
1.911 bisitz 7819: color: RGB(80, 80, 80);
7820: text-decoration: none;
1.693 droeschl 7821: }
1.795 www 7822:
1.949 droeschl 7823: ol.LC_primary_menu a.LC_new_message {
7824: font-weight:bold;
7825: color: darkred;
7826: }
7827:
1.975 raeburn 7828: ol.LC_docs_parameters {
7829: margin-left: 0;
7830: padding: 0;
7831: list-style: none;
7832: }
7833:
7834: ol.LC_docs_parameters li {
7835: margin: 0;
7836: padding-right: 20px;
7837: display: inline;
7838: }
7839:
1.976 raeburn 7840: ol.LC_docs_parameters li:before {
7841: content: "\\002022 \\0020";
7842: }
7843:
7844: li.LC_docs_parameters_title {
7845: font-weight: bold;
7846: }
7847:
7848: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7849: content: "";
7850: }
7851:
1.897 wenzelju 7852: ul#LC_secondary_menu {
1.1107 raeburn 7853: clear: right;
1.911 bisitz 7854: color: $fontmenu;
7855: background: $tabbg;
7856: list-style: none;
7857: padding: 0;
7858: margin: 0;
7859: width: 100%;
1.995 raeburn 7860: text-align: left;
1.1107 raeburn 7861: float: left;
1.808 droeschl 7862: }
7863:
1.897 wenzelju 7864: ul#LC_secondary_menu li {
1.911 bisitz 7865: font-weight: bold;
7866: line-height: 1.8em;
1.1107 raeburn 7867: border-right: 1px solid black;
7868: float: left;
7869: }
7870:
7871: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7872: background-color: $data_table_light;
7873: }
7874:
7875: ul#LC_secondary_menu li a {
1.911 bisitz 7876: padding: 0 0.8em;
1.1107 raeburn 7877: }
7878:
7879: ul#LC_secondary_menu li ul {
7880: display: none;
7881: }
7882:
7883: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7884: display: block;
7885: position: absolute;
7886: margin: 0;
7887: padding: 0;
7888: list-style:none;
7889: float: none;
7890: background-color: $data_table_light;
7891: z-index: 2;
7892: margin-left: -1px;
7893: }
7894:
7895: ul#LC_secondary_menu li ul li {
7896: font-size: 90%;
7897: vertical-align: top;
7898: border-left: 1px solid black;
1.911 bisitz 7899: border-right: 1px solid black;
1.1119 raeburn 7900: background-color: $data_table_light;
1.1107 raeburn 7901: list-style:none;
7902: float: none;
7903: }
7904:
7905: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7906: background-color: $data_table_dark;
1.807 droeschl 7907: }
7908:
1.847 tempelho 7909: ul.LC_TabContent {
1.911 bisitz 7910: display:block;
7911: background: $sidebg;
7912: border-bottom: solid 1px $lg_border_color;
7913: list-style:none;
1.1020 raeburn 7914: margin: -1px -10px 0 -10px;
1.911 bisitz 7915: padding: 0;
1.693 droeschl 7916: }
7917:
1.795 www 7918: ul.LC_TabContent li,
7919: ul.LC_TabContentBigger li {
1.911 bisitz 7920: float:left;
1.741 harmsja 7921: }
1.795 www 7922:
1.897 wenzelju 7923: ul#LC_secondary_menu li a {
1.911 bisitz 7924: color: $fontmenu;
7925: text-decoration: none;
1.693 droeschl 7926: }
1.795 www 7927:
1.721 harmsja 7928: ul.LC_TabContent {
1.952 onken 7929: min-height:20px;
1.721 harmsja 7930: }
1.795 www 7931:
7932: ul.LC_TabContent li {
1.911 bisitz 7933: vertical-align:middle;
1.959 onken 7934: padding: 0 16px 0 10px;
1.911 bisitz 7935: background-color:$tabbg;
7936: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7937: border-left: solid 1px $font;
1.721 harmsja 7938: }
1.795 www 7939:
1.847 tempelho 7940: ul.LC_TabContent .right {
1.911 bisitz 7941: float:right;
1.847 tempelho 7942: }
7943:
1.911 bisitz 7944: ul.LC_TabContent li a,
7945: ul.LC_TabContent li {
7946: color:rgb(47,47,47);
7947: text-decoration:none;
7948: font-size:95%;
7949: font-weight:bold;
1.952 onken 7950: min-height:20px;
7951: }
7952:
1.959 onken 7953: ul.LC_TabContent li a:hover,
7954: ul.LC_TabContent li a:focus {
1.952 onken 7955: color: $button_hover;
1.959 onken 7956: background:none;
7957: outline:none;
1.952 onken 7958: }
7959:
7960: ul.LC_TabContent li:hover {
7961: color: $button_hover;
7962: cursor:pointer;
1.721 harmsja 7963: }
1.795 www 7964:
1.911 bisitz 7965: ul.LC_TabContent li.active {
1.952 onken 7966: color: $font;
1.911 bisitz 7967: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7968: border-bottom:solid 1px #FFFFFF;
7969: cursor: default;
1.744 ehlerst 7970: }
1.795 www 7971:
1.959 onken 7972: ul.LC_TabContent li.active a {
7973: color:$font;
7974: background:#FFFFFF;
7975: outline: none;
7976: }
1.1047 raeburn 7977:
7978: ul.LC_TabContent li.goback {
7979: float: left;
7980: border-left: none;
7981: }
7982:
1.870 tempelho 7983: #maincoursedoc {
1.911 bisitz 7984: clear:both;
1.870 tempelho 7985: }
7986:
7987: ul.LC_TabContentBigger {
1.911 bisitz 7988: display:block;
7989: list-style:none;
7990: padding: 0;
1.870 tempelho 7991: }
7992:
1.795 www 7993: ul.LC_TabContentBigger li {
1.911 bisitz 7994: vertical-align:bottom;
7995: height: 30px;
7996: font-size:110%;
7997: font-weight:bold;
7998: color: #737373;
1.841 tempelho 7999: }
8000:
1.957 onken 8001: ul.LC_TabContentBigger li.active {
8002: position: relative;
8003: top: 1px;
8004: }
8005:
1.870 tempelho 8006: ul.LC_TabContentBigger li a {
1.911 bisitz 8007: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
8008: height: 30px;
8009: line-height: 30px;
8010: text-align: center;
8011: display: block;
8012: text-decoration: none;
1.958 onken 8013: outline: none;
1.741 harmsja 8014: }
1.795 www 8015:
1.870 tempelho 8016: ul.LC_TabContentBigger li.active a {
1.911 bisitz 8017: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
8018: color:$font;
1.744 ehlerst 8019: }
1.795 www 8020:
1.870 tempelho 8021: ul.LC_TabContentBigger li b {
1.911 bisitz 8022: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
8023: display: block;
8024: float: left;
8025: padding: 0 30px;
1.957 onken 8026: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 8027: }
8028:
1.956 onken 8029: ul.LC_TabContentBigger li:hover b {
8030: color:$button_hover;
8031: }
8032:
1.870 tempelho 8033: ul.LC_TabContentBigger li.active b {
1.911 bisitz 8034: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
8035: color:$font;
1.957 onken 8036: border: 0;
1.741 harmsja 8037: }
1.693 droeschl 8038:
1.870 tempelho 8039:
1.862 bisitz 8040: ul.LC_CourseBreadcrumbs {
8041: background: $sidebg;
1.1020 raeburn 8042: height: 2em;
1.862 bisitz 8043: padding-left: 10px;
1.1020 raeburn 8044: margin: 0;
1.862 bisitz 8045: list-style-position: inside;
8046: }
8047:
1.911 bisitz 8048: ol#LC_MenuBreadcrumbs,
1.862 bisitz 8049: ol#LC_PathBreadcrumbs {
1.911 bisitz 8050: padding-left: 10px;
8051: margin: 0;
1.933 droeschl 8052: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 8053: }
8054:
1.911 bisitz 8055: ol#LC_MenuBreadcrumbs li,
8056: ol#LC_PathBreadcrumbs li,
1.862 bisitz 8057: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 8058: display: inline;
1.933 droeschl 8059: white-space: normal;
1.693 droeschl 8060: }
8061:
1.823 bisitz 8062: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 8063: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 8064: text-decoration: none;
8065: font-size:90%;
1.693 droeschl 8066: }
1.795 www 8067:
1.969 droeschl 8068: ol#LC_MenuBreadcrumbs h1 {
8069: display: inline;
8070: font-size: 90%;
8071: line-height: 2.5em;
8072: margin: 0;
8073: padding: 0;
8074: }
8075:
1.795 www 8076: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 8077: text-decoration:none;
8078: font-size:100%;
8079: font-weight:bold;
1.693 droeschl 8080: }
1.795 www 8081:
1.840 bisitz 8082: .LC_Box {
1.911 bisitz 8083: border: solid 1px $lg_border_color;
8084: padding: 0 10px 10px 10px;
1.746 neumanie 8085: }
1.795 www 8086:
1.1020 raeburn 8087: .LC_DocsBox {
8088: border: solid 1px $lg_border_color;
8089: padding: 0 0 10px 10px;
8090: }
8091:
1.795 www 8092: .LC_AboutMe_Image {
1.911 bisitz 8093: float:left;
8094: margin-right:10px;
1.747 neumanie 8095: }
1.795 www 8096:
8097: .LC_Clear_AboutMe_Image {
1.911 bisitz 8098: clear:left;
1.747 neumanie 8099: }
1.795 www 8100:
1.721 harmsja 8101: dl.LC_ListStyleClean dt {
1.911 bisitz 8102: padding-right: 5px;
8103: display: table-header-group;
1.693 droeschl 8104: }
8105:
1.721 harmsja 8106: dl.LC_ListStyleClean dd {
1.911 bisitz 8107: display: table-row;
1.693 droeschl 8108: }
8109:
1.721 harmsja 8110: .LC_ListStyleClean,
8111: .LC_ListStyleSimple,
8112: .LC_ListStyleNormal,
1.795 www 8113: .LC_ListStyleSpecial {
1.911 bisitz 8114: /* display:block; */
8115: list-style-position: inside;
8116: list-style-type: none;
8117: overflow: hidden;
8118: padding: 0;
1.693 droeschl 8119: }
8120:
1.721 harmsja 8121: .LC_ListStyleSimple li,
8122: .LC_ListStyleSimple dd,
8123: .LC_ListStyleNormal li,
8124: .LC_ListStyleNormal dd,
8125: .LC_ListStyleSpecial li,
1.795 www 8126: .LC_ListStyleSpecial dd {
1.911 bisitz 8127: margin: 0;
8128: padding: 5px 5px 5px 10px;
8129: clear: both;
1.693 droeschl 8130: }
8131:
1.721 harmsja 8132: .LC_ListStyleClean li,
8133: .LC_ListStyleClean dd {
1.911 bisitz 8134: padding-top: 0;
8135: padding-bottom: 0;
1.693 droeschl 8136: }
8137:
1.721 harmsja 8138: .LC_ListStyleSimple dd,
1.795 www 8139: .LC_ListStyleSimple li {
1.911 bisitz 8140: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8141: }
8142:
1.721 harmsja 8143: .LC_ListStyleSpecial li,
8144: .LC_ListStyleSpecial dd {
1.911 bisitz 8145: list-style-type: none;
8146: background-color: RGB(220, 220, 220);
8147: margin-bottom: 4px;
1.693 droeschl 8148: }
8149:
1.721 harmsja 8150: table.LC_SimpleTable {
1.911 bisitz 8151: margin:5px;
8152: border:solid 1px $lg_border_color;
1.795 www 8153: }
1.693 droeschl 8154:
1.721 harmsja 8155: table.LC_SimpleTable tr {
1.911 bisitz 8156: padding: 0;
8157: border:solid 1px $lg_border_color;
1.693 droeschl 8158: }
1.795 www 8159:
8160: table.LC_SimpleTable thead {
1.911 bisitz 8161: background:rgb(220,220,220);
1.693 droeschl 8162: }
8163:
1.721 harmsja 8164: div.LC_columnSection {
1.911 bisitz 8165: display: block;
8166: clear: both;
8167: overflow: hidden;
8168: margin: 0;
1.693 droeschl 8169: }
8170:
1.721 harmsja 8171: div.LC_columnSection>* {
1.911 bisitz 8172: float: left;
8173: margin: 10px 20px 10px 0;
8174: overflow:hidden;
1.693 droeschl 8175: }
1.721 harmsja 8176:
1.795 www 8177: table em {
1.911 bisitz 8178: font-weight: bold;
8179: font-style: normal;
1.748 schulted 8180: }
1.795 www 8181:
1.779 bisitz 8182: table.LC_tableBrowseRes,
1.795 www 8183: table.LC_tableOfContent {
1.911 bisitz 8184: border:none;
8185: border-spacing: 1px;
8186: padding: 3px;
8187: background-color: #FFFFFF;
8188: font-size: 90%;
1.753 droeschl 8189: }
1.789 droeschl 8190:
1.911 bisitz 8191: table.LC_tableOfContent {
8192: border-collapse: collapse;
1.789 droeschl 8193: }
8194:
1.771 droeschl 8195: table.LC_tableBrowseRes a,
1.768 schulted 8196: table.LC_tableOfContent a {
1.911 bisitz 8197: background-color: transparent;
8198: text-decoration: none;
1.753 droeschl 8199: }
8200:
1.795 www 8201: table.LC_tableOfContent img {
1.911 bisitz 8202: border: none;
8203: height: 1.3em;
8204: vertical-align: text-bottom;
8205: margin-right: 0.3em;
1.753 droeschl 8206: }
1.757 schulted 8207:
1.795 www 8208: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8209: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8210: }
8211:
1.795 www 8212: a#LC_content_toolbar_everything {
1.911 bisitz 8213: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8214: }
8215:
1.795 www 8216: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8217: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8218: }
8219:
1.795 www 8220: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8221: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8222: }
8223:
1.795 www 8224: a#LC_content_toolbar_changefolder {
1.911 bisitz 8225: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8226: }
8227:
1.795 www 8228: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8229: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8230: }
8231:
1.1043 raeburn 8232: a#LC_content_toolbar_edittoplevel {
8233: background-image:url(/res/adm/pages/edittoplevel.gif);
8234: }
8235:
1.795 www 8236: ul#LC_toolbar li a:hover {
1.911 bisitz 8237: background-position: bottom center;
1.757 schulted 8238: }
8239:
1.795 www 8240: ul#LC_toolbar {
1.911 bisitz 8241: padding: 0;
8242: margin: 2px;
8243: list-style:none;
8244: position:relative;
8245: background-color:white;
1.1082 raeburn 8246: overflow: auto;
1.757 schulted 8247: }
8248:
1.795 www 8249: ul#LC_toolbar li {
1.911 bisitz 8250: border:1px solid white;
8251: padding: 0;
8252: margin: 0;
8253: float: left;
8254: display:inline;
8255: vertical-align:middle;
1.1082 raeburn 8256: white-space: nowrap;
1.911 bisitz 8257: }
1.757 schulted 8258:
1.783 amueller 8259:
1.795 www 8260: a.LC_toolbarItem {
1.911 bisitz 8261: display:block;
8262: padding: 0;
8263: margin: 0;
8264: height: 32px;
8265: width: 32px;
8266: color:white;
8267: border: none;
8268: background-repeat:no-repeat;
8269: background-color:transparent;
1.757 schulted 8270: }
8271:
1.915 droeschl 8272: ul.LC_funclist {
8273: margin: 0;
8274: padding: 0.5em 1em 0.5em 0;
8275: }
8276:
1.933 droeschl 8277: ul.LC_funclist > li:first-child {
8278: font-weight:bold;
8279: margin-left:0.8em;
8280: }
8281:
1.915 droeschl 8282: ul.LC_funclist + ul.LC_funclist {
8283: /*
8284: left border as a seperator if we have more than
8285: one list
8286: */
8287: border-left: 1px solid $sidebg;
8288: /*
8289: this hides the left border behind the border of the
8290: outer box if element is wrapped to the next 'line'
8291: */
8292: margin-left: -1px;
8293: }
8294:
1.843 bisitz 8295: ul.LC_funclist li {
1.915 droeschl 8296: display: inline;
1.782 bisitz 8297: white-space: nowrap;
1.915 droeschl 8298: margin: 0 0 0 25px;
8299: line-height: 150%;
1.782 bisitz 8300: }
8301:
1.974 wenzelju 8302: .LC_hidden {
8303: display: none;
8304: }
8305:
1.1030 www 8306: .LCmodal-overlay {
8307: position:fixed;
8308: top:0;
8309: right:0;
8310: bottom:0;
8311: left:0;
8312: height:100%;
8313: width:100%;
8314: margin:0;
8315: padding:0;
8316: background:#999;
8317: opacity:.75;
8318: filter: alpha(opacity=75);
8319: -moz-opacity: 0.75;
8320: z-index:101;
8321: }
8322:
8323: * html .LCmodal-overlay {
8324: position: absolute;
8325: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8326: }
8327:
8328: .LCmodal-window {
8329: position:fixed;
8330: top:50%;
8331: left:50%;
8332: margin:0;
8333: padding:0;
8334: z-index:102;
8335: }
8336:
8337: * html .LCmodal-window {
8338: position:absolute;
8339: }
8340:
8341: .LCclose-window {
8342: position:absolute;
8343: width:32px;
8344: height:32px;
8345: right:8px;
8346: top:8px;
8347: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8348: text-indent:-99999px;
8349: overflow:hidden;
8350: cursor:pointer;
8351: }
8352:
1.1335 raeburn 8353: pre.LC_wordwrap {
8354: white-space: pre-wrap;
8355: white-space: -moz-pre-wrap;
8356: white-space: -pre-wrap;
8357: white-space: -o-pre-wrap;
8358: word-wrap: break-word;
8359: }
8360:
1.1100 raeburn 8361: /*
1.1231 damieng 8362: styles used for response display
8363: */
8364: div.LC_radiofoil, div.LC_rankfoil {
8365: margin: .5em 0em .5em 0em;
8366: }
8367: table.LC_itemgroup {
8368: margin-top: 1em;
8369: }
8370:
8371: /*
1.1100 raeburn 8372: styles used by TTH when "Default set of options to pass to tth/m
8373: when converting TeX" in course settings has been set
8374:
8375: option passed: -t
8376:
8377: */
8378:
8379: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8380: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8381: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8382: td div.norm {line-height:normal;}
8383:
8384: /*
8385: option passed -y3
8386: */
8387:
8388: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8389: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8390: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8391:
1.1230 damieng 8392: /*
8393: sections with roles, for content only
8394: */
8395: section[class^="role-"] {
8396: padding-left: 10px;
8397: padding-right: 5px;
8398: margin-top: 8px;
8399: margin-bottom: 8px;
8400: border: 1px solid #2A4;
8401: border-radius: 5px;
8402: box-shadow: 0px 1px 1px #BBB;
8403: }
8404: section[class^="role-"]>h1 {
8405: position: relative;
8406: margin: 0px;
8407: padding-top: 10px;
8408: padding-left: 40px;
8409: }
8410: section[class^="role-"]>h1:before {
8411: position: absolute;
8412: left: -5px;
8413: top: 5px;
8414: }
8415: section.role-activity>h1:before {
8416: content:url('/adm/daxe/images/section_icons/activity.png');
8417: }
8418: section.role-advice>h1:before {
8419: content:url('/adm/daxe/images/section_icons/advice.png');
8420: }
8421: section.role-bibliography>h1:before {
8422: content:url('/adm/daxe/images/section_icons/bibliography.png');
8423: }
8424: section.role-citation>h1:before {
8425: content:url('/adm/daxe/images/section_icons/citation.png');
8426: }
8427: section.role-conclusion>h1:before {
8428: content:url('/adm/daxe/images/section_icons/conclusion.png');
8429: }
8430: section.role-definition>h1:before {
8431: content:url('/adm/daxe/images/section_icons/definition.png');
8432: }
8433: section.role-demonstration>h1:before {
8434: content:url('/adm/daxe/images/section_icons/demonstration.png');
8435: }
8436: section.role-example>h1:before {
8437: content:url('/adm/daxe/images/section_icons/example.png');
8438: }
8439: section.role-explanation>h1:before {
8440: content:url('/adm/daxe/images/section_icons/explanation.png');
8441: }
8442: section.role-introduction>h1:before {
8443: content:url('/adm/daxe/images/section_icons/introduction.png');
8444: }
8445: section.role-method>h1:before {
8446: content:url('/adm/daxe/images/section_icons/method.png');
8447: }
8448: section.role-more_information>h1:before {
8449: content:url('/adm/daxe/images/section_icons/more_information.png');
8450: }
8451: section.role-objectives>h1:before {
8452: content:url('/adm/daxe/images/section_icons/objectives.png');
8453: }
8454: section.role-prerequisites>h1:before {
8455: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8456: }
8457: section.role-remark>h1:before {
8458: content:url('/adm/daxe/images/section_icons/remark.png');
8459: }
8460: section.role-reminder>h1:before {
8461: content:url('/adm/daxe/images/section_icons/reminder.png');
8462: }
8463: section.role-summary>h1:before {
8464: content:url('/adm/daxe/images/section_icons/summary.png');
8465: }
8466: section.role-syntax>h1:before {
8467: content:url('/adm/daxe/images/section_icons/syntax.png');
8468: }
8469: section.role-warning>h1:before {
8470: content:url('/adm/daxe/images/section_icons/warning.png');
8471: }
8472:
1.1269 raeburn 8473: #LC_minitab_header {
8474: float:left;
8475: width:100%;
8476: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8477: font-size:93%;
8478: line-height:normal;
8479: margin: 0.5em 0 0.5em 0;
8480: }
8481: #LC_minitab_header ul {
8482: margin:0;
8483: padding:10px 10px 0;
8484: list-style:none;
8485: }
8486: #LC_minitab_header li {
8487: float:left;
8488: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8489: margin:0;
8490: padding:0 0 0 9px;
8491: }
8492: #LC_minitab_header a {
8493: display:block;
8494: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8495: padding:5px 15px 4px 6px;
8496: }
8497: #LC_minitab_header #LC_current_minitab {
8498: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8499: }
8500: #LC_minitab_header #LC_current_minitab a {
8501: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8502: padding-bottom:5px;
8503: }
8504:
8505:
1.343 albertel 8506: END
8507: }
8508:
1.306 albertel 8509: =pod
8510:
8511: =item * &headtag()
8512:
8513: Returns a uniform footer for LON-CAPA web pages.
8514:
1.307 albertel 8515: Inputs: $title - optional title for the head
8516: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8517: $args - optional arguments
1.319 albertel 8518: force_register - if is true call registerurl so the remote is
8519: informed
1.415 albertel 8520: redirect -> array ref of
8521: 1- seconds before redirect occurs
8522: 2- url to redirect to
8523: 3- whether the side effect should occur
1.315 albertel 8524: (side effect of setting
8525: $env{'internal.head.redirect'} to the url
8526: redirected too)
1.352 albertel 8527: domain -> force to color decorate a page for a specific
8528: domain
8529: function -> force usage of a specific rolish color scheme
8530: bgcolor -> override the default page bgcolor
1.460 albertel 8531: no_auto_mt_title
8532: -> prevent &mt()ing the title arg
1.464 albertel 8533:
1.306 albertel 8534: =cut
8535:
8536: sub headtag {
1.313 albertel 8537: my ($title,$head_extra,$args) = @_;
1.306 albertel 8538:
1.363 albertel 8539: my $function = $args->{'function'} || &get_users_function();
8540: my $domain = $args->{'domain'} || &determinedomain();
8541: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8542: my $httphost = $args->{'use_absolute'};
1.418 albertel 8543: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8544: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8545: #time(),
1.418 albertel 8546: $env{'environment.color.timestamp'},
1.363 albertel 8547: $function,$domain,$bgcolor);
8548:
1.369 www 8549: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8550:
1.308 albertel 8551: my $result =
8552: '<head>'.
1.1160 raeburn 8553: &font_settings($args);
1.319 albertel 8554:
1.1188 raeburn 8555: my $inhibitprint;
8556: if ($args->{'print_suppress'}) {
8557: $inhibitprint = &print_suppression();
8558: }
1.1064 raeburn 8559:
1.461 albertel 8560: if (!$args->{'frameset'}) {
8561: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8562: }
1.962 droeschl 8563: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8564: $result .= Apache::lonxml::display_title();
1.319 albertel 8565: }
1.436 albertel 8566: if (!$args->{'no_nav_bar'}
8567: && !$args->{'only_body'}
8568: && !$args->{'frameset'}) {
1.1154 raeburn 8569: $result .= &help_menu_js($httphost);
1.1032 www 8570: $result.=&modal_window();
1.1038 www 8571: $result.=&togglebox_script();
1.1034 www 8572: $result.=&wishlist_window();
1.1041 www 8573: $result.=&LCprogressbarUpdate_script();
1.1034 www 8574: } else {
8575: if ($args->{'add_modal'}) {
8576: $result.=&modal_window();
8577: }
8578: if ($args->{'add_wishlist'}) {
8579: $result.=&wishlist_window();
8580: }
1.1038 www 8581: if ($args->{'add_togglebox'}) {
8582: $result.=&togglebox_script();
8583: }
1.1041 www 8584: if ($args->{'add_progressbar'}) {
8585: $result.=&LCprogressbarUpdate_script();
8586: }
1.436 albertel 8587: }
1.314 albertel 8588: if (ref($args->{'redirect'})) {
1.414 albertel 8589: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8590: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8591: if (!$inhibit_continue) {
8592: $env{'internal.head.redirect'} = $url;
8593: }
1.313 albertel 8594: $result.=<<ADDMETA
8595: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8596: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8597: ADDMETA
1.1210 raeburn 8598: } else {
8599: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8600: my $requrl = $env{'request.uri'};
8601: if ($requrl eq '') {
8602: $requrl = $ENV{'REQUEST_URI'};
8603: $requrl =~ s/\?.+$//;
8604: }
8605: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8606: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8607: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8608: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8609: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8610: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1340 raeburn 8611: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1352 raeburn 8612: my ($offload,$offloadoth);
1.1210 raeburn 8613: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8614: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1340 raeburn 8615: $offload = 1;
1.1353 raeburn 8616: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8617: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8618: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8619: $offloadoth = 1;
8620: $dom_in_use = $env{'user.domain'};
8621: }
8622: }
1.1340 raeburn 8623: }
8624: }
8625: unless ($offload) {
8626: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8627: if ($domdefs{'offloadoth'}{$lonhost}) {
8628: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8629: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8630: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8631: $offload = 1;
1.1352 raeburn 8632: $offloadoth = 1;
1.1340 raeburn 8633: $dom_in_use = $env{'user.domain'};
8634: }
1.1210 raeburn 8635: }
1.1340 raeburn 8636: }
8637: }
8638: }
8639: if ($offload) {
8640: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
1.1352 raeburn 8641: if (($newserver eq '') && ($offloadoth)) {
8642: my @domains = &Apache::lonnet::current_machine_domains();
8643: if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
8644: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
8645: }
8646: }
1.1340 raeburn 8647: if (($newserver) && ($newserver ne $lonhost)) {
8648: my $numsec = 5;
8649: my $timeout = $numsec * 1000;
8650: my ($newurl,$locknum,%locks,$msg);
8651: if ($env{'request.role.adv'}) {
8652: ($locknum,%locks) = &Apache::lonnet::get_locks();
8653: }
8654: my $disable_submit = 0;
8655: if ($requrl =~ /$LONCAPA::assess_re/) {
8656: $disable_submit = 1;
8657: }
8658: if ($locknum) {
8659: my @lockinfo = sort(values(%locks));
1.1354 raeburn 8660: $msg = &mt('Once the following tasks are complete:')." \n".
1.1340 raeburn 8661: join(", ",sort(values(%locks)))."\n";
8662: if (&show_course()) {
8663: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
8664: } else {
8665: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
1.1210 raeburn 8666: }
1.1340 raeburn 8667: } else {
8668: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8669: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8670: }
8671: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8672: $newurl = '/adm/switchserver?otherserver='.$newserver;
8673: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8674: $newurl .= '&role='.$env{'request.role'};
8675: }
8676: if ($env{'request.symb'}) {
8677: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8678: if ($shownsymb =~ m{^/enc/}) {
8679: my $reqdmajor = 2;
8680: my $reqdminor = 11;
8681: my $reqdsubminor = 3;
8682: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8683: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8684: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8685: if (($major eq '' && $minor eq '') ||
8686: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8687: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8688: ($reqdsubminor > $subminor))))) {
8689: undef($shownsymb);
8690: }
1.1210 raeburn 8691: }
1.1340 raeburn 8692: if ($shownsymb) {
8693: &js_escape(\$shownsymb);
8694: $newurl .= '&symb='.$shownsymb;
1.1210 raeburn 8695: }
1.1340 raeburn 8696: } else {
8697: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8698: &js_escape(\$shownurl);
8699: $newurl .= '&origurl='.$shownurl;
1.1210 raeburn 8700: }
1.1340 raeburn 8701: }
8702: &js_escape(\$msg);
8703: $result.=<<OFFLOAD
1.1210 raeburn 8704: <meta http-equiv="pragma" content="no-cache" />
8705: <script type="text/javascript">
1.1215 raeburn 8706: // <![CDATA[
1.1210 raeburn 8707: function LC_Offload_Now() {
8708: var dest = "$newurl";
8709: if (dest != '') {
8710: window.location.href="$newurl";
8711: }
8712: }
1.1214 raeburn 8713: \$(document).ready(function () {
8714: window.alert('$msg');
8715: if ($disable_submit) {
1.1210 raeburn 8716: \$(".LC_hwk_submit").prop("disabled", true);
8717: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8718: }
8719: setTimeout('LC_Offload_Now()', $timeout);
8720: });
1.1215 raeburn 8721: // ]]>
1.1210 raeburn 8722: </script>
8723: OFFLOAD
8724: }
8725: }
8726: }
8727: }
8728: }
1.313 albertel 8729: }
1.306 albertel 8730: if (!defined($title)) {
8731: $title = 'The LearningOnline Network with CAPA';
8732: }
1.460 albertel 8733: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8734: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8735: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8736: if (!$args->{'frameset'}) {
8737: $result .= ' /';
8738: }
8739: $result .= '>'
1.1064 raeburn 8740: .$inhibitprint
1.414 albertel 8741: .$head_extra;
1.1242 raeburn 8742: my $clientmobile;
8743: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8744: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8745: } else {
8746: $clientmobile = $env{'browser.mobile'};
8747: }
8748: if ($clientmobile) {
1.1137 raeburn 8749: $result .= '
8750: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8751: <meta name="apple-mobile-web-app-capable" content="yes" />';
8752: }
1.1278 raeburn 8753: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8754: return $result.'</head>';
1.306 albertel 8755: }
8756:
8757: =pod
8758:
1.340 albertel 8759: =item * &font_settings()
8760:
8761: Returns neccessary <meta> to set the proper encoding
8762:
1.1160 raeburn 8763: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8764:
8765: =cut
8766:
8767: sub font_settings {
1.1160 raeburn 8768: my ($args) = @_;
1.340 albertel 8769: my $headerstring='';
1.1160 raeburn 8770: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8771: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8772: $headerstring.=
8773: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8774: if (!$args->{'frameset'}) {
8775: $headerstring.= ' /';
8776: }
8777: $headerstring .= '>'."\n";
1.340 albertel 8778: }
8779: return $headerstring;
8780: }
8781:
1.341 albertel 8782: =pod
8783:
1.1064 raeburn 8784: =item * &print_suppression()
8785:
8786: In course context returns css which causes the body to be blank when media="print",
8787: if printout generation is unavailable for the current resource.
8788:
8789: This could be because:
8790:
8791: (a) printstartdate is in the future
8792:
8793: (b) printenddate is in the past
8794:
8795: (c) there is an active exam block with "printout"
8796: functionality blocked
8797:
8798: Users with pav, pfo or evb privileges are exempt.
8799:
8800: Inputs: none
8801:
8802: =cut
8803:
8804:
8805: sub print_suppression {
8806: my $noprint;
8807: if ($env{'request.course.id'}) {
8808: my $scope = $env{'request.course.id'};
8809: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8810: (&Apache::lonnet::allowed('pfo',$scope))) {
8811: return;
8812: }
8813: if ($env{'request.course.sec'} ne '') {
8814: $scope .= "/$env{'request.course.sec'}";
8815: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8816: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8817: return;
1.1064 raeburn 8818: }
8819: }
8820: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8821: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8822: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8823: if ($blocked) {
8824: my $checkrole = "cm./$cdom/$cnum";
8825: if ($env{'request.course.sec'} ne '') {
8826: $checkrole .= "/$env{'request.course.sec'}";
8827: }
8828: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8829: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8830: $noprint = 1;
8831: }
8832: }
8833: unless ($noprint) {
8834: my $symb = &Apache::lonnet::symbread();
8835: if ($symb ne '') {
8836: my $navmap = Apache::lonnavmaps::navmap->new();
8837: if (ref($navmap)) {
8838: my $res = $navmap->getBySymb($symb);
8839: if (ref($res)) {
8840: if (!$res->resprintable()) {
8841: $noprint = 1;
8842: }
8843: }
8844: }
8845: }
8846: }
8847: if ($noprint) {
8848: return <<"ENDSTYLE";
8849: <style type="text/css" media="print">
8850: body { display:none }
8851: </style>
8852: ENDSTYLE
8853: }
8854: }
8855: return;
8856: }
8857:
8858: =pod
8859:
1.341 albertel 8860: =item * &xml_begin()
8861:
8862: Returns the needed doctype and <html>
8863:
8864: Inputs: none
8865:
8866: =cut
8867:
8868: sub xml_begin {
1.1168 raeburn 8869: my ($is_frameset) = @_;
1.341 albertel 8870: my $output='';
8871:
8872: if ($env{'browser.mathml'}) {
8873: $output='<?xml version="1.0"?>'
8874: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8875: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8876:
8877: # .'<!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">] >'
8878: .'<!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">'
8879: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8880: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8881: } elsif ($is_frameset) {
8882: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8883: '<html>'."\n";
1.341 albertel 8884: } else {
1.1168 raeburn 8885: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8886: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8887: }
8888: return $output;
8889: }
1.340 albertel 8890:
8891: =pod
8892:
1.306 albertel 8893: =item * &start_page()
8894:
8895: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8896:
1.648 raeburn 8897: Inputs:
8898:
8899: =over 4
8900:
8901: $title - optional title for the page
8902:
8903: $head_extra - optional extra HTML to incude inside the <head>
8904:
8905: $args - additional optional args supported are:
8906:
8907: =over 8
8908:
8909: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8910: arg on
1.814 bisitz 8911: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8912: add_entries -> additional attributes to add to the <body>
8913: domain -> force to color decorate a page for a
1.317 albertel 8914: specific domain
1.648 raeburn 8915: function -> force usage of a specific rolish color
1.317 albertel 8916: scheme
1.648 raeburn 8917: redirect -> see &headtag()
8918: bgcolor -> override the default page bg color
8919: js_ready -> return a string ready for being used in
1.317 albertel 8920: a javascript writeln
1.648 raeburn 8921: html_encode -> return a string ready for being used in
1.320 albertel 8922: a html attribute
1.648 raeburn 8923: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8924: $forcereg arg
1.648 raeburn 8925: frameset -> if true will start with a <frameset>
1.330 albertel 8926: rather than <body>
1.648 raeburn 8927: skip_phases -> hash ref of
1.338 albertel 8928: head -> skip the <html><head> generation
8929: body -> skip all <body> generation
1.648 raeburn 8930: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8931: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8932: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 8933: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8934: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 8935: group -> includes the current group, if page is for a
1.1274 raeburn 8936: specific group
8937: use_absolute -> for request for external resource or syllabus, this
8938: will contain https://<hostname> if server uses
8939: https (as per hosts.tab), but request is for http
8940: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8941:
1.648 raeburn 8942: =back
1.460 albertel 8943:
1.648 raeburn 8944: =back
1.562 albertel 8945:
1.306 albertel 8946: =cut
8947:
8948: sub start_page {
1.309 albertel 8949: my ($title,$head_extra,$args) = @_;
1.318 albertel 8950: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8951:
1.315 albertel 8952: $env{'internal.start_page'}++;
1.1318 raeburn 8953: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu);
1.964 droeschl 8954:
1.338 albertel 8955: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8956: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8957: }
1.1316 raeburn 8958:
8959: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 8960: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
8961: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
8962: $args->{'no_primary_menu'} = 1;
8963: }
8964: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
8965: $args->{'no_inline_menu'} = 1;
8966: }
8967: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
8968: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
8969: }
8970: } else {
8971: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8972: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
8973: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
8974: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
8975: $args->{'no_primary_menu'} = 1;
8976: }
8977: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
8978: $args->{'no_inline_menu'} = 1;
8979: }
8980: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
8981: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
8982: }
8983: }
8984: }
1.1316 raeburn 8985: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
8986: $env{'course.'.$env{'request.course.id'}.'.domain'},
8987: $env{'course.'.$env{'request.course.id'}.'.num'});
8988: }
1.338 albertel 8989:
8990: if (! exists($args->{'skip_phases'}{'body'}) ) {
8991: if ($args->{'frameset'}) {
8992: my $attr_string = &make_attr_string($args->{'force_register'},
8993: $args->{'add_entries'});
8994: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8995: } else {
8996: $result .=
8997: &bodytag($title,
8998: $args->{'function'}, $args->{'add_entries'},
8999: $args->{'only_body'}, $args->{'domain'},
9000: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 9001: $args->{'bgcolor'}, $args,
1.1318 raeburn 9002: \@advtools,$ltiscope,$ltiuri,\%ltimenu);
1.831 bisitz 9003: }
1.330 albertel 9004: }
1.338 albertel 9005:
1.315 albertel 9006: if ($args->{'js_ready'}) {
1.713 kaisler 9007: $result = &js_ready($result);
1.315 albertel 9008: }
1.320 albertel 9009: if ($args->{'html_encode'}) {
1.713 kaisler 9010: $result = &html_encode($result);
9011: }
9012:
1.813 bisitz 9013: # Preparation for new and consistent functionlist at top of screen
9014: # if ($args->{'functionlist'}) {
9015: # $result .= &build_functionlist();
9016: #}
9017:
1.964 droeschl 9018: # Don't add anything more if only_body wanted or in const space
9019: return $result if $args->{'only_body'}
9020: || $env{'request.state'} eq 'construct';
1.813 bisitz 9021:
9022: #Breadcrumbs
1.758 kaisler 9023: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
9024: &Apache::lonhtmlcommon::clear_breadcrumbs();
9025: #if any br links exists, add them to the breadcrumbs
9026: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
9027: foreach my $crumb (@{$args->{'bread_crumbs'}}){
9028: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
9029: }
9030: }
1.1096 raeburn 9031: # if @advtools array contains items add then to the breadcrumbs
9032: if (@advtools > 0) {
9033: &Apache::lonmenu::advtools_crumbs(@advtools);
9034: }
1.1272 raeburn 9035: my $menulink;
9036: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
9037: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 9038: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 9039: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
9040: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
9041: (!$env{'request.role.adv'}))) {
9042: $menulink = 0;
9043: } else {
9044: undef($menulink);
9045: }
1.758 kaisler 9046: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
9047: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 9048: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 9049: } else {
1.1272 raeburn 9050: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 9051: }
1.320 albertel 9052: }
1.315 albertel 9053: return $result;
1.306 albertel 9054: }
9055:
9056: sub end_page {
1.315 albertel 9057: my ($args) = @_;
9058: $env{'internal.end_page'}++;
1.330 albertel 9059: my $result;
1.335 albertel 9060: if ($args->{'discussion'}) {
9061: my ($target,$parser);
9062: if (ref($args->{'discussion'})) {
9063: ($target,$parser) =($args->{'discussion'}{'target'},
9064: $args->{'discussion'}{'parser'});
9065: }
9066: $result .= &Apache::lonxml::xmlend($target,$parser);
9067: }
1.330 albertel 9068: if ($args->{'frameset'}) {
9069: $result .= '</frameset>';
9070: } else {
1.635 raeburn 9071: $result .= &endbodytag($args);
1.330 albertel 9072: }
1.1080 raeburn 9073: unless ($args->{'notbody'}) {
9074: $result .= "\n</html>";
9075: }
1.330 albertel 9076:
1.315 albertel 9077: if ($args->{'js_ready'}) {
1.317 albertel 9078: $result = &js_ready($result);
1.315 albertel 9079: }
1.335 albertel 9080:
1.320 albertel 9081: if ($args->{'html_encode'}) {
9082: $result = &html_encode($result);
9083: }
1.335 albertel 9084:
1.315 albertel 9085: return $result;
9086: }
9087:
1.1034 www 9088: sub wishlist_window {
9089: return(<<'ENDWISHLIST');
1.1046 raeburn 9090: <script type="text/javascript">
1.1034 www 9091: // <![CDATA[
9092: // <!-- BEGIN LON-CAPA Internal
9093: function set_wishlistlink(title, path) {
9094: if (!title) {
9095: title = document.title;
9096: title = title.replace(/^LON-CAPA /,'');
9097: }
1.1175 raeburn 9098: title = encodeURIComponent(title);
1.1203 raeburn 9099: title = title.replace("'","\\\'");
1.1034 www 9100: if (!path) {
9101: path = location.pathname;
9102: }
1.1175 raeburn 9103: path = encodeURIComponent(path);
1.1203 raeburn 9104: path = path.replace("'","\\\'");
1.1034 www 9105: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
9106: 'wishlistNewLink','width=560,height=350,scrollbars=0');
9107: }
9108: // END LON-CAPA Internal -->
9109: // ]]>
9110: </script>
9111: ENDWISHLIST
9112: }
9113:
1.1030 www 9114: sub modal_window {
9115: return(<<'ENDMODAL');
1.1046 raeburn 9116: <script type="text/javascript">
1.1030 www 9117: // <![CDATA[
9118: // <!-- BEGIN LON-CAPA Internal
9119: var modalWindow = {
9120: parent:"body",
9121: windowId:null,
9122: content:null,
9123: width:null,
9124: height:null,
9125: close:function()
9126: {
9127: $(".LCmodal-window").remove();
9128: $(".LCmodal-overlay").remove();
9129: },
9130: open:function()
9131: {
9132: var modal = "";
9133: modal += "<div class=\"LCmodal-overlay\"></div>";
9134: 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;\">";
9135: modal += this.content;
9136: modal += "</div>";
9137:
9138: $(this.parent).append(modal);
9139:
9140: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
9141: $(".LCclose-window").click(function(){modalWindow.close();});
9142: $(".LCmodal-overlay").click(function(){modalWindow.close();});
9143: }
9144: };
1.1140 raeburn 9145: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 9146: {
1.1266 raeburn 9147: source = source.replace(/'/g,"'");
1.1030 www 9148: modalWindow.windowId = "myModal";
9149: modalWindow.width = width;
9150: modalWindow.height = height;
1.1196 raeburn 9151: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9152: modalWindow.open();
1.1208 raeburn 9153: };
1.1030 www 9154: // END LON-CAPA Internal -->
9155: // ]]>
9156: </script>
9157: ENDMODAL
9158: }
9159:
9160: sub modal_link {
1.1140 raeburn 9161: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9162: unless ($width) { $width=480; }
9163: unless ($height) { $height=400; }
1.1031 www 9164: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 9165: unless ($transparency) { $transparency='true'; }
9166:
1.1074 raeburn 9167: my $target_attr;
9168: if (defined($target)) {
9169: $target_attr = 'target="'.$target.'"';
9170: }
9171: return <<"ENDLINK";
1.1336 raeburn 9172: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 9173: ENDLINK
1.1030 www 9174: }
9175:
1.1032 www 9176: sub modal_adhoc_script {
9177: my ($funcname,$width,$height,$content)=@_;
9178: return (<<ENDADHOC);
1.1046 raeburn 9179: <script type="text/javascript">
1.1032 www 9180: // <![CDATA[
9181: var $funcname = function()
9182: {
9183: modalWindow.windowId = "myModal";
9184: modalWindow.width = $width;
9185: modalWindow.height = $height;
9186: modalWindow.content = '$content';
9187: modalWindow.open();
9188: };
9189: // ]]>
9190: </script>
9191: ENDADHOC
9192: }
9193:
1.1041 www 9194: sub modal_adhoc_inner {
9195: my ($funcname,$width,$height,$content)=@_;
9196: my $innerwidth=$width-20;
9197: $content=&js_ready(
1.1140 raeburn 9198: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
9199: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9200: $content.
1.1041 www 9201: &end_scrollbox().
1.1140 raeburn 9202: &end_page()
1.1041 www 9203: );
9204: return &modal_adhoc_script($funcname,$width,$height,$content);
9205: }
9206:
9207: sub modal_adhoc_window {
9208: my ($funcname,$width,$height,$content,$linktext)=@_;
9209: return &modal_adhoc_inner($funcname,$width,$height,$content).
9210: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9211: }
9212:
9213: sub modal_adhoc_launch {
9214: my ($funcname,$width,$height,$content)=@_;
9215: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9216: <script type="text/javascript">
9217: // <![CDATA[
9218: $funcname();
9219: // ]]>
9220: </script>
9221: ENDLAUNCH
9222: }
9223:
9224: sub modal_adhoc_close {
9225: return (<<ENDCLOSE);
9226: <script type="text/javascript">
9227: // <![CDATA[
9228: modalWindow.close();
9229: // ]]>
9230: </script>
9231: ENDCLOSE
9232: }
9233:
1.1038 www 9234: sub togglebox_script {
9235: return(<<ENDTOGGLE);
9236: <script type="text/javascript">
9237: // <![CDATA[
9238: function LCtoggleDisplay(id,hidetext,showtext) {
9239: link = document.getElementById(id + "link").childNodes[0];
9240: with (document.getElementById(id).style) {
9241: if (display == "none" ) {
9242: display = "inline";
9243: link.nodeValue = hidetext;
9244: } else {
9245: display = "none";
9246: link.nodeValue = showtext;
9247: }
9248: }
9249: }
9250: // ]]>
9251: </script>
9252: ENDTOGGLE
9253: }
9254:
1.1039 www 9255: sub start_togglebox {
9256: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9257: unless ($heading) { $heading=''; } else { $heading.=' '; }
9258: unless ($showtext) { $showtext=&mt('show'); }
9259: unless ($hidetext) { $hidetext=&mt('hide'); }
9260: unless ($headerbg) { $headerbg='#FFFFFF'; }
9261: return &start_data_table().
9262: &start_data_table_header_row().
9263: '<td bgcolor="'.$headerbg.'">'.$heading.
9264: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9265: $showtext.'\')">'.$showtext.'</a>]</td>'.
9266: &end_data_table_header_row().
9267: '<tr id="'.$id.'" style="display:none""><td>';
9268: }
9269:
9270: sub end_togglebox {
9271: return '</td></tr>'.&end_data_table();
9272: }
9273:
1.1041 www 9274: sub LCprogressbar_script {
1.1302 raeburn 9275: my ($id,$number_to_do)=@_;
9276: if ($number_to_do) {
9277: return(<<ENDPROGRESS);
1.1041 www 9278: <script type="text/javascript">
9279: // <![CDATA[
1.1045 www 9280: \$('#progressbar$id').progressbar({
1.1041 www 9281: value: 0,
9282: change: function(event, ui) {
9283: var newVal = \$(this).progressbar('option', 'value');
9284: \$('.pblabel', this).text(LCprogressTxt);
9285: }
9286: });
9287: // ]]>
9288: </script>
9289: ENDPROGRESS
1.1302 raeburn 9290: } else {
9291: return(<<ENDPROGRESS);
9292: <script type="text/javascript">
9293: // <![CDATA[
9294: \$('#progressbar$id').progressbar({
9295: value: false,
9296: create: function(event, ui) {
9297: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9298: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9299: }
9300: });
9301: // ]]>
9302: </script>
9303: ENDPROGRESS
9304: }
1.1041 www 9305: }
9306:
9307: sub LCprogressbarUpdate_script {
9308: return(<<ENDPROGRESSUPDATE);
9309: <style type="text/css">
9310: .ui-progressbar { position:relative; }
1.1302 raeburn 9311: .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 9312: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9313: </style>
9314: <script type="text/javascript">
9315: // <![CDATA[
1.1045 www 9316: var LCprogressTxt='---';
9317:
1.1302 raeburn 9318: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9319: LCprogressTxt=progresstext;
1.1302 raeburn 9320: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9321: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9322: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 9323: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9324: } else {
9325: \$('#progressbar'+id).progressbar('value',percent);
9326: }
1.1041 www 9327: }
9328: // ]]>
9329: </script>
9330: ENDPROGRESSUPDATE
9331: }
9332:
1.1042 www 9333: my $LClastpercent;
1.1045 www 9334: my $LCidcnt;
9335: my $LCcurrentid;
1.1042 www 9336:
1.1041 www 9337: sub LCprogressbar {
1.1302 raeburn 9338: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9339: $LClastpercent=0;
1.1045 www 9340: $LCidcnt++;
9341: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 9342: my ($starting,$content);
9343: if ($number_to_do) {
9344: $starting=&mt('Starting');
9345: $content=(<<ENDPROGBAR);
9346: $preamble
1.1045 www 9347: <div id="progressbar$LCcurrentid">
1.1041 www 9348: <span class="pblabel">$starting</span>
9349: </div>
9350: ENDPROGBAR
1.1302 raeburn 9351: } else {
9352: $starting=&mt('Loading...');
9353: $LClastpercent='false';
9354: $content=(<<ENDPROGBAR);
9355: $preamble
9356: <div id="progressbar$LCcurrentid">
9357: <div class="progress-label">$starting</div>
9358: </div>
9359: ENDPROGBAR
9360: }
9361: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9362: }
9363:
9364: sub LCprogressbarUpdate {
1.1302 raeburn 9365: my ($r,$val,$text,$number_to_do)=@_;
9366: if ($number_to_do) {
9367: unless ($val) {
9368: if ($LClastpercent) {
9369: $val=$LClastpercent;
9370: } else {
9371: $val=0;
9372: }
9373: }
9374: if ($val<0) { $val=0; }
9375: if ($val>100) { $val=0; }
9376: $LClastpercent=$val;
9377: unless ($text) { $text=$val.'%'; }
9378: } else {
9379: $val = 'false';
1.1042 www 9380: }
1.1041 www 9381: $text=&js_ready($text);
1.1044 www 9382: &r_print($r,<<ENDUPDATE);
1.1041 www 9383: <script type="text/javascript">
9384: // <![CDATA[
1.1302 raeburn 9385: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9386: // ]]>
9387: </script>
9388: ENDUPDATE
1.1035 www 9389: }
9390:
1.1042 www 9391: sub LCprogressbarClose {
9392: my ($r)=@_;
9393: $LClastpercent=0;
1.1044 www 9394: &r_print($r,<<ENDCLOSE);
1.1042 www 9395: <script type="text/javascript">
9396: // <![CDATA[
1.1045 www 9397: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9398: // ]]>
9399: </script>
9400: ENDCLOSE
1.1044 www 9401: }
9402:
9403: sub r_print {
9404: my ($r,$to_print)=@_;
9405: if ($r) {
9406: $r->print($to_print);
9407: $r->rflush();
9408: } else {
9409: print($to_print);
9410: }
1.1042 www 9411: }
9412:
1.320 albertel 9413: sub html_encode {
9414: my ($result) = @_;
9415:
1.322 albertel 9416: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9417:
9418: return $result;
9419: }
1.1044 www 9420:
1.317 albertel 9421: sub js_ready {
9422: my ($result) = @_;
9423:
1.323 albertel 9424: $result =~ s/[\n\r]/ /xmsg;
9425: $result =~ s/\\/\\\\/xmsg;
9426: $result =~ s/'/\\'/xmsg;
1.372 albertel 9427: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9428:
9429: return $result;
9430: }
9431:
1.315 albertel 9432: sub validate_page {
9433: if ( exists($env{'internal.start_page'})
1.316 albertel 9434: && $env{'internal.start_page'} > 1) {
9435: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9436: $env{'internal.start_page'}.' '.
1.316 albertel 9437: $ENV{'request.filename'});
1.315 albertel 9438: }
9439: if ( exists($env{'internal.end_page'})
1.316 albertel 9440: && $env{'internal.end_page'} > 1) {
9441: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9442: $env{'internal.end_page'}.' '.
1.316 albertel 9443: $env{'request.filename'});
1.315 albertel 9444: }
9445: if ( exists($env{'internal.start_page'})
9446: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9447: &Apache::lonnet::logthis('start_page called without end_page '.
9448: $env{'request.filename'});
1.315 albertel 9449: }
9450: if ( ! exists($env{'internal.start_page'})
9451: && exists($env{'internal.end_page'})) {
1.316 albertel 9452: &Apache::lonnet::logthis('end_page called without start_page'.
9453: $env{'request.filename'});
1.315 albertel 9454: }
1.306 albertel 9455: }
1.315 albertel 9456:
1.996 www 9457:
9458: sub start_scrollbox {
1.1140 raeburn 9459: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9460: unless ($outerwidth) { $outerwidth='520px'; }
9461: unless ($width) { $width='500px'; }
9462: unless ($height) { $height='200px'; }
1.1075 raeburn 9463: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9464: if ($id ne '') {
1.1140 raeburn 9465: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9466: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9467: }
1.1075 raeburn 9468: if ($bgcolor ne '') {
9469: $tdcol = "background-color: $bgcolor;";
9470: }
1.1137 raeburn 9471: my $nicescroll_js;
9472: if ($env{'browser.mobile'}) {
1.1140 raeburn 9473: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9474: }
9475: return <<"END";
9476: $nicescroll_js
9477:
9478: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9479: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9480: END
9481: }
9482:
9483: sub end_scrollbox {
9484: return '</div></td></tr></table>';
9485: }
9486:
9487: sub nicescroll_javascript {
9488: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9489: my %options;
9490: if (ref($cursor) eq 'HASH') {
9491: %options = %{$cursor};
9492: }
9493: unless ($options{'railalign'} =~ /^left|right$/) {
9494: $options{'railalign'} = 'left';
9495: }
9496: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9497: my $function = &get_users_function();
9498: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9499: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9500: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9501: }
1.1140 raeburn 9502: }
9503: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9504: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9505: $options{'cursoropacity'}='1.0';
9506: }
1.1140 raeburn 9507: } else {
9508: $options{'cursoropacity'}='1.0';
9509: }
9510: if ($options{'cursorfixedheight'} eq 'none') {
9511: delete($options{'cursorfixedheight'});
9512: } else {
9513: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9514: }
9515: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9516: delete($options{'railoffset'});
9517: }
9518: my @niceoptions;
9519: while (my($key,$value) = each(%options)) {
9520: if ($value =~ /^\{.+\}$/) {
9521: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9522: } else {
1.1140 raeburn 9523: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9524: }
1.1140 raeburn 9525: }
9526: my $nicescroll_js = '
1.1137 raeburn 9527: $(document).ready(
1.1140 raeburn 9528: function() {
9529: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9530: }
1.1137 raeburn 9531: );
9532: ';
1.1140 raeburn 9533: if ($framecheck) {
9534: $nicescroll_js .= '
9535: function expand_div(caller) {
9536: if (top === self) {
9537: document.getElementById("'.$id.'").style.width = "auto";
9538: document.getElementById("'.$id.'").style.height = "auto";
9539: } else {
9540: try {
9541: if (parent.frames) {
9542: if (parent.frames.length > 1) {
9543: var framesrc = parent.frames[1].location.href;
9544: var currsrc = framesrc.replace(/\#.*$/,"");
9545: if ((caller == "search") || (currsrc == "'.$location.'")) {
9546: document.getElementById("'.$id.'").style.width = "auto";
9547: document.getElementById("'.$id.'").style.height = "auto";
9548: }
9549: }
9550: }
9551: } catch (e) {
9552: return;
9553: }
1.1137 raeburn 9554: }
1.1140 raeburn 9555: return;
1.996 www 9556: }
1.1140 raeburn 9557: ';
9558: }
9559: if ($needjsready) {
9560: $nicescroll_js = '
9561: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9562: } else {
9563: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9564: }
9565: return $nicescroll_js;
1.996 www 9566: }
9567:
1.318 albertel 9568: sub simple_error_page {
1.1150 bisitz 9569: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 9570: my %displayargs;
1.1151 raeburn 9571: if (ref($args) eq 'HASH') {
9572: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 9573: if ($args->{'only_body'}) {
9574: $displayargs{'only_body'} = 1;
9575: }
9576: if ($args->{'no_nav_bar'}) {
9577: $displayargs{'no_nav_bar'} = 1;
9578: }
1.1151 raeburn 9579: } else {
9580: $msg = &mt($msg);
9581: }
1.1150 bisitz 9582:
1.318 albertel 9583: my $page =
1.1304 raeburn 9584: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 9585: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9586: &Apache::loncommon::end_page();
9587: if (ref($r)) {
9588: $r->print($page);
1.327 albertel 9589: return;
1.318 albertel 9590: }
9591: return $page;
9592: }
1.347 albertel 9593:
9594: {
1.610 albertel 9595: my @row_count;
1.961 onken 9596:
9597: sub start_data_table_count {
9598: unshift(@row_count, 0);
9599: return;
9600: }
9601:
9602: sub end_data_table_count {
9603: shift(@row_count);
9604: return;
9605: }
9606:
1.347 albertel 9607: sub start_data_table {
1.1018 raeburn 9608: my ($add_class,$id) = @_;
1.422 albertel 9609: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9610: my $table_id;
9611: if (defined($id)) {
9612: $table_id = ' id="'.$id.'"';
9613: }
1.961 onken 9614: &start_data_table_count();
1.1018 raeburn 9615: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9616: }
9617:
9618: sub end_data_table {
1.961 onken 9619: &end_data_table_count();
1.389 albertel 9620: return '</table>'."\n";;
1.347 albertel 9621: }
9622:
9623: sub start_data_table_row {
1.974 wenzelju 9624: my ($add_class, $id) = @_;
1.610 albertel 9625: $row_count[0]++;
9626: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9627: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9628: $id = (' id="'.$id.'"') unless ($id eq '');
9629: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9630: }
1.471 banghart 9631:
9632: sub continue_data_table_row {
1.974 wenzelju 9633: my ($add_class, $id) = @_;
1.610 albertel 9634: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9635: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9636: $id = (' id="'.$id.'"') unless ($id eq '');
9637: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9638: }
1.347 albertel 9639:
9640: sub end_data_table_row {
1.389 albertel 9641: return '</tr>'."\n";;
1.347 albertel 9642: }
1.367 www 9643:
1.421 albertel 9644: sub start_data_table_empty_row {
1.707 bisitz 9645: # $row_count[0]++;
1.421 albertel 9646: return '<tr class="LC_empty_row" >'."\n";;
9647: }
9648:
9649: sub end_data_table_empty_row {
9650: return '</tr>'."\n";;
9651: }
9652:
1.367 www 9653: sub start_data_table_header_row {
1.389 albertel 9654: return '<tr class="LC_header_row">'."\n";;
1.367 www 9655: }
9656:
9657: sub end_data_table_header_row {
1.389 albertel 9658: return '</tr>'."\n";;
1.367 www 9659: }
1.890 droeschl 9660:
9661: sub data_table_caption {
9662: my $caption = shift;
9663: return "<caption class=\"LC_caption\">$caption</caption>";
9664: }
1.347 albertel 9665: }
9666:
1.548 albertel 9667: =pod
9668:
9669: =item * &inhibit_menu_check($arg)
9670:
9671: Checks for a inhibitmenu state and generates output to preserve it
9672:
9673: Inputs: $arg - can be any of
9674: - undef - in which case the return value is a string
9675: to add into arguments list of a uri
9676: - 'input' - in which case the return value is a HTML
9677: <form> <input> field of type hidden to
9678: preserve the value
9679: - a url - in which case the return value is the url with
9680: the neccesary cgi args added to preserve the
9681: inhibitmenu state
9682: - a ref to a url - no return value, but the string is
9683: updated to include the neccessary cgi
9684: args to preserve the inhibitmenu state
9685:
9686: =cut
9687:
9688: sub inhibit_menu_check {
9689: my ($arg) = @_;
9690: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9691: if ($arg eq 'input') {
9692: if ($env{'form.inhibitmenu'}) {
9693: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9694: } else {
9695: return
9696: }
9697: }
9698: if ($env{'form.inhibitmenu'}) {
9699: if (ref($arg)) {
9700: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9701: } elsif ($arg eq '') {
9702: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9703: } else {
9704: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9705: }
9706: }
9707: if (!ref($arg)) {
9708: return $arg;
9709: }
9710: }
9711:
1.251 albertel 9712: ###############################################
1.182 matthew 9713:
9714: =pod
9715:
1.549 albertel 9716: =back
9717:
9718: =head1 User Information Routines
9719:
9720: =over 4
9721:
1.405 albertel 9722: =item * &get_users_function()
1.182 matthew 9723:
9724: Used by &bodytag to determine the current users primary role.
9725: Returns either 'student','coordinator','admin', or 'author'.
9726:
9727: =cut
9728:
9729: ###############################################
9730: sub get_users_function {
1.815 tempelho 9731: my $function = 'norole';
1.818 tempelho 9732: if ($env{'request.role'}=~/^(st)/) {
9733: $function='student';
9734: }
1.907 raeburn 9735: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9736: $function='coordinator';
9737: }
1.258 albertel 9738: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9739: $function='admin';
9740: }
1.826 bisitz 9741: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9742: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9743: $function='author';
9744: }
9745: return $function;
1.54 www 9746: }
1.99 www 9747:
9748: ###############################################
9749:
1.233 raeburn 9750: =pod
9751:
1.821 raeburn 9752: =item * &show_course()
9753:
9754: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9755: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9756:
9757: Inputs:
9758: None
9759:
9760: Outputs:
9761: Scalar: 1 if 'Course' to be used, 0 otherwise.
9762:
9763: =cut
9764:
9765: ###############################################
9766: sub show_course {
9767: my $course = !$env{'user.adv'};
9768: if (!$env{'user.adv'}) {
9769: foreach my $env (keys(%env)) {
9770: next if ($env !~ m/^user\.priv\./);
9771: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9772: $course = 0;
9773: last;
9774: }
9775: }
9776: }
9777: return $course;
9778: }
9779:
9780: ###############################################
9781:
9782: =pod
9783:
1.542 raeburn 9784: =item * &check_user_status()
1.274 raeburn 9785:
9786: Determines current status of supplied role for a
9787: specific user. Roles can be active, previous or future.
9788:
9789: Inputs:
9790: user's domain, user's username, course's domain,
1.375 raeburn 9791: course's number, optional section ID.
1.274 raeburn 9792:
9793: Outputs:
9794: role status: active, previous or future.
9795:
9796: =cut
9797:
9798: sub check_user_status {
1.412 raeburn 9799: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9800: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9801: my @uroles = keys(%userinfo);
1.274 raeburn 9802: my $srchstr;
9803: my $active_chk = 'none';
1.412 raeburn 9804: my $now = time;
1.274 raeburn 9805: if (@uroles > 0) {
1.908 raeburn 9806: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9807: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9808: } else {
1.412 raeburn 9809: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9810: }
9811: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9812: my $role_end = 0;
9813: my $role_start = 0;
9814: $active_chk = 'active';
1.412 raeburn 9815: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9816: $role_end = $1;
9817: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9818: $role_start = $1;
1.274 raeburn 9819: }
9820: }
9821: if ($role_start > 0) {
1.412 raeburn 9822: if ($now < $role_start) {
1.274 raeburn 9823: $active_chk = 'future';
9824: }
9825: }
9826: if ($role_end > 0) {
1.412 raeburn 9827: if ($now > $role_end) {
1.274 raeburn 9828: $active_chk = 'previous';
9829: }
9830: }
9831: }
9832: }
9833: return $active_chk;
9834: }
9835:
9836: ###############################################
9837:
9838: =pod
9839:
1.405 albertel 9840: =item * &get_sections()
1.233 raeburn 9841:
9842: Determines all the sections for a course including
9843: sections with students and sections containing other roles.
1.419 raeburn 9844: Incoming parameters:
9845:
9846: 1. domain
9847: 2. course number
9848: 3. reference to array containing roles for which sections should
9849: be gathered (optional).
9850: 4. reference to array containing status types for which sections
9851: should be gathered (optional).
9852:
9853: If the third argument is undefined, sections are gathered for any role.
9854: If the fourth argument is undefined, sections are gathered for any status.
9855: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9856:
1.374 raeburn 9857: Returns section hash (keys are section IDs, values are
9858: number of users in each section), subject to the
1.419 raeburn 9859: optional roles filter, optional status filter
1.233 raeburn 9860:
9861: =cut
9862:
9863: ###############################################
9864: sub get_sections {
1.419 raeburn 9865: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9866: if (!defined($cdom) || !defined($cnum)) {
9867: my $cid = $env{'request.course.id'};
9868:
9869: return if (!defined($cid));
9870:
9871: $cdom = $env{'course.'.$cid.'.domain'};
9872: $cnum = $env{'course.'.$cid.'.num'};
9873: }
9874:
9875: my %sectioncount;
1.419 raeburn 9876: my $now = time;
1.240 albertel 9877:
1.1118 raeburn 9878: my $check_students = 1;
9879: my $only_students = 0;
9880: if (ref($possible_roles) eq 'ARRAY') {
9881: if (grep(/^st$/,@{$possible_roles})) {
9882: if (@{$possible_roles} == 1) {
9883: $only_students = 1;
9884: }
9885: } else {
9886: $check_students = 0;
9887: }
9888: }
9889:
9890: if ($check_students) {
1.276 albertel 9891: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9892: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9893: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9894: my $start_index = &Apache::loncoursedata::CL_START();
9895: my $end_index = &Apache::loncoursedata::CL_END();
9896: my $status;
1.366 albertel 9897: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9898: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9899: $data->[$status_index],
9900: $data->[$start_index],
9901: $data->[$end_index]);
9902: if ($stu_status eq 'Active') {
9903: $status = 'active';
9904: } elsif ($end < $now) {
9905: $status = 'previous';
9906: } elsif ($start > $now) {
9907: $status = 'future';
9908: }
9909: if ($section ne '-1' && $section !~ /^\s*$/) {
9910: if ((!defined($possible_status)) || (($status ne '') &&
9911: (grep/^\Q$status\E$/,@{$possible_status}))) {
9912: $sectioncount{$section}++;
9913: }
1.240 albertel 9914: }
9915: }
9916: }
1.1118 raeburn 9917: if ($only_students) {
9918: return %sectioncount;
9919: }
1.240 albertel 9920: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9921: foreach my $user (sort(keys(%courseroles))) {
9922: if ($user !~ /^(\w{2})/) { next; }
9923: my ($role) = ($user =~ /^(\w{2})/);
9924: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9925: my ($section,$status);
1.240 albertel 9926: if ($role eq 'cr' &&
9927: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9928: $section=$1;
9929: }
9930: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9931: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9932: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9933: if ($end == -1 && $start == -1) {
9934: next; #deleted role
9935: }
9936: if (!defined($possible_status)) {
9937: $sectioncount{$section}++;
9938: } else {
9939: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9940: $status = 'active';
9941: } elsif ($end < $now) {
9942: $status = 'future';
9943: } elsif ($start > $now) {
9944: $status = 'previous';
9945: }
9946: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9947: $sectioncount{$section}++;
9948: }
9949: }
1.233 raeburn 9950: }
1.366 albertel 9951: return %sectioncount;
1.233 raeburn 9952: }
9953:
1.274 raeburn 9954: ###############################################
1.294 raeburn 9955:
9956: =pod
1.405 albertel 9957:
9958: =item * &get_course_users()
9959:
1.275 raeburn 9960: Retrieves usernames:domains for users in the specified course
9961: with specific role(s), and access status.
9962:
9963: Incoming parameters:
1.277 albertel 9964: 1. course domain
9965: 2. course number
9966: 3. access status: users must have - either active,
1.275 raeburn 9967: previous, future, or all.
1.277 albertel 9968: 4. reference to array of permissible roles
1.288 raeburn 9969: 5. reference to array of section restrictions (optional)
9970: 6. reference to results object (hash of hashes).
9971: 7. reference to optional userdata hash
1.609 raeburn 9972: 8. reference to optional statushash
1.630 raeburn 9973: 9. flag if privileged users (except those set to unhide in
9974: course settings) should be excluded
1.609 raeburn 9975: Keys of top level results hash are roles.
1.275 raeburn 9976: Keys of inner hashes are username:domain, with
9977: values set to access type.
1.288 raeburn 9978: Optional userdata hash returns an array with arguments in the
9979: same order as loncoursedata::get_classlist() for student data.
9980:
1.609 raeburn 9981: Optional statushash returns
9982:
1.288 raeburn 9983: Entries for end, start, section and status are blank because
9984: of the possibility of multiple values for non-student roles.
9985:
1.275 raeburn 9986: =cut
1.405 albertel 9987:
1.275 raeburn 9988: ###############################################
1.405 albertel 9989:
1.275 raeburn 9990: sub get_course_users {
1.630 raeburn 9991: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9992: my %idx = ();
1.419 raeburn 9993: my %seclists;
1.288 raeburn 9994:
9995: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9996: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9997: $idx{end} = &Apache::loncoursedata::CL_END();
9998: $idx{start} = &Apache::loncoursedata::CL_START();
9999: $idx{id} = &Apache::loncoursedata::CL_ID();
10000: $idx{section} = &Apache::loncoursedata::CL_SECTION();
10001: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
10002: $idx{status} = &Apache::loncoursedata::CL_STATUS();
10003:
1.290 albertel 10004: if (grep(/^st$/,@{$roles})) {
1.276 albertel 10005: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 10006: my $now = time;
1.277 albertel 10007: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 10008: my $match = 0;
1.412 raeburn 10009: my $secmatch = 0;
1.419 raeburn 10010: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 10011: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 10012: if ($section eq '') {
10013: $section = 'none';
10014: }
1.291 albertel 10015: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10016: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10017: $secmatch = 1;
10018: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 10019: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10020: $secmatch = 1;
10021: }
10022: } else {
1.419 raeburn 10023: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 10024: $secmatch = 1;
10025: }
1.290 albertel 10026: }
1.412 raeburn 10027: if (!$secmatch) {
10028: next;
10029: }
1.419 raeburn 10030: }
1.275 raeburn 10031: if (defined($$types{'active'})) {
1.288 raeburn 10032: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 10033: push(@{$$users{st}{$student}},'active');
1.288 raeburn 10034: $match = 1;
1.275 raeburn 10035: }
10036: }
10037: if (defined($$types{'previous'})) {
1.609 raeburn 10038: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 10039: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 10040: $match = 1;
1.275 raeburn 10041: }
10042: }
10043: if (defined($$types{'future'})) {
1.609 raeburn 10044: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 10045: push(@{$$users{st}{$student}},'future');
1.288 raeburn 10046: $match = 1;
1.275 raeburn 10047: }
10048: }
1.609 raeburn 10049: if ($match) {
10050: push(@{$seclists{$student}},$section);
10051: if (ref($userdata) eq 'HASH') {
10052: $$userdata{$student} = $$classlist{$student};
10053: }
10054: if (ref($statushash) eq 'HASH') {
10055: $statushash->{$student}{'st'}{$section} = $status;
10056: }
1.288 raeburn 10057: }
1.275 raeburn 10058: }
10059: }
1.412 raeburn 10060: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 10061: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10062: my $now = time;
1.609 raeburn 10063: my %displaystatus = ( previous => 'Expired',
10064: active => 'Active',
10065: future => 'Future',
10066: );
1.1121 raeburn 10067: my (%nothide,@possdoms);
1.630 raeburn 10068: if ($hidepriv) {
10069: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
10070: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
10071: if ($user !~ /:/) {
10072: $nothide{join(':',split(/[\@]/,$user))}=1;
10073: } else {
10074: $nothide{$user} = 1;
10075: }
10076: }
1.1121 raeburn 10077: my @possdoms = ($cdom);
10078: if ($coursehash{'checkforpriv'}) {
10079: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
10080: }
1.630 raeburn 10081: }
1.439 raeburn 10082: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 10083: my $match = 0;
1.412 raeburn 10084: my $secmatch = 0;
1.439 raeburn 10085: my $status;
1.412 raeburn 10086: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 10087: $user =~ s/:$//;
1.439 raeburn 10088: my ($end,$start) = split(/:/,$coursepersonnel{$person});
10089: if ($end == -1 || $start == -1) {
10090: next;
10091: }
10092: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
10093: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 10094: my ($uname,$udom) = split(/:/,$user);
10095: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10096: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10097: $secmatch = 1;
10098: } elsif ($usec eq '') {
1.420 albertel 10099: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10100: $secmatch = 1;
10101: }
10102: } else {
10103: if (grep(/^\Q$usec\E$/,@{$sections})) {
10104: $secmatch = 1;
10105: }
10106: }
10107: if (!$secmatch) {
10108: next;
10109: }
1.288 raeburn 10110: }
1.419 raeburn 10111: if ($usec eq '') {
10112: $usec = 'none';
10113: }
1.275 raeburn 10114: if ($uname ne '' && $udom ne '') {
1.630 raeburn 10115: if ($hidepriv) {
1.1121 raeburn 10116: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 10117: (!$nothide{$uname.':'.$udom})) {
10118: next;
10119: }
10120: }
1.503 raeburn 10121: if ($end > 0 && $end < $now) {
1.439 raeburn 10122: $status = 'previous';
10123: } elsif ($start > $now) {
10124: $status = 'future';
10125: } else {
10126: $status = 'active';
10127: }
1.277 albertel 10128: foreach my $type (keys(%{$types})) {
1.275 raeburn 10129: if ($status eq $type) {
1.420 albertel 10130: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 10131: push(@{$$users{$role}{$user}},$type);
10132: }
1.288 raeburn 10133: $match = 1;
10134: }
10135: }
1.419 raeburn 10136: if (($match) && (ref($userdata) eq 'HASH')) {
10137: if (!exists($$userdata{$uname.':'.$udom})) {
10138: &get_user_info($udom,$uname,\%idx,$userdata);
10139: }
1.420 albertel 10140: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 10141: push(@{$seclists{$uname.':'.$udom}},$usec);
10142: }
1.609 raeburn 10143: if (ref($statushash) eq 'HASH') {
10144: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
10145: }
1.275 raeburn 10146: }
10147: }
10148: }
10149: }
1.290 albertel 10150: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10151: if ((defined($cdom)) && (defined($cnum))) {
10152: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10153: if ( defined($csettings{'internal.courseowner'}) ) {
10154: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10155: next if ($owner eq '');
10156: my ($ownername,$ownerdom);
10157: if ($owner =~ /^([^:]+):([^:]+)$/) {
10158: $ownername = $1;
10159: $ownerdom = $2;
10160: } else {
10161: $ownername = $owner;
10162: $ownerdom = $cdom;
10163: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10164: }
10165: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10166: if (defined($userdata) &&
1.609 raeburn 10167: !exists($$userdata{$owner})) {
10168: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10169: if (!grep(/^none$/,@{$seclists{$owner}})) {
10170: push(@{$seclists{$owner}},'none');
10171: }
10172: if (ref($statushash) eq 'HASH') {
10173: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10174: }
1.290 albertel 10175: }
1.279 raeburn 10176: }
10177: }
10178: }
1.419 raeburn 10179: foreach my $user (keys(%seclists)) {
10180: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10181: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10182: }
1.275 raeburn 10183: }
10184: return;
10185: }
10186:
1.288 raeburn 10187: sub get_user_info {
10188: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10189: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10190: &plainname($uname,$udom,'lastname');
1.291 albertel 10191: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10192: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10193: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10194: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10195: return;
10196: }
1.275 raeburn 10197:
1.472 raeburn 10198: ###############################################
10199:
10200: =pod
10201:
10202: =item * &get_user_quota()
10203:
1.1134 raeburn 10204: Retrieves quota assigned for storage of user files.
10205: Default is to report quota for portfolio files.
1.472 raeburn 10206:
10207: Incoming parameters:
10208: 1. user's username
10209: 2. user's domain
1.1134 raeburn 10210: 3. quota name - portfolio, author, or course
1.1136 raeburn 10211: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 10212: 4. crstype - official, unofficial, textbook, placement or community,
10213: if quota name is course
1.472 raeburn 10214:
10215: Returns:
1.1163 raeburn 10216: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10217: 2. (Optional) Type of setting: custom or default
10218: (individually assigned or default for user's
10219: institutional status).
10220: 3. (Optional) - User's institutional status (e.g., faculty, staff
10221: or student - types as defined in localenroll::inst_usertypes
10222: for user's domain, which determines default quota for user.
10223: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10224:
10225: If a value has been stored in the user's environment,
1.536 raeburn 10226: it will return that, otherwise it returns the maximal default
1.1134 raeburn 10227: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10228:
10229: =cut
10230:
10231: ###############################################
10232:
10233:
10234: sub get_user_quota {
1.1136 raeburn 10235: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10236: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10237: if (!defined($udom)) {
10238: $udom = $env{'user.domain'};
10239: }
10240: if (!defined($uname)) {
10241: $uname = $env{'user.name'};
10242: }
10243: if (($udom eq '' || $uname eq '') ||
10244: ($udom eq 'public') && ($uname eq 'public')) {
10245: $quota = 0;
1.536 raeburn 10246: $quotatype = 'default';
10247: $defquota = 0;
1.472 raeburn 10248: } else {
1.536 raeburn 10249: my $inststatus;
1.1134 raeburn 10250: if ($quotaname eq 'course') {
10251: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10252: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10253: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10254: } else {
10255: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10256: $quota = $cenv{'internal.uploadquota'};
10257: }
1.536 raeburn 10258: } else {
1.1134 raeburn 10259: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10260: if ($quotaname eq 'author') {
10261: $quota = $env{'environment.authorquota'};
10262: } else {
10263: $quota = $env{'environment.portfolioquota'};
10264: }
10265: $inststatus = $env{'environment.inststatus'};
10266: } else {
10267: my %userenv =
10268: &Apache::lonnet::get('environment',['portfolioquota',
10269: 'authorquota','inststatus'],$udom,$uname);
10270: my ($tmp) = keys(%userenv);
10271: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10272: if ($quotaname eq 'author') {
10273: $quota = $userenv{'authorquota'};
10274: } else {
10275: $quota = $userenv{'portfolioquota'};
10276: }
10277: $inststatus = $userenv{'inststatus'};
10278: } else {
10279: undef(%userenv);
10280: }
10281: }
10282: }
10283: if ($quota eq '' || wantarray) {
10284: if ($quotaname eq 'course') {
10285: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 10286: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 10287: ($crstype eq 'community') || ($crstype eq 'textbook') ||
10288: ($crstype eq 'placement')) {
1.1136 raeburn 10289: $defquota = $domdefs{$crstype.'quota'};
10290: }
10291: if ($defquota eq '') {
10292: $defquota = 500;
10293: }
1.1134 raeburn 10294: } else {
10295: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10296: }
10297: if ($quota eq '') {
10298: $quota = $defquota;
10299: $quotatype = 'default';
10300: } else {
10301: $quotatype = 'custom';
10302: }
1.472 raeburn 10303: }
10304: }
1.536 raeburn 10305: if (wantarray) {
10306: return ($quota,$quotatype,$settingstatus,$defquota);
10307: } else {
10308: return $quota;
10309: }
1.472 raeburn 10310: }
10311:
10312: ###############################################
10313:
10314: =pod
10315:
10316: =item * &default_quota()
10317:
1.536 raeburn 10318: Retrieves default quota assigned for storage of user portfolio files,
10319: given an (optional) user's institutional status.
1.472 raeburn 10320:
10321: Incoming parameters:
1.1142 raeburn 10322:
1.472 raeburn 10323: 1. domain
1.536 raeburn 10324: 2. (Optional) institutional status(es). This is a : separated list of
10325: status types (e.g., faculty, staff, student etc.)
10326: which apply to the user for whom the default is being retrieved.
10327: If the institutional status string in undefined, the domain
1.1134 raeburn 10328: default quota will be returned.
10329: 3. quota name - portfolio, author, or course
10330: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10331:
10332: Returns:
1.1142 raeburn 10333:
1.1163 raeburn 10334: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10335: 2. (Optional) institutional type which determined the value of the
10336: default quota.
1.472 raeburn 10337:
10338: If a value has been stored in the domain's configuration db,
10339: it will return that, otherwise it returns 20 (for backwards
10340: compatibility with domains which have not set up a configuration
1.1163 raeburn 10341: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10342:
1.536 raeburn 10343: If the user's status includes multiple types (e.g., staff and student),
10344: the largest default quota which applies to the user determines the
10345: default quota returned.
10346:
1.472 raeburn 10347: =cut
10348:
10349: ###############################################
10350:
10351:
10352: sub default_quota {
1.1134 raeburn 10353: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10354: my ($defquota,$settingstatus);
10355: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10356: ['quotas'],$udom);
1.1134 raeburn 10357: my $key = 'defaultquota';
10358: if ($quotaname eq 'author') {
10359: $key = 'authorquota';
10360: }
1.622 raeburn 10361: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10362: if ($inststatus ne '') {
1.765 raeburn 10363: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10364: foreach my $item (@statuses) {
1.1134 raeburn 10365: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10366: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10367: if ($defquota eq '') {
1.1134 raeburn 10368: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10369: $settingstatus = $item;
1.1134 raeburn 10370: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10371: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10372: $settingstatus = $item;
10373: }
10374: }
1.1134 raeburn 10375: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10376: if ($quotahash{'quotas'}{$item} ne '') {
10377: if ($defquota eq '') {
10378: $defquota = $quotahash{'quotas'}{$item};
10379: $settingstatus = $item;
10380: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10381: $defquota = $quotahash{'quotas'}{$item};
10382: $settingstatus = $item;
10383: }
1.536 raeburn 10384: }
10385: }
10386: }
10387: }
10388: if ($defquota eq '') {
1.1134 raeburn 10389: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10390: $defquota = $quotahash{'quotas'}{$key}{'default'};
10391: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10392: $defquota = $quotahash{'quotas'}{'default'};
10393: }
1.536 raeburn 10394: $settingstatus = 'default';
1.1139 raeburn 10395: if ($defquota eq '') {
10396: if ($quotaname eq 'author') {
10397: $defquota = 500;
10398: }
10399: }
1.536 raeburn 10400: }
10401: } else {
10402: $settingstatus = 'default';
1.1134 raeburn 10403: if ($quotaname eq 'author') {
10404: $defquota = 500;
10405: } else {
10406: $defquota = 20;
10407: }
1.536 raeburn 10408: }
10409: if (wantarray) {
10410: return ($defquota,$settingstatus);
1.472 raeburn 10411: } else {
1.536 raeburn 10412: return $defquota;
1.472 raeburn 10413: }
10414: }
10415:
1.1135 raeburn 10416: ###############################################
10417:
10418: =pod
10419:
1.1136 raeburn 10420: =item * &excess_filesize_warning()
1.1135 raeburn 10421:
10422: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 10423: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 10424: space to be exceeded.
1.1136 raeburn 10425:
10426: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 10427: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 10428:
1.1165 raeburn 10429: Inputs: 7
1.1136 raeburn 10430: 1. username or coursenum
1.1135 raeburn 10431: 2. domain
1.1136 raeburn 10432: 3. context ('author' or 'course')
1.1135 raeburn 10433: 4. filename of file for which action is being requested
10434: 5. filesize (kB) of file
10435: 6. action being taken: copy or upload.
1.1237 raeburn 10436: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 10437:
10438: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 10439: otherwise return null.
10440:
10441: =back
1.1135 raeburn 10442:
10443: =cut
10444:
1.1136 raeburn 10445: sub excess_filesize_warning {
1.1165 raeburn 10446: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 10447: my $current_disk_usage = 0;
1.1165 raeburn 10448: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 10449: if ($context eq 'author') {
10450: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10451: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10452: } else {
10453: foreach my $subdir ('docs','supplemental') {
10454: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10455: }
10456: }
1.1135 raeburn 10457: $disk_quota = int($disk_quota * 1000);
10458: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 10459: return '<p class="LC_warning">'.
1.1135 raeburn 10460: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 10461: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10462: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 10463: $disk_quota,$current_disk_usage).
10464: '</p>';
10465: }
10466: return;
10467: }
10468:
10469: ###############################################
10470:
10471:
1.1136 raeburn 10472:
10473:
1.384 raeburn 10474: sub get_secgrprole_info {
10475: my ($cdom,$cnum,$needroles,$type) = @_;
10476: my %sections_count = &get_sections($cdom,$cnum);
10477: my @sections = (sort {$a <=> $b} keys(%sections_count));
10478: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10479: my @groups = sort(keys(%curr_groups));
10480: my $allroles = [];
10481: my $rolehash;
10482: my $accesshash = {
10483: active => 'Currently has access',
10484: future => 'Will have future access',
10485: previous => 'Previously had access',
10486: };
10487: if ($needroles) {
10488: $rolehash = {'all' => 'all'};
1.385 albertel 10489: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10490: if (&Apache::lonnet::error(%user_roles)) {
10491: undef(%user_roles);
10492: }
10493: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10494: my ($role)=split(/\:/,$item,2);
10495: if ($role eq 'cr') { next; }
10496: if ($role =~ /^cr/) {
10497: $$rolehash{$role} = (split('/',$role))[3];
10498: } else {
10499: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10500: }
10501: }
10502: foreach my $key (sort(keys(%{$rolehash}))) {
10503: push(@{$allroles},$key);
10504: }
10505: push (@{$allroles},'st');
10506: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10507: }
10508: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10509: }
10510:
1.555 raeburn 10511: sub user_picker {
1.1279 raeburn 10512: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10513: my $currdom = $dom;
1.1253 raeburn 10514: my @alldoms = &Apache::lonnet::all_domains();
10515: if (@alldoms == 1) {
10516: my %domsrch = &Apache::lonnet::get_dom('configuration',
10517: ['directorysrch'],$alldoms[0]);
10518: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10519: my $showdom = $domdesc;
10520: if ($showdom eq '') {
10521: $showdom = $dom;
10522: }
10523: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10524: if ((!$domsrch{'directorysrch'}{'available'}) &&
10525: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10526: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10527: }
10528: }
10529: }
1.555 raeburn 10530: my %curr_selected = (
10531: srchin => 'dom',
1.580 raeburn 10532: srchby => 'lastname',
1.555 raeburn 10533: );
10534: my $srchterm;
1.625 raeburn 10535: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10536: if ($srch->{'srchby'} ne '') {
10537: $curr_selected{'srchby'} = $srch->{'srchby'};
10538: }
10539: if ($srch->{'srchin'} ne '') {
10540: $curr_selected{'srchin'} = $srch->{'srchin'};
10541: }
10542: if ($srch->{'srchtype'} ne '') {
10543: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10544: }
10545: if ($srch->{'srchdomain'} ne '') {
10546: $currdom = $srch->{'srchdomain'};
10547: }
10548: $srchterm = $srch->{'srchterm'};
10549: }
1.1222 damieng 10550: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10551: 'usr' => 'Search criteria',
1.563 raeburn 10552: 'doma' => 'Domain/institution to search',
1.558 albertel 10553: 'uname' => 'username',
10554: 'lastname' => 'last name',
1.555 raeburn 10555: 'lastfirst' => 'last name, first name',
1.558 albertel 10556: 'crs' => 'in this course',
1.576 raeburn 10557: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10558: 'alc' => 'all LON-CAPA',
1.573 raeburn 10559: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10560: 'exact' => 'is',
10561: 'contains' => 'contains',
1.569 raeburn 10562: 'begins' => 'begins with',
1.1222 damieng 10563: );
10564: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10565: 'youm' => "You must include some text to search for.",
10566: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10567: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10568: 'yomc' => "You must choose a domain when using an institutional directory search.",
10569: 'ymcd' => "You must choose a domain when using a domain search.",
10570: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10571: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10572: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10573: );
1.1222 damieng 10574: &html_escape(\%html_lt);
10575: &js_escape(\%js_lt);
1.1255 raeburn 10576: my $domform;
1.1277 raeburn 10577: my $allow_blank = 1;
1.1255 raeburn 10578: if ($fixeddom) {
1.1277 raeburn 10579: $allow_blank = 0;
10580: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 10581: } else {
1.1287 raeburn 10582: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 10583: my ($trusted,$untrusted);
1.1287 raeburn 10584: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 10585: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 10586: } elsif ($context eq 'author') {
1.1288 raeburn 10587: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 10588: } elsif ($context eq 'domain') {
1.1288 raeburn 10589: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 10590: }
1.1288 raeburn 10591: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 10592: }
1.563 raeburn 10593: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10594:
10595: my @srchins = ('crs','dom','alc','instd');
10596:
10597: foreach my $option (@srchins) {
10598: # FIXME 'alc' option unavailable until
10599: # loncreateuser::print_user_query_page()
10600: # has been completed.
10601: next if ($option eq 'alc');
1.880 raeburn 10602: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10603: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 10604: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10605: if ($curr_selected{'srchin'} eq $option) {
10606: $srchinsel .= '
1.1222 damieng 10607: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10608: } else {
10609: $srchinsel .= '
1.1222 damieng 10610: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10611: }
1.555 raeburn 10612: }
1.563 raeburn 10613: $srchinsel .= "\n </select>\n";
1.555 raeburn 10614:
10615: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10616: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10617: if ($curr_selected{'srchby'} eq $option) {
10618: $srchbysel .= '
1.1222 damieng 10619: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10620: } else {
10621: $srchbysel .= '
1.1222 damieng 10622: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10623: }
10624: }
10625: $srchbysel .= "\n </select>\n";
10626:
10627: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10628: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10629: if ($curr_selected{'srchtype'} eq $option) {
10630: $srchtypesel .= '
1.1222 damieng 10631: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10632: } else {
10633: $srchtypesel .= '
1.1222 damieng 10634: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10635: }
10636: }
10637: $srchtypesel .= "\n </select>\n";
10638:
1.558 albertel 10639: my ($newuserscript,$new_user_create);
1.994 raeburn 10640: my $context_dom = $env{'request.role.domain'};
10641: if ($context eq 'requestcrs') {
10642: if ($env{'form.coursedom'} ne '') {
10643: $context_dom = $env{'form.coursedom'};
10644: }
10645: }
1.556 raeburn 10646: if ($forcenewuser) {
1.576 raeburn 10647: if (ref($srch) eq 'HASH') {
1.994 raeburn 10648: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10649: if ($cancreate) {
10650: $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>';
10651: } else {
1.799 bisitz 10652: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10653: my %usertypetext = (
10654: official => 'institutional',
10655: unofficial => 'non-institutional',
10656: );
1.799 bisitz 10657: $new_user_create = '<p class="LC_warning">'
10658: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10659: .' '
10660: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10661: ,'<a href="'.$helplink.'">','</a>')
10662: .'</p><br />';
1.627 raeburn 10663: }
1.576 raeburn 10664: }
10665: }
10666:
1.556 raeburn 10667: $newuserscript = <<"ENDSCRIPT";
10668:
1.570 raeburn 10669: function setSearch(createnew,callingForm) {
1.556 raeburn 10670: if (createnew == 1) {
1.570 raeburn 10671: for (var i=0; i<callingForm.srchby.length; i++) {
10672: if (callingForm.srchby.options[i].value == 'uname') {
10673: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10674: }
10675: }
1.570 raeburn 10676: for (var i=0; i<callingForm.srchin.length; i++) {
10677: if ( callingForm.srchin.options[i].value == 'dom') {
10678: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10679: }
10680: }
1.570 raeburn 10681: for (var i=0; i<callingForm.srchtype.length; i++) {
10682: if (callingForm.srchtype.options[i].value == 'exact') {
10683: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10684: }
10685: }
1.570 raeburn 10686: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10687: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10688: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10689: }
10690: }
10691: }
10692: }
10693: ENDSCRIPT
1.558 albertel 10694:
1.556 raeburn 10695: }
10696:
1.555 raeburn 10697: my $output = <<"END_BLOCK";
1.556 raeburn 10698: <script type="text/javascript">
1.824 bisitz 10699: // <![CDATA[
1.570 raeburn 10700: function validateEntry(callingForm) {
1.558 albertel 10701:
1.556 raeburn 10702: var checkok = 1;
1.558 albertel 10703: var srchin;
1.570 raeburn 10704: for (var i=0; i<callingForm.srchin.length; i++) {
10705: if ( callingForm.srchin[i].checked ) {
10706: srchin = callingForm.srchin[i].value;
1.558 albertel 10707: }
10708: }
10709:
1.570 raeburn 10710: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10711: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10712: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10713: var srchterm = callingForm.srchterm.value;
10714: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10715: var msg = "";
10716:
10717: if (srchterm == "") {
10718: checkok = 0;
1.1222 damieng 10719: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10720: }
10721:
1.569 raeburn 10722: if (srchtype== 'begins') {
10723: if (srchterm.length < 2) {
10724: checkok = 0;
1.1222 damieng 10725: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10726: }
10727: }
10728:
1.556 raeburn 10729: if (srchtype== 'contains') {
10730: if (srchterm.length < 3) {
10731: checkok = 0;
1.1222 damieng 10732: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10733: }
10734: }
10735: if (srchin == 'instd') {
10736: if (srchdomain == '') {
10737: checkok = 0;
1.1222 damieng 10738: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10739: }
10740: }
10741: if (srchin == 'dom') {
10742: if (srchdomain == '') {
10743: checkok = 0;
1.1222 damieng 10744: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10745: }
10746: }
10747: if (srchby == 'lastfirst') {
10748: if (srchterm.indexOf(",") == -1) {
10749: checkok = 0;
1.1222 damieng 10750: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10751: }
10752: if (srchterm.indexOf(",") == srchterm.length -1) {
10753: checkok = 0;
1.1222 damieng 10754: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10755: }
10756: }
10757: if (checkok == 0) {
1.1222 damieng 10758: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10759: return;
10760: }
10761: if (checkok == 1) {
1.570 raeburn 10762: callingForm.submit();
1.556 raeburn 10763: }
10764: }
10765:
10766: $newuserscript
10767:
1.824 bisitz 10768: // ]]>
1.556 raeburn 10769: </script>
1.558 albertel 10770:
10771: $new_user_create
10772:
1.555 raeburn 10773: END_BLOCK
1.558 albertel 10774:
1.876 raeburn 10775: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10776: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10777: $domform.
10778: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10779: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10780: $srchbysel.
10781: $srchtypesel.
10782: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10783: $srchinsel.
10784: &Apache::lonhtmlcommon::row_closure(1).
10785: &Apache::lonhtmlcommon::end_pick_box().
10786: '<br />';
1.1253 raeburn 10787: return ($output,1);
1.555 raeburn 10788: }
10789:
1.612 raeburn 10790: sub user_rule_check {
1.615 raeburn 10791: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10792: my ($response,%inst_response);
1.612 raeburn 10793: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10794: if (keys(%{$usershash}) > 1) {
10795: my (%by_username,%by_id,%userdoms);
10796: my $checkid;
10797: if (ref($checks) eq 'HASH') {
10798: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10799: $checkid = 1;
10800: }
10801: }
10802: foreach my $user (keys(%{$usershash})) {
10803: my ($uname,$udom) = split(/:/,$user);
10804: if ($checkid) {
10805: if (ref($usershash->{$user}) eq 'HASH') {
10806: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10807: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10808: $userdoms{$udom} = 1;
1.1227 raeburn 10809: if (ref($inst_results) eq 'HASH') {
10810: $inst_results->{$uname.':'.$udom} = {};
10811: }
1.1226 raeburn 10812: }
10813: }
10814: } else {
10815: $by_username{$udom}{$uname} = 1;
10816: $userdoms{$udom} = 1;
1.1227 raeburn 10817: if (ref($inst_results) eq 'HASH') {
10818: $inst_results->{$uname.':'.$udom} = {};
10819: }
1.1226 raeburn 10820: }
10821: }
10822: foreach my $udom (keys(%userdoms)) {
10823: if (!$got_rules->{$udom}) {
10824: my %domconfig = &Apache::lonnet::get_dom('configuration',
10825: ['usercreation'],$udom);
10826: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10827: foreach my $item ('username','id') {
10828: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10829: $$curr_rules{$udom}{$item} =
10830: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10831: }
10832: }
10833: }
10834: $got_rules->{$udom} = 1;
10835: }
1.612 raeburn 10836: }
1.1226 raeburn 10837: if ($checkid) {
10838: foreach my $udom (keys(%by_id)) {
10839: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10840: if ($outcome eq 'ok') {
1.1227 raeburn 10841: foreach my $id (keys(%{$by_id{$udom}})) {
10842: my $uname = $by_id{$udom}{$id};
10843: $inst_response{$uname.':'.$udom} = $outcome;
10844: }
1.1226 raeburn 10845: if (ref($results) eq 'HASH') {
10846: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10847: if (exists($inst_response{$uname.':'.$udom})) {
10848: $inst_response{$uname.':'.$udom} = $outcome;
10849: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10850: }
1.1226 raeburn 10851: }
10852: }
10853: }
1.612 raeburn 10854: }
1.615 raeburn 10855: } else {
1.1226 raeburn 10856: foreach my $udom (keys(%by_username)) {
10857: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10858: if ($outcome eq 'ok') {
1.1227 raeburn 10859: foreach my $uname (keys(%{$by_username{$udom}})) {
10860: $inst_response{$uname.':'.$udom} = $outcome;
10861: }
1.1226 raeburn 10862: if (ref($results) eq 'HASH') {
10863: foreach my $uname (keys(%{$results})) {
10864: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10865: }
10866: }
10867: }
10868: }
1.612 raeburn 10869: }
1.1226 raeburn 10870: } elsif (keys(%{$usershash}) == 1) {
10871: my $user = (keys(%{$usershash}))[0];
10872: my ($uname,$udom) = split(/:/,$user);
10873: if (($udom ne '') && ($uname ne '')) {
10874: if (ref($usershash->{$user}) eq 'HASH') {
10875: if (ref($checks) eq 'HASH') {
10876: if (defined($checks->{'username'})) {
10877: ($inst_response{$user},%{$inst_results->{$user}}) =
10878: &Apache::lonnet::get_instuser($udom,$uname);
10879: } elsif (defined($checks->{'id'})) {
10880: if ($usershash->{$user}->{'id'} ne '') {
10881: ($inst_response{$user},%{$inst_results->{$user}}) =
10882: &Apache::lonnet::get_instuser($udom,undef,
10883: $usershash->{$user}->{'id'});
10884: } else {
10885: ($inst_response{$user},%{$inst_results->{$user}}) =
10886: &Apache::lonnet::get_instuser($udom,$uname);
10887: }
1.585 raeburn 10888: }
1.1226 raeburn 10889: } else {
10890: ($inst_response{$user},%{$inst_results->{$user}}) =
10891: &Apache::lonnet::get_instuser($udom,$uname);
10892: return;
10893: }
10894: if (!$got_rules->{$udom}) {
10895: my %domconfig = &Apache::lonnet::get_dom('configuration',
10896: ['usercreation'],$udom);
10897: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10898: foreach my $item ('username','id') {
10899: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10900: $$curr_rules{$udom}{$item} =
10901: $domconfig{'usercreation'}{$item.'_rule'};
10902: }
10903: }
10904: }
10905: $got_rules->{$udom} = 1;
1.585 raeburn 10906: }
10907: }
1.1226 raeburn 10908: } else {
10909: return;
10910: }
10911: } else {
10912: return;
10913: }
10914: foreach my $user (keys(%{$usershash})) {
10915: my ($uname,$udom) = split(/:/,$user);
10916: next if (($udom eq '') || ($uname eq ''));
10917: my $id;
1.1227 raeburn 10918: if (ref($inst_results) eq 'HASH') {
10919: if (ref($inst_results->{$user}) eq 'HASH') {
10920: $id = $inst_results->{$user}->{'id'};
10921: }
10922: }
10923: if ($id eq '') {
10924: if (ref($usershash->{$user})) {
10925: $id = $usershash->{$user}->{'id'};
10926: }
1.585 raeburn 10927: }
1.612 raeburn 10928: foreach my $item (keys(%{$checks})) {
10929: if (ref($$curr_rules{$udom}) eq 'HASH') {
10930: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10931: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10932: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10933: $$curr_rules{$udom}{$item});
1.612 raeburn 10934: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10935: if ($rule_check{$rule}) {
10936: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10937: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10938: if (ref($inst_results) eq 'HASH') {
10939: if (ref($inst_results->{$user}) eq 'HASH') {
10940: if (keys(%{$inst_results->{$user}}) == 0) {
10941: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10942: } elsif ($item eq 'id') {
10943: if ($inst_results->{$user}->{'id'} eq '') {
10944: $$alerts{$item}{$udom}{$uname} = 1;
10945: }
1.615 raeburn 10946: }
1.612 raeburn 10947: }
10948: }
1.615 raeburn 10949: }
10950: last;
1.585 raeburn 10951: }
10952: }
10953: }
10954: }
10955: }
10956: }
10957: }
10958: }
1.612 raeburn 10959: return;
10960: }
10961:
10962: sub user_rule_formats {
10963: my ($domain,$domdesc,$curr_rules,$check) = @_;
10964: my %text = (
10965: 'username' => 'Usernames',
10966: 'id' => 'IDs',
10967: );
10968: my $output;
10969: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10970: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10971: if (@{$ruleorder} > 0) {
1.1102 raeburn 10972: $output = '<br />'.
10973: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10974: '<span class="LC_cusr_emph">','</span>',$domdesc).
10975: ' <ul>';
1.612 raeburn 10976: foreach my $rule (@{$ruleorder}) {
10977: if (ref($curr_rules) eq 'ARRAY') {
10978: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10979: if (ref($rules->{$rule}) eq 'HASH') {
10980: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10981: $rules->{$rule}{'desc'}.'</li>';
10982: }
10983: }
10984: }
10985: }
10986: $output .= '</ul>';
10987: }
10988: }
10989: return $output;
10990: }
10991:
10992: sub instrule_disallow_msg {
1.615 raeburn 10993: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10994: my $response;
10995: my %text = (
10996: item => 'username',
10997: items => 'usernames',
10998: match => 'matches',
10999: do => 'does',
11000: action => 'a username',
11001: one => 'one',
11002: );
11003: if ($count > 1) {
11004: $text{'item'} = 'usernames';
11005: $text{'match'} ='match';
11006: $text{'do'} = 'do';
11007: $text{'action'} = 'usernames',
11008: $text{'one'} = 'ones';
11009: }
11010: if ($checkitem eq 'id') {
11011: $text{'items'} = 'IDs';
11012: $text{'item'} = 'ID';
11013: $text{'action'} = 'an ID';
1.615 raeburn 11014: if ($count > 1) {
11015: $text{'item'} = 'IDs';
11016: $text{'action'} = 'IDs';
11017: }
1.612 raeburn 11018: }
1.674 bisitz 11019: $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 11020: if ($mode eq 'upload') {
11021: if ($checkitem eq 'username') {
11022: $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'}.");
11023: } elsif ($checkitem eq 'id') {
1.674 bisitz 11024: $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 11025: }
1.669 raeburn 11026: } elsif ($mode eq 'selfcreate') {
11027: if ($checkitem eq 'id') {
11028: $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.");
11029: }
1.615 raeburn 11030: } else {
11031: if ($checkitem eq 'username') {
11032: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
11033: } elsif ($checkitem eq 'id') {
11034: $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.");
11035: }
1.612 raeburn 11036: }
11037: return $response;
1.585 raeburn 11038: }
11039:
1.624 raeburn 11040: sub personal_data_fieldtitles {
11041: my %fieldtitles = &Apache::lonlocal::texthash (
11042: id => 'Student/Employee ID',
11043: permanentemail => 'E-mail address',
11044: lastname => 'Last Name',
11045: firstname => 'First Name',
11046: middlename => 'Middle Name',
11047: generation => 'Generation',
11048: gen => 'Generation',
1.765 raeburn 11049: inststatus => 'Affiliation',
1.624 raeburn 11050: );
11051: return %fieldtitles;
11052: }
11053:
1.642 raeburn 11054: sub sorted_inst_types {
11055: my ($dom) = @_;
1.1185 raeburn 11056: my ($usertypes,$order);
11057: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11058: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
11059: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
11060: $order = $domdefaults{'inststatus'}{'inststatusorder'};
11061: } else {
11062: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
11063: }
1.642 raeburn 11064: my $othertitle = &mt('All users');
11065: if ($env{'request.course.id'}) {
1.668 raeburn 11066: $othertitle = &mt('Any users');
1.642 raeburn 11067: }
11068: my @types;
11069: if (ref($order) eq 'ARRAY') {
11070: @types = @{$order};
11071: }
11072: if (@types == 0) {
11073: if (ref($usertypes) eq 'HASH') {
11074: @types = sort(keys(%{$usertypes}));
11075: }
11076: }
11077: if (keys(%{$usertypes}) > 0) {
11078: $othertitle = &mt('Other users');
11079: }
11080: return ($othertitle,$usertypes,\@types);
11081: }
11082:
1.645 raeburn 11083: sub get_institutional_codes {
11084: my ($settings,$allcourses,$LC_code) = @_;
11085: # Get complete list of course sections to update
11086: my @currsections = ();
11087: my @currxlists = ();
11088: my $coursecode = $$settings{'internal.coursecode'};
11089:
11090: if ($$settings{'internal.sectionnums'} ne '') {
11091: @currsections = split(/,/,$$settings{'internal.sectionnums'});
11092: }
11093:
11094: if ($$settings{'internal.crosslistings'} ne '') {
11095: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
11096: }
11097:
11098: if (@currxlists > 0) {
11099: foreach (@currxlists) {
11100: if (m/^([^:]+):(\w*)$/) {
11101: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 11102: push(@{$allcourses},$1);
1.645 raeburn 11103: $$LC_code{$1} = $2;
11104: }
11105: }
11106: }
11107: }
11108:
11109: if (@currsections > 0) {
11110: foreach (@currsections) {
11111: if (m/^(\w+):(\w*)$/) {
11112: my $sec = $coursecode.$1;
11113: my $lc_sec = $2;
11114: unless (grep/^$sec$/,@{$allcourses}) {
1.1263 raeburn 11115: push(@{$allcourses},$sec);
1.645 raeburn 11116: $$LC_code{$sec} = $lc_sec;
11117: }
11118: }
11119: }
11120: }
11121: return;
11122: }
11123:
1.971 raeburn 11124: sub get_standard_codeitems {
11125: return ('Year','Semester','Department','Number','Section');
11126: }
11127:
1.112 bowersj2 11128: =pod
11129:
1.780 raeburn 11130: =head1 Slot Helpers
11131:
11132: =over 4
11133:
11134: =item * sorted_slots()
11135:
1.1040 raeburn 11136: Sorts an array of slot names in order of an optional sort key,
11137: default sort is by slot start time (earliest first).
1.780 raeburn 11138:
11139: Inputs:
11140:
11141: =over 4
11142:
11143: slotsarr - Reference to array of unsorted slot names.
11144:
11145: slots - Reference to hash of hash, where outer hash keys are slot names.
11146:
1.1040 raeburn 11147: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
11148:
1.549 albertel 11149: =back
11150:
1.780 raeburn 11151: Returns:
11152:
11153: =over 4
11154:
1.1040 raeburn 11155: sorted - An array of slot names sorted by a specified sort key
11156: (default sort key is start time of the slot).
1.780 raeburn 11157:
11158: =back
11159:
11160: =cut
11161:
11162:
11163: sub sorted_slots {
1.1040 raeburn 11164: my ($slotsarr,$slots,$sortkey) = @_;
11165: if ($sortkey eq '') {
11166: $sortkey = 'starttime';
11167: }
1.780 raeburn 11168: my @sorted;
11169: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11170: @sorted =
11171: sort {
11172: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11173: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11174: }
11175: if (ref($slots->{$a})) { return -1;}
11176: if (ref($slots->{$b})) { return 1;}
11177: return 0;
11178: } @{$slotsarr};
11179: }
11180: return @sorted;
11181: }
11182:
1.1040 raeburn 11183: =pod
11184:
11185: =item * get_future_slots()
11186:
11187: Inputs:
11188:
11189: =over 4
11190:
11191: cnum - course number
11192:
11193: cdom - course domain
11194:
11195: now - current UNIX time
11196:
11197: symb - optional symb
11198:
11199: =back
11200:
11201: Returns:
11202:
11203: =over 4
11204:
11205: sorted_reservable - ref to array of student_schedulable slots currently
11206: reservable, ordered by end date of reservation period.
11207:
11208: reservable_now - ref to hash of student_schedulable slots currently
11209: reservable.
11210:
11211: Keys in inner hash are:
11212: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11213: (b) endreserve: end date of reservation period.
11214: (c) uniqueperiod: start,end dates when slot is to be uniquely
11215: selected.
1.1040 raeburn 11216:
11217: sorted_future - ref to array of student_schedulable slots reservable in
11218: the future, ordered by start date of reservation period.
11219:
11220: future_reservable - ref to hash of student_schedulable slots reservable
11221: in the future.
11222:
11223: Keys in inner hash are:
11224: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11225: (b) startreserve: start date of reservation period.
11226: (c) uniqueperiod: start,end dates when slot is to be uniquely
11227: selected.
1.1040 raeburn 11228:
11229: =back
11230:
11231: =cut
11232:
11233: sub get_future_slots {
11234: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 11235: my $map;
11236: if ($symb) {
11237: ($map) = &Apache::lonnet::decode_symb($symb);
11238: }
1.1040 raeburn 11239: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11240: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11241: foreach my $slot (keys(%slots)) {
11242: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11243: if ($symb) {
1.1229 raeburn 11244: if ($slots{$slot}->{'symb'} ne '') {
11245: my $canuse;
11246: my %oksymbs;
11247: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
11248: map { $oksymbs{$_} = 1; } @slotsymbs;
11249: if ($oksymbs{$symb}) {
11250: $canuse = 1;
11251: } else {
11252: foreach my $item (@slotsymbs) {
11253: if ($item =~ /\.(page|sequence)$/) {
11254: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
11255: if (($map ne '') && ($map eq $sloturl)) {
11256: $canuse = 1;
11257: last;
11258: }
11259: }
11260: }
11261: }
11262: next unless ($canuse);
11263: }
1.1040 raeburn 11264: }
11265: if (($slots{$slot}->{'starttime'} > $now) &&
11266: ($slots{$slot}->{'endtime'} > $now)) {
11267: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11268: my $userallowed = 0;
11269: if ($slots{$slot}->{'allowedsections'}) {
11270: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11271: if (!defined($env{'request.role.sec'})
11272: && grep(/^No section assigned$/,@allowed_sec)) {
11273: $userallowed=1;
11274: } else {
11275: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11276: $userallowed=1;
11277: }
11278: }
11279: unless ($userallowed) {
11280: if (defined($env{'request.course.groups'})) {
11281: my @groups = split(/:/,$env{'request.course.groups'});
11282: foreach my $group (@groups) {
11283: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11284: $userallowed=1;
11285: last;
11286: }
11287: }
11288: }
11289: }
11290: }
11291: if ($slots{$slot}->{'allowedusers'}) {
11292: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11293: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11294: if (grep(/^\Q$user\E$/,@allowed_users)) {
11295: $userallowed = 1;
11296: }
11297: }
11298: next unless($userallowed);
11299: }
11300: my $startreserve = $slots{$slot}->{'startreserve'};
11301: my $endreserve = $slots{$slot}->{'endreserve'};
11302: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 11303: my $uniqueperiod;
11304: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11305: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11306: }
1.1040 raeburn 11307: if (($startreserve < $now) &&
11308: (!$endreserve || $endreserve > $now)) {
11309: my $lastres = $endreserve;
11310: if (!$lastres) {
11311: $lastres = $slots{$slot}->{'starttime'};
11312: }
11313: $reservable_now{$slot} = {
11314: symb => $symb,
1.1250 raeburn 11315: endreserve => $lastres,
11316: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11317: };
11318: } elsif (($startreserve > $now) &&
11319: (!$endreserve || $endreserve > $startreserve)) {
11320: $future_reservable{$slot} = {
11321: symb => $symb,
1.1250 raeburn 11322: startreserve => $startreserve,
11323: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11324: };
11325: }
11326: }
11327: }
11328: my @unsorted_reservable = keys(%reservable_now);
11329: if (@unsorted_reservable > 0) {
11330: @sorted_reservable =
11331: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11332: }
11333: my @unsorted_future = keys(%future_reservable);
11334: if (@unsorted_future > 0) {
11335: @sorted_future =
11336: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11337: }
11338: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11339: }
1.780 raeburn 11340:
11341: =pod
11342:
1.1057 foxr 11343: =back
11344:
1.549 albertel 11345: =head1 HTTP Helpers
11346:
11347: =over 4
11348:
1.648 raeburn 11349: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11350:
1.258 albertel 11351: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11352: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11353: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11354:
11355: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11356: $possible_names is an ref to an array of form element names. As an example:
11357: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11358: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11359:
11360: =cut
1.1 albertel 11361:
1.6 albertel 11362: sub get_unprocessed_cgi {
1.25 albertel 11363: my ($query,$possible_names)= @_;
1.26 matthew 11364: # $Apache::lonxml::debug=1;
1.356 albertel 11365: foreach my $pair (split(/&/,$query)) {
11366: my ($name, $value) = split(/=/,$pair);
1.369 www 11367: $name = &unescape($name);
1.25 albertel 11368: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11369: $value =~ tr/+/ /;
11370: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11371: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11372: }
1.16 harris41 11373: }
1.6 albertel 11374: }
11375:
1.112 bowersj2 11376: =pod
11377:
1.648 raeburn 11378: =item * &cacheheader()
1.112 bowersj2 11379:
11380: returns cache-controlling header code
11381:
11382: =cut
11383:
1.7 albertel 11384: sub cacheheader {
1.258 albertel 11385: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11386: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11387: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11388: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11389: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11390: return $output;
1.7 albertel 11391: }
11392:
1.112 bowersj2 11393: =pod
11394:
1.648 raeburn 11395: =item * &no_cache($r)
1.112 bowersj2 11396:
11397: specifies header code to not have cache
11398:
11399: =cut
11400:
1.9 albertel 11401: sub no_cache {
1.216 albertel 11402: my ($r) = @_;
11403: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11404: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11405: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11406: $r->no_cache(1);
11407: $r->header_out("Expires" => $date);
11408: $r->header_out("Pragma" => "no-cache");
1.123 www 11409: }
11410:
11411: sub content_type {
1.181 albertel 11412: my ($r,$type,$charset) = @_;
1.299 foxr 11413: if ($r) {
11414: # Note that printout.pl calls this with undef for $r.
11415: &no_cache($r);
11416: }
1.258 albertel 11417: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11418: unless ($charset) {
11419: $charset=&Apache::lonlocal::current_encoding;
11420: }
11421: if ($charset) { $type.='; charset='.$charset; }
11422: if ($r) {
11423: $r->content_type($type);
11424: } else {
11425: print("Content-type: $type\n\n");
11426: }
1.9 albertel 11427: }
1.25 albertel 11428:
1.112 bowersj2 11429: =pod
11430:
1.648 raeburn 11431: =item * &add_to_env($name,$value)
1.112 bowersj2 11432:
1.258 albertel 11433: adds $name to the %env hash with value
1.112 bowersj2 11434: $value, if $name already exists, the entry is converted to an array
11435: reference and $value is added to the array.
11436:
11437: =cut
11438:
1.25 albertel 11439: sub add_to_env {
11440: my ($name,$value)=@_;
1.258 albertel 11441: if (defined($env{$name})) {
11442: if (ref($env{$name})) {
1.25 albertel 11443: #already have multiple values
1.258 albertel 11444: push(@{ $env{$name} },$value);
1.25 albertel 11445: } else {
11446: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11447: my $first=$env{$name};
11448: undef($env{$name});
11449: push(@{ $env{$name} },$first,$value);
1.25 albertel 11450: }
11451: } else {
1.258 albertel 11452: $env{$name}=$value;
1.25 albertel 11453: }
1.31 albertel 11454: }
1.149 albertel 11455:
11456: =pod
11457:
1.648 raeburn 11458: =item * &get_env_multiple($name)
1.149 albertel 11459:
1.258 albertel 11460: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11461: values may be defined and end up as an array ref.
11462:
11463: returns an array of values
11464:
11465: =cut
11466:
11467: sub get_env_multiple {
11468: my ($name) = @_;
11469: my @values;
1.258 albertel 11470: if (defined($env{$name})) {
1.149 albertel 11471: # exists is it an array
1.258 albertel 11472: if (ref($env{$name})) {
11473: @values=@{ $env{$name} };
1.149 albertel 11474: } else {
1.258 albertel 11475: $values[0]=$env{$name};
1.149 albertel 11476: }
11477: }
11478: return(@values);
11479: }
11480:
1.1249 damieng 11481: # Looks at given dependencies, and returns something depending on the context.
11482: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11483: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11484: # For all other contexts, returns ($output, $counter, $numpathchg).
11485: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11486: # $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.
11487: # $numpathchg: integer with the number of cleaned up dependency paths.
11488: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11489: # \%mapping: hash reference clean path -> original path for all dependencies.
11490: # @param {string} actionurl - The path to the handler, indicative of the context.
11491: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11492: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11493: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11494: # @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)
11495: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11496: sub ask_for_embedded_content {
1.1249 damieng 11497: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11498: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11499: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11500: %currsubfile,%unused,$rem);
1.1071 raeburn 11501: my $counter = 0;
11502: my $numnew = 0;
1.987 raeburn 11503: my $numremref = 0;
11504: my $numinvalid = 0;
11505: my $numpathchg = 0;
11506: my $numexisting = 0;
1.1071 raeburn 11507: my $numunused = 0;
11508: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11509: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11510: my $heading = &mt('Upload embedded files');
11511: my $buttontext = &mt('Upload');
11512:
1.1249 damieng 11513: # fills these variables based on the context:
11514: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11515: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11516: if ($env{'request.course.id'}) {
1.1123 raeburn 11517: if ($actionurl eq '/adm/dependencies') {
11518: $navmap = Apache::lonnavmaps::navmap->new();
11519: }
11520: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11521: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11522: }
1.1123 raeburn 11523: if (($actionurl eq '/adm/portfolio') ||
11524: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11525: my $current_path='/';
11526: if ($env{'form.currentpath'}) {
11527: $current_path = $env{'form.currentpath'};
11528: }
11529: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11530: $udom = $cdom;
11531: $uname = $cnum;
1.984 raeburn 11532: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11533: } else {
11534: $udom = $env{'user.domain'};
11535: $uname = $env{'user.name'};
11536: $url = '/userfiles/portfolio';
11537: }
1.987 raeburn 11538: $toplevel = $url.'/';
1.984 raeburn 11539: $url .= $current_path;
11540: $getpropath = 1;
1.987 raeburn 11541: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11542: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11543: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11544: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11545: $toplevel = $url;
1.984 raeburn 11546: if ($rest ne '') {
1.987 raeburn 11547: $url .= $rest;
11548: }
11549: } elsif ($actionurl eq '/adm/coursedocs') {
11550: if (ref($args) eq 'HASH') {
1.1071 raeburn 11551: $url = $args->{'docs_url'};
11552: $toplevel = $url;
1.1084 raeburn 11553: if ($args->{'context'} eq 'paste') {
11554: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11555: ($path) =
11556: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11557: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11558: $fileloc =~ s{^/}{};
11559: }
1.1071 raeburn 11560: }
1.1084 raeburn 11561: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11562: if ($env{'request.course.id'} ne '') {
11563: if (ref($args) eq 'HASH') {
11564: $url = $args->{'docs_url'};
11565: $title = $args->{'docs_title'};
1.1126 raeburn 11566: $toplevel = $url;
11567: unless ($toplevel =~ m{^/}) {
11568: $toplevel = "/$url";
11569: }
1.1085 raeburn 11570: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11571: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11572: $path = $1;
11573: } else {
11574: ($path) =
11575: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11576: }
1.1195 raeburn 11577: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11578: $fileloc = $toplevel;
11579: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11580: my ($udom,$uname,$fname) =
11581: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11582: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11583: } else {
11584: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11585: }
1.1071 raeburn 11586: $fileloc =~ s{^/}{};
11587: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11588: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11589: }
1.987 raeburn 11590: }
1.1123 raeburn 11591: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11592: $udom = $cdom;
11593: $uname = $cnum;
11594: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11595: $toplevel = $url;
11596: $path = $url;
11597: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11598: $fileloc =~ s{^/}{};
1.987 raeburn 11599: }
1.1249 damieng 11600:
11601: # parses the dependency paths to get some info
11602: # fills $newfiles, $mapping, $subdependencies, $dependencies
11603: # $newfiles: hash URL -> 1 for new files or external URLs
11604: # (will be completed later)
11605: # $mapping:
11606: # for external URLs: external URL -> external URL
11607: # for relative paths: clean path -> original path
11608: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11609: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11610: foreach my $file (keys(%{$allfiles})) {
11611: my $embed_file;
11612: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11613: $embed_file = $1;
11614: } else {
11615: $embed_file = $file;
11616: }
1.1158 raeburn 11617: my ($absolutepath,$cleaned_file);
11618: if ($embed_file =~ m{^\w+://}) {
11619: $cleaned_file = $embed_file;
1.1147 raeburn 11620: $newfiles{$cleaned_file} = 1;
11621: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11622: } else {
1.1158 raeburn 11623: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11624: if ($embed_file =~ m{^/}) {
11625: $absolutepath = $embed_file;
11626: }
1.1147 raeburn 11627: if ($cleaned_file =~ m{/}) {
11628: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11629: $path = &check_for_traversal($path,$url,$toplevel);
11630: my $item = $fname;
11631: if ($path ne '') {
11632: $item = $path.'/'.$fname;
11633: $subdependencies{$path}{$fname} = 1;
11634: } else {
11635: $dependencies{$item} = 1;
11636: }
11637: if ($absolutepath) {
11638: $mapping{$item} = $absolutepath;
11639: } else {
11640: $mapping{$item} = $embed_file;
11641: }
11642: } else {
11643: $dependencies{$embed_file} = 1;
11644: if ($absolutepath) {
1.1147 raeburn 11645: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11646: } else {
1.1147 raeburn 11647: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11648: }
11649: }
1.984 raeburn 11650: }
11651: }
1.1249 damieng 11652:
11653: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11654: # and lists
11655: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11656: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11657: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11658: # the path had to be cleaned up
11659: # $existing: hash clean path -> 1 if the file exists
11660: # $numexisting: number of keys in $existing
11661: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11662: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11663: # dependency subdirectories that are
11664: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11665: my $dirptr = 16384;
1.984 raeburn 11666: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11667: $currsubfile{$path} = {};
1.1123 raeburn 11668: if (($actionurl eq '/adm/portfolio') ||
11669: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11670: my ($sublistref,$listerror) =
11671: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11672: if (ref($sublistref) eq 'ARRAY') {
11673: foreach my $line (@{$sublistref}) {
11674: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11675: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11676: }
1.984 raeburn 11677: }
1.987 raeburn 11678: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11679: if (opendir(my $dir,$url.'/'.$path)) {
11680: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11681: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11682: }
1.1084 raeburn 11683: } elsif (($actionurl eq '/adm/dependencies') ||
11684: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11685: ($args->{'context'} eq 'paste')) ||
11686: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11687: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11688: my $dir;
11689: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11690: $dir = $fileloc;
11691: } else {
11692: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11693: }
1.1071 raeburn 11694: if ($dir ne '') {
11695: my ($sublistref,$listerror) =
11696: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11697: if (ref($sublistref) eq 'ARRAY') {
11698: foreach my $line (@{$sublistref}) {
11699: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11700: undef,$mtime)=split(/\&/,$line,12);
11701: unless (($testdir&$dirptr) ||
11702: ($file_name =~ /^\.\.?$/)) {
11703: $currsubfile{$path}{$file_name} = [$size,$mtime];
11704: }
11705: }
11706: }
11707: }
1.984 raeburn 11708: }
11709: }
11710: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11711: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11712: my $item = $path.'/'.$file;
11713: unless ($mapping{$item} eq $item) {
11714: $pathchanges{$item} = 1;
11715: }
11716: $existing{$item} = 1;
11717: $numexisting ++;
11718: } else {
11719: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11720: }
11721: }
1.1071 raeburn 11722: if ($actionurl eq '/adm/dependencies') {
11723: foreach my $path (keys(%currsubfile)) {
11724: if (ref($currsubfile{$path}) eq 'HASH') {
11725: foreach my $file (keys(%{$currsubfile{$path}})) {
11726: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11727: next if (($rem ne '') &&
11728: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11729: (ref($navmap) &&
11730: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11731: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11732: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11733: $unused{$path.'/'.$file} = 1;
11734: }
11735: }
11736: }
11737: }
11738: }
1.984 raeburn 11739: }
1.1249 damieng 11740:
11741: # fills $currfile, hash file name -> 1 or [$size,$mtime]
11742: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 11743: my %currfile;
1.1123 raeburn 11744: if (($actionurl eq '/adm/portfolio') ||
11745: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11746: my ($dirlistref,$listerror) =
11747: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11748: if (ref($dirlistref) eq 'ARRAY') {
11749: foreach my $line (@{$dirlistref}) {
11750: my ($file_name,$rest) = split(/\&/,$line,2);
11751: $currfile{$file_name} = 1;
11752: }
1.984 raeburn 11753: }
1.987 raeburn 11754: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11755: if (opendir(my $dir,$url)) {
1.987 raeburn 11756: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11757: map {$currfile{$_} = 1;} @dir_list;
11758: }
1.1084 raeburn 11759: } elsif (($actionurl eq '/adm/dependencies') ||
11760: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11761: ($args->{'context'} eq 'paste')) ||
11762: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11763: if ($env{'request.course.id'} ne '') {
11764: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11765: if ($dir ne '') {
11766: my ($dirlistref,$listerror) =
11767: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11768: if (ref($dirlistref) eq 'ARRAY') {
11769: foreach my $line (@{$dirlistref}) {
11770: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11771: $size,undef,$mtime)=split(/\&/,$line,12);
11772: unless (($testdir&$dirptr) ||
11773: ($file_name =~ /^\.\.?$/)) {
11774: $currfile{$file_name} = [$size,$mtime];
11775: }
11776: }
11777: }
11778: }
11779: }
1.984 raeburn 11780: }
1.1249 damieng 11781: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
11782: # are not in subdirectories, using $currfile
1.984 raeburn 11783: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11784: if (exists($currfile{$file})) {
1.987 raeburn 11785: unless ($mapping{$file} eq $file) {
11786: $pathchanges{$file} = 1;
11787: }
11788: $existing{$file} = 1;
11789: $numexisting ++;
11790: } else {
1.984 raeburn 11791: $newfiles{$file} = 1;
11792: }
11793: }
1.1071 raeburn 11794: foreach my $file (keys(%currfile)) {
11795: unless (($file eq $filename) ||
11796: ($file eq $filename.'.bak') ||
11797: ($dependencies{$file})) {
1.1085 raeburn 11798: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11799: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11800: next if (($rem ne '') &&
11801: (($env{"httpref.$rem".$file} ne '') ||
11802: (ref($navmap) &&
11803: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11804: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11805: ($navmap->getResourceByUrl($rem.$1)))))));
11806: }
1.1085 raeburn 11807: }
1.1071 raeburn 11808: $unused{$file} = 1;
11809: }
11810: }
1.1249 damieng 11811:
11812: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 11813: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11814: ($args->{'context'} eq 'paste')) {
11815: $counter = scalar(keys(%existing));
11816: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11817: return ($output,$counter,$numpathchg,\%existing);
11818: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11819: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11820: $counter = scalar(keys(%existing));
11821: $numpathchg = scalar(keys(%pathchanges));
11822: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11823: }
1.1249 damieng 11824:
11825: # returns HTML otherwise, with dependency results and to ask for more uploads
11826:
11827: # $upload_output: missing dependencies (with upload form)
11828: # $modify_output: uploaded dependencies (in use)
11829: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 11830: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11831: if ($actionurl eq '/adm/dependencies') {
11832: next if ($embed_file =~ m{^\w+://});
11833: }
1.660 raeburn 11834: $upload_output .= &start_data_table_row().
1.1123 raeburn 11835: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11836: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11837: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11838: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11839: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11840: }
1.1123 raeburn 11841: $upload_output .= '</td>';
1.1071 raeburn 11842: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11843: $upload_output.='<td align="right">'.
11844: '<span class="LC_info LC_fontsize_medium">'.
11845: &mt("URL points to web address").'</span>';
1.987 raeburn 11846: $numremref++;
1.660 raeburn 11847: } elsif ($args->{'error_on_invalid_names'}
11848: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11849: $upload_output.='<td align="right"><span class="LC_warning">'.
11850: &mt('Invalid characters').'</span>';
1.987 raeburn 11851: $numinvalid++;
1.660 raeburn 11852: } else {
1.1123 raeburn 11853: $upload_output .= '<td>'.
11854: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11855: $embed_file,\%mapping,
1.1071 raeburn 11856: $allfiles,$codebase,'upload');
11857: $counter ++;
11858: $numnew ++;
1.987 raeburn 11859: }
11860: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11861: }
11862: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11863: if ($actionurl eq '/adm/dependencies') {
11864: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11865: $modify_output .= &start_data_table_row().
11866: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11867: '<img src="'.&icon($embed_file).'" border="0" />'.
11868: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11869: '<td>'.$size.'</td>'.
11870: '<td>'.$mtime.'</td>'.
11871: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11872: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11873: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11874: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11875: &embedded_file_element('upload_embedded',$counter,
11876: $embed_file,\%mapping,
11877: $allfiles,$codebase,'modify').
11878: '</div></td>'.
11879: &end_data_table_row()."\n";
11880: $counter ++;
11881: } else {
11882: $upload_output .= &start_data_table_row().
1.1123 raeburn 11883: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11884: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11885: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11886: &Apache::loncommon::end_data_table_row()."\n";
11887: }
11888: }
11889: my $delidx = $counter;
11890: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11891: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11892: $delete_output .= &start_data_table_row().
11893: '<td><img src="'.&icon($oldfile).'" />'.
11894: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11895: '<td>'.$size.'</td>'.
11896: '<td>'.$mtime.'</td>'.
11897: '<td><label><input type="checkbox" name="del_upload_dep" '.
11898: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11899: &embedded_file_element('upload_embedded',$delidx,
11900: $oldfile,\%mapping,$allfiles,
11901: $codebase,'delete').'</td>'.
11902: &end_data_table_row()."\n";
11903: $numunused ++;
11904: $delidx ++;
1.987 raeburn 11905: }
11906: if ($upload_output) {
11907: $upload_output = &start_data_table().
11908: $upload_output.
11909: &end_data_table()."\n";
11910: }
1.1071 raeburn 11911: if ($modify_output) {
11912: $modify_output = &start_data_table().
11913: &start_data_table_header_row().
11914: '<th>'.&mt('File').'</th>'.
11915: '<th>'.&mt('Size (KB)').'</th>'.
11916: '<th>'.&mt('Modified').'</th>'.
11917: '<th>'.&mt('Upload replacement?').'</th>'.
11918: &end_data_table_header_row().
11919: $modify_output.
11920: &end_data_table()."\n";
11921: }
11922: if ($delete_output) {
11923: $delete_output = &start_data_table().
11924: &start_data_table_header_row().
11925: '<th>'.&mt('File').'</th>'.
11926: '<th>'.&mt('Size (KB)').'</th>'.
11927: '<th>'.&mt('Modified').'</th>'.
11928: '<th>'.&mt('Delete?').'</th>'.
11929: &end_data_table_header_row().
11930: $delete_output.
11931: &end_data_table()."\n";
11932: }
1.987 raeburn 11933: my $applies = 0;
11934: if ($numremref) {
11935: $applies ++;
11936: }
11937: if ($numinvalid) {
11938: $applies ++;
11939: }
11940: if ($numexisting) {
11941: $applies ++;
11942: }
1.1071 raeburn 11943: if ($counter || $numunused) {
1.987 raeburn 11944: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11945: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11946: $state.'<h3>'.$heading.'</h3>';
11947: if ($actionurl eq '/adm/dependencies') {
11948: if ($numnew) {
11949: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11950: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11951: $upload_output.'<br />'."\n";
11952: }
11953: if ($numexisting) {
11954: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11955: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11956: $modify_output.'<br />'."\n";
11957: $buttontext = &mt('Save changes');
11958: }
11959: if ($numunused) {
11960: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11961: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11962: $delete_output.'<br />'."\n";
11963: $buttontext = &mt('Save changes');
11964: }
11965: } else {
11966: $output .= $upload_output.'<br />'."\n";
11967: }
11968: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11969: $counter.'" />'."\n";
11970: if ($actionurl eq '/adm/dependencies') {
11971: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11972: $numnew.'" />'."\n";
11973: } elsif ($actionurl eq '') {
1.987 raeburn 11974: $output .= '<input type="hidden" name="phase" value="three" />';
11975: }
11976: } elsif ($applies) {
11977: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11978: if ($applies > 1) {
11979: $output .=
1.1123 raeburn 11980: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11981: if ($numremref) {
11982: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11983: }
11984: if ($numinvalid) {
11985: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11986: }
11987: if ($numexisting) {
11988: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11989: }
11990: $output .= '</ul><br />';
11991: } elsif ($numremref) {
11992: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11993: } elsif ($numinvalid) {
11994: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11995: } elsif ($numexisting) {
11996: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11997: }
11998: $output .= $upload_output.'<br />';
11999: }
12000: my ($pathchange_output,$chgcount);
1.1071 raeburn 12001: $chgcount = $counter;
1.987 raeburn 12002: if (keys(%pathchanges) > 0) {
12003: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 12004: if ($counter) {
1.987 raeburn 12005: $output .= &embedded_file_element('pathchange',$chgcount,
12006: $embed_file,\%mapping,
1.1071 raeburn 12007: $allfiles,$codebase,'change');
1.987 raeburn 12008: } else {
12009: $pathchange_output .=
12010: &start_data_table_row().
12011: '<td><input type ="checkbox" name="namechange" value="'.
12012: $chgcount.'" checked="checked" /></td>'.
12013: '<td>'.$mapping{$embed_file}.'</td>'.
12014: '<td>'.$embed_file.
12015: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 12016: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 12017: '</td>'.&end_data_table_row();
1.660 raeburn 12018: }
1.987 raeburn 12019: $numpathchg ++;
12020: $chgcount ++;
1.660 raeburn 12021: }
12022: }
1.1127 raeburn 12023: if (($counter) || ($numunused)) {
1.987 raeburn 12024: if ($numpathchg) {
12025: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
12026: $numpathchg.'" />'."\n";
12027: }
12028: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12029: ($actionurl eq '/adm/imsimport')) {
12030: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
12031: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
12032: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 12033: } elsif ($actionurl eq '/adm/dependencies') {
12034: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 12035: }
1.1123 raeburn 12036: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 12037: } elsif ($numpathchg) {
12038: my %pathchange = ();
12039: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
12040: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12041: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 12042: }
1.987 raeburn 12043: }
1.1071 raeburn 12044: return ($output,$counter,$numpathchg);
1.987 raeburn 12045: }
12046:
1.1147 raeburn 12047: =pod
12048:
12049: =item * clean_path($name)
12050:
12051: Performs clean-up of directories, subdirectories and filename in an
12052: embedded object, referenced in an HTML file which is being uploaded
12053: to a course or portfolio, where
12054: "Upload embedded images/multimedia files if HTML file" checkbox was
12055: checked.
12056:
12057: Clean-up is similar to replacements in lonnet::clean_filename()
12058: except each / between sub-directory and next level is preserved.
12059:
12060: =cut
12061:
12062: sub clean_path {
12063: my ($embed_file) = @_;
12064: $embed_file =~s{^/+}{};
12065: my @contents;
12066: if ($embed_file =~ m{/}) {
12067: @contents = split(/\//,$embed_file);
12068: } else {
12069: @contents = ($embed_file);
12070: }
12071: my $lastidx = scalar(@contents)-1;
12072: for (my $i=0; $i<=$lastidx; $i++) {
12073: $contents[$i]=~s{\\}{/}g;
12074: $contents[$i]=~s/\s+/\_/g;
12075: $contents[$i]=~s{[^/\w\.\-]}{}g;
12076: if ($i == $lastidx) {
12077: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
12078: }
12079: }
12080: if ($lastidx > 0) {
12081: return join('/',@contents);
12082: } else {
12083: return $contents[0];
12084: }
12085: }
12086:
1.987 raeburn 12087: sub embedded_file_element {
1.1071 raeburn 12088: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 12089: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
12090: (ref($codebase) eq 'HASH'));
12091: my $output;
1.1071 raeburn 12092: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 12093: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
12094: }
12095: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
12096: &escape($embed_file).'" />';
12097: unless (($context eq 'upload_embedded') &&
12098: ($mapping->{$embed_file} eq $embed_file)) {
12099: $output .='
12100: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
12101: }
12102: my $attrib;
12103: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
12104: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
12105: }
12106: $output .=
12107: "\n\t\t".
12108: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
12109: $attrib.'" />';
12110: if (exists($codebase->{$mapping->{$embed_file}})) {
12111: $output .=
12112: "\n\t\t".
12113: '<input name="codebase_'.$num.'" type="hidden" value="'.
12114: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 12115: }
1.987 raeburn 12116: return $output;
1.660 raeburn 12117: }
12118:
1.1071 raeburn 12119: sub get_dependency_details {
12120: my ($currfile,$currsubfile,$embed_file) = @_;
12121: my ($size,$mtime,$showsize,$showmtime);
12122: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
12123: if ($embed_file =~ m{/}) {
12124: my ($path,$fname) = split(/\//,$embed_file);
12125: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
12126: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
12127: }
12128: } else {
12129: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
12130: ($size,$mtime) = @{$currfile->{$embed_file}};
12131: }
12132: }
12133: $showsize = $size/1024.0;
12134: $showsize = sprintf("%.1f",$showsize);
12135: if ($mtime > 0) {
12136: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
12137: }
12138: }
12139: return ($showsize,$showmtime);
12140: }
12141:
12142: sub ask_embedded_js {
12143: return <<"END";
12144: <script type="text/javascript"">
12145: // <![CDATA[
12146: function toggleBrowse(counter) {
12147: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
12148: var fileid = document.getElementById('embedded_item_'+counter);
12149: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12150: if (chkboxid.checked == true) {
12151: uploaddivid.style.display='block';
12152: } else {
12153: uploaddivid.style.display='none';
12154: fileid.value = '';
12155: }
12156: }
12157: // ]]>
12158: </script>
12159:
12160: END
12161: }
12162:
1.661 raeburn 12163: sub upload_embedded {
12164: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12165: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12166: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12167: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12168: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12169: my $orig_uploaded_filename =
12170: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12171: foreach my $type ('orig','ref','attrib','codebase') {
12172: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12173: $env{'form.embedded_'.$type.'_'.$i} =
12174: &unescape($env{'form.embedded_'.$type.'_'.$i});
12175: }
12176: }
1.661 raeburn 12177: my ($path,$fname) =
12178: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12179: # no path, whole string is fname
12180: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12181: $fname = &Apache::lonnet::clean_filename($fname);
12182: # See if there is anything left
12183: next if ($fname eq '');
12184:
12185: # Check if file already exists as a file or directory.
12186: my ($state,$msg);
12187: if ($context eq 'portfolio') {
12188: my $port_path = $dirpath;
12189: if ($group ne '') {
12190: $port_path = "groups/$group/$port_path";
12191: }
1.987 raeburn 12192: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12193: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12194: $dir_root,$port_path,$disk_quota,
12195: $current_disk_usage,$uname,$udom);
12196: if ($state eq 'will_exceed_quota'
1.984 raeburn 12197: || $state eq 'file_locked') {
1.661 raeburn 12198: $output .= $msg;
12199: next;
12200: }
12201: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12202: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12203: if ($state eq 'exists') {
12204: $output .= $msg;
12205: next;
12206: }
12207: }
12208: # Check if extension is valid
12209: if (($fname =~ /\.(\w+)$/) &&
12210: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 12211: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12212: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12213: next;
12214: } elsif (($fname =~ /\.(\w+)$/) &&
12215: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12216: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12217: next;
12218: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 12219: $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 12220: next;
12221: }
12222: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 12223: my $subdir = $path;
12224: $subdir =~ s{/+$}{};
1.661 raeburn 12225: if ($context eq 'portfolio') {
1.984 raeburn 12226: my $result;
12227: if ($state eq 'existingfile') {
12228: $result=
12229: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 12230: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12231: } else {
1.984 raeburn 12232: $result=
12233: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12234: $dirpath.
1.1123 raeburn 12235: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12236: if ($result !~ m|^/uploaded/|) {
12237: $output .= '<span class="LC_error">'
12238: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12239: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12240: .'</span><br />';
12241: next;
12242: } else {
1.987 raeburn 12243: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12244: $path.$fname.'</span>').'<br />';
1.984 raeburn 12245: }
1.661 raeburn 12246: }
1.1123 raeburn 12247: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 12248: my $extendedsubdir = $dirpath.'/'.$subdir;
12249: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12250: my $result =
1.1126 raeburn 12251: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12252: if ($result !~ m|^/uploaded/|) {
12253: $output .= '<span class="LC_error">'
12254: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12255: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12256: .'</span><br />';
12257: next;
12258: } else {
12259: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12260: $path.$fname.'</span>').'<br />';
1.1125 raeburn 12261: if ($context eq 'syllabus') {
12262: &Apache::lonnet::make_public_indefinitely($result);
12263: }
1.987 raeburn 12264: }
1.661 raeburn 12265: } else {
12266: # Save the file
12267: my $target = $env{'form.embedded_item_'.$i};
12268: my $fullpath = $dir_root.$dirpath.'/'.$path;
12269: my $dest = $fullpath.$fname;
12270: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12271: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12272: my $count;
12273: my $filepath = $dir_root;
1.1027 raeburn 12274: foreach my $subdir (@parts) {
12275: $filepath .= "/$subdir";
12276: if (!-e $filepath) {
1.661 raeburn 12277: mkdir($filepath,0770);
12278: }
12279: }
12280: my $fh;
12281: if (!open($fh,'>'.$dest)) {
12282: &Apache::lonnet::logthis('Failed to create '.$dest);
12283: $output .= '<span class="LC_error">'.
1.1071 raeburn 12284: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12285: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12286: '</span><br />';
12287: } else {
12288: if (!print $fh $env{'form.embedded_item_'.$i}) {
12289: &Apache::lonnet::logthis('Failed to write to '.$dest);
12290: $output .= '<span class="LC_error">'.
1.1071 raeburn 12291: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12292: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12293: '</span><br />';
12294: } else {
1.987 raeburn 12295: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12296: $url.'</span>').'<br />';
12297: unless ($context eq 'testbank') {
12298: $footer .= &mt('View embedded file: [_1]',
12299: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12300: }
12301: }
12302: close($fh);
12303: }
12304: }
12305: if ($env{'form.embedded_ref_'.$i}) {
12306: $pathchange{$i} = 1;
12307: }
12308: }
12309: if ($output) {
12310: $output = '<p>'.$output.'</p>';
12311: }
12312: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12313: $returnflag = 'ok';
1.1071 raeburn 12314: my $numpathchgs = scalar(keys(%pathchange));
12315: if ($numpathchgs > 0) {
1.987 raeburn 12316: if ($context eq 'portfolio') {
12317: $output .= '<p>'.&mt('or').'</p>';
12318: } elsif ($context eq 'testbank') {
1.1071 raeburn 12319: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12320: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12321: $returnflag = 'modify_orightml';
12322: }
12323: }
1.1071 raeburn 12324: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12325: }
12326:
12327: sub modify_html_form {
12328: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12329: my $end = 0;
12330: my $modifyform;
12331: if ($context eq 'upload_embedded') {
12332: return unless (ref($pathchange) eq 'HASH');
12333: if ($env{'form.number_embedded_items'}) {
12334: $end += $env{'form.number_embedded_items'};
12335: }
12336: if ($env{'form.number_pathchange_items'}) {
12337: $end += $env{'form.number_pathchange_items'};
12338: }
12339: if ($end) {
12340: for (my $i=0; $i<$end; $i++) {
12341: if ($i < $env{'form.number_embedded_items'}) {
12342: next unless($pathchange->{$i});
12343: }
12344: $modifyform .=
12345: &start_data_table_row().
12346: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12347: 'checked="checked" /></td>'.
12348: '<td>'.$env{'form.embedded_ref_'.$i}.
12349: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12350: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12351: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12352: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12353: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12354: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12355: '<td>'.$env{'form.embedded_orig_'.$i}.
12356: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12357: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12358: &end_data_table_row();
1.1071 raeburn 12359: }
1.987 raeburn 12360: }
12361: } else {
12362: $modifyform = $pathchgtable;
12363: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12364: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12365: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12366: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12367: }
12368: }
12369: if ($modifyform) {
1.1071 raeburn 12370: if ($actionurl eq '/adm/dependencies') {
12371: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12372: }
1.987 raeburn 12373: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12374: '<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".
12375: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12376: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12377: '</ol></p>'."\n".'<p>'.
12378: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12379: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12380: &start_data_table()."\n".
12381: &start_data_table_header_row().
12382: '<th>'.&mt('Change?').'</th>'.
12383: '<th>'.&mt('Current reference').'</th>'.
12384: '<th>'.&mt('Required reference').'</th>'.
12385: &end_data_table_header_row()."\n".
12386: $modifyform.
12387: &end_data_table().'<br />'."\n".$hiddenstate.
12388: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12389: '</form>'."\n";
12390: }
12391: return;
12392: }
12393:
12394: sub modify_html_refs {
1.1123 raeburn 12395: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12396: my $container;
12397: if ($context eq 'portfolio') {
12398: $container = $env{'form.container'};
12399: } elsif ($context eq 'coursedoc') {
12400: $container = $env{'form.primaryurl'};
1.1071 raeburn 12401: } elsif ($context eq 'manage_dependencies') {
12402: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12403: $container = "/$container";
1.1123 raeburn 12404: } elsif ($context eq 'syllabus') {
12405: $container = $url;
1.987 raeburn 12406: } else {
1.1027 raeburn 12407: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12408: }
12409: my (%allfiles,%codebase,$output,$content);
12410: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 12411: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12412: if (wantarray) {
12413: return ('',0,0);
12414: } else {
12415: return;
12416: }
12417: }
12418: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12419: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12420: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12421: if (wantarray) {
12422: return ('',0,0);
12423: } else {
12424: return;
12425: }
12426: }
1.987 raeburn 12427: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12428: if ($content eq '-1') {
12429: if (wantarray) {
12430: return ('',0,0);
12431: } else {
12432: return;
12433: }
12434: }
1.987 raeburn 12435: } else {
1.1071 raeburn 12436: unless ($container =~ /^\Q$dir_root\E/) {
12437: if (wantarray) {
12438: return ('',0,0);
12439: } else {
12440: return;
12441: }
12442: }
1.1317 raeburn 12443: if (open(my $fh,'<',$container)) {
1.987 raeburn 12444: $content = join('', <$fh>);
12445: close($fh);
12446: } else {
1.1071 raeburn 12447: if (wantarray) {
12448: return ('',0,0);
12449: } else {
12450: return;
12451: }
1.987 raeburn 12452: }
12453: }
12454: my ($count,$codebasecount) = (0,0);
12455: my $mm = new File::MMagic;
12456: my $mime_type = $mm->checktype_contents($content);
12457: if ($mime_type eq 'text/html') {
12458: my $parse_result =
12459: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12460: \%codebase,\$content);
12461: if ($parse_result eq 'ok') {
12462: foreach my $i (@changes) {
12463: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12464: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12465: if ($allfiles{$ref}) {
12466: my $newname = $orig;
12467: my ($attrib_regexp,$codebase);
1.1006 raeburn 12468: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12469: if ($attrib_regexp =~ /:/) {
12470: $attrib_regexp =~ s/\:/|/g;
12471: }
12472: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12473: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12474: $count += $numchg;
1.1123 raeburn 12475: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 12476: delete($allfiles{$ref});
1.987 raeburn 12477: }
12478: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12479: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12480: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12481: $codebasecount ++;
12482: }
12483: }
12484: }
1.1123 raeburn 12485: my $skiprewrites;
1.987 raeburn 12486: if ($count || $codebasecount) {
12487: my $saveresult;
1.1071 raeburn 12488: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12489: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12490: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12491: if ($url eq $container) {
12492: my ($fname) = ($container =~ m{/([^/]+)$});
12493: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12494: $count,'<span class="LC_filename">'.
1.1071 raeburn 12495: $fname.'</span>').'</p>';
1.987 raeburn 12496: } else {
12497: $output = '<p class="LC_error">'.
12498: &mt('Error: update failed for: [_1].',
12499: '<span class="LC_filename">'.
12500: $container.'</span>').'</p>';
12501: }
1.1123 raeburn 12502: if ($context eq 'syllabus') {
12503: unless ($saveresult eq 'ok') {
12504: $skiprewrites = 1;
12505: }
12506: }
1.987 raeburn 12507: } else {
1.1317 raeburn 12508: if (open(my $fh,'>',$container)) {
1.987 raeburn 12509: print $fh $content;
12510: close($fh);
12511: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12512: $count,'<span class="LC_filename">'.
12513: $container.'</span>').'</p>';
1.661 raeburn 12514: } else {
1.987 raeburn 12515: $output = '<p class="LC_error">'.
12516: &mt('Error: could not update [_1].',
12517: '<span class="LC_filename">'.
12518: $container.'</span>').'</p>';
1.661 raeburn 12519: }
12520: }
12521: }
1.1123 raeburn 12522: if (($context eq 'syllabus') && (!$skiprewrites)) {
12523: my ($actionurl,$state);
12524: $actionurl = "/public/$udom/$uname/syllabus";
12525: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12526: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12527: \%codebase,
12528: {'context' => 'rewrites',
12529: 'ignore_remote_references' => 1,});
12530: if (ref($mapping) eq 'HASH') {
12531: my $rewrites = 0;
12532: foreach my $key (keys(%{$mapping})) {
12533: next if ($key =~ m{^https?://});
12534: my $ref = $mapping->{$key};
12535: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12536: my $attrib;
12537: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12538: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12539: }
12540: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12541: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12542: $rewrites += $numchg;
12543: }
12544: }
12545: if ($rewrites) {
12546: my $saveresult;
12547: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12548: if ($url eq $container) {
12549: my ($fname) = ($container =~ m{/([^/]+)$});
12550: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12551: $count,'<span class="LC_filename">'.
12552: $fname.'</span>').'</p>';
12553: } else {
12554: $output .= '<p class="LC_error">'.
12555: &mt('Error: could not update links in [_1].',
12556: '<span class="LC_filename">'.
12557: $container.'</span>').'</p>';
12558:
12559: }
12560: }
12561: }
12562: }
1.987 raeburn 12563: } else {
12564: &logthis('Failed to parse '.$container.
12565: ' to modify references: '.$parse_result);
1.661 raeburn 12566: }
12567: }
1.1071 raeburn 12568: if (wantarray) {
12569: return ($output,$count,$codebasecount);
12570: } else {
12571: return $output;
12572: }
1.661 raeburn 12573: }
12574:
12575: sub check_for_existing {
12576: my ($path,$fname,$element) = @_;
12577: my ($state,$msg);
12578: if (-d $path.'/'.$fname) {
12579: $state = 'exists';
12580: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12581: } elsif (-e $path.'/'.$fname) {
12582: $state = 'exists';
12583: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12584: }
12585: if ($state eq 'exists') {
12586: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12587: }
12588: return ($state,$msg);
12589: }
12590:
12591: sub check_for_upload {
12592: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12593: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12594: my $filesize = length($env{'form.'.$element});
12595: if (!$filesize) {
12596: my $msg = '<span class="LC_error">'.
12597: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12598: '<span class="LC_filename">'.$fname.'</span>',
12599: $filesize).'<br />'.
1.1007 raeburn 12600: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12601: '</span>';
12602: return ('zero_bytes',$msg);
12603: }
12604: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12605: my $getpropath = 1;
1.1021 raeburn 12606: my ($dirlistref,$listerror) =
12607: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12608: my $found_file = 0;
12609: my $locked_file = 0;
1.991 raeburn 12610: my @lockers;
12611: my $navmap;
12612: if ($env{'request.course.id'}) {
12613: $navmap = Apache::lonnavmaps::navmap->new();
12614: }
1.1021 raeburn 12615: if (ref($dirlistref) eq 'ARRAY') {
12616: foreach my $line (@{$dirlistref}) {
12617: my ($file_name,$rest)=split(/\&/,$line,2);
12618: if ($file_name eq $fname){
12619: $file_name = $path.$file_name;
12620: if ($group ne '') {
12621: $file_name = $group.$file_name;
12622: }
12623: $found_file = 1;
12624: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12625: foreach my $lock (@lockers) {
12626: if (ref($lock) eq 'ARRAY') {
12627: my ($symb,$crsid) = @{$lock};
12628: if ($crsid eq $env{'request.course.id'}) {
12629: if (ref($navmap)) {
12630: my $res = $navmap->getBySymb($symb);
12631: foreach my $part (@{$res->parts()}) {
12632: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12633: unless (($slot_status == $res->RESERVED) ||
12634: ($slot_status == $res->RESERVED_LOCATION)) {
12635: $locked_file = 1;
12636: }
1.991 raeburn 12637: }
1.1021 raeburn 12638: } else {
12639: $locked_file = 1;
1.991 raeburn 12640: }
12641: } else {
12642: $locked_file = 1;
12643: }
12644: }
1.1021 raeburn 12645: }
12646: } else {
12647: my @info = split(/\&/,$rest);
12648: my $currsize = $info[6]/1000;
12649: if ($currsize < $filesize) {
12650: my $extra = $filesize - $currsize;
12651: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12652: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12653: &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 12654: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12655: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12656: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12657: return ('will_exceed_quota',$msg);
12658: }
1.984 raeburn 12659: }
12660: }
1.661 raeburn 12661: }
12662: }
12663: }
12664: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12665: my $msg = '<p class="LC_warning">'.
12666: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12667: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12668: return ('will_exceed_quota',$msg);
12669: } elsif ($found_file) {
12670: if ($locked_file) {
1.1179 bisitz 12671: my $msg = '<p class="LC_warning">';
1.661 raeburn 12672: $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 12673: $msg .= '</p>';
1.661 raeburn 12674: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12675: return ('file_locked',$msg);
12676: } else {
1.1179 bisitz 12677: my $msg = '<p class="LC_error">';
1.984 raeburn 12678: $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 12679: $msg .= '</p>';
1.984 raeburn 12680: return ('existingfile',$msg);
1.661 raeburn 12681: }
12682: }
12683: }
12684:
1.987 raeburn 12685: sub check_for_traversal {
12686: my ($path,$url,$toplevel) = @_;
12687: my @parts=split(/\//,$path);
12688: my $cleanpath;
12689: my $fullpath = $url;
12690: for (my $i=0;$i<@parts;$i++) {
12691: next if ($parts[$i] eq '.');
12692: if ($parts[$i] eq '..') {
12693: $fullpath =~ s{([^/]+/)$}{};
12694: } else {
12695: $fullpath .= $parts[$i].'/';
12696: }
12697: }
12698: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12699: $cleanpath = $1;
12700: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12701: my $curr_toprel = $1;
12702: my @parts = split(/\//,$curr_toprel);
12703: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12704: my @urlparts = split(/\//,$url_toprel);
12705: my $doubledots;
12706: my $startdiff = -1;
12707: for (my $i=0; $i<@urlparts; $i++) {
12708: if ($startdiff == -1) {
12709: unless ($urlparts[$i] eq $parts[$i]) {
12710: $startdiff = $i;
12711: $doubledots .= '../';
12712: }
12713: } else {
12714: $doubledots .= '../';
12715: }
12716: }
12717: if ($startdiff > -1) {
12718: $cleanpath = $doubledots;
12719: for (my $i=$startdiff; $i<@parts; $i++) {
12720: $cleanpath .= $parts[$i].'/';
12721: }
12722: }
12723: }
12724: $cleanpath =~ s{(/)$}{};
12725: return $cleanpath;
12726: }
1.31 albertel 12727:
1.1053 raeburn 12728: sub is_archive_file {
12729: my ($mimetype) = @_;
12730: if (($mimetype eq 'application/octet-stream') ||
12731: ($mimetype eq 'application/x-stuffit') ||
12732: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12733: return 1;
12734: }
12735: return;
12736: }
12737:
12738: sub decompress_form {
1.1065 raeburn 12739: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12740: my %lt = &Apache::lonlocal::texthash (
12741: this => 'This file is an archive file.',
1.1067 raeburn 12742: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12743: itsc => 'Its contents are as follows:',
1.1053 raeburn 12744: youm => 'You may wish to extract its contents.',
12745: extr => 'Extract contents',
1.1067 raeburn 12746: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12747: proa => 'Process automatically?',
1.1053 raeburn 12748: yes => 'Yes',
12749: no => 'No',
1.1067 raeburn 12750: fold => 'Title for folder containing movie',
12751: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12752: );
1.1065 raeburn 12753: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12754: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12755: my $info = &list_archive_contents($fileloc,\@paths);
12756: if (@paths) {
12757: foreach my $path (@paths) {
12758: $path =~ s{^/}{};
1.1067 raeburn 12759: if ($path =~ m{^([^/]+)/$}) {
12760: $topdir = $1;
12761: }
1.1065 raeburn 12762: if ($path =~ m{^([^/]+)/}) {
12763: $toplevel{$1} = $path;
12764: } else {
12765: $toplevel{$path} = $path;
12766: }
12767: }
12768: }
1.1067 raeburn 12769: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12770: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12771: "$topdir/media/",
12772: "$topdir/media/$topdir.mp4",
12773: "$topdir/media/FirstFrame.png",
12774: "$topdir/media/player.swf",
12775: "$topdir/media/swfobject.js",
12776: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12777: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12778: "$topdir/$topdir.mp4",
12779: "$topdir/$topdir\_config.xml",
12780: "$topdir/$topdir\_controller.swf",
12781: "$topdir/$topdir\_embed.css",
12782: "$topdir/$topdir\_First_Frame.png",
12783: "$topdir/$topdir\_player.html",
12784: "$topdir/$topdir\_Thumbnails.png",
12785: "$topdir/playerProductInstall.swf",
12786: "$topdir/scripts/",
12787: "$topdir/scripts/config_xml.js",
12788: "$topdir/scripts/handlebars.js",
12789: "$topdir/scripts/jquery-1.7.1.min.js",
12790: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12791: "$topdir/scripts/modernizr.js",
12792: "$topdir/scripts/player-min.js",
12793: "$topdir/scripts/swfobject.js",
12794: "$topdir/skins/",
12795: "$topdir/skins/configuration_express.xml",
12796: "$topdir/skins/express_show/",
12797: "$topdir/skins/express_show/player-min.css",
12798: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12799: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12800: "$topdir/$topdir.mp4",
12801: "$topdir/$topdir\_config.xml",
12802: "$topdir/$topdir\_controller.swf",
12803: "$topdir/$topdir\_embed.css",
12804: "$topdir/$topdir\_First_Frame.png",
12805: "$topdir/$topdir\_player.html",
12806: "$topdir/$topdir\_Thumbnails.png",
12807: "$topdir/playerProductInstall.swf",
12808: "$topdir/scripts/",
12809: "$topdir/scripts/config_xml.js",
12810: "$topdir/scripts/techsmith-smart-player.min.js",
12811: "$topdir/skins/",
12812: "$topdir/skins/configuration_express.xml",
12813: "$topdir/skins/express_show/",
12814: "$topdir/skins/express_show/spritesheet.min.css",
12815: "$topdir/skins/express_show/spritesheet.png",
12816: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12817: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12818: if (@diffs == 0) {
1.1164 raeburn 12819: $is_camtasia = 6;
12820: } else {
1.1197 raeburn 12821: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12822: if (@diffs == 0) {
12823: $is_camtasia = 8;
1.1197 raeburn 12824: } else {
12825: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12826: if (@diffs == 0) {
12827: $is_camtasia = 8;
12828: }
1.1164 raeburn 12829: }
1.1067 raeburn 12830: }
12831: }
12832: my $output;
12833: if ($is_camtasia) {
12834: $output = <<"ENDCAM";
12835: <script type="text/javascript" language="Javascript">
12836: // <![CDATA[
12837:
12838: function camtasiaToggle() {
12839: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12840: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12841: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12842: document.getElementById('camtasia_titles').style.display='block';
12843: } else {
12844: document.getElementById('camtasia_titles').style.display='none';
12845: }
12846: }
12847: }
12848: return;
12849: }
12850:
12851: // ]]>
12852: </script>
12853: <p>$lt{'camt'}</p>
12854: ENDCAM
1.1065 raeburn 12855: } else {
1.1067 raeburn 12856: $output = '<p>'.$lt{'this'};
12857: if ($info eq '') {
12858: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12859: } else {
12860: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12861: '<div><pre>'.$info.'</pre></div>';
12862: }
1.1065 raeburn 12863: }
1.1067 raeburn 12864: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12865: my $duplicates;
12866: my $num = 0;
12867: if (ref($dirlist) eq 'ARRAY') {
12868: foreach my $item (@{$dirlist}) {
12869: if (ref($item) eq 'ARRAY') {
12870: if (exists($toplevel{$item->[0]})) {
12871: $duplicates .=
12872: &start_data_table_row().
12873: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12874: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12875: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12876: 'value="1" />'.&mt('Yes').'</label>'.
12877: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12878: '<td>'.$item->[0].'</td>';
12879: if ($item->[2]) {
12880: $duplicates .= '<td>'.&mt('Directory').'</td>';
12881: } else {
12882: $duplicates .= '<td>'.&mt('File').'</td>';
12883: }
12884: $duplicates .= '<td>'.$item->[3].'</td>'.
12885: '<td>'.
12886: &Apache::lonlocal::locallocaltime($item->[4]).
12887: '</td>'.
12888: &end_data_table_row();
12889: $num ++;
12890: }
12891: }
12892: }
12893: }
12894: my $itemcount;
12895: if (@paths > 0) {
12896: $itemcount = scalar(@paths);
12897: } else {
12898: $itemcount = 1;
12899: }
1.1067 raeburn 12900: if ($is_camtasia) {
12901: $output .= $lt{'auto'}.'<br />'.
12902: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12903: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12904: $lt{'yes'}.'</label> <label>'.
12905: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12906: $lt{'no'}.'</label></span><br />'.
12907: '<div id="camtasia_titles" style="display:block">'.
12908: &Apache::lonhtmlcommon::start_pick_box().
12909: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12910: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12911: &Apache::lonhtmlcommon::row_closure().
12912: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12913: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12914: &Apache::lonhtmlcommon::row_closure(1).
12915: &Apache::lonhtmlcommon::end_pick_box().
12916: '</div>';
12917: }
1.1065 raeburn 12918: $output .=
12919: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12920: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12921: "\n";
1.1065 raeburn 12922: if ($duplicates ne '') {
12923: $output .= '<p><span class="LC_warning">'.
12924: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12925: &start_data_table().
12926: &start_data_table_header_row().
12927: '<th>'.&mt('Overwrite?').'</th>'.
12928: '<th>'.&mt('Name').'</th>'.
12929: '<th>'.&mt('Type').'</th>'.
12930: '<th>'.&mt('Size').'</th>'.
12931: '<th>'.&mt('Last modified').'</th>'.
12932: &end_data_table_header_row().
12933: $duplicates.
12934: &end_data_table().
12935: '</p>';
12936: }
1.1067 raeburn 12937: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12938: if (ref($hiddenelements) eq 'HASH') {
12939: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12940: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12941: }
12942: }
12943: $output .= <<"END";
1.1067 raeburn 12944: <br />
1.1053 raeburn 12945: <input type="submit" name="decompress" value="$lt{'extr'}" />
12946: </form>
12947: $noextract
12948: END
12949: return $output;
12950: }
12951:
1.1065 raeburn 12952: sub decompression_utility {
12953: my ($program) = @_;
12954: my @utilities = ('tar','gunzip','bunzip2','unzip');
12955: my $location;
12956: if (grep(/^\Q$program\E$/,@utilities)) {
12957: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12958: '/usr/sbin/') {
12959: if (-x $dir.$program) {
12960: $location = $dir.$program;
12961: last;
12962: }
12963: }
12964: }
12965: return $location;
12966: }
12967:
12968: sub list_archive_contents {
12969: my ($file,$pathsref) = @_;
12970: my (@cmd,$output);
12971: my $needsregexp;
12972: if ($file =~ /\.zip$/) {
12973: @cmd = (&decompression_utility('unzip'),"-l");
12974: $needsregexp = 1;
12975: } elsif (($file =~ m/\.tar\.gz$/) ||
12976: ($file =~ /\.tgz$/)) {
12977: @cmd = (&decompression_utility('tar'),"-ztf");
12978: } elsif ($file =~ /\.tar\.bz2$/) {
12979: @cmd = (&decompression_utility('tar'),"-jtf");
12980: } elsif ($file =~ m|\.tar$|) {
12981: @cmd = (&decompression_utility('tar'),"-tf");
12982: }
12983: if (@cmd) {
12984: undef($!);
12985: undef($@);
12986: if (open(my $fh,"-|", @cmd, $file)) {
12987: while (my $line = <$fh>) {
12988: $output .= $line;
12989: chomp($line);
12990: my $item;
12991: if ($needsregexp) {
12992: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12993: } else {
12994: $item = $line;
12995: }
12996: if ($item ne '') {
12997: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12998: push(@{$pathsref},$item);
12999: }
13000: }
13001: }
13002: close($fh);
13003: }
13004: }
13005: return $output;
13006: }
13007:
1.1053 raeburn 13008: sub decompress_uploaded_file {
13009: my ($file,$dir) = @_;
13010: &Apache::lonnet::appenv({'cgi.file' => $file});
13011: &Apache::lonnet::appenv({'cgi.dir' => $dir});
13012: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
13013: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
13014: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
13015: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
13016: my $decompressed = $env{'cgi.decompressed'};
13017: &Apache::lonnet::delenv('cgi.file');
13018: &Apache::lonnet::delenv('cgi.dir');
13019: &Apache::lonnet::delenv('cgi.decompressed');
13020: return ($decompressed,$result);
13021: }
13022:
1.1055 raeburn 13023: sub process_decompression {
13024: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 13025: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
13026: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13027: &mt('Unexpected file path.').'</p>'."\n";
13028: }
13029: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
13030: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13031: &mt('Unexpected course context.').'</p>'."\n";
13032: }
1.1293 raeburn 13033: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 13034: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13035: &mt('Filename contained unexpected characters.').'</p>'."\n";
13036: }
1.1055 raeburn 13037: my ($dir,$error,$warning,$output);
1.1180 raeburn 13038: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 13039: $error = &mt('Filename not a supported archive file type.').
13040: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 13041: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
13042: } else {
13043: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13044: if ($docuhome eq 'no_host') {
13045: $error = &mt('Could not determine home server for course.');
13046: } else {
13047: my @ids=&Apache::lonnet::current_machine_ids();
13048: my $currdir = "$dir_root/$destination";
13049: if (grep(/^\Q$docuhome\E$/,@ids)) {
13050: $dir = &LONCAPA::propath($docudom,$docuname).
13051: "$dir_root/$destination";
13052: } else {
13053: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
13054: "$dir_root/$docudom/$docuname/$destination";
13055: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
13056: $error = &mt('Archive file not found.');
13057: }
13058: }
1.1065 raeburn 13059: my (@to_overwrite,@to_skip);
13060: if ($env{'form.archive_overwrite_total'} > 0) {
13061: my $total = $env{'form.archive_overwrite_total'};
13062: for (my $i=0; $i<$total; $i++) {
13063: if ($env{'form.archive_overwrite_'.$i} == 1) {
13064: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
13065: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
13066: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
13067: }
13068: }
13069: }
13070: my $numskip = scalar(@to_skip);
1.1292 raeburn 13071: my $numoverwrite = scalar(@to_overwrite);
13072: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 13073: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
13074: } elsif ($dir eq '') {
1.1055 raeburn 13075: $error = &mt('Directory containing archive file unavailable.');
13076: } elsif (!$error) {
1.1065 raeburn 13077: my ($decompressed,$display);
1.1292 raeburn 13078: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 13079: my $tempdir = time.'_'.$$.int(rand(10000));
13080: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 13081: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
13082: ($decompressed,$display) =
13083: &decompress_uploaded_file($file,"$dir/$tempdir");
13084: foreach my $item (@to_skip) {
13085: if (($item ne '') && ($item !~ /\.\./)) {
13086: if (-f "$dir/$tempdir/$item") {
13087: unlink("$dir/$tempdir/$item");
13088: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 13089: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 13090: }
13091: }
13092: }
13093: foreach my $item (@to_overwrite) {
13094: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
13095: if (($item ne '') && ($item !~ /\.\./)) {
13096: if (-f "$dir/$item") {
13097: unlink("$dir/$item");
13098: } elsif (-d "$dir/$item") {
1.1300 raeburn 13099: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 13100: }
13101: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
13102: }
1.1065 raeburn 13103: }
13104: }
1.1292 raeburn 13105: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 13106: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 13107: }
1.1065 raeburn 13108: }
13109: } else {
13110: ($decompressed,$display) =
13111: &decompress_uploaded_file($file,$dir);
13112: }
1.1055 raeburn 13113: if ($decompressed eq 'ok') {
1.1065 raeburn 13114: $output = '<p class="LC_info">'.
13115: &mt('Files extracted successfully from archive.').
13116: '</p>'."\n";
1.1055 raeburn 13117: my ($warning,$result,@contents);
13118: my ($newdirlistref,$newlisterror) =
13119: &Apache::lonnet::dirlist($currdir,$docudom,
13120: $docuname,1);
13121: my (%is_dir,%changes,@newitems);
13122: my $dirptr = 16384;
1.1065 raeburn 13123: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 13124: foreach my $dir_line (@{$newdirlistref}) {
13125: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 13126: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 13127: push(@newitems,$item);
13128: if ($dirptr&$testdir) {
13129: $is_dir{$item} = 1;
13130: }
13131: $changes{$item} = 1;
13132: }
13133: }
13134: }
13135: if (keys(%changes) > 0) {
13136: foreach my $item (sort(@newitems)) {
13137: if ($changes{$item}) {
13138: push(@contents,$item);
13139: }
13140: }
13141: }
13142: if (@contents > 0) {
1.1067 raeburn 13143: my $wantform;
13144: unless ($env{'form.autoextract_camtasia'}) {
13145: $wantform = 1;
13146: }
1.1056 raeburn 13147: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 13148: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13149: $currdir,\%is_dir,
13150: \%children,\%parent,
1.1056 raeburn 13151: \@contents,\%dirorder,
13152: \%titles,$wantform);
1.1055 raeburn 13153: if ($datatable ne '') {
13154: $output .= &archive_options_form('decompressed',$datatable,
13155: $count,$hiddenelem);
1.1065 raeburn 13156: my $startcount = 6;
1.1055 raeburn 13157: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13158: \%titles,\%children);
1.1055 raeburn 13159: }
1.1067 raeburn 13160: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 13161: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13162: my %displayed;
13163: my $total = 1;
13164: $env{'form.archive_directory'} = [];
13165: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13166: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13167: $path =~ s{/$}{};
13168: my $item;
13169: if ($path ne '') {
13170: $item = "$path/$titles{$i}";
13171: } else {
13172: $item = $titles{$i};
13173: }
13174: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13175: if ($item eq $contents[0]) {
13176: push(@{$env{'form.archive_directory'}},$i);
13177: $env{'form.archive_'.$i} = 'display';
13178: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13179: $displayed{'folder'} = $i;
1.1164 raeburn 13180: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13181: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13182: $env{'form.archive_'.$i} = 'display';
13183: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13184: $displayed{'web'} = $i;
13185: } else {
1.1164 raeburn 13186: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13187: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13188: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13189: push(@{$env{'form.archive_directory'}},$i);
13190: }
13191: $env{'form.archive_'.$i} = 'dependency';
13192: }
13193: $total ++;
13194: }
13195: for (my $i=1; $i<$total; $i++) {
13196: next if ($i == $displayed{'web'});
13197: next if ($i == $displayed{'folder'});
13198: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13199: }
13200: $env{'form.phase'} = 'decompress_cleanup';
13201: $env{'form.archivedelete'} = 1;
13202: $env{'form.archive_count'} = $total-1;
13203: $output .=
13204: &process_extracted_files('coursedocs',$docudom,
13205: $docuname,$destination,
13206: $dir_root,$hiddenelem);
13207: }
1.1055 raeburn 13208: } else {
13209: $warning = &mt('No new items extracted from archive file.');
13210: }
13211: } else {
13212: $output = $display;
13213: $error = &mt('An error occurred during extraction from the archive file.');
13214: }
13215: }
13216: }
13217: }
13218: if ($error) {
13219: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13220: $error.'</p>'."\n";
13221: }
13222: if ($warning) {
13223: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13224: }
13225: return $output;
13226: }
13227:
13228: sub get_extracted {
1.1056 raeburn 13229: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13230: $titles,$wantform) = @_;
1.1055 raeburn 13231: my $count = 0;
13232: my $depth = 0;
13233: my $datatable;
1.1056 raeburn 13234: my @hierarchy;
1.1055 raeburn 13235: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13236: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13237: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13238: foreach my $item (@{$contents}) {
13239: $count ++;
1.1056 raeburn 13240: @{$dirorder->{$count}} = @hierarchy;
13241: $titles->{$count} = $item;
1.1055 raeburn 13242: &archive_hierarchy($depth,$count,$parent,$children);
13243: if ($wantform) {
13244: $datatable .= &archive_row($is_dir->{$item},$item,
13245: $currdir,$depth,$count);
13246: }
13247: if ($is_dir->{$item}) {
13248: $depth ++;
1.1056 raeburn 13249: push(@hierarchy,$count);
13250: $parent->{$depth} = $count;
1.1055 raeburn 13251: $datatable .=
13252: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13253: \$depth,\$count,\@hierarchy,$dirorder,
13254: $children,$parent,$titles,$wantform);
1.1055 raeburn 13255: $depth --;
1.1056 raeburn 13256: pop(@hierarchy);
1.1055 raeburn 13257: }
13258: }
13259: return ($count,$datatable);
13260: }
13261:
13262: sub recurse_extracted_archive {
1.1056 raeburn 13263: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13264: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13265: my $result='';
1.1056 raeburn 13266: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13267: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13268: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13269: return $result;
13270: }
13271: my $dirptr = 16384;
13272: my ($newdirlistref,$newlisterror) =
13273: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13274: if (ref($newdirlistref) eq 'ARRAY') {
13275: foreach my $dir_line (@{$newdirlistref}) {
13276: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13277: unless ($item =~ /^\.+$/) {
13278: $$count ++;
1.1056 raeburn 13279: @{$dirorder->{$$count}} = @{$hierarchy};
13280: $titles->{$$count} = $item;
1.1055 raeburn 13281: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13282:
1.1055 raeburn 13283: my $is_dir;
13284: if ($dirptr&$testdir) {
13285: $is_dir = 1;
13286: }
13287: if ($wantform) {
13288: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13289: }
13290: if ($is_dir) {
13291: $$depth ++;
1.1056 raeburn 13292: push(@{$hierarchy},$$count);
13293: $parent->{$$depth} = $$count;
1.1055 raeburn 13294: $result .=
13295: &recurse_extracted_archive("$currdir/$item",$docudom,
13296: $docuname,$depth,$count,
1.1056 raeburn 13297: $hierarchy,$dirorder,$children,
13298: $parent,$titles,$wantform);
1.1055 raeburn 13299: $$depth --;
1.1056 raeburn 13300: pop(@{$hierarchy});
1.1055 raeburn 13301: }
13302: }
13303: }
13304: }
13305: return $result;
13306: }
13307:
13308: sub archive_hierarchy {
13309: my ($depth,$count,$parent,$children) =@_;
13310: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13311: if (exists($parent->{$depth})) {
13312: $children->{$parent->{$depth}} .= $count.':';
13313: }
13314: }
13315: return;
13316: }
13317:
13318: sub archive_row {
13319: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13320: my ($name) = ($item =~ m{([^/]+)$});
13321: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13322: 'display' => 'Add as file',
1.1055 raeburn 13323: 'dependency' => 'Include as dependency',
13324: 'discard' => 'Discard',
13325: );
13326: if ($is_dir) {
1.1059 raeburn 13327: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13328: }
1.1056 raeburn 13329: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13330: my $offset = 0;
1.1055 raeburn 13331: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13332: $offset ++;
1.1065 raeburn 13333: if ($action ne 'display') {
13334: $offset ++;
13335: }
1.1055 raeburn 13336: $output .= '<td><span class="LC_nobreak">'.
13337: '<label><input type="radio" name="archive_'.$count.
13338: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13339: my $text = $choices{$action};
13340: if ($is_dir) {
13341: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13342: if ($action eq 'display') {
1.1059 raeburn 13343: $text = &mt('Add as folder');
1.1055 raeburn 13344: }
1.1056 raeburn 13345: } else {
13346: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13347:
13348: }
13349: $output .= ' /> '.$choices{$action}.'</label></span>';
13350: if ($action eq 'dependency') {
13351: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13352: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13353: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13354: '<option value=""></option>'."\n".
13355: '</select>'."\n".
13356: '</div>';
1.1059 raeburn 13357: } elsif ($action eq 'display') {
13358: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13359: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13360: '</div>';
1.1055 raeburn 13361: }
1.1056 raeburn 13362: $output .= '</td>';
1.1055 raeburn 13363: }
13364: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13365: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13366: for (my $i=0; $i<$depth; $i++) {
13367: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13368: }
13369: if ($is_dir) {
13370: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13371: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13372: } else {
13373: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13374: }
13375: $output .= ' '.$name.'</td>'."\n".
13376: &end_data_table_row();
13377: return $output;
13378: }
13379:
13380: sub archive_options_form {
1.1065 raeburn 13381: my ($form,$display,$count,$hiddenelem) = @_;
13382: my %lt = &Apache::lonlocal::texthash(
13383: perm => 'Permanently remove archive file?',
13384: hows => 'How should each extracted item be incorporated in the course?',
13385: cont => 'Content actions for all',
13386: addf => 'Add as folder/file',
13387: incd => 'Include as dependency for a displayed file',
13388: disc => 'Discard',
13389: no => 'No',
13390: yes => 'Yes',
13391: save => 'Save',
13392: );
13393: my $output = <<"END";
13394: <form name="$form" method="post" action="">
13395: <p><span class="LC_nobreak">$lt{'perm'}
13396: <label>
13397: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13398: </label>
13399:
13400: <label>
13401: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13402: </span>
13403: </p>
13404: <input type="hidden" name="phase" value="decompress_cleanup" />
13405: <br />$lt{'hows'}
13406: <div class="LC_columnSection">
13407: <fieldset>
13408: <legend>$lt{'cont'}</legend>
13409: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13410: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13411: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13412: </fieldset>
13413: </div>
13414: END
13415: return $output.
1.1055 raeburn 13416: &start_data_table()."\n".
1.1065 raeburn 13417: $display."\n".
1.1055 raeburn 13418: &end_data_table()."\n".
13419: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13420: $hiddenelem.
1.1065 raeburn 13421: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13422: '</form>';
13423: }
13424:
13425: sub archive_javascript {
1.1056 raeburn 13426: my ($startcount,$numitems,$titles,$children) = @_;
13427: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13428: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13429: my $scripttag = <<START;
13430: <script type="text/javascript">
13431: // <![CDATA[
13432:
13433: function checkAll(form,prefix) {
13434: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13435: for (var i=0; i < form.elements.length; i++) {
13436: var id = form.elements[i].id;
13437: if ((id != '') && (id != undefined)) {
13438: if (idstr.test(id)) {
13439: if (form.elements[i].type == 'radio') {
13440: form.elements[i].checked = true;
1.1056 raeburn 13441: var nostart = i-$startcount;
1.1059 raeburn 13442: var offset = nostart%7;
13443: var count = (nostart-offset)/7;
1.1056 raeburn 13444: dependencyCheck(form,count,offset);
1.1055 raeburn 13445: }
13446: }
13447: }
13448: }
13449: }
13450:
13451: function propagateCheck(form,count) {
13452: if (count > 0) {
1.1059 raeburn 13453: var startelement = $startcount + ((count-1) * 7);
13454: for (var j=1; j<6; j++) {
13455: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13456: var item = startelement + j;
13457: if (form.elements[item].type == 'radio') {
13458: if (form.elements[item].checked) {
13459: containerCheck(form,count,j);
13460: break;
13461: }
1.1055 raeburn 13462: }
13463: }
13464: }
13465: }
13466: }
13467:
13468: numitems = $numitems
1.1056 raeburn 13469: var titles = new Array(numitems);
13470: var parents = new Array(numitems);
1.1055 raeburn 13471: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13472: parents[i] = new Array;
1.1055 raeburn 13473: }
1.1059 raeburn 13474: var maintitle = '$maintitle';
1.1055 raeburn 13475:
13476: START
13477:
1.1056 raeburn 13478: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13479: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13480: for (my $i=0; $i<@contents; $i ++) {
13481: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13482: }
13483: }
13484:
1.1056 raeburn 13485: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13486: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13487: }
13488:
1.1055 raeburn 13489: $scripttag .= <<END;
13490:
13491: function containerCheck(form,count,offset) {
13492: if (count > 0) {
1.1056 raeburn 13493: dependencyCheck(form,count,offset);
1.1059 raeburn 13494: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13495: form.elements[item].checked = true;
13496: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13497: if (parents[count].length > 0) {
13498: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13499: containerCheck(form,parents[count][j],offset);
13500: }
13501: }
13502: }
13503: }
13504: }
13505:
13506: function dependencyCheck(form,count,offset) {
13507: if (count > 0) {
1.1059 raeburn 13508: var chosen = (offset+$startcount)+7*(count-1);
13509: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13510: var currtype = form.elements[depitem].type;
13511: if (form.elements[chosen].value == 'dependency') {
13512: document.getElementById('arc_depon_'+count).style.display='block';
13513: form.elements[depitem].options.length = 0;
13514: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13515: for (var i=1; i<=numitems; i++) {
13516: if (i == count) {
13517: continue;
13518: }
1.1059 raeburn 13519: var startelement = $startcount + (i-1) * 7;
13520: for (var j=1; j<6; j++) {
13521: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13522: var item = startelement + j;
13523: if (form.elements[item].type == 'radio') {
13524: if (form.elements[item].checked) {
13525: if (form.elements[item].value == 'display') {
13526: var n = form.elements[depitem].options.length;
13527: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13528: }
13529: }
13530: }
13531: }
13532: }
13533: }
13534: } else {
13535: document.getElementById('arc_depon_'+count).style.display='none';
13536: form.elements[depitem].options.length = 0;
13537: form.elements[depitem].options[0] = new Option('Select','',true,true);
13538: }
1.1059 raeburn 13539: titleCheck(form,count,offset);
1.1056 raeburn 13540: }
13541: }
13542:
13543: function propagateSelect(form,count,offset) {
13544: if (count > 0) {
1.1065 raeburn 13545: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13546: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13547: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13548: if (parents[count].length > 0) {
13549: for (var j=0; j<parents[count].length; j++) {
13550: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13551: }
13552: }
13553: }
13554: }
13555: }
1.1056 raeburn 13556:
13557: function containerSelect(form,count,offset,picked) {
13558: if (count > 0) {
1.1065 raeburn 13559: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13560: if (form.elements[item].type == 'radio') {
13561: if (form.elements[item].value == 'dependency') {
13562: if (form.elements[item+1].type == 'select-one') {
13563: for (var i=0; i<form.elements[item+1].options.length; i++) {
13564: if (form.elements[item+1].options[i].value == picked) {
13565: form.elements[item+1].selectedIndex = i;
13566: break;
13567: }
13568: }
13569: }
13570: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13571: if (parents[count].length > 0) {
13572: for (var j=0; j<parents[count].length; j++) {
13573: containerSelect(form,parents[count][j],offset,picked);
13574: }
13575: }
13576: }
13577: }
13578: }
13579: }
13580: }
13581:
1.1059 raeburn 13582: function titleCheck(form,count,offset) {
13583: if (count > 0) {
13584: var chosen = (offset+$startcount)+7*(count-1);
13585: var depitem = $startcount + ((count-1) * 7) + 2;
13586: var currtype = form.elements[depitem].type;
13587: if (form.elements[chosen].value == 'display') {
13588: document.getElementById('arc_title_'+count).style.display='block';
13589: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13590: document.getElementById('archive_title_'+count).value=maintitle;
13591: }
13592: } else {
13593: document.getElementById('arc_title_'+count).style.display='none';
13594: if (currtype == 'text') {
13595: document.getElementById('archive_title_'+count).value='';
13596: }
13597: }
13598: }
13599: return;
13600: }
13601:
1.1055 raeburn 13602: // ]]>
13603: </script>
13604: END
13605: return $scripttag;
13606: }
13607:
13608: sub process_extracted_files {
1.1067 raeburn 13609: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13610: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 13611: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13612: my @ids=&Apache::lonnet::current_machine_ids();
13613: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13614: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13615: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13616: if (grep(/^\Q$docuhome\E$/,@ids)) {
13617: $prefix = &LONCAPA::propath($docudom,$docuname);
13618: $pathtocheck = "$dir_root/$destination";
13619: $dir = $dir_root;
13620: $ishome = 1;
13621: } else {
13622: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13623: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 13624: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13625: }
13626: my $currdir = "$dir_root/$destination";
13627: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13628: if ($env{'form.folderpath'}) {
13629: my @items = split('&',$env{'form.folderpath'});
13630: $folders{'0'} = $items[-2];
1.1099 raeburn 13631: if ($env{'form.folderpath'} =~ /\:1$/) {
13632: $containers{'0'}='page';
13633: } else {
13634: $containers{'0'}='sequence';
13635: }
1.1055 raeburn 13636: }
13637: my @archdirs = &get_env_multiple('form.archive_directory');
13638: if ($numitems) {
13639: for (my $i=1; $i<=$numitems; $i++) {
13640: my $path = $env{'form.archive_content_'.$i};
13641: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13642: my $item = $1;
13643: $toplevelitems{$item} = $i;
13644: if (grep(/^\Q$i\E$/,@archdirs)) {
13645: $is_dir{$item} = 1;
13646: }
13647: }
13648: }
13649: }
1.1067 raeburn 13650: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13651: if (keys(%toplevelitems) > 0) {
13652: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13653: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13654: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13655: }
1.1066 raeburn 13656: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13657: if ($numitems) {
13658: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13659: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13660: my $path = $env{'form.archive_content_'.$i};
13661: if ($path =~ /^\Q$pathtocheck\E/) {
13662: if ($env{'form.archive_'.$i} eq 'discard') {
13663: if ($prefix ne '' && $path ne '') {
13664: if (-e $prefix.$path) {
1.1066 raeburn 13665: if ((@archdirs > 0) &&
13666: (grep(/^\Q$i\E$/,@archdirs))) {
13667: $todeletedir{$prefix.$path} = 1;
13668: } else {
13669: $todelete{$prefix.$path} = 1;
13670: }
1.1055 raeburn 13671: }
13672: }
13673: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13674: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13675: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13676: $docstitle = $env{'form.archive_title_'.$i};
13677: if ($docstitle eq '') {
13678: $docstitle = $title;
13679: }
1.1055 raeburn 13680: $outer = 0;
1.1056 raeburn 13681: if (ref($dirorder{$i}) eq 'ARRAY') {
13682: if (@{$dirorder{$i}} > 0) {
13683: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13684: if ($env{'form.archive_'.$item} eq 'display') {
13685: $outer = $item;
13686: last;
13687: }
13688: }
13689: }
13690: }
13691: my ($errtext,$fatal) =
13692: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13693: '/'.$folders{$outer}.'.'.
13694: $containers{$outer});
13695: next if ($fatal);
13696: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13697: if ($context eq 'coursedocs') {
1.1056 raeburn 13698: $mapinner{$i} = time;
1.1055 raeburn 13699: $folders{$i} = 'default_'.$mapinner{$i};
13700: $containers{$i} = 'sequence';
13701: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13702: $folders{$i}.'.'.$containers{$i};
13703: my $newidx = &LONCAPA::map::getresidx();
13704: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13705: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13706: push(@LONCAPA::map::order,$newidx);
13707: my ($outtext,$errtext) =
13708: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13709: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13710: '.'.$containers{$outer},1,1);
1.1056 raeburn 13711: $newseqid{$i} = $newidx;
1.1067 raeburn 13712: unless ($errtext) {
1.1294 raeburn 13713: $result .= '<li>'.&mt('Folder: [_1] added to course',
13714: &HTML::Entities::encode($docstitle,'<>&"')).
13715: '</li>'."\n";
1.1067 raeburn 13716: }
1.1055 raeburn 13717: }
13718: } else {
13719: if ($context eq 'coursedocs') {
13720: my $newidx=&LONCAPA::map::getresidx();
13721: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13722: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13723: $title;
1.1294 raeburn 13724: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
13725: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13726: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13727: }
13728: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13729: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13730: }
13731: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13732: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13733: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13734: unless ($ishome) {
13735: my $fetch = "$newdest{$i}/$title";
13736: $fetch =~ s/^\Q$prefix$dir\E//;
13737: $prompttofetch{$fetch} = 1;
13738: }
1.1292 raeburn 13739: }
1.1067 raeburn 13740: }
1.1294 raeburn 13741: $LONCAPA::map::resources[$newidx]=
13742: $docstitle.':'.$url.':false:normal:res';
13743: push(@LONCAPA::map::order, $newidx);
13744: my ($outtext,$errtext)=
13745: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13746: $docuname.'/'.$folders{$outer}.
13747: '.'.$containers{$outer},1,1);
13748: unless ($errtext) {
13749: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13750: $result .= '<li>'.&mt('File: [_1] added to course',
13751: &HTML::Entities::encode($docstitle,'<>&"')).
13752: '</li>'."\n";
13753: }
1.1067 raeburn 13754: }
1.1294 raeburn 13755: } else {
13756: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13757: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 13758: }
1.1055 raeburn 13759: }
13760: }
1.1086 raeburn 13761: }
13762: } else {
1.1294 raeburn 13763: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13764: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 13765: }
13766: }
13767: for (my $i=1; $i<=$numitems; $i++) {
13768: next unless ($env{'form.archive_'.$i} eq 'dependency');
13769: my $path = $env{'form.archive_content_'.$i};
13770: if ($path =~ /^\Q$pathtocheck\E/) {
13771: my ($title) = ($path =~ m{/([^/]+)$});
13772: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13773: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13774: if (ref($dirorder{$i}) eq 'ARRAY') {
13775: my ($itemidx,$fullpath,$relpath);
13776: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13777: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13778: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13779: if ($dirorder{$i}->[$j] eq $container) {
13780: $itemidx = $j;
1.1056 raeburn 13781: }
13782: }
1.1086 raeburn 13783: }
13784: if ($itemidx eq '') {
13785: $itemidx = 0;
13786: }
13787: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13788: if ($mapinner{$referrer{$i}}) {
13789: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13790: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13791: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13792: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13793: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13794: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13795: if (!-e $fullpath) {
13796: mkdir($fullpath,0755);
1.1056 raeburn 13797: }
13798: }
1.1086 raeburn 13799: } else {
13800: last;
1.1056 raeburn 13801: }
1.1086 raeburn 13802: }
13803: }
13804: } elsif ($newdest{$referrer{$i}}) {
13805: $fullpath = $newdest{$referrer{$i}};
13806: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13807: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13808: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13809: last;
13810: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13811: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13812: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13813: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13814: if (!-e $fullpath) {
13815: mkdir($fullpath,0755);
1.1056 raeburn 13816: }
13817: }
1.1086 raeburn 13818: } else {
13819: last;
1.1056 raeburn 13820: }
1.1055 raeburn 13821: }
13822: }
1.1086 raeburn 13823: if ($fullpath ne '') {
13824: if (-e "$prefix$path") {
1.1292 raeburn 13825: unless (rename("$prefix$path","$fullpath/$title")) {
13826: $warning .= &mt('Failed to rename dependency').'<br />';
13827: }
1.1086 raeburn 13828: }
13829: if (-e "$fullpath/$title") {
13830: my $showpath;
13831: if ($relpath ne '') {
13832: $showpath = "$relpath/$title";
13833: } else {
13834: $showpath = "/$title";
13835: }
1.1294 raeburn 13836: $result .= '<li>'.&mt('[_1] included as a dependency',
13837: &HTML::Entities::encode($showpath,'<>&"')).
13838: '</li>'."\n";
1.1292 raeburn 13839: unless ($ishome) {
13840: my $fetch = "$fullpath/$title";
13841: $fetch =~ s/^\Q$prefix$dir\E//;
13842: $prompttofetch{$fetch} = 1;
13843: }
1.1086 raeburn 13844: }
13845: }
1.1055 raeburn 13846: }
1.1086 raeburn 13847: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13848: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 13849: &HTML::Entities::encode($path,'<>&"'),
13850: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13851: '<br />';
1.1055 raeburn 13852: }
13853: } else {
1.1294 raeburn 13854: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 13855: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13856: }
13857: }
13858: if (keys(%todelete)) {
13859: foreach my $key (keys(%todelete)) {
13860: unlink($key);
1.1066 raeburn 13861: }
13862: }
13863: if (keys(%todeletedir)) {
13864: foreach my $key (keys(%todeletedir)) {
13865: rmdir($key);
13866: }
13867: }
13868: foreach my $dir (sort(keys(%is_dir))) {
13869: if (($pathtocheck ne '') && ($dir ne '')) {
13870: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13871: }
13872: }
1.1067 raeburn 13873: if ($result ne '') {
13874: $output .= '<ul>'."\n".
13875: $result."\n".
13876: '</ul>';
13877: }
13878: unless ($ishome) {
13879: my $replicationfail;
13880: foreach my $item (keys(%prompttofetch)) {
13881: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13882: unless ($fetchresult eq 'ok') {
13883: $replicationfail .= '<li>'.$item.'</li>'."\n";
13884: }
13885: }
13886: if ($replicationfail) {
13887: $output .= '<p class="LC_error">'.
13888: &mt('Course home server failed to retrieve:').'<ul>'.
13889: $replicationfail.
13890: '</ul></p>';
13891: }
13892: }
1.1055 raeburn 13893: } else {
13894: $warning = &mt('No items found in archive.');
13895: }
13896: if ($error) {
13897: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13898: $error.'</p>'."\n";
13899: }
13900: if ($warning) {
13901: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13902: }
13903: return $output;
13904: }
13905:
1.1066 raeburn 13906: sub cleanup_empty_dirs {
13907: my ($path) = @_;
13908: if (($path ne '') && (-d $path)) {
13909: if (opendir(my $dirh,$path)) {
13910: my @dircontents = grep(!/^\./,readdir($dirh));
13911: my $numitems = 0;
13912: foreach my $item (@dircontents) {
13913: if (-d "$path/$item") {
1.1111 raeburn 13914: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13915: if (-e "$path/$item") {
13916: $numitems ++;
13917: }
13918: } else {
13919: $numitems ++;
13920: }
13921: }
13922: if ($numitems == 0) {
13923: rmdir($path);
13924: }
13925: closedir($dirh);
13926: }
13927: }
13928: return;
13929: }
13930:
1.41 ng 13931: =pod
1.45 matthew 13932:
1.1162 raeburn 13933: =item * &get_folder_hierarchy()
1.1068 raeburn 13934:
13935: Provides hierarchy of names of folders/sub-folders containing the current
13936: item,
13937:
13938: Inputs: 3
13939: - $navmap - navmaps object
13940:
13941: - $map - url for map (either the trigger itself, or map containing
13942: the resource, which is the trigger).
13943:
13944: - $showitem - 1 => show title for map itself; 0 => do not show.
13945:
13946: Outputs: 1 @pathitems - array of folder/subfolder names.
13947:
13948: =cut
13949:
13950: sub get_folder_hierarchy {
13951: my ($navmap,$map,$showitem) = @_;
13952: my @pathitems;
13953: if (ref($navmap)) {
13954: my $mapres = $navmap->getResourceByUrl($map);
13955: if (ref($mapres)) {
13956: my $pcslist = $mapres->map_hierarchy();
13957: if ($pcslist ne '') {
13958: my @pcs = split(/,/,$pcslist);
13959: foreach my $pc (@pcs) {
13960: if ($pc == 1) {
1.1129 raeburn 13961: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13962: } else {
13963: my $res = $navmap->getByMapPc($pc);
13964: if (ref($res)) {
13965: my $title = $res->compTitle();
13966: $title =~ s/\W+/_/g;
13967: if ($title ne '') {
13968: push(@pathitems,$title);
13969: }
13970: }
13971: }
13972: }
13973: }
1.1071 raeburn 13974: if ($showitem) {
13975: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 13976: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13977: } else {
13978: my $maptitle = $mapres->compTitle();
13979: $maptitle =~ s/\W+/_/g;
13980: if ($maptitle ne '') {
13981: push(@pathitems,$maptitle);
13982: }
1.1068 raeburn 13983: }
13984: }
13985: }
13986: }
13987: return @pathitems;
13988: }
13989:
13990: =pod
13991:
1.1015 raeburn 13992: =item * &get_turnedin_filepath()
13993:
13994: Determines path in a user's portfolio file for storage of files uploaded
13995: to a specific essayresponse or dropbox item.
13996:
13997: Inputs: 3 required + 1 optional.
13998: $symb is symb for resource, $uname and $udom are for current user (required).
13999: $caller is optional (can be "submission", if routine is called when storing
14000: an upoaded file when "Submit Answer" button was pressed).
14001:
14002: Returns array containing $path and $multiresp.
14003: $path is path in portfolio. $multiresp is 1 if this resource contains more
14004: than one file upload item. Callers of routine should append partid as a
14005: subdirectory to $path in cases where $multiresp is 1.
14006:
14007: Called by: homework/essayresponse.pm and homework/structuretags.pm
14008:
14009: =cut
14010:
14011: sub get_turnedin_filepath {
14012: my ($symb,$uname,$udom,$caller) = @_;
14013: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
14014: my $turnindir;
14015: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
14016: $turnindir = $userhash{'turnindir'};
14017: my ($path,$multiresp);
14018: if ($turnindir eq '') {
14019: if ($caller eq 'submission') {
14020: $turnindir = &mt('turned in');
14021: $turnindir =~ s/\W+/_/g;
14022: my %newhash = (
14023: 'turnindir' => $turnindir,
14024: );
14025: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
14026: }
14027: }
14028: if ($turnindir ne '') {
14029: $path = '/'.$turnindir.'/';
14030: my ($multipart,$turnin,@pathitems);
14031: my $navmap = Apache::lonnavmaps::navmap->new();
14032: if (defined($navmap)) {
14033: my $mapres = $navmap->getResourceByUrl($map);
14034: if (ref($mapres)) {
14035: my $pcslist = $mapres->map_hierarchy();
14036: if ($pcslist ne '') {
14037: foreach my $pc (split(/,/,$pcslist)) {
14038: my $res = $navmap->getByMapPc($pc);
14039: if (ref($res)) {
14040: my $title = $res->compTitle();
14041: $title =~ s/\W+/_/g;
14042: if ($title ne '') {
1.1149 raeburn 14043: if (($pc > 1) && (length($title) > 12)) {
14044: $title = substr($title,0,12);
14045: }
1.1015 raeburn 14046: push(@pathitems,$title);
14047: }
14048: }
14049: }
14050: }
14051: my $maptitle = $mapres->compTitle();
14052: $maptitle =~ s/\W+/_/g;
14053: if ($maptitle ne '') {
1.1149 raeburn 14054: if (length($maptitle) > 12) {
14055: $maptitle = substr($maptitle,0,12);
14056: }
1.1015 raeburn 14057: push(@pathitems,$maptitle);
14058: }
14059: unless ($env{'request.state'} eq 'construct') {
14060: my $res = $navmap->getBySymb($symb);
14061: if (ref($res)) {
14062: my $partlist = $res->parts();
14063: my $totaluploads = 0;
14064: if (ref($partlist) eq 'ARRAY') {
14065: foreach my $part (@{$partlist}) {
14066: my @types = $res->responseType($part);
14067: my @ids = $res->responseIds($part);
14068: for (my $i=0; $i < scalar(@ids); $i++) {
14069: if ($types[$i] eq 'essay') {
14070: my $partid = $part.'_'.$ids[$i];
14071: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
14072: $totaluploads ++;
14073: }
14074: }
14075: }
14076: }
14077: if ($totaluploads > 1) {
14078: $multiresp = 1;
14079: }
14080: }
14081: }
14082: }
14083: } else {
14084: return;
14085: }
14086: } else {
14087: return;
14088: }
14089: my $restitle=&Apache::lonnet::gettitle($symb);
14090: $restitle =~ s/\W+/_/g;
14091: if ($restitle eq '') {
14092: $restitle = ($resurl =~ m{/[^/]+$});
14093: if ($restitle eq '') {
14094: $restitle = time;
14095: }
14096: }
1.1149 raeburn 14097: if (length($restitle) > 12) {
14098: $restitle = substr($restitle,0,12);
14099: }
1.1015 raeburn 14100: push(@pathitems,$restitle);
14101: $path .= join('/',@pathitems);
14102: }
14103: return ($path,$multiresp);
14104: }
14105:
14106: =pod
14107:
1.464 albertel 14108: =back
1.41 ng 14109:
1.112 bowersj2 14110: =head1 CSV Upload/Handling functions
1.38 albertel 14111:
1.41 ng 14112: =over 4
14113:
1.648 raeburn 14114: =item * &upfile_store($r)
1.41 ng 14115:
14116: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 14117: needs $env{'form.upfile'}
1.41 ng 14118: returns $datatoken to be put into hidden field
14119:
14120: =cut
1.31 albertel 14121:
14122: sub upfile_store {
14123: my $r=shift;
1.258 albertel 14124: $env{'form.upfile'}=~s/\r/\n/gs;
14125: $env{'form.upfile'}=~s/\f/\n/gs;
14126: $env{'form.upfile'}=~s/\n+/\n/gs;
14127: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 14128:
1.1299 raeburn 14129: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
14130: '_enroll_'.$env{'request.course.id'}.'_'.
14131: time.'_'.$$);
14132: return if ($datatoken eq '');
14133:
1.31 albertel 14134: {
1.158 raeburn 14135: my $datafile = $r->dir_config('lonDaemons').
14136: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14137: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 14138: print $fh $env{'form.upfile'};
1.158 raeburn 14139: close($fh);
14140: }
1.31 albertel 14141: }
14142: return $datatoken;
14143: }
14144:
1.56 matthew 14145: =pod
14146:
1.1290 raeburn 14147: =item * &load_tmp_file($r,$datatoken)
1.41 ng 14148:
14149: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 14150: $datatoken is the name to assign to the temporary file.
1.258 albertel 14151: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14152:
14153: =cut
1.31 albertel 14154:
14155: sub load_tmp_file {
1.1290 raeburn 14156: my ($r,$datatoken) = @_;
14157: return if ($datatoken eq '');
1.31 albertel 14158: my @studentdata=();
14159: {
1.158 raeburn 14160: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 14161: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14162: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14163: @studentdata=<$fh>;
14164: close($fh);
14165: }
1.31 albertel 14166: }
1.258 albertel 14167: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14168: }
14169:
1.1290 raeburn 14170: sub valid_datatoken {
14171: my ($datatoken) = @_;
1.1325 raeburn 14172: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1290 raeburn 14173: return $datatoken;
14174: }
14175: return;
14176: }
14177:
1.56 matthew 14178: =pod
14179:
1.648 raeburn 14180: =item * &upfile_record_sep()
1.41 ng 14181:
14182: Separate uploaded file into records
14183: returns array of records,
1.258 albertel 14184: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14185:
14186: =cut
1.31 albertel 14187:
14188: sub upfile_record_sep {
1.258 albertel 14189: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14190: } else {
1.248 albertel 14191: my @records;
1.258 albertel 14192: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14193: if ($line=~/^\s*$/) { next; }
14194: push(@records,$line);
14195: }
14196: return @records;
1.31 albertel 14197: }
14198: }
14199:
1.56 matthew 14200: =pod
14201:
1.648 raeburn 14202: =item * &record_sep($record)
1.41 ng 14203:
1.258 albertel 14204: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14205:
14206: =cut
14207:
1.263 www 14208: sub takeleft {
14209: my $index=shift;
14210: return substr('0000'.$index,-4,4);
14211: }
14212:
1.31 albertel 14213: sub record_sep {
14214: my $record=shift;
14215: my %components=();
1.258 albertel 14216: if ($env{'form.upfiletype'} eq 'xml') {
14217: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14218: my $i=0;
1.356 albertel 14219: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14220: $field=~s/^(\"|\')//;
14221: $field=~s/(\"|\')$//;
1.263 www 14222: $components{&takeleft($i)}=$field;
1.31 albertel 14223: $i++;
14224: }
1.258 albertel 14225: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14226: my $i=0;
1.356 albertel 14227: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14228: $field=~s/^(\"|\')//;
14229: $field=~s/(\"|\')$//;
1.263 www 14230: $components{&takeleft($i)}=$field;
1.31 albertel 14231: $i++;
14232: }
14233: } else {
1.561 www 14234: my $separator=',';
1.480 banghart 14235: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14236: $separator=';';
1.480 banghart 14237: }
1.31 albertel 14238: my $i=0;
1.561 www 14239: # the character we are looking for to indicate the end of a quote or a record
14240: my $looking_for=$separator;
14241: # do not add the characters to the fields
14242: my $ignore=0;
14243: # we just encountered a separator (or the beginning of the record)
14244: my $just_found_separator=1;
14245: # store the field we are working on here
14246: my $field='';
14247: # work our way through all characters in record
14248: foreach my $character ($record=~/(.)/g) {
14249: if ($character eq $looking_for) {
14250: if ($character ne $separator) {
14251: # Found the end of a quote, again looking for separator
14252: $looking_for=$separator;
14253: $ignore=1;
14254: } else {
14255: # Found a separator, store away what we got
14256: $components{&takeleft($i)}=$field;
14257: $i++;
14258: $just_found_separator=1;
14259: $ignore=0;
14260: $field='';
14261: }
14262: next;
14263: }
14264: # single or double quotation marks after a separator indicate beginning of a quote
14265: # we are now looking for the end of the quote and need to ignore separators
14266: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14267: $looking_for=$character;
14268: next;
14269: }
14270: # ignore would be true after we reached the end of a quote
14271: if ($ignore) { next; }
14272: if (($just_found_separator) && ($character=~/\s/)) { next; }
14273: $field.=$character;
14274: $just_found_separator=0;
1.31 albertel 14275: }
1.561 www 14276: # catch the very last entry, since we never encountered the separator
14277: $components{&takeleft($i)}=$field;
1.31 albertel 14278: }
14279: return %components;
14280: }
14281:
1.144 matthew 14282: ######################################################
14283: ######################################################
14284:
1.56 matthew 14285: =pod
14286:
1.648 raeburn 14287: =item * &upfile_select_html()
1.41 ng 14288:
1.144 matthew 14289: Return HTML code to select a file from the users machine and specify
14290: the file type.
1.41 ng 14291:
14292: =cut
14293:
1.144 matthew 14294: ######################################################
14295: ######################################################
1.31 albertel 14296: sub upfile_select_html {
1.144 matthew 14297: my %Types = (
14298: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14299: semisv => &mt('Semicolon separated values'),
1.144 matthew 14300: space => &mt('Space separated'),
14301: tab => &mt('Tabulator separated'),
14302: # xml => &mt('HTML/XML'),
14303: );
14304: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14305: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14306: foreach my $type (sort(keys(%Types))) {
14307: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14308: }
14309: $Str .= "</select>\n";
14310: return $Str;
1.31 albertel 14311: }
14312:
1.301 albertel 14313: sub get_samples {
14314: my ($records,$toget) = @_;
14315: my @samples=({});
14316: my $got=0;
14317: foreach my $rec (@$records) {
14318: my %temp = &record_sep($rec);
14319: if (! grep(/\S/, values(%temp))) { next; }
14320: if (%temp) {
14321: $samples[$got]=\%temp;
14322: $got++;
14323: if ($got == $toget) { last; }
14324: }
14325: }
14326: return \@samples;
14327: }
14328:
1.144 matthew 14329: ######################################################
14330: ######################################################
14331:
1.56 matthew 14332: =pod
14333:
1.648 raeburn 14334: =item * &csv_print_samples($r,$records)
1.41 ng 14335:
14336: Prints a table of sample values from each column uploaded $r is an
14337: Apache Request ref, $records is an arrayref from
14338: &Apache::loncommon::upfile_record_sep
14339:
14340: =cut
14341:
1.144 matthew 14342: ######################################################
14343: ######################################################
1.31 albertel 14344: sub csv_print_samples {
14345: my ($r,$records) = @_;
1.662 bisitz 14346: my $samples = &get_samples($records,5);
1.301 albertel 14347:
1.594 raeburn 14348: $r->print(&mt('Samples').'<br />'.&start_data_table().
14349: &start_data_table_header_row());
1.356 albertel 14350: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14351: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14352: $r->print(&end_data_table_header_row());
1.301 albertel 14353: foreach my $hash (@$samples) {
1.594 raeburn 14354: $r->print(&start_data_table_row());
1.356 albertel 14355: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14356: $r->print('<td>');
1.356 albertel 14357: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14358: $r->print('</td>');
14359: }
1.594 raeburn 14360: $r->print(&end_data_table_row());
1.31 albertel 14361: }
1.594 raeburn 14362: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14363: }
14364:
1.144 matthew 14365: ######################################################
14366: ######################################################
14367:
1.56 matthew 14368: =pod
14369:
1.648 raeburn 14370: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14371:
14372: Prints a table to create associations between values and table columns.
1.144 matthew 14373:
1.41 ng 14374: $r is an Apache Request ref,
14375: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14376: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14377:
14378: =cut
14379:
1.144 matthew 14380: ######################################################
14381: ######################################################
1.31 albertel 14382: sub csv_print_select_table {
14383: my ($r,$records,$d) = @_;
1.301 albertel 14384: my $i=0;
14385: my $samples = &get_samples($records,1);
1.144 matthew 14386: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14387: &start_data_table().&start_data_table_header_row().
1.144 matthew 14388: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14389: '<th>'.&mt('Column').'</th>'.
14390: &end_data_table_header_row()."\n");
1.356 albertel 14391: foreach my $array_ref (@$d) {
14392: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14393: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14394:
1.875 bisitz 14395: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14396: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14397: $r->print('<option value="none"></option>');
1.356 albertel 14398: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14399: $r->print('<option value="'.$sample.'"'.
14400: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14401: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14402: }
1.594 raeburn 14403: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14404: $i++;
14405: }
1.594 raeburn 14406: $r->print(&end_data_table());
1.31 albertel 14407: $i--;
14408: return $i;
14409: }
1.56 matthew 14410:
1.144 matthew 14411: ######################################################
14412: ######################################################
14413:
1.56 matthew 14414: =pod
1.31 albertel 14415:
1.648 raeburn 14416: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14417:
14418: Prints a table of sample values from the upload and can make associate samples to internal names.
14419:
14420: $r is an Apache Request ref,
14421: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14422: $d is an array of 2 element arrays (internal name, displayed name)
14423:
14424: =cut
14425:
1.144 matthew 14426: ######################################################
14427: ######################################################
1.31 albertel 14428: sub csv_samples_select_table {
14429: my ($r,$records,$d) = @_;
14430: my $i=0;
1.144 matthew 14431: #
1.662 bisitz 14432: my $max_samples = 5;
14433: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14434: $r->print(&start_data_table().
14435: &start_data_table_header_row().'<th>'.
14436: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14437: &end_data_table_header_row());
1.301 albertel 14438:
14439: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14440: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14441: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14442: foreach my $option (@$d) {
14443: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14444: $r->print('<option value="'.$value.'"'.
1.253 albertel 14445: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14446: $display.'</option>');
1.31 albertel 14447: }
14448: $r->print('</select></td><td>');
1.662 bisitz 14449: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14450: if (defined($samples->[$line]{$key})) {
14451: $r->print($samples->[$line]{$key}."<br />\n");
14452: }
14453: }
1.594 raeburn 14454: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14455: $i++;
14456: }
1.594 raeburn 14457: $r->print(&end_data_table());
1.31 albertel 14458: $i--;
14459: return($i);
1.115 matthew 14460: }
14461:
1.144 matthew 14462: ######################################################
14463: ######################################################
14464:
1.115 matthew 14465: =pod
14466:
1.648 raeburn 14467: =item * &clean_excel_name($name)
1.115 matthew 14468:
14469: Returns a replacement for $name which does not contain any illegal characters.
14470:
14471: =cut
14472:
1.144 matthew 14473: ######################################################
14474: ######################################################
1.115 matthew 14475: sub clean_excel_name {
14476: my ($name) = @_;
14477: $name =~ s/[:\*\?\/\\]//g;
14478: if (length($name) > 31) {
14479: $name = substr($name,0,31);
14480: }
14481: return $name;
1.25 albertel 14482: }
1.84 albertel 14483:
1.85 albertel 14484: =pod
14485:
1.648 raeburn 14486: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14487:
14488: Returns either 1 or undef
14489:
14490: 1 if the part is to be hidden, undef if it is to be shown
14491:
14492: Arguments are:
14493:
14494: $id the id of the part to be checked
14495: $symb, optional the symb of the resource to check
14496: $udom, optional the domain of the user to check for
14497: $uname, optional the username of the user to check for
14498:
14499: =cut
1.84 albertel 14500:
14501: sub check_if_partid_hidden {
14502: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14503: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14504: $symb,$udom,$uname);
1.141 albertel 14505: my $truth=1;
14506: #if the string starts with !, then the list is the list to show not hide
14507: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14508: my @hiddenlist=split(/,/,$hiddenparts);
14509: foreach my $checkid (@hiddenlist) {
1.141 albertel 14510: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14511: }
1.141 albertel 14512: return !$truth;
1.84 albertel 14513: }
1.127 matthew 14514:
1.138 matthew 14515:
14516: ############################################################
14517: ############################################################
14518:
14519: =pod
14520:
1.157 matthew 14521: =back
14522:
1.138 matthew 14523: =head1 cgi-bin script and graphing routines
14524:
1.157 matthew 14525: =over 4
14526:
1.648 raeburn 14527: =item * &get_cgi_id()
1.138 matthew 14528:
14529: Inputs: none
14530:
14531: Returns an id which can be used to pass environment variables
14532: to various cgi-bin scripts. These environment variables will
14533: be removed from the users environment after a given time by
14534: the routine &Apache::lonnet::transfer_profile_to_env.
14535:
14536: =cut
14537:
14538: ############################################################
14539: ############################################################
1.152 albertel 14540: my $uniq=0;
1.136 matthew 14541: sub get_cgi_id {
1.154 albertel 14542: $uniq=($uniq+1)%100000;
1.280 albertel 14543: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14544: }
14545:
1.127 matthew 14546: ############################################################
14547: ############################################################
14548:
14549: =pod
14550:
1.648 raeburn 14551: =item * &DrawBarGraph()
1.127 matthew 14552:
1.138 matthew 14553: Facilitates the plotting of data in a (stacked) bar graph.
14554: Puts plot definition data into the users environment in order for
14555: graph.png to plot it. Returns an <img> tag for the plot.
14556: The bars on the plot are labeled '1','2',...,'n'.
14557:
14558: Inputs:
14559:
14560: =over 4
14561:
14562: =item $Title: string, the title of the plot
14563:
14564: =item $xlabel: string, text describing the X-axis of the plot
14565:
14566: =item $ylabel: string, text describing the Y-axis of the plot
14567:
14568: =item $Max: scalar, the maximum Y value to use in the plot
14569: If $Max is < any data point, the graph will not be rendered.
14570:
1.140 matthew 14571: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14572: they are plotted. If undefined, default values will be used.
14573:
1.178 matthew 14574: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14575:
1.138 matthew 14576: =item @Values: An array of array references. Each array reference holds data
14577: to be plotted in a stacked bar chart.
14578:
1.239 matthew 14579: =item If the final element of @Values is a hash reference the key/value
14580: pairs will be added to the graph definition.
14581:
1.138 matthew 14582: =back
14583:
14584: Returns:
14585:
14586: An <img> tag which references graph.png and the appropriate identifying
14587: information for the plot.
14588:
1.127 matthew 14589: =cut
14590:
14591: ############################################################
14592: ############################################################
1.134 matthew 14593: sub DrawBarGraph {
1.178 matthew 14594: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14595: #
14596: if (! defined($colors)) {
14597: $colors = ['#33ff00',
14598: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14599: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14600: ];
14601: }
1.228 matthew 14602: my $extra_settings = {};
14603: if (ref($Values[-1]) eq 'HASH') {
14604: $extra_settings = pop(@Values);
14605: }
1.127 matthew 14606: #
1.136 matthew 14607: my $identifier = &get_cgi_id();
14608: my $id = 'cgi.'.$identifier;
1.129 matthew 14609: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14610: return '';
14611: }
1.225 matthew 14612: #
14613: my @Labels;
14614: if (defined($labels)) {
14615: @Labels = @$labels;
14616: } else {
14617: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 14618: push(@Labels,$i+1);
1.225 matthew 14619: }
14620: }
14621: #
1.129 matthew 14622: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14623: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14624: my %ValuesHash;
14625: my $NumSets=1;
14626: foreach my $array (@Values) {
14627: next if (! ref($array));
1.136 matthew 14628: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14629: join(',',@$array);
1.129 matthew 14630: }
1.127 matthew 14631: #
1.136 matthew 14632: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14633: if ($NumBars < 3) {
14634: $width = 120+$NumBars*32;
1.220 matthew 14635: $xskip = 1;
1.225 matthew 14636: $bar_width = 30;
14637: } elsif ($NumBars < 5) {
14638: $width = 120+$NumBars*20;
14639: $xskip = 1;
14640: $bar_width = 20;
1.220 matthew 14641: } elsif ($NumBars < 10) {
1.136 matthew 14642: $width = 120+$NumBars*15;
14643: $xskip = 1;
14644: $bar_width = 15;
14645: } elsif ($NumBars <= 25) {
14646: $width = 120+$NumBars*11;
14647: $xskip = 5;
14648: $bar_width = 8;
14649: } elsif ($NumBars <= 50) {
14650: $width = 120+$NumBars*8;
14651: $xskip = 5;
14652: $bar_width = 4;
14653: } else {
14654: $width = 120+$NumBars*8;
14655: $xskip = 5;
14656: $bar_width = 4;
14657: }
14658: #
1.137 matthew 14659: $Max = 1 if ($Max < 1);
14660: if ( int($Max) < $Max ) {
14661: $Max++;
14662: $Max = int($Max);
14663: }
1.127 matthew 14664: $Title = '' if (! defined($Title));
14665: $xlabel = '' if (! defined($xlabel));
14666: $ylabel = '' if (! defined($ylabel));
1.369 www 14667: $ValuesHash{$id.'.title'} = &escape($Title);
14668: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14669: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14670: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14671: $ValuesHash{$id.'.NumBars'} = $NumBars;
14672: $ValuesHash{$id.'.NumSets'} = $NumSets;
14673: $ValuesHash{$id.'.PlotType'} = 'bar';
14674: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14675: $ValuesHash{$id.'.height'} = $height;
14676: $ValuesHash{$id.'.width'} = $width;
14677: $ValuesHash{$id.'.xskip'} = $xskip;
14678: $ValuesHash{$id.'.bar_width'} = $bar_width;
14679: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14680: #
1.228 matthew 14681: # Deal with other parameters
14682: while (my ($key,$value) = each(%$extra_settings)) {
14683: $ValuesHash{$id.'.'.$key} = $value;
14684: }
14685: #
1.646 raeburn 14686: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14687: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14688: }
14689:
14690: ############################################################
14691: ############################################################
14692:
14693: =pod
14694:
1.648 raeburn 14695: =item * &DrawXYGraph()
1.137 matthew 14696:
1.138 matthew 14697: Facilitates the plotting of data in an XY graph.
14698: Puts plot definition data into the users environment in order for
14699: graph.png to plot it. Returns an <img> tag for the plot.
14700:
14701: Inputs:
14702:
14703: =over 4
14704:
14705: =item $Title: string, the title of the plot
14706:
14707: =item $xlabel: string, text describing the X-axis of the plot
14708:
14709: =item $ylabel: string, text describing the Y-axis of the plot
14710:
14711: =item $Max: scalar, the maximum Y value to use in the plot
14712: If $Max is < any data point, the graph will not be rendered.
14713:
14714: =item $colors: Array ref containing the hex color codes for the data to be
14715: plotted in. If undefined, default values will be used.
14716:
14717: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14718:
14719: =item $Ydata: Array ref containing Array refs.
1.185 www 14720: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14721:
14722: =item %Values: hash indicating or overriding any default values which are
14723: passed to graph.png.
14724: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14725:
14726: =back
14727:
14728: Returns:
14729:
14730: An <img> tag which references graph.png and the appropriate identifying
14731: information for the plot.
14732:
1.137 matthew 14733: =cut
14734:
14735: ############################################################
14736: ############################################################
14737: sub DrawXYGraph {
14738: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14739: #
14740: # Create the identifier for the graph
14741: my $identifier = &get_cgi_id();
14742: my $id = 'cgi.'.$identifier;
14743: #
14744: $Title = '' if (! defined($Title));
14745: $xlabel = '' if (! defined($xlabel));
14746: $ylabel = '' if (! defined($ylabel));
14747: my %ValuesHash =
14748: (
1.369 www 14749: $id.'.title' => &escape($Title),
14750: $id.'.xlabel' => &escape($xlabel),
14751: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14752: $id.'.y_max_value'=> $Max,
14753: $id.'.labels' => join(',',@$Xlabels),
14754: $id.'.PlotType' => 'XY',
14755: );
14756: #
14757: if (defined($colors) && ref($colors) eq 'ARRAY') {
14758: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14759: }
14760: #
14761: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14762: return '';
14763: }
14764: my $NumSets=1;
1.138 matthew 14765: foreach my $array (@{$Ydata}){
1.137 matthew 14766: next if (! ref($array));
14767: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14768: }
1.138 matthew 14769: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14770: #
14771: # Deal with other parameters
14772: while (my ($key,$value) = each(%Values)) {
14773: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14774: }
14775: #
1.646 raeburn 14776: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14777: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14778: }
14779:
14780: ############################################################
14781: ############################################################
14782:
14783: =pod
14784:
1.648 raeburn 14785: =item * &DrawXYYGraph()
1.138 matthew 14786:
14787: Facilitates the plotting of data in an XY graph with two Y axes.
14788: Puts plot definition data into the users environment in order for
14789: graph.png to plot it. Returns an <img> tag for the plot.
14790:
14791: Inputs:
14792:
14793: =over 4
14794:
14795: =item $Title: string, the title of the plot
14796:
14797: =item $xlabel: string, text describing the X-axis of the plot
14798:
14799: =item $ylabel: string, text describing the Y-axis of the plot
14800:
14801: =item $colors: Array ref containing the hex color codes for the data to be
14802: plotted in. If undefined, default values will be used.
14803:
14804: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14805:
14806: =item $Ydata1: The first data set
14807:
14808: =item $Min1: The minimum value of the left Y-axis
14809:
14810: =item $Max1: The maximum value of the left Y-axis
14811:
14812: =item $Ydata2: The second data set
14813:
14814: =item $Min2: The minimum value of the right Y-axis
14815:
14816: =item $Max2: The maximum value of the left Y-axis
14817:
14818: =item %Values: hash indicating or overriding any default values which are
14819: passed to graph.png.
14820: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14821:
14822: =back
14823:
14824: Returns:
14825:
14826: An <img> tag which references graph.png and the appropriate identifying
14827: information for the plot.
1.136 matthew 14828:
14829: =cut
14830:
14831: ############################################################
14832: ############################################################
1.137 matthew 14833: sub DrawXYYGraph {
14834: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14835: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14836: #
14837: # Create the identifier for the graph
14838: my $identifier = &get_cgi_id();
14839: my $id = 'cgi.'.$identifier;
14840: #
14841: $Title = '' if (! defined($Title));
14842: $xlabel = '' if (! defined($xlabel));
14843: $ylabel = '' if (! defined($ylabel));
14844: my %ValuesHash =
14845: (
1.369 www 14846: $id.'.title' => &escape($Title),
14847: $id.'.xlabel' => &escape($xlabel),
14848: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14849: $id.'.labels' => join(',',@$Xlabels),
14850: $id.'.PlotType' => 'XY',
14851: $id.'.NumSets' => 2,
1.137 matthew 14852: $id.'.two_axes' => 1,
14853: $id.'.y1_max_value' => $Max1,
14854: $id.'.y1_min_value' => $Min1,
14855: $id.'.y2_max_value' => $Max2,
14856: $id.'.y2_min_value' => $Min2,
1.136 matthew 14857: );
14858: #
1.137 matthew 14859: if (defined($colors) && ref($colors) eq 'ARRAY') {
14860: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14861: }
14862: #
14863: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14864: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14865: return '';
14866: }
14867: my $NumSets=1;
1.137 matthew 14868: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14869: next if (! ref($array));
14870: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14871: }
14872: #
14873: # Deal with other parameters
14874: while (my ($key,$value) = each(%Values)) {
14875: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14876: }
14877: #
1.646 raeburn 14878: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14879: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14880: }
14881:
14882: ############################################################
14883: ############################################################
14884:
14885: =pod
14886:
1.157 matthew 14887: =back
14888:
1.139 matthew 14889: =head1 Statistics helper routines?
14890:
14891: Bad place for them but what the hell.
14892:
1.157 matthew 14893: =over 4
14894:
1.648 raeburn 14895: =item * &chartlink()
1.139 matthew 14896:
14897: Returns a link to the chart for a specific student.
14898:
14899: Inputs:
14900:
14901: =over 4
14902:
14903: =item $linktext: The text of the link
14904:
14905: =item $sname: The students username
14906:
14907: =item $sdomain: The students domain
14908:
14909: =back
14910:
1.157 matthew 14911: =back
14912:
1.139 matthew 14913: =cut
14914:
14915: ############################################################
14916: ############################################################
14917: sub chartlink {
14918: my ($linktext, $sname, $sdomain) = @_;
14919: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14920: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14921: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14922: '">'.$linktext.'</a>';
1.153 matthew 14923: }
14924:
14925: #######################################################
14926: #######################################################
14927:
14928: =pod
14929:
14930: =head1 Course Environment Routines
1.157 matthew 14931:
14932: =over 4
1.153 matthew 14933:
1.648 raeburn 14934: =item * &restore_course_settings()
1.153 matthew 14935:
1.648 raeburn 14936: =item * &store_course_settings()
1.153 matthew 14937:
14938: Restores/Store indicated form parameters from the course environment.
14939: Will not overwrite existing values of the form parameters.
14940:
14941: Inputs:
14942: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14943:
14944: a hash ref describing the data to be stored. For example:
14945:
14946: %Save_Parameters = ('Status' => 'scalar',
14947: 'chartoutputmode' => 'scalar',
14948: 'chartoutputdata' => 'scalar',
14949: 'Section' => 'array',
1.373 raeburn 14950: 'Group' => 'array',
1.153 matthew 14951: 'StudentData' => 'array',
14952: 'Maps' => 'array');
14953:
14954: Returns: both routines return nothing
14955:
1.631 raeburn 14956: =back
14957:
1.153 matthew 14958: =cut
14959:
14960: #######################################################
14961: #######################################################
14962: sub store_course_settings {
1.496 albertel 14963: return &store_settings($env{'request.course.id'},@_);
14964: }
14965:
14966: sub store_settings {
1.153 matthew 14967: # save to the environment
14968: # appenv the same items, just to be safe
1.300 albertel 14969: my $udom = $env{'user.domain'};
14970: my $uname = $env{'user.name'};
1.496 albertel 14971: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14972: my %SaveHash;
14973: my %AppHash;
14974: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14975: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14976: my $envname = 'environment.'.$basename;
1.258 albertel 14977: if (exists($env{'form.'.$setting})) {
1.153 matthew 14978: # Save this value away
14979: if ($type eq 'scalar' &&
1.258 albertel 14980: (! exists($env{$envname}) ||
14981: $env{$envname} ne $env{'form.'.$setting})) {
14982: $SaveHash{$basename} = $env{'form.'.$setting};
14983: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14984: } elsif ($type eq 'array') {
14985: my $stored_form;
1.258 albertel 14986: if (ref($env{'form.'.$setting})) {
1.153 matthew 14987: $stored_form = join(',',
14988: map {
1.369 www 14989: &escape($_);
1.258 albertel 14990: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14991: } else {
14992: $stored_form =
1.369 www 14993: &escape($env{'form.'.$setting});
1.153 matthew 14994: }
14995: # Determine if the array contents are the same.
1.258 albertel 14996: if ($stored_form ne $env{$envname}) {
1.153 matthew 14997: $SaveHash{$basename} = $stored_form;
14998: $AppHash{$envname} = $stored_form;
14999: }
15000: }
15001: }
15002: }
15003: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 15004: $udom,$uname);
1.153 matthew 15005: if ($put_result !~ /^(ok|delayed)/) {
15006: &Apache::lonnet::logthis('unable to save form parameters, '.
15007: 'got error:'.$put_result);
15008: }
15009: # Make sure these settings stick around in this session, too
1.646 raeburn 15010: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 15011: return;
15012: }
15013:
15014: sub restore_course_settings {
1.499 albertel 15015: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 15016: }
15017:
15018: sub restore_settings {
15019: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15020: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 15021: next if (exists($env{'form.'.$setting}));
1.496 albertel 15022: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 15023: '.'.$setting;
1.258 albertel 15024: if (exists($env{$envname})) {
1.153 matthew 15025: if ($type eq 'scalar') {
1.258 albertel 15026: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 15027: } elsif ($type eq 'array') {
1.258 albertel 15028: $env{'form.'.$setting} = [
1.153 matthew 15029: map {
1.369 www 15030: &unescape($_);
1.258 albertel 15031: } split(',',$env{$envname})
1.153 matthew 15032: ];
15033: }
15034: }
15035: }
1.127 matthew 15036: }
15037:
1.618 raeburn 15038: #######################################################
15039: #######################################################
15040:
15041: =pod
15042:
15043: =head1 Domain E-mail Routines
15044:
15045: =over 4
15046:
1.648 raeburn 15047: =item * &build_recipient_list()
1.618 raeburn 15048:
1.1144 raeburn 15049: Build recipient lists for following types of e-mail:
1.766 raeburn 15050: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 15051: (d) Help requests, (e) Course requests needing approval, (f) loncapa
15052: module change checking, student/employee ID conflict checks, as
15053: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
15054: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 15055:
15056: Inputs:
1.619 raeburn 15057: defmail (scalar - email address of default recipient),
1.1144 raeburn 15058: mailing type (scalar: errormail, packagesmail, helpdeskmail,
15059: requestsmail, updatesmail, or idconflictsmail).
15060:
1.619 raeburn 15061: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 15062:
1.619 raeburn 15063: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 15064: i.e., predates configuration by DC via domainprefs.pm
15065:
15066: $requname username of requester (if mailing type is helpdeskmail)
15067:
15068: $requdom domain of requester (if mailing type is helpdeskmail)
15069:
15070: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
15071:
1.618 raeburn 15072:
1.655 raeburn 15073: Returns: comma separated list of addresses to which to send e-mail.
15074:
15075: =back
1.618 raeburn 15076:
15077: =cut
15078:
15079: ############################################################
15080: ############################################################
15081: sub build_recipient_list {
1.1297 raeburn 15082: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 15083: my @recipients;
1.1270 raeburn 15084: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 15085: my %domconfig =
1.1270 raeburn 15086: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 15087: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 15088: if (exists($domconfig{'contacts'}{$mailing})) {
15089: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
15090: my @contacts = ('adminemail','supportemail');
15091: foreach my $item (@contacts) {
15092: if ($domconfig{'contacts'}{$mailing}{$item}) {
15093: my $addr = $domconfig{'contacts'}{$item};
15094: if (!grep(/^\Q$addr\E$/,@recipients)) {
15095: push(@recipients,$addr);
15096: }
1.619 raeburn 15097: }
1.1270 raeburn 15098: }
15099: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
15100: if ($mailing eq 'helpdeskmail') {
15101: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
15102: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
15103: my @ok_bccs;
15104: foreach my $bcc (@bccs) {
15105: $bcc =~ s/^\s+//g;
15106: $bcc =~ s/\s+$//g;
15107: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15108: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15109: push(@ok_bccs,$bcc);
15110: }
15111: }
15112: }
15113: if (@ok_bccs > 0) {
15114: $allbcc = join(', ',@ok_bccs);
15115: }
15116: }
15117: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 15118: }
15119: }
1.766 raeburn 15120: } elsif ($origmail ne '') {
1.1270 raeburn 15121: $lastresort = $origmail;
1.618 raeburn 15122: }
1.1297 raeburn 15123: if ($mailing eq 'helpdeskmail') {
15124: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
15125: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
15126: my ($inststatus,$inststatus_checked);
15127: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
15128: ($env{'user.domain'} ne 'public')) {
15129: $inststatus_checked = 1;
15130: $inststatus = $env{'environment.inststatus'};
15131: }
15132: unless ($inststatus_checked) {
15133: if (($requname ne '') && ($requdom ne '')) {
15134: if (($requname =~ /^$match_username$/) &&
15135: ($requdom =~ /^$match_domain$/) &&
15136: (&Apache::lonnet::domain($requdom))) {
15137: my $requhome = &Apache::lonnet::homeserver($requname,
15138: $requdom);
15139: unless ($requhome eq 'no_host') {
15140: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
15141: $inststatus = $userenv{'inststatus'};
15142: $inststatus_checked = 1;
15143: }
15144: }
15145: }
15146: }
15147: unless ($inststatus_checked) {
15148: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15149: my %srch = (srchby => 'email',
15150: srchdomain => $defdom,
15151: srchterm => $reqemail,
15152: srchtype => 'exact');
15153: my %srch_results = &Apache::lonnet::usersearch(\%srch);
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: unless ($inststatus_checked) {
15162: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15163: if ($dirsrchres eq 'ok') {
15164: foreach my $uname (keys(%srch_results)) {
15165: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15166: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15167: $inststatus_checked = 1;
15168: last;
15169: }
15170: }
15171: }
15172: }
15173: }
15174: }
15175: if ($inststatus ne '') {
15176: foreach my $status (split(/\:/,$inststatus)) {
15177: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15178: my @contacts = ('adminemail','supportemail');
15179: foreach my $item (@contacts) {
15180: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15181: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15182: if (!grep(/^\Q$addr\E$/,@recipients)) {
15183: push(@recipients,$addr);
15184: }
15185: }
15186: }
15187: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15188: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15189: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15190: my @ok_bccs;
15191: foreach my $bcc (@bccs) {
15192: $bcc =~ s/^\s+//g;
15193: $bcc =~ s/\s+$//g;
15194: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15195: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15196: push(@ok_bccs,$bcc);
15197: }
15198: }
15199: }
15200: if (@ok_bccs > 0) {
15201: $allbcc = join(', ',@ok_bccs);
15202: }
15203: }
15204: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15205: last;
15206: }
15207: }
15208: }
15209: }
15210: }
1.619 raeburn 15211: } elsif ($origmail ne '') {
1.1270 raeburn 15212: $lastresort = $origmail;
15213: }
1.1297 raeburn 15214: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 15215: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15216: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15217: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15218: my %what = (
15219: perlvar => 1,
15220: );
15221: my $primary = &Apache::lonnet::domain($defdom,'primary');
15222: if ($primary) {
15223: my $gotaddr;
15224: my ($result,$returnhash) =
15225: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15226: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15227: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15228: $lastresort = $returnhash->{'lonSupportEMail'};
15229: $gotaddr = 1;
15230: }
15231: }
15232: unless ($gotaddr) {
15233: my $uintdom = &Apache::lonnet::internet_dom($primary);
15234: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15235: unless ($uintdom eq $intdom) {
15236: my %domconfig =
15237: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15238: if (ref($domconfig{'contacts'}) eq 'HASH') {
15239: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15240: my @contacts = ('adminemail','supportemail');
15241: foreach my $item (@contacts) {
15242: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15243: my $addr = $domconfig{'contacts'}{$item};
15244: if (!grep(/^\Q$addr\E$/,@recipients)) {
15245: push(@recipients,$addr);
15246: }
15247: }
15248: }
15249: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15250: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15251: }
15252: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15253: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15254: my @ok_bccs;
15255: foreach my $bcc (@bccs) {
15256: $bcc =~ s/^\s+//g;
15257: $bcc =~ s/\s+$//g;
15258: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15259: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15260: push(@ok_bccs,$bcc);
15261: }
15262: }
15263: }
15264: if (@ok_bccs > 0) {
15265: $allbcc = join(', ',@ok_bccs);
15266: }
15267: }
15268: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15269: }
15270: }
15271: }
15272: }
15273: }
15274: }
1.618 raeburn 15275: }
1.688 raeburn 15276: if (defined($defmail)) {
15277: if ($defmail ne '') {
15278: push(@recipients,$defmail);
15279: }
1.618 raeburn 15280: }
15281: if ($otheremails) {
1.619 raeburn 15282: my @others;
15283: if ($otheremails =~ /,/) {
15284: @others = split(/,/,$otheremails);
1.618 raeburn 15285: } else {
1.619 raeburn 15286: push(@others,$otheremails);
15287: }
15288: foreach my $addr (@others) {
15289: if (!grep(/^\Q$addr\E$/,@recipients)) {
15290: push(@recipients,$addr);
15291: }
1.618 raeburn 15292: }
15293: }
1.1298 raeburn 15294: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 15295: if ((!@recipients) && ($lastresort ne '')) {
15296: push(@recipients,$lastresort);
15297: }
15298: } elsif ($lastresort ne '') {
15299: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15300: push(@recipients,$lastresort);
15301: }
15302: }
1.1271 raeburn 15303: my $recipientlist = join(',',@recipients);
1.1270 raeburn 15304: if (wantarray) {
15305: return ($recipientlist,$allbcc,$addtext);
15306: } else {
15307: return $recipientlist;
15308: }
1.618 raeburn 15309: }
15310:
1.127 matthew 15311: ############################################################
15312: ############################################################
1.154 albertel 15313:
1.655 raeburn 15314: =pod
15315:
1.1224 musolffc 15316: =over 4
15317:
1.1223 musolffc 15318: =item * &mime_email()
15319:
15320: Sends an email with a possible attachment
15321:
15322: Inputs:
15323:
15324: =over 4
15325:
15326: from - Sender's email address
15327:
1.1343 raeburn 15328: replyto - Reply-To email address
15329:
1.1223 musolffc 15330: to - Email address of recipient
15331:
15332: subject - Subject of email
15333:
15334: body - Body of email
15335:
15336: cc_string - Carbon copy email address
15337:
15338: bcc - Blind carbon copy email address
15339:
15340: attachment_path - Path of file to be attached
15341:
15342: file_name - Name of file to be attached
15343:
15344: attachment_text - The body of an attachment of type "TEXT"
15345:
15346: =back
15347:
15348: =back
15349:
15350: =cut
15351:
15352: ############################################################
15353: ############################################################
15354:
15355: sub mime_email {
1.1343 raeburn 15356: my ($from,$replyto,$to,$subject,$body,$cc_string,$bcc,$attachment_path,
15357: $file_name,$attachment_text) = @_;
15358:
1.1223 musolffc 15359: my $msg = MIME::Lite->new(
15360: From => $from,
15361: To => $to,
15362: Subject => $subject,
15363: Type =>'TEXT',
15364: Data => $body,
15365: );
1.1343 raeburn 15366: if ($replyto ne '') {
15367: $msg->add("Reply-To" => $replyto);
15368: }
1.1223 musolffc 15369: if ($cc_string ne '') {
15370: $msg->add("Cc" => $cc_string);
15371: }
15372: if ($bcc ne '') {
15373: $msg->add("Bcc" => $bcc);
15374: }
15375: $msg->attr("content-type" => "text/plain");
15376: $msg->attr("content-type.charset" => "UTF-8");
15377: # Attach file if given
15378: if ($attachment_path) {
15379: unless ($file_name) {
15380: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
15381: }
15382: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
15383: $msg->attach(Type => $type,
15384: Path => $attachment_path,
15385: Filename => $file_name
15386: );
15387: # Otherwise attach text if given
15388: } elsif ($attachment_text) {
15389: $msg->attach(Type => 'TEXT',
15390: Data => $attachment_text);
15391: }
15392: # Send it
15393: $msg->send('sendmail');
15394: }
15395:
15396: ############################################################
15397: ############################################################
15398:
15399: =pod
15400:
1.655 raeburn 15401: =head1 Course Catalog Routines
15402:
15403: =over 4
15404:
15405: =item * &gather_categories()
15406:
15407: Converts category definitions - keys of categories hash stored in
15408: coursecategories in configuration.db on the primary library server in a
15409: domain - to an array. Also generates javascript and idx hash used to
15410: generate Domain Coordinator interface for editing Course Categories.
15411:
15412: Inputs:
1.663 raeburn 15413:
1.655 raeburn 15414: categories (reference to hash of category definitions).
1.663 raeburn 15415:
1.655 raeburn 15416: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15417: categories and subcategories).
1.663 raeburn 15418:
1.655 raeburn 15419: idx (reference to hash of counters used in Domain Coordinator interface for
15420: editing Course Categories).
1.663 raeburn 15421:
1.655 raeburn 15422: jsarray (reference to array of categories used to create Javascript arrays for
15423: Domain Coordinator interface for editing Course Categories).
15424:
15425: Returns: nothing
15426:
15427: Side effects: populates cats, idx and jsarray.
15428:
15429: =cut
15430:
15431: sub gather_categories {
15432: my ($categories,$cats,$idx,$jsarray) = @_;
15433: my %counters;
15434: my $num = 0;
15435: foreach my $item (keys(%{$categories})) {
15436: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15437: if ($container eq '' && $depth == 0) {
15438: $cats->[$depth][$categories->{$item}] = $cat;
15439: } else {
15440: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15441: }
15442: my ($escitem,$tail) = split(/:/,$item,2);
15443: if ($counters{$tail} eq '') {
15444: $counters{$tail} = $num;
15445: $num ++;
15446: }
15447: if (ref($idx) eq 'HASH') {
15448: $idx->{$item} = $counters{$tail};
15449: }
15450: if (ref($jsarray) eq 'ARRAY') {
15451: push(@{$jsarray->[$counters{$tail}]},$item);
15452: }
15453: }
15454: return;
15455: }
15456:
15457: =pod
15458:
15459: =item * &extract_categories()
15460:
15461: Used to generate breadcrumb trails for course categories.
15462:
15463: Inputs:
1.663 raeburn 15464:
1.655 raeburn 15465: categories (reference to hash of category definitions).
1.663 raeburn 15466:
1.655 raeburn 15467: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15468: categories and subcategories).
1.663 raeburn 15469:
1.655 raeburn 15470: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15471:
1.655 raeburn 15472: allitems (reference to hash - key is category key
15473: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15474:
1.655 raeburn 15475: idx (reference to hash of counters used in Domain Coordinator interface for
15476: editing Course Categories).
1.663 raeburn 15477:
1.655 raeburn 15478: jsarray (reference to array of categories used to create Javascript arrays for
15479: Domain Coordinator interface for editing Course Categories).
15480:
1.665 raeburn 15481: subcats (reference to hash of arrays containing all subcategories within each
15482: category, -recursive)
15483:
1.1321 raeburn 15484: maxd (reference to hash used to hold max depth for all top-level categories).
15485:
1.655 raeburn 15486: Returns: nothing
15487:
15488: Side effects: populates trails and allitems hash references.
15489:
15490: =cut
15491:
15492: sub extract_categories {
1.1321 raeburn 15493: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 15494: if (ref($categories) eq 'HASH') {
15495: &gather_categories($categories,$cats,$idx,$jsarray);
15496: if (ref($cats->[0]) eq 'ARRAY') {
15497: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15498: my $name = $cats->[0][$i];
15499: my $item = &escape($name).'::0';
15500: my $trailstr;
15501: if ($name eq 'instcode') {
15502: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15503: } elsif ($name eq 'communities') {
15504: $trailstr = &mt('Communities');
1.1239 raeburn 15505: } elsif ($name eq 'placement') {
15506: $trailstr = &mt('Placement Tests');
1.655 raeburn 15507: } else {
15508: $trailstr = $name;
15509: }
15510: if ($allitems->{$item} eq '') {
15511: push(@{$trails},$trailstr);
15512: $allitems->{$item} = scalar(@{$trails})-1;
15513: }
15514: my @parents = ($name);
15515: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15516: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15517: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15518: if (ref($subcats) eq 'HASH') {
15519: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15520: }
1.1321 raeburn 15521: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 15522: }
15523: } else {
15524: if (ref($subcats) eq 'HASH') {
15525: $subcats->{$item} = [];
1.655 raeburn 15526: }
1.1321 raeburn 15527: if (ref($maxd) eq 'HASH') {
15528: $maxd->{$name} = 1;
15529: }
1.655 raeburn 15530: }
15531: }
15532: }
15533: }
15534: return;
15535: }
15536:
15537: =pod
15538:
1.1162 raeburn 15539: =item * &recurse_categories()
1.655 raeburn 15540:
15541: Recursively used to generate breadcrumb trails for course categories.
15542:
15543: Inputs:
1.663 raeburn 15544:
1.655 raeburn 15545: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15546: categories and subcategories).
1.663 raeburn 15547:
1.655 raeburn 15548: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15549:
15550: category (current course category, for which breadcrumb trail is being generated).
15551:
15552: trails (reference to array of breadcrumb trails for each category).
15553:
1.655 raeburn 15554: allitems (reference to hash - key is category key
15555: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15556:
1.655 raeburn 15557: parents (array containing containers directories for current category,
15558: back to top level).
15559:
15560: Returns: nothing
15561:
15562: Side effects: populates trails and allitems hash references
15563:
15564: =cut
15565:
15566: sub recurse_categories {
1.1321 raeburn 15567: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 15568: my $shallower = $depth - 1;
15569: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
15570: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
15571: my $name = $cats->[$depth]{$category}[$k];
15572: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15573: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15574: if ($allitems->{$item} eq '') {
15575: push(@{$trails},$trailstr);
15576: $allitems->{$item} = scalar(@{$trails})-1;
15577: }
15578: my $deeper = $depth+1;
15579: push(@{$parents},$category);
1.665 raeburn 15580: if (ref($subcats) eq 'HASH') {
15581: my $subcat = &escape($name).':'.$category.':'.$depth;
15582: for (my $j=@{$parents}; $j>=0; $j--) {
15583: my $higher;
15584: if ($j > 0) {
15585: $higher = &escape($parents->[$j]).':'.
15586: &escape($parents->[$j-1]).':'.$j;
15587: } else {
15588: $higher = &escape($parents->[$j]).'::'.$j;
15589: }
15590: push(@{$subcats->{$higher}},$subcat);
15591: }
15592: }
15593: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 15594: $subcats,$maxd);
1.655 raeburn 15595: pop(@{$parents});
15596: }
15597: } else {
15598: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15599: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15600: if ($allitems->{$item} eq '') {
15601: push(@{$trails},$trailstr);
15602: $allitems->{$item} = scalar(@{$trails})-1;
15603: }
1.1321 raeburn 15604: if (ref($maxd) eq 'HASH') {
15605: if ($depth > $maxd->{$parents->[0]}) {
15606: $maxd->{$parents->[0]} = $depth;
15607: }
15608: }
1.655 raeburn 15609: }
15610: return;
15611: }
15612:
1.663 raeburn 15613: =pod
15614:
1.1162 raeburn 15615: =item * &assign_categories_table()
1.663 raeburn 15616:
15617: Create a datatable for display of hierarchical categories in a domain,
15618: with checkboxes to allow a course to be categorized.
15619:
15620: Inputs:
15621:
15622: cathash - reference to hash of categories defined for the domain (from
15623: configuration.db)
15624:
15625: currcat - scalar with an & separated list of categories assigned to a course.
15626:
1.919 raeburn 15627: type - scalar contains course type (Course or Community).
15628:
1.1260 raeburn 15629: disabled - scalar (optional) contains disabled="disabled" if input elements are
15630: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15631:
1.663 raeburn 15632: Returns: $output (markup to be displayed)
15633:
15634: =cut
15635:
15636: sub assign_categories_table {
1.1259 raeburn 15637: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15638: my $output;
15639: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 15640: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
15641: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 15642: $maxdepth = scalar(@cats);
15643: if (@cats > 0) {
15644: my $itemcount = 0;
15645: if (ref($cats[0]) eq 'ARRAY') {
15646: my @currcategories;
15647: if ($currcat ne '') {
15648: @currcategories = split('&',$currcat);
15649: }
1.919 raeburn 15650: my $table;
1.663 raeburn 15651: for (my $i=0; $i<@{$cats[0]}; $i++) {
15652: my $parent = $cats[0][$i];
1.919 raeburn 15653: next if ($parent eq 'instcode');
15654: if ($type eq 'Community') {
15655: next unless ($parent eq 'communities');
1.1239 raeburn 15656: } elsif ($type eq 'Placement') {
15657: next unless ($parent eq 'placement');
1.919 raeburn 15658: } else {
1.1239 raeburn 15659: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 15660: }
1.663 raeburn 15661: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15662: my $item = &escape($parent).'::0';
15663: my $checked = '';
15664: if (@currcategories > 0) {
15665: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15666: $checked = ' checked="checked"';
1.663 raeburn 15667: }
15668: }
1.919 raeburn 15669: my $parent_title = $parent;
15670: if ($parent eq 'communities') {
15671: $parent_title = &mt('Communities');
1.1239 raeburn 15672: } elsif ($parent eq 'placement') {
15673: $parent_title = &mt('Placement Tests');
1.919 raeburn 15674: }
15675: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15676: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15677: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15678: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15679: my $depth = 1;
15680: push(@path,$parent);
1.1259 raeburn 15681: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15682: pop(@path);
1.919 raeburn 15683: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15684: $itemcount ++;
15685: }
1.919 raeburn 15686: if ($itemcount) {
15687: $output = &Apache::loncommon::start_data_table().
15688: $table.
15689: &Apache::loncommon::end_data_table();
15690: }
1.663 raeburn 15691: }
15692: }
15693: }
15694: return $output;
15695: }
15696:
15697: =pod
15698:
1.1162 raeburn 15699: =item * &assign_category_rows()
1.663 raeburn 15700:
15701: Create a datatable row for display of nested categories in a domain,
15702: with checkboxes to allow a course to be categorized,called recursively.
15703:
15704: Inputs:
15705:
15706: itemcount - track row number for alternating colors
15707:
15708: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15709: categories and subcategories.
15710:
15711: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15712:
15713: parent - parent of current category item
15714:
15715: path - Array containing all categories back up through the hierarchy from the
15716: current category to the top level.
15717:
15718: currcategories - reference to array of current categories assigned to the course
15719:
1.1260 raeburn 15720: disabled - scalar (optional) contains disabled="disabled" if input elements are
15721: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15722:
1.663 raeburn 15723: Returns: $output (markup to be displayed).
15724:
15725: =cut
15726:
15727: sub assign_category_rows {
1.1259 raeburn 15728: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15729: my ($text,$name,$item,$chgstr);
15730: if (ref($cats) eq 'ARRAY') {
15731: my $maxdepth = scalar(@{$cats});
15732: if (ref($cats->[$depth]) eq 'HASH') {
15733: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15734: my $numchildren = @{$cats->[$depth]{$parent}};
15735: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 15736: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15737: for (my $j=0; $j<$numchildren; $j++) {
15738: $name = $cats->[$depth]{$parent}[$j];
15739: $item = &escape($name).':'.&escape($parent).':'.$depth;
15740: my $deeper = $depth+1;
15741: my $checked = '';
15742: if (ref($currcategories) eq 'ARRAY') {
15743: if (@{$currcategories} > 0) {
15744: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15745: $checked = ' checked="checked"';
1.663 raeburn 15746: }
15747: }
15748: }
1.664 raeburn 15749: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15750: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15751: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15752: '<input type="hidden" name="catname" value="'.$name.'" />'.
15753: '</td><td>';
1.663 raeburn 15754: if (ref($path) eq 'ARRAY') {
15755: push(@{$path},$name);
1.1259 raeburn 15756: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15757: pop(@{$path});
15758: }
15759: $text .= '</td></tr>';
15760: }
15761: $text .= '</table></td>';
15762: }
15763: }
15764: }
15765: return $text;
15766: }
15767:
1.1181 raeburn 15768: =pod
15769:
15770: =back
15771:
15772: =cut
15773:
1.655 raeburn 15774: ############################################################
15775: ############################################################
15776:
15777:
1.443 albertel 15778: sub commit_customrole {
1.664 raeburn 15779: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15780: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15781: ($start?', '.&mt('starting').' '.localtime($start):'').
15782: ($end?', ending '.localtime($end):'').': <b>'.
15783: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15784: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15785: '</b><br />';
15786: return $output;
15787: }
15788:
15789: sub commit_standardrole {
1.1116 raeburn 15790: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15791: my ($output,$logmsg,$linefeed);
15792: if ($context eq 'auto') {
15793: $linefeed = "\n";
15794: } else {
15795: $linefeed = "<br />\n";
15796: }
1.443 albertel 15797: if ($three eq 'st') {
1.541 raeburn 15798: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 15799: $one,$two,$sec,$context,$credits);
1.541 raeburn 15800: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15801: ($result eq 'unknown_course') || ($result eq 'refused')) {
15802: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15803: } else {
1.541 raeburn 15804: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15805: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15806: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15807: if ($context eq 'auto') {
15808: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15809: } else {
15810: $output .= '<b>'.$result.'</b>'.$linefeed.
15811: &mt('Add to classlist').': <b>ok</b>';
15812: }
15813: $output .= $linefeed;
1.443 albertel 15814: }
15815: } else {
15816: $output = &mt('Assigning').' '.$three.' in '.$url.
15817: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15818: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15819: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15820: if ($context eq 'auto') {
15821: $output .= $result.$linefeed;
15822: } else {
15823: $output .= '<b>'.$result.'</b>'.$linefeed;
15824: }
1.443 albertel 15825: }
15826: return $output;
15827: }
15828:
15829: sub commit_studentrole {
1.1116 raeburn 15830: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15831: $credits) = @_;
1.626 raeburn 15832: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15833: if ($context eq 'auto') {
15834: $linefeed = "\n";
15835: } else {
15836: $linefeed = '<br />'."\n";
15837: }
1.443 albertel 15838: if (defined($one) && defined($two)) {
15839: my $cid=$one.'_'.$two;
15840: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15841: my $secchange = 0;
15842: my $expire_role_result;
15843: my $modify_section_result;
1.628 raeburn 15844: if ($oldsec ne '-1') {
15845: if ($oldsec ne $sec) {
1.443 albertel 15846: $secchange = 1;
1.628 raeburn 15847: my $now = time;
1.443 albertel 15848: my $uurl='/'.$cid;
15849: $uurl=~s/\_/\//g;
15850: if ($oldsec) {
15851: $uurl.='/'.$oldsec;
15852: }
1.626 raeburn 15853: $oldsecurl = $uurl;
1.628 raeburn 15854: $expire_role_result =
1.652 raeburn 15855: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15856: if ($env{'request.course.sec'} ne '') {
15857: if ($expire_role_result eq 'refused') {
15858: my @roles = ('st');
15859: my @statuses = ('previous');
15860: my @roledoms = ($one);
15861: my $withsec = 1;
15862: my %roleshash =
15863: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15864: \@statuses,\@roles,\@roledoms,$withsec);
15865: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15866: my ($oldstart,$oldend) =
15867: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15868: if ($oldend > 0 && $oldend <= $now) {
15869: $expire_role_result = 'ok';
15870: }
15871: }
15872: }
15873: }
1.443 albertel 15874: $result = $expire_role_result;
15875: }
15876: }
15877: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 15878: $modify_section_result =
15879: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15880: undef,undef,undef,$sec,
15881: $end,$start,'','',$cid,
15882: '',$context,$credits);
1.443 albertel 15883: if ($modify_section_result =~ /^ok/) {
15884: if ($secchange == 1) {
1.628 raeburn 15885: if ($sec eq '') {
15886: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15887: } else {
15888: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15889: }
1.443 albertel 15890: } elsif ($oldsec eq '-1') {
1.628 raeburn 15891: if ($sec eq '') {
15892: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15893: } else {
15894: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15895: }
1.443 albertel 15896: } else {
1.628 raeburn 15897: if ($sec eq '') {
15898: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15899: } else {
15900: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15901: }
1.443 albertel 15902: }
15903: } else {
1.1115 raeburn 15904: if ($secchange) {
1.628 raeburn 15905: $$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;
15906: } else {
15907: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15908: }
1.443 albertel 15909: }
15910: $result = $modify_section_result;
15911: } elsif ($secchange == 1) {
1.628 raeburn 15912: if ($oldsec eq '') {
1.1103 raeburn 15913: $$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 15914: } else {
15915: $$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;
15916: }
1.626 raeburn 15917: if ($expire_role_result eq 'refused') {
15918: my $newsecurl = '/'.$cid;
15919: $newsecurl =~ s/\_/\//g;
15920: if ($sec ne '') {
15921: $newsecurl.='/'.$sec;
15922: }
15923: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15924: if ($sec eq '') {
15925: $$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;
15926: } else {
15927: $$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;
15928: }
15929: }
15930: }
1.443 albertel 15931: }
15932: } else {
1.626 raeburn 15933: $$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 15934: $result = "error: incomplete course id\n";
15935: }
15936: return $result;
15937: }
15938:
1.1108 raeburn 15939: sub show_role_extent {
15940: my ($scope,$context,$role) = @_;
15941: $scope =~ s{^/}{};
15942: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15943: push(@courseroles,'co');
15944: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15945: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15946: $scope =~ s{/}{_};
15947: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15948: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15949: my ($audom,$auname) = split(/\//,$scope);
15950: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15951: &Apache::loncommon::plainname($auname,$audom).'</span>');
15952: } else {
15953: $scope =~ s{/$}{};
15954: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15955: &Apache::lonnet::domain($scope,'description').'</span>');
15956: }
15957: }
15958:
1.443 albertel 15959: ############################################################
15960: ############################################################
15961:
1.566 albertel 15962: sub check_clone {
1.578 raeburn 15963: my ($args,$linefeed) = @_;
1.566 albertel 15964: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15965: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15966: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1344 raeburn 15967: my $clonetitle;
15968: my @clonemsg;
1.566 albertel 15969: my $can_clone = 0;
1.944 raeburn 15970: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15971: if ($lctype ne 'community') {
15972: $lctype = 'course';
15973: }
1.566 albertel 15974: if ($clonehome eq 'no_host') {
1.944 raeburn 15975: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 15976: push(@clonemsg,({
15977: mt => 'No new community created.',
15978: args => [],
15979: },
15980: {
15981: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
15982: args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
15983: }));
1.908 raeburn 15984: } else {
1.1344 raeburn 15985: push(@clonemsg,({
15986: mt => 'No new course created.',
15987: args => [],
15988: },
15989: {
15990: mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
15991: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
15992: }));
15993: }
1.566 albertel 15994: } else {
15995: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1344 raeburn 15996: $clonetitle = $clonedesc{'description'};
1.944 raeburn 15997: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15998: if ($clonedesc{'type'} ne 'Community') {
1.1344 raeburn 15999: push(@clonemsg,({
16000: mt => 'No new community created.',
16001: args => [],
16002: },
16003: {
16004: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
16005: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16006: }));
16007: return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 16008: }
16009: }
1.1262 raeburn 16010: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 16011: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 16012: $can_clone = 1;
16013: } else {
1.1221 raeburn 16014: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 16015: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 16016: if ($clonehash{'cloners'} eq '') {
16017: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
16018: if ($domdefs{'canclone'}) {
16019: unless ($domdefs{'canclone'} eq 'none') {
16020: if ($domdefs{'canclone'} eq 'domain') {
16021: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
16022: $can_clone = 1;
16023: }
16024: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16025: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
16026: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
16027: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
16028: $can_clone = 1;
16029: }
16030: }
16031: }
16032: }
1.578 raeburn 16033: } else {
1.1221 raeburn 16034: my @cloners = split(/,/,$clonehash{'cloners'});
16035: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 16036: $can_clone = 1;
1.1221 raeburn 16037: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 16038: $can_clone = 1;
1.1225 raeburn 16039: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
16040: $can_clone = 1;
1.1221 raeburn 16041: }
16042: unless ($can_clone) {
1.1225 raeburn 16043: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16044: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 16045: my (%gotdomdefaults,%gotcodedefaults);
16046: foreach my $cloner (@cloners) {
16047: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
16048: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
16049: my (%codedefaults,@code_order);
16050: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
16051: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
16052: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
16053: }
16054: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
16055: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
16056: }
16057: } else {
16058: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
16059: \%codedefaults,
16060: \@code_order);
16061: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
16062: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
16063: }
16064: if (@code_order > 0) {
16065: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
16066: $cloner,$clonehash{'internal.coursecode'},
16067: $args->{'crscode'})) {
16068: $can_clone = 1;
16069: last;
16070: }
16071: }
16072: }
16073: }
16074: }
1.1225 raeburn 16075: }
16076: }
16077: unless ($can_clone) {
16078: my $ccrole = 'cc';
16079: if ($args->{'crstype'} eq 'Community') {
16080: $ccrole = 'co';
16081: }
16082: my %roleshash =
16083: &Apache::lonnet::get_my_roles($args->{'ccuname'},
16084: $args->{'ccdomain'},
16085: 'userroles',['active'],[$ccrole],
16086: [$args->{'clonedomain'}]);
16087: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
16088: $can_clone = 1;
16089: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
16090: $args->{'ccuname'},$args->{'ccdomain'})) {
16091: $can_clone = 1;
1.1221 raeburn 16092: }
16093: }
16094: unless ($can_clone) {
16095: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16096: push(@clonemsg,({
16097: mt => 'No new community created.',
16098: args => [],
16099: },
16100: {
16101: 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]).',
16102: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16103: }));
1.942 raeburn 16104: } else {
1.1344 raeburn 16105: push(@clonemsg,({
16106: mt => 'No new course created.',
16107: args => [],
16108: },
16109: {
16110: 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]).',
16111: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16112: }));
1.1221 raeburn 16113: }
1.566 albertel 16114: }
1.578 raeburn 16115: }
1.566 albertel 16116: }
1.1344 raeburn 16117: return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16118: }
16119:
1.444 albertel 16120: sub construct_course {
1.1262 raeburn 16121: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1344 raeburn 16122: $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
16123: my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 16124: my $linefeed = '<br />'."\n";
16125: if ($context eq 'auto') {
16126: $linefeed = "\n";
16127: }
1.566 albertel 16128:
16129: #
16130: # Are we cloning?
16131: #
1.1344 raeburn 16132: my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16133: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1344 raeburn 16134: ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 16135: if (!$can_clone) {
1.1344 raeburn 16136: return (0,$outcome,$clonemsgref);
1.566 albertel 16137: }
16138: }
16139:
1.444 albertel 16140: #
16141: # Open course
16142: #
1.1239 raeburn 16143: my $showncrstype;
16144: if ($args->{'crstype'} eq 'Placement') {
16145: $showncrstype = 'placement test';
16146: } else {
16147: $showncrstype = lc($args->{'crstype'});
16148: }
1.444 albertel 16149: my %cenv=();
16150: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
16151: $args->{'cdescr'},
16152: $args->{'curl'},
16153: $args->{'course_home'},
16154: $args->{'nonstandard'},
16155: $args->{'crscode'},
16156: $args->{'ccuname'}.':'.
16157: $args->{'ccdomain'},
1.882 raeburn 16158: $args->{'crstype'},
1.1344 raeburn 16159: $cnum,$context,$category,
16160: $callercontext);
1.444 albertel 16161:
16162: # Note: The testing routines depend on this being output; see
16163: # Utils::Course. This needs to at least be output as a comment
16164: # if anyone ever decides to not show this, and Utils::Course::new
16165: # will need to be suitably modified.
1.1344 raeburn 16166: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16167: $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16168: } else {
16169: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16170: }
1.943 raeburn 16171: if ($$courseid =~ /^error:/) {
1.1344 raeburn 16172: return (0,$outcome,$clonemsgref);
1.943 raeburn 16173: }
16174:
1.444 albertel 16175: #
16176: # Check if created correctly
16177: #
1.479 albertel 16178: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 16179: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 16180: if ($crsuhome eq 'no_host') {
1.1344 raeburn 16181: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16182: $outcome .= &mt_user($user_lh,
16183: 'Course creation failed, unrecognized course home server.');
16184: } else {
16185: $outcome .= &mt('Course creation failed, unrecognized course home server.');
16186: }
16187: $outcome .= $linefeed;
16188: return (0,$outcome,$clonemsgref);
1.943 raeburn 16189: }
1.541 raeburn 16190: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 16191:
1.444 albertel 16192: #
1.566 albertel 16193: # Do the cloning
16194: #
1.1344 raeburn 16195: my @clonemsg;
1.566 albertel 16196: if ($can_clone && $cloneid) {
1.1344 raeburn 16197: push(@clonemsg,
16198: {
16199: mt => 'Created [_1] by cloning from [_2]',
16200: args => [$showncrstype,$clonetitle],
16201: });
1.566 albertel 16202: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 16203: # Copy all files
1.1344 raeburn 16204: my @info =
16205: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
16206: $args->{'dateshift'},$args->{'crscode'},
16207: $args->{'ccuname'}.':'.$args->{'ccdomain'},
16208: $args->{'tinyurls'});
16209: if (@info) {
16210: push(@clonemsg,@info);
16211: }
1.444 albertel 16212: # Restore URL
1.566 albertel 16213: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16214: # Restore title
1.566 albertel 16215: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16216: # Restore creation date, creator and creation context.
16217: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16218: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16219: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16220: # Mark as cloned
1.566 albertel 16221: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16222: # Need to clone grading mode
16223: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16224: $cenv{'grading'}=$newenv{'grading'};
16225: # Do not clone these environment entries
16226: &Apache::lonnet::del('environment',
16227: ['default_enrollment_start_date',
16228: 'default_enrollment_end_date',
16229: 'question.email',
16230: 'policy.email',
16231: 'comment.email',
16232: 'pch.users.denied',
1.725 raeburn 16233: 'plc.users.denied',
16234: 'hidefromcat',
1.1121 raeburn 16235: 'checkforpriv',
1.1355 raeburn 16236: 'categories'],
1.638 www 16237: $$crsudom,$$crsunum);
1.1170 raeburn 16238: if ($args->{'textbook'}) {
16239: $cenv{'internal.textbook'} = $args->{'textbook'};
16240: }
1.444 albertel 16241: }
1.566 albertel 16242:
1.444 albertel 16243: #
16244: # Set environment (will override cloned, if existing)
16245: #
16246: my @sections = ();
16247: my @xlists = ();
16248: if ($args->{'crstype'}) {
16249: $cenv{'type'}=$args->{'crstype'};
16250: }
16251: if ($args->{'crsid'}) {
16252: $cenv{'courseid'}=$args->{'crsid'};
16253: }
16254: if ($args->{'crscode'}) {
16255: $cenv{'internal.coursecode'}=$args->{'crscode'};
16256: }
16257: if ($args->{'crsquota'} ne '') {
16258: $cenv{'internal.coursequota'}=$args->{'crsquota'};
16259: } else {
16260: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
16261: }
16262: if ($args->{'ccuname'}) {
16263: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
16264: ':'.$args->{'ccdomain'};
16265: } else {
16266: $cenv{'internal.courseowner'} = $args->{'curruser'};
16267: }
1.1116 raeburn 16268: if ($args->{'defaultcredits'}) {
16269: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
16270: }
1.444 albertel 16271: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
16272: if ($args->{'crssections'}) {
16273: $cenv{'internal.sectionnums'} = '';
16274: if ($args->{'crssections'} =~ m/,/) {
16275: @sections = split/,/,$args->{'crssections'};
16276: } else {
16277: $sections[0] = $args->{'crssections'};
16278: }
16279: if (@sections > 0) {
16280: foreach my $item (@sections) {
16281: my ($sec,$gp) = split/:/,$item;
16282: my $class = $args->{'crscode'}.$sec;
16283: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16284: $cenv{'internal.sectionnums'} .= $item.',';
16285: unless ($addcheck eq 'ok') {
1.1263 raeburn 16286: push(@badclasses,$class);
1.444 albertel 16287: }
16288: }
16289: $cenv{'internal.sectionnums'} =~ s/,$//;
16290: }
16291: }
16292: # do not hide course coordinator from staff listing,
16293: # even if privileged
16294: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 16295: # add course coordinator's domain to domains to check for privileged users
16296: # if different to course domain
16297: if ($$crsudom ne $args->{'ccdomain'}) {
16298: $cenv{'checkforpriv'} = $args->{'ccdomain'};
16299: }
1.444 albertel 16300: # add crosslistings
16301: if ($args->{'crsxlist'}) {
16302: $cenv{'internal.crosslistings'}='';
16303: if ($args->{'crsxlist'} =~ m/,/) {
16304: @xlists = split/,/,$args->{'crsxlist'};
16305: } else {
16306: $xlists[0] = $args->{'crsxlist'};
16307: }
16308: if (@xlists > 0) {
16309: foreach my $item (@xlists) {
16310: my ($xl,$gp) = split/:/,$item;
16311: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
16312: $cenv{'internal.crosslistings'} .= $item.',';
16313: unless ($addcheck eq 'ok') {
1.1263 raeburn 16314: push(@badclasses,$xl);
1.444 albertel 16315: }
16316: }
16317: $cenv{'internal.crosslistings'} =~ s/,$//;
16318: }
16319: }
16320: if ($args->{'autoadds'}) {
16321: $cenv{'internal.autoadds'}=$args->{'autoadds'};
16322: }
16323: if ($args->{'autodrops'}) {
16324: $cenv{'internal.autodrops'}=$args->{'autodrops'};
16325: }
16326: # check for notification of enrollment changes
16327: my @notified = ();
16328: if ($args->{'notify_owner'}) {
16329: if ($args->{'ccuname'} ne '') {
16330: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
16331: }
16332: }
16333: if ($args->{'notify_dc'}) {
16334: if ($uname ne '') {
1.630 raeburn 16335: push(@notified,$uname.':'.$udom);
1.444 albertel 16336: }
16337: }
16338: if (@notified > 0) {
16339: my $notifylist;
16340: if (@notified > 1) {
16341: $notifylist = join(',',@notified);
16342: } else {
16343: $notifylist = $notified[0];
16344: }
16345: $cenv{'internal.notifylist'} = $notifylist;
16346: }
16347: if (@badclasses > 0) {
16348: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 16349: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16350: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16351: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16352: );
1.1264 raeburn 16353: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16354: &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 16355: if ($context eq 'auto') {
16356: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 16357: } else {
1.566 albertel 16358: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 16359: }
16360: foreach my $item (@badclasses) {
1.541 raeburn 16361: if ($context eq 'auto') {
1.1261 raeburn 16362: $outcome .= " - $item\n";
1.541 raeburn 16363: } else {
1.1261 raeburn 16364: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16365: }
1.1261 raeburn 16366: }
16367: if ($context eq 'auto') {
16368: $outcome .= $linefeed;
16369: } else {
16370: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 16371: }
1.444 albertel 16372: }
16373: if ($args->{'no_end_date'}) {
16374: $args->{'endaccess'} = 0;
16375: }
16376: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16377: $cenv{'internal.autoend'}=$args->{'enrollend'};
16378: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16379: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16380: if ($args->{'showphotos'}) {
16381: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16382: }
16383: $cenv{'internal.authtype'} = $args->{'authtype'};
16384: $cenv{'internal.autharg'} = $args->{'autharg'};
16385: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16386: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16387: 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');
16388: if ($context eq 'auto') {
16389: $outcome .= $krb_msg;
16390: } else {
1.566 albertel 16391: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16392: }
16393: $outcome .= $linefeed;
1.444 albertel 16394: }
16395: }
16396: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16397: if ($args->{'setpolicy'}) {
16398: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16399: }
16400: if ($args->{'setcontent'}) {
16401: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16402: }
1.1251 raeburn 16403: if ($args->{'setcomment'}) {
16404: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16405: }
1.444 albertel 16406: }
16407: if ($args->{'reshome'}) {
16408: $cenv{'reshome'}=$args->{'reshome'}.'/';
16409: $cenv{'reshome'}=~s/\/+$/\//;
16410: }
16411: #
16412: # course has keyed access
16413: #
16414: if ($args->{'setkeys'}) {
16415: $cenv{'keyaccess'}='yes';
16416: }
16417: # if specified, key authority is not course, but user
16418: # only active if keyaccess is yes
16419: if ($args->{'keyauth'}) {
1.487 albertel 16420: my ($user,$domain) = split(':',$args->{'keyauth'});
16421: $user = &LONCAPA::clean_username($user);
16422: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16423: if ($user ne '' && $domain ne '') {
1.487 albertel 16424: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16425: }
16426: }
16427:
1.1166 raeburn 16428: #
1.1167 raeburn 16429: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 16430: #
16431: if ($args->{'uniquecode'}) {
16432: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16433: if ($code) {
16434: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 16435: my %crsinfo =
16436: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16437: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16438: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16439: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16440: }
1.1166 raeburn 16441: if (ref($coderef)) {
16442: $$coderef = $code;
16443: }
16444: }
16445: }
16446:
1.444 albertel 16447: if ($args->{'disresdis'}) {
16448: $cenv{'pch.roles.denied'}='st';
16449: }
16450: if ($args->{'disablechat'}) {
16451: $cenv{'plc.roles.denied'}='st';
16452: }
16453:
16454: # Record we've not yet viewed the Course Initialization Helper for this
16455: # course
16456: $cenv{'course.helper.not.run'} = 1;
16457: #
16458: # Use new Randomseed
16459: #
16460: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16461: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16462: #
16463: # The encryption code and receipt prefix for this course
16464: #
16465: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16466: $cenv{'internal.encpref'}=100+int(9*rand(99));
16467: #
16468: # By default, use standard grading
16469: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16470:
1.541 raeburn 16471: $outcome .= $linefeed.&mt('Setting environment').': '.
16472: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16473: #
16474: # Open all assignments
16475: #
16476: if ($args->{'openall'}) {
1.1341 raeburn 16477: my $opendate = time;
16478: if ($args->{'openallfrom'} =~ /^\d+$/) {
16479: $opendate = $args->{'openallfrom'};
16480: }
1.444 albertel 16481: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1341 raeburn 16482: my %storecontent = ($storeunder => $opendate,
1.444 albertel 16483: $storeunder.'.type' => 'date_start');
1.1341 raeburn 16484: $outcome .= &mt('All assignments open starting [_1]',
16485: &Apache::lonlocal::locallocaltime($opendate)).': '.
16486: &Apache::lonnet::cput
16487: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16488: }
16489: #
16490: # Set first page
16491: #
16492: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16493: || ($cloneid)) {
1.445 albertel 16494: use LONCAPA::map;
1.444 albertel 16495: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16496:
16497: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16498: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16499:
1.444 albertel 16500: $outcome .= ($fatal?$errtext:'read ok').' - ';
16501: my $title; my $url;
16502: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16503: $title=&mt('Syllabus');
1.444 albertel 16504: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16505: } else {
1.963 raeburn 16506: $title=&mt('Table of Contents');
1.444 albertel 16507: $url='/adm/navmaps';
16508: }
1.445 albertel 16509:
16510: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16511: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16512:
16513: if ($errtext) { $fatal=2; }
1.541 raeburn 16514: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16515: }
1.566 albertel 16516:
1.1237 raeburn 16517: #
16518: # Set params for Placement Tests
16519: #
1.1239 raeburn 16520: if ($args->{'crstype'} eq 'Placement') {
16521: my %storecontent;
16522: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
16523: my %defaults = (
16524: buttonshide => { value => 'yes',
16525: type => 'string_yesno',},
16526: type => { value => 'randomizetry',
16527: type => 'string_questiontype',},
16528: maxtries => { value => 1,
16529: type => 'int_pos',},
16530: problemstatus => { value => 'no',
16531: type => 'string_problemstatus',},
16532: );
16533: foreach my $key (keys(%defaults)) {
16534: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
16535: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
16536: }
1.1237 raeburn 16537: &Apache::lonnet::cput
16538: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
16539: }
16540:
1.1344 raeburn 16541: return (1,$outcome,\@clonemsg);
1.444 albertel 16542: }
16543:
1.1166 raeburn 16544: sub make_unique_code {
16545: my ($cdom,$cnum) = @_;
16546: # get lock on uniquecodes db
16547: my $lockhash = {
16548: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16549: ':'.$env{'user.domain'},
16550: };
16551: my $tries = 0;
16552: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16553: my ($code,$error);
16554:
16555: while (($gotlock ne 'ok') && ($tries<3)) {
16556: $tries ++;
16557: sleep 1;
16558: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16559: }
16560: if ($gotlock eq 'ok') {
16561: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
16562: my $gotcode;
16563: my $attempts = 0;
16564: while ((!$gotcode) && ($attempts < 100)) {
16565: $code = &generate_code();
16566: if (!exists($currcodes{$code})) {
16567: $gotcode = 1;
16568: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
16569: $error = 'nostore';
16570: }
16571: }
16572: $attempts ++;
16573: }
16574: my @del_lock = ($cnum."\0".'uniquecodes');
16575: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
16576: } else {
16577: $error = 'nolock';
16578: }
16579: return ($code,$error);
16580: }
16581:
16582: sub generate_code {
16583: my $code;
16584: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
16585: for (my $i=0; $i<6; $i++) {
16586: my $lettnum = int (rand 2);
16587: my $item = '';
16588: if ($lettnum) {
16589: $item = $letts[int( rand(18) )];
16590: } else {
16591: $item = 1+int( rand(8) );
16592: }
16593: $code .= $item;
16594: }
16595: return $code;
16596: }
16597:
1.444 albertel 16598: ############################################################
16599: ############################################################
16600:
1.1237 raeburn 16601: # Community, Course and Placement Test
1.378 raeburn 16602: sub course_type {
16603: my ($cid) = @_;
16604: if (!defined($cid)) {
16605: $cid = $env{'request.course.id'};
16606: }
1.404 albertel 16607: if (defined($env{'course.'.$cid.'.type'})) {
16608: return $env{'course.'.$cid.'.type'};
1.378 raeburn 16609: } else {
16610: return 'Course';
1.377 raeburn 16611: }
16612: }
1.156 albertel 16613:
1.406 raeburn 16614: sub group_term {
16615: my $crstype = &course_type();
16616: my %names = (
16617: 'Course' => 'group',
1.865 raeburn 16618: 'Community' => 'group',
1.1237 raeburn 16619: 'Placement' => 'group',
1.406 raeburn 16620: );
16621: return $names{$crstype};
16622: }
16623:
1.902 raeburn 16624: sub course_types {
1.1310 raeburn 16625: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 16626: my %typename = (
16627: official => 'Official course',
16628: unofficial => 'Unofficial course',
16629: community => 'Community',
1.1165 raeburn 16630: textbook => 'Textbook course',
1.1237 raeburn 16631: placement => 'Placement test',
1.1310 raeburn 16632: lti => 'LTI provider',
1.902 raeburn 16633: );
16634: return (\@types,\%typename);
16635: }
16636:
1.156 albertel 16637: sub icon {
16638: my ($file)=@_;
1.505 albertel 16639: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 16640: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 16641: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 16642: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
16643: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
16644: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16645: $curfext.".gif") {
16646: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16647: $curfext.".gif";
16648: }
16649: }
1.249 albertel 16650: return &lonhttpdurl($iconname);
1.154 albertel 16651: }
1.84 albertel 16652:
1.575 albertel 16653: sub lonhttpdurl {
1.692 www 16654: #
16655: # Had been used for "small fry" static images on separate port 8080.
16656: # Modify here if lightweight http functionality desired again.
16657: # Currently eliminated due to increasing firewall issues.
16658: #
1.575 albertel 16659: my ($url)=@_;
1.692 www 16660: return $url;
1.215 albertel 16661: }
16662:
1.213 albertel 16663: sub connection_aborted {
16664: my ($r)=@_;
16665: $r->print(" ");$r->rflush();
16666: my $c = $r->connection;
16667: return $c->aborted();
16668: }
16669:
1.221 foxr 16670: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 16671: # strings as 'strings'.
16672: sub escape_single {
1.221 foxr 16673: my ($input) = @_;
1.223 albertel 16674: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16675: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16676: return $input;
16677: }
1.223 albertel 16678:
1.222 foxr 16679: # Same as escape_single, but escape's "'s This
16680: # can be used for "strings"
16681: sub escape_double {
16682: my ($input) = @_;
16683: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16684: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16685: return $input;
16686: }
1.223 albertel 16687:
1.222 foxr 16688: # Escapes the last element of a full URL.
16689: sub escape_url {
16690: my ($url) = @_;
1.238 raeburn 16691: my @urlslices = split(/\//, $url,-1);
1.369 www 16692: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 16693: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16694: }
1.462 albertel 16695:
1.820 raeburn 16696: sub compare_arrays {
16697: my ($arrayref1,$arrayref2) = @_;
16698: my (@difference,%count);
16699: @difference = ();
16700: %count = ();
16701: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16702: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16703: foreach my $element (keys(%count)) {
16704: if ($count{$element} == 1) {
16705: push(@difference,$element);
16706: }
16707: }
16708: }
16709: return @difference;
16710: }
16711:
1.1322 raeburn 16712: sub lon_status_items {
16713: my %defaults = (
16714: E => 100,
16715: W => 4,
16716: N => 1,
1.1324 raeburn 16717: U => 5,
1.1322 raeburn 16718: threshold => 200,
16719: sysmail => 2500,
16720: );
16721: my %names = (
16722: E => 'Errors',
16723: W => 'Warnings',
16724: N => 'Notices',
1.1324 raeburn 16725: U => 'Unsent',
1.1322 raeburn 16726: );
16727: return (\%defaults,\%names);
16728: }
16729:
1.817 bisitz 16730: # -------------------------------------------------------- Initialize user login
1.462 albertel 16731: sub init_user_environment {
1.463 albertel 16732: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16733: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16734:
16735: my $public=($username eq 'public' && $domain eq 'public');
16736:
1.1062 raeburn 16737: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16738: my $now=time;
16739:
16740: if ($public) {
16741: my $max_public=100;
16742: my $oldest;
16743: my $oldest_time=0;
16744: for(my $next=1;$next<=$max_public;$next++) {
16745: if (-e $lonids."/publicuser_$next.id") {
16746: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16747: if ($mtime<$oldest_time || !$oldest_time) {
16748: $oldest_time=$mtime;
16749: $oldest=$next;
16750: }
16751: } else {
16752: $cookie="publicuser_$next";
16753: last;
16754: }
16755: }
16756: if (!$cookie) { $cookie="publicuser_$oldest"; }
16757: } else {
1.1275 raeburn 16758: # See if old ID present, if so, remove if this isn't a robot,
16759: # killing any existing non-robot sessions
1.463 albertel 16760: if (!$args->{'robot'}) {
16761: opendir(DIR,$lonids);
16762: while ($filename=readdir(DIR)) {
16763: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 16764: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
16765: &GDBM_READER(),0640)) {
1.1295 raeburn 16766: my $linkedfile;
1.1320 raeburn 16767: if (exists($oldenv{'user.linkedenv'})) {
16768: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 16769: }
1.1320 raeburn 16770: untie(%oldenv);
16771: if (unlink("$lonids/$filename")) {
16772: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
16773: if (-l "$lonids/$linkedfile.id") {
16774: unlink("$lonids/$linkedfile.id");
16775: }
1.1295 raeburn 16776: }
16777: }
16778: } else {
16779: unlink($lonids.'/'.$filename);
16780: }
1.463 albertel 16781: }
1.462 albertel 16782: }
1.463 albertel 16783: closedir(DIR);
1.1204 raeburn 16784: # If there is a undeleted lockfile for the user's paste buffer remove it.
16785: my $namespace = 'nohist_courseeditor';
16786: my $lockingkey = 'paste'."\0".'locked_num';
16787: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16788: $domain,$username);
16789: if (exists($lockhash{$lockingkey})) {
16790: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16791: unless ($delresult eq 'ok') {
16792: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16793: }
16794: }
1.462 albertel 16795: }
16796: # Give them a new cookie
1.463 albertel 16797: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16798: : $now.$$.int(rand(10000)));
1.463 albertel 16799: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16800:
16801: # Initialize roles
16802:
1.1062 raeburn 16803: ($userroles,$firstaccenv,$timerintenv) =
16804: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16805: }
16806: # ------------------------------------ Check browser type and MathML capability
16807:
1.1194 raeburn 16808: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16809: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16810:
16811: # ------------------------------------------------------------- Get environment
16812:
16813: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16814: my ($tmp) = keys(%userenv);
1.1275 raeburn 16815: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 16816: undef(%userenv);
16817: }
16818: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16819: $form->{'interface'}=$userenv{'interface'};
16820: }
16821: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16822:
16823: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16824: foreach my $option ('interface','localpath','localres') {
16825: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16826: }
16827: # --------------------------------------------------------- Write first profile
16828:
16829: {
1.1350 raeburn 16830: my $ip = &Apache::lonnet::get_requestor_ip($r);
1.462 albertel 16831: my %initial_env =
16832: ("user.name" => $username,
16833: "user.domain" => $domain,
16834: "user.home" => $authhost,
16835: "browser.type" => $clientbrowser,
16836: "browser.version" => $clientversion,
16837: "browser.mathml" => $clientmathml,
16838: "browser.unicode" => $clientunicode,
16839: "browser.os" => $clientos,
1.1137 raeburn 16840: "browser.mobile" => $clientmobile,
1.1141 raeburn 16841: "browser.info" => $clientinfo,
1.1194 raeburn 16842: "browser.osversion" => $clientosversion,
1.462 albertel 16843: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16844: "request.course.fn" => '',
16845: "request.course.uri" => '',
16846: "request.course.sec" => '',
16847: "request.role" => 'cm',
16848: "request.role.adv" => $env{'user.adv'},
1.1350 raeburn 16849: "request.host" => $ip,);
1.462 albertel 16850:
16851: if ($form->{'localpath'}) {
16852: $initial_env{"browser.localpath"} = $form->{'localpath'};
16853: $initial_env{"browser.localres"} = $form->{'localres'};
16854: }
16855:
16856: if ($form->{'interface'}) {
16857: $form->{'interface'}=~s/\W//gs;
16858: $initial_env{"browser.interface"} = $form->{'interface'};
16859: $env{'browser.interface'}=$form->{'interface'};
16860: }
16861:
1.1157 raeburn 16862: if ($form->{'iptoken'}) {
16863: my $lonhost = $r->dir_config('lonHostID');
16864: $initial_env{"user.noloadbalance"} = $lonhost;
16865: $env{'user.noloadbalance'} = $lonhost;
16866: }
16867:
1.1268 raeburn 16868: if ($form->{'noloadbalance'}) {
16869: my @hosts = &Apache::lonnet::current_machine_ids();
16870: my $hosthere = $form->{'noloadbalance'};
16871: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16872: $initial_env{"user.noloadbalance"} = $hosthere;
16873: $env{'user.noloadbalance'} = $hosthere;
16874: }
16875: }
16876:
1.1016 raeburn 16877: unless ($domain eq 'public') {
1.1273 raeburn 16878: my %is_adv = ( is_adv => $env{'user.adv'} );
16879: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
16880:
16881: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16882: $userenv{'availabletools.'.$tool} =
16883: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16884: undef,\%userenv,\%domdef,\%is_adv);
16885: }
1.980 raeburn 16886:
1.1311 raeburn 16887: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 16888: $userenv{'canrequest.'.$crstype} =
16889: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16890: 'reload','requestcourses',
16891: \%userenv,\%domdef,\%is_adv);
16892: }
1.724 raeburn 16893:
1.1273 raeburn 16894: $userenv{'canrequest.author'} =
16895: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16896: 'reload','requestauthor',
1.980 raeburn 16897: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 16898: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16899: $domain,$username);
16900: my $reqstatus = $reqauthor{'author_status'};
16901: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16902: if (ref($reqauthor{'author'}) eq 'HASH') {
16903: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16904: $reqauthor{'author'}{'timestamp'};
16905: }
1.1092 raeburn 16906: }
1.1287 raeburn 16907: my ($types,$typename) = &course_types();
16908: if (ref($types) eq 'ARRAY') {
16909: my @options = ('approval','validate','autolimit');
16910: my $optregex = join('|',@options);
16911: my (%willtrust,%trustchecked);
16912: foreach my $type (@{$types}) {
16913: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
16914: if ($dom_str ne '') {
16915: my $updatedstr = '';
16916: my @possdomains = split(',',$dom_str);
16917: foreach my $entry (@possdomains) {
16918: my ($extdom,$extopt) = split(':',$entry);
16919: unless ($trustchecked{$extdom}) {
16920: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
16921: $trustchecked{$extdom} = 1;
16922: }
16923: if ($willtrust{$extdom}) {
16924: $updatedstr .= $entry.',';
16925: }
16926: }
16927: $updatedstr =~ s/,$//;
16928: if ($updatedstr) {
16929: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
16930: } else {
16931: delete($userenv{'reqcrsotherdom.'.$type});
16932: }
16933: }
16934: }
16935: }
1.1092 raeburn 16936: }
1.462 albertel 16937: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16938:
1.462 albertel 16939: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16940: &GDBM_WRCREAT(),0640)) {
16941: &_add_to_env(\%disk_env,\%initial_env);
16942: &_add_to_env(\%disk_env,\%userenv,'environment.');
16943: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16944: if (ref($firstaccenv) eq 'HASH') {
16945: &_add_to_env(\%disk_env,$firstaccenv);
16946: }
16947: if (ref($timerintenv) eq 'HASH') {
16948: &_add_to_env(\%disk_env,$timerintenv);
16949: }
1.463 albertel 16950: if (ref($args->{'extra_env'})) {
16951: &_add_to_env(\%disk_env,$args->{'extra_env'});
16952: }
1.462 albertel 16953: untie(%disk_env);
16954: } else {
1.705 tempelho 16955: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16956: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16957: return 'error: '.$!;
16958: }
16959: }
16960: $env{'request.role'}='cm';
16961: $env{'request.role.adv'}=$env{'user.adv'};
16962: $env{'browser.type'}=$clientbrowser;
16963:
16964: return $cookie;
16965:
16966: }
16967:
16968: sub _add_to_env {
16969: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16970: if (ref($env_data) eq 'HASH') {
16971: while (my ($key,$value) = each(%$env_data)) {
16972: $idf->{$prefix.$key} = $value;
16973: $env{$prefix.$key} = $value;
16974: }
1.462 albertel 16975: }
16976: }
16977:
1.685 tempelho 16978: # --- Get the symbolic name of a problem and the url
16979: sub get_symb {
16980: my ($request,$silent) = @_;
1.726 raeburn 16981: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16982: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16983: if ($symb eq '') {
16984: if (!$silent) {
1.1071 raeburn 16985: if (ref($request)) {
16986: $request->print("Unable to handle ambiguous references:$url:.");
16987: }
1.685 tempelho 16988: return ();
16989: }
16990: }
16991: &Apache::lonenc::check_decrypt(\$symb);
16992: return ($symb);
16993: }
16994:
16995: # --------------------------------------------------------------Get annotation
16996:
16997: sub get_annotation {
16998: my ($symb,$enc) = @_;
16999:
17000: my $key = $symb;
17001: if (!$enc) {
17002: $key =
17003: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
17004: }
17005: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
17006: return $annotation{$key};
17007: }
17008:
17009: sub clean_symb {
1.731 raeburn 17010: my ($symb,$delete_enc) = @_;
1.685 tempelho 17011:
17012: &Apache::lonenc::check_decrypt(\$symb);
17013: my $enc = $env{'request.enc'};
1.731 raeburn 17014: if ($delete_enc) {
1.730 raeburn 17015: delete($env{'request.enc'});
17016: }
1.685 tempelho 17017:
17018: return ($symb,$enc);
17019: }
1.462 albertel 17020:
1.1181 raeburn 17021: ############################################################
17022: ############################################################
17023:
17024: =pod
17025:
17026: =head1 Routines for building display used to search for courses
17027:
17028:
17029: =over 4
17030:
17031: =item * &build_filters()
17032:
17033: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 17034: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
17035: and quotacheck.pl
17036:
1.1181 raeburn 17037:
17038: Inputs:
17039:
17040: filterlist - anonymous array of fields to include as potential filters
17041:
17042: crstype - course type
17043:
17044: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
17045: to pop-open a course selector (will contain "extra element").
17046:
17047: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
17048:
17049: filter - anonymous hash of criteria and their values
17050:
17051: action - form action
17052:
17053: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
17054:
1.1182 raeburn 17055: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 17056:
17057: cloneruname - username of owner of new course who wants to clone
17058:
17059: clonerudom - domain of owner of new course who wants to clone
17060:
17061: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
17062:
17063: codetitlesref - reference to array of titles of components in institutional codes (official courses)
17064:
17065: codedom - domain
17066:
17067: formname - value of form element named "form".
17068:
17069: fixeddom - domain, if fixed.
17070:
17071: prevphase - value to assign to form element named "phase" when going back to the previous screen
17072:
17073: cnameelement - name of form element in form on opener page which will receive title of selected course
17074:
17075: cnumelement - name of form element in form on opener page which will receive courseID of selected course
17076:
17077: cdomelement - name of form element in form on opener page which will receive domain of selected course
17078:
17079: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
17080:
17081: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
17082:
17083: clonewarning - warning message about missing information for intended course owner when DC creates a course
17084:
1.1182 raeburn 17085:
1.1181 raeburn 17086: Returns: $output - HTML for display of search criteria, and hidden form elements.
17087:
1.1182 raeburn 17088:
1.1181 raeburn 17089: Side Effects: None
17090:
17091: =cut
17092:
17093: # ---------------------------------------------- search for courses based on last activity etc.
17094:
17095: sub build_filters {
17096: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
17097: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
17098: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
17099: $cnameelement,$cnumelement,$cdomelement,$setroles,
17100: $clonetext,$clonewarning) = @_;
1.1182 raeburn 17101: my ($list,$jscript);
1.1181 raeburn 17102: my $onchange = 'javascript:updateFilters(this)';
17103: my ($domainselectform,$sincefilterform,$createdfilterform,
17104: $ownerdomselectform,$persondomselectform,$instcodeform,
17105: $typeselectform,$instcodetitle);
17106: if ($formname eq '') {
17107: $formname = $caller;
17108: }
17109: foreach my $item (@{$filterlist}) {
17110: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
17111: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
17112: if ($item eq 'domainfilter') {
17113: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
17114: } elsif ($item eq 'coursefilter') {
17115: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
17116: } elsif ($item eq 'ownerfilter') {
17117: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17118: } elsif ($item eq 'ownerdomfilter') {
17119: $filter->{'ownerdomfilter'} =
17120: &LONCAPA::clean_domain($filter->{$item});
17121: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
17122: 'ownerdomfilter',1);
17123: } elsif ($item eq 'personfilter') {
17124: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17125: } elsif ($item eq 'persondomfilter') {
17126: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
17127: 'persondomfilter',1);
17128: } else {
17129: $filter->{$item} =~ s/\W//g;
17130: }
17131: if (!$filter->{$item}) {
17132: $filter->{$item} = '';
17133: }
17134: }
17135: if ($item eq 'domainfilter') {
17136: my $allow_blank = 1;
17137: if ($formname eq 'portform') {
17138: $allow_blank=0;
17139: } elsif ($formname eq 'studentform') {
17140: $allow_blank=0;
17141: }
17142: if ($fixeddom) {
17143: $domainselectform = '<input type="hidden" name="domainfilter"'.
17144: ' value="'.$codedom.'" />'.
17145: &Apache::lonnet::domain($codedom,'description');
17146: } else {
17147: $domainselectform = &select_dom_form($filter->{$item},
17148: 'domainfilter',
17149: $allow_blank,'',$onchange);
17150: }
17151: } else {
17152: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
17153: }
17154: }
17155:
17156: # last course activity filter and selection
17157: $sincefilterform = &timebased_select_form('sincefilter',$filter);
17158:
17159: # course created filter and selection
17160: if (exists($filter->{'createdfilter'})) {
17161: $createdfilterform = &timebased_select_form('createdfilter',$filter);
17162: }
17163:
1.1239 raeburn 17164: my $prefix = $crstype;
17165: if ($crstype eq 'Placement') {
17166: $prefix = 'Placement Test'
17167: }
1.1181 raeburn 17168: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 17169: 'cac' => "$prefix Activity",
17170: 'ccr' => "$prefix Created",
17171: 'cde' => "$prefix Title",
17172: 'cdo' => "$prefix Domain",
1.1181 raeburn 17173: 'ins' => 'Institutional Code',
17174: 'inc' => 'Institutional Categorization',
1.1239 raeburn 17175: 'cow' => "$prefix Owner/Co-owner",
17176: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 17177: 'cog' => 'Type',
17178: );
17179:
17180: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17181: my $typeval = 'Course';
17182: if ($crstype eq 'Community') {
17183: $typeval = 'Community';
1.1239 raeburn 17184: } elsif ($crstype eq 'Placement') {
17185: $typeval = 'Placement';
1.1181 raeburn 17186: }
17187: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
17188: } else {
17189: $typeselectform = '<select name="type" size="1"';
17190: if ($onchange) {
17191: $typeselectform .= ' onchange="'.$onchange.'"';
17192: }
17193: $typeselectform .= '>'."\n";
1.1237 raeburn 17194: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 17195: my $shown;
17196: if ($posstype eq 'Placement') {
17197: $shown = &mt('Placement Test');
17198: } else {
17199: $shown = &mt($posstype);
17200: }
1.1181 raeburn 17201: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 17202: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 17203: }
17204: $typeselectform.="</select>";
17205: }
17206:
17207: my ($cloneableonlyform,$cloneabletitle);
17208: if (exists($filter->{'cloneableonly'})) {
17209: my $cloneableon = '';
17210: my $cloneableoff = ' checked="checked"';
17211: if ($filter->{'cloneableonly'}) {
17212: $cloneableon = $cloneableoff;
17213: $cloneableoff = '';
17214: }
17215: $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>';
17216: if ($formname eq 'ccrs') {
1.1187 bisitz 17217: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 17218: } else {
17219: $cloneabletitle = &mt('Cloneable by you');
17220: }
17221: }
17222: my $officialjs;
17223: if ($crstype eq 'Course') {
17224: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 17225: # if (($fixeddom) || ($formname eq 'requestcrs') ||
17226: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
17227: if ($codedom) {
1.1181 raeburn 17228: $officialjs = 1;
17229: ($instcodeform,$jscript,$$numtitlesref) =
17230: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
17231: $officialjs,$codetitlesref);
17232: if ($jscript) {
1.1182 raeburn 17233: $jscript = '<script type="text/javascript">'."\n".
17234: '// <![CDATA['."\n".
17235: $jscript."\n".
17236: '// ]]>'."\n".
17237: '</script>'."\n";
1.1181 raeburn 17238: }
17239: }
17240: if ($instcodeform eq '') {
17241: $instcodeform =
17242: '<input type="text" name="instcodefilter" size="10" value="'.
17243: $list->{'instcodefilter'}.'" />';
17244: $instcodetitle = $lt{'ins'};
17245: } else {
17246: $instcodetitle = $lt{'inc'};
17247: }
17248: if ($fixeddom) {
17249: $instcodetitle .= '<br />('.$codedom.')';
17250: }
17251: }
17252: }
17253: my $output = qq|
17254: <form method="post" name="filterpicker" action="$action">
17255: <input type="hidden" name="form" value="$formname" />
17256: |;
17257: if ($formname eq 'modifycourse') {
17258: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
17259: '<input type="hidden" name="prevphase" value="'.
17260: $prevphase.'" />'."\n";
1.1198 musolffc 17261: } elsif ($formname eq 'quotacheck') {
17262: $output .= qq|
17263: <input type="hidden" name="sortby" value="" />
17264: <input type="hidden" name="sortorder" value="" />
17265: |;
17266: } else {
1.1181 raeburn 17267: my $name_input;
17268: if ($cnameelement ne '') {
17269: $name_input = '<input type="hidden" name="cnameelement" value="'.
17270: $cnameelement.'" />';
17271: }
17272: $output .= qq|
1.1182 raeburn 17273: <input type="hidden" name="cnumelement" value="$cnumelement" />
17274: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 17275: $name_input
17276: $roleelement
17277: $multelement
17278: $typeelement
17279: |;
17280: if ($formname eq 'portform') {
17281: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
17282: }
17283: }
17284: if ($fixeddom) {
17285: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
17286: }
17287: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
17288: if ($sincefilterform) {
17289: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
17290: .$sincefilterform
17291: .&Apache::lonhtmlcommon::row_closure();
17292: }
17293: if ($createdfilterform) {
17294: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17295: .$createdfilterform
17296: .&Apache::lonhtmlcommon::row_closure();
17297: }
17298: if ($domainselectform) {
17299: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
17300: .$domainselectform
17301: .&Apache::lonhtmlcommon::row_closure();
17302: }
17303: if ($typeselectform) {
17304: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17305: $output .= $typeselectform;
17306: } else {
17307: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
17308: .$typeselectform
17309: .&Apache::lonhtmlcommon::row_closure();
17310: }
17311: }
17312: if ($instcodeform) {
17313: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
17314: .$instcodeform
17315: .&Apache::lonhtmlcommon::row_closure();
17316: }
17317: if (exists($filter->{'ownerfilter'})) {
17318: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
17319: '<table><tr><td>'.&mt('Username').'<br />'.
17320: '<input type="text" name="ownerfilter" size="20" value="'.
17321: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17322: $ownerdomselectform.'</td></tr></table>'.
17323: &Apache::lonhtmlcommon::row_closure();
17324: }
17325: if (exists($filter->{'personfilter'})) {
17326: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
17327: '<table><tr><td>'.&mt('Username').'<br />'.
17328: '<input type="text" name="personfilter" size="20" value="'.
17329: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17330: $persondomselectform.'</td></tr></table>'.
17331: &Apache::lonhtmlcommon::row_closure();
17332: }
17333: if (exists($filter->{'coursefilter'})) {
17334: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
17335: .'<input type="text" name="coursefilter" size="25" value="'
17336: .$list->{'coursefilter'}.'" />'
17337: .&Apache::lonhtmlcommon::row_closure();
17338: }
17339: if ($cloneableonlyform) {
17340: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
17341: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
17342: }
17343: if (exists($filter->{'descriptfilter'})) {
17344: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
17345: .'<input type="text" name="descriptfilter" size="40" value="'
17346: .$list->{'descriptfilter'}.'" />'
17347: .&Apache::lonhtmlcommon::row_closure(1);
17348: }
17349: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
17350: '<input type="hidden" name="updater" value="" />'."\n".
17351: '<input type="submit" name="gosearch" value="'.
17352: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
17353: return $jscript.$clonewarning.$output;
17354: }
17355:
17356: =pod
17357:
17358: =item * &timebased_select_form()
17359:
1.1182 raeburn 17360: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 17361: filter e.g., Course Activity, Course Created, when searching for courses
17362: or communities
17363:
17364: Inputs:
17365:
17366: item - name of form element (sincefilter or createdfilter)
17367:
17368: filter - anonymous hash of criteria and their values
17369:
17370: Returns: HTML for a select box contained a blank, then six time selections,
17371: with value set in incoming form variables currently selected.
17372:
17373: Side Effects: None
17374:
17375: =cut
17376:
17377: sub timebased_select_form {
17378: my ($item,$filter) = @_;
17379: if (ref($filter) eq 'HASH') {
17380: $filter->{$item} =~ s/[^\d-]//g;
17381: if (!$filter->{$item}) { $filter->{$item}=-1; }
17382: return &select_form(
17383: $filter->{$item},
17384: $item,
17385: { '-1' => '',
17386: '86400' => &mt('today'),
17387: '604800' => &mt('last week'),
17388: '2592000' => &mt('last month'),
17389: '7776000' => &mt('last three months'),
17390: '15552000' => &mt('last six months'),
17391: '31104000' => &mt('last year'),
17392: 'select_form_order' =>
17393: ['-1','86400','604800','2592000','7776000',
17394: '15552000','31104000']});
17395: }
17396: }
17397:
17398: =pod
17399:
17400: =item * &js_changer()
17401:
17402: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 17403: when course type or domain is changed, and also to hide 'Searching ...' on
17404: page load completion for page showing search result.
1.1181 raeburn 17405:
17406: Inputs: None
17407:
1.1183 raeburn 17408: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 17409:
17410: Side Effects: None
17411:
17412: =cut
17413:
17414: sub js_changer {
17415: return <<ENDJS;
17416: <script type="text/javascript">
17417: // <![CDATA[
17418: function updateFilters(caller) {
17419: if (typeof(caller) != "undefined") {
17420: document.filterpicker.updater.value = caller.name;
17421: }
17422: document.filterpicker.submit();
17423: }
1.1183 raeburn 17424:
17425: function hideSearching() {
17426: if (document.getElementById('searching')) {
17427: document.getElementById('searching').style.display = 'none';
17428: }
17429: return;
17430: }
17431:
1.1181 raeburn 17432: // ]]>
17433: </script>
17434:
17435: ENDJS
17436: }
17437:
17438: =pod
17439:
1.1182 raeburn 17440: =item * &search_courses()
17441:
17442: Process selected filters form course search form and pass to lonnet::courseiddump
17443: to retrieve a hash for which keys are courseIDs which match the selected filters.
17444:
17445: Inputs:
17446:
17447: dom - domain being searched
17448:
17449: type - course type ('Course' or 'Community' or '.' if any).
17450:
17451: filter - anonymous hash of criteria and their values
17452:
17453: numtitles - for institutional codes - number of categories
17454:
17455: cloneruname - optional username of new course owner
17456:
17457: clonerudom - optional domain of new course owner
17458:
1.1221 raeburn 17459: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 17460: (used when DC is using course creation form)
17461:
17462: codetitles - reference to array of titles of components in institutional codes (official courses).
17463:
1.1221 raeburn 17464: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17465: (and so can clone automatically)
17466:
17467: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17468:
17469: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17470: courses to clone
1.1182 raeburn 17471:
17472: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17473:
17474:
17475: Side Effects: None
17476:
17477: =cut
17478:
17479:
17480: sub search_courses {
1.1221 raeburn 17481: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17482: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 17483: my (%courses,%showcourses,$cloner);
17484: if (($filter->{'ownerfilter'} ne '') ||
17485: ($filter->{'ownerdomfilter'} ne '')) {
17486: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17487: $filter->{'ownerdomfilter'};
17488: }
17489: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17490: if (!$filter->{$item}) {
17491: $filter->{$item}='.';
17492: }
17493: }
17494: my $now = time;
17495: my $timefilter =
17496: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17497: my ($createdbefore,$createdafter);
17498: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17499: $createdbefore = $now;
17500: $createdafter = $now-$filter->{'createdfilter'};
17501: }
17502: my ($instcodefilter,$regexpok);
17503: if ($numtitles) {
17504: if ($env{'form.official'} eq 'on') {
17505: $instcodefilter =
17506: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17507: $regexpok = 1;
17508: } elsif ($env{'form.official'} eq 'off') {
17509: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17510: unless ($instcodefilter eq '') {
17511: $regexpok = -1;
17512: }
17513: }
17514: } else {
17515: $instcodefilter = $filter->{'instcodefilter'};
17516: }
17517: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17518: if ($type eq '') { $type = '.'; }
17519:
17520: if (($clonerudom ne '') && ($cloneruname ne '')) {
17521: $cloner = $cloneruname.':'.$clonerudom;
17522: }
17523: %courses = &Apache::lonnet::courseiddump($dom,
17524: $filter->{'descriptfilter'},
17525: $timefilter,
17526: $instcodefilter,
17527: $filter->{'combownerfilter'},
17528: $filter->{'coursefilter'},
17529: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 17530: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 17531: $filter->{'cloneableonly'},
17532: $createdbefore,$createdafter,undef,
1.1221 raeburn 17533: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 17534: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17535: my $ccrole;
17536: if ($type eq 'Community') {
17537: $ccrole = 'co';
17538: } else {
17539: $ccrole = 'cc';
17540: }
17541: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17542: $filter->{'persondomfilter'},
17543: 'userroles',undef,
17544: [$ccrole,'in','ad','ep','ta','cr'],
17545: $dom);
17546: foreach my $role (keys(%rolehash)) {
17547: my ($cnum,$cdom,$courserole) = split(':',$role);
17548: my $cid = $cdom.'_'.$cnum;
17549: if (exists($courses{$cid})) {
17550: if (ref($courses{$cid}) eq 'HASH') {
17551: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17552: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 17553: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 17554: }
17555: } else {
17556: $courses{$cid}{roles} = [$courserole];
17557: }
17558: $showcourses{$cid} = $courses{$cid};
17559: }
17560: }
17561: }
17562: %courses = %showcourses;
17563: }
17564: return %courses;
17565: }
17566:
17567: =pod
17568:
1.1181 raeburn 17569: =back
17570:
1.1207 raeburn 17571: =head1 Routines for version requirements for current course.
17572:
17573: =over 4
17574:
17575: =item * &check_release_required()
17576:
17577: Compares required LON-CAPA version with version on server, and
17578: if required version is newer looks for a server with the required version.
17579:
17580: Looks first at servers in user's owen domain; if none suitable, looks at
17581: servers in course's domain are permitted to host sessions for user's domain.
17582:
17583: Inputs:
17584:
17585: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17586:
17587: $courseid - Course ID of current course
17588:
17589: $rolecode - User's current role in course (for switchserver query string).
17590:
17591: $required - LON-CAPA version needed by course (format: Major.Minor).
17592:
17593:
17594: Returns:
17595:
17596: $switchserver - query string tp append to /adm/switchserver call (if
17597: current server's LON-CAPA version is too old.
17598:
17599: $warning - Message is displayed if no suitable server could be found.
17600:
17601: =cut
17602:
17603: sub check_release_required {
17604: my ($loncaparev,$courseid,$rolecode,$required) = @_;
17605: my ($switchserver,$warning);
17606: if ($required ne '') {
17607: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
17608: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17609: if ($reqdmajor ne '' && $reqdminor ne '') {
17610: my $otherserver;
17611: if (($major eq '' && $minor eq '') ||
17612: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
17613: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
17614: my $switchlcrev =
17615: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
17616: $userdomserver);
17617: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17618: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
17619: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
17620: my $cdom = $env{'course.'.$courseid.'.domain'};
17621: if ($cdom ne $env{'user.domain'}) {
17622: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
17623: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
17624: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17625: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
17626: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
17627: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
17628: my $canhost =
17629: &Apache::lonnet::can_host_session($env{'user.domain'},
17630: $coursedomserver,
17631: $remoterev,
17632: $udomdefaults{'remotesessions'},
17633: $defdomdefaults{'hostedsessions'});
17634:
17635: if ($canhost) {
17636: $otherserver = $coursedomserver;
17637: } else {
17638: $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.");
17639: }
17640: } else {
17641: $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).");
17642: }
17643: } else {
17644: $otherserver = $userdomserver;
17645: }
17646: }
17647: if ($otherserver ne '') {
17648: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
17649: }
17650: }
17651: }
17652: return ($switchserver,$warning);
17653: }
17654:
17655: =pod
17656:
17657: =item * &check_release_result()
17658:
17659: Inputs:
17660:
17661: $switchwarning - Warning message if no suitable server found to host session.
17662:
17663: $switchserver - query string to append to /adm/switchserver containing lonHostID
17664: and current role.
17665:
17666: Returns: HTML to display with information about requirement to switch server.
17667: Either displaying warning with link to Roles/Courses screen or
17668: display link to switchserver.
17669:
1.1181 raeburn 17670: =cut
17671:
1.1207 raeburn 17672: sub check_release_result {
17673: my ($switchwarning,$switchserver) = @_;
17674: my $output = &start_page('Selected course unavailable on this server').
17675: '<p class="LC_warning">';
17676: if ($switchwarning) {
17677: $output .= $switchwarning.'<br /><a href="/adm/roles">';
17678: if (&show_course()) {
17679: $output .= &mt('Display courses');
17680: } else {
17681: $output .= &mt('Display roles');
17682: }
17683: $output .= '</a>';
17684: } elsif ($switchserver) {
17685: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
17686: '<br />'.
17687: '<a href="/adm/switchserver?'.$switchserver.'">'.
17688: &mt('Switch Server').
17689: '</a>';
17690: }
17691: $output .= '</p>'.&end_page();
17692: return $output;
17693: }
17694:
17695: =pod
17696:
17697: =item * &needs_coursereinit()
17698:
17699: Determine if course contents stored for user's session needs to be
17700: refreshed, because content has changed since "Big Hash" last tied.
17701:
17702: Check for change is made if time last checked is more than 10 minutes ago
17703: (by default).
17704:
17705: Inputs:
17706:
17707: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17708:
17709: $interval (optional) - Time which may elapse (in s) between last check for content
17710: change in current course. (default: 600 s).
17711:
17712: Returns: an array; first element is:
17713:
17714: =over 4
17715:
17716: 'switch' - if content updates mean user's session
17717: needs to be switched to a server running a newer LON-CAPA version
17718:
17719: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
17720: on current server hosting user's session
17721:
17722: '' - if no action required.
17723:
17724: =back
17725:
17726: If first item element is 'switch':
17727:
17728: second item is $switchwarning - Warning message if no suitable server found to host session.
17729:
17730: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
17731: and current role.
17732:
17733: otherwise: no other elements returned.
17734:
17735: =back
17736:
17737: =cut
17738:
17739: sub needs_coursereinit {
17740: my ($loncaparev,$interval) = @_;
17741: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
17742: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17743: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17744: my $now = time;
17745: if ($interval eq '') {
17746: $interval = 600;
17747: }
17748: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 17749: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1283 raeburn 17750: my $blocked = &blocking_status('reinit',$cnum,$cdom,undef,1);
1.1282 raeburn 17751: if ($blocked) {
17752: return ();
17753: }
1.1207 raeburn 17754: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17755: if ($lastchange > $env{'request.course.tied'}) {
17756: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17757: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17758: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17759: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17760: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17761: $curr_reqd_hash{'internal.releaserequired'}});
17762: my ($switchserver,$switchwarning) =
17763: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17764: $curr_reqd_hash{'internal.releaserequired'});
17765: if ($switchwarning ne '' || $switchserver ne '') {
17766: return ('switch',$switchwarning,$switchserver);
17767: }
17768: }
17769: }
17770: return ('update');
17771: }
17772: }
17773: return ();
17774: }
1.1181 raeburn 17775:
1.1083 raeburn 17776: sub update_content_constraints {
1.1326 raeburn 17777: my ($cdom,$cnum,$chome,$cid,$keeporder) = @_;
1.1083 raeburn 17778: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17779: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 17780: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 17781: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 17782: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 17783: if ($item eq 'resourcetag') {
17784: if ($name eq 'responsetype') {
17785: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17786: }
1.1307 raeburn 17787: } elsif ($item eq 'course') {
17788: if ($name eq 'courserestype') {
17789: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
17790: }
1.1083 raeburn 17791: }
17792: }
17793: my $navmap = Apache::lonnavmaps::navmap->new();
17794: if (defined($navmap)) {
1.1307 raeburn 17795: my (%allresponses,%allcrsrestypes);
17796: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
17797: if ($res->is_tool()) {
17798: if ($allcrsrestypes{'exttool'}) {
17799: $allcrsrestypes{'exttool'} ++;
17800: } else {
17801: $allcrsrestypes{'exttool'} = 1;
17802: }
17803: next;
17804: }
1.1083 raeburn 17805: my %responses = $res->responseTypes();
17806: foreach my $key (keys(%responses)) {
17807: next unless(exists($checkresponsetypes{$key}));
17808: $allresponses{$key} += $responses{$key};
17809: }
17810: }
17811: foreach my $key (keys(%allresponses)) {
17812: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17813: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17814: ($reqdmajor,$reqdminor) = ($major,$minor);
17815: }
17816: }
1.1307 raeburn 17817: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 17818: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 17819: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17820: ($reqdmajor,$reqdminor) = ($major,$minor);
17821: }
17822: }
1.1083 raeburn 17823: undef($navmap);
17824: }
1.1326 raeburn 17825: my (@resources,@order,@resparms,@zombies);
17826: if ($keeporder) {
17827: use LONCAPA::map;
17828: @resources = @LONCAPA::map::resources;
17829: @order = @LONCAPA::map::order;
17830: @resparms = @LONCAPA::map::resparms;
17831: @zombies = @LONCAPA::map::zombies;
17832: }
1.1308 raeburn 17833: my $suppmap = 'supplemental.sequence';
17834: my ($suppcount,$supptools,$errors) = (0,0,0);
17835: ($suppcount,$supptools,$errors) = &recurse_supplemental($cnum,$cdom,$suppmap,
17836: $suppcount,$supptools,$errors);
1.1326 raeburn 17837: if ($keeporder) {
17838: @LONCAPA::map::resources = @resources;
17839: @LONCAPA::map::order = @order;
17840: @LONCAPA::map::resparms = @resparms;
17841: @LONCAPA::map::zombies = @zombies;
17842: }
1.1308 raeburn 17843: if ($supptools) {
17844: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
17845: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17846: ($reqdmajor,$reqdminor) = ($major,$minor);
17847: }
17848: }
1.1083 raeburn 17849: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17850: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17851: }
17852: return;
17853: }
17854:
1.1110 raeburn 17855: sub allmaps_incourse {
17856: my ($cdom,$cnum,$chome,$cid) = @_;
17857: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17858: $cid = $env{'request.course.id'};
17859: $cdom = $env{'course.'.$cid.'.domain'};
17860: $cnum = $env{'course.'.$cid.'.num'};
17861: $chome = $env{'course.'.$cid.'.home'};
17862: }
17863: my %allmaps = ();
17864: my $lastchange =
17865: &Apache::lonnet::get_coursechange($cdom,$cnum);
17866: if ($lastchange > $env{'request.course.tied'}) {
17867: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17868: unless ($ferr) {
1.1326 raeburn 17869: &update_content_constraints($cdom,$cnum,$chome,$cid,1);
1.1110 raeburn 17870: }
17871: }
17872: my $navmap = Apache::lonnavmaps::navmap->new();
17873: if (defined($navmap)) {
17874: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17875: $allmaps{$res->src()} = 1;
17876: }
17877: }
17878: return \%allmaps;
17879: }
17880:
1.1083 raeburn 17881: sub parse_supplemental_title {
17882: my ($title) = @_;
17883:
17884: my ($foldertitle,$renametitle);
17885: if ($title =~ /&&&/) {
17886: $title = &HTML::Entites::decode($title);
17887: }
17888: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17889: $renametitle=$4;
17890: my ($time,$uname,$udom) = ($1,$2,$3);
17891: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17892: my $name = &plainname($uname,$udom);
17893: $name = &HTML::Entities::encode($name,'"<>&\'');
17894: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17895: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17896: $name.': <br />'.$foldertitle;
17897: }
17898: if (wantarray) {
17899: return ($title,$foldertitle,$renametitle);
17900: }
17901: return $title;
17902: }
17903:
1.1143 raeburn 17904: sub recurse_supplemental {
1.1308 raeburn 17905: my ($cnum,$cdom,$suppmap,$numfiles,$numexttools,$errors) = @_;
1.1143 raeburn 17906: if ($suppmap) {
17907: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17908: if ($fatal) {
17909: $errors ++;
17910: } else {
17911: if ($#LONCAPA::map::resources > 0) {
17912: foreach my $res (@LONCAPA::map::resources) {
17913: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17914: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 17915: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1308 raeburn 17916: ($numfiles,$numexttools,$errors) = &recurse_supplemental($cnum,$cdom,$1,
17917: $numfiles,$numexttools,$errors);
1.1143 raeburn 17918: } else {
1.1308 raeburn 17919: if ($src =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
17920: $numexttools ++;
17921: }
1.1143 raeburn 17922: $numfiles ++;
17923: }
17924: }
17925: }
17926: }
17927: }
17928: }
1.1308 raeburn 17929: return ($numfiles,$numexttools,$errors);
1.1143 raeburn 17930: }
17931:
1.1101 raeburn 17932: sub symb_to_docspath {
1.1267 raeburn 17933: my ($symb,$navmapref) = @_;
17934: return unless ($symb && ref($navmapref));
1.1101 raeburn 17935: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17936: if ($resurl=~/\.(sequence|page)$/) {
17937: $mapurl=$resurl;
17938: } elsif ($resurl eq 'adm/navmaps') {
17939: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17940: }
17941: my $mapresobj;
1.1267 raeburn 17942: unless (ref($$navmapref)) {
17943: $$navmapref = Apache::lonnavmaps::navmap->new();
17944: }
17945: if (ref($$navmapref)) {
17946: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 17947: }
17948: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17949: my $type=$2;
17950: my $path;
17951: if (ref($mapresobj)) {
17952: my $pcslist = $mapresobj->map_hierarchy();
17953: if ($pcslist ne '') {
17954: foreach my $pc (split(/,/,$pcslist)) {
17955: next if ($pc <= 1);
1.1267 raeburn 17956: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 17957: if (ref($res)) {
17958: my $thisurl = $res->src();
17959: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17960: my $thistitle = $res->title();
17961: $path .= '&'.
17962: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 17963: &escape($thistitle).
1.1101 raeburn 17964: ':'.$res->randompick().
17965: ':'.$res->randomout().
17966: ':'.$res->encrypted().
17967: ':'.$res->randomorder().
17968: ':'.$res->is_page();
17969: }
17970: }
17971: }
17972: $path =~ s/^\&//;
17973: my $maptitle = $mapresobj->title();
17974: if ($mapurl eq 'default') {
1.1129 raeburn 17975: $maptitle = 'Main Content';
1.1101 raeburn 17976: }
17977: $path .= (($path ne '')? '&' : '').
17978: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17979: &escape($maptitle).
1.1101 raeburn 17980: ':'.$mapresobj->randompick().
17981: ':'.$mapresobj->randomout().
17982: ':'.$mapresobj->encrypted().
17983: ':'.$mapresobj->randomorder().
17984: ':'.$mapresobj->is_page();
17985: } else {
17986: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17987: my $ispage = (($type eq 'page')? 1 : '');
17988: if ($mapurl eq 'default') {
1.1129 raeburn 17989: $maptitle = 'Main Content';
1.1101 raeburn 17990: }
17991: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17992: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 17993: }
17994: unless ($mapurl eq 'default') {
17995: $path = 'default&'.
1.1146 raeburn 17996: &escape('Main Content').
1.1101 raeburn 17997: ':::::&'.$path;
17998: }
17999: return $path;
18000: }
18001:
1.1094 raeburn 18002: sub captcha_display {
1.1327 raeburn 18003: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 18004: my ($output,$error);
1.1234 raeburn 18005: my ($captcha,$pubkey,$privkey,$version) =
1.1327 raeburn 18006: &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 18007: if ($captcha eq 'original') {
1.1094 raeburn 18008: $output = &create_captcha();
18009: unless ($output) {
1.1172 raeburn 18010: $error = 'captcha';
1.1094 raeburn 18011: }
18012: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 18013: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 18014: unless ($output) {
1.1172 raeburn 18015: $error = 'recaptcha';
1.1094 raeburn 18016: }
18017: }
1.1234 raeburn 18018: return ($output,$error,$captcha,$version);
1.1094 raeburn 18019: }
18020:
18021: sub captcha_response {
1.1327 raeburn 18022: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 18023: my ($captcha_chk,$captcha_error);
1.1327 raeburn 18024: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 18025: if ($captcha eq 'original') {
1.1094 raeburn 18026: ($captcha_chk,$captcha_error) = &check_captcha();
18027: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 18028: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 18029: } else {
18030: $captcha_chk = 1;
18031: }
18032: return ($captcha_chk,$captcha_error);
18033: }
18034:
18035: sub get_captcha_config {
1.1327 raeburn 18036: my ($context,$lonhost,$dom_in_effect) = @_;
1.1234 raeburn 18037: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 18038: my $hostname = &Apache::lonnet::hostname($lonhost);
18039: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
18040: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 18041: if ($context eq 'usercreation') {
18042: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
18043: if (ref($domconfig{$context}) eq 'HASH') {
18044: $hashtocheck = $domconfig{$context}{'cancreate'};
18045: if (ref($hashtocheck) eq 'HASH') {
18046: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
18047: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
18048: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
18049: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
18050: }
18051: if ($privkey && $pubkey) {
18052: $captcha = 'recaptcha';
1.1234 raeburn 18053: $version = $hashtocheck->{'recaptchaversion'};
18054: if ($version ne '2') {
18055: $version = 1;
18056: }
1.1095 raeburn 18057: } else {
18058: $captcha = 'original';
18059: }
18060: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
18061: $captcha = 'original';
18062: }
1.1094 raeburn 18063: }
1.1095 raeburn 18064: } else {
18065: $captcha = 'captcha';
18066: }
18067: } elsif ($context eq 'login') {
18068: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
18069: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
18070: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
18071: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 18072: if ($privkey && $pubkey) {
18073: $captcha = 'recaptcha';
1.1234 raeburn 18074: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
18075: if ($version ne '2') {
18076: $version = 1;
18077: }
1.1095 raeburn 18078: } else {
18079: $captcha = 'original';
1.1094 raeburn 18080: }
1.1095 raeburn 18081: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
18082: $captcha = 'original';
1.1094 raeburn 18083: }
1.1327 raeburn 18084: } elsif ($context eq 'passwords') {
18085: if ($dom_in_effect) {
18086: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
18087: if ($passwdconf{'captcha'} eq 'recaptcha') {
18088: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
18089: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
18090: $privkey = $passwdconf{'recaptchakeys'}{'private'};
18091: }
18092: if ($privkey && $pubkey) {
18093: $captcha = 'recaptcha';
18094: $version = $passwdconf{'recaptchaversion'};
18095: if ($version ne '2') {
18096: $version = 1;
18097: }
18098: } else {
18099: $captcha = 'original';
18100: }
18101: } elsif ($passwdconf{'captcha'} ne 'notused') {
18102: $captcha = 'original';
18103: }
18104: }
18105: }
1.1234 raeburn 18106: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 18107: }
18108:
18109: sub create_captcha {
18110: my %captcha_params = &captcha_settings();
18111: my ($output,$maxtries,$tries) = ('',10,0);
18112: while ($tries < $maxtries) {
18113: $tries ++;
18114: my $captcha = Authen::Captcha->new (
18115: output_folder => $captcha_params{'output_dir'},
18116: data_folder => $captcha_params{'db_dir'},
18117: );
18118: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
18119:
18120: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
18121: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
18122: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 18123: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
18124: '<br />'.
18125: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 18126: last;
18127: }
18128: }
1.1323 raeburn 18129: if ($output eq '') {
18130: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
18131: }
1.1094 raeburn 18132: return $output;
18133: }
18134:
18135: sub captcha_settings {
18136: my %captcha_params = (
18137: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
18138: www_output_dir => "/captchaspool",
18139: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
18140: numchars => '5',
18141: );
18142: return %captcha_params;
18143: }
18144:
18145: sub check_captcha {
18146: my ($captcha_chk,$captcha_error);
18147: my $code = $env{'form.code'};
18148: my $md5sum = $env{'form.crypt'};
18149: my %captcha_params = &captcha_settings();
18150: my $captcha = Authen::Captcha->new(
18151: output_folder => $captcha_params{'output_dir'},
18152: data_folder => $captcha_params{'db_dir'},
18153: );
1.1109 raeburn 18154: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 18155: my %captcha_hash = (
18156: 0 => 'Code not checked (file error)',
18157: -1 => 'Failed: code expired',
18158: -2 => 'Failed: invalid code (not in database)',
18159: -3 => 'Failed: invalid code (code does not match crypt)',
18160: );
18161: if ($captcha_chk != 1) {
18162: $captcha_error = $captcha_hash{$captcha_chk}
18163: }
18164: return ($captcha_chk,$captcha_error);
18165: }
18166:
18167: sub create_recaptcha {
1.1234 raeburn 18168: my ($pubkey,$version) = @_;
18169: if ($version >= 2) {
18170: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
18171: } else {
18172: my $use_ssl;
18173: if ($ENV{'SERVER_PORT'} == 443) {
18174: $use_ssl = 1;
18175: }
18176: my $captcha = Captcha::reCAPTCHA->new;
18177: return $captcha->get_options_setter({theme => 'white'})."\n".
18178: $captcha->get_html($pubkey,undef,$use_ssl).
18179: &mt('If the text is hard to read, [_1] will replace them.',
18180: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
18181: '<br /><br />';
18182: }
1.1094 raeburn 18183: }
18184:
18185: sub check_recaptcha {
1.1234 raeburn 18186: my ($privkey,$version) = @_;
1.1094 raeburn 18187: my $captcha_chk;
1.1350 raeburn 18188: my $ip = &Apache::lonnet::get_requestor_ip();
1.1234 raeburn 18189: if ($version >= 2) {
18190: my %info = (
18191: secret => $privkey,
18192: response => $env{'form.g-recaptcha-response'},
1.1350 raeburn 18193: remoteip => $ip,
1.1234 raeburn 18194: );
1.1280 raeburn 18195: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
18196: $request->content(join('&',map {
18197: my $name = escape($_);
18198: "$name=" . ( ref($info{$_}) eq 'ARRAY'
18199: ? join("&$name=", map {escape($_) } @{$info{$_}})
18200: : &escape($info{$_}) );
18201: } keys(%info)));
18202: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 18203: if ($response->is_success) {
18204: my $data = JSON::DWIW->from_json($response->decoded_content);
18205: if (ref($data) eq 'HASH') {
18206: if ($data->{'success'}) {
18207: $captcha_chk = 1;
18208: }
18209: }
18210: }
18211: } else {
18212: my $captcha = Captcha::reCAPTCHA->new;
18213: my $captcha_result =
18214: $captcha->check_answer(
18215: $privkey,
1.1350 raeburn 18216: $ip,
1.1234 raeburn 18217: $env{'form.recaptcha_challenge_field'},
18218: $env{'form.recaptcha_response_field'},
18219: );
18220: if ($captcha_result->{is_valid}) {
18221: $captcha_chk = 1;
18222: }
1.1094 raeburn 18223: }
18224: return $captcha_chk;
18225: }
18226:
1.1174 raeburn 18227: sub emailusername_info {
1.1244 raeburn 18228: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 18229: my %titles = &Apache::lonlocal::texthash (
18230: lastname => 'Last Name',
18231: firstname => 'First Name',
18232: institution => 'School/college/university',
18233: location => "School's city, state/province, country",
18234: web => "School's web address",
18235: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 18236: id => 'Student/Employee ID',
1.1174 raeburn 18237: );
18238: return (\@fields,\%titles);
18239: }
18240:
1.1161 raeburn 18241: sub cleanup_html {
18242: my ($incoming) = @_;
18243: my $outgoing;
18244: if ($incoming ne '') {
18245: $outgoing = $incoming;
18246: $outgoing =~ s/;/;/g;
18247: $outgoing =~ s/\#/#/g;
18248: $outgoing =~ s/\&/&/g;
18249: $outgoing =~ s/</</g;
18250: $outgoing =~ s/>/>/g;
18251: $outgoing =~ s/\(/(/g;
18252: $outgoing =~ s/\)/)/g;
18253: $outgoing =~ s/"/"/g;
18254: $outgoing =~ s/'/'/g;
18255: $outgoing =~ s/\$/$/g;
18256: $outgoing =~ s{/}{/}g;
18257: $outgoing =~ s/=/=/g;
18258: $outgoing =~ s/\\/\/g
18259: }
18260: return $outgoing;
18261: }
18262:
1.1190 musolffc 18263: # Checks for critical messages and returns a redirect url if one exists.
18264: # $interval indicates how often to check for messages.
1.1282 raeburn 18265: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 18266: sub critical_redirect {
1.1282 raeburn 18267: my ($interval,$context) = @_;
1.1356 raeburn 18268: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
18269: return ();
18270: }
1.1190 musolffc 18271: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 18272: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
18273: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18274: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18275: my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
18276: if ($blocked) {
18277: my $checkrole = "cm./$cdom/$cnum";
18278: if ($env{'request.course.sec'} ne '') {
18279: $checkrole .= "/$env{'request.course.sec'}";
18280: }
18281: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
18282: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
18283: return;
18284: }
18285: }
18286: }
1.1190 musolffc 18287: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
18288: $env{'user.name'});
18289: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 18290: my $redirecturl;
1.1190 musolffc 18291: if ($what[0]) {
1.1356 raeburn 18292: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1190 musolffc 18293: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 18294: my $url=&Apache::lonnet::absolute_url().$redirecturl;
18295: return (1, $url);
1.1190 musolffc 18296: }
1.1191 raeburn 18297: }
18298: }
18299: return ();
1.1190 musolffc 18300: }
18301:
1.1174 raeburn 18302: # Use:
18303: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
18304: #
18305: ##################################################
18306: # password associated functions #
18307: ##################################################
18308: sub des_keys {
18309: # Make a new key for DES encryption.
18310: # Each key has two parts which are returned separately.
18311: # Please note: Each key must be passed through the &hex function
18312: # before it is output to the web browser. The hex versions cannot
18313: # be used to decrypt.
18314: my @hexstr=('0','1','2','3','4','5','6','7',
18315: '8','9','a','b','c','d','e','f');
18316: my $lkey='';
18317: for (0..7) {
18318: $lkey.=$hexstr[rand(15)];
18319: }
18320: my $ukey='';
18321: for (0..7) {
18322: $ukey.=$hexstr[rand(15)];
18323: }
18324: return ($lkey,$ukey);
18325: }
18326:
18327: sub des_decrypt {
18328: my ($key,$cyphertext) = @_;
18329: my $keybin=pack("H16",$key);
18330: my $cypher;
18331: if ($Crypt::DES::VERSION>=2.03) {
18332: $cypher=new Crypt::DES $keybin;
18333: } else {
18334: $cypher=new DES $keybin;
18335: }
1.1233 raeburn 18336: my $plaintext='';
18337: my $cypherlength = length($cyphertext);
18338: my $numchunks = int($cypherlength/32);
18339: for (my $j=0; $j<$numchunks; $j++) {
18340: my $start = $j*32;
18341: my $cypherblock = substr($cyphertext,$start,32);
18342: my $chunk =
18343: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
18344: $chunk .=
18345: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
18346: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
18347: $plaintext .= $chunk;
18348: }
1.1174 raeburn 18349: return $plaintext;
18350: }
18351:
1.1344 raeburn 18352: sub get_requested_shorturls {
1.1309 raeburn 18353: my ($cdom,$cnum,$navmap) = @_;
18354: return unless (ref($navmap));
1.1344 raeburn 18355: my ($numnew,$errors);
1.1309 raeburn 18356: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
18357: if (@toshorten) {
18358: my (%maps,%resources,%titles);
18359: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
18360: 'shorturls',$cdom,$cnum);
18361: if (keys(%resources)) {
1.1344 raeburn 18362: my %tocreate;
1.1309 raeburn 18363: foreach my $item (sort {$a <=> $b} (@toshorten)) {
18364: my $symb = $resources{$item};
18365: if ($symb) {
18366: $tocreate{$cnum.'&'.$symb} = 1;
18367: }
18368: }
1.1344 raeburn 18369: if (keys(%tocreate)) {
18370: ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
18371: \%tocreate);
18372: }
1.1309 raeburn 18373: }
1.1344 raeburn 18374: }
18375: return ($numnew,$errors);
18376: }
18377:
18378: sub make_short_symbs {
18379: my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
18380: my ($numnew,@errors);
18381: if (ref($tocreateref) eq 'HASH') {
18382: my %tocreate = %{$tocreateref};
1.1309 raeburn 18383: if (keys(%tocreate)) {
18384: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
18385: my $su = Short::URL->new(no_vowels => 1);
18386: my $init = '';
18387: my (%newunique,%addcourse,%courseonly,%failed);
18388: # get lock on tiny db
18389: my $now = time;
1.1344 raeburn 18390: if ($lockuser eq '') {
18391: $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
18392: }
1.1309 raeburn 18393: my $lockhash = {
1.1344 raeburn 18394: "lock\0$now" => $lockuser,
1.1309 raeburn 18395: };
18396: my $tries = 0;
18397: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18398: my ($code,$error);
18399: while (($gotlock ne 'ok') && ($tries<3)) {
18400: $tries ++;
18401: sleep 1;
1.1319 raeburn 18402: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 18403: }
18404: if ($gotlock eq 'ok') {
18405: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
18406: \%addcourse,\%courseonly,\%failed);
18407: if (keys(%failed)) {
18408: my $numfailed = scalar(keys(%failed));
18409: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
18410: }
18411: if (keys(%newunique)) {
18412: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
18413: if ($putres eq 'ok') {
18414: $numnew = scalar(keys(%newunique));
18415: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
18416: unless ($newputres eq 'ok') {
18417: push(@errors,&mt('error: could not store course look-up of short URLs'));
18418: }
18419: } else {
18420: push(@errors,&mt('error: could not store unique six character URLs'));
18421: }
18422: }
18423: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
18424: unless ($dellockres eq 'ok') {
18425: push(@errors,&mt('error: could not release lockfile'));
18426: }
18427: } else {
18428: push(@errors,&mt('error: could not obtain lockfile'));
18429: }
18430: if (keys(%courseonly)) {
18431: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
18432: if ($result ne 'ok') {
18433: push(@errors,&mt('error: could not update course look-up of short URLs'));
18434: }
18435: }
18436: }
18437: }
18438: return ($numnew,\@errors);
18439: }
18440:
18441: sub shorten_symbs {
18442: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
18443: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
18444: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
18445: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
18446: my (%possibles,%collisions);
18447: foreach my $key (keys(%{$tocreate})) {
18448: my $num = String::CRC32::crc32($key);
18449: my $tiny = $su->encode($num,$init);
18450: if ($tiny) {
18451: $possibles{$tiny} = $key;
18452: }
18453: }
18454: if (!$init) {
18455: $init = 1;
18456: } else {
18457: $init ++;
18458: }
18459: if (keys(%possibles)) {
18460: my @posstiny = keys(%possibles);
18461: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
18462: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
18463: if (keys(%currtiny)) {
18464: foreach my $key (keys(%currtiny)) {
18465: next if ($currtiny{$key} eq '');
18466: if ($currtiny{$key} eq $possibles{$key}) {
18467: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
18468: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18469: $courseonly->{$tsymb} = $key;
18470: }
18471: } else {
18472: $collisions{$possibles{$key}} = 1;
18473: }
18474: delete($possibles{$key});
18475: }
18476: }
18477: foreach my $key (keys(%possibles)) {
18478: $newunique->{$key} = $possibles{$key};
18479: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
18480: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18481: $addcourse->{$tsymb} = $key;
18482: }
18483: }
18484: }
18485: if (keys(%collisions)) {
18486: if ($init <5) {
18487: if (!$init) {
18488: $init = 1;
18489: } else {
18490: $init ++;
18491: }
18492: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
18493: $newunique,$addcourse,$courseonly,$failed);
18494: } else {
18495: foreach my $key (keys(%collisions)) {
18496: $failed->{$key} = 1;
18497: }
18498: }
18499: }
18500: return $init;
18501: }
18502:
1.1328 raeburn 18503: sub is_nonframeable {
1.1329 raeburn 18504: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
18505: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
1.1330 raeburn 18506: return if (($remprotocol eq '') || ($remhost eq ''));
1.1329 raeburn 18507:
18508: $remprotocol = lc($remprotocol);
18509: $remhost = lc($remhost);
18510: my $remport = 80;
18511: if ($remprotocol eq 'https') {
18512: $remport = 443;
18513: }
1.1330 raeburn 18514: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
1.1329 raeburn 18515: if ($cached) {
18516: unless ($nocache) {
18517: if ($result) {
18518: return 1;
18519: } else {
18520: return 0;
18521: }
18522: }
18523: }
1.1328 raeburn 18524: my $uselink;
18525: my $request = new HTTP::Request('HEAD',$url);
18526: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
18527: if ($response->is_success()) {
18528: my $secpolicy = lc($response->header('content-security-policy'));
18529: my $xframeop = lc($response->header('x-frame-options'));
18530: $secpolicy =~ s/^\s+|\s+$//g;
18531: $xframeop =~ s/^\s+|\s+$//g;
18532: if (($secpolicy ne '') || ($xframeop ne '')) {
1.1329 raeburn 18533: my $remotehost = $remprotocol.'://'.$remhost;
1.1328 raeburn 18534: my ($origin,$protocol,$port);
18535: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
18536: $port = $ENV{'SERVER_PORT'};
18537: } else {
18538: $port = 80;
18539: }
18540: if ($absolute eq '') {
18541: $protocol = 'http:';
18542: if ($port == 443) {
18543: $protocol = 'https:';
18544: }
18545: $origin = $protocol.'//'.lc($hostname);
18546: } else {
18547: $origin = lc($absolute);
18548: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
18549: }
18550: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
18551: my $framepolicy = $1;
18552: $framepolicy =~ s/^\s+|\s+$//g;
18553: my @policies = split(/\s+/,$framepolicy);
18554: if (@policies) {
18555: if (grep(/^\Q'none'\E$/,@policies)) {
18556: $uselink = 1;
18557: } else {
18558: $uselink = 1;
18559: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
18560: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
18561: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
18562: undef($uselink);
18563: }
18564: if ($uselink) {
18565: if (grep(/^\Q'self'\E$/,@policies)) {
18566: if (($origin ne '') && ($remotehost eq $origin)) {
18567: undef($uselink);
18568: }
18569: }
18570: }
18571: if ($uselink) {
18572: my @possok;
18573: if ($ip ne '') {
18574: push(@possok,$ip);
18575: }
18576: my $hoststr = '';
18577: foreach my $part (reverse(split(/\./,$hostname))) {
18578: if ($hoststr eq '') {
18579: $hoststr = $part;
18580: } else {
18581: $hoststr = "$part.$hoststr";
18582: }
18583: if ($hoststr eq $hostname) {
18584: push(@possok,$hostname);
18585: } else {
18586: push(@possok,"*.$hoststr");
18587: }
18588: }
18589: if (@possok) {
18590: foreach my $poss (@possok) {
18591: last if (!$uselink);
18592: foreach my $policy (@policies) {
18593: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
18594: undef($uselink);
18595: last;
18596: }
18597: }
18598: }
18599: }
18600: }
18601: }
18602: }
18603: } elsif ($xframeop ne '') {
18604: $uselink = 1;
18605: my @policies = split(/\s*,\s*/,$xframeop);
18606: if (@policies) {
18607: unless (grep(/^deny$/,@policies)) {
18608: if ($origin ne '') {
18609: if (grep(/^sameorigin$/,@policies)) {
18610: if ($remotehost eq $origin) {
18611: undef($uselink);
18612: }
18613: }
18614: if ($uselink) {
18615: foreach my $policy (@policies) {
18616: if ($policy =~ /^allow-from\s*(.+)$/) {
18617: my $allowfrom = $1;
18618: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
18619: undef($uselink);
18620: last;
18621: }
18622: }
18623: }
18624: }
18625: }
18626: }
18627: }
18628: }
18629: }
18630: }
1.1329 raeburn 18631: if ($nocache) {
18632: if ($cached) {
18633: my $devalidate;
18634: if ($uselink && !$result) {
18635: $devalidate = 1;
18636: } elsif (!$uselink && $result) {
18637: $devalidate = 1;
18638: }
18639: if ($devalidate) {
18640: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
18641: }
18642: }
18643: } else {
18644: if ($uselink) {
18645: $result = 1;
18646: } else {
18647: $result = 0;
18648: }
18649: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
18650: }
1.1328 raeburn 18651: return $uselink;
18652: }
18653:
1.112 bowersj2 18654: 1;
18655: __END__;
1.41 ng 18656:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>