Annotation of loncom/interface/loncommon.pm, revision 1.1334
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1334 ! raeburn 4: # $Id: loncommon.pm,v 1.1333 2019/08/25 02:42:56 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;
83: use LWP::UserAgent;
1.1174 raeburn 84: use Crypt::DES;
85: use DynaLoader; # for Crypt::DES version
1.1223 musolffc 86: use MIME::Lite;
87: use MIME::Types;
1.1292 raeburn 88: use File::Copy();
1.1300 raeburn 89: use File::Path();
1.1309 raeburn 90: use String::CRC32();
91: use Short::URL();
1.117 www 92:
1.517 raeburn 93: # ---------------------------------------------- Designs
94: use vars qw(%defaultdesign);
95:
1.22 www 96: my $readit;
97:
1.517 raeburn 98:
1.157 matthew 99: ##
100: ## Global Variables
101: ##
1.46 matthew 102:
1.643 foxr 103:
104: # ----------------------------------------------- SSI with retries:
105: #
106:
107: =pod
108:
1.648 raeburn 109: =head1 Server Side include with retries:
1.643 foxr 110:
111: =over 4
112:
1.648 raeburn 113: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 114:
115: Performs an ssi with some number of retries. Retries continue either
116: until the result is ok or until the retry count supplied by the
117: caller is exhausted.
118:
119: Inputs:
1.648 raeburn 120:
121: =over 4
122:
1.643 foxr 123: resource - Identifies the resource to insert.
1.648 raeburn 124:
1.643 foxr 125: retries - Count of the number of retries allowed.
1.648 raeburn 126:
1.643 foxr 127: form - Hash that identifies the rendering options.
128:
1.648 raeburn 129: =back
130:
131: Returns:
132:
133: =over 4
134:
1.643 foxr 135: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 136:
1.643 foxr 137: response - The response from the last attempt (which may or may not have been successful.
138:
1.648 raeburn 139: =back
140:
141: =back
142:
1.643 foxr 143: =cut
144:
145: sub ssi_with_retries {
146: my ($resource, $retries, %form) = @_;
147:
148:
149: my $ok = 0; # True if we got a good response.
150: my $content;
151: my $response;
152:
153: # Try to get the ssi done. within the retries count:
154:
155: do {
156: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
157: $ok = $response->is_success;
1.650 www 158: if (!$ok) {
159: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
160: }
1.643 foxr 161: $retries--;
162: } while (!$ok && ($retries > 0));
163:
164: if (!$ok) {
165: $content = ''; # On error return an empty content.
166: }
167: return ($content, $response);
168:
169: }
170:
171:
172:
1.20 www 173: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 174: my %language;
1.124 www 175: my %supported_language;
1.1088 foxr 176: my %supported_codes;
1.1048 foxr 177: my %latex_language; # For choosing hyphenation in <transl..>
178: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 179: my %cprtag;
1.192 taceyjo1 180: my %scprtag;
1.351 www 181: my %fe; my %fd; my %fm;
1.41 ng 182: my %category_extensions;
1.12 harris41 183:
1.46 matthew 184: # ---------------------------------------------- Thesaurus variables
1.144 matthew 185: #
186: # %Keywords:
187: # A hash used by &keyword to determine if a word is considered a keyword.
188: # $thesaurus_db_file
189: # Scalar containing the full path to the thesaurus database.
1.46 matthew 190:
191: my %Keywords;
192: my $thesaurus_db_file;
193:
1.144 matthew 194: #
195: # Initialize values from language.tab, copyright.tab, filetypes.tab,
196: # thesaurus.tab, and filecategories.tab.
197: #
1.18 www 198: BEGIN {
1.46 matthew 199: # Variable initialization
200: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
201: #
1.22 www 202: unless ($readit) {
1.12 harris41 203: # ------------------------------------------------------------------- languages
204: {
1.158 raeburn 205: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
206: '/language.tab';
1.1317 raeburn 207: if ( open(my $fh,'<',$langtabfile) ) {
1.356 albertel 208: while (my $line = <$fh>) {
209: next if ($line=~/^\#/);
210: chomp($line);
1.1088 foxr 211: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 212: $language{$key}=$val.' - '.$enc;
213: if ($sup) {
214: $supported_language{$key}=$sup;
1.1088 foxr 215: $supported_codes{$key} = $code;
1.158 raeburn 216: }
1.1048 foxr 217: if ($latex) {
218: $latex_language_bykey{$key} = $latex;
1.1088 foxr 219: $latex_language{$code} = $latex;
1.1048 foxr 220: }
1.158 raeburn 221: }
222: close($fh);
223: }
1.12 harris41 224: }
225: # ------------------------------------------------------------------ copyrights
226: {
1.158 raeburn 227: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
228: '/copyright.tab';
1.1317 raeburn 229: if ( open (my $fh,'<',$copyrightfile) ) {
1.356 albertel 230: while (my $line = <$fh>) {
231: next if ($line=~/^\#/);
232: chomp($line);
233: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 234: $cprtag{$key}=$val;
235: }
236: close($fh);
237: }
1.12 harris41 238: }
1.351 www 239: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 240: {
241: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
242: '/source_copyright.tab';
1.1317 raeburn 243: if ( open (my $fh,'<',$sourcecopyrightfile) ) {
1.356 albertel 244: while (my $line = <$fh>) {
245: next if ($line =~ /^\#/);
246: chomp($line);
247: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 248: $scprtag{$key}=$val;
249: }
250: close($fh);
251: }
252: }
1.63 www 253:
1.517 raeburn 254: # -------------------------------------------------------------- default domain designs
1.63 www 255: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 256: my $designfile = $designdir.'/default.tab';
1.1317 raeburn 257: if ( open (my $fh,'<',$designfile) ) {
1.517 raeburn 258: while (my $line = <$fh>) {
259: next if ($line =~ /^\#/);
260: chomp($line);
261: my ($key,$val)=(split(/\=/,$line));
262: if ($val) { $defaultdesign{$key}=$val; }
263: }
264: close($fh);
1.63 www 265: }
266:
1.15 harris41 267: # ------------------------------------------------------------- file categories
268: {
1.158 raeburn 269: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
270: '/filecategories.tab';
1.1317 raeburn 271: if ( open (my $fh,'<',$categoryfile) ) {
1.356 albertel 272: while (my $line = <$fh>) {
273: next if ($line =~ /^\#/);
274: chomp($line);
275: my ($extension,$category)=(split(/\s+/,$line,2));
1.1263 raeburn 276: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 277: }
278: close($fh);
279: }
280:
1.15 harris41 281: }
1.12 harris41 282: # ------------------------------------------------------------------ file types
283: {
1.158 raeburn 284: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
285: '/filetypes.tab';
1.1317 raeburn 286: if ( open (my $fh,'<',$typesfile) ) {
1.356 albertel 287: while (my $line = <$fh>) {
288: next if ($line =~ /^\#/);
289: chomp($line);
290: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 291: if ($descr ne '') {
292: $fe{$ending}=lc($emb);
293: $fd{$ending}=$descr;
1.351 www 294: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 295: }
296: }
297: close($fh);
298: }
1.12 harris41 299: }
1.22 www 300: &Apache::lonnet::logthis(
1.705 tempelho 301: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 302: $readit=1;
1.46 matthew 303: } # end of unless($readit)
1.32 matthew 304:
305: }
1.112 bowersj2 306:
1.42 matthew 307: ###############################################################
308: ## HTML and Javascript Helper Functions ##
309: ###############################################################
310:
311: =pod
312:
1.112 bowersj2 313: =head1 HTML and Javascript Functions
1.42 matthew 314:
1.112 bowersj2 315: =over 4
316:
1.648 raeburn 317: =item * &browser_and_searcher_javascript()
1.112 bowersj2 318:
319: X<browsing, javascript>X<searching, javascript>Returns a string
320: containing javascript with two functions, C<openbrowser> and
321: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
322: tags.
1.42 matthew 323:
1.648 raeburn 324: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 325:
326: inputs: formname, elementname, only, omit
327:
328: formname and elementname indicate the name of the html form and name of
329: the element that the results of the browsing selection are to be placed in.
330:
331: Specifying 'only' will restrict the browser to displaying only files
1.185 www 332: with the given extension. Can be a comma separated list.
1.42 matthew 333:
334: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 335: with the given extension. Can be a comma separated list.
1.42 matthew 336:
1.648 raeburn 337: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 338:
339: Inputs: formname, elementname
340:
341: formname and elementname specify the name of the html form and the name
342: of the element the selection from the search results will be placed in.
1.542 raeburn 343:
1.42 matthew 344: =cut
345:
346: sub browser_and_searcher_javascript {
1.199 albertel 347: my ($mode)=@_;
348: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 349: my $resurl=&escape_single(&lastresurl());
1.42 matthew 350: return <<END;
1.219 albertel 351: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 352: var editbrowser = null;
1.135 albertel 353: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 354: var url = '$resurl/?';
1.42 matthew 355: if (editbrowser == null) {
356: url += 'launch=1&';
357: }
358: url += 'catalogmode=interactive&';
1.199 albertel 359: url += 'mode=$mode&';
1.611 albertel 360: url += 'inhibitmenu=yes&';
1.42 matthew 361: url += 'form=' + formname + '&';
362: if (only != null) {
363: url += 'only=' + only + '&';
1.217 albertel 364: } else {
365: url += 'only=&';
366: }
1.42 matthew 367: if (omit != null) {
368: url += 'omit=' + omit + '&';
1.217 albertel 369: } else {
370: url += 'omit=&';
371: }
1.135 albertel 372: if (titleelement != null) {
373: url += 'titleelement=' + titleelement + '&';
1.217 albertel 374: } else {
375: url += 'titleelement=&';
376: }
1.42 matthew 377: url += 'element=' + elementname + '';
378: var title = 'Browser';
1.435 albertel 379: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 380: options += ',width=700,height=600';
381: editbrowser = open(url,title,options,'1');
382: editbrowser.focus();
383: }
384: var editsearcher;
1.135 albertel 385: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 386: var url = '/adm/searchcat?';
387: if (editsearcher == null) {
388: url += 'launch=1&';
389: }
390: url += 'catalogmode=interactive&';
1.199 albertel 391: url += 'mode=$mode&';
1.42 matthew 392: url += 'form=' + formname + '&';
1.135 albertel 393: if (titleelement != null) {
394: url += 'titleelement=' + titleelement + '&';
1.217 albertel 395: } else {
396: url += 'titleelement=&';
397: }
1.42 matthew 398: url += 'element=' + elementname + '';
399: var title = 'Search';
1.435 albertel 400: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 401: options += ',width=700,height=600';
402: editsearcher = open(url,title,options,'1');
403: editsearcher.focus();
404: }
1.219 albertel 405: // END LON-CAPA Internal -->
1.42 matthew 406: END
1.170 www 407: }
408:
409: sub lastresurl {
1.258 albertel 410: if ($env{'environment.lastresurl'}) {
411: return $env{'environment.lastresurl'}
1.170 www 412: } else {
413: return '/res';
414: }
415: }
416:
417: sub storeresurl {
418: my $resurl=&Apache::lonnet::clutter(shift);
419: unless ($resurl=~/^\/res/) { return 0; }
420: $resurl=~s/\/$//;
421: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 422: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 423: return 1;
1.42 matthew 424: }
425:
1.74 www 426: sub studentbrowser_javascript {
1.111 www 427: unless (
1.258 albertel 428: (($env{'request.course.id'}) &&
1.302 albertel 429: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
430: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
431: '/'.$env{'request.course.sec'})
432: ))
1.258 albertel 433: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 434: ) { return ''; }
1.74 www 435: return (<<'ENDSTDBRW');
1.776 bisitz 436: <script type="text/javascript" language="Javascript">
1.824 bisitz 437: // <![CDATA[
1.74 www 438: var stdeditbrowser;
1.999 www 439: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 440: var url = '/adm/pickstudent?';
441: var filter;
1.558 albertel 442: if (!ignorefilter) {
443: eval('filter=document.'+formname+'.'+uname+'.value;');
444: }
1.74 www 445: if (filter != null) {
446: if (filter != '') {
447: url += 'filter='+filter+'&';
448: }
449: }
450: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 451: '&udomelement='+udom+
452: '&clicker='+clicker;
1.111 www 453: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 454: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 455: var title = 'Student_Browser';
1.74 www 456: var options = 'scrollbars=1,resizable=1,menubar=0';
457: options += ',width=700,height=600';
458: stdeditbrowser = open(url,title,options,'1');
459: stdeditbrowser.focus();
460: }
1.824 bisitz 461: // ]]>
1.74 www 462: </script>
463: ENDSTDBRW
464: }
1.42 matthew 465:
1.1003 www 466: sub resourcebrowser_javascript {
467: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 468: return (<<'ENDRESBRW');
1.1003 www 469: <script type="text/javascript" language="Javascript">
470: // <![CDATA[
471: var reseditbrowser;
1.1004 www 472: function openresbrowser(formname,reslink) {
1.1005 www 473: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 474: var title = 'Resource_Browser';
475: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 476: options += ',width=700,height=500';
1.1004 www 477: reseditbrowser = open(url,title,options,'1');
478: reseditbrowser.focus();
1.1003 www 479: }
480: // ]]>
481: </script>
1.1004 www 482: ENDRESBRW
1.1003 www 483: }
484:
1.74 www 485: sub selectstudent_link {
1.999 www 486: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
487: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
488: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
489: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 490: if ($env{'request.course.id'}) {
1.302 albertel 491: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
492: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
493: '/'.$env{'request.course.sec'})) {
1.111 www 494: return '';
495: }
1.999 www 496: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 497: if ($courseadvonly) {
498: $callargs .= ",'',1,1";
499: }
500: return '<span class="LC_nobreak">'.
501: '<a href="javascript:openstdbrowser('.$callargs.');">'.
502: &mt('Select User').'</a></span>';
1.74 www 503: }
1.258 albertel 504: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 505: $callargs .= ",'',1";
1.793 raeburn 506: return '<span class="LC_nobreak">'.
507: '<a href="javascript:openstdbrowser('.$callargs.');">'.
508: &mt('Select User').'</a></span>';
1.111 www 509: }
510: return '';
1.91 www 511: }
512:
1.1004 www 513: sub selectresource_link {
514: my ($form,$reslink,$arg)=@_;
515:
516: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
517: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
518: unless ($env{'request.course.id'}) { return $arg; }
519: return '<span class="LC_nobreak">'.
520: '<a href="javascript:openresbrowser('.$callargs.');">'.
521: $arg.'</a></span>';
522: }
523:
524:
525:
1.653 raeburn 526: sub authorbrowser_javascript {
527: return <<"ENDAUTHORBRW";
1.776 bisitz 528: <script type="text/javascript" language="JavaScript">
1.824 bisitz 529: // <![CDATA[
1.653 raeburn 530: var stdeditbrowser;
531:
532: function openauthorbrowser(formname,udom) {
533: var url = '/adm/pickauthor?';
534: url += 'form='+formname+'&roledom='+udom;
535: var title = 'Author_Browser';
536: var options = 'scrollbars=1,resizable=1,menubar=0';
537: options += ',width=700,height=600';
538: stdeditbrowser = open(url,title,options,'1');
539: stdeditbrowser.focus();
540: }
541:
1.824 bisitz 542: // ]]>
1.653 raeburn 543: </script>
544: ENDAUTHORBRW
545: }
546:
1.91 www 547: sub coursebrowser_javascript {
1.1116 raeburn 548: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1221 raeburn 549: $credits_element,$instcode) = @_;
1.932 raeburn 550: my $wintitle = 'Course_Browser';
1.931 raeburn 551: if ($crstype eq 'Community') {
1.932 raeburn 552: $wintitle = 'Community_Browser';
1.909 raeburn 553: }
1.876 raeburn 554: my $id_functions = &javascript_index_functions();
555: my $output = '
1.776 bisitz 556: <script type="text/javascript" language="JavaScript">
1.824 bisitz 557: // <![CDATA[
1.468 raeburn 558: var stdeditbrowser;'."\n";
1.876 raeburn 559:
560: $output .= <<"ENDSTDBRW";
1.909 raeburn 561: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 562: var url = '/adm/pickcourse?';
1.895 raeburn 563: var formid = getFormIdByName(formname);
1.876 raeburn 564: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 565: if (domainfilter != null) {
566: if (domainfilter != '') {
567: url += 'domainfilter='+domainfilter+'&';
568: }
569: }
1.91 www 570: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 571: '&cdomelement='+udom+
572: '&cnameelement='+desc;
1.468 raeburn 573: if (extra_element !=null && extra_element != '') {
1.594 raeburn 574: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 575: url += '&roleelement='+extra_element;
576: if (domainfilter == null || domainfilter == '') {
577: url += '&domainfilter='+extra_element;
578: }
1.234 raeburn 579: }
1.468 raeburn 580: else {
581: if (formname == 'portform') {
582: url += '&setroles='+extra_element;
1.800 raeburn 583: } else {
584: if (formname == 'rules') {
585: url += '&fixeddom='+extra_element;
586: }
1.468 raeburn 587: }
588: }
1.230 raeburn 589: }
1.909 raeburn 590: if (type != null && type != '') {
591: url += '&type='+type;
592: }
593: if (type_elem != null && type_elem != '') {
594: url += '&typeelement='+type_elem;
595: }
1.872 raeburn 596: if (formname == 'ccrs') {
597: var ownername = document.forms[formid].ccuname.value;
598: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1238 raeburn 599: url += '&cloner='+ownername+':'+ownerdom;
600: if (type == 'Course') {
601: url += '&crscode='+document.forms[formid].crscode.value;
602: }
1.1221 raeburn 603: }
604: if (formname == 'requestcrs') {
605: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 606: }
1.293 raeburn 607: if (multflag !=null && multflag != '') {
608: url += '&multiple='+multflag;
609: }
1.909 raeburn 610: var title = '$wintitle';
1.91 www 611: var options = 'scrollbars=1,resizable=1,menubar=0';
612: options += ',width=700,height=600';
613: stdeditbrowser = open(url,title,options,'1');
614: stdeditbrowser.focus();
615: }
1.876 raeburn 616: $id_functions
617: ENDSTDBRW
1.1116 raeburn 618: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
619: $output .= &setsec_javascript($sec_element,$formname,$role_element,
620: $credits_element);
1.876 raeburn 621: }
622: $output .= '
623: // ]]>
624: </script>';
625: return $output;
626: }
627:
628: sub javascript_index_functions {
629: return <<"ENDJS";
630:
631: function getFormIdByName(formname) {
632: for (var i=0;i<document.forms.length;i++) {
633: if (document.forms[i].name == formname) {
634: return i;
635: }
636: }
637: return -1;
638: }
639:
640: function getIndexByName(formid,item) {
641: for (var i=0;i<document.forms[formid].elements.length;i++) {
642: if (document.forms[formid].elements[i].name == item) {
643: return i;
644: }
645: }
646: return -1;
647: }
1.468 raeburn 648:
1.876 raeburn 649: function getDomainFromSelectbox(formname,udom) {
650: var userdom;
651: var formid = getFormIdByName(formname);
652: if (formid > -1) {
653: var domid = getIndexByName(formid,udom);
654: if (domid > -1) {
655: if (document.forms[formid].elements[domid].type == 'select-one') {
656: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
657: }
658: if (document.forms[formid].elements[domid].type == 'hidden') {
659: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 660: }
661: }
662: }
1.876 raeburn 663: return userdom;
664: }
665:
666: ENDJS
1.468 raeburn 667:
1.876 raeburn 668: }
669:
1.1017 raeburn 670: sub javascript_array_indexof {
1.1018 raeburn 671: return <<ENDJS;
1.1017 raeburn 672: <script type="text/javascript" language="JavaScript">
673: // <![CDATA[
674:
675: if (!Array.prototype.indexOf) {
676: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
677: "use strict";
678: if (this === void 0 || this === null) {
679: throw new TypeError();
680: }
681: var t = Object(this);
682: var len = t.length >>> 0;
683: if (len === 0) {
684: return -1;
685: }
686: var n = 0;
687: if (arguments.length > 0) {
688: n = Number(arguments[1]);
1.1088 foxr 689: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 690: n = 0;
691: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
692: n = (n > 0 || -1) * Math.floor(Math.abs(n));
693: }
694: }
695: if (n >= len) {
696: return -1;
697: }
698: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
699: for (; k < len; k++) {
700: if (k in t && t[k] === searchElement) {
701: return k;
702: }
703: }
704: return -1;
705: }
706: }
707:
708: // ]]>
709: </script>
710:
711: ENDJS
712:
713: }
714:
1.876 raeburn 715: sub userbrowser_javascript {
716: my $id_functions = &javascript_index_functions();
717: return <<"ENDUSERBRW";
718:
1.888 raeburn 719: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 720: var url = '/adm/pickuser?';
721: var userdom = getDomainFromSelectbox(formname,udom);
722: if (userdom != null) {
723: if (userdom != '') {
724: url += 'srchdom='+userdom+'&';
725: }
726: }
727: url += 'form=' + formname + '&unameelement='+uname+
728: '&udomelement='+udom+
729: '&ulastelement='+ulast+
730: '&ufirstelement='+ufirst+
731: '&uemailelement='+uemail+
1.881 raeburn 732: '&hideudomelement='+hideudom+
733: '&coursedom='+crsdom;
1.888 raeburn 734: if ((caller != null) && (caller != undefined)) {
735: url += '&caller='+caller;
736: }
1.876 raeburn 737: var title = 'User_Browser';
738: var options = 'scrollbars=1,resizable=1,menubar=0';
739: options += ',width=700,height=600';
740: var stdeditbrowser = open(url,title,options,'1');
741: stdeditbrowser.focus();
742: }
743:
1.888 raeburn 744: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 745: var formid = getFormIdByName(formname);
746: if (formid > -1) {
1.888 raeburn 747: var unameid = getIndexByName(formid,uname);
1.876 raeburn 748: var domid = getIndexByName(formid,udom);
749: var hidedomid = getIndexByName(formid,origdom);
750: if (hidedomid > -1) {
751: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 752: var unameval = document.forms[formid].elements[unameid].value;
753: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
754: if (domid > -1) {
755: var slct = document.forms[formid].elements[domid];
756: if (slct.type == 'select-one') {
757: var i;
758: for (i=0;i<slct.length;i++) {
759: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
760: }
761: }
762: if (slct.type == 'hidden') {
763: slct.value = fixeddom;
1.876 raeburn 764: }
765: }
1.468 raeburn 766: }
767: }
768: }
1.876 raeburn 769: return;
770: }
771:
772: $id_functions
773: ENDUSERBRW
1.468 raeburn 774: }
775:
776: sub setsec_javascript {
1.1116 raeburn 777: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 778: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
779: $communityrolestr);
780: if ($role_element ne '') {
781: my @allroles = ('st','ta','ep','in','ad');
782: foreach my $crstype ('Course','Community') {
783: if ($crstype eq 'Community') {
784: foreach my $role (@allroles) {
785: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
786: }
787: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
788: } else {
789: foreach my $role (@allroles) {
790: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
791: }
792: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
793: }
794: }
795: $rolestr = '"'.join('","',@allroles).'"';
796: $courserolestr = '"'.join('","',@courserolenames).'"';
797: $communityrolestr = '"'.join('","',@communityrolenames).'"';
798: }
1.468 raeburn 799: my $setsections = qq|
800: function setSect(sectionlist) {
1.629 raeburn 801: var sectionsArray = new Array();
802: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
803: sectionsArray = sectionlist.split(",");
804: }
1.468 raeburn 805: var numSections = sectionsArray.length;
806: document.$formname.$sec_element.length = 0;
807: if (numSections == 0) {
808: document.$formname.$sec_element.multiple=false;
809: document.$formname.$sec_element.size=1;
810: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
811: } else {
812: if (numSections == 1) {
813: document.$formname.$sec_element.multiple=false;
814: document.$formname.$sec_element.size=1;
815: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
816: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
817: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
818: } else {
819: for (var i=0; i<numSections; i++) {
820: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
821: }
822: document.$formname.$sec_element.multiple=true
823: if (numSections < 3) {
824: document.$formname.$sec_element.size=numSections;
825: } else {
826: document.$formname.$sec_element.size=3;
827: }
828: document.$formname.$sec_element.options[0].selected = false
829: }
830: }
1.91 www 831: }
1.905 raeburn 832:
833: function setRole(crstype) {
1.468 raeburn 834: |;
1.905 raeburn 835: if ($role_element eq '') {
836: $setsections .= ' return;
837: }
838: ';
839: } else {
840: $setsections .= qq|
841: var elementLength = document.$formname.$role_element.length;
842: var allroles = Array($rolestr);
843: var courserolenames = Array($courserolestr);
844: var communityrolenames = Array($communityrolestr);
845: if (elementLength != undefined) {
846: if (document.$formname.$role_element.options[5].value == 'cc') {
847: if (crstype == 'Course') {
848: return;
849: } else {
850: allroles[5] = 'co';
851: for (var i=0; i<6; i++) {
852: document.$formname.$role_element.options[i].value = allroles[i];
853: document.$formname.$role_element.options[i].text = communityrolenames[i];
854: }
855: }
856: } else {
857: if (crstype == 'Community') {
858: return;
859: } else {
860: allroles[5] = 'cc';
861: for (var i=0; i<6; i++) {
862: document.$formname.$role_element.options[i].value = allroles[i];
863: document.$formname.$role_element.options[i].text = courserolenames[i];
864: }
865: }
866: }
867: }
868: return;
869: }
870: |;
871: }
1.1116 raeburn 872: if ($credits_element) {
873: $setsections .= qq|
874: function setCredits(defaultcredits) {
875: document.$formname.$credits_element.value = defaultcredits;
876: return;
877: }
878: |;
879: }
1.468 raeburn 880: return $setsections;
881: }
882:
1.91 www 883: sub selectcourse_link {
1.909 raeburn 884: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
885: $typeelement) = @_;
886: my $type = $selecttype;
1.871 raeburn 887: my $linktext = &mt('Select Course');
888: if ($selecttype eq 'Community') {
1.909 raeburn 889: $linktext = &mt('Select Community');
1.1239 raeburn 890: } elsif ($selecttype eq 'Placement') {
891: $linktext = &mt('Select Placement Test');
1.906 raeburn 892: } elsif ($selecttype eq 'Course/Community') {
893: $linktext = &mt('Select Course/Community');
1.909 raeburn 894: $type = '';
1.1019 raeburn 895: } elsif ($selecttype eq 'Select') {
896: $linktext = &mt('Select');
897: $type = '';
1.871 raeburn 898: }
1.787 bisitz 899: return '<span class="LC_nobreak">'
900: ."<a href='"
901: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
902: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 903: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 904: ."'>".$linktext.'</a>'
1.787 bisitz 905: .'</span>';
1.74 www 906: }
1.42 matthew 907:
1.653 raeburn 908: sub selectauthor_link {
909: my ($form,$udom)=@_;
910: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
911: &mt('Select Author').'</a>';
912: }
913:
1.876 raeburn 914: sub selectuser_link {
1.881 raeburn 915: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 916: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 917: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 918: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 919: ');">'.$linktext.'</a>';
1.876 raeburn 920: }
921:
1.273 raeburn 922: sub check_uncheck_jscript {
923: my $jscript = <<"ENDSCRT";
924: function checkAll(field) {
925: if (field.length > 0) {
926: for (i = 0; i < field.length; i++) {
1.1093 raeburn 927: if (!field[i].disabled) {
928: field[i].checked = true;
929: }
1.273 raeburn 930: }
931: } else {
1.1093 raeburn 932: if (!field.disabled) {
933: field.checked = true;
934: }
1.273 raeburn 935: }
936: }
937:
938: function uncheckAll(field) {
939: if (field.length > 0) {
940: for (i = 0; i < field.length; i++) {
941: field[i].checked = false ;
1.543 albertel 942: }
943: } else {
1.273 raeburn 944: field.checked = false ;
945: }
946: }
947: ENDSCRT
948: return $jscript;
949: }
950:
1.656 www 951: sub select_timezone {
1.1256 raeburn 952: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
953: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 954: if ($includeempty) {
955: $output .= '<option value=""';
956: if (($selected eq '') || ($selected eq 'local')) {
957: $output .= ' selected="selected" ';
958: }
959: $output .= '> </option>';
960: }
1.657 raeburn 961: my @timezones = DateTime::TimeZone->all_names;
962: foreach my $tzone (@timezones) {
963: $output.= '<option value="'.$tzone.'"';
964: if ($tzone eq $selected) {
965: $output.=' selected="selected"';
966: }
967: $output.=">$tzone</option>\n";
1.656 www 968: }
969: $output.="</select>";
970: return $output;
971: }
1.273 raeburn 972:
1.687 raeburn 973: sub select_datelocale {
1.1256 raeburn 974: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
975: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 976: if ($includeempty) {
977: $output .= '<option value=""';
978: if ($selected eq '') {
979: $output .= ' selected="selected" ';
980: }
981: $output .= '> </option>';
982: }
1.1241 raeburn 983: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 984: my (@possibles,%locale_names);
1.1241 raeburn 985: my @locales = DateTime::Locale->ids();
986: foreach my $id (@locales) {
987: if ($id ne '') {
988: my ($en_terr,$native_terr);
989: my $loc = DateTime::Locale->load($id);
990: if (ref($loc)) {
991: $en_terr = $loc->name();
992: $native_terr = $loc->native_name();
1.687 raeburn 993: if (grep(/^en$/,@languages) || !@languages) {
994: if ($en_terr ne '') {
995: $locale_names{$id} = '('.$en_terr.')';
996: } elsif ($native_terr ne '') {
997: $locale_names{$id} = $native_terr;
998: }
999: } else {
1000: if ($native_terr ne '') {
1001: $locale_names{$id} = $native_terr.' ';
1002: } elsif ($en_terr ne '') {
1003: $locale_names{$id} = '('.$en_terr.')';
1004: }
1005: }
1.1220 raeburn 1006: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1241 raeburn 1007: push(@possibles,$id);
1008: }
1.687 raeburn 1009: }
1010: }
1011: foreach my $item (sort(@possibles)) {
1012: $output.= '<option value="'.$item.'"';
1013: if ($item eq $selected) {
1014: $output.=' selected="selected"';
1015: }
1016: $output.=">$item";
1017: if ($locale_names{$item} ne '') {
1.1220 raeburn 1018: $output.=' '.$locale_names{$item};
1.687 raeburn 1019: }
1020: $output.="</option>\n";
1021: }
1022: $output.="</select>";
1023: return $output;
1024: }
1025:
1.792 raeburn 1026: sub select_language {
1.1256 raeburn 1027: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1028: my %langchoices;
1029: if ($includeempty) {
1.1117 raeburn 1030: %langchoices = ('' => 'No language preference');
1.792 raeburn 1031: }
1032: foreach my $id (&languageids()) {
1033: my $code = &supportedlanguagecode($id);
1034: if ($code) {
1035: $langchoices{$code} = &plainlanguagedescription($id);
1036: }
1037: }
1.1117 raeburn 1038: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1256 raeburn 1039: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1040: }
1041:
1.42 matthew 1042: =pod
1.36 matthew 1043:
1.1088 foxr 1044:
1045: =item * &list_languages()
1046:
1047: Returns an array reference that is suitable for use in language prompters.
1048: Each array element is itself a two element array. The first element
1049: is the language code. The second element a descsriptiuon of the
1050: language itself. This is suitable for use in e.g.
1051: &Apache::edit::select_arg (once dereferenced that is).
1052:
1053: =cut
1054:
1055: sub list_languages {
1056: my @lang_choices;
1057:
1058: foreach my $id (&languageids()) {
1059: my $code = &supportedlanguagecode($id);
1060: if ($code) {
1061: my $selector = $supported_codes{$id};
1062: my $description = &plainlanguagedescription($id);
1.1263 raeburn 1063: push(@lang_choices, [$selector, $description]);
1.1088 foxr 1064: }
1065: }
1066: return \@lang_choices;
1067: }
1068:
1069: =pod
1070:
1.648 raeburn 1071: =item * &linked_select_forms(...)
1.36 matthew 1072:
1073: linked_select_forms returns a string containing a <script></script> block
1074: and html for two <select> menus. The select menus will be linked in that
1075: changing the value of the first menu will result in new values being placed
1076: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1077: order unless a defined order is provided.
1.36 matthew 1078:
1079: linked_select_forms takes the following ordered inputs:
1080:
1081: =over 4
1082:
1.112 bowersj2 1083: =item * $formname, the name of the <form> tag
1.36 matthew 1084:
1.112 bowersj2 1085: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1086:
1.112 bowersj2 1087: =item * $firstdefault, the default value for the first menu
1.36 matthew 1088:
1.112 bowersj2 1089: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1090:
1.112 bowersj2 1091: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1092:
1.112 bowersj2 1093: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1094:
1.609 raeburn 1095: =item * $menuorder, the order of values in the first menu
1096:
1.1115 raeburn 1097: =item * $onchangefirst, additional javascript call to execute for an onchange
1098: event for the first <select> tag
1099:
1100: =item * $onchangesecond, additional javascript call to execute for an onchange
1101: event for the second <select> tag
1102:
1.1245 raeburn 1103: =item * $suffix, to differentiate separate uses of select2data javascript
1104: objects in a page.
1105:
1.41 ng 1106: =back
1107:
1.36 matthew 1108: Below is an example of such a hash. Only the 'text', 'default', and
1109: 'select2' keys must appear as stated. keys(%menu) are the possible
1110: values for the first select menu. The text that coincides with the
1.41 ng 1111: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1112: and text for the second menu are given in the hash pointed to by
1113: $menu{$choice1}->{'select2'}.
1114:
1.112 bowersj2 1115: my %menu = ( A1 => { text =>"Choice A1" ,
1116: default => "B3",
1117: select2 => {
1118: B1 => "Choice B1",
1119: B2 => "Choice B2",
1120: B3 => "Choice B3",
1121: B4 => "Choice B4"
1.609 raeburn 1122: },
1123: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1124: },
1125: A2 => { text =>"Choice A2" ,
1126: default => "C2",
1127: select2 => {
1128: C1 => "Choice C1",
1129: C2 => "Choice C2",
1130: C3 => "Choice C3"
1.609 raeburn 1131: },
1132: order => ['C2','C1','C3'],
1.112 bowersj2 1133: },
1134: A3 => { text =>"Choice A3" ,
1135: default => "D6",
1136: select2 => {
1137: D1 => "Choice D1",
1138: D2 => "Choice D2",
1139: D3 => "Choice D3",
1140: D4 => "Choice D4",
1141: D5 => "Choice D5",
1142: D6 => "Choice D6",
1143: D7 => "Choice D7"
1.609 raeburn 1144: },
1145: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1146: }
1147: );
1.36 matthew 1148:
1149: =cut
1150:
1151: sub linked_select_forms {
1152: my ($formname,
1153: $middletext,
1154: $firstdefault,
1155: $firstselectname,
1156: $secondselectname,
1.609 raeburn 1157: $hashref,
1158: $menuorder,
1.1115 raeburn 1159: $onchangefirst,
1.1245 raeburn 1160: $onchangesecond,
1161: $suffix
1.36 matthew 1162: ) = @_;
1163: my $second = "document.$formname.$secondselectname";
1164: my $first = "document.$formname.$firstselectname";
1165: # output the javascript to do the changing
1166: my $result = '';
1.776 bisitz 1167: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1168: $result.="// <![CDATA[\n";
1.1245 raeburn 1169: $result.="var select2data${suffix} = new Object();\n";
1.36 matthew 1170: $" = '","';
1171: my $debug = '';
1172: foreach my $s1 (sort(keys(%$hashref))) {
1.1245 raeburn 1173: $result.="select2data${suffix}['d_$s1'] = new Object();\n";
1174: $result.="select2data${suffix}['d_$s1'].def = new String('".
1.36 matthew 1175: $hashref->{$s1}->{'default'}."');\n";
1.1245 raeburn 1176: $result.="select2data${suffix}['d_$s1'].values = new Array(";
1.36 matthew 1177: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1178: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1179: @s2values = @{$hashref->{$s1}->{'order'}};
1180: }
1.36 matthew 1181: $result.="\"@s2values\");\n";
1.1245 raeburn 1182: $result.="select2data${suffix}['d_$s1'].texts = new Array(";
1.36 matthew 1183: my @s2texts;
1184: foreach my $value (@s2values) {
1.1263 raeburn 1185: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1186: }
1187: $result.="\"@s2texts\");\n";
1188: }
1189: $"=' ';
1190: $result.= <<"END";
1191:
1.1245 raeburn 1192: function select1${suffix}_changed() {
1.36 matthew 1193: // Determine new choice
1.1245 raeburn 1194: var newvalue = "d_" + $first.options[$first.selectedIndex].value;
1.36 matthew 1195: // update select2
1.1245 raeburn 1196: var values = select2data${suffix}[newvalue].values;
1197: var texts = select2data${suffix}[newvalue].texts;
1198: var select2def = select2data${suffix}[newvalue].def;
1.36 matthew 1199: var i;
1200: // out with the old
1.1245 raeburn 1201: $second.options.length = 0;
1202: // in with the new
1.36 matthew 1203: for (i=0;i<values.length; i++) {
1204: $second.options[i] = new Option(values[i]);
1.143 matthew 1205: $second.options[i].value = values[i];
1.36 matthew 1206: $second.options[i].text = texts[i];
1207: if (values[i] == select2def) {
1208: $second.options[i].selected = true;
1209: }
1210: }
1211: }
1.824 bisitz 1212: // ]]>
1.36 matthew 1213: </script>
1214: END
1215: # output the initial values for the selection lists
1.1245 raeburn 1216: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1${suffix}_changed();$onchangefirst\">\n";
1.609 raeburn 1217: my @order = sort(keys(%{$hashref}));
1218: if (ref($menuorder) eq 'ARRAY') {
1219: @order = @{$menuorder};
1220: }
1221: foreach my $value (@order) {
1.36 matthew 1222: $result.=" <option value=\"$value\" ";
1.253 albertel 1223: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1224: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1225: }
1226: $result .= "</select>\n";
1227: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1228: $result .= $middletext;
1.1115 raeburn 1229: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1230: if ($onchangesecond) {
1231: $result .= ' onchange="'.$onchangesecond.'"';
1232: }
1233: $result .= ">\n";
1.36 matthew 1234: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1235:
1236: my @secondorder = sort(keys(%select2));
1237: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1238: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1239: }
1240: foreach my $value (@secondorder) {
1.36 matthew 1241: $result.=" <option value=\"$value\" ";
1.253 albertel 1242: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1243: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1244: }
1245: $result .= "</select>\n";
1246: # return $debug;
1247: return $result;
1248: } # end of sub linked_select_forms {
1249:
1.45 matthew 1250: =pod
1.44 bowersj2 1251:
1.973 raeburn 1252: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1253:
1.112 bowersj2 1254: Returns a string corresponding to an HTML link to the given help
1255: $topic, where $topic corresponds to the name of a .tex file in
1256: /home/httpd/html/adm/help/tex, with underscores replaced by
1257: spaces.
1258:
1259: $text will optionally be linked to the same topic, allowing you to
1260: link text in addition to the graphic. If you do not want to link
1261: text, but wish to specify one of the later parameters, pass an
1262: empty string.
1263:
1264: $stayOnPage is a value that will be interpreted as a boolean. If true,
1265: the link will not open a new window. If false, the link will open
1266: a new window using Javascript. (Default is false.)
1267:
1268: $width and $height are optional numerical parameters that will
1269: override the width and height of the popped up window, which may
1.973 raeburn 1270: be useful for certain help topics with big pictures included.
1271:
1272: $imgid is the id of the img tag used for the help icon. This may be
1273: used in a javascript call to switch the image src. See
1274: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1275:
1276: =cut
1277:
1278: sub help_open_topic {
1.973 raeburn 1279: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1280: $text = "" if (not defined $text);
1.44 bowersj2 1281: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1282: $width = 500 if (not defined $width);
1.44 bowersj2 1283: $height = 400 if (not defined $height);
1284: my $filename = $topic;
1285: $filename =~ s/ /_/g;
1286:
1.48 bowersj2 1287: my $template = "";
1288: my $link;
1.572 banghart 1289:
1.159 www 1290: $topic=~s/\W/\_/g;
1.44 bowersj2 1291:
1.572 banghart 1292: if (!$stayOnPage) {
1.1033 www 1293: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1294: } elsif ($stayOnPage eq 'popup') {
1295: $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 1296: } else {
1.48 bowersj2 1297: $link = "/adm/help/${filename}.hlp";
1298: }
1299:
1300: # Add the text
1.1314 raeburn 1301: my $target = ' target="_top"';
1302: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1303: $target = '';
1304: }
1.755 neumanie 1305: if ($text ne "") {
1.763 bisitz 1306: $template.='<span class="LC_help_open_topic">'
1.1314 raeburn 1307: .'<a'.$target.' href="'.$link.'">'
1.763 bisitz 1308: .$text.'</a>';
1.48 bowersj2 1309: }
1310:
1.763 bisitz 1311: # (Always) Add the graphic
1.179 matthew 1312: my $title = &mt('Online Help');
1.667 raeburn 1313: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1314: if ($imgid ne '') {
1315: $imgid = ' id="'.$imgid.'"';
1316: }
1.1314 raeburn 1317: $template.=' <a'.$target.' href="'.$link.'" title="'.$title.'">'
1.763 bisitz 1318: .'<img src="'.$helpicon.'" border="0"'
1319: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1320: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1321: .' /></a>';
1322: if ($text ne "") {
1323: $template.='</span>';
1324: }
1.44 bowersj2 1325: return $template;
1326:
1.106 bowersj2 1327: }
1328:
1329: # This is a quicky function for Latex cheatsheet editing, since it
1330: # appears in at least four places
1331: sub helpLatexCheatsheet {
1.1037 www 1332: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1333: my $out;
1.106 bowersj2 1334: my $addOther = '';
1.732 raeburn 1335: if ($topic) {
1.1037 www 1336: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1337: }
1338: $out = '<span>' # Start cheatsheet
1339: .$addOther
1340: .'<span>'
1.1037 www 1341: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1342: .'</span> <span>'
1.1037 www 1343: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1344: .'</span>';
1.732 raeburn 1345: unless ($not_author) {
1.1186 kruse 1346: $out .= '<span>'
1347: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1348: .'</span> <span>'
1349: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1350: .'</span>';
1.732 raeburn 1351: }
1.763 bisitz 1352: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1353: return $out;
1.172 www 1354: }
1355:
1.430 albertel 1356: sub general_help {
1357: my $helptopic='Student_Intro';
1358: if ($env{'request.role'}=~/^(ca|au)/) {
1359: $helptopic='Authoring_Intro';
1.907 raeburn 1360: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1361: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1362: } elsif ($env{'request.role'}=~/^dc/) {
1363: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1364: }
1365: return $helptopic;
1366: }
1367:
1368: sub update_help_link {
1369: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1370: my $origurl = $ENV{'REQUEST_URI'};
1371: $origurl=~s|^/~|/priv/|;
1372: my $timestamp = time;
1373: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1374: $$datum = &escape($$datum);
1375: }
1376:
1377: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1378: my $output .= <<"ENDOUTPUT";
1379: <script type="text/javascript">
1.824 bisitz 1380: // <![CDATA[
1.430 albertel 1381: banner_link = '$banner_link';
1.824 bisitz 1382: // ]]>
1.430 albertel 1383: </script>
1384: ENDOUTPUT
1385: return $output;
1386: }
1387:
1388: # now just updates the help link and generates a blue icon
1.193 raeburn 1389: sub help_open_menu {
1.430 albertel 1390: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1391: = @_;
1.949 droeschl 1392: $stayOnPage = 1;
1.430 albertel 1393: my $output;
1394: if ($component_help) {
1395: if (!$text) {
1396: $output=&help_open_topic($component_help,undef,$stayOnPage,
1397: $width,$height);
1398: } else {
1399: my $help_text;
1400: $help_text=&unescape($topic);
1401: $output='<table><tr><td>'.
1402: &help_open_topic($component_help,$help_text,$stayOnPage,
1403: $width,$height).'</td></tr></table>';
1404: }
1405: }
1406: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1407: return $output.$banner_link;
1408: }
1409:
1410: sub top_nav_help {
1411: my ($text) = @_;
1.436 albertel 1412: $text = &mt($text);
1.949 droeschl 1413: my $stay_on_page = 1;
1414:
1.1168 raeburn 1415: my ($link,$banner_link);
1416: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1417: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1418: : "javascript:helpMenu('open')";
1419: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1420: }
1.201 raeburn 1421: my $title = &mt('Get help');
1.1168 raeburn 1422: if ($link) {
1423: return <<"END";
1.436 albertel 1424: $banner_link
1.1159 raeburn 1425: <a href="$link" title="$title">$text</a>
1.436 albertel 1426: END
1.1168 raeburn 1427: } else {
1428: return ' '.$text.' ';
1429: }
1.436 albertel 1430: }
1431:
1432: sub help_menu_js {
1.1154 raeburn 1433: my ($httphost) = @_;
1.949 droeschl 1434: my $stayOnPage = 1;
1.436 albertel 1435: my $width = 620;
1436: my $height = 600;
1.430 albertel 1437: my $helptopic=&general_help();
1.1154 raeburn 1438: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1439: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1440: my $start_page =
1441: &Apache::loncommon::start_page('Help Menu', undef,
1442: {'frameset' => 1,
1443: 'js_ready' => 1,
1.1154 raeburn 1444: 'use_absolute' => $httphost,
1.331 albertel 1445: 'add_entries' => {
1.1168 raeburn 1446: 'border' => '0',
1.579 raeburn 1447: 'rows' => "110,*",},});
1.331 albertel 1448: my $end_page =
1449: &Apache::loncommon::end_page({'frameset' => 1,
1450: 'js_ready' => 1,});
1451:
1.436 albertel 1452: my $template .= <<"ENDTEMPLATE";
1453: <script type="text/javascript">
1.877 bisitz 1454: // <![CDATA[
1.253 albertel 1455: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1456: var banner_link = '';
1.243 raeburn 1457: function helpMenu(target) {
1458: var caller = this;
1459: if (target == 'open') {
1460: var newWindow = null;
1461: try {
1.262 albertel 1462: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1463: }
1464: catch(error) {
1465: writeHelp(caller);
1466: return;
1467: }
1468: if (newWindow) {
1469: caller = newWindow;
1470: }
1.193 raeburn 1471: }
1.243 raeburn 1472: writeHelp(caller);
1473: return;
1474: }
1475: function writeHelp(caller) {
1.1168 raeburn 1476: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1477: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1478: caller.document.close();
1479: caller.focus();
1.193 raeburn 1480: }
1.877 bisitz 1481: // END LON-CAPA Internal -->
1.253 albertel 1482: // ]]>
1.436 albertel 1483: </script>
1.193 raeburn 1484: ENDTEMPLATE
1485: return $template;
1486: }
1487:
1.172 www 1488: sub help_open_bug {
1489: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1490: unless ($env{'user.adv'}) { return ''; }
1.172 www 1491: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1492: $text = "" if (not defined $text);
1493: $stayOnPage=1;
1.184 albertel 1494: $width = 600 if (not defined $width);
1495: $height = 600 if (not defined $height);
1.172 www 1496:
1497: $topic=~s/\W+/\+/g;
1498: my $link='';
1499: my $template='';
1.379 albertel 1500: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1501: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1502: if (!$stayOnPage)
1503: {
1504: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1505: }
1506: else
1507: {
1508: $link = $url;
1509: }
1.1314 raeburn 1510:
1511: my $target = ' target="_top"';
1512: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1513: $target = '';
1514: }
1.172 www 1515: # Add the text
1516: if ($text ne "")
1517: {
1518: $template .=
1519: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.1314 raeburn 1520: "<td bgcolor='#FF5555'><a".$target." href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1521: }
1522:
1523: # Add the graphic
1.179 matthew 1524: my $title = &mt('Report a Bug');
1.215 albertel 1525: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1526: $template .= <<"ENDTEMPLATE";
1.1314 raeburn 1527: <a$target href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1528: ENDTEMPLATE
1529: if ($text ne '') { $template.='</td></tr></table>' };
1530: return $template;
1531:
1532: }
1533:
1534: sub help_open_faq {
1535: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1536: unless ($env{'user.adv'}) { return ''; }
1.172 www 1537: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1538: $text = "" if (not defined $text);
1539: $stayOnPage=1;
1540: $width = 350 if (not defined $width);
1541: $height = 400 if (not defined $height);
1542:
1543: $topic=~s/\W+/\+/g;
1544: my $link='';
1545: my $template='';
1546: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1547: if (!$stayOnPage)
1548: {
1549: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1550: }
1551: else
1552: {
1553: $link = $url;
1554: }
1555:
1556: # Add the text
1557: if ($text ne "")
1558: {
1559: $template .=
1.173 www 1560: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1561: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1562: }
1563:
1564: # Add the graphic
1.179 matthew 1565: my $title = &mt('View the FAQ');
1.215 albertel 1566: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1567: $template .= <<"ENDTEMPLATE";
1.436 albertel 1568: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1569: ENDTEMPLATE
1570: if ($text ne '') { $template.='</td></tr></table>' };
1571: return $template;
1572:
1.44 bowersj2 1573: }
1.37 matthew 1574:
1.180 matthew 1575: ###############################################################
1576: ###############################################################
1577:
1.45 matthew 1578: =pod
1579:
1.648 raeburn 1580: =item * &change_content_javascript():
1.256 matthew 1581:
1582: This and the next function allow you to create small sections of an
1583: otherwise static HTML page that you can update on the fly with
1584: Javascript, even in Netscape 4.
1585:
1586: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1587: must be written to the HTML page once. It will prove the Javascript
1588: function "change(name, content)". Calling the change function with the
1589: name of the section
1590: you want to update, matching the name passed to C<changable_area>, and
1591: the new content you want to put in there, will put the content into
1592: that area.
1593:
1594: B<Note>: Netscape 4 only reserves enough space for the changable area
1595: to contain room for the original contents. You need to "make space"
1596: for whatever changes you wish to make, and be B<sure> to check your
1597: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1598: it's adequate for updating a one-line status display, but little more.
1599: This script will set the space to 100% width, so you only need to
1600: worry about height in Netscape 4.
1601:
1602: Modern browsers are much less limiting, and if you can commit to the
1603: user not using Netscape 4, this feature may be used freely with
1604: pretty much any HTML.
1605:
1606: =cut
1607:
1608: sub change_content_javascript {
1609: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1610: if ($env{'browser.type'} eq 'netscape' &&
1611: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1612: return (<<NETSCAPE4);
1613: function change(name, content) {
1614: doc = document.layers[name+"___escape"].layers[0].document;
1615: doc.open();
1616: doc.write(content);
1617: doc.close();
1618: }
1619: NETSCAPE4
1620: } else {
1621: # Otherwise, we need to use semi-standards-compliant code
1622: # (technically, "innerHTML" isn't standard but the equivalent
1623: # is really scary, and every useful browser supports it
1624: return (<<DOMBASED);
1625: function change(name, content) {
1626: element = document.getElementById(name);
1627: element.innerHTML = content;
1628: }
1629: DOMBASED
1630: }
1631: }
1632:
1633: =pod
1634:
1.648 raeburn 1635: =item * &changable_area($name,$origContent):
1.256 matthew 1636:
1637: This provides a "changable area" that can be modified on the fly via
1638: the Javascript code provided in C<change_content_javascript>. $name is
1639: the name you will use to reference the area later; do not repeat the
1640: same name on a given HTML page more then once. $origContent is what
1641: the area will originally contain, which can be left blank.
1642:
1643: =cut
1644:
1645: sub changable_area {
1646: my ($name, $origContent) = @_;
1647:
1.258 albertel 1648: if ($env{'browser.type'} eq 'netscape' &&
1649: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1650: # If this is netscape 4, we need to use the Layer tag
1651: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1652: } else {
1653: return "<span id='$name'>$origContent</span>";
1654: }
1655: }
1656:
1657: =pod
1658:
1.648 raeburn 1659: =item * &viewport_geometry_js
1.590 raeburn 1660:
1661: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1662:
1663: =cut
1664:
1665:
1666: sub viewport_geometry_js {
1667: return <<"GEOMETRY";
1668: var Geometry = {};
1669: function init_geometry() {
1670: if (Geometry.init) { return };
1671: Geometry.init=1;
1672: if (window.innerHeight) {
1673: Geometry.getViewportHeight = function() { return window.innerHeight; };
1674: Geometry.getViewportWidth = function() { return window.innerWidth; };
1675: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1676: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1677: }
1678: else if (document.documentElement && document.documentElement.clientHeight) {
1679: Geometry.getViewportHeight =
1680: function() { return document.documentElement.clientHeight; };
1681: Geometry.getViewportWidth =
1682: function() { return document.documentElement.clientWidth; };
1683:
1684: Geometry.getHorizontalScroll =
1685: function() { return document.documentElement.scrollLeft; };
1686: Geometry.getVerticalScroll =
1687: function() { return document.documentElement.scrollTop; };
1688: }
1689: else if (document.body.clientHeight) {
1690: Geometry.getViewportHeight =
1691: function() { return document.body.clientHeight; };
1692: Geometry.getViewportWidth =
1693: function() { return document.body.clientWidth; };
1694: Geometry.getHorizontalScroll =
1695: function() { return document.body.scrollLeft; };
1696: Geometry.getVerticalScroll =
1697: function() { return document.body.scrollTop; };
1698: }
1699: }
1700:
1701: GEOMETRY
1702: }
1703:
1704: =pod
1705:
1.648 raeburn 1706: =item * &viewport_size_js()
1.590 raeburn 1707:
1708: 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.
1709:
1710: =cut
1711:
1712: sub viewport_size_js {
1713: my $geometry = &viewport_geometry_js();
1714: return <<"DIMS";
1715:
1716: $geometry
1717:
1718: function getViewportDims(width,height) {
1719: init_geometry();
1720: width.value = Geometry.getViewportWidth();
1721: height.value = Geometry.getViewportHeight();
1722: return;
1723: }
1724:
1725: DIMS
1726: }
1727:
1728: =pod
1729:
1.648 raeburn 1730: =item * &resize_textarea_js()
1.565 albertel 1731:
1732: emits the needed javascript to resize a textarea to be as big as possible
1733:
1734: creates a function resize_textrea that takes two IDs first should be
1735: the id of the element to resize, second should be the id of a div that
1736: surrounds everything that comes after the textarea, this routine needs
1737: to be attached to the <body> for the onload and onresize events.
1738:
1.648 raeburn 1739: =back
1.565 albertel 1740:
1741: =cut
1742:
1743: sub resize_textarea_js {
1.590 raeburn 1744: my $geometry = &viewport_geometry_js();
1.565 albertel 1745: return <<"RESIZE";
1746: <script type="text/javascript">
1.824 bisitz 1747: // <![CDATA[
1.590 raeburn 1748: $geometry
1.565 albertel 1749:
1.588 albertel 1750: function getX(element) {
1751: var x = 0;
1752: while (element) {
1753: x += element.offsetLeft;
1754: element = element.offsetParent;
1755: }
1756: return x;
1757: }
1758: function getY(element) {
1759: var y = 0;
1760: while (element) {
1761: y += element.offsetTop;
1762: element = element.offsetParent;
1763: }
1764: return y;
1765: }
1766:
1767:
1.565 albertel 1768: function resize_textarea(textarea_id,bottom_id) {
1769: init_geometry();
1770: var textarea = document.getElementById(textarea_id);
1771: //alert(textarea);
1772:
1.588 albertel 1773: var textarea_top = getY(textarea);
1.565 albertel 1774: var textarea_height = textarea.offsetHeight;
1775: var bottom = document.getElementById(bottom_id);
1.588 albertel 1776: var bottom_top = getY(bottom);
1.565 albertel 1777: var bottom_height = bottom.offsetHeight;
1778: var window_height = Geometry.getViewportHeight();
1.588 albertel 1779: var fudge = 23;
1.565 albertel 1780: var new_height = window_height-fudge-textarea_top-bottom_height;
1781: if (new_height < 300) {
1782: new_height = 300;
1783: }
1784: textarea.style.height=new_height+'px';
1785: }
1.824 bisitz 1786: // ]]>
1.565 albertel 1787: </script>
1788: RESIZE
1789:
1790: }
1791:
1.1205 golterma 1792: sub colorfuleditor_js {
1.1248 raeburn 1793: my $browse_or_search;
1794: my $respath;
1795: my ($cnum,$cdom) = &crsauthor_url();
1796: if ($cnum) {
1797: $respath = "/res/$cdom/$cnum/";
1798: my %js_lt = &Apache::lonlocal::texthash(
1799: sunm => 'Sub-directory name',
1800: save => 'Save page to make this permanent',
1801: );
1802: &js_escape(\%js_lt);
1803: $browse_or_search = <<"END";
1804:
1805: function toggleChooser(form,element,titleid,only,search) {
1806: var disp = 'none';
1807: if (document.getElementById('chooser_'+element)) {
1808: var curr = document.getElementById('chooser_'+element).style.display;
1809: if (curr == 'none') {
1810: disp='inline';
1811: if (form.elements['chooser_'+element].length) {
1812: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1813: form.elements['chooser_'+element][i].checked = false;
1814: }
1815: }
1816: toggleResImport(form,element);
1817: }
1818: document.getElementById('chooser_'+element).style.display = disp;
1819: }
1820: }
1821:
1822: function toggleCrsFile(form,element,numdirs) {
1823: if (document.getElementById('chooser_'+element+'_crsres')) {
1824: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1825: if (curr == 'none') {
1826: if (numdirs) {
1827: form.elements['coursepath_'+element].selectedIndex = 0;
1828: if (numdirs > 1) {
1829: window['select1'+element+'_changed']();
1830: }
1831: }
1832: }
1833: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1834:
1835: }
1836: if (document.getElementById('chooser_'+element+'_upload')) {
1837: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1838: if (document.getElementById('uploadcrsres_'+element)) {
1839: document.getElementById('uploadcrsres_'+element).value = '';
1840: }
1841: }
1842: return;
1843: }
1844:
1845: function toggleCrsUpload(form,element,numcrsdirs) {
1846: if (document.getElementById('chooser_'+element+'_crsres')) {
1847: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1848: }
1849: if (document.getElementById('chooser_'+element+'_upload')) {
1850: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1851: if (curr == 'none') {
1852: if (numcrsdirs) {
1853: form.elements['crsauthorpath_'+element].selectedIndex = 0;
1854: form.elements['newsubdir_'+element][0].checked = true;
1855: toggleNewsubdir(form,element);
1856: }
1857: }
1858: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1859: }
1860: return;
1861: }
1862:
1863: function toggleResImport(form,element) {
1864: var choices = new Array('crsres','upload');
1865: for (var i=0; i<choices.length; i++) {
1866: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1867: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1868: }
1869: }
1870: }
1871:
1872: function toggleNewsubdir(form,element) {
1873: var newsub = form.elements['newsubdir_'+element];
1874: if (newsub) {
1875: if (newsub.length) {
1876: for (var j=0; j<newsub.length; j++) {
1877: if (newsub[j].checked) {
1878: if (document.getElementById('newsubdirname_'+element)) {
1879: if (newsub[j].value == '1') {
1880: document.getElementById('newsubdirname_'+element).type = "text";
1881: if (document.getElementById('newsubdir_'+element)) {
1882: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1883: }
1884: } else {
1885: document.getElementById('newsubdirname_'+element).type = "hidden";
1886: document.getElementById('newsubdirname_'+element).value = "";
1887: document.getElementById('newsubdir_'+element).innerHTML = "";
1888: }
1889: }
1890: break;
1891: }
1892: }
1893: }
1894: }
1895: }
1896:
1897: function updateCrsFile(form,element) {
1898: var directory = form.elements['coursepath_'+element];
1899: var filename = form.elements['coursefile_'+element];
1900: var path = directory.options[directory.selectedIndex].value;
1901: var file = filename.options[filename.selectedIndex].value;
1902: form.elements[element].value = '$respath';
1903: if (path == '/') {
1904: form.elements[element].value += file;
1905: } else {
1906: form.elements[element].value += path+'/'+file;
1907: }
1908: unClean();
1909: if (document.getElementById('previewimg_'+element)) {
1910: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1911: var newsrc = document.getElementById('previewimg_'+element).src;
1912: }
1913: if (document.getElementById('showimg_'+element)) {
1914: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
1915: }
1916: toggleChooser(form,element);
1917: return;
1918: }
1919:
1920: function uploadDone(suffix,name) {
1921: if (name) {
1922: document.forms["lonhomework"].elements[suffix].value = name;
1923: unClean();
1924: toggleChooser(document.forms["lonhomework"],suffix);
1925: }
1926: }
1927:
1928: \$(document).ready(function(){
1929:
1930: \$(document).delegate('form :submit', 'click', function( event ) {
1931: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
1932: var buttonId = this.id;
1933: var suffix = buttonId.toString();
1934: suffix = suffix.replace(/^crsupload_/,'');
1935: event.preventDefault();
1936: document.lonhomework.target = 'crsupload_target_'+suffix;
1937: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
1938: \$(this.form).submit();
1939: document.lonhomework.target = '';
1940: if (document.getElementById('crsuploadto_'+suffix)) {
1941: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
1942: }
1943: return false;
1944: }
1945: });
1946: });
1947: END
1948: }
1.1205 golterma 1949: return <<"COLORFULEDIT"
1950: <script type="text/javascript">
1951: // <![CDATA[>
1952: function fold_box(curDepth, lastresource){
1953:
1954: // we need a list because there can be several blocks you need to fold in one tag
1955: var block = document.getElementsByName('foldblock_'+curDepth);
1956: // but there is only one folding button per tag
1957: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1958:
1959: if(block.item(0).style.display == 'none'){
1960:
1961: foldbutton.value = '@{[&mt("Hide")]}';
1962: for (i = 0; i < block.length; i++){
1963: block.item(i).style.display = '';
1964: }
1965: }else{
1966:
1967: foldbutton.value = '@{[&mt("Show")]}';
1968: for (i = 0; i < block.length; i++){
1969: // block.item(i).style.visibility = 'collapse';
1970: block.item(i).style.display = 'none';
1971: }
1972: };
1973: saveState(lastresource);
1974: }
1975:
1976: function saveState (lastresource) {
1977:
1978: var tag_list = getTagList();
1979: if(tag_list != null){
1980: var timestamp = new Date().getTime();
1981: var key = lastresource;
1982:
1983: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1984: // starting with timestamp
1985: var value = timestamp+';';
1986:
1987: // building the list of key-value pairs
1988: for(var i = 0; i < tag_list.length; i++){
1989: value += tag_list[i]+',';
1990: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1991: }
1992:
1993: // only iterate whole storage if nothing to override
1994: if(localStorage.getItem(key) == null){
1995:
1996: // prevent storage from growing large
1997: if(localStorage.length > 50){
1998: var regex_getTimestamp = /^(?:\d)+;/;
1999: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
2000: var oldest_key;
2001:
2002: for(var i = 1; i < localStorage.length; i++){
2003: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
2004: oldest_key = localStorage.key(i);
2005: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
2006: }
2007: }
2008: localStorage.removeItem(oldest_key);
2009: }
2010: }
2011: localStorage.setItem(key,value);
2012: }
2013: }
2014:
2015: // restore folding status of blocks (on page load)
2016: function restoreState (lastresource) {
2017: if(localStorage.getItem(lastresource) != null){
2018: var key = lastresource;
2019: var value = localStorage.getItem(key);
2020: var regex_delTimestamp = /^\d+;/;
2021:
2022: value.replace(regex_delTimestamp, '');
2023:
2024: var valueArr = value.split(';');
2025: var pairs;
2026: var elements;
2027: for (var i = 0; i < valueArr.length; i++){
2028: pairs = valueArr[i].split(',');
2029: elements = document.getElementsByName(pairs[0]);
2030:
2031: for (var j = 0; j < elements.length; j++){
2032: elements[j].style.display = pairs[1];
2033: if (pairs[1] == "none"){
2034: var regex_id = /([_\\d]+)\$/;
2035: regex_id.exec(pairs[0]);
2036: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2037: }
2038: }
2039: }
2040: }
2041: }
2042:
2043: function getTagList () {
2044:
2045: var stringToSearch = document.lonhomework.innerHTML;
2046:
2047: var ret = new Array();
2048: var regex_findBlock = /(foldblock_.*?)"/g;
2049: var tag_list = stringToSearch.match(regex_findBlock);
2050:
2051: if(tag_list != null){
2052: for(var i = 0; i < tag_list.length; i++){
2053: ret.push(tag_list[i].replace(/"/, ''));
2054: }
2055: }
2056: return ret;
2057: }
2058:
2059: function saveScrollPosition (resource) {
2060: var tag_list = getTagList();
2061:
2062: // we dont always want to jump to the first block
2063: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2064: if(\$(window).scrollTop() > 170){
2065: if(tag_list != null){
2066: var result;
2067: for(var i = 0; i < tag_list.length; i++){
2068: if(isElementInViewport(tag_list[i])){
2069: result += tag_list[i]+';';
2070: }
2071: }
2072: sessionStorage.setItem('anchor_'+resource, result);
2073: }
2074: } else {
2075: // we dont need to save zero, just delete the item to leave everything tidy
2076: sessionStorage.removeItem('anchor_'+resource);
2077: }
2078: }
2079:
2080: function restoreScrollPosition(resource){
2081:
2082: var elem = sessionStorage.getItem('anchor_'+resource);
2083: if(elem != null){
2084: var tag_list = elem.split(';');
2085: var elem_list;
2086:
2087: for(var i = 0; i < tag_list.length; i++){
2088: elem_list = document.getElementsByName(tag_list[i]);
2089:
2090: if(elem_list.length > 0){
2091: elem = elem_list[0];
2092: break;
2093: }
2094: }
2095: elem.scrollIntoView();
2096: }
2097: }
2098:
2099: function isElementInViewport(el) {
2100:
2101: // change to last element instead of first
2102: var elem = document.getElementsByName(el);
2103: var rect = elem[0].getBoundingClientRect();
2104:
2105: return (
2106: rect.top >= 0 &&
2107: rect.left >= 0 &&
2108: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2109: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2110: );
2111: }
2112:
2113: function autosize(depth){
2114: var cmInst = window['cm'+depth];
2115: var fitsizeButton = document.getElementById('fitsize'+depth);
2116:
2117: // is fixed size, switching to dynamic
2118: if (sessionStorage.getItem("autosized_"+depth) == null) {
2119: cmInst.setSize("","auto");
2120: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2121: sessionStorage.setItem("autosized_"+depth, "yes");
2122:
2123: // is dynamic size, switching to fixed
2124: } else {
2125: cmInst.setSize("","300px");
2126: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2127: sessionStorage.removeItem("autosized_"+depth);
2128: }
2129: }
2130:
1.1248 raeburn 2131: $browse_or_search
1.1205 golterma 2132:
2133: // ]]>
2134: </script>
2135: COLORFULEDIT
2136: }
2137:
2138: sub xmleditor_js {
2139: return <<XMLEDIT
2140: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2141: <script type="text/javascript">
2142: // <![CDATA[>
2143:
2144: function saveScrollPosition (resource) {
2145:
2146: var scrollPos = \$(window).scrollTop();
2147: sessionStorage.setItem(resource,scrollPos);
2148: }
2149:
2150: function restoreScrollPosition(resource){
2151:
2152: var scrollPos = sessionStorage.getItem(resource);
2153: \$(window).scrollTop(scrollPos);
2154: }
2155:
2156: // unless internet explorer
2157: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2158:
2159: \$(document).ready(function() {
2160: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2161: });
2162: }
2163:
2164: // inserts text at cursor position into codemirror (xml editor only)
2165: function insertText(text){
2166: cm.focus();
2167: var curPos = cm.getCursor();
2168: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2169: }
2170: // ]]>
2171: </script>
2172: XMLEDIT
2173: }
2174:
2175: sub insert_folding_button {
2176: my $curDepth = $Apache::lonxml::curdepth;
2177: my $lastresource = $env{'request.ambiguous'};
2178:
2179: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2180: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2181: }
2182:
1.1248 raeburn 2183: sub crsauthor_url {
2184: my ($url) = @_;
2185: if ($url eq '') {
2186: $url = $ENV{'REQUEST_URI'};
2187: }
2188: my ($cnum,$cdom);
2189: if ($env{'request.course.id'}) {
2190: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2191: if ($audom ne '' && $auname ne '') {
2192: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2193: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2194: $cnum = $auname;
2195: $cdom = $audom;
2196: }
2197: }
2198: }
2199: return ($cnum,$cdom);
2200: }
2201:
2202: sub import_crsauthor_form {
1.1265 raeburn 2203: my ($form,$firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2204: return (0) unless ($env{'request.course.id'});
2205: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2206: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2207: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2208: return (0) unless (($cnum ne '') && ($cdom ne ''));
2209: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
2210: my @ids=&Apache::lonnet::current_machine_ids();
2211: my ($output,$is_home,$relpath,%subdirs,%files,%selimport_menus);
2212:
2213: if (grep(/^\Q$crshome\E$/,@ids)) {
2214: $is_home = 1;
2215: }
2216: $relpath = "/priv/$cdom/$cnum";
2217: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$relpath,'',\%subdirs,\%files);
2218: my %lt = &Apache::lonlocal::texthash (
2219: fnam => 'Filename',
2220: dire => 'Directory',
2221: );
2222: my $numdirs = scalar(keys(%files));
2223: my (%possexts,$singledir,@singledirfiles);
2224: if ($only) {
2225: map { $possexts{$_} = 1; } split(/\s*,\s*/,$only);
2226: }
2227: my (%nonemptydirs,$possdirs);
2228: if ($numdirs > 1) {
2229: my @order;
2230: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
2231: if (ref($files{$key}) eq 'HASH') {
2232: my $shown = $key;
2233: if ($key eq '') {
2234: $shown = '/';
2235: }
2236: my @ordered = ();
2237: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$key}}))) {
1.1315 raeburn 2238: next if ($file =~ /\.rights$/);
1.1248 raeburn 2239: if ($only) {
2240: my ($ext) = ($file =~ /\.([^.]+)$/);
2241: unless ($possexts{lc($ext)}) {
2242: next;
2243: }
2244: }
2245: $selimport_menus{$key}->{'select2'}->{$file} = $file;
2246: push(@ordered,$file);
2247: }
2248: if (@ordered) {
2249: push(@order,$key);
2250: $nonemptydirs{$key} = 1;
2251: $selimport_menus{$key}->{'text'} = $shown;
2252: $selimport_menus{$key}->{'default'} = '';
2253: $selimport_menus{$key}->{'select2'}->{''} = '';
2254: $selimport_menus{$key}->{'order'} = \@ordered;
2255: }
2256: }
2257: }
2258: $possdirs = scalar(keys(%nonemptydirs));
2259: if ($possdirs > 1) {
2260: my @order = sort { lc($a) cmp lc($b) } (keys(%nonemptydirs));
2261: $output = $lt{'dire'}.
2262: &linked_select_forms($form,'<br />'.
2263: $lt{'fnam'},'',
2264: $firstselectname,$secondselectname,
2265: \%selimport_menus,\@order,
2266: $onchangefirst,'',$suffix).'<br />';
2267: } elsif ($possdirs == 1) {
2268: $singledir = (keys(%nonemptydirs))[0];
2269: if (ref($selimport_menus{$singledir}->{'order'}) eq 'ARRAY') {
2270: @singledirfiles = @{$selimport_menus{$singledir}->{'order'}};
2271: }
2272: delete($selimport_menus{$singledir});
2273: }
2274: } elsif ($numdirs == 1) {
2275: $singledir = (keys(%files))[0];
2276: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$singledir}}))) {
2277: if ($only) {
2278: my ($ext) = ($file =~ /\.([^.]+)$/);
2279: unless ($possexts{lc($ext)}) {
2280: next;
2281: }
1.1315 raeburn 2282: } else {
2283: next if ($file =~ /\.rights$/);
1.1248 raeburn 2284: }
2285: push(@singledirfiles,$file);
2286: }
2287: if (@singledirfiles) {
1.1315 raeburn 2288: $possdirs = 1;
1.1248 raeburn 2289: }
2290: }
2291: if (($possdirs == 1) && (@singledirfiles)) {
2292: my $showdir = $singledir;
2293: if ($singledir eq '') {
2294: $showdir = '/';
2295: }
2296: $output = $lt{'dire'}.
2297: '<select name="'.$firstselectname.'">'.
2298: '<option value="'.$singledir.'">'.$showdir.'</option>'."\n".
2299: '</select><br />'.
2300: $lt{'fnam'}.'<select name="'.$secondselectname.'">'."\n".
2301: '<option value="" selected="selected">'.$lt{'se'}.'</option>'."\n";
2302: foreach my $file (@singledirfiles) {
2303: $output .= '<option value="'.$file.'">'.$file.'</option>'."\n";
2304: }
2305: $output .= '</select><br />'."\n";
2306: }
2307: return ($possdirs,$output);
2308: }
2309:
1.565 albertel 2310: =pod
2311:
1.256 matthew 2312: =head1 Excel and CSV file utility routines
2313:
2314: =cut
2315:
2316: ###############################################################
2317: ###############################################################
2318:
2319: =pod
2320:
1.1162 raeburn 2321: =over 4
2322:
1.648 raeburn 2323: =item * &csv_translate($text)
1.37 matthew 2324:
1.185 www 2325: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2326: format.
2327:
2328: =cut
2329:
1.180 matthew 2330: ###############################################################
2331: ###############################################################
1.37 matthew 2332: sub csv_translate {
2333: my $text = shift;
2334: $text =~ s/\"/\"\"/g;
1.209 albertel 2335: $text =~ s/\n/ /g;
1.37 matthew 2336: return $text;
2337: }
1.180 matthew 2338:
2339: ###############################################################
2340: ###############################################################
2341:
2342: =pod
2343:
1.648 raeburn 2344: =item * &define_excel_formats()
1.180 matthew 2345:
2346: Define some commonly used Excel cell formats.
2347:
2348: Currently supported formats:
2349:
2350: =over 4
2351:
2352: =item header
2353:
2354: =item bold
2355:
2356: =item h1
2357:
2358: =item h2
2359:
2360: =item h3
2361:
1.256 matthew 2362: =item h4
2363:
2364: =item i
2365:
1.180 matthew 2366: =item date
2367:
2368: =back
2369:
2370: Inputs: $workbook
2371:
2372: Returns: $format, a hash reference.
2373:
1.1057 foxr 2374:
1.180 matthew 2375: =cut
2376:
2377: ###############################################################
2378: ###############################################################
2379: sub define_excel_formats {
2380: my ($workbook) = @_;
2381: my $format;
2382: $format->{'header'} = $workbook->add_format(bold => 1,
2383: bottom => 1,
2384: align => 'center');
2385: $format->{'bold'} = $workbook->add_format(bold=>1);
2386: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2387: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2388: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2389: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2390: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2391: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2392: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2393: return $format;
2394: }
2395:
2396: ###############################################################
2397: ###############################################################
1.113 bowersj2 2398:
2399: =pod
2400:
1.648 raeburn 2401: =item * &create_workbook()
1.255 matthew 2402:
2403: Create an Excel worksheet. If it fails, output message on the
2404: request object and return undefs.
2405:
2406: Inputs: Apache request object
2407:
2408: Returns (undef) on failure,
2409: Excel worksheet object, scalar with filename, and formats
2410: from &Apache::loncommon::define_excel_formats on success
2411:
2412: =cut
2413:
2414: ###############################################################
2415: ###############################################################
2416: sub create_workbook {
2417: my ($r) = @_;
2418: #
2419: # Create the excel spreadsheet
2420: my $filename = '/prtspool/'.
1.258 albertel 2421: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2422: time.'_'.rand(1000000000).'.xls';
2423: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2424: if (! defined($workbook)) {
2425: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2426: $r->print(
2427: '<p class="LC_error">'
2428: .&mt('Problems occurred in creating the new Excel file.')
2429: .' '.&mt('This error has been logged.')
2430: .' '.&mt('Please alert your LON-CAPA administrator.')
2431: .'</p>'
2432: );
1.255 matthew 2433: return (undef);
2434: }
2435: #
1.1014 foxr 2436: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2437: #
2438: my $format = &Apache::loncommon::define_excel_formats($workbook);
2439: return ($workbook,$filename,$format);
2440: }
2441:
2442: ###############################################################
2443: ###############################################################
2444:
2445: =pod
2446:
1.648 raeburn 2447: =item * &create_text_file()
1.113 bowersj2 2448:
1.542 raeburn 2449: Create a file to write to and eventually make available to the user.
1.256 matthew 2450: If file creation fails, outputs an error message on the request object and
2451: return undefs.
1.113 bowersj2 2452:
1.256 matthew 2453: Inputs: Apache request object, and file suffix
1.113 bowersj2 2454:
1.256 matthew 2455: Returns (undef) on failure,
2456: Filehandle and filename on success.
1.113 bowersj2 2457:
2458: =cut
2459:
1.256 matthew 2460: ###############################################################
2461: ###############################################################
2462: sub create_text_file {
2463: my ($r,$suffix) = @_;
2464: if (! defined($suffix)) { $suffix = 'txt'; };
2465: my $fh;
2466: my $filename = '/prtspool/'.
1.258 albertel 2467: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2468: time.'_'.rand(1000000000).'.'.$suffix;
2469: $fh = Apache::File->new('>/home/httpd'.$filename);
2470: if (! defined($fh)) {
2471: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2472: $r->print(
2473: '<p class="LC_error">'
2474: .&mt('Problems occurred in creating the output file.')
2475: .' '.&mt('This error has been logged.')
2476: .' '.&mt('Please alert your LON-CAPA administrator.')
2477: .'</p>'
2478: );
1.113 bowersj2 2479: }
1.256 matthew 2480: return ($fh,$filename)
1.113 bowersj2 2481: }
2482:
2483:
1.256 matthew 2484: =pod
1.113 bowersj2 2485:
2486: =back
2487:
2488: =cut
1.37 matthew 2489:
2490: ###############################################################
1.33 matthew 2491: ## Home server <option> list generating code ##
2492: ###############################################################
1.35 matthew 2493:
1.169 www 2494: # ------------------------------------------
2495:
2496: sub domain_select {
1.1289 raeburn 2497: my ($name,$value,$multiple,$incdoms,$excdoms)=@_;
2498: my @possdoms;
2499: if (ref($incdoms) eq 'ARRAY') {
2500: @possdoms = @{$incdoms};
2501: } else {
2502: @possdoms = &Apache::lonnet::all_domains();
2503: }
2504:
1.169 www 2505: my %domains=map {
1.514 albertel 2506: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.1289 raeburn 2507: } @possdoms;
2508:
2509: if ((ref($excdoms) eq 'ARRAY') && (@{$excdoms} > 0)) {
2510: foreach my $dom (@{$excdoms}) {
2511: delete($domains{$dom});
2512: }
2513: }
2514:
1.169 www 2515: if ($multiple) {
2516: $domains{''}=&mt('Any domain');
1.550 albertel 2517: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2518: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2519: } else {
1.550 albertel 2520: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2521: return &select_form($name,$value,\%domains);
1.169 www 2522: }
2523: }
2524:
1.282 albertel 2525: #-------------------------------------------
2526:
2527: =pod
2528:
1.519 raeburn 2529: =head1 Routines for form select boxes
2530:
2531: =over 4
2532:
1.648 raeburn 2533: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2534:
2535: Returns a string containing a <select> element int multiple mode
2536:
2537:
2538: Args:
2539: $name - name of the <select> element
1.506 raeburn 2540: $value - scalar or array ref of values that should already be selected
1.282 albertel 2541: $size - number of rows long the select element is
1.283 albertel 2542: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2543: (shown text should already have been &mt())
1.506 raeburn 2544: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2545:
1.282 albertel 2546: =cut
2547:
2548: #-------------------------------------------
1.169 www 2549: sub multiple_select_form {
1.284 albertel 2550: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2551: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2552: my $output='';
1.191 matthew 2553: if (! defined($size)) {
2554: $size = 4;
1.283 albertel 2555: if (scalar(keys(%$hash))<4) {
2556: $size = scalar(keys(%$hash));
1.191 matthew 2557: }
2558: }
1.734 bisitz 2559: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2560: my @order;
1.506 raeburn 2561: if (ref($order) eq 'ARRAY') {
2562: @order = @{$order};
2563: } else {
2564: @order = sort(keys(%$hash));
1.501 banghart 2565: }
2566: if (exists($$hash{'select_form_order'})) {
2567: @order = @{$$hash{'select_form_order'}};
2568: }
2569:
1.284 albertel 2570: foreach my $key (@order) {
1.356 albertel 2571: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2572: $output.='selected="selected" ' if ($selected{$key});
2573: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2574: }
2575: $output.="</select>\n";
2576: return $output;
2577: }
2578:
1.88 www 2579: #-------------------------------------------
2580:
2581: =pod
2582:
1.1254 raeburn 2583: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2584:
2585: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2586: allow a user to select options from a ref to a hash containing:
2587: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2588: a javascript onchange item, e.g., onchange="this.form.submit();".
2589: An optional arg -- $readonly -- if true will cause the select form
2590: to be disabled, e.g., for the case where an instructor has a section-
2591: specific role, and is viewing/modifying parameters.
1.970 raeburn 2592:
1.88 www 2593: See lonrights.pm for an example invocation and use.
2594:
2595: =cut
2596:
2597: #-------------------------------------------
2598: sub select_form {
1.1228 raeburn 2599: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2600: return unless (ref($hashref) eq 'HASH');
2601: if ($onchange) {
2602: $onchange = ' onchange="'.$onchange.'"';
2603: }
1.1228 raeburn 2604: my $disabled;
2605: if ($readonly) {
2606: $disabled = ' disabled="disabled"';
2607: }
2608: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2609: my @keys;
1.970 raeburn 2610: if (exists($hashref->{'select_form_order'})) {
2611: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2612: } else {
1.970 raeburn 2613: @keys=sort(keys(%{$hashref}));
1.128 albertel 2614: }
1.356 albertel 2615: foreach my $key (@keys) {
2616: $selectform.=
2617: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2618: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2619: ">".$hashref->{$key}."</option>\n";
1.88 www 2620: }
2621: $selectform.="</select>";
2622: return $selectform;
2623: }
2624:
1.475 www 2625: # For display filters
2626:
2627: sub display_filter {
1.1074 raeburn 2628: my ($context) = @_;
1.475 www 2629: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2630: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2631: my $phraseinput = 'hidden';
2632: my $includeinput = 'hidden';
2633: my ($checked,$includetypestext);
2634: if ($env{'form.displayfilter'} eq 'containing') {
2635: $phraseinput = 'text';
2636: if ($context eq 'parmslog') {
2637: $includeinput = 'checkbox';
2638: if ($env{'form.includetypes'}) {
2639: $checked = ' checked="checked"';
2640: }
2641: $includetypestext = &mt('Include parameter types');
2642: }
2643: } else {
2644: $includetypestext = ' ';
2645: }
2646: my ($additional,$secondid,$thirdid);
2647: if ($context eq 'parmslog') {
2648: $additional =
2649: '<label><input type="'.$includeinput.'" name="includetypes"'.
2650: $checked.' name="includetypes" value="1" id="includetypes" />'.
2651: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2652: '</label>';
2653: $secondid = 'includetypes';
2654: $thirdid = 'includetypestext';
2655: }
2656: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2657: '$secondid','$thirdid')";
2658: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2659: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2660: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2661: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2662: &mt('Filter: [_1]',
1.477 www 2663: &select_form($env{'form.displayfilter'},
2664: 'displayfilter',
1.970 raeburn 2665: {'currentfolder' => 'Current folder/page',
1.477 www 2666: 'containing' => 'Containing phrase',
1.1074 raeburn 2667: 'none' => 'None'},$onchange)).' '.
2668: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2669: &HTML::Entities::encode($env{'form.containingphrase'}).
2670: '" />'.$additional;
2671: }
2672:
2673: sub display_filter_js {
2674: my $includetext = &mt('Include parameter types');
2675: return <<"ENDJS";
2676:
2677: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2678: var firstType = 'hidden';
2679: if (setter.options[setter.selectedIndex].value == 'containing') {
2680: firstType = 'text';
2681: }
2682: firstObject = document.getElementById(firstid);
2683: if (typeof(firstObject) == 'object') {
2684: if (firstObject.type != firstType) {
2685: changeInputType(firstObject,firstType);
2686: }
2687: }
2688: if (context == 'parmslog') {
2689: var secondType = 'hidden';
2690: if (firstType == 'text') {
2691: secondType = 'checkbox';
2692: }
2693: secondObject = document.getElementById(secondid);
2694: if (typeof(secondObject) == 'object') {
2695: if (secondObject.type != secondType) {
2696: changeInputType(secondObject,secondType);
2697: }
2698: }
2699: var textItem = document.getElementById(thirdid);
2700: var currtext = textItem.innerHTML;
2701: var newtext;
2702: if (firstType == 'text') {
2703: newtext = '$includetext';
2704: } else {
2705: newtext = ' ';
2706: }
2707: if (currtext != newtext) {
2708: textItem.innerHTML = newtext;
2709: }
2710: }
2711: return;
2712: }
2713:
2714: function changeInputType(oldObject,newType) {
2715: var newObject = document.createElement('input');
2716: newObject.type = newType;
2717: if (oldObject.size) {
2718: newObject.size = oldObject.size;
2719: }
2720: if (oldObject.value) {
2721: newObject.value = oldObject.value;
2722: }
2723: if (oldObject.name) {
2724: newObject.name = oldObject.name;
2725: }
2726: if (oldObject.id) {
2727: newObject.id = oldObject.id;
2728: }
2729: oldObject.parentNode.replaceChild(newObject,oldObject);
2730: return;
2731: }
2732:
2733: ENDJS
1.475 www 2734: }
2735:
1.167 www 2736: sub gradeleveldescription {
2737: my $gradelevel=shift;
2738: my %gradelevels=(0 => 'Not specified',
2739: 1 => 'Grade 1',
2740: 2 => 'Grade 2',
2741: 3 => 'Grade 3',
2742: 4 => 'Grade 4',
2743: 5 => 'Grade 5',
2744: 6 => 'Grade 6',
2745: 7 => 'Grade 7',
2746: 8 => 'Grade 8',
2747: 9 => 'Grade 9',
2748: 10 => 'Grade 10',
2749: 11 => 'Grade 11',
2750: 12 => 'Grade 12',
2751: 13 => 'Grade 13',
2752: 14 => '100 Level',
2753: 15 => '200 Level',
2754: 16 => '300 Level',
2755: 17 => '400 Level',
2756: 18 => 'Graduate Level');
2757: return &mt($gradelevels{$gradelevel});
2758: }
2759:
1.163 www 2760: sub select_level_form {
2761: my ($deflevel,$name)=@_;
2762: unless ($deflevel) { $deflevel=0; }
1.167 www 2763: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2764: for (my $i=0; $i<=18; $i++) {
2765: $selectform.="<option value=\"$i\" ".
1.253 albertel 2766: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2767: ">".&gradeleveldescription($i)."</option>\n";
2768: }
2769: $selectform.="</select>";
2770: return $selectform;
1.163 www 2771: }
1.167 www 2772:
1.35 matthew 2773: #-------------------------------------------
2774:
1.45 matthew 2775: =pod
2776:
1.1256 raeburn 2777: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2778:
2779: Returns a string containing a <select name='$name' size='1'> form to
2780: allow a user to select the domain to preform an operation in.
2781: See loncreateuser.pm for an example invocation and use.
2782:
1.90 www 2783: If the $includeempty flag is set, it also includes an empty choice ("no domain
2784: selected");
2785:
1.743 raeburn 2786: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2787:
1.910 raeburn 2788: 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.
2789:
1.1121 raeburn 2790: The optional $incdoms is a reference to an array of domains which will be the only available options.
2791:
2792: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2793:
1.1256 raeburn 2794: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
2795:
1.35 matthew 2796: =cut
2797:
2798: #-------------------------------------------
1.34 matthew 2799: sub select_dom_form {
1.1256 raeburn 2800: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2801: if ($onchange) {
1.874 raeburn 2802: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2803: }
1.1256 raeburn 2804: if ($disabled) {
2805: $disabled = ' disabled="disabled"';
2806: }
1.1121 raeburn 2807: my (@domains,%exclude);
1.910 raeburn 2808: if (ref($incdoms) eq 'ARRAY') {
2809: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2810: } else {
2811: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2812: }
1.90 www 2813: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2814: if (ref($excdoms) eq 'ARRAY') {
2815: map { $exclude{$_} = 1; } @{$excdoms};
2816: }
1.1256 raeburn 2817: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2818: foreach my $dom (@domains) {
1.1121 raeburn 2819: next if ($exclude{$dom});
1.356 albertel 2820: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2821: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2822: if ($showdomdesc) {
2823: if ($dom ne '') {
2824: my $domdesc = &Apache::lonnet::domain($dom,'description');
2825: if ($domdesc ne '') {
2826: $selectdomain .= ' ('.$domdesc.')';
2827: }
2828: }
2829: }
2830: $selectdomain .= "</option>\n";
1.34 matthew 2831: }
2832: $selectdomain.="</select>";
2833: return $selectdomain;
2834: }
2835:
1.35 matthew 2836: #-------------------------------------------
2837:
1.45 matthew 2838: =pod
2839:
1.648 raeburn 2840: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2841:
1.586 raeburn 2842: input: 4 arguments (two required, two optional) -
2843: $domain - domain of new user
2844: $name - name of form element
2845: $default - Value of 'default' causes a default item to be first
2846: option, and selected by default.
2847: $hide - Value of 'hide' causes hiding of the name of the server,
2848: if 1 server found, or default, if 0 found.
1.594 raeburn 2849: output: returns 2 items:
1.586 raeburn 2850: (a) form element which contains either:
2851: (i) <select name="$name">
2852: <option value="$hostid1">$hostid $servers{$hostid}</option>
2853: <option value="$hostid2">$hostid $servers{$hostid}</option>
2854: </select>
2855: form item if there are multiple library servers in $domain, or
2856: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2857: if there is only one library server in $domain.
2858:
2859: (b) number of library servers found.
2860:
2861: See loncreateuser.pm for example of use.
1.35 matthew 2862:
2863: =cut
2864:
2865: #-------------------------------------------
1.586 raeburn 2866: sub home_server_form_item {
2867: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2868: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2869: my $result;
2870: my $numlib = keys(%servers);
2871: if ($numlib > 1) {
2872: $result .= '<select name="'.$name.'" />'."\n";
2873: if ($default) {
1.804 bisitz 2874: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2875: '</option>'."\n";
2876: }
2877: foreach my $hostid (sort(keys(%servers))) {
2878: $result.= '<option value="'.$hostid.'">'.
2879: $hostid.' '.$servers{$hostid}."</option>\n";
2880: }
2881: $result .= '</select>'."\n";
2882: } elsif ($numlib == 1) {
2883: my $hostid;
2884: foreach my $item (keys(%servers)) {
2885: $hostid = $item;
2886: }
2887: $result .= '<input type="hidden" name="'.$name.'" value="'.
2888: $hostid.'" />';
2889: if (!$hide) {
2890: $result .= $hostid.' '.$servers{$hostid};
2891: }
2892: $result .= "\n";
2893: } elsif ($default) {
2894: $result .= '<input type="hidden" name="'.$name.
2895: '" value="default" />';
2896: if (!$hide) {
2897: $result .= &mt('default');
2898: }
2899: $result .= "\n";
1.33 matthew 2900: }
1.586 raeburn 2901: return ($result,$numlib);
1.33 matthew 2902: }
1.112 bowersj2 2903:
2904: =pod
2905:
1.534 albertel 2906: =back
2907:
1.112 bowersj2 2908: =cut
1.87 matthew 2909:
2910: ###############################################################
1.112 bowersj2 2911: ## Decoding User Agent ##
1.87 matthew 2912: ###############################################################
2913:
2914: =pod
2915:
1.112 bowersj2 2916: =head1 Decoding the User Agent
2917:
2918: =over 4
2919:
2920: =item * &decode_user_agent()
1.87 matthew 2921:
2922: Inputs: $r
2923:
2924: Outputs:
2925:
2926: =over 4
2927:
1.112 bowersj2 2928: =item * $httpbrowser
1.87 matthew 2929:
1.112 bowersj2 2930: =item * $clientbrowser
1.87 matthew 2931:
1.112 bowersj2 2932: =item * $clientversion
1.87 matthew 2933:
1.112 bowersj2 2934: =item * $clientmathml
1.87 matthew 2935:
1.112 bowersj2 2936: =item * $clientunicode
1.87 matthew 2937:
1.112 bowersj2 2938: =item * $clientos
1.87 matthew 2939:
1.1137 raeburn 2940: =item * $clientmobile
2941:
1.1141 raeburn 2942: =item * $clientinfo
2943:
1.1194 raeburn 2944: =item * $clientosversion
2945:
1.87 matthew 2946: =back
2947:
1.157 matthew 2948: =back
2949:
1.87 matthew 2950: =cut
2951:
2952: ###############################################################
2953: ###############################################################
2954: sub decode_user_agent {
1.247 albertel 2955: my ($r)=@_;
1.87 matthew 2956: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2957: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2958: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2959: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2960: my $clientbrowser='unknown';
2961: my $clientversion='0';
2962: my $clientmathml='';
2963: my $clientunicode='0';
1.1137 raeburn 2964: my $clientmobile=0;
1.1194 raeburn 2965: my $clientosversion='';
1.87 matthew 2966: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2967: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2968: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2969: $clientbrowser=$bname;
2970: $httpbrowser=~/$vreg/i;
2971: $clientversion=$1;
2972: $clientmathml=($clientversion>=$minv);
2973: $clientunicode=($clientversion>=$univ);
2974: }
2975: }
2976: my $clientos='unknown';
1.1141 raeburn 2977: my $clientinfo;
1.87 matthew 2978: if (($httpbrowser=~/linux/i) ||
2979: ($httpbrowser=~/unix/i) ||
2980: ($httpbrowser=~/ux/i) ||
2981: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2982: if (($httpbrowser=~/vax/i) ||
2983: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2984: if ($httpbrowser=~/next/i) { $clientos='next'; }
2985: if (($httpbrowser=~/mac/i) ||
2986: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 2987: if ($httpbrowser=~/win/i) {
2988: $clientos='win';
2989: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2990: $clientosversion = $1;
2991: }
2992: }
1.87 matthew 2993: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2994: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2995: $clientmobile=lc($1);
2996: }
1.1141 raeburn 2997: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2998: $clientinfo = 'firefox-'.$1;
2999: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
3000: $clientinfo = 'chromeframe-'.$1;
3001: }
1.87 matthew 3002: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 3003: $clientunicode,$clientos,$clientmobile,$clientinfo,
3004: $clientosversion);
1.87 matthew 3005: }
3006:
1.32 matthew 3007: ###############################################################
3008: ## Authentication changing form generation subroutines ##
3009: ###############################################################
3010: ##
3011: ## All of the authform_xxxxxxx subroutines take their inputs in a
3012: ## hash, and have reasonable default values.
3013: ##
3014: ## formname = the name given in the <form> tag.
1.35 matthew 3015: #-------------------------------------------
3016:
1.45 matthew 3017: =pod
3018:
1.112 bowersj2 3019: =head1 Authentication Routines
3020:
3021: =over 4
3022:
1.648 raeburn 3023: =item * &authform_xxxxxx()
1.35 matthew 3024:
3025: The authform_xxxxxx subroutines provide javascript and html forms which
3026: handle some of the conveniences required for authentication forms.
3027: This is not an optimal method, but it works.
3028:
3029: =over 4
3030:
1.112 bowersj2 3031: =item * authform_header
1.35 matthew 3032:
1.112 bowersj2 3033: =item * authform_authorwarning
1.35 matthew 3034:
1.112 bowersj2 3035: =item * authform_nochange
1.35 matthew 3036:
1.112 bowersj2 3037: =item * authform_kerberos
1.35 matthew 3038:
1.112 bowersj2 3039: =item * authform_internal
1.35 matthew 3040:
1.112 bowersj2 3041: =item * authform_filesystem
1.35 matthew 3042:
1.1310 raeburn 3043: =item * authform_lti
3044:
1.35 matthew 3045: =back
3046:
1.648 raeburn 3047: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3048:
1.35 matthew 3049: =cut
3050:
3051: #-------------------------------------------
1.32 matthew 3052: sub authform_header{
3053: my %in = (
3054: formname => 'cu',
1.80 albertel 3055: kerb_def_dom => '',
1.32 matthew 3056: @_,
3057: );
3058: $in{'formname'} = 'document.' . $in{'formname'};
3059: my $result='';
1.80 albertel 3060:
3061: #---------------------------------------------- Code for upper case translation
3062: my $Javascript_toUpperCase;
3063: unless ($in{kerb_def_dom}) {
3064: $Javascript_toUpperCase =<<"END";
3065: switch (choice) {
3066: case 'krb': currentform.elements[choicearg].value =
3067: currentform.elements[choicearg].value.toUpperCase();
3068: break;
3069: default:
3070: }
3071: END
3072: } else {
3073: $Javascript_toUpperCase = "";
3074: }
3075:
1.165 raeburn 3076: my $radioval = "'nochange'";
1.591 raeburn 3077: if (defined($in{'curr_authtype'})) {
3078: if ($in{'curr_authtype'} ne '') {
3079: $radioval = "'".$in{'curr_authtype'}."arg'";
3080: }
1.174 matthew 3081: }
1.165 raeburn 3082: my $argfield = 'null';
1.591 raeburn 3083: if (defined($in{'mode'})) {
1.165 raeburn 3084: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3085: if (defined($in{'curr_autharg'})) {
3086: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3087: $argfield = "'$in{'curr_autharg'}'";
3088: }
3089: }
3090: }
3091: }
3092:
1.32 matthew 3093: $result.=<<"END";
3094: var current = new Object();
1.165 raeburn 3095: current.radiovalue = $radioval;
3096: current.argfield = $argfield;
1.32 matthew 3097:
3098: function changed_radio(choice,currentform) {
3099: var choicearg = choice + 'arg';
3100: // If a radio button in changed, we need to change the argfield
3101: if (current.radiovalue != choice) {
3102: current.radiovalue = choice;
3103: if (current.argfield != null) {
3104: currentform.elements[current.argfield].value = '';
3105: }
3106: if (choice == 'nochange') {
3107: current.argfield = null;
3108: } else {
3109: current.argfield = choicearg;
3110: switch(choice) {
3111: case 'krb':
3112: currentform.elements[current.argfield].value =
3113: "$in{'kerb_def_dom'}";
3114: break;
3115: default:
3116: break;
3117: }
3118: }
3119: }
3120: return;
3121: }
1.22 www 3122:
1.32 matthew 3123: function changed_text(choice,currentform) {
3124: var choicearg = choice + 'arg';
3125: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3126: $Javascript_toUpperCase
1.32 matthew 3127: // clear old field
3128: if ((current.argfield != choicearg) && (current.argfield != null)) {
3129: currentform.elements[current.argfield].value = '';
3130: }
3131: current.argfield = choicearg;
3132: }
3133: set_auth_radio_buttons(choice,currentform);
3134: return;
1.20 www 3135: }
1.32 matthew 3136:
3137: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3138: var numauthchoices = currentform.login.length;
3139: if (typeof numauthchoices == "undefined") {
3140: return;
3141: }
1.32 matthew 3142: var i=0;
1.986 raeburn 3143: while (i < numauthchoices) {
1.32 matthew 3144: if (currentform.login[i].value == newvalue) { break; }
3145: i++;
3146: }
1.986 raeburn 3147: if (i == numauthchoices) {
1.32 matthew 3148: return;
3149: }
3150: current.radiovalue = newvalue;
3151: currentform.login[i].checked = true;
3152: return;
3153: }
3154: END
3155: return $result;
3156: }
3157:
1.1106 raeburn 3158: sub authform_authorwarning {
1.32 matthew 3159: my $result='';
1.144 matthew 3160: $result='<i>'.
3161: &mt('As a general rule, only authors or co-authors should be '.
3162: 'filesystem authenticated '.
3163: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3164: return $result;
3165: }
3166:
1.1106 raeburn 3167: sub authform_nochange {
1.32 matthew 3168: my %in = (
3169: formname => 'document.cu',
3170: kerb_def_dom => 'MSU.EDU',
3171: @_,
3172: );
1.1106 raeburn 3173: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3174: my $result;
1.1104 raeburn 3175: if (!$authnum) {
1.1105 raeburn 3176: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3177: } else {
3178: $result = '<label>'.&mt('[_1] Do not change login data',
3179: '<input type="radio" name="login" value="nochange" '.
3180: 'checked="checked" onclick="'.
1.281 albertel 3181: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3182: '</label>';
1.586 raeburn 3183: }
1.32 matthew 3184: return $result;
3185: }
3186:
1.591 raeburn 3187: sub authform_kerberos {
1.32 matthew 3188: my %in = (
3189: formname => 'document.cu',
3190: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3191: kerb_def_auth => 'krb4',
1.32 matthew 3192: @_,
3193: );
1.586 raeburn 3194: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3195: $autharg,$jscall,$disabled);
1.1106 raeburn 3196: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3197: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3198: $check5 = ' checked="checked"';
1.80 albertel 3199: } else {
1.772 bisitz 3200: $check4 = ' checked="checked"';
1.80 albertel 3201: }
1.1259 raeburn 3202: if ($in{'readonly'}) {
3203: $disabled = ' disabled="disabled"';
3204: }
1.165 raeburn 3205: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3206: if (defined($in{'curr_authtype'})) {
3207: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3208: $krbcheck = ' checked="checked"';
1.623 raeburn 3209: if (defined($in{'mode'})) {
3210: if ($in{'mode'} eq 'modifyuser') {
3211: $krbcheck = '';
3212: }
3213: }
1.591 raeburn 3214: if (defined($in{'curr_kerb_ver'})) {
3215: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3216: $check5 = ' checked="checked"';
1.591 raeburn 3217: $check4 = '';
3218: } else {
1.772 bisitz 3219: $check4 = ' checked="checked"';
1.591 raeburn 3220: $check5 = '';
3221: }
1.586 raeburn 3222: }
1.591 raeburn 3223: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3224: $krbarg = $in{'curr_autharg'};
3225: }
1.586 raeburn 3226: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3227: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3228: $result =
3229: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3230: $in{'curr_autharg'},$krbver);
3231: } else {
3232: $result =
3233: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3234: }
3235: return $result;
3236: }
3237: }
3238: } else {
3239: if ($authnum == 1) {
1.784 bisitz 3240: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3241: }
3242: }
1.586 raeburn 3243: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3244: return;
1.587 raeburn 3245: } elsif ($authtype eq '') {
1.591 raeburn 3246: if (defined($in{'mode'})) {
1.587 raeburn 3247: if ($in{'mode'} eq 'modifycourse') {
3248: if ($authnum == 1) {
1.1259 raeburn 3249: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3250: }
3251: }
3252: }
1.586 raeburn 3253: }
3254: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3255: if ($authtype eq '') {
3256: $authtype = '<input type="radio" name="login" value="krb" '.
3257: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3258: $krbcheck.$disabled.' />';
1.586 raeburn 3259: }
3260: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3261: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3262: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3263: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3264: $in{'curr_authtype'} eq 'krb4')) {
3265: $result .= &mt
1.144 matthew 3266: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3267: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3268: '<label>'.$authtype,
1.281 albertel 3269: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3270: 'value="'.$krbarg.'" '.
1.1259 raeburn 3271: 'onchange="'.$jscall.'"'.$disabled.' />',
3272: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3273: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3274: '</label>');
1.586 raeburn 3275: } elsif ($can_assign{'krb4'}) {
3276: $result .= &mt
3277: ('[_1] Kerberos authenticated with domain [_2] '.
3278: '[_3] Version 4 [_4]',
3279: '<label>'.$authtype,
3280: '</label><input type="text" size="10" name="krbarg" '.
3281: 'value="'.$krbarg.'" '.
1.1259 raeburn 3282: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3283: '<label><input type="hidden" name="krbver" value="4" />',
3284: '</label>');
3285: } elsif ($can_assign{'krb5'}) {
3286: $result .= &mt
3287: ('[_1] Kerberos authenticated with domain [_2] '.
3288: '[_3] Version 5 [_4]',
3289: '<label>'.$authtype,
3290: '</label><input type="text" size="10" name="krbarg" '.
3291: 'value="'.$krbarg.'" '.
1.1259 raeburn 3292: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3293: '<label><input type="hidden" name="krbver" value="5" />',
3294: '</label>');
3295: }
1.32 matthew 3296: return $result;
3297: }
3298:
1.1106 raeburn 3299: sub authform_internal {
1.586 raeburn 3300: my %in = (
1.32 matthew 3301: formname => 'document.cu',
3302: kerb_def_dom => 'MSU.EDU',
3303: @_,
3304: );
1.1259 raeburn 3305: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3306: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3307: if ($in{'readonly'}) {
3308: $disabled = ' disabled="disabled"';
3309: }
1.591 raeburn 3310: if (defined($in{'curr_authtype'})) {
3311: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3312: if ($can_assign{'int'}) {
1.772 bisitz 3313: $intcheck = 'checked="checked" ';
1.623 raeburn 3314: if (defined($in{'mode'})) {
3315: if ($in{'mode'} eq 'modifyuser') {
3316: $intcheck = '';
3317: }
3318: }
1.591 raeburn 3319: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3320: $intarg = $in{'curr_autharg'};
3321: }
3322: } else {
3323: $result = &mt('Currently internally authenticated.');
3324: return $result;
1.165 raeburn 3325: }
3326: }
1.586 raeburn 3327: } else {
3328: if ($authnum == 1) {
1.784 bisitz 3329: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3330: }
3331: }
3332: if (!$can_assign{'int'}) {
3333: return;
1.587 raeburn 3334: } elsif ($authtype eq '') {
1.591 raeburn 3335: if (defined($in{'mode'})) {
1.587 raeburn 3336: if ($in{'mode'} eq 'modifycourse') {
3337: if ($authnum == 1) {
1.1259 raeburn 3338: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3339: }
3340: }
3341: }
1.165 raeburn 3342: }
1.586 raeburn 3343: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3344: if ($authtype eq '') {
3345: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3346: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3347: }
1.605 bisitz 3348: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3349: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3350: $result = &mt
1.144 matthew 3351: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3352: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3353: $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 3354: return $result;
3355: }
3356:
1.1104 raeburn 3357: sub authform_local {
1.32 matthew 3358: my %in = (
3359: formname => 'document.cu',
3360: kerb_def_dom => 'MSU.EDU',
3361: @_,
3362: );
1.1259 raeburn 3363: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3364: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3365: if ($in{'readonly'}) {
3366: $disabled = ' disabled="disabled"';
3367: }
1.591 raeburn 3368: if (defined($in{'curr_authtype'})) {
3369: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3370: if ($can_assign{'loc'}) {
1.772 bisitz 3371: $loccheck = 'checked="checked" ';
1.623 raeburn 3372: if (defined($in{'mode'})) {
3373: if ($in{'mode'} eq 'modifyuser') {
3374: $loccheck = '';
3375: }
3376: }
1.591 raeburn 3377: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3378: $locarg = $in{'curr_autharg'};
3379: }
3380: } else {
3381: $result = &mt('Currently using local (institutional) authentication.');
3382: return $result;
1.165 raeburn 3383: }
3384: }
1.586 raeburn 3385: } else {
3386: if ($authnum == 1) {
1.784 bisitz 3387: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3388: }
3389: }
3390: if (!$can_assign{'loc'}) {
3391: return;
1.587 raeburn 3392: } elsif ($authtype eq '') {
1.591 raeburn 3393: if (defined($in{'mode'})) {
1.587 raeburn 3394: if ($in{'mode'} eq 'modifycourse') {
3395: if ($authnum == 1) {
1.1259 raeburn 3396: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3397: }
3398: }
3399: }
1.165 raeburn 3400: }
1.586 raeburn 3401: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3402: if ($authtype eq '') {
3403: $authtype = '<input type="radio" name="login" value="loc" '.
3404: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3405: $jscall.'"'.$disabled.' />';
1.586 raeburn 3406: }
3407: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3408: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3409: $result = &mt('[_1] Local Authentication with argument [_2]',
3410: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3411: return $result;
3412: }
3413:
1.1106 raeburn 3414: sub authform_filesystem {
1.32 matthew 3415: my %in = (
3416: formname => 'document.cu',
3417: kerb_def_dom => 'MSU.EDU',
3418: @_,
3419: );
1.1259 raeburn 3420: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3421: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3422: if ($in{'readonly'}) {
3423: $disabled = ' disabled="disabled"';
3424: }
1.591 raeburn 3425: if (defined($in{'curr_authtype'})) {
3426: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3427: if ($can_assign{'fsys'}) {
1.772 bisitz 3428: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3429: if (defined($in{'mode'})) {
3430: if ($in{'mode'} eq 'modifyuser') {
3431: $fsyscheck = '';
3432: }
3433: }
1.586 raeburn 3434: } else {
3435: $result = &mt('Currently Filesystem Authenticated.');
3436: return $result;
1.1259 raeburn 3437: }
1.586 raeburn 3438: }
3439: } else {
3440: if ($authnum == 1) {
1.784 bisitz 3441: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3442: }
3443: }
3444: if (!$can_assign{'fsys'}) {
3445: return;
1.587 raeburn 3446: } elsif ($authtype eq '') {
1.591 raeburn 3447: if (defined($in{'mode'})) {
1.587 raeburn 3448: if ($in{'mode'} eq 'modifycourse') {
3449: if ($authnum == 1) {
1.1259 raeburn 3450: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3451: }
3452: }
3453: }
1.586 raeburn 3454: }
3455: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3456: if ($authtype eq '') {
3457: $authtype = '<input type="radio" name="login" value="fsys" '.
3458: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3459: $jscall.'"'.$disabled.' />';
1.586 raeburn 3460: }
1.1310 raeburn 3461: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3462: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3463: $result = &mt
1.144 matthew 3464: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1310 raeburn 3465: '<label>'.$authtype,'</label>'.$autharg);
3466: return $result;
3467: }
3468:
3469: sub authform_lti {
3470: my %in = (
3471: formname => 'document.cu',
3472: kerb_def_dom => 'MSU.EDU',
3473: @_,
3474: );
3475: my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);
3476: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
3477: if ($in{'readonly'}) {
3478: $disabled = ' disabled="disabled"';
3479: }
3480: if (defined($in{'curr_authtype'})) {
3481: if ($in{'curr_authtype'} eq 'lti') {
3482: if ($can_assign{'lti'}) {
3483: $lticheck = 'checked="checked" ';
3484: if (defined($in{'mode'})) {
3485: if ($in{'mode'} eq 'modifyuser') {
3486: $lticheck = '';
3487: }
3488: }
3489: } else {
3490: $result = &mt('Currently LTI Authenticated.');
3491: return $result;
3492: }
3493: }
3494: } else {
3495: if ($authnum == 1) {
3496: $authtype = '<input type="hidden" name="login" value="lti" />';
3497: }
3498: }
3499: if (!$can_assign{'lti'}) {
3500: return;
3501: } elsif ($authtype eq '') {
3502: if (defined($in{'mode'})) {
3503: if ($in{'mode'} eq 'modifycourse') {
3504: if ($authnum == 1) {
3505: $authtype = '<input type="radio" name="login" value="lti"'.$disabled.' />';
3506: }
3507: }
3508: }
3509: }
3510: $jscall = "javascript:changed_radio('lti',$in{'formname'});";
3511: if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {
3512: $authtype = '<input type="radio" name="login" value="lti" '.
3513: $lticheck.' onchange="'.$jscall.'" onclick="'.
3514: $jscall.'"'.$disabled.' />';
3515: }
3516: $autharg = '<input type="hidden" name="ltiarg" value="" />';
3517: if ($authtype) {
3518: $result = &mt('[_1] LTI Authenticated',
3519: '<label>'.$authtype.'</label>'.$autharg);
3520: } else {
3521: $result = '<b>'.&mt('LTI Authenticated').'</b>'.
3522: $autharg;
3523: }
1.32 matthew 3524: return $result;
3525: }
3526:
1.586 raeburn 3527: sub get_assignable_auth {
3528: my ($dom) = @_;
3529: if ($dom eq '') {
3530: $dom = $env{'request.role.domain'};
3531: }
3532: my %can_assign = (
3533: krb4 => 1,
3534: krb5 => 1,
3535: int => 1,
3536: loc => 1,
1.1310 raeburn 3537: lti => 1,
1.586 raeburn 3538: );
3539: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3540: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3541: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3542: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3543: my $context;
3544: if ($env{'request.role'} =~ /^au/) {
3545: $context = 'author';
1.1259 raeburn 3546: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3547: $context = 'domain';
3548: } elsif ($env{'request.course.id'}) {
3549: $context = 'course';
3550: }
3551: if ($context) {
3552: if (ref($authhash->{$context}) eq 'HASH') {
3553: %can_assign = %{$authhash->{$context}};
3554: }
3555: }
3556: }
3557: }
3558: my $authnum = 0;
3559: foreach my $key (keys(%can_assign)) {
3560: if ($can_assign{$key}) {
3561: $authnum ++;
3562: }
3563: }
3564: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3565: $authnum --;
3566: }
3567: return ($authnum,%can_assign);
3568: }
3569:
1.1331 raeburn 3570: sub check_passwd_rules {
3571: my ($domain,$plainpass) = @_;
3572: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3573: my ($min,$max,@chars,@brokerule,$warning);
1.1333 raeburn 3574: $min = $Apache::lonnet::passwdmin;
1.1331 raeburn 3575: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3576: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1333 raeburn 3577: if ($passwdconf{'min'} > $min) {
3578: $min = $passwdconf{'min'};
3579: }
1.1331 raeburn 3580: }
3581: if ($passwdconf{'max'} =~ /^\d+$/) {
3582: $max = $passwdconf{'max'};
3583: }
3584: @chars = @{$passwdconf{'chars'}};
3585: }
3586: if (($min) && (length($plainpass) < $min)) {
3587: push(@brokerule,'min');
3588: }
3589: if (($max) && (length($plainpass) > $max)) {
3590: push(@brokerule,'max');
3591: }
3592: if (@chars) {
3593: my %rules;
3594: map { $rules{$_} = 1; } @chars;
3595: if ($rules{'uc'}) {
3596: unless ($plainpass =~ /[A-Z]/) {
3597: push(@brokerule,'uc');
3598: }
3599: }
3600: if ($rules{'lc'}) {
1.1332 raeburn 3601: unless ($plainpass =~ /[a-z]/) {
1.1331 raeburn 3602: push(@brokerule,'lc');
3603: }
3604: }
3605: if ($rules{'num'}) {
3606: unless ($plainpass =~ /\d/) {
3607: push(@brokerule,'num');
3608: }
3609: }
3610: if ($rules{'spec'}) {
3611: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3612: push(@brokerule,'spec');
3613: }
3614: }
3615: }
3616: if (@brokerule) {
3617: my %rulenames = &Apache::lonlocal::texthash(
3618: uc => 'At least one upper case letter',
3619: lc => 'At least one lower case letter',
3620: num => 'At least one number',
3621: spec => 'At least one non-alphanumeric',
3622: );
3623: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3624: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3625: $rulenames{'num'} .= ': 0123456789';
3626: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3627: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3628: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3629: $warning = &mt('Password did not satisfy the following:').'<ul>';
3630: foreach my $rule ('min','max','uc','ls','num','spec') {
3631: if (grep(/^$rule$/,@brokerule)) {
3632: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3633: }
3634: }
3635: $warning .= '</ul>';
3636: }
1.1332 raeburn 3637: if (wantarray) {
3638: return @brokerule;
3639: }
1.1331 raeburn 3640: return $warning;
3641: }
3642:
1.80 albertel 3643: ###############################################################
3644: ## Get Kerberos Defaults for Domain ##
3645: ###############################################################
3646: ##
3647: ## Returns default kerberos version and an associated argument
3648: ## as listed in file domain.tab. If not listed, provides
3649: ## appropriate default domain and kerberos version.
3650: ##
3651: #-------------------------------------------
3652:
3653: =pod
3654:
1.648 raeburn 3655: =item * &get_kerberos_defaults()
1.80 albertel 3656:
3657: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3658: version and domain. If not found, it defaults to version 4 and the
3659: domain of the server.
1.80 albertel 3660:
1.648 raeburn 3661: =over 4
3662:
1.80 albertel 3663: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3664:
1.648 raeburn 3665: =back
3666:
3667: =back
3668:
1.80 albertel 3669: =cut
3670:
3671: #-------------------------------------------
3672: sub get_kerberos_defaults {
3673: my $domain=shift;
1.641 raeburn 3674: my ($krbdef,$krbdefdom);
3675: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3676: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3677: $krbdef = $domdefaults{'auth_def'};
3678: $krbdefdom = $domdefaults{'auth_arg_def'};
3679: } else {
1.80 albertel 3680: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3681: my $krbdefdom=$1;
3682: $krbdefdom=~tr/a-z/A-Z/;
3683: $krbdef = "krb4";
3684: }
3685: return ($krbdef,$krbdefdom);
3686: }
1.112 bowersj2 3687:
1.32 matthew 3688:
1.46 matthew 3689: ###############################################################
3690: ## Thesaurus Functions ##
3691: ###############################################################
1.20 www 3692:
1.46 matthew 3693: =pod
1.20 www 3694:
1.112 bowersj2 3695: =head1 Thesaurus Functions
3696:
3697: =over 4
3698:
1.648 raeburn 3699: =item * &initialize_keywords()
1.46 matthew 3700:
3701: Initializes the package variable %Keywords if it is empty. Uses the
3702: package variable $thesaurus_db_file.
3703:
3704: =cut
3705:
3706: ###################################################
3707:
3708: sub initialize_keywords {
3709: return 1 if (scalar keys(%Keywords));
3710: # If we are here, %Keywords is empty, so fill it up
3711: # Make sure the file we need exists...
3712: if (! -e $thesaurus_db_file) {
3713: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3714: " failed because it does not exist");
3715: return 0;
3716: }
3717: # Set up the hash as a database
3718: my %thesaurus_db;
3719: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3720: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3721: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3722: $thesaurus_db_file);
3723: return 0;
3724: }
3725: # Get the average number of appearances of a word.
3726: my $avecount = $thesaurus_db{'average.count'};
3727: # Put keywords (those that appear > average) into %Keywords
3728: while (my ($word,$data)=each (%thesaurus_db)) {
3729: my ($count,undef) = split /:/,$data;
3730: $Keywords{$word}++ if ($count > $avecount);
3731: }
3732: untie %thesaurus_db;
3733: # Remove special values from %Keywords.
1.356 albertel 3734: foreach my $value ('total.count','average.count') {
3735: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3736: }
1.46 matthew 3737: return 1;
3738: }
3739:
3740: ###################################################
3741:
3742: =pod
3743:
1.648 raeburn 3744: =item * &keyword($word)
1.46 matthew 3745:
3746: Returns true if $word is a keyword. A keyword is a word that appears more
3747: than the average number of times in the thesaurus database. Calls
3748: &initialize_keywords
3749:
3750: =cut
3751:
3752: ###################################################
1.20 www 3753:
3754: sub keyword {
1.46 matthew 3755: return if (!&initialize_keywords());
3756: my $word=lc(shift());
3757: $word=~s/\W//g;
3758: return exists($Keywords{$word});
1.20 www 3759: }
1.46 matthew 3760:
3761: ###############################################################
3762:
3763: =pod
1.20 www 3764:
1.648 raeburn 3765: =item * &get_related_words()
1.46 matthew 3766:
1.160 matthew 3767: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3768: an array of words. If the keyword is not in the thesaurus, an empty array
3769: will be returned. The order of the words returned is determined by the
3770: database which holds them.
3771:
3772: Uses global $thesaurus_db_file.
3773:
1.1057 foxr 3774:
1.46 matthew 3775: =cut
3776:
3777: ###############################################################
3778: sub get_related_words {
3779: my $keyword = shift;
3780: my %thesaurus_db;
3781: if (! -e $thesaurus_db_file) {
3782: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3783: "failed because the file does not exist");
3784: return ();
3785: }
3786: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3787: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3788: return ();
3789: }
3790: my @Words=();
1.429 www 3791: my $count=0;
1.46 matthew 3792: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3793: # The first element is the number of times
3794: # the word appears. We do not need it now.
1.429 www 3795: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3796: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3797: my $threshold=$mostfrequentcount/10;
3798: foreach my $possibleword (@RelatedWords) {
3799: my ($word,$wordcount)=split(/\,/,$possibleword);
3800: if ($wordcount>$threshold) {
3801: push(@Words,$word);
3802: $count++;
3803: if ($count>10) { last; }
3804: }
1.20 www 3805: }
3806: }
1.46 matthew 3807: untie %thesaurus_db;
3808: return @Words;
1.14 harris41 3809: }
1.1090 foxr 3810: ###############################################################
3811: #
3812: # Spell checking
3813: #
3814:
3815: =pod
3816:
1.1142 raeburn 3817: =back
3818:
1.1090 foxr 3819: =head1 Spell checking
3820:
3821: =over 4
3822:
3823: =item * &check_spelling($wordlist $language)
3824:
3825: Takes a string containing words and feeds it to an external
3826: spellcheck program via a pipeline. Returns a string containing
3827: them mis-spelled words.
3828:
3829: Parameters:
3830:
3831: =over 4
3832:
3833: =item - $wordlist
3834:
3835: String that will be fed into the spellcheck program.
3836:
3837: =item - $language
3838:
3839: Language string that specifies the language for which the spell
3840: check will be performed.
3841:
3842: =back
3843:
3844: =back
3845:
3846: Note: This sub assumes that aspell is installed.
3847:
3848:
3849: =cut
3850:
1.46 matthew 3851:
1.1090 foxr 3852: sub check_spelling {
3853: my ($wordlist, $language) = @_;
1.1091 foxr 3854: my @misspellings;
3855:
3856: # Generate the speller and set the langauge.
3857: # if explicitly selected:
1.1090 foxr 3858:
1.1091 foxr 3859: my $speller = Text::Aspell->new;
1.1090 foxr 3860: if ($language) {
1.1091 foxr 3861: $speller->set_option('lang', $language);
1.1090 foxr 3862: }
3863:
1.1091 foxr 3864: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3865:
1.1091 foxr 3866: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3867:
1.1091 foxr 3868: foreach my $word (@words) {
3869: if(! $speller->check($word)) {
3870: push(@misspellings, $word);
1.1090 foxr 3871: }
3872: }
1.1091 foxr 3873: return join(' ', @misspellings);
3874:
1.1090 foxr 3875: }
3876:
1.61 www 3877: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3878: =pod
3879:
1.112 bowersj2 3880: =head1 User Name Functions
3881:
3882: =over 4
3883:
1.648 raeburn 3884: =item * &plainname($uname,$udom,$first)
1.81 albertel 3885:
1.112 bowersj2 3886: Takes a users logon name and returns it as a string in
1.226 albertel 3887: "first middle last generation" form
3888: if $first is set to 'lastname' then it returns it as
3889: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3890:
3891: =cut
1.61 www 3892:
1.295 www 3893:
1.81 albertel 3894: ###############################################################
1.61 www 3895: sub plainname {
1.226 albertel 3896: my ($uname,$udom,$first)=@_;
1.537 albertel 3897: return if (!defined($uname) || !defined($udom));
1.295 www 3898: my %names=&getnames($uname,$udom);
1.226 albertel 3899: my $name=&Apache::lonnet::format_name($names{'firstname'},
3900: $names{'middlename'},
3901: $names{'lastname'},
3902: $names{'generation'},$first);
3903: $name=~s/^\s+//;
1.62 www 3904: $name=~s/\s+$//;
3905: $name=~s/\s+/ /g;
1.353 albertel 3906: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3907: return $name;
1.61 www 3908: }
1.66 www 3909:
3910: # -------------------------------------------------------------------- Nickname
1.81 albertel 3911: =pod
3912:
1.648 raeburn 3913: =item * &nickname($uname,$udom)
1.81 albertel 3914:
3915: Gets a users name and returns it as a string as
3916:
3917: ""nickname""
1.66 www 3918:
1.81 albertel 3919: if the user has a nickname or
3920:
3921: "first middle last generation"
3922:
3923: if the user does not
3924:
3925: =cut
1.66 www 3926:
3927: sub nickname {
3928: my ($uname,$udom)=@_;
1.537 albertel 3929: return if (!defined($uname) || !defined($udom));
1.295 www 3930: my %names=&getnames($uname,$udom);
1.68 albertel 3931: my $name=$names{'nickname'};
1.66 www 3932: if ($name) {
3933: $name='"'.$name.'"';
3934: } else {
3935: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3936: $names{'lastname'}.' '.$names{'generation'};
3937: $name=~s/\s+$//;
3938: $name=~s/\s+/ /g;
3939: }
3940: return $name;
3941: }
3942:
1.295 www 3943: sub getnames {
3944: my ($uname,$udom)=@_;
1.537 albertel 3945: return if (!defined($uname) || !defined($udom));
1.433 albertel 3946: if ($udom eq 'public' && $uname eq 'public') {
3947: return ('lastname' => &mt('Public'));
3948: }
1.295 www 3949: my $id=$uname.':'.$udom;
3950: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3951: if ($cached) {
3952: return %{$names};
3953: } else {
3954: my %loadnames=&Apache::lonnet::get('environment',
3955: ['firstname','middlename','lastname','generation','nickname'],
3956: $udom,$uname);
3957: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3958: return %loadnames;
3959: }
3960: }
1.61 www 3961:
1.542 raeburn 3962: # -------------------------------------------------------------------- getemails
1.648 raeburn 3963:
1.542 raeburn 3964: =pod
3965:
1.648 raeburn 3966: =item * &getemails($uname,$udom)
1.542 raeburn 3967:
3968: Gets a user's email information and returns it as a hash with keys:
3969: notification, critnotification, permanentemail
3970:
3971: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3972: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3973:
1.648 raeburn 3974:
1.542 raeburn 3975: =cut
3976:
1.648 raeburn 3977:
1.466 albertel 3978: sub getemails {
3979: my ($uname,$udom)=@_;
3980: if ($udom eq 'public' && $uname eq 'public') {
3981: return;
3982: }
1.467 www 3983: if (!$udom) { $udom=$env{'user.domain'}; }
3984: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3985: my $id=$uname.':'.$udom;
3986: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3987: if ($cached) {
3988: return %{$names};
3989: } else {
3990: my %loadnames=&Apache::lonnet::get('environment',
3991: ['notification','critnotification',
3992: 'permanentemail'],
3993: $udom,$uname);
3994: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3995: return %loadnames;
3996: }
3997: }
3998:
1.551 albertel 3999: sub flush_email_cache {
4000: my ($uname,$udom)=@_;
4001: if (!$udom) { $udom =$env{'user.domain'}; }
4002: if (!$uname) { $uname=$env{'user.name'}; }
4003: return if ($udom eq 'public' && $uname eq 'public');
4004: my $id=$uname.':'.$udom;
4005: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
4006: }
4007:
1.728 raeburn 4008: # -------------------------------------------------------------------- getlangs
4009:
4010: =pod
4011:
4012: =item * &getlangs($uname,$udom)
4013:
4014: Gets a user's language preference and returns it as a hash with key:
4015: language.
4016:
4017: =cut
4018:
4019:
4020: sub getlangs {
4021: my ($uname,$udom) = @_;
4022: if (!$udom) { $udom =$env{'user.domain'}; }
4023: if (!$uname) { $uname=$env{'user.name'}; }
4024: my $id=$uname.':'.$udom;
4025: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
4026: if ($cached) {
4027: return %{$langs};
4028: } else {
4029: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
4030: $udom,$uname);
4031: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
4032: return %loadlangs;
4033: }
4034: }
4035:
4036: sub flush_langs_cache {
4037: my ($uname,$udom)=@_;
4038: if (!$udom) { $udom =$env{'user.domain'}; }
4039: if (!$uname) { $uname=$env{'user.name'}; }
4040: return if ($udom eq 'public' && $uname eq 'public');
4041: my $id=$uname.':'.$udom;
4042: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
4043: }
4044:
1.61 www 4045: # ------------------------------------------------------------------ Screenname
1.81 albertel 4046:
4047: =pod
4048:
1.648 raeburn 4049: =item * &screenname($uname,$udom)
1.81 albertel 4050:
4051: Gets a users screenname and returns it as a string
4052:
4053: =cut
1.61 www 4054:
4055: sub screenname {
4056: my ($uname,$udom)=@_;
1.258 albertel 4057: if ($uname eq $env{'user.name'} &&
4058: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 4059: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 4060: return $names{'screenname'};
1.62 www 4061: }
4062:
1.212 albertel 4063:
1.802 bisitz 4064: # ------------------------------------------------------------- Confirm Wrapper
4065: =pod
4066:
1.1142 raeburn 4067: =item * &confirmwrapper($message)
1.802 bisitz 4068:
4069: Wrap messages about completion of operation in box
4070:
4071: =cut
4072:
4073: sub confirmwrapper {
4074: my ($message)=@_;
4075: if ($message) {
4076: return "\n".'<div class="LC_confirm_box">'."\n"
4077: .$message."\n"
4078: .'</div>'."\n";
4079: } else {
4080: return $message;
4081: }
4082: }
4083:
1.62 www 4084: # ------------------------------------------------------------- Message Wrapper
4085:
4086: sub messagewrapper {
1.369 www 4087: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 4088: return
1.441 albertel 4089: '<a href="/adm/email?compose=individual&'.
4090: 'recname='.$username.'&recdom='.$domain.
4091: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 4092: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 4093: }
1.802 bisitz 4094:
1.74 www 4095: # --------------------------------------------------------------- Notes Wrapper
4096:
4097: sub noteswrapper {
4098: my ($link,$un,$do)=@_;
4099: return
1.896 amueller 4100: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 4101: }
1.802 bisitz 4102:
1.62 www 4103: # ------------------------------------------------------------- Aboutme Wrapper
4104:
4105: sub aboutmewrapper {
1.1070 raeburn 4106: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 4107: if (!defined($username) && !defined($domain)) {
4108: return;
4109: }
1.1096 raeburn 4110: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 4111: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 4112: }
4113:
4114: # ------------------------------------------------------------ Syllabus Wrapper
4115:
4116: sub syllabuswrapper {
1.707 bisitz 4117: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 4118: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 4119: }
1.14 harris41 4120:
1.802 bisitz 4121: # -----------------------------------------------------------------------------
4122:
1.208 matthew 4123: sub track_student_link {
1.887 raeburn 4124: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 4125: my $link ="/adm/trackstudent?";
1.208 matthew 4126: my $title = 'View recent activity';
4127: if (defined($sname) && $sname !~ /^\s*$/ &&
4128: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 4129: $link .= "selected_student=$sname:$sdom";
1.208 matthew 4130: $title .= ' of this student';
1.268 albertel 4131: }
1.208 matthew 4132: if (defined($target) && $target !~ /^\s*$/) {
4133: $target = qq{target="$target"};
4134: } else {
4135: $target = '';
4136: }
1.268 albertel 4137: if ($start) { $link.='&start='.$start; }
1.887 raeburn 4138: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 4139: $title = &mt($title);
4140: $linktext = &mt($linktext);
1.448 albertel 4141: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
4142: &help_open_topic('View_recent_activity');
1.208 matthew 4143: }
4144:
1.781 raeburn 4145: sub slot_reservations_link {
4146: my ($linktext,$sname,$sdom,$target) = @_;
4147: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
4148: my $title = 'View slot reservation history';
4149: if (defined($sname) && $sname !~ /^\s*$/ &&
4150: defined($sdom) && $sdom !~ /^\s*$/) {
4151: $link .= "&uname=$sname&udom=$sdom";
4152: $title .= ' of this student';
4153: }
4154: if (defined($target) && $target !~ /^\s*$/) {
4155: $target = qq{target="$target"};
4156: } else {
4157: $target = '';
4158: }
4159: $title = &mt($title);
4160: $linktext = &mt($linktext);
4161: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4162: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4163:
4164: }
4165:
1.508 www 4166: # ===================================================== Display a student photo
4167:
4168:
1.509 albertel 4169: sub student_image_tag {
1.508 www 4170: my ($domain,$user)=@_;
4171: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4172: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4173: return '<img src="'.$imgsrc.'" align="right" />';
4174: } else {
4175: return '';
4176: }
4177: }
4178:
1.112 bowersj2 4179: =pod
4180:
4181: =back
4182:
4183: =head1 Access .tab File Data
4184:
4185: =over 4
4186:
1.648 raeburn 4187: =item * &languageids()
1.112 bowersj2 4188:
4189: returns list of all language ids
4190:
4191: =cut
4192:
1.14 harris41 4193: sub languageids {
1.16 harris41 4194: return sort(keys(%language));
1.14 harris41 4195: }
4196:
1.112 bowersj2 4197: =pod
4198:
1.648 raeburn 4199: =item * &languagedescription()
1.112 bowersj2 4200:
4201: returns description of a specified language id
4202:
4203: =cut
4204:
1.14 harris41 4205: sub languagedescription {
1.125 www 4206: my $code=shift;
4207: return ($supported_language{$code}?'* ':'').
4208: $language{$code}.
1.126 www 4209: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4210: }
4211:
1.1048 foxr 4212: =pod
4213:
4214: =item * &plainlanguagedescription
4215:
4216: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4217: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4218:
4219: =cut
4220:
1.145 www 4221: sub plainlanguagedescription {
4222: my $code=shift;
4223: return $language{$code};
4224: }
4225:
1.1048 foxr 4226: =pod
4227:
4228: =item * &supportedlanguagecode
4229:
4230: Returns the supported language code (e.g. sptutf maps to pt) given a language
4231: code.
4232:
4233: =cut
4234:
1.145 www 4235: sub supportedlanguagecode {
4236: my $code=shift;
4237: return $supported_language{$code};
1.97 www 4238: }
4239:
1.112 bowersj2 4240: =pod
4241:
1.1048 foxr 4242: =item * &latexlanguage()
4243:
4244: Given a language key code returns the correspondnig language to use
4245: to select the correct hyphenation on LaTeX printouts. This is undef if there
4246: is no supported hyphenation for the language code.
4247:
4248: =cut
4249:
4250: sub latexlanguage {
4251: my $code = shift;
4252: return $latex_language{$code};
4253: }
4254:
4255: =pod
4256:
4257: =item * &latexhyphenation()
4258:
4259: Same as above but what's supplied is the language as it might be stored
4260: in the metadata.
4261:
4262: =cut
4263:
4264: sub latexhyphenation {
4265: my $key = shift;
4266: return $latex_language_bykey{$key};
4267: }
4268:
4269: =pod
4270:
1.648 raeburn 4271: =item * ©rightids()
1.112 bowersj2 4272:
4273: returns list of all copyrights
4274:
4275: =cut
4276:
4277: sub copyrightids {
4278: return sort(keys(%cprtag));
4279: }
4280:
4281: =pod
4282:
1.648 raeburn 4283: =item * ©rightdescription()
1.112 bowersj2 4284:
4285: returns description of a specified copyright id
4286:
4287: =cut
4288:
4289: sub copyrightdescription {
1.166 www 4290: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4291: }
1.197 matthew 4292:
4293: =pod
4294:
1.648 raeburn 4295: =item * &source_copyrightids()
1.192 taceyjo1 4296:
4297: returns list of all source copyrights
4298:
4299: =cut
4300:
4301: sub source_copyrightids {
4302: return sort(keys(%scprtag));
4303: }
4304:
4305: =pod
4306:
1.648 raeburn 4307: =item * &source_copyrightdescription()
1.192 taceyjo1 4308:
4309: returns description of a specified source copyright id
4310:
4311: =cut
4312:
4313: sub source_copyrightdescription {
4314: return &mt($scprtag{shift(@_)});
4315: }
1.112 bowersj2 4316:
4317: =pod
4318:
1.648 raeburn 4319: =item * &filecategories()
1.112 bowersj2 4320:
4321: returns list of all file categories
4322:
4323: =cut
4324:
4325: sub filecategories {
4326: return sort(keys(%category_extensions));
4327: }
4328:
4329: =pod
4330:
1.648 raeburn 4331: =item * &filecategorytypes()
1.112 bowersj2 4332:
4333: returns list of file types belonging to a given file
4334: category
4335:
4336: =cut
4337:
4338: sub filecategorytypes {
1.356 albertel 4339: my ($cat) = @_;
1.1248 raeburn 4340: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4341: return @{$category_extensions{lc($cat)}};
4342: } else {
4343: return ();
4344: }
1.112 bowersj2 4345: }
4346:
4347: =pod
4348:
1.648 raeburn 4349: =item * &fileembstyle()
1.112 bowersj2 4350:
4351: returns embedding style for a specified file type
4352:
4353: =cut
4354:
4355: sub fileembstyle {
4356: return $fe{lc(shift(@_))};
1.169 www 4357: }
4358:
1.351 www 4359: sub filemimetype {
4360: return $fm{lc(shift(@_))};
4361: }
4362:
1.169 www 4363:
4364: sub filecategoryselect {
4365: my ($name,$value)=@_;
1.189 matthew 4366: return &select_form($value,$name,
1.970 raeburn 4367: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4368: }
4369:
4370: =pod
4371:
1.648 raeburn 4372: =item * &filedescription()
1.112 bowersj2 4373:
4374: returns description for a specified file type
4375:
4376: =cut
4377:
4378: sub filedescription {
1.188 matthew 4379: my $file_description = $fd{lc(shift())};
4380: $file_description =~ s:([\[\]]):~$1:g;
4381: return &mt($file_description);
1.112 bowersj2 4382: }
4383:
4384: =pod
4385:
1.648 raeburn 4386: =item * &filedescriptionex()
1.112 bowersj2 4387:
4388: returns description for a specified file type with
4389: extra formatting
4390:
4391: =cut
4392:
4393: sub filedescriptionex {
4394: my $ex=shift;
1.188 matthew 4395: my $file_description = $fd{lc($ex)};
4396: $file_description =~ s:([\[\]]):~$1:g;
4397: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4398: }
4399:
4400: # End of .tab access
4401: =pod
4402:
4403: =back
4404:
4405: =cut
4406:
4407: # ------------------------------------------------------------------ File Types
4408: sub fileextensions {
4409: return sort(keys(%fe));
4410: }
4411:
1.97 www 4412: # ----------------------------------------------------------- Display Languages
4413: # returns a hash with all desired display languages
4414: #
4415:
4416: sub display_languages {
4417: my %languages=();
1.695 raeburn 4418: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4419: $languages{$lang}=1;
1.97 www 4420: }
4421: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4422: if ($env{'form.displaylanguage'}) {
1.356 albertel 4423: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4424: $languages{$lang}=1;
1.97 www 4425: }
4426: }
4427: return %languages;
1.14 harris41 4428: }
4429:
1.582 albertel 4430: sub languages {
4431: my ($possible_langs) = @_;
1.695 raeburn 4432: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4433: if (!ref($possible_langs)) {
4434: if( wantarray ) {
4435: return @preferred_langs;
4436: } else {
4437: return $preferred_langs[0];
4438: }
4439: }
4440: my %possibilities = map { $_ => 1 } (@$possible_langs);
4441: my @preferred_possibilities;
4442: foreach my $preferred_lang (@preferred_langs) {
4443: if (exists($possibilities{$preferred_lang})) {
4444: push(@preferred_possibilities, $preferred_lang);
4445: }
4446: }
4447: if( wantarray ) {
4448: return @preferred_possibilities;
4449: }
4450: return $preferred_possibilities[0];
4451: }
4452:
1.742 raeburn 4453: sub user_lang {
4454: my ($touname,$toudom,$fromcid) = @_;
4455: my @userlangs;
4456: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4457: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4458: $env{'course.'.$fromcid.'.languages'}));
4459: } else {
4460: my %langhash = &getlangs($touname,$toudom);
4461: if ($langhash{'languages'} ne '') {
4462: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4463: } else {
4464: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4465: if ($domdefs{'lang_def'} ne '') {
4466: @userlangs = ($domdefs{'lang_def'});
4467: }
4468: }
4469: }
4470: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4471: my $user_lh = Apache::localize->get_handle(@languages);
4472: return $user_lh;
4473: }
4474:
4475:
1.112 bowersj2 4476: ###############################################################
4477: ## Student Answer Attempts ##
4478: ###############################################################
4479:
4480: =pod
4481:
4482: =head1 Alternate Problem Views
4483:
4484: =over 4
4485:
1.648 raeburn 4486: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4487: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4488:
4489: Return string with previous attempt on problem. Arguments:
4490:
4491: =over 4
4492:
4493: =item * $symb: Problem, including path
4494:
4495: =item * $username: username of the desired student
4496:
4497: =item * $domain: domain of the desired student
1.14 harris41 4498:
1.112 bowersj2 4499: =item * $course: Course ID
1.14 harris41 4500:
1.112 bowersj2 4501: =item * $getattempt: Leave blank for all attempts, otherwise put
4502: something
1.14 harris41 4503:
1.112 bowersj2 4504: =item * $regexp: if string matches this regexp, the string will be
4505: sent to $gradesub
1.14 harris41 4506:
1.112 bowersj2 4507: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4508:
1.1199 raeburn 4509: =item * $usec: section of the desired student
4510:
4511: =item * $identifier: counter for student (multiple students one problem) or
4512: problem (one student; whole sequence).
4513:
1.112 bowersj2 4514: =back
1.14 harris41 4515:
1.112 bowersj2 4516: The output string is a table containing all desired attempts, if any.
1.16 harris41 4517:
1.112 bowersj2 4518: =cut
1.1 albertel 4519:
4520: sub get_previous_attempt {
1.1199 raeburn 4521: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4522: my $prevattempts='';
1.43 ng 4523: no strict 'refs';
1.1 albertel 4524: if ($symb) {
1.3 albertel 4525: my (%returnhash)=
4526: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4527: if ($returnhash{'version'}) {
4528: my %lasthash=();
4529: my $version;
4530: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4531: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4532: if ($key =~ /\.rawrndseed$/) {
4533: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4534: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4535: } else {
4536: $lasthash{$key}=$returnhash{$version.':'.$key};
4537: }
1.19 harris41 4538: }
1.1 albertel 4539: }
1.596 albertel 4540: $prevattempts=&start_data_table().&start_data_table_header_row();
4541: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4542: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4543: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4544: foreach my $key (sort(keys(%lasthash))) {
4545: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4546: if ($#parts > 0) {
1.31 albertel 4547: my $data=$parts[-1];
1.989 raeburn 4548: next if ($data eq 'foilorder');
1.31 albertel 4549: pop(@parts);
1.1010 www 4550: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4551: if ($data eq 'type') {
4552: unless ($showsurv) {
4553: my $id = join(',',@parts);
4554: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4555: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4556: $lasthidden{$ign.'.'.$id} = 1;
4557: }
1.945 raeburn 4558: }
1.1199 raeburn 4559: if ($identifier ne '') {
4560: my $id = join(',',@parts);
4561: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4562: $domain,$username,$usec,undef,$course) =~ /^no/) {
4563: $hidestatus{$ign.'.'.$id} = 1;
4564: }
4565: }
4566: } elsif ($data eq 'regrader') {
4567: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4568: my $id = join(',',@parts);
4569: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4570: }
1.1010 www 4571: }
1.31 albertel 4572: } else {
1.41 ng 4573: if ($#parts == 0) {
4574: $prevattempts.='<th>'.$parts[0].'</th>';
4575: } else {
4576: $prevattempts.='<th>'.$ign.'</th>';
4577: }
1.31 albertel 4578: }
1.16 harris41 4579: }
1.596 albertel 4580: $prevattempts.=&end_data_table_header_row();
1.40 ng 4581: if ($getattempt eq '') {
1.1199 raeburn 4582: my (%solved,%resets,%probstatus);
1.1200 raeburn 4583: if (($identifier ne '') && (keys(%regraded) > 0)) {
4584: for ($version=1;$version<=$returnhash{'version'};$version++) {
4585: foreach my $id (keys(%regraded)) {
4586: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4587: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4588: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4589: push(@{$resets{$id}},$version);
1.1199 raeburn 4590: }
4591: }
4592: }
1.1200 raeburn 4593: }
4594: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4595: my (@hidden,@unsolved);
1.945 raeburn 4596: if (%typeparts) {
4597: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4598: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4599: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4600: push(@hidden,$id);
1.1199 raeburn 4601: } elsif ($identifier ne '') {
4602: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4603: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4604: ($hidestatus{$id})) {
1.1200 raeburn 4605: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4606: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4607: push(@{$solved{$id}},$version);
4608: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4609: (ref($solved{$id}) eq 'ARRAY')) {
4610: my $skip;
4611: if (ref($resets{$id}) eq 'ARRAY') {
4612: foreach my $reset (@{$resets{$id}}) {
4613: if ($reset > $solved{$id}[-1]) {
4614: $skip=1;
4615: last;
4616: }
4617: }
4618: }
4619: unless ($skip) {
4620: my ($ign,$partslist) = split(/\./,$id,2);
4621: push(@unsolved,$partslist);
4622: }
4623: }
4624: }
1.945 raeburn 4625: }
4626: }
4627: }
4628: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4629: '<td>'.&mt('Transaction [_1]',$version);
4630: if (@unsolved) {
4631: $prevattempts .= '<span class="LC_nobreak"><label>'.
4632: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4633: &mt('Hide').'</label></span>';
4634: }
4635: $prevattempts .= '</td>';
1.945 raeburn 4636: if (@hidden) {
4637: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4638: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4639: my $hide;
4640: foreach my $id (@hidden) {
4641: if ($key =~ /^\Q$id\E/) {
4642: $hide = 1;
4643: last;
4644: }
4645: }
4646: if ($hide) {
4647: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4648: if (($data eq 'award') || ($data eq 'awarddetail')) {
4649: my $value = &format_previous_attempt_value($key,
4650: $returnhash{$version.':'.$key});
1.1173 kruse 4651: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4652: } else {
4653: $prevattempts.='<td> </td>';
4654: }
4655: } else {
4656: if ($key =~ /\./) {
1.1212 raeburn 4657: my $value = $returnhash{$version.':'.$key};
4658: if ($key =~ /\.rndseed$/) {
4659: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4660: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4661: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4662: }
4663: }
4664: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4665: ' </td>';
1.945 raeburn 4666: } else {
4667: $prevattempts.='<td> </td>';
4668: }
4669: }
4670: }
4671: } else {
4672: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4673: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4674: my $value = $returnhash{$version.':'.$key};
4675: if ($key =~ /\.rndseed$/) {
4676: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4677: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4678: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4679: }
4680: }
4681: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4682: ' </td>';
1.945 raeburn 4683: }
4684: }
4685: $prevattempts.=&end_data_table_row();
1.40 ng 4686: }
1.1 albertel 4687: }
1.945 raeburn 4688: my @currhidden = keys(%lasthidden);
1.596 albertel 4689: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4690: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4691: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4692: if (%typeparts) {
4693: my $hidden;
4694: foreach my $id (@currhidden) {
4695: if ($key =~ /^\Q$id\E/) {
4696: $hidden = 1;
4697: last;
4698: }
4699: }
4700: if ($hidden) {
4701: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4702: if (($data eq 'award') || ($data eq 'awarddetail')) {
4703: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4704: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4705: $value = &$gradesub($value);
4706: }
1.1173 kruse 4707: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4708: } else {
4709: $prevattempts.='<td> </td>';
4710: }
4711: } else {
4712: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4713: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4714: $value = &$gradesub($value);
4715: }
1.1173 kruse 4716: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4717: }
4718: } else {
4719: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4720: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4721: $value = &$gradesub($value);
4722: }
1.1173 kruse 4723: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4724: }
1.16 harris41 4725: }
1.596 albertel 4726: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4727: } else {
1.1305 raeburn 4728: my $msg;
4729: if ($symb =~ /ext\.tool$/) {
4730: $msg = &mt('No grade passed back.');
4731: } else {
4732: $msg = &mt('Nothing submitted - no attempts.');
4733: }
1.596 albertel 4734: $prevattempts=
4735: &start_data_table().&start_data_table_row().
1.1305 raeburn 4736: '<td>'.$msg.'</td>'.
1.596 albertel 4737: &end_data_table_row().&end_data_table();
1.1 albertel 4738: }
4739: } else {
1.596 albertel 4740: $prevattempts=
4741: &start_data_table().&start_data_table_row().
4742: '<td>'.&mt('No data.').'</td>'.
4743: &end_data_table_row().&end_data_table();
1.1 albertel 4744: }
1.10 albertel 4745: }
4746:
1.581 albertel 4747: sub format_previous_attempt_value {
4748: my ($key,$value) = @_;
1.1011 www 4749: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4750: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4751: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4752: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4753: } elsif ($key =~ /answerstring$/) {
4754: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4755: my @answer = %answers;
4756: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4757: my @anskeys = sort(keys(%answers));
4758: if (@anskeys == 1) {
4759: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4760: if ($answer =~ m{\0}) {
4761: $answer =~ s{\0}{,}g;
1.988 raeburn 4762: }
4763: my $tag_internal_answer_name = 'INTERNAL';
4764: if ($anskeys[0] eq $tag_internal_answer_name) {
4765: $value = $answer;
4766: } else {
4767: $value = $anskeys[0].'='.$answer;
4768: }
4769: } else {
4770: foreach my $ans (@anskeys) {
4771: my $answer = $answers{$ans};
1.1001 raeburn 4772: if ($answer =~ m{\0}) {
4773: $answer =~ s{\0}{,}g;
1.988 raeburn 4774: }
4775: $value .= $ans.'='.$answer.'<br />';;
4776: }
4777: }
1.581 albertel 4778: } else {
1.1173 kruse 4779: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4780: }
4781: return $value;
4782: }
4783:
4784:
1.107 albertel 4785: sub relative_to_absolute {
4786: my ($url,$output)=@_;
4787: my $parser=HTML::TokeParser->new(\$output);
4788: my $token;
4789: my $thisdir=$url;
4790: my @rlinks=();
4791: while ($token=$parser->get_token) {
4792: if ($token->[0] eq 'S') {
4793: if ($token->[1] eq 'a') {
4794: if ($token->[2]->{'href'}) {
4795: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4796: }
4797: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4798: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4799: } elsif ($token->[1] eq 'base') {
4800: $thisdir=$token->[2]->{'href'};
4801: }
4802: }
4803: }
4804: $thisdir=~s-/[^/]*$--;
1.356 albertel 4805: foreach my $link (@rlinks) {
1.726 raeburn 4806: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4807: ($link=~/^\//) ||
4808: ($link=~/^javascript:/i) ||
4809: ($link=~/^mailto:/i) ||
4810: ($link=~/^\#/)) {
4811: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4812: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4813: }
4814: }
4815: # -------------------------------------------------- Deal with Applet codebases
4816: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4817: return $output;
4818: }
4819:
1.112 bowersj2 4820: =pod
4821:
1.648 raeburn 4822: =item * &get_student_view()
1.112 bowersj2 4823:
4824: show a snapshot of what student was looking at
4825:
4826: =cut
4827:
1.10 albertel 4828: sub get_student_view {
1.186 albertel 4829: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4830: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4831: my (%form);
1.10 albertel 4832: my @elements=('symb','courseid','domain','username');
4833: foreach my $element (@elements) {
1.186 albertel 4834: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4835: }
1.186 albertel 4836: if (defined($moreenv)) {
4837: %form=(%form,%{$moreenv});
4838: }
1.236 albertel 4839: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4840: $feedurl=&Apache::lonnet::clutter($feedurl);
1.1306 raeburn 4841: if (($feedurl =~ /ext\.tool$/) && ($target eq 'tex')) {
4842: $feedurl =~ s{^/adm/wrapper}{};
4843: }
1.650 www 4844: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4845: $userview=~s/\<body[^\>]*\>//gi;
4846: $userview=~s/\<\/body\>//gi;
4847: $userview=~s/\<html\>//gi;
4848: $userview=~s/\<\/html\>//gi;
4849: $userview=~s/\<head\>//gi;
4850: $userview=~s/\<\/head\>//gi;
4851: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4852: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4853: if (wantarray) {
4854: return ($userview,$response);
4855: } else {
4856: return $userview;
4857: }
4858: }
4859:
4860: sub get_student_view_with_retries {
4861: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4862:
4863: my $ok = 0; # True if we got a good response.
4864: my $content;
4865: my $response;
4866:
4867: # Try to get the student_view done. within the retries count:
4868:
4869: do {
4870: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4871: $ok = $response->is_success;
4872: if (!$ok) {
4873: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4874: }
4875: $retries--;
4876: } while (!$ok && ($retries > 0));
4877:
4878: if (!$ok) {
4879: $content = ''; # On error return an empty content.
4880: }
1.651 www 4881: if (wantarray) {
4882: return ($content, $response);
4883: } else {
4884: return $content;
4885: }
1.11 albertel 4886: }
4887:
1.112 bowersj2 4888: =pod
4889:
1.648 raeburn 4890: =item * &get_student_answers()
1.112 bowersj2 4891:
4892: show a snapshot of how student was answering problem
4893:
4894: =cut
4895:
1.11 albertel 4896: sub get_student_answers {
1.100 sakharuk 4897: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4898: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4899: my (%moreenv);
1.11 albertel 4900: my @elements=('symb','courseid','domain','username');
4901: foreach my $element (@elements) {
1.186 albertel 4902: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4903: }
1.186 albertel 4904: $moreenv{'grade_target'}='answer';
4905: %moreenv=(%form,%moreenv);
1.497 raeburn 4906: $feedurl = &Apache::lonnet::clutter($feedurl);
4907: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4908: return $userview;
1.1 albertel 4909: }
1.116 albertel 4910:
4911: =pod
4912:
4913: =item * &submlink()
4914:
1.242 albertel 4915: Inputs: $text $uname $udom $symb $target
1.116 albertel 4916:
4917: Returns: A link to grades.pm such as to see the SUBM view of a student
4918:
4919: =cut
4920:
4921: ###############################################
4922: sub submlink {
1.242 albertel 4923: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4924: if (!($uname && $udom)) {
4925: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4926: &Apache::lonnet::whichuser($symb);
1.116 albertel 4927: if (!$symb) { $symb=$cursymb; }
4928: }
1.254 matthew 4929: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4930: $symb=&escape($symb);
1.960 bisitz 4931: if ($target) { $target=" target=\"$target\""; }
4932: return
4933: '<a href="/adm/grades?command=submission'.
4934: '&symb='.$symb.
4935: '&student='.$uname.
4936: '&userdom='.$udom.'"'.
4937: $target.'>'.$text.'</a>';
1.242 albertel 4938: }
4939: ##############################################
4940:
4941: =pod
4942:
4943: =item * &pgrdlink()
4944:
4945: Inputs: $text $uname $udom $symb $target
4946:
4947: Returns: A link to grades.pm such as to see the PGRD view of a student
4948:
4949: =cut
4950:
4951: ###############################################
4952: sub pgrdlink {
4953: my $link=&submlink(@_);
4954: $link=~s/(&command=submission)/$1&showgrading=yes/;
4955: return $link;
4956: }
4957: ##############################################
4958:
4959: =pod
4960:
4961: =item * &pprmlink()
4962:
4963: Inputs: $text $uname $udom $symb $target
4964:
4965: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4966: student and a specific resource
1.242 albertel 4967:
4968: =cut
4969:
4970: ###############################################
4971: sub pprmlink {
4972: my ($text,$uname,$udom,$symb,$target)=@_;
4973: if (!($uname && $udom)) {
4974: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4975: &Apache::lonnet::whichuser($symb);
1.242 albertel 4976: if (!$symb) { $symb=$cursymb; }
4977: }
1.254 matthew 4978: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4979: $symb=&escape($symb);
1.242 albertel 4980: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4981: return '<a href="/adm/parmset?command=set&'.
4982: 'symb='.$symb.'&uname='.$uname.
4983: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4984: }
4985: ##############################################
1.37 matthew 4986:
1.112 bowersj2 4987: =pod
4988:
4989: =back
4990:
4991: =cut
4992:
1.37 matthew 4993: ###############################################
1.51 www 4994:
4995:
4996: sub timehash {
1.687 raeburn 4997: my ($thistime) = @_;
4998: my $timezone = &Apache::lonlocal::gettimezone();
4999: my $dt = DateTime->from_epoch(epoch => $thistime)
5000: ->set_time_zone($timezone);
5001: my $wday = $dt->day_of_week();
5002: if ($wday == 7) { $wday = 0; }
5003: return ( 'second' => $dt->second(),
5004: 'minute' => $dt->minute(),
5005: 'hour' => $dt->hour(),
5006: 'day' => $dt->day_of_month(),
5007: 'month' => $dt->month(),
5008: 'year' => $dt->year(),
5009: 'weekday' => $wday,
5010: 'dayyear' => $dt->day_of_year(),
5011: 'dlsav' => $dt->is_dst() );
1.51 www 5012: }
5013:
1.370 www 5014: sub utc_string {
5015: my ($date)=@_;
1.371 www 5016: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 5017: }
5018:
1.51 www 5019: sub maketime {
5020: my %th=@_;
1.687 raeburn 5021: my ($epoch_time,$timezone,$dt);
5022: $timezone = &Apache::lonlocal::gettimezone();
5023: eval {
5024: $dt = DateTime->new( year => $th{'year'},
5025: month => $th{'month'},
5026: day => $th{'day'},
5027: hour => $th{'hour'},
5028: minute => $th{'minute'},
5029: second => $th{'second'},
5030: time_zone => $timezone,
5031: );
5032: };
5033: if (!$@) {
5034: $epoch_time = $dt->epoch;
5035: if ($epoch_time) {
5036: return $epoch_time;
5037: }
5038: }
1.51 www 5039: return POSIX::mktime(
5040: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 5041: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 5042: }
5043:
5044: #########################################
1.51 www 5045:
5046: sub findallcourses {
1.482 raeburn 5047: my ($roles,$uname,$udom) = @_;
1.355 albertel 5048: my %roles;
5049: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 5050: my %courses;
1.51 www 5051: my $now=time;
1.482 raeburn 5052: if (!defined($uname)) {
5053: $uname = $env{'user.name'};
5054: }
5055: if (!defined($udom)) {
5056: $udom = $env{'user.domain'};
5057: }
5058: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 5059: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 5060: if (!%roles) {
5061: %roles = (
5062: cc => 1,
1.907 raeburn 5063: co => 1,
1.482 raeburn 5064: in => 1,
5065: ep => 1,
5066: ta => 1,
5067: cr => 1,
5068: st => 1,
5069: );
5070: }
5071: foreach my $entry (keys(%roleshash)) {
5072: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
5073: if ($trole =~ /^cr/) {
5074: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
5075: } else {
5076: next if (!exists($roles{$trole}));
5077: }
5078: if ($tend) {
5079: next if ($tend < $now);
5080: }
5081: if ($tstart) {
5082: next if ($tstart > $now);
5083: }
1.1058 raeburn 5084: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 5085: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5086: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5087: if ($secpart eq '') {
5088: ($cnum,$role) = split(/_/,$cnumpart);
5089: $sec = 'none';
1.1058 raeburn 5090: $value .= $cnum.'/';
1.482 raeburn 5091: } else {
5092: $cnum = $cnumpart;
5093: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5094: $value .= $cnum.'/'.$sec;
5095: }
5096: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5097: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5098: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5099: }
5100: } else {
5101: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5102: }
1.482 raeburn 5103: }
5104: } else {
5105: foreach my $key (keys(%env)) {
1.483 albertel 5106: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5107: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5108: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5109: next if ($role eq 'ca' || $role eq 'aa');
5110: next if (%roles && !exists($roles{$role}));
5111: my ($starttime,$endtime)=split(/\./,$env{$key});
5112: my $active=1;
5113: if ($starttime) {
5114: if ($now<$starttime) { $active=0; }
5115: }
5116: if ($endtime) {
5117: if ($now>$endtime) { $active=0; }
5118: }
5119: if ($active) {
1.1058 raeburn 5120: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5121: if ($sec eq '') {
5122: $sec = 'none';
1.1058 raeburn 5123: } else {
5124: $value .= $sec;
5125: }
5126: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5127: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5128: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5129: }
5130: } else {
5131: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5132: }
1.474 raeburn 5133: }
5134: }
1.51 www 5135: }
5136: }
1.474 raeburn 5137: return %courses;
1.51 www 5138: }
1.37 matthew 5139:
1.54 www 5140: ###############################################
1.474 raeburn 5141:
5142: sub blockcheck {
1.1189 raeburn 5143: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 5144:
1.1189 raeburn 5145: if (defined($udom) && defined($uname)) {
5146: # If uname and udom are for a course, check for blocks in the course.
5147: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5148: my ($startblock,$endblock,$triggerblock) =
5149: &get_blocks($setters,$activity,$udom,$uname,$url);
5150: return ($startblock,$endblock,$triggerblock);
5151: }
5152: } else {
1.490 raeburn 5153: $udom = $env{'user.domain'};
5154: $uname = $env{'user.name'};
5155: }
5156:
1.502 raeburn 5157: my $startblock = 0;
5158: my $endblock = 0;
1.1062 raeburn 5159: my $triggerblock = '';
1.482 raeburn 5160: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 5161:
1.490 raeburn 5162: # If uname is for a user, and activity is course-specific, i.e.,
5163: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5164:
1.490 raeburn 5165: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 5166: $activity eq 'groups' || $activity eq 'printout' ||
5167: $activity eq 'reinit' || $activity eq 'alert') &&
1.1189 raeburn 5168: ($env{'request.course.id'})) {
1.490 raeburn 5169: foreach my $key (keys(%live_courses)) {
5170: if ($key ne $env{'request.course.id'}) {
5171: delete($live_courses{$key});
5172: }
5173: }
5174: }
5175:
5176: my $otheruser = 0;
5177: my %own_courses;
5178: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5179: # Resource belongs to user other than current user.
5180: $otheruser = 1;
5181: # Gather courses for current user
5182: %own_courses =
5183: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5184: }
5185:
5186: # Gather active course roles - course coordinator, instructor,
5187: # exam proctor, ta, student, or custom role.
1.474 raeburn 5188:
5189: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5190: my ($cdom,$cnum);
5191: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5192: $cdom = $env{'course.'.$course.'.domain'};
5193: $cnum = $env{'course.'.$course.'.num'};
5194: } else {
1.490 raeburn 5195: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5196: }
5197: my $no_ownblock = 0;
5198: my $no_userblock = 0;
1.533 raeburn 5199: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5200: # Check if current user has 'evb' priv for this
5201: if (defined($own_courses{$course})) {
5202: foreach my $sec (keys(%{$own_courses{$course}})) {
5203: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5204: if ($sec ne 'none') {
5205: $checkrole .= '/'.$sec;
5206: }
5207: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5208: $no_ownblock = 1;
5209: last;
5210: }
5211: }
5212: }
5213: # if they have 'evb' priv and are currently not playing student
5214: next if (($no_ownblock) &&
5215: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5216: }
1.474 raeburn 5217: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5218: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5219: if ($sec ne 'none') {
1.482 raeburn 5220: $checkrole .= '/'.$sec;
1.474 raeburn 5221: }
1.490 raeburn 5222: if ($otheruser) {
5223: # Resource belongs to user other than current user.
5224: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5225: my (%allroles,%userroles);
5226: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5227: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5228: my ($trole,$tdom,$tnum,$tsec);
5229: if ($entry =~ /^cr/) {
5230: ($trole,$tdom,$tnum,$tsec) =
5231: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5232: } else {
5233: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5234: }
5235: my ($spec,$area,$trest);
5236: $area = '/'.$tdom.'/'.$tnum;
5237: $trest = $tnum;
5238: if ($tsec ne '') {
5239: $area .= '/'.$tsec;
5240: $trest .= '/'.$tsec;
5241: }
5242: $spec = $trole.'.'.$area;
5243: if ($trole =~ /^cr/) {
5244: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5245: $tdom,$spec,$trest,$area);
5246: } else {
5247: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5248: $tdom,$spec,$trest,$area);
5249: }
5250: }
1.1276 raeburn 5251: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5252: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5253: if ($1) {
5254: $no_userblock = 1;
5255: last;
5256: }
1.486 raeburn 5257: }
5258: }
1.490 raeburn 5259: } else {
5260: # Resource belongs to current user
5261: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5262: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5263: $no_ownblock = 1;
5264: last;
5265: }
1.474 raeburn 5266: }
5267: }
5268: # if they have the evb priv and are currently not playing student
1.482 raeburn 5269: next if (($no_ownblock) &&
1.491 albertel 5270: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5271: next if ($no_userblock);
1.474 raeburn 5272:
1.1303 raeburn 5273: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5274: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5275:
1.1062 raeburn 5276: my ($start,$end,$trigger) =
5277: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 5278: if (($start != 0) &&
5279: (($startblock == 0) || ($startblock > $start))) {
5280: $startblock = $start;
1.1062 raeburn 5281: if ($trigger ne '') {
5282: $triggerblock = $trigger;
5283: }
1.502 raeburn 5284: }
5285: if (($end != 0) &&
5286: (($endblock == 0) || ($endblock < $end))) {
5287: $endblock = $end;
1.1062 raeburn 5288: if ($trigger ne '') {
5289: $triggerblock = $trigger;
5290: }
1.502 raeburn 5291: }
1.490 raeburn 5292: }
1.1062 raeburn 5293: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5294: }
5295:
5296: sub get_blocks {
1.1062 raeburn 5297: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 5298: my $startblock = 0;
5299: my $endblock = 0;
1.1062 raeburn 5300: my $triggerblock = '';
1.490 raeburn 5301: my $course = $cdom.'_'.$cnum;
5302: $setters->{$course} = {};
5303: $setters->{$course}{'staff'} = [];
5304: $setters->{$course}{'times'} = [];
1.1062 raeburn 5305: $setters->{$course}{'triggers'} = [];
5306: my (@blockers,%triggered);
5307: my $now = time;
5308: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5309: if ($activity eq 'docs') {
5310: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
5311: foreach my $block (@blockers) {
5312: if ($block =~ /^firstaccess____(.+)$/) {
5313: my $item = $1;
5314: my $type = 'map';
5315: my $timersymb = $item;
5316: if ($item eq 'course') {
5317: $type = 'course';
5318: } elsif ($item =~ /___\d+___/) {
5319: $type = 'resource';
5320: } else {
5321: $timersymb = &Apache::lonnet::symbread($item);
5322: }
5323: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5324: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5325: $triggered{$block} = {
5326: start => $start,
5327: end => $end,
5328: type => $type,
5329: };
5330: }
5331: }
5332: } else {
5333: foreach my $block (keys(%commblocks)) {
5334: if ($block =~ m/^(\d+)____(\d+)$/) {
5335: my ($start,$end) = ($1,$2);
5336: if ($start <= time && $end >= time) {
5337: if (ref($commblocks{$block}) eq 'HASH') {
5338: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5339: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5340: unless(grep(/^\Q$block\E$/,@blockers)) {
5341: push(@blockers,$block);
5342: }
5343: }
5344: }
5345: }
5346: }
5347: } elsif ($block =~ /^firstaccess____(.+)$/) {
5348: my $item = $1;
5349: my $timersymb = $item;
5350: my $type = 'map';
5351: if ($item eq 'course') {
5352: $type = 'course';
5353: } elsif ($item =~ /___\d+___/) {
5354: $type = 'resource';
5355: } else {
5356: $timersymb = &Apache::lonnet::symbread($item);
5357: }
5358: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5359: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5360: if ($start && $end) {
5361: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 5362: if (ref($commblocks{$block}) eq 'HASH') {
5363: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5364: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5365: unless(grep(/^\Q$block\E$/,@blockers)) {
5366: push(@blockers,$block);
5367: $triggered{$block} = {
5368: start => $start,
5369: end => $end,
5370: type => $type,
5371: };
5372: }
5373: }
5374: }
1.1062 raeburn 5375: }
5376: }
1.490 raeburn 5377: }
1.1062 raeburn 5378: }
5379: }
5380: }
5381: foreach my $blocker (@blockers) {
5382: my ($staff_name,$staff_dom,$title,$blocks) =
5383: &parse_block_record($commblocks{$blocker});
5384: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5385: my ($start,$end,$triggertype);
5386: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5387: ($start,$end) = ($1,$2);
5388: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5389: $start = $triggered{$blocker}{'start'};
5390: $end = $triggered{$blocker}{'end'};
5391: $triggertype = $triggered{$blocker}{'type'};
5392: }
5393: if ($start) {
5394: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5395: if ($triggertype) {
5396: push(@{$$setters{$course}{'triggers'}},$triggertype);
5397: } else {
5398: push(@{$$setters{$course}{'triggers'}},0);
5399: }
5400: if ( ($startblock == 0) || ($startblock > $start) ) {
5401: $startblock = $start;
5402: if ($triggertype) {
5403: $triggerblock = $blocker;
1.474 raeburn 5404: }
5405: }
1.1062 raeburn 5406: if ( ($endblock == 0) || ($endblock < $end) ) {
5407: $endblock = $end;
5408: if ($triggertype) {
5409: $triggerblock = $blocker;
5410: }
5411: }
1.474 raeburn 5412: }
5413: }
1.1062 raeburn 5414: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5415: }
5416:
5417: sub parse_block_record {
5418: my ($record) = @_;
5419: my ($setuname,$setudom,$title,$blocks);
5420: if (ref($record) eq 'HASH') {
5421: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5422: $title = &unescape($record->{'event'});
5423: $blocks = $record->{'blocks'};
5424: } else {
5425: my @data = split(/:/,$record,3);
5426: if (scalar(@data) eq 2) {
5427: $title = $data[1];
5428: ($setuname,$setudom) = split(/@/,$data[0]);
5429: } else {
5430: ($setuname,$setudom,$title) = @data;
5431: }
5432: $blocks = { 'com' => 'on' };
5433: }
5434: return ($setuname,$setudom,$title,$blocks);
5435: }
5436:
1.854 kalberla 5437: sub blocking_status {
1.1189 raeburn 5438: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 5439: my %setters;
1.890 droeschl 5440:
1.1061 raeburn 5441: # check for active blocking
1.1062 raeburn 5442: my ($startblock,$endblock,$triggerblock) =
1.1189 raeburn 5443: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 5444: my $blocked = 0;
5445: if ($startblock && $endblock) {
5446: $blocked = 1;
5447: }
1.890 droeschl 5448:
1.1061 raeburn 5449: # caller just wants to know whether a block is active
5450: if (!wantarray) { return $blocked; }
5451:
5452: # build a link to a popup window containing the details
5453: my $querystring = "?activity=$activity";
5454: # $uname and $udom decide whose portfolio the user is trying to look at
1.1232 raeburn 5455: if (($activity eq 'port') || ($activity eq 'passwd')) {
5456: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5457: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5458: } elsif ($activity eq 'docs') {
5459: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
5460: }
1.1061 raeburn 5461:
5462: my $output .= <<'END_MYBLOCK';
5463: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5464: var options = "width=" + w + ",height=" + h + ",";
5465: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5466: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5467: var newWin = window.open(url, wdwName, options);
5468: newWin.focus();
5469: }
1.890 droeschl 5470: END_MYBLOCK
1.854 kalberla 5471:
1.1061 raeburn 5472: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5473:
1.1061 raeburn 5474: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5475: my $text = &mt('Communication Blocked');
1.1217 raeburn 5476: my $class = 'LC_comblock';
1.1062 raeburn 5477: if ($activity eq 'docs') {
5478: $text = &mt('Content Access Blocked');
1.1217 raeburn 5479: $class = '';
1.1063 raeburn 5480: } elsif ($activity eq 'printout') {
5481: $text = &mt('Printing Blocked');
1.1232 raeburn 5482: } elsif ($activity eq 'passwd') {
5483: $text = &mt('Password Changing Blocked');
1.1282 raeburn 5484: } elsif ($activity eq 'alert') {
5485: $text = &mt('Checking Critical Messages Blocked');
5486: } elsif ($activity eq 'reinit') {
5487: $text = &mt('Checking Course Update Blocked');
1.1062 raeburn 5488: }
1.1061 raeburn 5489: $output .= <<"END_BLOCK";
1.1217 raeburn 5490: <div class='$class'>
1.869 kalberla 5491: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5492: title='$text'>
5493: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5494: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5495: title='$text'>$text</a>
1.867 kalberla 5496: </div>
5497:
5498: END_BLOCK
1.474 raeburn 5499:
1.1061 raeburn 5500: return ($blocked, $output);
1.854 kalberla 5501: }
1.490 raeburn 5502:
1.60 matthew 5503: ###############################################
5504:
1.682 raeburn 5505: sub check_ip_acc {
1.1201 raeburn 5506: my ($acc,$clientip)=@_;
1.682 raeburn 5507: &Apache::lonxml::debug("acc is $acc");
5508: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5509: return 1;
5510: }
1.1219 raeburn 5511: my $allowed;
1.1252 raeburn 5512: my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
1.682 raeburn 5513:
5514: my $name;
1.1219 raeburn 5515: my %access = (
5516: allowfrom => 1,
5517: denyfrom => 0,
5518: );
5519: my @allows;
5520: my @denies;
5521: foreach my $item (split(',',$acc)) {
5522: $item =~ s/^\s*//;
5523: $item =~ s/\s*$//;
5524: my $pattern;
5525: if ($item =~ /^\!(.+)$/) {
5526: push(@denies,$1);
5527: } else {
5528: push(@allows,$item);
5529: }
5530: }
5531: my $numdenies = scalar(@denies);
5532: my $numallows = scalar(@allows);
5533: my $count = 0;
5534: foreach my $pattern (@denies,@allows) {
5535: $count ++;
5536: my $acctype = 'allowfrom';
5537: if ($count <= $numdenies) {
5538: $acctype = 'denyfrom';
5539: }
1.682 raeburn 5540: if ($pattern =~ /\*$/) {
5541: #35.8.*
5542: $pattern=~s/\*//;
1.1219 raeburn 5543: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5544: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5545: #35.8.3.[34-56]
5546: my $low=$2;
5547: my $high=$3;
5548: $pattern=$1;
5549: if ($ip =~ /^\Q$pattern\E/) {
5550: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5551: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5552: }
5553: } elsif ($pattern =~ /^\*/) {
5554: #*.msu.edu
5555: $pattern=~s/\*//;
5556: if (!defined($name)) {
5557: use Socket;
5558: my $netaddr=inet_aton($ip);
5559: ($name)=gethostbyaddr($netaddr,AF_INET);
5560: }
1.1219 raeburn 5561: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5562: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5563: #127.0.0.1
1.1219 raeburn 5564: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5565: } else {
5566: #some.name.com
5567: if (!defined($name)) {
5568: use Socket;
5569: my $netaddr=inet_aton($ip);
5570: ($name)=gethostbyaddr($netaddr,AF_INET);
5571: }
1.1219 raeburn 5572: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5573: }
5574: if ($allowed =~ /^(0|1)$/) { last; }
5575: }
5576: if ($allowed eq '') {
5577: if ($numdenies && !$numallows) {
5578: $allowed = 1;
5579: } else {
5580: $allowed = 0;
1.682 raeburn 5581: }
5582: }
5583: return $allowed;
5584: }
5585:
5586: ###############################################
5587:
1.60 matthew 5588: =pod
5589:
1.112 bowersj2 5590: =head1 Domain Template Functions
5591:
5592: =over 4
5593:
5594: =item * &determinedomain()
1.60 matthew 5595:
5596: Inputs: $domain (usually will be undef)
5597:
1.63 www 5598: Returns: Determines which domain should be used for designs
1.60 matthew 5599:
5600: =cut
1.54 www 5601:
1.60 matthew 5602: ###############################################
1.63 www 5603: sub determinedomain {
5604: my $domain=shift;
1.531 albertel 5605: if (! $domain) {
1.60 matthew 5606: # Determine domain if we have not been given one
1.893 raeburn 5607: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5608: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5609: if ($env{'request.role.domain'}) {
5610: $domain=$env{'request.role.domain'};
1.60 matthew 5611: }
5612: }
1.63 www 5613: return $domain;
5614: }
5615: ###############################################
1.517 raeburn 5616:
1.518 albertel 5617: sub devalidate_domconfig_cache {
5618: my ($udom)=@_;
5619: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5620: }
5621:
5622: # ---------------------- Get domain configuration for a domain
5623: sub get_domainconf {
5624: my ($udom) = @_;
5625: my $cachetime=1800;
5626: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5627: if (defined($cached)) { return %{$result}; }
5628:
5629: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5630: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5631: my (%designhash,%legacy);
1.518 albertel 5632: if (keys(%domconfig) > 0) {
5633: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5634: if (keys(%{$domconfig{'login'}})) {
5635: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5636: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5637: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5638: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5639: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5640: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5641: if ($key eq 'loginvia') {
5642: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5643: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5644: $designhash{$udom.'.login.loginvia'} = $server;
5645: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5646:
5647: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5648: } else {
5649: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5650: }
1.948 raeburn 5651: }
1.1208 raeburn 5652: } elsif ($key eq 'headtag') {
5653: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5654: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5655: }
1.946 raeburn 5656: }
1.1208 raeburn 5657: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5658: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5659: }
1.946 raeburn 5660: }
5661: }
5662: }
5663: } else {
5664: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5665: $designhash{$udom.'.login.'.$key.'_'.$img} =
5666: $domconfig{'login'}{$key}{$img};
5667: }
1.699 raeburn 5668: }
5669: } else {
5670: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5671: }
1.632 raeburn 5672: }
5673: } else {
5674: $legacy{'login'} = 1;
1.518 albertel 5675: }
1.632 raeburn 5676: } else {
5677: $legacy{'login'} = 1;
1.518 albertel 5678: }
5679: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5680: if (keys(%{$domconfig{'rolecolors'}})) {
5681: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5682: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5683: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5684: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5685: }
1.518 albertel 5686: }
5687: }
1.632 raeburn 5688: } else {
5689: $legacy{'rolecolors'} = 1;
1.518 albertel 5690: }
1.632 raeburn 5691: } else {
5692: $legacy{'rolecolors'} = 1;
1.518 albertel 5693: }
1.948 raeburn 5694: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5695: if ($domconfig{'autoenroll'}{'co-owners'}) {
5696: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5697: }
5698: }
1.632 raeburn 5699: if (keys(%legacy) > 0) {
5700: my %legacyhash = &get_legacy_domconf($udom);
5701: foreach my $item (keys(%legacyhash)) {
5702: if ($item =~ /^\Q$udom\E\.login/) {
5703: if ($legacy{'login'}) {
5704: $designhash{$item} = $legacyhash{$item};
5705: }
5706: } else {
5707: if ($legacy{'rolecolors'}) {
5708: $designhash{$item} = $legacyhash{$item};
5709: }
1.518 albertel 5710: }
5711: }
5712: }
1.632 raeburn 5713: } else {
5714: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5715: }
5716: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5717: $cachetime);
5718: return %designhash;
5719: }
5720:
1.632 raeburn 5721: sub get_legacy_domconf {
5722: my ($udom) = @_;
5723: my %legacyhash;
5724: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5725: my $designfile = $designdir.'/'.$udom.'.tab';
5726: if (-e $designfile) {
1.1317 raeburn 5727: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5728: while (my $line = <$fh>) {
5729: next if ($line =~ /^\#/);
5730: chomp($line);
5731: my ($key,$val)=(split(/\=/,$line));
5732: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5733: }
5734: close($fh);
5735: }
5736: }
1.1026 raeburn 5737: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5738: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5739: }
5740: return %legacyhash;
5741: }
5742:
1.63 www 5743: =pod
5744:
1.112 bowersj2 5745: =item * &domainlogo()
1.63 www 5746:
5747: Inputs: $domain (usually will be undef)
5748:
5749: Returns: A link to a domain logo, if the domain logo exists.
5750: If the domain logo does not exist, a description of the domain.
5751:
5752: =cut
1.112 bowersj2 5753:
1.63 www 5754: ###############################################
5755: sub domainlogo {
1.517 raeburn 5756: my $domain = &determinedomain(shift);
1.518 albertel 5757: my %designhash = &get_domainconf($domain);
1.517 raeburn 5758: # See if there is a logo
5759: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5760: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5761: if ($imgsrc =~ m{^/(adm|res)/}) {
5762: if ($imgsrc =~ m{^/res/}) {
5763: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5764: &Apache::lonnet::repcopy($local_name);
5765: }
5766: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5767: }
5768: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5769: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5770: return &Apache::lonnet::domain($domain,'description');
1.59 www 5771: } else {
1.60 matthew 5772: return '';
1.59 www 5773: }
5774: }
1.63 www 5775: ##############################################
5776:
5777: =pod
5778:
1.112 bowersj2 5779: =item * &designparm()
1.63 www 5780:
5781: Inputs: $which parameter; $domain (usually will be undef)
5782:
5783: Returns: value of designparamter $which
5784:
5785: =cut
1.112 bowersj2 5786:
1.397 albertel 5787:
1.400 albertel 5788: ##############################################
1.397 albertel 5789: sub designparm {
5790: my ($which,$domain)=@_;
5791: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5792: return $env{'environment.color.'.$which};
1.96 www 5793: }
1.63 www 5794: $domain=&determinedomain($domain);
1.1016 raeburn 5795: my %domdesign;
5796: unless ($domain eq 'public') {
5797: %domdesign = &get_domainconf($domain);
5798: }
1.520 raeburn 5799: my $output;
1.517 raeburn 5800: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5801: $output = $domdesign{$domain.'.'.$which};
1.63 www 5802: } else {
1.520 raeburn 5803: $output = $defaultdesign{$which};
5804: }
5805: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5806: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5807: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5808: if ($output =~ m{^/res/}) {
5809: my $local_name = &Apache::lonnet::filelocation('',$output);
5810: &Apache::lonnet::repcopy($local_name);
5811: }
1.520 raeburn 5812: $output = &lonhttpdurl($output);
5813: }
1.63 www 5814: }
1.520 raeburn 5815: return $output;
1.63 www 5816: }
1.59 www 5817:
1.822 bisitz 5818: ##############################################
5819: =pod
5820:
1.832 bisitz 5821: =item * &authorspace()
5822:
1.1028 raeburn 5823: Inputs: $url (usually will be undef).
1.832 bisitz 5824:
1.1132 raeburn 5825: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5826: directory being viewed (or for which action is being taken).
5827: If $url is provided, and begins /priv/<domain>/<uname>
5828: the path will be that portion of the $context argument.
5829: Otherwise the path will be for the author space of the current
5830: user when the current role is author, or for that of the
5831: co-author/assistant co-author space when the current role
5832: is co-author or assistant co-author.
1.832 bisitz 5833:
5834: =cut
5835:
5836: sub authorspace {
1.1028 raeburn 5837: my ($url) = @_;
5838: if ($url ne '') {
5839: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5840: return $1;
5841: }
5842: }
1.832 bisitz 5843: my $caname = '';
1.1024 www 5844: my $cadom = '';
1.1028 raeburn 5845: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5846: ($cadom,$caname) =
1.832 bisitz 5847: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5848: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5849: $caname = $env{'user.name'};
1.1024 www 5850: $cadom = $env{'user.domain'};
1.832 bisitz 5851: }
1.1028 raeburn 5852: if (($caname ne '') && ($cadom ne '')) {
5853: return "/priv/$cadom/$caname/";
5854: }
5855: return;
1.832 bisitz 5856: }
5857:
5858: ##############################################
5859: =pod
5860:
1.822 bisitz 5861: =item * &head_subbox()
5862:
5863: Inputs: $content (contains HTML code with page functions, etc.)
5864:
5865: Returns: HTML div with $content
5866: To be included in page header
5867:
5868: =cut
5869:
5870: sub head_subbox {
5871: my ($content)=@_;
5872: my $output =
1.993 raeburn 5873: '<div class="LC_head_subbox">'
1.822 bisitz 5874: .$content
5875: .'</div>'
5876: }
5877:
5878: ##############################################
5879: =pod
5880:
5881: =item * &CSTR_pageheader()
5882:
1.1026 raeburn 5883: Input: (optional) filename from which breadcrumb trail is built.
5884: In most cases no input as needed, as $env{'request.filename'}
5885: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5886:
5887: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5888: To be included on Authoring Space pages
1.822 bisitz 5889:
5890: =cut
5891:
5892: sub CSTR_pageheader {
1.1026 raeburn 5893: my ($trailfile) = @_;
5894: if ($trailfile eq '') {
5895: $trailfile = $env{'request.filename'};
5896: }
5897:
5898: # this is for resources; directories have customtitle, and crumbs
5899: # and select recent are created in lonpubdir.pm
5900:
5901: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5902: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5903: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5904: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5905: $formaction =~ s{/+}{/}g;
1.822 bisitz 5906:
5907: my $parentpath = '';
5908: my $lastitem = '';
5909: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5910: $parentpath = $1;
5911: $lastitem = $2;
5912: } else {
5913: $lastitem = $thisdisfn;
5914: }
1.921 bisitz 5915:
1.1246 raeburn 5916: my ($crsauthor,$title);
5917: if (($env{'request.course.id'}) &&
5918: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 5919: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 5920: $crsauthor = 1;
5921: $title = &mt('Course Authoring Space');
5922: } else {
5923: $title = &mt('Authoring Space');
5924: }
5925:
1.1314 raeburn 5926: my ($target,$crumbtarget) = (' target="_top"','_top'); #FIXME lonpubdir: target="_parent"
1.1313 raeburn 5927: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1.1314 raeburn 5928: $target = '';
5929: $crumbtarget = '';
1.1313 raeburn 5930: }
5931:
1.921 bisitz 5932: my $output =
1.822 bisitz 5933: '<div>'
5934: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 5935: .'<b>'.$title.'</b> '
1.1314 raeburn 5936: .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
5937: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 5938:
5939: if ($lastitem) {
5940: $output .=
5941: '<span class="LC_filename">'
5942: .$lastitem
5943: .'</span>';
5944: }
1.1245 raeburn 5945:
1.1246 raeburn 5946: if ($crsauthor) {
5947: $output .= '</form>'.&Apache::lonmenu::constspaceform();
5948: } else {
5949: $output .=
5950: '<br />'
1.1314 raeburn 5951: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.1246 raeburn 5952: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5953: .'</form>'
5954: .&Apache::lonmenu::constspaceform();
5955: }
5956: $output .= '</div>';
1.921 bisitz 5957:
5958: return $output;
1.822 bisitz 5959: }
5960:
1.60 matthew 5961: ###############################################
5962: ###############################################
5963:
5964: =pod
5965:
1.112 bowersj2 5966: =back
5967:
1.549 albertel 5968: =head1 HTML Helpers
1.112 bowersj2 5969:
5970: =over 4
5971:
5972: =item * &bodytag()
1.60 matthew 5973:
5974: Returns a uniform header for LON-CAPA web pages.
5975:
5976: Inputs:
5977:
1.112 bowersj2 5978: =over 4
5979:
5980: =item * $title, A title to be displayed on the page.
5981:
5982: =item * $function, the current role (can be undef).
5983:
5984: =item * $addentries, extra parameters for the <body> tag.
5985:
5986: =item * $bodyonly, if defined, only return the <body> tag.
5987:
5988: =item * $domain, if defined, force a given domain.
5989:
5990: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5991: text interface only)
1.60 matthew 5992:
1.814 bisitz 5993: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5994: navigational links
1.317 albertel 5995:
1.338 albertel 5996: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5997:
1.460 albertel 5998: =item * $args, optional argument valid values are
5999: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 6000: use_absolute -> for external resource or syllabus, this will
6001: contain https://<hostname> if server uses
6002: https (as per hosts.tab), but request is for http
6003: hostname -> hostname, from $r->hostname().
1.460 albertel 6004:
1.1096 raeburn 6005: =item * $advtoolsref, optional argument, ref to an array containing
6006: inlineremote items to be added in "Functions" menu below
6007: breadcrumbs.
6008:
1.1316 raeburn 6009: =item * $ltiscope, optional argument, will be one of: resource, map or
6010: course, if LON-CAPA is in LTI Provider context. Value is
6011: the scope of use, i.e., launch was for access to a single, a map
6012: or the entire course.
6013:
6014: =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6015: context, this will contain the URL for the landing item in
6016: the course, after launch from an LTI Consumer
6017:
1.1318 raeburn 6018: =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6019: context, this will contain a reference to hash of items
6020: to be included in the page header and/or inline menu.
6021:
1.112 bowersj2 6022: =back
6023:
1.60 matthew 6024: Returns: A uniform header for LON-CAPA web pages.
6025: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6026: If $bodyonly is undef or zero, an html string containing a <body> tag and
6027: other decorations will be returned.
6028:
6029: =cut
6030:
1.54 www 6031: sub bodytag {
1.831 bisitz 6032: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1318 raeburn 6033: $no_nav_bar,$bgcolor,$args,$advtoolsref,$ltiscope,$ltiuri,$ltimenu)=@_;
1.339 albertel 6034:
1.954 raeburn 6035: my $public;
6036: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6037: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6038: $public = 1;
6039: }
1.460 albertel 6040: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 6041: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 6042: my $hostname = $args->{'hostname'};
1.339 albertel 6043:
1.183 matthew 6044: $function = &get_users_function() if (!$function);
1.339 albertel 6045: my $img = &designparm($function.'.img',$domain);
6046: my $font = &designparm($function.'.font',$domain);
6047: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6048:
1.803 bisitz 6049: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6050: 'bgcolor' => $pgbg,
1.339 albertel 6051: 'text' => $font,
6052: 'alink' => &designparm($function.'.alink',$domain),
6053: 'vlink' => &designparm($function.'.vlink',$domain),
6054: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6055: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6056:
1.63 www 6057: # role and realm
1.1178 raeburn 6058: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6059: if ($realm) {
6060: $realm = '/'.$realm;
6061: }
1.378 raeburn 6062: if ($role eq 'ca') {
1.479 albertel 6063: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6064: $realm = &plainname($rname,$rdom);
1.378 raeburn 6065: }
1.55 www 6066: # realm
1.258 albertel 6067: if ($env{'request.course.id'}) {
1.378 raeburn 6068: if ($env{'request.role'} !~ /^cr/) {
6069: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 6070: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 6071: if ($env{'request.role.desc'}) {
6072: $role = $env{'request.role.desc'};
6073: } else {
6074: $role = &mt('Helpdesk[_1]',' '.$2);
6075: }
1.1257 raeburn 6076: } else {
6077: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6078: }
1.898 raeburn 6079: if ($env{'request.course.sec'}) {
6080: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
6081: }
1.359 albertel 6082: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 6083: } else {
6084: $role = &Apache::lonnet::plaintext($role);
1.54 www 6085: }
1.433 albertel 6086:
1.359 albertel 6087: if (!$realm) { $realm=' '; }
1.330 albertel 6088:
1.438 albertel 6089: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6090:
1.101 www 6091: # construct main body tag
1.359 albertel 6092: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6093: &Apache::lontexconvert::init_math_support();
1.252 albertel 6094:
1.1131 raeburn 6095: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6096:
1.1130 raeburn 6097: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6098: return $bodytag;
1.1130 raeburn 6099: }
1.359 albertel 6100:
1.954 raeburn 6101: if ($public) {
1.433 albertel 6102: undef($role);
6103: }
1.1318 raeburn 6104:
6105: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
6106: if (ref($ltimenu) eq 'HASH') {
6107: unless ($ltimenu->{'role'}) {
6108: undef($role);
6109: }
6110: unless ($ltimenu->{'coursetitle'}) {
6111: $realm=' ';
6112: }
6113: }
6114: }
6115:
1.762 bisitz 6116: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6117: #
6118: # Extra info if you are the DC
6119: my $dc_info = '';
6120: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
6121: $env{'course.'.$env{'request.course.id'}.
6122: '.domain'}.'/'})) {
6123: my $cid = $env{'request.course.id'};
1.917 raeburn 6124: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6125: $dc_info =~ s/\s+$//;
1.359 albertel 6126: }
6127:
1.1237 raeburn 6128: my $crstype;
6129: if ($env{'request.course.id'}) {
6130: $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
6131: } elsif ($args->{'crstype'}) {
6132: $crstype = $args->{'crstype'};
6133: }
6134: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
6135: undef($role);
6136: } else {
1.1242 raeburn 6137: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 6138: }
1.853 droeschl 6139:
1.903 droeschl 6140: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6141:
6142: # if ($env{'request.state'} eq 'construct') {
6143: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6144: # }
6145:
1.1130 raeburn 6146: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 6147: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6148:
1.1318 raeburn 6149: unless ($args->{'no_primary_menu'}) {
6150: my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu);
1.359 albertel 6151:
1.1318 raeburn 6152: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6153: if ($dc_info) {
6154: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6155: }
6156: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6157: <em>$realm</em> $dc_info</div>|;
6158: return $bodytag;
6159: }
1.894 droeschl 6160:
1.1318 raeburn 6161: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6162: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6163: }
1.916 droeschl 6164:
1.1318 raeburn 6165: $bodytag .= $right;
1.852 droeschl 6166:
1.1318 raeburn 6167: if ($dc_info) {
6168: $dc_info = &dc_courseid_toggle($dc_info);
6169: }
6170: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6171: }
1.916 droeschl 6172:
1.1169 raeburn 6173: #if directed to not display the secondary menu, don't.
1.1168 raeburn 6174: if ($args->{'no_secondary_menu'}) {
6175: return $bodytag;
6176: }
1.1169 raeburn 6177: #don't show menus for public users
1.954 raeburn 6178: if (!$public){
1.1318 raeburn 6179: unless ($args->{'no_inline_menu'}) {
6180: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
6181: $args->{'no_primary_menu'});
6182: }
1.903 droeschl 6183: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6184: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6185: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6186: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1316 raeburn 6187: $args->{'bread_crumbs'},'','',$hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6188: } elsif ($forcereg) {
6189: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1258 raeburn 6190: $args->{'group'},
1.1274 raeburn 6191: $args->{'hide_buttons'},
1.1316 raeburn 6192: $hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6193: } else {
6194: $bodytag .=
6195: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6196: $forcereg,$args->{'group'},
6197: $args->{'bread_crumbs'},
1.1274 raeburn 6198: $advtoolsref,'',$hostname);
1.920 raeburn 6199: }
1.903 droeschl 6200: }else{
6201: # this is to seperate menu from content when there's no secondary
6202: # menu. Especially needed for public accessible ressources.
6203: $bodytag .= '<hr style="clear:both" />';
6204: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6205: }
1.903 droeschl 6206:
1.235 raeburn 6207: return $bodytag;
1.182 matthew 6208: }
6209:
1.917 raeburn 6210: sub dc_courseid_toggle {
6211: my ($dc_info) = @_;
1.980 raeburn 6212: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6213: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6214: &mt('(More ...)').'</a></span>'.
6215: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6216: }
6217:
1.330 albertel 6218: sub make_attr_string {
6219: my ($register,$attr_ref) = @_;
6220:
6221: if ($attr_ref && !ref($attr_ref)) {
6222: die("addentries Must be a hash ref ".
6223: join(':',caller(1))." ".
6224: join(':',caller(0))." ");
6225: }
6226:
6227: if ($register) {
1.339 albertel 6228: my ($on_load,$on_unload);
6229: foreach my $key (keys(%{$attr_ref})) {
6230: if (lc($key) eq 'onload') {
6231: $on_load.=$attr_ref->{$key}.';';
6232: delete($attr_ref->{$key});
6233:
6234: } elsif (lc($key) eq 'onunload') {
6235: $on_unload.=$attr_ref->{$key}.';';
6236: delete($attr_ref->{$key});
6237: }
6238: }
1.953 droeschl 6239: $attr_ref->{'onload'} = $on_load;
6240: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6241: }
1.339 albertel 6242:
1.330 albertel 6243: my $attr_string;
1.1159 raeburn 6244: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6245: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6246: }
6247: return $attr_string;
6248: }
6249:
6250:
1.182 matthew 6251: ###############################################
1.251 albertel 6252: ###############################################
6253:
6254: =pod
6255:
6256: =item * &endbodytag()
6257:
6258: Returns a uniform footer for LON-CAPA web pages.
6259:
1.635 raeburn 6260: Inputs: 1 - optional reference to an args hash
6261: If in the hash, key for noredirectlink has a value which evaluates to true,
6262: a 'Continue' link is not displayed if the page contains an
6263: internal redirect in the <head></head> section,
6264: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6265:
6266: =cut
6267:
6268: sub endbodytag {
1.635 raeburn 6269: my ($args) = @_;
1.1080 raeburn 6270: my $endbodytag;
6271: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6272: $endbodytag='</body>';
6273: }
1.315 albertel 6274: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6275: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6276: $endbodytag=
6277: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6278: &mt('Continue').'</a>'.
6279: $endbodytag;
6280: }
1.315 albertel 6281: }
1.251 albertel 6282: return $endbodytag;
6283: }
6284:
1.352 albertel 6285: =pod
6286:
6287: =item * &standard_css()
6288:
6289: Returns a style sheet
6290:
6291: Inputs: (all optional)
6292: domain -> force to color decorate a page for a specific
6293: domain
6294: function -> force usage of a specific rolish color scheme
6295: bgcolor -> override the default page bgcolor
6296:
6297: =cut
6298:
1.343 albertel 6299: sub standard_css {
1.345 albertel 6300: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6301: $function = &get_users_function() if (!$function);
6302: my $img = &designparm($function.'.img', $domain);
6303: my $tabbg = &designparm($function.'.tabbg', $domain);
6304: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6305: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6306: #second colour for later usage
1.345 albertel 6307: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6308: my $pgbg_or_bgcolor =
6309: $bgcolor ||
1.352 albertel 6310: &designparm($function.'.pgbg', $domain);
1.382 albertel 6311: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6312: my $alink = &designparm($function.'.alink', $domain);
6313: my $vlink = &designparm($function.'.vlink', $domain);
6314: my $link = &designparm($function.'.link', $domain);
6315:
1.602 albertel 6316: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6317: my $mono = 'monospace';
1.850 bisitz 6318: my $data_table_head = $sidebg;
6319: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6320: my $data_table_dark = '#E0E0E0';
1.470 banghart 6321: my $data_table_darker = '#CCCCCC';
1.349 albertel 6322: my $data_table_highlight = '#FFFF00';
1.352 albertel 6323: my $mail_new = '#FFBB77';
6324: my $mail_new_hover = '#DD9955';
6325: my $mail_read = '#BBBB77';
6326: my $mail_read_hover = '#999944';
6327: my $mail_replied = '#AAAA88';
6328: my $mail_replied_hover = '#888855';
6329: my $mail_other = '#99BBBB';
6330: my $mail_other_hover = '#669999';
1.391 albertel 6331: my $table_header = '#DDDDDD';
1.489 raeburn 6332: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6333: my $lg_border_color = '#C8C8C8';
1.952 onken 6334: my $button_hover = '#BF2317';
1.392 albertel 6335:
1.608 albertel 6336: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6337: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6338: : '0 3px 0 4px';
1.448 albertel 6339:
1.523 albertel 6340:
1.343 albertel 6341: return <<END;
1.947 droeschl 6342:
6343: /* needed for iframe to allow 100% height in FF */
6344: body, html {
6345: margin: 0;
6346: padding: 0 0.5%;
6347: height: 99%; /* to avoid scrollbars */
6348: }
6349:
1.795 www 6350: body {
1.911 bisitz 6351: font-family: $sans;
6352: line-height:130%;
6353: font-size:0.83em;
6354: color:$font;
1.795 www 6355: }
6356:
1.959 onken 6357: a:focus,
6358: a:focus img {
1.795 www 6359: color: red;
6360: }
1.698 harmsja 6361:
1.911 bisitz 6362: form, .inline {
6363: display: inline;
1.795 www 6364: }
1.721 harmsja 6365:
1.795 www 6366: .LC_right {
1.911 bisitz 6367: text-align:right;
1.795 www 6368: }
6369:
6370: .LC_middle {
1.911 bisitz 6371: vertical-align:middle;
1.795 www 6372: }
1.721 harmsja 6373:
1.1130 raeburn 6374: .LC_floatleft {
6375: float: left;
6376: }
6377:
6378: .LC_floatright {
6379: float: right;
6380: }
6381:
1.911 bisitz 6382: .LC_400Box {
6383: width:400px;
6384: }
1.721 harmsja 6385:
1.947 droeschl 6386: .LC_iframecontainer {
6387: width: 98%;
6388: margin: 0;
6389: position: fixed;
6390: top: 8.5em;
6391: bottom: 0;
6392: }
6393:
6394: .LC_iframecontainer iframe{
6395: border: none;
6396: width: 100%;
6397: height: 100%;
6398: }
6399:
1.778 bisitz 6400: .LC_filename {
6401: font-family: $mono;
6402: white-space:pre;
1.921 bisitz 6403: font-size: 120%;
1.778 bisitz 6404: }
6405:
6406: .LC_fileicon {
6407: border: none;
6408: height: 1.3em;
6409: vertical-align: text-bottom;
6410: margin-right: 0.3em;
6411: text-decoration:none;
6412: }
6413:
1.1008 www 6414: .LC_setting {
6415: text-decoration:underline;
6416: }
6417:
1.350 albertel 6418: .LC_error {
6419: color: red;
6420: }
1.795 www 6421:
1.1097 bisitz 6422: .LC_warning {
6423: color: darkorange;
6424: }
6425:
1.457 albertel 6426: .LC_diff_removed {
1.733 bisitz 6427: color: red;
1.394 albertel 6428: }
1.532 albertel 6429:
6430: .LC_info,
1.457 albertel 6431: .LC_success,
6432: .LC_diff_added {
1.350 albertel 6433: color: green;
6434: }
1.795 www 6435:
1.802 bisitz 6436: div.LC_confirm_box {
6437: background-color: #FAFAFA;
6438: border: 1px solid $lg_border_color;
6439: margin-right: 0;
6440: padding: 5px;
6441: }
6442:
6443: div.LC_confirm_box .LC_error img,
6444: div.LC_confirm_box .LC_success img {
6445: vertical-align: middle;
6446: }
6447:
1.1242 raeburn 6448: .LC_maxwidth {
6449: max-width: 100%;
6450: height: auto;
6451: }
6452:
1.1243 raeburn 6453: .LC_textsize_mobile {
6454: \@media only screen and (max-device-width: 480px) {
6455: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6456: }
6457: }
6458:
1.440 albertel 6459: .LC_icon {
1.771 droeschl 6460: border: none;
1.790 droeschl 6461: vertical-align: middle;
1.771 droeschl 6462: }
6463:
1.543 albertel 6464: .LC_docs_spacer {
6465: width: 25px;
6466: height: 1px;
1.771 droeschl 6467: border: none;
1.543 albertel 6468: }
1.346 albertel 6469:
1.532 albertel 6470: .LC_internal_info {
1.735 bisitz 6471: color: #999999;
1.532 albertel 6472: }
6473:
1.794 www 6474: .LC_discussion {
1.1050 www 6475: background: $data_table_dark;
1.911 bisitz 6476: border: 1px solid black;
6477: margin: 2px;
1.794 www 6478: }
6479:
6480: .LC_disc_action_left {
1.1050 www 6481: background: $sidebg;
1.911 bisitz 6482: text-align: left;
1.1050 www 6483: padding: 4px;
6484: margin: 2px;
1.794 www 6485: }
6486:
6487: .LC_disc_action_right {
1.1050 www 6488: background: $sidebg;
1.911 bisitz 6489: text-align: right;
1.1050 www 6490: padding: 4px;
6491: margin: 2px;
1.794 www 6492: }
6493:
6494: .LC_disc_new_item {
1.911 bisitz 6495: background: white;
6496: border: 2px solid red;
1.1050 www 6497: margin: 4px;
6498: padding: 4px;
1.794 www 6499: }
6500:
6501: .LC_disc_old_item {
1.911 bisitz 6502: background: white;
1.1050 www 6503: margin: 4px;
6504: padding: 4px;
1.794 www 6505: }
6506:
1.458 albertel 6507: table.LC_pastsubmission {
6508: border: 1px solid black;
6509: margin: 2px;
6510: }
6511:
1.924 bisitz 6512: table#LC_menubuttons {
1.345 albertel 6513: width: 100%;
6514: background: $pgbg;
1.392 albertel 6515: border: 2px;
1.402 albertel 6516: border-collapse: separate;
1.803 bisitz 6517: padding: 0;
1.345 albertel 6518: }
1.392 albertel 6519:
1.801 tempelho 6520: table#LC_title_bar a {
6521: color: $fontmenu;
6522: }
1.836 bisitz 6523:
1.807 droeschl 6524: table#LC_title_bar {
1.819 tempelho 6525: clear: both;
1.836 bisitz 6526: display: none;
1.807 droeschl 6527: }
6528:
1.795 www 6529: table#LC_title_bar,
1.933 droeschl 6530: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6531: table#LC_title_bar.LC_with_remote {
1.359 albertel 6532: width: 100%;
1.392 albertel 6533: border-color: $pgbg;
6534: border-style: solid;
6535: border-width: $border;
1.379 albertel 6536: background: $pgbg;
1.801 tempelho 6537: color: $fontmenu;
1.392 albertel 6538: border-collapse: collapse;
1.803 bisitz 6539: padding: 0;
1.819 tempelho 6540: margin: 0;
1.359 albertel 6541: }
1.795 www 6542:
1.933 droeschl 6543: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6544: margin: 0;
6545: padding: 0;
1.933 droeschl 6546: position: relative;
6547: list-style: none;
1.913 droeschl 6548: }
1.933 droeschl 6549: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6550: display: inline;
6551: }
1.933 droeschl 6552:
6553: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6554: padding: 0;
1.933 droeschl 6555: margin: 0;
6556: float: left;
1.913 droeschl 6557: }
1.933 droeschl 6558: .LC_breadcrumb_tools_tools {
6559: padding: 0;
6560: margin: 0;
1.913 droeschl 6561: float: right;
6562: }
6563:
1.1240 raeburn 6564: .LC_placement_prog {
6565: padding-right: 20px;
6566: font-weight: bold;
6567: font-size: 90%;
6568: }
6569:
1.359 albertel 6570: table#LC_title_bar td {
6571: background: $tabbg;
6572: }
1.795 www 6573:
1.911 bisitz 6574: table#LC_menubuttons img {
1.803 bisitz 6575: border: none;
1.346 albertel 6576: }
1.795 www 6577:
1.842 droeschl 6578: .LC_breadcrumbs_component {
1.911 bisitz 6579: float: right;
6580: margin: 0 1em;
1.357 albertel 6581: }
1.842 droeschl 6582: .LC_breadcrumbs_component img {
1.911 bisitz 6583: vertical-align: middle;
1.777 tempelho 6584: }
1.795 www 6585:
1.1243 raeburn 6586: .LC_breadcrumbs_hoverable {
6587: background: $sidebg;
6588: }
6589:
1.383 albertel 6590: td.LC_table_cell_checkbox {
6591: text-align: center;
6592: }
1.795 www 6593:
6594: .LC_fontsize_small {
1.911 bisitz 6595: font-size: 70%;
1.705 tempelho 6596: }
6597:
1.844 bisitz 6598: #LC_breadcrumbs {
1.911 bisitz 6599: clear:both;
6600: background: $sidebg;
6601: border-bottom: 1px solid $lg_border_color;
6602: line-height: 2.5em;
1.933 droeschl 6603: overflow: hidden;
1.911 bisitz 6604: margin: 0;
6605: padding: 0;
1.995 raeburn 6606: text-align: left;
1.819 tempelho 6607: }
1.862 bisitz 6608:
1.1098 bisitz 6609: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6610: clear:both;
6611: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6612: border: 1px solid $sidebg;
1.1098 bisitz 6613: margin: 0 0 10px 0;
1.966 bisitz 6614: padding: 3px;
1.995 raeburn 6615: text-align: left;
1.822 bisitz 6616: }
6617:
1.795 www 6618: .LC_fontsize_medium {
1.911 bisitz 6619: font-size: 85%;
1.705 tempelho 6620: }
6621:
1.795 www 6622: .LC_fontsize_large {
1.911 bisitz 6623: font-size: 120%;
1.705 tempelho 6624: }
6625:
1.346 albertel 6626: .LC_menubuttons_inline_text {
6627: color: $font;
1.698 harmsja 6628: font-size: 90%;
1.701 harmsja 6629: padding-left:3px;
1.346 albertel 6630: }
6631:
1.934 droeschl 6632: .LC_menubuttons_inline_text img{
6633: vertical-align: middle;
6634: }
6635:
1.1051 www 6636: li.LC_menubuttons_inline_text img {
1.951 onken 6637: cursor:pointer;
1.1002 droeschl 6638: text-decoration: none;
1.951 onken 6639: }
6640:
1.526 www 6641: .LC_menubuttons_link {
6642: text-decoration: none;
6643: }
1.795 www 6644:
1.522 albertel 6645: .LC_menubuttons_category {
1.521 www 6646: color: $font;
1.526 www 6647: background: $pgbg;
1.521 www 6648: font-size: larger;
6649: font-weight: bold;
6650: }
6651:
1.346 albertel 6652: td.LC_menubuttons_text {
1.911 bisitz 6653: color: $font;
1.346 albertel 6654: }
1.706 harmsja 6655:
1.346 albertel 6656: .LC_current_location {
6657: background: $tabbg;
6658: }
1.795 www 6659:
1.1286 raeburn 6660: td.LC_zero_height {
6661: line-height: 0;
6662: cellpadding: 0;
6663: }
6664:
1.938 bisitz 6665: table.LC_data_table {
1.347 albertel 6666: border: 1px solid #000000;
1.402 albertel 6667: border-collapse: separate;
1.426 albertel 6668: border-spacing: 1px;
1.610 albertel 6669: background: $pgbg;
1.347 albertel 6670: }
1.795 www 6671:
1.422 albertel 6672: .LC_data_table_dense {
6673: font-size: small;
6674: }
1.795 www 6675:
1.507 raeburn 6676: table.LC_nested_outer {
6677: border: 1px solid #000000;
1.589 raeburn 6678: border-collapse: collapse;
1.803 bisitz 6679: border-spacing: 0;
1.507 raeburn 6680: width: 100%;
6681: }
1.795 www 6682:
1.879 raeburn 6683: table.LC_innerpickbox,
1.507 raeburn 6684: table.LC_nested {
1.803 bisitz 6685: border: none;
1.589 raeburn 6686: border-collapse: collapse;
1.803 bisitz 6687: border-spacing: 0;
1.507 raeburn 6688: width: 100%;
6689: }
1.795 www 6690:
1.911 bisitz 6691: table.LC_data_table tr th,
6692: table.LC_calendar tr th,
1.879 raeburn 6693: table.LC_prior_tries tr th,
6694: table.LC_innerpickbox tr th {
1.349 albertel 6695: font-weight: bold;
6696: background-color: $data_table_head;
1.801 tempelho 6697: color:$fontmenu;
1.701 harmsja 6698: font-size:90%;
1.347 albertel 6699: }
1.795 www 6700:
1.879 raeburn 6701: table.LC_innerpickbox tr th,
6702: table.LC_innerpickbox tr td {
6703: vertical-align: top;
6704: }
6705:
1.711 raeburn 6706: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6707: background-color: #CCCCCC;
1.711 raeburn 6708: font-weight: bold;
6709: text-align: left;
6710: }
1.795 www 6711:
1.912 bisitz 6712: table.LC_data_table tr.LC_odd_row > td {
6713: background-color: $data_table_light;
6714: padding: 2px;
6715: vertical-align: top;
6716: }
6717:
1.809 bisitz 6718: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6719: background-color: $data_table_light;
1.912 bisitz 6720: vertical-align: top;
6721: }
6722:
6723: table.LC_data_table tr.LC_even_row > td {
6724: background-color: $data_table_dark;
1.425 albertel 6725: padding: 2px;
1.900 bisitz 6726: vertical-align: top;
1.347 albertel 6727: }
1.795 www 6728:
1.809 bisitz 6729: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6730: background-color: $data_table_dark;
1.900 bisitz 6731: vertical-align: top;
1.347 albertel 6732: }
1.795 www 6733:
1.425 albertel 6734: table.LC_data_table tr.LC_data_table_highlight td {
6735: background-color: $data_table_darker;
6736: }
1.795 www 6737:
1.639 raeburn 6738: table.LC_data_table tr td.LC_leftcol_header {
6739: background-color: $data_table_head;
6740: font-weight: bold;
6741: }
1.795 www 6742:
1.451 albertel 6743: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6744: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6745: font-weight: bold;
6746: font-style: italic;
6747: text-align: center;
6748: padding: 8px;
1.347 albertel 6749: }
1.795 www 6750:
1.1114 raeburn 6751: table.LC_data_table tr.LC_empty_row td,
6752: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6753: background-color: $sidebg;
6754: }
6755:
6756: table.LC_nested tr.LC_empty_row td {
6757: background-color: #FFFFFF;
6758: }
6759:
1.890 droeschl 6760: table.LC_caption {
6761: }
6762:
1.507 raeburn 6763: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6764: padding: 4ex
6765: }
1.795 www 6766:
1.507 raeburn 6767: table.LC_nested_outer tr th {
6768: font-weight: bold;
1.801 tempelho 6769: color:$fontmenu;
1.507 raeburn 6770: background-color: $data_table_head;
1.701 harmsja 6771: font-size: small;
1.507 raeburn 6772: border-bottom: 1px solid #000000;
6773: }
1.795 www 6774:
1.507 raeburn 6775: table.LC_nested_outer tr td.LC_subheader {
6776: background-color: $data_table_head;
6777: font-weight: bold;
6778: font-size: small;
6779: border-bottom: 1px solid #000000;
6780: text-align: right;
1.451 albertel 6781: }
1.795 www 6782:
1.507 raeburn 6783: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6784: background-color: #CCCCCC;
1.451 albertel 6785: font-weight: bold;
6786: font-size: small;
1.507 raeburn 6787: text-align: center;
6788: }
1.795 www 6789:
1.589 raeburn 6790: table.LC_nested tr.LC_info_row td.LC_left_item,
6791: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6792: text-align: left;
1.451 albertel 6793: }
1.795 www 6794:
1.507 raeburn 6795: table.LC_nested td {
1.735 bisitz 6796: background-color: #FFFFFF;
1.451 albertel 6797: font-size: small;
1.507 raeburn 6798: }
1.795 www 6799:
1.507 raeburn 6800: table.LC_nested_outer tr th.LC_right_item,
6801: table.LC_nested tr.LC_info_row td.LC_right_item,
6802: table.LC_nested tr.LC_odd_row td.LC_right_item,
6803: table.LC_nested tr td.LC_right_item {
1.451 albertel 6804: text-align: right;
6805: }
6806:
1.507 raeburn 6807: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6808: background-color: #EEEEEE;
1.451 albertel 6809: }
6810:
1.473 raeburn 6811: table.LC_createuser {
6812: }
6813:
6814: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6815: font-size: small;
1.473 raeburn 6816: }
6817:
6818: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6819: background-color: #CCCCCC;
1.473 raeburn 6820: font-weight: bold;
6821: text-align: center;
6822: }
6823:
1.349 albertel 6824: table.LC_calendar {
6825: border: 1px solid #000000;
6826: border-collapse: collapse;
1.917 raeburn 6827: width: 98%;
1.349 albertel 6828: }
1.795 www 6829:
1.349 albertel 6830: table.LC_calendar_pickdate {
6831: font-size: xx-small;
6832: }
1.795 www 6833:
1.349 albertel 6834: table.LC_calendar tr td {
6835: border: 1px solid #000000;
6836: vertical-align: top;
1.917 raeburn 6837: width: 14%;
1.349 albertel 6838: }
1.795 www 6839:
1.349 albertel 6840: table.LC_calendar tr td.LC_calendar_day_empty {
6841: background-color: $data_table_dark;
6842: }
1.795 www 6843:
1.779 bisitz 6844: table.LC_calendar tr td.LC_calendar_day_current {
6845: background-color: $data_table_highlight;
1.777 tempelho 6846: }
1.795 www 6847:
1.938 bisitz 6848: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6849: background-color: $mail_new;
6850: }
1.795 www 6851:
1.938 bisitz 6852: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6853: background-color: $mail_new_hover;
6854: }
1.795 www 6855:
1.938 bisitz 6856: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6857: background-color: $mail_read;
6858: }
1.795 www 6859:
1.938 bisitz 6860: /*
6861: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6862: background-color: $mail_read_hover;
6863: }
1.938 bisitz 6864: */
1.795 www 6865:
1.938 bisitz 6866: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6867: background-color: $mail_replied;
6868: }
1.795 www 6869:
1.938 bisitz 6870: /*
6871: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6872: background-color: $mail_replied_hover;
6873: }
1.938 bisitz 6874: */
1.795 www 6875:
1.938 bisitz 6876: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6877: background-color: $mail_other;
6878: }
1.795 www 6879:
1.938 bisitz 6880: /*
6881: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6882: background-color: $mail_other_hover;
6883: }
1.938 bisitz 6884: */
1.494 raeburn 6885:
1.777 tempelho 6886: table.LC_data_table tr > td.LC_browser_file,
6887: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6888: background: #AAEE77;
1.389 albertel 6889: }
1.795 www 6890:
1.777 tempelho 6891: table.LC_data_table tr > td.LC_browser_file_locked,
6892: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6893: background: #FFAA99;
1.387 albertel 6894: }
1.795 www 6895:
1.777 tempelho 6896: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6897: background: #888888;
1.779 bisitz 6898: }
1.795 www 6899:
1.777 tempelho 6900: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6901: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6902: background: #F8F866;
1.777 tempelho 6903: }
1.795 www 6904:
1.696 bisitz 6905: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6906: background: #E0E8FF;
1.387 albertel 6907: }
1.696 bisitz 6908:
1.707 bisitz 6909: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6910: /* background: #77FF77; */
1.707 bisitz 6911: }
1.795 www 6912:
1.707 bisitz 6913: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6914: border-right: 8px solid #FFFF77;
1.707 bisitz 6915: }
1.795 www 6916:
1.707 bisitz 6917: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6918: border-right: 8px solid #FFAA77;
1.707 bisitz 6919: }
1.795 www 6920:
1.707 bisitz 6921: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6922: border-right: 8px solid #FF7777;
1.707 bisitz 6923: }
1.795 www 6924:
1.707 bisitz 6925: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6926: border-right: 8px solid #AAFF77;
1.707 bisitz 6927: }
1.795 www 6928:
1.707 bisitz 6929: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6930: border-right: 8px solid #11CC55;
1.707 bisitz 6931: }
6932:
1.388 albertel 6933: span.LC_current_location {
1.701 harmsja 6934: font-size:larger;
1.388 albertel 6935: background: $pgbg;
6936: }
1.387 albertel 6937:
1.1029 www 6938: span.LC_current_nav_location {
6939: font-weight:bold;
6940: background: $sidebg;
6941: }
6942:
1.395 albertel 6943: span.LC_parm_menu_item {
6944: font-size: larger;
6945: }
1.795 www 6946:
1.395 albertel 6947: span.LC_parm_scope_all {
6948: color: red;
6949: }
1.795 www 6950:
1.395 albertel 6951: span.LC_parm_scope_folder {
6952: color: green;
6953: }
1.795 www 6954:
1.395 albertel 6955: span.LC_parm_scope_resource {
6956: color: orange;
6957: }
1.795 www 6958:
1.395 albertel 6959: span.LC_parm_part {
6960: color: blue;
6961: }
1.795 www 6962:
1.911 bisitz 6963: span.LC_parm_folder,
6964: span.LC_parm_symb {
1.395 albertel 6965: font-size: x-small;
6966: font-family: $mono;
6967: color: #AAAAAA;
6968: }
6969:
1.977 bisitz 6970: ul.LC_parm_parmlist li {
6971: display: inline-block;
6972: padding: 0.3em 0.8em;
6973: vertical-align: top;
6974: width: 150px;
6975: border-top:1px solid $lg_border_color;
6976: }
6977:
1.795 www 6978: td.LC_parm_overview_level_menu,
6979: td.LC_parm_overview_map_menu,
6980: td.LC_parm_overview_parm_selectors,
6981: td.LC_parm_overview_restrictions {
1.396 albertel 6982: border: 1px solid black;
6983: border-collapse: collapse;
6984: }
1.795 www 6985:
1.1285 raeburn 6986: span.LC_parm_recursive,
6987: td.LC_parm_recursive {
6988: font-weight: bold;
6989: font-size: smaller;
6990: }
6991:
1.396 albertel 6992: table.LC_parm_overview_restrictions td {
6993: border-width: 1px 4px 1px 4px;
6994: border-style: solid;
6995: border-color: $pgbg;
6996: text-align: center;
6997: }
1.795 www 6998:
1.396 albertel 6999: table.LC_parm_overview_restrictions th {
7000: background: $tabbg;
7001: border-width: 1px 4px 1px 4px;
7002: border-style: solid;
7003: border-color: $pgbg;
7004: }
1.795 www 7005:
1.398 albertel 7006: table#LC_helpmenu {
1.803 bisitz 7007: border: none;
1.398 albertel 7008: height: 55px;
1.803 bisitz 7009: border-spacing: 0;
1.398 albertel 7010: }
7011:
7012: table#LC_helpmenu fieldset legend {
7013: font-size: larger;
7014: }
1.795 www 7015:
1.397 albertel 7016: table#LC_helpmenu_links {
7017: width: 100%;
7018: border: 1px solid black;
7019: background: $pgbg;
1.803 bisitz 7020: padding: 0;
1.397 albertel 7021: border-spacing: 1px;
7022: }
1.795 www 7023:
1.397 albertel 7024: table#LC_helpmenu_links tr td {
7025: padding: 1px;
7026: background: $tabbg;
1.399 albertel 7027: text-align: center;
7028: font-weight: bold;
1.397 albertel 7029: }
1.396 albertel 7030:
1.795 www 7031: table#LC_helpmenu_links a:link,
7032: table#LC_helpmenu_links a:visited,
1.397 albertel 7033: table#LC_helpmenu_links a:active {
7034: text-decoration: none;
7035: color: $font;
7036: }
1.795 www 7037:
1.397 albertel 7038: table#LC_helpmenu_links a:hover {
7039: text-decoration: underline;
7040: color: $vlink;
7041: }
1.396 albertel 7042:
1.417 albertel 7043: .LC_chrt_popup_exists {
7044: border: 1px solid #339933;
7045: margin: -1px;
7046: }
1.795 www 7047:
1.417 albertel 7048: .LC_chrt_popup_up {
7049: border: 1px solid yellow;
7050: margin: -1px;
7051: }
1.795 www 7052:
1.417 albertel 7053: .LC_chrt_popup {
7054: border: 1px solid #8888FF;
7055: background: #CCCCFF;
7056: }
1.795 www 7057:
1.421 albertel 7058: table.LC_pick_box {
7059: border-collapse: separate;
7060: background: white;
7061: border: 1px solid black;
7062: border-spacing: 1px;
7063: }
1.795 www 7064:
1.421 albertel 7065: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7066: background: $sidebg;
1.421 albertel 7067: font-weight: bold;
1.900 bisitz 7068: text-align: left;
1.740 bisitz 7069: vertical-align: top;
1.421 albertel 7070: width: 184px;
7071: padding: 8px;
7072: }
1.795 www 7073:
1.579 raeburn 7074: table.LC_pick_box td.LC_pick_box_value {
7075: text-align: left;
7076: padding: 8px;
7077: }
1.795 www 7078:
1.579 raeburn 7079: table.LC_pick_box td.LC_pick_box_select {
7080: text-align: left;
7081: padding: 8px;
7082: }
1.795 www 7083:
1.424 albertel 7084: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7085: padding: 0;
1.421 albertel 7086: height: 1px;
7087: background: black;
7088: }
1.795 www 7089:
1.421 albertel 7090: table.LC_pick_box td.LC_pick_box_submit {
7091: text-align: right;
7092: }
1.795 www 7093:
1.579 raeburn 7094: table.LC_pick_box td.LC_evenrow_value {
7095: text-align: left;
7096: padding: 8px;
7097: background-color: $data_table_light;
7098: }
1.795 www 7099:
1.579 raeburn 7100: table.LC_pick_box td.LC_oddrow_value {
7101: text-align: left;
7102: padding: 8px;
7103: background-color: $data_table_light;
7104: }
1.795 www 7105:
1.579 raeburn 7106: span.LC_helpform_receipt_cat {
7107: font-weight: bold;
7108: }
1.795 www 7109:
1.424 albertel 7110: table.LC_group_priv_box {
7111: background: white;
7112: border: 1px solid black;
7113: border-spacing: 1px;
7114: }
1.795 www 7115:
1.424 albertel 7116: table.LC_group_priv_box td.LC_pick_box_title {
7117: background: $tabbg;
7118: font-weight: bold;
7119: text-align: right;
7120: width: 184px;
7121: }
1.795 www 7122:
1.424 albertel 7123: table.LC_group_priv_box td.LC_groups_fixed {
7124: background: $data_table_light;
7125: text-align: center;
7126: }
1.795 www 7127:
1.424 albertel 7128: table.LC_group_priv_box td.LC_groups_optional {
7129: background: $data_table_dark;
7130: text-align: center;
7131: }
1.795 www 7132:
1.424 albertel 7133: table.LC_group_priv_box td.LC_groups_functionality {
7134: background: $data_table_darker;
7135: text-align: center;
7136: font-weight: bold;
7137: }
1.795 www 7138:
1.424 albertel 7139: table.LC_group_priv td {
7140: text-align: left;
1.803 bisitz 7141: padding: 0;
1.424 albertel 7142: }
7143:
7144: .LC_navbuttons {
7145: margin: 2ex 0ex 2ex 0ex;
7146: }
1.795 www 7147:
1.423 albertel 7148: .LC_topic_bar {
7149: font-weight: bold;
7150: background: $tabbg;
1.918 wenzelju 7151: margin: 1em 0em 1em 2em;
1.805 bisitz 7152: padding: 3px;
1.918 wenzelju 7153: font-size: 1.2em;
1.423 albertel 7154: }
1.795 www 7155:
1.423 albertel 7156: .LC_topic_bar span {
1.918 wenzelju 7157: left: 0.5em;
7158: position: absolute;
1.423 albertel 7159: vertical-align: middle;
1.918 wenzelju 7160: font-size: 1.2em;
1.423 albertel 7161: }
1.795 www 7162:
1.423 albertel 7163: table.LC_course_group_status {
7164: margin: 20px;
7165: }
1.795 www 7166:
1.423 albertel 7167: table.LC_status_selector td {
7168: vertical-align: top;
7169: text-align: center;
1.424 albertel 7170: padding: 4px;
7171: }
1.795 www 7172:
1.599 albertel 7173: div.LC_feedback_link {
1.616 albertel 7174: clear: both;
1.829 kalberla 7175: background: $sidebg;
1.779 bisitz 7176: width: 100%;
1.829 kalberla 7177: padding-bottom: 10px;
7178: border: 1px $tabbg solid;
1.833 kalberla 7179: height: 22px;
7180: line-height: 22px;
7181: padding-top: 5px;
7182: }
7183:
7184: div.LC_feedback_link img {
7185: height: 22px;
1.867 kalberla 7186: vertical-align:middle;
1.829 kalberla 7187: }
7188:
1.911 bisitz 7189: div.LC_feedback_link a {
1.829 kalberla 7190: text-decoration: none;
1.489 raeburn 7191: }
1.795 www 7192:
1.867 kalberla 7193: div.LC_comblock {
1.911 bisitz 7194: display:inline;
1.867 kalberla 7195: color:$font;
7196: font-size:90%;
7197: }
7198:
7199: div.LC_feedback_link div.LC_comblock {
7200: padding-left:5px;
7201: }
7202:
7203: div.LC_feedback_link div.LC_comblock a {
7204: color:$font;
7205: }
7206:
1.489 raeburn 7207: span.LC_feedback_link {
1.858 bisitz 7208: /* background: $feedback_link_bg; */
1.599 albertel 7209: font-size: larger;
7210: }
1.795 www 7211:
1.599 albertel 7212: span.LC_message_link {
1.858 bisitz 7213: /* background: $feedback_link_bg; */
1.599 albertel 7214: font-size: larger;
7215: position: absolute;
7216: right: 1em;
1.489 raeburn 7217: }
1.421 albertel 7218:
1.515 albertel 7219: table.LC_prior_tries {
1.524 albertel 7220: border: 1px solid #000000;
7221: border-collapse: separate;
7222: border-spacing: 1px;
1.515 albertel 7223: }
1.523 albertel 7224:
1.515 albertel 7225: table.LC_prior_tries td {
1.524 albertel 7226: padding: 2px;
1.515 albertel 7227: }
1.523 albertel 7228:
7229: .LC_answer_correct {
1.795 www 7230: background: lightgreen;
7231: color: darkgreen;
7232: padding: 6px;
1.523 albertel 7233: }
1.795 www 7234:
1.523 albertel 7235: .LC_answer_charged_try {
1.797 www 7236: background: #FFAAAA;
1.795 www 7237: color: darkred;
7238: padding: 6px;
1.523 albertel 7239: }
1.795 www 7240:
1.779 bisitz 7241: .LC_answer_not_charged_try,
1.523 albertel 7242: .LC_answer_no_grade,
7243: .LC_answer_late {
1.795 www 7244: background: lightyellow;
1.523 albertel 7245: color: black;
1.795 www 7246: padding: 6px;
1.523 albertel 7247: }
1.795 www 7248:
1.523 albertel 7249: .LC_answer_previous {
1.795 www 7250: background: lightblue;
7251: color: darkblue;
7252: padding: 6px;
1.523 albertel 7253: }
1.795 www 7254:
1.779 bisitz 7255: .LC_answer_no_message {
1.777 tempelho 7256: background: #FFFFFF;
7257: color: black;
1.795 www 7258: padding: 6px;
1.779 bisitz 7259: }
1.795 www 7260:
1.1334 ! raeburn 7261: .LC_answer_unknown,
! 7262: .LC_answer_warning {
1.779 bisitz 7263: background: orange;
7264: color: black;
1.795 www 7265: padding: 6px;
1.777 tempelho 7266: }
1.795 www 7267:
1.529 albertel 7268: span.LC_prior_numerical,
7269: span.LC_prior_string,
7270: span.LC_prior_custom,
7271: span.LC_prior_reaction,
7272: span.LC_prior_math {
1.925 bisitz 7273: font-family: $mono;
1.523 albertel 7274: white-space: pre;
7275: }
7276:
1.525 albertel 7277: span.LC_prior_string {
1.925 bisitz 7278: font-family: $mono;
1.525 albertel 7279: white-space: pre;
7280: }
7281:
1.523 albertel 7282: table.LC_prior_option {
7283: width: 100%;
7284: border-collapse: collapse;
7285: }
1.795 www 7286:
1.911 bisitz 7287: table.LC_prior_rank,
1.795 www 7288: table.LC_prior_match {
1.528 albertel 7289: border-collapse: collapse;
7290: }
1.795 www 7291:
1.528 albertel 7292: table.LC_prior_option tr td,
7293: table.LC_prior_rank tr td,
7294: table.LC_prior_match tr td {
1.524 albertel 7295: border: 1px solid #000000;
1.515 albertel 7296: }
7297:
1.855 bisitz 7298: .LC_nobreak {
1.544 albertel 7299: white-space: nowrap;
1.519 raeburn 7300: }
7301:
1.576 raeburn 7302: span.LC_cusr_emph {
7303: font-style: italic;
7304: }
7305:
1.633 raeburn 7306: span.LC_cusr_subheading {
7307: font-weight: normal;
7308: font-size: 85%;
7309: }
7310:
1.861 bisitz 7311: div.LC_docs_entry_move {
1.859 bisitz 7312: border: 1px solid #BBBBBB;
1.545 albertel 7313: background: #DDDDDD;
1.861 bisitz 7314: width: 22px;
1.859 bisitz 7315: padding: 1px;
7316: margin: 0;
1.545 albertel 7317: }
7318:
1.861 bisitz 7319: table.LC_data_table tr > td.LC_docs_entry_commands,
7320: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7321: font-size: x-small;
7322: }
1.795 www 7323:
1.861 bisitz 7324: .LC_docs_entry_parameter {
7325: white-space: nowrap;
7326: }
7327:
1.544 albertel 7328: .LC_docs_copy {
1.545 albertel 7329: color: #000099;
1.544 albertel 7330: }
1.795 www 7331:
1.544 albertel 7332: .LC_docs_cut {
1.545 albertel 7333: color: #550044;
1.544 albertel 7334: }
1.795 www 7335:
1.544 albertel 7336: .LC_docs_rename {
1.545 albertel 7337: color: #009900;
1.544 albertel 7338: }
1.795 www 7339:
1.544 albertel 7340: .LC_docs_remove {
1.545 albertel 7341: color: #990000;
7342: }
7343:
1.1284 raeburn 7344: .LC_docs_alias {
7345: color: #440055;
7346: }
7347:
1.1286 raeburn 7348: .LC_domprefs_email,
1.1284 raeburn 7349: .LC_docs_alias_name,
1.547 albertel 7350: .LC_docs_reinit_warn,
7351: .LC_docs_ext_edit {
7352: font-size: x-small;
7353: }
7354:
1.545 albertel 7355: table.LC_docs_adddocs td,
7356: table.LC_docs_adddocs th {
7357: border: 1px solid #BBBBBB;
7358: padding: 4px;
7359: background: #DDDDDD;
1.543 albertel 7360: }
7361:
1.584 albertel 7362: table.LC_sty_begin {
7363: background: #BBFFBB;
7364: }
1.795 www 7365:
1.584 albertel 7366: table.LC_sty_end {
7367: background: #FFBBBB;
7368: }
7369:
1.589 raeburn 7370: table.LC_double_column {
1.803 bisitz 7371: border-width: 0;
1.589 raeburn 7372: border-collapse: collapse;
7373: width: 100%;
7374: padding: 2px;
7375: }
7376:
7377: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7378: top: 2px;
1.589 raeburn 7379: left: 2px;
7380: width: 47%;
7381: vertical-align: top;
7382: }
7383:
7384: table.LC_double_column tr td.LC_right_col {
7385: top: 2px;
1.779 bisitz 7386: right: 2px;
1.589 raeburn 7387: width: 47%;
7388: vertical-align: top;
7389: }
7390:
1.591 raeburn 7391: div.LC_left_float {
7392: float: left;
7393: padding-right: 5%;
1.597 albertel 7394: padding-bottom: 4px;
1.591 raeburn 7395: }
7396:
7397: div.LC_clear_float_header {
1.597 albertel 7398: padding-bottom: 2px;
1.591 raeburn 7399: }
7400:
7401: div.LC_clear_float_footer {
1.597 albertel 7402: padding-top: 10px;
1.591 raeburn 7403: clear: both;
7404: }
7405:
1.597 albertel 7406: div.LC_grade_show_user {
1.941 bisitz 7407: /* border-left: 5px solid $sidebg; */
7408: border-top: 5px solid #000000;
7409: margin: 50px 0 0 0;
1.936 bisitz 7410: padding: 15px 0 5px 10px;
1.597 albertel 7411: }
1.795 www 7412:
1.936 bisitz 7413: div.LC_grade_show_user_odd_row {
1.941 bisitz 7414: /* border-left: 5px solid #000000; */
7415: }
7416:
7417: div.LC_grade_show_user div.LC_Box {
7418: margin-right: 50px;
1.597 albertel 7419: }
7420:
7421: div.LC_grade_submissions,
7422: div.LC_grade_message_center,
1.936 bisitz 7423: div.LC_grade_info_links {
1.597 albertel 7424: margin: 5px;
7425: width: 99%;
7426: background: #FFFFFF;
7427: }
1.795 www 7428:
1.597 albertel 7429: div.LC_grade_submissions_header,
1.936 bisitz 7430: div.LC_grade_message_center_header {
1.705 tempelho 7431: font-weight: bold;
7432: font-size: large;
1.597 albertel 7433: }
1.795 www 7434:
1.597 albertel 7435: div.LC_grade_submissions_body,
1.936 bisitz 7436: div.LC_grade_message_center_body {
1.597 albertel 7437: border: 1px solid black;
7438: width: 99%;
7439: background: #FFFFFF;
7440: }
1.795 www 7441:
1.613 albertel 7442: table.LC_scantron_action {
7443: width: 100%;
7444: }
1.795 www 7445:
1.613 albertel 7446: table.LC_scantron_action tr th {
1.698 harmsja 7447: font-weight:bold;
7448: font-style:normal;
1.613 albertel 7449: }
1.795 www 7450:
1.779 bisitz 7451: .LC_edit_problem_header,
1.614 albertel 7452: div.LC_edit_problem_footer {
1.705 tempelho 7453: font-weight: normal;
7454: font-size: medium;
1.602 albertel 7455: margin: 2px;
1.1060 bisitz 7456: background-color: $sidebg;
1.600 albertel 7457: }
1.795 www 7458:
1.600 albertel 7459: div.LC_edit_problem_header,
1.602 albertel 7460: div.LC_edit_problem_header div,
1.614 albertel 7461: div.LC_edit_problem_footer,
7462: div.LC_edit_problem_footer div,
1.602 albertel 7463: div.LC_edit_problem_editxml_header,
7464: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7465: z-index: 100;
1.600 albertel 7466: }
1.795 www 7467:
1.600 albertel 7468: div.LC_edit_problem_header_title {
1.705 tempelho 7469: font-weight: bold;
7470: font-size: larger;
1.602 albertel 7471: background: $tabbg;
7472: padding: 3px;
1.1060 bisitz 7473: margin: 0 0 5px 0;
1.602 albertel 7474: }
1.795 www 7475:
1.602 albertel 7476: table.LC_edit_problem_header_title {
7477: width: 100%;
1.600 albertel 7478: background: $tabbg;
1.602 albertel 7479: }
7480:
1.1205 golterma 7481: div.LC_edit_actionbar {
7482: background-color: $sidebg;
1.1218 droeschl 7483: margin: 0;
7484: padding: 0;
7485: line-height: 200%;
1.602 albertel 7486: }
1.795 www 7487:
1.1218 droeschl 7488: div.LC_edit_actionbar div{
7489: padding: 0;
7490: margin: 0;
7491: display: inline-block;
1.600 albertel 7492: }
1.795 www 7493:
1.1124 bisitz 7494: .LC_edit_opt {
7495: padding-left: 1em;
7496: white-space: nowrap;
7497: }
7498:
1.1152 golterma 7499: .LC_edit_problem_latexhelper{
7500: text-align: right;
7501: }
7502:
7503: #LC_edit_problem_colorful div{
7504: margin-left: 40px;
7505: }
7506:
1.1205 golterma 7507: #LC_edit_problem_codemirror div{
7508: margin-left: 0px;
7509: }
7510:
1.911 bisitz 7511: img.stift {
1.803 bisitz 7512: border-width: 0;
7513: vertical-align: middle;
1.677 riegler 7514: }
1.680 riegler 7515:
1.923 bisitz 7516: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7517: vertical-align: top;
1.777 tempelho 7518: }
1.795 www 7519:
1.716 raeburn 7520: div.LC_createcourse {
1.911 bisitz 7521: margin: 10px 10px 10px 10px;
1.716 raeburn 7522: }
7523:
1.917 raeburn 7524: .LC_dccid {
1.1130 raeburn 7525: float: right;
1.917 raeburn 7526: margin: 0.2em 0 0 0;
7527: padding: 0;
7528: font-size: 90%;
7529: display:none;
7530: }
7531:
1.897 wenzelju 7532: ol.LC_primary_menu a:hover,
1.721 harmsja 7533: ol#LC_MenuBreadcrumbs a:hover,
7534: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7535: ul#LC_secondary_menu a:hover,
1.721 harmsja 7536: .LC_FormSectionClearButton input:hover
1.795 www 7537: ul.LC_TabContent li:hover a {
1.952 onken 7538: color:$button_hover;
1.911 bisitz 7539: text-decoration:none;
1.693 droeschl 7540: }
7541:
1.779 bisitz 7542: h1 {
1.911 bisitz 7543: padding: 0;
7544: line-height:130%;
1.693 droeschl 7545: }
1.698 harmsja 7546:
1.911 bisitz 7547: h2,
7548: h3,
7549: h4,
7550: h5,
7551: h6 {
7552: margin: 5px 0 5px 0;
7553: padding: 0;
7554: line-height:130%;
1.693 droeschl 7555: }
1.795 www 7556:
7557: .LC_hcell {
1.911 bisitz 7558: padding:3px 15px 3px 15px;
7559: margin: 0;
7560: background-color:$tabbg;
7561: color:$fontmenu;
7562: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7563: }
1.795 www 7564:
1.840 bisitz 7565: .LC_Box > .LC_hcell {
1.911 bisitz 7566: margin: 0 -10px 10px -10px;
1.835 bisitz 7567: }
7568:
1.721 harmsja 7569: .LC_noBorder {
1.911 bisitz 7570: border: 0;
1.698 harmsja 7571: }
1.693 droeschl 7572:
1.721 harmsja 7573: .LC_FormSectionClearButton input {
1.911 bisitz 7574: background-color:transparent;
7575: border: none;
7576: cursor:pointer;
7577: text-decoration:underline;
1.693 droeschl 7578: }
1.763 bisitz 7579:
7580: .LC_help_open_topic {
1.911 bisitz 7581: color: #FFFFFF;
7582: background-color: #EEEEFF;
7583: margin: 1px;
7584: padding: 4px;
7585: border: 1px solid #000033;
7586: white-space: nowrap;
7587: /* vertical-align: middle; */
1.759 neumanie 7588: }
1.693 droeschl 7589:
1.911 bisitz 7590: dl,
7591: ul,
7592: div,
7593: fieldset {
7594: margin: 10px 10px 10px 0;
7595: /* overflow: hidden; */
1.693 droeschl 7596: }
1.795 www 7597:
1.1211 raeburn 7598: article.geogebraweb div {
7599: margin: 0;
7600: }
7601:
1.838 bisitz 7602: fieldset > legend {
1.911 bisitz 7603: font-weight: bold;
7604: padding: 0 5px 0 5px;
1.838 bisitz 7605: }
7606:
1.813 bisitz 7607: #LC_nav_bar {
1.911 bisitz 7608: float: left;
1.995 raeburn 7609: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7610: margin: 0 0 2px 0;
1.807 droeschl 7611: }
7612:
1.916 droeschl 7613: #LC_realm {
7614: margin: 0.2em 0 0 0;
7615: padding: 0;
7616: font-weight: bold;
7617: text-align: center;
1.995 raeburn 7618: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7619: }
7620:
1.911 bisitz 7621: #LC_nav_bar em {
7622: font-weight: bold;
7623: font-style: normal;
1.807 droeschl 7624: }
7625:
1.897 wenzelju 7626: ol.LC_primary_menu {
1.934 droeschl 7627: margin: 0;
1.1076 raeburn 7628: padding: 0;
1.807 droeschl 7629: }
7630:
1.852 droeschl 7631: ol#LC_PathBreadcrumbs {
1.911 bisitz 7632: margin: 0;
1.693 droeschl 7633: }
7634:
1.897 wenzelju 7635: ol.LC_primary_menu li {
1.1076 raeburn 7636: color: RGB(80, 80, 80);
7637: vertical-align: middle;
7638: text-align: left;
7639: list-style: none;
1.1205 golterma 7640: position: relative;
1.1076 raeburn 7641: float: left;
1.1205 golterma 7642: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7643: line-height: 1.5em;
1.1076 raeburn 7644: }
7645:
1.1205 golterma 7646: ol.LC_primary_menu li a,
7647: ol.LC_primary_menu li p {
1.1076 raeburn 7648: display: block;
7649: margin: 0;
7650: padding: 0 5px 0 10px;
7651: text-decoration: none;
7652: }
7653:
1.1205 golterma 7654: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7655: display: inline-block;
7656: width: 95%;
7657: text-align: left;
7658: }
7659:
7660: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7661: display: inline-block;
7662: width: 5%;
7663: float: right;
7664: text-align: right;
7665: font-size: 70%;
7666: }
7667:
7668: ol.LC_primary_menu ul {
1.1076 raeburn 7669: display: none;
1.1205 golterma 7670: width: 15em;
1.1076 raeburn 7671: background-color: $data_table_light;
1.1205 golterma 7672: position: absolute;
7673: top: 100%;
1.1076 raeburn 7674: }
7675:
1.1205 golterma 7676: ol.LC_primary_menu ul ul {
7677: left: 100%;
7678: top: 0;
7679: }
7680:
7681: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7682: display: block;
7683: position: absolute;
7684: margin: 0;
7685: padding: 0;
1.1078 raeburn 7686: z-index: 2;
1.1076 raeburn 7687: }
7688:
7689: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7690: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7691: font-size: 90%;
1.911 bisitz 7692: vertical-align: top;
1.1076 raeburn 7693: float: none;
1.1079 raeburn 7694: border-left: 1px solid black;
7695: border-right: 1px solid black;
1.1205 golterma 7696: /* A dark bottom border to visualize different menu options;
7697: overwritten in the create_submenu routine for the last border-bottom of the menu */
7698: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7699: }
7700:
1.1205 golterma 7701: ol.LC_primary_menu li li p:hover {
7702: color:$button_hover;
7703: text-decoration:none;
7704: background-color:$data_table_dark;
1.1076 raeburn 7705: }
7706:
7707: ol.LC_primary_menu li li a:hover {
7708: color:$button_hover;
7709: background-color:$data_table_dark;
1.693 droeschl 7710: }
7711:
1.1205 golterma 7712: /* Font-size equal to the size of the predecessors*/
7713: ol.LC_primary_menu li:hover li li {
7714: font-size: 100%;
7715: }
7716:
1.897 wenzelju 7717: ol.LC_primary_menu li img {
1.911 bisitz 7718: vertical-align: bottom;
1.934 droeschl 7719: height: 1.1em;
1.1077 raeburn 7720: margin: 0.2em 0 0 0;
1.693 droeschl 7721: }
7722:
1.897 wenzelju 7723: ol.LC_primary_menu a {
1.911 bisitz 7724: color: RGB(80, 80, 80);
7725: text-decoration: none;
1.693 droeschl 7726: }
1.795 www 7727:
1.949 droeschl 7728: ol.LC_primary_menu a.LC_new_message {
7729: font-weight:bold;
7730: color: darkred;
7731: }
7732:
1.975 raeburn 7733: ol.LC_docs_parameters {
7734: margin-left: 0;
7735: padding: 0;
7736: list-style: none;
7737: }
7738:
7739: ol.LC_docs_parameters li {
7740: margin: 0;
7741: padding-right: 20px;
7742: display: inline;
7743: }
7744:
1.976 raeburn 7745: ol.LC_docs_parameters li:before {
7746: content: "\\002022 \\0020";
7747: }
7748:
7749: li.LC_docs_parameters_title {
7750: font-weight: bold;
7751: }
7752:
7753: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7754: content: "";
7755: }
7756:
1.897 wenzelju 7757: ul#LC_secondary_menu {
1.1107 raeburn 7758: clear: right;
1.911 bisitz 7759: color: $fontmenu;
7760: background: $tabbg;
7761: list-style: none;
7762: padding: 0;
7763: margin: 0;
7764: width: 100%;
1.995 raeburn 7765: text-align: left;
1.1107 raeburn 7766: float: left;
1.808 droeschl 7767: }
7768:
1.897 wenzelju 7769: ul#LC_secondary_menu li {
1.911 bisitz 7770: font-weight: bold;
7771: line-height: 1.8em;
1.1107 raeburn 7772: border-right: 1px solid black;
7773: float: left;
7774: }
7775:
7776: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7777: background-color: $data_table_light;
7778: }
7779:
7780: ul#LC_secondary_menu li a {
1.911 bisitz 7781: padding: 0 0.8em;
1.1107 raeburn 7782: }
7783:
7784: ul#LC_secondary_menu li ul {
7785: display: none;
7786: }
7787:
7788: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7789: display: block;
7790: position: absolute;
7791: margin: 0;
7792: padding: 0;
7793: list-style:none;
7794: float: none;
7795: background-color: $data_table_light;
7796: z-index: 2;
7797: margin-left: -1px;
7798: }
7799:
7800: ul#LC_secondary_menu li ul li {
7801: font-size: 90%;
7802: vertical-align: top;
7803: border-left: 1px solid black;
1.911 bisitz 7804: border-right: 1px solid black;
1.1119 raeburn 7805: background-color: $data_table_light;
1.1107 raeburn 7806: list-style:none;
7807: float: none;
7808: }
7809:
7810: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7811: background-color: $data_table_dark;
1.807 droeschl 7812: }
7813:
1.847 tempelho 7814: ul.LC_TabContent {
1.911 bisitz 7815: display:block;
7816: background: $sidebg;
7817: border-bottom: solid 1px $lg_border_color;
7818: list-style:none;
1.1020 raeburn 7819: margin: -1px -10px 0 -10px;
1.911 bisitz 7820: padding: 0;
1.693 droeschl 7821: }
7822:
1.795 www 7823: ul.LC_TabContent li,
7824: ul.LC_TabContentBigger li {
1.911 bisitz 7825: float:left;
1.741 harmsja 7826: }
1.795 www 7827:
1.897 wenzelju 7828: ul#LC_secondary_menu li a {
1.911 bisitz 7829: color: $fontmenu;
7830: text-decoration: none;
1.693 droeschl 7831: }
1.795 www 7832:
1.721 harmsja 7833: ul.LC_TabContent {
1.952 onken 7834: min-height:20px;
1.721 harmsja 7835: }
1.795 www 7836:
7837: ul.LC_TabContent li {
1.911 bisitz 7838: vertical-align:middle;
1.959 onken 7839: padding: 0 16px 0 10px;
1.911 bisitz 7840: background-color:$tabbg;
7841: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7842: border-left: solid 1px $font;
1.721 harmsja 7843: }
1.795 www 7844:
1.847 tempelho 7845: ul.LC_TabContent .right {
1.911 bisitz 7846: float:right;
1.847 tempelho 7847: }
7848:
1.911 bisitz 7849: ul.LC_TabContent li a,
7850: ul.LC_TabContent li {
7851: color:rgb(47,47,47);
7852: text-decoration:none;
7853: font-size:95%;
7854: font-weight:bold;
1.952 onken 7855: min-height:20px;
7856: }
7857:
1.959 onken 7858: ul.LC_TabContent li a:hover,
7859: ul.LC_TabContent li a:focus {
1.952 onken 7860: color: $button_hover;
1.959 onken 7861: background:none;
7862: outline:none;
1.952 onken 7863: }
7864:
7865: ul.LC_TabContent li:hover {
7866: color: $button_hover;
7867: cursor:pointer;
1.721 harmsja 7868: }
1.795 www 7869:
1.911 bisitz 7870: ul.LC_TabContent li.active {
1.952 onken 7871: color: $font;
1.911 bisitz 7872: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7873: border-bottom:solid 1px #FFFFFF;
7874: cursor: default;
1.744 ehlerst 7875: }
1.795 www 7876:
1.959 onken 7877: ul.LC_TabContent li.active a {
7878: color:$font;
7879: background:#FFFFFF;
7880: outline: none;
7881: }
1.1047 raeburn 7882:
7883: ul.LC_TabContent li.goback {
7884: float: left;
7885: border-left: none;
7886: }
7887:
1.870 tempelho 7888: #maincoursedoc {
1.911 bisitz 7889: clear:both;
1.870 tempelho 7890: }
7891:
7892: ul.LC_TabContentBigger {
1.911 bisitz 7893: display:block;
7894: list-style:none;
7895: padding: 0;
1.870 tempelho 7896: }
7897:
1.795 www 7898: ul.LC_TabContentBigger li {
1.911 bisitz 7899: vertical-align:bottom;
7900: height: 30px;
7901: font-size:110%;
7902: font-weight:bold;
7903: color: #737373;
1.841 tempelho 7904: }
7905:
1.957 onken 7906: ul.LC_TabContentBigger li.active {
7907: position: relative;
7908: top: 1px;
7909: }
7910:
1.870 tempelho 7911: ul.LC_TabContentBigger li a {
1.911 bisitz 7912: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7913: height: 30px;
7914: line-height: 30px;
7915: text-align: center;
7916: display: block;
7917: text-decoration: none;
1.958 onken 7918: outline: none;
1.741 harmsja 7919: }
1.795 www 7920:
1.870 tempelho 7921: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7922: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7923: color:$font;
1.744 ehlerst 7924: }
1.795 www 7925:
1.870 tempelho 7926: ul.LC_TabContentBigger li b {
1.911 bisitz 7927: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7928: display: block;
7929: float: left;
7930: padding: 0 30px;
1.957 onken 7931: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7932: }
7933:
1.956 onken 7934: ul.LC_TabContentBigger li:hover b {
7935: color:$button_hover;
7936: }
7937:
1.870 tempelho 7938: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7939: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7940: color:$font;
1.957 onken 7941: border: 0;
1.741 harmsja 7942: }
1.693 droeschl 7943:
1.870 tempelho 7944:
1.862 bisitz 7945: ul.LC_CourseBreadcrumbs {
7946: background: $sidebg;
1.1020 raeburn 7947: height: 2em;
1.862 bisitz 7948: padding-left: 10px;
1.1020 raeburn 7949: margin: 0;
1.862 bisitz 7950: list-style-position: inside;
7951: }
7952:
1.911 bisitz 7953: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7954: ol#LC_PathBreadcrumbs {
1.911 bisitz 7955: padding-left: 10px;
7956: margin: 0;
1.933 droeschl 7957: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7958: }
7959:
1.911 bisitz 7960: ol#LC_MenuBreadcrumbs li,
7961: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7962: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7963: display: inline;
1.933 droeschl 7964: white-space: normal;
1.693 droeschl 7965: }
7966:
1.823 bisitz 7967: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7968: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7969: text-decoration: none;
7970: font-size:90%;
1.693 droeschl 7971: }
1.795 www 7972:
1.969 droeschl 7973: ol#LC_MenuBreadcrumbs h1 {
7974: display: inline;
7975: font-size: 90%;
7976: line-height: 2.5em;
7977: margin: 0;
7978: padding: 0;
7979: }
7980:
1.795 www 7981: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7982: text-decoration:none;
7983: font-size:100%;
7984: font-weight:bold;
1.693 droeschl 7985: }
1.795 www 7986:
1.840 bisitz 7987: .LC_Box {
1.911 bisitz 7988: border: solid 1px $lg_border_color;
7989: padding: 0 10px 10px 10px;
1.746 neumanie 7990: }
1.795 www 7991:
1.1020 raeburn 7992: .LC_DocsBox {
7993: border: solid 1px $lg_border_color;
7994: padding: 0 0 10px 10px;
7995: }
7996:
1.795 www 7997: .LC_AboutMe_Image {
1.911 bisitz 7998: float:left;
7999: margin-right:10px;
1.747 neumanie 8000: }
1.795 www 8001:
8002: .LC_Clear_AboutMe_Image {
1.911 bisitz 8003: clear:left;
1.747 neumanie 8004: }
1.795 www 8005:
1.721 harmsja 8006: dl.LC_ListStyleClean dt {
1.911 bisitz 8007: padding-right: 5px;
8008: display: table-header-group;
1.693 droeschl 8009: }
8010:
1.721 harmsja 8011: dl.LC_ListStyleClean dd {
1.911 bisitz 8012: display: table-row;
1.693 droeschl 8013: }
8014:
1.721 harmsja 8015: .LC_ListStyleClean,
8016: .LC_ListStyleSimple,
8017: .LC_ListStyleNormal,
1.795 www 8018: .LC_ListStyleSpecial {
1.911 bisitz 8019: /* display:block; */
8020: list-style-position: inside;
8021: list-style-type: none;
8022: overflow: hidden;
8023: padding: 0;
1.693 droeschl 8024: }
8025:
1.721 harmsja 8026: .LC_ListStyleSimple li,
8027: .LC_ListStyleSimple dd,
8028: .LC_ListStyleNormal li,
8029: .LC_ListStyleNormal dd,
8030: .LC_ListStyleSpecial li,
1.795 www 8031: .LC_ListStyleSpecial dd {
1.911 bisitz 8032: margin: 0;
8033: padding: 5px 5px 5px 10px;
8034: clear: both;
1.693 droeschl 8035: }
8036:
1.721 harmsja 8037: .LC_ListStyleClean li,
8038: .LC_ListStyleClean dd {
1.911 bisitz 8039: padding-top: 0;
8040: padding-bottom: 0;
1.693 droeschl 8041: }
8042:
1.721 harmsja 8043: .LC_ListStyleSimple dd,
1.795 www 8044: .LC_ListStyleSimple li {
1.911 bisitz 8045: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8046: }
8047:
1.721 harmsja 8048: .LC_ListStyleSpecial li,
8049: .LC_ListStyleSpecial dd {
1.911 bisitz 8050: list-style-type: none;
8051: background-color: RGB(220, 220, 220);
8052: margin-bottom: 4px;
1.693 droeschl 8053: }
8054:
1.721 harmsja 8055: table.LC_SimpleTable {
1.911 bisitz 8056: margin:5px;
8057: border:solid 1px $lg_border_color;
1.795 www 8058: }
1.693 droeschl 8059:
1.721 harmsja 8060: table.LC_SimpleTable tr {
1.911 bisitz 8061: padding: 0;
8062: border:solid 1px $lg_border_color;
1.693 droeschl 8063: }
1.795 www 8064:
8065: table.LC_SimpleTable thead {
1.911 bisitz 8066: background:rgb(220,220,220);
1.693 droeschl 8067: }
8068:
1.721 harmsja 8069: div.LC_columnSection {
1.911 bisitz 8070: display: block;
8071: clear: both;
8072: overflow: hidden;
8073: margin: 0;
1.693 droeschl 8074: }
8075:
1.721 harmsja 8076: div.LC_columnSection>* {
1.911 bisitz 8077: float: left;
8078: margin: 10px 20px 10px 0;
8079: overflow:hidden;
1.693 droeschl 8080: }
1.721 harmsja 8081:
1.795 www 8082: table em {
1.911 bisitz 8083: font-weight: bold;
8084: font-style: normal;
1.748 schulted 8085: }
1.795 www 8086:
1.779 bisitz 8087: table.LC_tableBrowseRes,
1.795 www 8088: table.LC_tableOfContent {
1.911 bisitz 8089: border:none;
8090: border-spacing: 1px;
8091: padding: 3px;
8092: background-color: #FFFFFF;
8093: font-size: 90%;
1.753 droeschl 8094: }
1.789 droeschl 8095:
1.911 bisitz 8096: table.LC_tableOfContent {
8097: border-collapse: collapse;
1.789 droeschl 8098: }
8099:
1.771 droeschl 8100: table.LC_tableBrowseRes a,
1.768 schulted 8101: table.LC_tableOfContent a {
1.911 bisitz 8102: background-color: transparent;
8103: text-decoration: none;
1.753 droeschl 8104: }
8105:
1.795 www 8106: table.LC_tableOfContent img {
1.911 bisitz 8107: border: none;
8108: height: 1.3em;
8109: vertical-align: text-bottom;
8110: margin-right: 0.3em;
1.753 droeschl 8111: }
1.757 schulted 8112:
1.795 www 8113: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8114: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8115: }
8116:
1.795 www 8117: a#LC_content_toolbar_everything {
1.911 bisitz 8118: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8119: }
8120:
1.795 www 8121: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8122: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8123: }
8124:
1.795 www 8125: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8126: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8127: }
8128:
1.795 www 8129: a#LC_content_toolbar_changefolder {
1.911 bisitz 8130: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8131: }
8132:
1.795 www 8133: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8134: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8135: }
8136:
1.1043 raeburn 8137: a#LC_content_toolbar_edittoplevel {
8138: background-image:url(/res/adm/pages/edittoplevel.gif);
8139: }
8140:
1.795 www 8141: ul#LC_toolbar li a:hover {
1.911 bisitz 8142: background-position: bottom center;
1.757 schulted 8143: }
8144:
1.795 www 8145: ul#LC_toolbar {
1.911 bisitz 8146: padding: 0;
8147: margin: 2px;
8148: list-style:none;
8149: position:relative;
8150: background-color:white;
1.1082 raeburn 8151: overflow: auto;
1.757 schulted 8152: }
8153:
1.795 www 8154: ul#LC_toolbar li {
1.911 bisitz 8155: border:1px solid white;
8156: padding: 0;
8157: margin: 0;
8158: float: left;
8159: display:inline;
8160: vertical-align:middle;
1.1082 raeburn 8161: white-space: nowrap;
1.911 bisitz 8162: }
1.757 schulted 8163:
1.783 amueller 8164:
1.795 www 8165: a.LC_toolbarItem {
1.911 bisitz 8166: display:block;
8167: padding: 0;
8168: margin: 0;
8169: height: 32px;
8170: width: 32px;
8171: color:white;
8172: border: none;
8173: background-repeat:no-repeat;
8174: background-color:transparent;
1.757 schulted 8175: }
8176:
1.915 droeschl 8177: ul.LC_funclist {
8178: margin: 0;
8179: padding: 0.5em 1em 0.5em 0;
8180: }
8181:
1.933 droeschl 8182: ul.LC_funclist > li:first-child {
8183: font-weight:bold;
8184: margin-left:0.8em;
8185: }
8186:
1.915 droeschl 8187: ul.LC_funclist + ul.LC_funclist {
8188: /*
8189: left border as a seperator if we have more than
8190: one list
8191: */
8192: border-left: 1px solid $sidebg;
8193: /*
8194: this hides the left border behind the border of the
8195: outer box if element is wrapped to the next 'line'
8196: */
8197: margin-left: -1px;
8198: }
8199:
1.843 bisitz 8200: ul.LC_funclist li {
1.915 droeschl 8201: display: inline;
1.782 bisitz 8202: white-space: nowrap;
1.915 droeschl 8203: margin: 0 0 0 25px;
8204: line-height: 150%;
1.782 bisitz 8205: }
8206:
1.974 wenzelju 8207: .LC_hidden {
8208: display: none;
8209: }
8210:
1.1030 www 8211: .LCmodal-overlay {
8212: position:fixed;
8213: top:0;
8214: right:0;
8215: bottom:0;
8216: left:0;
8217: height:100%;
8218: width:100%;
8219: margin:0;
8220: padding:0;
8221: background:#999;
8222: opacity:.75;
8223: filter: alpha(opacity=75);
8224: -moz-opacity: 0.75;
8225: z-index:101;
8226: }
8227:
8228: * html .LCmodal-overlay {
8229: position: absolute;
8230: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8231: }
8232:
8233: .LCmodal-window {
8234: position:fixed;
8235: top:50%;
8236: left:50%;
8237: margin:0;
8238: padding:0;
8239: z-index:102;
8240: }
8241:
8242: * html .LCmodal-window {
8243: position:absolute;
8244: }
8245:
8246: .LCclose-window {
8247: position:absolute;
8248: width:32px;
8249: height:32px;
8250: right:8px;
8251: top:8px;
8252: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8253: text-indent:-99999px;
8254: overflow:hidden;
8255: cursor:pointer;
8256: }
8257:
1.1100 raeburn 8258: /*
1.1231 damieng 8259: styles used for response display
8260: */
8261: div.LC_radiofoil, div.LC_rankfoil {
8262: margin: .5em 0em .5em 0em;
8263: }
8264: table.LC_itemgroup {
8265: margin-top: 1em;
8266: }
8267:
8268: /*
1.1100 raeburn 8269: styles used by TTH when "Default set of options to pass to tth/m
8270: when converting TeX" in course settings has been set
8271:
8272: option passed: -t
8273:
8274: */
8275:
8276: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8277: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8278: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8279: td div.norm {line-height:normal;}
8280:
8281: /*
8282: option passed -y3
8283: */
8284:
8285: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8286: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8287: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8288:
1.1230 damieng 8289: /*
8290: sections with roles, for content only
8291: */
8292: section[class^="role-"] {
8293: padding-left: 10px;
8294: padding-right: 5px;
8295: margin-top: 8px;
8296: margin-bottom: 8px;
8297: border: 1px solid #2A4;
8298: border-radius: 5px;
8299: box-shadow: 0px 1px 1px #BBB;
8300: }
8301: section[class^="role-"]>h1 {
8302: position: relative;
8303: margin: 0px;
8304: padding-top: 10px;
8305: padding-left: 40px;
8306: }
8307: section[class^="role-"]>h1:before {
8308: position: absolute;
8309: left: -5px;
8310: top: 5px;
8311: }
8312: section.role-activity>h1:before {
8313: content:url('/adm/daxe/images/section_icons/activity.png');
8314: }
8315: section.role-advice>h1:before {
8316: content:url('/adm/daxe/images/section_icons/advice.png');
8317: }
8318: section.role-bibliography>h1:before {
8319: content:url('/adm/daxe/images/section_icons/bibliography.png');
8320: }
8321: section.role-citation>h1:before {
8322: content:url('/adm/daxe/images/section_icons/citation.png');
8323: }
8324: section.role-conclusion>h1:before {
8325: content:url('/adm/daxe/images/section_icons/conclusion.png');
8326: }
8327: section.role-definition>h1:before {
8328: content:url('/adm/daxe/images/section_icons/definition.png');
8329: }
8330: section.role-demonstration>h1:before {
8331: content:url('/adm/daxe/images/section_icons/demonstration.png');
8332: }
8333: section.role-example>h1:before {
8334: content:url('/adm/daxe/images/section_icons/example.png');
8335: }
8336: section.role-explanation>h1:before {
8337: content:url('/adm/daxe/images/section_icons/explanation.png');
8338: }
8339: section.role-introduction>h1:before {
8340: content:url('/adm/daxe/images/section_icons/introduction.png');
8341: }
8342: section.role-method>h1:before {
8343: content:url('/adm/daxe/images/section_icons/method.png');
8344: }
8345: section.role-more_information>h1:before {
8346: content:url('/adm/daxe/images/section_icons/more_information.png');
8347: }
8348: section.role-objectives>h1:before {
8349: content:url('/adm/daxe/images/section_icons/objectives.png');
8350: }
8351: section.role-prerequisites>h1:before {
8352: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8353: }
8354: section.role-remark>h1:before {
8355: content:url('/adm/daxe/images/section_icons/remark.png');
8356: }
8357: section.role-reminder>h1:before {
8358: content:url('/adm/daxe/images/section_icons/reminder.png');
8359: }
8360: section.role-summary>h1:before {
8361: content:url('/adm/daxe/images/section_icons/summary.png');
8362: }
8363: section.role-syntax>h1:before {
8364: content:url('/adm/daxe/images/section_icons/syntax.png');
8365: }
8366: section.role-warning>h1:before {
8367: content:url('/adm/daxe/images/section_icons/warning.png');
8368: }
8369:
1.1269 raeburn 8370: #LC_minitab_header {
8371: float:left;
8372: width:100%;
8373: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8374: font-size:93%;
8375: line-height:normal;
8376: margin: 0.5em 0 0.5em 0;
8377: }
8378: #LC_minitab_header ul {
8379: margin:0;
8380: padding:10px 10px 0;
8381: list-style:none;
8382: }
8383: #LC_minitab_header li {
8384: float:left;
8385: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8386: margin:0;
8387: padding:0 0 0 9px;
8388: }
8389: #LC_minitab_header a {
8390: display:block;
8391: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8392: padding:5px 15px 4px 6px;
8393: }
8394: #LC_minitab_header #LC_current_minitab {
8395: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8396: }
8397: #LC_minitab_header #LC_current_minitab a {
8398: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8399: padding-bottom:5px;
8400: }
8401:
8402:
1.343 albertel 8403: END
8404: }
8405:
1.306 albertel 8406: =pod
8407:
8408: =item * &headtag()
8409:
8410: Returns a uniform footer for LON-CAPA web pages.
8411:
1.307 albertel 8412: Inputs: $title - optional title for the head
8413: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8414: $args - optional arguments
1.319 albertel 8415: force_register - if is true call registerurl so the remote is
8416: informed
1.415 albertel 8417: redirect -> array ref of
8418: 1- seconds before redirect occurs
8419: 2- url to redirect to
8420: 3- whether the side effect should occur
1.315 albertel 8421: (side effect of setting
8422: $env{'internal.head.redirect'} to the url
8423: redirected too)
1.352 albertel 8424: domain -> force to color decorate a page for a specific
8425: domain
8426: function -> force usage of a specific rolish color scheme
8427: bgcolor -> override the default page bgcolor
1.460 albertel 8428: no_auto_mt_title
8429: -> prevent &mt()ing the title arg
1.464 albertel 8430:
1.306 albertel 8431: =cut
8432:
8433: sub headtag {
1.313 albertel 8434: my ($title,$head_extra,$args) = @_;
1.306 albertel 8435:
1.363 albertel 8436: my $function = $args->{'function'} || &get_users_function();
8437: my $domain = $args->{'domain'} || &determinedomain();
8438: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8439: my $httphost = $args->{'use_absolute'};
1.418 albertel 8440: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8441: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8442: #time(),
1.418 albertel 8443: $env{'environment.color.timestamp'},
1.363 albertel 8444: $function,$domain,$bgcolor);
8445:
1.369 www 8446: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8447:
1.308 albertel 8448: my $result =
8449: '<head>'.
1.1160 raeburn 8450: &font_settings($args);
1.319 albertel 8451:
1.1188 raeburn 8452: my $inhibitprint;
8453: if ($args->{'print_suppress'}) {
8454: $inhibitprint = &print_suppression();
8455: }
1.1064 raeburn 8456:
1.461 albertel 8457: if (!$args->{'frameset'}) {
8458: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8459: }
1.962 droeschl 8460: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8461: $result .= Apache::lonxml::display_title();
1.319 albertel 8462: }
1.436 albertel 8463: if (!$args->{'no_nav_bar'}
8464: && !$args->{'only_body'}
8465: && !$args->{'frameset'}) {
1.1154 raeburn 8466: $result .= &help_menu_js($httphost);
1.1032 www 8467: $result.=&modal_window();
1.1038 www 8468: $result.=&togglebox_script();
1.1034 www 8469: $result.=&wishlist_window();
1.1041 www 8470: $result.=&LCprogressbarUpdate_script();
1.1034 www 8471: } else {
8472: if ($args->{'add_modal'}) {
8473: $result.=&modal_window();
8474: }
8475: if ($args->{'add_wishlist'}) {
8476: $result.=&wishlist_window();
8477: }
1.1038 www 8478: if ($args->{'add_togglebox'}) {
8479: $result.=&togglebox_script();
8480: }
1.1041 www 8481: if ($args->{'add_progressbar'}) {
8482: $result.=&LCprogressbarUpdate_script();
8483: }
1.436 albertel 8484: }
1.314 albertel 8485: if (ref($args->{'redirect'})) {
1.414 albertel 8486: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8487: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8488: if (!$inhibit_continue) {
8489: $env{'internal.head.redirect'} = $url;
8490: }
1.313 albertel 8491: $result.=<<ADDMETA
8492: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8493: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8494: ADDMETA
1.1210 raeburn 8495: } else {
8496: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8497: my $requrl = $env{'request.uri'};
8498: if ($requrl eq '') {
8499: $requrl = $ENV{'REQUEST_URI'};
8500: $requrl =~ s/\?.+$//;
8501: }
8502: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8503: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8504: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8505: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8506: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8507: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
8508: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8509: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
8510: if ($domdefs{'offloadnow'}{$lonhost}) {
8511: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
8512: if (($newserver) && ($newserver ne $lonhost)) {
8513: my $numsec = 5;
8514: my $timeout = $numsec * 1000;
8515: my ($newurl,$locknum,%locks,$msg);
8516: if ($env{'request.role.adv'}) {
8517: ($locknum,%locks) = &Apache::lonnet::get_locks();
8518: }
8519: my $disable_submit = 0;
8520: if ($requrl =~ /$LONCAPA::assess_re/) {
8521: $disable_submit = 1;
8522: }
8523: if ($locknum) {
8524: my @lockinfo = sort(values(%locks));
8525: $msg = &mt('Once the following tasks are complete: ')."\\n".
8526: join(", ",sort(values(%locks)))."\\n".
8527: &mt('your session will be transferred to a different server, after you click "Roles".');
8528: } else {
8529: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8530: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
8531: }
8532: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8533: $newurl = '/adm/switchserver?otherserver='.$newserver;
8534: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8535: $newurl .= '&role='.$env{'request.role'};
8536: }
8537: if ($env{'request.symb'}) {
8538: $newurl .= '&symb='.$env{'request.symb'};
8539: } else {
8540: $newurl .= '&origurl='.$requrl;
8541: }
8542: }
1.1222 damieng 8543: &js_escape(\$msg);
1.1210 raeburn 8544: $result.=<<OFFLOAD
8545: <meta http-equiv="pragma" content="no-cache" />
8546: <script type="text/javascript">
1.1215 raeburn 8547: // <![CDATA[
1.1210 raeburn 8548: function LC_Offload_Now() {
8549: var dest = "$newurl";
8550: if (dest != '') {
8551: window.location.href="$newurl";
8552: }
8553: }
1.1214 raeburn 8554: \$(document).ready(function () {
8555: window.alert('$msg');
8556: if ($disable_submit) {
1.1210 raeburn 8557: \$(".LC_hwk_submit").prop("disabled", true);
8558: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8559: }
8560: setTimeout('LC_Offload_Now()', $timeout);
8561: });
1.1215 raeburn 8562: // ]]>
1.1210 raeburn 8563: </script>
8564: OFFLOAD
8565: }
8566: }
8567: }
8568: }
8569: }
8570: }
1.313 albertel 8571: }
1.306 albertel 8572: if (!defined($title)) {
8573: $title = 'The LearningOnline Network with CAPA';
8574: }
1.460 albertel 8575: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8576: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8577: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8578: if (!$args->{'frameset'}) {
8579: $result .= ' /';
8580: }
8581: $result .= '>'
1.1064 raeburn 8582: .$inhibitprint
1.414 albertel 8583: .$head_extra;
1.1242 raeburn 8584: my $clientmobile;
8585: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8586: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8587: } else {
8588: $clientmobile = $env{'browser.mobile'};
8589: }
8590: if ($clientmobile) {
1.1137 raeburn 8591: $result .= '
8592: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8593: <meta name="apple-mobile-web-app-capable" content="yes" />';
8594: }
1.1278 raeburn 8595: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8596: return $result.'</head>';
1.306 albertel 8597: }
8598:
8599: =pod
8600:
1.340 albertel 8601: =item * &font_settings()
8602:
8603: Returns neccessary <meta> to set the proper encoding
8604:
1.1160 raeburn 8605: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8606:
8607: =cut
8608:
8609: sub font_settings {
1.1160 raeburn 8610: my ($args) = @_;
1.340 albertel 8611: my $headerstring='';
1.1160 raeburn 8612: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8613: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8614: $headerstring.=
8615: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8616: if (!$args->{'frameset'}) {
8617: $headerstring.= ' /';
8618: }
8619: $headerstring .= '>'."\n";
1.340 albertel 8620: }
8621: return $headerstring;
8622: }
8623:
1.341 albertel 8624: =pod
8625:
1.1064 raeburn 8626: =item * &print_suppression()
8627:
8628: In course context returns css which causes the body to be blank when media="print",
8629: if printout generation is unavailable for the current resource.
8630:
8631: This could be because:
8632:
8633: (a) printstartdate is in the future
8634:
8635: (b) printenddate is in the past
8636:
8637: (c) there is an active exam block with "printout"
8638: functionality blocked
8639:
8640: Users with pav, pfo or evb privileges are exempt.
8641:
8642: Inputs: none
8643:
8644: =cut
8645:
8646:
8647: sub print_suppression {
8648: my $noprint;
8649: if ($env{'request.course.id'}) {
8650: my $scope = $env{'request.course.id'};
8651: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8652: (&Apache::lonnet::allowed('pfo',$scope))) {
8653: return;
8654: }
8655: if ($env{'request.course.sec'} ne '') {
8656: $scope .= "/$env{'request.course.sec'}";
8657: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8658: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8659: return;
1.1064 raeburn 8660: }
8661: }
8662: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8663: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8664: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8665: if ($blocked) {
8666: my $checkrole = "cm./$cdom/$cnum";
8667: if ($env{'request.course.sec'} ne '') {
8668: $checkrole .= "/$env{'request.course.sec'}";
8669: }
8670: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8671: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8672: $noprint = 1;
8673: }
8674: }
8675: unless ($noprint) {
8676: my $symb = &Apache::lonnet::symbread();
8677: if ($symb ne '') {
8678: my $navmap = Apache::lonnavmaps::navmap->new();
8679: if (ref($navmap)) {
8680: my $res = $navmap->getBySymb($symb);
8681: if (ref($res)) {
8682: if (!$res->resprintable()) {
8683: $noprint = 1;
8684: }
8685: }
8686: }
8687: }
8688: }
8689: if ($noprint) {
8690: return <<"ENDSTYLE";
8691: <style type="text/css" media="print">
8692: body { display:none }
8693: </style>
8694: ENDSTYLE
8695: }
8696: }
8697: return;
8698: }
8699:
8700: =pod
8701:
1.341 albertel 8702: =item * &xml_begin()
8703:
8704: Returns the needed doctype and <html>
8705:
8706: Inputs: none
8707:
8708: =cut
8709:
8710: sub xml_begin {
1.1168 raeburn 8711: my ($is_frameset) = @_;
1.341 albertel 8712: my $output='';
8713:
8714: if ($env{'browser.mathml'}) {
8715: $output='<?xml version="1.0"?>'
8716: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8717: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8718:
8719: # .'<!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">] >'
8720: .'<!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">'
8721: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8722: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8723: } elsif ($is_frameset) {
8724: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8725: '<html>'."\n";
1.341 albertel 8726: } else {
1.1168 raeburn 8727: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8728: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8729: }
8730: return $output;
8731: }
1.340 albertel 8732:
8733: =pod
8734:
1.306 albertel 8735: =item * &start_page()
8736:
8737: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8738:
1.648 raeburn 8739: Inputs:
8740:
8741: =over 4
8742:
8743: $title - optional title for the page
8744:
8745: $head_extra - optional extra HTML to incude inside the <head>
8746:
8747: $args - additional optional args supported are:
8748:
8749: =over 8
8750:
8751: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8752: arg on
1.814 bisitz 8753: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8754: add_entries -> additional attributes to add to the <body>
8755: domain -> force to color decorate a page for a
1.317 albertel 8756: specific domain
1.648 raeburn 8757: function -> force usage of a specific rolish color
1.317 albertel 8758: scheme
1.648 raeburn 8759: redirect -> see &headtag()
8760: bgcolor -> override the default page bg color
8761: js_ready -> return a string ready for being used in
1.317 albertel 8762: a javascript writeln
1.648 raeburn 8763: html_encode -> return a string ready for being used in
1.320 albertel 8764: a html attribute
1.648 raeburn 8765: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8766: $forcereg arg
1.648 raeburn 8767: frameset -> if true will start with a <frameset>
1.330 albertel 8768: rather than <body>
1.648 raeburn 8769: skip_phases -> hash ref of
1.338 albertel 8770: head -> skip the <html><head> generation
8771: body -> skip all <body> generation
1.648 raeburn 8772: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8773: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8774: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 8775: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8776: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 8777: group -> includes the current group, if page is for a
1.1274 raeburn 8778: specific group
8779: use_absolute -> for request for external resource or syllabus, this
8780: will contain https://<hostname> if server uses
8781: https (as per hosts.tab), but request is for http
8782: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8783:
1.648 raeburn 8784: =back
1.460 albertel 8785:
1.648 raeburn 8786: =back
1.562 albertel 8787:
1.306 albertel 8788: =cut
8789:
8790: sub start_page {
1.309 albertel 8791: my ($title,$head_extra,$args) = @_;
1.318 albertel 8792: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8793:
1.315 albertel 8794: $env{'internal.start_page'}++;
1.1318 raeburn 8795: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu);
1.964 droeschl 8796:
1.338 albertel 8797: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8798: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8799: }
1.1316 raeburn 8800:
8801: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 8802: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
8803: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
8804: $args->{'no_primary_menu'} = 1;
8805: }
8806: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
8807: $args->{'no_inline_menu'} = 1;
8808: }
8809: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
8810: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
8811: }
8812: } else {
8813: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8814: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
8815: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
8816: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
8817: $args->{'no_primary_menu'} = 1;
8818: }
8819: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
8820: $args->{'no_inline_menu'} = 1;
8821: }
8822: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
8823: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
8824: }
8825: }
8826: }
1.1316 raeburn 8827: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
8828: $env{'course.'.$env{'request.course.id'}.'.domain'},
8829: $env{'course.'.$env{'request.course.id'}.'.num'});
8830: }
1.338 albertel 8831:
8832: if (! exists($args->{'skip_phases'}{'body'}) ) {
8833: if ($args->{'frameset'}) {
8834: my $attr_string = &make_attr_string($args->{'force_register'},
8835: $args->{'add_entries'});
8836: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8837: } else {
8838: $result .=
8839: &bodytag($title,
8840: $args->{'function'}, $args->{'add_entries'},
8841: $args->{'only_body'}, $args->{'domain'},
8842: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8843: $args->{'bgcolor'}, $args,
1.1318 raeburn 8844: \@advtools,$ltiscope,$ltiuri,\%ltimenu);
1.831 bisitz 8845: }
1.330 albertel 8846: }
1.338 albertel 8847:
1.315 albertel 8848: if ($args->{'js_ready'}) {
1.713 kaisler 8849: $result = &js_ready($result);
1.315 albertel 8850: }
1.320 albertel 8851: if ($args->{'html_encode'}) {
1.713 kaisler 8852: $result = &html_encode($result);
8853: }
8854:
1.813 bisitz 8855: # Preparation for new and consistent functionlist at top of screen
8856: # if ($args->{'functionlist'}) {
8857: # $result .= &build_functionlist();
8858: #}
8859:
1.964 droeschl 8860: # Don't add anything more if only_body wanted or in const space
8861: return $result if $args->{'only_body'}
8862: || $env{'request.state'} eq 'construct';
1.813 bisitz 8863:
8864: #Breadcrumbs
1.758 kaisler 8865: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8866: &Apache::lonhtmlcommon::clear_breadcrumbs();
8867: #if any br links exists, add them to the breadcrumbs
8868: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8869: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8870: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8871: }
8872: }
1.1096 raeburn 8873: # if @advtools array contains items add then to the breadcrumbs
8874: if (@advtools > 0) {
8875: &Apache::lonmenu::advtools_crumbs(@advtools);
8876: }
1.1272 raeburn 8877: my $menulink;
8878: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8879: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 8880: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 8881: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
8882: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
8883: (!$env{'request.role.adv'}))) {
8884: $menulink = 0;
8885: } else {
8886: undef($menulink);
8887: }
1.758 kaisler 8888: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8889: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 8890: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 8891: } else {
1.1272 raeburn 8892: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8893: }
1.320 albertel 8894: }
1.315 albertel 8895: return $result;
1.306 albertel 8896: }
8897:
8898: sub end_page {
1.315 albertel 8899: my ($args) = @_;
8900: $env{'internal.end_page'}++;
1.330 albertel 8901: my $result;
1.335 albertel 8902: if ($args->{'discussion'}) {
8903: my ($target,$parser);
8904: if (ref($args->{'discussion'})) {
8905: ($target,$parser) =($args->{'discussion'}{'target'},
8906: $args->{'discussion'}{'parser'});
8907: }
8908: $result .= &Apache::lonxml::xmlend($target,$parser);
8909: }
1.330 albertel 8910: if ($args->{'frameset'}) {
8911: $result .= '</frameset>';
8912: } else {
1.635 raeburn 8913: $result .= &endbodytag($args);
1.330 albertel 8914: }
1.1080 raeburn 8915: unless ($args->{'notbody'}) {
8916: $result .= "\n</html>";
8917: }
1.330 albertel 8918:
1.315 albertel 8919: if ($args->{'js_ready'}) {
1.317 albertel 8920: $result = &js_ready($result);
1.315 albertel 8921: }
1.335 albertel 8922:
1.320 albertel 8923: if ($args->{'html_encode'}) {
8924: $result = &html_encode($result);
8925: }
1.335 albertel 8926:
1.315 albertel 8927: return $result;
8928: }
8929:
1.1034 www 8930: sub wishlist_window {
8931: return(<<'ENDWISHLIST');
1.1046 raeburn 8932: <script type="text/javascript">
1.1034 www 8933: // <![CDATA[
8934: // <!-- BEGIN LON-CAPA Internal
8935: function set_wishlistlink(title, path) {
8936: if (!title) {
8937: title = document.title;
8938: title = title.replace(/^LON-CAPA /,'');
8939: }
1.1175 raeburn 8940: title = encodeURIComponent(title);
1.1203 raeburn 8941: title = title.replace("'","\\\'");
1.1034 www 8942: if (!path) {
8943: path = location.pathname;
8944: }
1.1175 raeburn 8945: path = encodeURIComponent(path);
1.1203 raeburn 8946: path = path.replace("'","\\\'");
1.1034 www 8947: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8948: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8949: }
8950: // END LON-CAPA Internal -->
8951: // ]]>
8952: </script>
8953: ENDWISHLIST
8954: }
8955:
1.1030 www 8956: sub modal_window {
8957: return(<<'ENDMODAL');
1.1046 raeburn 8958: <script type="text/javascript">
1.1030 www 8959: // <![CDATA[
8960: // <!-- BEGIN LON-CAPA Internal
8961: var modalWindow = {
8962: parent:"body",
8963: windowId:null,
8964: content:null,
8965: width:null,
8966: height:null,
8967: close:function()
8968: {
8969: $(".LCmodal-window").remove();
8970: $(".LCmodal-overlay").remove();
8971: },
8972: open:function()
8973: {
8974: var modal = "";
8975: modal += "<div class=\"LCmodal-overlay\"></div>";
8976: 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;\">";
8977: modal += this.content;
8978: modal += "</div>";
8979:
8980: $(this.parent).append(modal);
8981:
8982: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8983: $(".LCclose-window").click(function(){modalWindow.close();});
8984: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8985: }
8986: };
1.1140 raeburn 8987: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8988: {
1.1266 raeburn 8989: source = source.replace(/'/g,"'");
1.1030 www 8990: modalWindow.windowId = "myModal";
8991: modalWindow.width = width;
8992: modalWindow.height = height;
1.1196 raeburn 8993: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8994: modalWindow.open();
1.1208 raeburn 8995: };
1.1030 www 8996: // END LON-CAPA Internal -->
8997: // ]]>
8998: </script>
8999: ENDMODAL
9000: }
9001:
9002: sub modal_link {
1.1140 raeburn 9003: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9004: unless ($width) { $width=480; }
9005: unless ($height) { $height=400; }
1.1031 www 9006: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 9007: unless ($transparency) { $transparency='true'; }
9008:
1.1074 raeburn 9009: my $target_attr;
9010: if (defined($target)) {
9011: $target_attr = 'target="'.$target.'"';
9012: }
9013: return <<"ENDLINK";
1.1140 raeburn 9014: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 9015: $linktext</a>
9016: ENDLINK
1.1030 www 9017: }
9018:
1.1032 www 9019: sub modal_adhoc_script {
9020: my ($funcname,$width,$height,$content)=@_;
9021: return (<<ENDADHOC);
1.1046 raeburn 9022: <script type="text/javascript">
1.1032 www 9023: // <![CDATA[
9024: var $funcname = function()
9025: {
9026: modalWindow.windowId = "myModal";
9027: modalWindow.width = $width;
9028: modalWindow.height = $height;
9029: modalWindow.content = '$content';
9030: modalWindow.open();
9031: };
9032: // ]]>
9033: </script>
9034: ENDADHOC
9035: }
9036:
1.1041 www 9037: sub modal_adhoc_inner {
9038: my ($funcname,$width,$height,$content)=@_;
9039: my $innerwidth=$width-20;
9040: $content=&js_ready(
1.1140 raeburn 9041: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
9042: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9043: $content.
1.1041 www 9044: &end_scrollbox().
1.1140 raeburn 9045: &end_page()
1.1041 www 9046: );
9047: return &modal_adhoc_script($funcname,$width,$height,$content);
9048: }
9049:
9050: sub modal_adhoc_window {
9051: my ($funcname,$width,$height,$content,$linktext)=@_;
9052: return &modal_adhoc_inner($funcname,$width,$height,$content).
9053: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9054: }
9055:
9056: sub modal_adhoc_launch {
9057: my ($funcname,$width,$height,$content)=@_;
9058: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9059: <script type="text/javascript">
9060: // <![CDATA[
9061: $funcname();
9062: // ]]>
9063: </script>
9064: ENDLAUNCH
9065: }
9066:
9067: sub modal_adhoc_close {
9068: return (<<ENDCLOSE);
9069: <script type="text/javascript">
9070: // <![CDATA[
9071: modalWindow.close();
9072: // ]]>
9073: </script>
9074: ENDCLOSE
9075: }
9076:
1.1038 www 9077: sub togglebox_script {
9078: return(<<ENDTOGGLE);
9079: <script type="text/javascript">
9080: // <![CDATA[
9081: function LCtoggleDisplay(id,hidetext,showtext) {
9082: link = document.getElementById(id + "link").childNodes[0];
9083: with (document.getElementById(id).style) {
9084: if (display == "none" ) {
9085: display = "inline";
9086: link.nodeValue = hidetext;
9087: } else {
9088: display = "none";
9089: link.nodeValue = showtext;
9090: }
9091: }
9092: }
9093: // ]]>
9094: </script>
9095: ENDTOGGLE
9096: }
9097:
1.1039 www 9098: sub start_togglebox {
9099: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9100: unless ($heading) { $heading=''; } else { $heading.=' '; }
9101: unless ($showtext) { $showtext=&mt('show'); }
9102: unless ($hidetext) { $hidetext=&mt('hide'); }
9103: unless ($headerbg) { $headerbg='#FFFFFF'; }
9104: return &start_data_table().
9105: &start_data_table_header_row().
9106: '<td bgcolor="'.$headerbg.'">'.$heading.
9107: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9108: $showtext.'\')">'.$showtext.'</a>]</td>'.
9109: &end_data_table_header_row().
9110: '<tr id="'.$id.'" style="display:none""><td>';
9111: }
9112:
9113: sub end_togglebox {
9114: return '</td></tr>'.&end_data_table();
9115: }
9116:
1.1041 www 9117: sub LCprogressbar_script {
1.1302 raeburn 9118: my ($id,$number_to_do)=@_;
9119: if ($number_to_do) {
9120: return(<<ENDPROGRESS);
1.1041 www 9121: <script type="text/javascript">
9122: // <![CDATA[
1.1045 www 9123: \$('#progressbar$id').progressbar({
1.1041 www 9124: value: 0,
9125: change: function(event, ui) {
9126: var newVal = \$(this).progressbar('option', 'value');
9127: \$('.pblabel', this).text(LCprogressTxt);
9128: }
9129: });
9130: // ]]>
9131: </script>
9132: ENDPROGRESS
1.1302 raeburn 9133: } else {
9134: return(<<ENDPROGRESS);
9135: <script type="text/javascript">
9136: // <![CDATA[
9137: \$('#progressbar$id').progressbar({
9138: value: false,
9139: create: function(event, ui) {
9140: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9141: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9142: }
9143: });
9144: // ]]>
9145: </script>
9146: ENDPROGRESS
9147: }
1.1041 www 9148: }
9149:
9150: sub LCprogressbarUpdate_script {
9151: return(<<ENDPROGRESSUPDATE);
9152: <style type="text/css">
9153: .ui-progressbar { position:relative; }
1.1302 raeburn 9154: .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 9155: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9156: </style>
9157: <script type="text/javascript">
9158: // <![CDATA[
1.1045 www 9159: var LCprogressTxt='---';
9160:
1.1302 raeburn 9161: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9162: LCprogressTxt=progresstext;
1.1302 raeburn 9163: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9164: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9165: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 9166: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9167: } else {
9168: \$('#progressbar'+id).progressbar('value',percent);
9169: }
1.1041 www 9170: }
9171: // ]]>
9172: </script>
9173: ENDPROGRESSUPDATE
9174: }
9175:
1.1042 www 9176: my $LClastpercent;
1.1045 www 9177: my $LCidcnt;
9178: my $LCcurrentid;
1.1042 www 9179:
1.1041 www 9180: sub LCprogressbar {
1.1302 raeburn 9181: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9182: $LClastpercent=0;
1.1045 www 9183: $LCidcnt++;
9184: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 9185: my ($starting,$content);
9186: if ($number_to_do) {
9187: $starting=&mt('Starting');
9188: $content=(<<ENDPROGBAR);
9189: $preamble
1.1045 www 9190: <div id="progressbar$LCcurrentid">
1.1041 www 9191: <span class="pblabel">$starting</span>
9192: </div>
9193: ENDPROGBAR
1.1302 raeburn 9194: } else {
9195: $starting=&mt('Loading...');
9196: $LClastpercent='false';
9197: $content=(<<ENDPROGBAR);
9198: $preamble
9199: <div id="progressbar$LCcurrentid">
9200: <div class="progress-label">$starting</div>
9201: </div>
9202: ENDPROGBAR
9203: }
9204: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9205: }
9206:
9207: sub LCprogressbarUpdate {
1.1302 raeburn 9208: my ($r,$val,$text,$number_to_do)=@_;
9209: if ($number_to_do) {
9210: unless ($val) {
9211: if ($LClastpercent) {
9212: $val=$LClastpercent;
9213: } else {
9214: $val=0;
9215: }
9216: }
9217: if ($val<0) { $val=0; }
9218: if ($val>100) { $val=0; }
9219: $LClastpercent=$val;
9220: unless ($text) { $text=$val.'%'; }
9221: } else {
9222: $val = 'false';
1.1042 www 9223: }
1.1041 www 9224: $text=&js_ready($text);
1.1044 www 9225: &r_print($r,<<ENDUPDATE);
1.1041 www 9226: <script type="text/javascript">
9227: // <![CDATA[
1.1302 raeburn 9228: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9229: // ]]>
9230: </script>
9231: ENDUPDATE
1.1035 www 9232: }
9233:
1.1042 www 9234: sub LCprogressbarClose {
9235: my ($r)=@_;
9236: $LClastpercent=0;
1.1044 www 9237: &r_print($r,<<ENDCLOSE);
1.1042 www 9238: <script type="text/javascript">
9239: // <![CDATA[
1.1045 www 9240: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9241: // ]]>
9242: </script>
9243: ENDCLOSE
1.1044 www 9244: }
9245:
9246: sub r_print {
9247: my ($r,$to_print)=@_;
9248: if ($r) {
9249: $r->print($to_print);
9250: $r->rflush();
9251: } else {
9252: print($to_print);
9253: }
1.1042 www 9254: }
9255:
1.320 albertel 9256: sub html_encode {
9257: my ($result) = @_;
9258:
1.322 albertel 9259: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9260:
9261: return $result;
9262: }
1.1044 www 9263:
1.317 albertel 9264: sub js_ready {
9265: my ($result) = @_;
9266:
1.323 albertel 9267: $result =~ s/[\n\r]/ /xmsg;
9268: $result =~ s/\\/\\\\/xmsg;
9269: $result =~ s/'/\\'/xmsg;
1.372 albertel 9270: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9271:
9272: return $result;
9273: }
9274:
1.315 albertel 9275: sub validate_page {
9276: if ( exists($env{'internal.start_page'})
1.316 albertel 9277: && $env{'internal.start_page'} > 1) {
9278: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9279: $env{'internal.start_page'}.' '.
1.316 albertel 9280: $ENV{'request.filename'});
1.315 albertel 9281: }
9282: if ( exists($env{'internal.end_page'})
1.316 albertel 9283: && $env{'internal.end_page'} > 1) {
9284: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9285: $env{'internal.end_page'}.' '.
1.316 albertel 9286: $env{'request.filename'});
1.315 albertel 9287: }
9288: if ( exists($env{'internal.start_page'})
9289: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9290: &Apache::lonnet::logthis('start_page called without end_page '.
9291: $env{'request.filename'});
1.315 albertel 9292: }
9293: if ( ! exists($env{'internal.start_page'})
9294: && exists($env{'internal.end_page'})) {
1.316 albertel 9295: &Apache::lonnet::logthis('end_page called without start_page'.
9296: $env{'request.filename'});
1.315 albertel 9297: }
1.306 albertel 9298: }
1.315 albertel 9299:
1.996 www 9300:
9301: sub start_scrollbox {
1.1140 raeburn 9302: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9303: unless ($outerwidth) { $outerwidth='520px'; }
9304: unless ($width) { $width='500px'; }
9305: unless ($height) { $height='200px'; }
1.1075 raeburn 9306: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9307: if ($id ne '') {
1.1140 raeburn 9308: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9309: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9310: }
1.1075 raeburn 9311: if ($bgcolor ne '') {
9312: $tdcol = "background-color: $bgcolor;";
9313: }
1.1137 raeburn 9314: my $nicescroll_js;
9315: if ($env{'browser.mobile'}) {
1.1140 raeburn 9316: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9317: }
9318: return <<"END";
9319: $nicescroll_js
9320:
9321: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9322: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9323: END
9324: }
9325:
9326: sub end_scrollbox {
9327: return '</div></td></tr></table>';
9328: }
9329:
9330: sub nicescroll_javascript {
9331: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9332: my %options;
9333: if (ref($cursor) eq 'HASH') {
9334: %options = %{$cursor};
9335: }
9336: unless ($options{'railalign'} =~ /^left|right$/) {
9337: $options{'railalign'} = 'left';
9338: }
9339: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9340: my $function = &get_users_function();
9341: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9342: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9343: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9344: }
1.1140 raeburn 9345: }
9346: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9347: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9348: $options{'cursoropacity'}='1.0';
9349: }
1.1140 raeburn 9350: } else {
9351: $options{'cursoropacity'}='1.0';
9352: }
9353: if ($options{'cursorfixedheight'} eq 'none') {
9354: delete($options{'cursorfixedheight'});
9355: } else {
9356: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9357: }
9358: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9359: delete($options{'railoffset'});
9360: }
9361: my @niceoptions;
9362: while (my($key,$value) = each(%options)) {
9363: if ($value =~ /^\{.+\}$/) {
9364: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9365: } else {
1.1140 raeburn 9366: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9367: }
1.1140 raeburn 9368: }
9369: my $nicescroll_js = '
1.1137 raeburn 9370: $(document).ready(
1.1140 raeburn 9371: function() {
9372: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9373: }
1.1137 raeburn 9374: );
9375: ';
1.1140 raeburn 9376: if ($framecheck) {
9377: $nicescroll_js .= '
9378: function expand_div(caller) {
9379: if (top === self) {
9380: document.getElementById("'.$id.'").style.width = "auto";
9381: document.getElementById("'.$id.'").style.height = "auto";
9382: } else {
9383: try {
9384: if (parent.frames) {
9385: if (parent.frames.length > 1) {
9386: var framesrc = parent.frames[1].location.href;
9387: var currsrc = framesrc.replace(/\#.*$/,"");
9388: if ((caller == "search") || (currsrc == "'.$location.'")) {
9389: document.getElementById("'.$id.'").style.width = "auto";
9390: document.getElementById("'.$id.'").style.height = "auto";
9391: }
9392: }
9393: }
9394: } catch (e) {
9395: return;
9396: }
1.1137 raeburn 9397: }
1.1140 raeburn 9398: return;
1.996 www 9399: }
1.1140 raeburn 9400: ';
9401: }
9402: if ($needjsready) {
9403: $nicescroll_js = '
9404: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9405: } else {
9406: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9407: }
9408: return $nicescroll_js;
1.996 www 9409: }
9410:
1.318 albertel 9411: sub simple_error_page {
1.1150 bisitz 9412: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 9413: my %displayargs;
1.1151 raeburn 9414: if (ref($args) eq 'HASH') {
9415: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 9416: if ($args->{'only_body'}) {
9417: $displayargs{'only_body'} = 1;
9418: }
9419: if ($args->{'no_nav_bar'}) {
9420: $displayargs{'no_nav_bar'} = 1;
9421: }
1.1151 raeburn 9422: } else {
9423: $msg = &mt($msg);
9424: }
1.1150 bisitz 9425:
1.318 albertel 9426: my $page =
1.1304 raeburn 9427: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 9428: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9429: &Apache::loncommon::end_page();
9430: if (ref($r)) {
9431: $r->print($page);
1.327 albertel 9432: return;
1.318 albertel 9433: }
9434: return $page;
9435: }
1.347 albertel 9436:
9437: {
1.610 albertel 9438: my @row_count;
1.961 onken 9439:
9440: sub start_data_table_count {
9441: unshift(@row_count, 0);
9442: return;
9443: }
9444:
9445: sub end_data_table_count {
9446: shift(@row_count);
9447: return;
9448: }
9449:
1.347 albertel 9450: sub start_data_table {
1.1018 raeburn 9451: my ($add_class,$id) = @_;
1.422 albertel 9452: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9453: my $table_id;
9454: if (defined($id)) {
9455: $table_id = ' id="'.$id.'"';
9456: }
1.961 onken 9457: &start_data_table_count();
1.1018 raeburn 9458: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9459: }
9460:
9461: sub end_data_table {
1.961 onken 9462: &end_data_table_count();
1.389 albertel 9463: return '</table>'."\n";;
1.347 albertel 9464: }
9465:
9466: sub start_data_table_row {
1.974 wenzelju 9467: my ($add_class, $id) = @_;
1.610 albertel 9468: $row_count[0]++;
9469: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9470: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9471: $id = (' id="'.$id.'"') unless ($id eq '');
9472: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9473: }
1.471 banghart 9474:
9475: sub continue_data_table_row {
1.974 wenzelju 9476: my ($add_class, $id) = @_;
1.610 albertel 9477: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9478: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9479: $id = (' id="'.$id.'"') unless ($id eq '');
9480: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9481: }
1.347 albertel 9482:
9483: sub end_data_table_row {
1.389 albertel 9484: return '</tr>'."\n";;
1.347 albertel 9485: }
1.367 www 9486:
1.421 albertel 9487: sub start_data_table_empty_row {
1.707 bisitz 9488: # $row_count[0]++;
1.421 albertel 9489: return '<tr class="LC_empty_row" >'."\n";;
9490: }
9491:
9492: sub end_data_table_empty_row {
9493: return '</tr>'."\n";;
9494: }
9495:
1.367 www 9496: sub start_data_table_header_row {
1.389 albertel 9497: return '<tr class="LC_header_row">'."\n";;
1.367 www 9498: }
9499:
9500: sub end_data_table_header_row {
1.389 albertel 9501: return '</tr>'."\n";;
1.367 www 9502: }
1.890 droeschl 9503:
9504: sub data_table_caption {
9505: my $caption = shift;
9506: return "<caption class=\"LC_caption\">$caption</caption>";
9507: }
1.347 albertel 9508: }
9509:
1.548 albertel 9510: =pod
9511:
9512: =item * &inhibit_menu_check($arg)
9513:
9514: Checks for a inhibitmenu state and generates output to preserve it
9515:
9516: Inputs: $arg - can be any of
9517: - undef - in which case the return value is a string
9518: to add into arguments list of a uri
9519: - 'input' - in which case the return value is a HTML
9520: <form> <input> field of type hidden to
9521: preserve the value
9522: - a url - in which case the return value is the url with
9523: the neccesary cgi args added to preserve the
9524: inhibitmenu state
9525: - a ref to a url - no return value, but the string is
9526: updated to include the neccessary cgi
9527: args to preserve the inhibitmenu state
9528:
9529: =cut
9530:
9531: sub inhibit_menu_check {
9532: my ($arg) = @_;
9533: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9534: if ($arg eq 'input') {
9535: if ($env{'form.inhibitmenu'}) {
9536: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9537: } else {
9538: return
9539: }
9540: }
9541: if ($env{'form.inhibitmenu'}) {
9542: if (ref($arg)) {
9543: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9544: } elsif ($arg eq '') {
9545: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9546: } else {
9547: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9548: }
9549: }
9550: if (!ref($arg)) {
9551: return $arg;
9552: }
9553: }
9554:
1.251 albertel 9555: ###############################################
1.182 matthew 9556:
9557: =pod
9558:
1.549 albertel 9559: =back
9560:
9561: =head1 User Information Routines
9562:
9563: =over 4
9564:
1.405 albertel 9565: =item * &get_users_function()
1.182 matthew 9566:
9567: Used by &bodytag to determine the current users primary role.
9568: Returns either 'student','coordinator','admin', or 'author'.
9569:
9570: =cut
9571:
9572: ###############################################
9573: sub get_users_function {
1.815 tempelho 9574: my $function = 'norole';
1.818 tempelho 9575: if ($env{'request.role'}=~/^(st)/) {
9576: $function='student';
9577: }
1.907 raeburn 9578: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9579: $function='coordinator';
9580: }
1.258 albertel 9581: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9582: $function='admin';
9583: }
1.826 bisitz 9584: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9585: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9586: $function='author';
9587: }
9588: return $function;
1.54 www 9589: }
1.99 www 9590:
9591: ###############################################
9592:
1.233 raeburn 9593: =pod
9594:
1.821 raeburn 9595: =item * &show_course()
9596:
9597: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9598: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9599:
9600: Inputs:
9601: None
9602:
9603: Outputs:
9604: Scalar: 1 if 'Course' to be used, 0 otherwise.
9605:
9606: =cut
9607:
9608: ###############################################
9609: sub show_course {
9610: my $course = !$env{'user.adv'};
9611: if (!$env{'user.adv'}) {
9612: foreach my $env (keys(%env)) {
9613: next if ($env !~ m/^user\.priv\./);
9614: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9615: $course = 0;
9616: last;
9617: }
9618: }
9619: }
9620: return $course;
9621: }
9622:
9623: ###############################################
9624:
9625: =pod
9626:
1.542 raeburn 9627: =item * &check_user_status()
1.274 raeburn 9628:
9629: Determines current status of supplied role for a
9630: specific user. Roles can be active, previous or future.
9631:
9632: Inputs:
9633: user's domain, user's username, course's domain,
1.375 raeburn 9634: course's number, optional section ID.
1.274 raeburn 9635:
9636: Outputs:
9637: role status: active, previous or future.
9638:
9639: =cut
9640:
9641: sub check_user_status {
1.412 raeburn 9642: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9643: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9644: my @uroles = keys(%userinfo);
1.274 raeburn 9645: my $srchstr;
9646: my $active_chk = 'none';
1.412 raeburn 9647: my $now = time;
1.274 raeburn 9648: if (@uroles > 0) {
1.908 raeburn 9649: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9650: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9651: } else {
1.412 raeburn 9652: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9653: }
9654: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9655: my $role_end = 0;
9656: my $role_start = 0;
9657: $active_chk = 'active';
1.412 raeburn 9658: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9659: $role_end = $1;
9660: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9661: $role_start = $1;
1.274 raeburn 9662: }
9663: }
9664: if ($role_start > 0) {
1.412 raeburn 9665: if ($now < $role_start) {
1.274 raeburn 9666: $active_chk = 'future';
9667: }
9668: }
9669: if ($role_end > 0) {
1.412 raeburn 9670: if ($now > $role_end) {
1.274 raeburn 9671: $active_chk = 'previous';
9672: }
9673: }
9674: }
9675: }
9676: return $active_chk;
9677: }
9678:
9679: ###############################################
9680:
9681: =pod
9682:
1.405 albertel 9683: =item * &get_sections()
1.233 raeburn 9684:
9685: Determines all the sections for a course including
9686: sections with students and sections containing other roles.
1.419 raeburn 9687: Incoming parameters:
9688:
9689: 1. domain
9690: 2. course number
9691: 3. reference to array containing roles for which sections should
9692: be gathered (optional).
9693: 4. reference to array containing status types for which sections
9694: should be gathered (optional).
9695:
9696: If the third argument is undefined, sections are gathered for any role.
9697: If the fourth argument is undefined, sections are gathered for any status.
9698: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9699:
1.374 raeburn 9700: Returns section hash (keys are section IDs, values are
9701: number of users in each section), subject to the
1.419 raeburn 9702: optional roles filter, optional status filter
1.233 raeburn 9703:
9704: =cut
9705:
9706: ###############################################
9707: sub get_sections {
1.419 raeburn 9708: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9709: if (!defined($cdom) || !defined($cnum)) {
9710: my $cid = $env{'request.course.id'};
9711:
9712: return if (!defined($cid));
9713:
9714: $cdom = $env{'course.'.$cid.'.domain'};
9715: $cnum = $env{'course.'.$cid.'.num'};
9716: }
9717:
9718: my %sectioncount;
1.419 raeburn 9719: my $now = time;
1.240 albertel 9720:
1.1118 raeburn 9721: my $check_students = 1;
9722: my $only_students = 0;
9723: if (ref($possible_roles) eq 'ARRAY') {
9724: if (grep(/^st$/,@{$possible_roles})) {
9725: if (@{$possible_roles} == 1) {
9726: $only_students = 1;
9727: }
9728: } else {
9729: $check_students = 0;
9730: }
9731: }
9732:
9733: if ($check_students) {
1.276 albertel 9734: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9735: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9736: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9737: my $start_index = &Apache::loncoursedata::CL_START();
9738: my $end_index = &Apache::loncoursedata::CL_END();
9739: my $status;
1.366 albertel 9740: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9741: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9742: $data->[$status_index],
9743: $data->[$start_index],
9744: $data->[$end_index]);
9745: if ($stu_status eq 'Active') {
9746: $status = 'active';
9747: } elsif ($end < $now) {
9748: $status = 'previous';
9749: } elsif ($start > $now) {
9750: $status = 'future';
9751: }
9752: if ($section ne '-1' && $section !~ /^\s*$/) {
9753: if ((!defined($possible_status)) || (($status ne '') &&
9754: (grep/^\Q$status\E$/,@{$possible_status}))) {
9755: $sectioncount{$section}++;
9756: }
1.240 albertel 9757: }
9758: }
9759: }
1.1118 raeburn 9760: if ($only_students) {
9761: return %sectioncount;
9762: }
1.240 albertel 9763: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9764: foreach my $user (sort(keys(%courseroles))) {
9765: if ($user !~ /^(\w{2})/) { next; }
9766: my ($role) = ($user =~ /^(\w{2})/);
9767: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9768: my ($section,$status);
1.240 albertel 9769: if ($role eq 'cr' &&
9770: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9771: $section=$1;
9772: }
9773: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9774: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9775: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9776: if ($end == -1 && $start == -1) {
9777: next; #deleted role
9778: }
9779: if (!defined($possible_status)) {
9780: $sectioncount{$section}++;
9781: } else {
9782: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9783: $status = 'active';
9784: } elsif ($end < $now) {
9785: $status = 'future';
9786: } elsif ($start > $now) {
9787: $status = 'previous';
9788: }
9789: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9790: $sectioncount{$section}++;
9791: }
9792: }
1.233 raeburn 9793: }
1.366 albertel 9794: return %sectioncount;
1.233 raeburn 9795: }
9796:
1.274 raeburn 9797: ###############################################
1.294 raeburn 9798:
9799: =pod
1.405 albertel 9800:
9801: =item * &get_course_users()
9802:
1.275 raeburn 9803: Retrieves usernames:domains for users in the specified course
9804: with specific role(s), and access status.
9805:
9806: Incoming parameters:
1.277 albertel 9807: 1. course domain
9808: 2. course number
9809: 3. access status: users must have - either active,
1.275 raeburn 9810: previous, future, or all.
1.277 albertel 9811: 4. reference to array of permissible roles
1.288 raeburn 9812: 5. reference to array of section restrictions (optional)
9813: 6. reference to results object (hash of hashes).
9814: 7. reference to optional userdata hash
1.609 raeburn 9815: 8. reference to optional statushash
1.630 raeburn 9816: 9. flag if privileged users (except those set to unhide in
9817: course settings) should be excluded
1.609 raeburn 9818: Keys of top level results hash are roles.
1.275 raeburn 9819: Keys of inner hashes are username:domain, with
9820: values set to access type.
1.288 raeburn 9821: Optional userdata hash returns an array with arguments in the
9822: same order as loncoursedata::get_classlist() for student data.
9823:
1.609 raeburn 9824: Optional statushash returns
9825:
1.288 raeburn 9826: Entries for end, start, section and status are blank because
9827: of the possibility of multiple values for non-student roles.
9828:
1.275 raeburn 9829: =cut
1.405 albertel 9830:
1.275 raeburn 9831: ###############################################
1.405 albertel 9832:
1.275 raeburn 9833: sub get_course_users {
1.630 raeburn 9834: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9835: my %idx = ();
1.419 raeburn 9836: my %seclists;
1.288 raeburn 9837:
9838: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9839: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9840: $idx{end} = &Apache::loncoursedata::CL_END();
9841: $idx{start} = &Apache::loncoursedata::CL_START();
9842: $idx{id} = &Apache::loncoursedata::CL_ID();
9843: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9844: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9845: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9846:
1.290 albertel 9847: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9848: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9849: my $now = time;
1.277 albertel 9850: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9851: my $match = 0;
1.412 raeburn 9852: my $secmatch = 0;
1.419 raeburn 9853: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9854: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9855: if ($section eq '') {
9856: $section = 'none';
9857: }
1.291 albertel 9858: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9859: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9860: $secmatch = 1;
9861: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9862: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9863: $secmatch = 1;
9864: }
9865: } else {
1.419 raeburn 9866: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9867: $secmatch = 1;
9868: }
1.290 albertel 9869: }
1.412 raeburn 9870: if (!$secmatch) {
9871: next;
9872: }
1.419 raeburn 9873: }
1.275 raeburn 9874: if (defined($$types{'active'})) {
1.288 raeburn 9875: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9876: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9877: $match = 1;
1.275 raeburn 9878: }
9879: }
9880: if (defined($$types{'previous'})) {
1.609 raeburn 9881: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9882: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9883: $match = 1;
1.275 raeburn 9884: }
9885: }
9886: if (defined($$types{'future'})) {
1.609 raeburn 9887: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9888: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9889: $match = 1;
1.275 raeburn 9890: }
9891: }
1.609 raeburn 9892: if ($match) {
9893: push(@{$seclists{$student}},$section);
9894: if (ref($userdata) eq 'HASH') {
9895: $$userdata{$student} = $$classlist{$student};
9896: }
9897: if (ref($statushash) eq 'HASH') {
9898: $statushash->{$student}{'st'}{$section} = $status;
9899: }
1.288 raeburn 9900: }
1.275 raeburn 9901: }
9902: }
1.412 raeburn 9903: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9904: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9905: my $now = time;
1.609 raeburn 9906: my %displaystatus = ( previous => 'Expired',
9907: active => 'Active',
9908: future => 'Future',
9909: );
1.1121 raeburn 9910: my (%nothide,@possdoms);
1.630 raeburn 9911: if ($hidepriv) {
9912: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9913: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9914: if ($user !~ /:/) {
9915: $nothide{join(':',split(/[\@]/,$user))}=1;
9916: } else {
9917: $nothide{$user} = 1;
9918: }
9919: }
1.1121 raeburn 9920: my @possdoms = ($cdom);
9921: if ($coursehash{'checkforpriv'}) {
9922: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9923: }
1.630 raeburn 9924: }
1.439 raeburn 9925: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9926: my $match = 0;
1.412 raeburn 9927: my $secmatch = 0;
1.439 raeburn 9928: my $status;
1.412 raeburn 9929: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9930: $user =~ s/:$//;
1.439 raeburn 9931: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9932: if ($end == -1 || $start == -1) {
9933: next;
9934: }
9935: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9936: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9937: my ($uname,$udom) = split(/:/,$user);
9938: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9939: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9940: $secmatch = 1;
9941: } elsif ($usec eq '') {
1.420 albertel 9942: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9943: $secmatch = 1;
9944: }
9945: } else {
9946: if (grep(/^\Q$usec\E$/,@{$sections})) {
9947: $secmatch = 1;
9948: }
9949: }
9950: if (!$secmatch) {
9951: next;
9952: }
1.288 raeburn 9953: }
1.419 raeburn 9954: if ($usec eq '') {
9955: $usec = 'none';
9956: }
1.275 raeburn 9957: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9958: if ($hidepriv) {
1.1121 raeburn 9959: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9960: (!$nothide{$uname.':'.$udom})) {
9961: next;
9962: }
9963: }
1.503 raeburn 9964: if ($end > 0 && $end < $now) {
1.439 raeburn 9965: $status = 'previous';
9966: } elsif ($start > $now) {
9967: $status = 'future';
9968: } else {
9969: $status = 'active';
9970: }
1.277 albertel 9971: foreach my $type (keys(%{$types})) {
1.275 raeburn 9972: if ($status eq $type) {
1.420 albertel 9973: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9974: push(@{$$users{$role}{$user}},$type);
9975: }
1.288 raeburn 9976: $match = 1;
9977: }
9978: }
1.419 raeburn 9979: if (($match) && (ref($userdata) eq 'HASH')) {
9980: if (!exists($$userdata{$uname.':'.$udom})) {
9981: &get_user_info($udom,$uname,\%idx,$userdata);
9982: }
1.420 albertel 9983: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9984: push(@{$seclists{$uname.':'.$udom}},$usec);
9985: }
1.609 raeburn 9986: if (ref($statushash) eq 'HASH') {
9987: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9988: }
1.275 raeburn 9989: }
9990: }
9991: }
9992: }
1.290 albertel 9993: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9994: if ((defined($cdom)) && (defined($cnum))) {
9995: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9996: if ( defined($csettings{'internal.courseowner'}) ) {
9997: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9998: next if ($owner eq '');
9999: my ($ownername,$ownerdom);
10000: if ($owner =~ /^([^:]+):([^:]+)$/) {
10001: $ownername = $1;
10002: $ownerdom = $2;
10003: } else {
10004: $ownername = $owner;
10005: $ownerdom = $cdom;
10006: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10007: }
10008: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10009: if (defined($userdata) &&
1.609 raeburn 10010: !exists($$userdata{$owner})) {
10011: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10012: if (!grep(/^none$/,@{$seclists{$owner}})) {
10013: push(@{$seclists{$owner}},'none');
10014: }
10015: if (ref($statushash) eq 'HASH') {
10016: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10017: }
1.290 albertel 10018: }
1.279 raeburn 10019: }
10020: }
10021: }
1.419 raeburn 10022: foreach my $user (keys(%seclists)) {
10023: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10024: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10025: }
1.275 raeburn 10026: }
10027: return;
10028: }
10029:
1.288 raeburn 10030: sub get_user_info {
10031: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10032: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10033: &plainname($uname,$udom,'lastname');
1.291 albertel 10034: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10035: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10036: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10037: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10038: return;
10039: }
1.275 raeburn 10040:
1.472 raeburn 10041: ###############################################
10042:
10043: =pod
10044:
10045: =item * &get_user_quota()
10046:
1.1134 raeburn 10047: Retrieves quota assigned for storage of user files.
10048: Default is to report quota for portfolio files.
1.472 raeburn 10049:
10050: Incoming parameters:
10051: 1. user's username
10052: 2. user's domain
1.1134 raeburn 10053: 3. quota name - portfolio, author, or course
1.1136 raeburn 10054: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 10055: 4. crstype - official, unofficial, textbook, placement or community,
10056: if quota name is course
1.472 raeburn 10057:
10058: Returns:
1.1163 raeburn 10059: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10060: 2. (Optional) Type of setting: custom or default
10061: (individually assigned or default for user's
10062: institutional status).
10063: 3. (Optional) - User's institutional status (e.g., faculty, staff
10064: or student - types as defined in localenroll::inst_usertypes
10065: for user's domain, which determines default quota for user.
10066: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10067:
10068: If a value has been stored in the user's environment,
1.536 raeburn 10069: it will return that, otherwise it returns the maximal default
1.1134 raeburn 10070: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10071:
10072: =cut
10073:
10074: ###############################################
10075:
10076:
10077: sub get_user_quota {
1.1136 raeburn 10078: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10079: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10080: if (!defined($udom)) {
10081: $udom = $env{'user.domain'};
10082: }
10083: if (!defined($uname)) {
10084: $uname = $env{'user.name'};
10085: }
10086: if (($udom eq '' || $uname eq '') ||
10087: ($udom eq 'public') && ($uname eq 'public')) {
10088: $quota = 0;
1.536 raeburn 10089: $quotatype = 'default';
10090: $defquota = 0;
1.472 raeburn 10091: } else {
1.536 raeburn 10092: my $inststatus;
1.1134 raeburn 10093: if ($quotaname eq 'course') {
10094: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10095: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10096: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10097: } else {
10098: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10099: $quota = $cenv{'internal.uploadquota'};
10100: }
1.536 raeburn 10101: } else {
1.1134 raeburn 10102: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10103: if ($quotaname eq 'author') {
10104: $quota = $env{'environment.authorquota'};
10105: } else {
10106: $quota = $env{'environment.portfolioquota'};
10107: }
10108: $inststatus = $env{'environment.inststatus'};
10109: } else {
10110: my %userenv =
10111: &Apache::lonnet::get('environment',['portfolioquota',
10112: 'authorquota','inststatus'],$udom,$uname);
10113: my ($tmp) = keys(%userenv);
10114: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10115: if ($quotaname eq 'author') {
10116: $quota = $userenv{'authorquota'};
10117: } else {
10118: $quota = $userenv{'portfolioquota'};
10119: }
10120: $inststatus = $userenv{'inststatus'};
10121: } else {
10122: undef(%userenv);
10123: }
10124: }
10125: }
10126: if ($quota eq '' || wantarray) {
10127: if ($quotaname eq 'course') {
10128: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 10129: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 10130: ($crstype eq 'community') || ($crstype eq 'textbook') ||
10131: ($crstype eq 'placement')) {
1.1136 raeburn 10132: $defquota = $domdefs{$crstype.'quota'};
10133: }
10134: if ($defquota eq '') {
10135: $defquota = 500;
10136: }
1.1134 raeburn 10137: } else {
10138: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10139: }
10140: if ($quota eq '') {
10141: $quota = $defquota;
10142: $quotatype = 'default';
10143: } else {
10144: $quotatype = 'custom';
10145: }
1.472 raeburn 10146: }
10147: }
1.536 raeburn 10148: if (wantarray) {
10149: return ($quota,$quotatype,$settingstatus,$defquota);
10150: } else {
10151: return $quota;
10152: }
1.472 raeburn 10153: }
10154:
10155: ###############################################
10156:
10157: =pod
10158:
10159: =item * &default_quota()
10160:
1.536 raeburn 10161: Retrieves default quota assigned for storage of user portfolio files,
10162: given an (optional) user's institutional status.
1.472 raeburn 10163:
10164: Incoming parameters:
1.1142 raeburn 10165:
1.472 raeburn 10166: 1. domain
1.536 raeburn 10167: 2. (Optional) institutional status(es). This is a : separated list of
10168: status types (e.g., faculty, staff, student etc.)
10169: which apply to the user for whom the default is being retrieved.
10170: If the institutional status string in undefined, the domain
1.1134 raeburn 10171: default quota will be returned.
10172: 3. quota name - portfolio, author, or course
10173: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10174:
10175: Returns:
1.1142 raeburn 10176:
1.1163 raeburn 10177: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10178: 2. (Optional) institutional type which determined the value of the
10179: default quota.
1.472 raeburn 10180:
10181: If a value has been stored in the domain's configuration db,
10182: it will return that, otherwise it returns 20 (for backwards
10183: compatibility with domains which have not set up a configuration
1.1163 raeburn 10184: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10185:
1.536 raeburn 10186: If the user's status includes multiple types (e.g., staff and student),
10187: the largest default quota which applies to the user determines the
10188: default quota returned.
10189:
1.472 raeburn 10190: =cut
10191:
10192: ###############################################
10193:
10194:
10195: sub default_quota {
1.1134 raeburn 10196: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10197: my ($defquota,$settingstatus);
10198: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10199: ['quotas'],$udom);
1.1134 raeburn 10200: my $key = 'defaultquota';
10201: if ($quotaname eq 'author') {
10202: $key = 'authorquota';
10203: }
1.622 raeburn 10204: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10205: if ($inststatus ne '') {
1.765 raeburn 10206: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10207: foreach my $item (@statuses) {
1.1134 raeburn 10208: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10209: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10210: if ($defquota eq '') {
1.1134 raeburn 10211: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10212: $settingstatus = $item;
1.1134 raeburn 10213: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10214: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10215: $settingstatus = $item;
10216: }
10217: }
1.1134 raeburn 10218: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10219: if ($quotahash{'quotas'}{$item} ne '') {
10220: if ($defquota eq '') {
10221: $defquota = $quotahash{'quotas'}{$item};
10222: $settingstatus = $item;
10223: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10224: $defquota = $quotahash{'quotas'}{$item};
10225: $settingstatus = $item;
10226: }
1.536 raeburn 10227: }
10228: }
10229: }
10230: }
10231: if ($defquota eq '') {
1.1134 raeburn 10232: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10233: $defquota = $quotahash{'quotas'}{$key}{'default'};
10234: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10235: $defquota = $quotahash{'quotas'}{'default'};
10236: }
1.536 raeburn 10237: $settingstatus = 'default';
1.1139 raeburn 10238: if ($defquota eq '') {
10239: if ($quotaname eq 'author') {
10240: $defquota = 500;
10241: }
10242: }
1.536 raeburn 10243: }
10244: } else {
10245: $settingstatus = 'default';
1.1134 raeburn 10246: if ($quotaname eq 'author') {
10247: $defquota = 500;
10248: } else {
10249: $defquota = 20;
10250: }
1.536 raeburn 10251: }
10252: if (wantarray) {
10253: return ($defquota,$settingstatus);
1.472 raeburn 10254: } else {
1.536 raeburn 10255: return $defquota;
1.472 raeburn 10256: }
10257: }
10258:
1.1135 raeburn 10259: ###############################################
10260:
10261: =pod
10262:
1.1136 raeburn 10263: =item * &excess_filesize_warning()
1.1135 raeburn 10264:
10265: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 10266: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 10267: space to be exceeded.
1.1136 raeburn 10268:
10269: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 10270: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 10271:
1.1165 raeburn 10272: Inputs: 7
1.1136 raeburn 10273: 1. username or coursenum
1.1135 raeburn 10274: 2. domain
1.1136 raeburn 10275: 3. context ('author' or 'course')
1.1135 raeburn 10276: 4. filename of file for which action is being requested
10277: 5. filesize (kB) of file
10278: 6. action being taken: copy or upload.
1.1237 raeburn 10279: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 10280:
10281: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 10282: otherwise return null.
10283:
10284: =back
1.1135 raeburn 10285:
10286: =cut
10287:
1.1136 raeburn 10288: sub excess_filesize_warning {
1.1165 raeburn 10289: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 10290: my $current_disk_usage = 0;
1.1165 raeburn 10291: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 10292: if ($context eq 'author') {
10293: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10294: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10295: } else {
10296: foreach my $subdir ('docs','supplemental') {
10297: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10298: }
10299: }
1.1135 raeburn 10300: $disk_quota = int($disk_quota * 1000);
10301: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 10302: return '<p class="LC_warning">'.
1.1135 raeburn 10303: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 10304: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10305: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 10306: $disk_quota,$current_disk_usage).
10307: '</p>';
10308: }
10309: return;
10310: }
10311:
10312: ###############################################
10313:
10314:
1.1136 raeburn 10315:
10316:
1.384 raeburn 10317: sub get_secgrprole_info {
10318: my ($cdom,$cnum,$needroles,$type) = @_;
10319: my %sections_count = &get_sections($cdom,$cnum);
10320: my @sections = (sort {$a <=> $b} keys(%sections_count));
10321: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10322: my @groups = sort(keys(%curr_groups));
10323: my $allroles = [];
10324: my $rolehash;
10325: my $accesshash = {
10326: active => 'Currently has access',
10327: future => 'Will have future access',
10328: previous => 'Previously had access',
10329: };
10330: if ($needroles) {
10331: $rolehash = {'all' => 'all'};
1.385 albertel 10332: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10333: if (&Apache::lonnet::error(%user_roles)) {
10334: undef(%user_roles);
10335: }
10336: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10337: my ($role)=split(/\:/,$item,2);
10338: if ($role eq 'cr') { next; }
10339: if ($role =~ /^cr/) {
10340: $$rolehash{$role} = (split('/',$role))[3];
10341: } else {
10342: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10343: }
10344: }
10345: foreach my $key (sort(keys(%{$rolehash}))) {
10346: push(@{$allroles},$key);
10347: }
10348: push (@{$allroles},'st');
10349: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10350: }
10351: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10352: }
10353:
1.555 raeburn 10354: sub user_picker {
1.1279 raeburn 10355: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10356: my $currdom = $dom;
1.1253 raeburn 10357: my @alldoms = &Apache::lonnet::all_domains();
10358: if (@alldoms == 1) {
10359: my %domsrch = &Apache::lonnet::get_dom('configuration',
10360: ['directorysrch'],$alldoms[0]);
10361: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10362: my $showdom = $domdesc;
10363: if ($showdom eq '') {
10364: $showdom = $dom;
10365: }
10366: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10367: if ((!$domsrch{'directorysrch'}{'available'}) &&
10368: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10369: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10370: }
10371: }
10372: }
1.555 raeburn 10373: my %curr_selected = (
10374: srchin => 'dom',
1.580 raeburn 10375: srchby => 'lastname',
1.555 raeburn 10376: );
10377: my $srchterm;
1.625 raeburn 10378: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10379: if ($srch->{'srchby'} ne '') {
10380: $curr_selected{'srchby'} = $srch->{'srchby'};
10381: }
10382: if ($srch->{'srchin'} ne '') {
10383: $curr_selected{'srchin'} = $srch->{'srchin'};
10384: }
10385: if ($srch->{'srchtype'} ne '') {
10386: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10387: }
10388: if ($srch->{'srchdomain'} ne '') {
10389: $currdom = $srch->{'srchdomain'};
10390: }
10391: $srchterm = $srch->{'srchterm'};
10392: }
1.1222 damieng 10393: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10394: 'usr' => 'Search criteria',
1.563 raeburn 10395: 'doma' => 'Domain/institution to search',
1.558 albertel 10396: 'uname' => 'username',
10397: 'lastname' => 'last name',
1.555 raeburn 10398: 'lastfirst' => 'last name, first name',
1.558 albertel 10399: 'crs' => 'in this course',
1.576 raeburn 10400: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10401: 'alc' => 'all LON-CAPA',
1.573 raeburn 10402: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10403: 'exact' => 'is',
10404: 'contains' => 'contains',
1.569 raeburn 10405: 'begins' => 'begins with',
1.1222 damieng 10406: );
10407: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10408: 'youm' => "You must include some text to search for.",
10409: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10410: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10411: 'yomc' => "You must choose a domain when using an institutional directory search.",
10412: 'ymcd' => "You must choose a domain when using a domain search.",
10413: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10414: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10415: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10416: );
1.1222 damieng 10417: &html_escape(\%html_lt);
10418: &js_escape(\%js_lt);
1.1255 raeburn 10419: my $domform;
1.1277 raeburn 10420: my $allow_blank = 1;
1.1255 raeburn 10421: if ($fixeddom) {
1.1277 raeburn 10422: $allow_blank = 0;
10423: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 10424: } else {
1.1287 raeburn 10425: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 10426: my ($trusted,$untrusted);
1.1287 raeburn 10427: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 10428: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 10429: } elsif ($context eq 'author') {
1.1288 raeburn 10430: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 10431: } elsif ($context eq 'domain') {
1.1288 raeburn 10432: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 10433: }
1.1288 raeburn 10434: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 10435: }
1.563 raeburn 10436: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10437:
10438: my @srchins = ('crs','dom','alc','instd');
10439:
10440: foreach my $option (@srchins) {
10441: # FIXME 'alc' option unavailable until
10442: # loncreateuser::print_user_query_page()
10443: # has been completed.
10444: next if ($option eq 'alc');
1.880 raeburn 10445: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10446: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 10447: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10448: if ($curr_selected{'srchin'} eq $option) {
10449: $srchinsel .= '
1.1222 damieng 10450: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10451: } else {
10452: $srchinsel .= '
1.1222 damieng 10453: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10454: }
1.555 raeburn 10455: }
1.563 raeburn 10456: $srchinsel .= "\n </select>\n";
1.555 raeburn 10457:
10458: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10459: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10460: if ($curr_selected{'srchby'} eq $option) {
10461: $srchbysel .= '
1.1222 damieng 10462: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10463: } else {
10464: $srchbysel .= '
1.1222 damieng 10465: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10466: }
10467: }
10468: $srchbysel .= "\n </select>\n";
10469:
10470: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10471: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10472: if ($curr_selected{'srchtype'} eq $option) {
10473: $srchtypesel .= '
1.1222 damieng 10474: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10475: } else {
10476: $srchtypesel .= '
1.1222 damieng 10477: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10478: }
10479: }
10480: $srchtypesel .= "\n </select>\n";
10481:
1.558 albertel 10482: my ($newuserscript,$new_user_create);
1.994 raeburn 10483: my $context_dom = $env{'request.role.domain'};
10484: if ($context eq 'requestcrs') {
10485: if ($env{'form.coursedom'} ne '') {
10486: $context_dom = $env{'form.coursedom'};
10487: }
10488: }
1.556 raeburn 10489: if ($forcenewuser) {
1.576 raeburn 10490: if (ref($srch) eq 'HASH') {
1.994 raeburn 10491: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10492: if ($cancreate) {
10493: $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>';
10494: } else {
1.799 bisitz 10495: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10496: my %usertypetext = (
10497: official => 'institutional',
10498: unofficial => 'non-institutional',
10499: );
1.799 bisitz 10500: $new_user_create = '<p class="LC_warning">'
10501: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10502: .' '
10503: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10504: ,'<a href="'.$helplink.'">','</a>')
10505: .'</p><br />';
1.627 raeburn 10506: }
1.576 raeburn 10507: }
10508: }
10509:
1.556 raeburn 10510: $newuserscript = <<"ENDSCRIPT";
10511:
1.570 raeburn 10512: function setSearch(createnew,callingForm) {
1.556 raeburn 10513: if (createnew == 1) {
1.570 raeburn 10514: for (var i=0; i<callingForm.srchby.length; i++) {
10515: if (callingForm.srchby.options[i].value == 'uname') {
10516: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10517: }
10518: }
1.570 raeburn 10519: for (var i=0; i<callingForm.srchin.length; i++) {
10520: if ( callingForm.srchin.options[i].value == 'dom') {
10521: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10522: }
10523: }
1.570 raeburn 10524: for (var i=0; i<callingForm.srchtype.length; i++) {
10525: if (callingForm.srchtype.options[i].value == 'exact') {
10526: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10527: }
10528: }
1.570 raeburn 10529: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10530: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10531: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10532: }
10533: }
10534: }
10535: }
10536: ENDSCRIPT
1.558 albertel 10537:
1.556 raeburn 10538: }
10539:
1.555 raeburn 10540: my $output = <<"END_BLOCK";
1.556 raeburn 10541: <script type="text/javascript">
1.824 bisitz 10542: // <![CDATA[
1.570 raeburn 10543: function validateEntry(callingForm) {
1.558 albertel 10544:
1.556 raeburn 10545: var checkok = 1;
1.558 albertel 10546: var srchin;
1.570 raeburn 10547: for (var i=0; i<callingForm.srchin.length; i++) {
10548: if ( callingForm.srchin[i].checked ) {
10549: srchin = callingForm.srchin[i].value;
1.558 albertel 10550: }
10551: }
10552:
1.570 raeburn 10553: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10554: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10555: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10556: var srchterm = callingForm.srchterm.value;
10557: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10558: var msg = "";
10559:
10560: if (srchterm == "") {
10561: checkok = 0;
1.1222 damieng 10562: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10563: }
10564:
1.569 raeburn 10565: if (srchtype== 'begins') {
10566: if (srchterm.length < 2) {
10567: checkok = 0;
1.1222 damieng 10568: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10569: }
10570: }
10571:
1.556 raeburn 10572: if (srchtype== 'contains') {
10573: if (srchterm.length < 3) {
10574: checkok = 0;
1.1222 damieng 10575: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10576: }
10577: }
10578: if (srchin == 'instd') {
10579: if (srchdomain == '') {
10580: checkok = 0;
1.1222 damieng 10581: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10582: }
10583: }
10584: if (srchin == 'dom') {
10585: if (srchdomain == '') {
10586: checkok = 0;
1.1222 damieng 10587: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10588: }
10589: }
10590: if (srchby == 'lastfirst') {
10591: if (srchterm.indexOf(",") == -1) {
10592: checkok = 0;
1.1222 damieng 10593: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10594: }
10595: if (srchterm.indexOf(",") == srchterm.length -1) {
10596: checkok = 0;
1.1222 damieng 10597: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10598: }
10599: }
10600: if (checkok == 0) {
1.1222 damieng 10601: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10602: return;
10603: }
10604: if (checkok == 1) {
1.570 raeburn 10605: callingForm.submit();
1.556 raeburn 10606: }
10607: }
10608:
10609: $newuserscript
10610:
1.824 bisitz 10611: // ]]>
1.556 raeburn 10612: </script>
1.558 albertel 10613:
10614: $new_user_create
10615:
1.555 raeburn 10616: END_BLOCK
1.558 albertel 10617:
1.876 raeburn 10618: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10619: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10620: $domform.
10621: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10622: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10623: $srchbysel.
10624: $srchtypesel.
10625: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10626: $srchinsel.
10627: &Apache::lonhtmlcommon::row_closure(1).
10628: &Apache::lonhtmlcommon::end_pick_box().
10629: '<br />';
1.1253 raeburn 10630: return ($output,1);
1.555 raeburn 10631: }
10632:
1.612 raeburn 10633: sub user_rule_check {
1.615 raeburn 10634: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10635: my ($response,%inst_response);
1.612 raeburn 10636: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10637: if (keys(%{$usershash}) > 1) {
10638: my (%by_username,%by_id,%userdoms);
10639: my $checkid;
10640: if (ref($checks) eq 'HASH') {
10641: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10642: $checkid = 1;
10643: }
10644: }
10645: foreach my $user (keys(%{$usershash})) {
10646: my ($uname,$udom) = split(/:/,$user);
10647: if ($checkid) {
10648: if (ref($usershash->{$user}) eq 'HASH') {
10649: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10650: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10651: $userdoms{$udom} = 1;
1.1227 raeburn 10652: if (ref($inst_results) eq 'HASH') {
10653: $inst_results->{$uname.':'.$udom} = {};
10654: }
1.1226 raeburn 10655: }
10656: }
10657: } else {
10658: $by_username{$udom}{$uname} = 1;
10659: $userdoms{$udom} = 1;
1.1227 raeburn 10660: if (ref($inst_results) eq 'HASH') {
10661: $inst_results->{$uname.':'.$udom} = {};
10662: }
1.1226 raeburn 10663: }
10664: }
10665: foreach my $udom (keys(%userdoms)) {
10666: if (!$got_rules->{$udom}) {
10667: my %domconfig = &Apache::lonnet::get_dom('configuration',
10668: ['usercreation'],$udom);
10669: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10670: foreach my $item ('username','id') {
10671: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10672: $$curr_rules{$udom}{$item} =
10673: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10674: }
10675: }
10676: }
10677: $got_rules->{$udom} = 1;
10678: }
1.612 raeburn 10679: }
1.1226 raeburn 10680: if ($checkid) {
10681: foreach my $udom (keys(%by_id)) {
10682: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10683: if ($outcome eq 'ok') {
1.1227 raeburn 10684: foreach my $id (keys(%{$by_id{$udom}})) {
10685: my $uname = $by_id{$udom}{$id};
10686: $inst_response{$uname.':'.$udom} = $outcome;
10687: }
1.1226 raeburn 10688: if (ref($results) eq 'HASH') {
10689: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10690: if (exists($inst_response{$uname.':'.$udom})) {
10691: $inst_response{$uname.':'.$udom} = $outcome;
10692: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10693: }
1.1226 raeburn 10694: }
10695: }
10696: }
1.612 raeburn 10697: }
1.615 raeburn 10698: } else {
1.1226 raeburn 10699: foreach my $udom (keys(%by_username)) {
10700: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10701: if ($outcome eq 'ok') {
1.1227 raeburn 10702: foreach my $uname (keys(%{$by_username{$udom}})) {
10703: $inst_response{$uname.':'.$udom} = $outcome;
10704: }
1.1226 raeburn 10705: if (ref($results) eq 'HASH') {
10706: foreach my $uname (keys(%{$results})) {
10707: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10708: }
10709: }
10710: }
10711: }
1.612 raeburn 10712: }
1.1226 raeburn 10713: } elsif (keys(%{$usershash}) == 1) {
10714: my $user = (keys(%{$usershash}))[0];
10715: my ($uname,$udom) = split(/:/,$user);
10716: if (($udom ne '') && ($uname ne '')) {
10717: if (ref($usershash->{$user}) eq 'HASH') {
10718: if (ref($checks) eq 'HASH') {
10719: if (defined($checks->{'username'})) {
10720: ($inst_response{$user},%{$inst_results->{$user}}) =
10721: &Apache::lonnet::get_instuser($udom,$uname);
10722: } elsif (defined($checks->{'id'})) {
10723: if ($usershash->{$user}->{'id'} ne '') {
10724: ($inst_response{$user},%{$inst_results->{$user}}) =
10725: &Apache::lonnet::get_instuser($udom,undef,
10726: $usershash->{$user}->{'id'});
10727: } else {
10728: ($inst_response{$user},%{$inst_results->{$user}}) =
10729: &Apache::lonnet::get_instuser($udom,$uname);
10730: }
1.585 raeburn 10731: }
1.1226 raeburn 10732: } else {
10733: ($inst_response{$user},%{$inst_results->{$user}}) =
10734: &Apache::lonnet::get_instuser($udom,$uname);
10735: return;
10736: }
10737: if (!$got_rules->{$udom}) {
10738: my %domconfig = &Apache::lonnet::get_dom('configuration',
10739: ['usercreation'],$udom);
10740: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10741: foreach my $item ('username','id') {
10742: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10743: $$curr_rules{$udom}{$item} =
10744: $domconfig{'usercreation'}{$item.'_rule'};
10745: }
10746: }
10747: }
10748: $got_rules->{$udom} = 1;
1.585 raeburn 10749: }
10750: }
1.1226 raeburn 10751: } else {
10752: return;
10753: }
10754: } else {
10755: return;
10756: }
10757: foreach my $user (keys(%{$usershash})) {
10758: my ($uname,$udom) = split(/:/,$user);
10759: next if (($udom eq '') || ($uname eq ''));
10760: my $id;
1.1227 raeburn 10761: if (ref($inst_results) eq 'HASH') {
10762: if (ref($inst_results->{$user}) eq 'HASH') {
10763: $id = $inst_results->{$user}->{'id'};
10764: }
10765: }
10766: if ($id eq '') {
10767: if (ref($usershash->{$user})) {
10768: $id = $usershash->{$user}->{'id'};
10769: }
1.585 raeburn 10770: }
1.612 raeburn 10771: foreach my $item (keys(%{$checks})) {
10772: if (ref($$curr_rules{$udom}) eq 'HASH') {
10773: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10774: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10775: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10776: $$curr_rules{$udom}{$item});
1.612 raeburn 10777: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10778: if ($rule_check{$rule}) {
10779: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10780: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10781: if (ref($inst_results) eq 'HASH') {
10782: if (ref($inst_results->{$user}) eq 'HASH') {
10783: if (keys(%{$inst_results->{$user}}) == 0) {
10784: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10785: } elsif ($item eq 'id') {
10786: if ($inst_results->{$user}->{'id'} eq '') {
10787: $$alerts{$item}{$udom}{$uname} = 1;
10788: }
1.615 raeburn 10789: }
1.612 raeburn 10790: }
10791: }
1.615 raeburn 10792: }
10793: last;
1.585 raeburn 10794: }
10795: }
10796: }
10797: }
10798: }
10799: }
10800: }
10801: }
1.612 raeburn 10802: return;
10803: }
10804:
10805: sub user_rule_formats {
10806: my ($domain,$domdesc,$curr_rules,$check) = @_;
10807: my %text = (
10808: 'username' => 'Usernames',
10809: 'id' => 'IDs',
10810: );
10811: my $output;
10812: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10813: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10814: if (@{$ruleorder} > 0) {
1.1102 raeburn 10815: $output = '<br />'.
10816: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10817: '<span class="LC_cusr_emph">','</span>',$domdesc).
10818: ' <ul>';
1.612 raeburn 10819: foreach my $rule (@{$ruleorder}) {
10820: if (ref($curr_rules) eq 'ARRAY') {
10821: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10822: if (ref($rules->{$rule}) eq 'HASH') {
10823: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10824: $rules->{$rule}{'desc'}.'</li>';
10825: }
10826: }
10827: }
10828: }
10829: $output .= '</ul>';
10830: }
10831: }
10832: return $output;
10833: }
10834:
10835: sub instrule_disallow_msg {
1.615 raeburn 10836: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10837: my $response;
10838: my %text = (
10839: item => 'username',
10840: items => 'usernames',
10841: match => 'matches',
10842: do => 'does',
10843: action => 'a username',
10844: one => 'one',
10845: );
10846: if ($count > 1) {
10847: $text{'item'} = 'usernames';
10848: $text{'match'} ='match';
10849: $text{'do'} = 'do';
10850: $text{'action'} = 'usernames',
10851: $text{'one'} = 'ones';
10852: }
10853: if ($checkitem eq 'id') {
10854: $text{'items'} = 'IDs';
10855: $text{'item'} = 'ID';
10856: $text{'action'} = 'an ID';
1.615 raeburn 10857: if ($count > 1) {
10858: $text{'item'} = 'IDs';
10859: $text{'action'} = 'IDs';
10860: }
1.612 raeburn 10861: }
1.674 bisitz 10862: $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 10863: if ($mode eq 'upload') {
10864: if ($checkitem eq 'username') {
10865: $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'}.");
10866: } elsif ($checkitem eq 'id') {
1.674 bisitz 10867: $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 10868: }
1.669 raeburn 10869: } elsif ($mode eq 'selfcreate') {
10870: if ($checkitem eq 'id') {
10871: $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.");
10872: }
1.615 raeburn 10873: } else {
10874: if ($checkitem eq 'username') {
10875: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10876: } elsif ($checkitem eq 'id') {
10877: $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.");
10878: }
1.612 raeburn 10879: }
10880: return $response;
1.585 raeburn 10881: }
10882:
1.624 raeburn 10883: sub personal_data_fieldtitles {
10884: my %fieldtitles = &Apache::lonlocal::texthash (
10885: id => 'Student/Employee ID',
10886: permanentemail => 'E-mail address',
10887: lastname => 'Last Name',
10888: firstname => 'First Name',
10889: middlename => 'Middle Name',
10890: generation => 'Generation',
10891: gen => 'Generation',
1.765 raeburn 10892: inststatus => 'Affiliation',
1.624 raeburn 10893: );
10894: return %fieldtitles;
10895: }
10896:
1.642 raeburn 10897: sub sorted_inst_types {
10898: my ($dom) = @_;
1.1185 raeburn 10899: my ($usertypes,$order);
10900: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10901: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10902: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10903: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10904: } else {
10905: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10906: }
1.642 raeburn 10907: my $othertitle = &mt('All users');
10908: if ($env{'request.course.id'}) {
1.668 raeburn 10909: $othertitle = &mt('Any users');
1.642 raeburn 10910: }
10911: my @types;
10912: if (ref($order) eq 'ARRAY') {
10913: @types = @{$order};
10914: }
10915: if (@types == 0) {
10916: if (ref($usertypes) eq 'HASH') {
10917: @types = sort(keys(%{$usertypes}));
10918: }
10919: }
10920: if (keys(%{$usertypes}) > 0) {
10921: $othertitle = &mt('Other users');
10922: }
10923: return ($othertitle,$usertypes,\@types);
10924: }
10925:
1.645 raeburn 10926: sub get_institutional_codes {
10927: my ($settings,$allcourses,$LC_code) = @_;
10928: # Get complete list of course sections to update
10929: my @currsections = ();
10930: my @currxlists = ();
10931: my $coursecode = $$settings{'internal.coursecode'};
10932:
10933: if ($$settings{'internal.sectionnums'} ne '') {
10934: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10935: }
10936:
10937: if ($$settings{'internal.crosslistings'} ne '') {
10938: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10939: }
10940:
10941: if (@currxlists > 0) {
10942: foreach (@currxlists) {
10943: if (m/^([^:]+):(\w*)$/) {
10944: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 10945: push(@{$allcourses},$1);
1.645 raeburn 10946: $$LC_code{$1} = $2;
10947: }
10948: }
10949: }
10950: }
10951:
10952: if (@currsections > 0) {
10953: foreach (@currsections) {
10954: if (m/^(\w+):(\w*)$/) {
10955: my $sec = $coursecode.$1;
10956: my $lc_sec = $2;
10957: unless (grep/^$sec$/,@{$allcourses}) {
1.1263 raeburn 10958: push(@{$allcourses},$sec);
1.645 raeburn 10959: $$LC_code{$sec} = $lc_sec;
10960: }
10961: }
10962: }
10963: }
10964: return;
10965: }
10966:
1.971 raeburn 10967: sub get_standard_codeitems {
10968: return ('Year','Semester','Department','Number','Section');
10969: }
10970:
1.112 bowersj2 10971: =pod
10972:
1.780 raeburn 10973: =head1 Slot Helpers
10974:
10975: =over 4
10976:
10977: =item * sorted_slots()
10978:
1.1040 raeburn 10979: Sorts an array of slot names in order of an optional sort key,
10980: default sort is by slot start time (earliest first).
1.780 raeburn 10981:
10982: Inputs:
10983:
10984: =over 4
10985:
10986: slotsarr - Reference to array of unsorted slot names.
10987:
10988: slots - Reference to hash of hash, where outer hash keys are slot names.
10989:
1.1040 raeburn 10990: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10991:
1.549 albertel 10992: =back
10993:
1.780 raeburn 10994: Returns:
10995:
10996: =over 4
10997:
1.1040 raeburn 10998: sorted - An array of slot names sorted by a specified sort key
10999: (default sort key is start time of the slot).
1.780 raeburn 11000:
11001: =back
11002:
11003: =cut
11004:
11005:
11006: sub sorted_slots {
1.1040 raeburn 11007: my ($slotsarr,$slots,$sortkey) = @_;
11008: if ($sortkey eq '') {
11009: $sortkey = 'starttime';
11010: }
1.780 raeburn 11011: my @sorted;
11012: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11013: @sorted =
11014: sort {
11015: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11016: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11017: }
11018: if (ref($slots->{$a})) { return -1;}
11019: if (ref($slots->{$b})) { return 1;}
11020: return 0;
11021: } @{$slotsarr};
11022: }
11023: return @sorted;
11024: }
11025:
1.1040 raeburn 11026: =pod
11027:
11028: =item * get_future_slots()
11029:
11030: Inputs:
11031:
11032: =over 4
11033:
11034: cnum - course number
11035:
11036: cdom - course domain
11037:
11038: now - current UNIX time
11039:
11040: symb - optional symb
11041:
11042: =back
11043:
11044: Returns:
11045:
11046: =over 4
11047:
11048: sorted_reservable - ref to array of student_schedulable slots currently
11049: reservable, ordered by end date of reservation period.
11050:
11051: reservable_now - ref to hash of student_schedulable slots currently
11052: reservable.
11053:
11054: Keys in inner hash are:
11055: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11056: (b) endreserve: end date of reservation period.
11057: (c) uniqueperiod: start,end dates when slot is to be uniquely
11058: selected.
1.1040 raeburn 11059:
11060: sorted_future - ref to array of student_schedulable slots reservable in
11061: the future, ordered by start date of reservation period.
11062:
11063: future_reservable - ref to hash of student_schedulable slots reservable
11064: in the future.
11065:
11066: Keys in inner hash are:
11067: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11068: (b) startreserve: start date of reservation period.
11069: (c) uniqueperiod: start,end dates when slot is to be uniquely
11070: selected.
1.1040 raeburn 11071:
11072: =back
11073:
11074: =cut
11075:
11076: sub get_future_slots {
11077: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 11078: my $map;
11079: if ($symb) {
11080: ($map) = &Apache::lonnet::decode_symb($symb);
11081: }
1.1040 raeburn 11082: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11083: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11084: foreach my $slot (keys(%slots)) {
11085: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11086: if ($symb) {
1.1229 raeburn 11087: if ($slots{$slot}->{'symb'} ne '') {
11088: my $canuse;
11089: my %oksymbs;
11090: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
11091: map { $oksymbs{$_} = 1; } @slotsymbs;
11092: if ($oksymbs{$symb}) {
11093: $canuse = 1;
11094: } else {
11095: foreach my $item (@slotsymbs) {
11096: if ($item =~ /\.(page|sequence)$/) {
11097: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
11098: if (($map ne '') && ($map eq $sloturl)) {
11099: $canuse = 1;
11100: last;
11101: }
11102: }
11103: }
11104: }
11105: next unless ($canuse);
11106: }
1.1040 raeburn 11107: }
11108: if (($slots{$slot}->{'starttime'} > $now) &&
11109: ($slots{$slot}->{'endtime'} > $now)) {
11110: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11111: my $userallowed = 0;
11112: if ($slots{$slot}->{'allowedsections'}) {
11113: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11114: if (!defined($env{'request.role.sec'})
11115: && grep(/^No section assigned$/,@allowed_sec)) {
11116: $userallowed=1;
11117: } else {
11118: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11119: $userallowed=1;
11120: }
11121: }
11122: unless ($userallowed) {
11123: if (defined($env{'request.course.groups'})) {
11124: my @groups = split(/:/,$env{'request.course.groups'});
11125: foreach my $group (@groups) {
11126: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11127: $userallowed=1;
11128: last;
11129: }
11130: }
11131: }
11132: }
11133: }
11134: if ($slots{$slot}->{'allowedusers'}) {
11135: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11136: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11137: if (grep(/^\Q$user\E$/,@allowed_users)) {
11138: $userallowed = 1;
11139: }
11140: }
11141: next unless($userallowed);
11142: }
11143: my $startreserve = $slots{$slot}->{'startreserve'};
11144: my $endreserve = $slots{$slot}->{'endreserve'};
11145: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 11146: my $uniqueperiod;
11147: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11148: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11149: }
1.1040 raeburn 11150: if (($startreserve < $now) &&
11151: (!$endreserve || $endreserve > $now)) {
11152: my $lastres = $endreserve;
11153: if (!$lastres) {
11154: $lastres = $slots{$slot}->{'starttime'};
11155: }
11156: $reservable_now{$slot} = {
11157: symb => $symb,
1.1250 raeburn 11158: endreserve => $lastres,
11159: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11160: };
11161: } elsif (($startreserve > $now) &&
11162: (!$endreserve || $endreserve > $startreserve)) {
11163: $future_reservable{$slot} = {
11164: symb => $symb,
1.1250 raeburn 11165: startreserve => $startreserve,
11166: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11167: };
11168: }
11169: }
11170: }
11171: my @unsorted_reservable = keys(%reservable_now);
11172: if (@unsorted_reservable > 0) {
11173: @sorted_reservable =
11174: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11175: }
11176: my @unsorted_future = keys(%future_reservable);
11177: if (@unsorted_future > 0) {
11178: @sorted_future =
11179: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11180: }
11181: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11182: }
1.780 raeburn 11183:
11184: =pod
11185:
1.1057 foxr 11186: =back
11187:
1.549 albertel 11188: =head1 HTTP Helpers
11189:
11190: =over 4
11191:
1.648 raeburn 11192: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11193:
1.258 albertel 11194: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11195: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11196: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11197:
11198: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11199: $possible_names is an ref to an array of form element names. As an example:
11200: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11201: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11202:
11203: =cut
1.1 albertel 11204:
1.6 albertel 11205: sub get_unprocessed_cgi {
1.25 albertel 11206: my ($query,$possible_names)= @_;
1.26 matthew 11207: # $Apache::lonxml::debug=1;
1.356 albertel 11208: foreach my $pair (split(/&/,$query)) {
11209: my ($name, $value) = split(/=/,$pair);
1.369 www 11210: $name = &unescape($name);
1.25 albertel 11211: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11212: $value =~ tr/+/ /;
11213: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11214: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11215: }
1.16 harris41 11216: }
1.6 albertel 11217: }
11218:
1.112 bowersj2 11219: =pod
11220:
1.648 raeburn 11221: =item * &cacheheader()
1.112 bowersj2 11222:
11223: returns cache-controlling header code
11224:
11225: =cut
11226:
1.7 albertel 11227: sub cacheheader {
1.258 albertel 11228: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11229: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11230: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11231: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11232: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11233: return $output;
1.7 albertel 11234: }
11235:
1.112 bowersj2 11236: =pod
11237:
1.648 raeburn 11238: =item * &no_cache($r)
1.112 bowersj2 11239:
11240: specifies header code to not have cache
11241:
11242: =cut
11243:
1.9 albertel 11244: sub no_cache {
1.216 albertel 11245: my ($r) = @_;
11246: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11247: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11248: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11249: $r->no_cache(1);
11250: $r->header_out("Expires" => $date);
11251: $r->header_out("Pragma" => "no-cache");
1.123 www 11252: }
11253:
11254: sub content_type {
1.181 albertel 11255: my ($r,$type,$charset) = @_;
1.299 foxr 11256: if ($r) {
11257: # Note that printout.pl calls this with undef for $r.
11258: &no_cache($r);
11259: }
1.258 albertel 11260: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11261: unless ($charset) {
11262: $charset=&Apache::lonlocal::current_encoding;
11263: }
11264: if ($charset) { $type.='; charset='.$charset; }
11265: if ($r) {
11266: $r->content_type($type);
11267: } else {
11268: print("Content-type: $type\n\n");
11269: }
1.9 albertel 11270: }
1.25 albertel 11271:
1.112 bowersj2 11272: =pod
11273:
1.648 raeburn 11274: =item * &add_to_env($name,$value)
1.112 bowersj2 11275:
1.258 albertel 11276: adds $name to the %env hash with value
1.112 bowersj2 11277: $value, if $name already exists, the entry is converted to an array
11278: reference and $value is added to the array.
11279:
11280: =cut
11281:
1.25 albertel 11282: sub add_to_env {
11283: my ($name,$value)=@_;
1.258 albertel 11284: if (defined($env{$name})) {
11285: if (ref($env{$name})) {
1.25 albertel 11286: #already have multiple values
1.258 albertel 11287: push(@{ $env{$name} },$value);
1.25 albertel 11288: } else {
11289: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11290: my $first=$env{$name};
11291: undef($env{$name});
11292: push(@{ $env{$name} },$first,$value);
1.25 albertel 11293: }
11294: } else {
1.258 albertel 11295: $env{$name}=$value;
1.25 albertel 11296: }
1.31 albertel 11297: }
1.149 albertel 11298:
11299: =pod
11300:
1.648 raeburn 11301: =item * &get_env_multiple($name)
1.149 albertel 11302:
1.258 albertel 11303: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11304: values may be defined and end up as an array ref.
11305:
11306: returns an array of values
11307:
11308: =cut
11309:
11310: sub get_env_multiple {
11311: my ($name) = @_;
11312: my @values;
1.258 albertel 11313: if (defined($env{$name})) {
1.149 albertel 11314: # exists is it an array
1.258 albertel 11315: if (ref($env{$name})) {
11316: @values=@{ $env{$name} };
1.149 albertel 11317: } else {
1.258 albertel 11318: $values[0]=$env{$name};
1.149 albertel 11319: }
11320: }
11321: return(@values);
11322: }
11323:
1.1249 damieng 11324: # Looks at given dependencies, and returns something depending on the context.
11325: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11326: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11327: # For all other contexts, returns ($output, $counter, $numpathchg).
11328: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11329: # $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.
11330: # $numpathchg: integer with the number of cleaned up dependency paths.
11331: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11332: # \%mapping: hash reference clean path -> original path for all dependencies.
11333: # @param {string} actionurl - The path to the handler, indicative of the context.
11334: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11335: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11336: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11337: # @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)
11338: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11339: sub ask_for_embedded_content {
1.1249 damieng 11340: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11341: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11342: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11343: %currsubfile,%unused,$rem);
1.1071 raeburn 11344: my $counter = 0;
11345: my $numnew = 0;
1.987 raeburn 11346: my $numremref = 0;
11347: my $numinvalid = 0;
11348: my $numpathchg = 0;
11349: my $numexisting = 0;
1.1071 raeburn 11350: my $numunused = 0;
11351: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11352: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11353: my $heading = &mt('Upload embedded files');
11354: my $buttontext = &mt('Upload');
11355:
1.1249 damieng 11356: # fills these variables based on the context:
11357: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11358: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11359: if ($env{'request.course.id'}) {
1.1123 raeburn 11360: if ($actionurl eq '/adm/dependencies') {
11361: $navmap = Apache::lonnavmaps::navmap->new();
11362: }
11363: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11364: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11365: }
1.1123 raeburn 11366: if (($actionurl eq '/adm/portfolio') ||
11367: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11368: my $current_path='/';
11369: if ($env{'form.currentpath'}) {
11370: $current_path = $env{'form.currentpath'};
11371: }
11372: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11373: $udom = $cdom;
11374: $uname = $cnum;
1.984 raeburn 11375: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11376: } else {
11377: $udom = $env{'user.domain'};
11378: $uname = $env{'user.name'};
11379: $url = '/userfiles/portfolio';
11380: }
1.987 raeburn 11381: $toplevel = $url.'/';
1.984 raeburn 11382: $url .= $current_path;
11383: $getpropath = 1;
1.987 raeburn 11384: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11385: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11386: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11387: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11388: $toplevel = $url;
1.984 raeburn 11389: if ($rest ne '') {
1.987 raeburn 11390: $url .= $rest;
11391: }
11392: } elsif ($actionurl eq '/adm/coursedocs') {
11393: if (ref($args) eq 'HASH') {
1.1071 raeburn 11394: $url = $args->{'docs_url'};
11395: $toplevel = $url;
1.1084 raeburn 11396: if ($args->{'context'} eq 'paste') {
11397: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11398: ($path) =
11399: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11400: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11401: $fileloc =~ s{^/}{};
11402: }
1.1071 raeburn 11403: }
1.1084 raeburn 11404: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11405: if ($env{'request.course.id'} ne '') {
11406: if (ref($args) eq 'HASH') {
11407: $url = $args->{'docs_url'};
11408: $title = $args->{'docs_title'};
1.1126 raeburn 11409: $toplevel = $url;
11410: unless ($toplevel =~ m{^/}) {
11411: $toplevel = "/$url";
11412: }
1.1085 raeburn 11413: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11414: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11415: $path = $1;
11416: } else {
11417: ($path) =
11418: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11419: }
1.1195 raeburn 11420: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11421: $fileloc = $toplevel;
11422: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11423: my ($udom,$uname,$fname) =
11424: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11425: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11426: } else {
11427: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11428: }
1.1071 raeburn 11429: $fileloc =~ s{^/}{};
11430: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11431: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11432: }
1.987 raeburn 11433: }
1.1123 raeburn 11434: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11435: $udom = $cdom;
11436: $uname = $cnum;
11437: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11438: $toplevel = $url;
11439: $path = $url;
11440: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11441: $fileloc =~ s{^/}{};
1.987 raeburn 11442: }
1.1249 damieng 11443:
11444: # parses the dependency paths to get some info
11445: # fills $newfiles, $mapping, $subdependencies, $dependencies
11446: # $newfiles: hash URL -> 1 for new files or external URLs
11447: # (will be completed later)
11448: # $mapping:
11449: # for external URLs: external URL -> external URL
11450: # for relative paths: clean path -> original path
11451: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11452: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11453: foreach my $file (keys(%{$allfiles})) {
11454: my $embed_file;
11455: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11456: $embed_file = $1;
11457: } else {
11458: $embed_file = $file;
11459: }
1.1158 raeburn 11460: my ($absolutepath,$cleaned_file);
11461: if ($embed_file =~ m{^\w+://}) {
11462: $cleaned_file = $embed_file;
1.1147 raeburn 11463: $newfiles{$cleaned_file} = 1;
11464: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11465: } else {
1.1158 raeburn 11466: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11467: if ($embed_file =~ m{^/}) {
11468: $absolutepath = $embed_file;
11469: }
1.1147 raeburn 11470: if ($cleaned_file =~ m{/}) {
11471: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11472: $path = &check_for_traversal($path,$url,$toplevel);
11473: my $item = $fname;
11474: if ($path ne '') {
11475: $item = $path.'/'.$fname;
11476: $subdependencies{$path}{$fname} = 1;
11477: } else {
11478: $dependencies{$item} = 1;
11479: }
11480: if ($absolutepath) {
11481: $mapping{$item} = $absolutepath;
11482: } else {
11483: $mapping{$item} = $embed_file;
11484: }
11485: } else {
11486: $dependencies{$embed_file} = 1;
11487: if ($absolutepath) {
1.1147 raeburn 11488: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11489: } else {
1.1147 raeburn 11490: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11491: }
11492: }
1.984 raeburn 11493: }
11494: }
1.1249 damieng 11495:
11496: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11497: # and lists
11498: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11499: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11500: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11501: # the path had to be cleaned up
11502: # $existing: hash clean path -> 1 if the file exists
11503: # $numexisting: number of keys in $existing
11504: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11505: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11506: # dependency subdirectories that are
11507: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11508: my $dirptr = 16384;
1.984 raeburn 11509: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11510: $currsubfile{$path} = {};
1.1123 raeburn 11511: if (($actionurl eq '/adm/portfolio') ||
11512: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11513: my ($sublistref,$listerror) =
11514: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11515: if (ref($sublistref) eq 'ARRAY') {
11516: foreach my $line (@{$sublistref}) {
11517: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11518: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11519: }
1.984 raeburn 11520: }
1.987 raeburn 11521: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11522: if (opendir(my $dir,$url.'/'.$path)) {
11523: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11524: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11525: }
1.1084 raeburn 11526: } elsif (($actionurl eq '/adm/dependencies') ||
11527: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11528: ($args->{'context'} eq 'paste')) ||
11529: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11530: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11531: my $dir;
11532: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11533: $dir = $fileloc;
11534: } else {
11535: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11536: }
1.1071 raeburn 11537: if ($dir ne '') {
11538: my ($sublistref,$listerror) =
11539: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11540: if (ref($sublistref) eq 'ARRAY') {
11541: foreach my $line (@{$sublistref}) {
11542: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11543: undef,$mtime)=split(/\&/,$line,12);
11544: unless (($testdir&$dirptr) ||
11545: ($file_name =~ /^\.\.?$/)) {
11546: $currsubfile{$path}{$file_name} = [$size,$mtime];
11547: }
11548: }
11549: }
11550: }
1.984 raeburn 11551: }
11552: }
11553: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11554: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11555: my $item = $path.'/'.$file;
11556: unless ($mapping{$item} eq $item) {
11557: $pathchanges{$item} = 1;
11558: }
11559: $existing{$item} = 1;
11560: $numexisting ++;
11561: } else {
11562: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11563: }
11564: }
1.1071 raeburn 11565: if ($actionurl eq '/adm/dependencies') {
11566: foreach my $path (keys(%currsubfile)) {
11567: if (ref($currsubfile{$path}) eq 'HASH') {
11568: foreach my $file (keys(%{$currsubfile{$path}})) {
11569: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11570: next if (($rem ne '') &&
11571: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11572: (ref($navmap) &&
11573: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11574: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11575: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11576: $unused{$path.'/'.$file} = 1;
11577: }
11578: }
11579: }
11580: }
11581: }
1.984 raeburn 11582: }
1.1249 damieng 11583:
11584: # fills $currfile, hash file name -> 1 or [$size,$mtime]
11585: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 11586: my %currfile;
1.1123 raeburn 11587: if (($actionurl eq '/adm/portfolio') ||
11588: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11589: my ($dirlistref,$listerror) =
11590: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11591: if (ref($dirlistref) eq 'ARRAY') {
11592: foreach my $line (@{$dirlistref}) {
11593: my ($file_name,$rest) = split(/\&/,$line,2);
11594: $currfile{$file_name} = 1;
11595: }
1.984 raeburn 11596: }
1.987 raeburn 11597: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11598: if (opendir(my $dir,$url)) {
1.987 raeburn 11599: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11600: map {$currfile{$_} = 1;} @dir_list;
11601: }
1.1084 raeburn 11602: } elsif (($actionurl eq '/adm/dependencies') ||
11603: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11604: ($args->{'context'} eq 'paste')) ||
11605: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11606: if ($env{'request.course.id'} ne '') {
11607: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11608: if ($dir ne '') {
11609: my ($dirlistref,$listerror) =
11610: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11611: if (ref($dirlistref) eq 'ARRAY') {
11612: foreach my $line (@{$dirlistref}) {
11613: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11614: $size,undef,$mtime)=split(/\&/,$line,12);
11615: unless (($testdir&$dirptr) ||
11616: ($file_name =~ /^\.\.?$/)) {
11617: $currfile{$file_name} = [$size,$mtime];
11618: }
11619: }
11620: }
11621: }
11622: }
1.984 raeburn 11623: }
1.1249 damieng 11624: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
11625: # are not in subdirectories, using $currfile
1.984 raeburn 11626: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11627: if (exists($currfile{$file})) {
1.987 raeburn 11628: unless ($mapping{$file} eq $file) {
11629: $pathchanges{$file} = 1;
11630: }
11631: $existing{$file} = 1;
11632: $numexisting ++;
11633: } else {
1.984 raeburn 11634: $newfiles{$file} = 1;
11635: }
11636: }
1.1071 raeburn 11637: foreach my $file (keys(%currfile)) {
11638: unless (($file eq $filename) ||
11639: ($file eq $filename.'.bak') ||
11640: ($dependencies{$file})) {
1.1085 raeburn 11641: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11642: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11643: next if (($rem ne '') &&
11644: (($env{"httpref.$rem".$file} ne '') ||
11645: (ref($navmap) &&
11646: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11647: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11648: ($navmap->getResourceByUrl($rem.$1)))))));
11649: }
1.1085 raeburn 11650: }
1.1071 raeburn 11651: $unused{$file} = 1;
11652: }
11653: }
1.1249 damieng 11654:
11655: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 11656: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11657: ($args->{'context'} eq 'paste')) {
11658: $counter = scalar(keys(%existing));
11659: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11660: return ($output,$counter,$numpathchg,\%existing);
11661: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11662: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11663: $counter = scalar(keys(%existing));
11664: $numpathchg = scalar(keys(%pathchanges));
11665: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11666: }
1.1249 damieng 11667:
11668: # returns HTML otherwise, with dependency results and to ask for more uploads
11669:
11670: # $upload_output: missing dependencies (with upload form)
11671: # $modify_output: uploaded dependencies (in use)
11672: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 11673: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11674: if ($actionurl eq '/adm/dependencies') {
11675: next if ($embed_file =~ m{^\w+://});
11676: }
1.660 raeburn 11677: $upload_output .= &start_data_table_row().
1.1123 raeburn 11678: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11679: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11680: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11681: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11682: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11683: }
1.1123 raeburn 11684: $upload_output .= '</td>';
1.1071 raeburn 11685: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11686: $upload_output.='<td align="right">'.
11687: '<span class="LC_info LC_fontsize_medium">'.
11688: &mt("URL points to web address").'</span>';
1.987 raeburn 11689: $numremref++;
1.660 raeburn 11690: } elsif ($args->{'error_on_invalid_names'}
11691: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11692: $upload_output.='<td align="right"><span class="LC_warning">'.
11693: &mt('Invalid characters').'</span>';
1.987 raeburn 11694: $numinvalid++;
1.660 raeburn 11695: } else {
1.1123 raeburn 11696: $upload_output .= '<td>'.
11697: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11698: $embed_file,\%mapping,
1.1071 raeburn 11699: $allfiles,$codebase,'upload');
11700: $counter ++;
11701: $numnew ++;
1.987 raeburn 11702: }
11703: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11704: }
11705: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11706: if ($actionurl eq '/adm/dependencies') {
11707: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11708: $modify_output .= &start_data_table_row().
11709: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11710: '<img src="'.&icon($embed_file).'" border="0" />'.
11711: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11712: '<td>'.$size.'</td>'.
11713: '<td>'.$mtime.'</td>'.
11714: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11715: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11716: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11717: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11718: &embedded_file_element('upload_embedded',$counter,
11719: $embed_file,\%mapping,
11720: $allfiles,$codebase,'modify').
11721: '</div></td>'.
11722: &end_data_table_row()."\n";
11723: $counter ++;
11724: } else {
11725: $upload_output .= &start_data_table_row().
1.1123 raeburn 11726: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11727: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11728: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11729: &Apache::loncommon::end_data_table_row()."\n";
11730: }
11731: }
11732: my $delidx = $counter;
11733: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11734: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11735: $delete_output .= &start_data_table_row().
11736: '<td><img src="'.&icon($oldfile).'" />'.
11737: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11738: '<td>'.$size.'</td>'.
11739: '<td>'.$mtime.'</td>'.
11740: '<td><label><input type="checkbox" name="del_upload_dep" '.
11741: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11742: &embedded_file_element('upload_embedded',$delidx,
11743: $oldfile,\%mapping,$allfiles,
11744: $codebase,'delete').'</td>'.
11745: &end_data_table_row()."\n";
11746: $numunused ++;
11747: $delidx ++;
1.987 raeburn 11748: }
11749: if ($upload_output) {
11750: $upload_output = &start_data_table().
11751: $upload_output.
11752: &end_data_table()."\n";
11753: }
1.1071 raeburn 11754: if ($modify_output) {
11755: $modify_output = &start_data_table().
11756: &start_data_table_header_row().
11757: '<th>'.&mt('File').'</th>'.
11758: '<th>'.&mt('Size (KB)').'</th>'.
11759: '<th>'.&mt('Modified').'</th>'.
11760: '<th>'.&mt('Upload replacement?').'</th>'.
11761: &end_data_table_header_row().
11762: $modify_output.
11763: &end_data_table()."\n";
11764: }
11765: if ($delete_output) {
11766: $delete_output = &start_data_table().
11767: &start_data_table_header_row().
11768: '<th>'.&mt('File').'</th>'.
11769: '<th>'.&mt('Size (KB)').'</th>'.
11770: '<th>'.&mt('Modified').'</th>'.
11771: '<th>'.&mt('Delete?').'</th>'.
11772: &end_data_table_header_row().
11773: $delete_output.
11774: &end_data_table()."\n";
11775: }
1.987 raeburn 11776: my $applies = 0;
11777: if ($numremref) {
11778: $applies ++;
11779: }
11780: if ($numinvalid) {
11781: $applies ++;
11782: }
11783: if ($numexisting) {
11784: $applies ++;
11785: }
1.1071 raeburn 11786: if ($counter || $numunused) {
1.987 raeburn 11787: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11788: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11789: $state.'<h3>'.$heading.'</h3>';
11790: if ($actionurl eq '/adm/dependencies') {
11791: if ($numnew) {
11792: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11793: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11794: $upload_output.'<br />'."\n";
11795: }
11796: if ($numexisting) {
11797: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11798: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11799: $modify_output.'<br />'."\n";
11800: $buttontext = &mt('Save changes');
11801: }
11802: if ($numunused) {
11803: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11804: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11805: $delete_output.'<br />'."\n";
11806: $buttontext = &mt('Save changes');
11807: }
11808: } else {
11809: $output .= $upload_output.'<br />'."\n";
11810: }
11811: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11812: $counter.'" />'."\n";
11813: if ($actionurl eq '/adm/dependencies') {
11814: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11815: $numnew.'" />'."\n";
11816: } elsif ($actionurl eq '') {
1.987 raeburn 11817: $output .= '<input type="hidden" name="phase" value="three" />';
11818: }
11819: } elsif ($applies) {
11820: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11821: if ($applies > 1) {
11822: $output .=
1.1123 raeburn 11823: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11824: if ($numremref) {
11825: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11826: }
11827: if ($numinvalid) {
11828: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11829: }
11830: if ($numexisting) {
11831: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11832: }
11833: $output .= '</ul><br />';
11834: } elsif ($numremref) {
11835: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11836: } elsif ($numinvalid) {
11837: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11838: } elsif ($numexisting) {
11839: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11840: }
11841: $output .= $upload_output.'<br />';
11842: }
11843: my ($pathchange_output,$chgcount);
1.1071 raeburn 11844: $chgcount = $counter;
1.987 raeburn 11845: if (keys(%pathchanges) > 0) {
11846: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11847: if ($counter) {
1.987 raeburn 11848: $output .= &embedded_file_element('pathchange',$chgcount,
11849: $embed_file,\%mapping,
1.1071 raeburn 11850: $allfiles,$codebase,'change');
1.987 raeburn 11851: } else {
11852: $pathchange_output .=
11853: &start_data_table_row().
11854: '<td><input type ="checkbox" name="namechange" value="'.
11855: $chgcount.'" checked="checked" /></td>'.
11856: '<td>'.$mapping{$embed_file}.'</td>'.
11857: '<td>'.$embed_file.
11858: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11859: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11860: '</td>'.&end_data_table_row();
1.660 raeburn 11861: }
1.987 raeburn 11862: $numpathchg ++;
11863: $chgcount ++;
1.660 raeburn 11864: }
11865: }
1.1127 raeburn 11866: if (($counter) || ($numunused)) {
1.987 raeburn 11867: if ($numpathchg) {
11868: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11869: $numpathchg.'" />'."\n";
11870: }
11871: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11872: ($actionurl eq '/adm/imsimport')) {
11873: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11874: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11875: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11876: } elsif ($actionurl eq '/adm/dependencies') {
11877: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11878: }
1.1123 raeburn 11879: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11880: } elsif ($numpathchg) {
11881: my %pathchange = ();
11882: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11883: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11884: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 11885: }
1.987 raeburn 11886: }
1.1071 raeburn 11887: return ($output,$counter,$numpathchg);
1.987 raeburn 11888: }
11889:
1.1147 raeburn 11890: =pod
11891:
11892: =item * clean_path($name)
11893:
11894: Performs clean-up of directories, subdirectories and filename in an
11895: embedded object, referenced in an HTML file which is being uploaded
11896: to a course or portfolio, where
11897: "Upload embedded images/multimedia files if HTML file" checkbox was
11898: checked.
11899:
11900: Clean-up is similar to replacements in lonnet::clean_filename()
11901: except each / between sub-directory and next level is preserved.
11902:
11903: =cut
11904:
11905: sub clean_path {
11906: my ($embed_file) = @_;
11907: $embed_file =~s{^/+}{};
11908: my @contents;
11909: if ($embed_file =~ m{/}) {
11910: @contents = split(/\//,$embed_file);
11911: } else {
11912: @contents = ($embed_file);
11913: }
11914: my $lastidx = scalar(@contents)-1;
11915: for (my $i=0; $i<=$lastidx; $i++) {
11916: $contents[$i]=~s{\\}{/}g;
11917: $contents[$i]=~s/\s+/\_/g;
11918: $contents[$i]=~s{[^/\w\.\-]}{}g;
11919: if ($i == $lastidx) {
11920: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11921: }
11922: }
11923: if ($lastidx > 0) {
11924: return join('/',@contents);
11925: } else {
11926: return $contents[0];
11927: }
11928: }
11929:
1.987 raeburn 11930: sub embedded_file_element {
1.1071 raeburn 11931: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11932: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11933: (ref($codebase) eq 'HASH'));
11934: my $output;
1.1071 raeburn 11935: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11936: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11937: }
11938: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11939: &escape($embed_file).'" />';
11940: unless (($context eq 'upload_embedded') &&
11941: ($mapping->{$embed_file} eq $embed_file)) {
11942: $output .='
11943: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11944: }
11945: my $attrib;
11946: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11947: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11948: }
11949: $output .=
11950: "\n\t\t".
11951: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11952: $attrib.'" />';
11953: if (exists($codebase->{$mapping->{$embed_file}})) {
11954: $output .=
11955: "\n\t\t".
11956: '<input name="codebase_'.$num.'" type="hidden" value="'.
11957: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11958: }
1.987 raeburn 11959: return $output;
1.660 raeburn 11960: }
11961:
1.1071 raeburn 11962: sub get_dependency_details {
11963: my ($currfile,$currsubfile,$embed_file) = @_;
11964: my ($size,$mtime,$showsize,$showmtime);
11965: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11966: if ($embed_file =~ m{/}) {
11967: my ($path,$fname) = split(/\//,$embed_file);
11968: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11969: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11970: }
11971: } else {
11972: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11973: ($size,$mtime) = @{$currfile->{$embed_file}};
11974: }
11975: }
11976: $showsize = $size/1024.0;
11977: $showsize = sprintf("%.1f",$showsize);
11978: if ($mtime > 0) {
11979: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11980: }
11981: }
11982: return ($showsize,$showmtime);
11983: }
11984:
11985: sub ask_embedded_js {
11986: return <<"END";
11987: <script type="text/javascript"">
11988: // <![CDATA[
11989: function toggleBrowse(counter) {
11990: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11991: var fileid = document.getElementById('embedded_item_'+counter);
11992: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11993: if (chkboxid.checked == true) {
11994: uploaddivid.style.display='block';
11995: } else {
11996: uploaddivid.style.display='none';
11997: fileid.value = '';
11998: }
11999: }
12000: // ]]>
12001: </script>
12002:
12003: END
12004: }
12005:
1.661 raeburn 12006: sub upload_embedded {
12007: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12008: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12009: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12010: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12011: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12012: my $orig_uploaded_filename =
12013: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12014: foreach my $type ('orig','ref','attrib','codebase') {
12015: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12016: $env{'form.embedded_'.$type.'_'.$i} =
12017: &unescape($env{'form.embedded_'.$type.'_'.$i});
12018: }
12019: }
1.661 raeburn 12020: my ($path,$fname) =
12021: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12022: # no path, whole string is fname
12023: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12024: $fname = &Apache::lonnet::clean_filename($fname);
12025: # See if there is anything left
12026: next if ($fname eq '');
12027:
12028: # Check if file already exists as a file or directory.
12029: my ($state,$msg);
12030: if ($context eq 'portfolio') {
12031: my $port_path = $dirpath;
12032: if ($group ne '') {
12033: $port_path = "groups/$group/$port_path";
12034: }
1.987 raeburn 12035: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12036: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12037: $dir_root,$port_path,$disk_quota,
12038: $current_disk_usage,$uname,$udom);
12039: if ($state eq 'will_exceed_quota'
1.984 raeburn 12040: || $state eq 'file_locked') {
1.661 raeburn 12041: $output .= $msg;
12042: next;
12043: }
12044: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12045: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12046: if ($state eq 'exists') {
12047: $output .= $msg;
12048: next;
12049: }
12050: }
12051: # Check if extension is valid
12052: if (($fname =~ /\.(\w+)$/) &&
12053: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 12054: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12055: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12056: next;
12057: } elsif (($fname =~ /\.(\w+)$/) &&
12058: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12059: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12060: next;
12061: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 12062: $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 12063: next;
12064: }
12065: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 12066: my $subdir = $path;
12067: $subdir =~ s{/+$}{};
1.661 raeburn 12068: if ($context eq 'portfolio') {
1.984 raeburn 12069: my $result;
12070: if ($state eq 'existingfile') {
12071: $result=
12072: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 12073: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12074: } else {
1.984 raeburn 12075: $result=
12076: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12077: $dirpath.
1.1123 raeburn 12078: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12079: if ($result !~ m|^/uploaded/|) {
12080: $output .= '<span class="LC_error">'
12081: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12082: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12083: .'</span><br />';
12084: next;
12085: } else {
1.987 raeburn 12086: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12087: $path.$fname.'</span>').'<br />';
1.984 raeburn 12088: }
1.661 raeburn 12089: }
1.1123 raeburn 12090: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 12091: my $extendedsubdir = $dirpath.'/'.$subdir;
12092: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12093: my $result =
1.1126 raeburn 12094: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12095: if ($result !~ m|^/uploaded/|) {
12096: $output .= '<span class="LC_error">'
12097: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12098: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12099: .'</span><br />';
12100: next;
12101: } else {
12102: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12103: $path.$fname.'</span>').'<br />';
1.1125 raeburn 12104: if ($context eq 'syllabus') {
12105: &Apache::lonnet::make_public_indefinitely($result);
12106: }
1.987 raeburn 12107: }
1.661 raeburn 12108: } else {
12109: # Save the file
12110: my $target = $env{'form.embedded_item_'.$i};
12111: my $fullpath = $dir_root.$dirpath.'/'.$path;
12112: my $dest = $fullpath.$fname;
12113: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12114: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12115: my $count;
12116: my $filepath = $dir_root;
1.1027 raeburn 12117: foreach my $subdir (@parts) {
12118: $filepath .= "/$subdir";
12119: if (!-e $filepath) {
1.661 raeburn 12120: mkdir($filepath,0770);
12121: }
12122: }
12123: my $fh;
12124: if (!open($fh,'>'.$dest)) {
12125: &Apache::lonnet::logthis('Failed to create '.$dest);
12126: $output .= '<span class="LC_error">'.
1.1071 raeburn 12127: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12128: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12129: '</span><br />';
12130: } else {
12131: if (!print $fh $env{'form.embedded_item_'.$i}) {
12132: &Apache::lonnet::logthis('Failed to write to '.$dest);
12133: $output .= '<span class="LC_error">'.
1.1071 raeburn 12134: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12135: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12136: '</span><br />';
12137: } else {
1.987 raeburn 12138: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12139: $url.'</span>').'<br />';
12140: unless ($context eq 'testbank') {
12141: $footer .= &mt('View embedded file: [_1]',
12142: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12143: }
12144: }
12145: close($fh);
12146: }
12147: }
12148: if ($env{'form.embedded_ref_'.$i}) {
12149: $pathchange{$i} = 1;
12150: }
12151: }
12152: if ($output) {
12153: $output = '<p>'.$output.'</p>';
12154: }
12155: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12156: $returnflag = 'ok';
1.1071 raeburn 12157: my $numpathchgs = scalar(keys(%pathchange));
12158: if ($numpathchgs > 0) {
1.987 raeburn 12159: if ($context eq 'portfolio') {
12160: $output .= '<p>'.&mt('or').'</p>';
12161: } elsif ($context eq 'testbank') {
1.1071 raeburn 12162: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12163: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12164: $returnflag = 'modify_orightml';
12165: }
12166: }
1.1071 raeburn 12167: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12168: }
12169:
12170: sub modify_html_form {
12171: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12172: my $end = 0;
12173: my $modifyform;
12174: if ($context eq 'upload_embedded') {
12175: return unless (ref($pathchange) eq 'HASH');
12176: if ($env{'form.number_embedded_items'}) {
12177: $end += $env{'form.number_embedded_items'};
12178: }
12179: if ($env{'form.number_pathchange_items'}) {
12180: $end += $env{'form.number_pathchange_items'};
12181: }
12182: if ($end) {
12183: for (my $i=0; $i<$end; $i++) {
12184: if ($i < $env{'form.number_embedded_items'}) {
12185: next unless($pathchange->{$i});
12186: }
12187: $modifyform .=
12188: &start_data_table_row().
12189: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12190: 'checked="checked" /></td>'.
12191: '<td>'.$env{'form.embedded_ref_'.$i}.
12192: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12193: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12194: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12195: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12196: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12197: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12198: '<td>'.$env{'form.embedded_orig_'.$i}.
12199: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12200: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12201: &end_data_table_row();
1.1071 raeburn 12202: }
1.987 raeburn 12203: }
12204: } else {
12205: $modifyform = $pathchgtable;
12206: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12207: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12208: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12209: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12210: }
12211: }
12212: if ($modifyform) {
1.1071 raeburn 12213: if ($actionurl eq '/adm/dependencies') {
12214: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12215: }
1.987 raeburn 12216: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12217: '<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".
12218: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12219: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12220: '</ol></p>'."\n".'<p>'.
12221: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12222: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12223: &start_data_table()."\n".
12224: &start_data_table_header_row().
12225: '<th>'.&mt('Change?').'</th>'.
12226: '<th>'.&mt('Current reference').'</th>'.
12227: '<th>'.&mt('Required reference').'</th>'.
12228: &end_data_table_header_row()."\n".
12229: $modifyform.
12230: &end_data_table().'<br />'."\n".$hiddenstate.
12231: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12232: '</form>'."\n";
12233: }
12234: return;
12235: }
12236:
12237: sub modify_html_refs {
1.1123 raeburn 12238: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12239: my $container;
12240: if ($context eq 'portfolio') {
12241: $container = $env{'form.container'};
12242: } elsif ($context eq 'coursedoc') {
12243: $container = $env{'form.primaryurl'};
1.1071 raeburn 12244: } elsif ($context eq 'manage_dependencies') {
12245: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12246: $container = "/$container";
1.1123 raeburn 12247: } elsif ($context eq 'syllabus') {
12248: $container = $url;
1.987 raeburn 12249: } else {
1.1027 raeburn 12250: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12251: }
12252: my (%allfiles,%codebase,$output,$content);
12253: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 12254: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12255: if (wantarray) {
12256: return ('',0,0);
12257: } else {
12258: return;
12259: }
12260: }
12261: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12262: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12263: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12264: if (wantarray) {
12265: return ('',0,0);
12266: } else {
12267: return;
12268: }
12269: }
1.987 raeburn 12270: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12271: if ($content eq '-1') {
12272: if (wantarray) {
12273: return ('',0,0);
12274: } else {
12275: return;
12276: }
12277: }
1.987 raeburn 12278: } else {
1.1071 raeburn 12279: unless ($container =~ /^\Q$dir_root\E/) {
12280: if (wantarray) {
12281: return ('',0,0);
12282: } else {
12283: return;
12284: }
12285: }
1.1317 raeburn 12286: if (open(my $fh,'<',$container)) {
1.987 raeburn 12287: $content = join('', <$fh>);
12288: close($fh);
12289: } else {
1.1071 raeburn 12290: if (wantarray) {
12291: return ('',0,0);
12292: } else {
12293: return;
12294: }
1.987 raeburn 12295: }
12296: }
12297: my ($count,$codebasecount) = (0,0);
12298: my $mm = new File::MMagic;
12299: my $mime_type = $mm->checktype_contents($content);
12300: if ($mime_type eq 'text/html') {
12301: my $parse_result =
12302: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12303: \%codebase,\$content);
12304: if ($parse_result eq 'ok') {
12305: foreach my $i (@changes) {
12306: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12307: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12308: if ($allfiles{$ref}) {
12309: my $newname = $orig;
12310: my ($attrib_regexp,$codebase);
1.1006 raeburn 12311: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12312: if ($attrib_regexp =~ /:/) {
12313: $attrib_regexp =~ s/\:/|/g;
12314: }
12315: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12316: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12317: $count += $numchg;
1.1123 raeburn 12318: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 12319: delete($allfiles{$ref});
1.987 raeburn 12320: }
12321: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12322: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12323: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12324: $codebasecount ++;
12325: }
12326: }
12327: }
1.1123 raeburn 12328: my $skiprewrites;
1.987 raeburn 12329: if ($count || $codebasecount) {
12330: my $saveresult;
1.1071 raeburn 12331: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12332: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12333: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12334: if ($url eq $container) {
12335: my ($fname) = ($container =~ m{/([^/]+)$});
12336: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12337: $count,'<span class="LC_filename">'.
1.1071 raeburn 12338: $fname.'</span>').'</p>';
1.987 raeburn 12339: } else {
12340: $output = '<p class="LC_error">'.
12341: &mt('Error: update failed for: [_1].',
12342: '<span class="LC_filename">'.
12343: $container.'</span>').'</p>';
12344: }
1.1123 raeburn 12345: if ($context eq 'syllabus') {
12346: unless ($saveresult eq 'ok') {
12347: $skiprewrites = 1;
12348: }
12349: }
1.987 raeburn 12350: } else {
1.1317 raeburn 12351: if (open(my $fh,'>',$container)) {
1.987 raeburn 12352: print $fh $content;
12353: close($fh);
12354: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12355: $count,'<span class="LC_filename">'.
12356: $container.'</span>').'</p>';
1.661 raeburn 12357: } else {
1.987 raeburn 12358: $output = '<p class="LC_error">'.
12359: &mt('Error: could not update [_1].',
12360: '<span class="LC_filename">'.
12361: $container.'</span>').'</p>';
1.661 raeburn 12362: }
12363: }
12364: }
1.1123 raeburn 12365: if (($context eq 'syllabus') && (!$skiprewrites)) {
12366: my ($actionurl,$state);
12367: $actionurl = "/public/$udom/$uname/syllabus";
12368: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12369: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12370: \%codebase,
12371: {'context' => 'rewrites',
12372: 'ignore_remote_references' => 1,});
12373: if (ref($mapping) eq 'HASH') {
12374: my $rewrites = 0;
12375: foreach my $key (keys(%{$mapping})) {
12376: next if ($key =~ m{^https?://});
12377: my $ref = $mapping->{$key};
12378: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12379: my $attrib;
12380: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12381: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12382: }
12383: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12384: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12385: $rewrites += $numchg;
12386: }
12387: }
12388: if ($rewrites) {
12389: my $saveresult;
12390: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12391: if ($url eq $container) {
12392: my ($fname) = ($container =~ m{/([^/]+)$});
12393: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12394: $count,'<span class="LC_filename">'.
12395: $fname.'</span>').'</p>';
12396: } else {
12397: $output .= '<p class="LC_error">'.
12398: &mt('Error: could not update links in [_1].',
12399: '<span class="LC_filename">'.
12400: $container.'</span>').'</p>';
12401:
12402: }
12403: }
12404: }
12405: }
1.987 raeburn 12406: } else {
12407: &logthis('Failed to parse '.$container.
12408: ' to modify references: '.$parse_result);
1.661 raeburn 12409: }
12410: }
1.1071 raeburn 12411: if (wantarray) {
12412: return ($output,$count,$codebasecount);
12413: } else {
12414: return $output;
12415: }
1.661 raeburn 12416: }
12417:
12418: sub check_for_existing {
12419: my ($path,$fname,$element) = @_;
12420: my ($state,$msg);
12421: if (-d $path.'/'.$fname) {
12422: $state = 'exists';
12423: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12424: } elsif (-e $path.'/'.$fname) {
12425: $state = 'exists';
12426: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12427: }
12428: if ($state eq 'exists') {
12429: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12430: }
12431: return ($state,$msg);
12432: }
12433:
12434: sub check_for_upload {
12435: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12436: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12437: my $filesize = length($env{'form.'.$element});
12438: if (!$filesize) {
12439: my $msg = '<span class="LC_error">'.
12440: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12441: '<span class="LC_filename">'.$fname.'</span>',
12442: $filesize).'<br />'.
1.1007 raeburn 12443: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12444: '</span>';
12445: return ('zero_bytes',$msg);
12446: }
12447: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12448: my $getpropath = 1;
1.1021 raeburn 12449: my ($dirlistref,$listerror) =
12450: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12451: my $found_file = 0;
12452: my $locked_file = 0;
1.991 raeburn 12453: my @lockers;
12454: my $navmap;
12455: if ($env{'request.course.id'}) {
12456: $navmap = Apache::lonnavmaps::navmap->new();
12457: }
1.1021 raeburn 12458: if (ref($dirlistref) eq 'ARRAY') {
12459: foreach my $line (@{$dirlistref}) {
12460: my ($file_name,$rest)=split(/\&/,$line,2);
12461: if ($file_name eq $fname){
12462: $file_name = $path.$file_name;
12463: if ($group ne '') {
12464: $file_name = $group.$file_name;
12465: }
12466: $found_file = 1;
12467: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12468: foreach my $lock (@lockers) {
12469: if (ref($lock) eq 'ARRAY') {
12470: my ($symb,$crsid) = @{$lock};
12471: if ($crsid eq $env{'request.course.id'}) {
12472: if (ref($navmap)) {
12473: my $res = $navmap->getBySymb($symb);
12474: foreach my $part (@{$res->parts()}) {
12475: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12476: unless (($slot_status == $res->RESERVED) ||
12477: ($slot_status == $res->RESERVED_LOCATION)) {
12478: $locked_file = 1;
12479: }
1.991 raeburn 12480: }
1.1021 raeburn 12481: } else {
12482: $locked_file = 1;
1.991 raeburn 12483: }
12484: } else {
12485: $locked_file = 1;
12486: }
12487: }
1.1021 raeburn 12488: }
12489: } else {
12490: my @info = split(/\&/,$rest);
12491: my $currsize = $info[6]/1000;
12492: if ($currsize < $filesize) {
12493: my $extra = $filesize - $currsize;
12494: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12495: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12496: &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 12497: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12498: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12499: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12500: return ('will_exceed_quota',$msg);
12501: }
1.984 raeburn 12502: }
12503: }
1.661 raeburn 12504: }
12505: }
12506: }
12507: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12508: my $msg = '<p class="LC_warning">'.
12509: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12510: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12511: return ('will_exceed_quota',$msg);
12512: } elsif ($found_file) {
12513: if ($locked_file) {
1.1179 bisitz 12514: my $msg = '<p class="LC_warning">';
1.661 raeburn 12515: $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 12516: $msg .= '</p>';
1.661 raeburn 12517: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12518: return ('file_locked',$msg);
12519: } else {
1.1179 bisitz 12520: my $msg = '<p class="LC_error">';
1.984 raeburn 12521: $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 12522: $msg .= '</p>';
1.984 raeburn 12523: return ('existingfile',$msg);
1.661 raeburn 12524: }
12525: }
12526: }
12527:
1.987 raeburn 12528: sub check_for_traversal {
12529: my ($path,$url,$toplevel) = @_;
12530: my @parts=split(/\//,$path);
12531: my $cleanpath;
12532: my $fullpath = $url;
12533: for (my $i=0;$i<@parts;$i++) {
12534: next if ($parts[$i] eq '.');
12535: if ($parts[$i] eq '..') {
12536: $fullpath =~ s{([^/]+/)$}{};
12537: } else {
12538: $fullpath .= $parts[$i].'/';
12539: }
12540: }
12541: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12542: $cleanpath = $1;
12543: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12544: my $curr_toprel = $1;
12545: my @parts = split(/\//,$curr_toprel);
12546: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12547: my @urlparts = split(/\//,$url_toprel);
12548: my $doubledots;
12549: my $startdiff = -1;
12550: for (my $i=0; $i<@urlparts; $i++) {
12551: if ($startdiff == -1) {
12552: unless ($urlparts[$i] eq $parts[$i]) {
12553: $startdiff = $i;
12554: $doubledots .= '../';
12555: }
12556: } else {
12557: $doubledots .= '../';
12558: }
12559: }
12560: if ($startdiff > -1) {
12561: $cleanpath = $doubledots;
12562: for (my $i=$startdiff; $i<@parts; $i++) {
12563: $cleanpath .= $parts[$i].'/';
12564: }
12565: }
12566: }
12567: $cleanpath =~ s{(/)$}{};
12568: return $cleanpath;
12569: }
1.31 albertel 12570:
1.1053 raeburn 12571: sub is_archive_file {
12572: my ($mimetype) = @_;
12573: if (($mimetype eq 'application/octet-stream') ||
12574: ($mimetype eq 'application/x-stuffit') ||
12575: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12576: return 1;
12577: }
12578: return;
12579: }
12580:
12581: sub decompress_form {
1.1065 raeburn 12582: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12583: my %lt = &Apache::lonlocal::texthash (
12584: this => 'This file is an archive file.',
1.1067 raeburn 12585: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12586: itsc => 'Its contents are as follows:',
1.1053 raeburn 12587: youm => 'You may wish to extract its contents.',
12588: extr => 'Extract contents',
1.1067 raeburn 12589: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12590: proa => 'Process automatically?',
1.1053 raeburn 12591: yes => 'Yes',
12592: no => 'No',
1.1067 raeburn 12593: fold => 'Title for folder containing movie',
12594: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12595: );
1.1065 raeburn 12596: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12597: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12598: my $info = &list_archive_contents($fileloc,\@paths);
12599: if (@paths) {
12600: foreach my $path (@paths) {
12601: $path =~ s{^/}{};
1.1067 raeburn 12602: if ($path =~ m{^([^/]+)/$}) {
12603: $topdir = $1;
12604: }
1.1065 raeburn 12605: if ($path =~ m{^([^/]+)/}) {
12606: $toplevel{$1} = $path;
12607: } else {
12608: $toplevel{$path} = $path;
12609: }
12610: }
12611: }
1.1067 raeburn 12612: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12613: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12614: "$topdir/media/",
12615: "$topdir/media/$topdir.mp4",
12616: "$topdir/media/FirstFrame.png",
12617: "$topdir/media/player.swf",
12618: "$topdir/media/swfobject.js",
12619: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12620: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12621: "$topdir/$topdir.mp4",
12622: "$topdir/$topdir\_config.xml",
12623: "$topdir/$topdir\_controller.swf",
12624: "$topdir/$topdir\_embed.css",
12625: "$topdir/$topdir\_First_Frame.png",
12626: "$topdir/$topdir\_player.html",
12627: "$topdir/$topdir\_Thumbnails.png",
12628: "$topdir/playerProductInstall.swf",
12629: "$topdir/scripts/",
12630: "$topdir/scripts/config_xml.js",
12631: "$topdir/scripts/handlebars.js",
12632: "$topdir/scripts/jquery-1.7.1.min.js",
12633: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12634: "$topdir/scripts/modernizr.js",
12635: "$topdir/scripts/player-min.js",
12636: "$topdir/scripts/swfobject.js",
12637: "$topdir/skins/",
12638: "$topdir/skins/configuration_express.xml",
12639: "$topdir/skins/express_show/",
12640: "$topdir/skins/express_show/player-min.css",
12641: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12642: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12643: "$topdir/$topdir.mp4",
12644: "$topdir/$topdir\_config.xml",
12645: "$topdir/$topdir\_controller.swf",
12646: "$topdir/$topdir\_embed.css",
12647: "$topdir/$topdir\_First_Frame.png",
12648: "$topdir/$topdir\_player.html",
12649: "$topdir/$topdir\_Thumbnails.png",
12650: "$topdir/playerProductInstall.swf",
12651: "$topdir/scripts/",
12652: "$topdir/scripts/config_xml.js",
12653: "$topdir/scripts/techsmith-smart-player.min.js",
12654: "$topdir/skins/",
12655: "$topdir/skins/configuration_express.xml",
12656: "$topdir/skins/express_show/",
12657: "$topdir/skins/express_show/spritesheet.min.css",
12658: "$topdir/skins/express_show/spritesheet.png",
12659: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12660: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12661: if (@diffs == 0) {
1.1164 raeburn 12662: $is_camtasia = 6;
12663: } else {
1.1197 raeburn 12664: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12665: if (@diffs == 0) {
12666: $is_camtasia = 8;
1.1197 raeburn 12667: } else {
12668: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12669: if (@diffs == 0) {
12670: $is_camtasia = 8;
12671: }
1.1164 raeburn 12672: }
1.1067 raeburn 12673: }
12674: }
12675: my $output;
12676: if ($is_camtasia) {
12677: $output = <<"ENDCAM";
12678: <script type="text/javascript" language="Javascript">
12679: // <![CDATA[
12680:
12681: function camtasiaToggle() {
12682: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12683: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12684: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12685: document.getElementById('camtasia_titles').style.display='block';
12686: } else {
12687: document.getElementById('camtasia_titles').style.display='none';
12688: }
12689: }
12690: }
12691: return;
12692: }
12693:
12694: // ]]>
12695: </script>
12696: <p>$lt{'camt'}</p>
12697: ENDCAM
1.1065 raeburn 12698: } else {
1.1067 raeburn 12699: $output = '<p>'.$lt{'this'};
12700: if ($info eq '') {
12701: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12702: } else {
12703: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12704: '<div><pre>'.$info.'</pre></div>';
12705: }
1.1065 raeburn 12706: }
1.1067 raeburn 12707: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12708: my $duplicates;
12709: my $num = 0;
12710: if (ref($dirlist) eq 'ARRAY') {
12711: foreach my $item (@{$dirlist}) {
12712: if (ref($item) eq 'ARRAY') {
12713: if (exists($toplevel{$item->[0]})) {
12714: $duplicates .=
12715: &start_data_table_row().
12716: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12717: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12718: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12719: 'value="1" />'.&mt('Yes').'</label>'.
12720: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12721: '<td>'.$item->[0].'</td>';
12722: if ($item->[2]) {
12723: $duplicates .= '<td>'.&mt('Directory').'</td>';
12724: } else {
12725: $duplicates .= '<td>'.&mt('File').'</td>';
12726: }
12727: $duplicates .= '<td>'.$item->[3].'</td>'.
12728: '<td>'.
12729: &Apache::lonlocal::locallocaltime($item->[4]).
12730: '</td>'.
12731: &end_data_table_row();
12732: $num ++;
12733: }
12734: }
12735: }
12736: }
12737: my $itemcount;
12738: if (@paths > 0) {
12739: $itemcount = scalar(@paths);
12740: } else {
12741: $itemcount = 1;
12742: }
1.1067 raeburn 12743: if ($is_camtasia) {
12744: $output .= $lt{'auto'}.'<br />'.
12745: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12746: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12747: $lt{'yes'}.'</label> <label>'.
12748: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12749: $lt{'no'}.'</label></span><br />'.
12750: '<div id="camtasia_titles" style="display:block">'.
12751: &Apache::lonhtmlcommon::start_pick_box().
12752: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12753: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12754: &Apache::lonhtmlcommon::row_closure().
12755: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12756: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12757: &Apache::lonhtmlcommon::row_closure(1).
12758: &Apache::lonhtmlcommon::end_pick_box().
12759: '</div>';
12760: }
1.1065 raeburn 12761: $output .=
12762: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12763: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12764: "\n";
1.1065 raeburn 12765: if ($duplicates ne '') {
12766: $output .= '<p><span class="LC_warning">'.
12767: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12768: &start_data_table().
12769: &start_data_table_header_row().
12770: '<th>'.&mt('Overwrite?').'</th>'.
12771: '<th>'.&mt('Name').'</th>'.
12772: '<th>'.&mt('Type').'</th>'.
12773: '<th>'.&mt('Size').'</th>'.
12774: '<th>'.&mt('Last modified').'</th>'.
12775: &end_data_table_header_row().
12776: $duplicates.
12777: &end_data_table().
12778: '</p>';
12779: }
1.1067 raeburn 12780: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12781: if (ref($hiddenelements) eq 'HASH') {
12782: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12783: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12784: }
12785: }
12786: $output .= <<"END";
1.1067 raeburn 12787: <br />
1.1053 raeburn 12788: <input type="submit" name="decompress" value="$lt{'extr'}" />
12789: </form>
12790: $noextract
12791: END
12792: return $output;
12793: }
12794:
1.1065 raeburn 12795: sub decompression_utility {
12796: my ($program) = @_;
12797: my @utilities = ('tar','gunzip','bunzip2','unzip');
12798: my $location;
12799: if (grep(/^\Q$program\E$/,@utilities)) {
12800: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12801: '/usr/sbin/') {
12802: if (-x $dir.$program) {
12803: $location = $dir.$program;
12804: last;
12805: }
12806: }
12807: }
12808: return $location;
12809: }
12810:
12811: sub list_archive_contents {
12812: my ($file,$pathsref) = @_;
12813: my (@cmd,$output);
12814: my $needsregexp;
12815: if ($file =~ /\.zip$/) {
12816: @cmd = (&decompression_utility('unzip'),"-l");
12817: $needsregexp = 1;
12818: } elsif (($file =~ m/\.tar\.gz$/) ||
12819: ($file =~ /\.tgz$/)) {
12820: @cmd = (&decompression_utility('tar'),"-ztf");
12821: } elsif ($file =~ /\.tar\.bz2$/) {
12822: @cmd = (&decompression_utility('tar'),"-jtf");
12823: } elsif ($file =~ m|\.tar$|) {
12824: @cmd = (&decompression_utility('tar'),"-tf");
12825: }
12826: if (@cmd) {
12827: undef($!);
12828: undef($@);
12829: if (open(my $fh,"-|", @cmd, $file)) {
12830: while (my $line = <$fh>) {
12831: $output .= $line;
12832: chomp($line);
12833: my $item;
12834: if ($needsregexp) {
12835: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12836: } else {
12837: $item = $line;
12838: }
12839: if ($item ne '') {
12840: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12841: push(@{$pathsref},$item);
12842: }
12843: }
12844: }
12845: close($fh);
12846: }
12847: }
12848: return $output;
12849: }
12850:
1.1053 raeburn 12851: sub decompress_uploaded_file {
12852: my ($file,$dir) = @_;
12853: &Apache::lonnet::appenv({'cgi.file' => $file});
12854: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12855: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12856: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12857: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12858: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12859: my $decompressed = $env{'cgi.decompressed'};
12860: &Apache::lonnet::delenv('cgi.file');
12861: &Apache::lonnet::delenv('cgi.dir');
12862: &Apache::lonnet::delenv('cgi.decompressed');
12863: return ($decompressed,$result);
12864: }
12865:
1.1055 raeburn 12866: sub process_decompression {
12867: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 12868: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12869: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12870: &mt('Unexpected file path.').'</p>'."\n";
12871: }
12872: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12873: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12874: &mt('Unexpected course context.').'</p>'."\n";
12875: }
1.1293 raeburn 12876: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 12877: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12878: &mt('Filename contained unexpected characters.').'</p>'."\n";
12879: }
1.1055 raeburn 12880: my ($dir,$error,$warning,$output);
1.1180 raeburn 12881: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 12882: $error = &mt('Filename not a supported archive file type.').
12883: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12884: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12885: } else {
12886: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12887: if ($docuhome eq 'no_host') {
12888: $error = &mt('Could not determine home server for course.');
12889: } else {
12890: my @ids=&Apache::lonnet::current_machine_ids();
12891: my $currdir = "$dir_root/$destination";
12892: if (grep(/^\Q$docuhome\E$/,@ids)) {
12893: $dir = &LONCAPA::propath($docudom,$docuname).
12894: "$dir_root/$destination";
12895: } else {
12896: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12897: "$dir_root/$docudom/$docuname/$destination";
12898: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12899: $error = &mt('Archive file not found.');
12900: }
12901: }
1.1065 raeburn 12902: my (@to_overwrite,@to_skip);
12903: if ($env{'form.archive_overwrite_total'} > 0) {
12904: my $total = $env{'form.archive_overwrite_total'};
12905: for (my $i=0; $i<$total; $i++) {
12906: if ($env{'form.archive_overwrite_'.$i} == 1) {
12907: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12908: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12909: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12910: }
12911: }
12912: }
12913: my $numskip = scalar(@to_skip);
1.1292 raeburn 12914: my $numoverwrite = scalar(@to_overwrite);
12915: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12916: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12917: } elsif ($dir eq '') {
1.1055 raeburn 12918: $error = &mt('Directory containing archive file unavailable.');
12919: } elsif (!$error) {
1.1065 raeburn 12920: my ($decompressed,$display);
1.1292 raeburn 12921: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12922: my $tempdir = time.'_'.$$.int(rand(10000));
12923: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 12924: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12925: ($decompressed,$display) =
12926: &decompress_uploaded_file($file,"$dir/$tempdir");
12927: foreach my $item (@to_skip) {
12928: if (($item ne '') && ($item !~ /\.\./)) {
12929: if (-f "$dir/$tempdir/$item") {
12930: unlink("$dir/$tempdir/$item");
12931: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 12932: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 12933: }
12934: }
12935: }
12936: foreach my $item (@to_overwrite) {
12937: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12938: if (($item ne '') && ($item !~ /\.\./)) {
12939: if (-f "$dir/$item") {
12940: unlink("$dir/$item");
12941: } elsif (-d "$dir/$item") {
1.1300 raeburn 12942: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 12943: }
12944: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12945: }
1.1065 raeburn 12946: }
12947: }
1.1292 raeburn 12948: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 12949: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 12950: }
1.1065 raeburn 12951: }
12952: } else {
12953: ($decompressed,$display) =
12954: &decompress_uploaded_file($file,$dir);
12955: }
1.1055 raeburn 12956: if ($decompressed eq 'ok') {
1.1065 raeburn 12957: $output = '<p class="LC_info">'.
12958: &mt('Files extracted successfully from archive.').
12959: '</p>'."\n";
1.1055 raeburn 12960: my ($warning,$result,@contents);
12961: my ($newdirlistref,$newlisterror) =
12962: &Apache::lonnet::dirlist($currdir,$docudom,
12963: $docuname,1);
12964: my (%is_dir,%changes,@newitems);
12965: my $dirptr = 16384;
1.1065 raeburn 12966: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12967: foreach my $dir_line (@{$newdirlistref}) {
12968: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 12969: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12970: push(@newitems,$item);
12971: if ($dirptr&$testdir) {
12972: $is_dir{$item} = 1;
12973: }
12974: $changes{$item} = 1;
12975: }
12976: }
12977: }
12978: if (keys(%changes) > 0) {
12979: foreach my $item (sort(@newitems)) {
12980: if ($changes{$item}) {
12981: push(@contents,$item);
12982: }
12983: }
12984: }
12985: if (@contents > 0) {
1.1067 raeburn 12986: my $wantform;
12987: unless ($env{'form.autoextract_camtasia'}) {
12988: $wantform = 1;
12989: }
1.1056 raeburn 12990: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12991: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12992: $currdir,\%is_dir,
12993: \%children,\%parent,
1.1056 raeburn 12994: \@contents,\%dirorder,
12995: \%titles,$wantform);
1.1055 raeburn 12996: if ($datatable ne '') {
12997: $output .= &archive_options_form('decompressed',$datatable,
12998: $count,$hiddenelem);
1.1065 raeburn 12999: my $startcount = 6;
1.1055 raeburn 13000: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13001: \%titles,\%children);
1.1055 raeburn 13002: }
1.1067 raeburn 13003: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 13004: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13005: my %displayed;
13006: my $total = 1;
13007: $env{'form.archive_directory'} = [];
13008: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13009: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13010: $path =~ s{/$}{};
13011: my $item;
13012: if ($path ne '') {
13013: $item = "$path/$titles{$i}";
13014: } else {
13015: $item = $titles{$i};
13016: }
13017: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13018: if ($item eq $contents[0]) {
13019: push(@{$env{'form.archive_directory'}},$i);
13020: $env{'form.archive_'.$i} = 'display';
13021: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13022: $displayed{'folder'} = $i;
1.1164 raeburn 13023: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13024: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13025: $env{'form.archive_'.$i} = 'display';
13026: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13027: $displayed{'web'} = $i;
13028: } else {
1.1164 raeburn 13029: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13030: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13031: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13032: push(@{$env{'form.archive_directory'}},$i);
13033: }
13034: $env{'form.archive_'.$i} = 'dependency';
13035: }
13036: $total ++;
13037: }
13038: for (my $i=1; $i<$total; $i++) {
13039: next if ($i == $displayed{'web'});
13040: next if ($i == $displayed{'folder'});
13041: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13042: }
13043: $env{'form.phase'} = 'decompress_cleanup';
13044: $env{'form.archivedelete'} = 1;
13045: $env{'form.archive_count'} = $total-1;
13046: $output .=
13047: &process_extracted_files('coursedocs',$docudom,
13048: $docuname,$destination,
13049: $dir_root,$hiddenelem);
13050: }
1.1055 raeburn 13051: } else {
13052: $warning = &mt('No new items extracted from archive file.');
13053: }
13054: } else {
13055: $output = $display;
13056: $error = &mt('An error occurred during extraction from the archive file.');
13057: }
13058: }
13059: }
13060: }
13061: if ($error) {
13062: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13063: $error.'</p>'."\n";
13064: }
13065: if ($warning) {
13066: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13067: }
13068: return $output;
13069: }
13070:
13071: sub get_extracted {
1.1056 raeburn 13072: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13073: $titles,$wantform) = @_;
1.1055 raeburn 13074: my $count = 0;
13075: my $depth = 0;
13076: my $datatable;
1.1056 raeburn 13077: my @hierarchy;
1.1055 raeburn 13078: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13079: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13080: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13081: foreach my $item (@{$contents}) {
13082: $count ++;
1.1056 raeburn 13083: @{$dirorder->{$count}} = @hierarchy;
13084: $titles->{$count} = $item;
1.1055 raeburn 13085: &archive_hierarchy($depth,$count,$parent,$children);
13086: if ($wantform) {
13087: $datatable .= &archive_row($is_dir->{$item},$item,
13088: $currdir,$depth,$count);
13089: }
13090: if ($is_dir->{$item}) {
13091: $depth ++;
1.1056 raeburn 13092: push(@hierarchy,$count);
13093: $parent->{$depth} = $count;
1.1055 raeburn 13094: $datatable .=
13095: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13096: \$depth,\$count,\@hierarchy,$dirorder,
13097: $children,$parent,$titles,$wantform);
1.1055 raeburn 13098: $depth --;
1.1056 raeburn 13099: pop(@hierarchy);
1.1055 raeburn 13100: }
13101: }
13102: return ($count,$datatable);
13103: }
13104:
13105: sub recurse_extracted_archive {
1.1056 raeburn 13106: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13107: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13108: my $result='';
1.1056 raeburn 13109: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13110: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13111: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13112: return $result;
13113: }
13114: my $dirptr = 16384;
13115: my ($newdirlistref,$newlisterror) =
13116: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13117: if (ref($newdirlistref) eq 'ARRAY') {
13118: foreach my $dir_line (@{$newdirlistref}) {
13119: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13120: unless ($item =~ /^\.+$/) {
13121: $$count ++;
1.1056 raeburn 13122: @{$dirorder->{$$count}} = @{$hierarchy};
13123: $titles->{$$count} = $item;
1.1055 raeburn 13124: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13125:
1.1055 raeburn 13126: my $is_dir;
13127: if ($dirptr&$testdir) {
13128: $is_dir = 1;
13129: }
13130: if ($wantform) {
13131: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13132: }
13133: if ($is_dir) {
13134: $$depth ++;
1.1056 raeburn 13135: push(@{$hierarchy},$$count);
13136: $parent->{$$depth} = $$count;
1.1055 raeburn 13137: $result .=
13138: &recurse_extracted_archive("$currdir/$item",$docudom,
13139: $docuname,$depth,$count,
1.1056 raeburn 13140: $hierarchy,$dirorder,$children,
13141: $parent,$titles,$wantform);
1.1055 raeburn 13142: $$depth --;
1.1056 raeburn 13143: pop(@{$hierarchy});
1.1055 raeburn 13144: }
13145: }
13146: }
13147: }
13148: return $result;
13149: }
13150:
13151: sub archive_hierarchy {
13152: my ($depth,$count,$parent,$children) =@_;
13153: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13154: if (exists($parent->{$depth})) {
13155: $children->{$parent->{$depth}} .= $count.':';
13156: }
13157: }
13158: return;
13159: }
13160:
13161: sub archive_row {
13162: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13163: my ($name) = ($item =~ m{([^/]+)$});
13164: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13165: 'display' => 'Add as file',
1.1055 raeburn 13166: 'dependency' => 'Include as dependency',
13167: 'discard' => 'Discard',
13168: );
13169: if ($is_dir) {
1.1059 raeburn 13170: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13171: }
1.1056 raeburn 13172: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13173: my $offset = 0;
1.1055 raeburn 13174: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13175: $offset ++;
1.1065 raeburn 13176: if ($action ne 'display') {
13177: $offset ++;
13178: }
1.1055 raeburn 13179: $output .= '<td><span class="LC_nobreak">'.
13180: '<label><input type="radio" name="archive_'.$count.
13181: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13182: my $text = $choices{$action};
13183: if ($is_dir) {
13184: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13185: if ($action eq 'display') {
1.1059 raeburn 13186: $text = &mt('Add as folder');
1.1055 raeburn 13187: }
1.1056 raeburn 13188: } else {
13189: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13190:
13191: }
13192: $output .= ' /> '.$choices{$action}.'</label></span>';
13193: if ($action eq 'dependency') {
13194: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13195: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13196: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13197: '<option value=""></option>'."\n".
13198: '</select>'."\n".
13199: '</div>';
1.1059 raeburn 13200: } elsif ($action eq 'display') {
13201: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13202: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13203: '</div>';
1.1055 raeburn 13204: }
1.1056 raeburn 13205: $output .= '</td>';
1.1055 raeburn 13206: }
13207: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13208: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13209: for (my $i=0; $i<$depth; $i++) {
13210: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13211: }
13212: if ($is_dir) {
13213: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13214: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13215: } else {
13216: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13217: }
13218: $output .= ' '.$name.'</td>'."\n".
13219: &end_data_table_row();
13220: return $output;
13221: }
13222:
13223: sub archive_options_form {
1.1065 raeburn 13224: my ($form,$display,$count,$hiddenelem) = @_;
13225: my %lt = &Apache::lonlocal::texthash(
13226: perm => 'Permanently remove archive file?',
13227: hows => 'How should each extracted item be incorporated in the course?',
13228: cont => 'Content actions for all',
13229: addf => 'Add as folder/file',
13230: incd => 'Include as dependency for a displayed file',
13231: disc => 'Discard',
13232: no => 'No',
13233: yes => 'Yes',
13234: save => 'Save',
13235: );
13236: my $output = <<"END";
13237: <form name="$form" method="post" action="">
13238: <p><span class="LC_nobreak">$lt{'perm'}
13239: <label>
13240: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13241: </label>
13242:
13243: <label>
13244: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13245: </span>
13246: </p>
13247: <input type="hidden" name="phase" value="decompress_cleanup" />
13248: <br />$lt{'hows'}
13249: <div class="LC_columnSection">
13250: <fieldset>
13251: <legend>$lt{'cont'}</legend>
13252: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13253: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13254: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13255: </fieldset>
13256: </div>
13257: END
13258: return $output.
1.1055 raeburn 13259: &start_data_table()."\n".
1.1065 raeburn 13260: $display."\n".
1.1055 raeburn 13261: &end_data_table()."\n".
13262: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13263: $hiddenelem.
1.1065 raeburn 13264: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13265: '</form>';
13266: }
13267:
13268: sub archive_javascript {
1.1056 raeburn 13269: my ($startcount,$numitems,$titles,$children) = @_;
13270: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13271: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13272: my $scripttag = <<START;
13273: <script type="text/javascript">
13274: // <![CDATA[
13275:
13276: function checkAll(form,prefix) {
13277: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13278: for (var i=0; i < form.elements.length; i++) {
13279: var id = form.elements[i].id;
13280: if ((id != '') && (id != undefined)) {
13281: if (idstr.test(id)) {
13282: if (form.elements[i].type == 'radio') {
13283: form.elements[i].checked = true;
1.1056 raeburn 13284: var nostart = i-$startcount;
1.1059 raeburn 13285: var offset = nostart%7;
13286: var count = (nostart-offset)/7;
1.1056 raeburn 13287: dependencyCheck(form,count,offset);
1.1055 raeburn 13288: }
13289: }
13290: }
13291: }
13292: }
13293:
13294: function propagateCheck(form,count) {
13295: if (count > 0) {
1.1059 raeburn 13296: var startelement = $startcount + ((count-1) * 7);
13297: for (var j=1; j<6; j++) {
13298: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13299: var item = startelement + j;
13300: if (form.elements[item].type == 'radio') {
13301: if (form.elements[item].checked) {
13302: containerCheck(form,count,j);
13303: break;
13304: }
1.1055 raeburn 13305: }
13306: }
13307: }
13308: }
13309: }
13310:
13311: numitems = $numitems
1.1056 raeburn 13312: var titles = new Array(numitems);
13313: var parents = new Array(numitems);
1.1055 raeburn 13314: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13315: parents[i] = new Array;
1.1055 raeburn 13316: }
1.1059 raeburn 13317: var maintitle = '$maintitle';
1.1055 raeburn 13318:
13319: START
13320:
1.1056 raeburn 13321: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13322: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13323: for (my $i=0; $i<@contents; $i ++) {
13324: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13325: }
13326: }
13327:
1.1056 raeburn 13328: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13329: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13330: }
13331:
1.1055 raeburn 13332: $scripttag .= <<END;
13333:
13334: function containerCheck(form,count,offset) {
13335: if (count > 0) {
1.1056 raeburn 13336: dependencyCheck(form,count,offset);
1.1059 raeburn 13337: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13338: form.elements[item].checked = true;
13339: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13340: if (parents[count].length > 0) {
13341: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13342: containerCheck(form,parents[count][j],offset);
13343: }
13344: }
13345: }
13346: }
13347: }
13348:
13349: function dependencyCheck(form,count,offset) {
13350: if (count > 0) {
1.1059 raeburn 13351: var chosen = (offset+$startcount)+7*(count-1);
13352: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13353: var currtype = form.elements[depitem].type;
13354: if (form.elements[chosen].value == 'dependency') {
13355: document.getElementById('arc_depon_'+count).style.display='block';
13356: form.elements[depitem].options.length = 0;
13357: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13358: for (var i=1; i<=numitems; i++) {
13359: if (i == count) {
13360: continue;
13361: }
1.1059 raeburn 13362: var startelement = $startcount + (i-1) * 7;
13363: for (var j=1; j<6; j++) {
13364: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13365: var item = startelement + j;
13366: if (form.elements[item].type == 'radio') {
13367: if (form.elements[item].checked) {
13368: if (form.elements[item].value == 'display') {
13369: var n = form.elements[depitem].options.length;
13370: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13371: }
13372: }
13373: }
13374: }
13375: }
13376: }
13377: } else {
13378: document.getElementById('arc_depon_'+count).style.display='none';
13379: form.elements[depitem].options.length = 0;
13380: form.elements[depitem].options[0] = new Option('Select','',true,true);
13381: }
1.1059 raeburn 13382: titleCheck(form,count,offset);
1.1056 raeburn 13383: }
13384: }
13385:
13386: function propagateSelect(form,count,offset) {
13387: if (count > 0) {
1.1065 raeburn 13388: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13389: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13390: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13391: if (parents[count].length > 0) {
13392: for (var j=0; j<parents[count].length; j++) {
13393: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13394: }
13395: }
13396: }
13397: }
13398: }
1.1056 raeburn 13399:
13400: function containerSelect(form,count,offset,picked) {
13401: if (count > 0) {
1.1065 raeburn 13402: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13403: if (form.elements[item].type == 'radio') {
13404: if (form.elements[item].value == 'dependency') {
13405: if (form.elements[item+1].type == 'select-one') {
13406: for (var i=0; i<form.elements[item+1].options.length; i++) {
13407: if (form.elements[item+1].options[i].value == picked) {
13408: form.elements[item+1].selectedIndex = i;
13409: break;
13410: }
13411: }
13412: }
13413: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13414: if (parents[count].length > 0) {
13415: for (var j=0; j<parents[count].length; j++) {
13416: containerSelect(form,parents[count][j],offset,picked);
13417: }
13418: }
13419: }
13420: }
13421: }
13422: }
13423: }
13424:
1.1059 raeburn 13425: function titleCheck(form,count,offset) {
13426: if (count > 0) {
13427: var chosen = (offset+$startcount)+7*(count-1);
13428: var depitem = $startcount + ((count-1) * 7) + 2;
13429: var currtype = form.elements[depitem].type;
13430: if (form.elements[chosen].value == 'display') {
13431: document.getElementById('arc_title_'+count).style.display='block';
13432: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13433: document.getElementById('archive_title_'+count).value=maintitle;
13434: }
13435: } else {
13436: document.getElementById('arc_title_'+count).style.display='none';
13437: if (currtype == 'text') {
13438: document.getElementById('archive_title_'+count).value='';
13439: }
13440: }
13441: }
13442: return;
13443: }
13444:
1.1055 raeburn 13445: // ]]>
13446: </script>
13447: END
13448: return $scripttag;
13449: }
13450:
13451: sub process_extracted_files {
1.1067 raeburn 13452: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13453: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 13454: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13455: my @ids=&Apache::lonnet::current_machine_ids();
13456: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13457: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13458: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13459: if (grep(/^\Q$docuhome\E$/,@ids)) {
13460: $prefix = &LONCAPA::propath($docudom,$docuname);
13461: $pathtocheck = "$dir_root/$destination";
13462: $dir = $dir_root;
13463: $ishome = 1;
13464: } else {
13465: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13466: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 13467: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13468: }
13469: my $currdir = "$dir_root/$destination";
13470: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13471: if ($env{'form.folderpath'}) {
13472: my @items = split('&',$env{'form.folderpath'});
13473: $folders{'0'} = $items[-2];
1.1099 raeburn 13474: if ($env{'form.folderpath'} =~ /\:1$/) {
13475: $containers{'0'}='page';
13476: } else {
13477: $containers{'0'}='sequence';
13478: }
1.1055 raeburn 13479: }
13480: my @archdirs = &get_env_multiple('form.archive_directory');
13481: if ($numitems) {
13482: for (my $i=1; $i<=$numitems; $i++) {
13483: my $path = $env{'form.archive_content_'.$i};
13484: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13485: my $item = $1;
13486: $toplevelitems{$item} = $i;
13487: if (grep(/^\Q$i\E$/,@archdirs)) {
13488: $is_dir{$item} = 1;
13489: }
13490: }
13491: }
13492: }
1.1067 raeburn 13493: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13494: if (keys(%toplevelitems) > 0) {
13495: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13496: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13497: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13498: }
1.1066 raeburn 13499: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13500: if ($numitems) {
13501: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13502: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13503: my $path = $env{'form.archive_content_'.$i};
13504: if ($path =~ /^\Q$pathtocheck\E/) {
13505: if ($env{'form.archive_'.$i} eq 'discard') {
13506: if ($prefix ne '' && $path ne '') {
13507: if (-e $prefix.$path) {
1.1066 raeburn 13508: if ((@archdirs > 0) &&
13509: (grep(/^\Q$i\E$/,@archdirs))) {
13510: $todeletedir{$prefix.$path} = 1;
13511: } else {
13512: $todelete{$prefix.$path} = 1;
13513: }
1.1055 raeburn 13514: }
13515: }
13516: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13517: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13518: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13519: $docstitle = $env{'form.archive_title_'.$i};
13520: if ($docstitle eq '') {
13521: $docstitle = $title;
13522: }
1.1055 raeburn 13523: $outer = 0;
1.1056 raeburn 13524: if (ref($dirorder{$i}) eq 'ARRAY') {
13525: if (@{$dirorder{$i}} > 0) {
13526: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13527: if ($env{'form.archive_'.$item} eq 'display') {
13528: $outer = $item;
13529: last;
13530: }
13531: }
13532: }
13533: }
13534: my ($errtext,$fatal) =
13535: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13536: '/'.$folders{$outer}.'.'.
13537: $containers{$outer});
13538: next if ($fatal);
13539: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13540: if ($context eq 'coursedocs') {
1.1056 raeburn 13541: $mapinner{$i} = time;
1.1055 raeburn 13542: $folders{$i} = 'default_'.$mapinner{$i};
13543: $containers{$i} = 'sequence';
13544: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13545: $folders{$i}.'.'.$containers{$i};
13546: my $newidx = &LONCAPA::map::getresidx();
13547: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13548: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13549: push(@LONCAPA::map::order,$newidx);
13550: my ($outtext,$errtext) =
13551: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13552: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13553: '.'.$containers{$outer},1,1);
1.1056 raeburn 13554: $newseqid{$i} = $newidx;
1.1067 raeburn 13555: unless ($errtext) {
1.1294 raeburn 13556: $result .= '<li>'.&mt('Folder: [_1] added to course',
13557: &HTML::Entities::encode($docstitle,'<>&"')).
13558: '</li>'."\n";
1.1067 raeburn 13559: }
1.1055 raeburn 13560: }
13561: } else {
13562: if ($context eq 'coursedocs') {
13563: my $newidx=&LONCAPA::map::getresidx();
13564: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13565: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13566: $title;
1.1294 raeburn 13567: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
13568: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13569: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13570: }
13571: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13572: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13573: }
13574: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13575: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13576: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13577: unless ($ishome) {
13578: my $fetch = "$newdest{$i}/$title";
13579: $fetch =~ s/^\Q$prefix$dir\E//;
13580: $prompttofetch{$fetch} = 1;
13581: }
1.1292 raeburn 13582: }
1.1067 raeburn 13583: }
1.1294 raeburn 13584: $LONCAPA::map::resources[$newidx]=
13585: $docstitle.':'.$url.':false:normal:res';
13586: push(@LONCAPA::map::order, $newidx);
13587: my ($outtext,$errtext)=
13588: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13589: $docuname.'/'.$folders{$outer}.
13590: '.'.$containers{$outer},1,1);
13591: unless ($errtext) {
13592: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13593: $result .= '<li>'.&mt('File: [_1] added to course',
13594: &HTML::Entities::encode($docstitle,'<>&"')).
13595: '</li>'."\n";
13596: }
1.1067 raeburn 13597: }
1.1294 raeburn 13598: } else {
13599: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13600: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 13601: }
1.1055 raeburn 13602: }
13603: }
1.1086 raeburn 13604: }
13605: } else {
1.1294 raeburn 13606: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13607: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 13608: }
13609: }
13610: for (my $i=1; $i<=$numitems; $i++) {
13611: next unless ($env{'form.archive_'.$i} eq 'dependency');
13612: my $path = $env{'form.archive_content_'.$i};
13613: if ($path =~ /^\Q$pathtocheck\E/) {
13614: my ($title) = ($path =~ m{/([^/]+)$});
13615: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13616: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13617: if (ref($dirorder{$i}) eq 'ARRAY') {
13618: my ($itemidx,$fullpath,$relpath);
13619: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13620: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13621: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13622: if ($dirorder{$i}->[$j] eq $container) {
13623: $itemidx = $j;
1.1056 raeburn 13624: }
13625: }
1.1086 raeburn 13626: }
13627: if ($itemidx eq '') {
13628: $itemidx = 0;
13629: }
13630: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13631: if ($mapinner{$referrer{$i}}) {
13632: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13633: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13634: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13635: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13636: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13637: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13638: if (!-e $fullpath) {
13639: mkdir($fullpath,0755);
1.1056 raeburn 13640: }
13641: }
1.1086 raeburn 13642: } else {
13643: last;
1.1056 raeburn 13644: }
1.1086 raeburn 13645: }
13646: }
13647: } elsif ($newdest{$referrer{$i}}) {
13648: $fullpath = $newdest{$referrer{$i}};
13649: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13650: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13651: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13652: last;
13653: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13654: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13655: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13656: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13657: if (!-e $fullpath) {
13658: mkdir($fullpath,0755);
1.1056 raeburn 13659: }
13660: }
1.1086 raeburn 13661: } else {
13662: last;
1.1056 raeburn 13663: }
1.1055 raeburn 13664: }
13665: }
1.1086 raeburn 13666: if ($fullpath ne '') {
13667: if (-e "$prefix$path") {
1.1292 raeburn 13668: unless (rename("$prefix$path","$fullpath/$title")) {
13669: $warning .= &mt('Failed to rename dependency').'<br />';
13670: }
1.1086 raeburn 13671: }
13672: if (-e "$fullpath/$title") {
13673: my $showpath;
13674: if ($relpath ne '') {
13675: $showpath = "$relpath/$title";
13676: } else {
13677: $showpath = "/$title";
13678: }
1.1294 raeburn 13679: $result .= '<li>'.&mt('[_1] included as a dependency',
13680: &HTML::Entities::encode($showpath,'<>&"')).
13681: '</li>'."\n";
1.1292 raeburn 13682: unless ($ishome) {
13683: my $fetch = "$fullpath/$title";
13684: $fetch =~ s/^\Q$prefix$dir\E//;
13685: $prompttofetch{$fetch} = 1;
13686: }
1.1086 raeburn 13687: }
13688: }
1.1055 raeburn 13689: }
1.1086 raeburn 13690: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13691: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 13692: &HTML::Entities::encode($path,'<>&"'),
13693: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13694: '<br />';
1.1055 raeburn 13695: }
13696: } else {
1.1294 raeburn 13697: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 13698: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13699: }
13700: }
13701: if (keys(%todelete)) {
13702: foreach my $key (keys(%todelete)) {
13703: unlink($key);
1.1066 raeburn 13704: }
13705: }
13706: if (keys(%todeletedir)) {
13707: foreach my $key (keys(%todeletedir)) {
13708: rmdir($key);
13709: }
13710: }
13711: foreach my $dir (sort(keys(%is_dir))) {
13712: if (($pathtocheck ne '') && ($dir ne '')) {
13713: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13714: }
13715: }
1.1067 raeburn 13716: if ($result ne '') {
13717: $output .= '<ul>'."\n".
13718: $result."\n".
13719: '</ul>';
13720: }
13721: unless ($ishome) {
13722: my $replicationfail;
13723: foreach my $item (keys(%prompttofetch)) {
13724: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13725: unless ($fetchresult eq 'ok') {
13726: $replicationfail .= '<li>'.$item.'</li>'."\n";
13727: }
13728: }
13729: if ($replicationfail) {
13730: $output .= '<p class="LC_error">'.
13731: &mt('Course home server failed to retrieve:').'<ul>'.
13732: $replicationfail.
13733: '</ul></p>';
13734: }
13735: }
1.1055 raeburn 13736: } else {
13737: $warning = &mt('No items found in archive.');
13738: }
13739: if ($error) {
13740: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13741: $error.'</p>'."\n";
13742: }
13743: if ($warning) {
13744: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13745: }
13746: return $output;
13747: }
13748:
1.1066 raeburn 13749: sub cleanup_empty_dirs {
13750: my ($path) = @_;
13751: if (($path ne '') && (-d $path)) {
13752: if (opendir(my $dirh,$path)) {
13753: my @dircontents = grep(!/^\./,readdir($dirh));
13754: my $numitems = 0;
13755: foreach my $item (@dircontents) {
13756: if (-d "$path/$item") {
1.1111 raeburn 13757: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13758: if (-e "$path/$item") {
13759: $numitems ++;
13760: }
13761: } else {
13762: $numitems ++;
13763: }
13764: }
13765: if ($numitems == 0) {
13766: rmdir($path);
13767: }
13768: closedir($dirh);
13769: }
13770: }
13771: return;
13772: }
13773:
1.41 ng 13774: =pod
1.45 matthew 13775:
1.1162 raeburn 13776: =item * &get_folder_hierarchy()
1.1068 raeburn 13777:
13778: Provides hierarchy of names of folders/sub-folders containing the current
13779: item,
13780:
13781: Inputs: 3
13782: - $navmap - navmaps object
13783:
13784: - $map - url for map (either the trigger itself, or map containing
13785: the resource, which is the trigger).
13786:
13787: - $showitem - 1 => show title for map itself; 0 => do not show.
13788:
13789: Outputs: 1 @pathitems - array of folder/subfolder names.
13790:
13791: =cut
13792:
13793: sub get_folder_hierarchy {
13794: my ($navmap,$map,$showitem) = @_;
13795: my @pathitems;
13796: if (ref($navmap)) {
13797: my $mapres = $navmap->getResourceByUrl($map);
13798: if (ref($mapres)) {
13799: my $pcslist = $mapres->map_hierarchy();
13800: if ($pcslist ne '') {
13801: my @pcs = split(/,/,$pcslist);
13802: foreach my $pc (@pcs) {
13803: if ($pc == 1) {
1.1129 raeburn 13804: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13805: } else {
13806: my $res = $navmap->getByMapPc($pc);
13807: if (ref($res)) {
13808: my $title = $res->compTitle();
13809: $title =~ s/\W+/_/g;
13810: if ($title ne '') {
13811: push(@pathitems,$title);
13812: }
13813: }
13814: }
13815: }
13816: }
1.1071 raeburn 13817: if ($showitem) {
13818: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 13819: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13820: } else {
13821: my $maptitle = $mapres->compTitle();
13822: $maptitle =~ s/\W+/_/g;
13823: if ($maptitle ne '') {
13824: push(@pathitems,$maptitle);
13825: }
1.1068 raeburn 13826: }
13827: }
13828: }
13829: }
13830: return @pathitems;
13831: }
13832:
13833: =pod
13834:
1.1015 raeburn 13835: =item * &get_turnedin_filepath()
13836:
13837: Determines path in a user's portfolio file for storage of files uploaded
13838: to a specific essayresponse or dropbox item.
13839:
13840: Inputs: 3 required + 1 optional.
13841: $symb is symb for resource, $uname and $udom are for current user (required).
13842: $caller is optional (can be "submission", if routine is called when storing
13843: an upoaded file when "Submit Answer" button was pressed).
13844:
13845: Returns array containing $path and $multiresp.
13846: $path is path in portfolio. $multiresp is 1 if this resource contains more
13847: than one file upload item. Callers of routine should append partid as a
13848: subdirectory to $path in cases where $multiresp is 1.
13849:
13850: Called by: homework/essayresponse.pm and homework/structuretags.pm
13851:
13852: =cut
13853:
13854: sub get_turnedin_filepath {
13855: my ($symb,$uname,$udom,$caller) = @_;
13856: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13857: my $turnindir;
13858: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13859: $turnindir = $userhash{'turnindir'};
13860: my ($path,$multiresp);
13861: if ($turnindir eq '') {
13862: if ($caller eq 'submission') {
13863: $turnindir = &mt('turned in');
13864: $turnindir =~ s/\W+/_/g;
13865: my %newhash = (
13866: 'turnindir' => $turnindir,
13867: );
13868: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13869: }
13870: }
13871: if ($turnindir ne '') {
13872: $path = '/'.$turnindir.'/';
13873: my ($multipart,$turnin,@pathitems);
13874: my $navmap = Apache::lonnavmaps::navmap->new();
13875: if (defined($navmap)) {
13876: my $mapres = $navmap->getResourceByUrl($map);
13877: if (ref($mapres)) {
13878: my $pcslist = $mapres->map_hierarchy();
13879: if ($pcslist ne '') {
13880: foreach my $pc (split(/,/,$pcslist)) {
13881: my $res = $navmap->getByMapPc($pc);
13882: if (ref($res)) {
13883: my $title = $res->compTitle();
13884: $title =~ s/\W+/_/g;
13885: if ($title ne '') {
1.1149 raeburn 13886: if (($pc > 1) && (length($title) > 12)) {
13887: $title = substr($title,0,12);
13888: }
1.1015 raeburn 13889: push(@pathitems,$title);
13890: }
13891: }
13892: }
13893: }
13894: my $maptitle = $mapres->compTitle();
13895: $maptitle =~ s/\W+/_/g;
13896: if ($maptitle ne '') {
1.1149 raeburn 13897: if (length($maptitle) > 12) {
13898: $maptitle = substr($maptitle,0,12);
13899: }
1.1015 raeburn 13900: push(@pathitems,$maptitle);
13901: }
13902: unless ($env{'request.state'} eq 'construct') {
13903: my $res = $navmap->getBySymb($symb);
13904: if (ref($res)) {
13905: my $partlist = $res->parts();
13906: my $totaluploads = 0;
13907: if (ref($partlist) eq 'ARRAY') {
13908: foreach my $part (@{$partlist}) {
13909: my @types = $res->responseType($part);
13910: my @ids = $res->responseIds($part);
13911: for (my $i=0; $i < scalar(@ids); $i++) {
13912: if ($types[$i] eq 'essay') {
13913: my $partid = $part.'_'.$ids[$i];
13914: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13915: $totaluploads ++;
13916: }
13917: }
13918: }
13919: }
13920: if ($totaluploads > 1) {
13921: $multiresp = 1;
13922: }
13923: }
13924: }
13925: }
13926: } else {
13927: return;
13928: }
13929: } else {
13930: return;
13931: }
13932: my $restitle=&Apache::lonnet::gettitle($symb);
13933: $restitle =~ s/\W+/_/g;
13934: if ($restitle eq '') {
13935: $restitle = ($resurl =~ m{/[^/]+$});
13936: if ($restitle eq '') {
13937: $restitle = time;
13938: }
13939: }
1.1149 raeburn 13940: if (length($restitle) > 12) {
13941: $restitle = substr($restitle,0,12);
13942: }
1.1015 raeburn 13943: push(@pathitems,$restitle);
13944: $path .= join('/',@pathitems);
13945: }
13946: return ($path,$multiresp);
13947: }
13948:
13949: =pod
13950:
1.464 albertel 13951: =back
1.41 ng 13952:
1.112 bowersj2 13953: =head1 CSV Upload/Handling functions
1.38 albertel 13954:
1.41 ng 13955: =over 4
13956:
1.648 raeburn 13957: =item * &upfile_store($r)
1.41 ng 13958:
13959: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13960: needs $env{'form.upfile'}
1.41 ng 13961: returns $datatoken to be put into hidden field
13962:
13963: =cut
1.31 albertel 13964:
13965: sub upfile_store {
13966: my $r=shift;
1.258 albertel 13967: $env{'form.upfile'}=~s/\r/\n/gs;
13968: $env{'form.upfile'}=~s/\f/\n/gs;
13969: $env{'form.upfile'}=~s/\n+/\n/gs;
13970: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13971:
1.1299 raeburn 13972: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13973: '_enroll_'.$env{'request.course.id'}.'_'.
13974: time.'_'.$$);
13975: return if ($datatoken eq '');
13976:
1.31 albertel 13977: {
1.158 raeburn 13978: my $datafile = $r->dir_config('lonDaemons').
13979: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 13980: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13981: print $fh $env{'form.upfile'};
1.158 raeburn 13982: close($fh);
13983: }
1.31 albertel 13984: }
13985: return $datatoken;
13986: }
13987:
1.56 matthew 13988: =pod
13989:
1.1290 raeburn 13990: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13991:
13992: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 13993: $datatoken is the name to assign to the temporary file.
1.258 albertel 13994: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13995:
13996: =cut
1.31 albertel 13997:
13998: sub load_tmp_file {
1.1290 raeburn 13999: my ($r,$datatoken) = @_;
14000: return if ($datatoken eq '');
1.31 albertel 14001: my @studentdata=();
14002: {
1.158 raeburn 14003: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 14004: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14005: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14006: @studentdata=<$fh>;
14007: close($fh);
14008: }
1.31 albertel 14009: }
1.258 albertel 14010: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14011: }
14012:
1.1290 raeburn 14013: sub valid_datatoken {
14014: my ($datatoken) = @_;
1.1325 raeburn 14015: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1290 raeburn 14016: return $datatoken;
14017: }
14018: return;
14019: }
14020:
1.56 matthew 14021: =pod
14022:
1.648 raeburn 14023: =item * &upfile_record_sep()
1.41 ng 14024:
14025: Separate uploaded file into records
14026: returns array of records,
1.258 albertel 14027: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14028:
14029: =cut
1.31 albertel 14030:
14031: sub upfile_record_sep {
1.258 albertel 14032: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14033: } else {
1.248 albertel 14034: my @records;
1.258 albertel 14035: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14036: if ($line=~/^\s*$/) { next; }
14037: push(@records,$line);
14038: }
14039: return @records;
1.31 albertel 14040: }
14041: }
14042:
1.56 matthew 14043: =pod
14044:
1.648 raeburn 14045: =item * &record_sep($record)
1.41 ng 14046:
1.258 albertel 14047: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14048:
14049: =cut
14050:
1.263 www 14051: sub takeleft {
14052: my $index=shift;
14053: return substr('0000'.$index,-4,4);
14054: }
14055:
1.31 albertel 14056: sub record_sep {
14057: my $record=shift;
14058: my %components=();
1.258 albertel 14059: if ($env{'form.upfiletype'} eq 'xml') {
14060: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14061: my $i=0;
1.356 albertel 14062: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14063: $field=~s/^(\"|\')//;
14064: $field=~s/(\"|\')$//;
1.263 www 14065: $components{&takeleft($i)}=$field;
1.31 albertel 14066: $i++;
14067: }
1.258 albertel 14068: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14069: my $i=0;
1.356 albertel 14070: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14071: $field=~s/^(\"|\')//;
14072: $field=~s/(\"|\')$//;
1.263 www 14073: $components{&takeleft($i)}=$field;
1.31 albertel 14074: $i++;
14075: }
14076: } else {
1.561 www 14077: my $separator=',';
1.480 banghart 14078: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14079: $separator=';';
1.480 banghart 14080: }
1.31 albertel 14081: my $i=0;
1.561 www 14082: # the character we are looking for to indicate the end of a quote or a record
14083: my $looking_for=$separator;
14084: # do not add the characters to the fields
14085: my $ignore=0;
14086: # we just encountered a separator (or the beginning of the record)
14087: my $just_found_separator=1;
14088: # store the field we are working on here
14089: my $field='';
14090: # work our way through all characters in record
14091: foreach my $character ($record=~/(.)/g) {
14092: if ($character eq $looking_for) {
14093: if ($character ne $separator) {
14094: # Found the end of a quote, again looking for separator
14095: $looking_for=$separator;
14096: $ignore=1;
14097: } else {
14098: # Found a separator, store away what we got
14099: $components{&takeleft($i)}=$field;
14100: $i++;
14101: $just_found_separator=1;
14102: $ignore=0;
14103: $field='';
14104: }
14105: next;
14106: }
14107: # single or double quotation marks after a separator indicate beginning of a quote
14108: # we are now looking for the end of the quote and need to ignore separators
14109: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14110: $looking_for=$character;
14111: next;
14112: }
14113: # ignore would be true after we reached the end of a quote
14114: if ($ignore) { next; }
14115: if (($just_found_separator) && ($character=~/\s/)) { next; }
14116: $field.=$character;
14117: $just_found_separator=0;
1.31 albertel 14118: }
1.561 www 14119: # catch the very last entry, since we never encountered the separator
14120: $components{&takeleft($i)}=$field;
1.31 albertel 14121: }
14122: return %components;
14123: }
14124:
1.144 matthew 14125: ######################################################
14126: ######################################################
14127:
1.56 matthew 14128: =pod
14129:
1.648 raeburn 14130: =item * &upfile_select_html()
1.41 ng 14131:
1.144 matthew 14132: Return HTML code to select a file from the users machine and specify
14133: the file type.
1.41 ng 14134:
14135: =cut
14136:
1.144 matthew 14137: ######################################################
14138: ######################################################
1.31 albertel 14139: sub upfile_select_html {
1.144 matthew 14140: my %Types = (
14141: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14142: semisv => &mt('Semicolon separated values'),
1.144 matthew 14143: space => &mt('Space separated'),
14144: tab => &mt('Tabulator separated'),
14145: # xml => &mt('HTML/XML'),
14146: );
14147: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14148: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14149: foreach my $type (sort(keys(%Types))) {
14150: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14151: }
14152: $Str .= "</select>\n";
14153: return $Str;
1.31 albertel 14154: }
14155:
1.301 albertel 14156: sub get_samples {
14157: my ($records,$toget) = @_;
14158: my @samples=({});
14159: my $got=0;
14160: foreach my $rec (@$records) {
14161: my %temp = &record_sep($rec);
14162: if (! grep(/\S/, values(%temp))) { next; }
14163: if (%temp) {
14164: $samples[$got]=\%temp;
14165: $got++;
14166: if ($got == $toget) { last; }
14167: }
14168: }
14169: return \@samples;
14170: }
14171:
1.144 matthew 14172: ######################################################
14173: ######################################################
14174:
1.56 matthew 14175: =pod
14176:
1.648 raeburn 14177: =item * &csv_print_samples($r,$records)
1.41 ng 14178:
14179: Prints a table of sample values from each column uploaded $r is an
14180: Apache Request ref, $records is an arrayref from
14181: &Apache::loncommon::upfile_record_sep
14182:
14183: =cut
14184:
1.144 matthew 14185: ######################################################
14186: ######################################################
1.31 albertel 14187: sub csv_print_samples {
14188: my ($r,$records) = @_;
1.662 bisitz 14189: my $samples = &get_samples($records,5);
1.301 albertel 14190:
1.594 raeburn 14191: $r->print(&mt('Samples').'<br />'.&start_data_table().
14192: &start_data_table_header_row());
1.356 albertel 14193: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14194: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14195: $r->print(&end_data_table_header_row());
1.301 albertel 14196: foreach my $hash (@$samples) {
1.594 raeburn 14197: $r->print(&start_data_table_row());
1.356 albertel 14198: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14199: $r->print('<td>');
1.356 albertel 14200: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14201: $r->print('</td>');
14202: }
1.594 raeburn 14203: $r->print(&end_data_table_row());
1.31 albertel 14204: }
1.594 raeburn 14205: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14206: }
14207:
1.144 matthew 14208: ######################################################
14209: ######################################################
14210:
1.56 matthew 14211: =pod
14212:
1.648 raeburn 14213: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14214:
14215: Prints a table to create associations between values and table columns.
1.144 matthew 14216:
1.41 ng 14217: $r is an Apache Request ref,
14218: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14219: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14220:
14221: =cut
14222:
1.144 matthew 14223: ######################################################
14224: ######################################################
1.31 albertel 14225: sub csv_print_select_table {
14226: my ($r,$records,$d) = @_;
1.301 albertel 14227: my $i=0;
14228: my $samples = &get_samples($records,1);
1.144 matthew 14229: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14230: &start_data_table().&start_data_table_header_row().
1.144 matthew 14231: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14232: '<th>'.&mt('Column').'</th>'.
14233: &end_data_table_header_row()."\n");
1.356 albertel 14234: foreach my $array_ref (@$d) {
14235: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14236: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14237:
1.875 bisitz 14238: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14239: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14240: $r->print('<option value="none"></option>');
1.356 albertel 14241: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14242: $r->print('<option value="'.$sample.'"'.
14243: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14244: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14245: }
1.594 raeburn 14246: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14247: $i++;
14248: }
1.594 raeburn 14249: $r->print(&end_data_table());
1.31 albertel 14250: $i--;
14251: return $i;
14252: }
1.56 matthew 14253:
1.144 matthew 14254: ######################################################
14255: ######################################################
14256:
1.56 matthew 14257: =pod
1.31 albertel 14258:
1.648 raeburn 14259: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14260:
14261: Prints a table of sample values from the upload and can make associate samples to internal names.
14262:
14263: $r is an Apache Request ref,
14264: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14265: $d is an array of 2 element arrays (internal name, displayed name)
14266:
14267: =cut
14268:
1.144 matthew 14269: ######################################################
14270: ######################################################
1.31 albertel 14271: sub csv_samples_select_table {
14272: my ($r,$records,$d) = @_;
14273: my $i=0;
1.144 matthew 14274: #
1.662 bisitz 14275: my $max_samples = 5;
14276: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14277: $r->print(&start_data_table().
14278: &start_data_table_header_row().'<th>'.
14279: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14280: &end_data_table_header_row());
1.301 albertel 14281:
14282: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14283: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14284: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14285: foreach my $option (@$d) {
14286: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14287: $r->print('<option value="'.$value.'"'.
1.253 albertel 14288: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14289: $display.'</option>');
1.31 albertel 14290: }
14291: $r->print('</select></td><td>');
1.662 bisitz 14292: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14293: if (defined($samples->[$line]{$key})) {
14294: $r->print($samples->[$line]{$key}."<br />\n");
14295: }
14296: }
1.594 raeburn 14297: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14298: $i++;
14299: }
1.594 raeburn 14300: $r->print(&end_data_table());
1.31 albertel 14301: $i--;
14302: return($i);
1.115 matthew 14303: }
14304:
1.144 matthew 14305: ######################################################
14306: ######################################################
14307:
1.115 matthew 14308: =pod
14309:
1.648 raeburn 14310: =item * &clean_excel_name($name)
1.115 matthew 14311:
14312: Returns a replacement for $name which does not contain any illegal characters.
14313:
14314: =cut
14315:
1.144 matthew 14316: ######################################################
14317: ######################################################
1.115 matthew 14318: sub clean_excel_name {
14319: my ($name) = @_;
14320: $name =~ s/[:\*\?\/\\]//g;
14321: if (length($name) > 31) {
14322: $name = substr($name,0,31);
14323: }
14324: return $name;
1.25 albertel 14325: }
1.84 albertel 14326:
1.85 albertel 14327: =pod
14328:
1.648 raeburn 14329: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14330:
14331: Returns either 1 or undef
14332:
14333: 1 if the part is to be hidden, undef if it is to be shown
14334:
14335: Arguments are:
14336:
14337: $id the id of the part to be checked
14338: $symb, optional the symb of the resource to check
14339: $udom, optional the domain of the user to check for
14340: $uname, optional the username of the user to check for
14341:
14342: =cut
1.84 albertel 14343:
14344: sub check_if_partid_hidden {
14345: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14346: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14347: $symb,$udom,$uname);
1.141 albertel 14348: my $truth=1;
14349: #if the string starts with !, then the list is the list to show not hide
14350: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14351: my @hiddenlist=split(/,/,$hiddenparts);
14352: foreach my $checkid (@hiddenlist) {
1.141 albertel 14353: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14354: }
1.141 albertel 14355: return !$truth;
1.84 albertel 14356: }
1.127 matthew 14357:
1.138 matthew 14358:
14359: ############################################################
14360: ############################################################
14361:
14362: =pod
14363:
1.157 matthew 14364: =back
14365:
1.138 matthew 14366: =head1 cgi-bin script and graphing routines
14367:
1.157 matthew 14368: =over 4
14369:
1.648 raeburn 14370: =item * &get_cgi_id()
1.138 matthew 14371:
14372: Inputs: none
14373:
14374: Returns an id which can be used to pass environment variables
14375: to various cgi-bin scripts. These environment variables will
14376: be removed from the users environment after a given time by
14377: the routine &Apache::lonnet::transfer_profile_to_env.
14378:
14379: =cut
14380:
14381: ############################################################
14382: ############################################################
1.152 albertel 14383: my $uniq=0;
1.136 matthew 14384: sub get_cgi_id {
1.154 albertel 14385: $uniq=($uniq+1)%100000;
1.280 albertel 14386: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14387: }
14388:
1.127 matthew 14389: ############################################################
14390: ############################################################
14391:
14392: =pod
14393:
1.648 raeburn 14394: =item * &DrawBarGraph()
1.127 matthew 14395:
1.138 matthew 14396: Facilitates the plotting of data in a (stacked) bar graph.
14397: Puts plot definition data into the users environment in order for
14398: graph.png to plot it. Returns an <img> tag for the plot.
14399: The bars on the plot are labeled '1','2',...,'n'.
14400:
14401: Inputs:
14402:
14403: =over 4
14404:
14405: =item $Title: string, the title of the plot
14406:
14407: =item $xlabel: string, text describing the X-axis of the plot
14408:
14409: =item $ylabel: string, text describing the Y-axis of the plot
14410:
14411: =item $Max: scalar, the maximum Y value to use in the plot
14412: If $Max is < any data point, the graph will not be rendered.
14413:
1.140 matthew 14414: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14415: they are plotted. If undefined, default values will be used.
14416:
1.178 matthew 14417: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14418:
1.138 matthew 14419: =item @Values: An array of array references. Each array reference holds data
14420: to be plotted in a stacked bar chart.
14421:
1.239 matthew 14422: =item If the final element of @Values is a hash reference the key/value
14423: pairs will be added to the graph definition.
14424:
1.138 matthew 14425: =back
14426:
14427: Returns:
14428:
14429: An <img> tag which references graph.png and the appropriate identifying
14430: information for the plot.
14431:
1.127 matthew 14432: =cut
14433:
14434: ############################################################
14435: ############################################################
1.134 matthew 14436: sub DrawBarGraph {
1.178 matthew 14437: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14438: #
14439: if (! defined($colors)) {
14440: $colors = ['#33ff00',
14441: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14442: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14443: ];
14444: }
1.228 matthew 14445: my $extra_settings = {};
14446: if (ref($Values[-1]) eq 'HASH') {
14447: $extra_settings = pop(@Values);
14448: }
1.127 matthew 14449: #
1.136 matthew 14450: my $identifier = &get_cgi_id();
14451: my $id = 'cgi.'.$identifier;
1.129 matthew 14452: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14453: return '';
14454: }
1.225 matthew 14455: #
14456: my @Labels;
14457: if (defined($labels)) {
14458: @Labels = @$labels;
14459: } else {
14460: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 14461: push(@Labels,$i+1);
1.225 matthew 14462: }
14463: }
14464: #
1.129 matthew 14465: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14466: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14467: my %ValuesHash;
14468: my $NumSets=1;
14469: foreach my $array (@Values) {
14470: next if (! ref($array));
1.136 matthew 14471: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14472: join(',',@$array);
1.129 matthew 14473: }
1.127 matthew 14474: #
1.136 matthew 14475: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14476: if ($NumBars < 3) {
14477: $width = 120+$NumBars*32;
1.220 matthew 14478: $xskip = 1;
1.225 matthew 14479: $bar_width = 30;
14480: } elsif ($NumBars < 5) {
14481: $width = 120+$NumBars*20;
14482: $xskip = 1;
14483: $bar_width = 20;
1.220 matthew 14484: } elsif ($NumBars < 10) {
1.136 matthew 14485: $width = 120+$NumBars*15;
14486: $xskip = 1;
14487: $bar_width = 15;
14488: } elsif ($NumBars <= 25) {
14489: $width = 120+$NumBars*11;
14490: $xskip = 5;
14491: $bar_width = 8;
14492: } elsif ($NumBars <= 50) {
14493: $width = 120+$NumBars*8;
14494: $xskip = 5;
14495: $bar_width = 4;
14496: } else {
14497: $width = 120+$NumBars*8;
14498: $xskip = 5;
14499: $bar_width = 4;
14500: }
14501: #
1.137 matthew 14502: $Max = 1 if ($Max < 1);
14503: if ( int($Max) < $Max ) {
14504: $Max++;
14505: $Max = int($Max);
14506: }
1.127 matthew 14507: $Title = '' if (! defined($Title));
14508: $xlabel = '' if (! defined($xlabel));
14509: $ylabel = '' if (! defined($ylabel));
1.369 www 14510: $ValuesHash{$id.'.title'} = &escape($Title);
14511: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14512: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14513: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14514: $ValuesHash{$id.'.NumBars'} = $NumBars;
14515: $ValuesHash{$id.'.NumSets'} = $NumSets;
14516: $ValuesHash{$id.'.PlotType'} = 'bar';
14517: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14518: $ValuesHash{$id.'.height'} = $height;
14519: $ValuesHash{$id.'.width'} = $width;
14520: $ValuesHash{$id.'.xskip'} = $xskip;
14521: $ValuesHash{$id.'.bar_width'} = $bar_width;
14522: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14523: #
1.228 matthew 14524: # Deal with other parameters
14525: while (my ($key,$value) = each(%$extra_settings)) {
14526: $ValuesHash{$id.'.'.$key} = $value;
14527: }
14528: #
1.646 raeburn 14529: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14530: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14531: }
14532:
14533: ############################################################
14534: ############################################################
14535:
14536: =pod
14537:
1.648 raeburn 14538: =item * &DrawXYGraph()
1.137 matthew 14539:
1.138 matthew 14540: Facilitates the plotting of data in an XY graph.
14541: Puts plot definition data into the users environment in order for
14542: graph.png to plot it. Returns an <img> tag for the plot.
14543:
14544: Inputs:
14545:
14546: =over 4
14547:
14548: =item $Title: string, the title of the plot
14549:
14550: =item $xlabel: string, text describing the X-axis of the plot
14551:
14552: =item $ylabel: string, text describing the Y-axis of the plot
14553:
14554: =item $Max: scalar, the maximum Y value to use in the plot
14555: If $Max is < any data point, the graph will not be rendered.
14556:
14557: =item $colors: Array ref containing the hex color codes for the data to be
14558: plotted in. If undefined, default values will be used.
14559:
14560: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14561:
14562: =item $Ydata: Array ref containing Array refs.
1.185 www 14563: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14564:
14565: =item %Values: hash indicating or overriding any default values which are
14566: passed to graph.png.
14567: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14568:
14569: =back
14570:
14571: Returns:
14572:
14573: An <img> tag which references graph.png and the appropriate identifying
14574: information for the plot.
14575:
1.137 matthew 14576: =cut
14577:
14578: ############################################################
14579: ############################################################
14580: sub DrawXYGraph {
14581: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14582: #
14583: # Create the identifier for the graph
14584: my $identifier = &get_cgi_id();
14585: my $id = 'cgi.'.$identifier;
14586: #
14587: $Title = '' if (! defined($Title));
14588: $xlabel = '' if (! defined($xlabel));
14589: $ylabel = '' if (! defined($ylabel));
14590: my %ValuesHash =
14591: (
1.369 www 14592: $id.'.title' => &escape($Title),
14593: $id.'.xlabel' => &escape($xlabel),
14594: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14595: $id.'.y_max_value'=> $Max,
14596: $id.'.labels' => join(',',@$Xlabels),
14597: $id.'.PlotType' => 'XY',
14598: );
14599: #
14600: if (defined($colors) && ref($colors) eq 'ARRAY') {
14601: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14602: }
14603: #
14604: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14605: return '';
14606: }
14607: my $NumSets=1;
1.138 matthew 14608: foreach my $array (@{$Ydata}){
1.137 matthew 14609: next if (! ref($array));
14610: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14611: }
1.138 matthew 14612: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14613: #
14614: # Deal with other parameters
14615: while (my ($key,$value) = each(%Values)) {
14616: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14617: }
14618: #
1.646 raeburn 14619: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14620: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14621: }
14622:
14623: ############################################################
14624: ############################################################
14625:
14626: =pod
14627:
1.648 raeburn 14628: =item * &DrawXYYGraph()
1.138 matthew 14629:
14630: Facilitates the plotting of data in an XY graph with two Y axes.
14631: Puts plot definition data into the users environment in order for
14632: graph.png to plot it. Returns an <img> tag for the plot.
14633:
14634: Inputs:
14635:
14636: =over 4
14637:
14638: =item $Title: string, the title of the plot
14639:
14640: =item $xlabel: string, text describing the X-axis of the plot
14641:
14642: =item $ylabel: string, text describing the Y-axis of the plot
14643:
14644: =item $colors: Array ref containing the hex color codes for the data to be
14645: plotted in. If undefined, default values will be used.
14646:
14647: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14648:
14649: =item $Ydata1: The first data set
14650:
14651: =item $Min1: The minimum value of the left Y-axis
14652:
14653: =item $Max1: The maximum value of the left Y-axis
14654:
14655: =item $Ydata2: The second data set
14656:
14657: =item $Min2: The minimum value of the right Y-axis
14658:
14659: =item $Max2: The maximum value of the left Y-axis
14660:
14661: =item %Values: hash indicating or overriding any default values which are
14662: passed to graph.png.
14663: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14664:
14665: =back
14666:
14667: Returns:
14668:
14669: An <img> tag which references graph.png and the appropriate identifying
14670: information for the plot.
1.136 matthew 14671:
14672: =cut
14673:
14674: ############################################################
14675: ############################################################
1.137 matthew 14676: sub DrawXYYGraph {
14677: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14678: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14679: #
14680: # Create the identifier for the graph
14681: my $identifier = &get_cgi_id();
14682: my $id = 'cgi.'.$identifier;
14683: #
14684: $Title = '' if (! defined($Title));
14685: $xlabel = '' if (! defined($xlabel));
14686: $ylabel = '' if (! defined($ylabel));
14687: my %ValuesHash =
14688: (
1.369 www 14689: $id.'.title' => &escape($Title),
14690: $id.'.xlabel' => &escape($xlabel),
14691: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14692: $id.'.labels' => join(',',@$Xlabels),
14693: $id.'.PlotType' => 'XY',
14694: $id.'.NumSets' => 2,
1.137 matthew 14695: $id.'.two_axes' => 1,
14696: $id.'.y1_max_value' => $Max1,
14697: $id.'.y1_min_value' => $Min1,
14698: $id.'.y2_max_value' => $Max2,
14699: $id.'.y2_min_value' => $Min2,
1.136 matthew 14700: );
14701: #
1.137 matthew 14702: if (defined($colors) && ref($colors) eq 'ARRAY') {
14703: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14704: }
14705: #
14706: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14707: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14708: return '';
14709: }
14710: my $NumSets=1;
1.137 matthew 14711: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14712: next if (! ref($array));
14713: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14714: }
14715: #
14716: # Deal with other parameters
14717: while (my ($key,$value) = each(%Values)) {
14718: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14719: }
14720: #
1.646 raeburn 14721: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14722: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14723: }
14724:
14725: ############################################################
14726: ############################################################
14727:
14728: =pod
14729:
1.157 matthew 14730: =back
14731:
1.139 matthew 14732: =head1 Statistics helper routines?
14733:
14734: Bad place for them but what the hell.
14735:
1.157 matthew 14736: =over 4
14737:
1.648 raeburn 14738: =item * &chartlink()
1.139 matthew 14739:
14740: Returns a link to the chart for a specific student.
14741:
14742: Inputs:
14743:
14744: =over 4
14745:
14746: =item $linktext: The text of the link
14747:
14748: =item $sname: The students username
14749:
14750: =item $sdomain: The students domain
14751:
14752: =back
14753:
1.157 matthew 14754: =back
14755:
1.139 matthew 14756: =cut
14757:
14758: ############################################################
14759: ############################################################
14760: sub chartlink {
14761: my ($linktext, $sname, $sdomain) = @_;
14762: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14763: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14764: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14765: '">'.$linktext.'</a>';
1.153 matthew 14766: }
14767:
14768: #######################################################
14769: #######################################################
14770:
14771: =pod
14772:
14773: =head1 Course Environment Routines
1.157 matthew 14774:
14775: =over 4
1.153 matthew 14776:
1.648 raeburn 14777: =item * &restore_course_settings()
1.153 matthew 14778:
1.648 raeburn 14779: =item * &store_course_settings()
1.153 matthew 14780:
14781: Restores/Store indicated form parameters from the course environment.
14782: Will not overwrite existing values of the form parameters.
14783:
14784: Inputs:
14785: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14786:
14787: a hash ref describing the data to be stored. For example:
14788:
14789: %Save_Parameters = ('Status' => 'scalar',
14790: 'chartoutputmode' => 'scalar',
14791: 'chartoutputdata' => 'scalar',
14792: 'Section' => 'array',
1.373 raeburn 14793: 'Group' => 'array',
1.153 matthew 14794: 'StudentData' => 'array',
14795: 'Maps' => 'array');
14796:
14797: Returns: both routines return nothing
14798:
1.631 raeburn 14799: =back
14800:
1.153 matthew 14801: =cut
14802:
14803: #######################################################
14804: #######################################################
14805: sub store_course_settings {
1.496 albertel 14806: return &store_settings($env{'request.course.id'},@_);
14807: }
14808:
14809: sub store_settings {
1.153 matthew 14810: # save to the environment
14811: # appenv the same items, just to be safe
1.300 albertel 14812: my $udom = $env{'user.domain'};
14813: my $uname = $env{'user.name'};
1.496 albertel 14814: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14815: my %SaveHash;
14816: my %AppHash;
14817: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14818: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14819: my $envname = 'environment.'.$basename;
1.258 albertel 14820: if (exists($env{'form.'.$setting})) {
1.153 matthew 14821: # Save this value away
14822: if ($type eq 'scalar' &&
1.258 albertel 14823: (! exists($env{$envname}) ||
14824: $env{$envname} ne $env{'form.'.$setting})) {
14825: $SaveHash{$basename} = $env{'form.'.$setting};
14826: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14827: } elsif ($type eq 'array') {
14828: my $stored_form;
1.258 albertel 14829: if (ref($env{'form.'.$setting})) {
1.153 matthew 14830: $stored_form = join(',',
14831: map {
1.369 www 14832: &escape($_);
1.258 albertel 14833: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14834: } else {
14835: $stored_form =
1.369 www 14836: &escape($env{'form.'.$setting});
1.153 matthew 14837: }
14838: # Determine if the array contents are the same.
1.258 albertel 14839: if ($stored_form ne $env{$envname}) {
1.153 matthew 14840: $SaveHash{$basename} = $stored_form;
14841: $AppHash{$envname} = $stored_form;
14842: }
14843: }
14844: }
14845: }
14846: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14847: $udom,$uname);
1.153 matthew 14848: if ($put_result !~ /^(ok|delayed)/) {
14849: &Apache::lonnet::logthis('unable to save form parameters, '.
14850: 'got error:'.$put_result);
14851: }
14852: # Make sure these settings stick around in this session, too
1.646 raeburn 14853: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14854: return;
14855: }
14856:
14857: sub restore_course_settings {
1.499 albertel 14858: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14859: }
14860:
14861: sub restore_settings {
14862: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14863: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14864: next if (exists($env{'form.'.$setting}));
1.496 albertel 14865: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14866: '.'.$setting;
1.258 albertel 14867: if (exists($env{$envname})) {
1.153 matthew 14868: if ($type eq 'scalar') {
1.258 albertel 14869: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14870: } elsif ($type eq 'array') {
1.258 albertel 14871: $env{'form.'.$setting} = [
1.153 matthew 14872: map {
1.369 www 14873: &unescape($_);
1.258 albertel 14874: } split(',',$env{$envname})
1.153 matthew 14875: ];
14876: }
14877: }
14878: }
1.127 matthew 14879: }
14880:
1.618 raeburn 14881: #######################################################
14882: #######################################################
14883:
14884: =pod
14885:
14886: =head1 Domain E-mail Routines
14887:
14888: =over 4
14889:
1.648 raeburn 14890: =item * &build_recipient_list()
1.618 raeburn 14891:
1.1144 raeburn 14892: Build recipient lists for following types of e-mail:
1.766 raeburn 14893: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 14894: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14895: module change checking, student/employee ID conflict checks, as
14896: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14897: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14898:
14899: Inputs:
1.619 raeburn 14900: defmail (scalar - email address of default recipient),
1.1144 raeburn 14901: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14902: requestsmail, updatesmail, or idconflictsmail).
14903:
1.619 raeburn 14904: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 14905:
1.619 raeburn 14906: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 14907: i.e., predates configuration by DC via domainprefs.pm
14908:
14909: $requname username of requester (if mailing type is helpdeskmail)
14910:
14911: $requdom domain of requester (if mailing type is helpdeskmail)
14912:
14913: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14914:
1.618 raeburn 14915:
1.655 raeburn 14916: Returns: comma separated list of addresses to which to send e-mail.
14917:
14918: =back
1.618 raeburn 14919:
14920: =cut
14921:
14922: ############################################################
14923: ############################################################
14924: sub build_recipient_list {
1.1297 raeburn 14925: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14926: my @recipients;
1.1270 raeburn 14927: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14928: my %domconfig =
1.1270 raeburn 14929: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14930: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14931: if (exists($domconfig{'contacts'}{$mailing})) {
14932: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14933: my @contacts = ('adminemail','supportemail');
14934: foreach my $item (@contacts) {
14935: if ($domconfig{'contacts'}{$mailing}{$item}) {
14936: my $addr = $domconfig{'contacts'}{$item};
14937: if (!grep(/^\Q$addr\E$/,@recipients)) {
14938: push(@recipients,$addr);
14939: }
1.619 raeburn 14940: }
1.1270 raeburn 14941: }
14942: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14943: if ($mailing eq 'helpdeskmail') {
14944: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14945: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14946: my @ok_bccs;
14947: foreach my $bcc (@bccs) {
14948: $bcc =~ s/^\s+//g;
14949: $bcc =~ s/\s+$//g;
14950: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14951: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14952: push(@ok_bccs,$bcc);
14953: }
14954: }
14955: }
14956: if (@ok_bccs > 0) {
14957: $allbcc = join(', ',@ok_bccs);
14958: }
14959: }
14960: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14961: }
14962: }
1.766 raeburn 14963: } elsif ($origmail ne '') {
1.1270 raeburn 14964: $lastresort = $origmail;
1.618 raeburn 14965: }
1.1297 raeburn 14966: if ($mailing eq 'helpdeskmail') {
14967: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14968: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14969: my ($inststatus,$inststatus_checked);
14970: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14971: ($env{'user.domain'} ne 'public')) {
14972: $inststatus_checked = 1;
14973: $inststatus = $env{'environment.inststatus'};
14974: }
14975: unless ($inststatus_checked) {
14976: if (($requname ne '') && ($requdom ne '')) {
14977: if (($requname =~ /^$match_username$/) &&
14978: ($requdom =~ /^$match_domain$/) &&
14979: (&Apache::lonnet::domain($requdom))) {
14980: my $requhome = &Apache::lonnet::homeserver($requname,
14981: $requdom);
14982: unless ($requhome eq 'no_host') {
14983: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14984: $inststatus = $userenv{'inststatus'};
14985: $inststatus_checked = 1;
14986: }
14987: }
14988: }
14989: }
14990: unless ($inststatus_checked) {
14991: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
14992: my %srch = (srchby => 'email',
14993: srchdomain => $defdom,
14994: srchterm => $reqemail,
14995: srchtype => 'exact');
14996: my %srch_results = &Apache::lonnet::usersearch(\%srch);
14997: foreach my $uname (keys(%srch_results)) {
14998: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14999: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15000: $inststatus_checked = 1;
15001: last;
15002: }
15003: }
15004: unless ($inststatus_checked) {
15005: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15006: if ($dirsrchres eq 'ok') {
15007: foreach my $uname (keys(%srch_results)) {
15008: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15009: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15010: $inststatus_checked = 1;
15011: last;
15012: }
15013: }
15014: }
15015: }
15016: }
15017: }
15018: if ($inststatus ne '') {
15019: foreach my $status (split(/\:/,$inststatus)) {
15020: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15021: my @contacts = ('adminemail','supportemail');
15022: foreach my $item (@contacts) {
15023: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15024: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15025: if (!grep(/^\Q$addr\E$/,@recipients)) {
15026: push(@recipients,$addr);
15027: }
15028: }
15029: }
15030: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15031: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15032: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15033: my @ok_bccs;
15034: foreach my $bcc (@bccs) {
15035: $bcc =~ s/^\s+//g;
15036: $bcc =~ s/\s+$//g;
15037: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15038: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15039: push(@ok_bccs,$bcc);
15040: }
15041: }
15042: }
15043: if (@ok_bccs > 0) {
15044: $allbcc = join(', ',@ok_bccs);
15045: }
15046: }
15047: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15048: last;
15049: }
15050: }
15051: }
15052: }
15053: }
1.619 raeburn 15054: } elsif ($origmail ne '') {
1.1270 raeburn 15055: $lastresort = $origmail;
15056: }
1.1297 raeburn 15057: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 15058: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15059: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15060: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15061: my %what = (
15062: perlvar => 1,
15063: );
15064: my $primary = &Apache::lonnet::domain($defdom,'primary');
15065: if ($primary) {
15066: my $gotaddr;
15067: my ($result,$returnhash) =
15068: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15069: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15070: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15071: $lastresort = $returnhash->{'lonSupportEMail'};
15072: $gotaddr = 1;
15073: }
15074: }
15075: unless ($gotaddr) {
15076: my $uintdom = &Apache::lonnet::internet_dom($primary);
15077: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15078: unless ($uintdom eq $intdom) {
15079: my %domconfig =
15080: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15081: if (ref($domconfig{'contacts'}) eq 'HASH') {
15082: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15083: my @contacts = ('adminemail','supportemail');
15084: foreach my $item (@contacts) {
15085: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15086: my $addr = $domconfig{'contacts'}{$item};
15087: if (!grep(/^\Q$addr\E$/,@recipients)) {
15088: push(@recipients,$addr);
15089: }
15090: }
15091: }
15092: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15093: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15094: }
15095: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15096: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15097: my @ok_bccs;
15098: foreach my $bcc (@bccs) {
15099: $bcc =~ s/^\s+//g;
15100: $bcc =~ s/\s+$//g;
15101: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15102: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15103: push(@ok_bccs,$bcc);
15104: }
15105: }
15106: }
15107: if (@ok_bccs > 0) {
15108: $allbcc = join(', ',@ok_bccs);
15109: }
15110: }
15111: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15112: }
15113: }
15114: }
15115: }
15116: }
15117: }
1.618 raeburn 15118: }
1.688 raeburn 15119: if (defined($defmail)) {
15120: if ($defmail ne '') {
15121: push(@recipients,$defmail);
15122: }
1.618 raeburn 15123: }
15124: if ($otheremails) {
1.619 raeburn 15125: my @others;
15126: if ($otheremails =~ /,/) {
15127: @others = split(/,/,$otheremails);
1.618 raeburn 15128: } else {
1.619 raeburn 15129: push(@others,$otheremails);
15130: }
15131: foreach my $addr (@others) {
15132: if (!grep(/^\Q$addr\E$/,@recipients)) {
15133: push(@recipients,$addr);
15134: }
1.618 raeburn 15135: }
15136: }
1.1298 raeburn 15137: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 15138: if ((!@recipients) && ($lastresort ne '')) {
15139: push(@recipients,$lastresort);
15140: }
15141: } elsif ($lastresort ne '') {
15142: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15143: push(@recipients,$lastresort);
15144: }
15145: }
1.1271 raeburn 15146: my $recipientlist = join(',',@recipients);
1.1270 raeburn 15147: if (wantarray) {
15148: return ($recipientlist,$allbcc,$addtext);
15149: } else {
15150: return $recipientlist;
15151: }
1.618 raeburn 15152: }
15153:
1.127 matthew 15154: ############################################################
15155: ############################################################
1.154 albertel 15156:
1.655 raeburn 15157: =pod
15158:
1.1224 musolffc 15159: =over 4
15160:
1.1223 musolffc 15161: =item * &mime_email()
15162:
15163: Sends an email with a possible attachment
15164:
15165: Inputs:
15166:
15167: =over 4
15168:
15169: from - Sender's email address
15170:
15171: to - Email address of recipient
15172:
15173: subject - Subject of email
15174:
15175: body - Body of email
15176:
15177: cc_string - Carbon copy email address
15178:
15179: bcc - Blind carbon copy email address
15180:
15181: type - File type of attachment
15182:
15183: attachment_path - Path of file to be attached
15184:
15185: file_name - Name of file to be attached
15186:
15187: attachment_text - The body of an attachment of type "TEXT"
15188:
15189: =back
15190:
15191: =back
15192:
15193: =cut
15194:
15195: ############################################################
15196: ############################################################
15197:
15198: sub mime_email {
15199: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
15200: $file_name, $attachment_text) = @_;
15201: my $msg = MIME::Lite->new(
15202: From => $from,
15203: To => $to,
15204: Subject => $subject,
15205: Type =>'TEXT',
15206: Data => $body,
15207: );
15208: if ($cc_string ne '') {
15209: $msg->add("Cc" => $cc_string);
15210: }
15211: if ($bcc ne '') {
15212: $msg->add("Bcc" => $bcc);
15213: }
15214: $msg->attr("content-type" => "text/plain");
15215: $msg->attr("content-type.charset" => "UTF-8");
15216: # Attach file if given
15217: if ($attachment_path) {
15218: unless ($file_name) {
15219: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
15220: }
15221: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
15222: $msg->attach(Type => $type,
15223: Path => $attachment_path,
15224: Filename => $file_name
15225: );
15226: # Otherwise attach text if given
15227: } elsif ($attachment_text) {
15228: $msg->attach(Type => 'TEXT',
15229: Data => $attachment_text);
15230: }
15231: # Send it
15232: $msg->send('sendmail');
15233: }
15234:
15235: ############################################################
15236: ############################################################
15237:
15238: =pod
15239:
1.655 raeburn 15240: =head1 Course Catalog Routines
15241:
15242: =over 4
15243:
15244: =item * &gather_categories()
15245:
15246: Converts category definitions - keys of categories hash stored in
15247: coursecategories in configuration.db on the primary library server in a
15248: domain - to an array. Also generates javascript and idx hash used to
15249: generate Domain Coordinator interface for editing Course Categories.
15250:
15251: Inputs:
1.663 raeburn 15252:
1.655 raeburn 15253: categories (reference to hash of category definitions).
1.663 raeburn 15254:
1.655 raeburn 15255: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15256: categories and subcategories).
1.663 raeburn 15257:
1.655 raeburn 15258: idx (reference to hash of counters used in Domain Coordinator interface for
15259: editing Course Categories).
1.663 raeburn 15260:
1.655 raeburn 15261: jsarray (reference to array of categories used to create Javascript arrays for
15262: Domain Coordinator interface for editing Course Categories).
15263:
15264: Returns: nothing
15265:
15266: Side effects: populates cats, idx and jsarray.
15267:
15268: =cut
15269:
15270: sub gather_categories {
15271: my ($categories,$cats,$idx,$jsarray) = @_;
15272: my %counters;
15273: my $num = 0;
15274: foreach my $item (keys(%{$categories})) {
15275: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15276: if ($container eq '' && $depth == 0) {
15277: $cats->[$depth][$categories->{$item}] = $cat;
15278: } else {
15279: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15280: }
15281: my ($escitem,$tail) = split(/:/,$item,2);
15282: if ($counters{$tail} eq '') {
15283: $counters{$tail} = $num;
15284: $num ++;
15285: }
15286: if (ref($idx) eq 'HASH') {
15287: $idx->{$item} = $counters{$tail};
15288: }
15289: if (ref($jsarray) eq 'ARRAY') {
15290: push(@{$jsarray->[$counters{$tail}]},$item);
15291: }
15292: }
15293: return;
15294: }
15295:
15296: =pod
15297:
15298: =item * &extract_categories()
15299:
15300: Used to generate breadcrumb trails for course categories.
15301:
15302: Inputs:
1.663 raeburn 15303:
1.655 raeburn 15304: categories (reference to hash of category definitions).
1.663 raeburn 15305:
1.655 raeburn 15306: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15307: categories and subcategories).
1.663 raeburn 15308:
1.655 raeburn 15309: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15310:
1.655 raeburn 15311: allitems (reference to hash - key is category key
15312: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15313:
1.655 raeburn 15314: idx (reference to hash of counters used in Domain Coordinator interface for
15315: editing Course Categories).
1.663 raeburn 15316:
1.655 raeburn 15317: jsarray (reference to array of categories used to create Javascript arrays for
15318: Domain Coordinator interface for editing Course Categories).
15319:
1.665 raeburn 15320: subcats (reference to hash of arrays containing all subcategories within each
15321: category, -recursive)
15322:
1.1321 raeburn 15323: maxd (reference to hash used to hold max depth for all top-level categories).
15324:
1.655 raeburn 15325: Returns: nothing
15326:
15327: Side effects: populates trails and allitems hash references.
15328:
15329: =cut
15330:
15331: sub extract_categories {
1.1321 raeburn 15332: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 15333: if (ref($categories) eq 'HASH') {
15334: &gather_categories($categories,$cats,$idx,$jsarray);
15335: if (ref($cats->[0]) eq 'ARRAY') {
15336: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15337: my $name = $cats->[0][$i];
15338: my $item = &escape($name).'::0';
15339: my $trailstr;
15340: if ($name eq 'instcode') {
15341: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15342: } elsif ($name eq 'communities') {
15343: $trailstr = &mt('Communities');
1.1239 raeburn 15344: } elsif ($name eq 'placement') {
15345: $trailstr = &mt('Placement Tests');
1.655 raeburn 15346: } else {
15347: $trailstr = $name;
15348: }
15349: if ($allitems->{$item} eq '') {
15350: push(@{$trails},$trailstr);
15351: $allitems->{$item} = scalar(@{$trails})-1;
15352: }
15353: my @parents = ($name);
15354: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15355: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15356: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15357: if (ref($subcats) eq 'HASH') {
15358: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15359: }
1.1321 raeburn 15360: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 15361: }
15362: } else {
15363: if (ref($subcats) eq 'HASH') {
15364: $subcats->{$item} = [];
1.655 raeburn 15365: }
1.1321 raeburn 15366: if (ref($maxd) eq 'HASH') {
15367: $maxd->{$name} = 1;
15368: }
1.655 raeburn 15369: }
15370: }
15371: }
15372: }
15373: return;
15374: }
15375:
15376: =pod
15377:
1.1162 raeburn 15378: =item * &recurse_categories()
1.655 raeburn 15379:
15380: Recursively used to generate breadcrumb trails for course categories.
15381:
15382: Inputs:
1.663 raeburn 15383:
1.655 raeburn 15384: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15385: categories and subcategories).
1.663 raeburn 15386:
1.655 raeburn 15387: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15388:
15389: category (current course category, for which breadcrumb trail is being generated).
15390:
15391: trails (reference to array of breadcrumb trails for each category).
15392:
1.655 raeburn 15393: allitems (reference to hash - key is category key
15394: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15395:
1.655 raeburn 15396: parents (array containing containers directories for current category,
15397: back to top level).
15398:
15399: Returns: nothing
15400:
15401: Side effects: populates trails and allitems hash references
15402:
15403: =cut
15404:
15405: sub recurse_categories {
1.1321 raeburn 15406: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 15407: my $shallower = $depth - 1;
15408: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
15409: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
15410: my $name = $cats->[$depth]{$category}[$k];
15411: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15412: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15413: if ($allitems->{$item} eq '') {
15414: push(@{$trails},$trailstr);
15415: $allitems->{$item} = scalar(@{$trails})-1;
15416: }
15417: my $deeper = $depth+1;
15418: push(@{$parents},$category);
1.665 raeburn 15419: if (ref($subcats) eq 'HASH') {
15420: my $subcat = &escape($name).':'.$category.':'.$depth;
15421: for (my $j=@{$parents}; $j>=0; $j--) {
15422: my $higher;
15423: if ($j > 0) {
15424: $higher = &escape($parents->[$j]).':'.
15425: &escape($parents->[$j-1]).':'.$j;
15426: } else {
15427: $higher = &escape($parents->[$j]).'::'.$j;
15428: }
15429: push(@{$subcats->{$higher}},$subcat);
15430: }
15431: }
15432: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 15433: $subcats,$maxd);
1.655 raeburn 15434: pop(@{$parents});
15435: }
15436: } else {
15437: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15438: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15439: if ($allitems->{$item} eq '') {
15440: push(@{$trails},$trailstr);
15441: $allitems->{$item} = scalar(@{$trails})-1;
15442: }
1.1321 raeburn 15443: if (ref($maxd) eq 'HASH') {
15444: if ($depth > $maxd->{$parents->[0]}) {
15445: $maxd->{$parents->[0]} = $depth;
15446: }
15447: }
1.655 raeburn 15448: }
15449: return;
15450: }
15451:
1.663 raeburn 15452: =pod
15453:
1.1162 raeburn 15454: =item * &assign_categories_table()
1.663 raeburn 15455:
15456: Create a datatable for display of hierarchical categories in a domain,
15457: with checkboxes to allow a course to be categorized.
15458:
15459: Inputs:
15460:
15461: cathash - reference to hash of categories defined for the domain (from
15462: configuration.db)
15463:
15464: currcat - scalar with an & separated list of categories assigned to a course.
15465:
1.919 raeburn 15466: type - scalar contains course type (Course or Community).
15467:
1.1260 raeburn 15468: disabled - scalar (optional) contains disabled="disabled" if input elements are
15469: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15470:
1.663 raeburn 15471: Returns: $output (markup to be displayed)
15472:
15473: =cut
15474:
15475: sub assign_categories_table {
1.1259 raeburn 15476: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15477: my $output;
15478: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 15479: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
15480: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 15481: $maxdepth = scalar(@cats);
15482: if (@cats > 0) {
15483: my $itemcount = 0;
15484: if (ref($cats[0]) eq 'ARRAY') {
15485: my @currcategories;
15486: if ($currcat ne '') {
15487: @currcategories = split('&',$currcat);
15488: }
1.919 raeburn 15489: my $table;
1.663 raeburn 15490: for (my $i=0; $i<@{$cats[0]}; $i++) {
15491: my $parent = $cats[0][$i];
1.919 raeburn 15492: next if ($parent eq 'instcode');
15493: if ($type eq 'Community') {
15494: next unless ($parent eq 'communities');
1.1239 raeburn 15495: } elsif ($type eq 'Placement') {
15496: next unless ($parent eq 'placement');
1.919 raeburn 15497: } else {
1.1239 raeburn 15498: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 15499: }
1.663 raeburn 15500: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15501: my $item = &escape($parent).'::0';
15502: my $checked = '';
15503: if (@currcategories > 0) {
15504: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15505: $checked = ' checked="checked"';
1.663 raeburn 15506: }
15507: }
1.919 raeburn 15508: my $parent_title = $parent;
15509: if ($parent eq 'communities') {
15510: $parent_title = &mt('Communities');
1.1239 raeburn 15511: } elsif ($parent eq 'placement') {
15512: $parent_title = &mt('Placement Tests');
1.919 raeburn 15513: }
15514: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15515: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15516: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15517: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15518: my $depth = 1;
15519: push(@path,$parent);
1.1259 raeburn 15520: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15521: pop(@path);
1.919 raeburn 15522: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15523: $itemcount ++;
15524: }
1.919 raeburn 15525: if ($itemcount) {
15526: $output = &Apache::loncommon::start_data_table().
15527: $table.
15528: &Apache::loncommon::end_data_table();
15529: }
1.663 raeburn 15530: }
15531: }
15532: }
15533: return $output;
15534: }
15535:
15536: =pod
15537:
1.1162 raeburn 15538: =item * &assign_category_rows()
1.663 raeburn 15539:
15540: Create a datatable row for display of nested categories in a domain,
15541: with checkboxes to allow a course to be categorized,called recursively.
15542:
15543: Inputs:
15544:
15545: itemcount - track row number for alternating colors
15546:
15547: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15548: categories and subcategories.
15549:
15550: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15551:
15552: parent - parent of current category item
15553:
15554: path - Array containing all categories back up through the hierarchy from the
15555: current category to the top level.
15556:
15557: currcategories - reference to array of current categories assigned to the course
15558:
1.1260 raeburn 15559: disabled - scalar (optional) contains disabled="disabled" if input elements are
15560: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15561:
1.663 raeburn 15562: Returns: $output (markup to be displayed).
15563:
15564: =cut
15565:
15566: sub assign_category_rows {
1.1259 raeburn 15567: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15568: my ($text,$name,$item,$chgstr);
15569: if (ref($cats) eq 'ARRAY') {
15570: my $maxdepth = scalar(@{$cats});
15571: if (ref($cats->[$depth]) eq 'HASH') {
15572: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15573: my $numchildren = @{$cats->[$depth]{$parent}};
15574: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 15575: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15576: for (my $j=0; $j<$numchildren; $j++) {
15577: $name = $cats->[$depth]{$parent}[$j];
15578: $item = &escape($name).':'.&escape($parent).':'.$depth;
15579: my $deeper = $depth+1;
15580: my $checked = '';
15581: if (ref($currcategories) eq 'ARRAY') {
15582: if (@{$currcategories} > 0) {
15583: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15584: $checked = ' checked="checked"';
1.663 raeburn 15585: }
15586: }
15587: }
1.664 raeburn 15588: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15589: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15590: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15591: '<input type="hidden" name="catname" value="'.$name.'" />'.
15592: '</td><td>';
1.663 raeburn 15593: if (ref($path) eq 'ARRAY') {
15594: push(@{$path},$name);
1.1259 raeburn 15595: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15596: pop(@{$path});
15597: }
15598: $text .= '</td></tr>';
15599: }
15600: $text .= '</table></td>';
15601: }
15602: }
15603: }
15604: return $text;
15605: }
15606:
1.1181 raeburn 15607: =pod
15608:
15609: =back
15610:
15611: =cut
15612:
1.655 raeburn 15613: ############################################################
15614: ############################################################
15615:
15616:
1.443 albertel 15617: sub commit_customrole {
1.664 raeburn 15618: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15619: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15620: ($start?', '.&mt('starting').' '.localtime($start):'').
15621: ($end?', ending '.localtime($end):'').': <b>'.
15622: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15623: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15624: '</b><br />';
15625: return $output;
15626: }
15627:
15628: sub commit_standardrole {
1.1116 raeburn 15629: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15630: my ($output,$logmsg,$linefeed);
15631: if ($context eq 'auto') {
15632: $linefeed = "\n";
15633: } else {
15634: $linefeed = "<br />\n";
15635: }
1.443 albertel 15636: if ($three eq 'st') {
1.541 raeburn 15637: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 15638: $one,$two,$sec,$context,$credits);
1.541 raeburn 15639: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15640: ($result eq 'unknown_course') || ($result eq 'refused')) {
15641: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15642: } else {
1.541 raeburn 15643: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15644: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15645: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15646: if ($context eq 'auto') {
15647: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15648: } else {
15649: $output .= '<b>'.$result.'</b>'.$linefeed.
15650: &mt('Add to classlist').': <b>ok</b>';
15651: }
15652: $output .= $linefeed;
1.443 albertel 15653: }
15654: } else {
15655: $output = &mt('Assigning').' '.$three.' in '.$url.
15656: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15657: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15658: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15659: if ($context eq 'auto') {
15660: $output .= $result.$linefeed;
15661: } else {
15662: $output .= '<b>'.$result.'</b>'.$linefeed;
15663: }
1.443 albertel 15664: }
15665: return $output;
15666: }
15667:
15668: sub commit_studentrole {
1.1116 raeburn 15669: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15670: $credits) = @_;
1.626 raeburn 15671: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15672: if ($context eq 'auto') {
15673: $linefeed = "\n";
15674: } else {
15675: $linefeed = '<br />'."\n";
15676: }
1.443 albertel 15677: if (defined($one) && defined($two)) {
15678: my $cid=$one.'_'.$two;
15679: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15680: my $secchange = 0;
15681: my $expire_role_result;
15682: my $modify_section_result;
1.628 raeburn 15683: if ($oldsec ne '-1') {
15684: if ($oldsec ne $sec) {
1.443 albertel 15685: $secchange = 1;
1.628 raeburn 15686: my $now = time;
1.443 albertel 15687: my $uurl='/'.$cid;
15688: $uurl=~s/\_/\//g;
15689: if ($oldsec) {
15690: $uurl.='/'.$oldsec;
15691: }
1.626 raeburn 15692: $oldsecurl = $uurl;
1.628 raeburn 15693: $expire_role_result =
1.652 raeburn 15694: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15695: if ($env{'request.course.sec'} ne '') {
15696: if ($expire_role_result eq 'refused') {
15697: my @roles = ('st');
15698: my @statuses = ('previous');
15699: my @roledoms = ($one);
15700: my $withsec = 1;
15701: my %roleshash =
15702: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15703: \@statuses,\@roles,\@roledoms,$withsec);
15704: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15705: my ($oldstart,$oldend) =
15706: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15707: if ($oldend > 0 && $oldend <= $now) {
15708: $expire_role_result = 'ok';
15709: }
15710: }
15711: }
15712: }
1.443 albertel 15713: $result = $expire_role_result;
15714: }
15715: }
15716: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 15717: $modify_section_result =
15718: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15719: undef,undef,undef,$sec,
15720: $end,$start,'','',$cid,
15721: '',$context,$credits);
1.443 albertel 15722: if ($modify_section_result =~ /^ok/) {
15723: if ($secchange == 1) {
1.628 raeburn 15724: if ($sec eq '') {
15725: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15726: } else {
15727: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15728: }
1.443 albertel 15729: } elsif ($oldsec eq '-1') {
1.628 raeburn 15730: if ($sec eq '') {
15731: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15732: } else {
15733: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15734: }
1.443 albertel 15735: } else {
1.628 raeburn 15736: if ($sec eq '') {
15737: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15738: } else {
15739: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15740: }
1.443 albertel 15741: }
15742: } else {
1.1115 raeburn 15743: if ($secchange) {
1.628 raeburn 15744: $$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;
15745: } else {
15746: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15747: }
1.443 albertel 15748: }
15749: $result = $modify_section_result;
15750: } elsif ($secchange == 1) {
1.628 raeburn 15751: if ($oldsec eq '') {
1.1103 raeburn 15752: $$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 15753: } else {
15754: $$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;
15755: }
1.626 raeburn 15756: if ($expire_role_result eq 'refused') {
15757: my $newsecurl = '/'.$cid;
15758: $newsecurl =~ s/\_/\//g;
15759: if ($sec ne '') {
15760: $newsecurl.='/'.$sec;
15761: }
15762: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15763: if ($sec eq '') {
15764: $$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;
15765: } else {
15766: $$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;
15767: }
15768: }
15769: }
1.443 albertel 15770: }
15771: } else {
1.626 raeburn 15772: $$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 15773: $result = "error: incomplete course id\n";
15774: }
15775: return $result;
15776: }
15777:
1.1108 raeburn 15778: sub show_role_extent {
15779: my ($scope,$context,$role) = @_;
15780: $scope =~ s{^/}{};
15781: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15782: push(@courseroles,'co');
15783: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15784: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15785: $scope =~ s{/}{_};
15786: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15787: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15788: my ($audom,$auname) = split(/\//,$scope);
15789: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15790: &Apache::loncommon::plainname($auname,$audom).'</span>');
15791: } else {
15792: $scope =~ s{/$}{};
15793: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15794: &Apache::lonnet::domain($scope,'description').'</span>');
15795: }
15796: }
15797:
1.443 albertel 15798: ############################################################
15799: ############################################################
15800:
1.566 albertel 15801: sub check_clone {
1.578 raeburn 15802: my ($args,$linefeed) = @_;
1.566 albertel 15803: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15804: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15805: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15806: my $clonemsg;
15807: my $can_clone = 0;
1.944 raeburn 15808: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15809: if ($lctype ne 'community') {
15810: $lctype = 'course';
15811: }
1.566 albertel 15812: if ($clonehome eq 'no_host') {
1.944 raeburn 15813: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15814: $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
15815: } else {
15816: $clonemsg = &mt('No new course created.').$linefeed.&mt('A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
15817: }
1.566 albertel 15818: } else {
15819: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15820: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15821: if ($clonedesc{'type'} ne 'Community') {
1.1262 raeburn 15822: $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
1.908 raeburn 15823: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15824: }
15825: }
1.1262 raeburn 15826: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15827: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15828: $can_clone = 1;
15829: } else {
1.1221 raeburn 15830: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15831: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 15832: if ($clonehash{'cloners'} eq '') {
15833: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15834: if ($domdefs{'canclone'}) {
15835: unless ($domdefs{'canclone'} eq 'none') {
15836: if ($domdefs{'canclone'} eq 'domain') {
15837: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15838: $can_clone = 1;
15839: }
15840: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15841: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15842: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15843: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15844: $can_clone = 1;
15845: }
15846: }
15847: }
15848: }
1.578 raeburn 15849: } else {
1.1221 raeburn 15850: my @cloners = split(/,/,$clonehash{'cloners'});
15851: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15852: $can_clone = 1;
1.1221 raeburn 15853: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15854: $can_clone = 1;
1.1225 raeburn 15855: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15856: $can_clone = 1;
1.1221 raeburn 15857: }
15858: unless ($can_clone) {
1.1225 raeburn 15859: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15860: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 15861: my (%gotdomdefaults,%gotcodedefaults);
15862: foreach my $cloner (@cloners) {
15863: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15864: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15865: my (%codedefaults,@code_order);
15866: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15867: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15868: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15869: }
15870: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15871: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15872: }
15873: } else {
15874: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15875: \%codedefaults,
15876: \@code_order);
15877: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15878: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15879: }
15880: if (@code_order > 0) {
15881: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15882: $cloner,$clonehash{'internal.coursecode'},
15883: $args->{'crscode'})) {
15884: $can_clone = 1;
15885: last;
15886: }
15887: }
15888: }
15889: }
15890: }
1.1225 raeburn 15891: }
15892: }
15893: unless ($can_clone) {
15894: my $ccrole = 'cc';
15895: if ($args->{'crstype'} eq 'Community') {
15896: $ccrole = 'co';
15897: }
15898: my %roleshash =
15899: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15900: $args->{'ccdomain'},
15901: 'userroles',['active'],[$ccrole],
15902: [$args->{'clonedomain'}]);
15903: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15904: $can_clone = 1;
15905: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15906: $args->{'ccuname'},$args->{'ccdomain'})) {
15907: $can_clone = 1;
1.1221 raeburn 15908: }
15909: }
15910: unless ($can_clone) {
15911: if ($args->{'crstype'} eq 'Community') {
15912: $clonemsg = &mt('No new community created.').$linefeed.&mt('The new community could not be cloned from the existing community because the new community owner ([_1]) does not have cloning rights in the existing community ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
1.942 raeburn 15913: } else {
1.1221 raeburn 15914: $clonemsg = &mt('No new course created.').$linefeed.&mt('The new course could not be cloned from the existing course because the new course owner ([_1]) does not have cloning rights in the existing course ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
15915: }
1.566 albertel 15916: }
1.578 raeburn 15917: }
1.566 albertel 15918: }
15919: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15920: }
15921:
1.444 albertel 15922: sub construct_course {
1.1262 raeburn 15923: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15924: $cnum,$category,$coderef) = @_;
1.444 albertel 15925: my $outcome;
1.541 raeburn 15926: my $linefeed = '<br />'."\n";
15927: if ($context eq 'auto') {
15928: $linefeed = "\n";
15929: }
1.566 albertel 15930:
15931: #
15932: # Are we cloning?
15933: #
15934: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15935: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15936: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15937: if ($context ne 'auto') {
1.578 raeburn 15938: if ($clonemsg ne '') {
15939: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15940: }
1.566 albertel 15941: }
15942: $outcome .= $clonemsg.$linefeed;
15943:
15944: if (!$can_clone) {
15945: return (0,$outcome);
15946: }
15947: }
15948:
1.444 albertel 15949: #
15950: # Open course
15951: #
1.1239 raeburn 15952: my $showncrstype;
15953: if ($args->{'crstype'} eq 'Placement') {
15954: $showncrstype = 'placement test';
15955: } else {
15956: $showncrstype = lc($args->{'crstype'});
15957: }
1.444 albertel 15958: my %cenv=();
15959: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15960: $args->{'cdescr'},
15961: $args->{'curl'},
15962: $args->{'course_home'},
15963: $args->{'nonstandard'},
15964: $args->{'crscode'},
15965: $args->{'ccuname'}.':'.
15966: $args->{'ccdomain'},
1.882 raeburn 15967: $args->{'crstype'},
1.885 raeburn 15968: $cnum,$context,$category);
1.444 albertel 15969:
15970: # Note: The testing routines depend on this being output; see
15971: # Utils::Course. This needs to at least be output as a comment
15972: # if anyone ever decides to not show this, and Utils::Course::new
15973: # will need to be suitably modified.
1.1239 raeburn 15974: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
1.943 raeburn 15975: if ($$courseid =~ /^error:/) {
15976: return (0,$outcome);
15977: }
15978:
1.444 albertel 15979: #
15980: # Check if created correctly
15981: #
1.479 albertel 15982: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15983: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15984: if ($crsuhome eq 'no_host') {
15985: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15986: return (0,$outcome);
15987: }
1.541 raeburn 15988: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15989:
1.444 albertel 15990: #
1.566 albertel 15991: # Do the cloning
15992: #
15993: if ($can_clone && $cloneid) {
1.1239 raeburn 15994: $clonemsg = &mt('Cloning [_1] from [_2]',$showncrstype,$clonehome);
1.566 albertel 15995: if ($context ne 'auto') {
15996: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15997: }
15998: $outcome .= $clonemsg.$linefeed;
15999: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 16000: # Copy all files
1.637 www 16001: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 16002: # Restore URL
1.566 albertel 16003: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16004: # Restore title
1.566 albertel 16005: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16006: # Restore creation date, creator and creation context.
16007: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16008: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16009: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16010: # Mark as cloned
1.566 albertel 16011: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16012: # Need to clone grading mode
16013: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16014: $cenv{'grading'}=$newenv{'grading'};
16015: # Do not clone these environment entries
16016: &Apache::lonnet::del('environment',
16017: ['default_enrollment_start_date',
16018: 'default_enrollment_end_date',
16019: 'question.email',
16020: 'policy.email',
16021: 'comment.email',
16022: 'pch.users.denied',
1.725 raeburn 16023: 'plc.users.denied',
16024: 'hidefromcat',
1.1121 raeburn 16025: 'checkforpriv',
1.1166 raeburn 16026: 'categories',
16027: 'internal.uniquecode'],
1.638 www 16028: $$crsudom,$$crsunum);
1.1170 raeburn 16029: if ($args->{'textbook'}) {
16030: $cenv{'internal.textbook'} = $args->{'textbook'};
16031: }
1.444 albertel 16032: }
1.566 albertel 16033:
1.444 albertel 16034: #
16035: # Set environment (will override cloned, if existing)
16036: #
16037: my @sections = ();
16038: my @xlists = ();
16039: if ($args->{'crstype'}) {
16040: $cenv{'type'}=$args->{'crstype'};
16041: }
16042: if ($args->{'crsid'}) {
16043: $cenv{'courseid'}=$args->{'crsid'};
16044: }
16045: if ($args->{'crscode'}) {
16046: $cenv{'internal.coursecode'}=$args->{'crscode'};
16047: }
16048: if ($args->{'crsquota'} ne '') {
16049: $cenv{'internal.coursequota'}=$args->{'crsquota'};
16050: } else {
16051: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
16052: }
16053: if ($args->{'ccuname'}) {
16054: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
16055: ':'.$args->{'ccdomain'};
16056: } else {
16057: $cenv{'internal.courseowner'} = $args->{'curruser'};
16058: }
1.1116 raeburn 16059: if ($args->{'defaultcredits'}) {
16060: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
16061: }
1.444 albertel 16062: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
16063: if ($args->{'crssections'}) {
16064: $cenv{'internal.sectionnums'} = '';
16065: if ($args->{'crssections'} =~ m/,/) {
16066: @sections = split/,/,$args->{'crssections'};
16067: } else {
16068: $sections[0] = $args->{'crssections'};
16069: }
16070: if (@sections > 0) {
16071: foreach my $item (@sections) {
16072: my ($sec,$gp) = split/:/,$item;
16073: my $class = $args->{'crscode'}.$sec;
16074: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16075: $cenv{'internal.sectionnums'} .= $item.',';
16076: unless ($addcheck eq 'ok') {
1.1263 raeburn 16077: push(@badclasses,$class);
1.444 albertel 16078: }
16079: }
16080: $cenv{'internal.sectionnums'} =~ s/,$//;
16081: }
16082: }
16083: # do not hide course coordinator from staff listing,
16084: # even if privileged
16085: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 16086: # add course coordinator's domain to domains to check for privileged users
16087: # if different to course domain
16088: if ($$crsudom ne $args->{'ccdomain'}) {
16089: $cenv{'checkforpriv'} = $args->{'ccdomain'};
16090: }
1.444 albertel 16091: # add crosslistings
16092: if ($args->{'crsxlist'}) {
16093: $cenv{'internal.crosslistings'}='';
16094: if ($args->{'crsxlist'} =~ m/,/) {
16095: @xlists = split/,/,$args->{'crsxlist'};
16096: } else {
16097: $xlists[0] = $args->{'crsxlist'};
16098: }
16099: if (@xlists > 0) {
16100: foreach my $item (@xlists) {
16101: my ($xl,$gp) = split/:/,$item;
16102: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
16103: $cenv{'internal.crosslistings'} .= $item.',';
16104: unless ($addcheck eq 'ok') {
1.1263 raeburn 16105: push(@badclasses,$xl);
1.444 albertel 16106: }
16107: }
16108: $cenv{'internal.crosslistings'} =~ s/,$//;
16109: }
16110: }
16111: if ($args->{'autoadds'}) {
16112: $cenv{'internal.autoadds'}=$args->{'autoadds'};
16113: }
16114: if ($args->{'autodrops'}) {
16115: $cenv{'internal.autodrops'}=$args->{'autodrops'};
16116: }
16117: # check for notification of enrollment changes
16118: my @notified = ();
16119: if ($args->{'notify_owner'}) {
16120: if ($args->{'ccuname'} ne '') {
16121: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
16122: }
16123: }
16124: if ($args->{'notify_dc'}) {
16125: if ($uname ne '') {
1.630 raeburn 16126: push(@notified,$uname.':'.$udom);
1.444 albertel 16127: }
16128: }
16129: if (@notified > 0) {
16130: my $notifylist;
16131: if (@notified > 1) {
16132: $notifylist = join(',',@notified);
16133: } else {
16134: $notifylist = $notified[0];
16135: }
16136: $cenv{'internal.notifylist'} = $notifylist;
16137: }
16138: if (@badclasses > 0) {
16139: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 16140: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16141: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16142: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16143: );
1.1264 raeburn 16144: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16145: &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 16146: if ($context eq 'auto') {
16147: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 16148: } else {
1.566 albertel 16149: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 16150: }
16151: foreach my $item (@badclasses) {
1.541 raeburn 16152: if ($context eq 'auto') {
1.1261 raeburn 16153: $outcome .= " - $item\n";
1.541 raeburn 16154: } else {
1.1261 raeburn 16155: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16156: }
1.1261 raeburn 16157: }
16158: if ($context eq 'auto') {
16159: $outcome .= $linefeed;
16160: } else {
16161: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 16162: }
1.444 albertel 16163: }
16164: if ($args->{'no_end_date'}) {
16165: $args->{'endaccess'} = 0;
16166: }
16167: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16168: $cenv{'internal.autoend'}=$args->{'enrollend'};
16169: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16170: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16171: if ($args->{'showphotos'}) {
16172: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16173: }
16174: $cenv{'internal.authtype'} = $args->{'authtype'};
16175: $cenv{'internal.autharg'} = $args->{'autharg'};
16176: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16177: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16178: 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');
16179: if ($context eq 'auto') {
16180: $outcome .= $krb_msg;
16181: } else {
1.566 albertel 16182: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16183: }
16184: $outcome .= $linefeed;
1.444 albertel 16185: }
16186: }
16187: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16188: if ($args->{'setpolicy'}) {
16189: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16190: }
16191: if ($args->{'setcontent'}) {
16192: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16193: }
1.1251 raeburn 16194: if ($args->{'setcomment'}) {
16195: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16196: }
1.444 albertel 16197: }
16198: if ($args->{'reshome'}) {
16199: $cenv{'reshome'}=$args->{'reshome'}.'/';
16200: $cenv{'reshome'}=~s/\/+$/\//;
16201: }
16202: #
16203: # course has keyed access
16204: #
16205: if ($args->{'setkeys'}) {
16206: $cenv{'keyaccess'}='yes';
16207: }
16208: # if specified, key authority is not course, but user
16209: # only active if keyaccess is yes
16210: if ($args->{'keyauth'}) {
1.487 albertel 16211: my ($user,$domain) = split(':',$args->{'keyauth'});
16212: $user = &LONCAPA::clean_username($user);
16213: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16214: if ($user ne '' && $domain ne '') {
1.487 albertel 16215: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16216: }
16217: }
16218:
1.1166 raeburn 16219: #
1.1167 raeburn 16220: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 16221: #
16222: if ($args->{'uniquecode'}) {
16223: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16224: if ($code) {
16225: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 16226: my %crsinfo =
16227: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16228: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16229: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16230: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16231: }
1.1166 raeburn 16232: if (ref($coderef)) {
16233: $$coderef = $code;
16234: }
16235: }
16236: }
16237:
1.444 albertel 16238: if ($args->{'disresdis'}) {
16239: $cenv{'pch.roles.denied'}='st';
16240: }
16241: if ($args->{'disablechat'}) {
16242: $cenv{'plc.roles.denied'}='st';
16243: }
16244:
16245: # Record we've not yet viewed the Course Initialization Helper for this
16246: # course
16247: $cenv{'course.helper.not.run'} = 1;
16248: #
16249: # Use new Randomseed
16250: #
16251: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16252: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16253: #
16254: # The encryption code and receipt prefix for this course
16255: #
16256: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16257: $cenv{'internal.encpref'}=100+int(9*rand(99));
16258: #
16259: # By default, use standard grading
16260: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16261:
1.541 raeburn 16262: $outcome .= $linefeed.&mt('Setting environment').': '.
16263: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16264: #
16265: # Open all assignments
16266: #
16267: if ($args->{'openall'}) {
16268: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
16269: my %storecontent = ($storeunder => time,
16270: $storeunder.'.type' => 'date_start');
16271:
16272: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 16273: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16274: }
16275: #
16276: # Set first page
16277: #
16278: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16279: || ($cloneid)) {
1.445 albertel 16280: use LONCAPA::map;
1.444 albertel 16281: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16282:
16283: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16284: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16285:
1.444 albertel 16286: $outcome .= ($fatal?$errtext:'read ok').' - ';
16287: my $title; my $url;
16288: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16289: $title=&mt('Syllabus');
1.444 albertel 16290: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16291: } else {
1.963 raeburn 16292: $title=&mt('Table of Contents');
1.444 albertel 16293: $url='/adm/navmaps';
16294: }
1.445 albertel 16295:
16296: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16297: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16298:
16299: if ($errtext) { $fatal=2; }
1.541 raeburn 16300: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16301: }
1.566 albertel 16302:
1.1237 raeburn 16303: #
16304: # Set params for Placement Tests
16305: #
1.1239 raeburn 16306: if ($args->{'crstype'} eq 'Placement') {
16307: my %storecontent;
16308: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
16309: my %defaults = (
16310: buttonshide => { value => 'yes',
16311: type => 'string_yesno',},
16312: type => { value => 'randomizetry',
16313: type => 'string_questiontype',},
16314: maxtries => { value => 1,
16315: type => 'int_pos',},
16316: problemstatus => { value => 'no',
16317: type => 'string_problemstatus',},
16318: );
16319: foreach my $key (keys(%defaults)) {
16320: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
16321: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
16322: }
1.1237 raeburn 16323: &Apache::lonnet::cput
16324: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
16325: }
16326:
1.566 albertel 16327: return (1,$outcome);
1.444 albertel 16328: }
16329:
1.1166 raeburn 16330: sub make_unique_code {
16331: my ($cdom,$cnum) = @_;
16332: # get lock on uniquecodes db
16333: my $lockhash = {
16334: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16335: ':'.$env{'user.domain'},
16336: };
16337: my $tries = 0;
16338: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16339: my ($code,$error);
16340:
16341: while (($gotlock ne 'ok') && ($tries<3)) {
16342: $tries ++;
16343: sleep 1;
16344: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16345: }
16346: if ($gotlock eq 'ok') {
16347: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
16348: my $gotcode;
16349: my $attempts = 0;
16350: while ((!$gotcode) && ($attempts < 100)) {
16351: $code = &generate_code();
16352: if (!exists($currcodes{$code})) {
16353: $gotcode = 1;
16354: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
16355: $error = 'nostore';
16356: }
16357: }
16358: $attempts ++;
16359: }
16360: my @del_lock = ($cnum."\0".'uniquecodes');
16361: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
16362: } else {
16363: $error = 'nolock';
16364: }
16365: return ($code,$error);
16366: }
16367:
16368: sub generate_code {
16369: my $code;
16370: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
16371: for (my $i=0; $i<6; $i++) {
16372: my $lettnum = int (rand 2);
16373: my $item = '';
16374: if ($lettnum) {
16375: $item = $letts[int( rand(18) )];
16376: } else {
16377: $item = 1+int( rand(8) );
16378: }
16379: $code .= $item;
16380: }
16381: return $code;
16382: }
16383:
1.444 albertel 16384: ############################################################
16385: ############################################################
16386:
1.1237 raeburn 16387: # Community, Course and Placement Test
1.378 raeburn 16388: sub course_type {
16389: my ($cid) = @_;
16390: if (!defined($cid)) {
16391: $cid = $env{'request.course.id'};
16392: }
1.404 albertel 16393: if (defined($env{'course.'.$cid.'.type'})) {
16394: return $env{'course.'.$cid.'.type'};
1.378 raeburn 16395: } else {
16396: return 'Course';
1.377 raeburn 16397: }
16398: }
1.156 albertel 16399:
1.406 raeburn 16400: sub group_term {
16401: my $crstype = &course_type();
16402: my %names = (
16403: 'Course' => 'group',
1.865 raeburn 16404: 'Community' => 'group',
1.1237 raeburn 16405: 'Placement' => 'group',
1.406 raeburn 16406: );
16407: return $names{$crstype};
16408: }
16409:
1.902 raeburn 16410: sub course_types {
1.1310 raeburn 16411: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 16412: my %typename = (
16413: official => 'Official course',
16414: unofficial => 'Unofficial course',
16415: community => 'Community',
1.1165 raeburn 16416: textbook => 'Textbook course',
1.1237 raeburn 16417: placement => 'Placement test',
1.1310 raeburn 16418: lti => 'LTI provider',
1.902 raeburn 16419: );
16420: return (\@types,\%typename);
16421: }
16422:
1.156 albertel 16423: sub icon {
16424: my ($file)=@_;
1.505 albertel 16425: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 16426: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 16427: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 16428: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
16429: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
16430: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16431: $curfext.".gif") {
16432: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16433: $curfext.".gif";
16434: }
16435: }
1.249 albertel 16436: return &lonhttpdurl($iconname);
1.154 albertel 16437: }
1.84 albertel 16438:
1.575 albertel 16439: sub lonhttpdurl {
1.692 www 16440: #
16441: # Had been used for "small fry" static images on separate port 8080.
16442: # Modify here if lightweight http functionality desired again.
16443: # Currently eliminated due to increasing firewall issues.
16444: #
1.575 albertel 16445: my ($url)=@_;
1.692 www 16446: return $url;
1.215 albertel 16447: }
16448:
1.213 albertel 16449: sub connection_aborted {
16450: my ($r)=@_;
16451: $r->print(" ");$r->rflush();
16452: my $c = $r->connection;
16453: return $c->aborted();
16454: }
16455:
1.221 foxr 16456: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 16457: # strings as 'strings'.
16458: sub escape_single {
1.221 foxr 16459: my ($input) = @_;
1.223 albertel 16460: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16461: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16462: return $input;
16463: }
1.223 albertel 16464:
1.222 foxr 16465: # Same as escape_single, but escape's "'s This
16466: # can be used for "strings"
16467: sub escape_double {
16468: my ($input) = @_;
16469: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16470: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16471: return $input;
16472: }
1.223 albertel 16473:
1.222 foxr 16474: # Escapes the last element of a full URL.
16475: sub escape_url {
16476: my ($url) = @_;
1.238 raeburn 16477: my @urlslices = split(/\//, $url,-1);
1.369 www 16478: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 16479: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16480: }
1.462 albertel 16481:
1.820 raeburn 16482: sub compare_arrays {
16483: my ($arrayref1,$arrayref2) = @_;
16484: my (@difference,%count);
16485: @difference = ();
16486: %count = ();
16487: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16488: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16489: foreach my $element (keys(%count)) {
16490: if ($count{$element} == 1) {
16491: push(@difference,$element);
16492: }
16493: }
16494: }
16495: return @difference;
16496: }
16497:
1.1322 raeburn 16498: sub lon_status_items {
16499: my %defaults = (
16500: E => 100,
16501: W => 4,
16502: N => 1,
1.1324 raeburn 16503: U => 5,
1.1322 raeburn 16504: threshold => 200,
16505: sysmail => 2500,
16506: );
16507: my %names = (
16508: E => 'Errors',
16509: W => 'Warnings',
16510: N => 'Notices',
1.1324 raeburn 16511: U => 'Unsent',
1.1322 raeburn 16512: );
16513: return (\%defaults,\%names);
16514: }
16515:
1.817 bisitz 16516: # -------------------------------------------------------- Initialize user login
1.462 albertel 16517: sub init_user_environment {
1.463 albertel 16518: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16519: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16520:
16521: my $public=($username eq 'public' && $domain eq 'public');
16522:
1.1062 raeburn 16523: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16524: my $now=time;
16525:
16526: if ($public) {
16527: my $max_public=100;
16528: my $oldest;
16529: my $oldest_time=0;
16530: for(my $next=1;$next<=$max_public;$next++) {
16531: if (-e $lonids."/publicuser_$next.id") {
16532: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16533: if ($mtime<$oldest_time || !$oldest_time) {
16534: $oldest_time=$mtime;
16535: $oldest=$next;
16536: }
16537: } else {
16538: $cookie="publicuser_$next";
16539: last;
16540: }
16541: }
16542: if (!$cookie) { $cookie="publicuser_$oldest"; }
16543: } else {
1.1275 raeburn 16544: # See if old ID present, if so, remove if this isn't a robot,
16545: # killing any existing non-robot sessions
1.463 albertel 16546: if (!$args->{'robot'}) {
16547: opendir(DIR,$lonids);
16548: while ($filename=readdir(DIR)) {
16549: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 16550: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
16551: &GDBM_READER(),0640)) {
1.1295 raeburn 16552: my $linkedfile;
1.1320 raeburn 16553: if (exists($oldenv{'user.linkedenv'})) {
16554: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 16555: }
1.1320 raeburn 16556: untie(%oldenv);
16557: if (unlink("$lonids/$filename")) {
16558: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
16559: if (-l "$lonids/$linkedfile.id") {
16560: unlink("$lonids/$linkedfile.id");
16561: }
1.1295 raeburn 16562: }
16563: }
16564: } else {
16565: unlink($lonids.'/'.$filename);
16566: }
1.463 albertel 16567: }
1.462 albertel 16568: }
1.463 albertel 16569: closedir(DIR);
1.1204 raeburn 16570: # If there is a undeleted lockfile for the user's paste buffer remove it.
16571: my $namespace = 'nohist_courseeditor';
16572: my $lockingkey = 'paste'."\0".'locked_num';
16573: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16574: $domain,$username);
16575: if (exists($lockhash{$lockingkey})) {
16576: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16577: unless ($delresult eq 'ok') {
16578: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16579: }
16580: }
1.462 albertel 16581: }
16582: # Give them a new cookie
1.463 albertel 16583: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16584: : $now.$$.int(rand(10000)));
1.463 albertel 16585: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16586:
16587: # Initialize roles
16588:
1.1062 raeburn 16589: ($userroles,$firstaccenv,$timerintenv) =
16590: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16591: }
16592: # ------------------------------------ Check browser type and MathML capability
16593:
1.1194 raeburn 16594: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16595: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16596:
16597: # ------------------------------------------------------------- Get environment
16598:
16599: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16600: my ($tmp) = keys(%userenv);
1.1275 raeburn 16601: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 16602: undef(%userenv);
16603: }
16604: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16605: $form->{'interface'}=$userenv{'interface'};
16606: }
16607: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16608:
16609: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16610: foreach my $option ('interface','localpath','localres') {
16611: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16612: }
16613: # --------------------------------------------------------- Write first profile
16614:
16615: {
16616: my %initial_env =
16617: ("user.name" => $username,
16618: "user.domain" => $domain,
16619: "user.home" => $authhost,
16620: "browser.type" => $clientbrowser,
16621: "browser.version" => $clientversion,
16622: "browser.mathml" => $clientmathml,
16623: "browser.unicode" => $clientunicode,
16624: "browser.os" => $clientos,
1.1137 raeburn 16625: "browser.mobile" => $clientmobile,
1.1141 raeburn 16626: "browser.info" => $clientinfo,
1.1194 raeburn 16627: "browser.osversion" => $clientosversion,
1.462 albertel 16628: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16629: "request.course.fn" => '',
16630: "request.course.uri" => '',
16631: "request.course.sec" => '',
16632: "request.role" => 'cm',
16633: "request.role.adv" => $env{'user.adv'},
16634: "request.host" => $ENV{'REMOTE_ADDR'},);
16635:
16636: if ($form->{'localpath'}) {
16637: $initial_env{"browser.localpath"} = $form->{'localpath'};
16638: $initial_env{"browser.localres"} = $form->{'localres'};
16639: }
16640:
16641: if ($form->{'interface'}) {
16642: $form->{'interface'}=~s/\W//gs;
16643: $initial_env{"browser.interface"} = $form->{'interface'};
16644: $env{'browser.interface'}=$form->{'interface'};
16645: }
16646:
1.1157 raeburn 16647: if ($form->{'iptoken'}) {
16648: my $lonhost = $r->dir_config('lonHostID');
16649: $initial_env{"user.noloadbalance"} = $lonhost;
16650: $env{'user.noloadbalance'} = $lonhost;
16651: }
16652:
1.1268 raeburn 16653: if ($form->{'noloadbalance'}) {
16654: my @hosts = &Apache::lonnet::current_machine_ids();
16655: my $hosthere = $form->{'noloadbalance'};
16656: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16657: $initial_env{"user.noloadbalance"} = $hosthere;
16658: $env{'user.noloadbalance'} = $hosthere;
16659: }
16660: }
16661:
1.1016 raeburn 16662: unless ($domain eq 'public') {
1.1273 raeburn 16663: my %is_adv = ( is_adv => $env{'user.adv'} );
16664: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
16665:
16666: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16667: $userenv{'availabletools.'.$tool} =
16668: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16669: undef,\%userenv,\%domdef,\%is_adv);
16670: }
1.980 raeburn 16671:
1.1311 raeburn 16672: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 16673: $userenv{'canrequest.'.$crstype} =
16674: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16675: 'reload','requestcourses',
16676: \%userenv,\%domdef,\%is_adv);
16677: }
1.724 raeburn 16678:
1.1273 raeburn 16679: $userenv{'canrequest.author'} =
16680: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16681: 'reload','requestauthor',
1.980 raeburn 16682: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 16683: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16684: $domain,$username);
16685: my $reqstatus = $reqauthor{'author_status'};
16686: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16687: if (ref($reqauthor{'author'}) eq 'HASH') {
16688: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16689: $reqauthor{'author'}{'timestamp'};
16690: }
1.1092 raeburn 16691: }
1.1287 raeburn 16692: my ($types,$typename) = &course_types();
16693: if (ref($types) eq 'ARRAY') {
16694: my @options = ('approval','validate','autolimit');
16695: my $optregex = join('|',@options);
16696: my (%willtrust,%trustchecked);
16697: foreach my $type (@{$types}) {
16698: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
16699: if ($dom_str ne '') {
16700: my $updatedstr = '';
16701: my @possdomains = split(',',$dom_str);
16702: foreach my $entry (@possdomains) {
16703: my ($extdom,$extopt) = split(':',$entry);
16704: unless ($trustchecked{$extdom}) {
16705: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
16706: $trustchecked{$extdom} = 1;
16707: }
16708: if ($willtrust{$extdom}) {
16709: $updatedstr .= $entry.',';
16710: }
16711: }
16712: $updatedstr =~ s/,$//;
16713: if ($updatedstr) {
16714: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
16715: } else {
16716: delete($userenv{'reqcrsotherdom.'.$type});
16717: }
16718: }
16719: }
16720: }
1.1092 raeburn 16721: }
1.462 albertel 16722: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16723:
1.462 albertel 16724: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16725: &GDBM_WRCREAT(),0640)) {
16726: &_add_to_env(\%disk_env,\%initial_env);
16727: &_add_to_env(\%disk_env,\%userenv,'environment.');
16728: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16729: if (ref($firstaccenv) eq 'HASH') {
16730: &_add_to_env(\%disk_env,$firstaccenv);
16731: }
16732: if (ref($timerintenv) eq 'HASH') {
16733: &_add_to_env(\%disk_env,$timerintenv);
16734: }
1.463 albertel 16735: if (ref($args->{'extra_env'})) {
16736: &_add_to_env(\%disk_env,$args->{'extra_env'});
16737: }
1.462 albertel 16738: untie(%disk_env);
16739: } else {
1.705 tempelho 16740: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16741: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16742: return 'error: '.$!;
16743: }
16744: }
16745: $env{'request.role'}='cm';
16746: $env{'request.role.adv'}=$env{'user.adv'};
16747: $env{'browser.type'}=$clientbrowser;
16748:
16749: return $cookie;
16750:
16751: }
16752:
16753: sub _add_to_env {
16754: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16755: if (ref($env_data) eq 'HASH') {
16756: while (my ($key,$value) = each(%$env_data)) {
16757: $idf->{$prefix.$key} = $value;
16758: $env{$prefix.$key} = $value;
16759: }
1.462 albertel 16760: }
16761: }
16762:
1.685 tempelho 16763: # --- Get the symbolic name of a problem and the url
16764: sub get_symb {
16765: my ($request,$silent) = @_;
1.726 raeburn 16766: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16767: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16768: if ($symb eq '') {
16769: if (!$silent) {
1.1071 raeburn 16770: if (ref($request)) {
16771: $request->print("Unable to handle ambiguous references:$url:.");
16772: }
1.685 tempelho 16773: return ();
16774: }
16775: }
16776: &Apache::lonenc::check_decrypt(\$symb);
16777: return ($symb);
16778: }
16779:
16780: # --------------------------------------------------------------Get annotation
16781:
16782: sub get_annotation {
16783: my ($symb,$enc) = @_;
16784:
16785: my $key = $symb;
16786: if (!$enc) {
16787: $key =
16788: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16789: }
16790: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16791: return $annotation{$key};
16792: }
16793:
16794: sub clean_symb {
1.731 raeburn 16795: my ($symb,$delete_enc) = @_;
1.685 tempelho 16796:
16797: &Apache::lonenc::check_decrypt(\$symb);
16798: my $enc = $env{'request.enc'};
1.731 raeburn 16799: if ($delete_enc) {
1.730 raeburn 16800: delete($env{'request.enc'});
16801: }
1.685 tempelho 16802:
16803: return ($symb,$enc);
16804: }
1.462 albertel 16805:
1.1181 raeburn 16806: ############################################################
16807: ############################################################
16808:
16809: =pod
16810:
16811: =head1 Routines for building display used to search for courses
16812:
16813:
16814: =over 4
16815:
16816: =item * &build_filters()
16817:
16818: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 16819: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16820: and quotacheck.pl
16821:
1.1181 raeburn 16822:
16823: Inputs:
16824:
16825: filterlist - anonymous array of fields to include as potential filters
16826:
16827: crstype - course type
16828:
16829: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16830: to pop-open a course selector (will contain "extra element").
16831:
16832: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16833:
16834: filter - anonymous hash of criteria and their values
16835:
16836: action - form action
16837:
16838: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16839:
1.1182 raeburn 16840: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 16841:
16842: cloneruname - username of owner of new course who wants to clone
16843:
16844: clonerudom - domain of owner of new course who wants to clone
16845:
16846: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16847:
16848: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16849:
16850: codedom - domain
16851:
16852: formname - value of form element named "form".
16853:
16854: fixeddom - domain, if fixed.
16855:
16856: prevphase - value to assign to form element named "phase" when going back to the previous screen
16857:
16858: cnameelement - name of form element in form on opener page which will receive title of selected course
16859:
16860: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16861:
16862: cdomelement - name of form element in form on opener page which will receive domain of selected course
16863:
16864: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16865:
16866: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16867:
16868: clonewarning - warning message about missing information for intended course owner when DC creates a course
16869:
1.1182 raeburn 16870:
1.1181 raeburn 16871: Returns: $output - HTML for display of search criteria, and hidden form elements.
16872:
1.1182 raeburn 16873:
1.1181 raeburn 16874: Side Effects: None
16875:
16876: =cut
16877:
16878: # ---------------------------------------------- search for courses based on last activity etc.
16879:
16880: sub build_filters {
16881: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16882: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16883: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16884: $cnameelement,$cnumelement,$cdomelement,$setroles,
16885: $clonetext,$clonewarning) = @_;
1.1182 raeburn 16886: my ($list,$jscript);
1.1181 raeburn 16887: my $onchange = 'javascript:updateFilters(this)';
16888: my ($domainselectform,$sincefilterform,$createdfilterform,
16889: $ownerdomselectform,$persondomselectform,$instcodeform,
16890: $typeselectform,$instcodetitle);
16891: if ($formname eq '') {
16892: $formname = $caller;
16893: }
16894: foreach my $item (@{$filterlist}) {
16895: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16896: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16897: if ($item eq 'domainfilter') {
16898: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16899: } elsif ($item eq 'coursefilter') {
16900: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16901: } elsif ($item eq 'ownerfilter') {
16902: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16903: } elsif ($item eq 'ownerdomfilter') {
16904: $filter->{'ownerdomfilter'} =
16905: &LONCAPA::clean_domain($filter->{$item});
16906: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16907: 'ownerdomfilter',1);
16908: } elsif ($item eq 'personfilter') {
16909: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16910: } elsif ($item eq 'persondomfilter') {
16911: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16912: 'persondomfilter',1);
16913: } else {
16914: $filter->{$item} =~ s/\W//g;
16915: }
16916: if (!$filter->{$item}) {
16917: $filter->{$item} = '';
16918: }
16919: }
16920: if ($item eq 'domainfilter') {
16921: my $allow_blank = 1;
16922: if ($formname eq 'portform') {
16923: $allow_blank=0;
16924: } elsif ($formname eq 'studentform') {
16925: $allow_blank=0;
16926: }
16927: if ($fixeddom) {
16928: $domainselectform = '<input type="hidden" name="domainfilter"'.
16929: ' value="'.$codedom.'" />'.
16930: &Apache::lonnet::domain($codedom,'description');
16931: } else {
16932: $domainselectform = &select_dom_form($filter->{$item},
16933: 'domainfilter',
16934: $allow_blank,'',$onchange);
16935: }
16936: } else {
16937: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16938: }
16939: }
16940:
16941: # last course activity filter and selection
16942: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16943:
16944: # course created filter and selection
16945: if (exists($filter->{'createdfilter'})) {
16946: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16947: }
16948:
1.1239 raeburn 16949: my $prefix = $crstype;
16950: if ($crstype eq 'Placement') {
16951: $prefix = 'Placement Test'
16952: }
1.1181 raeburn 16953: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 16954: 'cac' => "$prefix Activity",
16955: 'ccr' => "$prefix Created",
16956: 'cde' => "$prefix Title",
16957: 'cdo' => "$prefix Domain",
1.1181 raeburn 16958: 'ins' => 'Institutional Code',
16959: 'inc' => 'Institutional Categorization',
1.1239 raeburn 16960: 'cow' => "$prefix Owner/Co-owner",
16961: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 16962: 'cog' => 'Type',
16963: );
16964:
16965: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16966: my $typeval = 'Course';
16967: if ($crstype eq 'Community') {
16968: $typeval = 'Community';
1.1239 raeburn 16969: } elsif ($crstype eq 'Placement') {
16970: $typeval = 'Placement';
1.1181 raeburn 16971: }
16972: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16973: } else {
16974: $typeselectform = '<select name="type" size="1"';
16975: if ($onchange) {
16976: $typeselectform .= ' onchange="'.$onchange.'"';
16977: }
16978: $typeselectform .= '>'."\n";
1.1237 raeburn 16979: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 16980: my $shown;
16981: if ($posstype eq 'Placement') {
16982: $shown = &mt('Placement Test');
16983: } else {
16984: $shown = &mt($posstype);
16985: }
1.1181 raeburn 16986: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 16987: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 16988: }
16989: $typeselectform.="</select>";
16990: }
16991:
16992: my ($cloneableonlyform,$cloneabletitle);
16993: if (exists($filter->{'cloneableonly'})) {
16994: my $cloneableon = '';
16995: my $cloneableoff = ' checked="checked"';
16996: if ($filter->{'cloneableonly'}) {
16997: $cloneableon = $cloneableoff;
16998: $cloneableoff = '';
16999: }
17000: $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>';
17001: if ($formname eq 'ccrs') {
1.1187 bisitz 17002: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 17003: } else {
17004: $cloneabletitle = &mt('Cloneable by you');
17005: }
17006: }
17007: my $officialjs;
17008: if ($crstype eq 'Course') {
17009: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 17010: # if (($fixeddom) || ($formname eq 'requestcrs') ||
17011: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
17012: if ($codedom) {
1.1181 raeburn 17013: $officialjs = 1;
17014: ($instcodeform,$jscript,$$numtitlesref) =
17015: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
17016: $officialjs,$codetitlesref);
17017: if ($jscript) {
1.1182 raeburn 17018: $jscript = '<script type="text/javascript">'."\n".
17019: '// <![CDATA['."\n".
17020: $jscript."\n".
17021: '// ]]>'."\n".
17022: '</script>'."\n";
1.1181 raeburn 17023: }
17024: }
17025: if ($instcodeform eq '') {
17026: $instcodeform =
17027: '<input type="text" name="instcodefilter" size="10" value="'.
17028: $list->{'instcodefilter'}.'" />';
17029: $instcodetitle = $lt{'ins'};
17030: } else {
17031: $instcodetitle = $lt{'inc'};
17032: }
17033: if ($fixeddom) {
17034: $instcodetitle .= '<br />('.$codedom.')';
17035: }
17036: }
17037: }
17038: my $output = qq|
17039: <form method="post" name="filterpicker" action="$action">
17040: <input type="hidden" name="form" value="$formname" />
17041: |;
17042: if ($formname eq 'modifycourse') {
17043: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
17044: '<input type="hidden" name="prevphase" value="'.
17045: $prevphase.'" />'."\n";
1.1198 musolffc 17046: } elsif ($formname eq 'quotacheck') {
17047: $output .= qq|
17048: <input type="hidden" name="sortby" value="" />
17049: <input type="hidden" name="sortorder" value="" />
17050: |;
17051: } else {
1.1181 raeburn 17052: my $name_input;
17053: if ($cnameelement ne '') {
17054: $name_input = '<input type="hidden" name="cnameelement" value="'.
17055: $cnameelement.'" />';
17056: }
17057: $output .= qq|
1.1182 raeburn 17058: <input type="hidden" name="cnumelement" value="$cnumelement" />
17059: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 17060: $name_input
17061: $roleelement
17062: $multelement
17063: $typeelement
17064: |;
17065: if ($formname eq 'portform') {
17066: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
17067: }
17068: }
17069: if ($fixeddom) {
17070: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
17071: }
17072: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
17073: if ($sincefilterform) {
17074: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
17075: .$sincefilterform
17076: .&Apache::lonhtmlcommon::row_closure();
17077: }
17078: if ($createdfilterform) {
17079: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17080: .$createdfilterform
17081: .&Apache::lonhtmlcommon::row_closure();
17082: }
17083: if ($domainselectform) {
17084: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
17085: .$domainselectform
17086: .&Apache::lonhtmlcommon::row_closure();
17087: }
17088: if ($typeselectform) {
17089: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17090: $output .= $typeselectform;
17091: } else {
17092: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
17093: .$typeselectform
17094: .&Apache::lonhtmlcommon::row_closure();
17095: }
17096: }
17097: if ($instcodeform) {
17098: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
17099: .$instcodeform
17100: .&Apache::lonhtmlcommon::row_closure();
17101: }
17102: if (exists($filter->{'ownerfilter'})) {
17103: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
17104: '<table><tr><td>'.&mt('Username').'<br />'.
17105: '<input type="text" name="ownerfilter" size="20" value="'.
17106: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17107: $ownerdomselectform.'</td></tr></table>'.
17108: &Apache::lonhtmlcommon::row_closure();
17109: }
17110: if (exists($filter->{'personfilter'})) {
17111: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
17112: '<table><tr><td>'.&mt('Username').'<br />'.
17113: '<input type="text" name="personfilter" size="20" value="'.
17114: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17115: $persondomselectform.'</td></tr></table>'.
17116: &Apache::lonhtmlcommon::row_closure();
17117: }
17118: if (exists($filter->{'coursefilter'})) {
17119: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
17120: .'<input type="text" name="coursefilter" size="25" value="'
17121: .$list->{'coursefilter'}.'" />'
17122: .&Apache::lonhtmlcommon::row_closure();
17123: }
17124: if ($cloneableonlyform) {
17125: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
17126: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
17127: }
17128: if (exists($filter->{'descriptfilter'})) {
17129: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
17130: .'<input type="text" name="descriptfilter" size="40" value="'
17131: .$list->{'descriptfilter'}.'" />'
17132: .&Apache::lonhtmlcommon::row_closure(1);
17133: }
17134: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
17135: '<input type="hidden" name="updater" value="" />'."\n".
17136: '<input type="submit" name="gosearch" value="'.
17137: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
17138: return $jscript.$clonewarning.$output;
17139: }
17140:
17141: =pod
17142:
17143: =item * &timebased_select_form()
17144:
1.1182 raeburn 17145: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 17146: filter e.g., Course Activity, Course Created, when searching for courses
17147: or communities
17148:
17149: Inputs:
17150:
17151: item - name of form element (sincefilter or createdfilter)
17152:
17153: filter - anonymous hash of criteria and their values
17154:
17155: Returns: HTML for a select box contained a blank, then six time selections,
17156: with value set in incoming form variables currently selected.
17157:
17158: Side Effects: None
17159:
17160: =cut
17161:
17162: sub timebased_select_form {
17163: my ($item,$filter) = @_;
17164: if (ref($filter) eq 'HASH') {
17165: $filter->{$item} =~ s/[^\d-]//g;
17166: if (!$filter->{$item}) { $filter->{$item}=-1; }
17167: return &select_form(
17168: $filter->{$item},
17169: $item,
17170: { '-1' => '',
17171: '86400' => &mt('today'),
17172: '604800' => &mt('last week'),
17173: '2592000' => &mt('last month'),
17174: '7776000' => &mt('last three months'),
17175: '15552000' => &mt('last six months'),
17176: '31104000' => &mt('last year'),
17177: 'select_form_order' =>
17178: ['-1','86400','604800','2592000','7776000',
17179: '15552000','31104000']});
17180: }
17181: }
17182:
17183: =pod
17184:
17185: =item * &js_changer()
17186:
17187: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 17188: when course type or domain is changed, and also to hide 'Searching ...' on
17189: page load completion for page showing search result.
1.1181 raeburn 17190:
17191: Inputs: None
17192:
1.1183 raeburn 17193: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 17194:
17195: Side Effects: None
17196:
17197: =cut
17198:
17199: sub js_changer {
17200: return <<ENDJS;
17201: <script type="text/javascript">
17202: // <![CDATA[
17203: function updateFilters(caller) {
17204: if (typeof(caller) != "undefined") {
17205: document.filterpicker.updater.value = caller.name;
17206: }
17207: document.filterpicker.submit();
17208: }
1.1183 raeburn 17209:
17210: function hideSearching() {
17211: if (document.getElementById('searching')) {
17212: document.getElementById('searching').style.display = 'none';
17213: }
17214: return;
17215: }
17216:
1.1181 raeburn 17217: // ]]>
17218: </script>
17219:
17220: ENDJS
17221: }
17222:
17223: =pod
17224:
1.1182 raeburn 17225: =item * &search_courses()
17226:
17227: Process selected filters form course search form and pass to lonnet::courseiddump
17228: to retrieve a hash for which keys are courseIDs which match the selected filters.
17229:
17230: Inputs:
17231:
17232: dom - domain being searched
17233:
17234: type - course type ('Course' or 'Community' or '.' if any).
17235:
17236: filter - anonymous hash of criteria and their values
17237:
17238: numtitles - for institutional codes - number of categories
17239:
17240: cloneruname - optional username of new course owner
17241:
17242: clonerudom - optional domain of new course owner
17243:
1.1221 raeburn 17244: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 17245: (used when DC is using course creation form)
17246:
17247: codetitles - reference to array of titles of components in institutional codes (official courses).
17248:
1.1221 raeburn 17249: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17250: (and so can clone automatically)
17251:
17252: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17253:
17254: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17255: courses to clone
1.1182 raeburn 17256:
17257: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17258:
17259:
17260: Side Effects: None
17261:
17262: =cut
17263:
17264:
17265: sub search_courses {
1.1221 raeburn 17266: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17267: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 17268: my (%courses,%showcourses,$cloner);
17269: if (($filter->{'ownerfilter'} ne '') ||
17270: ($filter->{'ownerdomfilter'} ne '')) {
17271: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17272: $filter->{'ownerdomfilter'};
17273: }
17274: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17275: if (!$filter->{$item}) {
17276: $filter->{$item}='.';
17277: }
17278: }
17279: my $now = time;
17280: my $timefilter =
17281: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17282: my ($createdbefore,$createdafter);
17283: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17284: $createdbefore = $now;
17285: $createdafter = $now-$filter->{'createdfilter'};
17286: }
17287: my ($instcodefilter,$regexpok);
17288: if ($numtitles) {
17289: if ($env{'form.official'} eq 'on') {
17290: $instcodefilter =
17291: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17292: $regexpok = 1;
17293: } elsif ($env{'form.official'} eq 'off') {
17294: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17295: unless ($instcodefilter eq '') {
17296: $regexpok = -1;
17297: }
17298: }
17299: } else {
17300: $instcodefilter = $filter->{'instcodefilter'};
17301: }
17302: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17303: if ($type eq '') { $type = '.'; }
17304:
17305: if (($clonerudom ne '') && ($cloneruname ne '')) {
17306: $cloner = $cloneruname.':'.$clonerudom;
17307: }
17308: %courses = &Apache::lonnet::courseiddump($dom,
17309: $filter->{'descriptfilter'},
17310: $timefilter,
17311: $instcodefilter,
17312: $filter->{'combownerfilter'},
17313: $filter->{'coursefilter'},
17314: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 17315: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 17316: $filter->{'cloneableonly'},
17317: $createdbefore,$createdafter,undef,
1.1221 raeburn 17318: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 17319: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17320: my $ccrole;
17321: if ($type eq 'Community') {
17322: $ccrole = 'co';
17323: } else {
17324: $ccrole = 'cc';
17325: }
17326: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17327: $filter->{'persondomfilter'},
17328: 'userroles',undef,
17329: [$ccrole,'in','ad','ep','ta','cr'],
17330: $dom);
17331: foreach my $role (keys(%rolehash)) {
17332: my ($cnum,$cdom,$courserole) = split(':',$role);
17333: my $cid = $cdom.'_'.$cnum;
17334: if (exists($courses{$cid})) {
17335: if (ref($courses{$cid}) eq 'HASH') {
17336: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17337: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 17338: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 17339: }
17340: } else {
17341: $courses{$cid}{roles} = [$courserole];
17342: }
17343: $showcourses{$cid} = $courses{$cid};
17344: }
17345: }
17346: }
17347: %courses = %showcourses;
17348: }
17349: return %courses;
17350: }
17351:
17352: =pod
17353:
1.1181 raeburn 17354: =back
17355:
1.1207 raeburn 17356: =head1 Routines for version requirements for current course.
17357:
17358: =over 4
17359:
17360: =item * &check_release_required()
17361:
17362: Compares required LON-CAPA version with version on server, and
17363: if required version is newer looks for a server with the required version.
17364:
17365: Looks first at servers in user's owen domain; if none suitable, looks at
17366: servers in course's domain are permitted to host sessions for user's domain.
17367:
17368: Inputs:
17369:
17370: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17371:
17372: $courseid - Course ID of current course
17373:
17374: $rolecode - User's current role in course (for switchserver query string).
17375:
17376: $required - LON-CAPA version needed by course (format: Major.Minor).
17377:
17378:
17379: Returns:
17380:
17381: $switchserver - query string tp append to /adm/switchserver call (if
17382: current server's LON-CAPA version is too old.
17383:
17384: $warning - Message is displayed if no suitable server could be found.
17385:
17386: =cut
17387:
17388: sub check_release_required {
17389: my ($loncaparev,$courseid,$rolecode,$required) = @_;
17390: my ($switchserver,$warning);
17391: if ($required ne '') {
17392: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
17393: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17394: if ($reqdmajor ne '' && $reqdminor ne '') {
17395: my $otherserver;
17396: if (($major eq '' && $minor eq '') ||
17397: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
17398: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
17399: my $switchlcrev =
17400: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
17401: $userdomserver);
17402: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17403: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
17404: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
17405: my $cdom = $env{'course.'.$courseid.'.domain'};
17406: if ($cdom ne $env{'user.domain'}) {
17407: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
17408: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
17409: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17410: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
17411: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
17412: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
17413: my $canhost =
17414: &Apache::lonnet::can_host_session($env{'user.domain'},
17415: $coursedomserver,
17416: $remoterev,
17417: $udomdefaults{'remotesessions'},
17418: $defdomdefaults{'hostedsessions'});
17419:
17420: if ($canhost) {
17421: $otherserver = $coursedomserver;
17422: } else {
17423: $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.");
17424: }
17425: } else {
17426: $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).");
17427: }
17428: } else {
17429: $otherserver = $userdomserver;
17430: }
17431: }
17432: if ($otherserver ne '') {
17433: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
17434: }
17435: }
17436: }
17437: return ($switchserver,$warning);
17438: }
17439:
17440: =pod
17441:
17442: =item * &check_release_result()
17443:
17444: Inputs:
17445:
17446: $switchwarning - Warning message if no suitable server found to host session.
17447:
17448: $switchserver - query string to append to /adm/switchserver containing lonHostID
17449: and current role.
17450:
17451: Returns: HTML to display with information about requirement to switch server.
17452: Either displaying warning with link to Roles/Courses screen or
17453: display link to switchserver.
17454:
1.1181 raeburn 17455: =cut
17456:
1.1207 raeburn 17457: sub check_release_result {
17458: my ($switchwarning,$switchserver) = @_;
17459: my $output = &start_page('Selected course unavailable on this server').
17460: '<p class="LC_warning">';
17461: if ($switchwarning) {
17462: $output .= $switchwarning.'<br /><a href="/adm/roles">';
17463: if (&show_course()) {
17464: $output .= &mt('Display courses');
17465: } else {
17466: $output .= &mt('Display roles');
17467: }
17468: $output .= '</a>';
17469: } elsif ($switchserver) {
17470: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
17471: '<br />'.
17472: '<a href="/adm/switchserver?'.$switchserver.'">'.
17473: &mt('Switch Server').
17474: '</a>';
17475: }
17476: $output .= '</p>'.&end_page();
17477: return $output;
17478: }
17479:
17480: =pod
17481:
17482: =item * &needs_coursereinit()
17483:
17484: Determine if course contents stored for user's session needs to be
17485: refreshed, because content has changed since "Big Hash" last tied.
17486:
17487: Check for change is made if time last checked is more than 10 minutes ago
17488: (by default).
17489:
17490: Inputs:
17491:
17492: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17493:
17494: $interval (optional) - Time which may elapse (in s) between last check for content
17495: change in current course. (default: 600 s).
17496:
17497: Returns: an array; first element is:
17498:
17499: =over 4
17500:
17501: 'switch' - if content updates mean user's session
17502: needs to be switched to a server running a newer LON-CAPA version
17503:
17504: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
17505: on current server hosting user's session
17506:
17507: '' - if no action required.
17508:
17509: =back
17510:
17511: If first item element is 'switch':
17512:
17513: second item is $switchwarning - Warning message if no suitable server found to host session.
17514:
17515: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
17516: and current role.
17517:
17518: otherwise: no other elements returned.
17519:
17520: =back
17521:
17522: =cut
17523:
17524: sub needs_coursereinit {
17525: my ($loncaparev,$interval) = @_;
17526: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
17527: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17528: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17529: my $now = time;
17530: if ($interval eq '') {
17531: $interval = 600;
17532: }
17533: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 17534: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1283 raeburn 17535: my $blocked = &blocking_status('reinit',$cnum,$cdom,undef,1);
1.1282 raeburn 17536: if ($blocked) {
17537: return ();
17538: }
1.1207 raeburn 17539: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17540: if ($lastchange > $env{'request.course.tied'}) {
17541: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17542: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17543: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17544: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17545: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17546: $curr_reqd_hash{'internal.releaserequired'}});
17547: my ($switchserver,$switchwarning) =
17548: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17549: $curr_reqd_hash{'internal.releaserequired'});
17550: if ($switchwarning ne '' || $switchserver ne '') {
17551: return ('switch',$switchwarning,$switchserver);
17552: }
17553: }
17554: }
17555: return ('update');
17556: }
17557: }
17558: return ();
17559: }
1.1181 raeburn 17560:
1.1083 raeburn 17561: sub update_content_constraints {
1.1326 raeburn 17562: my ($cdom,$cnum,$chome,$cid,$keeporder) = @_;
1.1083 raeburn 17563: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17564: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 17565: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 17566: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 17567: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 17568: if ($item eq 'resourcetag') {
17569: if ($name eq 'responsetype') {
17570: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17571: }
1.1307 raeburn 17572: } elsif ($item eq 'course') {
17573: if ($name eq 'courserestype') {
17574: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
17575: }
1.1083 raeburn 17576: }
17577: }
17578: my $navmap = Apache::lonnavmaps::navmap->new();
17579: if (defined($navmap)) {
1.1307 raeburn 17580: my (%allresponses,%allcrsrestypes);
17581: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
17582: if ($res->is_tool()) {
17583: if ($allcrsrestypes{'exttool'}) {
17584: $allcrsrestypes{'exttool'} ++;
17585: } else {
17586: $allcrsrestypes{'exttool'} = 1;
17587: }
17588: next;
17589: }
1.1083 raeburn 17590: my %responses = $res->responseTypes();
17591: foreach my $key (keys(%responses)) {
17592: next unless(exists($checkresponsetypes{$key}));
17593: $allresponses{$key} += $responses{$key};
17594: }
17595: }
17596: foreach my $key (keys(%allresponses)) {
17597: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17598: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17599: ($reqdmajor,$reqdminor) = ($major,$minor);
17600: }
17601: }
1.1307 raeburn 17602: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 17603: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 17604: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17605: ($reqdmajor,$reqdminor) = ($major,$minor);
17606: }
17607: }
1.1083 raeburn 17608: undef($navmap);
17609: }
1.1326 raeburn 17610: my (@resources,@order,@resparms,@zombies);
17611: if ($keeporder) {
17612: use LONCAPA::map;
17613: @resources = @LONCAPA::map::resources;
17614: @order = @LONCAPA::map::order;
17615: @resparms = @LONCAPA::map::resparms;
17616: @zombies = @LONCAPA::map::zombies;
17617: }
1.1308 raeburn 17618: my $suppmap = 'supplemental.sequence';
17619: my ($suppcount,$supptools,$errors) = (0,0,0);
17620: ($suppcount,$supptools,$errors) = &recurse_supplemental($cnum,$cdom,$suppmap,
17621: $suppcount,$supptools,$errors);
1.1326 raeburn 17622: if ($keeporder) {
17623: @LONCAPA::map::resources = @resources;
17624: @LONCAPA::map::order = @order;
17625: @LONCAPA::map::resparms = @resparms;
17626: @LONCAPA::map::zombies = @zombies;
17627: }
1.1308 raeburn 17628: if ($supptools) {
17629: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
17630: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17631: ($reqdmajor,$reqdminor) = ($major,$minor);
17632: }
17633: }
1.1083 raeburn 17634: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17635: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17636: }
17637: return;
17638: }
17639:
1.1110 raeburn 17640: sub allmaps_incourse {
17641: my ($cdom,$cnum,$chome,$cid) = @_;
17642: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17643: $cid = $env{'request.course.id'};
17644: $cdom = $env{'course.'.$cid.'.domain'};
17645: $cnum = $env{'course.'.$cid.'.num'};
17646: $chome = $env{'course.'.$cid.'.home'};
17647: }
17648: my %allmaps = ();
17649: my $lastchange =
17650: &Apache::lonnet::get_coursechange($cdom,$cnum);
17651: if ($lastchange > $env{'request.course.tied'}) {
17652: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17653: unless ($ferr) {
1.1326 raeburn 17654: &update_content_constraints($cdom,$cnum,$chome,$cid,1);
1.1110 raeburn 17655: }
17656: }
17657: my $navmap = Apache::lonnavmaps::navmap->new();
17658: if (defined($navmap)) {
17659: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17660: $allmaps{$res->src()} = 1;
17661: }
17662: }
17663: return \%allmaps;
17664: }
17665:
1.1083 raeburn 17666: sub parse_supplemental_title {
17667: my ($title) = @_;
17668:
17669: my ($foldertitle,$renametitle);
17670: if ($title =~ /&&&/) {
17671: $title = &HTML::Entites::decode($title);
17672: }
17673: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17674: $renametitle=$4;
17675: my ($time,$uname,$udom) = ($1,$2,$3);
17676: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17677: my $name = &plainname($uname,$udom);
17678: $name = &HTML::Entities::encode($name,'"<>&\'');
17679: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17680: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17681: $name.': <br />'.$foldertitle;
17682: }
17683: if (wantarray) {
17684: return ($title,$foldertitle,$renametitle);
17685: }
17686: return $title;
17687: }
17688:
1.1143 raeburn 17689: sub recurse_supplemental {
1.1308 raeburn 17690: my ($cnum,$cdom,$suppmap,$numfiles,$numexttools,$errors) = @_;
1.1143 raeburn 17691: if ($suppmap) {
17692: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17693: if ($fatal) {
17694: $errors ++;
17695: } else {
17696: if ($#LONCAPA::map::resources > 0) {
17697: foreach my $res (@LONCAPA::map::resources) {
17698: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17699: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 17700: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1308 raeburn 17701: ($numfiles,$numexttools,$errors) = &recurse_supplemental($cnum,$cdom,$1,
17702: $numfiles,$numexttools,$errors);
1.1143 raeburn 17703: } else {
1.1308 raeburn 17704: if ($src =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
17705: $numexttools ++;
17706: }
1.1143 raeburn 17707: $numfiles ++;
17708: }
17709: }
17710: }
17711: }
17712: }
17713: }
1.1308 raeburn 17714: return ($numfiles,$numexttools,$errors);
1.1143 raeburn 17715: }
17716:
1.1101 raeburn 17717: sub symb_to_docspath {
1.1267 raeburn 17718: my ($symb,$navmapref) = @_;
17719: return unless ($symb && ref($navmapref));
1.1101 raeburn 17720: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17721: if ($resurl=~/\.(sequence|page)$/) {
17722: $mapurl=$resurl;
17723: } elsif ($resurl eq 'adm/navmaps') {
17724: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17725: }
17726: my $mapresobj;
1.1267 raeburn 17727: unless (ref($$navmapref)) {
17728: $$navmapref = Apache::lonnavmaps::navmap->new();
17729: }
17730: if (ref($$navmapref)) {
17731: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 17732: }
17733: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17734: my $type=$2;
17735: my $path;
17736: if (ref($mapresobj)) {
17737: my $pcslist = $mapresobj->map_hierarchy();
17738: if ($pcslist ne '') {
17739: foreach my $pc (split(/,/,$pcslist)) {
17740: next if ($pc <= 1);
1.1267 raeburn 17741: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 17742: if (ref($res)) {
17743: my $thisurl = $res->src();
17744: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17745: my $thistitle = $res->title();
17746: $path .= '&'.
17747: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 17748: &escape($thistitle).
1.1101 raeburn 17749: ':'.$res->randompick().
17750: ':'.$res->randomout().
17751: ':'.$res->encrypted().
17752: ':'.$res->randomorder().
17753: ':'.$res->is_page();
17754: }
17755: }
17756: }
17757: $path =~ s/^\&//;
17758: my $maptitle = $mapresobj->title();
17759: if ($mapurl eq 'default') {
1.1129 raeburn 17760: $maptitle = 'Main Content';
1.1101 raeburn 17761: }
17762: $path .= (($path ne '')? '&' : '').
17763: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17764: &escape($maptitle).
1.1101 raeburn 17765: ':'.$mapresobj->randompick().
17766: ':'.$mapresobj->randomout().
17767: ':'.$mapresobj->encrypted().
17768: ':'.$mapresobj->randomorder().
17769: ':'.$mapresobj->is_page();
17770: } else {
17771: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17772: my $ispage = (($type eq 'page')? 1 : '');
17773: if ($mapurl eq 'default') {
1.1129 raeburn 17774: $maptitle = 'Main Content';
1.1101 raeburn 17775: }
17776: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17777: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 17778: }
17779: unless ($mapurl eq 'default') {
17780: $path = 'default&'.
1.1146 raeburn 17781: &escape('Main Content').
1.1101 raeburn 17782: ':::::&'.$path;
17783: }
17784: return $path;
17785: }
17786:
1.1094 raeburn 17787: sub captcha_display {
1.1327 raeburn 17788: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 17789: my ($output,$error);
1.1234 raeburn 17790: my ($captcha,$pubkey,$privkey,$version) =
1.1327 raeburn 17791: &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 17792: if ($captcha eq 'original') {
1.1094 raeburn 17793: $output = &create_captcha();
17794: unless ($output) {
1.1172 raeburn 17795: $error = 'captcha';
1.1094 raeburn 17796: }
17797: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17798: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 17799: unless ($output) {
1.1172 raeburn 17800: $error = 'recaptcha';
1.1094 raeburn 17801: }
17802: }
1.1234 raeburn 17803: return ($output,$error,$captcha,$version);
1.1094 raeburn 17804: }
17805:
17806: sub captcha_response {
1.1327 raeburn 17807: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 17808: my ($captcha_chk,$captcha_error);
1.1327 raeburn 17809: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 17810: if ($captcha eq 'original') {
1.1094 raeburn 17811: ($captcha_chk,$captcha_error) = &check_captcha();
17812: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17813: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 17814: } else {
17815: $captcha_chk = 1;
17816: }
17817: return ($captcha_chk,$captcha_error);
17818: }
17819:
17820: sub get_captcha_config {
1.1327 raeburn 17821: my ($context,$lonhost,$dom_in_effect) = @_;
1.1234 raeburn 17822: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 17823: my $hostname = &Apache::lonnet::hostname($lonhost);
17824: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17825: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 17826: if ($context eq 'usercreation') {
17827: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17828: if (ref($domconfig{$context}) eq 'HASH') {
17829: $hashtocheck = $domconfig{$context}{'cancreate'};
17830: if (ref($hashtocheck) eq 'HASH') {
17831: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17832: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17833: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17834: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17835: }
17836: if ($privkey && $pubkey) {
17837: $captcha = 'recaptcha';
1.1234 raeburn 17838: $version = $hashtocheck->{'recaptchaversion'};
17839: if ($version ne '2') {
17840: $version = 1;
17841: }
1.1095 raeburn 17842: } else {
17843: $captcha = 'original';
17844: }
17845: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17846: $captcha = 'original';
17847: }
1.1094 raeburn 17848: }
1.1095 raeburn 17849: } else {
17850: $captcha = 'captcha';
17851: }
17852: } elsif ($context eq 'login') {
17853: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17854: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17855: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17856: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 17857: if ($privkey && $pubkey) {
17858: $captcha = 'recaptcha';
1.1234 raeburn 17859: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17860: if ($version ne '2') {
17861: $version = 1;
17862: }
1.1095 raeburn 17863: } else {
17864: $captcha = 'original';
1.1094 raeburn 17865: }
1.1095 raeburn 17866: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17867: $captcha = 'original';
1.1094 raeburn 17868: }
1.1327 raeburn 17869: } elsif ($context eq 'passwords') {
17870: if ($dom_in_effect) {
17871: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
17872: if ($passwdconf{'captcha'} eq 'recaptcha') {
17873: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
17874: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
17875: $privkey = $passwdconf{'recaptchakeys'}{'private'};
17876: }
17877: if ($privkey && $pubkey) {
17878: $captcha = 'recaptcha';
17879: $version = $passwdconf{'recaptchaversion'};
17880: if ($version ne '2') {
17881: $version = 1;
17882: }
17883: } else {
17884: $captcha = 'original';
17885: }
17886: } elsif ($passwdconf{'captcha'} ne 'notused') {
17887: $captcha = 'original';
17888: }
17889: }
17890: }
1.1234 raeburn 17891: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 17892: }
17893:
17894: sub create_captcha {
17895: my %captcha_params = &captcha_settings();
17896: my ($output,$maxtries,$tries) = ('',10,0);
17897: while ($tries < $maxtries) {
17898: $tries ++;
17899: my $captcha = Authen::Captcha->new (
17900: output_folder => $captcha_params{'output_dir'},
17901: data_folder => $captcha_params{'db_dir'},
17902: );
17903: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17904:
17905: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17906: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17907: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 17908: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17909: '<br />'.
17910: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 17911: last;
17912: }
17913: }
1.1323 raeburn 17914: if ($output eq '') {
17915: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
17916: }
1.1094 raeburn 17917: return $output;
17918: }
17919:
17920: sub captcha_settings {
17921: my %captcha_params = (
17922: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17923: www_output_dir => "/captchaspool",
17924: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17925: numchars => '5',
17926: );
17927: return %captcha_params;
17928: }
17929:
17930: sub check_captcha {
17931: my ($captcha_chk,$captcha_error);
17932: my $code = $env{'form.code'};
17933: my $md5sum = $env{'form.crypt'};
17934: my %captcha_params = &captcha_settings();
17935: my $captcha = Authen::Captcha->new(
17936: output_folder => $captcha_params{'output_dir'},
17937: data_folder => $captcha_params{'db_dir'},
17938: );
1.1109 raeburn 17939: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 17940: my %captcha_hash = (
17941: 0 => 'Code not checked (file error)',
17942: -1 => 'Failed: code expired',
17943: -2 => 'Failed: invalid code (not in database)',
17944: -3 => 'Failed: invalid code (code does not match crypt)',
17945: );
17946: if ($captcha_chk != 1) {
17947: $captcha_error = $captcha_hash{$captcha_chk}
17948: }
17949: return ($captcha_chk,$captcha_error);
17950: }
17951:
17952: sub create_recaptcha {
1.1234 raeburn 17953: my ($pubkey,$version) = @_;
17954: if ($version >= 2) {
17955: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17956: } else {
17957: my $use_ssl;
17958: if ($ENV{'SERVER_PORT'} == 443) {
17959: $use_ssl = 1;
17960: }
17961: my $captcha = Captcha::reCAPTCHA->new;
17962: return $captcha->get_options_setter({theme => 'white'})."\n".
17963: $captcha->get_html($pubkey,undef,$use_ssl).
17964: &mt('If the text is hard to read, [_1] will replace them.',
17965: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17966: '<br /><br />';
17967: }
1.1094 raeburn 17968: }
17969:
17970: sub check_recaptcha {
1.1234 raeburn 17971: my ($privkey,$version) = @_;
1.1094 raeburn 17972: my $captcha_chk;
1.1234 raeburn 17973: if ($version >= 2) {
17974: my %info = (
17975: secret => $privkey,
17976: response => $env{'form.g-recaptcha-response'},
17977: remoteip => $ENV{'REMOTE_ADDR'},
17978: );
1.1280 raeburn 17979: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
17980: $request->content(join('&',map {
17981: my $name = escape($_);
17982: "$name=" . ( ref($info{$_}) eq 'ARRAY'
17983: ? join("&$name=", map {escape($_) } @{$info{$_}})
17984: : &escape($info{$_}) );
17985: } keys(%info)));
17986: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 17987: if ($response->is_success) {
17988: my $data = JSON::DWIW->from_json($response->decoded_content);
17989: if (ref($data) eq 'HASH') {
17990: if ($data->{'success'}) {
17991: $captcha_chk = 1;
17992: }
17993: }
17994: }
17995: } else {
17996: my $captcha = Captcha::reCAPTCHA->new;
17997: my $captcha_result =
17998: $captcha->check_answer(
17999: $privkey,
18000: $ENV{'REMOTE_ADDR'},
18001: $env{'form.recaptcha_challenge_field'},
18002: $env{'form.recaptcha_response_field'},
18003: );
18004: if ($captcha_result->{is_valid}) {
18005: $captcha_chk = 1;
18006: }
1.1094 raeburn 18007: }
18008: return $captcha_chk;
18009: }
18010:
1.1174 raeburn 18011: sub emailusername_info {
1.1244 raeburn 18012: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 18013: my %titles = &Apache::lonlocal::texthash (
18014: lastname => 'Last Name',
18015: firstname => 'First Name',
18016: institution => 'School/college/university',
18017: location => "School's city, state/province, country",
18018: web => "School's web address",
18019: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 18020: id => 'Student/Employee ID',
1.1174 raeburn 18021: );
18022: return (\@fields,\%titles);
18023: }
18024:
1.1161 raeburn 18025: sub cleanup_html {
18026: my ($incoming) = @_;
18027: my $outgoing;
18028: if ($incoming ne '') {
18029: $outgoing = $incoming;
18030: $outgoing =~ s/;/;/g;
18031: $outgoing =~ s/\#/#/g;
18032: $outgoing =~ s/\&/&/g;
18033: $outgoing =~ s/</</g;
18034: $outgoing =~ s/>/>/g;
18035: $outgoing =~ s/\(/(/g;
18036: $outgoing =~ s/\)/)/g;
18037: $outgoing =~ s/"/"/g;
18038: $outgoing =~ s/'/'/g;
18039: $outgoing =~ s/\$/$/g;
18040: $outgoing =~ s{/}{/}g;
18041: $outgoing =~ s/=/=/g;
18042: $outgoing =~ s/\\/\/g
18043: }
18044: return $outgoing;
18045: }
18046:
1.1190 musolffc 18047: # Checks for critical messages and returns a redirect url if one exists.
18048: # $interval indicates how often to check for messages.
1.1282 raeburn 18049: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 18050: sub critical_redirect {
1.1282 raeburn 18051: my ($interval,$context) = @_;
1.1190 musolffc 18052: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 18053: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
18054: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18055: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18056: my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
18057: if ($blocked) {
18058: my $checkrole = "cm./$cdom/$cnum";
18059: if ($env{'request.course.sec'} ne '') {
18060: $checkrole .= "/$env{'request.course.sec'}";
18061: }
18062: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
18063: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
18064: return;
18065: }
18066: }
18067: }
1.1190 musolffc 18068: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
18069: $env{'user.name'});
18070: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 18071: my $redirecturl;
1.1190 musolffc 18072: if ($what[0]) {
18073: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
18074: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 18075: my $url=&Apache::lonnet::absolute_url().$redirecturl;
18076: return (1, $url);
1.1190 musolffc 18077: }
1.1191 raeburn 18078: }
18079: }
18080: return ();
1.1190 musolffc 18081: }
18082:
1.1174 raeburn 18083: # Use:
18084: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
18085: #
18086: ##################################################
18087: # password associated functions #
18088: ##################################################
18089: sub des_keys {
18090: # Make a new key for DES encryption.
18091: # Each key has two parts which are returned separately.
18092: # Please note: Each key must be passed through the &hex function
18093: # before it is output to the web browser. The hex versions cannot
18094: # be used to decrypt.
18095: my @hexstr=('0','1','2','3','4','5','6','7',
18096: '8','9','a','b','c','d','e','f');
18097: my $lkey='';
18098: for (0..7) {
18099: $lkey.=$hexstr[rand(15)];
18100: }
18101: my $ukey='';
18102: for (0..7) {
18103: $ukey.=$hexstr[rand(15)];
18104: }
18105: return ($lkey,$ukey);
18106: }
18107:
18108: sub des_decrypt {
18109: my ($key,$cyphertext) = @_;
18110: my $keybin=pack("H16",$key);
18111: my $cypher;
18112: if ($Crypt::DES::VERSION>=2.03) {
18113: $cypher=new Crypt::DES $keybin;
18114: } else {
18115: $cypher=new DES $keybin;
18116: }
1.1233 raeburn 18117: my $plaintext='';
18118: my $cypherlength = length($cyphertext);
18119: my $numchunks = int($cypherlength/32);
18120: for (my $j=0; $j<$numchunks; $j++) {
18121: my $start = $j*32;
18122: my $cypherblock = substr($cyphertext,$start,32);
18123: my $chunk =
18124: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
18125: $chunk .=
18126: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
18127: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
18128: $plaintext .= $chunk;
18129: }
1.1174 raeburn 18130: return $plaintext;
18131: }
18132:
1.1309 raeburn 18133: sub make_short_symbs {
18134: my ($cdom,$cnum,$navmap) = @_;
18135: return unless (ref($navmap));
18136: my ($numnew,@errors);
18137: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
18138: if (@toshorten) {
18139: my (%maps,%resources,%titles);
18140: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
18141: 'shorturls',$cdom,$cnum);
18142: my %tocreate;
18143: if (keys(%resources)) {
18144: foreach my $item (sort {$a <=> $b} (@toshorten)) {
18145: my $symb = $resources{$item};
18146: if ($symb) {
18147: $tocreate{$cnum.'&'.$symb} = 1;
18148: }
18149: }
18150: }
18151: if (keys(%tocreate)) {
18152: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
18153: my $su = Short::URL->new(no_vowels => 1);
18154: my $init = '';
18155: my (%newunique,%addcourse,%courseonly,%failed);
18156: # get lock on tiny db
18157: my $now = time;
18158: my $lockhash = {
18159: "lock\0$now" => $env{'user.name'}.
18160: ':'.$env{'user.domain'},
18161: };
18162: my $tries = 0;
18163: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18164: my ($code,$error);
18165: while (($gotlock ne 'ok') && ($tries<3)) {
18166: $tries ++;
18167: sleep 1;
1.1319 raeburn 18168: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 18169: }
18170: if ($gotlock eq 'ok') {
18171: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
18172: \%addcourse,\%courseonly,\%failed);
18173: if (keys(%failed)) {
18174: my $numfailed = scalar(keys(%failed));
18175: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
18176: }
18177: if (keys(%newunique)) {
18178: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
18179: if ($putres eq 'ok') {
18180: $numnew = scalar(keys(%newunique));
18181: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
18182: unless ($newputres eq 'ok') {
18183: push(@errors,&mt('error: could not store course look-up of short URLs'));
18184: }
18185: } else {
18186: push(@errors,&mt('error: could not store unique six character URLs'));
18187: }
18188: }
18189: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
18190: unless ($dellockres eq 'ok') {
18191: push(@errors,&mt('error: could not release lockfile'));
18192: }
18193: } else {
18194: push(@errors,&mt('error: could not obtain lockfile'));
18195: }
18196: if (keys(%courseonly)) {
18197: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
18198: if ($result ne 'ok') {
18199: push(@errors,&mt('error: could not update course look-up of short URLs'));
18200: }
18201: }
18202: }
18203: }
18204: return ($numnew,\@errors);
18205: }
18206:
18207: sub shorten_symbs {
18208: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
18209: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
18210: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
18211: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
18212: my (%possibles,%collisions);
18213: foreach my $key (keys(%{$tocreate})) {
18214: my $num = String::CRC32::crc32($key);
18215: my $tiny = $su->encode($num,$init);
18216: if ($tiny) {
18217: $possibles{$tiny} = $key;
18218: }
18219: }
18220: if (!$init) {
18221: $init = 1;
18222: } else {
18223: $init ++;
18224: }
18225: if (keys(%possibles)) {
18226: my @posstiny = keys(%possibles);
18227: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
18228: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
18229: if (keys(%currtiny)) {
18230: foreach my $key (keys(%currtiny)) {
18231: next if ($currtiny{$key} eq '');
18232: if ($currtiny{$key} eq $possibles{$key}) {
18233: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
18234: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18235: $courseonly->{$tsymb} = $key;
18236: }
18237: } else {
18238: $collisions{$possibles{$key}} = 1;
18239: }
18240: delete($possibles{$key});
18241: }
18242: }
18243: foreach my $key (keys(%possibles)) {
18244: $newunique->{$key} = $possibles{$key};
18245: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
18246: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18247: $addcourse->{$tsymb} = $key;
18248: }
18249: }
18250: }
18251: if (keys(%collisions)) {
18252: if ($init <5) {
18253: if (!$init) {
18254: $init = 1;
18255: } else {
18256: $init ++;
18257: }
18258: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
18259: $newunique,$addcourse,$courseonly,$failed);
18260: } else {
18261: foreach my $key (keys(%collisions)) {
18262: $failed->{$key} = 1;
18263: }
18264: }
18265: }
18266: return $init;
18267: }
18268:
1.1328 raeburn 18269: sub is_nonframeable {
1.1329 raeburn 18270: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
18271: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
1.1330 raeburn 18272: return if (($remprotocol eq '') || ($remhost eq ''));
1.1329 raeburn 18273:
18274: $remprotocol = lc($remprotocol);
18275: $remhost = lc($remhost);
18276: my $remport = 80;
18277: if ($remprotocol eq 'https') {
18278: $remport = 443;
18279: }
1.1330 raeburn 18280: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
1.1329 raeburn 18281: if ($cached) {
18282: unless ($nocache) {
18283: if ($result) {
18284: return 1;
18285: } else {
18286: return 0;
18287: }
18288: }
18289: }
1.1328 raeburn 18290: my $uselink;
18291: my $request = new HTTP::Request('HEAD',$url);
18292: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
18293: if ($response->is_success()) {
18294: my $secpolicy = lc($response->header('content-security-policy'));
18295: my $xframeop = lc($response->header('x-frame-options'));
18296: $secpolicy =~ s/^\s+|\s+$//g;
18297: $xframeop =~ s/^\s+|\s+$//g;
18298: if (($secpolicy ne '') || ($xframeop ne '')) {
1.1329 raeburn 18299: my $remotehost = $remprotocol.'://'.$remhost;
1.1328 raeburn 18300: my ($origin,$protocol,$port);
18301: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
18302: $port = $ENV{'SERVER_PORT'};
18303: } else {
18304: $port = 80;
18305: }
18306: if ($absolute eq '') {
18307: $protocol = 'http:';
18308: if ($port == 443) {
18309: $protocol = 'https:';
18310: }
18311: $origin = $protocol.'//'.lc($hostname);
18312: } else {
18313: $origin = lc($absolute);
18314: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
18315: }
18316: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
18317: my $framepolicy = $1;
18318: $framepolicy =~ s/^\s+|\s+$//g;
18319: my @policies = split(/\s+/,$framepolicy);
18320: if (@policies) {
18321: if (grep(/^\Q'none'\E$/,@policies)) {
18322: $uselink = 1;
18323: } else {
18324: $uselink = 1;
18325: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
18326: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
18327: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
18328: undef($uselink);
18329: }
18330: if ($uselink) {
18331: if (grep(/^\Q'self'\E$/,@policies)) {
18332: if (($origin ne '') && ($remotehost eq $origin)) {
18333: undef($uselink);
18334: }
18335: }
18336: }
18337: if ($uselink) {
18338: my @possok;
18339: if ($ip ne '') {
18340: push(@possok,$ip);
18341: }
18342: my $hoststr = '';
18343: foreach my $part (reverse(split(/\./,$hostname))) {
18344: if ($hoststr eq '') {
18345: $hoststr = $part;
18346: } else {
18347: $hoststr = "$part.$hoststr";
18348: }
18349: if ($hoststr eq $hostname) {
18350: push(@possok,$hostname);
18351: } else {
18352: push(@possok,"*.$hoststr");
18353: }
18354: }
18355: if (@possok) {
18356: foreach my $poss (@possok) {
18357: last if (!$uselink);
18358: foreach my $policy (@policies) {
18359: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
18360: undef($uselink);
18361: last;
18362: }
18363: }
18364: }
18365: }
18366: }
18367: }
18368: }
18369: } elsif ($xframeop ne '') {
18370: $uselink = 1;
18371: my @policies = split(/\s*,\s*/,$xframeop);
18372: if (@policies) {
18373: unless (grep(/^deny$/,@policies)) {
18374: if ($origin ne '') {
18375: if (grep(/^sameorigin$/,@policies)) {
18376: if ($remotehost eq $origin) {
18377: undef($uselink);
18378: }
18379: }
18380: if ($uselink) {
18381: foreach my $policy (@policies) {
18382: if ($policy =~ /^allow-from\s*(.+)$/) {
18383: my $allowfrom = $1;
18384: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
18385: undef($uselink);
18386: last;
18387: }
18388: }
18389: }
18390: }
18391: }
18392: }
18393: }
18394: }
18395: }
18396: }
1.1329 raeburn 18397: if ($nocache) {
18398: if ($cached) {
18399: my $devalidate;
18400: if ($uselink && !$result) {
18401: $devalidate = 1;
18402: } elsif (!$uselink && $result) {
18403: $devalidate = 1;
18404: }
18405: if ($devalidate) {
18406: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
18407: }
18408: }
18409: } else {
18410: if ($uselink) {
18411: $result = 1;
18412: } else {
18413: $result = 0;
18414: }
18415: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
18416: }
1.1328 raeburn 18417: return $uselink;
18418: }
18419:
1.112 bowersj2 18420: 1;
18421: __END__;
1.41 ng 18422:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>