Annotation of loncom/interface/loncommon.pm, revision 1.1333
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1333 ! raeburn 4: # $Id: loncommon.pm,v 1.1332 2019/05/11 21:34:01 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.779 bisitz 7261: .LC_answer_unknown {
7262: background: orange;
7263: color: black;
1.795 www 7264: padding: 6px;
1.777 tempelho 7265: }
1.795 www 7266:
1.529 albertel 7267: span.LC_prior_numerical,
7268: span.LC_prior_string,
7269: span.LC_prior_custom,
7270: span.LC_prior_reaction,
7271: span.LC_prior_math {
1.925 bisitz 7272: font-family: $mono;
1.523 albertel 7273: white-space: pre;
7274: }
7275:
1.525 albertel 7276: span.LC_prior_string {
1.925 bisitz 7277: font-family: $mono;
1.525 albertel 7278: white-space: pre;
7279: }
7280:
1.523 albertel 7281: table.LC_prior_option {
7282: width: 100%;
7283: border-collapse: collapse;
7284: }
1.795 www 7285:
1.911 bisitz 7286: table.LC_prior_rank,
1.795 www 7287: table.LC_prior_match {
1.528 albertel 7288: border-collapse: collapse;
7289: }
1.795 www 7290:
1.528 albertel 7291: table.LC_prior_option tr td,
7292: table.LC_prior_rank tr td,
7293: table.LC_prior_match tr td {
1.524 albertel 7294: border: 1px solid #000000;
1.515 albertel 7295: }
7296:
1.855 bisitz 7297: .LC_nobreak {
1.544 albertel 7298: white-space: nowrap;
1.519 raeburn 7299: }
7300:
1.576 raeburn 7301: span.LC_cusr_emph {
7302: font-style: italic;
7303: }
7304:
1.633 raeburn 7305: span.LC_cusr_subheading {
7306: font-weight: normal;
7307: font-size: 85%;
7308: }
7309:
1.861 bisitz 7310: div.LC_docs_entry_move {
1.859 bisitz 7311: border: 1px solid #BBBBBB;
1.545 albertel 7312: background: #DDDDDD;
1.861 bisitz 7313: width: 22px;
1.859 bisitz 7314: padding: 1px;
7315: margin: 0;
1.545 albertel 7316: }
7317:
1.861 bisitz 7318: table.LC_data_table tr > td.LC_docs_entry_commands,
7319: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7320: font-size: x-small;
7321: }
1.795 www 7322:
1.861 bisitz 7323: .LC_docs_entry_parameter {
7324: white-space: nowrap;
7325: }
7326:
1.544 albertel 7327: .LC_docs_copy {
1.545 albertel 7328: color: #000099;
1.544 albertel 7329: }
1.795 www 7330:
1.544 albertel 7331: .LC_docs_cut {
1.545 albertel 7332: color: #550044;
1.544 albertel 7333: }
1.795 www 7334:
1.544 albertel 7335: .LC_docs_rename {
1.545 albertel 7336: color: #009900;
1.544 albertel 7337: }
1.795 www 7338:
1.544 albertel 7339: .LC_docs_remove {
1.545 albertel 7340: color: #990000;
7341: }
7342:
1.1284 raeburn 7343: .LC_docs_alias {
7344: color: #440055;
7345: }
7346:
1.1286 raeburn 7347: .LC_domprefs_email,
1.1284 raeburn 7348: .LC_docs_alias_name,
1.547 albertel 7349: .LC_docs_reinit_warn,
7350: .LC_docs_ext_edit {
7351: font-size: x-small;
7352: }
7353:
1.545 albertel 7354: table.LC_docs_adddocs td,
7355: table.LC_docs_adddocs th {
7356: border: 1px solid #BBBBBB;
7357: padding: 4px;
7358: background: #DDDDDD;
1.543 albertel 7359: }
7360:
1.584 albertel 7361: table.LC_sty_begin {
7362: background: #BBFFBB;
7363: }
1.795 www 7364:
1.584 albertel 7365: table.LC_sty_end {
7366: background: #FFBBBB;
7367: }
7368:
1.589 raeburn 7369: table.LC_double_column {
1.803 bisitz 7370: border-width: 0;
1.589 raeburn 7371: border-collapse: collapse;
7372: width: 100%;
7373: padding: 2px;
7374: }
7375:
7376: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7377: top: 2px;
1.589 raeburn 7378: left: 2px;
7379: width: 47%;
7380: vertical-align: top;
7381: }
7382:
7383: table.LC_double_column tr td.LC_right_col {
7384: top: 2px;
1.779 bisitz 7385: right: 2px;
1.589 raeburn 7386: width: 47%;
7387: vertical-align: top;
7388: }
7389:
1.591 raeburn 7390: div.LC_left_float {
7391: float: left;
7392: padding-right: 5%;
1.597 albertel 7393: padding-bottom: 4px;
1.591 raeburn 7394: }
7395:
7396: div.LC_clear_float_header {
1.597 albertel 7397: padding-bottom: 2px;
1.591 raeburn 7398: }
7399:
7400: div.LC_clear_float_footer {
1.597 albertel 7401: padding-top: 10px;
1.591 raeburn 7402: clear: both;
7403: }
7404:
1.597 albertel 7405: div.LC_grade_show_user {
1.941 bisitz 7406: /* border-left: 5px solid $sidebg; */
7407: border-top: 5px solid #000000;
7408: margin: 50px 0 0 0;
1.936 bisitz 7409: padding: 15px 0 5px 10px;
1.597 albertel 7410: }
1.795 www 7411:
1.936 bisitz 7412: div.LC_grade_show_user_odd_row {
1.941 bisitz 7413: /* border-left: 5px solid #000000; */
7414: }
7415:
7416: div.LC_grade_show_user div.LC_Box {
7417: margin-right: 50px;
1.597 albertel 7418: }
7419:
7420: div.LC_grade_submissions,
7421: div.LC_grade_message_center,
1.936 bisitz 7422: div.LC_grade_info_links {
1.597 albertel 7423: margin: 5px;
7424: width: 99%;
7425: background: #FFFFFF;
7426: }
1.795 www 7427:
1.597 albertel 7428: div.LC_grade_submissions_header,
1.936 bisitz 7429: div.LC_grade_message_center_header {
1.705 tempelho 7430: font-weight: bold;
7431: font-size: large;
1.597 albertel 7432: }
1.795 www 7433:
1.597 albertel 7434: div.LC_grade_submissions_body,
1.936 bisitz 7435: div.LC_grade_message_center_body {
1.597 albertel 7436: border: 1px solid black;
7437: width: 99%;
7438: background: #FFFFFF;
7439: }
1.795 www 7440:
1.613 albertel 7441: table.LC_scantron_action {
7442: width: 100%;
7443: }
1.795 www 7444:
1.613 albertel 7445: table.LC_scantron_action tr th {
1.698 harmsja 7446: font-weight:bold;
7447: font-style:normal;
1.613 albertel 7448: }
1.795 www 7449:
1.779 bisitz 7450: .LC_edit_problem_header,
1.614 albertel 7451: div.LC_edit_problem_footer {
1.705 tempelho 7452: font-weight: normal;
7453: font-size: medium;
1.602 albertel 7454: margin: 2px;
1.1060 bisitz 7455: background-color: $sidebg;
1.600 albertel 7456: }
1.795 www 7457:
1.600 albertel 7458: div.LC_edit_problem_header,
1.602 albertel 7459: div.LC_edit_problem_header div,
1.614 albertel 7460: div.LC_edit_problem_footer,
7461: div.LC_edit_problem_footer div,
1.602 albertel 7462: div.LC_edit_problem_editxml_header,
7463: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7464: z-index: 100;
1.600 albertel 7465: }
1.795 www 7466:
1.600 albertel 7467: div.LC_edit_problem_header_title {
1.705 tempelho 7468: font-weight: bold;
7469: font-size: larger;
1.602 albertel 7470: background: $tabbg;
7471: padding: 3px;
1.1060 bisitz 7472: margin: 0 0 5px 0;
1.602 albertel 7473: }
1.795 www 7474:
1.602 albertel 7475: table.LC_edit_problem_header_title {
7476: width: 100%;
1.600 albertel 7477: background: $tabbg;
1.602 albertel 7478: }
7479:
1.1205 golterma 7480: div.LC_edit_actionbar {
7481: background-color: $sidebg;
1.1218 droeschl 7482: margin: 0;
7483: padding: 0;
7484: line-height: 200%;
1.602 albertel 7485: }
1.795 www 7486:
1.1218 droeschl 7487: div.LC_edit_actionbar div{
7488: padding: 0;
7489: margin: 0;
7490: display: inline-block;
1.600 albertel 7491: }
1.795 www 7492:
1.1124 bisitz 7493: .LC_edit_opt {
7494: padding-left: 1em;
7495: white-space: nowrap;
7496: }
7497:
1.1152 golterma 7498: .LC_edit_problem_latexhelper{
7499: text-align: right;
7500: }
7501:
7502: #LC_edit_problem_colorful div{
7503: margin-left: 40px;
7504: }
7505:
1.1205 golterma 7506: #LC_edit_problem_codemirror div{
7507: margin-left: 0px;
7508: }
7509:
1.911 bisitz 7510: img.stift {
1.803 bisitz 7511: border-width: 0;
7512: vertical-align: middle;
1.677 riegler 7513: }
1.680 riegler 7514:
1.923 bisitz 7515: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7516: vertical-align: top;
1.777 tempelho 7517: }
1.795 www 7518:
1.716 raeburn 7519: div.LC_createcourse {
1.911 bisitz 7520: margin: 10px 10px 10px 10px;
1.716 raeburn 7521: }
7522:
1.917 raeburn 7523: .LC_dccid {
1.1130 raeburn 7524: float: right;
1.917 raeburn 7525: margin: 0.2em 0 0 0;
7526: padding: 0;
7527: font-size: 90%;
7528: display:none;
7529: }
7530:
1.897 wenzelju 7531: ol.LC_primary_menu a:hover,
1.721 harmsja 7532: ol#LC_MenuBreadcrumbs a:hover,
7533: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7534: ul#LC_secondary_menu a:hover,
1.721 harmsja 7535: .LC_FormSectionClearButton input:hover
1.795 www 7536: ul.LC_TabContent li:hover a {
1.952 onken 7537: color:$button_hover;
1.911 bisitz 7538: text-decoration:none;
1.693 droeschl 7539: }
7540:
1.779 bisitz 7541: h1 {
1.911 bisitz 7542: padding: 0;
7543: line-height:130%;
1.693 droeschl 7544: }
1.698 harmsja 7545:
1.911 bisitz 7546: h2,
7547: h3,
7548: h4,
7549: h5,
7550: h6 {
7551: margin: 5px 0 5px 0;
7552: padding: 0;
7553: line-height:130%;
1.693 droeschl 7554: }
1.795 www 7555:
7556: .LC_hcell {
1.911 bisitz 7557: padding:3px 15px 3px 15px;
7558: margin: 0;
7559: background-color:$tabbg;
7560: color:$fontmenu;
7561: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7562: }
1.795 www 7563:
1.840 bisitz 7564: .LC_Box > .LC_hcell {
1.911 bisitz 7565: margin: 0 -10px 10px -10px;
1.835 bisitz 7566: }
7567:
1.721 harmsja 7568: .LC_noBorder {
1.911 bisitz 7569: border: 0;
1.698 harmsja 7570: }
1.693 droeschl 7571:
1.721 harmsja 7572: .LC_FormSectionClearButton input {
1.911 bisitz 7573: background-color:transparent;
7574: border: none;
7575: cursor:pointer;
7576: text-decoration:underline;
1.693 droeschl 7577: }
1.763 bisitz 7578:
7579: .LC_help_open_topic {
1.911 bisitz 7580: color: #FFFFFF;
7581: background-color: #EEEEFF;
7582: margin: 1px;
7583: padding: 4px;
7584: border: 1px solid #000033;
7585: white-space: nowrap;
7586: /* vertical-align: middle; */
1.759 neumanie 7587: }
1.693 droeschl 7588:
1.911 bisitz 7589: dl,
7590: ul,
7591: div,
7592: fieldset {
7593: margin: 10px 10px 10px 0;
7594: /* overflow: hidden; */
1.693 droeschl 7595: }
1.795 www 7596:
1.1211 raeburn 7597: article.geogebraweb div {
7598: margin: 0;
7599: }
7600:
1.838 bisitz 7601: fieldset > legend {
1.911 bisitz 7602: font-weight: bold;
7603: padding: 0 5px 0 5px;
1.838 bisitz 7604: }
7605:
1.813 bisitz 7606: #LC_nav_bar {
1.911 bisitz 7607: float: left;
1.995 raeburn 7608: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7609: margin: 0 0 2px 0;
1.807 droeschl 7610: }
7611:
1.916 droeschl 7612: #LC_realm {
7613: margin: 0.2em 0 0 0;
7614: padding: 0;
7615: font-weight: bold;
7616: text-align: center;
1.995 raeburn 7617: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7618: }
7619:
1.911 bisitz 7620: #LC_nav_bar em {
7621: font-weight: bold;
7622: font-style: normal;
1.807 droeschl 7623: }
7624:
1.897 wenzelju 7625: ol.LC_primary_menu {
1.934 droeschl 7626: margin: 0;
1.1076 raeburn 7627: padding: 0;
1.807 droeschl 7628: }
7629:
1.852 droeschl 7630: ol#LC_PathBreadcrumbs {
1.911 bisitz 7631: margin: 0;
1.693 droeschl 7632: }
7633:
1.897 wenzelju 7634: ol.LC_primary_menu li {
1.1076 raeburn 7635: color: RGB(80, 80, 80);
7636: vertical-align: middle;
7637: text-align: left;
7638: list-style: none;
1.1205 golterma 7639: position: relative;
1.1076 raeburn 7640: float: left;
1.1205 golterma 7641: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7642: line-height: 1.5em;
1.1076 raeburn 7643: }
7644:
1.1205 golterma 7645: ol.LC_primary_menu li a,
7646: ol.LC_primary_menu li p {
1.1076 raeburn 7647: display: block;
7648: margin: 0;
7649: padding: 0 5px 0 10px;
7650: text-decoration: none;
7651: }
7652:
1.1205 golterma 7653: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7654: display: inline-block;
7655: width: 95%;
7656: text-align: left;
7657: }
7658:
7659: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7660: display: inline-block;
7661: width: 5%;
7662: float: right;
7663: text-align: right;
7664: font-size: 70%;
7665: }
7666:
7667: ol.LC_primary_menu ul {
1.1076 raeburn 7668: display: none;
1.1205 golterma 7669: width: 15em;
1.1076 raeburn 7670: background-color: $data_table_light;
1.1205 golterma 7671: position: absolute;
7672: top: 100%;
1.1076 raeburn 7673: }
7674:
1.1205 golterma 7675: ol.LC_primary_menu ul ul {
7676: left: 100%;
7677: top: 0;
7678: }
7679:
7680: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7681: display: block;
7682: position: absolute;
7683: margin: 0;
7684: padding: 0;
1.1078 raeburn 7685: z-index: 2;
1.1076 raeburn 7686: }
7687:
7688: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7689: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7690: font-size: 90%;
1.911 bisitz 7691: vertical-align: top;
1.1076 raeburn 7692: float: none;
1.1079 raeburn 7693: border-left: 1px solid black;
7694: border-right: 1px solid black;
1.1205 golterma 7695: /* A dark bottom border to visualize different menu options;
7696: overwritten in the create_submenu routine for the last border-bottom of the menu */
7697: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7698: }
7699:
1.1205 golterma 7700: ol.LC_primary_menu li li p:hover {
7701: color:$button_hover;
7702: text-decoration:none;
7703: background-color:$data_table_dark;
1.1076 raeburn 7704: }
7705:
7706: ol.LC_primary_menu li li a:hover {
7707: color:$button_hover;
7708: background-color:$data_table_dark;
1.693 droeschl 7709: }
7710:
1.1205 golterma 7711: /* Font-size equal to the size of the predecessors*/
7712: ol.LC_primary_menu li:hover li li {
7713: font-size: 100%;
7714: }
7715:
1.897 wenzelju 7716: ol.LC_primary_menu li img {
1.911 bisitz 7717: vertical-align: bottom;
1.934 droeschl 7718: height: 1.1em;
1.1077 raeburn 7719: margin: 0.2em 0 0 0;
1.693 droeschl 7720: }
7721:
1.897 wenzelju 7722: ol.LC_primary_menu a {
1.911 bisitz 7723: color: RGB(80, 80, 80);
7724: text-decoration: none;
1.693 droeschl 7725: }
1.795 www 7726:
1.949 droeschl 7727: ol.LC_primary_menu a.LC_new_message {
7728: font-weight:bold;
7729: color: darkred;
7730: }
7731:
1.975 raeburn 7732: ol.LC_docs_parameters {
7733: margin-left: 0;
7734: padding: 0;
7735: list-style: none;
7736: }
7737:
7738: ol.LC_docs_parameters li {
7739: margin: 0;
7740: padding-right: 20px;
7741: display: inline;
7742: }
7743:
1.976 raeburn 7744: ol.LC_docs_parameters li:before {
7745: content: "\\002022 \\0020";
7746: }
7747:
7748: li.LC_docs_parameters_title {
7749: font-weight: bold;
7750: }
7751:
7752: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7753: content: "";
7754: }
7755:
1.897 wenzelju 7756: ul#LC_secondary_menu {
1.1107 raeburn 7757: clear: right;
1.911 bisitz 7758: color: $fontmenu;
7759: background: $tabbg;
7760: list-style: none;
7761: padding: 0;
7762: margin: 0;
7763: width: 100%;
1.995 raeburn 7764: text-align: left;
1.1107 raeburn 7765: float: left;
1.808 droeschl 7766: }
7767:
1.897 wenzelju 7768: ul#LC_secondary_menu li {
1.911 bisitz 7769: font-weight: bold;
7770: line-height: 1.8em;
1.1107 raeburn 7771: border-right: 1px solid black;
7772: float: left;
7773: }
7774:
7775: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7776: background-color: $data_table_light;
7777: }
7778:
7779: ul#LC_secondary_menu li a {
1.911 bisitz 7780: padding: 0 0.8em;
1.1107 raeburn 7781: }
7782:
7783: ul#LC_secondary_menu li ul {
7784: display: none;
7785: }
7786:
7787: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7788: display: block;
7789: position: absolute;
7790: margin: 0;
7791: padding: 0;
7792: list-style:none;
7793: float: none;
7794: background-color: $data_table_light;
7795: z-index: 2;
7796: margin-left: -1px;
7797: }
7798:
7799: ul#LC_secondary_menu li ul li {
7800: font-size: 90%;
7801: vertical-align: top;
7802: border-left: 1px solid black;
1.911 bisitz 7803: border-right: 1px solid black;
1.1119 raeburn 7804: background-color: $data_table_light;
1.1107 raeburn 7805: list-style:none;
7806: float: none;
7807: }
7808:
7809: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7810: background-color: $data_table_dark;
1.807 droeschl 7811: }
7812:
1.847 tempelho 7813: ul.LC_TabContent {
1.911 bisitz 7814: display:block;
7815: background: $sidebg;
7816: border-bottom: solid 1px $lg_border_color;
7817: list-style:none;
1.1020 raeburn 7818: margin: -1px -10px 0 -10px;
1.911 bisitz 7819: padding: 0;
1.693 droeschl 7820: }
7821:
1.795 www 7822: ul.LC_TabContent li,
7823: ul.LC_TabContentBigger li {
1.911 bisitz 7824: float:left;
1.741 harmsja 7825: }
1.795 www 7826:
1.897 wenzelju 7827: ul#LC_secondary_menu li a {
1.911 bisitz 7828: color: $fontmenu;
7829: text-decoration: none;
1.693 droeschl 7830: }
1.795 www 7831:
1.721 harmsja 7832: ul.LC_TabContent {
1.952 onken 7833: min-height:20px;
1.721 harmsja 7834: }
1.795 www 7835:
7836: ul.LC_TabContent li {
1.911 bisitz 7837: vertical-align:middle;
1.959 onken 7838: padding: 0 16px 0 10px;
1.911 bisitz 7839: background-color:$tabbg;
7840: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7841: border-left: solid 1px $font;
1.721 harmsja 7842: }
1.795 www 7843:
1.847 tempelho 7844: ul.LC_TabContent .right {
1.911 bisitz 7845: float:right;
1.847 tempelho 7846: }
7847:
1.911 bisitz 7848: ul.LC_TabContent li a,
7849: ul.LC_TabContent li {
7850: color:rgb(47,47,47);
7851: text-decoration:none;
7852: font-size:95%;
7853: font-weight:bold;
1.952 onken 7854: min-height:20px;
7855: }
7856:
1.959 onken 7857: ul.LC_TabContent li a:hover,
7858: ul.LC_TabContent li a:focus {
1.952 onken 7859: color: $button_hover;
1.959 onken 7860: background:none;
7861: outline:none;
1.952 onken 7862: }
7863:
7864: ul.LC_TabContent li:hover {
7865: color: $button_hover;
7866: cursor:pointer;
1.721 harmsja 7867: }
1.795 www 7868:
1.911 bisitz 7869: ul.LC_TabContent li.active {
1.952 onken 7870: color: $font;
1.911 bisitz 7871: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7872: border-bottom:solid 1px #FFFFFF;
7873: cursor: default;
1.744 ehlerst 7874: }
1.795 www 7875:
1.959 onken 7876: ul.LC_TabContent li.active a {
7877: color:$font;
7878: background:#FFFFFF;
7879: outline: none;
7880: }
1.1047 raeburn 7881:
7882: ul.LC_TabContent li.goback {
7883: float: left;
7884: border-left: none;
7885: }
7886:
1.870 tempelho 7887: #maincoursedoc {
1.911 bisitz 7888: clear:both;
1.870 tempelho 7889: }
7890:
7891: ul.LC_TabContentBigger {
1.911 bisitz 7892: display:block;
7893: list-style:none;
7894: padding: 0;
1.870 tempelho 7895: }
7896:
1.795 www 7897: ul.LC_TabContentBigger li {
1.911 bisitz 7898: vertical-align:bottom;
7899: height: 30px;
7900: font-size:110%;
7901: font-weight:bold;
7902: color: #737373;
1.841 tempelho 7903: }
7904:
1.957 onken 7905: ul.LC_TabContentBigger li.active {
7906: position: relative;
7907: top: 1px;
7908: }
7909:
1.870 tempelho 7910: ul.LC_TabContentBigger li a {
1.911 bisitz 7911: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7912: height: 30px;
7913: line-height: 30px;
7914: text-align: center;
7915: display: block;
7916: text-decoration: none;
1.958 onken 7917: outline: none;
1.741 harmsja 7918: }
1.795 www 7919:
1.870 tempelho 7920: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7921: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7922: color:$font;
1.744 ehlerst 7923: }
1.795 www 7924:
1.870 tempelho 7925: ul.LC_TabContentBigger li b {
1.911 bisitz 7926: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7927: display: block;
7928: float: left;
7929: padding: 0 30px;
1.957 onken 7930: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7931: }
7932:
1.956 onken 7933: ul.LC_TabContentBigger li:hover b {
7934: color:$button_hover;
7935: }
7936:
1.870 tempelho 7937: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7938: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7939: color:$font;
1.957 onken 7940: border: 0;
1.741 harmsja 7941: }
1.693 droeschl 7942:
1.870 tempelho 7943:
1.862 bisitz 7944: ul.LC_CourseBreadcrumbs {
7945: background: $sidebg;
1.1020 raeburn 7946: height: 2em;
1.862 bisitz 7947: padding-left: 10px;
1.1020 raeburn 7948: margin: 0;
1.862 bisitz 7949: list-style-position: inside;
7950: }
7951:
1.911 bisitz 7952: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7953: ol#LC_PathBreadcrumbs {
1.911 bisitz 7954: padding-left: 10px;
7955: margin: 0;
1.933 droeschl 7956: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7957: }
7958:
1.911 bisitz 7959: ol#LC_MenuBreadcrumbs li,
7960: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7961: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7962: display: inline;
1.933 droeschl 7963: white-space: normal;
1.693 droeschl 7964: }
7965:
1.823 bisitz 7966: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7967: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7968: text-decoration: none;
7969: font-size:90%;
1.693 droeschl 7970: }
1.795 www 7971:
1.969 droeschl 7972: ol#LC_MenuBreadcrumbs h1 {
7973: display: inline;
7974: font-size: 90%;
7975: line-height: 2.5em;
7976: margin: 0;
7977: padding: 0;
7978: }
7979:
1.795 www 7980: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7981: text-decoration:none;
7982: font-size:100%;
7983: font-weight:bold;
1.693 droeschl 7984: }
1.795 www 7985:
1.840 bisitz 7986: .LC_Box {
1.911 bisitz 7987: border: solid 1px $lg_border_color;
7988: padding: 0 10px 10px 10px;
1.746 neumanie 7989: }
1.795 www 7990:
1.1020 raeburn 7991: .LC_DocsBox {
7992: border: solid 1px $lg_border_color;
7993: padding: 0 0 10px 10px;
7994: }
7995:
1.795 www 7996: .LC_AboutMe_Image {
1.911 bisitz 7997: float:left;
7998: margin-right:10px;
1.747 neumanie 7999: }
1.795 www 8000:
8001: .LC_Clear_AboutMe_Image {
1.911 bisitz 8002: clear:left;
1.747 neumanie 8003: }
1.795 www 8004:
1.721 harmsja 8005: dl.LC_ListStyleClean dt {
1.911 bisitz 8006: padding-right: 5px;
8007: display: table-header-group;
1.693 droeschl 8008: }
8009:
1.721 harmsja 8010: dl.LC_ListStyleClean dd {
1.911 bisitz 8011: display: table-row;
1.693 droeschl 8012: }
8013:
1.721 harmsja 8014: .LC_ListStyleClean,
8015: .LC_ListStyleSimple,
8016: .LC_ListStyleNormal,
1.795 www 8017: .LC_ListStyleSpecial {
1.911 bisitz 8018: /* display:block; */
8019: list-style-position: inside;
8020: list-style-type: none;
8021: overflow: hidden;
8022: padding: 0;
1.693 droeschl 8023: }
8024:
1.721 harmsja 8025: .LC_ListStyleSimple li,
8026: .LC_ListStyleSimple dd,
8027: .LC_ListStyleNormal li,
8028: .LC_ListStyleNormal dd,
8029: .LC_ListStyleSpecial li,
1.795 www 8030: .LC_ListStyleSpecial dd {
1.911 bisitz 8031: margin: 0;
8032: padding: 5px 5px 5px 10px;
8033: clear: both;
1.693 droeschl 8034: }
8035:
1.721 harmsja 8036: .LC_ListStyleClean li,
8037: .LC_ListStyleClean dd {
1.911 bisitz 8038: padding-top: 0;
8039: padding-bottom: 0;
1.693 droeschl 8040: }
8041:
1.721 harmsja 8042: .LC_ListStyleSimple dd,
1.795 www 8043: .LC_ListStyleSimple li {
1.911 bisitz 8044: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8045: }
8046:
1.721 harmsja 8047: .LC_ListStyleSpecial li,
8048: .LC_ListStyleSpecial dd {
1.911 bisitz 8049: list-style-type: none;
8050: background-color: RGB(220, 220, 220);
8051: margin-bottom: 4px;
1.693 droeschl 8052: }
8053:
1.721 harmsja 8054: table.LC_SimpleTable {
1.911 bisitz 8055: margin:5px;
8056: border:solid 1px $lg_border_color;
1.795 www 8057: }
1.693 droeschl 8058:
1.721 harmsja 8059: table.LC_SimpleTable tr {
1.911 bisitz 8060: padding: 0;
8061: border:solid 1px $lg_border_color;
1.693 droeschl 8062: }
1.795 www 8063:
8064: table.LC_SimpleTable thead {
1.911 bisitz 8065: background:rgb(220,220,220);
1.693 droeschl 8066: }
8067:
1.721 harmsja 8068: div.LC_columnSection {
1.911 bisitz 8069: display: block;
8070: clear: both;
8071: overflow: hidden;
8072: margin: 0;
1.693 droeschl 8073: }
8074:
1.721 harmsja 8075: div.LC_columnSection>* {
1.911 bisitz 8076: float: left;
8077: margin: 10px 20px 10px 0;
8078: overflow:hidden;
1.693 droeschl 8079: }
1.721 harmsja 8080:
1.795 www 8081: table em {
1.911 bisitz 8082: font-weight: bold;
8083: font-style: normal;
1.748 schulted 8084: }
1.795 www 8085:
1.779 bisitz 8086: table.LC_tableBrowseRes,
1.795 www 8087: table.LC_tableOfContent {
1.911 bisitz 8088: border:none;
8089: border-spacing: 1px;
8090: padding: 3px;
8091: background-color: #FFFFFF;
8092: font-size: 90%;
1.753 droeschl 8093: }
1.789 droeschl 8094:
1.911 bisitz 8095: table.LC_tableOfContent {
8096: border-collapse: collapse;
1.789 droeschl 8097: }
8098:
1.771 droeschl 8099: table.LC_tableBrowseRes a,
1.768 schulted 8100: table.LC_tableOfContent a {
1.911 bisitz 8101: background-color: transparent;
8102: text-decoration: none;
1.753 droeschl 8103: }
8104:
1.795 www 8105: table.LC_tableOfContent img {
1.911 bisitz 8106: border: none;
8107: height: 1.3em;
8108: vertical-align: text-bottom;
8109: margin-right: 0.3em;
1.753 droeschl 8110: }
1.757 schulted 8111:
1.795 www 8112: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8113: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8114: }
8115:
1.795 www 8116: a#LC_content_toolbar_everything {
1.911 bisitz 8117: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8118: }
8119:
1.795 www 8120: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8121: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8122: }
8123:
1.795 www 8124: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8125: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8126: }
8127:
1.795 www 8128: a#LC_content_toolbar_changefolder {
1.911 bisitz 8129: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8130: }
8131:
1.795 www 8132: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8133: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8134: }
8135:
1.1043 raeburn 8136: a#LC_content_toolbar_edittoplevel {
8137: background-image:url(/res/adm/pages/edittoplevel.gif);
8138: }
8139:
1.795 www 8140: ul#LC_toolbar li a:hover {
1.911 bisitz 8141: background-position: bottom center;
1.757 schulted 8142: }
8143:
1.795 www 8144: ul#LC_toolbar {
1.911 bisitz 8145: padding: 0;
8146: margin: 2px;
8147: list-style:none;
8148: position:relative;
8149: background-color:white;
1.1082 raeburn 8150: overflow: auto;
1.757 schulted 8151: }
8152:
1.795 www 8153: ul#LC_toolbar li {
1.911 bisitz 8154: border:1px solid white;
8155: padding: 0;
8156: margin: 0;
8157: float: left;
8158: display:inline;
8159: vertical-align:middle;
1.1082 raeburn 8160: white-space: nowrap;
1.911 bisitz 8161: }
1.757 schulted 8162:
1.783 amueller 8163:
1.795 www 8164: a.LC_toolbarItem {
1.911 bisitz 8165: display:block;
8166: padding: 0;
8167: margin: 0;
8168: height: 32px;
8169: width: 32px;
8170: color:white;
8171: border: none;
8172: background-repeat:no-repeat;
8173: background-color:transparent;
1.757 schulted 8174: }
8175:
1.915 droeschl 8176: ul.LC_funclist {
8177: margin: 0;
8178: padding: 0.5em 1em 0.5em 0;
8179: }
8180:
1.933 droeschl 8181: ul.LC_funclist > li:first-child {
8182: font-weight:bold;
8183: margin-left:0.8em;
8184: }
8185:
1.915 droeschl 8186: ul.LC_funclist + ul.LC_funclist {
8187: /*
8188: left border as a seperator if we have more than
8189: one list
8190: */
8191: border-left: 1px solid $sidebg;
8192: /*
8193: this hides the left border behind the border of the
8194: outer box if element is wrapped to the next 'line'
8195: */
8196: margin-left: -1px;
8197: }
8198:
1.843 bisitz 8199: ul.LC_funclist li {
1.915 droeschl 8200: display: inline;
1.782 bisitz 8201: white-space: nowrap;
1.915 droeschl 8202: margin: 0 0 0 25px;
8203: line-height: 150%;
1.782 bisitz 8204: }
8205:
1.974 wenzelju 8206: .LC_hidden {
8207: display: none;
8208: }
8209:
1.1030 www 8210: .LCmodal-overlay {
8211: position:fixed;
8212: top:0;
8213: right:0;
8214: bottom:0;
8215: left:0;
8216: height:100%;
8217: width:100%;
8218: margin:0;
8219: padding:0;
8220: background:#999;
8221: opacity:.75;
8222: filter: alpha(opacity=75);
8223: -moz-opacity: 0.75;
8224: z-index:101;
8225: }
8226:
8227: * html .LCmodal-overlay {
8228: position: absolute;
8229: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8230: }
8231:
8232: .LCmodal-window {
8233: position:fixed;
8234: top:50%;
8235: left:50%;
8236: margin:0;
8237: padding:0;
8238: z-index:102;
8239: }
8240:
8241: * html .LCmodal-window {
8242: position:absolute;
8243: }
8244:
8245: .LCclose-window {
8246: position:absolute;
8247: width:32px;
8248: height:32px;
8249: right:8px;
8250: top:8px;
8251: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8252: text-indent:-99999px;
8253: overflow:hidden;
8254: cursor:pointer;
8255: }
8256:
1.1100 raeburn 8257: /*
1.1231 damieng 8258: styles used for response display
8259: */
8260: div.LC_radiofoil, div.LC_rankfoil {
8261: margin: .5em 0em .5em 0em;
8262: }
8263: table.LC_itemgroup {
8264: margin-top: 1em;
8265: }
8266:
8267: /*
1.1100 raeburn 8268: styles used by TTH when "Default set of options to pass to tth/m
8269: when converting TeX" in course settings has been set
8270:
8271: option passed: -t
8272:
8273: */
8274:
8275: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8276: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8277: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8278: td div.norm {line-height:normal;}
8279:
8280: /*
8281: option passed -y3
8282: */
8283:
8284: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8285: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8286: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8287:
1.1230 damieng 8288: /*
8289: sections with roles, for content only
8290: */
8291: section[class^="role-"] {
8292: padding-left: 10px;
8293: padding-right: 5px;
8294: margin-top: 8px;
8295: margin-bottom: 8px;
8296: border: 1px solid #2A4;
8297: border-radius: 5px;
8298: box-shadow: 0px 1px 1px #BBB;
8299: }
8300: section[class^="role-"]>h1 {
8301: position: relative;
8302: margin: 0px;
8303: padding-top: 10px;
8304: padding-left: 40px;
8305: }
8306: section[class^="role-"]>h1:before {
8307: position: absolute;
8308: left: -5px;
8309: top: 5px;
8310: }
8311: section.role-activity>h1:before {
8312: content:url('/adm/daxe/images/section_icons/activity.png');
8313: }
8314: section.role-advice>h1:before {
8315: content:url('/adm/daxe/images/section_icons/advice.png');
8316: }
8317: section.role-bibliography>h1:before {
8318: content:url('/adm/daxe/images/section_icons/bibliography.png');
8319: }
8320: section.role-citation>h1:before {
8321: content:url('/adm/daxe/images/section_icons/citation.png');
8322: }
8323: section.role-conclusion>h1:before {
8324: content:url('/adm/daxe/images/section_icons/conclusion.png');
8325: }
8326: section.role-definition>h1:before {
8327: content:url('/adm/daxe/images/section_icons/definition.png');
8328: }
8329: section.role-demonstration>h1:before {
8330: content:url('/adm/daxe/images/section_icons/demonstration.png');
8331: }
8332: section.role-example>h1:before {
8333: content:url('/adm/daxe/images/section_icons/example.png');
8334: }
8335: section.role-explanation>h1:before {
8336: content:url('/adm/daxe/images/section_icons/explanation.png');
8337: }
8338: section.role-introduction>h1:before {
8339: content:url('/adm/daxe/images/section_icons/introduction.png');
8340: }
8341: section.role-method>h1:before {
8342: content:url('/adm/daxe/images/section_icons/method.png');
8343: }
8344: section.role-more_information>h1:before {
8345: content:url('/adm/daxe/images/section_icons/more_information.png');
8346: }
8347: section.role-objectives>h1:before {
8348: content:url('/adm/daxe/images/section_icons/objectives.png');
8349: }
8350: section.role-prerequisites>h1:before {
8351: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8352: }
8353: section.role-remark>h1:before {
8354: content:url('/adm/daxe/images/section_icons/remark.png');
8355: }
8356: section.role-reminder>h1:before {
8357: content:url('/adm/daxe/images/section_icons/reminder.png');
8358: }
8359: section.role-summary>h1:before {
8360: content:url('/adm/daxe/images/section_icons/summary.png');
8361: }
8362: section.role-syntax>h1:before {
8363: content:url('/adm/daxe/images/section_icons/syntax.png');
8364: }
8365: section.role-warning>h1:before {
8366: content:url('/adm/daxe/images/section_icons/warning.png');
8367: }
8368:
1.1269 raeburn 8369: #LC_minitab_header {
8370: float:left;
8371: width:100%;
8372: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8373: font-size:93%;
8374: line-height:normal;
8375: margin: 0.5em 0 0.5em 0;
8376: }
8377: #LC_minitab_header ul {
8378: margin:0;
8379: padding:10px 10px 0;
8380: list-style:none;
8381: }
8382: #LC_minitab_header li {
8383: float:left;
8384: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8385: margin:0;
8386: padding:0 0 0 9px;
8387: }
8388: #LC_minitab_header a {
8389: display:block;
8390: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8391: padding:5px 15px 4px 6px;
8392: }
8393: #LC_minitab_header #LC_current_minitab {
8394: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8395: }
8396: #LC_minitab_header #LC_current_minitab a {
8397: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8398: padding-bottom:5px;
8399: }
8400:
8401:
1.343 albertel 8402: END
8403: }
8404:
1.306 albertel 8405: =pod
8406:
8407: =item * &headtag()
8408:
8409: Returns a uniform footer for LON-CAPA web pages.
8410:
1.307 albertel 8411: Inputs: $title - optional title for the head
8412: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8413: $args - optional arguments
1.319 albertel 8414: force_register - if is true call registerurl so the remote is
8415: informed
1.415 albertel 8416: redirect -> array ref of
8417: 1- seconds before redirect occurs
8418: 2- url to redirect to
8419: 3- whether the side effect should occur
1.315 albertel 8420: (side effect of setting
8421: $env{'internal.head.redirect'} to the url
8422: redirected too)
1.352 albertel 8423: domain -> force to color decorate a page for a specific
8424: domain
8425: function -> force usage of a specific rolish color scheme
8426: bgcolor -> override the default page bgcolor
1.460 albertel 8427: no_auto_mt_title
8428: -> prevent &mt()ing the title arg
1.464 albertel 8429:
1.306 albertel 8430: =cut
8431:
8432: sub headtag {
1.313 albertel 8433: my ($title,$head_extra,$args) = @_;
1.306 albertel 8434:
1.363 albertel 8435: my $function = $args->{'function'} || &get_users_function();
8436: my $domain = $args->{'domain'} || &determinedomain();
8437: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8438: my $httphost = $args->{'use_absolute'};
1.418 albertel 8439: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8440: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8441: #time(),
1.418 albertel 8442: $env{'environment.color.timestamp'},
1.363 albertel 8443: $function,$domain,$bgcolor);
8444:
1.369 www 8445: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8446:
1.308 albertel 8447: my $result =
8448: '<head>'.
1.1160 raeburn 8449: &font_settings($args);
1.319 albertel 8450:
1.1188 raeburn 8451: my $inhibitprint;
8452: if ($args->{'print_suppress'}) {
8453: $inhibitprint = &print_suppression();
8454: }
1.1064 raeburn 8455:
1.461 albertel 8456: if (!$args->{'frameset'}) {
8457: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8458: }
1.962 droeschl 8459: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8460: $result .= Apache::lonxml::display_title();
1.319 albertel 8461: }
1.436 albertel 8462: if (!$args->{'no_nav_bar'}
8463: && !$args->{'only_body'}
8464: && !$args->{'frameset'}) {
1.1154 raeburn 8465: $result .= &help_menu_js($httphost);
1.1032 www 8466: $result.=&modal_window();
1.1038 www 8467: $result.=&togglebox_script();
1.1034 www 8468: $result.=&wishlist_window();
1.1041 www 8469: $result.=&LCprogressbarUpdate_script();
1.1034 www 8470: } else {
8471: if ($args->{'add_modal'}) {
8472: $result.=&modal_window();
8473: }
8474: if ($args->{'add_wishlist'}) {
8475: $result.=&wishlist_window();
8476: }
1.1038 www 8477: if ($args->{'add_togglebox'}) {
8478: $result.=&togglebox_script();
8479: }
1.1041 www 8480: if ($args->{'add_progressbar'}) {
8481: $result.=&LCprogressbarUpdate_script();
8482: }
1.436 albertel 8483: }
1.314 albertel 8484: if (ref($args->{'redirect'})) {
1.414 albertel 8485: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8486: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8487: if (!$inhibit_continue) {
8488: $env{'internal.head.redirect'} = $url;
8489: }
1.313 albertel 8490: $result.=<<ADDMETA
8491: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8492: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8493: ADDMETA
1.1210 raeburn 8494: } else {
8495: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8496: my $requrl = $env{'request.uri'};
8497: if ($requrl eq '') {
8498: $requrl = $ENV{'REQUEST_URI'};
8499: $requrl =~ s/\?.+$//;
8500: }
8501: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8502: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8503: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8504: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8505: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8506: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
8507: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8508: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
8509: if ($domdefs{'offloadnow'}{$lonhost}) {
8510: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
8511: if (($newserver) && ($newserver ne $lonhost)) {
8512: my $numsec = 5;
8513: my $timeout = $numsec * 1000;
8514: my ($newurl,$locknum,%locks,$msg);
8515: if ($env{'request.role.adv'}) {
8516: ($locknum,%locks) = &Apache::lonnet::get_locks();
8517: }
8518: my $disable_submit = 0;
8519: if ($requrl =~ /$LONCAPA::assess_re/) {
8520: $disable_submit = 1;
8521: }
8522: if ($locknum) {
8523: my @lockinfo = sort(values(%locks));
8524: $msg = &mt('Once the following tasks are complete: ')."\\n".
8525: join(", ",sort(values(%locks)))."\\n".
8526: &mt('your session will be transferred to a different server, after you click "Roles".');
8527: } else {
8528: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8529: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
8530: }
8531: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8532: $newurl = '/adm/switchserver?otherserver='.$newserver;
8533: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8534: $newurl .= '&role='.$env{'request.role'};
8535: }
8536: if ($env{'request.symb'}) {
8537: $newurl .= '&symb='.$env{'request.symb'};
8538: } else {
8539: $newurl .= '&origurl='.$requrl;
8540: }
8541: }
1.1222 damieng 8542: &js_escape(\$msg);
1.1210 raeburn 8543: $result.=<<OFFLOAD
8544: <meta http-equiv="pragma" content="no-cache" />
8545: <script type="text/javascript">
1.1215 raeburn 8546: // <![CDATA[
1.1210 raeburn 8547: function LC_Offload_Now() {
8548: var dest = "$newurl";
8549: if (dest != '') {
8550: window.location.href="$newurl";
8551: }
8552: }
1.1214 raeburn 8553: \$(document).ready(function () {
8554: window.alert('$msg');
8555: if ($disable_submit) {
1.1210 raeburn 8556: \$(".LC_hwk_submit").prop("disabled", true);
8557: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8558: }
8559: setTimeout('LC_Offload_Now()', $timeout);
8560: });
1.1215 raeburn 8561: // ]]>
1.1210 raeburn 8562: </script>
8563: OFFLOAD
8564: }
8565: }
8566: }
8567: }
8568: }
8569: }
1.313 albertel 8570: }
1.306 albertel 8571: if (!defined($title)) {
8572: $title = 'The LearningOnline Network with CAPA';
8573: }
1.460 albertel 8574: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8575: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8576: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8577: if (!$args->{'frameset'}) {
8578: $result .= ' /';
8579: }
8580: $result .= '>'
1.1064 raeburn 8581: .$inhibitprint
1.414 albertel 8582: .$head_extra;
1.1242 raeburn 8583: my $clientmobile;
8584: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8585: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8586: } else {
8587: $clientmobile = $env{'browser.mobile'};
8588: }
8589: if ($clientmobile) {
1.1137 raeburn 8590: $result .= '
8591: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8592: <meta name="apple-mobile-web-app-capable" content="yes" />';
8593: }
1.1278 raeburn 8594: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8595: return $result.'</head>';
1.306 albertel 8596: }
8597:
8598: =pod
8599:
1.340 albertel 8600: =item * &font_settings()
8601:
8602: Returns neccessary <meta> to set the proper encoding
8603:
1.1160 raeburn 8604: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8605:
8606: =cut
8607:
8608: sub font_settings {
1.1160 raeburn 8609: my ($args) = @_;
1.340 albertel 8610: my $headerstring='';
1.1160 raeburn 8611: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8612: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8613: $headerstring.=
8614: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8615: if (!$args->{'frameset'}) {
8616: $headerstring.= ' /';
8617: }
8618: $headerstring .= '>'."\n";
1.340 albertel 8619: }
8620: return $headerstring;
8621: }
8622:
1.341 albertel 8623: =pod
8624:
1.1064 raeburn 8625: =item * &print_suppression()
8626:
8627: In course context returns css which causes the body to be blank when media="print",
8628: if printout generation is unavailable for the current resource.
8629:
8630: This could be because:
8631:
8632: (a) printstartdate is in the future
8633:
8634: (b) printenddate is in the past
8635:
8636: (c) there is an active exam block with "printout"
8637: functionality blocked
8638:
8639: Users with pav, pfo or evb privileges are exempt.
8640:
8641: Inputs: none
8642:
8643: =cut
8644:
8645:
8646: sub print_suppression {
8647: my $noprint;
8648: if ($env{'request.course.id'}) {
8649: my $scope = $env{'request.course.id'};
8650: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8651: (&Apache::lonnet::allowed('pfo',$scope))) {
8652: return;
8653: }
8654: if ($env{'request.course.sec'} ne '') {
8655: $scope .= "/$env{'request.course.sec'}";
8656: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8657: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8658: return;
1.1064 raeburn 8659: }
8660: }
8661: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8662: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8663: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8664: if ($blocked) {
8665: my $checkrole = "cm./$cdom/$cnum";
8666: if ($env{'request.course.sec'} ne '') {
8667: $checkrole .= "/$env{'request.course.sec'}";
8668: }
8669: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8670: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8671: $noprint = 1;
8672: }
8673: }
8674: unless ($noprint) {
8675: my $symb = &Apache::lonnet::symbread();
8676: if ($symb ne '') {
8677: my $navmap = Apache::lonnavmaps::navmap->new();
8678: if (ref($navmap)) {
8679: my $res = $navmap->getBySymb($symb);
8680: if (ref($res)) {
8681: if (!$res->resprintable()) {
8682: $noprint = 1;
8683: }
8684: }
8685: }
8686: }
8687: }
8688: if ($noprint) {
8689: return <<"ENDSTYLE";
8690: <style type="text/css" media="print">
8691: body { display:none }
8692: </style>
8693: ENDSTYLE
8694: }
8695: }
8696: return;
8697: }
8698:
8699: =pod
8700:
1.341 albertel 8701: =item * &xml_begin()
8702:
8703: Returns the needed doctype and <html>
8704:
8705: Inputs: none
8706:
8707: =cut
8708:
8709: sub xml_begin {
1.1168 raeburn 8710: my ($is_frameset) = @_;
1.341 albertel 8711: my $output='';
8712:
8713: if ($env{'browser.mathml'}) {
8714: $output='<?xml version="1.0"?>'
8715: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8716: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8717:
8718: # .'<!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">] >'
8719: .'<!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">'
8720: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8721: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8722: } elsif ($is_frameset) {
8723: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8724: '<html>'."\n";
1.341 albertel 8725: } else {
1.1168 raeburn 8726: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8727: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8728: }
8729: return $output;
8730: }
1.340 albertel 8731:
8732: =pod
8733:
1.306 albertel 8734: =item * &start_page()
8735:
8736: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8737:
1.648 raeburn 8738: Inputs:
8739:
8740: =over 4
8741:
8742: $title - optional title for the page
8743:
8744: $head_extra - optional extra HTML to incude inside the <head>
8745:
8746: $args - additional optional args supported are:
8747:
8748: =over 8
8749:
8750: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8751: arg on
1.814 bisitz 8752: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8753: add_entries -> additional attributes to add to the <body>
8754: domain -> force to color decorate a page for a
1.317 albertel 8755: specific domain
1.648 raeburn 8756: function -> force usage of a specific rolish color
1.317 albertel 8757: scheme
1.648 raeburn 8758: redirect -> see &headtag()
8759: bgcolor -> override the default page bg color
8760: js_ready -> return a string ready for being used in
1.317 albertel 8761: a javascript writeln
1.648 raeburn 8762: html_encode -> return a string ready for being used in
1.320 albertel 8763: a html attribute
1.648 raeburn 8764: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8765: $forcereg arg
1.648 raeburn 8766: frameset -> if true will start with a <frameset>
1.330 albertel 8767: rather than <body>
1.648 raeburn 8768: skip_phases -> hash ref of
1.338 albertel 8769: head -> skip the <html><head> generation
8770: body -> skip all <body> generation
1.648 raeburn 8771: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8772: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8773: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 8774: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8775: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 8776: group -> includes the current group, if page is for a
1.1274 raeburn 8777: specific group
8778: use_absolute -> for request for external resource or syllabus, this
8779: will contain https://<hostname> if server uses
8780: https (as per hosts.tab), but request is for http
8781: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8782:
1.648 raeburn 8783: =back
1.460 albertel 8784:
1.648 raeburn 8785: =back
1.562 albertel 8786:
1.306 albertel 8787: =cut
8788:
8789: sub start_page {
1.309 albertel 8790: my ($title,$head_extra,$args) = @_;
1.318 albertel 8791: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8792:
1.315 albertel 8793: $env{'internal.start_page'}++;
1.1318 raeburn 8794: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu);
1.964 droeschl 8795:
1.338 albertel 8796: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8797: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8798: }
1.1316 raeburn 8799:
8800: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 8801: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
8802: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
8803: $args->{'no_primary_menu'} = 1;
8804: }
8805: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
8806: $args->{'no_inline_menu'} = 1;
8807: }
8808: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
8809: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
8810: }
8811: } else {
8812: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8813: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
8814: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
8815: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
8816: $args->{'no_primary_menu'} = 1;
8817: }
8818: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
8819: $args->{'no_inline_menu'} = 1;
8820: }
8821: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
8822: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
8823: }
8824: }
8825: }
1.1316 raeburn 8826: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
8827: $env{'course.'.$env{'request.course.id'}.'.domain'},
8828: $env{'course.'.$env{'request.course.id'}.'.num'});
8829: }
1.338 albertel 8830:
8831: if (! exists($args->{'skip_phases'}{'body'}) ) {
8832: if ($args->{'frameset'}) {
8833: my $attr_string = &make_attr_string($args->{'force_register'},
8834: $args->{'add_entries'});
8835: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8836: } else {
8837: $result .=
8838: &bodytag($title,
8839: $args->{'function'}, $args->{'add_entries'},
8840: $args->{'only_body'}, $args->{'domain'},
8841: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8842: $args->{'bgcolor'}, $args,
1.1318 raeburn 8843: \@advtools,$ltiscope,$ltiuri,\%ltimenu);
1.831 bisitz 8844: }
1.330 albertel 8845: }
1.338 albertel 8846:
1.315 albertel 8847: if ($args->{'js_ready'}) {
1.713 kaisler 8848: $result = &js_ready($result);
1.315 albertel 8849: }
1.320 albertel 8850: if ($args->{'html_encode'}) {
1.713 kaisler 8851: $result = &html_encode($result);
8852: }
8853:
1.813 bisitz 8854: # Preparation for new and consistent functionlist at top of screen
8855: # if ($args->{'functionlist'}) {
8856: # $result .= &build_functionlist();
8857: #}
8858:
1.964 droeschl 8859: # Don't add anything more if only_body wanted or in const space
8860: return $result if $args->{'only_body'}
8861: || $env{'request.state'} eq 'construct';
1.813 bisitz 8862:
8863: #Breadcrumbs
1.758 kaisler 8864: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8865: &Apache::lonhtmlcommon::clear_breadcrumbs();
8866: #if any br links exists, add them to the breadcrumbs
8867: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8868: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8869: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8870: }
8871: }
1.1096 raeburn 8872: # if @advtools array contains items add then to the breadcrumbs
8873: if (@advtools > 0) {
8874: &Apache::lonmenu::advtools_crumbs(@advtools);
8875: }
1.1272 raeburn 8876: my $menulink;
8877: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8878: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 8879: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 8880: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
8881: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
8882: (!$env{'request.role.adv'}))) {
8883: $menulink = 0;
8884: } else {
8885: undef($menulink);
8886: }
1.758 kaisler 8887: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8888: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 8889: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 8890: } else {
1.1272 raeburn 8891: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8892: }
1.320 albertel 8893: }
1.315 albertel 8894: return $result;
1.306 albertel 8895: }
8896:
8897: sub end_page {
1.315 albertel 8898: my ($args) = @_;
8899: $env{'internal.end_page'}++;
1.330 albertel 8900: my $result;
1.335 albertel 8901: if ($args->{'discussion'}) {
8902: my ($target,$parser);
8903: if (ref($args->{'discussion'})) {
8904: ($target,$parser) =($args->{'discussion'}{'target'},
8905: $args->{'discussion'}{'parser'});
8906: }
8907: $result .= &Apache::lonxml::xmlend($target,$parser);
8908: }
1.330 albertel 8909: if ($args->{'frameset'}) {
8910: $result .= '</frameset>';
8911: } else {
1.635 raeburn 8912: $result .= &endbodytag($args);
1.330 albertel 8913: }
1.1080 raeburn 8914: unless ($args->{'notbody'}) {
8915: $result .= "\n</html>";
8916: }
1.330 albertel 8917:
1.315 albertel 8918: if ($args->{'js_ready'}) {
1.317 albertel 8919: $result = &js_ready($result);
1.315 albertel 8920: }
1.335 albertel 8921:
1.320 albertel 8922: if ($args->{'html_encode'}) {
8923: $result = &html_encode($result);
8924: }
1.335 albertel 8925:
1.315 albertel 8926: return $result;
8927: }
8928:
1.1034 www 8929: sub wishlist_window {
8930: return(<<'ENDWISHLIST');
1.1046 raeburn 8931: <script type="text/javascript">
1.1034 www 8932: // <![CDATA[
8933: // <!-- BEGIN LON-CAPA Internal
8934: function set_wishlistlink(title, path) {
8935: if (!title) {
8936: title = document.title;
8937: title = title.replace(/^LON-CAPA /,'');
8938: }
1.1175 raeburn 8939: title = encodeURIComponent(title);
1.1203 raeburn 8940: title = title.replace("'","\\\'");
1.1034 www 8941: if (!path) {
8942: path = location.pathname;
8943: }
1.1175 raeburn 8944: path = encodeURIComponent(path);
1.1203 raeburn 8945: path = path.replace("'","\\\'");
1.1034 www 8946: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8947: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8948: }
8949: // END LON-CAPA Internal -->
8950: // ]]>
8951: </script>
8952: ENDWISHLIST
8953: }
8954:
1.1030 www 8955: sub modal_window {
8956: return(<<'ENDMODAL');
1.1046 raeburn 8957: <script type="text/javascript">
1.1030 www 8958: // <![CDATA[
8959: // <!-- BEGIN LON-CAPA Internal
8960: var modalWindow = {
8961: parent:"body",
8962: windowId:null,
8963: content:null,
8964: width:null,
8965: height:null,
8966: close:function()
8967: {
8968: $(".LCmodal-window").remove();
8969: $(".LCmodal-overlay").remove();
8970: },
8971: open:function()
8972: {
8973: var modal = "";
8974: modal += "<div class=\"LCmodal-overlay\"></div>";
8975: 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;\">";
8976: modal += this.content;
8977: modal += "</div>";
8978:
8979: $(this.parent).append(modal);
8980:
8981: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8982: $(".LCclose-window").click(function(){modalWindow.close();});
8983: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8984: }
8985: };
1.1140 raeburn 8986: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8987: {
1.1266 raeburn 8988: source = source.replace(/'/g,"'");
1.1030 www 8989: modalWindow.windowId = "myModal";
8990: modalWindow.width = width;
8991: modalWindow.height = height;
1.1196 raeburn 8992: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8993: modalWindow.open();
1.1208 raeburn 8994: };
1.1030 www 8995: // END LON-CAPA Internal -->
8996: // ]]>
8997: </script>
8998: ENDMODAL
8999: }
9000:
9001: sub modal_link {
1.1140 raeburn 9002: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9003: unless ($width) { $width=480; }
9004: unless ($height) { $height=400; }
1.1031 www 9005: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 9006: unless ($transparency) { $transparency='true'; }
9007:
1.1074 raeburn 9008: my $target_attr;
9009: if (defined($target)) {
9010: $target_attr = 'target="'.$target.'"';
9011: }
9012: return <<"ENDLINK";
1.1140 raeburn 9013: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 9014: $linktext</a>
9015: ENDLINK
1.1030 www 9016: }
9017:
1.1032 www 9018: sub modal_adhoc_script {
9019: my ($funcname,$width,$height,$content)=@_;
9020: return (<<ENDADHOC);
1.1046 raeburn 9021: <script type="text/javascript">
1.1032 www 9022: // <![CDATA[
9023: var $funcname = function()
9024: {
9025: modalWindow.windowId = "myModal";
9026: modalWindow.width = $width;
9027: modalWindow.height = $height;
9028: modalWindow.content = '$content';
9029: modalWindow.open();
9030: };
9031: // ]]>
9032: </script>
9033: ENDADHOC
9034: }
9035:
1.1041 www 9036: sub modal_adhoc_inner {
9037: my ($funcname,$width,$height,$content)=@_;
9038: my $innerwidth=$width-20;
9039: $content=&js_ready(
1.1140 raeburn 9040: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
9041: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9042: $content.
1.1041 www 9043: &end_scrollbox().
1.1140 raeburn 9044: &end_page()
1.1041 www 9045: );
9046: return &modal_adhoc_script($funcname,$width,$height,$content);
9047: }
9048:
9049: sub modal_adhoc_window {
9050: my ($funcname,$width,$height,$content,$linktext)=@_;
9051: return &modal_adhoc_inner($funcname,$width,$height,$content).
9052: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9053: }
9054:
9055: sub modal_adhoc_launch {
9056: my ($funcname,$width,$height,$content)=@_;
9057: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9058: <script type="text/javascript">
9059: // <![CDATA[
9060: $funcname();
9061: // ]]>
9062: </script>
9063: ENDLAUNCH
9064: }
9065:
9066: sub modal_adhoc_close {
9067: return (<<ENDCLOSE);
9068: <script type="text/javascript">
9069: // <![CDATA[
9070: modalWindow.close();
9071: // ]]>
9072: </script>
9073: ENDCLOSE
9074: }
9075:
1.1038 www 9076: sub togglebox_script {
9077: return(<<ENDTOGGLE);
9078: <script type="text/javascript">
9079: // <![CDATA[
9080: function LCtoggleDisplay(id,hidetext,showtext) {
9081: link = document.getElementById(id + "link").childNodes[0];
9082: with (document.getElementById(id).style) {
9083: if (display == "none" ) {
9084: display = "inline";
9085: link.nodeValue = hidetext;
9086: } else {
9087: display = "none";
9088: link.nodeValue = showtext;
9089: }
9090: }
9091: }
9092: // ]]>
9093: </script>
9094: ENDTOGGLE
9095: }
9096:
1.1039 www 9097: sub start_togglebox {
9098: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9099: unless ($heading) { $heading=''; } else { $heading.=' '; }
9100: unless ($showtext) { $showtext=&mt('show'); }
9101: unless ($hidetext) { $hidetext=&mt('hide'); }
9102: unless ($headerbg) { $headerbg='#FFFFFF'; }
9103: return &start_data_table().
9104: &start_data_table_header_row().
9105: '<td bgcolor="'.$headerbg.'">'.$heading.
9106: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9107: $showtext.'\')">'.$showtext.'</a>]</td>'.
9108: &end_data_table_header_row().
9109: '<tr id="'.$id.'" style="display:none""><td>';
9110: }
9111:
9112: sub end_togglebox {
9113: return '</td></tr>'.&end_data_table();
9114: }
9115:
1.1041 www 9116: sub LCprogressbar_script {
1.1302 raeburn 9117: my ($id,$number_to_do)=@_;
9118: if ($number_to_do) {
9119: return(<<ENDPROGRESS);
1.1041 www 9120: <script type="text/javascript">
9121: // <![CDATA[
1.1045 www 9122: \$('#progressbar$id').progressbar({
1.1041 www 9123: value: 0,
9124: change: function(event, ui) {
9125: var newVal = \$(this).progressbar('option', 'value');
9126: \$('.pblabel', this).text(LCprogressTxt);
9127: }
9128: });
9129: // ]]>
9130: </script>
9131: ENDPROGRESS
1.1302 raeburn 9132: } else {
9133: return(<<ENDPROGRESS);
9134: <script type="text/javascript">
9135: // <![CDATA[
9136: \$('#progressbar$id').progressbar({
9137: value: false,
9138: create: function(event, ui) {
9139: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9140: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9141: }
9142: });
9143: // ]]>
9144: </script>
9145: ENDPROGRESS
9146: }
1.1041 www 9147: }
9148:
9149: sub LCprogressbarUpdate_script {
9150: return(<<ENDPROGRESSUPDATE);
9151: <style type="text/css">
9152: .ui-progressbar { position:relative; }
1.1302 raeburn 9153: .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 9154: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9155: </style>
9156: <script type="text/javascript">
9157: // <![CDATA[
1.1045 www 9158: var LCprogressTxt='---';
9159:
1.1302 raeburn 9160: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9161: LCprogressTxt=progresstext;
1.1302 raeburn 9162: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9163: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9164: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 9165: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9166: } else {
9167: \$('#progressbar'+id).progressbar('value',percent);
9168: }
1.1041 www 9169: }
9170: // ]]>
9171: </script>
9172: ENDPROGRESSUPDATE
9173: }
9174:
1.1042 www 9175: my $LClastpercent;
1.1045 www 9176: my $LCidcnt;
9177: my $LCcurrentid;
1.1042 www 9178:
1.1041 www 9179: sub LCprogressbar {
1.1302 raeburn 9180: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9181: $LClastpercent=0;
1.1045 www 9182: $LCidcnt++;
9183: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 9184: my ($starting,$content);
9185: if ($number_to_do) {
9186: $starting=&mt('Starting');
9187: $content=(<<ENDPROGBAR);
9188: $preamble
1.1045 www 9189: <div id="progressbar$LCcurrentid">
1.1041 www 9190: <span class="pblabel">$starting</span>
9191: </div>
9192: ENDPROGBAR
1.1302 raeburn 9193: } else {
9194: $starting=&mt('Loading...');
9195: $LClastpercent='false';
9196: $content=(<<ENDPROGBAR);
9197: $preamble
9198: <div id="progressbar$LCcurrentid">
9199: <div class="progress-label">$starting</div>
9200: </div>
9201: ENDPROGBAR
9202: }
9203: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9204: }
9205:
9206: sub LCprogressbarUpdate {
1.1302 raeburn 9207: my ($r,$val,$text,$number_to_do)=@_;
9208: if ($number_to_do) {
9209: unless ($val) {
9210: if ($LClastpercent) {
9211: $val=$LClastpercent;
9212: } else {
9213: $val=0;
9214: }
9215: }
9216: if ($val<0) { $val=0; }
9217: if ($val>100) { $val=0; }
9218: $LClastpercent=$val;
9219: unless ($text) { $text=$val.'%'; }
9220: } else {
9221: $val = 'false';
1.1042 www 9222: }
1.1041 www 9223: $text=&js_ready($text);
1.1044 www 9224: &r_print($r,<<ENDUPDATE);
1.1041 www 9225: <script type="text/javascript">
9226: // <![CDATA[
1.1302 raeburn 9227: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9228: // ]]>
9229: </script>
9230: ENDUPDATE
1.1035 www 9231: }
9232:
1.1042 www 9233: sub LCprogressbarClose {
9234: my ($r)=@_;
9235: $LClastpercent=0;
1.1044 www 9236: &r_print($r,<<ENDCLOSE);
1.1042 www 9237: <script type="text/javascript">
9238: // <![CDATA[
1.1045 www 9239: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9240: // ]]>
9241: </script>
9242: ENDCLOSE
1.1044 www 9243: }
9244:
9245: sub r_print {
9246: my ($r,$to_print)=@_;
9247: if ($r) {
9248: $r->print($to_print);
9249: $r->rflush();
9250: } else {
9251: print($to_print);
9252: }
1.1042 www 9253: }
9254:
1.320 albertel 9255: sub html_encode {
9256: my ($result) = @_;
9257:
1.322 albertel 9258: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9259:
9260: return $result;
9261: }
1.1044 www 9262:
1.317 albertel 9263: sub js_ready {
9264: my ($result) = @_;
9265:
1.323 albertel 9266: $result =~ s/[\n\r]/ /xmsg;
9267: $result =~ s/\\/\\\\/xmsg;
9268: $result =~ s/'/\\'/xmsg;
1.372 albertel 9269: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9270:
9271: return $result;
9272: }
9273:
1.315 albertel 9274: sub validate_page {
9275: if ( exists($env{'internal.start_page'})
1.316 albertel 9276: && $env{'internal.start_page'} > 1) {
9277: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9278: $env{'internal.start_page'}.' '.
1.316 albertel 9279: $ENV{'request.filename'});
1.315 albertel 9280: }
9281: if ( exists($env{'internal.end_page'})
1.316 albertel 9282: && $env{'internal.end_page'} > 1) {
9283: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9284: $env{'internal.end_page'}.' '.
1.316 albertel 9285: $env{'request.filename'});
1.315 albertel 9286: }
9287: if ( exists($env{'internal.start_page'})
9288: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9289: &Apache::lonnet::logthis('start_page called without end_page '.
9290: $env{'request.filename'});
1.315 albertel 9291: }
9292: if ( ! exists($env{'internal.start_page'})
9293: && exists($env{'internal.end_page'})) {
1.316 albertel 9294: &Apache::lonnet::logthis('end_page called without start_page'.
9295: $env{'request.filename'});
1.315 albertel 9296: }
1.306 albertel 9297: }
1.315 albertel 9298:
1.996 www 9299:
9300: sub start_scrollbox {
1.1140 raeburn 9301: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9302: unless ($outerwidth) { $outerwidth='520px'; }
9303: unless ($width) { $width='500px'; }
9304: unless ($height) { $height='200px'; }
1.1075 raeburn 9305: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9306: if ($id ne '') {
1.1140 raeburn 9307: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9308: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9309: }
1.1075 raeburn 9310: if ($bgcolor ne '') {
9311: $tdcol = "background-color: $bgcolor;";
9312: }
1.1137 raeburn 9313: my $nicescroll_js;
9314: if ($env{'browser.mobile'}) {
1.1140 raeburn 9315: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9316: }
9317: return <<"END";
9318: $nicescroll_js
9319:
9320: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9321: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9322: END
9323: }
9324:
9325: sub end_scrollbox {
9326: return '</div></td></tr></table>';
9327: }
9328:
9329: sub nicescroll_javascript {
9330: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9331: my %options;
9332: if (ref($cursor) eq 'HASH') {
9333: %options = %{$cursor};
9334: }
9335: unless ($options{'railalign'} =~ /^left|right$/) {
9336: $options{'railalign'} = 'left';
9337: }
9338: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9339: my $function = &get_users_function();
9340: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9341: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9342: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9343: }
1.1140 raeburn 9344: }
9345: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9346: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9347: $options{'cursoropacity'}='1.0';
9348: }
1.1140 raeburn 9349: } else {
9350: $options{'cursoropacity'}='1.0';
9351: }
9352: if ($options{'cursorfixedheight'} eq 'none') {
9353: delete($options{'cursorfixedheight'});
9354: } else {
9355: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9356: }
9357: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9358: delete($options{'railoffset'});
9359: }
9360: my @niceoptions;
9361: while (my($key,$value) = each(%options)) {
9362: if ($value =~ /^\{.+\}$/) {
9363: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9364: } else {
1.1140 raeburn 9365: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9366: }
1.1140 raeburn 9367: }
9368: my $nicescroll_js = '
1.1137 raeburn 9369: $(document).ready(
1.1140 raeburn 9370: function() {
9371: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9372: }
1.1137 raeburn 9373: );
9374: ';
1.1140 raeburn 9375: if ($framecheck) {
9376: $nicescroll_js .= '
9377: function expand_div(caller) {
9378: if (top === self) {
9379: document.getElementById("'.$id.'").style.width = "auto";
9380: document.getElementById("'.$id.'").style.height = "auto";
9381: } else {
9382: try {
9383: if (parent.frames) {
9384: if (parent.frames.length > 1) {
9385: var framesrc = parent.frames[1].location.href;
9386: var currsrc = framesrc.replace(/\#.*$/,"");
9387: if ((caller == "search") || (currsrc == "'.$location.'")) {
9388: document.getElementById("'.$id.'").style.width = "auto";
9389: document.getElementById("'.$id.'").style.height = "auto";
9390: }
9391: }
9392: }
9393: } catch (e) {
9394: return;
9395: }
1.1137 raeburn 9396: }
1.1140 raeburn 9397: return;
1.996 www 9398: }
1.1140 raeburn 9399: ';
9400: }
9401: if ($needjsready) {
9402: $nicescroll_js = '
9403: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9404: } else {
9405: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9406: }
9407: return $nicescroll_js;
1.996 www 9408: }
9409:
1.318 albertel 9410: sub simple_error_page {
1.1150 bisitz 9411: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 9412: my %displayargs;
1.1151 raeburn 9413: if (ref($args) eq 'HASH') {
9414: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 9415: if ($args->{'only_body'}) {
9416: $displayargs{'only_body'} = 1;
9417: }
9418: if ($args->{'no_nav_bar'}) {
9419: $displayargs{'no_nav_bar'} = 1;
9420: }
1.1151 raeburn 9421: } else {
9422: $msg = &mt($msg);
9423: }
1.1150 bisitz 9424:
1.318 albertel 9425: my $page =
1.1304 raeburn 9426: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 9427: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9428: &Apache::loncommon::end_page();
9429: if (ref($r)) {
9430: $r->print($page);
1.327 albertel 9431: return;
1.318 albertel 9432: }
9433: return $page;
9434: }
1.347 albertel 9435:
9436: {
1.610 albertel 9437: my @row_count;
1.961 onken 9438:
9439: sub start_data_table_count {
9440: unshift(@row_count, 0);
9441: return;
9442: }
9443:
9444: sub end_data_table_count {
9445: shift(@row_count);
9446: return;
9447: }
9448:
1.347 albertel 9449: sub start_data_table {
1.1018 raeburn 9450: my ($add_class,$id) = @_;
1.422 albertel 9451: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9452: my $table_id;
9453: if (defined($id)) {
9454: $table_id = ' id="'.$id.'"';
9455: }
1.961 onken 9456: &start_data_table_count();
1.1018 raeburn 9457: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9458: }
9459:
9460: sub end_data_table {
1.961 onken 9461: &end_data_table_count();
1.389 albertel 9462: return '</table>'."\n";;
1.347 albertel 9463: }
9464:
9465: sub start_data_table_row {
1.974 wenzelju 9466: my ($add_class, $id) = @_;
1.610 albertel 9467: $row_count[0]++;
9468: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9469: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9470: $id = (' id="'.$id.'"') unless ($id eq '');
9471: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9472: }
1.471 banghart 9473:
9474: sub continue_data_table_row {
1.974 wenzelju 9475: my ($add_class, $id) = @_;
1.610 albertel 9476: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9477: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9478: $id = (' id="'.$id.'"') unless ($id eq '');
9479: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9480: }
1.347 albertel 9481:
9482: sub end_data_table_row {
1.389 albertel 9483: return '</tr>'."\n";;
1.347 albertel 9484: }
1.367 www 9485:
1.421 albertel 9486: sub start_data_table_empty_row {
1.707 bisitz 9487: # $row_count[0]++;
1.421 albertel 9488: return '<tr class="LC_empty_row" >'."\n";;
9489: }
9490:
9491: sub end_data_table_empty_row {
9492: return '</tr>'."\n";;
9493: }
9494:
1.367 www 9495: sub start_data_table_header_row {
1.389 albertel 9496: return '<tr class="LC_header_row">'."\n";;
1.367 www 9497: }
9498:
9499: sub end_data_table_header_row {
1.389 albertel 9500: return '</tr>'."\n";;
1.367 www 9501: }
1.890 droeschl 9502:
9503: sub data_table_caption {
9504: my $caption = shift;
9505: return "<caption class=\"LC_caption\">$caption</caption>";
9506: }
1.347 albertel 9507: }
9508:
1.548 albertel 9509: =pod
9510:
9511: =item * &inhibit_menu_check($arg)
9512:
9513: Checks for a inhibitmenu state and generates output to preserve it
9514:
9515: Inputs: $arg - can be any of
9516: - undef - in which case the return value is a string
9517: to add into arguments list of a uri
9518: - 'input' - in which case the return value is a HTML
9519: <form> <input> field of type hidden to
9520: preserve the value
9521: - a url - in which case the return value is the url with
9522: the neccesary cgi args added to preserve the
9523: inhibitmenu state
9524: - a ref to a url - no return value, but the string is
9525: updated to include the neccessary cgi
9526: args to preserve the inhibitmenu state
9527:
9528: =cut
9529:
9530: sub inhibit_menu_check {
9531: my ($arg) = @_;
9532: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9533: if ($arg eq 'input') {
9534: if ($env{'form.inhibitmenu'}) {
9535: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9536: } else {
9537: return
9538: }
9539: }
9540: if ($env{'form.inhibitmenu'}) {
9541: if (ref($arg)) {
9542: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9543: } elsif ($arg eq '') {
9544: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9545: } else {
9546: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9547: }
9548: }
9549: if (!ref($arg)) {
9550: return $arg;
9551: }
9552: }
9553:
1.251 albertel 9554: ###############################################
1.182 matthew 9555:
9556: =pod
9557:
1.549 albertel 9558: =back
9559:
9560: =head1 User Information Routines
9561:
9562: =over 4
9563:
1.405 albertel 9564: =item * &get_users_function()
1.182 matthew 9565:
9566: Used by &bodytag to determine the current users primary role.
9567: Returns either 'student','coordinator','admin', or 'author'.
9568:
9569: =cut
9570:
9571: ###############################################
9572: sub get_users_function {
1.815 tempelho 9573: my $function = 'norole';
1.818 tempelho 9574: if ($env{'request.role'}=~/^(st)/) {
9575: $function='student';
9576: }
1.907 raeburn 9577: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9578: $function='coordinator';
9579: }
1.258 albertel 9580: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9581: $function='admin';
9582: }
1.826 bisitz 9583: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9584: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9585: $function='author';
9586: }
9587: return $function;
1.54 www 9588: }
1.99 www 9589:
9590: ###############################################
9591:
1.233 raeburn 9592: =pod
9593:
1.821 raeburn 9594: =item * &show_course()
9595:
9596: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9597: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9598:
9599: Inputs:
9600: None
9601:
9602: Outputs:
9603: Scalar: 1 if 'Course' to be used, 0 otherwise.
9604:
9605: =cut
9606:
9607: ###############################################
9608: sub show_course {
9609: my $course = !$env{'user.adv'};
9610: if (!$env{'user.adv'}) {
9611: foreach my $env (keys(%env)) {
9612: next if ($env !~ m/^user\.priv\./);
9613: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9614: $course = 0;
9615: last;
9616: }
9617: }
9618: }
9619: return $course;
9620: }
9621:
9622: ###############################################
9623:
9624: =pod
9625:
1.542 raeburn 9626: =item * &check_user_status()
1.274 raeburn 9627:
9628: Determines current status of supplied role for a
9629: specific user. Roles can be active, previous or future.
9630:
9631: Inputs:
9632: user's domain, user's username, course's domain,
1.375 raeburn 9633: course's number, optional section ID.
1.274 raeburn 9634:
9635: Outputs:
9636: role status: active, previous or future.
9637:
9638: =cut
9639:
9640: sub check_user_status {
1.412 raeburn 9641: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9642: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9643: my @uroles = keys(%userinfo);
1.274 raeburn 9644: my $srchstr;
9645: my $active_chk = 'none';
1.412 raeburn 9646: my $now = time;
1.274 raeburn 9647: if (@uroles > 0) {
1.908 raeburn 9648: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9649: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9650: } else {
1.412 raeburn 9651: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9652: }
9653: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9654: my $role_end = 0;
9655: my $role_start = 0;
9656: $active_chk = 'active';
1.412 raeburn 9657: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9658: $role_end = $1;
9659: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9660: $role_start = $1;
1.274 raeburn 9661: }
9662: }
9663: if ($role_start > 0) {
1.412 raeburn 9664: if ($now < $role_start) {
1.274 raeburn 9665: $active_chk = 'future';
9666: }
9667: }
9668: if ($role_end > 0) {
1.412 raeburn 9669: if ($now > $role_end) {
1.274 raeburn 9670: $active_chk = 'previous';
9671: }
9672: }
9673: }
9674: }
9675: return $active_chk;
9676: }
9677:
9678: ###############################################
9679:
9680: =pod
9681:
1.405 albertel 9682: =item * &get_sections()
1.233 raeburn 9683:
9684: Determines all the sections for a course including
9685: sections with students and sections containing other roles.
1.419 raeburn 9686: Incoming parameters:
9687:
9688: 1. domain
9689: 2. course number
9690: 3. reference to array containing roles for which sections should
9691: be gathered (optional).
9692: 4. reference to array containing status types for which sections
9693: should be gathered (optional).
9694:
9695: If the third argument is undefined, sections are gathered for any role.
9696: If the fourth argument is undefined, sections are gathered for any status.
9697: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9698:
1.374 raeburn 9699: Returns section hash (keys are section IDs, values are
9700: number of users in each section), subject to the
1.419 raeburn 9701: optional roles filter, optional status filter
1.233 raeburn 9702:
9703: =cut
9704:
9705: ###############################################
9706: sub get_sections {
1.419 raeburn 9707: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9708: if (!defined($cdom) || !defined($cnum)) {
9709: my $cid = $env{'request.course.id'};
9710:
9711: return if (!defined($cid));
9712:
9713: $cdom = $env{'course.'.$cid.'.domain'};
9714: $cnum = $env{'course.'.$cid.'.num'};
9715: }
9716:
9717: my %sectioncount;
1.419 raeburn 9718: my $now = time;
1.240 albertel 9719:
1.1118 raeburn 9720: my $check_students = 1;
9721: my $only_students = 0;
9722: if (ref($possible_roles) eq 'ARRAY') {
9723: if (grep(/^st$/,@{$possible_roles})) {
9724: if (@{$possible_roles} == 1) {
9725: $only_students = 1;
9726: }
9727: } else {
9728: $check_students = 0;
9729: }
9730: }
9731:
9732: if ($check_students) {
1.276 albertel 9733: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9734: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9735: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9736: my $start_index = &Apache::loncoursedata::CL_START();
9737: my $end_index = &Apache::loncoursedata::CL_END();
9738: my $status;
1.366 albertel 9739: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9740: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9741: $data->[$status_index],
9742: $data->[$start_index],
9743: $data->[$end_index]);
9744: if ($stu_status eq 'Active') {
9745: $status = 'active';
9746: } elsif ($end < $now) {
9747: $status = 'previous';
9748: } elsif ($start > $now) {
9749: $status = 'future';
9750: }
9751: if ($section ne '-1' && $section !~ /^\s*$/) {
9752: if ((!defined($possible_status)) || (($status ne '') &&
9753: (grep/^\Q$status\E$/,@{$possible_status}))) {
9754: $sectioncount{$section}++;
9755: }
1.240 albertel 9756: }
9757: }
9758: }
1.1118 raeburn 9759: if ($only_students) {
9760: return %sectioncount;
9761: }
1.240 albertel 9762: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9763: foreach my $user (sort(keys(%courseroles))) {
9764: if ($user !~ /^(\w{2})/) { next; }
9765: my ($role) = ($user =~ /^(\w{2})/);
9766: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9767: my ($section,$status);
1.240 albertel 9768: if ($role eq 'cr' &&
9769: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9770: $section=$1;
9771: }
9772: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9773: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9774: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9775: if ($end == -1 && $start == -1) {
9776: next; #deleted role
9777: }
9778: if (!defined($possible_status)) {
9779: $sectioncount{$section}++;
9780: } else {
9781: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9782: $status = 'active';
9783: } elsif ($end < $now) {
9784: $status = 'future';
9785: } elsif ($start > $now) {
9786: $status = 'previous';
9787: }
9788: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9789: $sectioncount{$section}++;
9790: }
9791: }
1.233 raeburn 9792: }
1.366 albertel 9793: return %sectioncount;
1.233 raeburn 9794: }
9795:
1.274 raeburn 9796: ###############################################
1.294 raeburn 9797:
9798: =pod
1.405 albertel 9799:
9800: =item * &get_course_users()
9801:
1.275 raeburn 9802: Retrieves usernames:domains for users in the specified course
9803: with specific role(s), and access status.
9804:
9805: Incoming parameters:
1.277 albertel 9806: 1. course domain
9807: 2. course number
9808: 3. access status: users must have - either active,
1.275 raeburn 9809: previous, future, or all.
1.277 albertel 9810: 4. reference to array of permissible roles
1.288 raeburn 9811: 5. reference to array of section restrictions (optional)
9812: 6. reference to results object (hash of hashes).
9813: 7. reference to optional userdata hash
1.609 raeburn 9814: 8. reference to optional statushash
1.630 raeburn 9815: 9. flag if privileged users (except those set to unhide in
9816: course settings) should be excluded
1.609 raeburn 9817: Keys of top level results hash are roles.
1.275 raeburn 9818: Keys of inner hashes are username:domain, with
9819: values set to access type.
1.288 raeburn 9820: Optional userdata hash returns an array with arguments in the
9821: same order as loncoursedata::get_classlist() for student data.
9822:
1.609 raeburn 9823: Optional statushash returns
9824:
1.288 raeburn 9825: Entries for end, start, section and status are blank because
9826: of the possibility of multiple values for non-student roles.
9827:
1.275 raeburn 9828: =cut
1.405 albertel 9829:
1.275 raeburn 9830: ###############################################
1.405 albertel 9831:
1.275 raeburn 9832: sub get_course_users {
1.630 raeburn 9833: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9834: my %idx = ();
1.419 raeburn 9835: my %seclists;
1.288 raeburn 9836:
9837: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9838: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9839: $idx{end} = &Apache::loncoursedata::CL_END();
9840: $idx{start} = &Apache::loncoursedata::CL_START();
9841: $idx{id} = &Apache::loncoursedata::CL_ID();
9842: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9843: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9844: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9845:
1.290 albertel 9846: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9847: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9848: my $now = time;
1.277 albertel 9849: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9850: my $match = 0;
1.412 raeburn 9851: my $secmatch = 0;
1.419 raeburn 9852: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9853: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9854: if ($section eq '') {
9855: $section = 'none';
9856: }
1.291 albertel 9857: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9858: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9859: $secmatch = 1;
9860: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9861: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9862: $secmatch = 1;
9863: }
9864: } else {
1.419 raeburn 9865: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9866: $secmatch = 1;
9867: }
1.290 albertel 9868: }
1.412 raeburn 9869: if (!$secmatch) {
9870: next;
9871: }
1.419 raeburn 9872: }
1.275 raeburn 9873: if (defined($$types{'active'})) {
1.288 raeburn 9874: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9875: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9876: $match = 1;
1.275 raeburn 9877: }
9878: }
9879: if (defined($$types{'previous'})) {
1.609 raeburn 9880: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9881: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9882: $match = 1;
1.275 raeburn 9883: }
9884: }
9885: if (defined($$types{'future'})) {
1.609 raeburn 9886: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9887: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9888: $match = 1;
1.275 raeburn 9889: }
9890: }
1.609 raeburn 9891: if ($match) {
9892: push(@{$seclists{$student}},$section);
9893: if (ref($userdata) eq 'HASH') {
9894: $$userdata{$student} = $$classlist{$student};
9895: }
9896: if (ref($statushash) eq 'HASH') {
9897: $statushash->{$student}{'st'}{$section} = $status;
9898: }
1.288 raeburn 9899: }
1.275 raeburn 9900: }
9901: }
1.412 raeburn 9902: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9903: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9904: my $now = time;
1.609 raeburn 9905: my %displaystatus = ( previous => 'Expired',
9906: active => 'Active',
9907: future => 'Future',
9908: );
1.1121 raeburn 9909: my (%nothide,@possdoms);
1.630 raeburn 9910: if ($hidepriv) {
9911: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9912: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9913: if ($user !~ /:/) {
9914: $nothide{join(':',split(/[\@]/,$user))}=1;
9915: } else {
9916: $nothide{$user} = 1;
9917: }
9918: }
1.1121 raeburn 9919: my @possdoms = ($cdom);
9920: if ($coursehash{'checkforpriv'}) {
9921: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9922: }
1.630 raeburn 9923: }
1.439 raeburn 9924: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9925: my $match = 0;
1.412 raeburn 9926: my $secmatch = 0;
1.439 raeburn 9927: my $status;
1.412 raeburn 9928: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9929: $user =~ s/:$//;
1.439 raeburn 9930: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9931: if ($end == -1 || $start == -1) {
9932: next;
9933: }
9934: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9935: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9936: my ($uname,$udom) = split(/:/,$user);
9937: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9938: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9939: $secmatch = 1;
9940: } elsif ($usec eq '') {
1.420 albertel 9941: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9942: $secmatch = 1;
9943: }
9944: } else {
9945: if (grep(/^\Q$usec\E$/,@{$sections})) {
9946: $secmatch = 1;
9947: }
9948: }
9949: if (!$secmatch) {
9950: next;
9951: }
1.288 raeburn 9952: }
1.419 raeburn 9953: if ($usec eq '') {
9954: $usec = 'none';
9955: }
1.275 raeburn 9956: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9957: if ($hidepriv) {
1.1121 raeburn 9958: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9959: (!$nothide{$uname.':'.$udom})) {
9960: next;
9961: }
9962: }
1.503 raeburn 9963: if ($end > 0 && $end < $now) {
1.439 raeburn 9964: $status = 'previous';
9965: } elsif ($start > $now) {
9966: $status = 'future';
9967: } else {
9968: $status = 'active';
9969: }
1.277 albertel 9970: foreach my $type (keys(%{$types})) {
1.275 raeburn 9971: if ($status eq $type) {
1.420 albertel 9972: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9973: push(@{$$users{$role}{$user}},$type);
9974: }
1.288 raeburn 9975: $match = 1;
9976: }
9977: }
1.419 raeburn 9978: if (($match) && (ref($userdata) eq 'HASH')) {
9979: if (!exists($$userdata{$uname.':'.$udom})) {
9980: &get_user_info($udom,$uname,\%idx,$userdata);
9981: }
1.420 albertel 9982: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9983: push(@{$seclists{$uname.':'.$udom}},$usec);
9984: }
1.609 raeburn 9985: if (ref($statushash) eq 'HASH') {
9986: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9987: }
1.275 raeburn 9988: }
9989: }
9990: }
9991: }
1.290 albertel 9992: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9993: if ((defined($cdom)) && (defined($cnum))) {
9994: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9995: if ( defined($csettings{'internal.courseowner'}) ) {
9996: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9997: next if ($owner eq '');
9998: my ($ownername,$ownerdom);
9999: if ($owner =~ /^([^:]+):([^:]+)$/) {
10000: $ownername = $1;
10001: $ownerdom = $2;
10002: } else {
10003: $ownername = $owner;
10004: $ownerdom = $cdom;
10005: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10006: }
10007: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10008: if (defined($userdata) &&
1.609 raeburn 10009: !exists($$userdata{$owner})) {
10010: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10011: if (!grep(/^none$/,@{$seclists{$owner}})) {
10012: push(@{$seclists{$owner}},'none');
10013: }
10014: if (ref($statushash) eq 'HASH') {
10015: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10016: }
1.290 albertel 10017: }
1.279 raeburn 10018: }
10019: }
10020: }
1.419 raeburn 10021: foreach my $user (keys(%seclists)) {
10022: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10023: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10024: }
1.275 raeburn 10025: }
10026: return;
10027: }
10028:
1.288 raeburn 10029: sub get_user_info {
10030: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10031: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10032: &plainname($uname,$udom,'lastname');
1.291 albertel 10033: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10034: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10035: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10036: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10037: return;
10038: }
1.275 raeburn 10039:
1.472 raeburn 10040: ###############################################
10041:
10042: =pod
10043:
10044: =item * &get_user_quota()
10045:
1.1134 raeburn 10046: Retrieves quota assigned for storage of user files.
10047: Default is to report quota for portfolio files.
1.472 raeburn 10048:
10049: Incoming parameters:
10050: 1. user's username
10051: 2. user's domain
1.1134 raeburn 10052: 3. quota name - portfolio, author, or course
1.1136 raeburn 10053: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 10054: 4. crstype - official, unofficial, textbook, placement or community,
10055: if quota name is course
1.472 raeburn 10056:
10057: Returns:
1.1163 raeburn 10058: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10059: 2. (Optional) Type of setting: custom or default
10060: (individually assigned or default for user's
10061: institutional status).
10062: 3. (Optional) - User's institutional status (e.g., faculty, staff
10063: or student - types as defined in localenroll::inst_usertypes
10064: for user's domain, which determines default quota for user.
10065: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10066:
10067: If a value has been stored in the user's environment,
1.536 raeburn 10068: it will return that, otherwise it returns the maximal default
1.1134 raeburn 10069: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10070:
10071: =cut
10072:
10073: ###############################################
10074:
10075:
10076: sub get_user_quota {
1.1136 raeburn 10077: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10078: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10079: if (!defined($udom)) {
10080: $udom = $env{'user.domain'};
10081: }
10082: if (!defined($uname)) {
10083: $uname = $env{'user.name'};
10084: }
10085: if (($udom eq '' || $uname eq '') ||
10086: ($udom eq 'public') && ($uname eq 'public')) {
10087: $quota = 0;
1.536 raeburn 10088: $quotatype = 'default';
10089: $defquota = 0;
1.472 raeburn 10090: } else {
1.536 raeburn 10091: my $inststatus;
1.1134 raeburn 10092: if ($quotaname eq 'course') {
10093: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10094: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10095: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10096: } else {
10097: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10098: $quota = $cenv{'internal.uploadquota'};
10099: }
1.536 raeburn 10100: } else {
1.1134 raeburn 10101: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10102: if ($quotaname eq 'author') {
10103: $quota = $env{'environment.authorquota'};
10104: } else {
10105: $quota = $env{'environment.portfolioquota'};
10106: }
10107: $inststatus = $env{'environment.inststatus'};
10108: } else {
10109: my %userenv =
10110: &Apache::lonnet::get('environment',['portfolioquota',
10111: 'authorquota','inststatus'],$udom,$uname);
10112: my ($tmp) = keys(%userenv);
10113: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10114: if ($quotaname eq 'author') {
10115: $quota = $userenv{'authorquota'};
10116: } else {
10117: $quota = $userenv{'portfolioquota'};
10118: }
10119: $inststatus = $userenv{'inststatus'};
10120: } else {
10121: undef(%userenv);
10122: }
10123: }
10124: }
10125: if ($quota eq '' || wantarray) {
10126: if ($quotaname eq 'course') {
10127: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 10128: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 10129: ($crstype eq 'community') || ($crstype eq 'textbook') ||
10130: ($crstype eq 'placement')) {
1.1136 raeburn 10131: $defquota = $domdefs{$crstype.'quota'};
10132: }
10133: if ($defquota eq '') {
10134: $defquota = 500;
10135: }
1.1134 raeburn 10136: } else {
10137: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10138: }
10139: if ($quota eq '') {
10140: $quota = $defquota;
10141: $quotatype = 'default';
10142: } else {
10143: $quotatype = 'custom';
10144: }
1.472 raeburn 10145: }
10146: }
1.536 raeburn 10147: if (wantarray) {
10148: return ($quota,$quotatype,$settingstatus,$defquota);
10149: } else {
10150: return $quota;
10151: }
1.472 raeburn 10152: }
10153:
10154: ###############################################
10155:
10156: =pod
10157:
10158: =item * &default_quota()
10159:
1.536 raeburn 10160: Retrieves default quota assigned for storage of user portfolio files,
10161: given an (optional) user's institutional status.
1.472 raeburn 10162:
10163: Incoming parameters:
1.1142 raeburn 10164:
1.472 raeburn 10165: 1. domain
1.536 raeburn 10166: 2. (Optional) institutional status(es). This is a : separated list of
10167: status types (e.g., faculty, staff, student etc.)
10168: which apply to the user for whom the default is being retrieved.
10169: If the institutional status string in undefined, the domain
1.1134 raeburn 10170: default quota will be returned.
10171: 3. quota name - portfolio, author, or course
10172: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10173:
10174: Returns:
1.1142 raeburn 10175:
1.1163 raeburn 10176: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10177: 2. (Optional) institutional type which determined the value of the
10178: default quota.
1.472 raeburn 10179:
10180: If a value has been stored in the domain's configuration db,
10181: it will return that, otherwise it returns 20 (for backwards
10182: compatibility with domains which have not set up a configuration
1.1163 raeburn 10183: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10184:
1.536 raeburn 10185: If the user's status includes multiple types (e.g., staff and student),
10186: the largest default quota which applies to the user determines the
10187: default quota returned.
10188:
1.472 raeburn 10189: =cut
10190:
10191: ###############################################
10192:
10193:
10194: sub default_quota {
1.1134 raeburn 10195: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10196: my ($defquota,$settingstatus);
10197: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10198: ['quotas'],$udom);
1.1134 raeburn 10199: my $key = 'defaultquota';
10200: if ($quotaname eq 'author') {
10201: $key = 'authorquota';
10202: }
1.622 raeburn 10203: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10204: if ($inststatus ne '') {
1.765 raeburn 10205: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10206: foreach my $item (@statuses) {
1.1134 raeburn 10207: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10208: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10209: if ($defquota eq '') {
1.1134 raeburn 10210: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10211: $settingstatus = $item;
1.1134 raeburn 10212: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10213: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10214: $settingstatus = $item;
10215: }
10216: }
1.1134 raeburn 10217: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10218: if ($quotahash{'quotas'}{$item} ne '') {
10219: if ($defquota eq '') {
10220: $defquota = $quotahash{'quotas'}{$item};
10221: $settingstatus = $item;
10222: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10223: $defquota = $quotahash{'quotas'}{$item};
10224: $settingstatus = $item;
10225: }
1.536 raeburn 10226: }
10227: }
10228: }
10229: }
10230: if ($defquota eq '') {
1.1134 raeburn 10231: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10232: $defquota = $quotahash{'quotas'}{$key}{'default'};
10233: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10234: $defquota = $quotahash{'quotas'}{'default'};
10235: }
1.536 raeburn 10236: $settingstatus = 'default';
1.1139 raeburn 10237: if ($defquota eq '') {
10238: if ($quotaname eq 'author') {
10239: $defquota = 500;
10240: }
10241: }
1.536 raeburn 10242: }
10243: } else {
10244: $settingstatus = 'default';
1.1134 raeburn 10245: if ($quotaname eq 'author') {
10246: $defquota = 500;
10247: } else {
10248: $defquota = 20;
10249: }
1.536 raeburn 10250: }
10251: if (wantarray) {
10252: return ($defquota,$settingstatus);
1.472 raeburn 10253: } else {
1.536 raeburn 10254: return $defquota;
1.472 raeburn 10255: }
10256: }
10257:
1.1135 raeburn 10258: ###############################################
10259:
10260: =pod
10261:
1.1136 raeburn 10262: =item * &excess_filesize_warning()
1.1135 raeburn 10263:
10264: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 10265: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 10266: space to be exceeded.
1.1136 raeburn 10267:
10268: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 10269: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 10270:
1.1165 raeburn 10271: Inputs: 7
1.1136 raeburn 10272: 1. username or coursenum
1.1135 raeburn 10273: 2. domain
1.1136 raeburn 10274: 3. context ('author' or 'course')
1.1135 raeburn 10275: 4. filename of file for which action is being requested
10276: 5. filesize (kB) of file
10277: 6. action being taken: copy or upload.
1.1237 raeburn 10278: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 10279:
10280: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 10281: otherwise return null.
10282:
10283: =back
1.1135 raeburn 10284:
10285: =cut
10286:
1.1136 raeburn 10287: sub excess_filesize_warning {
1.1165 raeburn 10288: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 10289: my $current_disk_usage = 0;
1.1165 raeburn 10290: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 10291: if ($context eq 'author') {
10292: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10293: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10294: } else {
10295: foreach my $subdir ('docs','supplemental') {
10296: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10297: }
10298: }
1.1135 raeburn 10299: $disk_quota = int($disk_quota * 1000);
10300: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 10301: return '<p class="LC_warning">'.
1.1135 raeburn 10302: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 10303: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10304: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 10305: $disk_quota,$current_disk_usage).
10306: '</p>';
10307: }
10308: return;
10309: }
10310:
10311: ###############################################
10312:
10313:
1.1136 raeburn 10314:
10315:
1.384 raeburn 10316: sub get_secgrprole_info {
10317: my ($cdom,$cnum,$needroles,$type) = @_;
10318: my %sections_count = &get_sections($cdom,$cnum);
10319: my @sections = (sort {$a <=> $b} keys(%sections_count));
10320: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10321: my @groups = sort(keys(%curr_groups));
10322: my $allroles = [];
10323: my $rolehash;
10324: my $accesshash = {
10325: active => 'Currently has access',
10326: future => 'Will have future access',
10327: previous => 'Previously had access',
10328: };
10329: if ($needroles) {
10330: $rolehash = {'all' => 'all'};
1.385 albertel 10331: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10332: if (&Apache::lonnet::error(%user_roles)) {
10333: undef(%user_roles);
10334: }
10335: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10336: my ($role)=split(/\:/,$item,2);
10337: if ($role eq 'cr') { next; }
10338: if ($role =~ /^cr/) {
10339: $$rolehash{$role} = (split('/',$role))[3];
10340: } else {
10341: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10342: }
10343: }
10344: foreach my $key (sort(keys(%{$rolehash}))) {
10345: push(@{$allroles},$key);
10346: }
10347: push (@{$allroles},'st');
10348: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10349: }
10350: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10351: }
10352:
1.555 raeburn 10353: sub user_picker {
1.1279 raeburn 10354: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10355: my $currdom = $dom;
1.1253 raeburn 10356: my @alldoms = &Apache::lonnet::all_domains();
10357: if (@alldoms == 1) {
10358: my %domsrch = &Apache::lonnet::get_dom('configuration',
10359: ['directorysrch'],$alldoms[0]);
10360: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10361: my $showdom = $domdesc;
10362: if ($showdom eq '') {
10363: $showdom = $dom;
10364: }
10365: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10366: if ((!$domsrch{'directorysrch'}{'available'}) &&
10367: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10368: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10369: }
10370: }
10371: }
1.555 raeburn 10372: my %curr_selected = (
10373: srchin => 'dom',
1.580 raeburn 10374: srchby => 'lastname',
1.555 raeburn 10375: );
10376: my $srchterm;
1.625 raeburn 10377: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10378: if ($srch->{'srchby'} ne '') {
10379: $curr_selected{'srchby'} = $srch->{'srchby'};
10380: }
10381: if ($srch->{'srchin'} ne '') {
10382: $curr_selected{'srchin'} = $srch->{'srchin'};
10383: }
10384: if ($srch->{'srchtype'} ne '') {
10385: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10386: }
10387: if ($srch->{'srchdomain'} ne '') {
10388: $currdom = $srch->{'srchdomain'};
10389: }
10390: $srchterm = $srch->{'srchterm'};
10391: }
1.1222 damieng 10392: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10393: 'usr' => 'Search criteria',
1.563 raeburn 10394: 'doma' => 'Domain/institution to search',
1.558 albertel 10395: 'uname' => 'username',
10396: 'lastname' => 'last name',
1.555 raeburn 10397: 'lastfirst' => 'last name, first name',
1.558 albertel 10398: 'crs' => 'in this course',
1.576 raeburn 10399: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10400: 'alc' => 'all LON-CAPA',
1.573 raeburn 10401: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10402: 'exact' => 'is',
10403: 'contains' => 'contains',
1.569 raeburn 10404: 'begins' => 'begins with',
1.1222 damieng 10405: );
10406: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10407: 'youm' => "You must include some text to search for.",
10408: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10409: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10410: 'yomc' => "You must choose a domain when using an institutional directory search.",
10411: 'ymcd' => "You must choose a domain when using a domain search.",
10412: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10413: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10414: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10415: );
1.1222 damieng 10416: &html_escape(\%html_lt);
10417: &js_escape(\%js_lt);
1.1255 raeburn 10418: my $domform;
1.1277 raeburn 10419: my $allow_blank = 1;
1.1255 raeburn 10420: if ($fixeddom) {
1.1277 raeburn 10421: $allow_blank = 0;
10422: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 10423: } else {
1.1287 raeburn 10424: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 10425: my ($trusted,$untrusted);
1.1287 raeburn 10426: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 10427: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 10428: } elsif ($context eq 'author') {
1.1288 raeburn 10429: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 10430: } elsif ($context eq 'domain') {
1.1288 raeburn 10431: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 10432: }
1.1288 raeburn 10433: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 10434: }
1.563 raeburn 10435: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10436:
10437: my @srchins = ('crs','dom','alc','instd');
10438:
10439: foreach my $option (@srchins) {
10440: # FIXME 'alc' option unavailable until
10441: # loncreateuser::print_user_query_page()
10442: # has been completed.
10443: next if ($option eq 'alc');
1.880 raeburn 10444: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10445: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 10446: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10447: if ($curr_selected{'srchin'} eq $option) {
10448: $srchinsel .= '
1.1222 damieng 10449: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10450: } else {
10451: $srchinsel .= '
1.1222 damieng 10452: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10453: }
1.555 raeburn 10454: }
1.563 raeburn 10455: $srchinsel .= "\n </select>\n";
1.555 raeburn 10456:
10457: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10458: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10459: if ($curr_selected{'srchby'} eq $option) {
10460: $srchbysel .= '
1.1222 damieng 10461: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10462: } else {
10463: $srchbysel .= '
1.1222 damieng 10464: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10465: }
10466: }
10467: $srchbysel .= "\n </select>\n";
10468:
10469: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10470: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10471: if ($curr_selected{'srchtype'} eq $option) {
10472: $srchtypesel .= '
1.1222 damieng 10473: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10474: } else {
10475: $srchtypesel .= '
1.1222 damieng 10476: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10477: }
10478: }
10479: $srchtypesel .= "\n </select>\n";
10480:
1.558 albertel 10481: my ($newuserscript,$new_user_create);
1.994 raeburn 10482: my $context_dom = $env{'request.role.domain'};
10483: if ($context eq 'requestcrs') {
10484: if ($env{'form.coursedom'} ne '') {
10485: $context_dom = $env{'form.coursedom'};
10486: }
10487: }
1.556 raeburn 10488: if ($forcenewuser) {
1.576 raeburn 10489: if (ref($srch) eq 'HASH') {
1.994 raeburn 10490: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10491: if ($cancreate) {
10492: $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>';
10493: } else {
1.799 bisitz 10494: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10495: my %usertypetext = (
10496: official => 'institutional',
10497: unofficial => 'non-institutional',
10498: );
1.799 bisitz 10499: $new_user_create = '<p class="LC_warning">'
10500: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10501: .' '
10502: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10503: ,'<a href="'.$helplink.'">','</a>')
10504: .'</p><br />';
1.627 raeburn 10505: }
1.576 raeburn 10506: }
10507: }
10508:
1.556 raeburn 10509: $newuserscript = <<"ENDSCRIPT";
10510:
1.570 raeburn 10511: function setSearch(createnew,callingForm) {
1.556 raeburn 10512: if (createnew == 1) {
1.570 raeburn 10513: for (var i=0; i<callingForm.srchby.length; i++) {
10514: if (callingForm.srchby.options[i].value == 'uname') {
10515: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10516: }
10517: }
1.570 raeburn 10518: for (var i=0; i<callingForm.srchin.length; i++) {
10519: if ( callingForm.srchin.options[i].value == 'dom') {
10520: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10521: }
10522: }
1.570 raeburn 10523: for (var i=0; i<callingForm.srchtype.length; i++) {
10524: if (callingForm.srchtype.options[i].value == 'exact') {
10525: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10526: }
10527: }
1.570 raeburn 10528: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10529: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10530: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10531: }
10532: }
10533: }
10534: }
10535: ENDSCRIPT
1.558 albertel 10536:
1.556 raeburn 10537: }
10538:
1.555 raeburn 10539: my $output = <<"END_BLOCK";
1.556 raeburn 10540: <script type="text/javascript">
1.824 bisitz 10541: // <![CDATA[
1.570 raeburn 10542: function validateEntry(callingForm) {
1.558 albertel 10543:
1.556 raeburn 10544: var checkok = 1;
1.558 albertel 10545: var srchin;
1.570 raeburn 10546: for (var i=0; i<callingForm.srchin.length; i++) {
10547: if ( callingForm.srchin[i].checked ) {
10548: srchin = callingForm.srchin[i].value;
1.558 albertel 10549: }
10550: }
10551:
1.570 raeburn 10552: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10553: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10554: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10555: var srchterm = callingForm.srchterm.value;
10556: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10557: var msg = "";
10558:
10559: if (srchterm == "") {
10560: checkok = 0;
1.1222 damieng 10561: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10562: }
10563:
1.569 raeburn 10564: if (srchtype== 'begins') {
10565: if (srchterm.length < 2) {
10566: checkok = 0;
1.1222 damieng 10567: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10568: }
10569: }
10570:
1.556 raeburn 10571: if (srchtype== 'contains') {
10572: if (srchterm.length < 3) {
10573: checkok = 0;
1.1222 damieng 10574: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10575: }
10576: }
10577: if (srchin == 'instd') {
10578: if (srchdomain == '') {
10579: checkok = 0;
1.1222 damieng 10580: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10581: }
10582: }
10583: if (srchin == 'dom') {
10584: if (srchdomain == '') {
10585: checkok = 0;
1.1222 damieng 10586: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10587: }
10588: }
10589: if (srchby == 'lastfirst') {
10590: if (srchterm.indexOf(",") == -1) {
10591: checkok = 0;
1.1222 damieng 10592: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10593: }
10594: if (srchterm.indexOf(",") == srchterm.length -1) {
10595: checkok = 0;
1.1222 damieng 10596: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10597: }
10598: }
10599: if (checkok == 0) {
1.1222 damieng 10600: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10601: return;
10602: }
10603: if (checkok == 1) {
1.570 raeburn 10604: callingForm.submit();
1.556 raeburn 10605: }
10606: }
10607:
10608: $newuserscript
10609:
1.824 bisitz 10610: // ]]>
1.556 raeburn 10611: </script>
1.558 albertel 10612:
10613: $new_user_create
10614:
1.555 raeburn 10615: END_BLOCK
1.558 albertel 10616:
1.876 raeburn 10617: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10618: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10619: $domform.
10620: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10621: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10622: $srchbysel.
10623: $srchtypesel.
10624: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10625: $srchinsel.
10626: &Apache::lonhtmlcommon::row_closure(1).
10627: &Apache::lonhtmlcommon::end_pick_box().
10628: '<br />';
1.1253 raeburn 10629: return ($output,1);
1.555 raeburn 10630: }
10631:
1.612 raeburn 10632: sub user_rule_check {
1.615 raeburn 10633: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10634: my ($response,%inst_response);
1.612 raeburn 10635: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10636: if (keys(%{$usershash}) > 1) {
10637: my (%by_username,%by_id,%userdoms);
10638: my $checkid;
10639: if (ref($checks) eq 'HASH') {
10640: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10641: $checkid = 1;
10642: }
10643: }
10644: foreach my $user (keys(%{$usershash})) {
10645: my ($uname,$udom) = split(/:/,$user);
10646: if ($checkid) {
10647: if (ref($usershash->{$user}) eq 'HASH') {
10648: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10649: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10650: $userdoms{$udom} = 1;
1.1227 raeburn 10651: if (ref($inst_results) eq 'HASH') {
10652: $inst_results->{$uname.':'.$udom} = {};
10653: }
1.1226 raeburn 10654: }
10655: }
10656: } else {
10657: $by_username{$udom}{$uname} = 1;
10658: $userdoms{$udom} = 1;
1.1227 raeburn 10659: if (ref($inst_results) eq 'HASH') {
10660: $inst_results->{$uname.':'.$udom} = {};
10661: }
1.1226 raeburn 10662: }
10663: }
10664: foreach my $udom (keys(%userdoms)) {
10665: if (!$got_rules->{$udom}) {
10666: my %domconfig = &Apache::lonnet::get_dom('configuration',
10667: ['usercreation'],$udom);
10668: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10669: foreach my $item ('username','id') {
10670: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10671: $$curr_rules{$udom}{$item} =
10672: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10673: }
10674: }
10675: }
10676: $got_rules->{$udom} = 1;
10677: }
1.612 raeburn 10678: }
1.1226 raeburn 10679: if ($checkid) {
10680: foreach my $udom (keys(%by_id)) {
10681: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10682: if ($outcome eq 'ok') {
1.1227 raeburn 10683: foreach my $id (keys(%{$by_id{$udom}})) {
10684: my $uname = $by_id{$udom}{$id};
10685: $inst_response{$uname.':'.$udom} = $outcome;
10686: }
1.1226 raeburn 10687: if (ref($results) eq 'HASH') {
10688: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10689: if (exists($inst_response{$uname.':'.$udom})) {
10690: $inst_response{$uname.':'.$udom} = $outcome;
10691: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10692: }
1.1226 raeburn 10693: }
10694: }
10695: }
1.612 raeburn 10696: }
1.615 raeburn 10697: } else {
1.1226 raeburn 10698: foreach my $udom (keys(%by_username)) {
10699: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10700: if ($outcome eq 'ok') {
1.1227 raeburn 10701: foreach my $uname (keys(%{$by_username{$udom}})) {
10702: $inst_response{$uname.':'.$udom} = $outcome;
10703: }
1.1226 raeburn 10704: if (ref($results) eq 'HASH') {
10705: foreach my $uname (keys(%{$results})) {
10706: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10707: }
10708: }
10709: }
10710: }
1.612 raeburn 10711: }
1.1226 raeburn 10712: } elsif (keys(%{$usershash}) == 1) {
10713: my $user = (keys(%{$usershash}))[0];
10714: my ($uname,$udom) = split(/:/,$user);
10715: if (($udom ne '') && ($uname ne '')) {
10716: if (ref($usershash->{$user}) eq 'HASH') {
10717: if (ref($checks) eq 'HASH') {
10718: if (defined($checks->{'username'})) {
10719: ($inst_response{$user},%{$inst_results->{$user}}) =
10720: &Apache::lonnet::get_instuser($udom,$uname);
10721: } elsif (defined($checks->{'id'})) {
10722: if ($usershash->{$user}->{'id'} ne '') {
10723: ($inst_response{$user},%{$inst_results->{$user}}) =
10724: &Apache::lonnet::get_instuser($udom,undef,
10725: $usershash->{$user}->{'id'});
10726: } else {
10727: ($inst_response{$user},%{$inst_results->{$user}}) =
10728: &Apache::lonnet::get_instuser($udom,$uname);
10729: }
1.585 raeburn 10730: }
1.1226 raeburn 10731: } else {
10732: ($inst_response{$user},%{$inst_results->{$user}}) =
10733: &Apache::lonnet::get_instuser($udom,$uname);
10734: return;
10735: }
10736: if (!$got_rules->{$udom}) {
10737: my %domconfig = &Apache::lonnet::get_dom('configuration',
10738: ['usercreation'],$udom);
10739: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10740: foreach my $item ('username','id') {
10741: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10742: $$curr_rules{$udom}{$item} =
10743: $domconfig{'usercreation'}{$item.'_rule'};
10744: }
10745: }
10746: }
10747: $got_rules->{$udom} = 1;
1.585 raeburn 10748: }
10749: }
1.1226 raeburn 10750: } else {
10751: return;
10752: }
10753: } else {
10754: return;
10755: }
10756: foreach my $user (keys(%{$usershash})) {
10757: my ($uname,$udom) = split(/:/,$user);
10758: next if (($udom eq '') || ($uname eq ''));
10759: my $id;
1.1227 raeburn 10760: if (ref($inst_results) eq 'HASH') {
10761: if (ref($inst_results->{$user}) eq 'HASH') {
10762: $id = $inst_results->{$user}->{'id'};
10763: }
10764: }
10765: if ($id eq '') {
10766: if (ref($usershash->{$user})) {
10767: $id = $usershash->{$user}->{'id'};
10768: }
1.585 raeburn 10769: }
1.612 raeburn 10770: foreach my $item (keys(%{$checks})) {
10771: if (ref($$curr_rules{$udom}) eq 'HASH') {
10772: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10773: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10774: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10775: $$curr_rules{$udom}{$item});
1.612 raeburn 10776: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10777: if ($rule_check{$rule}) {
10778: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10779: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10780: if (ref($inst_results) eq 'HASH') {
10781: if (ref($inst_results->{$user}) eq 'HASH') {
10782: if (keys(%{$inst_results->{$user}}) == 0) {
10783: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10784: } elsif ($item eq 'id') {
10785: if ($inst_results->{$user}->{'id'} eq '') {
10786: $$alerts{$item}{$udom}{$uname} = 1;
10787: }
1.615 raeburn 10788: }
1.612 raeburn 10789: }
10790: }
1.615 raeburn 10791: }
10792: last;
1.585 raeburn 10793: }
10794: }
10795: }
10796: }
10797: }
10798: }
10799: }
10800: }
1.612 raeburn 10801: return;
10802: }
10803:
10804: sub user_rule_formats {
10805: my ($domain,$domdesc,$curr_rules,$check) = @_;
10806: my %text = (
10807: 'username' => 'Usernames',
10808: 'id' => 'IDs',
10809: );
10810: my $output;
10811: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10812: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10813: if (@{$ruleorder} > 0) {
1.1102 raeburn 10814: $output = '<br />'.
10815: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10816: '<span class="LC_cusr_emph">','</span>',$domdesc).
10817: ' <ul>';
1.612 raeburn 10818: foreach my $rule (@{$ruleorder}) {
10819: if (ref($curr_rules) eq 'ARRAY') {
10820: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10821: if (ref($rules->{$rule}) eq 'HASH') {
10822: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10823: $rules->{$rule}{'desc'}.'</li>';
10824: }
10825: }
10826: }
10827: }
10828: $output .= '</ul>';
10829: }
10830: }
10831: return $output;
10832: }
10833:
10834: sub instrule_disallow_msg {
1.615 raeburn 10835: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10836: my $response;
10837: my %text = (
10838: item => 'username',
10839: items => 'usernames',
10840: match => 'matches',
10841: do => 'does',
10842: action => 'a username',
10843: one => 'one',
10844: );
10845: if ($count > 1) {
10846: $text{'item'} = 'usernames';
10847: $text{'match'} ='match';
10848: $text{'do'} = 'do';
10849: $text{'action'} = 'usernames',
10850: $text{'one'} = 'ones';
10851: }
10852: if ($checkitem eq 'id') {
10853: $text{'items'} = 'IDs';
10854: $text{'item'} = 'ID';
10855: $text{'action'} = 'an ID';
1.615 raeburn 10856: if ($count > 1) {
10857: $text{'item'} = 'IDs';
10858: $text{'action'} = 'IDs';
10859: }
1.612 raeburn 10860: }
1.674 bisitz 10861: $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 10862: if ($mode eq 'upload') {
10863: if ($checkitem eq 'username') {
10864: $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'}.");
10865: } elsif ($checkitem eq 'id') {
1.674 bisitz 10866: $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 10867: }
1.669 raeburn 10868: } elsif ($mode eq 'selfcreate') {
10869: if ($checkitem eq 'id') {
10870: $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.");
10871: }
1.615 raeburn 10872: } else {
10873: if ($checkitem eq 'username') {
10874: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10875: } elsif ($checkitem eq 'id') {
10876: $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.");
10877: }
1.612 raeburn 10878: }
10879: return $response;
1.585 raeburn 10880: }
10881:
1.624 raeburn 10882: sub personal_data_fieldtitles {
10883: my %fieldtitles = &Apache::lonlocal::texthash (
10884: id => 'Student/Employee ID',
10885: permanentemail => 'E-mail address',
10886: lastname => 'Last Name',
10887: firstname => 'First Name',
10888: middlename => 'Middle Name',
10889: generation => 'Generation',
10890: gen => 'Generation',
1.765 raeburn 10891: inststatus => 'Affiliation',
1.624 raeburn 10892: );
10893: return %fieldtitles;
10894: }
10895:
1.642 raeburn 10896: sub sorted_inst_types {
10897: my ($dom) = @_;
1.1185 raeburn 10898: my ($usertypes,$order);
10899: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10900: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10901: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10902: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10903: } else {
10904: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10905: }
1.642 raeburn 10906: my $othertitle = &mt('All users');
10907: if ($env{'request.course.id'}) {
1.668 raeburn 10908: $othertitle = &mt('Any users');
1.642 raeburn 10909: }
10910: my @types;
10911: if (ref($order) eq 'ARRAY') {
10912: @types = @{$order};
10913: }
10914: if (@types == 0) {
10915: if (ref($usertypes) eq 'HASH') {
10916: @types = sort(keys(%{$usertypes}));
10917: }
10918: }
10919: if (keys(%{$usertypes}) > 0) {
10920: $othertitle = &mt('Other users');
10921: }
10922: return ($othertitle,$usertypes,\@types);
10923: }
10924:
1.645 raeburn 10925: sub get_institutional_codes {
10926: my ($settings,$allcourses,$LC_code) = @_;
10927: # Get complete list of course sections to update
10928: my @currsections = ();
10929: my @currxlists = ();
10930: my $coursecode = $$settings{'internal.coursecode'};
10931:
10932: if ($$settings{'internal.sectionnums'} ne '') {
10933: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10934: }
10935:
10936: if ($$settings{'internal.crosslistings'} ne '') {
10937: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10938: }
10939:
10940: if (@currxlists > 0) {
10941: foreach (@currxlists) {
10942: if (m/^([^:]+):(\w*)$/) {
10943: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 10944: push(@{$allcourses},$1);
1.645 raeburn 10945: $$LC_code{$1} = $2;
10946: }
10947: }
10948: }
10949: }
10950:
10951: if (@currsections > 0) {
10952: foreach (@currsections) {
10953: if (m/^(\w+):(\w*)$/) {
10954: my $sec = $coursecode.$1;
10955: my $lc_sec = $2;
10956: unless (grep/^$sec$/,@{$allcourses}) {
1.1263 raeburn 10957: push(@{$allcourses},$sec);
1.645 raeburn 10958: $$LC_code{$sec} = $lc_sec;
10959: }
10960: }
10961: }
10962: }
10963: return;
10964: }
10965:
1.971 raeburn 10966: sub get_standard_codeitems {
10967: return ('Year','Semester','Department','Number','Section');
10968: }
10969:
1.112 bowersj2 10970: =pod
10971:
1.780 raeburn 10972: =head1 Slot Helpers
10973:
10974: =over 4
10975:
10976: =item * sorted_slots()
10977:
1.1040 raeburn 10978: Sorts an array of slot names in order of an optional sort key,
10979: default sort is by slot start time (earliest first).
1.780 raeburn 10980:
10981: Inputs:
10982:
10983: =over 4
10984:
10985: slotsarr - Reference to array of unsorted slot names.
10986:
10987: slots - Reference to hash of hash, where outer hash keys are slot names.
10988:
1.1040 raeburn 10989: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10990:
1.549 albertel 10991: =back
10992:
1.780 raeburn 10993: Returns:
10994:
10995: =over 4
10996:
1.1040 raeburn 10997: sorted - An array of slot names sorted by a specified sort key
10998: (default sort key is start time of the slot).
1.780 raeburn 10999:
11000: =back
11001:
11002: =cut
11003:
11004:
11005: sub sorted_slots {
1.1040 raeburn 11006: my ($slotsarr,$slots,$sortkey) = @_;
11007: if ($sortkey eq '') {
11008: $sortkey = 'starttime';
11009: }
1.780 raeburn 11010: my @sorted;
11011: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11012: @sorted =
11013: sort {
11014: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11015: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11016: }
11017: if (ref($slots->{$a})) { return -1;}
11018: if (ref($slots->{$b})) { return 1;}
11019: return 0;
11020: } @{$slotsarr};
11021: }
11022: return @sorted;
11023: }
11024:
1.1040 raeburn 11025: =pod
11026:
11027: =item * get_future_slots()
11028:
11029: Inputs:
11030:
11031: =over 4
11032:
11033: cnum - course number
11034:
11035: cdom - course domain
11036:
11037: now - current UNIX time
11038:
11039: symb - optional symb
11040:
11041: =back
11042:
11043: Returns:
11044:
11045: =over 4
11046:
11047: sorted_reservable - ref to array of student_schedulable slots currently
11048: reservable, ordered by end date of reservation period.
11049:
11050: reservable_now - ref to hash of student_schedulable slots currently
11051: reservable.
11052:
11053: Keys in inner hash are:
11054: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11055: (b) endreserve: end date of reservation period.
11056: (c) uniqueperiod: start,end dates when slot is to be uniquely
11057: selected.
1.1040 raeburn 11058:
11059: sorted_future - ref to array of student_schedulable slots reservable in
11060: the future, ordered by start date of reservation period.
11061:
11062: future_reservable - ref to hash of student_schedulable slots reservable
11063: in the future.
11064:
11065: Keys in inner hash are:
11066: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11067: (b) startreserve: start date of reservation period.
11068: (c) uniqueperiod: start,end dates when slot is to be uniquely
11069: selected.
1.1040 raeburn 11070:
11071: =back
11072:
11073: =cut
11074:
11075: sub get_future_slots {
11076: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 11077: my $map;
11078: if ($symb) {
11079: ($map) = &Apache::lonnet::decode_symb($symb);
11080: }
1.1040 raeburn 11081: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11082: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11083: foreach my $slot (keys(%slots)) {
11084: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11085: if ($symb) {
1.1229 raeburn 11086: if ($slots{$slot}->{'symb'} ne '') {
11087: my $canuse;
11088: my %oksymbs;
11089: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
11090: map { $oksymbs{$_} = 1; } @slotsymbs;
11091: if ($oksymbs{$symb}) {
11092: $canuse = 1;
11093: } else {
11094: foreach my $item (@slotsymbs) {
11095: if ($item =~ /\.(page|sequence)$/) {
11096: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
11097: if (($map ne '') && ($map eq $sloturl)) {
11098: $canuse = 1;
11099: last;
11100: }
11101: }
11102: }
11103: }
11104: next unless ($canuse);
11105: }
1.1040 raeburn 11106: }
11107: if (($slots{$slot}->{'starttime'} > $now) &&
11108: ($slots{$slot}->{'endtime'} > $now)) {
11109: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11110: my $userallowed = 0;
11111: if ($slots{$slot}->{'allowedsections'}) {
11112: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11113: if (!defined($env{'request.role.sec'})
11114: && grep(/^No section assigned$/,@allowed_sec)) {
11115: $userallowed=1;
11116: } else {
11117: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11118: $userallowed=1;
11119: }
11120: }
11121: unless ($userallowed) {
11122: if (defined($env{'request.course.groups'})) {
11123: my @groups = split(/:/,$env{'request.course.groups'});
11124: foreach my $group (@groups) {
11125: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11126: $userallowed=1;
11127: last;
11128: }
11129: }
11130: }
11131: }
11132: }
11133: if ($slots{$slot}->{'allowedusers'}) {
11134: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11135: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11136: if (grep(/^\Q$user\E$/,@allowed_users)) {
11137: $userallowed = 1;
11138: }
11139: }
11140: next unless($userallowed);
11141: }
11142: my $startreserve = $slots{$slot}->{'startreserve'};
11143: my $endreserve = $slots{$slot}->{'endreserve'};
11144: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 11145: my $uniqueperiod;
11146: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11147: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11148: }
1.1040 raeburn 11149: if (($startreserve < $now) &&
11150: (!$endreserve || $endreserve > $now)) {
11151: my $lastres = $endreserve;
11152: if (!$lastres) {
11153: $lastres = $slots{$slot}->{'starttime'};
11154: }
11155: $reservable_now{$slot} = {
11156: symb => $symb,
1.1250 raeburn 11157: endreserve => $lastres,
11158: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11159: };
11160: } elsif (($startreserve > $now) &&
11161: (!$endreserve || $endreserve > $startreserve)) {
11162: $future_reservable{$slot} = {
11163: symb => $symb,
1.1250 raeburn 11164: startreserve => $startreserve,
11165: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11166: };
11167: }
11168: }
11169: }
11170: my @unsorted_reservable = keys(%reservable_now);
11171: if (@unsorted_reservable > 0) {
11172: @sorted_reservable =
11173: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11174: }
11175: my @unsorted_future = keys(%future_reservable);
11176: if (@unsorted_future > 0) {
11177: @sorted_future =
11178: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11179: }
11180: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11181: }
1.780 raeburn 11182:
11183: =pod
11184:
1.1057 foxr 11185: =back
11186:
1.549 albertel 11187: =head1 HTTP Helpers
11188:
11189: =over 4
11190:
1.648 raeburn 11191: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11192:
1.258 albertel 11193: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11194: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11195: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11196:
11197: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11198: $possible_names is an ref to an array of form element names. As an example:
11199: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11200: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11201:
11202: =cut
1.1 albertel 11203:
1.6 albertel 11204: sub get_unprocessed_cgi {
1.25 albertel 11205: my ($query,$possible_names)= @_;
1.26 matthew 11206: # $Apache::lonxml::debug=1;
1.356 albertel 11207: foreach my $pair (split(/&/,$query)) {
11208: my ($name, $value) = split(/=/,$pair);
1.369 www 11209: $name = &unescape($name);
1.25 albertel 11210: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11211: $value =~ tr/+/ /;
11212: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11213: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11214: }
1.16 harris41 11215: }
1.6 albertel 11216: }
11217:
1.112 bowersj2 11218: =pod
11219:
1.648 raeburn 11220: =item * &cacheheader()
1.112 bowersj2 11221:
11222: returns cache-controlling header code
11223:
11224: =cut
11225:
1.7 albertel 11226: sub cacheheader {
1.258 albertel 11227: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11228: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11229: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11230: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11231: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11232: return $output;
1.7 albertel 11233: }
11234:
1.112 bowersj2 11235: =pod
11236:
1.648 raeburn 11237: =item * &no_cache($r)
1.112 bowersj2 11238:
11239: specifies header code to not have cache
11240:
11241: =cut
11242:
1.9 albertel 11243: sub no_cache {
1.216 albertel 11244: my ($r) = @_;
11245: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11246: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11247: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11248: $r->no_cache(1);
11249: $r->header_out("Expires" => $date);
11250: $r->header_out("Pragma" => "no-cache");
1.123 www 11251: }
11252:
11253: sub content_type {
1.181 albertel 11254: my ($r,$type,$charset) = @_;
1.299 foxr 11255: if ($r) {
11256: # Note that printout.pl calls this with undef for $r.
11257: &no_cache($r);
11258: }
1.258 albertel 11259: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11260: unless ($charset) {
11261: $charset=&Apache::lonlocal::current_encoding;
11262: }
11263: if ($charset) { $type.='; charset='.$charset; }
11264: if ($r) {
11265: $r->content_type($type);
11266: } else {
11267: print("Content-type: $type\n\n");
11268: }
1.9 albertel 11269: }
1.25 albertel 11270:
1.112 bowersj2 11271: =pod
11272:
1.648 raeburn 11273: =item * &add_to_env($name,$value)
1.112 bowersj2 11274:
1.258 albertel 11275: adds $name to the %env hash with value
1.112 bowersj2 11276: $value, if $name already exists, the entry is converted to an array
11277: reference and $value is added to the array.
11278:
11279: =cut
11280:
1.25 albertel 11281: sub add_to_env {
11282: my ($name,$value)=@_;
1.258 albertel 11283: if (defined($env{$name})) {
11284: if (ref($env{$name})) {
1.25 albertel 11285: #already have multiple values
1.258 albertel 11286: push(@{ $env{$name} },$value);
1.25 albertel 11287: } else {
11288: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11289: my $first=$env{$name};
11290: undef($env{$name});
11291: push(@{ $env{$name} },$first,$value);
1.25 albertel 11292: }
11293: } else {
1.258 albertel 11294: $env{$name}=$value;
1.25 albertel 11295: }
1.31 albertel 11296: }
1.149 albertel 11297:
11298: =pod
11299:
1.648 raeburn 11300: =item * &get_env_multiple($name)
1.149 albertel 11301:
1.258 albertel 11302: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11303: values may be defined and end up as an array ref.
11304:
11305: returns an array of values
11306:
11307: =cut
11308:
11309: sub get_env_multiple {
11310: my ($name) = @_;
11311: my @values;
1.258 albertel 11312: if (defined($env{$name})) {
1.149 albertel 11313: # exists is it an array
1.258 albertel 11314: if (ref($env{$name})) {
11315: @values=@{ $env{$name} };
1.149 albertel 11316: } else {
1.258 albertel 11317: $values[0]=$env{$name};
1.149 albertel 11318: }
11319: }
11320: return(@values);
11321: }
11322:
1.1249 damieng 11323: # Looks at given dependencies, and returns something depending on the context.
11324: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11325: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11326: # For all other contexts, returns ($output, $counter, $numpathchg).
11327: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11328: # $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.
11329: # $numpathchg: integer with the number of cleaned up dependency paths.
11330: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11331: # \%mapping: hash reference clean path -> original path for all dependencies.
11332: # @param {string} actionurl - The path to the handler, indicative of the context.
11333: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11334: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11335: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11336: # @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)
11337: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11338: sub ask_for_embedded_content {
1.1249 damieng 11339: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11340: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11341: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11342: %currsubfile,%unused,$rem);
1.1071 raeburn 11343: my $counter = 0;
11344: my $numnew = 0;
1.987 raeburn 11345: my $numremref = 0;
11346: my $numinvalid = 0;
11347: my $numpathchg = 0;
11348: my $numexisting = 0;
1.1071 raeburn 11349: my $numunused = 0;
11350: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11351: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11352: my $heading = &mt('Upload embedded files');
11353: my $buttontext = &mt('Upload');
11354:
1.1249 damieng 11355: # fills these variables based on the context:
11356: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11357: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11358: if ($env{'request.course.id'}) {
1.1123 raeburn 11359: if ($actionurl eq '/adm/dependencies') {
11360: $navmap = Apache::lonnavmaps::navmap->new();
11361: }
11362: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11363: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11364: }
1.1123 raeburn 11365: if (($actionurl eq '/adm/portfolio') ||
11366: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11367: my $current_path='/';
11368: if ($env{'form.currentpath'}) {
11369: $current_path = $env{'form.currentpath'};
11370: }
11371: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11372: $udom = $cdom;
11373: $uname = $cnum;
1.984 raeburn 11374: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11375: } else {
11376: $udom = $env{'user.domain'};
11377: $uname = $env{'user.name'};
11378: $url = '/userfiles/portfolio';
11379: }
1.987 raeburn 11380: $toplevel = $url.'/';
1.984 raeburn 11381: $url .= $current_path;
11382: $getpropath = 1;
1.987 raeburn 11383: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11384: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11385: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11386: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11387: $toplevel = $url;
1.984 raeburn 11388: if ($rest ne '') {
1.987 raeburn 11389: $url .= $rest;
11390: }
11391: } elsif ($actionurl eq '/adm/coursedocs') {
11392: if (ref($args) eq 'HASH') {
1.1071 raeburn 11393: $url = $args->{'docs_url'};
11394: $toplevel = $url;
1.1084 raeburn 11395: if ($args->{'context'} eq 'paste') {
11396: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11397: ($path) =
11398: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11399: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11400: $fileloc =~ s{^/}{};
11401: }
1.1071 raeburn 11402: }
1.1084 raeburn 11403: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11404: if ($env{'request.course.id'} ne '') {
11405: if (ref($args) eq 'HASH') {
11406: $url = $args->{'docs_url'};
11407: $title = $args->{'docs_title'};
1.1126 raeburn 11408: $toplevel = $url;
11409: unless ($toplevel =~ m{^/}) {
11410: $toplevel = "/$url";
11411: }
1.1085 raeburn 11412: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11413: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11414: $path = $1;
11415: } else {
11416: ($path) =
11417: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11418: }
1.1195 raeburn 11419: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11420: $fileloc = $toplevel;
11421: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11422: my ($udom,$uname,$fname) =
11423: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11424: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11425: } else {
11426: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11427: }
1.1071 raeburn 11428: $fileloc =~ s{^/}{};
11429: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11430: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11431: }
1.987 raeburn 11432: }
1.1123 raeburn 11433: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11434: $udom = $cdom;
11435: $uname = $cnum;
11436: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11437: $toplevel = $url;
11438: $path = $url;
11439: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11440: $fileloc =~ s{^/}{};
1.987 raeburn 11441: }
1.1249 damieng 11442:
11443: # parses the dependency paths to get some info
11444: # fills $newfiles, $mapping, $subdependencies, $dependencies
11445: # $newfiles: hash URL -> 1 for new files or external URLs
11446: # (will be completed later)
11447: # $mapping:
11448: # for external URLs: external URL -> external URL
11449: # for relative paths: clean path -> original path
11450: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11451: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11452: foreach my $file (keys(%{$allfiles})) {
11453: my $embed_file;
11454: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11455: $embed_file = $1;
11456: } else {
11457: $embed_file = $file;
11458: }
1.1158 raeburn 11459: my ($absolutepath,$cleaned_file);
11460: if ($embed_file =~ m{^\w+://}) {
11461: $cleaned_file = $embed_file;
1.1147 raeburn 11462: $newfiles{$cleaned_file} = 1;
11463: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11464: } else {
1.1158 raeburn 11465: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11466: if ($embed_file =~ m{^/}) {
11467: $absolutepath = $embed_file;
11468: }
1.1147 raeburn 11469: if ($cleaned_file =~ m{/}) {
11470: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11471: $path = &check_for_traversal($path,$url,$toplevel);
11472: my $item = $fname;
11473: if ($path ne '') {
11474: $item = $path.'/'.$fname;
11475: $subdependencies{$path}{$fname} = 1;
11476: } else {
11477: $dependencies{$item} = 1;
11478: }
11479: if ($absolutepath) {
11480: $mapping{$item} = $absolutepath;
11481: } else {
11482: $mapping{$item} = $embed_file;
11483: }
11484: } else {
11485: $dependencies{$embed_file} = 1;
11486: if ($absolutepath) {
1.1147 raeburn 11487: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11488: } else {
1.1147 raeburn 11489: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11490: }
11491: }
1.984 raeburn 11492: }
11493: }
1.1249 damieng 11494:
11495: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11496: # and lists
11497: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11498: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11499: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11500: # the path had to be cleaned up
11501: # $existing: hash clean path -> 1 if the file exists
11502: # $numexisting: number of keys in $existing
11503: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11504: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11505: # dependency subdirectories that are
11506: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11507: my $dirptr = 16384;
1.984 raeburn 11508: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11509: $currsubfile{$path} = {};
1.1123 raeburn 11510: if (($actionurl eq '/adm/portfolio') ||
11511: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11512: my ($sublistref,$listerror) =
11513: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11514: if (ref($sublistref) eq 'ARRAY') {
11515: foreach my $line (@{$sublistref}) {
11516: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11517: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11518: }
1.984 raeburn 11519: }
1.987 raeburn 11520: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11521: if (opendir(my $dir,$url.'/'.$path)) {
11522: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11523: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11524: }
1.1084 raeburn 11525: } elsif (($actionurl eq '/adm/dependencies') ||
11526: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11527: ($args->{'context'} eq 'paste')) ||
11528: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11529: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11530: my $dir;
11531: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11532: $dir = $fileloc;
11533: } else {
11534: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11535: }
1.1071 raeburn 11536: if ($dir ne '') {
11537: my ($sublistref,$listerror) =
11538: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11539: if (ref($sublistref) eq 'ARRAY') {
11540: foreach my $line (@{$sublistref}) {
11541: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11542: undef,$mtime)=split(/\&/,$line,12);
11543: unless (($testdir&$dirptr) ||
11544: ($file_name =~ /^\.\.?$/)) {
11545: $currsubfile{$path}{$file_name} = [$size,$mtime];
11546: }
11547: }
11548: }
11549: }
1.984 raeburn 11550: }
11551: }
11552: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11553: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11554: my $item = $path.'/'.$file;
11555: unless ($mapping{$item} eq $item) {
11556: $pathchanges{$item} = 1;
11557: }
11558: $existing{$item} = 1;
11559: $numexisting ++;
11560: } else {
11561: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11562: }
11563: }
1.1071 raeburn 11564: if ($actionurl eq '/adm/dependencies') {
11565: foreach my $path (keys(%currsubfile)) {
11566: if (ref($currsubfile{$path}) eq 'HASH') {
11567: foreach my $file (keys(%{$currsubfile{$path}})) {
11568: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11569: next if (($rem ne '') &&
11570: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11571: (ref($navmap) &&
11572: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11573: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11574: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11575: $unused{$path.'/'.$file} = 1;
11576: }
11577: }
11578: }
11579: }
11580: }
1.984 raeburn 11581: }
1.1249 damieng 11582:
11583: # fills $currfile, hash file name -> 1 or [$size,$mtime]
11584: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 11585: my %currfile;
1.1123 raeburn 11586: if (($actionurl eq '/adm/portfolio') ||
11587: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11588: my ($dirlistref,$listerror) =
11589: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11590: if (ref($dirlistref) eq 'ARRAY') {
11591: foreach my $line (@{$dirlistref}) {
11592: my ($file_name,$rest) = split(/\&/,$line,2);
11593: $currfile{$file_name} = 1;
11594: }
1.984 raeburn 11595: }
1.987 raeburn 11596: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11597: if (opendir(my $dir,$url)) {
1.987 raeburn 11598: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11599: map {$currfile{$_} = 1;} @dir_list;
11600: }
1.1084 raeburn 11601: } elsif (($actionurl eq '/adm/dependencies') ||
11602: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11603: ($args->{'context'} eq 'paste')) ||
11604: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11605: if ($env{'request.course.id'} ne '') {
11606: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11607: if ($dir ne '') {
11608: my ($dirlistref,$listerror) =
11609: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11610: if (ref($dirlistref) eq 'ARRAY') {
11611: foreach my $line (@{$dirlistref}) {
11612: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11613: $size,undef,$mtime)=split(/\&/,$line,12);
11614: unless (($testdir&$dirptr) ||
11615: ($file_name =~ /^\.\.?$/)) {
11616: $currfile{$file_name} = [$size,$mtime];
11617: }
11618: }
11619: }
11620: }
11621: }
1.984 raeburn 11622: }
1.1249 damieng 11623: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
11624: # are not in subdirectories, using $currfile
1.984 raeburn 11625: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11626: if (exists($currfile{$file})) {
1.987 raeburn 11627: unless ($mapping{$file} eq $file) {
11628: $pathchanges{$file} = 1;
11629: }
11630: $existing{$file} = 1;
11631: $numexisting ++;
11632: } else {
1.984 raeburn 11633: $newfiles{$file} = 1;
11634: }
11635: }
1.1071 raeburn 11636: foreach my $file (keys(%currfile)) {
11637: unless (($file eq $filename) ||
11638: ($file eq $filename.'.bak') ||
11639: ($dependencies{$file})) {
1.1085 raeburn 11640: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11641: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11642: next if (($rem ne '') &&
11643: (($env{"httpref.$rem".$file} ne '') ||
11644: (ref($navmap) &&
11645: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11646: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11647: ($navmap->getResourceByUrl($rem.$1)))))));
11648: }
1.1085 raeburn 11649: }
1.1071 raeburn 11650: $unused{$file} = 1;
11651: }
11652: }
1.1249 damieng 11653:
11654: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 11655: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11656: ($args->{'context'} eq 'paste')) {
11657: $counter = scalar(keys(%existing));
11658: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11659: return ($output,$counter,$numpathchg,\%existing);
11660: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11661: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11662: $counter = scalar(keys(%existing));
11663: $numpathchg = scalar(keys(%pathchanges));
11664: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11665: }
1.1249 damieng 11666:
11667: # returns HTML otherwise, with dependency results and to ask for more uploads
11668:
11669: # $upload_output: missing dependencies (with upload form)
11670: # $modify_output: uploaded dependencies (in use)
11671: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 11672: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11673: if ($actionurl eq '/adm/dependencies') {
11674: next if ($embed_file =~ m{^\w+://});
11675: }
1.660 raeburn 11676: $upload_output .= &start_data_table_row().
1.1123 raeburn 11677: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11678: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11679: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11680: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11681: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11682: }
1.1123 raeburn 11683: $upload_output .= '</td>';
1.1071 raeburn 11684: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11685: $upload_output.='<td align="right">'.
11686: '<span class="LC_info LC_fontsize_medium">'.
11687: &mt("URL points to web address").'</span>';
1.987 raeburn 11688: $numremref++;
1.660 raeburn 11689: } elsif ($args->{'error_on_invalid_names'}
11690: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11691: $upload_output.='<td align="right"><span class="LC_warning">'.
11692: &mt('Invalid characters').'</span>';
1.987 raeburn 11693: $numinvalid++;
1.660 raeburn 11694: } else {
1.1123 raeburn 11695: $upload_output .= '<td>'.
11696: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11697: $embed_file,\%mapping,
1.1071 raeburn 11698: $allfiles,$codebase,'upload');
11699: $counter ++;
11700: $numnew ++;
1.987 raeburn 11701: }
11702: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11703: }
11704: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11705: if ($actionurl eq '/adm/dependencies') {
11706: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11707: $modify_output .= &start_data_table_row().
11708: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11709: '<img src="'.&icon($embed_file).'" border="0" />'.
11710: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11711: '<td>'.$size.'</td>'.
11712: '<td>'.$mtime.'</td>'.
11713: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11714: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11715: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11716: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11717: &embedded_file_element('upload_embedded',$counter,
11718: $embed_file,\%mapping,
11719: $allfiles,$codebase,'modify').
11720: '</div></td>'.
11721: &end_data_table_row()."\n";
11722: $counter ++;
11723: } else {
11724: $upload_output .= &start_data_table_row().
1.1123 raeburn 11725: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11726: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11727: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11728: &Apache::loncommon::end_data_table_row()."\n";
11729: }
11730: }
11731: my $delidx = $counter;
11732: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11733: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11734: $delete_output .= &start_data_table_row().
11735: '<td><img src="'.&icon($oldfile).'" />'.
11736: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11737: '<td>'.$size.'</td>'.
11738: '<td>'.$mtime.'</td>'.
11739: '<td><label><input type="checkbox" name="del_upload_dep" '.
11740: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11741: &embedded_file_element('upload_embedded',$delidx,
11742: $oldfile,\%mapping,$allfiles,
11743: $codebase,'delete').'</td>'.
11744: &end_data_table_row()."\n";
11745: $numunused ++;
11746: $delidx ++;
1.987 raeburn 11747: }
11748: if ($upload_output) {
11749: $upload_output = &start_data_table().
11750: $upload_output.
11751: &end_data_table()."\n";
11752: }
1.1071 raeburn 11753: if ($modify_output) {
11754: $modify_output = &start_data_table().
11755: &start_data_table_header_row().
11756: '<th>'.&mt('File').'</th>'.
11757: '<th>'.&mt('Size (KB)').'</th>'.
11758: '<th>'.&mt('Modified').'</th>'.
11759: '<th>'.&mt('Upload replacement?').'</th>'.
11760: &end_data_table_header_row().
11761: $modify_output.
11762: &end_data_table()."\n";
11763: }
11764: if ($delete_output) {
11765: $delete_output = &start_data_table().
11766: &start_data_table_header_row().
11767: '<th>'.&mt('File').'</th>'.
11768: '<th>'.&mt('Size (KB)').'</th>'.
11769: '<th>'.&mt('Modified').'</th>'.
11770: '<th>'.&mt('Delete?').'</th>'.
11771: &end_data_table_header_row().
11772: $delete_output.
11773: &end_data_table()."\n";
11774: }
1.987 raeburn 11775: my $applies = 0;
11776: if ($numremref) {
11777: $applies ++;
11778: }
11779: if ($numinvalid) {
11780: $applies ++;
11781: }
11782: if ($numexisting) {
11783: $applies ++;
11784: }
1.1071 raeburn 11785: if ($counter || $numunused) {
1.987 raeburn 11786: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11787: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11788: $state.'<h3>'.$heading.'</h3>';
11789: if ($actionurl eq '/adm/dependencies') {
11790: if ($numnew) {
11791: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11792: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11793: $upload_output.'<br />'."\n";
11794: }
11795: if ($numexisting) {
11796: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11797: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11798: $modify_output.'<br />'."\n";
11799: $buttontext = &mt('Save changes');
11800: }
11801: if ($numunused) {
11802: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11803: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11804: $delete_output.'<br />'."\n";
11805: $buttontext = &mt('Save changes');
11806: }
11807: } else {
11808: $output .= $upload_output.'<br />'."\n";
11809: }
11810: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11811: $counter.'" />'."\n";
11812: if ($actionurl eq '/adm/dependencies') {
11813: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11814: $numnew.'" />'."\n";
11815: } elsif ($actionurl eq '') {
1.987 raeburn 11816: $output .= '<input type="hidden" name="phase" value="three" />';
11817: }
11818: } elsif ($applies) {
11819: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11820: if ($applies > 1) {
11821: $output .=
1.1123 raeburn 11822: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11823: if ($numremref) {
11824: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11825: }
11826: if ($numinvalid) {
11827: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11828: }
11829: if ($numexisting) {
11830: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11831: }
11832: $output .= '</ul><br />';
11833: } elsif ($numremref) {
11834: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11835: } elsif ($numinvalid) {
11836: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11837: } elsif ($numexisting) {
11838: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11839: }
11840: $output .= $upload_output.'<br />';
11841: }
11842: my ($pathchange_output,$chgcount);
1.1071 raeburn 11843: $chgcount = $counter;
1.987 raeburn 11844: if (keys(%pathchanges) > 0) {
11845: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11846: if ($counter) {
1.987 raeburn 11847: $output .= &embedded_file_element('pathchange',$chgcount,
11848: $embed_file,\%mapping,
1.1071 raeburn 11849: $allfiles,$codebase,'change');
1.987 raeburn 11850: } else {
11851: $pathchange_output .=
11852: &start_data_table_row().
11853: '<td><input type ="checkbox" name="namechange" value="'.
11854: $chgcount.'" checked="checked" /></td>'.
11855: '<td>'.$mapping{$embed_file}.'</td>'.
11856: '<td>'.$embed_file.
11857: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11858: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11859: '</td>'.&end_data_table_row();
1.660 raeburn 11860: }
1.987 raeburn 11861: $numpathchg ++;
11862: $chgcount ++;
1.660 raeburn 11863: }
11864: }
1.1127 raeburn 11865: if (($counter) || ($numunused)) {
1.987 raeburn 11866: if ($numpathchg) {
11867: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11868: $numpathchg.'" />'."\n";
11869: }
11870: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11871: ($actionurl eq '/adm/imsimport')) {
11872: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11873: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11874: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11875: } elsif ($actionurl eq '/adm/dependencies') {
11876: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11877: }
1.1123 raeburn 11878: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11879: } elsif ($numpathchg) {
11880: my %pathchange = ();
11881: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11882: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11883: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 11884: }
1.987 raeburn 11885: }
1.1071 raeburn 11886: return ($output,$counter,$numpathchg);
1.987 raeburn 11887: }
11888:
1.1147 raeburn 11889: =pod
11890:
11891: =item * clean_path($name)
11892:
11893: Performs clean-up of directories, subdirectories and filename in an
11894: embedded object, referenced in an HTML file which is being uploaded
11895: to a course or portfolio, where
11896: "Upload embedded images/multimedia files if HTML file" checkbox was
11897: checked.
11898:
11899: Clean-up is similar to replacements in lonnet::clean_filename()
11900: except each / between sub-directory and next level is preserved.
11901:
11902: =cut
11903:
11904: sub clean_path {
11905: my ($embed_file) = @_;
11906: $embed_file =~s{^/+}{};
11907: my @contents;
11908: if ($embed_file =~ m{/}) {
11909: @contents = split(/\//,$embed_file);
11910: } else {
11911: @contents = ($embed_file);
11912: }
11913: my $lastidx = scalar(@contents)-1;
11914: for (my $i=0; $i<=$lastidx; $i++) {
11915: $contents[$i]=~s{\\}{/}g;
11916: $contents[$i]=~s/\s+/\_/g;
11917: $contents[$i]=~s{[^/\w\.\-]}{}g;
11918: if ($i == $lastidx) {
11919: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11920: }
11921: }
11922: if ($lastidx > 0) {
11923: return join('/',@contents);
11924: } else {
11925: return $contents[0];
11926: }
11927: }
11928:
1.987 raeburn 11929: sub embedded_file_element {
1.1071 raeburn 11930: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11931: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11932: (ref($codebase) eq 'HASH'));
11933: my $output;
1.1071 raeburn 11934: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11935: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11936: }
11937: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11938: &escape($embed_file).'" />';
11939: unless (($context eq 'upload_embedded') &&
11940: ($mapping->{$embed_file} eq $embed_file)) {
11941: $output .='
11942: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11943: }
11944: my $attrib;
11945: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11946: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11947: }
11948: $output .=
11949: "\n\t\t".
11950: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11951: $attrib.'" />';
11952: if (exists($codebase->{$mapping->{$embed_file}})) {
11953: $output .=
11954: "\n\t\t".
11955: '<input name="codebase_'.$num.'" type="hidden" value="'.
11956: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11957: }
1.987 raeburn 11958: return $output;
1.660 raeburn 11959: }
11960:
1.1071 raeburn 11961: sub get_dependency_details {
11962: my ($currfile,$currsubfile,$embed_file) = @_;
11963: my ($size,$mtime,$showsize,$showmtime);
11964: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11965: if ($embed_file =~ m{/}) {
11966: my ($path,$fname) = split(/\//,$embed_file);
11967: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11968: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11969: }
11970: } else {
11971: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11972: ($size,$mtime) = @{$currfile->{$embed_file}};
11973: }
11974: }
11975: $showsize = $size/1024.0;
11976: $showsize = sprintf("%.1f",$showsize);
11977: if ($mtime > 0) {
11978: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11979: }
11980: }
11981: return ($showsize,$showmtime);
11982: }
11983:
11984: sub ask_embedded_js {
11985: return <<"END";
11986: <script type="text/javascript"">
11987: // <![CDATA[
11988: function toggleBrowse(counter) {
11989: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11990: var fileid = document.getElementById('embedded_item_'+counter);
11991: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11992: if (chkboxid.checked == true) {
11993: uploaddivid.style.display='block';
11994: } else {
11995: uploaddivid.style.display='none';
11996: fileid.value = '';
11997: }
11998: }
11999: // ]]>
12000: </script>
12001:
12002: END
12003: }
12004:
1.661 raeburn 12005: sub upload_embedded {
12006: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12007: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12008: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12009: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12010: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12011: my $orig_uploaded_filename =
12012: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12013: foreach my $type ('orig','ref','attrib','codebase') {
12014: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12015: $env{'form.embedded_'.$type.'_'.$i} =
12016: &unescape($env{'form.embedded_'.$type.'_'.$i});
12017: }
12018: }
1.661 raeburn 12019: my ($path,$fname) =
12020: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12021: # no path, whole string is fname
12022: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12023: $fname = &Apache::lonnet::clean_filename($fname);
12024: # See if there is anything left
12025: next if ($fname eq '');
12026:
12027: # Check if file already exists as a file or directory.
12028: my ($state,$msg);
12029: if ($context eq 'portfolio') {
12030: my $port_path = $dirpath;
12031: if ($group ne '') {
12032: $port_path = "groups/$group/$port_path";
12033: }
1.987 raeburn 12034: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12035: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12036: $dir_root,$port_path,$disk_quota,
12037: $current_disk_usage,$uname,$udom);
12038: if ($state eq 'will_exceed_quota'
1.984 raeburn 12039: || $state eq 'file_locked') {
1.661 raeburn 12040: $output .= $msg;
12041: next;
12042: }
12043: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12044: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12045: if ($state eq 'exists') {
12046: $output .= $msg;
12047: next;
12048: }
12049: }
12050: # Check if extension is valid
12051: if (($fname =~ /\.(\w+)$/) &&
12052: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 12053: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12054: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12055: next;
12056: } elsif (($fname =~ /\.(\w+)$/) &&
12057: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12058: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12059: next;
12060: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 12061: $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 12062: next;
12063: }
12064: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 12065: my $subdir = $path;
12066: $subdir =~ s{/+$}{};
1.661 raeburn 12067: if ($context eq 'portfolio') {
1.984 raeburn 12068: my $result;
12069: if ($state eq 'existingfile') {
12070: $result=
12071: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 12072: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12073: } else {
1.984 raeburn 12074: $result=
12075: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12076: $dirpath.
1.1123 raeburn 12077: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12078: if ($result !~ m|^/uploaded/|) {
12079: $output .= '<span class="LC_error">'
12080: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12081: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12082: .'</span><br />';
12083: next;
12084: } else {
1.987 raeburn 12085: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12086: $path.$fname.'</span>').'<br />';
1.984 raeburn 12087: }
1.661 raeburn 12088: }
1.1123 raeburn 12089: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 12090: my $extendedsubdir = $dirpath.'/'.$subdir;
12091: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12092: my $result =
1.1126 raeburn 12093: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12094: if ($result !~ m|^/uploaded/|) {
12095: $output .= '<span class="LC_error">'
12096: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12097: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12098: .'</span><br />';
12099: next;
12100: } else {
12101: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12102: $path.$fname.'</span>').'<br />';
1.1125 raeburn 12103: if ($context eq 'syllabus') {
12104: &Apache::lonnet::make_public_indefinitely($result);
12105: }
1.987 raeburn 12106: }
1.661 raeburn 12107: } else {
12108: # Save the file
12109: my $target = $env{'form.embedded_item_'.$i};
12110: my $fullpath = $dir_root.$dirpath.'/'.$path;
12111: my $dest = $fullpath.$fname;
12112: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12113: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12114: my $count;
12115: my $filepath = $dir_root;
1.1027 raeburn 12116: foreach my $subdir (@parts) {
12117: $filepath .= "/$subdir";
12118: if (!-e $filepath) {
1.661 raeburn 12119: mkdir($filepath,0770);
12120: }
12121: }
12122: my $fh;
12123: if (!open($fh,'>'.$dest)) {
12124: &Apache::lonnet::logthis('Failed to create '.$dest);
12125: $output .= '<span class="LC_error">'.
1.1071 raeburn 12126: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12127: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12128: '</span><br />';
12129: } else {
12130: if (!print $fh $env{'form.embedded_item_'.$i}) {
12131: &Apache::lonnet::logthis('Failed to write to '.$dest);
12132: $output .= '<span class="LC_error">'.
1.1071 raeburn 12133: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12134: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12135: '</span><br />';
12136: } else {
1.987 raeburn 12137: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12138: $url.'</span>').'<br />';
12139: unless ($context eq 'testbank') {
12140: $footer .= &mt('View embedded file: [_1]',
12141: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12142: }
12143: }
12144: close($fh);
12145: }
12146: }
12147: if ($env{'form.embedded_ref_'.$i}) {
12148: $pathchange{$i} = 1;
12149: }
12150: }
12151: if ($output) {
12152: $output = '<p>'.$output.'</p>';
12153: }
12154: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12155: $returnflag = 'ok';
1.1071 raeburn 12156: my $numpathchgs = scalar(keys(%pathchange));
12157: if ($numpathchgs > 0) {
1.987 raeburn 12158: if ($context eq 'portfolio') {
12159: $output .= '<p>'.&mt('or').'</p>';
12160: } elsif ($context eq 'testbank') {
1.1071 raeburn 12161: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12162: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12163: $returnflag = 'modify_orightml';
12164: }
12165: }
1.1071 raeburn 12166: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12167: }
12168:
12169: sub modify_html_form {
12170: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12171: my $end = 0;
12172: my $modifyform;
12173: if ($context eq 'upload_embedded') {
12174: return unless (ref($pathchange) eq 'HASH');
12175: if ($env{'form.number_embedded_items'}) {
12176: $end += $env{'form.number_embedded_items'};
12177: }
12178: if ($env{'form.number_pathchange_items'}) {
12179: $end += $env{'form.number_pathchange_items'};
12180: }
12181: if ($end) {
12182: for (my $i=0; $i<$end; $i++) {
12183: if ($i < $env{'form.number_embedded_items'}) {
12184: next unless($pathchange->{$i});
12185: }
12186: $modifyform .=
12187: &start_data_table_row().
12188: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12189: 'checked="checked" /></td>'.
12190: '<td>'.$env{'form.embedded_ref_'.$i}.
12191: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12192: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12193: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12194: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12195: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12196: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12197: '<td>'.$env{'form.embedded_orig_'.$i}.
12198: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12199: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12200: &end_data_table_row();
1.1071 raeburn 12201: }
1.987 raeburn 12202: }
12203: } else {
12204: $modifyform = $pathchgtable;
12205: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12206: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12207: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12208: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12209: }
12210: }
12211: if ($modifyform) {
1.1071 raeburn 12212: if ($actionurl eq '/adm/dependencies') {
12213: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12214: }
1.987 raeburn 12215: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12216: '<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".
12217: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12218: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12219: '</ol></p>'."\n".'<p>'.
12220: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12221: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12222: &start_data_table()."\n".
12223: &start_data_table_header_row().
12224: '<th>'.&mt('Change?').'</th>'.
12225: '<th>'.&mt('Current reference').'</th>'.
12226: '<th>'.&mt('Required reference').'</th>'.
12227: &end_data_table_header_row()."\n".
12228: $modifyform.
12229: &end_data_table().'<br />'."\n".$hiddenstate.
12230: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12231: '</form>'."\n";
12232: }
12233: return;
12234: }
12235:
12236: sub modify_html_refs {
1.1123 raeburn 12237: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12238: my $container;
12239: if ($context eq 'portfolio') {
12240: $container = $env{'form.container'};
12241: } elsif ($context eq 'coursedoc') {
12242: $container = $env{'form.primaryurl'};
1.1071 raeburn 12243: } elsif ($context eq 'manage_dependencies') {
12244: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12245: $container = "/$container";
1.1123 raeburn 12246: } elsif ($context eq 'syllabus') {
12247: $container = $url;
1.987 raeburn 12248: } else {
1.1027 raeburn 12249: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12250: }
12251: my (%allfiles,%codebase,$output,$content);
12252: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 12253: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12254: if (wantarray) {
12255: return ('',0,0);
12256: } else {
12257: return;
12258: }
12259: }
12260: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12261: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12262: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12263: if (wantarray) {
12264: return ('',0,0);
12265: } else {
12266: return;
12267: }
12268: }
1.987 raeburn 12269: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12270: if ($content eq '-1') {
12271: if (wantarray) {
12272: return ('',0,0);
12273: } else {
12274: return;
12275: }
12276: }
1.987 raeburn 12277: } else {
1.1071 raeburn 12278: unless ($container =~ /^\Q$dir_root\E/) {
12279: if (wantarray) {
12280: return ('',0,0);
12281: } else {
12282: return;
12283: }
12284: }
1.1317 raeburn 12285: if (open(my $fh,'<',$container)) {
1.987 raeburn 12286: $content = join('', <$fh>);
12287: close($fh);
12288: } else {
1.1071 raeburn 12289: if (wantarray) {
12290: return ('',0,0);
12291: } else {
12292: return;
12293: }
1.987 raeburn 12294: }
12295: }
12296: my ($count,$codebasecount) = (0,0);
12297: my $mm = new File::MMagic;
12298: my $mime_type = $mm->checktype_contents($content);
12299: if ($mime_type eq 'text/html') {
12300: my $parse_result =
12301: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12302: \%codebase,\$content);
12303: if ($parse_result eq 'ok') {
12304: foreach my $i (@changes) {
12305: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12306: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12307: if ($allfiles{$ref}) {
12308: my $newname = $orig;
12309: my ($attrib_regexp,$codebase);
1.1006 raeburn 12310: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12311: if ($attrib_regexp =~ /:/) {
12312: $attrib_regexp =~ s/\:/|/g;
12313: }
12314: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12315: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12316: $count += $numchg;
1.1123 raeburn 12317: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 12318: delete($allfiles{$ref});
1.987 raeburn 12319: }
12320: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12321: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12322: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12323: $codebasecount ++;
12324: }
12325: }
12326: }
1.1123 raeburn 12327: my $skiprewrites;
1.987 raeburn 12328: if ($count || $codebasecount) {
12329: my $saveresult;
1.1071 raeburn 12330: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12331: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12332: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12333: if ($url eq $container) {
12334: my ($fname) = ($container =~ m{/([^/]+)$});
12335: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12336: $count,'<span class="LC_filename">'.
1.1071 raeburn 12337: $fname.'</span>').'</p>';
1.987 raeburn 12338: } else {
12339: $output = '<p class="LC_error">'.
12340: &mt('Error: update failed for: [_1].',
12341: '<span class="LC_filename">'.
12342: $container.'</span>').'</p>';
12343: }
1.1123 raeburn 12344: if ($context eq 'syllabus') {
12345: unless ($saveresult eq 'ok') {
12346: $skiprewrites = 1;
12347: }
12348: }
1.987 raeburn 12349: } else {
1.1317 raeburn 12350: if (open(my $fh,'>',$container)) {
1.987 raeburn 12351: print $fh $content;
12352: close($fh);
12353: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12354: $count,'<span class="LC_filename">'.
12355: $container.'</span>').'</p>';
1.661 raeburn 12356: } else {
1.987 raeburn 12357: $output = '<p class="LC_error">'.
12358: &mt('Error: could not update [_1].',
12359: '<span class="LC_filename">'.
12360: $container.'</span>').'</p>';
1.661 raeburn 12361: }
12362: }
12363: }
1.1123 raeburn 12364: if (($context eq 'syllabus') && (!$skiprewrites)) {
12365: my ($actionurl,$state);
12366: $actionurl = "/public/$udom/$uname/syllabus";
12367: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12368: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12369: \%codebase,
12370: {'context' => 'rewrites',
12371: 'ignore_remote_references' => 1,});
12372: if (ref($mapping) eq 'HASH') {
12373: my $rewrites = 0;
12374: foreach my $key (keys(%{$mapping})) {
12375: next if ($key =~ m{^https?://});
12376: my $ref = $mapping->{$key};
12377: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12378: my $attrib;
12379: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12380: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12381: }
12382: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12383: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12384: $rewrites += $numchg;
12385: }
12386: }
12387: if ($rewrites) {
12388: my $saveresult;
12389: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12390: if ($url eq $container) {
12391: my ($fname) = ($container =~ m{/([^/]+)$});
12392: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12393: $count,'<span class="LC_filename">'.
12394: $fname.'</span>').'</p>';
12395: } else {
12396: $output .= '<p class="LC_error">'.
12397: &mt('Error: could not update links in [_1].',
12398: '<span class="LC_filename">'.
12399: $container.'</span>').'</p>';
12400:
12401: }
12402: }
12403: }
12404: }
1.987 raeburn 12405: } else {
12406: &logthis('Failed to parse '.$container.
12407: ' to modify references: '.$parse_result);
1.661 raeburn 12408: }
12409: }
1.1071 raeburn 12410: if (wantarray) {
12411: return ($output,$count,$codebasecount);
12412: } else {
12413: return $output;
12414: }
1.661 raeburn 12415: }
12416:
12417: sub check_for_existing {
12418: my ($path,$fname,$element) = @_;
12419: my ($state,$msg);
12420: if (-d $path.'/'.$fname) {
12421: $state = 'exists';
12422: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12423: } elsif (-e $path.'/'.$fname) {
12424: $state = 'exists';
12425: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12426: }
12427: if ($state eq 'exists') {
12428: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12429: }
12430: return ($state,$msg);
12431: }
12432:
12433: sub check_for_upload {
12434: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12435: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12436: my $filesize = length($env{'form.'.$element});
12437: if (!$filesize) {
12438: my $msg = '<span class="LC_error">'.
12439: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12440: '<span class="LC_filename">'.$fname.'</span>',
12441: $filesize).'<br />'.
1.1007 raeburn 12442: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12443: '</span>';
12444: return ('zero_bytes',$msg);
12445: }
12446: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12447: my $getpropath = 1;
1.1021 raeburn 12448: my ($dirlistref,$listerror) =
12449: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12450: my $found_file = 0;
12451: my $locked_file = 0;
1.991 raeburn 12452: my @lockers;
12453: my $navmap;
12454: if ($env{'request.course.id'}) {
12455: $navmap = Apache::lonnavmaps::navmap->new();
12456: }
1.1021 raeburn 12457: if (ref($dirlistref) eq 'ARRAY') {
12458: foreach my $line (@{$dirlistref}) {
12459: my ($file_name,$rest)=split(/\&/,$line,2);
12460: if ($file_name eq $fname){
12461: $file_name = $path.$file_name;
12462: if ($group ne '') {
12463: $file_name = $group.$file_name;
12464: }
12465: $found_file = 1;
12466: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12467: foreach my $lock (@lockers) {
12468: if (ref($lock) eq 'ARRAY') {
12469: my ($symb,$crsid) = @{$lock};
12470: if ($crsid eq $env{'request.course.id'}) {
12471: if (ref($navmap)) {
12472: my $res = $navmap->getBySymb($symb);
12473: foreach my $part (@{$res->parts()}) {
12474: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12475: unless (($slot_status == $res->RESERVED) ||
12476: ($slot_status == $res->RESERVED_LOCATION)) {
12477: $locked_file = 1;
12478: }
1.991 raeburn 12479: }
1.1021 raeburn 12480: } else {
12481: $locked_file = 1;
1.991 raeburn 12482: }
12483: } else {
12484: $locked_file = 1;
12485: }
12486: }
1.1021 raeburn 12487: }
12488: } else {
12489: my @info = split(/\&/,$rest);
12490: my $currsize = $info[6]/1000;
12491: if ($currsize < $filesize) {
12492: my $extra = $filesize - $currsize;
12493: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12494: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12495: &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 12496: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12497: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12498: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12499: return ('will_exceed_quota',$msg);
12500: }
1.984 raeburn 12501: }
12502: }
1.661 raeburn 12503: }
12504: }
12505: }
12506: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12507: my $msg = '<p class="LC_warning">'.
12508: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12509: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12510: return ('will_exceed_quota',$msg);
12511: } elsif ($found_file) {
12512: if ($locked_file) {
1.1179 bisitz 12513: my $msg = '<p class="LC_warning">';
1.661 raeburn 12514: $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 12515: $msg .= '</p>';
1.661 raeburn 12516: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12517: return ('file_locked',$msg);
12518: } else {
1.1179 bisitz 12519: my $msg = '<p class="LC_error">';
1.984 raeburn 12520: $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 12521: $msg .= '</p>';
1.984 raeburn 12522: return ('existingfile',$msg);
1.661 raeburn 12523: }
12524: }
12525: }
12526:
1.987 raeburn 12527: sub check_for_traversal {
12528: my ($path,$url,$toplevel) = @_;
12529: my @parts=split(/\//,$path);
12530: my $cleanpath;
12531: my $fullpath = $url;
12532: for (my $i=0;$i<@parts;$i++) {
12533: next if ($parts[$i] eq '.');
12534: if ($parts[$i] eq '..') {
12535: $fullpath =~ s{([^/]+/)$}{};
12536: } else {
12537: $fullpath .= $parts[$i].'/';
12538: }
12539: }
12540: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12541: $cleanpath = $1;
12542: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12543: my $curr_toprel = $1;
12544: my @parts = split(/\//,$curr_toprel);
12545: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12546: my @urlparts = split(/\//,$url_toprel);
12547: my $doubledots;
12548: my $startdiff = -1;
12549: for (my $i=0; $i<@urlparts; $i++) {
12550: if ($startdiff == -1) {
12551: unless ($urlparts[$i] eq $parts[$i]) {
12552: $startdiff = $i;
12553: $doubledots .= '../';
12554: }
12555: } else {
12556: $doubledots .= '../';
12557: }
12558: }
12559: if ($startdiff > -1) {
12560: $cleanpath = $doubledots;
12561: for (my $i=$startdiff; $i<@parts; $i++) {
12562: $cleanpath .= $parts[$i].'/';
12563: }
12564: }
12565: }
12566: $cleanpath =~ s{(/)$}{};
12567: return $cleanpath;
12568: }
1.31 albertel 12569:
1.1053 raeburn 12570: sub is_archive_file {
12571: my ($mimetype) = @_;
12572: if (($mimetype eq 'application/octet-stream') ||
12573: ($mimetype eq 'application/x-stuffit') ||
12574: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12575: return 1;
12576: }
12577: return;
12578: }
12579:
12580: sub decompress_form {
1.1065 raeburn 12581: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12582: my %lt = &Apache::lonlocal::texthash (
12583: this => 'This file is an archive file.',
1.1067 raeburn 12584: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12585: itsc => 'Its contents are as follows:',
1.1053 raeburn 12586: youm => 'You may wish to extract its contents.',
12587: extr => 'Extract contents',
1.1067 raeburn 12588: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12589: proa => 'Process automatically?',
1.1053 raeburn 12590: yes => 'Yes',
12591: no => 'No',
1.1067 raeburn 12592: fold => 'Title for folder containing movie',
12593: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12594: );
1.1065 raeburn 12595: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12596: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12597: my $info = &list_archive_contents($fileloc,\@paths);
12598: if (@paths) {
12599: foreach my $path (@paths) {
12600: $path =~ s{^/}{};
1.1067 raeburn 12601: if ($path =~ m{^([^/]+)/$}) {
12602: $topdir = $1;
12603: }
1.1065 raeburn 12604: if ($path =~ m{^([^/]+)/}) {
12605: $toplevel{$1} = $path;
12606: } else {
12607: $toplevel{$path} = $path;
12608: }
12609: }
12610: }
1.1067 raeburn 12611: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12612: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12613: "$topdir/media/",
12614: "$topdir/media/$topdir.mp4",
12615: "$topdir/media/FirstFrame.png",
12616: "$topdir/media/player.swf",
12617: "$topdir/media/swfobject.js",
12618: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12619: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12620: "$topdir/$topdir.mp4",
12621: "$topdir/$topdir\_config.xml",
12622: "$topdir/$topdir\_controller.swf",
12623: "$topdir/$topdir\_embed.css",
12624: "$topdir/$topdir\_First_Frame.png",
12625: "$topdir/$topdir\_player.html",
12626: "$topdir/$topdir\_Thumbnails.png",
12627: "$topdir/playerProductInstall.swf",
12628: "$topdir/scripts/",
12629: "$topdir/scripts/config_xml.js",
12630: "$topdir/scripts/handlebars.js",
12631: "$topdir/scripts/jquery-1.7.1.min.js",
12632: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12633: "$topdir/scripts/modernizr.js",
12634: "$topdir/scripts/player-min.js",
12635: "$topdir/scripts/swfobject.js",
12636: "$topdir/skins/",
12637: "$topdir/skins/configuration_express.xml",
12638: "$topdir/skins/express_show/",
12639: "$topdir/skins/express_show/player-min.css",
12640: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12641: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12642: "$topdir/$topdir.mp4",
12643: "$topdir/$topdir\_config.xml",
12644: "$topdir/$topdir\_controller.swf",
12645: "$topdir/$topdir\_embed.css",
12646: "$topdir/$topdir\_First_Frame.png",
12647: "$topdir/$topdir\_player.html",
12648: "$topdir/$topdir\_Thumbnails.png",
12649: "$topdir/playerProductInstall.swf",
12650: "$topdir/scripts/",
12651: "$topdir/scripts/config_xml.js",
12652: "$topdir/scripts/techsmith-smart-player.min.js",
12653: "$topdir/skins/",
12654: "$topdir/skins/configuration_express.xml",
12655: "$topdir/skins/express_show/",
12656: "$topdir/skins/express_show/spritesheet.min.css",
12657: "$topdir/skins/express_show/spritesheet.png",
12658: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12659: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12660: if (@diffs == 0) {
1.1164 raeburn 12661: $is_camtasia = 6;
12662: } else {
1.1197 raeburn 12663: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12664: if (@diffs == 0) {
12665: $is_camtasia = 8;
1.1197 raeburn 12666: } else {
12667: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12668: if (@diffs == 0) {
12669: $is_camtasia = 8;
12670: }
1.1164 raeburn 12671: }
1.1067 raeburn 12672: }
12673: }
12674: my $output;
12675: if ($is_camtasia) {
12676: $output = <<"ENDCAM";
12677: <script type="text/javascript" language="Javascript">
12678: // <![CDATA[
12679:
12680: function camtasiaToggle() {
12681: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12682: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12683: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12684: document.getElementById('camtasia_titles').style.display='block';
12685: } else {
12686: document.getElementById('camtasia_titles').style.display='none';
12687: }
12688: }
12689: }
12690: return;
12691: }
12692:
12693: // ]]>
12694: </script>
12695: <p>$lt{'camt'}</p>
12696: ENDCAM
1.1065 raeburn 12697: } else {
1.1067 raeburn 12698: $output = '<p>'.$lt{'this'};
12699: if ($info eq '') {
12700: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12701: } else {
12702: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12703: '<div><pre>'.$info.'</pre></div>';
12704: }
1.1065 raeburn 12705: }
1.1067 raeburn 12706: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12707: my $duplicates;
12708: my $num = 0;
12709: if (ref($dirlist) eq 'ARRAY') {
12710: foreach my $item (@{$dirlist}) {
12711: if (ref($item) eq 'ARRAY') {
12712: if (exists($toplevel{$item->[0]})) {
12713: $duplicates .=
12714: &start_data_table_row().
12715: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12716: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12717: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12718: 'value="1" />'.&mt('Yes').'</label>'.
12719: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12720: '<td>'.$item->[0].'</td>';
12721: if ($item->[2]) {
12722: $duplicates .= '<td>'.&mt('Directory').'</td>';
12723: } else {
12724: $duplicates .= '<td>'.&mt('File').'</td>';
12725: }
12726: $duplicates .= '<td>'.$item->[3].'</td>'.
12727: '<td>'.
12728: &Apache::lonlocal::locallocaltime($item->[4]).
12729: '</td>'.
12730: &end_data_table_row();
12731: $num ++;
12732: }
12733: }
12734: }
12735: }
12736: my $itemcount;
12737: if (@paths > 0) {
12738: $itemcount = scalar(@paths);
12739: } else {
12740: $itemcount = 1;
12741: }
1.1067 raeburn 12742: if ($is_camtasia) {
12743: $output .= $lt{'auto'}.'<br />'.
12744: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12745: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12746: $lt{'yes'}.'</label> <label>'.
12747: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12748: $lt{'no'}.'</label></span><br />'.
12749: '<div id="camtasia_titles" style="display:block">'.
12750: &Apache::lonhtmlcommon::start_pick_box().
12751: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12752: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12753: &Apache::lonhtmlcommon::row_closure().
12754: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12755: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12756: &Apache::lonhtmlcommon::row_closure(1).
12757: &Apache::lonhtmlcommon::end_pick_box().
12758: '</div>';
12759: }
1.1065 raeburn 12760: $output .=
12761: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12762: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12763: "\n";
1.1065 raeburn 12764: if ($duplicates ne '') {
12765: $output .= '<p><span class="LC_warning">'.
12766: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12767: &start_data_table().
12768: &start_data_table_header_row().
12769: '<th>'.&mt('Overwrite?').'</th>'.
12770: '<th>'.&mt('Name').'</th>'.
12771: '<th>'.&mt('Type').'</th>'.
12772: '<th>'.&mt('Size').'</th>'.
12773: '<th>'.&mt('Last modified').'</th>'.
12774: &end_data_table_header_row().
12775: $duplicates.
12776: &end_data_table().
12777: '</p>';
12778: }
1.1067 raeburn 12779: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12780: if (ref($hiddenelements) eq 'HASH') {
12781: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12782: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12783: }
12784: }
12785: $output .= <<"END";
1.1067 raeburn 12786: <br />
1.1053 raeburn 12787: <input type="submit" name="decompress" value="$lt{'extr'}" />
12788: </form>
12789: $noextract
12790: END
12791: return $output;
12792: }
12793:
1.1065 raeburn 12794: sub decompression_utility {
12795: my ($program) = @_;
12796: my @utilities = ('tar','gunzip','bunzip2','unzip');
12797: my $location;
12798: if (grep(/^\Q$program\E$/,@utilities)) {
12799: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12800: '/usr/sbin/') {
12801: if (-x $dir.$program) {
12802: $location = $dir.$program;
12803: last;
12804: }
12805: }
12806: }
12807: return $location;
12808: }
12809:
12810: sub list_archive_contents {
12811: my ($file,$pathsref) = @_;
12812: my (@cmd,$output);
12813: my $needsregexp;
12814: if ($file =~ /\.zip$/) {
12815: @cmd = (&decompression_utility('unzip'),"-l");
12816: $needsregexp = 1;
12817: } elsif (($file =~ m/\.tar\.gz$/) ||
12818: ($file =~ /\.tgz$/)) {
12819: @cmd = (&decompression_utility('tar'),"-ztf");
12820: } elsif ($file =~ /\.tar\.bz2$/) {
12821: @cmd = (&decompression_utility('tar'),"-jtf");
12822: } elsif ($file =~ m|\.tar$|) {
12823: @cmd = (&decompression_utility('tar'),"-tf");
12824: }
12825: if (@cmd) {
12826: undef($!);
12827: undef($@);
12828: if (open(my $fh,"-|", @cmd, $file)) {
12829: while (my $line = <$fh>) {
12830: $output .= $line;
12831: chomp($line);
12832: my $item;
12833: if ($needsregexp) {
12834: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12835: } else {
12836: $item = $line;
12837: }
12838: if ($item ne '') {
12839: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12840: push(@{$pathsref},$item);
12841: }
12842: }
12843: }
12844: close($fh);
12845: }
12846: }
12847: return $output;
12848: }
12849:
1.1053 raeburn 12850: sub decompress_uploaded_file {
12851: my ($file,$dir) = @_;
12852: &Apache::lonnet::appenv({'cgi.file' => $file});
12853: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12854: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12855: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12856: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12857: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12858: my $decompressed = $env{'cgi.decompressed'};
12859: &Apache::lonnet::delenv('cgi.file');
12860: &Apache::lonnet::delenv('cgi.dir');
12861: &Apache::lonnet::delenv('cgi.decompressed');
12862: return ($decompressed,$result);
12863: }
12864:
1.1055 raeburn 12865: sub process_decompression {
12866: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 12867: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12868: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12869: &mt('Unexpected file path.').'</p>'."\n";
12870: }
12871: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12872: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12873: &mt('Unexpected course context.').'</p>'."\n";
12874: }
1.1293 raeburn 12875: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 12876: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12877: &mt('Filename contained unexpected characters.').'</p>'."\n";
12878: }
1.1055 raeburn 12879: my ($dir,$error,$warning,$output);
1.1180 raeburn 12880: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 12881: $error = &mt('Filename not a supported archive file type.').
12882: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12883: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12884: } else {
12885: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12886: if ($docuhome eq 'no_host') {
12887: $error = &mt('Could not determine home server for course.');
12888: } else {
12889: my @ids=&Apache::lonnet::current_machine_ids();
12890: my $currdir = "$dir_root/$destination";
12891: if (grep(/^\Q$docuhome\E$/,@ids)) {
12892: $dir = &LONCAPA::propath($docudom,$docuname).
12893: "$dir_root/$destination";
12894: } else {
12895: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12896: "$dir_root/$docudom/$docuname/$destination";
12897: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12898: $error = &mt('Archive file not found.');
12899: }
12900: }
1.1065 raeburn 12901: my (@to_overwrite,@to_skip);
12902: if ($env{'form.archive_overwrite_total'} > 0) {
12903: my $total = $env{'form.archive_overwrite_total'};
12904: for (my $i=0; $i<$total; $i++) {
12905: if ($env{'form.archive_overwrite_'.$i} == 1) {
12906: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12907: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12908: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12909: }
12910: }
12911: }
12912: my $numskip = scalar(@to_skip);
1.1292 raeburn 12913: my $numoverwrite = scalar(@to_overwrite);
12914: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12915: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12916: } elsif ($dir eq '') {
1.1055 raeburn 12917: $error = &mt('Directory containing archive file unavailable.');
12918: } elsif (!$error) {
1.1065 raeburn 12919: my ($decompressed,$display);
1.1292 raeburn 12920: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12921: my $tempdir = time.'_'.$$.int(rand(10000));
12922: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 12923: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12924: ($decompressed,$display) =
12925: &decompress_uploaded_file($file,"$dir/$tempdir");
12926: foreach my $item (@to_skip) {
12927: if (($item ne '') && ($item !~ /\.\./)) {
12928: if (-f "$dir/$tempdir/$item") {
12929: unlink("$dir/$tempdir/$item");
12930: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 12931: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 12932: }
12933: }
12934: }
12935: foreach my $item (@to_overwrite) {
12936: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12937: if (($item ne '') && ($item !~ /\.\./)) {
12938: if (-f "$dir/$item") {
12939: unlink("$dir/$item");
12940: } elsif (-d "$dir/$item") {
1.1300 raeburn 12941: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 12942: }
12943: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12944: }
1.1065 raeburn 12945: }
12946: }
1.1292 raeburn 12947: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 12948: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 12949: }
1.1065 raeburn 12950: }
12951: } else {
12952: ($decompressed,$display) =
12953: &decompress_uploaded_file($file,$dir);
12954: }
1.1055 raeburn 12955: if ($decompressed eq 'ok') {
1.1065 raeburn 12956: $output = '<p class="LC_info">'.
12957: &mt('Files extracted successfully from archive.').
12958: '</p>'."\n";
1.1055 raeburn 12959: my ($warning,$result,@contents);
12960: my ($newdirlistref,$newlisterror) =
12961: &Apache::lonnet::dirlist($currdir,$docudom,
12962: $docuname,1);
12963: my (%is_dir,%changes,@newitems);
12964: my $dirptr = 16384;
1.1065 raeburn 12965: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12966: foreach my $dir_line (@{$newdirlistref}) {
12967: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 12968: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12969: push(@newitems,$item);
12970: if ($dirptr&$testdir) {
12971: $is_dir{$item} = 1;
12972: }
12973: $changes{$item} = 1;
12974: }
12975: }
12976: }
12977: if (keys(%changes) > 0) {
12978: foreach my $item (sort(@newitems)) {
12979: if ($changes{$item}) {
12980: push(@contents,$item);
12981: }
12982: }
12983: }
12984: if (@contents > 0) {
1.1067 raeburn 12985: my $wantform;
12986: unless ($env{'form.autoextract_camtasia'}) {
12987: $wantform = 1;
12988: }
1.1056 raeburn 12989: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12990: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12991: $currdir,\%is_dir,
12992: \%children,\%parent,
1.1056 raeburn 12993: \@contents,\%dirorder,
12994: \%titles,$wantform);
1.1055 raeburn 12995: if ($datatable ne '') {
12996: $output .= &archive_options_form('decompressed',$datatable,
12997: $count,$hiddenelem);
1.1065 raeburn 12998: my $startcount = 6;
1.1055 raeburn 12999: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13000: \%titles,\%children);
1.1055 raeburn 13001: }
1.1067 raeburn 13002: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 13003: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13004: my %displayed;
13005: my $total = 1;
13006: $env{'form.archive_directory'} = [];
13007: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13008: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13009: $path =~ s{/$}{};
13010: my $item;
13011: if ($path ne '') {
13012: $item = "$path/$titles{$i}";
13013: } else {
13014: $item = $titles{$i};
13015: }
13016: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13017: if ($item eq $contents[0]) {
13018: push(@{$env{'form.archive_directory'}},$i);
13019: $env{'form.archive_'.$i} = 'display';
13020: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13021: $displayed{'folder'} = $i;
1.1164 raeburn 13022: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13023: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13024: $env{'form.archive_'.$i} = 'display';
13025: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13026: $displayed{'web'} = $i;
13027: } else {
1.1164 raeburn 13028: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13029: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13030: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13031: push(@{$env{'form.archive_directory'}},$i);
13032: }
13033: $env{'form.archive_'.$i} = 'dependency';
13034: }
13035: $total ++;
13036: }
13037: for (my $i=1; $i<$total; $i++) {
13038: next if ($i == $displayed{'web'});
13039: next if ($i == $displayed{'folder'});
13040: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13041: }
13042: $env{'form.phase'} = 'decompress_cleanup';
13043: $env{'form.archivedelete'} = 1;
13044: $env{'form.archive_count'} = $total-1;
13045: $output .=
13046: &process_extracted_files('coursedocs',$docudom,
13047: $docuname,$destination,
13048: $dir_root,$hiddenelem);
13049: }
1.1055 raeburn 13050: } else {
13051: $warning = &mt('No new items extracted from archive file.');
13052: }
13053: } else {
13054: $output = $display;
13055: $error = &mt('An error occurred during extraction from the archive file.');
13056: }
13057: }
13058: }
13059: }
13060: if ($error) {
13061: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13062: $error.'</p>'."\n";
13063: }
13064: if ($warning) {
13065: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13066: }
13067: return $output;
13068: }
13069:
13070: sub get_extracted {
1.1056 raeburn 13071: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13072: $titles,$wantform) = @_;
1.1055 raeburn 13073: my $count = 0;
13074: my $depth = 0;
13075: my $datatable;
1.1056 raeburn 13076: my @hierarchy;
1.1055 raeburn 13077: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13078: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13079: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13080: foreach my $item (@{$contents}) {
13081: $count ++;
1.1056 raeburn 13082: @{$dirorder->{$count}} = @hierarchy;
13083: $titles->{$count} = $item;
1.1055 raeburn 13084: &archive_hierarchy($depth,$count,$parent,$children);
13085: if ($wantform) {
13086: $datatable .= &archive_row($is_dir->{$item},$item,
13087: $currdir,$depth,$count);
13088: }
13089: if ($is_dir->{$item}) {
13090: $depth ++;
1.1056 raeburn 13091: push(@hierarchy,$count);
13092: $parent->{$depth} = $count;
1.1055 raeburn 13093: $datatable .=
13094: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13095: \$depth,\$count,\@hierarchy,$dirorder,
13096: $children,$parent,$titles,$wantform);
1.1055 raeburn 13097: $depth --;
1.1056 raeburn 13098: pop(@hierarchy);
1.1055 raeburn 13099: }
13100: }
13101: return ($count,$datatable);
13102: }
13103:
13104: sub recurse_extracted_archive {
1.1056 raeburn 13105: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13106: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13107: my $result='';
1.1056 raeburn 13108: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13109: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13110: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13111: return $result;
13112: }
13113: my $dirptr = 16384;
13114: my ($newdirlistref,$newlisterror) =
13115: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13116: if (ref($newdirlistref) eq 'ARRAY') {
13117: foreach my $dir_line (@{$newdirlistref}) {
13118: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13119: unless ($item =~ /^\.+$/) {
13120: $$count ++;
1.1056 raeburn 13121: @{$dirorder->{$$count}} = @{$hierarchy};
13122: $titles->{$$count} = $item;
1.1055 raeburn 13123: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13124:
1.1055 raeburn 13125: my $is_dir;
13126: if ($dirptr&$testdir) {
13127: $is_dir = 1;
13128: }
13129: if ($wantform) {
13130: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13131: }
13132: if ($is_dir) {
13133: $$depth ++;
1.1056 raeburn 13134: push(@{$hierarchy},$$count);
13135: $parent->{$$depth} = $$count;
1.1055 raeburn 13136: $result .=
13137: &recurse_extracted_archive("$currdir/$item",$docudom,
13138: $docuname,$depth,$count,
1.1056 raeburn 13139: $hierarchy,$dirorder,$children,
13140: $parent,$titles,$wantform);
1.1055 raeburn 13141: $$depth --;
1.1056 raeburn 13142: pop(@{$hierarchy});
1.1055 raeburn 13143: }
13144: }
13145: }
13146: }
13147: return $result;
13148: }
13149:
13150: sub archive_hierarchy {
13151: my ($depth,$count,$parent,$children) =@_;
13152: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13153: if (exists($parent->{$depth})) {
13154: $children->{$parent->{$depth}} .= $count.':';
13155: }
13156: }
13157: return;
13158: }
13159:
13160: sub archive_row {
13161: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13162: my ($name) = ($item =~ m{([^/]+)$});
13163: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13164: 'display' => 'Add as file',
1.1055 raeburn 13165: 'dependency' => 'Include as dependency',
13166: 'discard' => 'Discard',
13167: );
13168: if ($is_dir) {
1.1059 raeburn 13169: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13170: }
1.1056 raeburn 13171: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13172: my $offset = 0;
1.1055 raeburn 13173: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13174: $offset ++;
1.1065 raeburn 13175: if ($action ne 'display') {
13176: $offset ++;
13177: }
1.1055 raeburn 13178: $output .= '<td><span class="LC_nobreak">'.
13179: '<label><input type="radio" name="archive_'.$count.
13180: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13181: my $text = $choices{$action};
13182: if ($is_dir) {
13183: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13184: if ($action eq 'display') {
1.1059 raeburn 13185: $text = &mt('Add as folder');
1.1055 raeburn 13186: }
1.1056 raeburn 13187: } else {
13188: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13189:
13190: }
13191: $output .= ' /> '.$choices{$action}.'</label></span>';
13192: if ($action eq 'dependency') {
13193: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13194: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13195: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13196: '<option value=""></option>'."\n".
13197: '</select>'."\n".
13198: '</div>';
1.1059 raeburn 13199: } elsif ($action eq 'display') {
13200: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13201: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13202: '</div>';
1.1055 raeburn 13203: }
1.1056 raeburn 13204: $output .= '</td>';
1.1055 raeburn 13205: }
13206: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13207: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13208: for (my $i=0; $i<$depth; $i++) {
13209: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13210: }
13211: if ($is_dir) {
13212: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13213: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13214: } else {
13215: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13216: }
13217: $output .= ' '.$name.'</td>'."\n".
13218: &end_data_table_row();
13219: return $output;
13220: }
13221:
13222: sub archive_options_form {
1.1065 raeburn 13223: my ($form,$display,$count,$hiddenelem) = @_;
13224: my %lt = &Apache::lonlocal::texthash(
13225: perm => 'Permanently remove archive file?',
13226: hows => 'How should each extracted item be incorporated in the course?',
13227: cont => 'Content actions for all',
13228: addf => 'Add as folder/file',
13229: incd => 'Include as dependency for a displayed file',
13230: disc => 'Discard',
13231: no => 'No',
13232: yes => 'Yes',
13233: save => 'Save',
13234: );
13235: my $output = <<"END";
13236: <form name="$form" method="post" action="">
13237: <p><span class="LC_nobreak">$lt{'perm'}
13238: <label>
13239: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13240: </label>
13241:
13242: <label>
13243: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13244: </span>
13245: </p>
13246: <input type="hidden" name="phase" value="decompress_cleanup" />
13247: <br />$lt{'hows'}
13248: <div class="LC_columnSection">
13249: <fieldset>
13250: <legend>$lt{'cont'}</legend>
13251: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13252: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13253: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13254: </fieldset>
13255: </div>
13256: END
13257: return $output.
1.1055 raeburn 13258: &start_data_table()."\n".
1.1065 raeburn 13259: $display."\n".
1.1055 raeburn 13260: &end_data_table()."\n".
13261: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13262: $hiddenelem.
1.1065 raeburn 13263: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13264: '</form>';
13265: }
13266:
13267: sub archive_javascript {
1.1056 raeburn 13268: my ($startcount,$numitems,$titles,$children) = @_;
13269: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13270: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13271: my $scripttag = <<START;
13272: <script type="text/javascript">
13273: // <![CDATA[
13274:
13275: function checkAll(form,prefix) {
13276: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13277: for (var i=0; i < form.elements.length; i++) {
13278: var id = form.elements[i].id;
13279: if ((id != '') && (id != undefined)) {
13280: if (idstr.test(id)) {
13281: if (form.elements[i].type == 'radio') {
13282: form.elements[i].checked = true;
1.1056 raeburn 13283: var nostart = i-$startcount;
1.1059 raeburn 13284: var offset = nostart%7;
13285: var count = (nostart-offset)/7;
1.1056 raeburn 13286: dependencyCheck(form,count,offset);
1.1055 raeburn 13287: }
13288: }
13289: }
13290: }
13291: }
13292:
13293: function propagateCheck(form,count) {
13294: if (count > 0) {
1.1059 raeburn 13295: var startelement = $startcount + ((count-1) * 7);
13296: for (var j=1; j<6; j++) {
13297: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13298: var item = startelement + j;
13299: if (form.elements[item].type == 'radio') {
13300: if (form.elements[item].checked) {
13301: containerCheck(form,count,j);
13302: break;
13303: }
1.1055 raeburn 13304: }
13305: }
13306: }
13307: }
13308: }
13309:
13310: numitems = $numitems
1.1056 raeburn 13311: var titles = new Array(numitems);
13312: var parents = new Array(numitems);
1.1055 raeburn 13313: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13314: parents[i] = new Array;
1.1055 raeburn 13315: }
1.1059 raeburn 13316: var maintitle = '$maintitle';
1.1055 raeburn 13317:
13318: START
13319:
1.1056 raeburn 13320: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13321: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13322: for (my $i=0; $i<@contents; $i ++) {
13323: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13324: }
13325: }
13326:
1.1056 raeburn 13327: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13328: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13329: }
13330:
1.1055 raeburn 13331: $scripttag .= <<END;
13332:
13333: function containerCheck(form,count,offset) {
13334: if (count > 0) {
1.1056 raeburn 13335: dependencyCheck(form,count,offset);
1.1059 raeburn 13336: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13337: form.elements[item].checked = true;
13338: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13339: if (parents[count].length > 0) {
13340: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13341: containerCheck(form,parents[count][j],offset);
13342: }
13343: }
13344: }
13345: }
13346: }
13347:
13348: function dependencyCheck(form,count,offset) {
13349: if (count > 0) {
1.1059 raeburn 13350: var chosen = (offset+$startcount)+7*(count-1);
13351: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13352: var currtype = form.elements[depitem].type;
13353: if (form.elements[chosen].value == 'dependency') {
13354: document.getElementById('arc_depon_'+count).style.display='block';
13355: form.elements[depitem].options.length = 0;
13356: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13357: for (var i=1; i<=numitems; i++) {
13358: if (i == count) {
13359: continue;
13360: }
1.1059 raeburn 13361: var startelement = $startcount + (i-1) * 7;
13362: for (var j=1; j<6; j++) {
13363: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13364: var item = startelement + j;
13365: if (form.elements[item].type == 'radio') {
13366: if (form.elements[item].checked) {
13367: if (form.elements[item].value == 'display') {
13368: var n = form.elements[depitem].options.length;
13369: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13370: }
13371: }
13372: }
13373: }
13374: }
13375: }
13376: } else {
13377: document.getElementById('arc_depon_'+count).style.display='none';
13378: form.elements[depitem].options.length = 0;
13379: form.elements[depitem].options[0] = new Option('Select','',true,true);
13380: }
1.1059 raeburn 13381: titleCheck(form,count,offset);
1.1056 raeburn 13382: }
13383: }
13384:
13385: function propagateSelect(form,count,offset) {
13386: if (count > 0) {
1.1065 raeburn 13387: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13388: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13389: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13390: if (parents[count].length > 0) {
13391: for (var j=0; j<parents[count].length; j++) {
13392: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13393: }
13394: }
13395: }
13396: }
13397: }
1.1056 raeburn 13398:
13399: function containerSelect(form,count,offset,picked) {
13400: if (count > 0) {
1.1065 raeburn 13401: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13402: if (form.elements[item].type == 'radio') {
13403: if (form.elements[item].value == 'dependency') {
13404: if (form.elements[item+1].type == 'select-one') {
13405: for (var i=0; i<form.elements[item+1].options.length; i++) {
13406: if (form.elements[item+1].options[i].value == picked) {
13407: form.elements[item+1].selectedIndex = i;
13408: break;
13409: }
13410: }
13411: }
13412: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13413: if (parents[count].length > 0) {
13414: for (var j=0; j<parents[count].length; j++) {
13415: containerSelect(form,parents[count][j],offset,picked);
13416: }
13417: }
13418: }
13419: }
13420: }
13421: }
13422: }
13423:
1.1059 raeburn 13424: function titleCheck(form,count,offset) {
13425: if (count > 0) {
13426: var chosen = (offset+$startcount)+7*(count-1);
13427: var depitem = $startcount + ((count-1) * 7) + 2;
13428: var currtype = form.elements[depitem].type;
13429: if (form.elements[chosen].value == 'display') {
13430: document.getElementById('arc_title_'+count).style.display='block';
13431: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13432: document.getElementById('archive_title_'+count).value=maintitle;
13433: }
13434: } else {
13435: document.getElementById('arc_title_'+count).style.display='none';
13436: if (currtype == 'text') {
13437: document.getElementById('archive_title_'+count).value='';
13438: }
13439: }
13440: }
13441: return;
13442: }
13443:
1.1055 raeburn 13444: // ]]>
13445: </script>
13446: END
13447: return $scripttag;
13448: }
13449:
13450: sub process_extracted_files {
1.1067 raeburn 13451: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13452: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 13453: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13454: my @ids=&Apache::lonnet::current_machine_ids();
13455: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13456: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13457: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13458: if (grep(/^\Q$docuhome\E$/,@ids)) {
13459: $prefix = &LONCAPA::propath($docudom,$docuname);
13460: $pathtocheck = "$dir_root/$destination";
13461: $dir = $dir_root;
13462: $ishome = 1;
13463: } else {
13464: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13465: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 13466: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13467: }
13468: my $currdir = "$dir_root/$destination";
13469: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13470: if ($env{'form.folderpath'}) {
13471: my @items = split('&',$env{'form.folderpath'});
13472: $folders{'0'} = $items[-2];
1.1099 raeburn 13473: if ($env{'form.folderpath'} =~ /\:1$/) {
13474: $containers{'0'}='page';
13475: } else {
13476: $containers{'0'}='sequence';
13477: }
1.1055 raeburn 13478: }
13479: my @archdirs = &get_env_multiple('form.archive_directory');
13480: if ($numitems) {
13481: for (my $i=1; $i<=$numitems; $i++) {
13482: my $path = $env{'form.archive_content_'.$i};
13483: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13484: my $item = $1;
13485: $toplevelitems{$item} = $i;
13486: if (grep(/^\Q$i\E$/,@archdirs)) {
13487: $is_dir{$item} = 1;
13488: }
13489: }
13490: }
13491: }
1.1067 raeburn 13492: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13493: if (keys(%toplevelitems) > 0) {
13494: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13495: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13496: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13497: }
1.1066 raeburn 13498: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13499: if ($numitems) {
13500: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13501: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13502: my $path = $env{'form.archive_content_'.$i};
13503: if ($path =~ /^\Q$pathtocheck\E/) {
13504: if ($env{'form.archive_'.$i} eq 'discard') {
13505: if ($prefix ne '' && $path ne '') {
13506: if (-e $prefix.$path) {
1.1066 raeburn 13507: if ((@archdirs > 0) &&
13508: (grep(/^\Q$i\E$/,@archdirs))) {
13509: $todeletedir{$prefix.$path} = 1;
13510: } else {
13511: $todelete{$prefix.$path} = 1;
13512: }
1.1055 raeburn 13513: }
13514: }
13515: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13516: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13517: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13518: $docstitle = $env{'form.archive_title_'.$i};
13519: if ($docstitle eq '') {
13520: $docstitle = $title;
13521: }
1.1055 raeburn 13522: $outer = 0;
1.1056 raeburn 13523: if (ref($dirorder{$i}) eq 'ARRAY') {
13524: if (@{$dirorder{$i}} > 0) {
13525: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13526: if ($env{'form.archive_'.$item} eq 'display') {
13527: $outer = $item;
13528: last;
13529: }
13530: }
13531: }
13532: }
13533: my ($errtext,$fatal) =
13534: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13535: '/'.$folders{$outer}.'.'.
13536: $containers{$outer});
13537: next if ($fatal);
13538: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13539: if ($context eq 'coursedocs') {
1.1056 raeburn 13540: $mapinner{$i} = time;
1.1055 raeburn 13541: $folders{$i} = 'default_'.$mapinner{$i};
13542: $containers{$i} = 'sequence';
13543: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13544: $folders{$i}.'.'.$containers{$i};
13545: my $newidx = &LONCAPA::map::getresidx();
13546: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13547: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13548: push(@LONCAPA::map::order,$newidx);
13549: my ($outtext,$errtext) =
13550: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13551: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13552: '.'.$containers{$outer},1,1);
1.1056 raeburn 13553: $newseqid{$i} = $newidx;
1.1067 raeburn 13554: unless ($errtext) {
1.1294 raeburn 13555: $result .= '<li>'.&mt('Folder: [_1] added to course',
13556: &HTML::Entities::encode($docstitle,'<>&"')).
13557: '</li>'."\n";
1.1067 raeburn 13558: }
1.1055 raeburn 13559: }
13560: } else {
13561: if ($context eq 'coursedocs') {
13562: my $newidx=&LONCAPA::map::getresidx();
13563: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13564: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13565: $title;
1.1294 raeburn 13566: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
13567: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13568: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13569: }
13570: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13571: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13572: }
13573: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13574: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13575: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13576: unless ($ishome) {
13577: my $fetch = "$newdest{$i}/$title";
13578: $fetch =~ s/^\Q$prefix$dir\E//;
13579: $prompttofetch{$fetch} = 1;
13580: }
1.1292 raeburn 13581: }
1.1067 raeburn 13582: }
1.1294 raeburn 13583: $LONCAPA::map::resources[$newidx]=
13584: $docstitle.':'.$url.':false:normal:res';
13585: push(@LONCAPA::map::order, $newidx);
13586: my ($outtext,$errtext)=
13587: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13588: $docuname.'/'.$folders{$outer}.
13589: '.'.$containers{$outer},1,1);
13590: unless ($errtext) {
13591: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13592: $result .= '<li>'.&mt('File: [_1] added to course',
13593: &HTML::Entities::encode($docstitle,'<>&"')).
13594: '</li>'."\n";
13595: }
1.1067 raeburn 13596: }
1.1294 raeburn 13597: } else {
13598: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13599: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 13600: }
1.1055 raeburn 13601: }
13602: }
1.1086 raeburn 13603: }
13604: } else {
1.1294 raeburn 13605: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13606: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 13607: }
13608: }
13609: for (my $i=1; $i<=$numitems; $i++) {
13610: next unless ($env{'form.archive_'.$i} eq 'dependency');
13611: my $path = $env{'form.archive_content_'.$i};
13612: if ($path =~ /^\Q$pathtocheck\E/) {
13613: my ($title) = ($path =~ m{/([^/]+)$});
13614: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13615: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13616: if (ref($dirorder{$i}) eq 'ARRAY') {
13617: my ($itemidx,$fullpath,$relpath);
13618: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13619: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13620: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13621: if ($dirorder{$i}->[$j] eq $container) {
13622: $itemidx = $j;
1.1056 raeburn 13623: }
13624: }
1.1086 raeburn 13625: }
13626: if ($itemidx eq '') {
13627: $itemidx = 0;
13628: }
13629: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13630: if ($mapinner{$referrer{$i}}) {
13631: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13632: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13633: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13634: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13635: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13636: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13637: if (!-e $fullpath) {
13638: mkdir($fullpath,0755);
1.1056 raeburn 13639: }
13640: }
1.1086 raeburn 13641: } else {
13642: last;
1.1056 raeburn 13643: }
1.1086 raeburn 13644: }
13645: }
13646: } elsif ($newdest{$referrer{$i}}) {
13647: $fullpath = $newdest{$referrer{$i}};
13648: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13649: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13650: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13651: last;
13652: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13653: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13654: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13655: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13656: if (!-e $fullpath) {
13657: mkdir($fullpath,0755);
1.1056 raeburn 13658: }
13659: }
1.1086 raeburn 13660: } else {
13661: last;
1.1056 raeburn 13662: }
1.1055 raeburn 13663: }
13664: }
1.1086 raeburn 13665: if ($fullpath ne '') {
13666: if (-e "$prefix$path") {
1.1292 raeburn 13667: unless (rename("$prefix$path","$fullpath/$title")) {
13668: $warning .= &mt('Failed to rename dependency').'<br />';
13669: }
1.1086 raeburn 13670: }
13671: if (-e "$fullpath/$title") {
13672: my $showpath;
13673: if ($relpath ne '') {
13674: $showpath = "$relpath/$title";
13675: } else {
13676: $showpath = "/$title";
13677: }
1.1294 raeburn 13678: $result .= '<li>'.&mt('[_1] included as a dependency',
13679: &HTML::Entities::encode($showpath,'<>&"')).
13680: '</li>'."\n";
1.1292 raeburn 13681: unless ($ishome) {
13682: my $fetch = "$fullpath/$title";
13683: $fetch =~ s/^\Q$prefix$dir\E//;
13684: $prompttofetch{$fetch} = 1;
13685: }
1.1086 raeburn 13686: }
13687: }
1.1055 raeburn 13688: }
1.1086 raeburn 13689: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13690: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 13691: &HTML::Entities::encode($path,'<>&"'),
13692: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13693: '<br />';
1.1055 raeburn 13694: }
13695: } else {
1.1294 raeburn 13696: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 13697: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13698: }
13699: }
13700: if (keys(%todelete)) {
13701: foreach my $key (keys(%todelete)) {
13702: unlink($key);
1.1066 raeburn 13703: }
13704: }
13705: if (keys(%todeletedir)) {
13706: foreach my $key (keys(%todeletedir)) {
13707: rmdir($key);
13708: }
13709: }
13710: foreach my $dir (sort(keys(%is_dir))) {
13711: if (($pathtocheck ne '') && ($dir ne '')) {
13712: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13713: }
13714: }
1.1067 raeburn 13715: if ($result ne '') {
13716: $output .= '<ul>'."\n".
13717: $result."\n".
13718: '</ul>';
13719: }
13720: unless ($ishome) {
13721: my $replicationfail;
13722: foreach my $item (keys(%prompttofetch)) {
13723: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13724: unless ($fetchresult eq 'ok') {
13725: $replicationfail .= '<li>'.$item.'</li>'."\n";
13726: }
13727: }
13728: if ($replicationfail) {
13729: $output .= '<p class="LC_error">'.
13730: &mt('Course home server failed to retrieve:').'<ul>'.
13731: $replicationfail.
13732: '</ul></p>';
13733: }
13734: }
1.1055 raeburn 13735: } else {
13736: $warning = &mt('No items found in archive.');
13737: }
13738: if ($error) {
13739: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13740: $error.'</p>'."\n";
13741: }
13742: if ($warning) {
13743: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13744: }
13745: return $output;
13746: }
13747:
1.1066 raeburn 13748: sub cleanup_empty_dirs {
13749: my ($path) = @_;
13750: if (($path ne '') && (-d $path)) {
13751: if (opendir(my $dirh,$path)) {
13752: my @dircontents = grep(!/^\./,readdir($dirh));
13753: my $numitems = 0;
13754: foreach my $item (@dircontents) {
13755: if (-d "$path/$item") {
1.1111 raeburn 13756: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13757: if (-e "$path/$item") {
13758: $numitems ++;
13759: }
13760: } else {
13761: $numitems ++;
13762: }
13763: }
13764: if ($numitems == 0) {
13765: rmdir($path);
13766: }
13767: closedir($dirh);
13768: }
13769: }
13770: return;
13771: }
13772:
1.41 ng 13773: =pod
1.45 matthew 13774:
1.1162 raeburn 13775: =item * &get_folder_hierarchy()
1.1068 raeburn 13776:
13777: Provides hierarchy of names of folders/sub-folders containing the current
13778: item,
13779:
13780: Inputs: 3
13781: - $navmap - navmaps object
13782:
13783: - $map - url for map (either the trigger itself, or map containing
13784: the resource, which is the trigger).
13785:
13786: - $showitem - 1 => show title for map itself; 0 => do not show.
13787:
13788: Outputs: 1 @pathitems - array of folder/subfolder names.
13789:
13790: =cut
13791:
13792: sub get_folder_hierarchy {
13793: my ($navmap,$map,$showitem) = @_;
13794: my @pathitems;
13795: if (ref($navmap)) {
13796: my $mapres = $navmap->getResourceByUrl($map);
13797: if (ref($mapres)) {
13798: my $pcslist = $mapres->map_hierarchy();
13799: if ($pcslist ne '') {
13800: my @pcs = split(/,/,$pcslist);
13801: foreach my $pc (@pcs) {
13802: if ($pc == 1) {
1.1129 raeburn 13803: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13804: } else {
13805: my $res = $navmap->getByMapPc($pc);
13806: if (ref($res)) {
13807: my $title = $res->compTitle();
13808: $title =~ s/\W+/_/g;
13809: if ($title ne '') {
13810: push(@pathitems,$title);
13811: }
13812: }
13813: }
13814: }
13815: }
1.1071 raeburn 13816: if ($showitem) {
13817: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 13818: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13819: } else {
13820: my $maptitle = $mapres->compTitle();
13821: $maptitle =~ s/\W+/_/g;
13822: if ($maptitle ne '') {
13823: push(@pathitems,$maptitle);
13824: }
1.1068 raeburn 13825: }
13826: }
13827: }
13828: }
13829: return @pathitems;
13830: }
13831:
13832: =pod
13833:
1.1015 raeburn 13834: =item * &get_turnedin_filepath()
13835:
13836: Determines path in a user's portfolio file for storage of files uploaded
13837: to a specific essayresponse or dropbox item.
13838:
13839: Inputs: 3 required + 1 optional.
13840: $symb is symb for resource, $uname and $udom are for current user (required).
13841: $caller is optional (can be "submission", if routine is called when storing
13842: an upoaded file when "Submit Answer" button was pressed).
13843:
13844: Returns array containing $path and $multiresp.
13845: $path is path in portfolio. $multiresp is 1 if this resource contains more
13846: than one file upload item. Callers of routine should append partid as a
13847: subdirectory to $path in cases where $multiresp is 1.
13848:
13849: Called by: homework/essayresponse.pm and homework/structuretags.pm
13850:
13851: =cut
13852:
13853: sub get_turnedin_filepath {
13854: my ($symb,$uname,$udom,$caller) = @_;
13855: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13856: my $turnindir;
13857: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13858: $turnindir = $userhash{'turnindir'};
13859: my ($path,$multiresp);
13860: if ($turnindir eq '') {
13861: if ($caller eq 'submission') {
13862: $turnindir = &mt('turned in');
13863: $turnindir =~ s/\W+/_/g;
13864: my %newhash = (
13865: 'turnindir' => $turnindir,
13866: );
13867: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13868: }
13869: }
13870: if ($turnindir ne '') {
13871: $path = '/'.$turnindir.'/';
13872: my ($multipart,$turnin,@pathitems);
13873: my $navmap = Apache::lonnavmaps::navmap->new();
13874: if (defined($navmap)) {
13875: my $mapres = $navmap->getResourceByUrl($map);
13876: if (ref($mapres)) {
13877: my $pcslist = $mapres->map_hierarchy();
13878: if ($pcslist ne '') {
13879: foreach my $pc (split(/,/,$pcslist)) {
13880: my $res = $navmap->getByMapPc($pc);
13881: if (ref($res)) {
13882: my $title = $res->compTitle();
13883: $title =~ s/\W+/_/g;
13884: if ($title ne '') {
1.1149 raeburn 13885: if (($pc > 1) && (length($title) > 12)) {
13886: $title = substr($title,0,12);
13887: }
1.1015 raeburn 13888: push(@pathitems,$title);
13889: }
13890: }
13891: }
13892: }
13893: my $maptitle = $mapres->compTitle();
13894: $maptitle =~ s/\W+/_/g;
13895: if ($maptitle ne '') {
1.1149 raeburn 13896: if (length($maptitle) > 12) {
13897: $maptitle = substr($maptitle,0,12);
13898: }
1.1015 raeburn 13899: push(@pathitems,$maptitle);
13900: }
13901: unless ($env{'request.state'} eq 'construct') {
13902: my $res = $navmap->getBySymb($symb);
13903: if (ref($res)) {
13904: my $partlist = $res->parts();
13905: my $totaluploads = 0;
13906: if (ref($partlist) eq 'ARRAY') {
13907: foreach my $part (@{$partlist}) {
13908: my @types = $res->responseType($part);
13909: my @ids = $res->responseIds($part);
13910: for (my $i=0; $i < scalar(@ids); $i++) {
13911: if ($types[$i] eq 'essay') {
13912: my $partid = $part.'_'.$ids[$i];
13913: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13914: $totaluploads ++;
13915: }
13916: }
13917: }
13918: }
13919: if ($totaluploads > 1) {
13920: $multiresp = 1;
13921: }
13922: }
13923: }
13924: }
13925: } else {
13926: return;
13927: }
13928: } else {
13929: return;
13930: }
13931: my $restitle=&Apache::lonnet::gettitle($symb);
13932: $restitle =~ s/\W+/_/g;
13933: if ($restitle eq '') {
13934: $restitle = ($resurl =~ m{/[^/]+$});
13935: if ($restitle eq '') {
13936: $restitle = time;
13937: }
13938: }
1.1149 raeburn 13939: if (length($restitle) > 12) {
13940: $restitle = substr($restitle,0,12);
13941: }
1.1015 raeburn 13942: push(@pathitems,$restitle);
13943: $path .= join('/',@pathitems);
13944: }
13945: return ($path,$multiresp);
13946: }
13947:
13948: =pod
13949:
1.464 albertel 13950: =back
1.41 ng 13951:
1.112 bowersj2 13952: =head1 CSV Upload/Handling functions
1.38 albertel 13953:
1.41 ng 13954: =over 4
13955:
1.648 raeburn 13956: =item * &upfile_store($r)
1.41 ng 13957:
13958: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13959: needs $env{'form.upfile'}
1.41 ng 13960: returns $datatoken to be put into hidden field
13961:
13962: =cut
1.31 albertel 13963:
13964: sub upfile_store {
13965: my $r=shift;
1.258 albertel 13966: $env{'form.upfile'}=~s/\r/\n/gs;
13967: $env{'form.upfile'}=~s/\f/\n/gs;
13968: $env{'form.upfile'}=~s/\n+/\n/gs;
13969: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13970:
1.1299 raeburn 13971: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13972: '_enroll_'.$env{'request.course.id'}.'_'.
13973: time.'_'.$$);
13974: return if ($datatoken eq '');
13975:
1.31 albertel 13976: {
1.158 raeburn 13977: my $datafile = $r->dir_config('lonDaemons').
13978: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 13979: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13980: print $fh $env{'form.upfile'};
1.158 raeburn 13981: close($fh);
13982: }
1.31 albertel 13983: }
13984: return $datatoken;
13985: }
13986:
1.56 matthew 13987: =pod
13988:
1.1290 raeburn 13989: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13990:
13991: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 13992: $datatoken is the name to assign to the temporary file.
1.258 albertel 13993: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13994:
13995: =cut
1.31 albertel 13996:
13997: sub load_tmp_file {
1.1290 raeburn 13998: my ($r,$datatoken) = @_;
13999: return if ($datatoken eq '');
1.31 albertel 14000: my @studentdata=();
14001: {
1.158 raeburn 14002: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 14003: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14004: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14005: @studentdata=<$fh>;
14006: close($fh);
14007: }
1.31 albertel 14008: }
1.258 albertel 14009: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14010: }
14011:
1.1290 raeburn 14012: sub valid_datatoken {
14013: my ($datatoken) = @_;
1.1325 raeburn 14014: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1290 raeburn 14015: return $datatoken;
14016: }
14017: return;
14018: }
14019:
1.56 matthew 14020: =pod
14021:
1.648 raeburn 14022: =item * &upfile_record_sep()
1.41 ng 14023:
14024: Separate uploaded file into records
14025: returns array of records,
1.258 albertel 14026: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14027:
14028: =cut
1.31 albertel 14029:
14030: sub upfile_record_sep {
1.258 albertel 14031: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14032: } else {
1.248 albertel 14033: my @records;
1.258 albertel 14034: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14035: if ($line=~/^\s*$/) { next; }
14036: push(@records,$line);
14037: }
14038: return @records;
1.31 albertel 14039: }
14040: }
14041:
1.56 matthew 14042: =pod
14043:
1.648 raeburn 14044: =item * &record_sep($record)
1.41 ng 14045:
1.258 albertel 14046: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14047:
14048: =cut
14049:
1.263 www 14050: sub takeleft {
14051: my $index=shift;
14052: return substr('0000'.$index,-4,4);
14053: }
14054:
1.31 albertel 14055: sub record_sep {
14056: my $record=shift;
14057: my %components=();
1.258 albertel 14058: if ($env{'form.upfiletype'} eq 'xml') {
14059: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14060: my $i=0;
1.356 albertel 14061: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14062: $field=~s/^(\"|\')//;
14063: $field=~s/(\"|\')$//;
1.263 www 14064: $components{&takeleft($i)}=$field;
1.31 albertel 14065: $i++;
14066: }
1.258 albertel 14067: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14068: my $i=0;
1.356 albertel 14069: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14070: $field=~s/^(\"|\')//;
14071: $field=~s/(\"|\')$//;
1.263 www 14072: $components{&takeleft($i)}=$field;
1.31 albertel 14073: $i++;
14074: }
14075: } else {
1.561 www 14076: my $separator=',';
1.480 banghart 14077: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14078: $separator=';';
1.480 banghart 14079: }
1.31 albertel 14080: my $i=0;
1.561 www 14081: # the character we are looking for to indicate the end of a quote or a record
14082: my $looking_for=$separator;
14083: # do not add the characters to the fields
14084: my $ignore=0;
14085: # we just encountered a separator (or the beginning of the record)
14086: my $just_found_separator=1;
14087: # store the field we are working on here
14088: my $field='';
14089: # work our way through all characters in record
14090: foreach my $character ($record=~/(.)/g) {
14091: if ($character eq $looking_for) {
14092: if ($character ne $separator) {
14093: # Found the end of a quote, again looking for separator
14094: $looking_for=$separator;
14095: $ignore=1;
14096: } else {
14097: # Found a separator, store away what we got
14098: $components{&takeleft($i)}=$field;
14099: $i++;
14100: $just_found_separator=1;
14101: $ignore=0;
14102: $field='';
14103: }
14104: next;
14105: }
14106: # single or double quotation marks after a separator indicate beginning of a quote
14107: # we are now looking for the end of the quote and need to ignore separators
14108: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14109: $looking_for=$character;
14110: next;
14111: }
14112: # ignore would be true after we reached the end of a quote
14113: if ($ignore) { next; }
14114: if (($just_found_separator) && ($character=~/\s/)) { next; }
14115: $field.=$character;
14116: $just_found_separator=0;
1.31 albertel 14117: }
1.561 www 14118: # catch the very last entry, since we never encountered the separator
14119: $components{&takeleft($i)}=$field;
1.31 albertel 14120: }
14121: return %components;
14122: }
14123:
1.144 matthew 14124: ######################################################
14125: ######################################################
14126:
1.56 matthew 14127: =pod
14128:
1.648 raeburn 14129: =item * &upfile_select_html()
1.41 ng 14130:
1.144 matthew 14131: Return HTML code to select a file from the users machine and specify
14132: the file type.
1.41 ng 14133:
14134: =cut
14135:
1.144 matthew 14136: ######################################################
14137: ######################################################
1.31 albertel 14138: sub upfile_select_html {
1.144 matthew 14139: my %Types = (
14140: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14141: semisv => &mt('Semicolon separated values'),
1.144 matthew 14142: space => &mt('Space separated'),
14143: tab => &mt('Tabulator separated'),
14144: # xml => &mt('HTML/XML'),
14145: );
14146: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14147: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14148: foreach my $type (sort(keys(%Types))) {
14149: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14150: }
14151: $Str .= "</select>\n";
14152: return $Str;
1.31 albertel 14153: }
14154:
1.301 albertel 14155: sub get_samples {
14156: my ($records,$toget) = @_;
14157: my @samples=({});
14158: my $got=0;
14159: foreach my $rec (@$records) {
14160: my %temp = &record_sep($rec);
14161: if (! grep(/\S/, values(%temp))) { next; }
14162: if (%temp) {
14163: $samples[$got]=\%temp;
14164: $got++;
14165: if ($got == $toget) { last; }
14166: }
14167: }
14168: return \@samples;
14169: }
14170:
1.144 matthew 14171: ######################################################
14172: ######################################################
14173:
1.56 matthew 14174: =pod
14175:
1.648 raeburn 14176: =item * &csv_print_samples($r,$records)
1.41 ng 14177:
14178: Prints a table of sample values from each column uploaded $r is an
14179: Apache Request ref, $records is an arrayref from
14180: &Apache::loncommon::upfile_record_sep
14181:
14182: =cut
14183:
1.144 matthew 14184: ######################################################
14185: ######################################################
1.31 albertel 14186: sub csv_print_samples {
14187: my ($r,$records) = @_;
1.662 bisitz 14188: my $samples = &get_samples($records,5);
1.301 albertel 14189:
1.594 raeburn 14190: $r->print(&mt('Samples').'<br />'.&start_data_table().
14191: &start_data_table_header_row());
1.356 albertel 14192: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14193: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14194: $r->print(&end_data_table_header_row());
1.301 albertel 14195: foreach my $hash (@$samples) {
1.594 raeburn 14196: $r->print(&start_data_table_row());
1.356 albertel 14197: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14198: $r->print('<td>');
1.356 albertel 14199: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14200: $r->print('</td>');
14201: }
1.594 raeburn 14202: $r->print(&end_data_table_row());
1.31 albertel 14203: }
1.594 raeburn 14204: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14205: }
14206:
1.144 matthew 14207: ######################################################
14208: ######################################################
14209:
1.56 matthew 14210: =pod
14211:
1.648 raeburn 14212: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14213:
14214: Prints a table to create associations between values and table columns.
1.144 matthew 14215:
1.41 ng 14216: $r is an Apache Request ref,
14217: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14218: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14219:
14220: =cut
14221:
1.144 matthew 14222: ######################################################
14223: ######################################################
1.31 albertel 14224: sub csv_print_select_table {
14225: my ($r,$records,$d) = @_;
1.301 albertel 14226: my $i=0;
14227: my $samples = &get_samples($records,1);
1.144 matthew 14228: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14229: &start_data_table().&start_data_table_header_row().
1.144 matthew 14230: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14231: '<th>'.&mt('Column').'</th>'.
14232: &end_data_table_header_row()."\n");
1.356 albertel 14233: foreach my $array_ref (@$d) {
14234: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14235: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14236:
1.875 bisitz 14237: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14238: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14239: $r->print('<option value="none"></option>');
1.356 albertel 14240: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14241: $r->print('<option value="'.$sample.'"'.
14242: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14243: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14244: }
1.594 raeburn 14245: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14246: $i++;
14247: }
1.594 raeburn 14248: $r->print(&end_data_table());
1.31 albertel 14249: $i--;
14250: return $i;
14251: }
1.56 matthew 14252:
1.144 matthew 14253: ######################################################
14254: ######################################################
14255:
1.56 matthew 14256: =pod
1.31 albertel 14257:
1.648 raeburn 14258: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14259:
14260: Prints a table of sample values from the upload and can make associate samples to internal names.
14261:
14262: $r is an Apache Request ref,
14263: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14264: $d is an array of 2 element arrays (internal name, displayed name)
14265:
14266: =cut
14267:
1.144 matthew 14268: ######################################################
14269: ######################################################
1.31 albertel 14270: sub csv_samples_select_table {
14271: my ($r,$records,$d) = @_;
14272: my $i=0;
1.144 matthew 14273: #
1.662 bisitz 14274: my $max_samples = 5;
14275: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14276: $r->print(&start_data_table().
14277: &start_data_table_header_row().'<th>'.
14278: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14279: &end_data_table_header_row());
1.301 albertel 14280:
14281: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14282: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14283: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14284: foreach my $option (@$d) {
14285: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14286: $r->print('<option value="'.$value.'"'.
1.253 albertel 14287: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14288: $display.'</option>');
1.31 albertel 14289: }
14290: $r->print('</select></td><td>');
1.662 bisitz 14291: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14292: if (defined($samples->[$line]{$key})) {
14293: $r->print($samples->[$line]{$key}."<br />\n");
14294: }
14295: }
1.594 raeburn 14296: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14297: $i++;
14298: }
1.594 raeburn 14299: $r->print(&end_data_table());
1.31 albertel 14300: $i--;
14301: return($i);
1.115 matthew 14302: }
14303:
1.144 matthew 14304: ######################################################
14305: ######################################################
14306:
1.115 matthew 14307: =pod
14308:
1.648 raeburn 14309: =item * &clean_excel_name($name)
1.115 matthew 14310:
14311: Returns a replacement for $name which does not contain any illegal characters.
14312:
14313: =cut
14314:
1.144 matthew 14315: ######################################################
14316: ######################################################
1.115 matthew 14317: sub clean_excel_name {
14318: my ($name) = @_;
14319: $name =~ s/[:\*\?\/\\]//g;
14320: if (length($name) > 31) {
14321: $name = substr($name,0,31);
14322: }
14323: return $name;
1.25 albertel 14324: }
1.84 albertel 14325:
1.85 albertel 14326: =pod
14327:
1.648 raeburn 14328: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14329:
14330: Returns either 1 or undef
14331:
14332: 1 if the part is to be hidden, undef if it is to be shown
14333:
14334: Arguments are:
14335:
14336: $id the id of the part to be checked
14337: $symb, optional the symb of the resource to check
14338: $udom, optional the domain of the user to check for
14339: $uname, optional the username of the user to check for
14340:
14341: =cut
1.84 albertel 14342:
14343: sub check_if_partid_hidden {
14344: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14345: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14346: $symb,$udom,$uname);
1.141 albertel 14347: my $truth=1;
14348: #if the string starts with !, then the list is the list to show not hide
14349: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14350: my @hiddenlist=split(/,/,$hiddenparts);
14351: foreach my $checkid (@hiddenlist) {
1.141 albertel 14352: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14353: }
1.141 albertel 14354: return !$truth;
1.84 albertel 14355: }
1.127 matthew 14356:
1.138 matthew 14357:
14358: ############################################################
14359: ############################################################
14360:
14361: =pod
14362:
1.157 matthew 14363: =back
14364:
1.138 matthew 14365: =head1 cgi-bin script and graphing routines
14366:
1.157 matthew 14367: =over 4
14368:
1.648 raeburn 14369: =item * &get_cgi_id()
1.138 matthew 14370:
14371: Inputs: none
14372:
14373: Returns an id which can be used to pass environment variables
14374: to various cgi-bin scripts. These environment variables will
14375: be removed from the users environment after a given time by
14376: the routine &Apache::lonnet::transfer_profile_to_env.
14377:
14378: =cut
14379:
14380: ############################################################
14381: ############################################################
1.152 albertel 14382: my $uniq=0;
1.136 matthew 14383: sub get_cgi_id {
1.154 albertel 14384: $uniq=($uniq+1)%100000;
1.280 albertel 14385: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14386: }
14387:
1.127 matthew 14388: ############################################################
14389: ############################################################
14390:
14391: =pod
14392:
1.648 raeburn 14393: =item * &DrawBarGraph()
1.127 matthew 14394:
1.138 matthew 14395: Facilitates the plotting of data in a (stacked) bar graph.
14396: Puts plot definition data into the users environment in order for
14397: graph.png to plot it. Returns an <img> tag for the plot.
14398: The bars on the plot are labeled '1','2',...,'n'.
14399:
14400: Inputs:
14401:
14402: =over 4
14403:
14404: =item $Title: string, the title of the plot
14405:
14406: =item $xlabel: string, text describing the X-axis of the plot
14407:
14408: =item $ylabel: string, text describing the Y-axis of the plot
14409:
14410: =item $Max: scalar, the maximum Y value to use in the plot
14411: If $Max is < any data point, the graph will not be rendered.
14412:
1.140 matthew 14413: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14414: they are plotted. If undefined, default values will be used.
14415:
1.178 matthew 14416: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14417:
1.138 matthew 14418: =item @Values: An array of array references. Each array reference holds data
14419: to be plotted in a stacked bar chart.
14420:
1.239 matthew 14421: =item If the final element of @Values is a hash reference the key/value
14422: pairs will be added to the graph definition.
14423:
1.138 matthew 14424: =back
14425:
14426: Returns:
14427:
14428: An <img> tag which references graph.png and the appropriate identifying
14429: information for the plot.
14430:
1.127 matthew 14431: =cut
14432:
14433: ############################################################
14434: ############################################################
1.134 matthew 14435: sub DrawBarGraph {
1.178 matthew 14436: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14437: #
14438: if (! defined($colors)) {
14439: $colors = ['#33ff00',
14440: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14441: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14442: ];
14443: }
1.228 matthew 14444: my $extra_settings = {};
14445: if (ref($Values[-1]) eq 'HASH') {
14446: $extra_settings = pop(@Values);
14447: }
1.127 matthew 14448: #
1.136 matthew 14449: my $identifier = &get_cgi_id();
14450: my $id = 'cgi.'.$identifier;
1.129 matthew 14451: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14452: return '';
14453: }
1.225 matthew 14454: #
14455: my @Labels;
14456: if (defined($labels)) {
14457: @Labels = @$labels;
14458: } else {
14459: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 14460: push(@Labels,$i+1);
1.225 matthew 14461: }
14462: }
14463: #
1.129 matthew 14464: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14465: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14466: my %ValuesHash;
14467: my $NumSets=1;
14468: foreach my $array (@Values) {
14469: next if (! ref($array));
1.136 matthew 14470: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14471: join(',',@$array);
1.129 matthew 14472: }
1.127 matthew 14473: #
1.136 matthew 14474: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14475: if ($NumBars < 3) {
14476: $width = 120+$NumBars*32;
1.220 matthew 14477: $xskip = 1;
1.225 matthew 14478: $bar_width = 30;
14479: } elsif ($NumBars < 5) {
14480: $width = 120+$NumBars*20;
14481: $xskip = 1;
14482: $bar_width = 20;
1.220 matthew 14483: } elsif ($NumBars < 10) {
1.136 matthew 14484: $width = 120+$NumBars*15;
14485: $xskip = 1;
14486: $bar_width = 15;
14487: } elsif ($NumBars <= 25) {
14488: $width = 120+$NumBars*11;
14489: $xskip = 5;
14490: $bar_width = 8;
14491: } elsif ($NumBars <= 50) {
14492: $width = 120+$NumBars*8;
14493: $xskip = 5;
14494: $bar_width = 4;
14495: } else {
14496: $width = 120+$NumBars*8;
14497: $xskip = 5;
14498: $bar_width = 4;
14499: }
14500: #
1.137 matthew 14501: $Max = 1 if ($Max < 1);
14502: if ( int($Max) < $Max ) {
14503: $Max++;
14504: $Max = int($Max);
14505: }
1.127 matthew 14506: $Title = '' if (! defined($Title));
14507: $xlabel = '' if (! defined($xlabel));
14508: $ylabel = '' if (! defined($ylabel));
1.369 www 14509: $ValuesHash{$id.'.title'} = &escape($Title);
14510: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14511: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14512: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14513: $ValuesHash{$id.'.NumBars'} = $NumBars;
14514: $ValuesHash{$id.'.NumSets'} = $NumSets;
14515: $ValuesHash{$id.'.PlotType'} = 'bar';
14516: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14517: $ValuesHash{$id.'.height'} = $height;
14518: $ValuesHash{$id.'.width'} = $width;
14519: $ValuesHash{$id.'.xskip'} = $xskip;
14520: $ValuesHash{$id.'.bar_width'} = $bar_width;
14521: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14522: #
1.228 matthew 14523: # Deal with other parameters
14524: while (my ($key,$value) = each(%$extra_settings)) {
14525: $ValuesHash{$id.'.'.$key} = $value;
14526: }
14527: #
1.646 raeburn 14528: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14529: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14530: }
14531:
14532: ############################################################
14533: ############################################################
14534:
14535: =pod
14536:
1.648 raeburn 14537: =item * &DrawXYGraph()
1.137 matthew 14538:
1.138 matthew 14539: Facilitates the plotting of data in an XY graph.
14540: Puts plot definition data into the users environment in order for
14541: graph.png to plot it. Returns an <img> tag for the plot.
14542:
14543: Inputs:
14544:
14545: =over 4
14546:
14547: =item $Title: string, the title of the plot
14548:
14549: =item $xlabel: string, text describing the X-axis of the plot
14550:
14551: =item $ylabel: string, text describing the Y-axis of the plot
14552:
14553: =item $Max: scalar, the maximum Y value to use in the plot
14554: If $Max is < any data point, the graph will not be rendered.
14555:
14556: =item $colors: Array ref containing the hex color codes for the data to be
14557: plotted in. If undefined, default values will be used.
14558:
14559: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14560:
14561: =item $Ydata: Array ref containing Array refs.
1.185 www 14562: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14563:
14564: =item %Values: hash indicating or overriding any default values which are
14565: passed to graph.png.
14566: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14567:
14568: =back
14569:
14570: Returns:
14571:
14572: An <img> tag which references graph.png and the appropriate identifying
14573: information for the plot.
14574:
1.137 matthew 14575: =cut
14576:
14577: ############################################################
14578: ############################################################
14579: sub DrawXYGraph {
14580: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14581: #
14582: # Create the identifier for the graph
14583: my $identifier = &get_cgi_id();
14584: my $id = 'cgi.'.$identifier;
14585: #
14586: $Title = '' if (! defined($Title));
14587: $xlabel = '' if (! defined($xlabel));
14588: $ylabel = '' if (! defined($ylabel));
14589: my %ValuesHash =
14590: (
1.369 www 14591: $id.'.title' => &escape($Title),
14592: $id.'.xlabel' => &escape($xlabel),
14593: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14594: $id.'.y_max_value'=> $Max,
14595: $id.'.labels' => join(',',@$Xlabels),
14596: $id.'.PlotType' => 'XY',
14597: );
14598: #
14599: if (defined($colors) && ref($colors) eq 'ARRAY') {
14600: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14601: }
14602: #
14603: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14604: return '';
14605: }
14606: my $NumSets=1;
1.138 matthew 14607: foreach my $array (@{$Ydata}){
1.137 matthew 14608: next if (! ref($array));
14609: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14610: }
1.138 matthew 14611: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14612: #
14613: # Deal with other parameters
14614: while (my ($key,$value) = each(%Values)) {
14615: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14616: }
14617: #
1.646 raeburn 14618: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14619: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14620: }
14621:
14622: ############################################################
14623: ############################################################
14624:
14625: =pod
14626:
1.648 raeburn 14627: =item * &DrawXYYGraph()
1.138 matthew 14628:
14629: Facilitates the plotting of data in an XY graph with two Y axes.
14630: Puts plot definition data into the users environment in order for
14631: graph.png to plot it. Returns an <img> tag for the plot.
14632:
14633: Inputs:
14634:
14635: =over 4
14636:
14637: =item $Title: string, the title of the plot
14638:
14639: =item $xlabel: string, text describing the X-axis of the plot
14640:
14641: =item $ylabel: string, text describing the Y-axis of the plot
14642:
14643: =item $colors: Array ref containing the hex color codes for the data to be
14644: plotted in. If undefined, default values will be used.
14645:
14646: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14647:
14648: =item $Ydata1: The first data set
14649:
14650: =item $Min1: The minimum value of the left Y-axis
14651:
14652: =item $Max1: The maximum value of the left Y-axis
14653:
14654: =item $Ydata2: The second data set
14655:
14656: =item $Min2: The minimum value of the right Y-axis
14657:
14658: =item $Max2: The maximum value of the left Y-axis
14659:
14660: =item %Values: hash indicating or overriding any default values which are
14661: passed to graph.png.
14662: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14663:
14664: =back
14665:
14666: Returns:
14667:
14668: An <img> tag which references graph.png and the appropriate identifying
14669: information for the plot.
1.136 matthew 14670:
14671: =cut
14672:
14673: ############################################################
14674: ############################################################
1.137 matthew 14675: sub DrawXYYGraph {
14676: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14677: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14678: #
14679: # Create the identifier for the graph
14680: my $identifier = &get_cgi_id();
14681: my $id = 'cgi.'.$identifier;
14682: #
14683: $Title = '' if (! defined($Title));
14684: $xlabel = '' if (! defined($xlabel));
14685: $ylabel = '' if (! defined($ylabel));
14686: my %ValuesHash =
14687: (
1.369 www 14688: $id.'.title' => &escape($Title),
14689: $id.'.xlabel' => &escape($xlabel),
14690: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14691: $id.'.labels' => join(',',@$Xlabels),
14692: $id.'.PlotType' => 'XY',
14693: $id.'.NumSets' => 2,
1.137 matthew 14694: $id.'.two_axes' => 1,
14695: $id.'.y1_max_value' => $Max1,
14696: $id.'.y1_min_value' => $Min1,
14697: $id.'.y2_max_value' => $Max2,
14698: $id.'.y2_min_value' => $Min2,
1.136 matthew 14699: );
14700: #
1.137 matthew 14701: if (defined($colors) && ref($colors) eq 'ARRAY') {
14702: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14703: }
14704: #
14705: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14706: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14707: return '';
14708: }
14709: my $NumSets=1;
1.137 matthew 14710: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14711: next if (! ref($array));
14712: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14713: }
14714: #
14715: # Deal with other parameters
14716: while (my ($key,$value) = each(%Values)) {
14717: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14718: }
14719: #
1.646 raeburn 14720: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14721: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14722: }
14723:
14724: ############################################################
14725: ############################################################
14726:
14727: =pod
14728:
1.157 matthew 14729: =back
14730:
1.139 matthew 14731: =head1 Statistics helper routines?
14732:
14733: Bad place for them but what the hell.
14734:
1.157 matthew 14735: =over 4
14736:
1.648 raeburn 14737: =item * &chartlink()
1.139 matthew 14738:
14739: Returns a link to the chart for a specific student.
14740:
14741: Inputs:
14742:
14743: =over 4
14744:
14745: =item $linktext: The text of the link
14746:
14747: =item $sname: The students username
14748:
14749: =item $sdomain: The students domain
14750:
14751: =back
14752:
1.157 matthew 14753: =back
14754:
1.139 matthew 14755: =cut
14756:
14757: ############################################################
14758: ############################################################
14759: sub chartlink {
14760: my ($linktext, $sname, $sdomain) = @_;
14761: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14762: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14763: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14764: '">'.$linktext.'</a>';
1.153 matthew 14765: }
14766:
14767: #######################################################
14768: #######################################################
14769:
14770: =pod
14771:
14772: =head1 Course Environment Routines
1.157 matthew 14773:
14774: =over 4
1.153 matthew 14775:
1.648 raeburn 14776: =item * &restore_course_settings()
1.153 matthew 14777:
1.648 raeburn 14778: =item * &store_course_settings()
1.153 matthew 14779:
14780: Restores/Store indicated form parameters from the course environment.
14781: Will not overwrite existing values of the form parameters.
14782:
14783: Inputs:
14784: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14785:
14786: a hash ref describing the data to be stored. For example:
14787:
14788: %Save_Parameters = ('Status' => 'scalar',
14789: 'chartoutputmode' => 'scalar',
14790: 'chartoutputdata' => 'scalar',
14791: 'Section' => 'array',
1.373 raeburn 14792: 'Group' => 'array',
1.153 matthew 14793: 'StudentData' => 'array',
14794: 'Maps' => 'array');
14795:
14796: Returns: both routines return nothing
14797:
1.631 raeburn 14798: =back
14799:
1.153 matthew 14800: =cut
14801:
14802: #######################################################
14803: #######################################################
14804: sub store_course_settings {
1.496 albertel 14805: return &store_settings($env{'request.course.id'},@_);
14806: }
14807:
14808: sub store_settings {
1.153 matthew 14809: # save to the environment
14810: # appenv the same items, just to be safe
1.300 albertel 14811: my $udom = $env{'user.domain'};
14812: my $uname = $env{'user.name'};
1.496 albertel 14813: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14814: my %SaveHash;
14815: my %AppHash;
14816: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14817: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14818: my $envname = 'environment.'.$basename;
1.258 albertel 14819: if (exists($env{'form.'.$setting})) {
1.153 matthew 14820: # Save this value away
14821: if ($type eq 'scalar' &&
1.258 albertel 14822: (! exists($env{$envname}) ||
14823: $env{$envname} ne $env{'form.'.$setting})) {
14824: $SaveHash{$basename} = $env{'form.'.$setting};
14825: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14826: } elsif ($type eq 'array') {
14827: my $stored_form;
1.258 albertel 14828: if (ref($env{'form.'.$setting})) {
1.153 matthew 14829: $stored_form = join(',',
14830: map {
1.369 www 14831: &escape($_);
1.258 albertel 14832: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14833: } else {
14834: $stored_form =
1.369 www 14835: &escape($env{'form.'.$setting});
1.153 matthew 14836: }
14837: # Determine if the array contents are the same.
1.258 albertel 14838: if ($stored_form ne $env{$envname}) {
1.153 matthew 14839: $SaveHash{$basename} = $stored_form;
14840: $AppHash{$envname} = $stored_form;
14841: }
14842: }
14843: }
14844: }
14845: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14846: $udom,$uname);
1.153 matthew 14847: if ($put_result !~ /^(ok|delayed)/) {
14848: &Apache::lonnet::logthis('unable to save form parameters, '.
14849: 'got error:'.$put_result);
14850: }
14851: # Make sure these settings stick around in this session, too
1.646 raeburn 14852: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14853: return;
14854: }
14855:
14856: sub restore_course_settings {
1.499 albertel 14857: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14858: }
14859:
14860: sub restore_settings {
14861: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14862: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14863: next if (exists($env{'form.'.$setting}));
1.496 albertel 14864: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14865: '.'.$setting;
1.258 albertel 14866: if (exists($env{$envname})) {
1.153 matthew 14867: if ($type eq 'scalar') {
1.258 albertel 14868: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14869: } elsif ($type eq 'array') {
1.258 albertel 14870: $env{'form.'.$setting} = [
1.153 matthew 14871: map {
1.369 www 14872: &unescape($_);
1.258 albertel 14873: } split(',',$env{$envname})
1.153 matthew 14874: ];
14875: }
14876: }
14877: }
1.127 matthew 14878: }
14879:
1.618 raeburn 14880: #######################################################
14881: #######################################################
14882:
14883: =pod
14884:
14885: =head1 Domain E-mail Routines
14886:
14887: =over 4
14888:
1.648 raeburn 14889: =item * &build_recipient_list()
1.618 raeburn 14890:
1.1144 raeburn 14891: Build recipient lists for following types of e-mail:
1.766 raeburn 14892: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 14893: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14894: module change checking, student/employee ID conflict checks, as
14895: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14896: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14897:
14898: Inputs:
1.619 raeburn 14899: defmail (scalar - email address of default recipient),
1.1144 raeburn 14900: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14901: requestsmail, updatesmail, or idconflictsmail).
14902:
1.619 raeburn 14903: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 14904:
1.619 raeburn 14905: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 14906: i.e., predates configuration by DC via domainprefs.pm
14907:
14908: $requname username of requester (if mailing type is helpdeskmail)
14909:
14910: $requdom domain of requester (if mailing type is helpdeskmail)
14911:
14912: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14913:
1.618 raeburn 14914:
1.655 raeburn 14915: Returns: comma separated list of addresses to which to send e-mail.
14916:
14917: =back
1.618 raeburn 14918:
14919: =cut
14920:
14921: ############################################################
14922: ############################################################
14923: sub build_recipient_list {
1.1297 raeburn 14924: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14925: my @recipients;
1.1270 raeburn 14926: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14927: my %domconfig =
1.1270 raeburn 14928: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14929: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14930: if (exists($domconfig{'contacts'}{$mailing})) {
14931: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14932: my @contacts = ('adminemail','supportemail');
14933: foreach my $item (@contacts) {
14934: if ($domconfig{'contacts'}{$mailing}{$item}) {
14935: my $addr = $domconfig{'contacts'}{$item};
14936: if (!grep(/^\Q$addr\E$/,@recipients)) {
14937: push(@recipients,$addr);
14938: }
1.619 raeburn 14939: }
1.1270 raeburn 14940: }
14941: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14942: if ($mailing eq 'helpdeskmail') {
14943: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14944: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14945: my @ok_bccs;
14946: foreach my $bcc (@bccs) {
14947: $bcc =~ s/^\s+//g;
14948: $bcc =~ s/\s+$//g;
14949: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14950: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14951: push(@ok_bccs,$bcc);
14952: }
14953: }
14954: }
14955: if (@ok_bccs > 0) {
14956: $allbcc = join(', ',@ok_bccs);
14957: }
14958: }
14959: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14960: }
14961: }
1.766 raeburn 14962: } elsif ($origmail ne '') {
1.1270 raeburn 14963: $lastresort = $origmail;
1.618 raeburn 14964: }
1.1297 raeburn 14965: if ($mailing eq 'helpdeskmail') {
14966: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14967: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14968: my ($inststatus,$inststatus_checked);
14969: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14970: ($env{'user.domain'} ne 'public')) {
14971: $inststatus_checked = 1;
14972: $inststatus = $env{'environment.inststatus'};
14973: }
14974: unless ($inststatus_checked) {
14975: if (($requname ne '') && ($requdom ne '')) {
14976: if (($requname =~ /^$match_username$/) &&
14977: ($requdom =~ /^$match_domain$/) &&
14978: (&Apache::lonnet::domain($requdom))) {
14979: my $requhome = &Apache::lonnet::homeserver($requname,
14980: $requdom);
14981: unless ($requhome eq 'no_host') {
14982: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14983: $inststatus = $userenv{'inststatus'};
14984: $inststatus_checked = 1;
14985: }
14986: }
14987: }
14988: }
14989: unless ($inststatus_checked) {
14990: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
14991: my %srch = (srchby => 'email',
14992: srchdomain => $defdom,
14993: srchterm => $reqemail,
14994: srchtype => 'exact');
14995: my %srch_results = &Apache::lonnet::usersearch(\%srch);
14996: foreach my $uname (keys(%srch_results)) {
14997: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14998: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14999: $inststatus_checked = 1;
15000: last;
15001: }
15002: }
15003: unless ($inststatus_checked) {
15004: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15005: if ($dirsrchres eq 'ok') {
15006: foreach my $uname (keys(%srch_results)) {
15007: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15008: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15009: $inststatus_checked = 1;
15010: last;
15011: }
15012: }
15013: }
15014: }
15015: }
15016: }
15017: if ($inststatus ne '') {
15018: foreach my $status (split(/\:/,$inststatus)) {
15019: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15020: my @contacts = ('adminemail','supportemail');
15021: foreach my $item (@contacts) {
15022: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15023: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15024: if (!grep(/^\Q$addr\E$/,@recipients)) {
15025: push(@recipients,$addr);
15026: }
15027: }
15028: }
15029: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15030: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15031: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15032: my @ok_bccs;
15033: foreach my $bcc (@bccs) {
15034: $bcc =~ s/^\s+//g;
15035: $bcc =~ s/\s+$//g;
15036: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15037: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15038: push(@ok_bccs,$bcc);
15039: }
15040: }
15041: }
15042: if (@ok_bccs > 0) {
15043: $allbcc = join(', ',@ok_bccs);
15044: }
15045: }
15046: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15047: last;
15048: }
15049: }
15050: }
15051: }
15052: }
1.619 raeburn 15053: } elsif ($origmail ne '') {
1.1270 raeburn 15054: $lastresort = $origmail;
15055: }
1.1297 raeburn 15056: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 15057: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15058: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15059: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15060: my %what = (
15061: perlvar => 1,
15062: );
15063: my $primary = &Apache::lonnet::domain($defdom,'primary');
15064: if ($primary) {
15065: my $gotaddr;
15066: my ($result,$returnhash) =
15067: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15068: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15069: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15070: $lastresort = $returnhash->{'lonSupportEMail'};
15071: $gotaddr = 1;
15072: }
15073: }
15074: unless ($gotaddr) {
15075: my $uintdom = &Apache::lonnet::internet_dom($primary);
15076: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15077: unless ($uintdom eq $intdom) {
15078: my %domconfig =
15079: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15080: if (ref($domconfig{'contacts'}) eq 'HASH') {
15081: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15082: my @contacts = ('adminemail','supportemail');
15083: foreach my $item (@contacts) {
15084: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15085: my $addr = $domconfig{'contacts'}{$item};
15086: if (!grep(/^\Q$addr\E$/,@recipients)) {
15087: push(@recipients,$addr);
15088: }
15089: }
15090: }
15091: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15092: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15093: }
15094: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15095: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15096: my @ok_bccs;
15097: foreach my $bcc (@bccs) {
15098: $bcc =~ s/^\s+//g;
15099: $bcc =~ s/\s+$//g;
15100: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15101: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15102: push(@ok_bccs,$bcc);
15103: }
15104: }
15105: }
15106: if (@ok_bccs > 0) {
15107: $allbcc = join(', ',@ok_bccs);
15108: }
15109: }
15110: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15111: }
15112: }
15113: }
15114: }
15115: }
15116: }
1.618 raeburn 15117: }
1.688 raeburn 15118: if (defined($defmail)) {
15119: if ($defmail ne '') {
15120: push(@recipients,$defmail);
15121: }
1.618 raeburn 15122: }
15123: if ($otheremails) {
1.619 raeburn 15124: my @others;
15125: if ($otheremails =~ /,/) {
15126: @others = split(/,/,$otheremails);
1.618 raeburn 15127: } else {
1.619 raeburn 15128: push(@others,$otheremails);
15129: }
15130: foreach my $addr (@others) {
15131: if (!grep(/^\Q$addr\E$/,@recipients)) {
15132: push(@recipients,$addr);
15133: }
1.618 raeburn 15134: }
15135: }
1.1298 raeburn 15136: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 15137: if ((!@recipients) && ($lastresort ne '')) {
15138: push(@recipients,$lastresort);
15139: }
15140: } elsif ($lastresort ne '') {
15141: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15142: push(@recipients,$lastresort);
15143: }
15144: }
1.1271 raeburn 15145: my $recipientlist = join(',',@recipients);
1.1270 raeburn 15146: if (wantarray) {
15147: return ($recipientlist,$allbcc,$addtext);
15148: } else {
15149: return $recipientlist;
15150: }
1.618 raeburn 15151: }
15152:
1.127 matthew 15153: ############################################################
15154: ############################################################
1.154 albertel 15155:
1.655 raeburn 15156: =pod
15157:
1.1224 musolffc 15158: =over 4
15159:
1.1223 musolffc 15160: =item * &mime_email()
15161:
15162: Sends an email with a possible attachment
15163:
15164: Inputs:
15165:
15166: =over 4
15167:
15168: from - Sender's email address
15169:
15170: to - Email address of recipient
15171:
15172: subject - Subject of email
15173:
15174: body - Body of email
15175:
15176: cc_string - Carbon copy email address
15177:
15178: bcc - Blind carbon copy email address
15179:
15180: type - File type of attachment
15181:
15182: attachment_path - Path of file to be attached
15183:
15184: file_name - Name of file to be attached
15185:
15186: attachment_text - The body of an attachment of type "TEXT"
15187:
15188: =back
15189:
15190: =back
15191:
15192: =cut
15193:
15194: ############################################################
15195: ############################################################
15196:
15197: sub mime_email {
15198: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
15199: $file_name, $attachment_text) = @_;
15200: my $msg = MIME::Lite->new(
15201: From => $from,
15202: To => $to,
15203: Subject => $subject,
15204: Type =>'TEXT',
15205: Data => $body,
15206: );
15207: if ($cc_string ne '') {
15208: $msg->add("Cc" => $cc_string);
15209: }
15210: if ($bcc ne '') {
15211: $msg->add("Bcc" => $bcc);
15212: }
15213: $msg->attr("content-type" => "text/plain");
15214: $msg->attr("content-type.charset" => "UTF-8");
15215: # Attach file if given
15216: if ($attachment_path) {
15217: unless ($file_name) {
15218: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
15219: }
15220: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
15221: $msg->attach(Type => $type,
15222: Path => $attachment_path,
15223: Filename => $file_name
15224: );
15225: # Otherwise attach text if given
15226: } elsif ($attachment_text) {
15227: $msg->attach(Type => 'TEXT',
15228: Data => $attachment_text);
15229: }
15230: # Send it
15231: $msg->send('sendmail');
15232: }
15233:
15234: ############################################################
15235: ############################################################
15236:
15237: =pod
15238:
1.655 raeburn 15239: =head1 Course Catalog Routines
15240:
15241: =over 4
15242:
15243: =item * &gather_categories()
15244:
15245: Converts category definitions - keys of categories hash stored in
15246: coursecategories in configuration.db on the primary library server in a
15247: domain - to an array. Also generates javascript and idx hash used to
15248: generate Domain Coordinator interface for editing Course Categories.
15249:
15250: Inputs:
1.663 raeburn 15251:
1.655 raeburn 15252: categories (reference to hash of category definitions).
1.663 raeburn 15253:
1.655 raeburn 15254: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15255: categories and subcategories).
1.663 raeburn 15256:
1.655 raeburn 15257: idx (reference to hash of counters used in Domain Coordinator interface for
15258: editing Course Categories).
1.663 raeburn 15259:
1.655 raeburn 15260: jsarray (reference to array of categories used to create Javascript arrays for
15261: Domain Coordinator interface for editing Course Categories).
15262:
15263: Returns: nothing
15264:
15265: Side effects: populates cats, idx and jsarray.
15266:
15267: =cut
15268:
15269: sub gather_categories {
15270: my ($categories,$cats,$idx,$jsarray) = @_;
15271: my %counters;
15272: my $num = 0;
15273: foreach my $item (keys(%{$categories})) {
15274: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15275: if ($container eq '' && $depth == 0) {
15276: $cats->[$depth][$categories->{$item}] = $cat;
15277: } else {
15278: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15279: }
15280: my ($escitem,$tail) = split(/:/,$item,2);
15281: if ($counters{$tail} eq '') {
15282: $counters{$tail} = $num;
15283: $num ++;
15284: }
15285: if (ref($idx) eq 'HASH') {
15286: $idx->{$item} = $counters{$tail};
15287: }
15288: if (ref($jsarray) eq 'ARRAY') {
15289: push(@{$jsarray->[$counters{$tail}]},$item);
15290: }
15291: }
15292: return;
15293: }
15294:
15295: =pod
15296:
15297: =item * &extract_categories()
15298:
15299: Used to generate breadcrumb trails for course categories.
15300:
15301: Inputs:
1.663 raeburn 15302:
1.655 raeburn 15303: categories (reference to hash of category definitions).
1.663 raeburn 15304:
1.655 raeburn 15305: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15306: categories and subcategories).
1.663 raeburn 15307:
1.655 raeburn 15308: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15309:
1.655 raeburn 15310: allitems (reference to hash - key is category key
15311: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15312:
1.655 raeburn 15313: idx (reference to hash of counters used in Domain Coordinator interface for
15314: editing Course Categories).
1.663 raeburn 15315:
1.655 raeburn 15316: jsarray (reference to array of categories used to create Javascript arrays for
15317: Domain Coordinator interface for editing Course Categories).
15318:
1.665 raeburn 15319: subcats (reference to hash of arrays containing all subcategories within each
15320: category, -recursive)
15321:
1.1321 raeburn 15322: maxd (reference to hash used to hold max depth for all top-level categories).
15323:
1.655 raeburn 15324: Returns: nothing
15325:
15326: Side effects: populates trails and allitems hash references.
15327:
15328: =cut
15329:
15330: sub extract_categories {
1.1321 raeburn 15331: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 15332: if (ref($categories) eq 'HASH') {
15333: &gather_categories($categories,$cats,$idx,$jsarray);
15334: if (ref($cats->[0]) eq 'ARRAY') {
15335: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15336: my $name = $cats->[0][$i];
15337: my $item = &escape($name).'::0';
15338: my $trailstr;
15339: if ($name eq 'instcode') {
15340: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15341: } elsif ($name eq 'communities') {
15342: $trailstr = &mt('Communities');
1.1239 raeburn 15343: } elsif ($name eq 'placement') {
15344: $trailstr = &mt('Placement Tests');
1.655 raeburn 15345: } else {
15346: $trailstr = $name;
15347: }
15348: if ($allitems->{$item} eq '') {
15349: push(@{$trails},$trailstr);
15350: $allitems->{$item} = scalar(@{$trails})-1;
15351: }
15352: my @parents = ($name);
15353: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15354: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15355: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15356: if (ref($subcats) eq 'HASH') {
15357: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15358: }
1.1321 raeburn 15359: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 15360: }
15361: } else {
15362: if (ref($subcats) eq 'HASH') {
15363: $subcats->{$item} = [];
1.655 raeburn 15364: }
1.1321 raeburn 15365: if (ref($maxd) eq 'HASH') {
15366: $maxd->{$name} = 1;
15367: }
1.655 raeburn 15368: }
15369: }
15370: }
15371: }
15372: return;
15373: }
15374:
15375: =pod
15376:
1.1162 raeburn 15377: =item * &recurse_categories()
1.655 raeburn 15378:
15379: Recursively used to generate breadcrumb trails for course categories.
15380:
15381: Inputs:
1.663 raeburn 15382:
1.655 raeburn 15383: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15384: categories and subcategories).
1.663 raeburn 15385:
1.655 raeburn 15386: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15387:
15388: category (current course category, for which breadcrumb trail is being generated).
15389:
15390: trails (reference to array of breadcrumb trails for each category).
15391:
1.655 raeburn 15392: allitems (reference to hash - key is category key
15393: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15394:
1.655 raeburn 15395: parents (array containing containers directories for current category,
15396: back to top level).
15397:
15398: Returns: nothing
15399:
15400: Side effects: populates trails and allitems hash references
15401:
15402: =cut
15403:
15404: sub recurse_categories {
1.1321 raeburn 15405: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 15406: my $shallower = $depth - 1;
15407: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
15408: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
15409: my $name = $cats->[$depth]{$category}[$k];
15410: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15411: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15412: if ($allitems->{$item} eq '') {
15413: push(@{$trails},$trailstr);
15414: $allitems->{$item} = scalar(@{$trails})-1;
15415: }
15416: my $deeper = $depth+1;
15417: push(@{$parents},$category);
1.665 raeburn 15418: if (ref($subcats) eq 'HASH') {
15419: my $subcat = &escape($name).':'.$category.':'.$depth;
15420: for (my $j=@{$parents}; $j>=0; $j--) {
15421: my $higher;
15422: if ($j > 0) {
15423: $higher = &escape($parents->[$j]).':'.
15424: &escape($parents->[$j-1]).':'.$j;
15425: } else {
15426: $higher = &escape($parents->[$j]).'::'.$j;
15427: }
15428: push(@{$subcats->{$higher}},$subcat);
15429: }
15430: }
15431: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 15432: $subcats,$maxd);
1.655 raeburn 15433: pop(@{$parents});
15434: }
15435: } else {
15436: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15437: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15438: if ($allitems->{$item} eq '') {
15439: push(@{$trails},$trailstr);
15440: $allitems->{$item} = scalar(@{$trails})-1;
15441: }
1.1321 raeburn 15442: if (ref($maxd) eq 'HASH') {
15443: if ($depth > $maxd->{$parents->[0]}) {
15444: $maxd->{$parents->[0]} = $depth;
15445: }
15446: }
1.655 raeburn 15447: }
15448: return;
15449: }
15450:
1.663 raeburn 15451: =pod
15452:
1.1162 raeburn 15453: =item * &assign_categories_table()
1.663 raeburn 15454:
15455: Create a datatable for display of hierarchical categories in a domain,
15456: with checkboxes to allow a course to be categorized.
15457:
15458: Inputs:
15459:
15460: cathash - reference to hash of categories defined for the domain (from
15461: configuration.db)
15462:
15463: currcat - scalar with an & separated list of categories assigned to a course.
15464:
1.919 raeburn 15465: type - scalar contains course type (Course or Community).
15466:
1.1260 raeburn 15467: disabled - scalar (optional) contains disabled="disabled" if input elements are
15468: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15469:
1.663 raeburn 15470: Returns: $output (markup to be displayed)
15471:
15472: =cut
15473:
15474: sub assign_categories_table {
1.1259 raeburn 15475: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15476: my $output;
15477: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 15478: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
15479: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 15480: $maxdepth = scalar(@cats);
15481: if (@cats > 0) {
15482: my $itemcount = 0;
15483: if (ref($cats[0]) eq 'ARRAY') {
15484: my @currcategories;
15485: if ($currcat ne '') {
15486: @currcategories = split('&',$currcat);
15487: }
1.919 raeburn 15488: my $table;
1.663 raeburn 15489: for (my $i=0; $i<@{$cats[0]}; $i++) {
15490: my $parent = $cats[0][$i];
1.919 raeburn 15491: next if ($parent eq 'instcode');
15492: if ($type eq 'Community') {
15493: next unless ($parent eq 'communities');
1.1239 raeburn 15494: } elsif ($type eq 'Placement') {
15495: next unless ($parent eq 'placement');
1.919 raeburn 15496: } else {
1.1239 raeburn 15497: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 15498: }
1.663 raeburn 15499: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15500: my $item = &escape($parent).'::0';
15501: my $checked = '';
15502: if (@currcategories > 0) {
15503: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15504: $checked = ' checked="checked"';
1.663 raeburn 15505: }
15506: }
1.919 raeburn 15507: my $parent_title = $parent;
15508: if ($parent eq 'communities') {
15509: $parent_title = &mt('Communities');
1.1239 raeburn 15510: } elsif ($parent eq 'placement') {
15511: $parent_title = &mt('Placement Tests');
1.919 raeburn 15512: }
15513: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15514: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15515: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15516: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15517: my $depth = 1;
15518: push(@path,$parent);
1.1259 raeburn 15519: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15520: pop(@path);
1.919 raeburn 15521: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15522: $itemcount ++;
15523: }
1.919 raeburn 15524: if ($itemcount) {
15525: $output = &Apache::loncommon::start_data_table().
15526: $table.
15527: &Apache::loncommon::end_data_table();
15528: }
1.663 raeburn 15529: }
15530: }
15531: }
15532: return $output;
15533: }
15534:
15535: =pod
15536:
1.1162 raeburn 15537: =item * &assign_category_rows()
1.663 raeburn 15538:
15539: Create a datatable row for display of nested categories in a domain,
15540: with checkboxes to allow a course to be categorized,called recursively.
15541:
15542: Inputs:
15543:
15544: itemcount - track row number for alternating colors
15545:
15546: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15547: categories and subcategories.
15548:
15549: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15550:
15551: parent - parent of current category item
15552:
15553: path - Array containing all categories back up through the hierarchy from the
15554: current category to the top level.
15555:
15556: currcategories - reference to array of current categories assigned to the course
15557:
1.1260 raeburn 15558: disabled - scalar (optional) contains disabled="disabled" if input elements are
15559: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15560:
1.663 raeburn 15561: Returns: $output (markup to be displayed).
15562:
15563: =cut
15564:
15565: sub assign_category_rows {
1.1259 raeburn 15566: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15567: my ($text,$name,$item,$chgstr);
15568: if (ref($cats) eq 'ARRAY') {
15569: my $maxdepth = scalar(@{$cats});
15570: if (ref($cats->[$depth]) eq 'HASH') {
15571: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15572: my $numchildren = @{$cats->[$depth]{$parent}};
15573: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 15574: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15575: for (my $j=0; $j<$numchildren; $j++) {
15576: $name = $cats->[$depth]{$parent}[$j];
15577: $item = &escape($name).':'.&escape($parent).':'.$depth;
15578: my $deeper = $depth+1;
15579: my $checked = '';
15580: if (ref($currcategories) eq 'ARRAY') {
15581: if (@{$currcategories} > 0) {
15582: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15583: $checked = ' checked="checked"';
1.663 raeburn 15584: }
15585: }
15586: }
1.664 raeburn 15587: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15588: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15589: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15590: '<input type="hidden" name="catname" value="'.$name.'" />'.
15591: '</td><td>';
1.663 raeburn 15592: if (ref($path) eq 'ARRAY') {
15593: push(@{$path},$name);
1.1259 raeburn 15594: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15595: pop(@{$path});
15596: }
15597: $text .= '</td></tr>';
15598: }
15599: $text .= '</table></td>';
15600: }
15601: }
15602: }
15603: return $text;
15604: }
15605:
1.1181 raeburn 15606: =pod
15607:
15608: =back
15609:
15610: =cut
15611:
1.655 raeburn 15612: ############################################################
15613: ############################################################
15614:
15615:
1.443 albertel 15616: sub commit_customrole {
1.664 raeburn 15617: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15618: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15619: ($start?', '.&mt('starting').' '.localtime($start):'').
15620: ($end?', ending '.localtime($end):'').': <b>'.
15621: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15622: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15623: '</b><br />';
15624: return $output;
15625: }
15626:
15627: sub commit_standardrole {
1.1116 raeburn 15628: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15629: my ($output,$logmsg,$linefeed);
15630: if ($context eq 'auto') {
15631: $linefeed = "\n";
15632: } else {
15633: $linefeed = "<br />\n";
15634: }
1.443 albertel 15635: if ($three eq 'st') {
1.541 raeburn 15636: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 15637: $one,$two,$sec,$context,$credits);
1.541 raeburn 15638: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15639: ($result eq 'unknown_course') || ($result eq 'refused')) {
15640: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15641: } else {
1.541 raeburn 15642: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15643: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15644: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15645: if ($context eq 'auto') {
15646: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15647: } else {
15648: $output .= '<b>'.$result.'</b>'.$linefeed.
15649: &mt('Add to classlist').': <b>ok</b>';
15650: }
15651: $output .= $linefeed;
1.443 albertel 15652: }
15653: } else {
15654: $output = &mt('Assigning').' '.$three.' in '.$url.
15655: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15656: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15657: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15658: if ($context eq 'auto') {
15659: $output .= $result.$linefeed;
15660: } else {
15661: $output .= '<b>'.$result.'</b>'.$linefeed;
15662: }
1.443 albertel 15663: }
15664: return $output;
15665: }
15666:
15667: sub commit_studentrole {
1.1116 raeburn 15668: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15669: $credits) = @_;
1.626 raeburn 15670: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15671: if ($context eq 'auto') {
15672: $linefeed = "\n";
15673: } else {
15674: $linefeed = '<br />'."\n";
15675: }
1.443 albertel 15676: if (defined($one) && defined($two)) {
15677: my $cid=$one.'_'.$two;
15678: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15679: my $secchange = 0;
15680: my $expire_role_result;
15681: my $modify_section_result;
1.628 raeburn 15682: if ($oldsec ne '-1') {
15683: if ($oldsec ne $sec) {
1.443 albertel 15684: $secchange = 1;
1.628 raeburn 15685: my $now = time;
1.443 albertel 15686: my $uurl='/'.$cid;
15687: $uurl=~s/\_/\//g;
15688: if ($oldsec) {
15689: $uurl.='/'.$oldsec;
15690: }
1.626 raeburn 15691: $oldsecurl = $uurl;
1.628 raeburn 15692: $expire_role_result =
1.652 raeburn 15693: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15694: if ($env{'request.course.sec'} ne '') {
15695: if ($expire_role_result eq 'refused') {
15696: my @roles = ('st');
15697: my @statuses = ('previous');
15698: my @roledoms = ($one);
15699: my $withsec = 1;
15700: my %roleshash =
15701: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15702: \@statuses,\@roles,\@roledoms,$withsec);
15703: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15704: my ($oldstart,$oldend) =
15705: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15706: if ($oldend > 0 && $oldend <= $now) {
15707: $expire_role_result = 'ok';
15708: }
15709: }
15710: }
15711: }
1.443 albertel 15712: $result = $expire_role_result;
15713: }
15714: }
15715: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 15716: $modify_section_result =
15717: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15718: undef,undef,undef,$sec,
15719: $end,$start,'','',$cid,
15720: '',$context,$credits);
1.443 albertel 15721: if ($modify_section_result =~ /^ok/) {
15722: if ($secchange == 1) {
1.628 raeburn 15723: if ($sec eq '') {
15724: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15725: } else {
15726: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15727: }
1.443 albertel 15728: } elsif ($oldsec eq '-1') {
1.628 raeburn 15729: if ($sec eq '') {
15730: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15731: } else {
15732: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15733: }
1.443 albertel 15734: } else {
1.628 raeburn 15735: if ($sec eq '') {
15736: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15737: } else {
15738: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15739: }
1.443 albertel 15740: }
15741: } else {
1.1115 raeburn 15742: if ($secchange) {
1.628 raeburn 15743: $$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;
15744: } else {
15745: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15746: }
1.443 albertel 15747: }
15748: $result = $modify_section_result;
15749: } elsif ($secchange == 1) {
1.628 raeburn 15750: if ($oldsec eq '') {
1.1103 raeburn 15751: $$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 15752: } else {
15753: $$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;
15754: }
1.626 raeburn 15755: if ($expire_role_result eq 'refused') {
15756: my $newsecurl = '/'.$cid;
15757: $newsecurl =~ s/\_/\//g;
15758: if ($sec ne '') {
15759: $newsecurl.='/'.$sec;
15760: }
15761: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15762: if ($sec eq '') {
15763: $$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;
15764: } else {
15765: $$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;
15766: }
15767: }
15768: }
1.443 albertel 15769: }
15770: } else {
1.626 raeburn 15771: $$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 15772: $result = "error: incomplete course id\n";
15773: }
15774: return $result;
15775: }
15776:
1.1108 raeburn 15777: sub show_role_extent {
15778: my ($scope,$context,$role) = @_;
15779: $scope =~ s{^/}{};
15780: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15781: push(@courseroles,'co');
15782: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15783: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15784: $scope =~ s{/}{_};
15785: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15786: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15787: my ($audom,$auname) = split(/\//,$scope);
15788: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15789: &Apache::loncommon::plainname($auname,$audom).'</span>');
15790: } else {
15791: $scope =~ s{/$}{};
15792: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15793: &Apache::lonnet::domain($scope,'description').'</span>');
15794: }
15795: }
15796:
1.443 albertel 15797: ############################################################
15798: ############################################################
15799:
1.566 albertel 15800: sub check_clone {
1.578 raeburn 15801: my ($args,$linefeed) = @_;
1.566 albertel 15802: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15803: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15804: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15805: my $clonemsg;
15806: my $can_clone = 0;
1.944 raeburn 15807: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15808: if ($lctype ne 'community') {
15809: $lctype = 'course';
15810: }
1.566 albertel 15811: if ($clonehome eq 'no_host') {
1.944 raeburn 15812: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15813: $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'});
15814: } else {
15815: $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'});
15816: }
1.566 albertel 15817: } else {
15818: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15819: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15820: if ($clonedesc{'type'} ne 'Community') {
1.1262 raeburn 15821: $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 15822: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15823: }
15824: }
1.1262 raeburn 15825: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15826: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15827: $can_clone = 1;
15828: } else {
1.1221 raeburn 15829: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15830: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 15831: if ($clonehash{'cloners'} eq '') {
15832: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15833: if ($domdefs{'canclone'}) {
15834: unless ($domdefs{'canclone'} eq 'none') {
15835: if ($domdefs{'canclone'} eq 'domain') {
15836: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15837: $can_clone = 1;
15838: }
15839: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15840: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15841: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15842: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15843: $can_clone = 1;
15844: }
15845: }
15846: }
15847: }
1.578 raeburn 15848: } else {
1.1221 raeburn 15849: my @cloners = split(/,/,$clonehash{'cloners'});
15850: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15851: $can_clone = 1;
1.1221 raeburn 15852: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15853: $can_clone = 1;
1.1225 raeburn 15854: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15855: $can_clone = 1;
1.1221 raeburn 15856: }
15857: unless ($can_clone) {
1.1225 raeburn 15858: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15859: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 15860: my (%gotdomdefaults,%gotcodedefaults);
15861: foreach my $cloner (@cloners) {
15862: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15863: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15864: my (%codedefaults,@code_order);
15865: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15866: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15867: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15868: }
15869: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15870: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15871: }
15872: } else {
15873: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15874: \%codedefaults,
15875: \@code_order);
15876: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15877: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15878: }
15879: if (@code_order > 0) {
15880: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15881: $cloner,$clonehash{'internal.coursecode'},
15882: $args->{'crscode'})) {
15883: $can_clone = 1;
15884: last;
15885: }
15886: }
15887: }
15888: }
15889: }
1.1225 raeburn 15890: }
15891: }
15892: unless ($can_clone) {
15893: my $ccrole = 'cc';
15894: if ($args->{'crstype'} eq 'Community') {
15895: $ccrole = 'co';
15896: }
15897: my %roleshash =
15898: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15899: $args->{'ccdomain'},
15900: 'userroles',['active'],[$ccrole],
15901: [$args->{'clonedomain'}]);
15902: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15903: $can_clone = 1;
15904: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15905: $args->{'ccuname'},$args->{'ccdomain'})) {
15906: $can_clone = 1;
1.1221 raeburn 15907: }
15908: }
15909: unless ($can_clone) {
15910: if ($args->{'crstype'} eq 'Community') {
15911: $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 15912: } else {
1.1221 raeburn 15913: $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'});
15914: }
1.566 albertel 15915: }
1.578 raeburn 15916: }
1.566 albertel 15917: }
15918: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15919: }
15920:
1.444 albertel 15921: sub construct_course {
1.1262 raeburn 15922: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15923: $cnum,$category,$coderef) = @_;
1.444 albertel 15924: my $outcome;
1.541 raeburn 15925: my $linefeed = '<br />'."\n";
15926: if ($context eq 'auto') {
15927: $linefeed = "\n";
15928: }
1.566 albertel 15929:
15930: #
15931: # Are we cloning?
15932: #
15933: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15934: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15935: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15936: if ($context ne 'auto') {
1.578 raeburn 15937: if ($clonemsg ne '') {
15938: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15939: }
1.566 albertel 15940: }
15941: $outcome .= $clonemsg.$linefeed;
15942:
15943: if (!$can_clone) {
15944: return (0,$outcome);
15945: }
15946: }
15947:
1.444 albertel 15948: #
15949: # Open course
15950: #
1.1239 raeburn 15951: my $showncrstype;
15952: if ($args->{'crstype'} eq 'Placement') {
15953: $showncrstype = 'placement test';
15954: } else {
15955: $showncrstype = lc($args->{'crstype'});
15956: }
1.444 albertel 15957: my %cenv=();
15958: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15959: $args->{'cdescr'},
15960: $args->{'curl'},
15961: $args->{'course_home'},
15962: $args->{'nonstandard'},
15963: $args->{'crscode'},
15964: $args->{'ccuname'}.':'.
15965: $args->{'ccdomain'},
1.882 raeburn 15966: $args->{'crstype'},
1.885 raeburn 15967: $cnum,$context,$category);
1.444 albertel 15968:
15969: # Note: The testing routines depend on this being output; see
15970: # Utils::Course. This needs to at least be output as a comment
15971: # if anyone ever decides to not show this, and Utils::Course::new
15972: # will need to be suitably modified.
1.1239 raeburn 15973: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
1.943 raeburn 15974: if ($$courseid =~ /^error:/) {
15975: return (0,$outcome);
15976: }
15977:
1.444 albertel 15978: #
15979: # Check if created correctly
15980: #
1.479 albertel 15981: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15982: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15983: if ($crsuhome eq 'no_host') {
15984: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15985: return (0,$outcome);
15986: }
1.541 raeburn 15987: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15988:
1.444 albertel 15989: #
1.566 albertel 15990: # Do the cloning
15991: #
15992: if ($can_clone && $cloneid) {
1.1239 raeburn 15993: $clonemsg = &mt('Cloning [_1] from [_2]',$showncrstype,$clonehome);
1.566 albertel 15994: if ($context ne 'auto') {
15995: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15996: }
15997: $outcome .= $clonemsg.$linefeed;
15998: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15999: # Copy all files
1.637 www 16000: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 16001: # Restore URL
1.566 albertel 16002: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16003: # Restore title
1.566 albertel 16004: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16005: # Restore creation date, creator and creation context.
16006: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16007: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16008: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16009: # Mark as cloned
1.566 albertel 16010: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16011: # Need to clone grading mode
16012: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16013: $cenv{'grading'}=$newenv{'grading'};
16014: # Do not clone these environment entries
16015: &Apache::lonnet::del('environment',
16016: ['default_enrollment_start_date',
16017: 'default_enrollment_end_date',
16018: 'question.email',
16019: 'policy.email',
16020: 'comment.email',
16021: 'pch.users.denied',
1.725 raeburn 16022: 'plc.users.denied',
16023: 'hidefromcat',
1.1121 raeburn 16024: 'checkforpriv',
1.1166 raeburn 16025: 'categories',
16026: 'internal.uniquecode'],
1.638 www 16027: $$crsudom,$$crsunum);
1.1170 raeburn 16028: if ($args->{'textbook'}) {
16029: $cenv{'internal.textbook'} = $args->{'textbook'};
16030: }
1.444 albertel 16031: }
1.566 albertel 16032:
1.444 albertel 16033: #
16034: # Set environment (will override cloned, if existing)
16035: #
16036: my @sections = ();
16037: my @xlists = ();
16038: if ($args->{'crstype'}) {
16039: $cenv{'type'}=$args->{'crstype'};
16040: }
16041: if ($args->{'crsid'}) {
16042: $cenv{'courseid'}=$args->{'crsid'};
16043: }
16044: if ($args->{'crscode'}) {
16045: $cenv{'internal.coursecode'}=$args->{'crscode'};
16046: }
16047: if ($args->{'crsquota'} ne '') {
16048: $cenv{'internal.coursequota'}=$args->{'crsquota'};
16049: } else {
16050: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
16051: }
16052: if ($args->{'ccuname'}) {
16053: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
16054: ':'.$args->{'ccdomain'};
16055: } else {
16056: $cenv{'internal.courseowner'} = $args->{'curruser'};
16057: }
1.1116 raeburn 16058: if ($args->{'defaultcredits'}) {
16059: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
16060: }
1.444 albertel 16061: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
16062: if ($args->{'crssections'}) {
16063: $cenv{'internal.sectionnums'} = '';
16064: if ($args->{'crssections'} =~ m/,/) {
16065: @sections = split/,/,$args->{'crssections'};
16066: } else {
16067: $sections[0] = $args->{'crssections'};
16068: }
16069: if (@sections > 0) {
16070: foreach my $item (@sections) {
16071: my ($sec,$gp) = split/:/,$item;
16072: my $class = $args->{'crscode'}.$sec;
16073: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16074: $cenv{'internal.sectionnums'} .= $item.',';
16075: unless ($addcheck eq 'ok') {
1.1263 raeburn 16076: push(@badclasses,$class);
1.444 albertel 16077: }
16078: }
16079: $cenv{'internal.sectionnums'} =~ s/,$//;
16080: }
16081: }
16082: # do not hide course coordinator from staff listing,
16083: # even if privileged
16084: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 16085: # add course coordinator's domain to domains to check for privileged users
16086: # if different to course domain
16087: if ($$crsudom ne $args->{'ccdomain'}) {
16088: $cenv{'checkforpriv'} = $args->{'ccdomain'};
16089: }
1.444 albertel 16090: # add crosslistings
16091: if ($args->{'crsxlist'}) {
16092: $cenv{'internal.crosslistings'}='';
16093: if ($args->{'crsxlist'} =~ m/,/) {
16094: @xlists = split/,/,$args->{'crsxlist'};
16095: } else {
16096: $xlists[0] = $args->{'crsxlist'};
16097: }
16098: if (@xlists > 0) {
16099: foreach my $item (@xlists) {
16100: my ($xl,$gp) = split/:/,$item;
16101: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
16102: $cenv{'internal.crosslistings'} .= $item.',';
16103: unless ($addcheck eq 'ok') {
1.1263 raeburn 16104: push(@badclasses,$xl);
1.444 albertel 16105: }
16106: }
16107: $cenv{'internal.crosslistings'} =~ s/,$//;
16108: }
16109: }
16110: if ($args->{'autoadds'}) {
16111: $cenv{'internal.autoadds'}=$args->{'autoadds'};
16112: }
16113: if ($args->{'autodrops'}) {
16114: $cenv{'internal.autodrops'}=$args->{'autodrops'};
16115: }
16116: # check for notification of enrollment changes
16117: my @notified = ();
16118: if ($args->{'notify_owner'}) {
16119: if ($args->{'ccuname'} ne '') {
16120: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
16121: }
16122: }
16123: if ($args->{'notify_dc'}) {
16124: if ($uname ne '') {
1.630 raeburn 16125: push(@notified,$uname.':'.$udom);
1.444 albertel 16126: }
16127: }
16128: if (@notified > 0) {
16129: my $notifylist;
16130: if (@notified > 1) {
16131: $notifylist = join(',',@notified);
16132: } else {
16133: $notifylist = $notified[0];
16134: }
16135: $cenv{'internal.notifylist'} = $notifylist;
16136: }
16137: if (@badclasses > 0) {
16138: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 16139: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16140: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16141: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16142: );
1.1264 raeburn 16143: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16144: &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 16145: if ($context eq 'auto') {
16146: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 16147: } else {
1.566 albertel 16148: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 16149: }
16150: foreach my $item (@badclasses) {
1.541 raeburn 16151: if ($context eq 'auto') {
1.1261 raeburn 16152: $outcome .= " - $item\n";
1.541 raeburn 16153: } else {
1.1261 raeburn 16154: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16155: }
1.1261 raeburn 16156: }
16157: if ($context eq 'auto') {
16158: $outcome .= $linefeed;
16159: } else {
16160: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 16161: }
1.444 albertel 16162: }
16163: if ($args->{'no_end_date'}) {
16164: $args->{'endaccess'} = 0;
16165: }
16166: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16167: $cenv{'internal.autoend'}=$args->{'enrollend'};
16168: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16169: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16170: if ($args->{'showphotos'}) {
16171: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16172: }
16173: $cenv{'internal.authtype'} = $args->{'authtype'};
16174: $cenv{'internal.autharg'} = $args->{'autharg'};
16175: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16176: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16177: 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');
16178: if ($context eq 'auto') {
16179: $outcome .= $krb_msg;
16180: } else {
1.566 albertel 16181: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16182: }
16183: $outcome .= $linefeed;
1.444 albertel 16184: }
16185: }
16186: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16187: if ($args->{'setpolicy'}) {
16188: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16189: }
16190: if ($args->{'setcontent'}) {
16191: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16192: }
1.1251 raeburn 16193: if ($args->{'setcomment'}) {
16194: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16195: }
1.444 albertel 16196: }
16197: if ($args->{'reshome'}) {
16198: $cenv{'reshome'}=$args->{'reshome'}.'/';
16199: $cenv{'reshome'}=~s/\/+$/\//;
16200: }
16201: #
16202: # course has keyed access
16203: #
16204: if ($args->{'setkeys'}) {
16205: $cenv{'keyaccess'}='yes';
16206: }
16207: # if specified, key authority is not course, but user
16208: # only active if keyaccess is yes
16209: if ($args->{'keyauth'}) {
1.487 albertel 16210: my ($user,$domain) = split(':',$args->{'keyauth'});
16211: $user = &LONCAPA::clean_username($user);
16212: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16213: if ($user ne '' && $domain ne '') {
1.487 albertel 16214: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16215: }
16216: }
16217:
1.1166 raeburn 16218: #
1.1167 raeburn 16219: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 16220: #
16221: if ($args->{'uniquecode'}) {
16222: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16223: if ($code) {
16224: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 16225: my %crsinfo =
16226: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16227: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16228: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16229: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16230: }
1.1166 raeburn 16231: if (ref($coderef)) {
16232: $$coderef = $code;
16233: }
16234: }
16235: }
16236:
1.444 albertel 16237: if ($args->{'disresdis'}) {
16238: $cenv{'pch.roles.denied'}='st';
16239: }
16240: if ($args->{'disablechat'}) {
16241: $cenv{'plc.roles.denied'}='st';
16242: }
16243:
16244: # Record we've not yet viewed the Course Initialization Helper for this
16245: # course
16246: $cenv{'course.helper.not.run'} = 1;
16247: #
16248: # Use new Randomseed
16249: #
16250: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16251: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16252: #
16253: # The encryption code and receipt prefix for this course
16254: #
16255: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16256: $cenv{'internal.encpref'}=100+int(9*rand(99));
16257: #
16258: # By default, use standard grading
16259: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16260:
1.541 raeburn 16261: $outcome .= $linefeed.&mt('Setting environment').': '.
16262: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16263: #
16264: # Open all assignments
16265: #
16266: if ($args->{'openall'}) {
16267: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
16268: my %storecontent = ($storeunder => time,
16269: $storeunder.'.type' => 'date_start');
16270:
16271: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 16272: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16273: }
16274: #
16275: # Set first page
16276: #
16277: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16278: || ($cloneid)) {
1.445 albertel 16279: use LONCAPA::map;
1.444 albertel 16280: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16281:
16282: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16283: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16284:
1.444 albertel 16285: $outcome .= ($fatal?$errtext:'read ok').' - ';
16286: my $title; my $url;
16287: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16288: $title=&mt('Syllabus');
1.444 albertel 16289: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16290: } else {
1.963 raeburn 16291: $title=&mt('Table of Contents');
1.444 albertel 16292: $url='/adm/navmaps';
16293: }
1.445 albertel 16294:
16295: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16296: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16297:
16298: if ($errtext) { $fatal=2; }
1.541 raeburn 16299: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16300: }
1.566 albertel 16301:
1.1237 raeburn 16302: #
16303: # Set params for Placement Tests
16304: #
1.1239 raeburn 16305: if ($args->{'crstype'} eq 'Placement') {
16306: my %storecontent;
16307: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
16308: my %defaults = (
16309: buttonshide => { value => 'yes',
16310: type => 'string_yesno',},
16311: type => { value => 'randomizetry',
16312: type => 'string_questiontype',},
16313: maxtries => { value => 1,
16314: type => 'int_pos',},
16315: problemstatus => { value => 'no',
16316: type => 'string_problemstatus',},
16317: );
16318: foreach my $key (keys(%defaults)) {
16319: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
16320: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
16321: }
1.1237 raeburn 16322: &Apache::lonnet::cput
16323: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
16324: }
16325:
1.566 albertel 16326: return (1,$outcome);
1.444 albertel 16327: }
16328:
1.1166 raeburn 16329: sub make_unique_code {
16330: my ($cdom,$cnum) = @_;
16331: # get lock on uniquecodes db
16332: my $lockhash = {
16333: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16334: ':'.$env{'user.domain'},
16335: };
16336: my $tries = 0;
16337: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16338: my ($code,$error);
16339:
16340: while (($gotlock ne 'ok') && ($tries<3)) {
16341: $tries ++;
16342: sleep 1;
16343: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16344: }
16345: if ($gotlock eq 'ok') {
16346: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
16347: my $gotcode;
16348: my $attempts = 0;
16349: while ((!$gotcode) && ($attempts < 100)) {
16350: $code = &generate_code();
16351: if (!exists($currcodes{$code})) {
16352: $gotcode = 1;
16353: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
16354: $error = 'nostore';
16355: }
16356: }
16357: $attempts ++;
16358: }
16359: my @del_lock = ($cnum."\0".'uniquecodes');
16360: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
16361: } else {
16362: $error = 'nolock';
16363: }
16364: return ($code,$error);
16365: }
16366:
16367: sub generate_code {
16368: my $code;
16369: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
16370: for (my $i=0; $i<6; $i++) {
16371: my $lettnum = int (rand 2);
16372: my $item = '';
16373: if ($lettnum) {
16374: $item = $letts[int( rand(18) )];
16375: } else {
16376: $item = 1+int( rand(8) );
16377: }
16378: $code .= $item;
16379: }
16380: return $code;
16381: }
16382:
1.444 albertel 16383: ############################################################
16384: ############################################################
16385:
1.1237 raeburn 16386: # Community, Course and Placement Test
1.378 raeburn 16387: sub course_type {
16388: my ($cid) = @_;
16389: if (!defined($cid)) {
16390: $cid = $env{'request.course.id'};
16391: }
1.404 albertel 16392: if (defined($env{'course.'.$cid.'.type'})) {
16393: return $env{'course.'.$cid.'.type'};
1.378 raeburn 16394: } else {
16395: return 'Course';
1.377 raeburn 16396: }
16397: }
1.156 albertel 16398:
1.406 raeburn 16399: sub group_term {
16400: my $crstype = &course_type();
16401: my %names = (
16402: 'Course' => 'group',
1.865 raeburn 16403: 'Community' => 'group',
1.1237 raeburn 16404: 'Placement' => 'group',
1.406 raeburn 16405: );
16406: return $names{$crstype};
16407: }
16408:
1.902 raeburn 16409: sub course_types {
1.1310 raeburn 16410: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 16411: my %typename = (
16412: official => 'Official course',
16413: unofficial => 'Unofficial course',
16414: community => 'Community',
1.1165 raeburn 16415: textbook => 'Textbook course',
1.1237 raeburn 16416: placement => 'Placement test',
1.1310 raeburn 16417: lti => 'LTI provider',
1.902 raeburn 16418: );
16419: return (\@types,\%typename);
16420: }
16421:
1.156 albertel 16422: sub icon {
16423: my ($file)=@_;
1.505 albertel 16424: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 16425: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 16426: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 16427: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
16428: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
16429: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16430: $curfext.".gif") {
16431: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16432: $curfext.".gif";
16433: }
16434: }
1.249 albertel 16435: return &lonhttpdurl($iconname);
1.154 albertel 16436: }
1.84 albertel 16437:
1.575 albertel 16438: sub lonhttpdurl {
1.692 www 16439: #
16440: # Had been used for "small fry" static images on separate port 8080.
16441: # Modify here if lightweight http functionality desired again.
16442: # Currently eliminated due to increasing firewall issues.
16443: #
1.575 albertel 16444: my ($url)=@_;
1.692 www 16445: return $url;
1.215 albertel 16446: }
16447:
1.213 albertel 16448: sub connection_aborted {
16449: my ($r)=@_;
16450: $r->print(" ");$r->rflush();
16451: my $c = $r->connection;
16452: return $c->aborted();
16453: }
16454:
1.221 foxr 16455: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 16456: # strings as 'strings'.
16457: sub escape_single {
1.221 foxr 16458: my ($input) = @_;
1.223 albertel 16459: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16460: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16461: return $input;
16462: }
1.223 albertel 16463:
1.222 foxr 16464: # Same as escape_single, but escape's "'s This
16465: # can be used for "strings"
16466: sub escape_double {
16467: my ($input) = @_;
16468: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16469: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16470: return $input;
16471: }
1.223 albertel 16472:
1.222 foxr 16473: # Escapes the last element of a full URL.
16474: sub escape_url {
16475: my ($url) = @_;
1.238 raeburn 16476: my @urlslices = split(/\//, $url,-1);
1.369 www 16477: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 16478: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16479: }
1.462 albertel 16480:
1.820 raeburn 16481: sub compare_arrays {
16482: my ($arrayref1,$arrayref2) = @_;
16483: my (@difference,%count);
16484: @difference = ();
16485: %count = ();
16486: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16487: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16488: foreach my $element (keys(%count)) {
16489: if ($count{$element} == 1) {
16490: push(@difference,$element);
16491: }
16492: }
16493: }
16494: return @difference;
16495: }
16496:
1.1322 raeburn 16497: sub lon_status_items {
16498: my %defaults = (
16499: E => 100,
16500: W => 4,
16501: N => 1,
1.1324 raeburn 16502: U => 5,
1.1322 raeburn 16503: threshold => 200,
16504: sysmail => 2500,
16505: );
16506: my %names = (
16507: E => 'Errors',
16508: W => 'Warnings',
16509: N => 'Notices',
1.1324 raeburn 16510: U => 'Unsent',
1.1322 raeburn 16511: );
16512: return (\%defaults,\%names);
16513: }
16514:
1.817 bisitz 16515: # -------------------------------------------------------- Initialize user login
1.462 albertel 16516: sub init_user_environment {
1.463 albertel 16517: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16518: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16519:
16520: my $public=($username eq 'public' && $domain eq 'public');
16521:
1.1062 raeburn 16522: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16523: my $now=time;
16524:
16525: if ($public) {
16526: my $max_public=100;
16527: my $oldest;
16528: my $oldest_time=0;
16529: for(my $next=1;$next<=$max_public;$next++) {
16530: if (-e $lonids."/publicuser_$next.id") {
16531: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16532: if ($mtime<$oldest_time || !$oldest_time) {
16533: $oldest_time=$mtime;
16534: $oldest=$next;
16535: }
16536: } else {
16537: $cookie="publicuser_$next";
16538: last;
16539: }
16540: }
16541: if (!$cookie) { $cookie="publicuser_$oldest"; }
16542: } else {
1.1275 raeburn 16543: # See if old ID present, if so, remove if this isn't a robot,
16544: # killing any existing non-robot sessions
1.463 albertel 16545: if (!$args->{'robot'}) {
16546: opendir(DIR,$lonids);
16547: while ($filename=readdir(DIR)) {
16548: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 16549: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
16550: &GDBM_READER(),0640)) {
1.1295 raeburn 16551: my $linkedfile;
1.1320 raeburn 16552: if (exists($oldenv{'user.linkedenv'})) {
16553: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 16554: }
1.1320 raeburn 16555: untie(%oldenv);
16556: if (unlink("$lonids/$filename")) {
16557: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
16558: if (-l "$lonids/$linkedfile.id") {
16559: unlink("$lonids/$linkedfile.id");
16560: }
1.1295 raeburn 16561: }
16562: }
16563: } else {
16564: unlink($lonids.'/'.$filename);
16565: }
1.463 albertel 16566: }
1.462 albertel 16567: }
1.463 albertel 16568: closedir(DIR);
1.1204 raeburn 16569: # If there is a undeleted lockfile for the user's paste buffer remove it.
16570: my $namespace = 'nohist_courseeditor';
16571: my $lockingkey = 'paste'."\0".'locked_num';
16572: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16573: $domain,$username);
16574: if (exists($lockhash{$lockingkey})) {
16575: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16576: unless ($delresult eq 'ok') {
16577: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16578: }
16579: }
1.462 albertel 16580: }
16581: # Give them a new cookie
1.463 albertel 16582: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16583: : $now.$$.int(rand(10000)));
1.463 albertel 16584: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16585:
16586: # Initialize roles
16587:
1.1062 raeburn 16588: ($userroles,$firstaccenv,$timerintenv) =
16589: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16590: }
16591: # ------------------------------------ Check browser type and MathML capability
16592:
1.1194 raeburn 16593: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16594: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16595:
16596: # ------------------------------------------------------------- Get environment
16597:
16598: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16599: my ($tmp) = keys(%userenv);
1.1275 raeburn 16600: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 16601: undef(%userenv);
16602: }
16603: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16604: $form->{'interface'}=$userenv{'interface'};
16605: }
16606: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16607:
16608: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16609: foreach my $option ('interface','localpath','localres') {
16610: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16611: }
16612: # --------------------------------------------------------- Write first profile
16613:
16614: {
16615: my %initial_env =
16616: ("user.name" => $username,
16617: "user.domain" => $domain,
16618: "user.home" => $authhost,
16619: "browser.type" => $clientbrowser,
16620: "browser.version" => $clientversion,
16621: "browser.mathml" => $clientmathml,
16622: "browser.unicode" => $clientunicode,
16623: "browser.os" => $clientos,
1.1137 raeburn 16624: "browser.mobile" => $clientmobile,
1.1141 raeburn 16625: "browser.info" => $clientinfo,
1.1194 raeburn 16626: "browser.osversion" => $clientosversion,
1.462 albertel 16627: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16628: "request.course.fn" => '',
16629: "request.course.uri" => '',
16630: "request.course.sec" => '',
16631: "request.role" => 'cm',
16632: "request.role.adv" => $env{'user.adv'},
16633: "request.host" => $ENV{'REMOTE_ADDR'},);
16634:
16635: if ($form->{'localpath'}) {
16636: $initial_env{"browser.localpath"} = $form->{'localpath'};
16637: $initial_env{"browser.localres"} = $form->{'localres'};
16638: }
16639:
16640: if ($form->{'interface'}) {
16641: $form->{'interface'}=~s/\W//gs;
16642: $initial_env{"browser.interface"} = $form->{'interface'};
16643: $env{'browser.interface'}=$form->{'interface'};
16644: }
16645:
1.1157 raeburn 16646: if ($form->{'iptoken'}) {
16647: my $lonhost = $r->dir_config('lonHostID');
16648: $initial_env{"user.noloadbalance"} = $lonhost;
16649: $env{'user.noloadbalance'} = $lonhost;
16650: }
16651:
1.1268 raeburn 16652: if ($form->{'noloadbalance'}) {
16653: my @hosts = &Apache::lonnet::current_machine_ids();
16654: my $hosthere = $form->{'noloadbalance'};
16655: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16656: $initial_env{"user.noloadbalance"} = $hosthere;
16657: $env{'user.noloadbalance'} = $hosthere;
16658: }
16659: }
16660:
1.1016 raeburn 16661: unless ($domain eq 'public') {
1.1273 raeburn 16662: my %is_adv = ( is_adv => $env{'user.adv'} );
16663: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
16664:
16665: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16666: $userenv{'availabletools.'.$tool} =
16667: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16668: undef,\%userenv,\%domdef,\%is_adv);
16669: }
1.980 raeburn 16670:
1.1311 raeburn 16671: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 16672: $userenv{'canrequest.'.$crstype} =
16673: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16674: 'reload','requestcourses',
16675: \%userenv,\%domdef,\%is_adv);
16676: }
1.724 raeburn 16677:
1.1273 raeburn 16678: $userenv{'canrequest.author'} =
16679: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16680: 'reload','requestauthor',
1.980 raeburn 16681: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 16682: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16683: $domain,$username);
16684: my $reqstatus = $reqauthor{'author_status'};
16685: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16686: if (ref($reqauthor{'author'}) eq 'HASH') {
16687: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16688: $reqauthor{'author'}{'timestamp'};
16689: }
1.1092 raeburn 16690: }
1.1287 raeburn 16691: my ($types,$typename) = &course_types();
16692: if (ref($types) eq 'ARRAY') {
16693: my @options = ('approval','validate','autolimit');
16694: my $optregex = join('|',@options);
16695: my (%willtrust,%trustchecked);
16696: foreach my $type (@{$types}) {
16697: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
16698: if ($dom_str ne '') {
16699: my $updatedstr = '';
16700: my @possdomains = split(',',$dom_str);
16701: foreach my $entry (@possdomains) {
16702: my ($extdom,$extopt) = split(':',$entry);
16703: unless ($trustchecked{$extdom}) {
16704: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
16705: $trustchecked{$extdom} = 1;
16706: }
16707: if ($willtrust{$extdom}) {
16708: $updatedstr .= $entry.',';
16709: }
16710: }
16711: $updatedstr =~ s/,$//;
16712: if ($updatedstr) {
16713: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
16714: } else {
16715: delete($userenv{'reqcrsotherdom.'.$type});
16716: }
16717: }
16718: }
16719: }
1.1092 raeburn 16720: }
1.462 albertel 16721: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16722:
1.462 albertel 16723: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16724: &GDBM_WRCREAT(),0640)) {
16725: &_add_to_env(\%disk_env,\%initial_env);
16726: &_add_to_env(\%disk_env,\%userenv,'environment.');
16727: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16728: if (ref($firstaccenv) eq 'HASH') {
16729: &_add_to_env(\%disk_env,$firstaccenv);
16730: }
16731: if (ref($timerintenv) eq 'HASH') {
16732: &_add_to_env(\%disk_env,$timerintenv);
16733: }
1.463 albertel 16734: if (ref($args->{'extra_env'})) {
16735: &_add_to_env(\%disk_env,$args->{'extra_env'});
16736: }
1.462 albertel 16737: untie(%disk_env);
16738: } else {
1.705 tempelho 16739: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16740: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16741: return 'error: '.$!;
16742: }
16743: }
16744: $env{'request.role'}='cm';
16745: $env{'request.role.adv'}=$env{'user.adv'};
16746: $env{'browser.type'}=$clientbrowser;
16747:
16748: return $cookie;
16749:
16750: }
16751:
16752: sub _add_to_env {
16753: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16754: if (ref($env_data) eq 'HASH') {
16755: while (my ($key,$value) = each(%$env_data)) {
16756: $idf->{$prefix.$key} = $value;
16757: $env{$prefix.$key} = $value;
16758: }
1.462 albertel 16759: }
16760: }
16761:
1.685 tempelho 16762: # --- Get the symbolic name of a problem and the url
16763: sub get_symb {
16764: my ($request,$silent) = @_;
1.726 raeburn 16765: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16766: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16767: if ($symb eq '') {
16768: if (!$silent) {
1.1071 raeburn 16769: if (ref($request)) {
16770: $request->print("Unable to handle ambiguous references:$url:.");
16771: }
1.685 tempelho 16772: return ();
16773: }
16774: }
16775: &Apache::lonenc::check_decrypt(\$symb);
16776: return ($symb);
16777: }
16778:
16779: # --------------------------------------------------------------Get annotation
16780:
16781: sub get_annotation {
16782: my ($symb,$enc) = @_;
16783:
16784: my $key = $symb;
16785: if (!$enc) {
16786: $key =
16787: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16788: }
16789: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16790: return $annotation{$key};
16791: }
16792:
16793: sub clean_symb {
1.731 raeburn 16794: my ($symb,$delete_enc) = @_;
1.685 tempelho 16795:
16796: &Apache::lonenc::check_decrypt(\$symb);
16797: my $enc = $env{'request.enc'};
1.731 raeburn 16798: if ($delete_enc) {
1.730 raeburn 16799: delete($env{'request.enc'});
16800: }
1.685 tempelho 16801:
16802: return ($symb,$enc);
16803: }
1.462 albertel 16804:
1.1181 raeburn 16805: ############################################################
16806: ############################################################
16807:
16808: =pod
16809:
16810: =head1 Routines for building display used to search for courses
16811:
16812:
16813: =over 4
16814:
16815: =item * &build_filters()
16816:
16817: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 16818: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16819: and quotacheck.pl
16820:
1.1181 raeburn 16821:
16822: Inputs:
16823:
16824: filterlist - anonymous array of fields to include as potential filters
16825:
16826: crstype - course type
16827:
16828: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16829: to pop-open a course selector (will contain "extra element").
16830:
16831: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16832:
16833: filter - anonymous hash of criteria and their values
16834:
16835: action - form action
16836:
16837: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16838:
1.1182 raeburn 16839: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 16840:
16841: cloneruname - username of owner of new course who wants to clone
16842:
16843: clonerudom - domain of owner of new course who wants to clone
16844:
16845: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16846:
16847: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16848:
16849: codedom - domain
16850:
16851: formname - value of form element named "form".
16852:
16853: fixeddom - domain, if fixed.
16854:
16855: prevphase - value to assign to form element named "phase" when going back to the previous screen
16856:
16857: cnameelement - name of form element in form on opener page which will receive title of selected course
16858:
16859: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16860:
16861: cdomelement - name of form element in form on opener page which will receive domain of selected course
16862:
16863: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16864:
16865: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16866:
16867: clonewarning - warning message about missing information for intended course owner when DC creates a course
16868:
1.1182 raeburn 16869:
1.1181 raeburn 16870: Returns: $output - HTML for display of search criteria, and hidden form elements.
16871:
1.1182 raeburn 16872:
1.1181 raeburn 16873: Side Effects: None
16874:
16875: =cut
16876:
16877: # ---------------------------------------------- search for courses based on last activity etc.
16878:
16879: sub build_filters {
16880: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16881: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16882: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16883: $cnameelement,$cnumelement,$cdomelement,$setroles,
16884: $clonetext,$clonewarning) = @_;
1.1182 raeburn 16885: my ($list,$jscript);
1.1181 raeburn 16886: my $onchange = 'javascript:updateFilters(this)';
16887: my ($domainselectform,$sincefilterform,$createdfilterform,
16888: $ownerdomselectform,$persondomselectform,$instcodeform,
16889: $typeselectform,$instcodetitle);
16890: if ($formname eq '') {
16891: $formname = $caller;
16892: }
16893: foreach my $item (@{$filterlist}) {
16894: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16895: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16896: if ($item eq 'domainfilter') {
16897: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16898: } elsif ($item eq 'coursefilter') {
16899: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16900: } elsif ($item eq 'ownerfilter') {
16901: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16902: } elsif ($item eq 'ownerdomfilter') {
16903: $filter->{'ownerdomfilter'} =
16904: &LONCAPA::clean_domain($filter->{$item});
16905: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16906: 'ownerdomfilter',1);
16907: } elsif ($item eq 'personfilter') {
16908: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16909: } elsif ($item eq 'persondomfilter') {
16910: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16911: 'persondomfilter',1);
16912: } else {
16913: $filter->{$item} =~ s/\W//g;
16914: }
16915: if (!$filter->{$item}) {
16916: $filter->{$item} = '';
16917: }
16918: }
16919: if ($item eq 'domainfilter') {
16920: my $allow_blank = 1;
16921: if ($formname eq 'portform') {
16922: $allow_blank=0;
16923: } elsif ($formname eq 'studentform') {
16924: $allow_blank=0;
16925: }
16926: if ($fixeddom) {
16927: $domainselectform = '<input type="hidden" name="domainfilter"'.
16928: ' value="'.$codedom.'" />'.
16929: &Apache::lonnet::domain($codedom,'description');
16930: } else {
16931: $domainselectform = &select_dom_form($filter->{$item},
16932: 'domainfilter',
16933: $allow_blank,'',$onchange);
16934: }
16935: } else {
16936: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16937: }
16938: }
16939:
16940: # last course activity filter and selection
16941: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16942:
16943: # course created filter and selection
16944: if (exists($filter->{'createdfilter'})) {
16945: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16946: }
16947:
1.1239 raeburn 16948: my $prefix = $crstype;
16949: if ($crstype eq 'Placement') {
16950: $prefix = 'Placement Test'
16951: }
1.1181 raeburn 16952: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 16953: 'cac' => "$prefix Activity",
16954: 'ccr' => "$prefix Created",
16955: 'cde' => "$prefix Title",
16956: 'cdo' => "$prefix Domain",
1.1181 raeburn 16957: 'ins' => 'Institutional Code',
16958: 'inc' => 'Institutional Categorization',
1.1239 raeburn 16959: 'cow' => "$prefix Owner/Co-owner",
16960: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 16961: 'cog' => 'Type',
16962: );
16963:
16964: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16965: my $typeval = 'Course';
16966: if ($crstype eq 'Community') {
16967: $typeval = 'Community';
1.1239 raeburn 16968: } elsif ($crstype eq 'Placement') {
16969: $typeval = 'Placement';
1.1181 raeburn 16970: }
16971: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16972: } else {
16973: $typeselectform = '<select name="type" size="1"';
16974: if ($onchange) {
16975: $typeselectform .= ' onchange="'.$onchange.'"';
16976: }
16977: $typeselectform .= '>'."\n";
1.1237 raeburn 16978: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 16979: my $shown;
16980: if ($posstype eq 'Placement') {
16981: $shown = &mt('Placement Test');
16982: } else {
16983: $shown = &mt($posstype);
16984: }
1.1181 raeburn 16985: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 16986: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 16987: }
16988: $typeselectform.="</select>";
16989: }
16990:
16991: my ($cloneableonlyform,$cloneabletitle);
16992: if (exists($filter->{'cloneableonly'})) {
16993: my $cloneableon = '';
16994: my $cloneableoff = ' checked="checked"';
16995: if ($filter->{'cloneableonly'}) {
16996: $cloneableon = $cloneableoff;
16997: $cloneableoff = '';
16998: }
16999: $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>';
17000: if ($formname eq 'ccrs') {
1.1187 bisitz 17001: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 17002: } else {
17003: $cloneabletitle = &mt('Cloneable by you');
17004: }
17005: }
17006: my $officialjs;
17007: if ($crstype eq 'Course') {
17008: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 17009: # if (($fixeddom) || ($formname eq 'requestcrs') ||
17010: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
17011: if ($codedom) {
1.1181 raeburn 17012: $officialjs = 1;
17013: ($instcodeform,$jscript,$$numtitlesref) =
17014: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
17015: $officialjs,$codetitlesref);
17016: if ($jscript) {
1.1182 raeburn 17017: $jscript = '<script type="text/javascript">'."\n".
17018: '// <![CDATA['."\n".
17019: $jscript."\n".
17020: '// ]]>'."\n".
17021: '</script>'."\n";
1.1181 raeburn 17022: }
17023: }
17024: if ($instcodeform eq '') {
17025: $instcodeform =
17026: '<input type="text" name="instcodefilter" size="10" value="'.
17027: $list->{'instcodefilter'}.'" />';
17028: $instcodetitle = $lt{'ins'};
17029: } else {
17030: $instcodetitle = $lt{'inc'};
17031: }
17032: if ($fixeddom) {
17033: $instcodetitle .= '<br />('.$codedom.')';
17034: }
17035: }
17036: }
17037: my $output = qq|
17038: <form method="post" name="filterpicker" action="$action">
17039: <input type="hidden" name="form" value="$formname" />
17040: |;
17041: if ($formname eq 'modifycourse') {
17042: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
17043: '<input type="hidden" name="prevphase" value="'.
17044: $prevphase.'" />'."\n";
1.1198 musolffc 17045: } elsif ($formname eq 'quotacheck') {
17046: $output .= qq|
17047: <input type="hidden" name="sortby" value="" />
17048: <input type="hidden" name="sortorder" value="" />
17049: |;
17050: } else {
1.1181 raeburn 17051: my $name_input;
17052: if ($cnameelement ne '') {
17053: $name_input = '<input type="hidden" name="cnameelement" value="'.
17054: $cnameelement.'" />';
17055: }
17056: $output .= qq|
1.1182 raeburn 17057: <input type="hidden" name="cnumelement" value="$cnumelement" />
17058: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 17059: $name_input
17060: $roleelement
17061: $multelement
17062: $typeelement
17063: |;
17064: if ($formname eq 'portform') {
17065: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
17066: }
17067: }
17068: if ($fixeddom) {
17069: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
17070: }
17071: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
17072: if ($sincefilterform) {
17073: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
17074: .$sincefilterform
17075: .&Apache::lonhtmlcommon::row_closure();
17076: }
17077: if ($createdfilterform) {
17078: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17079: .$createdfilterform
17080: .&Apache::lonhtmlcommon::row_closure();
17081: }
17082: if ($domainselectform) {
17083: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
17084: .$domainselectform
17085: .&Apache::lonhtmlcommon::row_closure();
17086: }
17087: if ($typeselectform) {
17088: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17089: $output .= $typeselectform;
17090: } else {
17091: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
17092: .$typeselectform
17093: .&Apache::lonhtmlcommon::row_closure();
17094: }
17095: }
17096: if ($instcodeform) {
17097: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
17098: .$instcodeform
17099: .&Apache::lonhtmlcommon::row_closure();
17100: }
17101: if (exists($filter->{'ownerfilter'})) {
17102: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
17103: '<table><tr><td>'.&mt('Username').'<br />'.
17104: '<input type="text" name="ownerfilter" size="20" value="'.
17105: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17106: $ownerdomselectform.'</td></tr></table>'.
17107: &Apache::lonhtmlcommon::row_closure();
17108: }
17109: if (exists($filter->{'personfilter'})) {
17110: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
17111: '<table><tr><td>'.&mt('Username').'<br />'.
17112: '<input type="text" name="personfilter" size="20" value="'.
17113: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17114: $persondomselectform.'</td></tr></table>'.
17115: &Apache::lonhtmlcommon::row_closure();
17116: }
17117: if (exists($filter->{'coursefilter'})) {
17118: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
17119: .'<input type="text" name="coursefilter" size="25" value="'
17120: .$list->{'coursefilter'}.'" />'
17121: .&Apache::lonhtmlcommon::row_closure();
17122: }
17123: if ($cloneableonlyform) {
17124: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
17125: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
17126: }
17127: if (exists($filter->{'descriptfilter'})) {
17128: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
17129: .'<input type="text" name="descriptfilter" size="40" value="'
17130: .$list->{'descriptfilter'}.'" />'
17131: .&Apache::lonhtmlcommon::row_closure(1);
17132: }
17133: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
17134: '<input type="hidden" name="updater" value="" />'."\n".
17135: '<input type="submit" name="gosearch" value="'.
17136: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
17137: return $jscript.$clonewarning.$output;
17138: }
17139:
17140: =pod
17141:
17142: =item * &timebased_select_form()
17143:
1.1182 raeburn 17144: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 17145: filter e.g., Course Activity, Course Created, when searching for courses
17146: or communities
17147:
17148: Inputs:
17149:
17150: item - name of form element (sincefilter or createdfilter)
17151:
17152: filter - anonymous hash of criteria and their values
17153:
17154: Returns: HTML for a select box contained a blank, then six time selections,
17155: with value set in incoming form variables currently selected.
17156:
17157: Side Effects: None
17158:
17159: =cut
17160:
17161: sub timebased_select_form {
17162: my ($item,$filter) = @_;
17163: if (ref($filter) eq 'HASH') {
17164: $filter->{$item} =~ s/[^\d-]//g;
17165: if (!$filter->{$item}) { $filter->{$item}=-1; }
17166: return &select_form(
17167: $filter->{$item},
17168: $item,
17169: { '-1' => '',
17170: '86400' => &mt('today'),
17171: '604800' => &mt('last week'),
17172: '2592000' => &mt('last month'),
17173: '7776000' => &mt('last three months'),
17174: '15552000' => &mt('last six months'),
17175: '31104000' => &mt('last year'),
17176: 'select_form_order' =>
17177: ['-1','86400','604800','2592000','7776000',
17178: '15552000','31104000']});
17179: }
17180: }
17181:
17182: =pod
17183:
17184: =item * &js_changer()
17185:
17186: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 17187: when course type or domain is changed, and also to hide 'Searching ...' on
17188: page load completion for page showing search result.
1.1181 raeburn 17189:
17190: Inputs: None
17191:
1.1183 raeburn 17192: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 17193:
17194: Side Effects: None
17195:
17196: =cut
17197:
17198: sub js_changer {
17199: return <<ENDJS;
17200: <script type="text/javascript">
17201: // <![CDATA[
17202: function updateFilters(caller) {
17203: if (typeof(caller) != "undefined") {
17204: document.filterpicker.updater.value = caller.name;
17205: }
17206: document.filterpicker.submit();
17207: }
1.1183 raeburn 17208:
17209: function hideSearching() {
17210: if (document.getElementById('searching')) {
17211: document.getElementById('searching').style.display = 'none';
17212: }
17213: return;
17214: }
17215:
1.1181 raeburn 17216: // ]]>
17217: </script>
17218:
17219: ENDJS
17220: }
17221:
17222: =pod
17223:
1.1182 raeburn 17224: =item * &search_courses()
17225:
17226: Process selected filters form course search form and pass to lonnet::courseiddump
17227: to retrieve a hash for which keys are courseIDs which match the selected filters.
17228:
17229: Inputs:
17230:
17231: dom - domain being searched
17232:
17233: type - course type ('Course' or 'Community' or '.' if any).
17234:
17235: filter - anonymous hash of criteria and their values
17236:
17237: numtitles - for institutional codes - number of categories
17238:
17239: cloneruname - optional username of new course owner
17240:
17241: clonerudom - optional domain of new course owner
17242:
1.1221 raeburn 17243: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 17244: (used when DC is using course creation form)
17245:
17246: codetitles - reference to array of titles of components in institutional codes (official courses).
17247:
1.1221 raeburn 17248: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17249: (and so can clone automatically)
17250:
17251: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17252:
17253: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17254: courses to clone
1.1182 raeburn 17255:
17256: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17257:
17258:
17259: Side Effects: None
17260:
17261: =cut
17262:
17263:
17264: sub search_courses {
1.1221 raeburn 17265: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17266: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 17267: my (%courses,%showcourses,$cloner);
17268: if (($filter->{'ownerfilter'} ne '') ||
17269: ($filter->{'ownerdomfilter'} ne '')) {
17270: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17271: $filter->{'ownerdomfilter'};
17272: }
17273: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17274: if (!$filter->{$item}) {
17275: $filter->{$item}='.';
17276: }
17277: }
17278: my $now = time;
17279: my $timefilter =
17280: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17281: my ($createdbefore,$createdafter);
17282: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17283: $createdbefore = $now;
17284: $createdafter = $now-$filter->{'createdfilter'};
17285: }
17286: my ($instcodefilter,$regexpok);
17287: if ($numtitles) {
17288: if ($env{'form.official'} eq 'on') {
17289: $instcodefilter =
17290: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17291: $regexpok = 1;
17292: } elsif ($env{'form.official'} eq 'off') {
17293: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17294: unless ($instcodefilter eq '') {
17295: $regexpok = -1;
17296: }
17297: }
17298: } else {
17299: $instcodefilter = $filter->{'instcodefilter'};
17300: }
17301: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17302: if ($type eq '') { $type = '.'; }
17303:
17304: if (($clonerudom ne '') && ($cloneruname ne '')) {
17305: $cloner = $cloneruname.':'.$clonerudom;
17306: }
17307: %courses = &Apache::lonnet::courseiddump($dom,
17308: $filter->{'descriptfilter'},
17309: $timefilter,
17310: $instcodefilter,
17311: $filter->{'combownerfilter'},
17312: $filter->{'coursefilter'},
17313: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 17314: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 17315: $filter->{'cloneableonly'},
17316: $createdbefore,$createdafter,undef,
1.1221 raeburn 17317: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 17318: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17319: my $ccrole;
17320: if ($type eq 'Community') {
17321: $ccrole = 'co';
17322: } else {
17323: $ccrole = 'cc';
17324: }
17325: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17326: $filter->{'persondomfilter'},
17327: 'userroles',undef,
17328: [$ccrole,'in','ad','ep','ta','cr'],
17329: $dom);
17330: foreach my $role (keys(%rolehash)) {
17331: my ($cnum,$cdom,$courserole) = split(':',$role);
17332: my $cid = $cdom.'_'.$cnum;
17333: if (exists($courses{$cid})) {
17334: if (ref($courses{$cid}) eq 'HASH') {
17335: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17336: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 17337: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 17338: }
17339: } else {
17340: $courses{$cid}{roles} = [$courserole];
17341: }
17342: $showcourses{$cid} = $courses{$cid};
17343: }
17344: }
17345: }
17346: %courses = %showcourses;
17347: }
17348: return %courses;
17349: }
17350:
17351: =pod
17352:
1.1181 raeburn 17353: =back
17354:
1.1207 raeburn 17355: =head1 Routines for version requirements for current course.
17356:
17357: =over 4
17358:
17359: =item * &check_release_required()
17360:
17361: Compares required LON-CAPA version with version on server, and
17362: if required version is newer looks for a server with the required version.
17363:
17364: Looks first at servers in user's owen domain; if none suitable, looks at
17365: servers in course's domain are permitted to host sessions for user's domain.
17366:
17367: Inputs:
17368:
17369: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17370:
17371: $courseid - Course ID of current course
17372:
17373: $rolecode - User's current role in course (for switchserver query string).
17374:
17375: $required - LON-CAPA version needed by course (format: Major.Minor).
17376:
17377:
17378: Returns:
17379:
17380: $switchserver - query string tp append to /adm/switchserver call (if
17381: current server's LON-CAPA version is too old.
17382:
17383: $warning - Message is displayed if no suitable server could be found.
17384:
17385: =cut
17386:
17387: sub check_release_required {
17388: my ($loncaparev,$courseid,$rolecode,$required) = @_;
17389: my ($switchserver,$warning);
17390: if ($required ne '') {
17391: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
17392: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17393: if ($reqdmajor ne '' && $reqdminor ne '') {
17394: my $otherserver;
17395: if (($major eq '' && $minor eq '') ||
17396: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
17397: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
17398: my $switchlcrev =
17399: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
17400: $userdomserver);
17401: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17402: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
17403: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
17404: my $cdom = $env{'course.'.$courseid.'.domain'};
17405: if ($cdom ne $env{'user.domain'}) {
17406: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
17407: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
17408: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17409: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
17410: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
17411: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
17412: my $canhost =
17413: &Apache::lonnet::can_host_session($env{'user.domain'},
17414: $coursedomserver,
17415: $remoterev,
17416: $udomdefaults{'remotesessions'},
17417: $defdomdefaults{'hostedsessions'});
17418:
17419: if ($canhost) {
17420: $otherserver = $coursedomserver;
17421: } else {
17422: $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.");
17423: }
17424: } else {
17425: $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).");
17426: }
17427: } else {
17428: $otherserver = $userdomserver;
17429: }
17430: }
17431: if ($otherserver ne '') {
17432: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
17433: }
17434: }
17435: }
17436: return ($switchserver,$warning);
17437: }
17438:
17439: =pod
17440:
17441: =item * &check_release_result()
17442:
17443: Inputs:
17444:
17445: $switchwarning - Warning message if no suitable server found to host session.
17446:
17447: $switchserver - query string to append to /adm/switchserver containing lonHostID
17448: and current role.
17449:
17450: Returns: HTML to display with information about requirement to switch server.
17451: Either displaying warning with link to Roles/Courses screen or
17452: display link to switchserver.
17453:
1.1181 raeburn 17454: =cut
17455:
1.1207 raeburn 17456: sub check_release_result {
17457: my ($switchwarning,$switchserver) = @_;
17458: my $output = &start_page('Selected course unavailable on this server').
17459: '<p class="LC_warning">';
17460: if ($switchwarning) {
17461: $output .= $switchwarning.'<br /><a href="/adm/roles">';
17462: if (&show_course()) {
17463: $output .= &mt('Display courses');
17464: } else {
17465: $output .= &mt('Display roles');
17466: }
17467: $output .= '</a>';
17468: } elsif ($switchserver) {
17469: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
17470: '<br />'.
17471: '<a href="/adm/switchserver?'.$switchserver.'">'.
17472: &mt('Switch Server').
17473: '</a>';
17474: }
17475: $output .= '</p>'.&end_page();
17476: return $output;
17477: }
17478:
17479: =pod
17480:
17481: =item * &needs_coursereinit()
17482:
17483: Determine if course contents stored for user's session needs to be
17484: refreshed, because content has changed since "Big Hash" last tied.
17485:
17486: Check for change is made if time last checked is more than 10 minutes ago
17487: (by default).
17488:
17489: Inputs:
17490:
17491: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17492:
17493: $interval (optional) - Time which may elapse (in s) between last check for content
17494: change in current course. (default: 600 s).
17495:
17496: Returns: an array; first element is:
17497:
17498: =over 4
17499:
17500: 'switch' - if content updates mean user's session
17501: needs to be switched to a server running a newer LON-CAPA version
17502:
17503: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
17504: on current server hosting user's session
17505:
17506: '' - if no action required.
17507:
17508: =back
17509:
17510: If first item element is 'switch':
17511:
17512: second item is $switchwarning - Warning message if no suitable server found to host session.
17513:
17514: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
17515: and current role.
17516:
17517: otherwise: no other elements returned.
17518:
17519: =back
17520:
17521: =cut
17522:
17523: sub needs_coursereinit {
17524: my ($loncaparev,$interval) = @_;
17525: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
17526: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17527: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17528: my $now = time;
17529: if ($interval eq '') {
17530: $interval = 600;
17531: }
17532: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 17533: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1283 raeburn 17534: my $blocked = &blocking_status('reinit',$cnum,$cdom,undef,1);
1.1282 raeburn 17535: if ($blocked) {
17536: return ();
17537: }
1.1207 raeburn 17538: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17539: if ($lastchange > $env{'request.course.tied'}) {
17540: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17541: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17542: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17543: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17544: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17545: $curr_reqd_hash{'internal.releaserequired'}});
17546: my ($switchserver,$switchwarning) =
17547: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17548: $curr_reqd_hash{'internal.releaserequired'});
17549: if ($switchwarning ne '' || $switchserver ne '') {
17550: return ('switch',$switchwarning,$switchserver);
17551: }
17552: }
17553: }
17554: return ('update');
17555: }
17556: }
17557: return ();
17558: }
1.1181 raeburn 17559:
1.1083 raeburn 17560: sub update_content_constraints {
1.1326 raeburn 17561: my ($cdom,$cnum,$chome,$cid,$keeporder) = @_;
1.1083 raeburn 17562: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17563: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 17564: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 17565: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 17566: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 17567: if ($item eq 'resourcetag') {
17568: if ($name eq 'responsetype') {
17569: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17570: }
1.1307 raeburn 17571: } elsif ($item eq 'course') {
17572: if ($name eq 'courserestype') {
17573: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
17574: }
1.1083 raeburn 17575: }
17576: }
17577: my $navmap = Apache::lonnavmaps::navmap->new();
17578: if (defined($navmap)) {
1.1307 raeburn 17579: my (%allresponses,%allcrsrestypes);
17580: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
17581: if ($res->is_tool()) {
17582: if ($allcrsrestypes{'exttool'}) {
17583: $allcrsrestypes{'exttool'} ++;
17584: } else {
17585: $allcrsrestypes{'exttool'} = 1;
17586: }
17587: next;
17588: }
1.1083 raeburn 17589: my %responses = $res->responseTypes();
17590: foreach my $key (keys(%responses)) {
17591: next unless(exists($checkresponsetypes{$key}));
17592: $allresponses{$key} += $responses{$key};
17593: }
17594: }
17595: foreach my $key (keys(%allresponses)) {
17596: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17597: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17598: ($reqdmajor,$reqdminor) = ($major,$minor);
17599: }
17600: }
1.1307 raeburn 17601: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 17602: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 17603: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17604: ($reqdmajor,$reqdminor) = ($major,$minor);
17605: }
17606: }
1.1083 raeburn 17607: undef($navmap);
17608: }
1.1326 raeburn 17609: my (@resources,@order,@resparms,@zombies);
17610: if ($keeporder) {
17611: use LONCAPA::map;
17612: @resources = @LONCAPA::map::resources;
17613: @order = @LONCAPA::map::order;
17614: @resparms = @LONCAPA::map::resparms;
17615: @zombies = @LONCAPA::map::zombies;
17616: }
1.1308 raeburn 17617: my $suppmap = 'supplemental.sequence';
17618: my ($suppcount,$supptools,$errors) = (0,0,0);
17619: ($suppcount,$supptools,$errors) = &recurse_supplemental($cnum,$cdom,$suppmap,
17620: $suppcount,$supptools,$errors);
1.1326 raeburn 17621: if ($keeporder) {
17622: @LONCAPA::map::resources = @resources;
17623: @LONCAPA::map::order = @order;
17624: @LONCAPA::map::resparms = @resparms;
17625: @LONCAPA::map::zombies = @zombies;
17626: }
1.1308 raeburn 17627: if ($supptools) {
17628: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
17629: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17630: ($reqdmajor,$reqdminor) = ($major,$minor);
17631: }
17632: }
1.1083 raeburn 17633: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17634: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17635: }
17636: return;
17637: }
17638:
1.1110 raeburn 17639: sub allmaps_incourse {
17640: my ($cdom,$cnum,$chome,$cid) = @_;
17641: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17642: $cid = $env{'request.course.id'};
17643: $cdom = $env{'course.'.$cid.'.domain'};
17644: $cnum = $env{'course.'.$cid.'.num'};
17645: $chome = $env{'course.'.$cid.'.home'};
17646: }
17647: my %allmaps = ();
17648: my $lastchange =
17649: &Apache::lonnet::get_coursechange($cdom,$cnum);
17650: if ($lastchange > $env{'request.course.tied'}) {
17651: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17652: unless ($ferr) {
1.1326 raeburn 17653: &update_content_constraints($cdom,$cnum,$chome,$cid,1);
1.1110 raeburn 17654: }
17655: }
17656: my $navmap = Apache::lonnavmaps::navmap->new();
17657: if (defined($navmap)) {
17658: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17659: $allmaps{$res->src()} = 1;
17660: }
17661: }
17662: return \%allmaps;
17663: }
17664:
1.1083 raeburn 17665: sub parse_supplemental_title {
17666: my ($title) = @_;
17667:
17668: my ($foldertitle,$renametitle);
17669: if ($title =~ /&&&/) {
17670: $title = &HTML::Entites::decode($title);
17671: }
17672: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17673: $renametitle=$4;
17674: my ($time,$uname,$udom) = ($1,$2,$3);
17675: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17676: my $name = &plainname($uname,$udom);
17677: $name = &HTML::Entities::encode($name,'"<>&\'');
17678: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17679: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17680: $name.': <br />'.$foldertitle;
17681: }
17682: if (wantarray) {
17683: return ($title,$foldertitle,$renametitle);
17684: }
17685: return $title;
17686: }
17687:
1.1143 raeburn 17688: sub recurse_supplemental {
1.1308 raeburn 17689: my ($cnum,$cdom,$suppmap,$numfiles,$numexttools,$errors) = @_;
1.1143 raeburn 17690: if ($suppmap) {
17691: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17692: if ($fatal) {
17693: $errors ++;
17694: } else {
17695: if ($#LONCAPA::map::resources > 0) {
17696: foreach my $res (@LONCAPA::map::resources) {
17697: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17698: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 17699: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1308 raeburn 17700: ($numfiles,$numexttools,$errors) = &recurse_supplemental($cnum,$cdom,$1,
17701: $numfiles,$numexttools,$errors);
1.1143 raeburn 17702: } else {
1.1308 raeburn 17703: if ($src =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
17704: $numexttools ++;
17705: }
1.1143 raeburn 17706: $numfiles ++;
17707: }
17708: }
17709: }
17710: }
17711: }
17712: }
1.1308 raeburn 17713: return ($numfiles,$numexttools,$errors);
1.1143 raeburn 17714: }
17715:
1.1101 raeburn 17716: sub symb_to_docspath {
1.1267 raeburn 17717: my ($symb,$navmapref) = @_;
17718: return unless ($symb && ref($navmapref));
1.1101 raeburn 17719: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17720: if ($resurl=~/\.(sequence|page)$/) {
17721: $mapurl=$resurl;
17722: } elsif ($resurl eq 'adm/navmaps') {
17723: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17724: }
17725: my $mapresobj;
1.1267 raeburn 17726: unless (ref($$navmapref)) {
17727: $$navmapref = Apache::lonnavmaps::navmap->new();
17728: }
17729: if (ref($$navmapref)) {
17730: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 17731: }
17732: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17733: my $type=$2;
17734: my $path;
17735: if (ref($mapresobj)) {
17736: my $pcslist = $mapresobj->map_hierarchy();
17737: if ($pcslist ne '') {
17738: foreach my $pc (split(/,/,$pcslist)) {
17739: next if ($pc <= 1);
1.1267 raeburn 17740: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 17741: if (ref($res)) {
17742: my $thisurl = $res->src();
17743: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17744: my $thistitle = $res->title();
17745: $path .= '&'.
17746: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 17747: &escape($thistitle).
1.1101 raeburn 17748: ':'.$res->randompick().
17749: ':'.$res->randomout().
17750: ':'.$res->encrypted().
17751: ':'.$res->randomorder().
17752: ':'.$res->is_page();
17753: }
17754: }
17755: }
17756: $path =~ s/^\&//;
17757: my $maptitle = $mapresobj->title();
17758: if ($mapurl eq 'default') {
1.1129 raeburn 17759: $maptitle = 'Main Content';
1.1101 raeburn 17760: }
17761: $path .= (($path ne '')? '&' : '').
17762: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17763: &escape($maptitle).
1.1101 raeburn 17764: ':'.$mapresobj->randompick().
17765: ':'.$mapresobj->randomout().
17766: ':'.$mapresobj->encrypted().
17767: ':'.$mapresobj->randomorder().
17768: ':'.$mapresobj->is_page();
17769: } else {
17770: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17771: my $ispage = (($type eq 'page')? 1 : '');
17772: if ($mapurl eq 'default') {
1.1129 raeburn 17773: $maptitle = 'Main Content';
1.1101 raeburn 17774: }
17775: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17776: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 17777: }
17778: unless ($mapurl eq 'default') {
17779: $path = 'default&'.
1.1146 raeburn 17780: &escape('Main Content').
1.1101 raeburn 17781: ':::::&'.$path;
17782: }
17783: return $path;
17784: }
17785:
1.1094 raeburn 17786: sub captcha_display {
1.1327 raeburn 17787: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 17788: my ($output,$error);
1.1234 raeburn 17789: my ($captcha,$pubkey,$privkey,$version) =
1.1327 raeburn 17790: &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 17791: if ($captcha eq 'original') {
1.1094 raeburn 17792: $output = &create_captcha();
17793: unless ($output) {
1.1172 raeburn 17794: $error = 'captcha';
1.1094 raeburn 17795: }
17796: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17797: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 17798: unless ($output) {
1.1172 raeburn 17799: $error = 'recaptcha';
1.1094 raeburn 17800: }
17801: }
1.1234 raeburn 17802: return ($output,$error,$captcha,$version);
1.1094 raeburn 17803: }
17804:
17805: sub captcha_response {
1.1327 raeburn 17806: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 17807: my ($captcha_chk,$captcha_error);
1.1327 raeburn 17808: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 17809: if ($captcha eq 'original') {
1.1094 raeburn 17810: ($captcha_chk,$captcha_error) = &check_captcha();
17811: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17812: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 17813: } else {
17814: $captcha_chk = 1;
17815: }
17816: return ($captcha_chk,$captcha_error);
17817: }
17818:
17819: sub get_captcha_config {
1.1327 raeburn 17820: my ($context,$lonhost,$dom_in_effect) = @_;
1.1234 raeburn 17821: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 17822: my $hostname = &Apache::lonnet::hostname($lonhost);
17823: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17824: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 17825: if ($context eq 'usercreation') {
17826: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17827: if (ref($domconfig{$context}) eq 'HASH') {
17828: $hashtocheck = $domconfig{$context}{'cancreate'};
17829: if (ref($hashtocheck) eq 'HASH') {
17830: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17831: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17832: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17833: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17834: }
17835: if ($privkey && $pubkey) {
17836: $captcha = 'recaptcha';
1.1234 raeburn 17837: $version = $hashtocheck->{'recaptchaversion'};
17838: if ($version ne '2') {
17839: $version = 1;
17840: }
1.1095 raeburn 17841: } else {
17842: $captcha = 'original';
17843: }
17844: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17845: $captcha = 'original';
17846: }
1.1094 raeburn 17847: }
1.1095 raeburn 17848: } else {
17849: $captcha = 'captcha';
17850: }
17851: } elsif ($context eq 'login') {
17852: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17853: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17854: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17855: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 17856: if ($privkey && $pubkey) {
17857: $captcha = 'recaptcha';
1.1234 raeburn 17858: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17859: if ($version ne '2') {
17860: $version = 1;
17861: }
1.1095 raeburn 17862: } else {
17863: $captcha = 'original';
1.1094 raeburn 17864: }
1.1095 raeburn 17865: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17866: $captcha = 'original';
1.1094 raeburn 17867: }
1.1327 raeburn 17868: } elsif ($context eq 'passwords') {
17869: if ($dom_in_effect) {
17870: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
17871: if ($passwdconf{'captcha'} eq 'recaptcha') {
17872: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
17873: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
17874: $privkey = $passwdconf{'recaptchakeys'}{'private'};
17875: }
17876: if ($privkey && $pubkey) {
17877: $captcha = 'recaptcha';
17878: $version = $passwdconf{'recaptchaversion'};
17879: if ($version ne '2') {
17880: $version = 1;
17881: }
17882: } else {
17883: $captcha = 'original';
17884: }
17885: } elsif ($passwdconf{'captcha'} ne 'notused') {
17886: $captcha = 'original';
17887: }
17888: }
17889: }
1.1234 raeburn 17890: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 17891: }
17892:
17893: sub create_captcha {
17894: my %captcha_params = &captcha_settings();
17895: my ($output,$maxtries,$tries) = ('',10,0);
17896: while ($tries < $maxtries) {
17897: $tries ++;
17898: my $captcha = Authen::Captcha->new (
17899: output_folder => $captcha_params{'output_dir'},
17900: data_folder => $captcha_params{'db_dir'},
17901: );
17902: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17903:
17904: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17905: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17906: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 17907: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17908: '<br />'.
17909: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 17910: last;
17911: }
17912: }
1.1323 raeburn 17913: if ($output eq '') {
17914: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
17915: }
1.1094 raeburn 17916: return $output;
17917: }
17918:
17919: sub captcha_settings {
17920: my %captcha_params = (
17921: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17922: www_output_dir => "/captchaspool",
17923: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17924: numchars => '5',
17925: );
17926: return %captcha_params;
17927: }
17928:
17929: sub check_captcha {
17930: my ($captcha_chk,$captcha_error);
17931: my $code = $env{'form.code'};
17932: my $md5sum = $env{'form.crypt'};
17933: my %captcha_params = &captcha_settings();
17934: my $captcha = Authen::Captcha->new(
17935: output_folder => $captcha_params{'output_dir'},
17936: data_folder => $captcha_params{'db_dir'},
17937: );
1.1109 raeburn 17938: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 17939: my %captcha_hash = (
17940: 0 => 'Code not checked (file error)',
17941: -1 => 'Failed: code expired',
17942: -2 => 'Failed: invalid code (not in database)',
17943: -3 => 'Failed: invalid code (code does not match crypt)',
17944: );
17945: if ($captcha_chk != 1) {
17946: $captcha_error = $captcha_hash{$captcha_chk}
17947: }
17948: return ($captcha_chk,$captcha_error);
17949: }
17950:
17951: sub create_recaptcha {
1.1234 raeburn 17952: my ($pubkey,$version) = @_;
17953: if ($version >= 2) {
17954: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17955: } else {
17956: my $use_ssl;
17957: if ($ENV{'SERVER_PORT'} == 443) {
17958: $use_ssl = 1;
17959: }
17960: my $captcha = Captcha::reCAPTCHA->new;
17961: return $captcha->get_options_setter({theme => 'white'})."\n".
17962: $captcha->get_html($pubkey,undef,$use_ssl).
17963: &mt('If the text is hard to read, [_1] will replace them.',
17964: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17965: '<br /><br />';
17966: }
1.1094 raeburn 17967: }
17968:
17969: sub check_recaptcha {
1.1234 raeburn 17970: my ($privkey,$version) = @_;
1.1094 raeburn 17971: my $captcha_chk;
1.1234 raeburn 17972: if ($version >= 2) {
17973: my %info = (
17974: secret => $privkey,
17975: response => $env{'form.g-recaptcha-response'},
17976: remoteip => $ENV{'REMOTE_ADDR'},
17977: );
1.1280 raeburn 17978: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
17979: $request->content(join('&',map {
17980: my $name = escape($_);
17981: "$name=" . ( ref($info{$_}) eq 'ARRAY'
17982: ? join("&$name=", map {escape($_) } @{$info{$_}})
17983: : &escape($info{$_}) );
17984: } keys(%info)));
17985: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 17986: if ($response->is_success) {
17987: my $data = JSON::DWIW->from_json($response->decoded_content);
17988: if (ref($data) eq 'HASH') {
17989: if ($data->{'success'}) {
17990: $captcha_chk = 1;
17991: }
17992: }
17993: }
17994: } else {
17995: my $captcha = Captcha::reCAPTCHA->new;
17996: my $captcha_result =
17997: $captcha->check_answer(
17998: $privkey,
17999: $ENV{'REMOTE_ADDR'},
18000: $env{'form.recaptcha_challenge_field'},
18001: $env{'form.recaptcha_response_field'},
18002: );
18003: if ($captcha_result->{is_valid}) {
18004: $captcha_chk = 1;
18005: }
1.1094 raeburn 18006: }
18007: return $captcha_chk;
18008: }
18009:
1.1174 raeburn 18010: sub emailusername_info {
1.1244 raeburn 18011: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 18012: my %titles = &Apache::lonlocal::texthash (
18013: lastname => 'Last Name',
18014: firstname => 'First Name',
18015: institution => 'School/college/university',
18016: location => "School's city, state/province, country",
18017: web => "School's web address",
18018: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 18019: id => 'Student/Employee ID',
1.1174 raeburn 18020: );
18021: return (\@fields,\%titles);
18022: }
18023:
1.1161 raeburn 18024: sub cleanup_html {
18025: my ($incoming) = @_;
18026: my $outgoing;
18027: if ($incoming ne '') {
18028: $outgoing = $incoming;
18029: $outgoing =~ s/;/;/g;
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: }
18043: return $outgoing;
18044: }
18045:
1.1190 musolffc 18046: # Checks for critical messages and returns a redirect url if one exists.
18047: # $interval indicates how often to check for messages.
1.1282 raeburn 18048: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 18049: sub critical_redirect {
1.1282 raeburn 18050: my ($interval,$context) = @_;
1.1190 musolffc 18051: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 18052: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
18053: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18054: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18055: my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
18056: if ($blocked) {
18057: my $checkrole = "cm./$cdom/$cnum";
18058: if ($env{'request.course.sec'} ne '') {
18059: $checkrole .= "/$env{'request.course.sec'}";
18060: }
18061: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
18062: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
18063: return;
18064: }
18065: }
18066: }
1.1190 musolffc 18067: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
18068: $env{'user.name'});
18069: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 18070: my $redirecturl;
1.1190 musolffc 18071: if ($what[0]) {
18072: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
18073: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 18074: my $url=&Apache::lonnet::absolute_url().$redirecturl;
18075: return (1, $url);
1.1190 musolffc 18076: }
1.1191 raeburn 18077: }
18078: }
18079: return ();
1.1190 musolffc 18080: }
18081:
1.1174 raeburn 18082: # Use:
18083: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
18084: #
18085: ##################################################
18086: # password associated functions #
18087: ##################################################
18088: sub des_keys {
18089: # Make a new key for DES encryption.
18090: # Each key has two parts which are returned separately.
18091: # Please note: Each key must be passed through the &hex function
18092: # before it is output to the web browser. The hex versions cannot
18093: # be used to decrypt.
18094: my @hexstr=('0','1','2','3','4','5','6','7',
18095: '8','9','a','b','c','d','e','f');
18096: my $lkey='';
18097: for (0..7) {
18098: $lkey.=$hexstr[rand(15)];
18099: }
18100: my $ukey='';
18101: for (0..7) {
18102: $ukey.=$hexstr[rand(15)];
18103: }
18104: return ($lkey,$ukey);
18105: }
18106:
18107: sub des_decrypt {
18108: my ($key,$cyphertext) = @_;
18109: my $keybin=pack("H16",$key);
18110: my $cypher;
18111: if ($Crypt::DES::VERSION>=2.03) {
18112: $cypher=new Crypt::DES $keybin;
18113: } else {
18114: $cypher=new DES $keybin;
18115: }
1.1233 raeburn 18116: my $plaintext='';
18117: my $cypherlength = length($cyphertext);
18118: my $numchunks = int($cypherlength/32);
18119: for (my $j=0; $j<$numchunks; $j++) {
18120: my $start = $j*32;
18121: my $cypherblock = substr($cyphertext,$start,32);
18122: my $chunk =
18123: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
18124: $chunk .=
18125: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
18126: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
18127: $plaintext .= $chunk;
18128: }
1.1174 raeburn 18129: return $plaintext;
18130: }
18131:
1.1309 raeburn 18132: sub make_short_symbs {
18133: my ($cdom,$cnum,$navmap) = @_;
18134: return unless (ref($navmap));
18135: my ($numnew,@errors);
18136: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
18137: if (@toshorten) {
18138: my (%maps,%resources,%titles);
18139: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
18140: 'shorturls',$cdom,$cnum);
18141: my %tocreate;
18142: if (keys(%resources)) {
18143: foreach my $item (sort {$a <=> $b} (@toshorten)) {
18144: my $symb = $resources{$item};
18145: if ($symb) {
18146: $tocreate{$cnum.'&'.$symb} = 1;
18147: }
18148: }
18149: }
18150: if (keys(%tocreate)) {
18151: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
18152: my $su = Short::URL->new(no_vowels => 1);
18153: my $init = '';
18154: my (%newunique,%addcourse,%courseonly,%failed);
18155: # get lock on tiny db
18156: my $now = time;
18157: my $lockhash = {
18158: "lock\0$now" => $env{'user.name'}.
18159: ':'.$env{'user.domain'},
18160: };
18161: my $tries = 0;
18162: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18163: my ($code,$error);
18164: while (($gotlock ne 'ok') && ($tries<3)) {
18165: $tries ++;
18166: sleep 1;
1.1319 raeburn 18167: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 18168: }
18169: if ($gotlock eq 'ok') {
18170: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
18171: \%addcourse,\%courseonly,\%failed);
18172: if (keys(%failed)) {
18173: my $numfailed = scalar(keys(%failed));
18174: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
18175: }
18176: if (keys(%newunique)) {
18177: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
18178: if ($putres eq 'ok') {
18179: $numnew = scalar(keys(%newunique));
18180: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
18181: unless ($newputres eq 'ok') {
18182: push(@errors,&mt('error: could not store course look-up of short URLs'));
18183: }
18184: } else {
18185: push(@errors,&mt('error: could not store unique six character URLs'));
18186: }
18187: }
18188: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
18189: unless ($dellockres eq 'ok') {
18190: push(@errors,&mt('error: could not release lockfile'));
18191: }
18192: } else {
18193: push(@errors,&mt('error: could not obtain lockfile'));
18194: }
18195: if (keys(%courseonly)) {
18196: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
18197: if ($result ne 'ok') {
18198: push(@errors,&mt('error: could not update course look-up of short URLs'));
18199: }
18200: }
18201: }
18202: }
18203: return ($numnew,\@errors);
18204: }
18205:
18206: sub shorten_symbs {
18207: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
18208: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
18209: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
18210: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
18211: my (%possibles,%collisions);
18212: foreach my $key (keys(%{$tocreate})) {
18213: my $num = String::CRC32::crc32($key);
18214: my $tiny = $su->encode($num,$init);
18215: if ($tiny) {
18216: $possibles{$tiny} = $key;
18217: }
18218: }
18219: if (!$init) {
18220: $init = 1;
18221: } else {
18222: $init ++;
18223: }
18224: if (keys(%possibles)) {
18225: my @posstiny = keys(%possibles);
18226: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
18227: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
18228: if (keys(%currtiny)) {
18229: foreach my $key (keys(%currtiny)) {
18230: next if ($currtiny{$key} eq '');
18231: if ($currtiny{$key} eq $possibles{$key}) {
18232: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
18233: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18234: $courseonly->{$tsymb} = $key;
18235: }
18236: } else {
18237: $collisions{$possibles{$key}} = 1;
18238: }
18239: delete($possibles{$key});
18240: }
18241: }
18242: foreach my $key (keys(%possibles)) {
18243: $newunique->{$key} = $possibles{$key};
18244: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
18245: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18246: $addcourse->{$tsymb} = $key;
18247: }
18248: }
18249: }
18250: if (keys(%collisions)) {
18251: if ($init <5) {
18252: if (!$init) {
18253: $init = 1;
18254: } else {
18255: $init ++;
18256: }
18257: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
18258: $newunique,$addcourse,$courseonly,$failed);
18259: } else {
18260: foreach my $key (keys(%collisions)) {
18261: $failed->{$key} = 1;
18262: }
18263: }
18264: }
18265: return $init;
18266: }
18267:
1.1328 raeburn 18268: sub is_nonframeable {
1.1329 raeburn 18269: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
18270: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
1.1330 raeburn 18271: return if (($remprotocol eq '') || ($remhost eq ''));
1.1329 raeburn 18272:
18273: $remprotocol = lc($remprotocol);
18274: $remhost = lc($remhost);
18275: my $remport = 80;
18276: if ($remprotocol eq 'https') {
18277: $remport = 443;
18278: }
1.1330 raeburn 18279: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
1.1329 raeburn 18280: if ($cached) {
18281: unless ($nocache) {
18282: if ($result) {
18283: return 1;
18284: } else {
18285: return 0;
18286: }
18287: }
18288: }
1.1328 raeburn 18289: my $uselink;
18290: my $request = new HTTP::Request('HEAD',$url);
18291: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
18292: if ($response->is_success()) {
18293: my $secpolicy = lc($response->header('content-security-policy'));
18294: my $xframeop = lc($response->header('x-frame-options'));
18295: $secpolicy =~ s/^\s+|\s+$//g;
18296: $xframeop =~ s/^\s+|\s+$//g;
18297: if (($secpolicy ne '') || ($xframeop ne '')) {
1.1329 raeburn 18298: my $remotehost = $remprotocol.'://'.$remhost;
1.1328 raeburn 18299: my ($origin,$protocol,$port);
18300: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
18301: $port = $ENV{'SERVER_PORT'};
18302: } else {
18303: $port = 80;
18304: }
18305: if ($absolute eq '') {
18306: $protocol = 'http:';
18307: if ($port == 443) {
18308: $protocol = 'https:';
18309: }
18310: $origin = $protocol.'//'.lc($hostname);
18311: } else {
18312: $origin = lc($absolute);
18313: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
18314: }
18315: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
18316: my $framepolicy = $1;
18317: $framepolicy =~ s/^\s+|\s+$//g;
18318: my @policies = split(/\s+/,$framepolicy);
18319: if (@policies) {
18320: if (grep(/^\Q'none'\E$/,@policies)) {
18321: $uselink = 1;
18322: } else {
18323: $uselink = 1;
18324: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
18325: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
18326: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
18327: undef($uselink);
18328: }
18329: if ($uselink) {
18330: if (grep(/^\Q'self'\E$/,@policies)) {
18331: if (($origin ne '') && ($remotehost eq $origin)) {
18332: undef($uselink);
18333: }
18334: }
18335: }
18336: if ($uselink) {
18337: my @possok;
18338: if ($ip ne '') {
18339: push(@possok,$ip);
18340: }
18341: my $hoststr = '';
18342: foreach my $part (reverse(split(/\./,$hostname))) {
18343: if ($hoststr eq '') {
18344: $hoststr = $part;
18345: } else {
18346: $hoststr = "$part.$hoststr";
18347: }
18348: if ($hoststr eq $hostname) {
18349: push(@possok,$hostname);
18350: } else {
18351: push(@possok,"*.$hoststr");
18352: }
18353: }
18354: if (@possok) {
18355: foreach my $poss (@possok) {
18356: last if (!$uselink);
18357: foreach my $policy (@policies) {
18358: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
18359: undef($uselink);
18360: last;
18361: }
18362: }
18363: }
18364: }
18365: }
18366: }
18367: }
18368: } elsif ($xframeop ne '') {
18369: $uselink = 1;
18370: my @policies = split(/\s*,\s*/,$xframeop);
18371: if (@policies) {
18372: unless (grep(/^deny$/,@policies)) {
18373: if ($origin ne '') {
18374: if (grep(/^sameorigin$/,@policies)) {
18375: if ($remotehost eq $origin) {
18376: undef($uselink);
18377: }
18378: }
18379: if ($uselink) {
18380: foreach my $policy (@policies) {
18381: if ($policy =~ /^allow-from\s*(.+)$/) {
18382: my $allowfrom = $1;
18383: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
18384: undef($uselink);
18385: last;
18386: }
18387: }
18388: }
18389: }
18390: }
18391: }
18392: }
18393: }
18394: }
18395: }
1.1329 raeburn 18396: if ($nocache) {
18397: if ($cached) {
18398: my $devalidate;
18399: if ($uselink && !$result) {
18400: $devalidate = 1;
18401: } elsif (!$uselink && $result) {
18402: $devalidate = 1;
18403: }
18404: if ($devalidate) {
18405: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
18406: }
18407: }
18408: } else {
18409: if ($uselink) {
18410: $result = 1;
18411: } else {
18412: $result = 0;
18413: }
18414: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
18415: }
1.1328 raeburn 18416: return $uselink;
18417: }
18418:
1.112 bowersj2 18419: 1;
18420: __END__;
1.41 ng 18421:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>