Annotation of loncom/interface/loncommon.pm, revision 1.1335
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1335 ! raeburn 4: # $Id: loncommon.pm,v 1.1334 2019/11/20 22:53:32 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1108 raeburn 70: use Apache::lonuserutils();
1.1110 raeburn 71: use Apache::lonuserstate();
1.1182 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1280 raeburn 74: use LONCAPA::LWPReq;
1.1328 raeburn 75: use HTTP::Request;
1.657 raeburn 76: use DateTime::TimeZone;
1.1241 raeburn 77: use DateTime::Locale;
1.1220 raeburn 78: use Encode();
1.1091 foxr 79: use Text::Aspell;
1.1094 raeburn 80: use Authen::Captcha;
81: use Captcha::reCAPTCHA;
1.1234 raeburn 82: use JSON::DWIW;
83: use LWP::UserAgent;
1.1174 raeburn 84: use Crypt::DES;
85: use DynaLoader; # for Crypt::DES version
1.1223 musolffc 86: use MIME::Lite;
87: use MIME::Types;
1.1292 raeburn 88: use File::Copy();
1.1300 raeburn 89: use File::Path();
1.1309 raeburn 90: use String::CRC32();
91: use Short::URL();
1.117 www 92:
1.517 raeburn 93: # ---------------------------------------------- Designs
94: use vars qw(%defaultdesign);
95:
1.22 www 96: my $readit;
97:
1.517 raeburn 98:
1.157 matthew 99: ##
100: ## Global Variables
101: ##
1.46 matthew 102:
1.643 foxr 103:
104: # ----------------------------------------------- SSI with retries:
105: #
106:
107: =pod
108:
1.648 raeburn 109: =head1 Server Side include with retries:
1.643 foxr 110:
111: =over 4
112:
1.648 raeburn 113: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 114:
115: Performs an ssi with some number of retries. Retries continue either
116: until the result is ok or until the retry count supplied by the
117: caller is exhausted.
118:
119: Inputs:
1.648 raeburn 120:
121: =over 4
122:
1.643 foxr 123: resource - Identifies the resource to insert.
1.648 raeburn 124:
1.643 foxr 125: retries - Count of the number of retries allowed.
1.648 raeburn 126:
1.643 foxr 127: form - Hash that identifies the rendering options.
128:
1.648 raeburn 129: =back
130:
131: Returns:
132:
133: =over 4
134:
1.643 foxr 135: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 136:
1.643 foxr 137: response - The response from the last attempt (which may or may not have been successful.
138:
1.648 raeburn 139: =back
140:
141: =back
142:
1.643 foxr 143: =cut
144:
145: sub ssi_with_retries {
146: my ($resource, $retries, %form) = @_;
147:
148:
149: my $ok = 0; # True if we got a good response.
150: my $content;
151: my $response;
152:
153: # Try to get the ssi done. within the retries count:
154:
155: do {
156: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
157: $ok = $response->is_success;
1.650 www 158: if (!$ok) {
159: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
160: }
1.643 foxr 161: $retries--;
162: } while (!$ok && ($retries > 0));
163:
164: if (!$ok) {
165: $content = ''; # On error return an empty content.
166: }
167: return ($content, $response);
168:
169: }
170:
171:
172:
1.20 www 173: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 174: my %language;
1.124 www 175: my %supported_language;
1.1088 foxr 176: my %supported_codes;
1.1048 foxr 177: my %latex_language; # For choosing hyphenation in <transl..>
178: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 179: my %cprtag;
1.192 taceyjo1 180: my %scprtag;
1.351 www 181: my %fe; my %fd; my %fm;
1.41 ng 182: my %category_extensions;
1.12 harris41 183:
1.46 matthew 184: # ---------------------------------------------- Thesaurus variables
1.144 matthew 185: #
186: # %Keywords:
187: # A hash used by &keyword to determine if a word is considered a keyword.
188: # $thesaurus_db_file
189: # Scalar containing the full path to the thesaurus database.
1.46 matthew 190:
191: my %Keywords;
192: my $thesaurus_db_file;
193:
1.144 matthew 194: #
195: # Initialize values from language.tab, copyright.tab, filetypes.tab,
196: # thesaurus.tab, and filecategories.tab.
197: #
1.18 www 198: BEGIN {
1.46 matthew 199: # Variable initialization
200: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
201: #
1.22 www 202: unless ($readit) {
1.12 harris41 203: # ------------------------------------------------------------------- languages
204: {
1.158 raeburn 205: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
206: '/language.tab';
1.1317 raeburn 207: if ( open(my $fh,'<',$langtabfile) ) {
1.356 albertel 208: while (my $line = <$fh>) {
209: next if ($line=~/^\#/);
210: chomp($line);
1.1088 foxr 211: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 212: $language{$key}=$val.' - '.$enc;
213: if ($sup) {
214: $supported_language{$key}=$sup;
1.1088 foxr 215: $supported_codes{$key} = $code;
1.158 raeburn 216: }
1.1048 foxr 217: if ($latex) {
218: $latex_language_bykey{$key} = $latex;
1.1088 foxr 219: $latex_language{$code} = $latex;
1.1048 foxr 220: }
1.158 raeburn 221: }
222: close($fh);
223: }
1.12 harris41 224: }
225: # ------------------------------------------------------------------ copyrights
226: {
1.158 raeburn 227: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
228: '/copyright.tab';
1.1317 raeburn 229: if ( open (my $fh,'<',$copyrightfile) ) {
1.356 albertel 230: while (my $line = <$fh>) {
231: next if ($line=~/^\#/);
232: chomp($line);
233: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 234: $cprtag{$key}=$val;
235: }
236: close($fh);
237: }
1.12 harris41 238: }
1.351 www 239: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 240: {
241: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
242: '/source_copyright.tab';
1.1317 raeburn 243: if ( open (my $fh,'<',$sourcecopyrightfile) ) {
1.356 albertel 244: while (my $line = <$fh>) {
245: next if ($line =~ /^\#/);
246: chomp($line);
247: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 248: $scprtag{$key}=$val;
249: }
250: close($fh);
251: }
252: }
1.63 www 253:
1.517 raeburn 254: # -------------------------------------------------------------- default domain designs
1.63 www 255: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 256: my $designfile = $designdir.'/default.tab';
1.1317 raeburn 257: if ( open (my $fh,'<',$designfile) ) {
1.517 raeburn 258: while (my $line = <$fh>) {
259: next if ($line =~ /^\#/);
260: chomp($line);
261: my ($key,$val)=(split(/\=/,$line));
262: if ($val) { $defaultdesign{$key}=$val; }
263: }
264: close($fh);
1.63 www 265: }
266:
1.15 harris41 267: # ------------------------------------------------------------- file categories
268: {
1.158 raeburn 269: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
270: '/filecategories.tab';
1.1317 raeburn 271: if ( open (my $fh,'<',$categoryfile) ) {
1.356 albertel 272: while (my $line = <$fh>) {
273: next if ($line =~ /^\#/);
274: chomp($line);
275: my ($extension,$category)=(split(/\s+/,$line,2));
1.1263 raeburn 276: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 277: }
278: close($fh);
279: }
280:
1.15 harris41 281: }
1.12 harris41 282: # ------------------------------------------------------------------ file types
283: {
1.158 raeburn 284: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
285: '/filetypes.tab';
1.1317 raeburn 286: if ( open (my $fh,'<',$typesfile) ) {
1.356 albertel 287: while (my $line = <$fh>) {
288: next if ($line =~ /^\#/);
289: chomp($line);
290: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 291: if ($descr ne '') {
292: $fe{$ending}=lc($emb);
293: $fd{$ending}=$descr;
1.351 www 294: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 295: }
296: }
297: close($fh);
298: }
1.12 harris41 299: }
1.22 www 300: &Apache::lonnet::logthis(
1.705 tempelho 301: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 302: $readit=1;
1.46 matthew 303: } # end of unless($readit)
1.32 matthew 304:
305: }
1.112 bowersj2 306:
1.42 matthew 307: ###############################################################
308: ## HTML and Javascript Helper Functions ##
309: ###############################################################
310:
311: =pod
312:
1.112 bowersj2 313: =head1 HTML and Javascript Functions
1.42 matthew 314:
1.112 bowersj2 315: =over 4
316:
1.648 raeburn 317: =item * &browser_and_searcher_javascript()
1.112 bowersj2 318:
319: X<browsing, javascript>X<searching, javascript>Returns a string
320: containing javascript with two functions, C<openbrowser> and
321: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
322: tags.
1.42 matthew 323:
1.648 raeburn 324: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 325:
326: inputs: formname, elementname, only, omit
327:
328: formname and elementname indicate the name of the html form and name of
329: the element that the results of the browsing selection are to be placed in.
330:
331: Specifying 'only' will restrict the browser to displaying only files
1.185 www 332: with the given extension. Can be a comma separated list.
1.42 matthew 333:
334: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 335: with the given extension. Can be a comma separated list.
1.42 matthew 336:
1.648 raeburn 337: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 338:
339: Inputs: formname, elementname
340:
341: formname and elementname specify the name of the html form and the name
342: of the element the selection from the search results will be placed in.
1.542 raeburn 343:
1.42 matthew 344: =cut
345:
346: sub browser_and_searcher_javascript {
1.199 albertel 347: my ($mode)=@_;
348: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 349: my $resurl=&escape_single(&lastresurl());
1.42 matthew 350: return <<END;
1.219 albertel 351: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 352: var editbrowser = null;
1.135 albertel 353: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 354: var url = '$resurl/?';
1.42 matthew 355: if (editbrowser == null) {
356: url += 'launch=1&';
357: }
358: url += 'catalogmode=interactive&';
1.199 albertel 359: url += 'mode=$mode&';
1.611 albertel 360: url += 'inhibitmenu=yes&';
1.42 matthew 361: url += 'form=' + formname + '&';
362: if (only != null) {
363: url += 'only=' + only + '&';
1.217 albertel 364: } else {
365: url += 'only=&';
366: }
1.42 matthew 367: if (omit != null) {
368: url += 'omit=' + omit + '&';
1.217 albertel 369: } else {
370: url += 'omit=&';
371: }
1.135 albertel 372: if (titleelement != null) {
373: url += 'titleelement=' + titleelement + '&';
1.217 albertel 374: } else {
375: url += 'titleelement=&';
376: }
1.42 matthew 377: url += 'element=' + elementname + '';
378: var title = 'Browser';
1.435 albertel 379: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 380: options += ',width=700,height=600';
381: editbrowser = open(url,title,options,'1');
382: editbrowser.focus();
383: }
384: var editsearcher;
1.135 albertel 385: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 386: var url = '/adm/searchcat?';
387: if (editsearcher == null) {
388: url += 'launch=1&';
389: }
390: url += 'catalogmode=interactive&';
1.199 albertel 391: url += 'mode=$mode&';
1.42 matthew 392: url += 'form=' + formname + '&';
1.135 albertel 393: if (titleelement != null) {
394: url += 'titleelement=' + titleelement + '&';
1.217 albertel 395: } else {
396: url += 'titleelement=&';
397: }
1.42 matthew 398: url += 'element=' + elementname + '';
399: var title = 'Search';
1.435 albertel 400: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 401: options += ',width=700,height=600';
402: editsearcher = open(url,title,options,'1');
403: editsearcher.focus();
404: }
1.219 albertel 405: // END LON-CAPA Internal -->
1.42 matthew 406: END
1.170 www 407: }
408:
409: sub lastresurl {
1.258 albertel 410: if ($env{'environment.lastresurl'}) {
411: return $env{'environment.lastresurl'}
1.170 www 412: } else {
413: return '/res';
414: }
415: }
416:
417: sub storeresurl {
418: my $resurl=&Apache::lonnet::clutter(shift);
419: unless ($resurl=~/^\/res/) { return 0; }
420: $resurl=~s/\/$//;
421: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 422: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 423: return 1;
1.42 matthew 424: }
425:
1.74 www 426: sub studentbrowser_javascript {
1.111 www 427: unless (
1.258 albertel 428: (($env{'request.course.id'}) &&
1.302 albertel 429: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
430: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
431: '/'.$env{'request.course.sec'})
432: ))
1.258 albertel 433: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 434: ) { return ''; }
1.74 www 435: return (<<'ENDSTDBRW');
1.776 bisitz 436: <script type="text/javascript" language="Javascript">
1.824 bisitz 437: // <![CDATA[
1.74 www 438: var stdeditbrowser;
1.999 www 439: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 440: var url = '/adm/pickstudent?';
441: var filter;
1.558 albertel 442: if (!ignorefilter) {
443: eval('filter=document.'+formname+'.'+uname+'.value;');
444: }
1.74 www 445: if (filter != null) {
446: if (filter != '') {
447: url += 'filter='+filter+'&';
448: }
449: }
450: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 451: '&udomelement='+udom+
452: '&clicker='+clicker;
1.111 www 453: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 454: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 455: var title = 'Student_Browser';
1.74 www 456: var options = 'scrollbars=1,resizable=1,menubar=0';
457: options += ',width=700,height=600';
458: stdeditbrowser = open(url,title,options,'1');
459: stdeditbrowser.focus();
460: }
1.824 bisitz 461: // ]]>
1.74 www 462: </script>
463: ENDSTDBRW
464: }
1.42 matthew 465:
1.1003 www 466: sub resourcebrowser_javascript {
467: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 468: return (<<'ENDRESBRW');
1.1003 www 469: <script type="text/javascript" language="Javascript">
470: // <![CDATA[
471: var reseditbrowser;
1.1004 www 472: function openresbrowser(formname,reslink) {
1.1005 www 473: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 474: var title = 'Resource_Browser';
475: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 476: options += ',width=700,height=500';
1.1004 www 477: reseditbrowser = open(url,title,options,'1');
478: reseditbrowser.focus();
1.1003 www 479: }
480: // ]]>
481: </script>
1.1004 www 482: ENDRESBRW
1.1003 www 483: }
484:
1.74 www 485: sub selectstudent_link {
1.999 www 486: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
487: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
488: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
489: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 490: if ($env{'request.course.id'}) {
1.302 albertel 491: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
492: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
493: '/'.$env{'request.course.sec'})) {
1.111 www 494: return '';
495: }
1.999 www 496: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 497: if ($courseadvonly) {
498: $callargs .= ",'',1,1";
499: }
500: return '<span class="LC_nobreak">'.
501: '<a href="javascript:openstdbrowser('.$callargs.');">'.
502: &mt('Select User').'</a></span>';
1.74 www 503: }
1.258 albertel 504: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 505: $callargs .= ",'',1";
1.793 raeburn 506: return '<span class="LC_nobreak">'.
507: '<a href="javascript:openstdbrowser('.$callargs.');">'.
508: &mt('Select User').'</a></span>';
1.111 www 509: }
510: return '';
1.91 www 511: }
512:
1.1004 www 513: sub selectresource_link {
514: my ($form,$reslink,$arg)=@_;
515:
516: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
517: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
518: unless ($env{'request.course.id'}) { return $arg; }
519: return '<span class="LC_nobreak">'.
520: '<a href="javascript:openresbrowser('.$callargs.');">'.
521: $arg.'</a></span>';
522: }
523:
524:
525:
1.653 raeburn 526: sub authorbrowser_javascript {
527: return <<"ENDAUTHORBRW";
1.776 bisitz 528: <script type="text/javascript" language="JavaScript">
1.824 bisitz 529: // <![CDATA[
1.653 raeburn 530: var stdeditbrowser;
531:
532: function openauthorbrowser(formname,udom) {
533: var url = '/adm/pickauthor?';
534: url += 'form='+formname+'&roledom='+udom;
535: var title = 'Author_Browser';
536: var options = 'scrollbars=1,resizable=1,menubar=0';
537: options += ',width=700,height=600';
538: stdeditbrowser = open(url,title,options,'1');
539: stdeditbrowser.focus();
540: }
541:
1.824 bisitz 542: // ]]>
1.653 raeburn 543: </script>
544: ENDAUTHORBRW
545: }
546:
1.91 www 547: sub coursebrowser_javascript {
1.1116 raeburn 548: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1221 raeburn 549: $credits_element,$instcode) = @_;
1.932 raeburn 550: my $wintitle = 'Course_Browser';
1.931 raeburn 551: if ($crstype eq 'Community') {
1.932 raeburn 552: $wintitle = 'Community_Browser';
1.909 raeburn 553: }
1.876 raeburn 554: my $id_functions = &javascript_index_functions();
555: my $output = '
1.776 bisitz 556: <script type="text/javascript" language="JavaScript">
1.824 bisitz 557: // <![CDATA[
1.468 raeburn 558: var stdeditbrowser;'."\n";
1.876 raeburn 559:
560: $output .= <<"ENDSTDBRW";
1.909 raeburn 561: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 562: var url = '/adm/pickcourse?';
1.895 raeburn 563: var formid = getFormIdByName(formname);
1.876 raeburn 564: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 565: if (domainfilter != null) {
566: if (domainfilter != '') {
567: url += 'domainfilter='+domainfilter+'&';
568: }
569: }
1.91 www 570: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 571: '&cdomelement='+udom+
572: '&cnameelement='+desc;
1.468 raeburn 573: if (extra_element !=null && extra_element != '') {
1.594 raeburn 574: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 575: url += '&roleelement='+extra_element;
576: if (domainfilter == null || domainfilter == '') {
577: url += '&domainfilter='+extra_element;
578: }
1.234 raeburn 579: }
1.468 raeburn 580: else {
581: if (formname == 'portform') {
582: url += '&setroles='+extra_element;
1.800 raeburn 583: } else {
584: if (formname == 'rules') {
585: url += '&fixeddom='+extra_element;
586: }
1.468 raeburn 587: }
588: }
1.230 raeburn 589: }
1.909 raeburn 590: if (type != null && type != '') {
591: url += '&type='+type;
592: }
593: if (type_elem != null && type_elem != '') {
594: url += '&typeelement='+type_elem;
595: }
1.872 raeburn 596: if (formname == 'ccrs') {
597: var ownername = document.forms[formid].ccuname.value;
598: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1238 raeburn 599: url += '&cloner='+ownername+':'+ownerdom;
600: if (type == 'Course') {
601: url += '&crscode='+document.forms[formid].crscode.value;
602: }
1.1221 raeburn 603: }
604: if (formname == 'requestcrs') {
605: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 606: }
1.293 raeburn 607: if (multflag !=null && multflag != '') {
608: url += '&multiple='+multflag;
609: }
1.909 raeburn 610: var title = '$wintitle';
1.91 www 611: var options = 'scrollbars=1,resizable=1,menubar=0';
612: options += ',width=700,height=600';
613: stdeditbrowser = open(url,title,options,'1');
614: stdeditbrowser.focus();
615: }
1.876 raeburn 616: $id_functions
617: ENDSTDBRW
1.1116 raeburn 618: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
619: $output .= &setsec_javascript($sec_element,$formname,$role_element,
620: $credits_element);
1.876 raeburn 621: }
622: $output .= '
623: // ]]>
624: </script>';
625: return $output;
626: }
627:
628: sub javascript_index_functions {
629: return <<"ENDJS";
630:
631: function getFormIdByName(formname) {
632: for (var i=0;i<document.forms.length;i++) {
633: if (document.forms[i].name == formname) {
634: return i;
635: }
636: }
637: return -1;
638: }
639:
640: function getIndexByName(formid,item) {
641: for (var i=0;i<document.forms[formid].elements.length;i++) {
642: if (document.forms[formid].elements[i].name == item) {
643: return i;
644: }
645: }
646: return -1;
647: }
1.468 raeburn 648:
1.876 raeburn 649: function getDomainFromSelectbox(formname,udom) {
650: var userdom;
651: var formid = getFormIdByName(formname);
652: if (formid > -1) {
653: var domid = getIndexByName(formid,udom);
654: if (domid > -1) {
655: if (document.forms[formid].elements[domid].type == 'select-one') {
656: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
657: }
658: if (document.forms[formid].elements[domid].type == 'hidden') {
659: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 660: }
661: }
662: }
1.876 raeburn 663: return userdom;
664: }
665:
666: ENDJS
1.468 raeburn 667:
1.876 raeburn 668: }
669:
1.1017 raeburn 670: sub javascript_array_indexof {
1.1018 raeburn 671: return <<ENDJS;
1.1017 raeburn 672: <script type="text/javascript" language="JavaScript">
673: // <![CDATA[
674:
675: if (!Array.prototype.indexOf) {
676: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
677: "use strict";
678: if (this === void 0 || this === null) {
679: throw new TypeError();
680: }
681: var t = Object(this);
682: var len = t.length >>> 0;
683: if (len === 0) {
684: return -1;
685: }
686: var n = 0;
687: if (arguments.length > 0) {
688: n = Number(arguments[1]);
1.1088 foxr 689: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 690: n = 0;
691: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
692: n = (n > 0 || -1) * Math.floor(Math.abs(n));
693: }
694: }
695: if (n >= len) {
696: return -1;
697: }
698: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
699: for (; k < len; k++) {
700: if (k in t && t[k] === searchElement) {
701: return k;
702: }
703: }
704: return -1;
705: }
706: }
707:
708: // ]]>
709: </script>
710:
711: ENDJS
712:
713: }
714:
1.876 raeburn 715: sub userbrowser_javascript {
716: my $id_functions = &javascript_index_functions();
717: return <<"ENDUSERBRW";
718:
1.888 raeburn 719: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 720: var url = '/adm/pickuser?';
721: var userdom = getDomainFromSelectbox(formname,udom);
722: if (userdom != null) {
723: if (userdom != '') {
724: url += 'srchdom='+userdom+'&';
725: }
726: }
727: url += 'form=' + formname + '&unameelement='+uname+
728: '&udomelement='+udom+
729: '&ulastelement='+ulast+
730: '&ufirstelement='+ufirst+
731: '&uemailelement='+uemail+
1.881 raeburn 732: '&hideudomelement='+hideudom+
733: '&coursedom='+crsdom;
1.888 raeburn 734: if ((caller != null) && (caller != undefined)) {
735: url += '&caller='+caller;
736: }
1.876 raeburn 737: var title = 'User_Browser';
738: var options = 'scrollbars=1,resizable=1,menubar=0';
739: options += ',width=700,height=600';
740: var stdeditbrowser = open(url,title,options,'1');
741: stdeditbrowser.focus();
742: }
743:
1.888 raeburn 744: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 745: var formid = getFormIdByName(formname);
746: if (formid > -1) {
1.888 raeburn 747: var unameid = getIndexByName(formid,uname);
1.876 raeburn 748: var domid = getIndexByName(formid,udom);
749: var hidedomid = getIndexByName(formid,origdom);
750: if (hidedomid > -1) {
751: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 752: var unameval = document.forms[formid].elements[unameid].value;
753: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
754: if (domid > -1) {
755: var slct = document.forms[formid].elements[domid];
756: if (slct.type == 'select-one') {
757: var i;
758: for (i=0;i<slct.length;i++) {
759: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
760: }
761: }
762: if (slct.type == 'hidden') {
763: slct.value = fixeddom;
1.876 raeburn 764: }
765: }
1.468 raeburn 766: }
767: }
768: }
1.876 raeburn 769: return;
770: }
771:
772: $id_functions
773: ENDUSERBRW
1.468 raeburn 774: }
775:
776: sub setsec_javascript {
1.1116 raeburn 777: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 778: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
779: $communityrolestr);
780: if ($role_element ne '') {
781: my @allroles = ('st','ta','ep','in','ad');
782: foreach my $crstype ('Course','Community') {
783: if ($crstype eq 'Community') {
784: foreach my $role (@allroles) {
785: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
786: }
787: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
788: } else {
789: foreach my $role (@allroles) {
790: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
791: }
792: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
793: }
794: }
795: $rolestr = '"'.join('","',@allroles).'"';
796: $courserolestr = '"'.join('","',@courserolenames).'"';
797: $communityrolestr = '"'.join('","',@communityrolenames).'"';
798: }
1.468 raeburn 799: my $setsections = qq|
800: function setSect(sectionlist) {
1.629 raeburn 801: var sectionsArray = new Array();
802: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
803: sectionsArray = sectionlist.split(",");
804: }
1.468 raeburn 805: var numSections = sectionsArray.length;
806: document.$formname.$sec_element.length = 0;
807: if (numSections == 0) {
808: document.$formname.$sec_element.multiple=false;
809: document.$formname.$sec_element.size=1;
810: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
811: } else {
812: if (numSections == 1) {
813: document.$formname.$sec_element.multiple=false;
814: document.$formname.$sec_element.size=1;
815: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
816: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
817: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
818: } else {
819: for (var i=0; i<numSections; i++) {
820: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
821: }
822: document.$formname.$sec_element.multiple=true
823: if (numSections < 3) {
824: document.$formname.$sec_element.size=numSections;
825: } else {
826: document.$formname.$sec_element.size=3;
827: }
828: document.$formname.$sec_element.options[0].selected = false
829: }
830: }
1.91 www 831: }
1.905 raeburn 832:
833: function setRole(crstype) {
1.468 raeburn 834: |;
1.905 raeburn 835: if ($role_element eq '') {
836: $setsections .= ' return;
837: }
838: ';
839: } else {
840: $setsections .= qq|
841: var elementLength = document.$formname.$role_element.length;
842: var allroles = Array($rolestr);
843: var courserolenames = Array($courserolestr);
844: var communityrolenames = Array($communityrolestr);
845: if (elementLength != undefined) {
846: if (document.$formname.$role_element.options[5].value == 'cc') {
847: if (crstype == 'Course') {
848: return;
849: } else {
850: allroles[5] = 'co';
851: for (var i=0; i<6; i++) {
852: document.$formname.$role_element.options[i].value = allroles[i];
853: document.$formname.$role_element.options[i].text = communityrolenames[i];
854: }
855: }
856: } else {
857: if (crstype == 'Community') {
858: return;
859: } else {
860: allroles[5] = 'cc';
861: for (var i=0; i<6; i++) {
862: document.$formname.$role_element.options[i].value = allroles[i];
863: document.$formname.$role_element.options[i].text = courserolenames[i];
864: }
865: }
866: }
867: }
868: return;
869: }
870: |;
871: }
1.1116 raeburn 872: if ($credits_element) {
873: $setsections .= qq|
874: function setCredits(defaultcredits) {
875: document.$formname.$credits_element.value = defaultcredits;
876: return;
877: }
878: |;
879: }
1.468 raeburn 880: return $setsections;
881: }
882:
1.91 www 883: sub selectcourse_link {
1.909 raeburn 884: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
885: $typeelement) = @_;
886: my $type = $selecttype;
1.871 raeburn 887: my $linktext = &mt('Select Course');
888: if ($selecttype eq 'Community') {
1.909 raeburn 889: $linktext = &mt('Select Community');
1.1239 raeburn 890: } elsif ($selecttype eq 'Placement') {
891: $linktext = &mt('Select Placement Test');
1.906 raeburn 892: } elsif ($selecttype eq 'Course/Community') {
893: $linktext = &mt('Select Course/Community');
1.909 raeburn 894: $type = '';
1.1019 raeburn 895: } elsif ($selecttype eq 'Select') {
896: $linktext = &mt('Select');
897: $type = '';
1.871 raeburn 898: }
1.787 bisitz 899: return '<span class="LC_nobreak">'
900: ."<a href='"
901: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
902: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 903: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 904: ."'>".$linktext.'</a>'
1.787 bisitz 905: .'</span>';
1.74 www 906: }
1.42 matthew 907:
1.653 raeburn 908: sub selectauthor_link {
909: my ($form,$udom)=@_;
910: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
911: &mt('Select Author').'</a>';
912: }
913:
1.876 raeburn 914: sub selectuser_link {
1.881 raeburn 915: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 916: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 917: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 918: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 919: ');">'.$linktext.'</a>';
1.876 raeburn 920: }
921:
1.273 raeburn 922: sub check_uncheck_jscript {
923: my $jscript = <<"ENDSCRT";
924: function checkAll(field) {
925: if (field.length > 0) {
926: for (i = 0; i < field.length; i++) {
1.1093 raeburn 927: if (!field[i].disabled) {
928: field[i].checked = true;
929: }
1.273 raeburn 930: }
931: } else {
1.1093 raeburn 932: if (!field.disabled) {
933: field.checked = true;
934: }
1.273 raeburn 935: }
936: }
937:
938: function uncheckAll(field) {
939: if (field.length > 0) {
940: for (i = 0; i < field.length; i++) {
941: field[i].checked = false ;
1.543 albertel 942: }
943: } else {
1.273 raeburn 944: field.checked = false ;
945: }
946: }
947: ENDSCRT
948: return $jscript;
949: }
950:
1.656 www 951: sub select_timezone {
1.1256 raeburn 952: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
953: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 954: if ($includeempty) {
955: $output .= '<option value=""';
956: if (($selected eq '') || ($selected eq 'local')) {
957: $output .= ' selected="selected" ';
958: }
959: $output .= '> </option>';
960: }
1.657 raeburn 961: my @timezones = DateTime::TimeZone->all_names;
962: foreach my $tzone (@timezones) {
963: $output.= '<option value="'.$tzone.'"';
964: if ($tzone eq $selected) {
965: $output.=' selected="selected"';
966: }
967: $output.=">$tzone</option>\n";
1.656 www 968: }
969: $output.="</select>";
970: return $output;
971: }
1.273 raeburn 972:
1.687 raeburn 973: sub select_datelocale {
1.1256 raeburn 974: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
975: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 976: if ($includeempty) {
977: $output .= '<option value=""';
978: if ($selected eq '') {
979: $output .= ' selected="selected" ';
980: }
981: $output .= '> </option>';
982: }
1.1241 raeburn 983: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 984: my (@possibles,%locale_names);
1.1241 raeburn 985: my @locales = DateTime::Locale->ids();
986: foreach my $id (@locales) {
987: if ($id ne '') {
988: my ($en_terr,$native_terr);
989: my $loc = DateTime::Locale->load($id);
990: if (ref($loc)) {
991: $en_terr = $loc->name();
992: $native_terr = $loc->native_name();
1.687 raeburn 993: if (grep(/^en$/,@languages) || !@languages) {
994: if ($en_terr ne '') {
995: $locale_names{$id} = '('.$en_terr.')';
996: } elsif ($native_terr ne '') {
997: $locale_names{$id} = $native_terr;
998: }
999: } else {
1000: if ($native_terr ne '') {
1001: $locale_names{$id} = $native_terr.' ';
1002: } elsif ($en_terr ne '') {
1003: $locale_names{$id} = '('.$en_terr.')';
1004: }
1005: }
1.1220 raeburn 1006: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1241 raeburn 1007: push(@possibles,$id);
1008: }
1.687 raeburn 1009: }
1010: }
1011: foreach my $item (sort(@possibles)) {
1012: $output.= '<option value="'.$item.'"';
1013: if ($item eq $selected) {
1014: $output.=' selected="selected"';
1015: }
1016: $output.=">$item";
1017: if ($locale_names{$item} ne '') {
1.1220 raeburn 1018: $output.=' '.$locale_names{$item};
1.687 raeburn 1019: }
1020: $output.="</option>\n";
1021: }
1022: $output.="</select>";
1023: return $output;
1024: }
1025:
1.792 raeburn 1026: sub select_language {
1.1256 raeburn 1027: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1028: my %langchoices;
1029: if ($includeempty) {
1.1117 raeburn 1030: %langchoices = ('' => 'No language preference');
1.792 raeburn 1031: }
1032: foreach my $id (&languageids()) {
1033: my $code = &supportedlanguagecode($id);
1034: if ($code) {
1035: $langchoices{$code} = &plainlanguagedescription($id);
1036: }
1037: }
1.1117 raeburn 1038: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1256 raeburn 1039: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1040: }
1041:
1.42 matthew 1042: =pod
1.36 matthew 1043:
1.1088 foxr 1044:
1045: =item * &list_languages()
1046:
1047: Returns an array reference that is suitable for use in language prompters.
1048: Each array element is itself a two element array. The first element
1049: is the language code. The second element a descsriptiuon of the
1050: language itself. This is suitable for use in e.g.
1051: &Apache::edit::select_arg (once dereferenced that is).
1052:
1053: =cut
1054:
1055: sub list_languages {
1056: my @lang_choices;
1057:
1058: foreach my $id (&languageids()) {
1059: my $code = &supportedlanguagecode($id);
1060: if ($code) {
1061: my $selector = $supported_codes{$id};
1062: my $description = &plainlanguagedescription($id);
1.1263 raeburn 1063: push(@lang_choices, [$selector, $description]);
1.1088 foxr 1064: }
1065: }
1066: return \@lang_choices;
1067: }
1068:
1069: =pod
1070:
1.648 raeburn 1071: =item * &linked_select_forms(...)
1.36 matthew 1072:
1073: linked_select_forms returns a string containing a <script></script> block
1074: and html for two <select> menus. The select menus will be linked in that
1075: changing the value of the first menu will result in new values being placed
1076: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1077: order unless a defined order is provided.
1.36 matthew 1078:
1079: linked_select_forms takes the following ordered inputs:
1080:
1081: =over 4
1082:
1.112 bowersj2 1083: =item * $formname, the name of the <form> tag
1.36 matthew 1084:
1.112 bowersj2 1085: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1086:
1.112 bowersj2 1087: =item * $firstdefault, the default value for the first menu
1.36 matthew 1088:
1.112 bowersj2 1089: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1090:
1.112 bowersj2 1091: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1092:
1.112 bowersj2 1093: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1094:
1.609 raeburn 1095: =item * $menuorder, the order of values in the first menu
1096:
1.1115 raeburn 1097: =item * $onchangefirst, additional javascript call to execute for an onchange
1098: event for the first <select> tag
1099:
1100: =item * $onchangesecond, additional javascript call to execute for an onchange
1101: event for the second <select> tag
1102:
1.1245 raeburn 1103: =item * $suffix, to differentiate separate uses of select2data javascript
1104: objects in a page.
1105:
1.41 ng 1106: =back
1107:
1.36 matthew 1108: Below is an example of such a hash. Only the 'text', 'default', and
1109: 'select2' keys must appear as stated. keys(%menu) are the possible
1110: values for the first select menu. The text that coincides with the
1.41 ng 1111: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1112: and text for the second menu are given in the hash pointed to by
1113: $menu{$choice1}->{'select2'}.
1114:
1.112 bowersj2 1115: my %menu = ( A1 => { text =>"Choice A1" ,
1116: default => "B3",
1117: select2 => {
1118: B1 => "Choice B1",
1119: B2 => "Choice B2",
1120: B3 => "Choice B3",
1121: B4 => "Choice B4"
1.609 raeburn 1122: },
1123: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1124: },
1125: A2 => { text =>"Choice A2" ,
1126: default => "C2",
1127: select2 => {
1128: C1 => "Choice C1",
1129: C2 => "Choice C2",
1130: C3 => "Choice C3"
1.609 raeburn 1131: },
1132: order => ['C2','C1','C3'],
1.112 bowersj2 1133: },
1134: A3 => { text =>"Choice A3" ,
1135: default => "D6",
1136: select2 => {
1137: D1 => "Choice D1",
1138: D2 => "Choice D2",
1139: D3 => "Choice D3",
1140: D4 => "Choice D4",
1141: D5 => "Choice D5",
1142: D6 => "Choice D6",
1143: D7 => "Choice D7"
1.609 raeburn 1144: },
1145: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1146: }
1147: );
1.36 matthew 1148:
1149: =cut
1150:
1151: sub linked_select_forms {
1152: my ($formname,
1153: $middletext,
1154: $firstdefault,
1155: $firstselectname,
1156: $secondselectname,
1.609 raeburn 1157: $hashref,
1158: $menuorder,
1.1115 raeburn 1159: $onchangefirst,
1.1245 raeburn 1160: $onchangesecond,
1161: $suffix
1.36 matthew 1162: ) = @_;
1163: my $second = "document.$formname.$secondselectname";
1164: my $first = "document.$formname.$firstselectname";
1165: # output the javascript to do the changing
1166: my $result = '';
1.776 bisitz 1167: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1168: $result.="// <![CDATA[\n";
1.1245 raeburn 1169: $result.="var select2data${suffix} = new Object();\n";
1.36 matthew 1170: $" = '","';
1171: my $debug = '';
1172: foreach my $s1 (sort(keys(%$hashref))) {
1.1245 raeburn 1173: $result.="select2data${suffix}['d_$s1'] = new Object();\n";
1174: $result.="select2data${suffix}['d_$s1'].def = new String('".
1.36 matthew 1175: $hashref->{$s1}->{'default'}."');\n";
1.1245 raeburn 1176: $result.="select2data${suffix}['d_$s1'].values = new Array(";
1.36 matthew 1177: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1178: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1179: @s2values = @{$hashref->{$s1}->{'order'}};
1180: }
1.36 matthew 1181: $result.="\"@s2values\");\n";
1.1245 raeburn 1182: $result.="select2data${suffix}['d_$s1'].texts = new Array(";
1.36 matthew 1183: my @s2texts;
1184: foreach my $value (@s2values) {
1.1263 raeburn 1185: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1186: }
1187: $result.="\"@s2texts\");\n";
1188: }
1189: $"=' ';
1190: $result.= <<"END";
1191:
1.1245 raeburn 1192: function select1${suffix}_changed() {
1.36 matthew 1193: // Determine new choice
1.1245 raeburn 1194: var newvalue = "d_" + $first.options[$first.selectedIndex].value;
1.36 matthew 1195: // update select2
1.1245 raeburn 1196: var values = select2data${suffix}[newvalue].values;
1197: var texts = select2data${suffix}[newvalue].texts;
1198: var select2def = select2data${suffix}[newvalue].def;
1.36 matthew 1199: var i;
1200: // out with the old
1.1245 raeburn 1201: $second.options.length = 0;
1202: // in with the new
1.36 matthew 1203: for (i=0;i<values.length; i++) {
1204: $second.options[i] = new Option(values[i]);
1.143 matthew 1205: $second.options[i].value = values[i];
1.36 matthew 1206: $second.options[i].text = texts[i];
1207: if (values[i] == select2def) {
1208: $second.options[i].selected = true;
1209: }
1210: }
1211: }
1.824 bisitz 1212: // ]]>
1.36 matthew 1213: </script>
1214: END
1215: # output the initial values for the selection lists
1.1245 raeburn 1216: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1${suffix}_changed();$onchangefirst\">\n";
1.609 raeburn 1217: my @order = sort(keys(%{$hashref}));
1218: if (ref($menuorder) eq 'ARRAY') {
1219: @order = @{$menuorder};
1220: }
1221: foreach my $value (@order) {
1.36 matthew 1222: $result.=" <option value=\"$value\" ";
1.253 albertel 1223: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1224: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1225: }
1226: $result .= "</select>\n";
1227: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1228: $result .= $middletext;
1.1115 raeburn 1229: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1230: if ($onchangesecond) {
1231: $result .= ' onchange="'.$onchangesecond.'"';
1232: }
1233: $result .= ">\n";
1.36 matthew 1234: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1235:
1236: my @secondorder = sort(keys(%select2));
1237: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1238: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1239: }
1240: foreach my $value (@secondorder) {
1.36 matthew 1241: $result.=" <option value=\"$value\" ";
1.253 albertel 1242: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1243: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1244: }
1245: $result .= "</select>\n";
1246: # return $debug;
1247: return $result;
1248: } # end of sub linked_select_forms {
1249:
1.45 matthew 1250: =pod
1.44 bowersj2 1251:
1.973 raeburn 1252: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1253:
1.112 bowersj2 1254: Returns a string corresponding to an HTML link to the given help
1255: $topic, where $topic corresponds to the name of a .tex file in
1256: /home/httpd/html/adm/help/tex, with underscores replaced by
1257: spaces.
1258:
1259: $text will optionally be linked to the same topic, allowing you to
1260: link text in addition to the graphic. If you do not want to link
1261: text, but wish to specify one of the later parameters, pass an
1262: empty string.
1263:
1264: $stayOnPage is a value that will be interpreted as a boolean. If true,
1265: the link will not open a new window. If false, the link will open
1266: a new window using Javascript. (Default is false.)
1267:
1268: $width and $height are optional numerical parameters that will
1269: override the width and height of the popped up window, which may
1.973 raeburn 1270: be useful for certain help topics with big pictures included.
1271:
1272: $imgid is the id of the img tag used for the help icon. This may be
1273: used in a javascript call to switch the image src. See
1274: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1275:
1276: =cut
1277:
1278: sub help_open_topic {
1.973 raeburn 1279: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1280: $text = "" if (not defined $text);
1.44 bowersj2 1281: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1282: $width = 500 if (not defined $width);
1.44 bowersj2 1283: $height = 400 if (not defined $height);
1284: my $filename = $topic;
1285: $filename =~ s/ /_/g;
1286:
1.48 bowersj2 1287: my $template = "";
1288: my $link;
1.572 banghart 1289:
1.159 www 1290: $topic=~s/\W/\_/g;
1.44 bowersj2 1291:
1.572 banghart 1292: if (!$stayOnPage) {
1.1033 www 1293: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1294: } elsif ($stayOnPage eq 'popup') {
1295: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 1296: } else {
1.48 bowersj2 1297: $link = "/adm/help/${filename}.hlp";
1298: }
1299:
1300: # Add the text
1.1314 raeburn 1301: my $target = ' target="_top"';
1302: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1303: $target = '';
1304: }
1.755 neumanie 1305: if ($text ne "") {
1.763 bisitz 1306: $template.='<span class="LC_help_open_topic">'
1.1314 raeburn 1307: .'<a'.$target.' href="'.$link.'">'
1.763 bisitz 1308: .$text.'</a>';
1.48 bowersj2 1309: }
1310:
1.763 bisitz 1311: # (Always) Add the graphic
1.179 matthew 1312: my $title = &mt('Online Help');
1.667 raeburn 1313: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1314: if ($imgid ne '') {
1315: $imgid = ' id="'.$imgid.'"';
1316: }
1.1314 raeburn 1317: $template.=' <a'.$target.' href="'.$link.'" title="'.$title.'">'
1.763 bisitz 1318: .'<img src="'.$helpicon.'" border="0"'
1319: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1320: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1321: .' /></a>';
1322: if ($text ne "") {
1323: $template.='</span>';
1324: }
1.44 bowersj2 1325: return $template;
1326:
1.106 bowersj2 1327: }
1328:
1329: # This is a quicky function for Latex cheatsheet editing, since it
1330: # appears in at least four places
1331: sub helpLatexCheatsheet {
1.1037 www 1332: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1333: my $out;
1.106 bowersj2 1334: my $addOther = '';
1.732 raeburn 1335: if ($topic) {
1.1037 www 1336: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1337: }
1338: $out = '<span>' # Start cheatsheet
1339: .$addOther
1340: .'<span>'
1.1037 www 1341: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1342: .'</span> <span>'
1.1037 www 1343: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1344: .'</span>';
1.732 raeburn 1345: unless ($not_author) {
1.1186 kruse 1346: $out .= '<span>'
1347: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1348: .'</span> <span>'
1349: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1350: .'</span>';
1.732 raeburn 1351: }
1.763 bisitz 1352: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1353: return $out;
1.172 www 1354: }
1355:
1.430 albertel 1356: sub general_help {
1357: my $helptopic='Student_Intro';
1358: if ($env{'request.role'}=~/^(ca|au)/) {
1359: $helptopic='Authoring_Intro';
1.907 raeburn 1360: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1361: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1362: } elsif ($env{'request.role'}=~/^dc/) {
1363: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1364: }
1365: return $helptopic;
1366: }
1367:
1368: sub update_help_link {
1369: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1370: my $origurl = $ENV{'REQUEST_URI'};
1371: $origurl=~s|^/~|/priv/|;
1372: my $timestamp = time;
1373: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1374: $$datum = &escape($$datum);
1375: }
1376:
1377: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1378: my $output .= <<"ENDOUTPUT";
1379: <script type="text/javascript">
1.824 bisitz 1380: // <![CDATA[
1.430 albertel 1381: banner_link = '$banner_link';
1.824 bisitz 1382: // ]]>
1.430 albertel 1383: </script>
1384: ENDOUTPUT
1385: return $output;
1386: }
1387:
1388: # now just updates the help link and generates a blue icon
1.193 raeburn 1389: sub help_open_menu {
1.430 albertel 1390: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1391: = @_;
1.949 droeschl 1392: $stayOnPage = 1;
1.430 albertel 1393: my $output;
1394: if ($component_help) {
1395: if (!$text) {
1396: $output=&help_open_topic($component_help,undef,$stayOnPage,
1397: $width,$height);
1398: } else {
1399: my $help_text;
1400: $help_text=&unescape($topic);
1401: $output='<table><tr><td>'.
1402: &help_open_topic($component_help,$help_text,$stayOnPage,
1403: $width,$height).'</td></tr></table>';
1404: }
1405: }
1406: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1407: return $output.$banner_link;
1408: }
1409:
1410: sub top_nav_help {
1411: my ($text) = @_;
1.436 albertel 1412: $text = &mt($text);
1.949 droeschl 1413: my $stay_on_page = 1;
1414:
1.1168 raeburn 1415: my ($link,$banner_link);
1416: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1417: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1418: : "javascript:helpMenu('open')";
1419: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1420: }
1.201 raeburn 1421: my $title = &mt('Get help');
1.1168 raeburn 1422: if ($link) {
1423: return <<"END";
1.436 albertel 1424: $banner_link
1.1159 raeburn 1425: <a href="$link" title="$title">$text</a>
1.436 albertel 1426: END
1.1168 raeburn 1427: } else {
1428: return ' '.$text.' ';
1429: }
1.436 albertel 1430: }
1431:
1432: sub help_menu_js {
1.1154 raeburn 1433: my ($httphost) = @_;
1.949 droeschl 1434: my $stayOnPage = 1;
1.436 albertel 1435: my $width = 620;
1436: my $height = 600;
1.430 albertel 1437: my $helptopic=&general_help();
1.1154 raeburn 1438: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1439: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1440: my $start_page =
1441: &Apache::loncommon::start_page('Help Menu', undef,
1442: {'frameset' => 1,
1443: 'js_ready' => 1,
1.1154 raeburn 1444: 'use_absolute' => $httphost,
1.331 albertel 1445: 'add_entries' => {
1.1168 raeburn 1446: 'border' => '0',
1.579 raeburn 1447: 'rows' => "110,*",},});
1.331 albertel 1448: my $end_page =
1449: &Apache::loncommon::end_page({'frameset' => 1,
1450: 'js_ready' => 1,});
1451:
1.436 albertel 1452: my $template .= <<"ENDTEMPLATE";
1453: <script type="text/javascript">
1.877 bisitz 1454: // <![CDATA[
1.253 albertel 1455: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1456: var banner_link = '';
1.243 raeburn 1457: function helpMenu(target) {
1458: var caller = this;
1459: if (target == 'open') {
1460: var newWindow = null;
1461: try {
1.262 albertel 1462: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1463: }
1464: catch(error) {
1465: writeHelp(caller);
1466: return;
1467: }
1468: if (newWindow) {
1469: caller = newWindow;
1470: }
1.193 raeburn 1471: }
1.243 raeburn 1472: writeHelp(caller);
1473: return;
1474: }
1475: function writeHelp(caller) {
1.1168 raeburn 1476: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1477: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1478: caller.document.close();
1479: caller.focus();
1.193 raeburn 1480: }
1.877 bisitz 1481: // END LON-CAPA Internal -->
1.253 albertel 1482: // ]]>
1.436 albertel 1483: </script>
1.193 raeburn 1484: ENDTEMPLATE
1485: return $template;
1486: }
1487:
1.172 www 1488: sub help_open_bug {
1489: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1490: unless ($env{'user.adv'}) { return ''; }
1.172 www 1491: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1492: $text = "" if (not defined $text);
1493: $stayOnPage=1;
1.184 albertel 1494: $width = 600 if (not defined $width);
1495: $height = 600 if (not defined $height);
1.172 www 1496:
1497: $topic=~s/\W+/\+/g;
1498: my $link='';
1499: my $template='';
1.379 albertel 1500: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1501: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1502: if (!$stayOnPage)
1503: {
1504: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1505: }
1506: else
1507: {
1508: $link = $url;
1509: }
1.1314 raeburn 1510:
1511: my $target = ' target="_top"';
1512: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1513: $target = '';
1514: }
1.172 www 1515: # Add the text
1516: if ($text ne "")
1517: {
1518: $template .=
1519: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.1314 raeburn 1520: "<td bgcolor='#FF5555'><a".$target." href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1521: }
1522:
1523: # Add the graphic
1.179 matthew 1524: my $title = &mt('Report a Bug');
1.215 albertel 1525: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1526: $template .= <<"ENDTEMPLATE";
1.1314 raeburn 1527: <a$target href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1528: ENDTEMPLATE
1529: if ($text ne '') { $template.='</td></tr></table>' };
1530: return $template;
1531:
1532: }
1533:
1534: sub help_open_faq {
1535: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1536: unless ($env{'user.adv'}) { return ''; }
1.172 www 1537: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1538: $text = "" if (not defined $text);
1539: $stayOnPage=1;
1540: $width = 350 if (not defined $width);
1541: $height = 400 if (not defined $height);
1542:
1543: $topic=~s/\W+/\+/g;
1544: my $link='';
1545: my $template='';
1546: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1547: if (!$stayOnPage)
1548: {
1549: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1550: }
1551: else
1552: {
1553: $link = $url;
1554: }
1555:
1556: # Add the text
1557: if ($text ne "")
1558: {
1559: $template .=
1.173 www 1560: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1561: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1562: }
1563:
1564: # Add the graphic
1.179 matthew 1565: my $title = &mt('View the FAQ');
1.215 albertel 1566: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1567: $template .= <<"ENDTEMPLATE";
1.436 albertel 1568: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1569: ENDTEMPLATE
1570: if ($text ne '') { $template.='</td></tr></table>' };
1571: return $template;
1572:
1.44 bowersj2 1573: }
1.37 matthew 1574:
1.180 matthew 1575: ###############################################################
1576: ###############################################################
1577:
1.45 matthew 1578: =pod
1579:
1.648 raeburn 1580: =item * &change_content_javascript():
1.256 matthew 1581:
1582: This and the next function allow you to create small sections of an
1583: otherwise static HTML page that you can update on the fly with
1584: Javascript, even in Netscape 4.
1585:
1586: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1587: must be written to the HTML page once. It will prove the Javascript
1588: function "change(name, content)". Calling the change function with the
1589: name of the section
1590: you want to update, matching the name passed to C<changable_area>, and
1591: the new content you want to put in there, will put the content into
1592: that area.
1593:
1594: B<Note>: Netscape 4 only reserves enough space for the changable area
1595: to contain room for the original contents. You need to "make space"
1596: for whatever changes you wish to make, and be B<sure> to check your
1597: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1598: it's adequate for updating a one-line status display, but little more.
1599: This script will set the space to 100% width, so you only need to
1600: worry about height in Netscape 4.
1601:
1602: Modern browsers are much less limiting, and if you can commit to the
1603: user not using Netscape 4, this feature may be used freely with
1604: pretty much any HTML.
1605:
1606: =cut
1607:
1608: sub change_content_javascript {
1609: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1610: if ($env{'browser.type'} eq 'netscape' &&
1611: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1612: return (<<NETSCAPE4);
1613: function change(name, content) {
1614: doc = document.layers[name+"___escape"].layers[0].document;
1615: doc.open();
1616: doc.write(content);
1617: doc.close();
1618: }
1619: NETSCAPE4
1620: } else {
1621: # Otherwise, we need to use semi-standards-compliant code
1622: # (technically, "innerHTML" isn't standard but the equivalent
1623: # is really scary, and every useful browser supports it
1624: return (<<DOMBASED);
1625: function change(name, content) {
1626: element = document.getElementById(name);
1627: element.innerHTML = content;
1628: }
1629: DOMBASED
1630: }
1631: }
1632:
1633: =pod
1634:
1.648 raeburn 1635: =item * &changable_area($name,$origContent):
1.256 matthew 1636:
1637: This provides a "changable area" that can be modified on the fly via
1638: the Javascript code provided in C<change_content_javascript>. $name is
1639: the name you will use to reference the area later; do not repeat the
1640: same name on a given HTML page more then once. $origContent is what
1641: the area will originally contain, which can be left blank.
1642:
1643: =cut
1644:
1645: sub changable_area {
1646: my ($name, $origContent) = @_;
1647:
1.258 albertel 1648: if ($env{'browser.type'} eq 'netscape' &&
1649: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1650: # If this is netscape 4, we need to use the Layer tag
1651: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1652: } else {
1653: return "<span id='$name'>$origContent</span>";
1654: }
1655: }
1656:
1657: =pod
1658:
1.648 raeburn 1659: =item * &viewport_geometry_js
1.590 raeburn 1660:
1661: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1662:
1663: =cut
1664:
1665:
1666: sub viewport_geometry_js {
1667: return <<"GEOMETRY";
1668: var Geometry = {};
1669: function init_geometry() {
1670: if (Geometry.init) { return };
1671: Geometry.init=1;
1672: if (window.innerHeight) {
1673: Geometry.getViewportHeight = function() { return window.innerHeight; };
1674: Geometry.getViewportWidth = function() { return window.innerWidth; };
1675: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1676: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1677: }
1678: else if (document.documentElement && document.documentElement.clientHeight) {
1679: Geometry.getViewportHeight =
1680: function() { return document.documentElement.clientHeight; };
1681: Geometry.getViewportWidth =
1682: function() { return document.documentElement.clientWidth; };
1683:
1684: Geometry.getHorizontalScroll =
1685: function() { return document.documentElement.scrollLeft; };
1686: Geometry.getVerticalScroll =
1687: function() { return document.documentElement.scrollTop; };
1688: }
1689: else if (document.body.clientHeight) {
1690: Geometry.getViewportHeight =
1691: function() { return document.body.clientHeight; };
1692: Geometry.getViewportWidth =
1693: function() { return document.body.clientWidth; };
1694: Geometry.getHorizontalScroll =
1695: function() { return document.body.scrollLeft; };
1696: Geometry.getVerticalScroll =
1697: function() { return document.body.scrollTop; };
1698: }
1699: }
1700:
1701: GEOMETRY
1702: }
1703:
1704: =pod
1705:
1.648 raeburn 1706: =item * &viewport_size_js()
1.590 raeburn 1707:
1708: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1709:
1710: =cut
1711:
1712: sub viewport_size_js {
1713: my $geometry = &viewport_geometry_js();
1714: return <<"DIMS";
1715:
1716: $geometry
1717:
1718: function getViewportDims(width,height) {
1719: init_geometry();
1720: width.value = Geometry.getViewportWidth();
1721: height.value = Geometry.getViewportHeight();
1722: return;
1723: }
1724:
1725: DIMS
1726: }
1727:
1728: =pod
1729:
1.648 raeburn 1730: =item * &resize_textarea_js()
1.565 albertel 1731:
1732: emits the needed javascript to resize a textarea to be as big as possible
1733:
1734: creates a function resize_textrea that takes two IDs first should be
1735: the id of the element to resize, second should be the id of a div that
1736: surrounds everything that comes after the textarea, this routine needs
1737: to be attached to the <body> for the onload and onresize events.
1738:
1.648 raeburn 1739: =back
1.565 albertel 1740:
1741: =cut
1742:
1743: sub resize_textarea_js {
1.590 raeburn 1744: my $geometry = &viewport_geometry_js();
1.565 albertel 1745: return <<"RESIZE";
1746: <script type="text/javascript">
1.824 bisitz 1747: // <![CDATA[
1.590 raeburn 1748: $geometry
1.565 albertel 1749:
1.588 albertel 1750: function getX(element) {
1751: var x = 0;
1752: while (element) {
1753: x += element.offsetLeft;
1754: element = element.offsetParent;
1755: }
1756: return x;
1757: }
1758: function getY(element) {
1759: var y = 0;
1760: while (element) {
1761: y += element.offsetTop;
1762: element = element.offsetParent;
1763: }
1764: return y;
1765: }
1766:
1767:
1.565 albertel 1768: function resize_textarea(textarea_id,bottom_id) {
1769: init_geometry();
1770: var textarea = document.getElementById(textarea_id);
1771: //alert(textarea);
1772:
1.588 albertel 1773: var textarea_top = getY(textarea);
1.565 albertel 1774: var textarea_height = textarea.offsetHeight;
1775: var bottom = document.getElementById(bottom_id);
1.588 albertel 1776: var bottom_top = getY(bottom);
1.565 albertel 1777: var bottom_height = bottom.offsetHeight;
1778: var window_height = Geometry.getViewportHeight();
1.588 albertel 1779: var fudge = 23;
1.565 albertel 1780: var new_height = window_height-fudge-textarea_top-bottom_height;
1781: if (new_height < 300) {
1782: new_height = 300;
1783: }
1784: textarea.style.height=new_height+'px';
1785: }
1.824 bisitz 1786: // ]]>
1.565 albertel 1787: </script>
1788: RESIZE
1789:
1790: }
1791:
1.1205 golterma 1792: sub colorfuleditor_js {
1.1248 raeburn 1793: my $browse_or_search;
1794: my $respath;
1795: my ($cnum,$cdom) = &crsauthor_url();
1796: if ($cnum) {
1797: $respath = "/res/$cdom/$cnum/";
1798: my %js_lt = &Apache::lonlocal::texthash(
1799: sunm => 'Sub-directory name',
1800: save => 'Save page to make this permanent',
1801: );
1802: &js_escape(\%js_lt);
1803: $browse_or_search = <<"END";
1804:
1805: function toggleChooser(form,element,titleid,only,search) {
1806: var disp = 'none';
1807: if (document.getElementById('chooser_'+element)) {
1808: var curr = document.getElementById('chooser_'+element).style.display;
1809: if (curr == 'none') {
1810: disp='inline';
1811: if (form.elements['chooser_'+element].length) {
1812: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1813: form.elements['chooser_'+element][i].checked = false;
1814: }
1815: }
1816: toggleResImport(form,element);
1817: }
1818: document.getElementById('chooser_'+element).style.display = disp;
1819: }
1820: }
1821:
1822: function toggleCrsFile(form,element,numdirs) {
1823: if (document.getElementById('chooser_'+element+'_crsres')) {
1824: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1825: if (curr == 'none') {
1826: if (numdirs) {
1827: form.elements['coursepath_'+element].selectedIndex = 0;
1828: if (numdirs > 1) {
1829: window['select1'+element+'_changed']();
1830: }
1831: }
1832: }
1833: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1834:
1835: }
1836: if (document.getElementById('chooser_'+element+'_upload')) {
1837: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1838: if (document.getElementById('uploadcrsres_'+element)) {
1839: document.getElementById('uploadcrsres_'+element).value = '';
1840: }
1841: }
1842: return;
1843: }
1844:
1845: function toggleCrsUpload(form,element,numcrsdirs) {
1846: if (document.getElementById('chooser_'+element+'_crsres')) {
1847: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1848: }
1849: if (document.getElementById('chooser_'+element+'_upload')) {
1850: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1851: if (curr == 'none') {
1852: if (numcrsdirs) {
1853: form.elements['crsauthorpath_'+element].selectedIndex = 0;
1854: form.elements['newsubdir_'+element][0].checked = true;
1855: toggleNewsubdir(form,element);
1856: }
1857: }
1858: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1859: }
1860: return;
1861: }
1862:
1863: function toggleResImport(form,element) {
1864: var choices = new Array('crsres','upload');
1865: for (var i=0; i<choices.length; i++) {
1866: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1867: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1868: }
1869: }
1870: }
1871:
1872: function toggleNewsubdir(form,element) {
1873: var newsub = form.elements['newsubdir_'+element];
1874: if (newsub) {
1875: if (newsub.length) {
1876: for (var j=0; j<newsub.length; j++) {
1877: if (newsub[j].checked) {
1878: if (document.getElementById('newsubdirname_'+element)) {
1879: if (newsub[j].value == '1') {
1880: document.getElementById('newsubdirname_'+element).type = "text";
1881: if (document.getElementById('newsubdir_'+element)) {
1882: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1883: }
1884: } else {
1885: document.getElementById('newsubdirname_'+element).type = "hidden";
1886: document.getElementById('newsubdirname_'+element).value = "";
1887: document.getElementById('newsubdir_'+element).innerHTML = "";
1888: }
1889: }
1890: break;
1891: }
1892: }
1893: }
1894: }
1895: }
1896:
1897: function updateCrsFile(form,element) {
1898: var directory = form.elements['coursepath_'+element];
1899: var filename = form.elements['coursefile_'+element];
1900: var path = directory.options[directory.selectedIndex].value;
1901: var file = filename.options[filename.selectedIndex].value;
1902: form.elements[element].value = '$respath';
1903: if (path == '/') {
1904: form.elements[element].value += file;
1905: } else {
1906: form.elements[element].value += path+'/'+file;
1907: }
1908: unClean();
1909: if (document.getElementById('previewimg_'+element)) {
1910: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1911: var newsrc = document.getElementById('previewimg_'+element).src;
1912: }
1913: if (document.getElementById('showimg_'+element)) {
1914: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
1915: }
1916: toggleChooser(form,element);
1917: return;
1918: }
1919:
1920: function uploadDone(suffix,name) {
1921: if (name) {
1922: document.forms["lonhomework"].elements[suffix].value = name;
1923: unClean();
1924: toggleChooser(document.forms["lonhomework"],suffix);
1925: }
1926: }
1927:
1928: \$(document).ready(function(){
1929:
1930: \$(document).delegate('form :submit', 'click', function( event ) {
1931: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
1932: var buttonId = this.id;
1933: var suffix = buttonId.toString();
1934: suffix = suffix.replace(/^crsupload_/,'');
1935: event.preventDefault();
1936: document.lonhomework.target = 'crsupload_target_'+suffix;
1937: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
1938: \$(this.form).submit();
1939: document.lonhomework.target = '';
1940: if (document.getElementById('crsuploadto_'+suffix)) {
1941: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
1942: }
1943: return false;
1944: }
1945: });
1946: });
1947: END
1948: }
1.1205 golterma 1949: return <<"COLORFULEDIT"
1950: <script type="text/javascript">
1951: // <![CDATA[>
1952: function fold_box(curDepth, lastresource){
1953:
1954: // we need a list because there can be several blocks you need to fold in one tag
1955: var block = document.getElementsByName('foldblock_'+curDepth);
1956: // but there is only one folding button per tag
1957: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1958:
1959: if(block.item(0).style.display == 'none'){
1960:
1961: foldbutton.value = '@{[&mt("Hide")]}';
1962: for (i = 0; i < block.length; i++){
1963: block.item(i).style.display = '';
1964: }
1965: }else{
1966:
1967: foldbutton.value = '@{[&mt("Show")]}';
1968: for (i = 0; i < block.length; i++){
1969: // block.item(i).style.visibility = 'collapse';
1970: block.item(i).style.display = 'none';
1971: }
1972: };
1973: saveState(lastresource);
1974: }
1975:
1976: function saveState (lastresource) {
1977:
1978: var tag_list = getTagList();
1979: if(tag_list != null){
1980: var timestamp = new Date().getTime();
1981: var key = lastresource;
1982:
1983: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1984: // starting with timestamp
1985: var value = timestamp+';';
1986:
1987: // building the list of key-value pairs
1988: for(var i = 0; i < tag_list.length; i++){
1989: value += tag_list[i]+',';
1990: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1991: }
1992:
1993: // only iterate whole storage if nothing to override
1994: if(localStorage.getItem(key) == null){
1995:
1996: // prevent storage from growing large
1997: if(localStorage.length > 50){
1998: var regex_getTimestamp = /^(?:\d)+;/;
1999: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
2000: var oldest_key;
2001:
2002: for(var i = 1; i < localStorage.length; i++){
2003: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
2004: oldest_key = localStorage.key(i);
2005: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
2006: }
2007: }
2008: localStorage.removeItem(oldest_key);
2009: }
2010: }
2011: localStorage.setItem(key,value);
2012: }
2013: }
2014:
2015: // restore folding status of blocks (on page load)
2016: function restoreState (lastresource) {
2017: if(localStorage.getItem(lastresource) != null){
2018: var key = lastresource;
2019: var value = localStorage.getItem(key);
2020: var regex_delTimestamp = /^\d+;/;
2021:
2022: value.replace(regex_delTimestamp, '');
2023:
2024: var valueArr = value.split(';');
2025: var pairs;
2026: var elements;
2027: for (var i = 0; i < valueArr.length; i++){
2028: pairs = valueArr[i].split(',');
2029: elements = document.getElementsByName(pairs[0]);
2030:
2031: for (var j = 0; j < elements.length; j++){
2032: elements[j].style.display = pairs[1];
2033: if (pairs[1] == "none"){
2034: var regex_id = /([_\\d]+)\$/;
2035: regex_id.exec(pairs[0]);
2036: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2037: }
2038: }
2039: }
2040: }
2041: }
2042:
2043: function getTagList () {
2044:
2045: var stringToSearch = document.lonhomework.innerHTML;
2046:
2047: var ret = new Array();
2048: var regex_findBlock = /(foldblock_.*?)"/g;
2049: var tag_list = stringToSearch.match(regex_findBlock);
2050:
2051: if(tag_list != null){
2052: for(var i = 0; i < tag_list.length; i++){
2053: ret.push(tag_list[i].replace(/"/, ''));
2054: }
2055: }
2056: return ret;
2057: }
2058:
2059: function saveScrollPosition (resource) {
2060: var tag_list = getTagList();
2061:
2062: // we dont always want to jump to the first block
2063: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2064: if(\$(window).scrollTop() > 170){
2065: if(tag_list != null){
2066: var result;
2067: for(var i = 0; i < tag_list.length; i++){
2068: if(isElementInViewport(tag_list[i])){
2069: result += tag_list[i]+';';
2070: }
2071: }
2072: sessionStorage.setItem('anchor_'+resource, result);
2073: }
2074: } else {
2075: // we dont need to save zero, just delete the item to leave everything tidy
2076: sessionStorage.removeItem('anchor_'+resource);
2077: }
2078: }
2079:
2080: function restoreScrollPosition(resource){
2081:
2082: var elem = sessionStorage.getItem('anchor_'+resource);
2083: if(elem != null){
2084: var tag_list = elem.split(';');
2085: var elem_list;
2086:
2087: for(var i = 0; i < tag_list.length; i++){
2088: elem_list = document.getElementsByName(tag_list[i]);
2089:
2090: if(elem_list.length > 0){
2091: elem = elem_list[0];
2092: break;
2093: }
2094: }
2095: elem.scrollIntoView();
2096: }
2097: }
2098:
2099: function isElementInViewport(el) {
2100:
2101: // change to last element instead of first
2102: var elem = document.getElementsByName(el);
2103: var rect = elem[0].getBoundingClientRect();
2104:
2105: return (
2106: rect.top >= 0 &&
2107: rect.left >= 0 &&
2108: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2109: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2110: );
2111: }
2112:
2113: function autosize(depth){
2114: var cmInst = window['cm'+depth];
2115: var fitsizeButton = document.getElementById('fitsize'+depth);
2116:
2117: // is fixed size, switching to dynamic
2118: if (sessionStorage.getItem("autosized_"+depth) == null) {
2119: cmInst.setSize("","auto");
2120: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2121: sessionStorage.setItem("autosized_"+depth, "yes");
2122:
2123: // is dynamic size, switching to fixed
2124: } else {
2125: cmInst.setSize("","300px");
2126: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2127: sessionStorage.removeItem("autosized_"+depth);
2128: }
2129: }
2130:
1.1248 raeburn 2131: $browse_or_search
1.1205 golterma 2132:
2133: // ]]>
2134: </script>
2135: COLORFULEDIT
2136: }
2137:
2138: sub xmleditor_js {
2139: return <<XMLEDIT
2140: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2141: <script type="text/javascript">
2142: // <![CDATA[>
2143:
2144: function saveScrollPosition (resource) {
2145:
2146: var scrollPos = \$(window).scrollTop();
2147: sessionStorage.setItem(resource,scrollPos);
2148: }
2149:
2150: function restoreScrollPosition(resource){
2151:
2152: var scrollPos = sessionStorage.getItem(resource);
2153: \$(window).scrollTop(scrollPos);
2154: }
2155:
2156: // unless internet explorer
2157: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2158:
2159: \$(document).ready(function() {
2160: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2161: });
2162: }
2163:
2164: // inserts text at cursor position into codemirror (xml editor only)
2165: function insertText(text){
2166: cm.focus();
2167: var curPos = cm.getCursor();
2168: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2169: }
2170: // ]]>
2171: </script>
2172: XMLEDIT
2173: }
2174:
2175: sub insert_folding_button {
2176: my $curDepth = $Apache::lonxml::curdepth;
2177: my $lastresource = $env{'request.ambiguous'};
2178:
2179: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2180: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2181: }
2182:
1.1248 raeburn 2183: sub crsauthor_url {
2184: my ($url) = @_;
2185: if ($url eq '') {
2186: $url = $ENV{'REQUEST_URI'};
2187: }
2188: my ($cnum,$cdom);
2189: if ($env{'request.course.id'}) {
2190: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2191: if ($audom ne '' && $auname ne '') {
2192: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2193: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2194: $cnum = $auname;
2195: $cdom = $audom;
2196: }
2197: }
2198: }
2199: return ($cnum,$cdom);
2200: }
2201:
2202: sub import_crsauthor_form {
1.1265 raeburn 2203: my ($form,$firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2204: return (0) unless ($env{'request.course.id'});
2205: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2206: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2207: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2208: return (0) unless (($cnum ne '') && ($cdom ne ''));
2209: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
2210: my @ids=&Apache::lonnet::current_machine_ids();
2211: my ($output,$is_home,$relpath,%subdirs,%files,%selimport_menus);
2212:
2213: if (grep(/^\Q$crshome\E$/,@ids)) {
2214: $is_home = 1;
2215: }
2216: $relpath = "/priv/$cdom/$cnum";
2217: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$relpath,'',\%subdirs,\%files);
2218: my %lt = &Apache::lonlocal::texthash (
2219: fnam => 'Filename',
2220: dire => 'Directory',
2221: );
2222: my $numdirs = scalar(keys(%files));
2223: my (%possexts,$singledir,@singledirfiles);
2224: if ($only) {
2225: map { $possexts{$_} = 1; } split(/\s*,\s*/,$only);
2226: }
2227: my (%nonemptydirs,$possdirs);
2228: if ($numdirs > 1) {
2229: my @order;
2230: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
2231: if (ref($files{$key}) eq 'HASH') {
2232: my $shown = $key;
2233: if ($key eq '') {
2234: $shown = '/';
2235: }
2236: my @ordered = ();
2237: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$key}}))) {
1.1315 raeburn 2238: next if ($file =~ /\.rights$/);
1.1248 raeburn 2239: if ($only) {
2240: my ($ext) = ($file =~ /\.([^.]+)$/);
2241: unless ($possexts{lc($ext)}) {
2242: next;
2243: }
2244: }
2245: $selimport_menus{$key}->{'select2'}->{$file} = $file;
2246: push(@ordered,$file);
2247: }
2248: if (@ordered) {
2249: push(@order,$key);
2250: $nonemptydirs{$key} = 1;
2251: $selimport_menus{$key}->{'text'} = $shown;
2252: $selimport_menus{$key}->{'default'} = '';
2253: $selimport_menus{$key}->{'select2'}->{''} = '';
2254: $selimport_menus{$key}->{'order'} = \@ordered;
2255: }
2256: }
2257: }
2258: $possdirs = scalar(keys(%nonemptydirs));
2259: if ($possdirs > 1) {
2260: my @order = sort { lc($a) cmp lc($b) } (keys(%nonemptydirs));
2261: $output = $lt{'dire'}.
2262: &linked_select_forms($form,'<br />'.
2263: $lt{'fnam'},'',
2264: $firstselectname,$secondselectname,
2265: \%selimport_menus,\@order,
2266: $onchangefirst,'',$suffix).'<br />';
2267: } elsif ($possdirs == 1) {
2268: $singledir = (keys(%nonemptydirs))[0];
2269: if (ref($selimport_menus{$singledir}->{'order'}) eq 'ARRAY') {
2270: @singledirfiles = @{$selimport_menus{$singledir}->{'order'}};
2271: }
2272: delete($selimport_menus{$singledir});
2273: }
2274: } elsif ($numdirs == 1) {
2275: $singledir = (keys(%files))[0];
2276: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$singledir}}))) {
2277: if ($only) {
2278: my ($ext) = ($file =~ /\.([^.]+)$/);
2279: unless ($possexts{lc($ext)}) {
2280: next;
2281: }
1.1315 raeburn 2282: } else {
2283: next if ($file =~ /\.rights$/);
1.1248 raeburn 2284: }
2285: push(@singledirfiles,$file);
2286: }
2287: if (@singledirfiles) {
1.1315 raeburn 2288: $possdirs = 1;
1.1248 raeburn 2289: }
2290: }
2291: if (($possdirs == 1) && (@singledirfiles)) {
2292: my $showdir = $singledir;
2293: if ($singledir eq '') {
2294: $showdir = '/';
2295: }
2296: $output = $lt{'dire'}.
2297: '<select name="'.$firstselectname.'">'.
2298: '<option value="'.$singledir.'">'.$showdir.'</option>'."\n".
2299: '</select><br />'.
2300: $lt{'fnam'}.'<select name="'.$secondselectname.'">'."\n".
2301: '<option value="" selected="selected">'.$lt{'se'}.'</option>'."\n";
2302: foreach my $file (@singledirfiles) {
2303: $output .= '<option value="'.$file.'">'.$file.'</option>'."\n";
2304: }
2305: $output .= '</select><br />'."\n";
2306: }
2307: return ($possdirs,$output);
2308: }
2309:
1.565 albertel 2310: =pod
2311:
1.256 matthew 2312: =head1 Excel and CSV file utility routines
2313:
2314: =cut
2315:
2316: ###############################################################
2317: ###############################################################
2318:
2319: =pod
2320:
1.1162 raeburn 2321: =over 4
2322:
1.648 raeburn 2323: =item * &csv_translate($text)
1.37 matthew 2324:
1.185 www 2325: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2326: format.
2327:
2328: =cut
2329:
1.180 matthew 2330: ###############################################################
2331: ###############################################################
1.37 matthew 2332: sub csv_translate {
2333: my $text = shift;
2334: $text =~ s/\"/\"\"/g;
1.209 albertel 2335: $text =~ s/\n/ /g;
1.37 matthew 2336: return $text;
2337: }
1.180 matthew 2338:
2339: ###############################################################
2340: ###############################################################
2341:
2342: =pod
2343:
1.648 raeburn 2344: =item * &define_excel_formats()
1.180 matthew 2345:
2346: Define some commonly used Excel cell formats.
2347:
2348: Currently supported formats:
2349:
2350: =over 4
2351:
2352: =item header
2353:
2354: =item bold
2355:
2356: =item h1
2357:
2358: =item h2
2359:
2360: =item h3
2361:
1.256 matthew 2362: =item h4
2363:
2364: =item i
2365:
1.180 matthew 2366: =item date
2367:
2368: =back
2369:
2370: Inputs: $workbook
2371:
2372: Returns: $format, a hash reference.
2373:
1.1057 foxr 2374:
1.180 matthew 2375: =cut
2376:
2377: ###############################################################
2378: ###############################################################
2379: sub define_excel_formats {
2380: my ($workbook) = @_;
2381: my $format;
2382: $format->{'header'} = $workbook->add_format(bold => 1,
2383: bottom => 1,
2384: align => 'center');
2385: $format->{'bold'} = $workbook->add_format(bold=>1);
2386: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2387: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2388: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2389: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2390: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2391: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2392: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2393: return $format;
2394: }
2395:
2396: ###############################################################
2397: ###############################################################
1.113 bowersj2 2398:
2399: =pod
2400:
1.648 raeburn 2401: =item * &create_workbook()
1.255 matthew 2402:
2403: Create an Excel worksheet. If it fails, output message on the
2404: request object and return undefs.
2405:
2406: Inputs: Apache request object
2407:
2408: Returns (undef) on failure,
2409: Excel worksheet object, scalar with filename, and formats
2410: from &Apache::loncommon::define_excel_formats on success
2411:
2412: =cut
2413:
2414: ###############################################################
2415: ###############################################################
2416: sub create_workbook {
2417: my ($r) = @_;
2418: #
2419: # Create the excel spreadsheet
2420: my $filename = '/prtspool/'.
1.258 albertel 2421: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2422: time.'_'.rand(1000000000).'.xls';
2423: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2424: if (! defined($workbook)) {
2425: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2426: $r->print(
2427: '<p class="LC_error">'
2428: .&mt('Problems occurred in creating the new Excel file.')
2429: .' '.&mt('This error has been logged.')
2430: .' '.&mt('Please alert your LON-CAPA administrator.')
2431: .'</p>'
2432: );
1.255 matthew 2433: return (undef);
2434: }
2435: #
1.1014 foxr 2436: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2437: #
2438: my $format = &Apache::loncommon::define_excel_formats($workbook);
2439: return ($workbook,$filename,$format);
2440: }
2441:
2442: ###############################################################
2443: ###############################################################
2444:
2445: =pod
2446:
1.648 raeburn 2447: =item * &create_text_file()
1.113 bowersj2 2448:
1.542 raeburn 2449: Create a file to write to and eventually make available to the user.
1.256 matthew 2450: If file creation fails, outputs an error message on the request object and
2451: return undefs.
1.113 bowersj2 2452:
1.256 matthew 2453: Inputs: Apache request object, and file suffix
1.113 bowersj2 2454:
1.256 matthew 2455: Returns (undef) on failure,
2456: Filehandle and filename on success.
1.113 bowersj2 2457:
2458: =cut
2459:
1.256 matthew 2460: ###############################################################
2461: ###############################################################
2462: sub create_text_file {
2463: my ($r,$suffix) = @_;
2464: if (! defined($suffix)) { $suffix = 'txt'; };
2465: my $fh;
2466: my $filename = '/prtspool/'.
1.258 albertel 2467: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2468: time.'_'.rand(1000000000).'.'.$suffix;
2469: $fh = Apache::File->new('>/home/httpd'.$filename);
2470: if (! defined($fh)) {
2471: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2472: $r->print(
2473: '<p class="LC_error">'
2474: .&mt('Problems occurred in creating the output file.')
2475: .' '.&mt('This error has been logged.')
2476: .' '.&mt('Please alert your LON-CAPA administrator.')
2477: .'</p>'
2478: );
1.113 bowersj2 2479: }
1.256 matthew 2480: return ($fh,$filename)
1.113 bowersj2 2481: }
2482:
2483:
1.256 matthew 2484: =pod
1.113 bowersj2 2485:
2486: =back
2487:
2488: =cut
1.37 matthew 2489:
2490: ###############################################################
1.33 matthew 2491: ## Home server <option> list generating code ##
2492: ###############################################################
1.35 matthew 2493:
1.169 www 2494: # ------------------------------------------
2495:
2496: sub domain_select {
1.1289 raeburn 2497: my ($name,$value,$multiple,$incdoms,$excdoms)=@_;
2498: my @possdoms;
2499: if (ref($incdoms) eq 'ARRAY') {
2500: @possdoms = @{$incdoms};
2501: } else {
2502: @possdoms = &Apache::lonnet::all_domains();
2503: }
2504:
1.169 www 2505: my %domains=map {
1.514 albertel 2506: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.1289 raeburn 2507: } @possdoms;
2508:
2509: if ((ref($excdoms) eq 'ARRAY') && (@{$excdoms} > 0)) {
2510: foreach my $dom (@{$excdoms}) {
2511: delete($domains{$dom});
2512: }
2513: }
2514:
1.169 www 2515: if ($multiple) {
2516: $domains{''}=&mt('Any domain');
1.550 albertel 2517: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2518: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2519: } else {
1.550 albertel 2520: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2521: return &select_form($name,$value,\%domains);
1.169 www 2522: }
2523: }
2524:
1.282 albertel 2525: #-------------------------------------------
2526:
2527: =pod
2528:
1.519 raeburn 2529: =head1 Routines for form select boxes
2530:
2531: =over 4
2532:
1.648 raeburn 2533: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2534:
2535: Returns a string containing a <select> element int multiple mode
2536:
2537:
2538: Args:
2539: $name - name of the <select> element
1.506 raeburn 2540: $value - scalar or array ref of values that should already be selected
1.282 albertel 2541: $size - number of rows long the select element is
1.283 albertel 2542: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2543: (shown text should already have been &mt())
1.506 raeburn 2544: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2545:
1.282 albertel 2546: =cut
2547:
2548: #-------------------------------------------
1.169 www 2549: sub multiple_select_form {
1.284 albertel 2550: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2551: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2552: my $output='';
1.191 matthew 2553: if (! defined($size)) {
2554: $size = 4;
1.283 albertel 2555: if (scalar(keys(%$hash))<4) {
2556: $size = scalar(keys(%$hash));
1.191 matthew 2557: }
2558: }
1.734 bisitz 2559: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2560: my @order;
1.506 raeburn 2561: if (ref($order) eq 'ARRAY') {
2562: @order = @{$order};
2563: } else {
2564: @order = sort(keys(%$hash));
1.501 banghart 2565: }
2566: if (exists($$hash{'select_form_order'})) {
2567: @order = @{$$hash{'select_form_order'}};
2568: }
2569:
1.284 albertel 2570: foreach my $key (@order) {
1.356 albertel 2571: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2572: $output.='selected="selected" ' if ($selected{$key});
2573: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2574: }
2575: $output.="</select>\n";
2576: return $output;
2577: }
2578:
1.88 www 2579: #-------------------------------------------
2580:
2581: =pod
2582:
1.1254 raeburn 2583: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2584:
2585: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2586: allow a user to select options from a ref to a hash containing:
2587: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2588: a javascript onchange item, e.g., onchange="this.form.submit();".
2589: An optional arg -- $readonly -- if true will cause the select form
2590: to be disabled, e.g., for the case where an instructor has a section-
2591: specific role, and is viewing/modifying parameters.
1.970 raeburn 2592:
1.88 www 2593: See lonrights.pm for an example invocation and use.
2594:
2595: =cut
2596:
2597: #-------------------------------------------
2598: sub select_form {
1.1228 raeburn 2599: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2600: return unless (ref($hashref) eq 'HASH');
2601: if ($onchange) {
2602: $onchange = ' onchange="'.$onchange.'"';
2603: }
1.1228 raeburn 2604: my $disabled;
2605: if ($readonly) {
2606: $disabled = ' disabled="disabled"';
2607: }
2608: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2609: my @keys;
1.970 raeburn 2610: if (exists($hashref->{'select_form_order'})) {
2611: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2612: } else {
1.970 raeburn 2613: @keys=sort(keys(%{$hashref}));
1.128 albertel 2614: }
1.356 albertel 2615: foreach my $key (@keys) {
2616: $selectform.=
2617: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2618: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2619: ">".$hashref->{$key}."</option>\n";
1.88 www 2620: }
2621: $selectform.="</select>";
2622: return $selectform;
2623: }
2624:
1.475 www 2625: # For display filters
2626:
2627: sub display_filter {
1.1074 raeburn 2628: my ($context) = @_;
1.475 www 2629: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2630: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2631: my $phraseinput = 'hidden';
2632: my $includeinput = 'hidden';
2633: my ($checked,$includetypestext);
2634: if ($env{'form.displayfilter'} eq 'containing') {
2635: $phraseinput = 'text';
2636: if ($context eq 'parmslog') {
2637: $includeinput = 'checkbox';
2638: if ($env{'form.includetypes'}) {
2639: $checked = ' checked="checked"';
2640: }
2641: $includetypestext = &mt('Include parameter types');
2642: }
2643: } else {
2644: $includetypestext = ' ';
2645: }
2646: my ($additional,$secondid,$thirdid);
2647: if ($context eq 'parmslog') {
2648: $additional =
2649: '<label><input type="'.$includeinput.'" name="includetypes"'.
2650: $checked.' name="includetypes" value="1" id="includetypes" />'.
2651: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2652: '</label>';
2653: $secondid = 'includetypes';
2654: $thirdid = 'includetypestext';
2655: }
2656: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2657: '$secondid','$thirdid')";
2658: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2659: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2660: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2661: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2662: &mt('Filter: [_1]',
1.477 www 2663: &select_form($env{'form.displayfilter'},
2664: 'displayfilter',
1.970 raeburn 2665: {'currentfolder' => 'Current folder/page',
1.477 www 2666: 'containing' => 'Containing phrase',
1.1074 raeburn 2667: 'none' => 'None'},$onchange)).' '.
2668: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2669: &HTML::Entities::encode($env{'form.containingphrase'}).
2670: '" />'.$additional;
2671: }
2672:
2673: sub display_filter_js {
2674: my $includetext = &mt('Include parameter types');
2675: return <<"ENDJS";
2676:
2677: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2678: var firstType = 'hidden';
2679: if (setter.options[setter.selectedIndex].value == 'containing') {
2680: firstType = 'text';
2681: }
2682: firstObject = document.getElementById(firstid);
2683: if (typeof(firstObject) == 'object') {
2684: if (firstObject.type != firstType) {
2685: changeInputType(firstObject,firstType);
2686: }
2687: }
2688: if (context == 'parmslog') {
2689: var secondType = 'hidden';
2690: if (firstType == 'text') {
2691: secondType = 'checkbox';
2692: }
2693: secondObject = document.getElementById(secondid);
2694: if (typeof(secondObject) == 'object') {
2695: if (secondObject.type != secondType) {
2696: changeInputType(secondObject,secondType);
2697: }
2698: }
2699: var textItem = document.getElementById(thirdid);
2700: var currtext = textItem.innerHTML;
2701: var newtext;
2702: if (firstType == 'text') {
2703: newtext = '$includetext';
2704: } else {
2705: newtext = ' ';
2706: }
2707: if (currtext != newtext) {
2708: textItem.innerHTML = newtext;
2709: }
2710: }
2711: return;
2712: }
2713:
2714: function changeInputType(oldObject,newType) {
2715: var newObject = document.createElement('input');
2716: newObject.type = newType;
2717: if (oldObject.size) {
2718: newObject.size = oldObject.size;
2719: }
2720: if (oldObject.value) {
2721: newObject.value = oldObject.value;
2722: }
2723: if (oldObject.name) {
2724: newObject.name = oldObject.name;
2725: }
2726: if (oldObject.id) {
2727: newObject.id = oldObject.id;
2728: }
2729: oldObject.parentNode.replaceChild(newObject,oldObject);
2730: return;
2731: }
2732:
2733: ENDJS
1.475 www 2734: }
2735:
1.167 www 2736: sub gradeleveldescription {
2737: my $gradelevel=shift;
2738: my %gradelevels=(0 => 'Not specified',
2739: 1 => 'Grade 1',
2740: 2 => 'Grade 2',
2741: 3 => 'Grade 3',
2742: 4 => 'Grade 4',
2743: 5 => 'Grade 5',
2744: 6 => 'Grade 6',
2745: 7 => 'Grade 7',
2746: 8 => 'Grade 8',
2747: 9 => 'Grade 9',
2748: 10 => 'Grade 10',
2749: 11 => 'Grade 11',
2750: 12 => 'Grade 12',
2751: 13 => 'Grade 13',
2752: 14 => '100 Level',
2753: 15 => '200 Level',
2754: 16 => '300 Level',
2755: 17 => '400 Level',
2756: 18 => 'Graduate Level');
2757: return &mt($gradelevels{$gradelevel});
2758: }
2759:
1.163 www 2760: sub select_level_form {
2761: my ($deflevel,$name)=@_;
2762: unless ($deflevel) { $deflevel=0; }
1.167 www 2763: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2764: for (my $i=0; $i<=18; $i++) {
2765: $selectform.="<option value=\"$i\" ".
1.253 albertel 2766: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2767: ">".&gradeleveldescription($i)."</option>\n";
2768: }
2769: $selectform.="</select>";
2770: return $selectform;
1.163 www 2771: }
1.167 www 2772:
1.35 matthew 2773: #-------------------------------------------
2774:
1.45 matthew 2775: =pod
2776:
1.1256 raeburn 2777: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2778:
2779: Returns a string containing a <select name='$name' size='1'> form to
2780: allow a user to select the domain to preform an operation in.
2781: See loncreateuser.pm for an example invocation and use.
2782:
1.90 www 2783: If the $includeempty flag is set, it also includes an empty choice ("no domain
2784: selected");
2785:
1.743 raeburn 2786: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2787:
1.910 raeburn 2788: The optional $onchange argument specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
2789:
1.1121 raeburn 2790: The optional $incdoms is a reference to an array of domains which will be the only available options.
2791:
2792: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2793:
1.1256 raeburn 2794: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
2795:
1.35 matthew 2796: =cut
2797:
2798: #-------------------------------------------
1.34 matthew 2799: sub select_dom_form {
1.1256 raeburn 2800: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2801: if ($onchange) {
1.874 raeburn 2802: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2803: }
1.1256 raeburn 2804: if ($disabled) {
2805: $disabled = ' disabled="disabled"';
2806: }
1.1121 raeburn 2807: my (@domains,%exclude);
1.910 raeburn 2808: if (ref($incdoms) eq 'ARRAY') {
2809: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2810: } else {
2811: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2812: }
1.90 www 2813: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2814: if (ref($excdoms) eq 'ARRAY') {
2815: map { $exclude{$_} = 1; } @{$excdoms};
2816: }
1.1256 raeburn 2817: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2818: foreach my $dom (@domains) {
1.1121 raeburn 2819: next if ($exclude{$dom});
1.356 albertel 2820: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2821: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2822: if ($showdomdesc) {
2823: if ($dom ne '') {
2824: my $domdesc = &Apache::lonnet::domain($dom,'description');
2825: if ($domdesc ne '') {
2826: $selectdomain .= ' ('.$domdesc.')';
2827: }
2828: }
2829: }
2830: $selectdomain .= "</option>\n";
1.34 matthew 2831: }
2832: $selectdomain.="</select>";
2833: return $selectdomain;
2834: }
2835:
1.35 matthew 2836: #-------------------------------------------
2837:
1.45 matthew 2838: =pod
2839:
1.648 raeburn 2840: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2841:
1.586 raeburn 2842: input: 4 arguments (two required, two optional) -
2843: $domain - domain of new user
2844: $name - name of form element
2845: $default - Value of 'default' causes a default item to be first
2846: option, and selected by default.
2847: $hide - Value of 'hide' causes hiding of the name of the server,
2848: if 1 server found, or default, if 0 found.
1.594 raeburn 2849: output: returns 2 items:
1.586 raeburn 2850: (a) form element which contains either:
2851: (i) <select name="$name">
2852: <option value="$hostid1">$hostid $servers{$hostid}</option>
2853: <option value="$hostid2">$hostid $servers{$hostid}</option>
2854: </select>
2855: form item if there are multiple library servers in $domain, or
2856: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2857: if there is only one library server in $domain.
2858:
2859: (b) number of library servers found.
2860:
2861: See loncreateuser.pm for example of use.
1.35 matthew 2862:
2863: =cut
2864:
2865: #-------------------------------------------
1.586 raeburn 2866: sub home_server_form_item {
2867: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2868: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2869: my $result;
2870: my $numlib = keys(%servers);
2871: if ($numlib > 1) {
2872: $result .= '<select name="'.$name.'" />'."\n";
2873: if ($default) {
1.804 bisitz 2874: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2875: '</option>'."\n";
2876: }
2877: foreach my $hostid (sort(keys(%servers))) {
2878: $result.= '<option value="'.$hostid.'">'.
2879: $hostid.' '.$servers{$hostid}."</option>\n";
2880: }
2881: $result .= '</select>'."\n";
2882: } elsif ($numlib == 1) {
2883: my $hostid;
2884: foreach my $item (keys(%servers)) {
2885: $hostid = $item;
2886: }
2887: $result .= '<input type="hidden" name="'.$name.'" value="'.
2888: $hostid.'" />';
2889: if (!$hide) {
2890: $result .= $hostid.' '.$servers{$hostid};
2891: }
2892: $result .= "\n";
2893: } elsif ($default) {
2894: $result .= '<input type="hidden" name="'.$name.
2895: '" value="default" />';
2896: if (!$hide) {
2897: $result .= &mt('default');
2898: }
2899: $result .= "\n";
1.33 matthew 2900: }
1.586 raeburn 2901: return ($result,$numlib);
1.33 matthew 2902: }
1.112 bowersj2 2903:
2904: =pod
2905:
1.534 albertel 2906: =back
2907:
1.112 bowersj2 2908: =cut
1.87 matthew 2909:
2910: ###############################################################
1.112 bowersj2 2911: ## Decoding User Agent ##
1.87 matthew 2912: ###############################################################
2913:
2914: =pod
2915:
1.112 bowersj2 2916: =head1 Decoding the User Agent
2917:
2918: =over 4
2919:
2920: =item * &decode_user_agent()
1.87 matthew 2921:
2922: Inputs: $r
2923:
2924: Outputs:
2925:
2926: =over 4
2927:
1.112 bowersj2 2928: =item * $httpbrowser
1.87 matthew 2929:
1.112 bowersj2 2930: =item * $clientbrowser
1.87 matthew 2931:
1.112 bowersj2 2932: =item * $clientversion
1.87 matthew 2933:
1.112 bowersj2 2934: =item * $clientmathml
1.87 matthew 2935:
1.112 bowersj2 2936: =item * $clientunicode
1.87 matthew 2937:
1.112 bowersj2 2938: =item * $clientos
1.87 matthew 2939:
1.1137 raeburn 2940: =item * $clientmobile
2941:
1.1141 raeburn 2942: =item * $clientinfo
2943:
1.1194 raeburn 2944: =item * $clientosversion
2945:
1.87 matthew 2946: =back
2947:
1.157 matthew 2948: =back
2949:
1.87 matthew 2950: =cut
2951:
2952: ###############################################################
2953: ###############################################################
2954: sub decode_user_agent {
1.247 albertel 2955: my ($r)=@_;
1.87 matthew 2956: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2957: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2958: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2959: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2960: my $clientbrowser='unknown';
2961: my $clientversion='0';
2962: my $clientmathml='';
2963: my $clientunicode='0';
1.1137 raeburn 2964: my $clientmobile=0;
1.1194 raeburn 2965: my $clientosversion='';
1.87 matthew 2966: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2967: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2968: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2969: $clientbrowser=$bname;
2970: $httpbrowser=~/$vreg/i;
2971: $clientversion=$1;
2972: $clientmathml=($clientversion>=$minv);
2973: $clientunicode=($clientversion>=$univ);
2974: }
2975: }
2976: my $clientos='unknown';
1.1141 raeburn 2977: my $clientinfo;
1.87 matthew 2978: if (($httpbrowser=~/linux/i) ||
2979: ($httpbrowser=~/unix/i) ||
2980: ($httpbrowser=~/ux/i) ||
2981: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2982: if (($httpbrowser=~/vax/i) ||
2983: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2984: if ($httpbrowser=~/next/i) { $clientos='next'; }
2985: if (($httpbrowser=~/mac/i) ||
2986: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 2987: if ($httpbrowser=~/win/i) {
2988: $clientos='win';
2989: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2990: $clientosversion = $1;
2991: }
2992: }
1.87 matthew 2993: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2994: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2995: $clientmobile=lc($1);
2996: }
1.1141 raeburn 2997: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2998: $clientinfo = 'firefox-'.$1;
2999: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
3000: $clientinfo = 'chromeframe-'.$1;
3001: }
1.87 matthew 3002: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 3003: $clientunicode,$clientos,$clientmobile,$clientinfo,
3004: $clientosversion);
1.87 matthew 3005: }
3006:
1.32 matthew 3007: ###############################################################
3008: ## Authentication changing form generation subroutines ##
3009: ###############################################################
3010: ##
3011: ## All of the authform_xxxxxxx subroutines take their inputs in a
3012: ## hash, and have reasonable default values.
3013: ##
3014: ## formname = the name given in the <form> tag.
1.35 matthew 3015: #-------------------------------------------
3016:
1.45 matthew 3017: =pod
3018:
1.112 bowersj2 3019: =head1 Authentication Routines
3020:
3021: =over 4
3022:
1.648 raeburn 3023: =item * &authform_xxxxxx()
1.35 matthew 3024:
3025: The authform_xxxxxx subroutines provide javascript and html forms which
3026: handle some of the conveniences required for authentication forms.
3027: This is not an optimal method, but it works.
3028:
3029: =over 4
3030:
1.112 bowersj2 3031: =item * authform_header
1.35 matthew 3032:
1.112 bowersj2 3033: =item * authform_authorwarning
1.35 matthew 3034:
1.112 bowersj2 3035: =item * authform_nochange
1.35 matthew 3036:
1.112 bowersj2 3037: =item * authform_kerberos
1.35 matthew 3038:
1.112 bowersj2 3039: =item * authform_internal
1.35 matthew 3040:
1.112 bowersj2 3041: =item * authform_filesystem
1.35 matthew 3042:
1.1310 raeburn 3043: =item * authform_lti
3044:
1.35 matthew 3045: =back
3046:
1.648 raeburn 3047: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3048:
1.35 matthew 3049: =cut
3050:
3051: #-------------------------------------------
1.32 matthew 3052: sub authform_header{
3053: my %in = (
3054: formname => 'cu',
1.80 albertel 3055: kerb_def_dom => '',
1.32 matthew 3056: @_,
3057: );
3058: $in{'formname'} = 'document.' . $in{'formname'};
3059: my $result='';
1.80 albertel 3060:
3061: #---------------------------------------------- Code for upper case translation
3062: my $Javascript_toUpperCase;
3063: unless ($in{kerb_def_dom}) {
3064: $Javascript_toUpperCase =<<"END";
3065: switch (choice) {
3066: case 'krb': currentform.elements[choicearg].value =
3067: currentform.elements[choicearg].value.toUpperCase();
3068: break;
3069: default:
3070: }
3071: END
3072: } else {
3073: $Javascript_toUpperCase = "";
3074: }
3075:
1.165 raeburn 3076: my $radioval = "'nochange'";
1.591 raeburn 3077: if (defined($in{'curr_authtype'})) {
3078: if ($in{'curr_authtype'} ne '') {
3079: $radioval = "'".$in{'curr_authtype'}."arg'";
3080: }
1.174 matthew 3081: }
1.165 raeburn 3082: my $argfield = 'null';
1.591 raeburn 3083: if (defined($in{'mode'})) {
1.165 raeburn 3084: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3085: if (defined($in{'curr_autharg'})) {
3086: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3087: $argfield = "'$in{'curr_autharg'}'";
3088: }
3089: }
3090: }
3091: }
3092:
1.32 matthew 3093: $result.=<<"END";
3094: var current = new Object();
1.165 raeburn 3095: current.radiovalue = $radioval;
3096: current.argfield = $argfield;
1.32 matthew 3097:
3098: function changed_radio(choice,currentform) {
3099: var choicearg = choice + 'arg';
3100: // If a radio button in changed, we need to change the argfield
3101: if (current.radiovalue != choice) {
3102: current.radiovalue = choice;
3103: if (current.argfield != null) {
3104: currentform.elements[current.argfield].value = '';
3105: }
3106: if (choice == 'nochange') {
3107: current.argfield = null;
3108: } else {
3109: current.argfield = choicearg;
3110: switch(choice) {
3111: case 'krb':
3112: currentform.elements[current.argfield].value =
3113: "$in{'kerb_def_dom'}";
3114: break;
3115: default:
3116: break;
3117: }
3118: }
3119: }
3120: return;
3121: }
1.22 www 3122:
1.32 matthew 3123: function changed_text(choice,currentform) {
3124: var choicearg = choice + 'arg';
3125: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3126: $Javascript_toUpperCase
1.32 matthew 3127: // clear old field
3128: if ((current.argfield != choicearg) && (current.argfield != null)) {
3129: currentform.elements[current.argfield].value = '';
3130: }
3131: current.argfield = choicearg;
3132: }
3133: set_auth_radio_buttons(choice,currentform);
3134: return;
1.20 www 3135: }
1.32 matthew 3136:
3137: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3138: var numauthchoices = currentform.login.length;
3139: if (typeof numauthchoices == "undefined") {
3140: return;
3141: }
1.32 matthew 3142: var i=0;
1.986 raeburn 3143: while (i < numauthchoices) {
1.32 matthew 3144: if (currentform.login[i].value == newvalue) { break; }
3145: i++;
3146: }
1.986 raeburn 3147: if (i == numauthchoices) {
1.32 matthew 3148: return;
3149: }
3150: current.radiovalue = newvalue;
3151: currentform.login[i].checked = true;
3152: return;
3153: }
3154: END
3155: return $result;
3156: }
3157:
1.1106 raeburn 3158: sub authform_authorwarning {
1.32 matthew 3159: my $result='';
1.144 matthew 3160: $result='<i>'.
3161: &mt('As a general rule, only authors or co-authors should be '.
3162: 'filesystem authenticated '.
3163: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3164: return $result;
3165: }
3166:
1.1106 raeburn 3167: sub authform_nochange {
1.32 matthew 3168: my %in = (
3169: formname => 'document.cu',
3170: kerb_def_dom => 'MSU.EDU',
3171: @_,
3172: );
1.1106 raeburn 3173: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3174: my $result;
1.1104 raeburn 3175: if (!$authnum) {
1.1105 raeburn 3176: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3177: } else {
3178: $result = '<label>'.&mt('[_1] Do not change login data',
3179: '<input type="radio" name="login" value="nochange" '.
3180: 'checked="checked" onclick="'.
1.281 albertel 3181: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3182: '</label>';
1.586 raeburn 3183: }
1.32 matthew 3184: return $result;
3185: }
3186:
1.591 raeburn 3187: sub authform_kerberos {
1.32 matthew 3188: my %in = (
3189: formname => 'document.cu',
3190: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3191: kerb_def_auth => 'krb4',
1.32 matthew 3192: @_,
3193: );
1.586 raeburn 3194: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3195: $autharg,$jscall,$disabled);
1.1106 raeburn 3196: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3197: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3198: $check5 = ' checked="checked"';
1.80 albertel 3199: } else {
1.772 bisitz 3200: $check4 = ' checked="checked"';
1.80 albertel 3201: }
1.1259 raeburn 3202: if ($in{'readonly'}) {
3203: $disabled = ' disabled="disabled"';
3204: }
1.165 raeburn 3205: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3206: if (defined($in{'curr_authtype'})) {
3207: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3208: $krbcheck = ' checked="checked"';
1.623 raeburn 3209: if (defined($in{'mode'})) {
3210: if ($in{'mode'} eq 'modifyuser') {
3211: $krbcheck = '';
3212: }
3213: }
1.591 raeburn 3214: if (defined($in{'curr_kerb_ver'})) {
3215: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3216: $check5 = ' checked="checked"';
1.591 raeburn 3217: $check4 = '';
3218: } else {
1.772 bisitz 3219: $check4 = ' checked="checked"';
1.591 raeburn 3220: $check5 = '';
3221: }
1.586 raeburn 3222: }
1.591 raeburn 3223: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3224: $krbarg = $in{'curr_autharg'};
3225: }
1.586 raeburn 3226: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3227: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3228: $result =
3229: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3230: $in{'curr_autharg'},$krbver);
3231: } else {
3232: $result =
3233: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3234: }
3235: return $result;
3236: }
3237: }
3238: } else {
3239: if ($authnum == 1) {
1.784 bisitz 3240: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3241: }
3242: }
1.586 raeburn 3243: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3244: return;
1.587 raeburn 3245: } elsif ($authtype eq '') {
1.591 raeburn 3246: if (defined($in{'mode'})) {
1.587 raeburn 3247: if ($in{'mode'} eq 'modifycourse') {
3248: if ($authnum == 1) {
1.1259 raeburn 3249: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3250: }
3251: }
3252: }
1.586 raeburn 3253: }
3254: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3255: if ($authtype eq '') {
3256: $authtype = '<input type="radio" name="login" value="krb" '.
3257: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3258: $krbcheck.$disabled.' />';
1.586 raeburn 3259: }
3260: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3261: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3262: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3263: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3264: $in{'curr_authtype'} eq 'krb4')) {
3265: $result .= &mt
1.144 matthew 3266: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3267: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3268: '<label>'.$authtype,
1.281 albertel 3269: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3270: 'value="'.$krbarg.'" '.
1.1259 raeburn 3271: 'onchange="'.$jscall.'"'.$disabled.' />',
3272: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3273: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3274: '</label>');
1.586 raeburn 3275: } elsif ($can_assign{'krb4'}) {
3276: $result .= &mt
3277: ('[_1] Kerberos authenticated with domain [_2] '.
3278: '[_3] Version 4 [_4]',
3279: '<label>'.$authtype,
3280: '</label><input type="text" size="10" name="krbarg" '.
3281: 'value="'.$krbarg.'" '.
1.1259 raeburn 3282: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3283: '<label><input type="hidden" name="krbver" value="4" />',
3284: '</label>');
3285: } elsif ($can_assign{'krb5'}) {
3286: $result .= &mt
3287: ('[_1] Kerberos authenticated with domain [_2] '.
3288: '[_3] Version 5 [_4]',
3289: '<label>'.$authtype,
3290: '</label><input type="text" size="10" name="krbarg" '.
3291: 'value="'.$krbarg.'" '.
1.1259 raeburn 3292: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3293: '<label><input type="hidden" name="krbver" value="5" />',
3294: '</label>');
3295: }
1.32 matthew 3296: return $result;
3297: }
3298:
1.1106 raeburn 3299: sub authform_internal {
1.586 raeburn 3300: my %in = (
1.32 matthew 3301: formname => 'document.cu',
3302: kerb_def_dom => 'MSU.EDU',
3303: @_,
3304: );
1.1259 raeburn 3305: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3306: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3307: if ($in{'readonly'}) {
3308: $disabled = ' disabled="disabled"';
3309: }
1.591 raeburn 3310: if (defined($in{'curr_authtype'})) {
3311: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3312: if ($can_assign{'int'}) {
1.772 bisitz 3313: $intcheck = 'checked="checked" ';
1.623 raeburn 3314: if (defined($in{'mode'})) {
3315: if ($in{'mode'} eq 'modifyuser') {
3316: $intcheck = '';
3317: }
3318: }
1.591 raeburn 3319: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3320: $intarg = $in{'curr_autharg'};
3321: }
3322: } else {
3323: $result = &mt('Currently internally authenticated.');
3324: return $result;
1.165 raeburn 3325: }
3326: }
1.586 raeburn 3327: } else {
3328: if ($authnum == 1) {
1.784 bisitz 3329: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3330: }
3331: }
3332: if (!$can_assign{'int'}) {
3333: return;
1.587 raeburn 3334: } elsif ($authtype eq '') {
1.591 raeburn 3335: if (defined($in{'mode'})) {
1.587 raeburn 3336: if ($in{'mode'} eq 'modifycourse') {
3337: if ($authnum == 1) {
1.1259 raeburn 3338: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3339: }
3340: }
3341: }
1.165 raeburn 3342: }
1.586 raeburn 3343: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3344: if ($authtype eq '') {
3345: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3346: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3347: }
1.605 bisitz 3348: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3349: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3350: $result = &mt
1.144 matthew 3351: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3352: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3353: $result.='<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.intarg.type='."'text'".' } else { this.form.intarg.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label>';
1.32 matthew 3354: return $result;
3355: }
3356:
1.1104 raeburn 3357: sub authform_local {
1.32 matthew 3358: my %in = (
3359: formname => 'document.cu',
3360: kerb_def_dom => 'MSU.EDU',
3361: @_,
3362: );
1.1259 raeburn 3363: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3364: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3365: if ($in{'readonly'}) {
3366: $disabled = ' disabled="disabled"';
3367: }
1.591 raeburn 3368: if (defined($in{'curr_authtype'})) {
3369: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3370: if ($can_assign{'loc'}) {
1.772 bisitz 3371: $loccheck = 'checked="checked" ';
1.623 raeburn 3372: if (defined($in{'mode'})) {
3373: if ($in{'mode'} eq 'modifyuser') {
3374: $loccheck = '';
3375: }
3376: }
1.591 raeburn 3377: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3378: $locarg = $in{'curr_autharg'};
3379: }
3380: } else {
3381: $result = &mt('Currently using local (institutional) authentication.');
3382: return $result;
1.165 raeburn 3383: }
3384: }
1.586 raeburn 3385: } else {
3386: if ($authnum == 1) {
1.784 bisitz 3387: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3388: }
3389: }
3390: if (!$can_assign{'loc'}) {
3391: return;
1.587 raeburn 3392: } elsif ($authtype eq '') {
1.591 raeburn 3393: if (defined($in{'mode'})) {
1.587 raeburn 3394: if ($in{'mode'} eq 'modifycourse') {
3395: if ($authnum == 1) {
1.1259 raeburn 3396: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3397: }
3398: }
3399: }
1.165 raeburn 3400: }
1.586 raeburn 3401: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3402: if ($authtype eq '') {
3403: $authtype = '<input type="radio" name="login" value="loc" '.
3404: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3405: $jscall.'"'.$disabled.' />';
1.586 raeburn 3406: }
3407: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3408: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3409: $result = &mt('[_1] Local Authentication with argument [_2]',
3410: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3411: return $result;
3412: }
3413:
1.1106 raeburn 3414: sub authform_filesystem {
1.32 matthew 3415: my %in = (
3416: formname => 'document.cu',
3417: kerb_def_dom => 'MSU.EDU',
3418: @_,
3419: );
1.1259 raeburn 3420: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3421: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3422: if ($in{'readonly'}) {
3423: $disabled = ' disabled="disabled"';
3424: }
1.591 raeburn 3425: if (defined($in{'curr_authtype'})) {
3426: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3427: if ($can_assign{'fsys'}) {
1.772 bisitz 3428: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3429: if (defined($in{'mode'})) {
3430: if ($in{'mode'} eq 'modifyuser') {
3431: $fsyscheck = '';
3432: }
3433: }
1.586 raeburn 3434: } else {
3435: $result = &mt('Currently Filesystem Authenticated.');
3436: return $result;
1.1259 raeburn 3437: }
1.586 raeburn 3438: }
3439: } else {
3440: if ($authnum == 1) {
1.784 bisitz 3441: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3442: }
3443: }
3444: if (!$can_assign{'fsys'}) {
3445: return;
1.587 raeburn 3446: } elsif ($authtype eq '') {
1.591 raeburn 3447: if (defined($in{'mode'})) {
1.587 raeburn 3448: if ($in{'mode'} eq 'modifycourse') {
3449: if ($authnum == 1) {
1.1259 raeburn 3450: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3451: }
3452: }
3453: }
1.586 raeburn 3454: }
3455: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3456: if ($authtype eq '') {
3457: $authtype = '<input type="radio" name="login" value="fsys" '.
3458: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3459: $jscall.'"'.$disabled.' />';
1.586 raeburn 3460: }
1.1310 raeburn 3461: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3462: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3463: $result = &mt
1.144 matthew 3464: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1310 raeburn 3465: '<label>'.$authtype,'</label>'.$autharg);
3466: return $result;
3467: }
3468:
3469: sub authform_lti {
3470: my %in = (
3471: formname => 'document.cu',
3472: kerb_def_dom => 'MSU.EDU',
3473: @_,
3474: );
3475: my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);
3476: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
3477: if ($in{'readonly'}) {
3478: $disabled = ' disabled="disabled"';
3479: }
3480: if (defined($in{'curr_authtype'})) {
3481: if ($in{'curr_authtype'} eq 'lti') {
3482: if ($can_assign{'lti'}) {
3483: $lticheck = 'checked="checked" ';
3484: if (defined($in{'mode'})) {
3485: if ($in{'mode'} eq 'modifyuser') {
3486: $lticheck = '';
3487: }
3488: }
3489: } else {
3490: $result = &mt('Currently LTI Authenticated.');
3491: return $result;
3492: }
3493: }
3494: } else {
3495: if ($authnum == 1) {
3496: $authtype = '<input type="hidden" name="login" value="lti" />';
3497: }
3498: }
3499: if (!$can_assign{'lti'}) {
3500: return;
3501: } elsif ($authtype eq '') {
3502: if (defined($in{'mode'})) {
3503: if ($in{'mode'} eq 'modifycourse') {
3504: if ($authnum == 1) {
3505: $authtype = '<input type="radio" name="login" value="lti"'.$disabled.' />';
3506: }
3507: }
3508: }
3509: }
3510: $jscall = "javascript:changed_radio('lti',$in{'formname'});";
3511: if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {
3512: $authtype = '<input type="radio" name="login" value="lti" '.
3513: $lticheck.' onchange="'.$jscall.'" onclick="'.
3514: $jscall.'"'.$disabled.' />';
3515: }
3516: $autharg = '<input type="hidden" name="ltiarg" value="" />';
3517: if ($authtype) {
3518: $result = &mt('[_1] LTI Authenticated',
3519: '<label>'.$authtype.'</label>'.$autharg);
3520: } else {
3521: $result = '<b>'.&mt('LTI Authenticated').'</b>'.
3522: $autharg;
3523: }
1.32 matthew 3524: return $result;
3525: }
3526:
1.586 raeburn 3527: sub get_assignable_auth {
3528: my ($dom) = @_;
3529: if ($dom eq '') {
3530: $dom = $env{'request.role.domain'};
3531: }
3532: my %can_assign = (
3533: krb4 => 1,
3534: krb5 => 1,
3535: int => 1,
3536: loc => 1,
1.1310 raeburn 3537: lti => 1,
1.586 raeburn 3538: );
3539: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3540: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3541: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3542: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3543: my $context;
3544: if ($env{'request.role'} =~ /^au/) {
3545: $context = 'author';
1.1259 raeburn 3546: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3547: $context = 'domain';
3548: } elsif ($env{'request.course.id'}) {
3549: $context = 'course';
3550: }
3551: if ($context) {
3552: if (ref($authhash->{$context}) eq 'HASH') {
3553: %can_assign = %{$authhash->{$context}};
3554: }
3555: }
3556: }
3557: }
3558: my $authnum = 0;
3559: foreach my $key (keys(%can_assign)) {
3560: if ($can_assign{$key}) {
3561: $authnum ++;
3562: }
3563: }
3564: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3565: $authnum --;
3566: }
3567: return ($authnum,%can_assign);
3568: }
3569:
1.1331 raeburn 3570: sub check_passwd_rules {
3571: my ($domain,$plainpass) = @_;
3572: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3573: my ($min,$max,@chars,@brokerule,$warning);
1.1333 raeburn 3574: $min = $Apache::lonnet::passwdmin;
1.1331 raeburn 3575: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3576: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1333 raeburn 3577: if ($passwdconf{'min'} > $min) {
3578: $min = $passwdconf{'min'};
3579: }
1.1331 raeburn 3580: }
3581: if ($passwdconf{'max'} =~ /^\d+$/) {
3582: $max = $passwdconf{'max'};
3583: }
3584: @chars = @{$passwdconf{'chars'}};
3585: }
3586: if (($min) && (length($plainpass) < $min)) {
3587: push(@brokerule,'min');
3588: }
3589: if (($max) && (length($plainpass) > $max)) {
3590: push(@brokerule,'max');
3591: }
3592: if (@chars) {
3593: my %rules;
3594: map { $rules{$_} = 1; } @chars;
3595: if ($rules{'uc'}) {
3596: unless ($plainpass =~ /[A-Z]/) {
3597: push(@brokerule,'uc');
3598: }
3599: }
3600: if ($rules{'lc'}) {
1.1332 raeburn 3601: unless ($plainpass =~ /[a-z]/) {
1.1331 raeburn 3602: push(@brokerule,'lc');
3603: }
3604: }
3605: if ($rules{'num'}) {
3606: unless ($plainpass =~ /\d/) {
3607: push(@brokerule,'num');
3608: }
3609: }
3610: if ($rules{'spec'}) {
3611: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3612: push(@brokerule,'spec');
3613: }
3614: }
3615: }
3616: if (@brokerule) {
3617: my %rulenames = &Apache::lonlocal::texthash(
3618: uc => 'At least one upper case letter',
3619: lc => 'At least one lower case letter',
3620: num => 'At least one number',
3621: spec => 'At least one non-alphanumeric',
3622: );
3623: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3624: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3625: $rulenames{'num'} .= ': 0123456789';
3626: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3627: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3628: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3629: $warning = &mt('Password did not satisfy the following:').'<ul>';
3630: foreach my $rule ('min','max','uc','ls','num','spec') {
3631: if (grep(/^$rule$/,@brokerule)) {
3632: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3633: }
3634: }
3635: $warning .= '</ul>';
3636: }
1.1332 raeburn 3637: if (wantarray) {
3638: return @brokerule;
3639: }
1.1331 raeburn 3640: return $warning;
3641: }
3642:
1.80 albertel 3643: ###############################################################
3644: ## Get Kerberos Defaults for Domain ##
3645: ###############################################################
3646: ##
3647: ## Returns default kerberos version and an associated argument
3648: ## as listed in file domain.tab. If not listed, provides
3649: ## appropriate default domain and kerberos version.
3650: ##
3651: #-------------------------------------------
3652:
3653: =pod
3654:
1.648 raeburn 3655: =item * &get_kerberos_defaults()
1.80 albertel 3656:
3657: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3658: version and domain. If not found, it defaults to version 4 and the
3659: domain of the server.
1.80 albertel 3660:
1.648 raeburn 3661: =over 4
3662:
1.80 albertel 3663: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3664:
1.648 raeburn 3665: =back
3666:
3667: =back
3668:
1.80 albertel 3669: =cut
3670:
3671: #-------------------------------------------
3672: sub get_kerberos_defaults {
3673: my $domain=shift;
1.641 raeburn 3674: my ($krbdef,$krbdefdom);
3675: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3676: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3677: $krbdef = $domdefaults{'auth_def'};
3678: $krbdefdom = $domdefaults{'auth_arg_def'};
3679: } else {
1.80 albertel 3680: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3681: my $krbdefdom=$1;
3682: $krbdefdom=~tr/a-z/A-Z/;
3683: $krbdef = "krb4";
3684: }
3685: return ($krbdef,$krbdefdom);
3686: }
1.112 bowersj2 3687:
1.32 matthew 3688:
1.46 matthew 3689: ###############################################################
3690: ## Thesaurus Functions ##
3691: ###############################################################
1.20 www 3692:
1.46 matthew 3693: =pod
1.20 www 3694:
1.112 bowersj2 3695: =head1 Thesaurus Functions
3696:
3697: =over 4
3698:
1.648 raeburn 3699: =item * &initialize_keywords()
1.46 matthew 3700:
3701: Initializes the package variable %Keywords if it is empty. Uses the
3702: package variable $thesaurus_db_file.
3703:
3704: =cut
3705:
3706: ###################################################
3707:
3708: sub initialize_keywords {
3709: return 1 if (scalar keys(%Keywords));
3710: # If we are here, %Keywords is empty, so fill it up
3711: # Make sure the file we need exists...
3712: if (! -e $thesaurus_db_file) {
3713: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3714: " failed because it does not exist");
3715: return 0;
3716: }
3717: # Set up the hash as a database
3718: my %thesaurus_db;
3719: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3720: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3721: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3722: $thesaurus_db_file);
3723: return 0;
3724: }
3725: # Get the average number of appearances of a word.
3726: my $avecount = $thesaurus_db{'average.count'};
3727: # Put keywords (those that appear > average) into %Keywords
3728: while (my ($word,$data)=each (%thesaurus_db)) {
3729: my ($count,undef) = split /:/,$data;
3730: $Keywords{$word}++ if ($count > $avecount);
3731: }
3732: untie %thesaurus_db;
3733: # Remove special values from %Keywords.
1.356 albertel 3734: foreach my $value ('total.count','average.count') {
3735: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3736: }
1.46 matthew 3737: return 1;
3738: }
3739:
3740: ###################################################
3741:
3742: =pod
3743:
1.648 raeburn 3744: =item * &keyword($word)
1.46 matthew 3745:
3746: Returns true if $word is a keyword. A keyword is a word that appears more
3747: than the average number of times in the thesaurus database. Calls
3748: &initialize_keywords
3749:
3750: =cut
3751:
3752: ###################################################
1.20 www 3753:
3754: sub keyword {
1.46 matthew 3755: return if (!&initialize_keywords());
3756: my $word=lc(shift());
3757: $word=~s/\W//g;
3758: return exists($Keywords{$word});
1.20 www 3759: }
1.46 matthew 3760:
3761: ###############################################################
3762:
3763: =pod
1.20 www 3764:
1.648 raeburn 3765: =item * &get_related_words()
1.46 matthew 3766:
1.160 matthew 3767: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3768: an array of words. If the keyword is not in the thesaurus, an empty array
3769: will be returned. The order of the words returned is determined by the
3770: database which holds them.
3771:
3772: Uses global $thesaurus_db_file.
3773:
1.1057 foxr 3774:
1.46 matthew 3775: =cut
3776:
3777: ###############################################################
3778: sub get_related_words {
3779: my $keyword = shift;
3780: my %thesaurus_db;
3781: if (! -e $thesaurus_db_file) {
3782: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3783: "failed because the file does not exist");
3784: return ();
3785: }
3786: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3787: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3788: return ();
3789: }
3790: my @Words=();
1.429 www 3791: my $count=0;
1.46 matthew 3792: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3793: # The first element is the number of times
3794: # the word appears. We do not need it now.
1.429 www 3795: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3796: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3797: my $threshold=$mostfrequentcount/10;
3798: foreach my $possibleword (@RelatedWords) {
3799: my ($word,$wordcount)=split(/\,/,$possibleword);
3800: if ($wordcount>$threshold) {
3801: push(@Words,$word);
3802: $count++;
3803: if ($count>10) { last; }
3804: }
1.20 www 3805: }
3806: }
1.46 matthew 3807: untie %thesaurus_db;
3808: return @Words;
1.14 harris41 3809: }
1.1090 foxr 3810: ###############################################################
3811: #
3812: # Spell checking
3813: #
3814:
3815: =pod
3816:
1.1142 raeburn 3817: =back
3818:
1.1090 foxr 3819: =head1 Spell checking
3820:
3821: =over 4
3822:
3823: =item * &check_spelling($wordlist $language)
3824:
3825: Takes a string containing words and feeds it to an external
3826: spellcheck program via a pipeline. Returns a string containing
3827: them mis-spelled words.
3828:
3829: Parameters:
3830:
3831: =over 4
3832:
3833: =item - $wordlist
3834:
3835: String that will be fed into the spellcheck program.
3836:
3837: =item - $language
3838:
3839: Language string that specifies the language for which the spell
3840: check will be performed.
3841:
3842: =back
3843:
3844: =back
3845:
3846: Note: This sub assumes that aspell is installed.
3847:
3848:
3849: =cut
3850:
1.46 matthew 3851:
1.1090 foxr 3852: sub check_spelling {
3853: my ($wordlist, $language) = @_;
1.1091 foxr 3854: my @misspellings;
3855:
3856: # Generate the speller and set the langauge.
3857: # if explicitly selected:
1.1090 foxr 3858:
1.1091 foxr 3859: my $speller = Text::Aspell->new;
1.1090 foxr 3860: if ($language) {
1.1091 foxr 3861: $speller->set_option('lang', $language);
1.1090 foxr 3862: }
3863:
1.1091 foxr 3864: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3865:
1.1091 foxr 3866: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3867:
1.1091 foxr 3868: foreach my $word (@words) {
3869: if(! $speller->check($word)) {
3870: push(@misspellings, $word);
1.1090 foxr 3871: }
3872: }
1.1091 foxr 3873: return join(' ', @misspellings);
3874:
1.1090 foxr 3875: }
3876:
1.61 www 3877: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3878: =pod
3879:
1.112 bowersj2 3880: =head1 User Name Functions
3881:
3882: =over 4
3883:
1.648 raeburn 3884: =item * &plainname($uname,$udom,$first)
1.81 albertel 3885:
1.112 bowersj2 3886: Takes a users logon name and returns it as a string in
1.226 albertel 3887: "first middle last generation" form
3888: if $first is set to 'lastname' then it returns it as
3889: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3890:
3891: =cut
1.61 www 3892:
1.295 www 3893:
1.81 albertel 3894: ###############################################################
1.61 www 3895: sub plainname {
1.226 albertel 3896: my ($uname,$udom,$first)=@_;
1.537 albertel 3897: return if (!defined($uname) || !defined($udom));
1.295 www 3898: my %names=&getnames($uname,$udom);
1.226 albertel 3899: my $name=&Apache::lonnet::format_name($names{'firstname'},
3900: $names{'middlename'},
3901: $names{'lastname'},
3902: $names{'generation'},$first);
3903: $name=~s/^\s+//;
1.62 www 3904: $name=~s/\s+$//;
3905: $name=~s/\s+/ /g;
1.353 albertel 3906: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3907: return $name;
1.61 www 3908: }
1.66 www 3909:
3910: # -------------------------------------------------------------------- Nickname
1.81 albertel 3911: =pod
3912:
1.648 raeburn 3913: =item * &nickname($uname,$udom)
1.81 albertel 3914:
3915: Gets a users name and returns it as a string as
3916:
3917: ""nickname""
1.66 www 3918:
1.81 albertel 3919: if the user has a nickname or
3920:
3921: "first middle last generation"
3922:
3923: if the user does not
3924:
3925: =cut
1.66 www 3926:
3927: sub nickname {
3928: my ($uname,$udom)=@_;
1.537 albertel 3929: return if (!defined($uname) || !defined($udom));
1.295 www 3930: my %names=&getnames($uname,$udom);
1.68 albertel 3931: my $name=$names{'nickname'};
1.66 www 3932: if ($name) {
3933: $name='"'.$name.'"';
3934: } else {
3935: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3936: $names{'lastname'}.' '.$names{'generation'};
3937: $name=~s/\s+$//;
3938: $name=~s/\s+/ /g;
3939: }
3940: return $name;
3941: }
3942:
1.295 www 3943: sub getnames {
3944: my ($uname,$udom)=@_;
1.537 albertel 3945: return if (!defined($uname) || !defined($udom));
1.433 albertel 3946: if ($udom eq 'public' && $uname eq 'public') {
3947: return ('lastname' => &mt('Public'));
3948: }
1.295 www 3949: my $id=$uname.':'.$udom;
3950: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3951: if ($cached) {
3952: return %{$names};
3953: } else {
3954: my %loadnames=&Apache::lonnet::get('environment',
3955: ['firstname','middlename','lastname','generation','nickname'],
3956: $udom,$uname);
3957: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3958: return %loadnames;
3959: }
3960: }
1.61 www 3961:
1.542 raeburn 3962: # -------------------------------------------------------------------- getemails
1.648 raeburn 3963:
1.542 raeburn 3964: =pod
3965:
1.648 raeburn 3966: =item * &getemails($uname,$udom)
1.542 raeburn 3967:
3968: Gets a user's email information and returns it as a hash with keys:
3969: notification, critnotification, permanentemail
3970:
3971: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3972: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3973:
1.648 raeburn 3974:
1.542 raeburn 3975: =cut
3976:
1.648 raeburn 3977:
1.466 albertel 3978: sub getemails {
3979: my ($uname,$udom)=@_;
3980: if ($udom eq 'public' && $uname eq 'public') {
3981: return;
3982: }
1.467 www 3983: if (!$udom) { $udom=$env{'user.domain'}; }
3984: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3985: my $id=$uname.':'.$udom;
3986: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3987: if ($cached) {
3988: return %{$names};
3989: } else {
3990: my %loadnames=&Apache::lonnet::get('environment',
3991: ['notification','critnotification',
3992: 'permanentemail'],
3993: $udom,$uname);
3994: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3995: return %loadnames;
3996: }
3997: }
3998:
1.551 albertel 3999: sub flush_email_cache {
4000: my ($uname,$udom)=@_;
4001: if (!$udom) { $udom =$env{'user.domain'}; }
4002: if (!$uname) { $uname=$env{'user.name'}; }
4003: return if ($udom eq 'public' && $uname eq 'public');
4004: my $id=$uname.':'.$udom;
4005: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
4006: }
4007:
1.728 raeburn 4008: # -------------------------------------------------------------------- getlangs
4009:
4010: =pod
4011:
4012: =item * &getlangs($uname,$udom)
4013:
4014: Gets a user's language preference and returns it as a hash with key:
4015: language.
4016:
4017: =cut
4018:
4019:
4020: sub getlangs {
4021: my ($uname,$udom) = @_;
4022: if (!$udom) { $udom =$env{'user.domain'}; }
4023: if (!$uname) { $uname=$env{'user.name'}; }
4024: my $id=$uname.':'.$udom;
4025: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
4026: if ($cached) {
4027: return %{$langs};
4028: } else {
4029: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
4030: $udom,$uname);
4031: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
4032: return %loadlangs;
4033: }
4034: }
4035:
4036: sub flush_langs_cache {
4037: my ($uname,$udom)=@_;
4038: if (!$udom) { $udom =$env{'user.domain'}; }
4039: if (!$uname) { $uname=$env{'user.name'}; }
4040: return if ($udom eq 'public' && $uname eq 'public');
4041: my $id=$uname.':'.$udom;
4042: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
4043: }
4044:
1.61 www 4045: # ------------------------------------------------------------------ Screenname
1.81 albertel 4046:
4047: =pod
4048:
1.648 raeburn 4049: =item * &screenname($uname,$udom)
1.81 albertel 4050:
4051: Gets a users screenname and returns it as a string
4052:
4053: =cut
1.61 www 4054:
4055: sub screenname {
4056: my ($uname,$udom)=@_;
1.258 albertel 4057: if ($uname eq $env{'user.name'} &&
4058: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 4059: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 4060: return $names{'screenname'};
1.62 www 4061: }
4062:
1.212 albertel 4063:
1.802 bisitz 4064: # ------------------------------------------------------------- Confirm Wrapper
4065: =pod
4066:
1.1142 raeburn 4067: =item * &confirmwrapper($message)
1.802 bisitz 4068:
4069: Wrap messages about completion of operation in box
4070:
4071: =cut
4072:
4073: sub confirmwrapper {
4074: my ($message)=@_;
4075: if ($message) {
4076: return "\n".'<div class="LC_confirm_box">'."\n"
4077: .$message."\n"
4078: .'</div>'."\n";
4079: } else {
4080: return $message;
4081: }
4082: }
4083:
1.62 www 4084: # ------------------------------------------------------------- Message Wrapper
4085:
4086: sub messagewrapper {
1.369 www 4087: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 4088: return
1.441 albertel 4089: '<a href="/adm/email?compose=individual&'.
4090: 'recname='.$username.'&recdom='.$domain.
4091: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 4092: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 4093: }
1.802 bisitz 4094:
1.74 www 4095: # --------------------------------------------------------------- Notes Wrapper
4096:
4097: sub noteswrapper {
4098: my ($link,$un,$do)=@_;
4099: return
1.896 amueller 4100: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 4101: }
1.802 bisitz 4102:
1.62 www 4103: # ------------------------------------------------------------- Aboutme Wrapper
4104:
4105: sub aboutmewrapper {
1.1070 raeburn 4106: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 4107: if (!defined($username) && !defined($domain)) {
4108: return;
4109: }
1.1096 raeburn 4110: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 4111: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 4112: }
4113:
4114: # ------------------------------------------------------------ Syllabus Wrapper
4115:
4116: sub syllabuswrapper {
1.707 bisitz 4117: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 4118: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 4119: }
1.14 harris41 4120:
1.802 bisitz 4121: # -----------------------------------------------------------------------------
4122:
1.208 matthew 4123: sub track_student_link {
1.887 raeburn 4124: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 4125: my $link ="/adm/trackstudent?";
1.208 matthew 4126: my $title = 'View recent activity';
4127: if (defined($sname) && $sname !~ /^\s*$/ &&
4128: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 4129: $link .= "selected_student=$sname:$sdom";
1.208 matthew 4130: $title .= ' of this student';
1.268 albertel 4131: }
1.208 matthew 4132: if (defined($target) && $target !~ /^\s*$/) {
4133: $target = qq{target="$target"};
4134: } else {
4135: $target = '';
4136: }
1.268 albertel 4137: if ($start) { $link.='&start='.$start; }
1.887 raeburn 4138: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 4139: $title = &mt($title);
4140: $linktext = &mt($linktext);
1.448 albertel 4141: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
4142: &help_open_topic('View_recent_activity');
1.208 matthew 4143: }
4144:
1.781 raeburn 4145: sub slot_reservations_link {
4146: my ($linktext,$sname,$sdom,$target) = @_;
4147: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
4148: my $title = 'View slot reservation history';
4149: if (defined($sname) && $sname !~ /^\s*$/ &&
4150: defined($sdom) && $sdom !~ /^\s*$/) {
4151: $link .= "&uname=$sname&udom=$sdom";
4152: $title .= ' of this student';
4153: }
4154: if (defined($target) && $target !~ /^\s*$/) {
4155: $target = qq{target="$target"};
4156: } else {
4157: $target = '';
4158: }
4159: $title = &mt($title);
4160: $linktext = &mt($linktext);
4161: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4162: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4163:
4164: }
4165:
1.508 www 4166: # ===================================================== Display a student photo
4167:
4168:
1.509 albertel 4169: sub student_image_tag {
1.508 www 4170: my ($domain,$user)=@_;
4171: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4172: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4173: return '<img src="'.$imgsrc.'" align="right" />';
4174: } else {
4175: return '';
4176: }
4177: }
4178:
1.112 bowersj2 4179: =pod
4180:
4181: =back
4182:
4183: =head1 Access .tab File Data
4184:
4185: =over 4
4186:
1.648 raeburn 4187: =item * &languageids()
1.112 bowersj2 4188:
4189: returns list of all language ids
4190:
4191: =cut
4192:
1.14 harris41 4193: sub languageids {
1.16 harris41 4194: return sort(keys(%language));
1.14 harris41 4195: }
4196:
1.112 bowersj2 4197: =pod
4198:
1.648 raeburn 4199: =item * &languagedescription()
1.112 bowersj2 4200:
4201: returns description of a specified language id
4202:
4203: =cut
4204:
1.14 harris41 4205: sub languagedescription {
1.125 www 4206: my $code=shift;
4207: return ($supported_language{$code}?'* ':'').
4208: $language{$code}.
1.126 www 4209: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4210: }
4211:
1.1048 foxr 4212: =pod
4213:
4214: =item * &plainlanguagedescription
4215:
4216: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4217: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4218:
4219: =cut
4220:
1.145 www 4221: sub plainlanguagedescription {
4222: my $code=shift;
4223: return $language{$code};
4224: }
4225:
1.1048 foxr 4226: =pod
4227:
4228: =item * &supportedlanguagecode
4229:
4230: Returns the supported language code (e.g. sptutf maps to pt) given a language
4231: code.
4232:
4233: =cut
4234:
1.145 www 4235: sub supportedlanguagecode {
4236: my $code=shift;
4237: return $supported_language{$code};
1.97 www 4238: }
4239:
1.112 bowersj2 4240: =pod
4241:
1.1048 foxr 4242: =item * &latexlanguage()
4243:
4244: Given a language key code returns the correspondnig language to use
4245: to select the correct hyphenation on LaTeX printouts. This is undef if there
4246: is no supported hyphenation for the language code.
4247:
4248: =cut
4249:
4250: sub latexlanguage {
4251: my $code = shift;
4252: return $latex_language{$code};
4253: }
4254:
4255: =pod
4256:
4257: =item * &latexhyphenation()
4258:
4259: Same as above but what's supplied is the language as it might be stored
4260: in the metadata.
4261:
4262: =cut
4263:
4264: sub latexhyphenation {
4265: my $key = shift;
4266: return $latex_language_bykey{$key};
4267: }
4268:
4269: =pod
4270:
1.648 raeburn 4271: =item * ©rightids()
1.112 bowersj2 4272:
4273: returns list of all copyrights
4274:
4275: =cut
4276:
4277: sub copyrightids {
4278: return sort(keys(%cprtag));
4279: }
4280:
4281: =pod
4282:
1.648 raeburn 4283: =item * ©rightdescription()
1.112 bowersj2 4284:
4285: returns description of a specified copyright id
4286:
4287: =cut
4288:
4289: sub copyrightdescription {
1.166 www 4290: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4291: }
1.197 matthew 4292:
4293: =pod
4294:
1.648 raeburn 4295: =item * &source_copyrightids()
1.192 taceyjo1 4296:
4297: returns list of all source copyrights
4298:
4299: =cut
4300:
4301: sub source_copyrightids {
4302: return sort(keys(%scprtag));
4303: }
4304:
4305: =pod
4306:
1.648 raeburn 4307: =item * &source_copyrightdescription()
1.192 taceyjo1 4308:
4309: returns description of a specified source copyright id
4310:
4311: =cut
4312:
4313: sub source_copyrightdescription {
4314: return &mt($scprtag{shift(@_)});
4315: }
1.112 bowersj2 4316:
4317: =pod
4318:
1.648 raeburn 4319: =item * &filecategories()
1.112 bowersj2 4320:
4321: returns list of all file categories
4322:
4323: =cut
4324:
4325: sub filecategories {
4326: return sort(keys(%category_extensions));
4327: }
4328:
4329: =pod
4330:
1.648 raeburn 4331: =item * &filecategorytypes()
1.112 bowersj2 4332:
4333: returns list of file types belonging to a given file
4334: category
4335:
4336: =cut
4337:
4338: sub filecategorytypes {
1.356 albertel 4339: my ($cat) = @_;
1.1248 raeburn 4340: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4341: return @{$category_extensions{lc($cat)}};
4342: } else {
4343: return ();
4344: }
1.112 bowersj2 4345: }
4346:
4347: =pod
4348:
1.648 raeburn 4349: =item * &fileembstyle()
1.112 bowersj2 4350:
4351: returns embedding style for a specified file type
4352:
4353: =cut
4354:
4355: sub fileembstyle {
4356: return $fe{lc(shift(@_))};
1.169 www 4357: }
4358:
1.351 www 4359: sub filemimetype {
4360: return $fm{lc(shift(@_))};
4361: }
4362:
1.169 www 4363:
4364: sub filecategoryselect {
4365: my ($name,$value)=@_;
1.189 matthew 4366: return &select_form($value,$name,
1.970 raeburn 4367: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4368: }
4369:
4370: =pod
4371:
1.648 raeburn 4372: =item * &filedescription()
1.112 bowersj2 4373:
4374: returns description for a specified file type
4375:
4376: =cut
4377:
4378: sub filedescription {
1.188 matthew 4379: my $file_description = $fd{lc(shift())};
4380: $file_description =~ s:([\[\]]):~$1:g;
4381: return &mt($file_description);
1.112 bowersj2 4382: }
4383:
4384: =pod
4385:
1.648 raeburn 4386: =item * &filedescriptionex()
1.112 bowersj2 4387:
4388: returns description for a specified file type with
4389: extra formatting
4390:
4391: =cut
4392:
4393: sub filedescriptionex {
4394: my $ex=shift;
1.188 matthew 4395: my $file_description = $fd{lc($ex)};
4396: $file_description =~ s:([\[\]]):~$1:g;
4397: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4398: }
4399:
4400: # End of .tab access
4401: =pod
4402:
4403: =back
4404:
4405: =cut
4406:
4407: # ------------------------------------------------------------------ File Types
4408: sub fileextensions {
4409: return sort(keys(%fe));
4410: }
4411:
1.97 www 4412: # ----------------------------------------------------------- Display Languages
4413: # returns a hash with all desired display languages
4414: #
4415:
4416: sub display_languages {
4417: my %languages=();
1.695 raeburn 4418: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4419: $languages{$lang}=1;
1.97 www 4420: }
4421: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4422: if ($env{'form.displaylanguage'}) {
1.356 albertel 4423: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4424: $languages{$lang}=1;
1.97 www 4425: }
4426: }
4427: return %languages;
1.14 harris41 4428: }
4429:
1.582 albertel 4430: sub languages {
4431: my ($possible_langs) = @_;
1.695 raeburn 4432: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4433: if (!ref($possible_langs)) {
4434: if( wantarray ) {
4435: return @preferred_langs;
4436: } else {
4437: return $preferred_langs[0];
4438: }
4439: }
4440: my %possibilities = map { $_ => 1 } (@$possible_langs);
4441: my @preferred_possibilities;
4442: foreach my $preferred_lang (@preferred_langs) {
4443: if (exists($possibilities{$preferred_lang})) {
4444: push(@preferred_possibilities, $preferred_lang);
4445: }
4446: }
4447: if( wantarray ) {
4448: return @preferred_possibilities;
4449: }
4450: return $preferred_possibilities[0];
4451: }
4452:
1.742 raeburn 4453: sub user_lang {
4454: my ($touname,$toudom,$fromcid) = @_;
4455: my @userlangs;
4456: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4457: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4458: $env{'course.'.$fromcid.'.languages'}));
4459: } else {
4460: my %langhash = &getlangs($touname,$toudom);
4461: if ($langhash{'languages'} ne '') {
4462: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4463: } else {
4464: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4465: if ($domdefs{'lang_def'} ne '') {
4466: @userlangs = ($domdefs{'lang_def'});
4467: }
4468: }
4469: }
4470: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4471: my $user_lh = Apache::localize->get_handle(@languages);
4472: return $user_lh;
4473: }
4474:
4475:
1.112 bowersj2 4476: ###############################################################
4477: ## Student Answer Attempts ##
4478: ###############################################################
4479:
4480: =pod
4481:
4482: =head1 Alternate Problem Views
4483:
4484: =over 4
4485:
1.648 raeburn 4486: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4487: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4488:
4489: Return string with previous attempt on problem. Arguments:
4490:
4491: =over 4
4492:
4493: =item * $symb: Problem, including path
4494:
4495: =item * $username: username of the desired student
4496:
4497: =item * $domain: domain of the desired student
1.14 harris41 4498:
1.112 bowersj2 4499: =item * $course: Course ID
1.14 harris41 4500:
1.112 bowersj2 4501: =item * $getattempt: Leave blank for all attempts, otherwise put
4502: something
1.14 harris41 4503:
1.112 bowersj2 4504: =item * $regexp: if string matches this regexp, the string will be
4505: sent to $gradesub
1.14 harris41 4506:
1.112 bowersj2 4507: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4508:
1.1199 raeburn 4509: =item * $usec: section of the desired student
4510:
4511: =item * $identifier: counter for student (multiple students one problem) or
4512: problem (one student; whole sequence).
4513:
1.112 bowersj2 4514: =back
1.14 harris41 4515:
1.112 bowersj2 4516: The output string is a table containing all desired attempts, if any.
1.16 harris41 4517:
1.112 bowersj2 4518: =cut
1.1 albertel 4519:
4520: sub get_previous_attempt {
1.1199 raeburn 4521: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4522: my $prevattempts='';
1.43 ng 4523: no strict 'refs';
1.1 albertel 4524: if ($symb) {
1.3 albertel 4525: my (%returnhash)=
4526: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4527: if ($returnhash{'version'}) {
4528: my %lasthash=();
4529: my $version;
4530: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4531: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4532: if ($key =~ /\.rawrndseed$/) {
4533: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4534: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4535: } else {
4536: $lasthash{$key}=$returnhash{$version.':'.$key};
4537: }
1.19 harris41 4538: }
1.1 albertel 4539: }
1.596 albertel 4540: $prevattempts=&start_data_table().&start_data_table_header_row();
4541: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4542: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4543: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4544: foreach my $key (sort(keys(%lasthash))) {
4545: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4546: if ($#parts > 0) {
1.31 albertel 4547: my $data=$parts[-1];
1.989 raeburn 4548: next if ($data eq 'foilorder');
1.31 albertel 4549: pop(@parts);
1.1010 www 4550: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4551: if ($data eq 'type') {
4552: unless ($showsurv) {
4553: my $id = join(',',@parts);
4554: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4555: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4556: $lasthidden{$ign.'.'.$id} = 1;
4557: }
1.945 raeburn 4558: }
1.1199 raeburn 4559: if ($identifier ne '') {
4560: my $id = join(',',@parts);
4561: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4562: $domain,$username,$usec,undef,$course) =~ /^no/) {
4563: $hidestatus{$ign.'.'.$id} = 1;
4564: }
4565: }
4566: } elsif ($data eq 'regrader') {
4567: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4568: my $id = join(',',@parts);
4569: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4570: }
1.1010 www 4571: }
1.31 albertel 4572: } else {
1.41 ng 4573: if ($#parts == 0) {
4574: $prevattempts.='<th>'.$parts[0].'</th>';
4575: } else {
4576: $prevattempts.='<th>'.$ign.'</th>';
4577: }
1.31 albertel 4578: }
1.16 harris41 4579: }
1.596 albertel 4580: $prevattempts.=&end_data_table_header_row();
1.40 ng 4581: if ($getattempt eq '') {
1.1199 raeburn 4582: my (%solved,%resets,%probstatus);
1.1200 raeburn 4583: if (($identifier ne '') && (keys(%regraded) > 0)) {
4584: for ($version=1;$version<=$returnhash{'version'};$version++) {
4585: foreach my $id (keys(%regraded)) {
4586: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4587: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4588: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4589: push(@{$resets{$id}},$version);
1.1199 raeburn 4590: }
4591: }
4592: }
1.1200 raeburn 4593: }
4594: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4595: my (@hidden,@unsolved);
1.945 raeburn 4596: if (%typeparts) {
4597: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4598: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4599: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4600: push(@hidden,$id);
1.1199 raeburn 4601: } elsif ($identifier ne '') {
4602: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4603: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4604: ($hidestatus{$id})) {
1.1200 raeburn 4605: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4606: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4607: push(@{$solved{$id}},$version);
4608: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4609: (ref($solved{$id}) eq 'ARRAY')) {
4610: my $skip;
4611: if (ref($resets{$id}) eq 'ARRAY') {
4612: foreach my $reset (@{$resets{$id}}) {
4613: if ($reset > $solved{$id}[-1]) {
4614: $skip=1;
4615: last;
4616: }
4617: }
4618: }
4619: unless ($skip) {
4620: my ($ign,$partslist) = split(/\./,$id,2);
4621: push(@unsolved,$partslist);
4622: }
4623: }
4624: }
1.945 raeburn 4625: }
4626: }
4627: }
4628: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4629: '<td>'.&mt('Transaction [_1]',$version);
4630: if (@unsolved) {
4631: $prevattempts .= '<span class="LC_nobreak"><label>'.
4632: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4633: &mt('Hide').'</label></span>';
4634: }
4635: $prevattempts .= '</td>';
1.945 raeburn 4636: if (@hidden) {
4637: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4638: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4639: my $hide;
4640: foreach my $id (@hidden) {
4641: if ($key =~ /^\Q$id\E/) {
4642: $hide = 1;
4643: last;
4644: }
4645: }
4646: if ($hide) {
4647: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4648: if (($data eq 'award') || ($data eq 'awarddetail')) {
4649: my $value = &format_previous_attempt_value($key,
4650: $returnhash{$version.':'.$key});
1.1173 kruse 4651: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4652: } else {
4653: $prevattempts.='<td> </td>';
4654: }
4655: } else {
4656: if ($key =~ /\./) {
1.1212 raeburn 4657: my $value = $returnhash{$version.':'.$key};
4658: if ($key =~ /\.rndseed$/) {
4659: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4660: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4661: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4662: }
4663: }
4664: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4665: ' </td>';
1.945 raeburn 4666: } else {
4667: $prevattempts.='<td> </td>';
4668: }
4669: }
4670: }
4671: } else {
4672: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4673: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4674: my $value = $returnhash{$version.':'.$key};
4675: if ($key =~ /\.rndseed$/) {
4676: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4677: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4678: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4679: }
4680: }
4681: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4682: ' </td>';
1.945 raeburn 4683: }
4684: }
4685: $prevattempts.=&end_data_table_row();
1.40 ng 4686: }
1.1 albertel 4687: }
1.945 raeburn 4688: my @currhidden = keys(%lasthidden);
1.596 albertel 4689: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4690: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4691: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4692: if (%typeparts) {
4693: my $hidden;
4694: foreach my $id (@currhidden) {
4695: if ($key =~ /^\Q$id\E/) {
4696: $hidden = 1;
4697: last;
4698: }
4699: }
4700: if ($hidden) {
4701: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4702: if (($data eq 'award') || ($data eq 'awarddetail')) {
4703: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4704: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4705: $value = &$gradesub($value);
4706: }
1.1173 kruse 4707: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4708: } else {
4709: $prevattempts.='<td> </td>';
4710: }
4711: } else {
4712: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4713: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4714: $value = &$gradesub($value);
4715: }
1.1173 kruse 4716: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4717: }
4718: } else {
4719: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4720: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4721: $value = &$gradesub($value);
4722: }
1.1173 kruse 4723: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4724: }
1.16 harris41 4725: }
1.596 albertel 4726: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4727: } else {
1.1305 raeburn 4728: my $msg;
4729: if ($symb =~ /ext\.tool$/) {
4730: $msg = &mt('No grade passed back.');
4731: } else {
4732: $msg = &mt('Nothing submitted - no attempts.');
4733: }
1.596 albertel 4734: $prevattempts=
4735: &start_data_table().&start_data_table_row().
1.1305 raeburn 4736: '<td>'.$msg.'</td>'.
1.596 albertel 4737: &end_data_table_row().&end_data_table();
1.1 albertel 4738: }
4739: } else {
1.596 albertel 4740: $prevattempts=
4741: &start_data_table().&start_data_table_row().
4742: '<td>'.&mt('No data.').'</td>'.
4743: &end_data_table_row().&end_data_table();
1.1 albertel 4744: }
1.10 albertel 4745: }
4746:
1.581 albertel 4747: sub format_previous_attempt_value {
4748: my ($key,$value) = @_;
1.1011 www 4749: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4750: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4751: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4752: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4753: } elsif ($key =~ /answerstring$/) {
4754: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4755: my @answer = %answers;
4756: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4757: my @anskeys = sort(keys(%answers));
4758: if (@anskeys == 1) {
4759: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4760: if ($answer =~ m{\0}) {
4761: $answer =~ s{\0}{,}g;
1.988 raeburn 4762: }
4763: my $tag_internal_answer_name = 'INTERNAL';
4764: if ($anskeys[0] eq $tag_internal_answer_name) {
4765: $value = $answer;
4766: } else {
4767: $value = $anskeys[0].'='.$answer;
4768: }
4769: } else {
4770: foreach my $ans (@anskeys) {
4771: my $answer = $answers{$ans};
1.1001 raeburn 4772: if ($answer =~ m{\0}) {
4773: $answer =~ s{\0}{,}g;
1.988 raeburn 4774: }
4775: $value .= $ans.'='.$answer.'<br />';;
4776: }
4777: }
1.581 albertel 4778: } else {
1.1173 kruse 4779: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4780: }
4781: return $value;
4782: }
4783:
4784:
1.107 albertel 4785: sub relative_to_absolute {
4786: my ($url,$output)=@_;
4787: my $parser=HTML::TokeParser->new(\$output);
4788: my $token;
4789: my $thisdir=$url;
4790: my @rlinks=();
4791: while ($token=$parser->get_token) {
4792: if ($token->[0] eq 'S') {
4793: if ($token->[1] eq 'a') {
4794: if ($token->[2]->{'href'}) {
4795: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4796: }
4797: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4798: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4799: } elsif ($token->[1] eq 'base') {
4800: $thisdir=$token->[2]->{'href'};
4801: }
4802: }
4803: }
4804: $thisdir=~s-/[^/]*$--;
1.356 albertel 4805: foreach my $link (@rlinks) {
1.726 raeburn 4806: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4807: ($link=~/^\//) ||
4808: ($link=~/^javascript:/i) ||
4809: ($link=~/^mailto:/i) ||
4810: ($link=~/^\#/)) {
4811: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4812: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4813: }
4814: }
4815: # -------------------------------------------------- Deal with Applet codebases
4816: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4817: return $output;
4818: }
4819:
1.112 bowersj2 4820: =pod
4821:
1.648 raeburn 4822: =item * &get_student_view()
1.112 bowersj2 4823:
4824: show a snapshot of what student was looking at
4825:
4826: =cut
4827:
1.10 albertel 4828: sub get_student_view {
1.186 albertel 4829: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4830: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4831: my (%form);
1.10 albertel 4832: my @elements=('symb','courseid','domain','username');
4833: foreach my $element (@elements) {
1.186 albertel 4834: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4835: }
1.186 albertel 4836: if (defined($moreenv)) {
4837: %form=(%form,%{$moreenv});
4838: }
1.236 albertel 4839: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4840: $feedurl=&Apache::lonnet::clutter($feedurl);
1.1306 raeburn 4841: if (($feedurl =~ /ext\.tool$/) && ($target eq 'tex')) {
4842: $feedurl =~ s{^/adm/wrapper}{};
4843: }
1.650 www 4844: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4845: $userview=~s/\<body[^\>]*\>//gi;
4846: $userview=~s/\<\/body\>//gi;
4847: $userview=~s/\<html\>//gi;
4848: $userview=~s/\<\/html\>//gi;
4849: $userview=~s/\<head\>//gi;
4850: $userview=~s/\<\/head\>//gi;
4851: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4852: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4853: if (wantarray) {
4854: return ($userview,$response);
4855: } else {
4856: return $userview;
4857: }
4858: }
4859:
4860: sub get_student_view_with_retries {
4861: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4862:
4863: my $ok = 0; # True if we got a good response.
4864: my $content;
4865: my $response;
4866:
4867: # Try to get the student_view done. within the retries count:
4868:
4869: do {
4870: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4871: $ok = $response->is_success;
4872: if (!$ok) {
4873: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4874: }
4875: $retries--;
4876: } while (!$ok && ($retries > 0));
4877:
4878: if (!$ok) {
4879: $content = ''; # On error return an empty content.
4880: }
1.651 www 4881: if (wantarray) {
4882: return ($content, $response);
4883: } else {
4884: return $content;
4885: }
1.11 albertel 4886: }
4887:
1.112 bowersj2 4888: =pod
4889:
1.648 raeburn 4890: =item * &get_student_answers()
1.112 bowersj2 4891:
4892: show a snapshot of how student was answering problem
4893:
4894: =cut
4895:
1.11 albertel 4896: sub get_student_answers {
1.100 sakharuk 4897: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4898: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4899: my (%moreenv);
1.11 albertel 4900: my @elements=('symb','courseid','domain','username');
4901: foreach my $element (@elements) {
1.186 albertel 4902: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4903: }
1.186 albertel 4904: $moreenv{'grade_target'}='answer';
4905: %moreenv=(%form,%moreenv);
1.497 raeburn 4906: $feedurl = &Apache::lonnet::clutter($feedurl);
4907: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4908: return $userview;
1.1 albertel 4909: }
1.116 albertel 4910:
4911: =pod
4912:
4913: =item * &submlink()
4914:
1.242 albertel 4915: Inputs: $text $uname $udom $symb $target
1.116 albertel 4916:
4917: Returns: A link to grades.pm such as to see the SUBM view of a student
4918:
4919: =cut
4920:
4921: ###############################################
4922: sub submlink {
1.242 albertel 4923: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4924: if (!($uname && $udom)) {
4925: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4926: &Apache::lonnet::whichuser($symb);
1.116 albertel 4927: if (!$symb) { $symb=$cursymb; }
4928: }
1.254 matthew 4929: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4930: $symb=&escape($symb);
1.960 bisitz 4931: if ($target) { $target=" target=\"$target\""; }
4932: return
4933: '<a href="/adm/grades?command=submission'.
4934: '&symb='.$symb.
4935: '&student='.$uname.
4936: '&userdom='.$udom.'"'.
4937: $target.'>'.$text.'</a>';
1.242 albertel 4938: }
4939: ##############################################
4940:
4941: =pod
4942:
4943: =item * &pgrdlink()
4944:
4945: Inputs: $text $uname $udom $symb $target
4946:
4947: Returns: A link to grades.pm such as to see the PGRD view of a student
4948:
4949: =cut
4950:
4951: ###############################################
4952: sub pgrdlink {
4953: my $link=&submlink(@_);
4954: $link=~s/(&command=submission)/$1&showgrading=yes/;
4955: return $link;
4956: }
4957: ##############################################
4958:
4959: =pod
4960:
4961: =item * &pprmlink()
4962:
4963: Inputs: $text $uname $udom $symb $target
4964:
4965: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4966: student and a specific resource
1.242 albertel 4967:
4968: =cut
4969:
4970: ###############################################
4971: sub pprmlink {
4972: my ($text,$uname,$udom,$symb,$target)=@_;
4973: if (!($uname && $udom)) {
4974: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4975: &Apache::lonnet::whichuser($symb);
1.242 albertel 4976: if (!$symb) { $symb=$cursymb; }
4977: }
1.254 matthew 4978: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4979: $symb=&escape($symb);
1.242 albertel 4980: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4981: return '<a href="/adm/parmset?command=set&'.
4982: 'symb='.$symb.'&uname='.$uname.
4983: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4984: }
4985: ##############################################
1.37 matthew 4986:
1.112 bowersj2 4987: =pod
4988:
4989: =back
4990:
4991: =cut
4992:
1.37 matthew 4993: ###############################################
1.51 www 4994:
4995:
4996: sub timehash {
1.687 raeburn 4997: my ($thistime) = @_;
4998: my $timezone = &Apache::lonlocal::gettimezone();
4999: my $dt = DateTime->from_epoch(epoch => $thistime)
5000: ->set_time_zone($timezone);
5001: my $wday = $dt->day_of_week();
5002: if ($wday == 7) { $wday = 0; }
5003: return ( 'second' => $dt->second(),
5004: 'minute' => $dt->minute(),
5005: 'hour' => $dt->hour(),
5006: 'day' => $dt->day_of_month(),
5007: 'month' => $dt->month(),
5008: 'year' => $dt->year(),
5009: 'weekday' => $wday,
5010: 'dayyear' => $dt->day_of_year(),
5011: 'dlsav' => $dt->is_dst() );
1.51 www 5012: }
5013:
1.370 www 5014: sub utc_string {
5015: my ($date)=@_;
1.371 www 5016: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 5017: }
5018:
1.51 www 5019: sub maketime {
5020: my %th=@_;
1.687 raeburn 5021: my ($epoch_time,$timezone,$dt);
5022: $timezone = &Apache::lonlocal::gettimezone();
5023: eval {
5024: $dt = DateTime->new( year => $th{'year'},
5025: month => $th{'month'},
5026: day => $th{'day'},
5027: hour => $th{'hour'},
5028: minute => $th{'minute'},
5029: second => $th{'second'},
5030: time_zone => $timezone,
5031: );
5032: };
5033: if (!$@) {
5034: $epoch_time = $dt->epoch;
5035: if ($epoch_time) {
5036: return $epoch_time;
5037: }
5038: }
1.51 www 5039: return POSIX::mktime(
5040: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 5041: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 5042: }
5043:
5044: #########################################
1.51 www 5045:
5046: sub findallcourses {
1.482 raeburn 5047: my ($roles,$uname,$udom) = @_;
1.355 albertel 5048: my %roles;
5049: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 5050: my %courses;
1.51 www 5051: my $now=time;
1.482 raeburn 5052: if (!defined($uname)) {
5053: $uname = $env{'user.name'};
5054: }
5055: if (!defined($udom)) {
5056: $udom = $env{'user.domain'};
5057: }
5058: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 5059: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 5060: if (!%roles) {
5061: %roles = (
5062: cc => 1,
1.907 raeburn 5063: co => 1,
1.482 raeburn 5064: in => 1,
5065: ep => 1,
5066: ta => 1,
5067: cr => 1,
5068: st => 1,
5069: );
5070: }
5071: foreach my $entry (keys(%roleshash)) {
5072: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
5073: if ($trole =~ /^cr/) {
5074: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
5075: } else {
5076: next if (!exists($roles{$trole}));
5077: }
5078: if ($tend) {
5079: next if ($tend < $now);
5080: }
5081: if ($tstart) {
5082: next if ($tstart > $now);
5083: }
1.1058 raeburn 5084: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 5085: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5086: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5087: if ($secpart eq '') {
5088: ($cnum,$role) = split(/_/,$cnumpart);
5089: $sec = 'none';
1.1058 raeburn 5090: $value .= $cnum.'/';
1.482 raeburn 5091: } else {
5092: $cnum = $cnumpart;
5093: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5094: $value .= $cnum.'/'.$sec;
5095: }
5096: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5097: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5098: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5099: }
5100: } else {
5101: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5102: }
1.482 raeburn 5103: }
5104: } else {
5105: foreach my $key (keys(%env)) {
1.483 albertel 5106: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5107: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5108: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5109: next if ($role eq 'ca' || $role eq 'aa');
5110: next if (%roles && !exists($roles{$role}));
5111: my ($starttime,$endtime)=split(/\./,$env{$key});
5112: my $active=1;
5113: if ($starttime) {
5114: if ($now<$starttime) { $active=0; }
5115: }
5116: if ($endtime) {
5117: if ($now>$endtime) { $active=0; }
5118: }
5119: if ($active) {
1.1058 raeburn 5120: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5121: if ($sec eq '') {
5122: $sec = 'none';
1.1058 raeburn 5123: } else {
5124: $value .= $sec;
5125: }
5126: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5127: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5128: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5129: }
5130: } else {
5131: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5132: }
1.474 raeburn 5133: }
5134: }
1.51 www 5135: }
5136: }
1.474 raeburn 5137: return %courses;
1.51 www 5138: }
1.37 matthew 5139:
1.54 www 5140: ###############################################
1.474 raeburn 5141:
5142: sub blockcheck {
1.1189 raeburn 5143: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 5144:
1.1189 raeburn 5145: if (defined($udom) && defined($uname)) {
5146: # If uname and udom are for a course, check for blocks in the course.
5147: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5148: my ($startblock,$endblock,$triggerblock) =
5149: &get_blocks($setters,$activity,$udom,$uname,$url);
5150: return ($startblock,$endblock,$triggerblock);
5151: }
5152: } else {
1.490 raeburn 5153: $udom = $env{'user.domain'};
5154: $uname = $env{'user.name'};
5155: }
5156:
1.502 raeburn 5157: my $startblock = 0;
5158: my $endblock = 0;
1.1062 raeburn 5159: my $triggerblock = '';
1.482 raeburn 5160: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 5161:
1.490 raeburn 5162: # If uname is for a user, and activity is course-specific, i.e.,
5163: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5164:
1.490 raeburn 5165: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 5166: $activity eq 'groups' || $activity eq 'printout' ||
5167: $activity eq 'reinit' || $activity eq 'alert') &&
1.1189 raeburn 5168: ($env{'request.course.id'})) {
1.490 raeburn 5169: foreach my $key (keys(%live_courses)) {
5170: if ($key ne $env{'request.course.id'}) {
5171: delete($live_courses{$key});
5172: }
5173: }
5174: }
5175:
5176: my $otheruser = 0;
5177: my %own_courses;
5178: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5179: # Resource belongs to user other than current user.
5180: $otheruser = 1;
5181: # Gather courses for current user
5182: %own_courses =
5183: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5184: }
5185:
5186: # Gather active course roles - course coordinator, instructor,
5187: # exam proctor, ta, student, or custom role.
1.474 raeburn 5188:
5189: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5190: my ($cdom,$cnum);
5191: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5192: $cdom = $env{'course.'.$course.'.domain'};
5193: $cnum = $env{'course.'.$course.'.num'};
5194: } else {
1.490 raeburn 5195: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5196: }
5197: my $no_ownblock = 0;
5198: my $no_userblock = 0;
1.533 raeburn 5199: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5200: # Check if current user has 'evb' priv for this
5201: if (defined($own_courses{$course})) {
5202: foreach my $sec (keys(%{$own_courses{$course}})) {
5203: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5204: if ($sec ne 'none') {
5205: $checkrole .= '/'.$sec;
5206: }
5207: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5208: $no_ownblock = 1;
5209: last;
5210: }
5211: }
5212: }
5213: # if they have 'evb' priv and are currently not playing student
5214: next if (($no_ownblock) &&
5215: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5216: }
1.474 raeburn 5217: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5218: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5219: if ($sec ne 'none') {
1.482 raeburn 5220: $checkrole .= '/'.$sec;
1.474 raeburn 5221: }
1.490 raeburn 5222: if ($otheruser) {
5223: # Resource belongs to user other than current user.
5224: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5225: my (%allroles,%userroles);
5226: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5227: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5228: my ($trole,$tdom,$tnum,$tsec);
5229: if ($entry =~ /^cr/) {
5230: ($trole,$tdom,$tnum,$tsec) =
5231: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5232: } else {
5233: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5234: }
5235: my ($spec,$area,$trest);
5236: $area = '/'.$tdom.'/'.$tnum;
5237: $trest = $tnum;
5238: if ($tsec ne '') {
5239: $area .= '/'.$tsec;
5240: $trest .= '/'.$tsec;
5241: }
5242: $spec = $trole.'.'.$area;
5243: if ($trole =~ /^cr/) {
5244: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5245: $tdom,$spec,$trest,$area);
5246: } else {
5247: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5248: $tdom,$spec,$trest,$area);
5249: }
5250: }
1.1276 raeburn 5251: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5252: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5253: if ($1) {
5254: $no_userblock = 1;
5255: last;
5256: }
1.486 raeburn 5257: }
5258: }
1.490 raeburn 5259: } else {
5260: # Resource belongs to current user
5261: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5262: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5263: $no_ownblock = 1;
5264: last;
5265: }
1.474 raeburn 5266: }
5267: }
5268: # if they have the evb priv and are currently not playing student
1.482 raeburn 5269: next if (($no_ownblock) &&
1.491 albertel 5270: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5271: next if ($no_userblock);
1.474 raeburn 5272:
1.1303 raeburn 5273: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5274: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5275:
1.1062 raeburn 5276: my ($start,$end,$trigger) =
5277: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 5278: if (($start != 0) &&
5279: (($startblock == 0) || ($startblock > $start))) {
5280: $startblock = $start;
1.1062 raeburn 5281: if ($trigger ne '') {
5282: $triggerblock = $trigger;
5283: }
1.502 raeburn 5284: }
5285: if (($end != 0) &&
5286: (($endblock == 0) || ($endblock < $end))) {
5287: $endblock = $end;
1.1062 raeburn 5288: if ($trigger ne '') {
5289: $triggerblock = $trigger;
5290: }
1.502 raeburn 5291: }
1.490 raeburn 5292: }
1.1062 raeburn 5293: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5294: }
5295:
5296: sub get_blocks {
1.1062 raeburn 5297: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 5298: my $startblock = 0;
5299: my $endblock = 0;
1.1062 raeburn 5300: my $triggerblock = '';
1.490 raeburn 5301: my $course = $cdom.'_'.$cnum;
5302: $setters->{$course} = {};
5303: $setters->{$course}{'staff'} = [];
5304: $setters->{$course}{'times'} = [];
1.1062 raeburn 5305: $setters->{$course}{'triggers'} = [];
5306: my (@blockers,%triggered);
5307: my $now = time;
5308: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5309: if ($activity eq 'docs') {
5310: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
5311: foreach my $block (@blockers) {
5312: if ($block =~ /^firstaccess____(.+)$/) {
5313: my $item = $1;
5314: my $type = 'map';
5315: my $timersymb = $item;
5316: if ($item eq 'course') {
5317: $type = 'course';
5318: } elsif ($item =~ /___\d+___/) {
5319: $type = 'resource';
5320: } else {
5321: $timersymb = &Apache::lonnet::symbread($item);
5322: }
5323: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5324: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5325: $triggered{$block} = {
5326: start => $start,
5327: end => $end,
5328: type => $type,
5329: };
5330: }
5331: }
5332: } else {
5333: foreach my $block (keys(%commblocks)) {
5334: if ($block =~ m/^(\d+)____(\d+)$/) {
5335: my ($start,$end) = ($1,$2);
5336: if ($start <= time && $end >= time) {
5337: if (ref($commblocks{$block}) eq 'HASH') {
5338: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5339: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5340: unless(grep(/^\Q$block\E$/,@blockers)) {
5341: push(@blockers,$block);
5342: }
5343: }
5344: }
5345: }
5346: }
5347: } elsif ($block =~ /^firstaccess____(.+)$/) {
5348: my $item = $1;
5349: my $timersymb = $item;
5350: my $type = 'map';
5351: if ($item eq 'course') {
5352: $type = 'course';
5353: } elsif ($item =~ /___\d+___/) {
5354: $type = 'resource';
5355: } else {
5356: $timersymb = &Apache::lonnet::symbread($item);
5357: }
5358: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5359: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5360: if ($start && $end) {
5361: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 5362: if (ref($commblocks{$block}) eq 'HASH') {
5363: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5364: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5365: unless(grep(/^\Q$block\E$/,@blockers)) {
5366: push(@blockers,$block);
5367: $triggered{$block} = {
5368: start => $start,
5369: end => $end,
5370: type => $type,
5371: };
5372: }
5373: }
5374: }
1.1062 raeburn 5375: }
5376: }
1.490 raeburn 5377: }
1.1062 raeburn 5378: }
5379: }
5380: }
5381: foreach my $blocker (@blockers) {
5382: my ($staff_name,$staff_dom,$title,$blocks) =
5383: &parse_block_record($commblocks{$blocker});
5384: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5385: my ($start,$end,$triggertype);
5386: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5387: ($start,$end) = ($1,$2);
5388: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5389: $start = $triggered{$blocker}{'start'};
5390: $end = $triggered{$blocker}{'end'};
5391: $triggertype = $triggered{$blocker}{'type'};
5392: }
5393: if ($start) {
5394: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5395: if ($triggertype) {
5396: push(@{$$setters{$course}{'triggers'}},$triggertype);
5397: } else {
5398: push(@{$$setters{$course}{'triggers'}},0);
5399: }
5400: if ( ($startblock == 0) || ($startblock > $start) ) {
5401: $startblock = $start;
5402: if ($triggertype) {
5403: $triggerblock = $blocker;
1.474 raeburn 5404: }
5405: }
1.1062 raeburn 5406: if ( ($endblock == 0) || ($endblock < $end) ) {
5407: $endblock = $end;
5408: if ($triggertype) {
5409: $triggerblock = $blocker;
5410: }
5411: }
1.474 raeburn 5412: }
5413: }
1.1062 raeburn 5414: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5415: }
5416:
5417: sub parse_block_record {
5418: my ($record) = @_;
5419: my ($setuname,$setudom,$title,$blocks);
5420: if (ref($record) eq 'HASH') {
5421: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5422: $title = &unescape($record->{'event'});
5423: $blocks = $record->{'blocks'};
5424: } else {
5425: my @data = split(/:/,$record,3);
5426: if (scalar(@data) eq 2) {
5427: $title = $data[1];
5428: ($setuname,$setudom) = split(/@/,$data[0]);
5429: } else {
5430: ($setuname,$setudom,$title) = @data;
5431: }
5432: $blocks = { 'com' => 'on' };
5433: }
5434: return ($setuname,$setudom,$title,$blocks);
5435: }
5436:
1.854 kalberla 5437: sub blocking_status {
1.1189 raeburn 5438: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 5439: my %setters;
1.890 droeschl 5440:
1.1061 raeburn 5441: # check for active blocking
1.1062 raeburn 5442: my ($startblock,$endblock,$triggerblock) =
1.1189 raeburn 5443: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 5444: my $blocked = 0;
5445: if ($startblock && $endblock) {
5446: $blocked = 1;
5447: }
1.890 droeschl 5448:
1.1061 raeburn 5449: # caller just wants to know whether a block is active
5450: if (!wantarray) { return $blocked; }
5451:
5452: # build a link to a popup window containing the details
5453: my $querystring = "?activity=$activity";
5454: # $uname and $udom decide whose portfolio the user is trying to look at
1.1232 raeburn 5455: if (($activity eq 'port') || ($activity eq 'passwd')) {
5456: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5457: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5458: } elsif ($activity eq 'docs') {
5459: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
5460: }
1.1061 raeburn 5461:
5462: my $output .= <<'END_MYBLOCK';
5463: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5464: var options = "width=" + w + ",height=" + h + ",";
5465: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5466: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5467: var newWin = window.open(url, wdwName, options);
5468: newWin.focus();
5469: }
1.890 droeschl 5470: END_MYBLOCK
1.854 kalberla 5471:
1.1061 raeburn 5472: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5473:
1.1061 raeburn 5474: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5475: my $text = &mt('Communication Blocked');
1.1217 raeburn 5476: my $class = 'LC_comblock';
1.1062 raeburn 5477: if ($activity eq 'docs') {
5478: $text = &mt('Content Access Blocked');
1.1217 raeburn 5479: $class = '';
1.1063 raeburn 5480: } elsif ($activity eq 'printout') {
5481: $text = &mt('Printing Blocked');
1.1232 raeburn 5482: } elsif ($activity eq 'passwd') {
5483: $text = &mt('Password Changing Blocked');
1.1282 raeburn 5484: } elsif ($activity eq 'alert') {
5485: $text = &mt('Checking Critical Messages Blocked');
5486: } elsif ($activity eq 'reinit') {
5487: $text = &mt('Checking Course Update Blocked');
1.1062 raeburn 5488: }
1.1061 raeburn 5489: $output .= <<"END_BLOCK";
1.1217 raeburn 5490: <div class='$class'>
1.869 kalberla 5491: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5492: title='$text'>
5493: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5494: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5495: title='$text'>$text</a>
1.867 kalberla 5496: </div>
5497:
5498: END_BLOCK
1.474 raeburn 5499:
1.1061 raeburn 5500: return ($blocked, $output);
1.854 kalberla 5501: }
1.490 raeburn 5502:
1.60 matthew 5503: ###############################################
5504:
1.682 raeburn 5505: sub check_ip_acc {
1.1201 raeburn 5506: my ($acc,$clientip)=@_;
1.682 raeburn 5507: &Apache::lonxml::debug("acc is $acc");
5508: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5509: return 1;
5510: }
1.1219 raeburn 5511: my $allowed;
1.1252 raeburn 5512: my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
1.682 raeburn 5513:
5514: my $name;
1.1219 raeburn 5515: my %access = (
5516: allowfrom => 1,
5517: denyfrom => 0,
5518: );
5519: my @allows;
5520: my @denies;
5521: foreach my $item (split(',',$acc)) {
5522: $item =~ s/^\s*//;
5523: $item =~ s/\s*$//;
5524: my $pattern;
5525: if ($item =~ /^\!(.+)$/) {
5526: push(@denies,$1);
5527: } else {
5528: push(@allows,$item);
5529: }
5530: }
5531: my $numdenies = scalar(@denies);
5532: my $numallows = scalar(@allows);
5533: my $count = 0;
5534: foreach my $pattern (@denies,@allows) {
5535: $count ++;
5536: my $acctype = 'allowfrom';
5537: if ($count <= $numdenies) {
5538: $acctype = 'denyfrom';
5539: }
1.682 raeburn 5540: if ($pattern =~ /\*$/) {
5541: #35.8.*
5542: $pattern=~s/\*//;
1.1219 raeburn 5543: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5544: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5545: #35.8.3.[34-56]
5546: my $low=$2;
5547: my $high=$3;
5548: $pattern=$1;
5549: if ($ip =~ /^\Q$pattern\E/) {
5550: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5551: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5552: }
5553: } elsif ($pattern =~ /^\*/) {
5554: #*.msu.edu
5555: $pattern=~s/\*//;
5556: if (!defined($name)) {
5557: use Socket;
5558: my $netaddr=inet_aton($ip);
5559: ($name)=gethostbyaddr($netaddr,AF_INET);
5560: }
1.1219 raeburn 5561: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5562: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5563: #127.0.0.1
1.1219 raeburn 5564: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5565: } else {
5566: #some.name.com
5567: if (!defined($name)) {
5568: use Socket;
5569: my $netaddr=inet_aton($ip);
5570: ($name)=gethostbyaddr($netaddr,AF_INET);
5571: }
1.1219 raeburn 5572: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5573: }
5574: if ($allowed =~ /^(0|1)$/) { last; }
5575: }
5576: if ($allowed eq '') {
5577: if ($numdenies && !$numallows) {
5578: $allowed = 1;
5579: } else {
5580: $allowed = 0;
1.682 raeburn 5581: }
5582: }
5583: return $allowed;
5584: }
5585:
5586: ###############################################
5587:
1.60 matthew 5588: =pod
5589:
1.112 bowersj2 5590: =head1 Domain Template Functions
5591:
5592: =over 4
5593:
5594: =item * &determinedomain()
1.60 matthew 5595:
5596: Inputs: $domain (usually will be undef)
5597:
1.63 www 5598: Returns: Determines which domain should be used for designs
1.60 matthew 5599:
5600: =cut
1.54 www 5601:
1.60 matthew 5602: ###############################################
1.63 www 5603: sub determinedomain {
5604: my $domain=shift;
1.531 albertel 5605: if (! $domain) {
1.60 matthew 5606: # Determine domain if we have not been given one
1.893 raeburn 5607: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5608: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5609: if ($env{'request.role.domain'}) {
5610: $domain=$env{'request.role.domain'};
1.60 matthew 5611: }
5612: }
1.63 www 5613: return $domain;
5614: }
5615: ###############################################
1.517 raeburn 5616:
1.518 albertel 5617: sub devalidate_domconfig_cache {
5618: my ($udom)=@_;
5619: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5620: }
5621:
5622: # ---------------------- Get domain configuration for a domain
5623: sub get_domainconf {
5624: my ($udom) = @_;
5625: my $cachetime=1800;
5626: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5627: if (defined($cached)) { return %{$result}; }
5628:
5629: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5630: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5631: my (%designhash,%legacy);
1.518 albertel 5632: if (keys(%domconfig) > 0) {
5633: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5634: if (keys(%{$domconfig{'login'}})) {
5635: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5636: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5637: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5638: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5639: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5640: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5641: if ($key eq 'loginvia') {
5642: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5643: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5644: $designhash{$udom.'.login.loginvia'} = $server;
5645: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5646:
5647: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5648: } else {
5649: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5650: }
1.948 raeburn 5651: }
1.1208 raeburn 5652: } elsif ($key eq 'headtag') {
5653: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5654: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5655: }
1.946 raeburn 5656: }
1.1208 raeburn 5657: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5658: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5659: }
1.946 raeburn 5660: }
5661: }
5662: }
5663: } else {
5664: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5665: $designhash{$udom.'.login.'.$key.'_'.$img} =
5666: $domconfig{'login'}{$key}{$img};
5667: }
1.699 raeburn 5668: }
5669: } else {
5670: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5671: }
1.632 raeburn 5672: }
5673: } else {
5674: $legacy{'login'} = 1;
1.518 albertel 5675: }
1.632 raeburn 5676: } else {
5677: $legacy{'login'} = 1;
1.518 albertel 5678: }
5679: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5680: if (keys(%{$domconfig{'rolecolors'}})) {
5681: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5682: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5683: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5684: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5685: }
1.518 albertel 5686: }
5687: }
1.632 raeburn 5688: } else {
5689: $legacy{'rolecolors'} = 1;
1.518 albertel 5690: }
1.632 raeburn 5691: } else {
5692: $legacy{'rolecolors'} = 1;
1.518 albertel 5693: }
1.948 raeburn 5694: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5695: if ($domconfig{'autoenroll'}{'co-owners'}) {
5696: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5697: }
5698: }
1.632 raeburn 5699: if (keys(%legacy) > 0) {
5700: my %legacyhash = &get_legacy_domconf($udom);
5701: foreach my $item (keys(%legacyhash)) {
5702: if ($item =~ /^\Q$udom\E\.login/) {
5703: if ($legacy{'login'}) {
5704: $designhash{$item} = $legacyhash{$item};
5705: }
5706: } else {
5707: if ($legacy{'rolecolors'}) {
5708: $designhash{$item} = $legacyhash{$item};
5709: }
1.518 albertel 5710: }
5711: }
5712: }
1.632 raeburn 5713: } else {
5714: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5715: }
5716: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5717: $cachetime);
5718: return %designhash;
5719: }
5720:
1.632 raeburn 5721: sub get_legacy_domconf {
5722: my ($udom) = @_;
5723: my %legacyhash;
5724: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5725: my $designfile = $designdir.'/'.$udom.'.tab';
5726: if (-e $designfile) {
1.1317 raeburn 5727: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5728: while (my $line = <$fh>) {
5729: next if ($line =~ /^\#/);
5730: chomp($line);
5731: my ($key,$val)=(split(/\=/,$line));
5732: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5733: }
5734: close($fh);
5735: }
5736: }
1.1026 raeburn 5737: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5738: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5739: }
5740: return %legacyhash;
5741: }
5742:
1.63 www 5743: =pod
5744:
1.112 bowersj2 5745: =item * &domainlogo()
1.63 www 5746:
5747: Inputs: $domain (usually will be undef)
5748:
5749: Returns: A link to a domain logo, if the domain logo exists.
5750: If the domain logo does not exist, a description of the domain.
5751:
5752: =cut
1.112 bowersj2 5753:
1.63 www 5754: ###############################################
5755: sub domainlogo {
1.517 raeburn 5756: my $domain = &determinedomain(shift);
1.518 albertel 5757: my %designhash = &get_domainconf($domain);
1.517 raeburn 5758: # See if there is a logo
5759: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5760: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5761: if ($imgsrc =~ m{^/(adm|res)/}) {
5762: if ($imgsrc =~ m{^/res/}) {
5763: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5764: &Apache::lonnet::repcopy($local_name);
5765: }
5766: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5767: }
5768: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5769: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5770: return &Apache::lonnet::domain($domain,'description');
1.59 www 5771: } else {
1.60 matthew 5772: return '';
1.59 www 5773: }
5774: }
1.63 www 5775: ##############################################
5776:
5777: =pod
5778:
1.112 bowersj2 5779: =item * &designparm()
1.63 www 5780:
5781: Inputs: $which parameter; $domain (usually will be undef)
5782:
5783: Returns: value of designparamter $which
5784:
5785: =cut
1.112 bowersj2 5786:
1.397 albertel 5787:
1.400 albertel 5788: ##############################################
1.397 albertel 5789: sub designparm {
5790: my ($which,$domain)=@_;
5791: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5792: return $env{'environment.color.'.$which};
1.96 www 5793: }
1.63 www 5794: $domain=&determinedomain($domain);
1.1016 raeburn 5795: my %domdesign;
5796: unless ($domain eq 'public') {
5797: %domdesign = &get_domainconf($domain);
5798: }
1.520 raeburn 5799: my $output;
1.517 raeburn 5800: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5801: $output = $domdesign{$domain.'.'.$which};
1.63 www 5802: } else {
1.520 raeburn 5803: $output = $defaultdesign{$which};
5804: }
5805: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5806: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5807: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5808: if ($output =~ m{^/res/}) {
5809: my $local_name = &Apache::lonnet::filelocation('',$output);
5810: &Apache::lonnet::repcopy($local_name);
5811: }
1.520 raeburn 5812: $output = &lonhttpdurl($output);
5813: }
1.63 www 5814: }
1.520 raeburn 5815: return $output;
1.63 www 5816: }
1.59 www 5817:
1.822 bisitz 5818: ##############################################
5819: =pod
5820:
1.832 bisitz 5821: =item * &authorspace()
5822:
1.1028 raeburn 5823: Inputs: $url (usually will be undef).
1.832 bisitz 5824:
1.1132 raeburn 5825: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5826: directory being viewed (or for which action is being taken).
5827: If $url is provided, and begins /priv/<domain>/<uname>
5828: the path will be that portion of the $context argument.
5829: Otherwise the path will be for the author space of the current
5830: user when the current role is author, or for that of the
5831: co-author/assistant co-author space when the current role
5832: is co-author or assistant co-author.
1.832 bisitz 5833:
5834: =cut
5835:
5836: sub authorspace {
1.1028 raeburn 5837: my ($url) = @_;
5838: if ($url ne '') {
5839: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5840: return $1;
5841: }
5842: }
1.832 bisitz 5843: my $caname = '';
1.1024 www 5844: my $cadom = '';
1.1028 raeburn 5845: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5846: ($cadom,$caname) =
1.832 bisitz 5847: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5848: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5849: $caname = $env{'user.name'};
1.1024 www 5850: $cadom = $env{'user.domain'};
1.832 bisitz 5851: }
1.1028 raeburn 5852: if (($caname ne '') && ($cadom ne '')) {
5853: return "/priv/$cadom/$caname/";
5854: }
5855: return;
1.832 bisitz 5856: }
5857:
5858: ##############################################
5859: =pod
5860:
1.822 bisitz 5861: =item * &head_subbox()
5862:
5863: Inputs: $content (contains HTML code with page functions, etc.)
5864:
5865: Returns: HTML div with $content
5866: To be included in page header
5867:
5868: =cut
5869:
5870: sub head_subbox {
5871: my ($content)=@_;
5872: my $output =
1.993 raeburn 5873: '<div class="LC_head_subbox">'
1.822 bisitz 5874: .$content
5875: .'</div>'
5876: }
5877:
5878: ##############################################
5879: =pod
5880:
5881: =item * &CSTR_pageheader()
5882:
1.1026 raeburn 5883: Input: (optional) filename from which breadcrumb trail is built.
5884: In most cases no input as needed, as $env{'request.filename'}
5885: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5886:
5887: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5888: To be included on Authoring Space pages
1.822 bisitz 5889:
5890: =cut
5891:
5892: sub CSTR_pageheader {
1.1026 raeburn 5893: my ($trailfile) = @_;
5894: if ($trailfile eq '') {
5895: $trailfile = $env{'request.filename'};
5896: }
5897:
5898: # this is for resources; directories have customtitle, and crumbs
5899: # and select recent are created in lonpubdir.pm
5900:
5901: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5902: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5903: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5904: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5905: $formaction =~ s{/+}{/}g;
1.822 bisitz 5906:
5907: my $parentpath = '';
5908: my $lastitem = '';
5909: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5910: $parentpath = $1;
5911: $lastitem = $2;
5912: } else {
5913: $lastitem = $thisdisfn;
5914: }
1.921 bisitz 5915:
1.1246 raeburn 5916: my ($crsauthor,$title);
5917: if (($env{'request.course.id'}) &&
5918: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 5919: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 5920: $crsauthor = 1;
5921: $title = &mt('Course Authoring Space');
5922: } else {
5923: $title = &mt('Authoring Space');
5924: }
5925:
1.1314 raeburn 5926: my ($target,$crumbtarget) = (' target="_top"','_top'); #FIXME lonpubdir: target="_parent"
1.1313 raeburn 5927: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1.1314 raeburn 5928: $target = '';
5929: $crumbtarget = '';
1.1313 raeburn 5930: }
5931:
1.921 bisitz 5932: my $output =
1.822 bisitz 5933: '<div>'
5934: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 5935: .'<b>'.$title.'</b> '
1.1314 raeburn 5936: .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
5937: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 5938:
5939: if ($lastitem) {
5940: $output .=
5941: '<span class="LC_filename">'
5942: .$lastitem
5943: .'</span>';
5944: }
1.1245 raeburn 5945:
1.1246 raeburn 5946: if ($crsauthor) {
5947: $output .= '</form>'.&Apache::lonmenu::constspaceform();
5948: } else {
5949: $output .=
5950: '<br />'
1.1314 raeburn 5951: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.1246 raeburn 5952: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5953: .'</form>'
5954: .&Apache::lonmenu::constspaceform();
5955: }
5956: $output .= '</div>';
1.921 bisitz 5957:
5958: return $output;
1.822 bisitz 5959: }
5960:
1.60 matthew 5961: ###############################################
5962: ###############################################
5963:
5964: =pod
5965:
1.112 bowersj2 5966: =back
5967:
1.549 albertel 5968: =head1 HTML Helpers
1.112 bowersj2 5969:
5970: =over 4
5971:
5972: =item * &bodytag()
1.60 matthew 5973:
5974: Returns a uniform header for LON-CAPA web pages.
5975:
5976: Inputs:
5977:
1.112 bowersj2 5978: =over 4
5979:
5980: =item * $title, A title to be displayed on the page.
5981:
5982: =item * $function, the current role (can be undef).
5983:
5984: =item * $addentries, extra parameters for the <body> tag.
5985:
5986: =item * $bodyonly, if defined, only return the <body> tag.
5987:
5988: =item * $domain, if defined, force a given domain.
5989:
5990: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5991: text interface only)
1.60 matthew 5992:
1.814 bisitz 5993: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5994: navigational links
1.317 albertel 5995:
1.338 albertel 5996: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5997:
1.460 albertel 5998: =item * $args, optional argument valid values are
5999: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 6000: use_absolute -> for external resource or syllabus, this will
6001: contain https://<hostname> if server uses
6002: https (as per hosts.tab), but request is for http
6003: hostname -> hostname, from $r->hostname().
1.460 albertel 6004:
1.1096 raeburn 6005: =item * $advtoolsref, optional argument, ref to an array containing
6006: inlineremote items to be added in "Functions" menu below
6007: breadcrumbs.
6008:
1.1316 raeburn 6009: =item * $ltiscope, optional argument, will be one of: resource, map or
6010: course, if LON-CAPA is in LTI Provider context. Value is
6011: the scope of use, i.e., launch was for access to a single, a map
6012: or the entire course.
6013:
6014: =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6015: context, this will contain the URL for the landing item in
6016: the course, after launch from an LTI Consumer
6017:
1.1318 raeburn 6018: =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6019: context, this will contain a reference to hash of items
6020: to be included in the page header and/or inline menu.
6021:
1.112 bowersj2 6022: =back
6023:
1.60 matthew 6024: Returns: A uniform header for LON-CAPA web pages.
6025: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6026: If $bodyonly is undef or zero, an html string containing a <body> tag and
6027: other decorations will be returned.
6028:
6029: =cut
6030:
1.54 www 6031: sub bodytag {
1.831 bisitz 6032: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1318 raeburn 6033: $no_nav_bar,$bgcolor,$args,$advtoolsref,$ltiscope,$ltiuri,$ltimenu)=@_;
1.339 albertel 6034:
1.954 raeburn 6035: my $public;
6036: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6037: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6038: $public = 1;
6039: }
1.460 albertel 6040: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 6041: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 6042: my $hostname = $args->{'hostname'};
1.339 albertel 6043:
1.183 matthew 6044: $function = &get_users_function() if (!$function);
1.339 albertel 6045: my $img = &designparm($function.'.img',$domain);
6046: my $font = &designparm($function.'.font',$domain);
6047: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6048:
1.803 bisitz 6049: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6050: 'bgcolor' => $pgbg,
1.339 albertel 6051: 'text' => $font,
6052: 'alink' => &designparm($function.'.alink',$domain),
6053: 'vlink' => &designparm($function.'.vlink',$domain),
6054: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6055: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6056:
1.63 www 6057: # role and realm
1.1178 raeburn 6058: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6059: if ($realm) {
6060: $realm = '/'.$realm;
6061: }
1.378 raeburn 6062: if ($role eq 'ca') {
1.479 albertel 6063: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6064: $realm = &plainname($rname,$rdom);
1.378 raeburn 6065: }
1.55 www 6066: # realm
1.258 albertel 6067: if ($env{'request.course.id'}) {
1.378 raeburn 6068: if ($env{'request.role'} !~ /^cr/) {
6069: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 6070: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 6071: if ($env{'request.role.desc'}) {
6072: $role = $env{'request.role.desc'};
6073: } else {
6074: $role = &mt('Helpdesk[_1]',' '.$2);
6075: }
1.1257 raeburn 6076: } else {
6077: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6078: }
1.898 raeburn 6079: if ($env{'request.course.sec'}) {
6080: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
6081: }
1.359 albertel 6082: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 6083: } else {
6084: $role = &Apache::lonnet::plaintext($role);
1.54 www 6085: }
1.433 albertel 6086:
1.359 albertel 6087: if (!$realm) { $realm=' '; }
1.330 albertel 6088:
1.438 albertel 6089: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6090:
1.101 www 6091: # construct main body tag
1.359 albertel 6092: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6093: &Apache::lontexconvert::init_math_support();
1.252 albertel 6094:
1.1131 raeburn 6095: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6096:
1.1130 raeburn 6097: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6098: return $bodytag;
1.1130 raeburn 6099: }
1.359 albertel 6100:
1.954 raeburn 6101: if ($public) {
1.433 albertel 6102: undef($role);
6103: }
1.1318 raeburn 6104:
6105: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
6106: if (ref($ltimenu) eq 'HASH') {
6107: unless ($ltimenu->{'role'}) {
6108: undef($role);
6109: }
6110: unless ($ltimenu->{'coursetitle'}) {
6111: $realm=' ';
6112: }
6113: }
6114: }
6115:
1.762 bisitz 6116: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6117: #
6118: # Extra info if you are the DC
6119: my $dc_info = '';
6120: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
6121: $env{'course.'.$env{'request.course.id'}.
6122: '.domain'}.'/'})) {
6123: my $cid = $env{'request.course.id'};
1.917 raeburn 6124: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6125: $dc_info =~ s/\s+$//;
1.359 albertel 6126: }
6127:
1.1237 raeburn 6128: my $crstype;
6129: if ($env{'request.course.id'}) {
6130: $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
6131: } elsif ($args->{'crstype'}) {
6132: $crstype = $args->{'crstype'};
6133: }
6134: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
6135: undef($role);
6136: } else {
1.1242 raeburn 6137: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 6138: }
1.853 droeschl 6139:
1.903 droeschl 6140: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6141:
6142: # if ($env{'request.state'} eq 'construct') {
6143: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6144: # }
6145:
1.1130 raeburn 6146: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 6147: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6148:
1.1318 raeburn 6149: unless ($args->{'no_primary_menu'}) {
6150: my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu);
1.359 albertel 6151:
1.1318 raeburn 6152: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6153: if ($dc_info) {
6154: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6155: }
6156: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6157: <em>$realm</em> $dc_info</div>|;
6158: return $bodytag;
6159: }
1.894 droeschl 6160:
1.1318 raeburn 6161: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6162: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6163: }
1.916 droeschl 6164:
1.1318 raeburn 6165: $bodytag .= $right;
1.852 droeschl 6166:
1.1318 raeburn 6167: if ($dc_info) {
6168: $dc_info = &dc_courseid_toggle($dc_info);
6169: }
6170: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6171: }
1.916 droeschl 6172:
1.1169 raeburn 6173: #if directed to not display the secondary menu, don't.
1.1168 raeburn 6174: if ($args->{'no_secondary_menu'}) {
6175: return $bodytag;
6176: }
1.1169 raeburn 6177: #don't show menus for public users
1.954 raeburn 6178: if (!$public){
1.1318 raeburn 6179: unless ($args->{'no_inline_menu'}) {
6180: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
6181: $args->{'no_primary_menu'});
6182: }
1.903 droeschl 6183: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6184: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6185: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6186: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1316 raeburn 6187: $args->{'bread_crumbs'},'','',$hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6188: } elsif ($forcereg) {
6189: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1258 raeburn 6190: $args->{'group'},
1.1274 raeburn 6191: $args->{'hide_buttons'},
1.1316 raeburn 6192: $hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6193: } else {
6194: $bodytag .=
6195: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6196: $forcereg,$args->{'group'},
6197: $args->{'bread_crumbs'},
1.1274 raeburn 6198: $advtoolsref,'',$hostname);
1.920 raeburn 6199: }
1.903 droeschl 6200: }else{
6201: # this is to seperate menu from content when there's no secondary
6202: # menu. Especially needed for public accessible ressources.
6203: $bodytag .= '<hr style="clear:both" />';
6204: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6205: }
1.903 droeschl 6206:
1.235 raeburn 6207: return $bodytag;
1.182 matthew 6208: }
6209:
1.917 raeburn 6210: sub dc_courseid_toggle {
6211: my ($dc_info) = @_;
1.980 raeburn 6212: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6213: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6214: &mt('(More ...)').'</a></span>'.
6215: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6216: }
6217:
1.330 albertel 6218: sub make_attr_string {
6219: my ($register,$attr_ref) = @_;
6220:
6221: if ($attr_ref && !ref($attr_ref)) {
6222: die("addentries Must be a hash ref ".
6223: join(':',caller(1))." ".
6224: join(':',caller(0))." ");
6225: }
6226:
6227: if ($register) {
1.339 albertel 6228: my ($on_load,$on_unload);
6229: foreach my $key (keys(%{$attr_ref})) {
6230: if (lc($key) eq 'onload') {
6231: $on_load.=$attr_ref->{$key}.';';
6232: delete($attr_ref->{$key});
6233:
6234: } elsif (lc($key) eq 'onunload') {
6235: $on_unload.=$attr_ref->{$key}.';';
6236: delete($attr_ref->{$key});
6237: }
6238: }
1.953 droeschl 6239: $attr_ref->{'onload'} = $on_load;
6240: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6241: }
1.339 albertel 6242:
1.330 albertel 6243: my $attr_string;
1.1159 raeburn 6244: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6245: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6246: }
6247: return $attr_string;
6248: }
6249:
6250:
1.182 matthew 6251: ###############################################
1.251 albertel 6252: ###############################################
6253:
6254: =pod
6255:
6256: =item * &endbodytag()
6257:
6258: Returns a uniform footer for LON-CAPA web pages.
6259:
1.635 raeburn 6260: Inputs: 1 - optional reference to an args hash
6261: If in the hash, key for noredirectlink has a value which evaluates to true,
6262: a 'Continue' link is not displayed if the page contains an
6263: internal redirect in the <head></head> section,
6264: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6265:
6266: =cut
6267:
6268: sub endbodytag {
1.635 raeburn 6269: my ($args) = @_;
1.1080 raeburn 6270: my $endbodytag;
6271: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6272: $endbodytag='</body>';
6273: }
1.315 albertel 6274: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6275: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6276: $endbodytag=
6277: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6278: &mt('Continue').'</a>'.
6279: $endbodytag;
6280: }
1.315 albertel 6281: }
1.251 albertel 6282: return $endbodytag;
6283: }
6284:
1.352 albertel 6285: =pod
6286:
6287: =item * &standard_css()
6288:
6289: Returns a style sheet
6290:
6291: Inputs: (all optional)
6292: domain -> force to color decorate a page for a specific
6293: domain
6294: function -> force usage of a specific rolish color scheme
6295: bgcolor -> override the default page bgcolor
6296:
6297: =cut
6298:
1.343 albertel 6299: sub standard_css {
1.345 albertel 6300: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6301: $function = &get_users_function() if (!$function);
6302: my $img = &designparm($function.'.img', $domain);
6303: my $tabbg = &designparm($function.'.tabbg', $domain);
6304: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6305: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6306: #second colour for later usage
1.345 albertel 6307: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6308: my $pgbg_or_bgcolor =
6309: $bgcolor ||
1.352 albertel 6310: &designparm($function.'.pgbg', $domain);
1.382 albertel 6311: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6312: my $alink = &designparm($function.'.alink', $domain);
6313: my $vlink = &designparm($function.'.vlink', $domain);
6314: my $link = &designparm($function.'.link', $domain);
6315:
1.602 albertel 6316: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6317: my $mono = 'monospace';
1.850 bisitz 6318: my $data_table_head = $sidebg;
6319: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6320: my $data_table_dark = '#E0E0E0';
1.470 banghart 6321: my $data_table_darker = '#CCCCCC';
1.349 albertel 6322: my $data_table_highlight = '#FFFF00';
1.352 albertel 6323: my $mail_new = '#FFBB77';
6324: my $mail_new_hover = '#DD9955';
6325: my $mail_read = '#BBBB77';
6326: my $mail_read_hover = '#999944';
6327: my $mail_replied = '#AAAA88';
6328: my $mail_replied_hover = '#888855';
6329: my $mail_other = '#99BBBB';
6330: my $mail_other_hover = '#669999';
1.391 albertel 6331: my $table_header = '#DDDDDD';
1.489 raeburn 6332: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6333: my $lg_border_color = '#C8C8C8';
1.952 onken 6334: my $button_hover = '#BF2317';
1.392 albertel 6335:
1.608 albertel 6336: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6337: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6338: : '0 3px 0 4px';
1.448 albertel 6339:
1.523 albertel 6340:
1.343 albertel 6341: return <<END;
1.947 droeschl 6342:
6343: /* needed for iframe to allow 100% height in FF */
6344: body, html {
6345: margin: 0;
6346: padding: 0 0.5%;
6347: height: 99%; /* to avoid scrollbars */
6348: }
6349:
1.795 www 6350: body {
1.911 bisitz 6351: font-family: $sans;
6352: line-height:130%;
6353: font-size:0.83em;
6354: color:$font;
1.795 www 6355: }
6356:
1.959 onken 6357: a:focus,
6358: a:focus img {
1.795 www 6359: color: red;
6360: }
1.698 harmsja 6361:
1.911 bisitz 6362: form, .inline {
6363: display: inline;
1.795 www 6364: }
1.721 harmsja 6365:
1.795 www 6366: .LC_right {
1.911 bisitz 6367: text-align:right;
1.795 www 6368: }
6369:
6370: .LC_middle {
1.911 bisitz 6371: vertical-align:middle;
1.795 www 6372: }
1.721 harmsja 6373:
1.1130 raeburn 6374: .LC_floatleft {
6375: float: left;
6376: }
6377:
6378: .LC_floatright {
6379: float: right;
6380: }
6381:
1.911 bisitz 6382: .LC_400Box {
6383: width:400px;
6384: }
1.721 harmsja 6385:
1.947 droeschl 6386: .LC_iframecontainer {
6387: width: 98%;
6388: margin: 0;
6389: position: fixed;
6390: top: 8.5em;
6391: bottom: 0;
6392: }
6393:
6394: .LC_iframecontainer iframe{
6395: border: none;
6396: width: 100%;
6397: height: 100%;
6398: }
6399:
1.778 bisitz 6400: .LC_filename {
6401: font-family: $mono;
6402: white-space:pre;
1.921 bisitz 6403: font-size: 120%;
1.778 bisitz 6404: }
6405:
6406: .LC_fileicon {
6407: border: none;
6408: height: 1.3em;
6409: vertical-align: text-bottom;
6410: margin-right: 0.3em;
6411: text-decoration:none;
6412: }
6413:
1.1008 www 6414: .LC_setting {
6415: text-decoration:underline;
6416: }
6417:
1.350 albertel 6418: .LC_error {
6419: color: red;
6420: }
1.795 www 6421:
1.1097 bisitz 6422: .LC_warning {
6423: color: darkorange;
6424: }
6425:
1.457 albertel 6426: .LC_diff_removed {
1.733 bisitz 6427: color: red;
1.394 albertel 6428: }
1.532 albertel 6429:
6430: .LC_info,
1.457 albertel 6431: .LC_success,
6432: .LC_diff_added {
1.350 albertel 6433: color: green;
6434: }
1.795 www 6435:
1.802 bisitz 6436: div.LC_confirm_box {
6437: background-color: #FAFAFA;
6438: border: 1px solid $lg_border_color;
6439: margin-right: 0;
6440: padding: 5px;
6441: }
6442:
6443: div.LC_confirm_box .LC_error img,
6444: div.LC_confirm_box .LC_success img {
6445: vertical-align: middle;
6446: }
6447:
1.1242 raeburn 6448: .LC_maxwidth {
6449: max-width: 100%;
6450: height: auto;
6451: }
6452:
1.1243 raeburn 6453: .LC_textsize_mobile {
6454: \@media only screen and (max-device-width: 480px) {
6455: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6456: }
6457: }
6458:
1.440 albertel 6459: .LC_icon {
1.771 droeschl 6460: border: none;
1.790 droeschl 6461: vertical-align: middle;
1.771 droeschl 6462: }
6463:
1.543 albertel 6464: .LC_docs_spacer {
6465: width: 25px;
6466: height: 1px;
1.771 droeschl 6467: border: none;
1.543 albertel 6468: }
1.346 albertel 6469:
1.532 albertel 6470: .LC_internal_info {
1.735 bisitz 6471: color: #999999;
1.532 albertel 6472: }
6473:
1.794 www 6474: .LC_discussion {
1.1050 www 6475: background: $data_table_dark;
1.911 bisitz 6476: border: 1px solid black;
6477: margin: 2px;
1.794 www 6478: }
6479:
6480: .LC_disc_action_left {
1.1050 www 6481: background: $sidebg;
1.911 bisitz 6482: text-align: left;
1.1050 www 6483: padding: 4px;
6484: margin: 2px;
1.794 www 6485: }
6486:
6487: .LC_disc_action_right {
1.1050 www 6488: background: $sidebg;
1.911 bisitz 6489: text-align: right;
1.1050 www 6490: padding: 4px;
6491: margin: 2px;
1.794 www 6492: }
6493:
6494: .LC_disc_new_item {
1.911 bisitz 6495: background: white;
6496: border: 2px solid red;
1.1050 www 6497: margin: 4px;
6498: padding: 4px;
1.794 www 6499: }
6500:
6501: .LC_disc_old_item {
1.911 bisitz 6502: background: white;
1.1050 www 6503: margin: 4px;
6504: padding: 4px;
1.794 www 6505: }
6506:
1.458 albertel 6507: table.LC_pastsubmission {
6508: border: 1px solid black;
6509: margin: 2px;
6510: }
6511:
1.924 bisitz 6512: table#LC_menubuttons {
1.345 albertel 6513: width: 100%;
6514: background: $pgbg;
1.392 albertel 6515: border: 2px;
1.402 albertel 6516: border-collapse: separate;
1.803 bisitz 6517: padding: 0;
1.345 albertel 6518: }
1.392 albertel 6519:
1.801 tempelho 6520: table#LC_title_bar a {
6521: color: $fontmenu;
6522: }
1.836 bisitz 6523:
1.807 droeschl 6524: table#LC_title_bar {
1.819 tempelho 6525: clear: both;
1.836 bisitz 6526: display: none;
1.807 droeschl 6527: }
6528:
1.795 www 6529: table#LC_title_bar,
1.933 droeschl 6530: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6531: table#LC_title_bar.LC_with_remote {
1.359 albertel 6532: width: 100%;
1.392 albertel 6533: border-color: $pgbg;
6534: border-style: solid;
6535: border-width: $border;
1.379 albertel 6536: background: $pgbg;
1.801 tempelho 6537: color: $fontmenu;
1.392 albertel 6538: border-collapse: collapse;
1.803 bisitz 6539: padding: 0;
1.819 tempelho 6540: margin: 0;
1.359 albertel 6541: }
1.795 www 6542:
1.933 droeschl 6543: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6544: margin: 0;
6545: padding: 0;
1.933 droeschl 6546: position: relative;
6547: list-style: none;
1.913 droeschl 6548: }
1.933 droeschl 6549: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6550: display: inline;
6551: }
1.933 droeschl 6552:
6553: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6554: padding: 0;
1.933 droeschl 6555: margin: 0;
6556: float: left;
1.913 droeschl 6557: }
1.933 droeschl 6558: .LC_breadcrumb_tools_tools {
6559: padding: 0;
6560: margin: 0;
1.913 droeschl 6561: float: right;
6562: }
6563:
1.1240 raeburn 6564: .LC_placement_prog {
6565: padding-right: 20px;
6566: font-weight: bold;
6567: font-size: 90%;
6568: }
6569:
1.359 albertel 6570: table#LC_title_bar td {
6571: background: $tabbg;
6572: }
1.795 www 6573:
1.911 bisitz 6574: table#LC_menubuttons img {
1.803 bisitz 6575: border: none;
1.346 albertel 6576: }
1.795 www 6577:
1.842 droeschl 6578: .LC_breadcrumbs_component {
1.911 bisitz 6579: float: right;
6580: margin: 0 1em;
1.357 albertel 6581: }
1.842 droeschl 6582: .LC_breadcrumbs_component img {
1.911 bisitz 6583: vertical-align: middle;
1.777 tempelho 6584: }
1.795 www 6585:
1.1243 raeburn 6586: .LC_breadcrumbs_hoverable {
6587: background: $sidebg;
6588: }
6589:
1.383 albertel 6590: td.LC_table_cell_checkbox {
6591: text-align: center;
6592: }
1.795 www 6593:
6594: .LC_fontsize_small {
1.911 bisitz 6595: font-size: 70%;
1.705 tempelho 6596: }
6597:
1.844 bisitz 6598: #LC_breadcrumbs {
1.911 bisitz 6599: clear:both;
6600: background: $sidebg;
6601: border-bottom: 1px solid $lg_border_color;
6602: line-height: 2.5em;
1.933 droeschl 6603: overflow: hidden;
1.911 bisitz 6604: margin: 0;
6605: padding: 0;
1.995 raeburn 6606: text-align: left;
1.819 tempelho 6607: }
1.862 bisitz 6608:
1.1098 bisitz 6609: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6610: clear:both;
6611: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6612: border: 1px solid $sidebg;
1.1098 bisitz 6613: margin: 0 0 10px 0;
1.966 bisitz 6614: padding: 3px;
1.995 raeburn 6615: text-align: left;
1.822 bisitz 6616: }
6617:
1.795 www 6618: .LC_fontsize_medium {
1.911 bisitz 6619: font-size: 85%;
1.705 tempelho 6620: }
6621:
1.795 www 6622: .LC_fontsize_large {
1.911 bisitz 6623: font-size: 120%;
1.705 tempelho 6624: }
6625:
1.346 albertel 6626: .LC_menubuttons_inline_text {
6627: color: $font;
1.698 harmsja 6628: font-size: 90%;
1.701 harmsja 6629: padding-left:3px;
1.346 albertel 6630: }
6631:
1.934 droeschl 6632: .LC_menubuttons_inline_text img{
6633: vertical-align: middle;
6634: }
6635:
1.1051 www 6636: li.LC_menubuttons_inline_text img {
1.951 onken 6637: cursor:pointer;
1.1002 droeschl 6638: text-decoration: none;
1.951 onken 6639: }
6640:
1.526 www 6641: .LC_menubuttons_link {
6642: text-decoration: none;
6643: }
1.795 www 6644:
1.522 albertel 6645: .LC_menubuttons_category {
1.521 www 6646: color: $font;
1.526 www 6647: background: $pgbg;
1.521 www 6648: font-size: larger;
6649: font-weight: bold;
6650: }
6651:
1.346 albertel 6652: td.LC_menubuttons_text {
1.911 bisitz 6653: color: $font;
1.346 albertel 6654: }
1.706 harmsja 6655:
1.346 albertel 6656: .LC_current_location {
6657: background: $tabbg;
6658: }
1.795 www 6659:
1.1286 raeburn 6660: td.LC_zero_height {
6661: line-height: 0;
6662: cellpadding: 0;
6663: }
6664:
1.938 bisitz 6665: table.LC_data_table {
1.347 albertel 6666: border: 1px solid #000000;
1.402 albertel 6667: border-collapse: separate;
1.426 albertel 6668: border-spacing: 1px;
1.610 albertel 6669: background: $pgbg;
1.347 albertel 6670: }
1.795 www 6671:
1.422 albertel 6672: .LC_data_table_dense {
6673: font-size: small;
6674: }
1.795 www 6675:
1.507 raeburn 6676: table.LC_nested_outer {
6677: border: 1px solid #000000;
1.589 raeburn 6678: border-collapse: collapse;
1.803 bisitz 6679: border-spacing: 0;
1.507 raeburn 6680: width: 100%;
6681: }
1.795 www 6682:
1.879 raeburn 6683: table.LC_innerpickbox,
1.507 raeburn 6684: table.LC_nested {
1.803 bisitz 6685: border: none;
1.589 raeburn 6686: border-collapse: collapse;
1.803 bisitz 6687: border-spacing: 0;
1.507 raeburn 6688: width: 100%;
6689: }
1.795 www 6690:
1.911 bisitz 6691: table.LC_data_table tr th,
6692: table.LC_calendar tr th,
1.879 raeburn 6693: table.LC_prior_tries tr th,
6694: table.LC_innerpickbox tr th {
1.349 albertel 6695: font-weight: bold;
6696: background-color: $data_table_head;
1.801 tempelho 6697: color:$fontmenu;
1.701 harmsja 6698: font-size:90%;
1.347 albertel 6699: }
1.795 www 6700:
1.879 raeburn 6701: table.LC_innerpickbox tr th,
6702: table.LC_innerpickbox tr td {
6703: vertical-align: top;
6704: }
6705:
1.711 raeburn 6706: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6707: background-color: #CCCCCC;
1.711 raeburn 6708: font-weight: bold;
6709: text-align: left;
6710: }
1.795 www 6711:
1.912 bisitz 6712: table.LC_data_table tr.LC_odd_row > td {
6713: background-color: $data_table_light;
6714: padding: 2px;
6715: vertical-align: top;
6716: }
6717:
1.809 bisitz 6718: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6719: background-color: $data_table_light;
1.912 bisitz 6720: vertical-align: top;
6721: }
6722:
6723: table.LC_data_table tr.LC_even_row > td {
6724: background-color: $data_table_dark;
1.425 albertel 6725: padding: 2px;
1.900 bisitz 6726: vertical-align: top;
1.347 albertel 6727: }
1.795 www 6728:
1.809 bisitz 6729: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6730: background-color: $data_table_dark;
1.900 bisitz 6731: vertical-align: top;
1.347 albertel 6732: }
1.795 www 6733:
1.425 albertel 6734: table.LC_data_table tr.LC_data_table_highlight td {
6735: background-color: $data_table_darker;
6736: }
1.795 www 6737:
1.639 raeburn 6738: table.LC_data_table tr td.LC_leftcol_header {
6739: background-color: $data_table_head;
6740: font-weight: bold;
6741: }
1.795 www 6742:
1.451 albertel 6743: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6744: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6745: font-weight: bold;
6746: font-style: italic;
6747: text-align: center;
6748: padding: 8px;
1.347 albertel 6749: }
1.795 www 6750:
1.1114 raeburn 6751: table.LC_data_table tr.LC_empty_row td,
6752: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6753: background-color: $sidebg;
6754: }
6755:
6756: table.LC_nested tr.LC_empty_row td {
6757: background-color: #FFFFFF;
6758: }
6759:
1.890 droeschl 6760: table.LC_caption {
6761: }
6762:
1.507 raeburn 6763: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6764: padding: 4ex
6765: }
1.795 www 6766:
1.507 raeburn 6767: table.LC_nested_outer tr th {
6768: font-weight: bold;
1.801 tempelho 6769: color:$fontmenu;
1.507 raeburn 6770: background-color: $data_table_head;
1.701 harmsja 6771: font-size: small;
1.507 raeburn 6772: border-bottom: 1px solid #000000;
6773: }
1.795 www 6774:
1.507 raeburn 6775: table.LC_nested_outer tr td.LC_subheader {
6776: background-color: $data_table_head;
6777: font-weight: bold;
6778: font-size: small;
6779: border-bottom: 1px solid #000000;
6780: text-align: right;
1.451 albertel 6781: }
1.795 www 6782:
1.507 raeburn 6783: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6784: background-color: #CCCCCC;
1.451 albertel 6785: font-weight: bold;
6786: font-size: small;
1.507 raeburn 6787: text-align: center;
6788: }
1.795 www 6789:
1.589 raeburn 6790: table.LC_nested tr.LC_info_row td.LC_left_item,
6791: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6792: text-align: left;
1.451 albertel 6793: }
1.795 www 6794:
1.507 raeburn 6795: table.LC_nested td {
1.735 bisitz 6796: background-color: #FFFFFF;
1.451 albertel 6797: font-size: small;
1.507 raeburn 6798: }
1.795 www 6799:
1.507 raeburn 6800: table.LC_nested_outer tr th.LC_right_item,
6801: table.LC_nested tr.LC_info_row td.LC_right_item,
6802: table.LC_nested tr.LC_odd_row td.LC_right_item,
6803: table.LC_nested tr td.LC_right_item {
1.451 albertel 6804: text-align: right;
6805: }
6806:
1.507 raeburn 6807: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6808: background-color: #EEEEEE;
1.451 albertel 6809: }
6810:
1.473 raeburn 6811: table.LC_createuser {
6812: }
6813:
6814: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6815: font-size: small;
1.473 raeburn 6816: }
6817:
6818: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6819: background-color: #CCCCCC;
1.473 raeburn 6820: font-weight: bold;
6821: text-align: center;
6822: }
6823:
1.349 albertel 6824: table.LC_calendar {
6825: border: 1px solid #000000;
6826: border-collapse: collapse;
1.917 raeburn 6827: width: 98%;
1.349 albertel 6828: }
1.795 www 6829:
1.349 albertel 6830: table.LC_calendar_pickdate {
6831: font-size: xx-small;
6832: }
1.795 www 6833:
1.349 albertel 6834: table.LC_calendar tr td {
6835: border: 1px solid #000000;
6836: vertical-align: top;
1.917 raeburn 6837: width: 14%;
1.349 albertel 6838: }
1.795 www 6839:
1.349 albertel 6840: table.LC_calendar tr td.LC_calendar_day_empty {
6841: background-color: $data_table_dark;
6842: }
1.795 www 6843:
1.779 bisitz 6844: table.LC_calendar tr td.LC_calendar_day_current {
6845: background-color: $data_table_highlight;
1.777 tempelho 6846: }
1.795 www 6847:
1.938 bisitz 6848: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6849: background-color: $mail_new;
6850: }
1.795 www 6851:
1.938 bisitz 6852: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6853: background-color: $mail_new_hover;
6854: }
1.795 www 6855:
1.938 bisitz 6856: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6857: background-color: $mail_read;
6858: }
1.795 www 6859:
1.938 bisitz 6860: /*
6861: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6862: background-color: $mail_read_hover;
6863: }
1.938 bisitz 6864: */
1.795 www 6865:
1.938 bisitz 6866: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6867: background-color: $mail_replied;
6868: }
1.795 www 6869:
1.938 bisitz 6870: /*
6871: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6872: background-color: $mail_replied_hover;
6873: }
1.938 bisitz 6874: */
1.795 www 6875:
1.938 bisitz 6876: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6877: background-color: $mail_other;
6878: }
1.795 www 6879:
1.938 bisitz 6880: /*
6881: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6882: background-color: $mail_other_hover;
6883: }
1.938 bisitz 6884: */
1.494 raeburn 6885:
1.777 tempelho 6886: table.LC_data_table tr > td.LC_browser_file,
6887: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6888: background: #AAEE77;
1.389 albertel 6889: }
1.795 www 6890:
1.777 tempelho 6891: table.LC_data_table tr > td.LC_browser_file_locked,
6892: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6893: background: #FFAA99;
1.387 albertel 6894: }
1.795 www 6895:
1.777 tempelho 6896: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6897: background: #888888;
1.779 bisitz 6898: }
1.795 www 6899:
1.777 tempelho 6900: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6901: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6902: background: #F8F866;
1.777 tempelho 6903: }
1.795 www 6904:
1.696 bisitz 6905: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6906: background: #E0E8FF;
1.387 albertel 6907: }
1.696 bisitz 6908:
1.707 bisitz 6909: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6910: /* background: #77FF77; */
1.707 bisitz 6911: }
1.795 www 6912:
1.707 bisitz 6913: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6914: border-right: 8px solid #FFFF77;
1.707 bisitz 6915: }
1.795 www 6916:
1.707 bisitz 6917: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6918: border-right: 8px solid #FFAA77;
1.707 bisitz 6919: }
1.795 www 6920:
1.707 bisitz 6921: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6922: border-right: 8px solid #FF7777;
1.707 bisitz 6923: }
1.795 www 6924:
1.707 bisitz 6925: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6926: border-right: 8px solid #AAFF77;
1.707 bisitz 6927: }
1.795 www 6928:
1.707 bisitz 6929: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6930: border-right: 8px solid #11CC55;
1.707 bisitz 6931: }
6932:
1.388 albertel 6933: span.LC_current_location {
1.701 harmsja 6934: font-size:larger;
1.388 albertel 6935: background: $pgbg;
6936: }
1.387 albertel 6937:
1.1029 www 6938: span.LC_current_nav_location {
6939: font-weight:bold;
6940: background: $sidebg;
6941: }
6942:
1.395 albertel 6943: span.LC_parm_menu_item {
6944: font-size: larger;
6945: }
1.795 www 6946:
1.395 albertel 6947: span.LC_parm_scope_all {
6948: color: red;
6949: }
1.795 www 6950:
1.395 albertel 6951: span.LC_parm_scope_folder {
6952: color: green;
6953: }
1.795 www 6954:
1.395 albertel 6955: span.LC_parm_scope_resource {
6956: color: orange;
6957: }
1.795 www 6958:
1.395 albertel 6959: span.LC_parm_part {
6960: color: blue;
6961: }
1.795 www 6962:
1.911 bisitz 6963: span.LC_parm_folder,
6964: span.LC_parm_symb {
1.395 albertel 6965: font-size: x-small;
6966: font-family: $mono;
6967: color: #AAAAAA;
6968: }
6969:
1.977 bisitz 6970: ul.LC_parm_parmlist li {
6971: display: inline-block;
6972: padding: 0.3em 0.8em;
6973: vertical-align: top;
6974: width: 150px;
6975: border-top:1px solid $lg_border_color;
6976: }
6977:
1.795 www 6978: td.LC_parm_overview_level_menu,
6979: td.LC_parm_overview_map_menu,
6980: td.LC_parm_overview_parm_selectors,
6981: td.LC_parm_overview_restrictions {
1.396 albertel 6982: border: 1px solid black;
6983: border-collapse: collapse;
6984: }
1.795 www 6985:
1.1285 raeburn 6986: span.LC_parm_recursive,
6987: td.LC_parm_recursive {
6988: font-weight: bold;
6989: font-size: smaller;
6990: }
6991:
1.396 albertel 6992: table.LC_parm_overview_restrictions td {
6993: border-width: 1px 4px 1px 4px;
6994: border-style: solid;
6995: border-color: $pgbg;
6996: text-align: center;
6997: }
1.795 www 6998:
1.396 albertel 6999: table.LC_parm_overview_restrictions th {
7000: background: $tabbg;
7001: border-width: 1px 4px 1px 4px;
7002: border-style: solid;
7003: border-color: $pgbg;
7004: }
1.795 www 7005:
1.398 albertel 7006: table#LC_helpmenu {
1.803 bisitz 7007: border: none;
1.398 albertel 7008: height: 55px;
1.803 bisitz 7009: border-spacing: 0;
1.398 albertel 7010: }
7011:
7012: table#LC_helpmenu fieldset legend {
7013: font-size: larger;
7014: }
1.795 www 7015:
1.397 albertel 7016: table#LC_helpmenu_links {
7017: width: 100%;
7018: border: 1px solid black;
7019: background: $pgbg;
1.803 bisitz 7020: padding: 0;
1.397 albertel 7021: border-spacing: 1px;
7022: }
1.795 www 7023:
1.397 albertel 7024: table#LC_helpmenu_links tr td {
7025: padding: 1px;
7026: background: $tabbg;
1.399 albertel 7027: text-align: center;
7028: font-weight: bold;
1.397 albertel 7029: }
1.396 albertel 7030:
1.795 www 7031: table#LC_helpmenu_links a:link,
7032: table#LC_helpmenu_links a:visited,
1.397 albertel 7033: table#LC_helpmenu_links a:active {
7034: text-decoration: none;
7035: color: $font;
7036: }
1.795 www 7037:
1.397 albertel 7038: table#LC_helpmenu_links a:hover {
7039: text-decoration: underline;
7040: color: $vlink;
7041: }
1.396 albertel 7042:
1.417 albertel 7043: .LC_chrt_popup_exists {
7044: border: 1px solid #339933;
7045: margin: -1px;
7046: }
1.795 www 7047:
1.417 albertel 7048: .LC_chrt_popup_up {
7049: border: 1px solid yellow;
7050: margin: -1px;
7051: }
1.795 www 7052:
1.417 albertel 7053: .LC_chrt_popup {
7054: border: 1px solid #8888FF;
7055: background: #CCCCFF;
7056: }
1.795 www 7057:
1.421 albertel 7058: table.LC_pick_box {
7059: border-collapse: separate;
7060: background: white;
7061: border: 1px solid black;
7062: border-spacing: 1px;
7063: }
1.795 www 7064:
1.421 albertel 7065: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7066: background: $sidebg;
1.421 albertel 7067: font-weight: bold;
1.900 bisitz 7068: text-align: left;
1.740 bisitz 7069: vertical-align: top;
1.421 albertel 7070: width: 184px;
7071: padding: 8px;
7072: }
1.795 www 7073:
1.579 raeburn 7074: table.LC_pick_box td.LC_pick_box_value {
7075: text-align: left;
7076: padding: 8px;
7077: }
1.795 www 7078:
1.579 raeburn 7079: table.LC_pick_box td.LC_pick_box_select {
7080: text-align: left;
7081: padding: 8px;
7082: }
1.795 www 7083:
1.424 albertel 7084: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7085: padding: 0;
1.421 albertel 7086: height: 1px;
7087: background: black;
7088: }
1.795 www 7089:
1.421 albertel 7090: table.LC_pick_box td.LC_pick_box_submit {
7091: text-align: right;
7092: }
1.795 www 7093:
1.579 raeburn 7094: table.LC_pick_box td.LC_evenrow_value {
7095: text-align: left;
7096: padding: 8px;
7097: background-color: $data_table_light;
7098: }
1.795 www 7099:
1.579 raeburn 7100: table.LC_pick_box td.LC_oddrow_value {
7101: text-align: left;
7102: padding: 8px;
7103: background-color: $data_table_light;
7104: }
1.795 www 7105:
1.579 raeburn 7106: span.LC_helpform_receipt_cat {
7107: font-weight: bold;
7108: }
1.795 www 7109:
1.424 albertel 7110: table.LC_group_priv_box {
7111: background: white;
7112: border: 1px solid black;
7113: border-spacing: 1px;
7114: }
1.795 www 7115:
1.424 albertel 7116: table.LC_group_priv_box td.LC_pick_box_title {
7117: background: $tabbg;
7118: font-weight: bold;
7119: text-align: right;
7120: width: 184px;
7121: }
1.795 www 7122:
1.424 albertel 7123: table.LC_group_priv_box td.LC_groups_fixed {
7124: background: $data_table_light;
7125: text-align: center;
7126: }
1.795 www 7127:
1.424 albertel 7128: table.LC_group_priv_box td.LC_groups_optional {
7129: background: $data_table_dark;
7130: text-align: center;
7131: }
1.795 www 7132:
1.424 albertel 7133: table.LC_group_priv_box td.LC_groups_functionality {
7134: background: $data_table_darker;
7135: text-align: center;
7136: font-weight: bold;
7137: }
1.795 www 7138:
1.424 albertel 7139: table.LC_group_priv td {
7140: text-align: left;
1.803 bisitz 7141: padding: 0;
1.424 albertel 7142: }
7143:
7144: .LC_navbuttons {
7145: margin: 2ex 0ex 2ex 0ex;
7146: }
1.795 www 7147:
1.423 albertel 7148: .LC_topic_bar {
7149: font-weight: bold;
7150: background: $tabbg;
1.918 wenzelju 7151: margin: 1em 0em 1em 2em;
1.805 bisitz 7152: padding: 3px;
1.918 wenzelju 7153: font-size: 1.2em;
1.423 albertel 7154: }
1.795 www 7155:
1.423 albertel 7156: .LC_topic_bar span {
1.918 wenzelju 7157: left: 0.5em;
7158: position: absolute;
1.423 albertel 7159: vertical-align: middle;
1.918 wenzelju 7160: font-size: 1.2em;
1.423 albertel 7161: }
1.795 www 7162:
1.423 albertel 7163: table.LC_course_group_status {
7164: margin: 20px;
7165: }
1.795 www 7166:
1.423 albertel 7167: table.LC_status_selector td {
7168: vertical-align: top;
7169: text-align: center;
1.424 albertel 7170: padding: 4px;
7171: }
1.795 www 7172:
1.599 albertel 7173: div.LC_feedback_link {
1.616 albertel 7174: clear: both;
1.829 kalberla 7175: background: $sidebg;
1.779 bisitz 7176: width: 100%;
1.829 kalberla 7177: padding-bottom: 10px;
7178: border: 1px $tabbg solid;
1.833 kalberla 7179: height: 22px;
7180: line-height: 22px;
7181: padding-top: 5px;
7182: }
7183:
7184: div.LC_feedback_link img {
7185: height: 22px;
1.867 kalberla 7186: vertical-align:middle;
1.829 kalberla 7187: }
7188:
1.911 bisitz 7189: div.LC_feedback_link a {
1.829 kalberla 7190: text-decoration: none;
1.489 raeburn 7191: }
1.795 www 7192:
1.867 kalberla 7193: div.LC_comblock {
1.911 bisitz 7194: display:inline;
1.867 kalberla 7195: color:$font;
7196: font-size:90%;
7197: }
7198:
7199: div.LC_feedback_link div.LC_comblock {
7200: padding-left:5px;
7201: }
7202:
7203: div.LC_feedback_link div.LC_comblock a {
7204: color:$font;
7205: }
7206:
1.489 raeburn 7207: span.LC_feedback_link {
1.858 bisitz 7208: /* background: $feedback_link_bg; */
1.599 albertel 7209: font-size: larger;
7210: }
1.795 www 7211:
1.599 albertel 7212: span.LC_message_link {
1.858 bisitz 7213: /* background: $feedback_link_bg; */
1.599 albertel 7214: font-size: larger;
7215: position: absolute;
7216: right: 1em;
1.489 raeburn 7217: }
1.421 albertel 7218:
1.515 albertel 7219: table.LC_prior_tries {
1.524 albertel 7220: border: 1px solid #000000;
7221: border-collapse: separate;
7222: border-spacing: 1px;
1.515 albertel 7223: }
1.523 albertel 7224:
1.515 albertel 7225: table.LC_prior_tries td {
1.524 albertel 7226: padding: 2px;
1.515 albertel 7227: }
1.523 albertel 7228:
7229: .LC_answer_correct {
1.795 www 7230: background: lightgreen;
7231: color: darkgreen;
7232: padding: 6px;
1.523 albertel 7233: }
1.795 www 7234:
1.523 albertel 7235: .LC_answer_charged_try {
1.797 www 7236: background: #FFAAAA;
1.795 www 7237: color: darkred;
7238: padding: 6px;
1.523 albertel 7239: }
1.795 www 7240:
1.779 bisitz 7241: .LC_answer_not_charged_try,
1.523 albertel 7242: .LC_answer_no_grade,
7243: .LC_answer_late {
1.795 www 7244: background: lightyellow;
1.523 albertel 7245: color: black;
1.795 www 7246: padding: 6px;
1.523 albertel 7247: }
1.795 www 7248:
1.523 albertel 7249: .LC_answer_previous {
1.795 www 7250: background: lightblue;
7251: color: darkblue;
7252: padding: 6px;
1.523 albertel 7253: }
1.795 www 7254:
1.779 bisitz 7255: .LC_answer_no_message {
1.777 tempelho 7256: background: #FFFFFF;
7257: color: black;
1.795 www 7258: padding: 6px;
1.779 bisitz 7259: }
1.795 www 7260:
1.1334 raeburn 7261: .LC_answer_unknown,
7262: .LC_answer_warning {
1.779 bisitz 7263: background: orange;
7264: color: black;
1.795 www 7265: padding: 6px;
1.777 tempelho 7266: }
1.795 www 7267:
1.529 albertel 7268: span.LC_prior_numerical,
7269: span.LC_prior_string,
7270: span.LC_prior_custom,
7271: span.LC_prior_reaction,
7272: span.LC_prior_math {
1.925 bisitz 7273: font-family: $mono;
1.523 albertel 7274: white-space: pre;
7275: }
7276:
1.525 albertel 7277: span.LC_prior_string {
1.925 bisitz 7278: font-family: $mono;
1.525 albertel 7279: white-space: pre;
7280: }
7281:
1.523 albertel 7282: table.LC_prior_option {
7283: width: 100%;
7284: border-collapse: collapse;
7285: }
1.795 www 7286:
1.911 bisitz 7287: table.LC_prior_rank,
1.795 www 7288: table.LC_prior_match {
1.528 albertel 7289: border-collapse: collapse;
7290: }
1.795 www 7291:
1.528 albertel 7292: table.LC_prior_option tr td,
7293: table.LC_prior_rank tr td,
7294: table.LC_prior_match tr td {
1.524 albertel 7295: border: 1px solid #000000;
1.515 albertel 7296: }
7297:
1.855 bisitz 7298: .LC_nobreak {
1.544 albertel 7299: white-space: nowrap;
1.519 raeburn 7300: }
7301:
1.576 raeburn 7302: span.LC_cusr_emph {
7303: font-style: italic;
7304: }
7305:
1.633 raeburn 7306: span.LC_cusr_subheading {
7307: font-weight: normal;
7308: font-size: 85%;
7309: }
7310:
1.861 bisitz 7311: div.LC_docs_entry_move {
1.859 bisitz 7312: border: 1px solid #BBBBBB;
1.545 albertel 7313: background: #DDDDDD;
1.861 bisitz 7314: width: 22px;
1.859 bisitz 7315: padding: 1px;
7316: margin: 0;
1.545 albertel 7317: }
7318:
1.861 bisitz 7319: table.LC_data_table tr > td.LC_docs_entry_commands,
7320: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7321: font-size: x-small;
7322: }
1.795 www 7323:
1.861 bisitz 7324: .LC_docs_entry_parameter {
7325: white-space: nowrap;
7326: }
7327:
1.544 albertel 7328: .LC_docs_copy {
1.545 albertel 7329: color: #000099;
1.544 albertel 7330: }
1.795 www 7331:
1.544 albertel 7332: .LC_docs_cut {
1.545 albertel 7333: color: #550044;
1.544 albertel 7334: }
1.795 www 7335:
1.544 albertel 7336: .LC_docs_rename {
1.545 albertel 7337: color: #009900;
1.544 albertel 7338: }
1.795 www 7339:
1.544 albertel 7340: .LC_docs_remove {
1.545 albertel 7341: color: #990000;
7342: }
7343:
1.1284 raeburn 7344: .LC_docs_alias {
7345: color: #440055;
7346: }
7347:
1.1286 raeburn 7348: .LC_domprefs_email,
1.1284 raeburn 7349: .LC_docs_alias_name,
1.547 albertel 7350: .LC_docs_reinit_warn,
7351: .LC_docs_ext_edit {
7352: font-size: x-small;
7353: }
7354:
1.545 albertel 7355: table.LC_docs_adddocs td,
7356: table.LC_docs_adddocs th {
7357: border: 1px solid #BBBBBB;
7358: padding: 4px;
7359: background: #DDDDDD;
1.543 albertel 7360: }
7361:
1.584 albertel 7362: table.LC_sty_begin {
7363: background: #BBFFBB;
7364: }
1.795 www 7365:
1.584 albertel 7366: table.LC_sty_end {
7367: background: #FFBBBB;
7368: }
7369:
1.589 raeburn 7370: table.LC_double_column {
1.803 bisitz 7371: border-width: 0;
1.589 raeburn 7372: border-collapse: collapse;
7373: width: 100%;
7374: padding: 2px;
7375: }
7376:
7377: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7378: top: 2px;
1.589 raeburn 7379: left: 2px;
7380: width: 47%;
7381: vertical-align: top;
7382: }
7383:
7384: table.LC_double_column tr td.LC_right_col {
7385: top: 2px;
1.779 bisitz 7386: right: 2px;
1.589 raeburn 7387: width: 47%;
7388: vertical-align: top;
7389: }
7390:
1.591 raeburn 7391: div.LC_left_float {
7392: float: left;
7393: padding-right: 5%;
1.597 albertel 7394: padding-bottom: 4px;
1.591 raeburn 7395: }
7396:
7397: div.LC_clear_float_header {
1.597 albertel 7398: padding-bottom: 2px;
1.591 raeburn 7399: }
7400:
7401: div.LC_clear_float_footer {
1.597 albertel 7402: padding-top: 10px;
1.591 raeburn 7403: clear: both;
7404: }
7405:
1.597 albertel 7406: div.LC_grade_show_user {
1.941 bisitz 7407: /* border-left: 5px solid $sidebg; */
7408: border-top: 5px solid #000000;
7409: margin: 50px 0 0 0;
1.936 bisitz 7410: padding: 15px 0 5px 10px;
1.597 albertel 7411: }
1.795 www 7412:
1.936 bisitz 7413: div.LC_grade_show_user_odd_row {
1.941 bisitz 7414: /* border-left: 5px solid #000000; */
7415: }
7416:
7417: div.LC_grade_show_user div.LC_Box {
7418: margin-right: 50px;
1.597 albertel 7419: }
7420:
7421: div.LC_grade_submissions,
7422: div.LC_grade_message_center,
1.936 bisitz 7423: div.LC_grade_info_links {
1.597 albertel 7424: margin: 5px;
7425: width: 99%;
7426: background: #FFFFFF;
7427: }
1.795 www 7428:
1.597 albertel 7429: div.LC_grade_submissions_header,
1.936 bisitz 7430: div.LC_grade_message_center_header {
1.705 tempelho 7431: font-weight: bold;
7432: font-size: large;
1.597 albertel 7433: }
1.795 www 7434:
1.597 albertel 7435: div.LC_grade_submissions_body,
1.936 bisitz 7436: div.LC_grade_message_center_body {
1.597 albertel 7437: border: 1px solid black;
7438: width: 99%;
7439: background: #FFFFFF;
7440: }
1.795 www 7441:
1.613 albertel 7442: table.LC_scantron_action {
7443: width: 100%;
7444: }
1.795 www 7445:
1.613 albertel 7446: table.LC_scantron_action tr th {
1.698 harmsja 7447: font-weight:bold;
7448: font-style:normal;
1.613 albertel 7449: }
1.795 www 7450:
1.779 bisitz 7451: .LC_edit_problem_header,
1.614 albertel 7452: div.LC_edit_problem_footer {
1.705 tempelho 7453: font-weight: normal;
7454: font-size: medium;
1.602 albertel 7455: margin: 2px;
1.1060 bisitz 7456: background-color: $sidebg;
1.600 albertel 7457: }
1.795 www 7458:
1.600 albertel 7459: div.LC_edit_problem_header,
1.602 albertel 7460: div.LC_edit_problem_header div,
1.614 albertel 7461: div.LC_edit_problem_footer,
7462: div.LC_edit_problem_footer div,
1.602 albertel 7463: div.LC_edit_problem_editxml_header,
7464: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7465: z-index: 100;
1.600 albertel 7466: }
1.795 www 7467:
1.600 albertel 7468: div.LC_edit_problem_header_title {
1.705 tempelho 7469: font-weight: bold;
7470: font-size: larger;
1.602 albertel 7471: background: $tabbg;
7472: padding: 3px;
1.1060 bisitz 7473: margin: 0 0 5px 0;
1.602 albertel 7474: }
1.795 www 7475:
1.602 albertel 7476: table.LC_edit_problem_header_title {
7477: width: 100%;
1.600 albertel 7478: background: $tabbg;
1.602 albertel 7479: }
7480:
1.1205 golterma 7481: div.LC_edit_actionbar {
7482: background-color: $sidebg;
1.1218 droeschl 7483: margin: 0;
7484: padding: 0;
7485: line-height: 200%;
1.602 albertel 7486: }
1.795 www 7487:
1.1218 droeschl 7488: div.LC_edit_actionbar div{
7489: padding: 0;
7490: margin: 0;
7491: display: inline-block;
1.600 albertel 7492: }
1.795 www 7493:
1.1124 bisitz 7494: .LC_edit_opt {
7495: padding-left: 1em;
7496: white-space: nowrap;
7497: }
7498:
1.1152 golterma 7499: .LC_edit_problem_latexhelper{
7500: text-align: right;
7501: }
7502:
7503: #LC_edit_problem_colorful div{
7504: margin-left: 40px;
7505: }
7506:
1.1205 golterma 7507: #LC_edit_problem_codemirror div{
7508: margin-left: 0px;
7509: }
7510:
1.911 bisitz 7511: img.stift {
1.803 bisitz 7512: border-width: 0;
7513: vertical-align: middle;
1.677 riegler 7514: }
1.680 riegler 7515:
1.923 bisitz 7516: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7517: vertical-align: top;
1.777 tempelho 7518: }
1.795 www 7519:
1.716 raeburn 7520: div.LC_createcourse {
1.911 bisitz 7521: margin: 10px 10px 10px 10px;
1.716 raeburn 7522: }
7523:
1.917 raeburn 7524: .LC_dccid {
1.1130 raeburn 7525: float: right;
1.917 raeburn 7526: margin: 0.2em 0 0 0;
7527: padding: 0;
7528: font-size: 90%;
7529: display:none;
7530: }
7531:
1.897 wenzelju 7532: ol.LC_primary_menu a:hover,
1.721 harmsja 7533: ol#LC_MenuBreadcrumbs a:hover,
7534: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7535: ul#LC_secondary_menu a:hover,
1.721 harmsja 7536: .LC_FormSectionClearButton input:hover
1.795 www 7537: ul.LC_TabContent li:hover a {
1.952 onken 7538: color:$button_hover;
1.911 bisitz 7539: text-decoration:none;
1.693 droeschl 7540: }
7541:
1.779 bisitz 7542: h1 {
1.911 bisitz 7543: padding: 0;
7544: line-height:130%;
1.693 droeschl 7545: }
1.698 harmsja 7546:
1.911 bisitz 7547: h2,
7548: h3,
7549: h4,
7550: h5,
7551: h6 {
7552: margin: 5px 0 5px 0;
7553: padding: 0;
7554: line-height:130%;
1.693 droeschl 7555: }
1.795 www 7556:
7557: .LC_hcell {
1.911 bisitz 7558: padding:3px 15px 3px 15px;
7559: margin: 0;
7560: background-color:$tabbg;
7561: color:$fontmenu;
7562: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7563: }
1.795 www 7564:
1.840 bisitz 7565: .LC_Box > .LC_hcell {
1.911 bisitz 7566: margin: 0 -10px 10px -10px;
1.835 bisitz 7567: }
7568:
1.721 harmsja 7569: .LC_noBorder {
1.911 bisitz 7570: border: 0;
1.698 harmsja 7571: }
1.693 droeschl 7572:
1.721 harmsja 7573: .LC_FormSectionClearButton input {
1.911 bisitz 7574: background-color:transparent;
7575: border: none;
7576: cursor:pointer;
7577: text-decoration:underline;
1.693 droeschl 7578: }
1.763 bisitz 7579:
7580: .LC_help_open_topic {
1.911 bisitz 7581: color: #FFFFFF;
7582: background-color: #EEEEFF;
7583: margin: 1px;
7584: padding: 4px;
7585: border: 1px solid #000033;
7586: white-space: nowrap;
7587: /* vertical-align: middle; */
1.759 neumanie 7588: }
1.693 droeschl 7589:
1.911 bisitz 7590: dl,
7591: ul,
7592: div,
7593: fieldset {
7594: margin: 10px 10px 10px 0;
7595: /* overflow: hidden; */
1.693 droeschl 7596: }
1.795 www 7597:
1.1211 raeburn 7598: article.geogebraweb div {
7599: margin: 0;
7600: }
7601:
1.838 bisitz 7602: fieldset > legend {
1.911 bisitz 7603: font-weight: bold;
7604: padding: 0 5px 0 5px;
1.838 bisitz 7605: }
7606:
1.813 bisitz 7607: #LC_nav_bar {
1.911 bisitz 7608: float: left;
1.995 raeburn 7609: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7610: margin: 0 0 2px 0;
1.807 droeschl 7611: }
7612:
1.916 droeschl 7613: #LC_realm {
7614: margin: 0.2em 0 0 0;
7615: padding: 0;
7616: font-weight: bold;
7617: text-align: center;
1.995 raeburn 7618: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7619: }
7620:
1.911 bisitz 7621: #LC_nav_bar em {
7622: font-weight: bold;
7623: font-style: normal;
1.807 droeschl 7624: }
7625:
1.897 wenzelju 7626: ol.LC_primary_menu {
1.934 droeschl 7627: margin: 0;
1.1076 raeburn 7628: padding: 0;
1.807 droeschl 7629: }
7630:
1.852 droeschl 7631: ol#LC_PathBreadcrumbs {
1.911 bisitz 7632: margin: 0;
1.693 droeschl 7633: }
7634:
1.897 wenzelju 7635: ol.LC_primary_menu li {
1.1076 raeburn 7636: color: RGB(80, 80, 80);
7637: vertical-align: middle;
7638: text-align: left;
7639: list-style: none;
1.1205 golterma 7640: position: relative;
1.1076 raeburn 7641: float: left;
1.1205 golterma 7642: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7643: line-height: 1.5em;
1.1076 raeburn 7644: }
7645:
1.1205 golterma 7646: ol.LC_primary_menu li a,
7647: ol.LC_primary_menu li p {
1.1076 raeburn 7648: display: block;
7649: margin: 0;
7650: padding: 0 5px 0 10px;
7651: text-decoration: none;
7652: }
7653:
1.1205 golterma 7654: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7655: display: inline-block;
7656: width: 95%;
7657: text-align: left;
7658: }
7659:
7660: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7661: display: inline-block;
7662: width: 5%;
7663: float: right;
7664: text-align: right;
7665: font-size: 70%;
7666: }
7667:
7668: ol.LC_primary_menu ul {
1.1076 raeburn 7669: display: none;
1.1205 golterma 7670: width: 15em;
1.1076 raeburn 7671: background-color: $data_table_light;
1.1205 golterma 7672: position: absolute;
7673: top: 100%;
1.1076 raeburn 7674: }
7675:
1.1205 golterma 7676: ol.LC_primary_menu ul ul {
7677: left: 100%;
7678: top: 0;
7679: }
7680:
7681: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7682: display: block;
7683: position: absolute;
7684: margin: 0;
7685: padding: 0;
1.1078 raeburn 7686: z-index: 2;
1.1076 raeburn 7687: }
7688:
7689: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7690: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7691: font-size: 90%;
1.911 bisitz 7692: vertical-align: top;
1.1076 raeburn 7693: float: none;
1.1079 raeburn 7694: border-left: 1px solid black;
7695: border-right: 1px solid black;
1.1205 golterma 7696: /* A dark bottom border to visualize different menu options;
7697: overwritten in the create_submenu routine for the last border-bottom of the menu */
7698: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7699: }
7700:
1.1205 golterma 7701: ol.LC_primary_menu li li p:hover {
7702: color:$button_hover;
7703: text-decoration:none;
7704: background-color:$data_table_dark;
1.1076 raeburn 7705: }
7706:
7707: ol.LC_primary_menu li li a:hover {
7708: color:$button_hover;
7709: background-color:$data_table_dark;
1.693 droeschl 7710: }
7711:
1.1205 golterma 7712: /* Font-size equal to the size of the predecessors*/
7713: ol.LC_primary_menu li:hover li li {
7714: font-size: 100%;
7715: }
7716:
1.897 wenzelju 7717: ol.LC_primary_menu li img {
1.911 bisitz 7718: vertical-align: bottom;
1.934 droeschl 7719: height: 1.1em;
1.1077 raeburn 7720: margin: 0.2em 0 0 0;
1.693 droeschl 7721: }
7722:
1.897 wenzelju 7723: ol.LC_primary_menu a {
1.911 bisitz 7724: color: RGB(80, 80, 80);
7725: text-decoration: none;
1.693 droeschl 7726: }
1.795 www 7727:
1.949 droeschl 7728: ol.LC_primary_menu a.LC_new_message {
7729: font-weight:bold;
7730: color: darkred;
7731: }
7732:
1.975 raeburn 7733: ol.LC_docs_parameters {
7734: margin-left: 0;
7735: padding: 0;
7736: list-style: none;
7737: }
7738:
7739: ol.LC_docs_parameters li {
7740: margin: 0;
7741: padding-right: 20px;
7742: display: inline;
7743: }
7744:
1.976 raeburn 7745: ol.LC_docs_parameters li:before {
7746: content: "\\002022 \\0020";
7747: }
7748:
7749: li.LC_docs_parameters_title {
7750: font-weight: bold;
7751: }
7752:
7753: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7754: content: "";
7755: }
7756:
1.897 wenzelju 7757: ul#LC_secondary_menu {
1.1107 raeburn 7758: clear: right;
1.911 bisitz 7759: color: $fontmenu;
7760: background: $tabbg;
7761: list-style: none;
7762: padding: 0;
7763: margin: 0;
7764: width: 100%;
1.995 raeburn 7765: text-align: left;
1.1107 raeburn 7766: float: left;
1.808 droeschl 7767: }
7768:
1.897 wenzelju 7769: ul#LC_secondary_menu li {
1.911 bisitz 7770: font-weight: bold;
7771: line-height: 1.8em;
1.1107 raeburn 7772: border-right: 1px solid black;
7773: float: left;
7774: }
7775:
7776: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7777: background-color: $data_table_light;
7778: }
7779:
7780: ul#LC_secondary_menu li a {
1.911 bisitz 7781: padding: 0 0.8em;
1.1107 raeburn 7782: }
7783:
7784: ul#LC_secondary_menu li ul {
7785: display: none;
7786: }
7787:
7788: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7789: display: block;
7790: position: absolute;
7791: margin: 0;
7792: padding: 0;
7793: list-style:none;
7794: float: none;
7795: background-color: $data_table_light;
7796: z-index: 2;
7797: margin-left: -1px;
7798: }
7799:
7800: ul#LC_secondary_menu li ul li {
7801: font-size: 90%;
7802: vertical-align: top;
7803: border-left: 1px solid black;
1.911 bisitz 7804: border-right: 1px solid black;
1.1119 raeburn 7805: background-color: $data_table_light;
1.1107 raeburn 7806: list-style:none;
7807: float: none;
7808: }
7809:
7810: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7811: background-color: $data_table_dark;
1.807 droeschl 7812: }
7813:
1.847 tempelho 7814: ul.LC_TabContent {
1.911 bisitz 7815: display:block;
7816: background: $sidebg;
7817: border-bottom: solid 1px $lg_border_color;
7818: list-style:none;
1.1020 raeburn 7819: margin: -1px -10px 0 -10px;
1.911 bisitz 7820: padding: 0;
1.693 droeschl 7821: }
7822:
1.795 www 7823: ul.LC_TabContent li,
7824: ul.LC_TabContentBigger li {
1.911 bisitz 7825: float:left;
1.741 harmsja 7826: }
1.795 www 7827:
1.897 wenzelju 7828: ul#LC_secondary_menu li a {
1.911 bisitz 7829: color: $fontmenu;
7830: text-decoration: none;
1.693 droeschl 7831: }
1.795 www 7832:
1.721 harmsja 7833: ul.LC_TabContent {
1.952 onken 7834: min-height:20px;
1.721 harmsja 7835: }
1.795 www 7836:
7837: ul.LC_TabContent li {
1.911 bisitz 7838: vertical-align:middle;
1.959 onken 7839: padding: 0 16px 0 10px;
1.911 bisitz 7840: background-color:$tabbg;
7841: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7842: border-left: solid 1px $font;
1.721 harmsja 7843: }
1.795 www 7844:
1.847 tempelho 7845: ul.LC_TabContent .right {
1.911 bisitz 7846: float:right;
1.847 tempelho 7847: }
7848:
1.911 bisitz 7849: ul.LC_TabContent li a,
7850: ul.LC_TabContent li {
7851: color:rgb(47,47,47);
7852: text-decoration:none;
7853: font-size:95%;
7854: font-weight:bold;
1.952 onken 7855: min-height:20px;
7856: }
7857:
1.959 onken 7858: ul.LC_TabContent li a:hover,
7859: ul.LC_TabContent li a:focus {
1.952 onken 7860: color: $button_hover;
1.959 onken 7861: background:none;
7862: outline:none;
1.952 onken 7863: }
7864:
7865: ul.LC_TabContent li:hover {
7866: color: $button_hover;
7867: cursor:pointer;
1.721 harmsja 7868: }
1.795 www 7869:
1.911 bisitz 7870: ul.LC_TabContent li.active {
1.952 onken 7871: color: $font;
1.911 bisitz 7872: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7873: border-bottom:solid 1px #FFFFFF;
7874: cursor: default;
1.744 ehlerst 7875: }
1.795 www 7876:
1.959 onken 7877: ul.LC_TabContent li.active a {
7878: color:$font;
7879: background:#FFFFFF;
7880: outline: none;
7881: }
1.1047 raeburn 7882:
7883: ul.LC_TabContent li.goback {
7884: float: left;
7885: border-left: none;
7886: }
7887:
1.870 tempelho 7888: #maincoursedoc {
1.911 bisitz 7889: clear:both;
1.870 tempelho 7890: }
7891:
7892: ul.LC_TabContentBigger {
1.911 bisitz 7893: display:block;
7894: list-style:none;
7895: padding: 0;
1.870 tempelho 7896: }
7897:
1.795 www 7898: ul.LC_TabContentBigger li {
1.911 bisitz 7899: vertical-align:bottom;
7900: height: 30px;
7901: font-size:110%;
7902: font-weight:bold;
7903: color: #737373;
1.841 tempelho 7904: }
7905:
1.957 onken 7906: ul.LC_TabContentBigger li.active {
7907: position: relative;
7908: top: 1px;
7909: }
7910:
1.870 tempelho 7911: ul.LC_TabContentBigger li a {
1.911 bisitz 7912: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7913: height: 30px;
7914: line-height: 30px;
7915: text-align: center;
7916: display: block;
7917: text-decoration: none;
1.958 onken 7918: outline: none;
1.741 harmsja 7919: }
1.795 www 7920:
1.870 tempelho 7921: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7922: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7923: color:$font;
1.744 ehlerst 7924: }
1.795 www 7925:
1.870 tempelho 7926: ul.LC_TabContentBigger li b {
1.911 bisitz 7927: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7928: display: block;
7929: float: left;
7930: padding: 0 30px;
1.957 onken 7931: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7932: }
7933:
1.956 onken 7934: ul.LC_TabContentBigger li:hover b {
7935: color:$button_hover;
7936: }
7937:
1.870 tempelho 7938: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7939: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7940: color:$font;
1.957 onken 7941: border: 0;
1.741 harmsja 7942: }
1.693 droeschl 7943:
1.870 tempelho 7944:
1.862 bisitz 7945: ul.LC_CourseBreadcrumbs {
7946: background: $sidebg;
1.1020 raeburn 7947: height: 2em;
1.862 bisitz 7948: padding-left: 10px;
1.1020 raeburn 7949: margin: 0;
1.862 bisitz 7950: list-style-position: inside;
7951: }
7952:
1.911 bisitz 7953: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7954: ol#LC_PathBreadcrumbs {
1.911 bisitz 7955: padding-left: 10px;
7956: margin: 0;
1.933 droeschl 7957: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7958: }
7959:
1.911 bisitz 7960: ol#LC_MenuBreadcrumbs li,
7961: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7962: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7963: display: inline;
1.933 droeschl 7964: white-space: normal;
1.693 droeschl 7965: }
7966:
1.823 bisitz 7967: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7968: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7969: text-decoration: none;
7970: font-size:90%;
1.693 droeschl 7971: }
1.795 www 7972:
1.969 droeschl 7973: ol#LC_MenuBreadcrumbs h1 {
7974: display: inline;
7975: font-size: 90%;
7976: line-height: 2.5em;
7977: margin: 0;
7978: padding: 0;
7979: }
7980:
1.795 www 7981: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7982: text-decoration:none;
7983: font-size:100%;
7984: font-weight:bold;
1.693 droeschl 7985: }
1.795 www 7986:
1.840 bisitz 7987: .LC_Box {
1.911 bisitz 7988: border: solid 1px $lg_border_color;
7989: padding: 0 10px 10px 10px;
1.746 neumanie 7990: }
1.795 www 7991:
1.1020 raeburn 7992: .LC_DocsBox {
7993: border: solid 1px $lg_border_color;
7994: padding: 0 0 10px 10px;
7995: }
7996:
1.795 www 7997: .LC_AboutMe_Image {
1.911 bisitz 7998: float:left;
7999: margin-right:10px;
1.747 neumanie 8000: }
1.795 www 8001:
8002: .LC_Clear_AboutMe_Image {
1.911 bisitz 8003: clear:left;
1.747 neumanie 8004: }
1.795 www 8005:
1.721 harmsja 8006: dl.LC_ListStyleClean dt {
1.911 bisitz 8007: padding-right: 5px;
8008: display: table-header-group;
1.693 droeschl 8009: }
8010:
1.721 harmsja 8011: dl.LC_ListStyleClean dd {
1.911 bisitz 8012: display: table-row;
1.693 droeschl 8013: }
8014:
1.721 harmsja 8015: .LC_ListStyleClean,
8016: .LC_ListStyleSimple,
8017: .LC_ListStyleNormal,
1.795 www 8018: .LC_ListStyleSpecial {
1.911 bisitz 8019: /* display:block; */
8020: list-style-position: inside;
8021: list-style-type: none;
8022: overflow: hidden;
8023: padding: 0;
1.693 droeschl 8024: }
8025:
1.721 harmsja 8026: .LC_ListStyleSimple li,
8027: .LC_ListStyleSimple dd,
8028: .LC_ListStyleNormal li,
8029: .LC_ListStyleNormal dd,
8030: .LC_ListStyleSpecial li,
1.795 www 8031: .LC_ListStyleSpecial dd {
1.911 bisitz 8032: margin: 0;
8033: padding: 5px 5px 5px 10px;
8034: clear: both;
1.693 droeschl 8035: }
8036:
1.721 harmsja 8037: .LC_ListStyleClean li,
8038: .LC_ListStyleClean dd {
1.911 bisitz 8039: padding-top: 0;
8040: padding-bottom: 0;
1.693 droeschl 8041: }
8042:
1.721 harmsja 8043: .LC_ListStyleSimple dd,
1.795 www 8044: .LC_ListStyleSimple li {
1.911 bisitz 8045: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8046: }
8047:
1.721 harmsja 8048: .LC_ListStyleSpecial li,
8049: .LC_ListStyleSpecial dd {
1.911 bisitz 8050: list-style-type: none;
8051: background-color: RGB(220, 220, 220);
8052: margin-bottom: 4px;
1.693 droeschl 8053: }
8054:
1.721 harmsja 8055: table.LC_SimpleTable {
1.911 bisitz 8056: margin:5px;
8057: border:solid 1px $lg_border_color;
1.795 www 8058: }
1.693 droeschl 8059:
1.721 harmsja 8060: table.LC_SimpleTable tr {
1.911 bisitz 8061: padding: 0;
8062: border:solid 1px $lg_border_color;
1.693 droeschl 8063: }
1.795 www 8064:
8065: table.LC_SimpleTable thead {
1.911 bisitz 8066: background:rgb(220,220,220);
1.693 droeschl 8067: }
8068:
1.721 harmsja 8069: div.LC_columnSection {
1.911 bisitz 8070: display: block;
8071: clear: both;
8072: overflow: hidden;
8073: margin: 0;
1.693 droeschl 8074: }
8075:
1.721 harmsja 8076: div.LC_columnSection>* {
1.911 bisitz 8077: float: left;
8078: margin: 10px 20px 10px 0;
8079: overflow:hidden;
1.693 droeschl 8080: }
1.721 harmsja 8081:
1.795 www 8082: table em {
1.911 bisitz 8083: font-weight: bold;
8084: font-style: normal;
1.748 schulted 8085: }
1.795 www 8086:
1.779 bisitz 8087: table.LC_tableBrowseRes,
1.795 www 8088: table.LC_tableOfContent {
1.911 bisitz 8089: border:none;
8090: border-spacing: 1px;
8091: padding: 3px;
8092: background-color: #FFFFFF;
8093: font-size: 90%;
1.753 droeschl 8094: }
1.789 droeschl 8095:
1.911 bisitz 8096: table.LC_tableOfContent {
8097: border-collapse: collapse;
1.789 droeschl 8098: }
8099:
1.771 droeschl 8100: table.LC_tableBrowseRes a,
1.768 schulted 8101: table.LC_tableOfContent a {
1.911 bisitz 8102: background-color: transparent;
8103: text-decoration: none;
1.753 droeschl 8104: }
8105:
1.795 www 8106: table.LC_tableOfContent img {
1.911 bisitz 8107: border: none;
8108: height: 1.3em;
8109: vertical-align: text-bottom;
8110: margin-right: 0.3em;
1.753 droeschl 8111: }
1.757 schulted 8112:
1.795 www 8113: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8114: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8115: }
8116:
1.795 www 8117: a#LC_content_toolbar_everything {
1.911 bisitz 8118: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8119: }
8120:
1.795 www 8121: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8122: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8123: }
8124:
1.795 www 8125: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8126: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8127: }
8128:
1.795 www 8129: a#LC_content_toolbar_changefolder {
1.911 bisitz 8130: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8131: }
8132:
1.795 www 8133: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8134: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8135: }
8136:
1.1043 raeburn 8137: a#LC_content_toolbar_edittoplevel {
8138: background-image:url(/res/adm/pages/edittoplevel.gif);
8139: }
8140:
1.795 www 8141: ul#LC_toolbar li a:hover {
1.911 bisitz 8142: background-position: bottom center;
1.757 schulted 8143: }
8144:
1.795 www 8145: ul#LC_toolbar {
1.911 bisitz 8146: padding: 0;
8147: margin: 2px;
8148: list-style:none;
8149: position:relative;
8150: background-color:white;
1.1082 raeburn 8151: overflow: auto;
1.757 schulted 8152: }
8153:
1.795 www 8154: ul#LC_toolbar li {
1.911 bisitz 8155: border:1px solid white;
8156: padding: 0;
8157: margin: 0;
8158: float: left;
8159: display:inline;
8160: vertical-align:middle;
1.1082 raeburn 8161: white-space: nowrap;
1.911 bisitz 8162: }
1.757 schulted 8163:
1.783 amueller 8164:
1.795 www 8165: a.LC_toolbarItem {
1.911 bisitz 8166: display:block;
8167: padding: 0;
8168: margin: 0;
8169: height: 32px;
8170: width: 32px;
8171: color:white;
8172: border: none;
8173: background-repeat:no-repeat;
8174: background-color:transparent;
1.757 schulted 8175: }
8176:
1.915 droeschl 8177: ul.LC_funclist {
8178: margin: 0;
8179: padding: 0.5em 1em 0.5em 0;
8180: }
8181:
1.933 droeschl 8182: ul.LC_funclist > li:first-child {
8183: font-weight:bold;
8184: margin-left:0.8em;
8185: }
8186:
1.915 droeschl 8187: ul.LC_funclist + ul.LC_funclist {
8188: /*
8189: left border as a seperator if we have more than
8190: one list
8191: */
8192: border-left: 1px solid $sidebg;
8193: /*
8194: this hides the left border behind the border of the
8195: outer box if element is wrapped to the next 'line'
8196: */
8197: margin-left: -1px;
8198: }
8199:
1.843 bisitz 8200: ul.LC_funclist li {
1.915 droeschl 8201: display: inline;
1.782 bisitz 8202: white-space: nowrap;
1.915 droeschl 8203: margin: 0 0 0 25px;
8204: line-height: 150%;
1.782 bisitz 8205: }
8206:
1.974 wenzelju 8207: .LC_hidden {
8208: display: none;
8209: }
8210:
1.1030 www 8211: .LCmodal-overlay {
8212: position:fixed;
8213: top:0;
8214: right:0;
8215: bottom:0;
8216: left:0;
8217: height:100%;
8218: width:100%;
8219: margin:0;
8220: padding:0;
8221: background:#999;
8222: opacity:.75;
8223: filter: alpha(opacity=75);
8224: -moz-opacity: 0.75;
8225: z-index:101;
8226: }
8227:
8228: * html .LCmodal-overlay {
8229: position: absolute;
8230: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8231: }
8232:
8233: .LCmodal-window {
8234: position:fixed;
8235: top:50%;
8236: left:50%;
8237: margin:0;
8238: padding:0;
8239: z-index:102;
8240: }
8241:
8242: * html .LCmodal-window {
8243: position:absolute;
8244: }
8245:
8246: .LCclose-window {
8247: position:absolute;
8248: width:32px;
8249: height:32px;
8250: right:8px;
8251: top:8px;
8252: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8253: text-indent:-99999px;
8254: overflow:hidden;
8255: cursor:pointer;
8256: }
8257:
1.1335 ! raeburn 8258: pre.LC_wordwrap {
! 8259: white-space: pre-wrap;
! 8260: white-space: -moz-pre-wrap;
! 8261: white-space: -pre-wrap;
! 8262: white-space: -o-pre-wrap;
! 8263: word-wrap: break-word;
! 8264: }
! 8265:
1.1100 raeburn 8266: /*
1.1231 damieng 8267: styles used for response display
8268: */
8269: div.LC_radiofoil, div.LC_rankfoil {
8270: margin: .5em 0em .5em 0em;
8271: }
8272: table.LC_itemgroup {
8273: margin-top: 1em;
8274: }
8275:
8276: /*
1.1100 raeburn 8277: styles used by TTH when "Default set of options to pass to tth/m
8278: when converting TeX" in course settings has been set
8279:
8280: option passed: -t
8281:
8282: */
8283:
8284: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8285: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8286: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8287: td div.norm {line-height:normal;}
8288:
8289: /*
8290: option passed -y3
8291: */
8292:
8293: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8294: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8295: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8296:
1.1230 damieng 8297: /*
8298: sections with roles, for content only
8299: */
8300: section[class^="role-"] {
8301: padding-left: 10px;
8302: padding-right: 5px;
8303: margin-top: 8px;
8304: margin-bottom: 8px;
8305: border: 1px solid #2A4;
8306: border-radius: 5px;
8307: box-shadow: 0px 1px 1px #BBB;
8308: }
8309: section[class^="role-"]>h1 {
8310: position: relative;
8311: margin: 0px;
8312: padding-top: 10px;
8313: padding-left: 40px;
8314: }
8315: section[class^="role-"]>h1:before {
8316: position: absolute;
8317: left: -5px;
8318: top: 5px;
8319: }
8320: section.role-activity>h1:before {
8321: content:url('/adm/daxe/images/section_icons/activity.png');
8322: }
8323: section.role-advice>h1:before {
8324: content:url('/adm/daxe/images/section_icons/advice.png');
8325: }
8326: section.role-bibliography>h1:before {
8327: content:url('/adm/daxe/images/section_icons/bibliography.png');
8328: }
8329: section.role-citation>h1:before {
8330: content:url('/adm/daxe/images/section_icons/citation.png');
8331: }
8332: section.role-conclusion>h1:before {
8333: content:url('/adm/daxe/images/section_icons/conclusion.png');
8334: }
8335: section.role-definition>h1:before {
8336: content:url('/adm/daxe/images/section_icons/definition.png');
8337: }
8338: section.role-demonstration>h1:before {
8339: content:url('/adm/daxe/images/section_icons/demonstration.png');
8340: }
8341: section.role-example>h1:before {
8342: content:url('/adm/daxe/images/section_icons/example.png');
8343: }
8344: section.role-explanation>h1:before {
8345: content:url('/adm/daxe/images/section_icons/explanation.png');
8346: }
8347: section.role-introduction>h1:before {
8348: content:url('/adm/daxe/images/section_icons/introduction.png');
8349: }
8350: section.role-method>h1:before {
8351: content:url('/adm/daxe/images/section_icons/method.png');
8352: }
8353: section.role-more_information>h1:before {
8354: content:url('/adm/daxe/images/section_icons/more_information.png');
8355: }
8356: section.role-objectives>h1:before {
8357: content:url('/adm/daxe/images/section_icons/objectives.png');
8358: }
8359: section.role-prerequisites>h1:before {
8360: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8361: }
8362: section.role-remark>h1:before {
8363: content:url('/adm/daxe/images/section_icons/remark.png');
8364: }
8365: section.role-reminder>h1:before {
8366: content:url('/adm/daxe/images/section_icons/reminder.png');
8367: }
8368: section.role-summary>h1:before {
8369: content:url('/adm/daxe/images/section_icons/summary.png');
8370: }
8371: section.role-syntax>h1:before {
8372: content:url('/adm/daxe/images/section_icons/syntax.png');
8373: }
8374: section.role-warning>h1:before {
8375: content:url('/adm/daxe/images/section_icons/warning.png');
8376: }
8377:
1.1269 raeburn 8378: #LC_minitab_header {
8379: float:left;
8380: width:100%;
8381: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8382: font-size:93%;
8383: line-height:normal;
8384: margin: 0.5em 0 0.5em 0;
8385: }
8386: #LC_minitab_header ul {
8387: margin:0;
8388: padding:10px 10px 0;
8389: list-style:none;
8390: }
8391: #LC_minitab_header li {
8392: float:left;
8393: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8394: margin:0;
8395: padding:0 0 0 9px;
8396: }
8397: #LC_minitab_header a {
8398: display:block;
8399: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8400: padding:5px 15px 4px 6px;
8401: }
8402: #LC_minitab_header #LC_current_minitab {
8403: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8404: }
8405: #LC_minitab_header #LC_current_minitab a {
8406: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8407: padding-bottom:5px;
8408: }
8409:
8410:
1.343 albertel 8411: END
8412: }
8413:
1.306 albertel 8414: =pod
8415:
8416: =item * &headtag()
8417:
8418: Returns a uniform footer for LON-CAPA web pages.
8419:
1.307 albertel 8420: Inputs: $title - optional title for the head
8421: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8422: $args - optional arguments
1.319 albertel 8423: force_register - if is true call registerurl so the remote is
8424: informed
1.415 albertel 8425: redirect -> array ref of
8426: 1- seconds before redirect occurs
8427: 2- url to redirect to
8428: 3- whether the side effect should occur
1.315 albertel 8429: (side effect of setting
8430: $env{'internal.head.redirect'} to the url
8431: redirected too)
1.352 albertel 8432: domain -> force to color decorate a page for a specific
8433: domain
8434: function -> force usage of a specific rolish color scheme
8435: bgcolor -> override the default page bgcolor
1.460 albertel 8436: no_auto_mt_title
8437: -> prevent &mt()ing the title arg
1.464 albertel 8438:
1.306 albertel 8439: =cut
8440:
8441: sub headtag {
1.313 albertel 8442: my ($title,$head_extra,$args) = @_;
1.306 albertel 8443:
1.363 albertel 8444: my $function = $args->{'function'} || &get_users_function();
8445: my $domain = $args->{'domain'} || &determinedomain();
8446: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8447: my $httphost = $args->{'use_absolute'};
1.418 albertel 8448: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8449: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8450: #time(),
1.418 albertel 8451: $env{'environment.color.timestamp'},
1.363 albertel 8452: $function,$domain,$bgcolor);
8453:
1.369 www 8454: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8455:
1.308 albertel 8456: my $result =
8457: '<head>'.
1.1160 raeburn 8458: &font_settings($args);
1.319 albertel 8459:
1.1188 raeburn 8460: my $inhibitprint;
8461: if ($args->{'print_suppress'}) {
8462: $inhibitprint = &print_suppression();
8463: }
1.1064 raeburn 8464:
1.461 albertel 8465: if (!$args->{'frameset'}) {
8466: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8467: }
1.962 droeschl 8468: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8469: $result .= Apache::lonxml::display_title();
1.319 albertel 8470: }
1.436 albertel 8471: if (!$args->{'no_nav_bar'}
8472: && !$args->{'only_body'}
8473: && !$args->{'frameset'}) {
1.1154 raeburn 8474: $result .= &help_menu_js($httphost);
1.1032 www 8475: $result.=&modal_window();
1.1038 www 8476: $result.=&togglebox_script();
1.1034 www 8477: $result.=&wishlist_window();
1.1041 www 8478: $result.=&LCprogressbarUpdate_script();
1.1034 www 8479: } else {
8480: if ($args->{'add_modal'}) {
8481: $result.=&modal_window();
8482: }
8483: if ($args->{'add_wishlist'}) {
8484: $result.=&wishlist_window();
8485: }
1.1038 www 8486: if ($args->{'add_togglebox'}) {
8487: $result.=&togglebox_script();
8488: }
1.1041 www 8489: if ($args->{'add_progressbar'}) {
8490: $result.=&LCprogressbarUpdate_script();
8491: }
1.436 albertel 8492: }
1.314 albertel 8493: if (ref($args->{'redirect'})) {
1.414 albertel 8494: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8495: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8496: if (!$inhibit_continue) {
8497: $env{'internal.head.redirect'} = $url;
8498: }
1.313 albertel 8499: $result.=<<ADDMETA
8500: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8501: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8502: ADDMETA
1.1210 raeburn 8503: } else {
8504: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8505: my $requrl = $env{'request.uri'};
8506: if ($requrl eq '') {
8507: $requrl = $ENV{'REQUEST_URI'};
8508: $requrl =~ s/\?.+$//;
8509: }
8510: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8511: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8512: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8513: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8514: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8515: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
8516: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8517: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
8518: if ($domdefs{'offloadnow'}{$lonhost}) {
8519: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
8520: if (($newserver) && ($newserver ne $lonhost)) {
8521: my $numsec = 5;
8522: my $timeout = $numsec * 1000;
8523: my ($newurl,$locknum,%locks,$msg);
8524: if ($env{'request.role.adv'}) {
8525: ($locknum,%locks) = &Apache::lonnet::get_locks();
8526: }
8527: my $disable_submit = 0;
8528: if ($requrl =~ /$LONCAPA::assess_re/) {
8529: $disable_submit = 1;
8530: }
8531: if ($locknum) {
8532: my @lockinfo = sort(values(%locks));
8533: $msg = &mt('Once the following tasks are complete: ')."\\n".
8534: join(", ",sort(values(%locks)))."\\n".
8535: &mt('your session will be transferred to a different server, after you click "Roles".');
8536: } else {
8537: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8538: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
8539: }
8540: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8541: $newurl = '/adm/switchserver?otherserver='.$newserver;
8542: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8543: $newurl .= '&role='.$env{'request.role'};
8544: }
8545: if ($env{'request.symb'}) {
8546: $newurl .= '&symb='.$env{'request.symb'};
8547: } else {
8548: $newurl .= '&origurl='.$requrl;
8549: }
8550: }
1.1222 damieng 8551: &js_escape(\$msg);
1.1210 raeburn 8552: $result.=<<OFFLOAD
8553: <meta http-equiv="pragma" content="no-cache" />
8554: <script type="text/javascript">
1.1215 raeburn 8555: // <![CDATA[
1.1210 raeburn 8556: function LC_Offload_Now() {
8557: var dest = "$newurl";
8558: if (dest != '') {
8559: window.location.href="$newurl";
8560: }
8561: }
1.1214 raeburn 8562: \$(document).ready(function () {
8563: window.alert('$msg');
8564: if ($disable_submit) {
1.1210 raeburn 8565: \$(".LC_hwk_submit").prop("disabled", true);
8566: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8567: }
8568: setTimeout('LC_Offload_Now()', $timeout);
8569: });
1.1215 raeburn 8570: // ]]>
1.1210 raeburn 8571: </script>
8572: OFFLOAD
8573: }
8574: }
8575: }
8576: }
8577: }
8578: }
1.313 albertel 8579: }
1.306 albertel 8580: if (!defined($title)) {
8581: $title = 'The LearningOnline Network with CAPA';
8582: }
1.460 albertel 8583: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8584: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8585: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8586: if (!$args->{'frameset'}) {
8587: $result .= ' /';
8588: }
8589: $result .= '>'
1.1064 raeburn 8590: .$inhibitprint
1.414 albertel 8591: .$head_extra;
1.1242 raeburn 8592: my $clientmobile;
8593: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8594: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8595: } else {
8596: $clientmobile = $env{'browser.mobile'};
8597: }
8598: if ($clientmobile) {
1.1137 raeburn 8599: $result .= '
8600: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8601: <meta name="apple-mobile-web-app-capable" content="yes" />';
8602: }
1.1278 raeburn 8603: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8604: return $result.'</head>';
1.306 albertel 8605: }
8606:
8607: =pod
8608:
1.340 albertel 8609: =item * &font_settings()
8610:
8611: Returns neccessary <meta> to set the proper encoding
8612:
1.1160 raeburn 8613: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8614:
8615: =cut
8616:
8617: sub font_settings {
1.1160 raeburn 8618: my ($args) = @_;
1.340 albertel 8619: my $headerstring='';
1.1160 raeburn 8620: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8621: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8622: $headerstring.=
8623: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8624: if (!$args->{'frameset'}) {
8625: $headerstring.= ' /';
8626: }
8627: $headerstring .= '>'."\n";
1.340 albertel 8628: }
8629: return $headerstring;
8630: }
8631:
1.341 albertel 8632: =pod
8633:
1.1064 raeburn 8634: =item * &print_suppression()
8635:
8636: In course context returns css which causes the body to be blank when media="print",
8637: if printout generation is unavailable for the current resource.
8638:
8639: This could be because:
8640:
8641: (a) printstartdate is in the future
8642:
8643: (b) printenddate is in the past
8644:
8645: (c) there is an active exam block with "printout"
8646: functionality blocked
8647:
8648: Users with pav, pfo or evb privileges are exempt.
8649:
8650: Inputs: none
8651:
8652: =cut
8653:
8654:
8655: sub print_suppression {
8656: my $noprint;
8657: if ($env{'request.course.id'}) {
8658: my $scope = $env{'request.course.id'};
8659: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8660: (&Apache::lonnet::allowed('pfo',$scope))) {
8661: return;
8662: }
8663: if ($env{'request.course.sec'} ne '') {
8664: $scope .= "/$env{'request.course.sec'}";
8665: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8666: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8667: return;
1.1064 raeburn 8668: }
8669: }
8670: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8671: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8672: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8673: if ($blocked) {
8674: my $checkrole = "cm./$cdom/$cnum";
8675: if ($env{'request.course.sec'} ne '') {
8676: $checkrole .= "/$env{'request.course.sec'}";
8677: }
8678: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8679: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8680: $noprint = 1;
8681: }
8682: }
8683: unless ($noprint) {
8684: my $symb = &Apache::lonnet::symbread();
8685: if ($symb ne '') {
8686: my $navmap = Apache::lonnavmaps::navmap->new();
8687: if (ref($navmap)) {
8688: my $res = $navmap->getBySymb($symb);
8689: if (ref($res)) {
8690: if (!$res->resprintable()) {
8691: $noprint = 1;
8692: }
8693: }
8694: }
8695: }
8696: }
8697: if ($noprint) {
8698: return <<"ENDSTYLE";
8699: <style type="text/css" media="print">
8700: body { display:none }
8701: </style>
8702: ENDSTYLE
8703: }
8704: }
8705: return;
8706: }
8707:
8708: =pod
8709:
1.341 albertel 8710: =item * &xml_begin()
8711:
8712: Returns the needed doctype and <html>
8713:
8714: Inputs: none
8715:
8716: =cut
8717:
8718: sub xml_begin {
1.1168 raeburn 8719: my ($is_frameset) = @_;
1.341 albertel 8720: my $output='';
8721:
8722: if ($env{'browser.mathml'}) {
8723: $output='<?xml version="1.0"?>'
8724: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8725: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8726:
8727: # .'<!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">] >'
8728: .'<!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">'
8729: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8730: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8731: } elsif ($is_frameset) {
8732: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8733: '<html>'."\n";
1.341 albertel 8734: } else {
1.1168 raeburn 8735: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8736: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8737: }
8738: return $output;
8739: }
1.340 albertel 8740:
8741: =pod
8742:
1.306 albertel 8743: =item * &start_page()
8744:
8745: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8746:
1.648 raeburn 8747: Inputs:
8748:
8749: =over 4
8750:
8751: $title - optional title for the page
8752:
8753: $head_extra - optional extra HTML to incude inside the <head>
8754:
8755: $args - additional optional args supported are:
8756:
8757: =over 8
8758:
8759: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8760: arg on
1.814 bisitz 8761: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8762: add_entries -> additional attributes to add to the <body>
8763: domain -> force to color decorate a page for a
1.317 albertel 8764: specific domain
1.648 raeburn 8765: function -> force usage of a specific rolish color
1.317 albertel 8766: scheme
1.648 raeburn 8767: redirect -> see &headtag()
8768: bgcolor -> override the default page bg color
8769: js_ready -> return a string ready for being used in
1.317 albertel 8770: a javascript writeln
1.648 raeburn 8771: html_encode -> return a string ready for being used in
1.320 albertel 8772: a html attribute
1.648 raeburn 8773: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8774: $forcereg arg
1.648 raeburn 8775: frameset -> if true will start with a <frameset>
1.330 albertel 8776: rather than <body>
1.648 raeburn 8777: skip_phases -> hash ref of
1.338 albertel 8778: head -> skip the <html><head> generation
8779: body -> skip all <body> generation
1.648 raeburn 8780: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8781: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8782: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 8783: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8784: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 8785: group -> includes the current group, if page is for a
1.1274 raeburn 8786: specific group
8787: use_absolute -> for request for external resource or syllabus, this
8788: will contain https://<hostname> if server uses
8789: https (as per hosts.tab), but request is for http
8790: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8791:
1.648 raeburn 8792: =back
1.460 albertel 8793:
1.648 raeburn 8794: =back
1.562 albertel 8795:
1.306 albertel 8796: =cut
8797:
8798: sub start_page {
1.309 albertel 8799: my ($title,$head_extra,$args) = @_;
1.318 albertel 8800: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8801:
1.315 albertel 8802: $env{'internal.start_page'}++;
1.1318 raeburn 8803: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu);
1.964 droeschl 8804:
1.338 albertel 8805: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8806: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8807: }
1.1316 raeburn 8808:
8809: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 8810: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
8811: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
8812: $args->{'no_primary_menu'} = 1;
8813: }
8814: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
8815: $args->{'no_inline_menu'} = 1;
8816: }
8817: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
8818: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
8819: }
8820: } else {
8821: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8822: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
8823: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
8824: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
8825: $args->{'no_primary_menu'} = 1;
8826: }
8827: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
8828: $args->{'no_inline_menu'} = 1;
8829: }
8830: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
8831: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
8832: }
8833: }
8834: }
1.1316 raeburn 8835: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
8836: $env{'course.'.$env{'request.course.id'}.'.domain'},
8837: $env{'course.'.$env{'request.course.id'}.'.num'});
8838: }
1.338 albertel 8839:
8840: if (! exists($args->{'skip_phases'}{'body'}) ) {
8841: if ($args->{'frameset'}) {
8842: my $attr_string = &make_attr_string($args->{'force_register'},
8843: $args->{'add_entries'});
8844: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8845: } else {
8846: $result .=
8847: &bodytag($title,
8848: $args->{'function'}, $args->{'add_entries'},
8849: $args->{'only_body'}, $args->{'domain'},
8850: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8851: $args->{'bgcolor'}, $args,
1.1318 raeburn 8852: \@advtools,$ltiscope,$ltiuri,\%ltimenu);
1.831 bisitz 8853: }
1.330 albertel 8854: }
1.338 albertel 8855:
1.315 albertel 8856: if ($args->{'js_ready'}) {
1.713 kaisler 8857: $result = &js_ready($result);
1.315 albertel 8858: }
1.320 albertel 8859: if ($args->{'html_encode'}) {
1.713 kaisler 8860: $result = &html_encode($result);
8861: }
8862:
1.813 bisitz 8863: # Preparation for new and consistent functionlist at top of screen
8864: # if ($args->{'functionlist'}) {
8865: # $result .= &build_functionlist();
8866: #}
8867:
1.964 droeschl 8868: # Don't add anything more if only_body wanted or in const space
8869: return $result if $args->{'only_body'}
8870: || $env{'request.state'} eq 'construct';
1.813 bisitz 8871:
8872: #Breadcrumbs
1.758 kaisler 8873: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8874: &Apache::lonhtmlcommon::clear_breadcrumbs();
8875: #if any br links exists, add them to the breadcrumbs
8876: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8877: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8878: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8879: }
8880: }
1.1096 raeburn 8881: # if @advtools array contains items add then to the breadcrumbs
8882: if (@advtools > 0) {
8883: &Apache::lonmenu::advtools_crumbs(@advtools);
8884: }
1.1272 raeburn 8885: my $menulink;
8886: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8887: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 8888: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 8889: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
8890: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
8891: (!$env{'request.role.adv'}))) {
8892: $menulink = 0;
8893: } else {
8894: undef($menulink);
8895: }
1.758 kaisler 8896: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8897: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 8898: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 8899: } else {
1.1272 raeburn 8900: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8901: }
1.320 albertel 8902: }
1.315 albertel 8903: return $result;
1.306 albertel 8904: }
8905:
8906: sub end_page {
1.315 albertel 8907: my ($args) = @_;
8908: $env{'internal.end_page'}++;
1.330 albertel 8909: my $result;
1.335 albertel 8910: if ($args->{'discussion'}) {
8911: my ($target,$parser);
8912: if (ref($args->{'discussion'})) {
8913: ($target,$parser) =($args->{'discussion'}{'target'},
8914: $args->{'discussion'}{'parser'});
8915: }
8916: $result .= &Apache::lonxml::xmlend($target,$parser);
8917: }
1.330 albertel 8918: if ($args->{'frameset'}) {
8919: $result .= '</frameset>';
8920: } else {
1.635 raeburn 8921: $result .= &endbodytag($args);
1.330 albertel 8922: }
1.1080 raeburn 8923: unless ($args->{'notbody'}) {
8924: $result .= "\n</html>";
8925: }
1.330 albertel 8926:
1.315 albertel 8927: if ($args->{'js_ready'}) {
1.317 albertel 8928: $result = &js_ready($result);
1.315 albertel 8929: }
1.335 albertel 8930:
1.320 albertel 8931: if ($args->{'html_encode'}) {
8932: $result = &html_encode($result);
8933: }
1.335 albertel 8934:
1.315 albertel 8935: return $result;
8936: }
8937:
1.1034 www 8938: sub wishlist_window {
8939: return(<<'ENDWISHLIST');
1.1046 raeburn 8940: <script type="text/javascript">
1.1034 www 8941: // <![CDATA[
8942: // <!-- BEGIN LON-CAPA Internal
8943: function set_wishlistlink(title, path) {
8944: if (!title) {
8945: title = document.title;
8946: title = title.replace(/^LON-CAPA /,'');
8947: }
1.1175 raeburn 8948: title = encodeURIComponent(title);
1.1203 raeburn 8949: title = title.replace("'","\\\'");
1.1034 www 8950: if (!path) {
8951: path = location.pathname;
8952: }
1.1175 raeburn 8953: path = encodeURIComponent(path);
1.1203 raeburn 8954: path = path.replace("'","\\\'");
1.1034 www 8955: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8956: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8957: }
8958: // END LON-CAPA Internal -->
8959: // ]]>
8960: </script>
8961: ENDWISHLIST
8962: }
8963:
1.1030 www 8964: sub modal_window {
8965: return(<<'ENDMODAL');
1.1046 raeburn 8966: <script type="text/javascript">
1.1030 www 8967: // <![CDATA[
8968: // <!-- BEGIN LON-CAPA Internal
8969: var modalWindow = {
8970: parent:"body",
8971: windowId:null,
8972: content:null,
8973: width:null,
8974: height:null,
8975: close:function()
8976: {
8977: $(".LCmodal-window").remove();
8978: $(".LCmodal-overlay").remove();
8979: },
8980: open:function()
8981: {
8982: var modal = "";
8983: modal += "<div class=\"LCmodal-overlay\"></div>";
8984: 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;\">";
8985: modal += this.content;
8986: modal += "</div>";
8987:
8988: $(this.parent).append(modal);
8989:
8990: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8991: $(".LCclose-window").click(function(){modalWindow.close();});
8992: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8993: }
8994: };
1.1140 raeburn 8995: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8996: {
1.1266 raeburn 8997: source = source.replace(/'/g,"'");
1.1030 www 8998: modalWindow.windowId = "myModal";
8999: modalWindow.width = width;
9000: modalWindow.height = height;
1.1196 raeburn 9001: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9002: modalWindow.open();
1.1208 raeburn 9003: };
1.1030 www 9004: // END LON-CAPA Internal -->
9005: // ]]>
9006: </script>
9007: ENDMODAL
9008: }
9009:
9010: sub modal_link {
1.1140 raeburn 9011: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9012: unless ($width) { $width=480; }
9013: unless ($height) { $height=400; }
1.1031 www 9014: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 9015: unless ($transparency) { $transparency='true'; }
9016:
1.1074 raeburn 9017: my $target_attr;
9018: if (defined($target)) {
9019: $target_attr = 'target="'.$target.'"';
9020: }
9021: return <<"ENDLINK";
1.1140 raeburn 9022: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 9023: $linktext</a>
9024: ENDLINK
1.1030 www 9025: }
9026:
1.1032 www 9027: sub modal_adhoc_script {
9028: my ($funcname,$width,$height,$content)=@_;
9029: return (<<ENDADHOC);
1.1046 raeburn 9030: <script type="text/javascript">
1.1032 www 9031: // <![CDATA[
9032: var $funcname = function()
9033: {
9034: modalWindow.windowId = "myModal";
9035: modalWindow.width = $width;
9036: modalWindow.height = $height;
9037: modalWindow.content = '$content';
9038: modalWindow.open();
9039: };
9040: // ]]>
9041: </script>
9042: ENDADHOC
9043: }
9044:
1.1041 www 9045: sub modal_adhoc_inner {
9046: my ($funcname,$width,$height,$content)=@_;
9047: my $innerwidth=$width-20;
9048: $content=&js_ready(
1.1140 raeburn 9049: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
9050: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9051: $content.
1.1041 www 9052: &end_scrollbox().
1.1140 raeburn 9053: &end_page()
1.1041 www 9054: );
9055: return &modal_adhoc_script($funcname,$width,$height,$content);
9056: }
9057:
9058: sub modal_adhoc_window {
9059: my ($funcname,$width,$height,$content,$linktext)=@_;
9060: return &modal_adhoc_inner($funcname,$width,$height,$content).
9061: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9062: }
9063:
9064: sub modal_adhoc_launch {
9065: my ($funcname,$width,$height,$content)=@_;
9066: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9067: <script type="text/javascript">
9068: // <![CDATA[
9069: $funcname();
9070: // ]]>
9071: </script>
9072: ENDLAUNCH
9073: }
9074:
9075: sub modal_adhoc_close {
9076: return (<<ENDCLOSE);
9077: <script type="text/javascript">
9078: // <![CDATA[
9079: modalWindow.close();
9080: // ]]>
9081: </script>
9082: ENDCLOSE
9083: }
9084:
1.1038 www 9085: sub togglebox_script {
9086: return(<<ENDTOGGLE);
9087: <script type="text/javascript">
9088: // <![CDATA[
9089: function LCtoggleDisplay(id,hidetext,showtext) {
9090: link = document.getElementById(id + "link").childNodes[0];
9091: with (document.getElementById(id).style) {
9092: if (display == "none" ) {
9093: display = "inline";
9094: link.nodeValue = hidetext;
9095: } else {
9096: display = "none";
9097: link.nodeValue = showtext;
9098: }
9099: }
9100: }
9101: // ]]>
9102: </script>
9103: ENDTOGGLE
9104: }
9105:
1.1039 www 9106: sub start_togglebox {
9107: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9108: unless ($heading) { $heading=''; } else { $heading.=' '; }
9109: unless ($showtext) { $showtext=&mt('show'); }
9110: unless ($hidetext) { $hidetext=&mt('hide'); }
9111: unless ($headerbg) { $headerbg='#FFFFFF'; }
9112: return &start_data_table().
9113: &start_data_table_header_row().
9114: '<td bgcolor="'.$headerbg.'">'.$heading.
9115: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9116: $showtext.'\')">'.$showtext.'</a>]</td>'.
9117: &end_data_table_header_row().
9118: '<tr id="'.$id.'" style="display:none""><td>';
9119: }
9120:
9121: sub end_togglebox {
9122: return '</td></tr>'.&end_data_table();
9123: }
9124:
1.1041 www 9125: sub LCprogressbar_script {
1.1302 raeburn 9126: my ($id,$number_to_do)=@_;
9127: if ($number_to_do) {
9128: return(<<ENDPROGRESS);
1.1041 www 9129: <script type="text/javascript">
9130: // <![CDATA[
1.1045 www 9131: \$('#progressbar$id').progressbar({
1.1041 www 9132: value: 0,
9133: change: function(event, ui) {
9134: var newVal = \$(this).progressbar('option', 'value');
9135: \$('.pblabel', this).text(LCprogressTxt);
9136: }
9137: });
9138: // ]]>
9139: </script>
9140: ENDPROGRESS
1.1302 raeburn 9141: } else {
9142: return(<<ENDPROGRESS);
9143: <script type="text/javascript">
9144: // <![CDATA[
9145: \$('#progressbar$id').progressbar({
9146: value: false,
9147: create: function(event, ui) {
9148: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9149: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9150: }
9151: });
9152: // ]]>
9153: </script>
9154: ENDPROGRESS
9155: }
1.1041 www 9156: }
9157:
9158: sub LCprogressbarUpdate_script {
9159: return(<<ENDPROGRESSUPDATE);
9160: <style type="text/css">
9161: .ui-progressbar { position:relative; }
1.1302 raeburn 9162: .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 9163: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9164: </style>
9165: <script type="text/javascript">
9166: // <![CDATA[
1.1045 www 9167: var LCprogressTxt='---';
9168:
1.1302 raeburn 9169: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9170: LCprogressTxt=progresstext;
1.1302 raeburn 9171: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9172: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9173: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 9174: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9175: } else {
9176: \$('#progressbar'+id).progressbar('value',percent);
9177: }
1.1041 www 9178: }
9179: // ]]>
9180: </script>
9181: ENDPROGRESSUPDATE
9182: }
9183:
1.1042 www 9184: my $LClastpercent;
1.1045 www 9185: my $LCidcnt;
9186: my $LCcurrentid;
1.1042 www 9187:
1.1041 www 9188: sub LCprogressbar {
1.1302 raeburn 9189: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9190: $LClastpercent=0;
1.1045 www 9191: $LCidcnt++;
9192: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 9193: my ($starting,$content);
9194: if ($number_to_do) {
9195: $starting=&mt('Starting');
9196: $content=(<<ENDPROGBAR);
9197: $preamble
1.1045 www 9198: <div id="progressbar$LCcurrentid">
1.1041 www 9199: <span class="pblabel">$starting</span>
9200: </div>
9201: ENDPROGBAR
1.1302 raeburn 9202: } else {
9203: $starting=&mt('Loading...');
9204: $LClastpercent='false';
9205: $content=(<<ENDPROGBAR);
9206: $preamble
9207: <div id="progressbar$LCcurrentid">
9208: <div class="progress-label">$starting</div>
9209: </div>
9210: ENDPROGBAR
9211: }
9212: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9213: }
9214:
9215: sub LCprogressbarUpdate {
1.1302 raeburn 9216: my ($r,$val,$text,$number_to_do)=@_;
9217: if ($number_to_do) {
9218: unless ($val) {
9219: if ($LClastpercent) {
9220: $val=$LClastpercent;
9221: } else {
9222: $val=0;
9223: }
9224: }
9225: if ($val<0) { $val=0; }
9226: if ($val>100) { $val=0; }
9227: $LClastpercent=$val;
9228: unless ($text) { $text=$val.'%'; }
9229: } else {
9230: $val = 'false';
1.1042 www 9231: }
1.1041 www 9232: $text=&js_ready($text);
1.1044 www 9233: &r_print($r,<<ENDUPDATE);
1.1041 www 9234: <script type="text/javascript">
9235: // <![CDATA[
1.1302 raeburn 9236: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9237: // ]]>
9238: </script>
9239: ENDUPDATE
1.1035 www 9240: }
9241:
1.1042 www 9242: sub LCprogressbarClose {
9243: my ($r)=@_;
9244: $LClastpercent=0;
1.1044 www 9245: &r_print($r,<<ENDCLOSE);
1.1042 www 9246: <script type="text/javascript">
9247: // <![CDATA[
1.1045 www 9248: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9249: // ]]>
9250: </script>
9251: ENDCLOSE
1.1044 www 9252: }
9253:
9254: sub r_print {
9255: my ($r,$to_print)=@_;
9256: if ($r) {
9257: $r->print($to_print);
9258: $r->rflush();
9259: } else {
9260: print($to_print);
9261: }
1.1042 www 9262: }
9263:
1.320 albertel 9264: sub html_encode {
9265: my ($result) = @_;
9266:
1.322 albertel 9267: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9268:
9269: return $result;
9270: }
1.1044 www 9271:
1.317 albertel 9272: sub js_ready {
9273: my ($result) = @_;
9274:
1.323 albertel 9275: $result =~ s/[\n\r]/ /xmsg;
9276: $result =~ s/\\/\\\\/xmsg;
9277: $result =~ s/'/\\'/xmsg;
1.372 albertel 9278: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9279:
9280: return $result;
9281: }
9282:
1.315 albertel 9283: sub validate_page {
9284: if ( exists($env{'internal.start_page'})
1.316 albertel 9285: && $env{'internal.start_page'} > 1) {
9286: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9287: $env{'internal.start_page'}.' '.
1.316 albertel 9288: $ENV{'request.filename'});
1.315 albertel 9289: }
9290: if ( exists($env{'internal.end_page'})
1.316 albertel 9291: && $env{'internal.end_page'} > 1) {
9292: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9293: $env{'internal.end_page'}.' '.
1.316 albertel 9294: $env{'request.filename'});
1.315 albertel 9295: }
9296: if ( exists($env{'internal.start_page'})
9297: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9298: &Apache::lonnet::logthis('start_page called without end_page '.
9299: $env{'request.filename'});
1.315 albertel 9300: }
9301: if ( ! exists($env{'internal.start_page'})
9302: && exists($env{'internal.end_page'})) {
1.316 albertel 9303: &Apache::lonnet::logthis('end_page called without start_page'.
9304: $env{'request.filename'});
1.315 albertel 9305: }
1.306 albertel 9306: }
1.315 albertel 9307:
1.996 www 9308:
9309: sub start_scrollbox {
1.1140 raeburn 9310: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9311: unless ($outerwidth) { $outerwidth='520px'; }
9312: unless ($width) { $width='500px'; }
9313: unless ($height) { $height='200px'; }
1.1075 raeburn 9314: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9315: if ($id ne '') {
1.1140 raeburn 9316: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9317: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9318: }
1.1075 raeburn 9319: if ($bgcolor ne '') {
9320: $tdcol = "background-color: $bgcolor;";
9321: }
1.1137 raeburn 9322: my $nicescroll_js;
9323: if ($env{'browser.mobile'}) {
1.1140 raeburn 9324: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9325: }
9326: return <<"END";
9327: $nicescroll_js
9328:
9329: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9330: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9331: END
9332: }
9333:
9334: sub end_scrollbox {
9335: return '</div></td></tr></table>';
9336: }
9337:
9338: sub nicescroll_javascript {
9339: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9340: my %options;
9341: if (ref($cursor) eq 'HASH') {
9342: %options = %{$cursor};
9343: }
9344: unless ($options{'railalign'} =~ /^left|right$/) {
9345: $options{'railalign'} = 'left';
9346: }
9347: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9348: my $function = &get_users_function();
9349: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9350: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9351: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9352: }
1.1140 raeburn 9353: }
9354: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9355: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9356: $options{'cursoropacity'}='1.0';
9357: }
1.1140 raeburn 9358: } else {
9359: $options{'cursoropacity'}='1.0';
9360: }
9361: if ($options{'cursorfixedheight'} eq 'none') {
9362: delete($options{'cursorfixedheight'});
9363: } else {
9364: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9365: }
9366: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9367: delete($options{'railoffset'});
9368: }
9369: my @niceoptions;
9370: while (my($key,$value) = each(%options)) {
9371: if ($value =~ /^\{.+\}$/) {
9372: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9373: } else {
1.1140 raeburn 9374: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9375: }
1.1140 raeburn 9376: }
9377: my $nicescroll_js = '
1.1137 raeburn 9378: $(document).ready(
1.1140 raeburn 9379: function() {
9380: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9381: }
1.1137 raeburn 9382: );
9383: ';
1.1140 raeburn 9384: if ($framecheck) {
9385: $nicescroll_js .= '
9386: function expand_div(caller) {
9387: if (top === self) {
9388: document.getElementById("'.$id.'").style.width = "auto";
9389: document.getElementById("'.$id.'").style.height = "auto";
9390: } else {
9391: try {
9392: if (parent.frames) {
9393: if (parent.frames.length > 1) {
9394: var framesrc = parent.frames[1].location.href;
9395: var currsrc = framesrc.replace(/\#.*$/,"");
9396: if ((caller == "search") || (currsrc == "'.$location.'")) {
9397: document.getElementById("'.$id.'").style.width = "auto";
9398: document.getElementById("'.$id.'").style.height = "auto";
9399: }
9400: }
9401: }
9402: } catch (e) {
9403: return;
9404: }
1.1137 raeburn 9405: }
1.1140 raeburn 9406: return;
1.996 www 9407: }
1.1140 raeburn 9408: ';
9409: }
9410: if ($needjsready) {
9411: $nicescroll_js = '
9412: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9413: } else {
9414: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9415: }
9416: return $nicescroll_js;
1.996 www 9417: }
9418:
1.318 albertel 9419: sub simple_error_page {
1.1150 bisitz 9420: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 9421: my %displayargs;
1.1151 raeburn 9422: if (ref($args) eq 'HASH') {
9423: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 9424: if ($args->{'only_body'}) {
9425: $displayargs{'only_body'} = 1;
9426: }
9427: if ($args->{'no_nav_bar'}) {
9428: $displayargs{'no_nav_bar'} = 1;
9429: }
1.1151 raeburn 9430: } else {
9431: $msg = &mt($msg);
9432: }
1.1150 bisitz 9433:
1.318 albertel 9434: my $page =
1.1304 raeburn 9435: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 9436: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9437: &Apache::loncommon::end_page();
9438: if (ref($r)) {
9439: $r->print($page);
1.327 albertel 9440: return;
1.318 albertel 9441: }
9442: return $page;
9443: }
1.347 albertel 9444:
9445: {
1.610 albertel 9446: my @row_count;
1.961 onken 9447:
9448: sub start_data_table_count {
9449: unshift(@row_count, 0);
9450: return;
9451: }
9452:
9453: sub end_data_table_count {
9454: shift(@row_count);
9455: return;
9456: }
9457:
1.347 albertel 9458: sub start_data_table {
1.1018 raeburn 9459: my ($add_class,$id) = @_;
1.422 albertel 9460: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9461: my $table_id;
9462: if (defined($id)) {
9463: $table_id = ' id="'.$id.'"';
9464: }
1.961 onken 9465: &start_data_table_count();
1.1018 raeburn 9466: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9467: }
9468:
9469: sub end_data_table {
1.961 onken 9470: &end_data_table_count();
1.389 albertel 9471: return '</table>'."\n";;
1.347 albertel 9472: }
9473:
9474: sub start_data_table_row {
1.974 wenzelju 9475: my ($add_class, $id) = @_;
1.610 albertel 9476: $row_count[0]++;
9477: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9478: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9479: $id = (' id="'.$id.'"') unless ($id eq '');
9480: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9481: }
1.471 banghart 9482:
9483: sub continue_data_table_row {
1.974 wenzelju 9484: my ($add_class, $id) = @_;
1.610 albertel 9485: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9486: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9487: $id = (' id="'.$id.'"') unless ($id eq '');
9488: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9489: }
1.347 albertel 9490:
9491: sub end_data_table_row {
1.389 albertel 9492: return '</tr>'."\n";;
1.347 albertel 9493: }
1.367 www 9494:
1.421 albertel 9495: sub start_data_table_empty_row {
1.707 bisitz 9496: # $row_count[0]++;
1.421 albertel 9497: return '<tr class="LC_empty_row" >'."\n";;
9498: }
9499:
9500: sub end_data_table_empty_row {
9501: return '</tr>'."\n";;
9502: }
9503:
1.367 www 9504: sub start_data_table_header_row {
1.389 albertel 9505: return '<tr class="LC_header_row">'."\n";;
1.367 www 9506: }
9507:
9508: sub end_data_table_header_row {
1.389 albertel 9509: return '</tr>'."\n";;
1.367 www 9510: }
1.890 droeschl 9511:
9512: sub data_table_caption {
9513: my $caption = shift;
9514: return "<caption class=\"LC_caption\">$caption</caption>";
9515: }
1.347 albertel 9516: }
9517:
1.548 albertel 9518: =pod
9519:
9520: =item * &inhibit_menu_check($arg)
9521:
9522: Checks for a inhibitmenu state and generates output to preserve it
9523:
9524: Inputs: $arg - can be any of
9525: - undef - in which case the return value is a string
9526: to add into arguments list of a uri
9527: - 'input' - in which case the return value is a HTML
9528: <form> <input> field of type hidden to
9529: preserve the value
9530: - a url - in which case the return value is the url with
9531: the neccesary cgi args added to preserve the
9532: inhibitmenu state
9533: - a ref to a url - no return value, but the string is
9534: updated to include the neccessary cgi
9535: args to preserve the inhibitmenu state
9536:
9537: =cut
9538:
9539: sub inhibit_menu_check {
9540: my ($arg) = @_;
9541: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9542: if ($arg eq 'input') {
9543: if ($env{'form.inhibitmenu'}) {
9544: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9545: } else {
9546: return
9547: }
9548: }
9549: if ($env{'form.inhibitmenu'}) {
9550: if (ref($arg)) {
9551: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9552: } elsif ($arg eq '') {
9553: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9554: } else {
9555: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9556: }
9557: }
9558: if (!ref($arg)) {
9559: return $arg;
9560: }
9561: }
9562:
1.251 albertel 9563: ###############################################
1.182 matthew 9564:
9565: =pod
9566:
1.549 albertel 9567: =back
9568:
9569: =head1 User Information Routines
9570:
9571: =over 4
9572:
1.405 albertel 9573: =item * &get_users_function()
1.182 matthew 9574:
9575: Used by &bodytag to determine the current users primary role.
9576: Returns either 'student','coordinator','admin', or 'author'.
9577:
9578: =cut
9579:
9580: ###############################################
9581: sub get_users_function {
1.815 tempelho 9582: my $function = 'norole';
1.818 tempelho 9583: if ($env{'request.role'}=~/^(st)/) {
9584: $function='student';
9585: }
1.907 raeburn 9586: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9587: $function='coordinator';
9588: }
1.258 albertel 9589: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9590: $function='admin';
9591: }
1.826 bisitz 9592: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9593: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9594: $function='author';
9595: }
9596: return $function;
1.54 www 9597: }
1.99 www 9598:
9599: ###############################################
9600:
1.233 raeburn 9601: =pod
9602:
1.821 raeburn 9603: =item * &show_course()
9604:
9605: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9606: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9607:
9608: Inputs:
9609: None
9610:
9611: Outputs:
9612: Scalar: 1 if 'Course' to be used, 0 otherwise.
9613:
9614: =cut
9615:
9616: ###############################################
9617: sub show_course {
9618: my $course = !$env{'user.adv'};
9619: if (!$env{'user.adv'}) {
9620: foreach my $env (keys(%env)) {
9621: next if ($env !~ m/^user\.priv\./);
9622: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9623: $course = 0;
9624: last;
9625: }
9626: }
9627: }
9628: return $course;
9629: }
9630:
9631: ###############################################
9632:
9633: =pod
9634:
1.542 raeburn 9635: =item * &check_user_status()
1.274 raeburn 9636:
9637: Determines current status of supplied role for a
9638: specific user. Roles can be active, previous or future.
9639:
9640: Inputs:
9641: user's domain, user's username, course's domain,
1.375 raeburn 9642: course's number, optional section ID.
1.274 raeburn 9643:
9644: Outputs:
9645: role status: active, previous or future.
9646:
9647: =cut
9648:
9649: sub check_user_status {
1.412 raeburn 9650: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9651: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9652: my @uroles = keys(%userinfo);
1.274 raeburn 9653: my $srchstr;
9654: my $active_chk = 'none';
1.412 raeburn 9655: my $now = time;
1.274 raeburn 9656: if (@uroles > 0) {
1.908 raeburn 9657: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9658: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9659: } else {
1.412 raeburn 9660: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9661: }
9662: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9663: my $role_end = 0;
9664: my $role_start = 0;
9665: $active_chk = 'active';
1.412 raeburn 9666: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9667: $role_end = $1;
9668: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9669: $role_start = $1;
1.274 raeburn 9670: }
9671: }
9672: if ($role_start > 0) {
1.412 raeburn 9673: if ($now < $role_start) {
1.274 raeburn 9674: $active_chk = 'future';
9675: }
9676: }
9677: if ($role_end > 0) {
1.412 raeburn 9678: if ($now > $role_end) {
1.274 raeburn 9679: $active_chk = 'previous';
9680: }
9681: }
9682: }
9683: }
9684: return $active_chk;
9685: }
9686:
9687: ###############################################
9688:
9689: =pod
9690:
1.405 albertel 9691: =item * &get_sections()
1.233 raeburn 9692:
9693: Determines all the sections for a course including
9694: sections with students and sections containing other roles.
1.419 raeburn 9695: Incoming parameters:
9696:
9697: 1. domain
9698: 2. course number
9699: 3. reference to array containing roles for which sections should
9700: be gathered (optional).
9701: 4. reference to array containing status types for which sections
9702: should be gathered (optional).
9703:
9704: If the third argument is undefined, sections are gathered for any role.
9705: If the fourth argument is undefined, sections are gathered for any status.
9706: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9707:
1.374 raeburn 9708: Returns section hash (keys are section IDs, values are
9709: number of users in each section), subject to the
1.419 raeburn 9710: optional roles filter, optional status filter
1.233 raeburn 9711:
9712: =cut
9713:
9714: ###############################################
9715: sub get_sections {
1.419 raeburn 9716: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9717: if (!defined($cdom) || !defined($cnum)) {
9718: my $cid = $env{'request.course.id'};
9719:
9720: return if (!defined($cid));
9721:
9722: $cdom = $env{'course.'.$cid.'.domain'};
9723: $cnum = $env{'course.'.$cid.'.num'};
9724: }
9725:
9726: my %sectioncount;
1.419 raeburn 9727: my $now = time;
1.240 albertel 9728:
1.1118 raeburn 9729: my $check_students = 1;
9730: my $only_students = 0;
9731: if (ref($possible_roles) eq 'ARRAY') {
9732: if (grep(/^st$/,@{$possible_roles})) {
9733: if (@{$possible_roles} == 1) {
9734: $only_students = 1;
9735: }
9736: } else {
9737: $check_students = 0;
9738: }
9739: }
9740:
9741: if ($check_students) {
1.276 albertel 9742: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9743: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9744: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9745: my $start_index = &Apache::loncoursedata::CL_START();
9746: my $end_index = &Apache::loncoursedata::CL_END();
9747: my $status;
1.366 albertel 9748: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9749: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9750: $data->[$status_index],
9751: $data->[$start_index],
9752: $data->[$end_index]);
9753: if ($stu_status eq 'Active') {
9754: $status = 'active';
9755: } elsif ($end < $now) {
9756: $status = 'previous';
9757: } elsif ($start > $now) {
9758: $status = 'future';
9759: }
9760: if ($section ne '-1' && $section !~ /^\s*$/) {
9761: if ((!defined($possible_status)) || (($status ne '') &&
9762: (grep/^\Q$status\E$/,@{$possible_status}))) {
9763: $sectioncount{$section}++;
9764: }
1.240 albertel 9765: }
9766: }
9767: }
1.1118 raeburn 9768: if ($only_students) {
9769: return %sectioncount;
9770: }
1.240 albertel 9771: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9772: foreach my $user (sort(keys(%courseroles))) {
9773: if ($user !~ /^(\w{2})/) { next; }
9774: my ($role) = ($user =~ /^(\w{2})/);
9775: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9776: my ($section,$status);
1.240 albertel 9777: if ($role eq 'cr' &&
9778: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9779: $section=$1;
9780: }
9781: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9782: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9783: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9784: if ($end == -1 && $start == -1) {
9785: next; #deleted role
9786: }
9787: if (!defined($possible_status)) {
9788: $sectioncount{$section}++;
9789: } else {
9790: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9791: $status = 'active';
9792: } elsif ($end < $now) {
9793: $status = 'future';
9794: } elsif ($start > $now) {
9795: $status = 'previous';
9796: }
9797: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9798: $sectioncount{$section}++;
9799: }
9800: }
1.233 raeburn 9801: }
1.366 albertel 9802: return %sectioncount;
1.233 raeburn 9803: }
9804:
1.274 raeburn 9805: ###############################################
1.294 raeburn 9806:
9807: =pod
1.405 albertel 9808:
9809: =item * &get_course_users()
9810:
1.275 raeburn 9811: Retrieves usernames:domains for users in the specified course
9812: with specific role(s), and access status.
9813:
9814: Incoming parameters:
1.277 albertel 9815: 1. course domain
9816: 2. course number
9817: 3. access status: users must have - either active,
1.275 raeburn 9818: previous, future, or all.
1.277 albertel 9819: 4. reference to array of permissible roles
1.288 raeburn 9820: 5. reference to array of section restrictions (optional)
9821: 6. reference to results object (hash of hashes).
9822: 7. reference to optional userdata hash
1.609 raeburn 9823: 8. reference to optional statushash
1.630 raeburn 9824: 9. flag if privileged users (except those set to unhide in
9825: course settings) should be excluded
1.609 raeburn 9826: Keys of top level results hash are roles.
1.275 raeburn 9827: Keys of inner hashes are username:domain, with
9828: values set to access type.
1.288 raeburn 9829: Optional userdata hash returns an array with arguments in the
9830: same order as loncoursedata::get_classlist() for student data.
9831:
1.609 raeburn 9832: Optional statushash returns
9833:
1.288 raeburn 9834: Entries for end, start, section and status are blank because
9835: of the possibility of multiple values for non-student roles.
9836:
1.275 raeburn 9837: =cut
1.405 albertel 9838:
1.275 raeburn 9839: ###############################################
1.405 albertel 9840:
1.275 raeburn 9841: sub get_course_users {
1.630 raeburn 9842: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9843: my %idx = ();
1.419 raeburn 9844: my %seclists;
1.288 raeburn 9845:
9846: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9847: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9848: $idx{end} = &Apache::loncoursedata::CL_END();
9849: $idx{start} = &Apache::loncoursedata::CL_START();
9850: $idx{id} = &Apache::loncoursedata::CL_ID();
9851: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9852: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9853: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9854:
1.290 albertel 9855: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9856: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9857: my $now = time;
1.277 albertel 9858: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9859: my $match = 0;
1.412 raeburn 9860: my $secmatch = 0;
1.419 raeburn 9861: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9862: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9863: if ($section eq '') {
9864: $section = 'none';
9865: }
1.291 albertel 9866: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9867: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9868: $secmatch = 1;
9869: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9870: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9871: $secmatch = 1;
9872: }
9873: } else {
1.419 raeburn 9874: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9875: $secmatch = 1;
9876: }
1.290 albertel 9877: }
1.412 raeburn 9878: if (!$secmatch) {
9879: next;
9880: }
1.419 raeburn 9881: }
1.275 raeburn 9882: if (defined($$types{'active'})) {
1.288 raeburn 9883: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9884: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9885: $match = 1;
1.275 raeburn 9886: }
9887: }
9888: if (defined($$types{'previous'})) {
1.609 raeburn 9889: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9890: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9891: $match = 1;
1.275 raeburn 9892: }
9893: }
9894: if (defined($$types{'future'})) {
1.609 raeburn 9895: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9896: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9897: $match = 1;
1.275 raeburn 9898: }
9899: }
1.609 raeburn 9900: if ($match) {
9901: push(@{$seclists{$student}},$section);
9902: if (ref($userdata) eq 'HASH') {
9903: $$userdata{$student} = $$classlist{$student};
9904: }
9905: if (ref($statushash) eq 'HASH') {
9906: $statushash->{$student}{'st'}{$section} = $status;
9907: }
1.288 raeburn 9908: }
1.275 raeburn 9909: }
9910: }
1.412 raeburn 9911: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9912: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9913: my $now = time;
1.609 raeburn 9914: my %displaystatus = ( previous => 'Expired',
9915: active => 'Active',
9916: future => 'Future',
9917: );
1.1121 raeburn 9918: my (%nothide,@possdoms);
1.630 raeburn 9919: if ($hidepriv) {
9920: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9921: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9922: if ($user !~ /:/) {
9923: $nothide{join(':',split(/[\@]/,$user))}=1;
9924: } else {
9925: $nothide{$user} = 1;
9926: }
9927: }
1.1121 raeburn 9928: my @possdoms = ($cdom);
9929: if ($coursehash{'checkforpriv'}) {
9930: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9931: }
1.630 raeburn 9932: }
1.439 raeburn 9933: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9934: my $match = 0;
1.412 raeburn 9935: my $secmatch = 0;
1.439 raeburn 9936: my $status;
1.412 raeburn 9937: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9938: $user =~ s/:$//;
1.439 raeburn 9939: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9940: if ($end == -1 || $start == -1) {
9941: next;
9942: }
9943: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9944: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9945: my ($uname,$udom) = split(/:/,$user);
9946: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9947: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9948: $secmatch = 1;
9949: } elsif ($usec eq '') {
1.420 albertel 9950: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9951: $secmatch = 1;
9952: }
9953: } else {
9954: if (grep(/^\Q$usec\E$/,@{$sections})) {
9955: $secmatch = 1;
9956: }
9957: }
9958: if (!$secmatch) {
9959: next;
9960: }
1.288 raeburn 9961: }
1.419 raeburn 9962: if ($usec eq '') {
9963: $usec = 'none';
9964: }
1.275 raeburn 9965: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9966: if ($hidepriv) {
1.1121 raeburn 9967: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9968: (!$nothide{$uname.':'.$udom})) {
9969: next;
9970: }
9971: }
1.503 raeburn 9972: if ($end > 0 && $end < $now) {
1.439 raeburn 9973: $status = 'previous';
9974: } elsif ($start > $now) {
9975: $status = 'future';
9976: } else {
9977: $status = 'active';
9978: }
1.277 albertel 9979: foreach my $type (keys(%{$types})) {
1.275 raeburn 9980: if ($status eq $type) {
1.420 albertel 9981: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9982: push(@{$$users{$role}{$user}},$type);
9983: }
1.288 raeburn 9984: $match = 1;
9985: }
9986: }
1.419 raeburn 9987: if (($match) && (ref($userdata) eq 'HASH')) {
9988: if (!exists($$userdata{$uname.':'.$udom})) {
9989: &get_user_info($udom,$uname,\%idx,$userdata);
9990: }
1.420 albertel 9991: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9992: push(@{$seclists{$uname.':'.$udom}},$usec);
9993: }
1.609 raeburn 9994: if (ref($statushash) eq 'HASH') {
9995: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9996: }
1.275 raeburn 9997: }
9998: }
9999: }
10000: }
1.290 albertel 10001: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10002: if ((defined($cdom)) && (defined($cnum))) {
10003: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10004: if ( defined($csettings{'internal.courseowner'}) ) {
10005: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10006: next if ($owner eq '');
10007: my ($ownername,$ownerdom);
10008: if ($owner =~ /^([^:]+):([^:]+)$/) {
10009: $ownername = $1;
10010: $ownerdom = $2;
10011: } else {
10012: $ownername = $owner;
10013: $ownerdom = $cdom;
10014: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10015: }
10016: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10017: if (defined($userdata) &&
1.609 raeburn 10018: !exists($$userdata{$owner})) {
10019: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10020: if (!grep(/^none$/,@{$seclists{$owner}})) {
10021: push(@{$seclists{$owner}},'none');
10022: }
10023: if (ref($statushash) eq 'HASH') {
10024: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10025: }
1.290 albertel 10026: }
1.279 raeburn 10027: }
10028: }
10029: }
1.419 raeburn 10030: foreach my $user (keys(%seclists)) {
10031: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10032: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10033: }
1.275 raeburn 10034: }
10035: return;
10036: }
10037:
1.288 raeburn 10038: sub get_user_info {
10039: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10040: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10041: &plainname($uname,$udom,'lastname');
1.291 albertel 10042: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10043: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10044: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10045: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10046: return;
10047: }
1.275 raeburn 10048:
1.472 raeburn 10049: ###############################################
10050:
10051: =pod
10052:
10053: =item * &get_user_quota()
10054:
1.1134 raeburn 10055: Retrieves quota assigned for storage of user files.
10056: Default is to report quota for portfolio files.
1.472 raeburn 10057:
10058: Incoming parameters:
10059: 1. user's username
10060: 2. user's domain
1.1134 raeburn 10061: 3. quota name - portfolio, author, or course
1.1136 raeburn 10062: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 10063: 4. crstype - official, unofficial, textbook, placement or community,
10064: if quota name is course
1.472 raeburn 10065:
10066: Returns:
1.1163 raeburn 10067: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10068: 2. (Optional) Type of setting: custom or default
10069: (individually assigned or default for user's
10070: institutional status).
10071: 3. (Optional) - User's institutional status (e.g., faculty, staff
10072: or student - types as defined in localenroll::inst_usertypes
10073: for user's domain, which determines default quota for user.
10074: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10075:
10076: If a value has been stored in the user's environment,
1.536 raeburn 10077: it will return that, otherwise it returns the maximal default
1.1134 raeburn 10078: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10079:
10080: =cut
10081:
10082: ###############################################
10083:
10084:
10085: sub get_user_quota {
1.1136 raeburn 10086: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10087: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10088: if (!defined($udom)) {
10089: $udom = $env{'user.domain'};
10090: }
10091: if (!defined($uname)) {
10092: $uname = $env{'user.name'};
10093: }
10094: if (($udom eq '' || $uname eq '') ||
10095: ($udom eq 'public') && ($uname eq 'public')) {
10096: $quota = 0;
1.536 raeburn 10097: $quotatype = 'default';
10098: $defquota = 0;
1.472 raeburn 10099: } else {
1.536 raeburn 10100: my $inststatus;
1.1134 raeburn 10101: if ($quotaname eq 'course') {
10102: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10103: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10104: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10105: } else {
10106: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10107: $quota = $cenv{'internal.uploadquota'};
10108: }
1.536 raeburn 10109: } else {
1.1134 raeburn 10110: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10111: if ($quotaname eq 'author') {
10112: $quota = $env{'environment.authorquota'};
10113: } else {
10114: $quota = $env{'environment.portfolioquota'};
10115: }
10116: $inststatus = $env{'environment.inststatus'};
10117: } else {
10118: my %userenv =
10119: &Apache::lonnet::get('environment',['portfolioquota',
10120: 'authorquota','inststatus'],$udom,$uname);
10121: my ($tmp) = keys(%userenv);
10122: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10123: if ($quotaname eq 'author') {
10124: $quota = $userenv{'authorquota'};
10125: } else {
10126: $quota = $userenv{'portfolioquota'};
10127: }
10128: $inststatus = $userenv{'inststatus'};
10129: } else {
10130: undef(%userenv);
10131: }
10132: }
10133: }
10134: if ($quota eq '' || wantarray) {
10135: if ($quotaname eq 'course') {
10136: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 10137: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 10138: ($crstype eq 'community') || ($crstype eq 'textbook') ||
10139: ($crstype eq 'placement')) {
1.1136 raeburn 10140: $defquota = $domdefs{$crstype.'quota'};
10141: }
10142: if ($defquota eq '') {
10143: $defquota = 500;
10144: }
1.1134 raeburn 10145: } else {
10146: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10147: }
10148: if ($quota eq '') {
10149: $quota = $defquota;
10150: $quotatype = 'default';
10151: } else {
10152: $quotatype = 'custom';
10153: }
1.472 raeburn 10154: }
10155: }
1.536 raeburn 10156: if (wantarray) {
10157: return ($quota,$quotatype,$settingstatus,$defquota);
10158: } else {
10159: return $quota;
10160: }
1.472 raeburn 10161: }
10162:
10163: ###############################################
10164:
10165: =pod
10166:
10167: =item * &default_quota()
10168:
1.536 raeburn 10169: Retrieves default quota assigned for storage of user portfolio files,
10170: given an (optional) user's institutional status.
1.472 raeburn 10171:
10172: Incoming parameters:
1.1142 raeburn 10173:
1.472 raeburn 10174: 1. domain
1.536 raeburn 10175: 2. (Optional) institutional status(es). This is a : separated list of
10176: status types (e.g., faculty, staff, student etc.)
10177: which apply to the user for whom the default is being retrieved.
10178: If the institutional status string in undefined, the domain
1.1134 raeburn 10179: default quota will be returned.
10180: 3. quota name - portfolio, author, or course
10181: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10182:
10183: Returns:
1.1142 raeburn 10184:
1.1163 raeburn 10185: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10186: 2. (Optional) institutional type which determined the value of the
10187: default quota.
1.472 raeburn 10188:
10189: If a value has been stored in the domain's configuration db,
10190: it will return that, otherwise it returns 20 (for backwards
10191: compatibility with domains which have not set up a configuration
1.1163 raeburn 10192: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10193:
1.536 raeburn 10194: If the user's status includes multiple types (e.g., staff and student),
10195: the largest default quota which applies to the user determines the
10196: default quota returned.
10197:
1.472 raeburn 10198: =cut
10199:
10200: ###############################################
10201:
10202:
10203: sub default_quota {
1.1134 raeburn 10204: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10205: my ($defquota,$settingstatus);
10206: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10207: ['quotas'],$udom);
1.1134 raeburn 10208: my $key = 'defaultquota';
10209: if ($quotaname eq 'author') {
10210: $key = 'authorquota';
10211: }
1.622 raeburn 10212: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10213: if ($inststatus ne '') {
1.765 raeburn 10214: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10215: foreach my $item (@statuses) {
1.1134 raeburn 10216: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10217: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10218: if ($defquota eq '') {
1.1134 raeburn 10219: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10220: $settingstatus = $item;
1.1134 raeburn 10221: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10222: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10223: $settingstatus = $item;
10224: }
10225: }
1.1134 raeburn 10226: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10227: if ($quotahash{'quotas'}{$item} ne '') {
10228: if ($defquota eq '') {
10229: $defquota = $quotahash{'quotas'}{$item};
10230: $settingstatus = $item;
10231: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10232: $defquota = $quotahash{'quotas'}{$item};
10233: $settingstatus = $item;
10234: }
1.536 raeburn 10235: }
10236: }
10237: }
10238: }
10239: if ($defquota eq '') {
1.1134 raeburn 10240: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10241: $defquota = $quotahash{'quotas'}{$key}{'default'};
10242: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10243: $defquota = $quotahash{'quotas'}{'default'};
10244: }
1.536 raeburn 10245: $settingstatus = 'default';
1.1139 raeburn 10246: if ($defquota eq '') {
10247: if ($quotaname eq 'author') {
10248: $defquota = 500;
10249: }
10250: }
1.536 raeburn 10251: }
10252: } else {
10253: $settingstatus = 'default';
1.1134 raeburn 10254: if ($quotaname eq 'author') {
10255: $defquota = 500;
10256: } else {
10257: $defquota = 20;
10258: }
1.536 raeburn 10259: }
10260: if (wantarray) {
10261: return ($defquota,$settingstatus);
1.472 raeburn 10262: } else {
1.536 raeburn 10263: return $defquota;
1.472 raeburn 10264: }
10265: }
10266:
1.1135 raeburn 10267: ###############################################
10268:
10269: =pod
10270:
1.1136 raeburn 10271: =item * &excess_filesize_warning()
1.1135 raeburn 10272:
10273: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 10274: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 10275: space to be exceeded.
1.1136 raeburn 10276:
10277: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 10278: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 10279:
1.1165 raeburn 10280: Inputs: 7
1.1136 raeburn 10281: 1. username or coursenum
1.1135 raeburn 10282: 2. domain
1.1136 raeburn 10283: 3. context ('author' or 'course')
1.1135 raeburn 10284: 4. filename of file for which action is being requested
10285: 5. filesize (kB) of file
10286: 6. action being taken: copy or upload.
1.1237 raeburn 10287: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 10288:
10289: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 10290: otherwise return null.
10291:
10292: =back
1.1135 raeburn 10293:
10294: =cut
10295:
1.1136 raeburn 10296: sub excess_filesize_warning {
1.1165 raeburn 10297: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 10298: my $current_disk_usage = 0;
1.1165 raeburn 10299: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 10300: if ($context eq 'author') {
10301: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10302: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10303: } else {
10304: foreach my $subdir ('docs','supplemental') {
10305: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10306: }
10307: }
1.1135 raeburn 10308: $disk_quota = int($disk_quota * 1000);
10309: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 10310: return '<p class="LC_warning">'.
1.1135 raeburn 10311: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 10312: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10313: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 10314: $disk_quota,$current_disk_usage).
10315: '</p>';
10316: }
10317: return;
10318: }
10319:
10320: ###############################################
10321:
10322:
1.1136 raeburn 10323:
10324:
1.384 raeburn 10325: sub get_secgrprole_info {
10326: my ($cdom,$cnum,$needroles,$type) = @_;
10327: my %sections_count = &get_sections($cdom,$cnum);
10328: my @sections = (sort {$a <=> $b} keys(%sections_count));
10329: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10330: my @groups = sort(keys(%curr_groups));
10331: my $allroles = [];
10332: my $rolehash;
10333: my $accesshash = {
10334: active => 'Currently has access',
10335: future => 'Will have future access',
10336: previous => 'Previously had access',
10337: };
10338: if ($needroles) {
10339: $rolehash = {'all' => 'all'};
1.385 albertel 10340: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10341: if (&Apache::lonnet::error(%user_roles)) {
10342: undef(%user_roles);
10343: }
10344: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10345: my ($role)=split(/\:/,$item,2);
10346: if ($role eq 'cr') { next; }
10347: if ($role =~ /^cr/) {
10348: $$rolehash{$role} = (split('/',$role))[3];
10349: } else {
10350: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10351: }
10352: }
10353: foreach my $key (sort(keys(%{$rolehash}))) {
10354: push(@{$allroles},$key);
10355: }
10356: push (@{$allroles},'st');
10357: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10358: }
10359: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10360: }
10361:
1.555 raeburn 10362: sub user_picker {
1.1279 raeburn 10363: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10364: my $currdom = $dom;
1.1253 raeburn 10365: my @alldoms = &Apache::lonnet::all_domains();
10366: if (@alldoms == 1) {
10367: my %domsrch = &Apache::lonnet::get_dom('configuration',
10368: ['directorysrch'],$alldoms[0]);
10369: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10370: my $showdom = $domdesc;
10371: if ($showdom eq '') {
10372: $showdom = $dom;
10373: }
10374: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10375: if ((!$domsrch{'directorysrch'}{'available'}) &&
10376: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10377: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10378: }
10379: }
10380: }
1.555 raeburn 10381: my %curr_selected = (
10382: srchin => 'dom',
1.580 raeburn 10383: srchby => 'lastname',
1.555 raeburn 10384: );
10385: my $srchterm;
1.625 raeburn 10386: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10387: if ($srch->{'srchby'} ne '') {
10388: $curr_selected{'srchby'} = $srch->{'srchby'};
10389: }
10390: if ($srch->{'srchin'} ne '') {
10391: $curr_selected{'srchin'} = $srch->{'srchin'};
10392: }
10393: if ($srch->{'srchtype'} ne '') {
10394: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10395: }
10396: if ($srch->{'srchdomain'} ne '') {
10397: $currdom = $srch->{'srchdomain'};
10398: }
10399: $srchterm = $srch->{'srchterm'};
10400: }
1.1222 damieng 10401: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10402: 'usr' => 'Search criteria',
1.563 raeburn 10403: 'doma' => 'Domain/institution to search',
1.558 albertel 10404: 'uname' => 'username',
10405: 'lastname' => 'last name',
1.555 raeburn 10406: 'lastfirst' => 'last name, first name',
1.558 albertel 10407: 'crs' => 'in this course',
1.576 raeburn 10408: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10409: 'alc' => 'all LON-CAPA',
1.573 raeburn 10410: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10411: 'exact' => 'is',
10412: 'contains' => 'contains',
1.569 raeburn 10413: 'begins' => 'begins with',
1.1222 damieng 10414: );
10415: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10416: 'youm' => "You must include some text to search for.",
10417: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10418: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10419: 'yomc' => "You must choose a domain when using an institutional directory search.",
10420: 'ymcd' => "You must choose a domain when using a domain search.",
10421: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10422: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10423: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10424: );
1.1222 damieng 10425: &html_escape(\%html_lt);
10426: &js_escape(\%js_lt);
1.1255 raeburn 10427: my $domform;
1.1277 raeburn 10428: my $allow_blank = 1;
1.1255 raeburn 10429: if ($fixeddom) {
1.1277 raeburn 10430: $allow_blank = 0;
10431: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 10432: } else {
1.1287 raeburn 10433: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 10434: my ($trusted,$untrusted);
1.1287 raeburn 10435: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 10436: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 10437: } elsif ($context eq 'author') {
1.1288 raeburn 10438: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 10439: } elsif ($context eq 'domain') {
1.1288 raeburn 10440: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 10441: }
1.1288 raeburn 10442: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 10443: }
1.563 raeburn 10444: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10445:
10446: my @srchins = ('crs','dom','alc','instd');
10447:
10448: foreach my $option (@srchins) {
10449: # FIXME 'alc' option unavailable until
10450: # loncreateuser::print_user_query_page()
10451: # has been completed.
10452: next if ($option eq 'alc');
1.880 raeburn 10453: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10454: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 10455: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10456: if ($curr_selected{'srchin'} eq $option) {
10457: $srchinsel .= '
1.1222 damieng 10458: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10459: } else {
10460: $srchinsel .= '
1.1222 damieng 10461: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10462: }
1.555 raeburn 10463: }
1.563 raeburn 10464: $srchinsel .= "\n </select>\n";
1.555 raeburn 10465:
10466: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10467: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10468: if ($curr_selected{'srchby'} eq $option) {
10469: $srchbysel .= '
1.1222 damieng 10470: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10471: } else {
10472: $srchbysel .= '
1.1222 damieng 10473: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10474: }
10475: }
10476: $srchbysel .= "\n </select>\n";
10477:
10478: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10479: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10480: if ($curr_selected{'srchtype'} eq $option) {
10481: $srchtypesel .= '
1.1222 damieng 10482: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10483: } else {
10484: $srchtypesel .= '
1.1222 damieng 10485: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10486: }
10487: }
10488: $srchtypesel .= "\n </select>\n";
10489:
1.558 albertel 10490: my ($newuserscript,$new_user_create);
1.994 raeburn 10491: my $context_dom = $env{'request.role.domain'};
10492: if ($context eq 'requestcrs') {
10493: if ($env{'form.coursedom'} ne '') {
10494: $context_dom = $env{'form.coursedom'};
10495: }
10496: }
1.556 raeburn 10497: if ($forcenewuser) {
1.576 raeburn 10498: if (ref($srch) eq 'HASH') {
1.994 raeburn 10499: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10500: if ($cancreate) {
10501: $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>';
10502: } else {
1.799 bisitz 10503: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10504: my %usertypetext = (
10505: official => 'institutional',
10506: unofficial => 'non-institutional',
10507: );
1.799 bisitz 10508: $new_user_create = '<p class="LC_warning">'
10509: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10510: .' '
10511: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10512: ,'<a href="'.$helplink.'">','</a>')
10513: .'</p><br />';
1.627 raeburn 10514: }
1.576 raeburn 10515: }
10516: }
10517:
1.556 raeburn 10518: $newuserscript = <<"ENDSCRIPT";
10519:
1.570 raeburn 10520: function setSearch(createnew,callingForm) {
1.556 raeburn 10521: if (createnew == 1) {
1.570 raeburn 10522: for (var i=0; i<callingForm.srchby.length; i++) {
10523: if (callingForm.srchby.options[i].value == 'uname') {
10524: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10525: }
10526: }
1.570 raeburn 10527: for (var i=0; i<callingForm.srchin.length; i++) {
10528: if ( callingForm.srchin.options[i].value == 'dom') {
10529: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10530: }
10531: }
1.570 raeburn 10532: for (var i=0; i<callingForm.srchtype.length; i++) {
10533: if (callingForm.srchtype.options[i].value == 'exact') {
10534: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10535: }
10536: }
1.570 raeburn 10537: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10538: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10539: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10540: }
10541: }
10542: }
10543: }
10544: ENDSCRIPT
1.558 albertel 10545:
1.556 raeburn 10546: }
10547:
1.555 raeburn 10548: my $output = <<"END_BLOCK";
1.556 raeburn 10549: <script type="text/javascript">
1.824 bisitz 10550: // <![CDATA[
1.570 raeburn 10551: function validateEntry(callingForm) {
1.558 albertel 10552:
1.556 raeburn 10553: var checkok = 1;
1.558 albertel 10554: var srchin;
1.570 raeburn 10555: for (var i=0; i<callingForm.srchin.length; i++) {
10556: if ( callingForm.srchin[i].checked ) {
10557: srchin = callingForm.srchin[i].value;
1.558 albertel 10558: }
10559: }
10560:
1.570 raeburn 10561: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10562: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10563: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10564: var srchterm = callingForm.srchterm.value;
10565: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10566: var msg = "";
10567:
10568: if (srchterm == "") {
10569: checkok = 0;
1.1222 damieng 10570: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10571: }
10572:
1.569 raeburn 10573: if (srchtype== 'begins') {
10574: if (srchterm.length < 2) {
10575: checkok = 0;
1.1222 damieng 10576: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10577: }
10578: }
10579:
1.556 raeburn 10580: if (srchtype== 'contains') {
10581: if (srchterm.length < 3) {
10582: checkok = 0;
1.1222 damieng 10583: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10584: }
10585: }
10586: if (srchin == 'instd') {
10587: if (srchdomain == '') {
10588: checkok = 0;
1.1222 damieng 10589: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10590: }
10591: }
10592: if (srchin == 'dom') {
10593: if (srchdomain == '') {
10594: checkok = 0;
1.1222 damieng 10595: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10596: }
10597: }
10598: if (srchby == 'lastfirst') {
10599: if (srchterm.indexOf(",") == -1) {
10600: checkok = 0;
1.1222 damieng 10601: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10602: }
10603: if (srchterm.indexOf(",") == srchterm.length -1) {
10604: checkok = 0;
1.1222 damieng 10605: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10606: }
10607: }
10608: if (checkok == 0) {
1.1222 damieng 10609: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10610: return;
10611: }
10612: if (checkok == 1) {
1.570 raeburn 10613: callingForm.submit();
1.556 raeburn 10614: }
10615: }
10616:
10617: $newuserscript
10618:
1.824 bisitz 10619: // ]]>
1.556 raeburn 10620: </script>
1.558 albertel 10621:
10622: $new_user_create
10623:
1.555 raeburn 10624: END_BLOCK
1.558 albertel 10625:
1.876 raeburn 10626: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10627: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10628: $domform.
10629: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10630: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10631: $srchbysel.
10632: $srchtypesel.
10633: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10634: $srchinsel.
10635: &Apache::lonhtmlcommon::row_closure(1).
10636: &Apache::lonhtmlcommon::end_pick_box().
10637: '<br />';
1.1253 raeburn 10638: return ($output,1);
1.555 raeburn 10639: }
10640:
1.612 raeburn 10641: sub user_rule_check {
1.615 raeburn 10642: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10643: my ($response,%inst_response);
1.612 raeburn 10644: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10645: if (keys(%{$usershash}) > 1) {
10646: my (%by_username,%by_id,%userdoms);
10647: my $checkid;
10648: if (ref($checks) eq 'HASH') {
10649: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10650: $checkid = 1;
10651: }
10652: }
10653: foreach my $user (keys(%{$usershash})) {
10654: my ($uname,$udom) = split(/:/,$user);
10655: if ($checkid) {
10656: if (ref($usershash->{$user}) eq 'HASH') {
10657: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10658: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10659: $userdoms{$udom} = 1;
1.1227 raeburn 10660: if (ref($inst_results) eq 'HASH') {
10661: $inst_results->{$uname.':'.$udom} = {};
10662: }
1.1226 raeburn 10663: }
10664: }
10665: } else {
10666: $by_username{$udom}{$uname} = 1;
10667: $userdoms{$udom} = 1;
1.1227 raeburn 10668: if (ref($inst_results) eq 'HASH') {
10669: $inst_results->{$uname.':'.$udom} = {};
10670: }
1.1226 raeburn 10671: }
10672: }
10673: foreach my $udom (keys(%userdoms)) {
10674: if (!$got_rules->{$udom}) {
10675: my %domconfig = &Apache::lonnet::get_dom('configuration',
10676: ['usercreation'],$udom);
10677: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10678: foreach my $item ('username','id') {
10679: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10680: $$curr_rules{$udom}{$item} =
10681: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10682: }
10683: }
10684: }
10685: $got_rules->{$udom} = 1;
10686: }
1.612 raeburn 10687: }
1.1226 raeburn 10688: if ($checkid) {
10689: foreach my $udom (keys(%by_id)) {
10690: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10691: if ($outcome eq 'ok') {
1.1227 raeburn 10692: foreach my $id (keys(%{$by_id{$udom}})) {
10693: my $uname = $by_id{$udom}{$id};
10694: $inst_response{$uname.':'.$udom} = $outcome;
10695: }
1.1226 raeburn 10696: if (ref($results) eq 'HASH') {
10697: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10698: if (exists($inst_response{$uname.':'.$udom})) {
10699: $inst_response{$uname.':'.$udom} = $outcome;
10700: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10701: }
1.1226 raeburn 10702: }
10703: }
10704: }
1.612 raeburn 10705: }
1.615 raeburn 10706: } else {
1.1226 raeburn 10707: foreach my $udom (keys(%by_username)) {
10708: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10709: if ($outcome eq 'ok') {
1.1227 raeburn 10710: foreach my $uname (keys(%{$by_username{$udom}})) {
10711: $inst_response{$uname.':'.$udom} = $outcome;
10712: }
1.1226 raeburn 10713: if (ref($results) eq 'HASH') {
10714: foreach my $uname (keys(%{$results})) {
10715: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10716: }
10717: }
10718: }
10719: }
1.612 raeburn 10720: }
1.1226 raeburn 10721: } elsif (keys(%{$usershash}) == 1) {
10722: my $user = (keys(%{$usershash}))[0];
10723: my ($uname,$udom) = split(/:/,$user);
10724: if (($udom ne '') && ($uname ne '')) {
10725: if (ref($usershash->{$user}) eq 'HASH') {
10726: if (ref($checks) eq 'HASH') {
10727: if (defined($checks->{'username'})) {
10728: ($inst_response{$user},%{$inst_results->{$user}}) =
10729: &Apache::lonnet::get_instuser($udom,$uname);
10730: } elsif (defined($checks->{'id'})) {
10731: if ($usershash->{$user}->{'id'} ne '') {
10732: ($inst_response{$user},%{$inst_results->{$user}}) =
10733: &Apache::lonnet::get_instuser($udom,undef,
10734: $usershash->{$user}->{'id'});
10735: } else {
10736: ($inst_response{$user},%{$inst_results->{$user}}) =
10737: &Apache::lonnet::get_instuser($udom,$uname);
10738: }
1.585 raeburn 10739: }
1.1226 raeburn 10740: } else {
10741: ($inst_response{$user},%{$inst_results->{$user}}) =
10742: &Apache::lonnet::get_instuser($udom,$uname);
10743: return;
10744: }
10745: if (!$got_rules->{$udom}) {
10746: my %domconfig = &Apache::lonnet::get_dom('configuration',
10747: ['usercreation'],$udom);
10748: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10749: foreach my $item ('username','id') {
10750: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10751: $$curr_rules{$udom}{$item} =
10752: $domconfig{'usercreation'}{$item.'_rule'};
10753: }
10754: }
10755: }
10756: $got_rules->{$udom} = 1;
1.585 raeburn 10757: }
10758: }
1.1226 raeburn 10759: } else {
10760: return;
10761: }
10762: } else {
10763: return;
10764: }
10765: foreach my $user (keys(%{$usershash})) {
10766: my ($uname,$udom) = split(/:/,$user);
10767: next if (($udom eq '') || ($uname eq ''));
10768: my $id;
1.1227 raeburn 10769: if (ref($inst_results) eq 'HASH') {
10770: if (ref($inst_results->{$user}) eq 'HASH') {
10771: $id = $inst_results->{$user}->{'id'};
10772: }
10773: }
10774: if ($id eq '') {
10775: if (ref($usershash->{$user})) {
10776: $id = $usershash->{$user}->{'id'};
10777: }
1.585 raeburn 10778: }
1.612 raeburn 10779: foreach my $item (keys(%{$checks})) {
10780: if (ref($$curr_rules{$udom}) eq 'HASH') {
10781: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10782: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10783: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10784: $$curr_rules{$udom}{$item});
1.612 raeburn 10785: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10786: if ($rule_check{$rule}) {
10787: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10788: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10789: if (ref($inst_results) eq 'HASH') {
10790: if (ref($inst_results->{$user}) eq 'HASH') {
10791: if (keys(%{$inst_results->{$user}}) == 0) {
10792: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10793: } elsif ($item eq 'id') {
10794: if ($inst_results->{$user}->{'id'} eq '') {
10795: $$alerts{$item}{$udom}{$uname} = 1;
10796: }
1.615 raeburn 10797: }
1.612 raeburn 10798: }
10799: }
1.615 raeburn 10800: }
10801: last;
1.585 raeburn 10802: }
10803: }
10804: }
10805: }
10806: }
10807: }
10808: }
10809: }
1.612 raeburn 10810: return;
10811: }
10812:
10813: sub user_rule_formats {
10814: my ($domain,$domdesc,$curr_rules,$check) = @_;
10815: my %text = (
10816: 'username' => 'Usernames',
10817: 'id' => 'IDs',
10818: );
10819: my $output;
10820: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10821: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10822: if (@{$ruleorder} > 0) {
1.1102 raeburn 10823: $output = '<br />'.
10824: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10825: '<span class="LC_cusr_emph">','</span>',$domdesc).
10826: ' <ul>';
1.612 raeburn 10827: foreach my $rule (@{$ruleorder}) {
10828: if (ref($curr_rules) eq 'ARRAY') {
10829: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10830: if (ref($rules->{$rule}) eq 'HASH') {
10831: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10832: $rules->{$rule}{'desc'}.'</li>';
10833: }
10834: }
10835: }
10836: }
10837: $output .= '</ul>';
10838: }
10839: }
10840: return $output;
10841: }
10842:
10843: sub instrule_disallow_msg {
1.615 raeburn 10844: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10845: my $response;
10846: my %text = (
10847: item => 'username',
10848: items => 'usernames',
10849: match => 'matches',
10850: do => 'does',
10851: action => 'a username',
10852: one => 'one',
10853: );
10854: if ($count > 1) {
10855: $text{'item'} = 'usernames';
10856: $text{'match'} ='match';
10857: $text{'do'} = 'do';
10858: $text{'action'} = 'usernames',
10859: $text{'one'} = 'ones';
10860: }
10861: if ($checkitem eq 'id') {
10862: $text{'items'} = 'IDs';
10863: $text{'item'} = 'ID';
10864: $text{'action'} = 'an ID';
1.615 raeburn 10865: if ($count > 1) {
10866: $text{'item'} = 'IDs';
10867: $text{'action'} = 'IDs';
10868: }
1.612 raeburn 10869: }
1.674 bisitz 10870: $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 10871: if ($mode eq 'upload') {
10872: if ($checkitem eq 'username') {
10873: $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'}.");
10874: } elsif ($checkitem eq 'id') {
1.674 bisitz 10875: $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 10876: }
1.669 raeburn 10877: } elsif ($mode eq 'selfcreate') {
10878: if ($checkitem eq 'id') {
10879: $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.");
10880: }
1.615 raeburn 10881: } else {
10882: if ($checkitem eq 'username') {
10883: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10884: } elsif ($checkitem eq 'id') {
10885: $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.");
10886: }
1.612 raeburn 10887: }
10888: return $response;
1.585 raeburn 10889: }
10890:
1.624 raeburn 10891: sub personal_data_fieldtitles {
10892: my %fieldtitles = &Apache::lonlocal::texthash (
10893: id => 'Student/Employee ID',
10894: permanentemail => 'E-mail address',
10895: lastname => 'Last Name',
10896: firstname => 'First Name',
10897: middlename => 'Middle Name',
10898: generation => 'Generation',
10899: gen => 'Generation',
1.765 raeburn 10900: inststatus => 'Affiliation',
1.624 raeburn 10901: );
10902: return %fieldtitles;
10903: }
10904:
1.642 raeburn 10905: sub sorted_inst_types {
10906: my ($dom) = @_;
1.1185 raeburn 10907: my ($usertypes,$order);
10908: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10909: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10910: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10911: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10912: } else {
10913: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10914: }
1.642 raeburn 10915: my $othertitle = &mt('All users');
10916: if ($env{'request.course.id'}) {
1.668 raeburn 10917: $othertitle = &mt('Any users');
1.642 raeburn 10918: }
10919: my @types;
10920: if (ref($order) eq 'ARRAY') {
10921: @types = @{$order};
10922: }
10923: if (@types == 0) {
10924: if (ref($usertypes) eq 'HASH') {
10925: @types = sort(keys(%{$usertypes}));
10926: }
10927: }
10928: if (keys(%{$usertypes}) > 0) {
10929: $othertitle = &mt('Other users');
10930: }
10931: return ($othertitle,$usertypes,\@types);
10932: }
10933:
1.645 raeburn 10934: sub get_institutional_codes {
10935: my ($settings,$allcourses,$LC_code) = @_;
10936: # Get complete list of course sections to update
10937: my @currsections = ();
10938: my @currxlists = ();
10939: my $coursecode = $$settings{'internal.coursecode'};
10940:
10941: if ($$settings{'internal.sectionnums'} ne '') {
10942: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10943: }
10944:
10945: if ($$settings{'internal.crosslistings'} ne '') {
10946: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10947: }
10948:
10949: if (@currxlists > 0) {
10950: foreach (@currxlists) {
10951: if (m/^([^:]+):(\w*)$/) {
10952: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 10953: push(@{$allcourses},$1);
1.645 raeburn 10954: $$LC_code{$1} = $2;
10955: }
10956: }
10957: }
10958: }
10959:
10960: if (@currsections > 0) {
10961: foreach (@currsections) {
10962: if (m/^(\w+):(\w*)$/) {
10963: my $sec = $coursecode.$1;
10964: my $lc_sec = $2;
10965: unless (grep/^$sec$/,@{$allcourses}) {
1.1263 raeburn 10966: push(@{$allcourses},$sec);
1.645 raeburn 10967: $$LC_code{$sec} = $lc_sec;
10968: }
10969: }
10970: }
10971: }
10972: return;
10973: }
10974:
1.971 raeburn 10975: sub get_standard_codeitems {
10976: return ('Year','Semester','Department','Number','Section');
10977: }
10978:
1.112 bowersj2 10979: =pod
10980:
1.780 raeburn 10981: =head1 Slot Helpers
10982:
10983: =over 4
10984:
10985: =item * sorted_slots()
10986:
1.1040 raeburn 10987: Sorts an array of slot names in order of an optional sort key,
10988: default sort is by slot start time (earliest first).
1.780 raeburn 10989:
10990: Inputs:
10991:
10992: =over 4
10993:
10994: slotsarr - Reference to array of unsorted slot names.
10995:
10996: slots - Reference to hash of hash, where outer hash keys are slot names.
10997:
1.1040 raeburn 10998: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10999:
1.549 albertel 11000: =back
11001:
1.780 raeburn 11002: Returns:
11003:
11004: =over 4
11005:
1.1040 raeburn 11006: sorted - An array of slot names sorted by a specified sort key
11007: (default sort key is start time of the slot).
1.780 raeburn 11008:
11009: =back
11010:
11011: =cut
11012:
11013:
11014: sub sorted_slots {
1.1040 raeburn 11015: my ($slotsarr,$slots,$sortkey) = @_;
11016: if ($sortkey eq '') {
11017: $sortkey = 'starttime';
11018: }
1.780 raeburn 11019: my @sorted;
11020: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11021: @sorted =
11022: sort {
11023: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11024: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11025: }
11026: if (ref($slots->{$a})) { return -1;}
11027: if (ref($slots->{$b})) { return 1;}
11028: return 0;
11029: } @{$slotsarr};
11030: }
11031: return @sorted;
11032: }
11033:
1.1040 raeburn 11034: =pod
11035:
11036: =item * get_future_slots()
11037:
11038: Inputs:
11039:
11040: =over 4
11041:
11042: cnum - course number
11043:
11044: cdom - course domain
11045:
11046: now - current UNIX time
11047:
11048: symb - optional symb
11049:
11050: =back
11051:
11052: Returns:
11053:
11054: =over 4
11055:
11056: sorted_reservable - ref to array of student_schedulable slots currently
11057: reservable, ordered by end date of reservation period.
11058:
11059: reservable_now - ref to hash of student_schedulable slots currently
11060: reservable.
11061:
11062: Keys in inner hash are:
11063: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11064: (b) endreserve: end date of reservation period.
11065: (c) uniqueperiod: start,end dates when slot is to be uniquely
11066: selected.
1.1040 raeburn 11067:
11068: sorted_future - ref to array of student_schedulable slots reservable in
11069: the future, ordered by start date of reservation period.
11070:
11071: future_reservable - ref to hash of student_schedulable slots reservable
11072: in the future.
11073:
11074: Keys in inner hash are:
11075: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11076: (b) startreserve: start date of reservation period.
11077: (c) uniqueperiod: start,end dates when slot is to be uniquely
11078: selected.
1.1040 raeburn 11079:
11080: =back
11081:
11082: =cut
11083:
11084: sub get_future_slots {
11085: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 11086: my $map;
11087: if ($symb) {
11088: ($map) = &Apache::lonnet::decode_symb($symb);
11089: }
1.1040 raeburn 11090: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11091: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11092: foreach my $slot (keys(%slots)) {
11093: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11094: if ($symb) {
1.1229 raeburn 11095: if ($slots{$slot}->{'symb'} ne '') {
11096: my $canuse;
11097: my %oksymbs;
11098: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
11099: map { $oksymbs{$_} = 1; } @slotsymbs;
11100: if ($oksymbs{$symb}) {
11101: $canuse = 1;
11102: } else {
11103: foreach my $item (@slotsymbs) {
11104: if ($item =~ /\.(page|sequence)$/) {
11105: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
11106: if (($map ne '') && ($map eq $sloturl)) {
11107: $canuse = 1;
11108: last;
11109: }
11110: }
11111: }
11112: }
11113: next unless ($canuse);
11114: }
1.1040 raeburn 11115: }
11116: if (($slots{$slot}->{'starttime'} > $now) &&
11117: ($slots{$slot}->{'endtime'} > $now)) {
11118: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11119: my $userallowed = 0;
11120: if ($slots{$slot}->{'allowedsections'}) {
11121: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11122: if (!defined($env{'request.role.sec'})
11123: && grep(/^No section assigned$/,@allowed_sec)) {
11124: $userallowed=1;
11125: } else {
11126: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11127: $userallowed=1;
11128: }
11129: }
11130: unless ($userallowed) {
11131: if (defined($env{'request.course.groups'})) {
11132: my @groups = split(/:/,$env{'request.course.groups'});
11133: foreach my $group (@groups) {
11134: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11135: $userallowed=1;
11136: last;
11137: }
11138: }
11139: }
11140: }
11141: }
11142: if ($slots{$slot}->{'allowedusers'}) {
11143: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11144: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11145: if (grep(/^\Q$user\E$/,@allowed_users)) {
11146: $userallowed = 1;
11147: }
11148: }
11149: next unless($userallowed);
11150: }
11151: my $startreserve = $slots{$slot}->{'startreserve'};
11152: my $endreserve = $slots{$slot}->{'endreserve'};
11153: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 11154: my $uniqueperiod;
11155: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11156: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11157: }
1.1040 raeburn 11158: if (($startreserve < $now) &&
11159: (!$endreserve || $endreserve > $now)) {
11160: my $lastres = $endreserve;
11161: if (!$lastres) {
11162: $lastres = $slots{$slot}->{'starttime'};
11163: }
11164: $reservable_now{$slot} = {
11165: symb => $symb,
1.1250 raeburn 11166: endreserve => $lastres,
11167: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11168: };
11169: } elsif (($startreserve > $now) &&
11170: (!$endreserve || $endreserve > $startreserve)) {
11171: $future_reservable{$slot} = {
11172: symb => $symb,
1.1250 raeburn 11173: startreserve => $startreserve,
11174: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11175: };
11176: }
11177: }
11178: }
11179: my @unsorted_reservable = keys(%reservable_now);
11180: if (@unsorted_reservable > 0) {
11181: @sorted_reservable =
11182: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11183: }
11184: my @unsorted_future = keys(%future_reservable);
11185: if (@unsorted_future > 0) {
11186: @sorted_future =
11187: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11188: }
11189: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11190: }
1.780 raeburn 11191:
11192: =pod
11193:
1.1057 foxr 11194: =back
11195:
1.549 albertel 11196: =head1 HTTP Helpers
11197:
11198: =over 4
11199:
1.648 raeburn 11200: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11201:
1.258 albertel 11202: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11203: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11204: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11205:
11206: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11207: $possible_names is an ref to an array of form element names. As an example:
11208: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11209: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11210:
11211: =cut
1.1 albertel 11212:
1.6 albertel 11213: sub get_unprocessed_cgi {
1.25 albertel 11214: my ($query,$possible_names)= @_;
1.26 matthew 11215: # $Apache::lonxml::debug=1;
1.356 albertel 11216: foreach my $pair (split(/&/,$query)) {
11217: my ($name, $value) = split(/=/,$pair);
1.369 www 11218: $name = &unescape($name);
1.25 albertel 11219: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11220: $value =~ tr/+/ /;
11221: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11222: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11223: }
1.16 harris41 11224: }
1.6 albertel 11225: }
11226:
1.112 bowersj2 11227: =pod
11228:
1.648 raeburn 11229: =item * &cacheheader()
1.112 bowersj2 11230:
11231: returns cache-controlling header code
11232:
11233: =cut
11234:
1.7 albertel 11235: sub cacheheader {
1.258 albertel 11236: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11237: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11238: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11239: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11240: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11241: return $output;
1.7 albertel 11242: }
11243:
1.112 bowersj2 11244: =pod
11245:
1.648 raeburn 11246: =item * &no_cache($r)
1.112 bowersj2 11247:
11248: specifies header code to not have cache
11249:
11250: =cut
11251:
1.9 albertel 11252: sub no_cache {
1.216 albertel 11253: my ($r) = @_;
11254: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11255: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11256: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11257: $r->no_cache(1);
11258: $r->header_out("Expires" => $date);
11259: $r->header_out("Pragma" => "no-cache");
1.123 www 11260: }
11261:
11262: sub content_type {
1.181 albertel 11263: my ($r,$type,$charset) = @_;
1.299 foxr 11264: if ($r) {
11265: # Note that printout.pl calls this with undef for $r.
11266: &no_cache($r);
11267: }
1.258 albertel 11268: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11269: unless ($charset) {
11270: $charset=&Apache::lonlocal::current_encoding;
11271: }
11272: if ($charset) { $type.='; charset='.$charset; }
11273: if ($r) {
11274: $r->content_type($type);
11275: } else {
11276: print("Content-type: $type\n\n");
11277: }
1.9 albertel 11278: }
1.25 albertel 11279:
1.112 bowersj2 11280: =pod
11281:
1.648 raeburn 11282: =item * &add_to_env($name,$value)
1.112 bowersj2 11283:
1.258 albertel 11284: adds $name to the %env hash with value
1.112 bowersj2 11285: $value, if $name already exists, the entry is converted to an array
11286: reference and $value is added to the array.
11287:
11288: =cut
11289:
1.25 albertel 11290: sub add_to_env {
11291: my ($name,$value)=@_;
1.258 albertel 11292: if (defined($env{$name})) {
11293: if (ref($env{$name})) {
1.25 albertel 11294: #already have multiple values
1.258 albertel 11295: push(@{ $env{$name} },$value);
1.25 albertel 11296: } else {
11297: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11298: my $first=$env{$name};
11299: undef($env{$name});
11300: push(@{ $env{$name} },$first,$value);
1.25 albertel 11301: }
11302: } else {
1.258 albertel 11303: $env{$name}=$value;
1.25 albertel 11304: }
1.31 albertel 11305: }
1.149 albertel 11306:
11307: =pod
11308:
1.648 raeburn 11309: =item * &get_env_multiple($name)
1.149 albertel 11310:
1.258 albertel 11311: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11312: values may be defined and end up as an array ref.
11313:
11314: returns an array of values
11315:
11316: =cut
11317:
11318: sub get_env_multiple {
11319: my ($name) = @_;
11320: my @values;
1.258 albertel 11321: if (defined($env{$name})) {
1.149 albertel 11322: # exists is it an array
1.258 albertel 11323: if (ref($env{$name})) {
11324: @values=@{ $env{$name} };
1.149 albertel 11325: } else {
1.258 albertel 11326: $values[0]=$env{$name};
1.149 albertel 11327: }
11328: }
11329: return(@values);
11330: }
11331:
1.1249 damieng 11332: # Looks at given dependencies, and returns something depending on the context.
11333: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11334: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11335: # For all other contexts, returns ($output, $counter, $numpathchg).
11336: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11337: # $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.
11338: # $numpathchg: integer with the number of cleaned up dependency paths.
11339: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11340: # \%mapping: hash reference clean path -> original path for all dependencies.
11341: # @param {string} actionurl - The path to the handler, indicative of the context.
11342: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11343: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11344: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11345: # @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)
11346: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11347: sub ask_for_embedded_content {
1.1249 damieng 11348: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11349: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11350: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11351: %currsubfile,%unused,$rem);
1.1071 raeburn 11352: my $counter = 0;
11353: my $numnew = 0;
1.987 raeburn 11354: my $numremref = 0;
11355: my $numinvalid = 0;
11356: my $numpathchg = 0;
11357: my $numexisting = 0;
1.1071 raeburn 11358: my $numunused = 0;
11359: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11360: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11361: my $heading = &mt('Upload embedded files');
11362: my $buttontext = &mt('Upload');
11363:
1.1249 damieng 11364: # fills these variables based on the context:
11365: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11366: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11367: if ($env{'request.course.id'}) {
1.1123 raeburn 11368: if ($actionurl eq '/adm/dependencies') {
11369: $navmap = Apache::lonnavmaps::navmap->new();
11370: }
11371: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11372: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11373: }
1.1123 raeburn 11374: if (($actionurl eq '/adm/portfolio') ||
11375: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11376: my $current_path='/';
11377: if ($env{'form.currentpath'}) {
11378: $current_path = $env{'form.currentpath'};
11379: }
11380: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11381: $udom = $cdom;
11382: $uname = $cnum;
1.984 raeburn 11383: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11384: } else {
11385: $udom = $env{'user.domain'};
11386: $uname = $env{'user.name'};
11387: $url = '/userfiles/portfolio';
11388: }
1.987 raeburn 11389: $toplevel = $url.'/';
1.984 raeburn 11390: $url .= $current_path;
11391: $getpropath = 1;
1.987 raeburn 11392: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11393: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11394: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11395: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11396: $toplevel = $url;
1.984 raeburn 11397: if ($rest ne '') {
1.987 raeburn 11398: $url .= $rest;
11399: }
11400: } elsif ($actionurl eq '/adm/coursedocs') {
11401: if (ref($args) eq 'HASH') {
1.1071 raeburn 11402: $url = $args->{'docs_url'};
11403: $toplevel = $url;
1.1084 raeburn 11404: if ($args->{'context'} eq 'paste') {
11405: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11406: ($path) =
11407: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11408: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11409: $fileloc =~ s{^/}{};
11410: }
1.1071 raeburn 11411: }
1.1084 raeburn 11412: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11413: if ($env{'request.course.id'} ne '') {
11414: if (ref($args) eq 'HASH') {
11415: $url = $args->{'docs_url'};
11416: $title = $args->{'docs_title'};
1.1126 raeburn 11417: $toplevel = $url;
11418: unless ($toplevel =~ m{^/}) {
11419: $toplevel = "/$url";
11420: }
1.1085 raeburn 11421: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11422: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11423: $path = $1;
11424: } else {
11425: ($path) =
11426: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11427: }
1.1195 raeburn 11428: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11429: $fileloc = $toplevel;
11430: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11431: my ($udom,$uname,$fname) =
11432: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11433: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11434: } else {
11435: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11436: }
1.1071 raeburn 11437: $fileloc =~ s{^/}{};
11438: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11439: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11440: }
1.987 raeburn 11441: }
1.1123 raeburn 11442: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11443: $udom = $cdom;
11444: $uname = $cnum;
11445: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11446: $toplevel = $url;
11447: $path = $url;
11448: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11449: $fileloc =~ s{^/}{};
1.987 raeburn 11450: }
1.1249 damieng 11451:
11452: # parses the dependency paths to get some info
11453: # fills $newfiles, $mapping, $subdependencies, $dependencies
11454: # $newfiles: hash URL -> 1 for new files or external URLs
11455: # (will be completed later)
11456: # $mapping:
11457: # for external URLs: external URL -> external URL
11458: # for relative paths: clean path -> original path
11459: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11460: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11461: foreach my $file (keys(%{$allfiles})) {
11462: my $embed_file;
11463: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11464: $embed_file = $1;
11465: } else {
11466: $embed_file = $file;
11467: }
1.1158 raeburn 11468: my ($absolutepath,$cleaned_file);
11469: if ($embed_file =~ m{^\w+://}) {
11470: $cleaned_file = $embed_file;
1.1147 raeburn 11471: $newfiles{$cleaned_file} = 1;
11472: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11473: } else {
1.1158 raeburn 11474: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11475: if ($embed_file =~ m{^/}) {
11476: $absolutepath = $embed_file;
11477: }
1.1147 raeburn 11478: if ($cleaned_file =~ m{/}) {
11479: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11480: $path = &check_for_traversal($path,$url,$toplevel);
11481: my $item = $fname;
11482: if ($path ne '') {
11483: $item = $path.'/'.$fname;
11484: $subdependencies{$path}{$fname} = 1;
11485: } else {
11486: $dependencies{$item} = 1;
11487: }
11488: if ($absolutepath) {
11489: $mapping{$item} = $absolutepath;
11490: } else {
11491: $mapping{$item} = $embed_file;
11492: }
11493: } else {
11494: $dependencies{$embed_file} = 1;
11495: if ($absolutepath) {
1.1147 raeburn 11496: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11497: } else {
1.1147 raeburn 11498: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11499: }
11500: }
1.984 raeburn 11501: }
11502: }
1.1249 damieng 11503:
11504: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11505: # and lists
11506: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11507: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11508: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11509: # the path had to be cleaned up
11510: # $existing: hash clean path -> 1 if the file exists
11511: # $numexisting: number of keys in $existing
11512: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11513: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11514: # dependency subdirectories that are
11515: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11516: my $dirptr = 16384;
1.984 raeburn 11517: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11518: $currsubfile{$path} = {};
1.1123 raeburn 11519: if (($actionurl eq '/adm/portfolio') ||
11520: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11521: my ($sublistref,$listerror) =
11522: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11523: if (ref($sublistref) eq 'ARRAY') {
11524: foreach my $line (@{$sublistref}) {
11525: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11526: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11527: }
1.984 raeburn 11528: }
1.987 raeburn 11529: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11530: if (opendir(my $dir,$url.'/'.$path)) {
11531: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11532: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11533: }
1.1084 raeburn 11534: } elsif (($actionurl eq '/adm/dependencies') ||
11535: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11536: ($args->{'context'} eq 'paste')) ||
11537: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11538: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11539: my $dir;
11540: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11541: $dir = $fileloc;
11542: } else {
11543: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11544: }
1.1071 raeburn 11545: if ($dir ne '') {
11546: my ($sublistref,$listerror) =
11547: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11548: if (ref($sublistref) eq 'ARRAY') {
11549: foreach my $line (@{$sublistref}) {
11550: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11551: undef,$mtime)=split(/\&/,$line,12);
11552: unless (($testdir&$dirptr) ||
11553: ($file_name =~ /^\.\.?$/)) {
11554: $currsubfile{$path}{$file_name} = [$size,$mtime];
11555: }
11556: }
11557: }
11558: }
1.984 raeburn 11559: }
11560: }
11561: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11562: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11563: my $item = $path.'/'.$file;
11564: unless ($mapping{$item} eq $item) {
11565: $pathchanges{$item} = 1;
11566: }
11567: $existing{$item} = 1;
11568: $numexisting ++;
11569: } else {
11570: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11571: }
11572: }
1.1071 raeburn 11573: if ($actionurl eq '/adm/dependencies') {
11574: foreach my $path (keys(%currsubfile)) {
11575: if (ref($currsubfile{$path}) eq 'HASH') {
11576: foreach my $file (keys(%{$currsubfile{$path}})) {
11577: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11578: next if (($rem ne '') &&
11579: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11580: (ref($navmap) &&
11581: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11582: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11583: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11584: $unused{$path.'/'.$file} = 1;
11585: }
11586: }
11587: }
11588: }
11589: }
1.984 raeburn 11590: }
1.1249 damieng 11591:
11592: # fills $currfile, hash file name -> 1 or [$size,$mtime]
11593: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 11594: my %currfile;
1.1123 raeburn 11595: if (($actionurl eq '/adm/portfolio') ||
11596: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11597: my ($dirlistref,$listerror) =
11598: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11599: if (ref($dirlistref) eq 'ARRAY') {
11600: foreach my $line (@{$dirlistref}) {
11601: my ($file_name,$rest) = split(/\&/,$line,2);
11602: $currfile{$file_name} = 1;
11603: }
1.984 raeburn 11604: }
1.987 raeburn 11605: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11606: if (opendir(my $dir,$url)) {
1.987 raeburn 11607: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11608: map {$currfile{$_} = 1;} @dir_list;
11609: }
1.1084 raeburn 11610: } elsif (($actionurl eq '/adm/dependencies') ||
11611: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11612: ($args->{'context'} eq 'paste')) ||
11613: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11614: if ($env{'request.course.id'} ne '') {
11615: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11616: if ($dir ne '') {
11617: my ($dirlistref,$listerror) =
11618: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11619: if (ref($dirlistref) eq 'ARRAY') {
11620: foreach my $line (@{$dirlistref}) {
11621: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11622: $size,undef,$mtime)=split(/\&/,$line,12);
11623: unless (($testdir&$dirptr) ||
11624: ($file_name =~ /^\.\.?$/)) {
11625: $currfile{$file_name} = [$size,$mtime];
11626: }
11627: }
11628: }
11629: }
11630: }
1.984 raeburn 11631: }
1.1249 damieng 11632: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
11633: # are not in subdirectories, using $currfile
1.984 raeburn 11634: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11635: if (exists($currfile{$file})) {
1.987 raeburn 11636: unless ($mapping{$file} eq $file) {
11637: $pathchanges{$file} = 1;
11638: }
11639: $existing{$file} = 1;
11640: $numexisting ++;
11641: } else {
1.984 raeburn 11642: $newfiles{$file} = 1;
11643: }
11644: }
1.1071 raeburn 11645: foreach my $file (keys(%currfile)) {
11646: unless (($file eq $filename) ||
11647: ($file eq $filename.'.bak') ||
11648: ($dependencies{$file})) {
1.1085 raeburn 11649: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11650: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11651: next if (($rem ne '') &&
11652: (($env{"httpref.$rem".$file} ne '') ||
11653: (ref($navmap) &&
11654: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11655: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11656: ($navmap->getResourceByUrl($rem.$1)))))));
11657: }
1.1085 raeburn 11658: }
1.1071 raeburn 11659: $unused{$file} = 1;
11660: }
11661: }
1.1249 damieng 11662:
11663: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 11664: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11665: ($args->{'context'} eq 'paste')) {
11666: $counter = scalar(keys(%existing));
11667: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11668: return ($output,$counter,$numpathchg,\%existing);
11669: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11670: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11671: $counter = scalar(keys(%existing));
11672: $numpathchg = scalar(keys(%pathchanges));
11673: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11674: }
1.1249 damieng 11675:
11676: # returns HTML otherwise, with dependency results and to ask for more uploads
11677:
11678: # $upload_output: missing dependencies (with upload form)
11679: # $modify_output: uploaded dependencies (in use)
11680: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 11681: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11682: if ($actionurl eq '/adm/dependencies') {
11683: next if ($embed_file =~ m{^\w+://});
11684: }
1.660 raeburn 11685: $upload_output .= &start_data_table_row().
1.1123 raeburn 11686: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11687: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11688: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11689: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11690: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11691: }
1.1123 raeburn 11692: $upload_output .= '</td>';
1.1071 raeburn 11693: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11694: $upload_output.='<td align="right">'.
11695: '<span class="LC_info LC_fontsize_medium">'.
11696: &mt("URL points to web address").'</span>';
1.987 raeburn 11697: $numremref++;
1.660 raeburn 11698: } elsif ($args->{'error_on_invalid_names'}
11699: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11700: $upload_output.='<td align="right"><span class="LC_warning">'.
11701: &mt('Invalid characters').'</span>';
1.987 raeburn 11702: $numinvalid++;
1.660 raeburn 11703: } else {
1.1123 raeburn 11704: $upload_output .= '<td>'.
11705: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11706: $embed_file,\%mapping,
1.1071 raeburn 11707: $allfiles,$codebase,'upload');
11708: $counter ++;
11709: $numnew ++;
1.987 raeburn 11710: }
11711: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11712: }
11713: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11714: if ($actionurl eq '/adm/dependencies') {
11715: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11716: $modify_output .= &start_data_table_row().
11717: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11718: '<img src="'.&icon($embed_file).'" border="0" />'.
11719: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11720: '<td>'.$size.'</td>'.
11721: '<td>'.$mtime.'</td>'.
11722: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11723: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11724: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11725: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11726: &embedded_file_element('upload_embedded',$counter,
11727: $embed_file,\%mapping,
11728: $allfiles,$codebase,'modify').
11729: '</div></td>'.
11730: &end_data_table_row()."\n";
11731: $counter ++;
11732: } else {
11733: $upload_output .= &start_data_table_row().
1.1123 raeburn 11734: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11735: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11736: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11737: &Apache::loncommon::end_data_table_row()."\n";
11738: }
11739: }
11740: my $delidx = $counter;
11741: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11742: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11743: $delete_output .= &start_data_table_row().
11744: '<td><img src="'.&icon($oldfile).'" />'.
11745: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11746: '<td>'.$size.'</td>'.
11747: '<td>'.$mtime.'</td>'.
11748: '<td><label><input type="checkbox" name="del_upload_dep" '.
11749: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11750: &embedded_file_element('upload_embedded',$delidx,
11751: $oldfile,\%mapping,$allfiles,
11752: $codebase,'delete').'</td>'.
11753: &end_data_table_row()."\n";
11754: $numunused ++;
11755: $delidx ++;
1.987 raeburn 11756: }
11757: if ($upload_output) {
11758: $upload_output = &start_data_table().
11759: $upload_output.
11760: &end_data_table()."\n";
11761: }
1.1071 raeburn 11762: if ($modify_output) {
11763: $modify_output = &start_data_table().
11764: &start_data_table_header_row().
11765: '<th>'.&mt('File').'</th>'.
11766: '<th>'.&mt('Size (KB)').'</th>'.
11767: '<th>'.&mt('Modified').'</th>'.
11768: '<th>'.&mt('Upload replacement?').'</th>'.
11769: &end_data_table_header_row().
11770: $modify_output.
11771: &end_data_table()."\n";
11772: }
11773: if ($delete_output) {
11774: $delete_output = &start_data_table().
11775: &start_data_table_header_row().
11776: '<th>'.&mt('File').'</th>'.
11777: '<th>'.&mt('Size (KB)').'</th>'.
11778: '<th>'.&mt('Modified').'</th>'.
11779: '<th>'.&mt('Delete?').'</th>'.
11780: &end_data_table_header_row().
11781: $delete_output.
11782: &end_data_table()."\n";
11783: }
1.987 raeburn 11784: my $applies = 0;
11785: if ($numremref) {
11786: $applies ++;
11787: }
11788: if ($numinvalid) {
11789: $applies ++;
11790: }
11791: if ($numexisting) {
11792: $applies ++;
11793: }
1.1071 raeburn 11794: if ($counter || $numunused) {
1.987 raeburn 11795: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11796: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11797: $state.'<h3>'.$heading.'</h3>';
11798: if ($actionurl eq '/adm/dependencies') {
11799: if ($numnew) {
11800: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11801: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11802: $upload_output.'<br />'."\n";
11803: }
11804: if ($numexisting) {
11805: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11806: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11807: $modify_output.'<br />'."\n";
11808: $buttontext = &mt('Save changes');
11809: }
11810: if ($numunused) {
11811: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11812: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11813: $delete_output.'<br />'."\n";
11814: $buttontext = &mt('Save changes');
11815: }
11816: } else {
11817: $output .= $upload_output.'<br />'."\n";
11818: }
11819: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11820: $counter.'" />'."\n";
11821: if ($actionurl eq '/adm/dependencies') {
11822: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11823: $numnew.'" />'."\n";
11824: } elsif ($actionurl eq '') {
1.987 raeburn 11825: $output .= '<input type="hidden" name="phase" value="three" />';
11826: }
11827: } elsif ($applies) {
11828: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11829: if ($applies > 1) {
11830: $output .=
1.1123 raeburn 11831: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11832: if ($numremref) {
11833: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11834: }
11835: if ($numinvalid) {
11836: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11837: }
11838: if ($numexisting) {
11839: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11840: }
11841: $output .= '</ul><br />';
11842: } elsif ($numremref) {
11843: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11844: } elsif ($numinvalid) {
11845: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11846: } elsif ($numexisting) {
11847: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11848: }
11849: $output .= $upload_output.'<br />';
11850: }
11851: my ($pathchange_output,$chgcount);
1.1071 raeburn 11852: $chgcount = $counter;
1.987 raeburn 11853: if (keys(%pathchanges) > 0) {
11854: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11855: if ($counter) {
1.987 raeburn 11856: $output .= &embedded_file_element('pathchange',$chgcount,
11857: $embed_file,\%mapping,
1.1071 raeburn 11858: $allfiles,$codebase,'change');
1.987 raeburn 11859: } else {
11860: $pathchange_output .=
11861: &start_data_table_row().
11862: '<td><input type ="checkbox" name="namechange" value="'.
11863: $chgcount.'" checked="checked" /></td>'.
11864: '<td>'.$mapping{$embed_file}.'</td>'.
11865: '<td>'.$embed_file.
11866: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11867: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11868: '</td>'.&end_data_table_row();
1.660 raeburn 11869: }
1.987 raeburn 11870: $numpathchg ++;
11871: $chgcount ++;
1.660 raeburn 11872: }
11873: }
1.1127 raeburn 11874: if (($counter) || ($numunused)) {
1.987 raeburn 11875: if ($numpathchg) {
11876: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11877: $numpathchg.'" />'."\n";
11878: }
11879: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11880: ($actionurl eq '/adm/imsimport')) {
11881: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11882: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11883: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11884: } elsif ($actionurl eq '/adm/dependencies') {
11885: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11886: }
1.1123 raeburn 11887: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11888: } elsif ($numpathchg) {
11889: my %pathchange = ();
11890: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11891: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11892: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 11893: }
1.987 raeburn 11894: }
1.1071 raeburn 11895: return ($output,$counter,$numpathchg);
1.987 raeburn 11896: }
11897:
1.1147 raeburn 11898: =pod
11899:
11900: =item * clean_path($name)
11901:
11902: Performs clean-up of directories, subdirectories and filename in an
11903: embedded object, referenced in an HTML file which is being uploaded
11904: to a course or portfolio, where
11905: "Upload embedded images/multimedia files if HTML file" checkbox was
11906: checked.
11907:
11908: Clean-up is similar to replacements in lonnet::clean_filename()
11909: except each / between sub-directory and next level is preserved.
11910:
11911: =cut
11912:
11913: sub clean_path {
11914: my ($embed_file) = @_;
11915: $embed_file =~s{^/+}{};
11916: my @contents;
11917: if ($embed_file =~ m{/}) {
11918: @contents = split(/\//,$embed_file);
11919: } else {
11920: @contents = ($embed_file);
11921: }
11922: my $lastidx = scalar(@contents)-1;
11923: for (my $i=0; $i<=$lastidx; $i++) {
11924: $contents[$i]=~s{\\}{/}g;
11925: $contents[$i]=~s/\s+/\_/g;
11926: $contents[$i]=~s{[^/\w\.\-]}{}g;
11927: if ($i == $lastidx) {
11928: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11929: }
11930: }
11931: if ($lastidx > 0) {
11932: return join('/',@contents);
11933: } else {
11934: return $contents[0];
11935: }
11936: }
11937:
1.987 raeburn 11938: sub embedded_file_element {
1.1071 raeburn 11939: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11940: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11941: (ref($codebase) eq 'HASH'));
11942: my $output;
1.1071 raeburn 11943: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11944: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11945: }
11946: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11947: &escape($embed_file).'" />';
11948: unless (($context eq 'upload_embedded') &&
11949: ($mapping->{$embed_file} eq $embed_file)) {
11950: $output .='
11951: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11952: }
11953: my $attrib;
11954: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11955: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11956: }
11957: $output .=
11958: "\n\t\t".
11959: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11960: $attrib.'" />';
11961: if (exists($codebase->{$mapping->{$embed_file}})) {
11962: $output .=
11963: "\n\t\t".
11964: '<input name="codebase_'.$num.'" type="hidden" value="'.
11965: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11966: }
1.987 raeburn 11967: return $output;
1.660 raeburn 11968: }
11969:
1.1071 raeburn 11970: sub get_dependency_details {
11971: my ($currfile,$currsubfile,$embed_file) = @_;
11972: my ($size,$mtime,$showsize,$showmtime);
11973: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11974: if ($embed_file =~ m{/}) {
11975: my ($path,$fname) = split(/\//,$embed_file);
11976: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11977: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11978: }
11979: } else {
11980: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11981: ($size,$mtime) = @{$currfile->{$embed_file}};
11982: }
11983: }
11984: $showsize = $size/1024.0;
11985: $showsize = sprintf("%.1f",$showsize);
11986: if ($mtime > 0) {
11987: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11988: }
11989: }
11990: return ($showsize,$showmtime);
11991: }
11992:
11993: sub ask_embedded_js {
11994: return <<"END";
11995: <script type="text/javascript"">
11996: // <![CDATA[
11997: function toggleBrowse(counter) {
11998: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11999: var fileid = document.getElementById('embedded_item_'+counter);
12000: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12001: if (chkboxid.checked == true) {
12002: uploaddivid.style.display='block';
12003: } else {
12004: uploaddivid.style.display='none';
12005: fileid.value = '';
12006: }
12007: }
12008: // ]]>
12009: </script>
12010:
12011: END
12012: }
12013:
1.661 raeburn 12014: sub upload_embedded {
12015: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12016: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12017: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12018: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12019: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12020: my $orig_uploaded_filename =
12021: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12022: foreach my $type ('orig','ref','attrib','codebase') {
12023: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12024: $env{'form.embedded_'.$type.'_'.$i} =
12025: &unescape($env{'form.embedded_'.$type.'_'.$i});
12026: }
12027: }
1.661 raeburn 12028: my ($path,$fname) =
12029: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12030: # no path, whole string is fname
12031: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12032: $fname = &Apache::lonnet::clean_filename($fname);
12033: # See if there is anything left
12034: next if ($fname eq '');
12035:
12036: # Check if file already exists as a file or directory.
12037: my ($state,$msg);
12038: if ($context eq 'portfolio') {
12039: my $port_path = $dirpath;
12040: if ($group ne '') {
12041: $port_path = "groups/$group/$port_path";
12042: }
1.987 raeburn 12043: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12044: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12045: $dir_root,$port_path,$disk_quota,
12046: $current_disk_usage,$uname,$udom);
12047: if ($state eq 'will_exceed_quota'
1.984 raeburn 12048: || $state eq 'file_locked') {
1.661 raeburn 12049: $output .= $msg;
12050: next;
12051: }
12052: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12053: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12054: if ($state eq 'exists') {
12055: $output .= $msg;
12056: next;
12057: }
12058: }
12059: # Check if extension is valid
12060: if (($fname =~ /\.(\w+)$/) &&
12061: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 12062: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12063: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12064: next;
12065: } elsif (($fname =~ /\.(\w+)$/) &&
12066: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12067: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12068: next;
12069: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 12070: $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 12071: next;
12072: }
12073: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 12074: my $subdir = $path;
12075: $subdir =~ s{/+$}{};
1.661 raeburn 12076: if ($context eq 'portfolio') {
1.984 raeburn 12077: my $result;
12078: if ($state eq 'existingfile') {
12079: $result=
12080: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 12081: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12082: } else {
1.984 raeburn 12083: $result=
12084: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12085: $dirpath.
1.1123 raeburn 12086: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12087: if ($result !~ m|^/uploaded/|) {
12088: $output .= '<span class="LC_error">'
12089: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12090: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12091: .'</span><br />';
12092: next;
12093: } else {
1.987 raeburn 12094: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12095: $path.$fname.'</span>').'<br />';
1.984 raeburn 12096: }
1.661 raeburn 12097: }
1.1123 raeburn 12098: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 12099: my $extendedsubdir = $dirpath.'/'.$subdir;
12100: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12101: my $result =
1.1126 raeburn 12102: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12103: if ($result !~ m|^/uploaded/|) {
12104: $output .= '<span class="LC_error">'
12105: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12106: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12107: .'</span><br />';
12108: next;
12109: } else {
12110: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12111: $path.$fname.'</span>').'<br />';
1.1125 raeburn 12112: if ($context eq 'syllabus') {
12113: &Apache::lonnet::make_public_indefinitely($result);
12114: }
1.987 raeburn 12115: }
1.661 raeburn 12116: } else {
12117: # Save the file
12118: my $target = $env{'form.embedded_item_'.$i};
12119: my $fullpath = $dir_root.$dirpath.'/'.$path;
12120: my $dest = $fullpath.$fname;
12121: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12122: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12123: my $count;
12124: my $filepath = $dir_root;
1.1027 raeburn 12125: foreach my $subdir (@parts) {
12126: $filepath .= "/$subdir";
12127: if (!-e $filepath) {
1.661 raeburn 12128: mkdir($filepath,0770);
12129: }
12130: }
12131: my $fh;
12132: if (!open($fh,'>'.$dest)) {
12133: &Apache::lonnet::logthis('Failed to create '.$dest);
12134: $output .= '<span class="LC_error">'.
1.1071 raeburn 12135: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12136: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12137: '</span><br />';
12138: } else {
12139: if (!print $fh $env{'form.embedded_item_'.$i}) {
12140: &Apache::lonnet::logthis('Failed to write to '.$dest);
12141: $output .= '<span class="LC_error">'.
1.1071 raeburn 12142: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12143: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12144: '</span><br />';
12145: } else {
1.987 raeburn 12146: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12147: $url.'</span>').'<br />';
12148: unless ($context eq 'testbank') {
12149: $footer .= &mt('View embedded file: [_1]',
12150: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12151: }
12152: }
12153: close($fh);
12154: }
12155: }
12156: if ($env{'form.embedded_ref_'.$i}) {
12157: $pathchange{$i} = 1;
12158: }
12159: }
12160: if ($output) {
12161: $output = '<p>'.$output.'</p>';
12162: }
12163: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12164: $returnflag = 'ok';
1.1071 raeburn 12165: my $numpathchgs = scalar(keys(%pathchange));
12166: if ($numpathchgs > 0) {
1.987 raeburn 12167: if ($context eq 'portfolio') {
12168: $output .= '<p>'.&mt('or').'</p>';
12169: } elsif ($context eq 'testbank') {
1.1071 raeburn 12170: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12171: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12172: $returnflag = 'modify_orightml';
12173: }
12174: }
1.1071 raeburn 12175: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12176: }
12177:
12178: sub modify_html_form {
12179: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12180: my $end = 0;
12181: my $modifyform;
12182: if ($context eq 'upload_embedded') {
12183: return unless (ref($pathchange) eq 'HASH');
12184: if ($env{'form.number_embedded_items'}) {
12185: $end += $env{'form.number_embedded_items'};
12186: }
12187: if ($env{'form.number_pathchange_items'}) {
12188: $end += $env{'form.number_pathchange_items'};
12189: }
12190: if ($end) {
12191: for (my $i=0; $i<$end; $i++) {
12192: if ($i < $env{'form.number_embedded_items'}) {
12193: next unless($pathchange->{$i});
12194: }
12195: $modifyform .=
12196: &start_data_table_row().
12197: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12198: 'checked="checked" /></td>'.
12199: '<td>'.$env{'form.embedded_ref_'.$i}.
12200: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12201: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12202: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12203: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12204: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12205: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12206: '<td>'.$env{'form.embedded_orig_'.$i}.
12207: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12208: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12209: &end_data_table_row();
1.1071 raeburn 12210: }
1.987 raeburn 12211: }
12212: } else {
12213: $modifyform = $pathchgtable;
12214: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12215: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12216: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12217: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12218: }
12219: }
12220: if ($modifyform) {
1.1071 raeburn 12221: if ($actionurl eq '/adm/dependencies') {
12222: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12223: }
1.987 raeburn 12224: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12225: '<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".
12226: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12227: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12228: '</ol></p>'."\n".'<p>'.
12229: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12230: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12231: &start_data_table()."\n".
12232: &start_data_table_header_row().
12233: '<th>'.&mt('Change?').'</th>'.
12234: '<th>'.&mt('Current reference').'</th>'.
12235: '<th>'.&mt('Required reference').'</th>'.
12236: &end_data_table_header_row()."\n".
12237: $modifyform.
12238: &end_data_table().'<br />'."\n".$hiddenstate.
12239: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12240: '</form>'."\n";
12241: }
12242: return;
12243: }
12244:
12245: sub modify_html_refs {
1.1123 raeburn 12246: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12247: my $container;
12248: if ($context eq 'portfolio') {
12249: $container = $env{'form.container'};
12250: } elsif ($context eq 'coursedoc') {
12251: $container = $env{'form.primaryurl'};
1.1071 raeburn 12252: } elsif ($context eq 'manage_dependencies') {
12253: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12254: $container = "/$container";
1.1123 raeburn 12255: } elsif ($context eq 'syllabus') {
12256: $container = $url;
1.987 raeburn 12257: } else {
1.1027 raeburn 12258: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12259: }
12260: my (%allfiles,%codebase,$output,$content);
12261: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 12262: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12263: if (wantarray) {
12264: return ('',0,0);
12265: } else {
12266: return;
12267: }
12268: }
12269: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12270: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12271: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12272: if (wantarray) {
12273: return ('',0,0);
12274: } else {
12275: return;
12276: }
12277: }
1.987 raeburn 12278: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12279: if ($content eq '-1') {
12280: if (wantarray) {
12281: return ('',0,0);
12282: } else {
12283: return;
12284: }
12285: }
1.987 raeburn 12286: } else {
1.1071 raeburn 12287: unless ($container =~ /^\Q$dir_root\E/) {
12288: if (wantarray) {
12289: return ('',0,0);
12290: } else {
12291: return;
12292: }
12293: }
1.1317 raeburn 12294: if (open(my $fh,'<',$container)) {
1.987 raeburn 12295: $content = join('', <$fh>);
12296: close($fh);
12297: } else {
1.1071 raeburn 12298: if (wantarray) {
12299: return ('',0,0);
12300: } else {
12301: return;
12302: }
1.987 raeburn 12303: }
12304: }
12305: my ($count,$codebasecount) = (0,0);
12306: my $mm = new File::MMagic;
12307: my $mime_type = $mm->checktype_contents($content);
12308: if ($mime_type eq 'text/html') {
12309: my $parse_result =
12310: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12311: \%codebase,\$content);
12312: if ($parse_result eq 'ok') {
12313: foreach my $i (@changes) {
12314: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12315: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12316: if ($allfiles{$ref}) {
12317: my $newname = $orig;
12318: my ($attrib_regexp,$codebase);
1.1006 raeburn 12319: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12320: if ($attrib_regexp =~ /:/) {
12321: $attrib_regexp =~ s/\:/|/g;
12322: }
12323: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12324: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12325: $count += $numchg;
1.1123 raeburn 12326: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 12327: delete($allfiles{$ref});
1.987 raeburn 12328: }
12329: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12330: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12331: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12332: $codebasecount ++;
12333: }
12334: }
12335: }
1.1123 raeburn 12336: my $skiprewrites;
1.987 raeburn 12337: if ($count || $codebasecount) {
12338: my $saveresult;
1.1071 raeburn 12339: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12340: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12341: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12342: if ($url eq $container) {
12343: my ($fname) = ($container =~ m{/([^/]+)$});
12344: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12345: $count,'<span class="LC_filename">'.
1.1071 raeburn 12346: $fname.'</span>').'</p>';
1.987 raeburn 12347: } else {
12348: $output = '<p class="LC_error">'.
12349: &mt('Error: update failed for: [_1].',
12350: '<span class="LC_filename">'.
12351: $container.'</span>').'</p>';
12352: }
1.1123 raeburn 12353: if ($context eq 'syllabus') {
12354: unless ($saveresult eq 'ok') {
12355: $skiprewrites = 1;
12356: }
12357: }
1.987 raeburn 12358: } else {
1.1317 raeburn 12359: if (open(my $fh,'>',$container)) {
1.987 raeburn 12360: print $fh $content;
12361: close($fh);
12362: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12363: $count,'<span class="LC_filename">'.
12364: $container.'</span>').'</p>';
1.661 raeburn 12365: } else {
1.987 raeburn 12366: $output = '<p class="LC_error">'.
12367: &mt('Error: could not update [_1].',
12368: '<span class="LC_filename">'.
12369: $container.'</span>').'</p>';
1.661 raeburn 12370: }
12371: }
12372: }
1.1123 raeburn 12373: if (($context eq 'syllabus') && (!$skiprewrites)) {
12374: my ($actionurl,$state);
12375: $actionurl = "/public/$udom/$uname/syllabus";
12376: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12377: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12378: \%codebase,
12379: {'context' => 'rewrites',
12380: 'ignore_remote_references' => 1,});
12381: if (ref($mapping) eq 'HASH') {
12382: my $rewrites = 0;
12383: foreach my $key (keys(%{$mapping})) {
12384: next if ($key =~ m{^https?://});
12385: my $ref = $mapping->{$key};
12386: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12387: my $attrib;
12388: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12389: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12390: }
12391: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12392: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12393: $rewrites += $numchg;
12394: }
12395: }
12396: if ($rewrites) {
12397: my $saveresult;
12398: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12399: if ($url eq $container) {
12400: my ($fname) = ($container =~ m{/([^/]+)$});
12401: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12402: $count,'<span class="LC_filename">'.
12403: $fname.'</span>').'</p>';
12404: } else {
12405: $output .= '<p class="LC_error">'.
12406: &mt('Error: could not update links in [_1].',
12407: '<span class="LC_filename">'.
12408: $container.'</span>').'</p>';
12409:
12410: }
12411: }
12412: }
12413: }
1.987 raeburn 12414: } else {
12415: &logthis('Failed to parse '.$container.
12416: ' to modify references: '.$parse_result);
1.661 raeburn 12417: }
12418: }
1.1071 raeburn 12419: if (wantarray) {
12420: return ($output,$count,$codebasecount);
12421: } else {
12422: return $output;
12423: }
1.661 raeburn 12424: }
12425:
12426: sub check_for_existing {
12427: my ($path,$fname,$element) = @_;
12428: my ($state,$msg);
12429: if (-d $path.'/'.$fname) {
12430: $state = 'exists';
12431: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12432: } elsif (-e $path.'/'.$fname) {
12433: $state = 'exists';
12434: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12435: }
12436: if ($state eq 'exists') {
12437: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12438: }
12439: return ($state,$msg);
12440: }
12441:
12442: sub check_for_upload {
12443: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12444: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12445: my $filesize = length($env{'form.'.$element});
12446: if (!$filesize) {
12447: my $msg = '<span class="LC_error">'.
12448: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12449: '<span class="LC_filename">'.$fname.'</span>',
12450: $filesize).'<br />'.
1.1007 raeburn 12451: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12452: '</span>';
12453: return ('zero_bytes',$msg);
12454: }
12455: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12456: my $getpropath = 1;
1.1021 raeburn 12457: my ($dirlistref,$listerror) =
12458: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12459: my $found_file = 0;
12460: my $locked_file = 0;
1.991 raeburn 12461: my @lockers;
12462: my $navmap;
12463: if ($env{'request.course.id'}) {
12464: $navmap = Apache::lonnavmaps::navmap->new();
12465: }
1.1021 raeburn 12466: if (ref($dirlistref) eq 'ARRAY') {
12467: foreach my $line (@{$dirlistref}) {
12468: my ($file_name,$rest)=split(/\&/,$line,2);
12469: if ($file_name eq $fname){
12470: $file_name = $path.$file_name;
12471: if ($group ne '') {
12472: $file_name = $group.$file_name;
12473: }
12474: $found_file = 1;
12475: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12476: foreach my $lock (@lockers) {
12477: if (ref($lock) eq 'ARRAY') {
12478: my ($symb,$crsid) = @{$lock};
12479: if ($crsid eq $env{'request.course.id'}) {
12480: if (ref($navmap)) {
12481: my $res = $navmap->getBySymb($symb);
12482: foreach my $part (@{$res->parts()}) {
12483: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12484: unless (($slot_status == $res->RESERVED) ||
12485: ($slot_status == $res->RESERVED_LOCATION)) {
12486: $locked_file = 1;
12487: }
1.991 raeburn 12488: }
1.1021 raeburn 12489: } else {
12490: $locked_file = 1;
1.991 raeburn 12491: }
12492: } else {
12493: $locked_file = 1;
12494: }
12495: }
1.1021 raeburn 12496: }
12497: } else {
12498: my @info = split(/\&/,$rest);
12499: my $currsize = $info[6]/1000;
12500: if ($currsize < $filesize) {
12501: my $extra = $filesize - $currsize;
12502: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12503: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12504: &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 12505: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12506: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12507: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12508: return ('will_exceed_quota',$msg);
12509: }
1.984 raeburn 12510: }
12511: }
1.661 raeburn 12512: }
12513: }
12514: }
12515: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12516: my $msg = '<p class="LC_warning">'.
12517: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12518: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12519: return ('will_exceed_quota',$msg);
12520: } elsif ($found_file) {
12521: if ($locked_file) {
1.1179 bisitz 12522: my $msg = '<p class="LC_warning">';
1.661 raeburn 12523: $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 12524: $msg .= '</p>';
1.661 raeburn 12525: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12526: return ('file_locked',$msg);
12527: } else {
1.1179 bisitz 12528: my $msg = '<p class="LC_error">';
1.984 raeburn 12529: $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 12530: $msg .= '</p>';
1.984 raeburn 12531: return ('existingfile',$msg);
1.661 raeburn 12532: }
12533: }
12534: }
12535:
1.987 raeburn 12536: sub check_for_traversal {
12537: my ($path,$url,$toplevel) = @_;
12538: my @parts=split(/\//,$path);
12539: my $cleanpath;
12540: my $fullpath = $url;
12541: for (my $i=0;$i<@parts;$i++) {
12542: next if ($parts[$i] eq '.');
12543: if ($parts[$i] eq '..') {
12544: $fullpath =~ s{([^/]+/)$}{};
12545: } else {
12546: $fullpath .= $parts[$i].'/';
12547: }
12548: }
12549: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12550: $cleanpath = $1;
12551: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12552: my $curr_toprel = $1;
12553: my @parts = split(/\//,$curr_toprel);
12554: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12555: my @urlparts = split(/\//,$url_toprel);
12556: my $doubledots;
12557: my $startdiff = -1;
12558: for (my $i=0; $i<@urlparts; $i++) {
12559: if ($startdiff == -1) {
12560: unless ($urlparts[$i] eq $parts[$i]) {
12561: $startdiff = $i;
12562: $doubledots .= '../';
12563: }
12564: } else {
12565: $doubledots .= '../';
12566: }
12567: }
12568: if ($startdiff > -1) {
12569: $cleanpath = $doubledots;
12570: for (my $i=$startdiff; $i<@parts; $i++) {
12571: $cleanpath .= $parts[$i].'/';
12572: }
12573: }
12574: }
12575: $cleanpath =~ s{(/)$}{};
12576: return $cleanpath;
12577: }
1.31 albertel 12578:
1.1053 raeburn 12579: sub is_archive_file {
12580: my ($mimetype) = @_;
12581: if (($mimetype eq 'application/octet-stream') ||
12582: ($mimetype eq 'application/x-stuffit') ||
12583: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12584: return 1;
12585: }
12586: return;
12587: }
12588:
12589: sub decompress_form {
1.1065 raeburn 12590: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12591: my %lt = &Apache::lonlocal::texthash (
12592: this => 'This file is an archive file.',
1.1067 raeburn 12593: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12594: itsc => 'Its contents are as follows:',
1.1053 raeburn 12595: youm => 'You may wish to extract its contents.',
12596: extr => 'Extract contents',
1.1067 raeburn 12597: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12598: proa => 'Process automatically?',
1.1053 raeburn 12599: yes => 'Yes',
12600: no => 'No',
1.1067 raeburn 12601: fold => 'Title for folder containing movie',
12602: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12603: );
1.1065 raeburn 12604: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12605: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12606: my $info = &list_archive_contents($fileloc,\@paths);
12607: if (@paths) {
12608: foreach my $path (@paths) {
12609: $path =~ s{^/}{};
1.1067 raeburn 12610: if ($path =~ m{^([^/]+)/$}) {
12611: $topdir = $1;
12612: }
1.1065 raeburn 12613: if ($path =~ m{^([^/]+)/}) {
12614: $toplevel{$1} = $path;
12615: } else {
12616: $toplevel{$path} = $path;
12617: }
12618: }
12619: }
1.1067 raeburn 12620: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12621: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12622: "$topdir/media/",
12623: "$topdir/media/$topdir.mp4",
12624: "$topdir/media/FirstFrame.png",
12625: "$topdir/media/player.swf",
12626: "$topdir/media/swfobject.js",
12627: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12628: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12629: "$topdir/$topdir.mp4",
12630: "$topdir/$topdir\_config.xml",
12631: "$topdir/$topdir\_controller.swf",
12632: "$topdir/$topdir\_embed.css",
12633: "$topdir/$topdir\_First_Frame.png",
12634: "$topdir/$topdir\_player.html",
12635: "$topdir/$topdir\_Thumbnails.png",
12636: "$topdir/playerProductInstall.swf",
12637: "$topdir/scripts/",
12638: "$topdir/scripts/config_xml.js",
12639: "$topdir/scripts/handlebars.js",
12640: "$topdir/scripts/jquery-1.7.1.min.js",
12641: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12642: "$topdir/scripts/modernizr.js",
12643: "$topdir/scripts/player-min.js",
12644: "$topdir/scripts/swfobject.js",
12645: "$topdir/skins/",
12646: "$topdir/skins/configuration_express.xml",
12647: "$topdir/skins/express_show/",
12648: "$topdir/skins/express_show/player-min.css",
12649: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12650: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12651: "$topdir/$topdir.mp4",
12652: "$topdir/$topdir\_config.xml",
12653: "$topdir/$topdir\_controller.swf",
12654: "$topdir/$topdir\_embed.css",
12655: "$topdir/$topdir\_First_Frame.png",
12656: "$topdir/$topdir\_player.html",
12657: "$topdir/$topdir\_Thumbnails.png",
12658: "$topdir/playerProductInstall.swf",
12659: "$topdir/scripts/",
12660: "$topdir/scripts/config_xml.js",
12661: "$topdir/scripts/techsmith-smart-player.min.js",
12662: "$topdir/skins/",
12663: "$topdir/skins/configuration_express.xml",
12664: "$topdir/skins/express_show/",
12665: "$topdir/skins/express_show/spritesheet.min.css",
12666: "$topdir/skins/express_show/spritesheet.png",
12667: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12668: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12669: if (@diffs == 0) {
1.1164 raeburn 12670: $is_camtasia = 6;
12671: } else {
1.1197 raeburn 12672: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12673: if (@diffs == 0) {
12674: $is_camtasia = 8;
1.1197 raeburn 12675: } else {
12676: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12677: if (@diffs == 0) {
12678: $is_camtasia = 8;
12679: }
1.1164 raeburn 12680: }
1.1067 raeburn 12681: }
12682: }
12683: my $output;
12684: if ($is_camtasia) {
12685: $output = <<"ENDCAM";
12686: <script type="text/javascript" language="Javascript">
12687: // <![CDATA[
12688:
12689: function camtasiaToggle() {
12690: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12691: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12692: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12693: document.getElementById('camtasia_titles').style.display='block';
12694: } else {
12695: document.getElementById('camtasia_titles').style.display='none';
12696: }
12697: }
12698: }
12699: return;
12700: }
12701:
12702: // ]]>
12703: </script>
12704: <p>$lt{'camt'}</p>
12705: ENDCAM
1.1065 raeburn 12706: } else {
1.1067 raeburn 12707: $output = '<p>'.$lt{'this'};
12708: if ($info eq '') {
12709: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12710: } else {
12711: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12712: '<div><pre>'.$info.'</pre></div>';
12713: }
1.1065 raeburn 12714: }
1.1067 raeburn 12715: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12716: my $duplicates;
12717: my $num = 0;
12718: if (ref($dirlist) eq 'ARRAY') {
12719: foreach my $item (@{$dirlist}) {
12720: if (ref($item) eq 'ARRAY') {
12721: if (exists($toplevel{$item->[0]})) {
12722: $duplicates .=
12723: &start_data_table_row().
12724: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12725: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12726: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12727: 'value="1" />'.&mt('Yes').'</label>'.
12728: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12729: '<td>'.$item->[0].'</td>';
12730: if ($item->[2]) {
12731: $duplicates .= '<td>'.&mt('Directory').'</td>';
12732: } else {
12733: $duplicates .= '<td>'.&mt('File').'</td>';
12734: }
12735: $duplicates .= '<td>'.$item->[3].'</td>'.
12736: '<td>'.
12737: &Apache::lonlocal::locallocaltime($item->[4]).
12738: '</td>'.
12739: &end_data_table_row();
12740: $num ++;
12741: }
12742: }
12743: }
12744: }
12745: my $itemcount;
12746: if (@paths > 0) {
12747: $itemcount = scalar(@paths);
12748: } else {
12749: $itemcount = 1;
12750: }
1.1067 raeburn 12751: if ($is_camtasia) {
12752: $output .= $lt{'auto'}.'<br />'.
12753: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12754: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12755: $lt{'yes'}.'</label> <label>'.
12756: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12757: $lt{'no'}.'</label></span><br />'.
12758: '<div id="camtasia_titles" style="display:block">'.
12759: &Apache::lonhtmlcommon::start_pick_box().
12760: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12761: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12762: &Apache::lonhtmlcommon::row_closure().
12763: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12764: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12765: &Apache::lonhtmlcommon::row_closure(1).
12766: &Apache::lonhtmlcommon::end_pick_box().
12767: '</div>';
12768: }
1.1065 raeburn 12769: $output .=
12770: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12771: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12772: "\n";
1.1065 raeburn 12773: if ($duplicates ne '') {
12774: $output .= '<p><span class="LC_warning">'.
12775: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12776: &start_data_table().
12777: &start_data_table_header_row().
12778: '<th>'.&mt('Overwrite?').'</th>'.
12779: '<th>'.&mt('Name').'</th>'.
12780: '<th>'.&mt('Type').'</th>'.
12781: '<th>'.&mt('Size').'</th>'.
12782: '<th>'.&mt('Last modified').'</th>'.
12783: &end_data_table_header_row().
12784: $duplicates.
12785: &end_data_table().
12786: '</p>';
12787: }
1.1067 raeburn 12788: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12789: if (ref($hiddenelements) eq 'HASH') {
12790: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12791: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12792: }
12793: }
12794: $output .= <<"END";
1.1067 raeburn 12795: <br />
1.1053 raeburn 12796: <input type="submit" name="decompress" value="$lt{'extr'}" />
12797: </form>
12798: $noextract
12799: END
12800: return $output;
12801: }
12802:
1.1065 raeburn 12803: sub decompression_utility {
12804: my ($program) = @_;
12805: my @utilities = ('tar','gunzip','bunzip2','unzip');
12806: my $location;
12807: if (grep(/^\Q$program\E$/,@utilities)) {
12808: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12809: '/usr/sbin/') {
12810: if (-x $dir.$program) {
12811: $location = $dir.$program;
12812: last;
12813: }
12814: }
12815: }
12816: return $location;
12817: }
12818:
12819: sub list_archive_contents {
12820: my ($file,$pathsref) = @_;
12821: my (@cmd,$output);
12822: my $needsregexp;
12823: if ($file =~ /\.zip$/) {
12824: @cmd = (&decompression_utility('unzip'),"-l");
12825: $needsregexp = 1;
12826: } elsif (($file =~ m/\.tar\.gz$/) ||
12827: ($file =~ /\.tgz$/)) {
12828: @cmd = (&decompression_utility('tar'),"-ztf");
12829: } elsif ($file =~ /\.tar\.bz2$/) {
12830: @cmd = (&decompression_utility('tar'),"-jtf");
12831: } elsif ($file =~ m|\.tar$|) {
12832: @cmd = (&decompression_utility('tar'),"-tf");
12833: }
12834: if (@cmd) {
12835: undef($!);
12836: undef($@);
12837: if (open(my $fh,"-|", @cmd, $file)) {
12838: while (my $line = <$fh>) {
12839: $output .= $line;
12840: chomp($line);
12841: my $item;
12842: if ($needsregexp) {
12843: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12844: } else {
12845: $item = $line;
12846: }
12847: if ($item ne '') {
12848: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12849: push(@{$pathsref},$item);
12850: }
12851: }
12852: }
12853: close($fh);
12854: }
12855: }
12856: return $output;
12857: }
12858:
1.1053 raeburn 12859: sub decompress_uploaded_file {
12860: my ($file,$dir) = @_;
12861: &Apache::lonnet::appenv({'cgi.file' => $file});
12862: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12863: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12864: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12865: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12866: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12867: my $decompressed = $env{'cgi.decompressed'};
12868: &Apache::lonnet::delenv('cgi.file');
12869: &Apache::lonnet::delenv('cgi.dir');
12870: &Apache::lonnet::delenv('cgi.decompressed');
12871: return ($decompressed,$result);
12872: }
12873:
1.1055 raeburn 12874: sub process_decompression {
12875: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 12876: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12877: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12878: &mt('Unexpected file path.').'</p>'."\n";
12879: }
12880: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12881: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12882: &mt('Unexpected course context.').'</p>'."\n";
12883: }
1.1293 raeburn 12884: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 12885: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12886: &mt('Filename contained unexpected characters.').'</p>'."\n";
12887: }
1.1055 raeburn 12888: my ($dir,$error,$warning,$output);
1.1180 raeburn 12889: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 12890: $error = &mt('Filename not a supported archive file type.').
12891: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12892: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12893: } else {
12894: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12895: if ($docuhome eq 'no_host') {
12896: $error = &mt('Could not determine home server for course.');
12897: } else {
12898: my @ids=&Apache::lonnet::current_machine_ids();
12899: my $currdir = "$dir_root/$destination";
12900: if (grep(/^\Q$docuhome\E$/,@ids)) {
12901: $dir = &LONCAPA::propath($docudom,$docuname).
12902: "$dir_root/$destination";
12903: } else {
12904: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12905: "$dir_root/$docudom/$docuname/$destination";
12906: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12907: $error = &mt('Archive file not found.');
12908: }
12909: }
1.1065 raeburn 12910: my (@to_overwrite,@to_skip);
12911: if ($env{'form.archive_overwrite_total'} > 0) {
12912: my $total = $env{'form.archive_overwrite_total'};
12913: for (my $i=0; $i<$total; $i++) {
12914: if ($env{'form.archive_overwrite_'.$i} == 1) {
12915: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12916: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12917: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12918: }
12919: }
12920: }
12921: my $numskip = scalar(@to_skip);
1.1292 raeburn 12922: my $numoverwrite = scalar(@to_overwrite);
12923: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12924: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12925: } elsif ($dir eq '') {
1.1055 raeburn 12926: $error = &mt('Directory containing archive file unavailable.');
12927: } elsif (!$error) {
1.1065 raeburn 12928: my ($decompressed,$display);
1.1292 raeburn 12929: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12930: my $tempdir = time.'_'.$$.int(rand(10000));
12931: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 12932: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12933: ($decompressed,$display) =
12934: &decompress_uploaded_file($file,"$dir/$tempdir");
12935: foreach my $item (@to_skip) {
12936: if (($item ne '') && ($item !~ /\.\./)) {
12937: if (-f "$dir/$tempdir/$item") {
12938: unlink("$dir/$tempdir/$item");
12939: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 12940: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 12941: }
12942: }
12943: }
12944: foreach my $item (@to_overwrite) {
12945: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12946: if (($item ne '') && ($item !~ /\.\./)) {
12947: if (-f "$dir/$item") {
12948: unlink("$dir/$item");
12949: } elsif (-d "$dir/$item") {
1.1300 raeburn 12950: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 12951: }
12952: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12953: }
1.1065 raeburn 12954: }
12955: }
1.1292 raeburn 12956: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 12957: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 12958: }
1.1065 raeburn 12959: }
12960: } else {
12961: ($decompressed,$display) =
12962: &decompress_uploaded_file($file,$dir);
12963: }
1.1055 raeburn 12964: if ($decompressed eq 'ok') {
1.1065 raeburn 12965: $output = '<p class="LC_info">'.
12966: &mt('Files extracted successfully from archive.').
12967: '</p>'."\n";
1.1055 raeburn 12968: my ($warning,$result,@contents);
12969: my ($newdirlistref,$newlisterror) =
12970: &Apache::lonnet::dirlist($currdir,$docudom,
12971: $docuname,1);
12972: my (%is_dir,%changes,@newitems);
12973: my $dirptr = 16384;
1.1065 raeburn 12974: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12975: foreach my $dir_line (@{$newdirlistref}) {
12976: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 12977: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12978: push(@newitems,$item);
12979: if ($dirptr&$testdir) {
12980: $is_dir{$item} = 1;
12981: }
12982: $changes{$item} = 1;
12983: }
12984: }
12985: }
12986: if (keys(%changes) > 0) {
12987: foreach my $item (sort(@newitems)) {
12988: if ($changes{$item}) {
12989: push(@contents,$item);
12990: }
12991: }
12992: }
12993: if (@contents > 0) {
1.1067 raeburn 12994: my $wantform;
12995: unless ($env{'form.autoextract_camtasia'}) {
12996: $wantform = 1;
12997: }
1.1056 raeburn 12998: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12999: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13000: $currdir,\%is_dir,
13001: \%children,\%parent,
1.1056 raeburn 13002: \@contents,\%dirorder,
13003: \%titles,$wantform);
1.1055 raeburn 13004: if ($datatable ne '') {
13005: $output .= &archive_options_form('decompressed',$datatable,
13006: $count,$hiddenelem);
1.1065 raeburn 13007: my $startcount = 6;
1.1055 raeburn 13008: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13009: \%titles,\%children);
1.1055 raeburn 13010: }
1.1067 raeburn 13011: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 13012: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13013: my %displayed;
13014: my $total = 1;
13015: $env{'form.archive_directory'} = [];
13016: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13017: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13018: $path =~ s{/$}{};
13019: my $item;
13020: if ($path ne '') {
13021: $item = "$path/$titles{$i}";
13022: } else {
13023: $item = $titles{$i};
13024: }
13025: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13026: if ($item eq $contents[0]) {
13027: push(@{$env{'form.archive_directory'}},$i);
13028: $env{'form.archive_'.$i} = 'display';
13029: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13030: $displayed{'folder'} = $i;
1.1164 raeburn 13031: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13032: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13033: $env{'form.archive_'.$i} = 'display';
13034: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13035: $displayed{'web'} = $i;
13036: } else {
1.1164 raeburn 13037: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13038: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13039: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13040: push(@{$env{'form.archive_directory'}},$i);
13041: }
13042: $env{'form.archive_'.$i} = 'dependency';
13043: }
13044: $total ++;
13045: }
13046: for (my $i=1; $i<$total; $i++) {
13047: next if ($i == $displayed{'web'});
13048: next if ($i == $displayed{'folder'});
13049: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13050: }
13051: $env{'form.phase'} = 'decompress_cleanup';
13052: $env{'form.archivedelete'} = 1;
13053: $env{'form.archive_count'} = $total-1;
13054: $output .=
13055: &process_extracted_files('coursedocs',$docudom,
13056: $docuname,$destination,
13057: $dir_root,$hiddenelem);
13058: }
1.1055 raeburn 13059: } else {
13060: $warning = &mt('No new items extracted from archive file.');
13061: }
13062: } else {
13063: $output = $display;
13064: $error = &mt('An error occurred during extraction from the archive file.');
13065: }
13066: }
13067: }
13068: }
13069: if ($error) {
13070: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13071: $error.'</p>'."\n";
13072: }
13073: if ($warning) {
13074: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13075: }
13076: return $output;
13077: }
13078:
13079: sub get_extracted {
1.1056 raeburn 13080: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13081: $titles,$wantform) = @_;
1.1055 raeburn 13082: my $count = 0;
13083: my $depth = 0;
13084: my $datatable;
1.1056 raeburn 13085: my @hierarchy;
1.1055 raeburn 13086: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13087: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13088: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13089: foreach my $item (@{$contents}) {
13090: $count ++;
1.1056 raeburn 13091: @{$dirorder->{$count}} = @hierarchy;
13092: $titles->{$count} = $item;
1.1055 raeburn 13093: &archive_hierarchy($depth,$count,$parent,$children);
13094: if ($wantform) {
13095: $datatable .= &archive_row($is_dir->{$item},$item,
13096: $currdir,$depth,$count);
13097: }
13098: if ($is_dir->{$item}) {
13099: $depth ++;
1.1056 raeburn 13100: push(@hierarchy,$count);
13101: $parent->{$depth} = $count;
1.1055 raeburn 13102: $datatable .=
13103: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13104: \$depth,\$count,\@hierarchy,$dirorder,
13105: $children,$parent,$titles,$wantform);
1.1055 raeburn 13106: $depth --;
1.1056 raeburn 13107: pop(@hierarchy);
1.1055 raeburn 13108: }
13109: }
13110: return ($count,$datatable);
13111: }
13112:
13113: sub recurse_extracted_archive {
1.1056 raeburn 13114: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13115: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13116: my $result='';
1.1056 raeburn 13117: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13118: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13119: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13120: return $result;
13121: }
13122: my $dirptr = 16384;
13123: my ($newdirlistref,$newlisterror) =
13124: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13125: if (ref($newdirlistref) eq 'ARRAY') {
13126: foreach my $dir_line (@{$newdirlistref}) {
13127: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13128: unless ($item =~ /^\.+$/) {
13129: $$count ++;
1.1056 raeburn 13130: @{$dirorder->{$$count}} = @{$hierarchy};
13131: $titles->{$$count} = $item;
1.1055 raeburn 13132: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13133:
1.1055 raeburn 13134: my $is_dir;
13135: if ($dirptr&$testdir) {
13136: $is_dir = 1;
13137: }
13138: if ($wantform) {
13139: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13140: }
13141: if ($is_dir) {
13142: $$depth ++;
1.1056 raeburn 13143: push(@{$hierarchy},$$count);
13144: $parent->{$$depth} = $$count;
1.1055 raeburn 13145: $result .=
13146: &recurse_extracted_archive("$currdir/$item",$docudom,
13147: $docuname,$depth,$count,
1.1056 raeburn 13148: $hierarchy,$dirorder,$children,
13149: $parent,$titles,$wantform);
1.1055 raeburn 13150: $$depth --;
1.1056 raeburn 13151: pop(@{$hierarchy});
1.1055 raeburn 13152: }
13153: }
13154: }
13155: }
13156: return $result;
13157: }
13158:
13159: sub archive_hierarchy {
13160: my ($depth,$count,$parent,$children) =@_;
13161: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13162: if (exists($parent->{$depth})) {
13163: $children->{$parent->{$depth}} .= $count.':';
13164: }
13165: }
13166: return;
13167: }
13168:
13169: sub archive_row {
13170: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13171: my ($name) = ($item =~ m{([^/]+)$});
13172: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13173: 'display' => 'Add as file',
1.1055 raeburn 13174: 'dependency' => 'Include as dependency',
13175: 'discard' => 'Discard',
13176: );
13177: if ($is_dir) {
1.1059 raeburn 13178: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13179: }
1.1056 raeburn 13180: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13181: my $offset = 0;
1.1055 raeburn 13182: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13183: $offset ++;
1.1065 raeburn 13184: if ($action ne 'display') {
13185: $offset ++;
13186: }
1.1055 raeburn 13187: $output .= '<td><span class="LC_nobreak">'.
13188: '<label><input type="radio" name="archive_'.$count.
13189: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13190: my $text = $choices{$action};
13191: if ($is_dir) {
13192: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13193: if ($action eq 'display') {
1.1059 raeburn 13194: $text = &mt('Add as folder');
1.1055 raeburn 13195: }
1.1056 raeburn 13196: } else {
13197: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13198:
13199: }
13200: $output .= ' /> '.$choices{$action}.'</label></span>';
13201: if ($action eq 'dependency') {
13202: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13203: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13204: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13205: '<option value=""></option>'."\n".
13206: '</select>'."\n".
13207: '</div>';
1.1059 raeburn 13208: } elsif ($action eq 'display') {
13209: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13210: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13211: '</div>';
1.1055 raeburn 13212: }
1.1056 raeburn 13213: $output .= '</td>';
1.1055 raeburn 13214: }
13215: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13216: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13217: for (my $i=0; $i<$depth; $i++) {
13218: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13219: }
13220: if ($is_dir) {
13221: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13222: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13223: } else {
13224: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13225: }
13226: $output .= ' '.$name.'</td>'."\n".
13227: &end_data_table_row();
13228: return $output;
13229: }
13230:
13231: sub archive_options_form {
1.1065 raeburn 13232: my ($form,$display,$count,$hiddenelem) = @_;
13233: my %lt = &Apache::lonlocal::texthash(
13234: perm => 'Permanently remove archive file?',
13235: hows => 'How should each extracted item be incorporated in the course?',
13236: cont => 'Content actions for all',
13237: addf => 'Add as folder/file',
13238: incd => 'Include as dependency for a displayed file',
13239: disc => 'Discard',
13240: no => 'No',
13241: yes => 'Yes',
13242: save => 'Save',
13243: );
13244: my $output = <<"END";
13245: <form name="$form" method="post" action="">
13246: <p><span class="LC_nobreak">$lt{'perm'}
13247: <label>
13248: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13249: </label>
13250:
13251: <label>
13252: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13253: </span>
13254: </p>
13255: <input type="hidden" name="phase" value="decompress_cleanup" />
13256: <br />$lt{'hows'}
13257: <div class="LC_columnSection">
13258: <fieldset>
13259: <legend>$lt{'cont'}</legend>
13260: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13261: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13262: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13263: </fieldset>
13264: </div>
13265: END
13266: return $output.
1.1055 raeburn 13267: &start_data_table()."\n".
1.1065 raeburn 13268: $display."\n".
1.1055 raeburn 13269: &end_data_table()."\n".
13270: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13271: $hiddenelem.
1.1065 raeburn 13272: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13273: '</form>';
13274: }
13275:
13276: sub archive_javascript {
1.1056 raeburn 13277: my ($startcount,$numitems,$titles,$children) = @_;
13278: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13279: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13280: my $scripttag = <<START;
13281: <script type="text/javascript">
13282: // <![CDATA[
13283:
13284: function checkAll(form,prefix) {
13285: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13286: for (var i=0; i < form.elements.length; i++) {
13287: var id = form.elements[i].id;
13288: if ((id != '') && (id != undefined)) {
13289: if (idstr.test(id)) {
13290: if (form.elements[i].type == 'radio') {
13291: form.elements[i].checked = true;
1.1056 raeburn 13292: var nostart = i-$startcount;
1.1059 raeburn 13293: var offset = nostart%7;
13294: var count = (nostart-offset)/7;
1.1056 raeburn 13295: dependencyCheck(form,count,offset);
1.1055 raeburn 13296: }
13297: }
13298: }
13299: }
13300: }
13301:
13302: function propagateCheck(form,count) {
13303: if (count > 0) {
1.1059 raeburn 13304: var startelement = $startcount + ((count-1) * 7);
13305: for (var j=1; j<6; j++) {
13306: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13307: var item = startelement + j;
13308: if (form.elements[item].type == 'radio') {
13309: if (form.elements[item].checked) {
13310: containerCheck(form,count,j);
13311: break;
13312: }
1.1055 raeburn 13313: }
13314: }
13315: }
13316: }
13317: }
13318:
13319: numitems = $numitems
1.1056 raeburn 13320: var titles = new Array(numitems);
13321: var parents = new Array(numitems);
1.1055 raeburn 13322: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13323: parents[i] = new Array;
1.1055 raeburn 13324: }
1.1059 raeburn 13325: var maintitle = '$maintitle';
1.1055 raeburn 13326:
13327: START
13328:
1.1056 raeburn 13329: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13330: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13331: for (my $i=0; $i<@contents; $i ++) {
13332: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13333: }
13334: }
13335:
1.1056 raeburn 13336: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13337: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13338: }
13339:
1.1055 raeburn 13340: $scripttag .= <<END;
13341:
13342: function containerCheck(form,count,offset) {
13343: if (count > 0) {
1.1056 raeburn 13344: dependencyCheck(form,count,offset);
1.1059 raeburn 13345: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13346: form.elements[item].checked = true;
13347: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13348: if (parents[count].length > 0) {
13349: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13350: containerCheck(form,parents[count][j],offset);
13351: }
13352: }
13353: }
13354: }
13355: }
13356:
13357: function dependencyCheck(form,count,offset) {
13358: if (count > 0) {
1.1059 raeburn 13359: var chosen = (offset+$startcount)+7*(count-1);
13360: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13361: var currtype = form.elements[depitem].type;
13362: if (form.elements[chosen].value == 'dependency') {
13363: document.getElementById('arc_depon_'+count).style.display='block';
13364: form.elements[depitem].options.length = 0;
13365: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13366: for (var i=1; i<=numitems; i++) {
13367: if (i == count) {
13368: continue;
13369: }
1.1059 raeburn 13370: var startelement = $startcount + (i-1) * 7;
13371: for (var j=1; j<6; j++) {
13372: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13373: var item = startelement + j;
13374: if (form.elements[item].type == 'radio') {
13375: if (form.elements[item].checked) {
13376: if (form.elements[item].value == 'display') {
13377: var n = form.elements[depitem].options.length;
13378: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13379: }
13380: }
13381: }
13382: }
13383: }
13384: }
13385: } else {
13386: document.getElementById('arc_depon_'+count).style.display='none';
13387: form.elements[depitem].options.length = 0;
13388: form.elements[depitem].options[0] = new Option('Select','',true,true);
13389: }
1.1059 raeburn 13390: titleCheck(form,count,offset);
1.1056 raeburn 13391: }
13392: }
13393:
13394: function propagateSelect(form,count,offset) {
13395: if (count > 0) {
1.1065 raeburn 13396: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13397: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13398: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13399: if (parents[count].length > 0) {
13400: for (var j=0; j<parents[count].length; j++) {
13401: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13402: }
13403: }
13404: }
13405: }
13406: }
1.1056 raeburn 13407:
13408: function containerSelect(form,count,offset,picked) {
13409: if (count > 0) {
1.1065 raeburn 13410: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13411: if (form.elements[item].type == 'radio') {
13412: if (form.elements[item].value == 'dependency') {
13413: if (form.elements[item+1].type == 'select-one') {
13414: for (var i=0; i<form.elements[item+1].options.length; i++) {
13415: if (form.elements[item+1].options[i].value == picked) {
13416: form.elements[item+1].selectedIndex = i;
13417: break;
13418: }
13419: }
13420: }
13421: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13422: if (parents[count].length > 0) {
13423: for (var j=0; j<parents[count].length; j++) {
13424: containerSelect(form,parents[count][j],offset,picked);
13425: }
13426: }
13427: }
13428: }
13429: }
13430: }
13431: }
13432:
1.1059 raeburn 13433: function titleCheck(form,count,offset) {
13434: if (count > 0) {
13435: var chosen = (offset+$startcount)+7*(count-1);
13436: var depitem = $startcount + ((count-1) * 7) + 2;
13437: var currtype = form.elements[depitem].type;
13438: if (form.elements[chosen].value == 'display') {
13439: document.getElementById('arc_title_'+count).style.display='block';
13440: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13441: document.getElementById('archive_title_'+count).value=maintitle;
13442: }
13443: } else {
13444: document.getElementById('arc_title_'+count).style.display='none';
13445: if (currtype == 'text') {
13446: document.getElementById('archive_title_'+count).value='';
13447: }
13448: }
13449: }
13450: return;
13451: }
13452:
1.1055 raeburn 13453: // ]]>
13454: </script>
13455: END
13456: return $scripttag;
13457: }
13458:
13459: sub process_extracted_files {
1.1067 raeburn 13460: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13461: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 13462: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13463: my @ids=&Apache::lonnet::current_machine_ids();
13464: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13465: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13466: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13467: if (grep(/^\Q$docuhome\E$/,@ids)) {
13468: $prefix = &LONCAPA::propath($docudom,$docuname);
13469: $pathtocheck = "$dir_root/$destination";
13470: $dir = $dir_root;
13471: $ishome = 1;
13472: } else {
13473: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13474: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 13475: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13476: }
13477: my $currdir = "$dir_root/$destination";
13478: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13479: if ($env{'form.folderpath'}) {
13480: my @items = split('&',$env{'form.folderpath'});
13481: $folders{'0'} = $items[-2];
1.1099 raeburn 13482: if ($env{'form.folderpath'} =~ /\:1$/) {
13483: $containers{'0'}='page';
13484: } else {
13485: $containers{'0'}='sequence';
13486: }
1.1055 raeburn 13487: }
13488: my @archdirs = &get_env_multiple('form.archive_directory');
13489: if ($numitems) {
13490: for (my $i=1; $i<=$numitems; $i++) {
13491: my $path = $env{'form.archive_content_'.$i};
13492: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13493: my $item = $1;
13494: $toplevelitems{$item} = $i;
13495: if (grep(/^\Q$i\E$/,@archdirs)) {
13496: $is_dir{$item} = 1;
13497: }
13498: }
13499: }
13500: }
1.1067 raeburn 13501: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13502: if (keys(%toplevelitems) > 0) {
13503: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13504: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13505: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13506: }
1.1066 raeburn 13507: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13508: if ($numitems) {
13509: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13510: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13511: my $path = $env{'form.archive_content_'.$i};
13512: if ($path =~ /^\Q$pathtocheck\E/) {
13513: if ($env{'form.archive_'.$i} eq 'discard') {
13514: if ($prefix ne '' && $path ne '') {
13515: if (-e $prefix.$path) {
1.1066 raeburn 13516: if ((@archdirs > 0) &&
13517: (grep(/^\Q$i\E$/,@archdirs))) {
13518: $todeletedir{$prefix.$path} = 1;
13519: } else {
13520: $todelete{$prefix.$path} = 1;
13521: }
1.1055 raeburn 13522: }
13523: }
13524: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13525: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13526: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13527: $docstitle = $env{'form.archive_title_'.$i};
13528: if ($docstitle eq '') {
13529: $docstitle = $title;
13530: }
1.1055 raeburn 13531: $outer = 0;
1.1056 raeburn 13532: if (ref($dirorder{$i}) eq 'ARRAY') {
13533: if (@{$dirorder{$i}} > 0) {
13534: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13535: if ($env{'form.archive_'.$item} eq 'display') {
13536: $outer = $item;
13537: last;
13538: }
13539: }
13540: }
13541: }
13542: my ($errtext,$fatal) =
13543: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13544: '/'.$folders{$outer}.'.'.
13545: $containers{$outer});
13546: next if ($fatal);
13547: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13548: if ($context eq 'coursedocs') {
1.1056 raeburn 13549: $mapinner{$i} = time;
1.1055 raeburn 13550: $folders{$i} = 'default_'.$mapinner{$i};
13551: $containers{$i} = 'sequence';
13552: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13553: $folders{$i}.'.'.$containers{$i};
13554: my $newidx = &LONCAPA::map::getresidx();
13555: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13556: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13557: push(@LONCAPA::map::order,$newidx);
13558: my ($outtext,$errtext) =
13559: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13560: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13561: '.'.$containers{$outer},1,1);
1.1056 raeburn 13562: $newseqid{$i} = $newidx;
1.1067 raeburn 13563: unless ($errtext) {
1.1294 raeburn 13564: $result .= '<li>'.&mt('Folder: [_1] added to course',
13565: &HTML::Entities::encode($docstitle,'<>&"')).
13566: '</li>'."\n";
1.1067 raeburn 13567: }
1.1055 raeburn 13568: }
13569: } else {
13570: if ($context eq 'coursedocs') {
13571: my $newidx=&LONCAPA::map::getresidx();
13572: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13573: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13574: $title;
1.1294 raeburn 13575: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
13576: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13577: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13578: }
13579: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13580: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13581: }
13582: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13583: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13584: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13585: unless ($ishome) {
13586: my $fetch = "$newdest{$i}/$title";
13587: $fetch =~ s/^\Q$prefix$dir\E//;
13588: $prompttofetch{$fetch} = 1;
13589: }
1.1292 raeburn 13590: }
1.1067 raeburn 13591: }
1.1294 raeburn 13592: $LONCAPA::map::resources[$newidx]=
13593: $docstitle.':'.$url.':false:normal:res';
13594: push(@LONCAPA::map::order, $newidx);
13595: my ($outtext,$errtext)=
13596: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13597: $docuname.'/'.$folders{$outer}.
13598: '.'.$containers{$outer},1,1);
13599: unless ($errtext) {
13600: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13601: $result .= '<li>'.&mt('File: [_1] added to course',
13602: &HTML::Entities::encode($docstitle,'<>&"')).
13603: '</li>'."\n";
13604: }
1.1067 raeburn 13605: }
1.1294 raeburn 13606: } else {
13607: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13608: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 13609: }
1.1055 raeburn 13610: }
13611: }
1.1086 raeburn 13612: }
13613: } else {
1.1294 raeburn 13614: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13615: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 13616: }
13617: }
13618: for (my $i=1; $i<=$numitems; $i++) {
13619: next unless ($env{'form.archive_'.$i} eq 'dependency');
13620: my $path = $env{'form.archive_content_'.$i};
13621: if ($path =~ /^\Q$pathtocheck\E/) {
13622: my ($title) = ($path =~ m{/([^/]+)$});
13623: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13624: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13625: if (ref($dirorder{$i}) eq 'ARRAY') {
13626: my ($itemidx,$fullpath,$relpath);
13627: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13628: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13629: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13630: if ($dirorder{$i}->[$j] eq $container) {
13631: $itemidx = $j;
1.1056 raeburn 13632: }
13633: }
1.1086 raeburn 13634: }
13635: if ($itemidx eq '') {
13636: $itemidx = 0;
13637: }
13638: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13639: if ($mapinner{$referrer{$i}}) {
13640: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13641: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13642: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13643: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13644: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13645: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13646: if (!-e $fullpath) {
13647: mkdir($fullpath,0755);
1.1056 raeburn 13648: }
13649: }
1.1086 raeburn 13650: } else {
13651: last;
1.1056 raeburn 13652: }
1.1086 raeburn 13653: }
13654: }
13655: } elsif ($newdest{$referrer{$i}}) {
13656: $fullpath = $newdest{$referrer{$i}};
13657: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13658: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13659: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13660: last;
13661: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13662: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13663: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13664: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13665: if (!-e $fullpath) {
13666: mkdir($fullpath,0755);
1.1056 raeburn 13667: }
13668: }
1.1086 raeburn 13669: } else {
13670: last;
1.1056 raeburn 13671: }
1.1055 raeburn 13672: }
13673: }
1.1086 raeburn 13674: if ($fullpath ne '') {
13675: if (-e "$prefix$path") {
1.1292 raeburn 13676: unless (rename("$prefix$path","$fullpath/$title")) {
13677: $warning .= &mt('Failed to rename dependency').'<br />';
13678: }
1.1086 raeburn 13679: }
13680: if (-e "$fullpath/$title") {
13681: my $showpath;
13682: if ($relpath ne '') {
13683: $showpath = "$relpath/$title";
13684: } else {
13685: $showpath = "/$title";
13686: }
1.1294 raeburn 13687: $result .= '<li>'.&mt('[_1] included as a dependency',
13688: &HTML::Entities::encode($showpath,'<>&"')).
13689: '</li>'."\n";
1.1292 raeburn 13690: unless ($ishome) {
13691: my $fetch = "$fullpath/$title";
13692: $fetch =~ s/^\Q$prefix$dir\E//;
13693: $prompttofetch{$fetch} = 1;
13694: }
1.1086 raeburn 13695: }
13696: }
1.1055 raeburn 13697: }
1.1086 raeburn 13698: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13699: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 13700: &HTML::Entities::encode($path,'<>&"'),
13701: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13702: '<br />';
1.1055 raeburn 13703: }
13704: } else {
1.1294 raeburn 13705: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 13706: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13707: }
13708: }
13709: if (keys(%todelete)) {
13710: foreach my $key (keys(%todelete)) {
13711: unlink($key);
1.1066 raeburn 13712: }
13713: }
13714: if (keys(%todeletedir)) {
13715: foreach my $key (keys(%todeletedir)) {
13716: rmdir($key);
13717: }
13718: }
13719: foreach my $dir (sort(keys(%is_dir))) {
13720: if (($pathtocheck ne '') && ($dir ne '')) {
13721: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13722: }
13723: }
1.1067 raeburn 13724: if ($result ne '') {
13725: $output .= '<ul>'."\n".
13726: $result."\n".
13727: '</ul>';
13728: }
13729: unless ($ishome) {
13730: my $replicationfail;
13731: foreach my $item (keys(%prompttofetch)) {
13732: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13733: unless ($fetchresult eq 'ok') {
13734: $replicationfail .= '<li>'.$item.'</li>'."\n";
13735: }
13736: }
13737: if ($replicationfail) {
13738: $output .= '<p class="LC_error">'.
13739: &mt('Course home server failed to retrieve:').'<ul>'.
13740: $replicationfail.
13741: '</ul></p>';
13742: }
13743: }
1.1055 raeburn 13744: } else {
13745: $warning = &mt('No items found in archive.');
13746: }
13747: if ($error) {
13748: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13749: $error.'</p>'."\n";
13750: }
13751: if ($warning) {
13752: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13753: }
13754: return $output;
13755: }
13756:
1.1066 raeburn 13757: sub cleanup_empty_dirs {
13758: my ($path) = @_;
13759: if (($path ne '') && (-d $path)) {
13760: if (opendir(my $dirh,$path)) {
13761: my @dircontents = grep(!/^\./,readdir($dirh));
13762: my $numitems = 0;
13763: foreach my $item (@dircontents) {
13764: if (-d "$path/$item") {
1.1111 raeburn 13765: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13766: if (-e "$path/$item") {
13767: $numitems ++;
13768: }
13769: } else {
13770: $numitems ++;
13771: }
13772: }
13773: if ($numitems == 0) {
13774: rmdir($path);
13775: }
13776: closedir($dirh);
13777: }
13778: }
13779: return;
13780: }
13781:
1.41 ng 13782: =pod
1.45 matthew 13783:
1.1162 raeburn 13784: =item * &get_folder_hierarchy()
1.1068 raeburn 13785:
13786: Provides hierarchy of names of folders/sub-folders containing the current
13787: item,
13788:
13789: Inputs: 3
13790: - $navmap - navmaps object
13791:
13792: - $map - url for map (either the trigger itself, or map containing
13793: the resource, which is the trigger).
13794:
13795: - $showitem - 1 => show title for map itself; 0 => do not show.
13796:
13797: Outputs: 1 @pathitems - array of folder/subfolder names.
13798:
13799: =cut
13800:
13801: sub get_folder_hierarchy {
13802: my ($navmap,$map,$showitem) = @_;
13803: my @pathitems;
13804: if (ref($navmap)) {
13805: my $mapres = $navmap->getResourceByUrl($map);
13806: if (ref($mapres)) {
13807: my $pcslist = $mapres->map_hierarchy();
13808: if ($pcslist ne '') {
13809: my @pcs = split(/,/,$pcslist);
13810: foreach my $pc (@pcs) {
13811: if ($pc == 1) {
1.1129 raeburn 13812: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13813: } else {
13814: my $res = $navmap->getByMapPc($pc);
13815: if (ref($res)) {
13816: my $title = $res->compTitle();
13817: $title =~ s/\W+/_/g;
13818: if ($title ne '') {
13819: push(@pathitems,$title);
13820: }
13821: }
13822: }
13823: }
13824: }
1.1071 raeburn 13825: if ($showitem) {
13826: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 13827: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13828: } else {
13829: my $maptitle = $mapres->compTitle();
13830: $maptitle =~ s/\W+/_/g;
13831: if ($maptitle ne '') {
13832: push(@pathitems,$maptitle);
13833: }
1.1068 raeburn 13834: }
13835: }
13836: }
13837: }
13838: return @pathitems;
13839: }
13840:
13841: =pod
13842:
1.1015 raeburn 13843: =item * &get_turnedin_filepath()
13844:
13845: Determines path in a user's portfolio file for storage of files uploaded
13846: to a specific essayresponse or dropbox item.
13847:
13848: Inputs: 3 required + 1 optional.
13849: $symb is symb for resource, $uname and $udom are for current user (required).
13850: $caller is optional (can be "submission", if routine is called when storing
13851: an upoaded file when "Submit Answer" button was pressed).
13852:
13853: Returns array containing $path and $multiresp.
13854: $path is path in portfolio. $multiresp is 1 if this resource contains more
13855: than one file upload item. Callers of routine should append partid as a
13856: subdirectory to $path in cases where $multiresp is 1.
13857:
13858: Called by: homework/essayresponse.pm and homework/structuretags.pm
13859:
13860: =cut
13861:
13862: sub get_turnedin_filepath {
13863: my ($symb,$uname,$udom,$caller) = @_;
13864: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13865: my $turnindir;
13866: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13867: $turnindir = $userhash{'turnindir'};
13868: my ($path,$multiresp);
13869: if ($turnindir eq '') {
13870: if ($caller eq 'submission') {
13871: $turnindir = &mt('turned in');
13872: $turnindir =~ s/\W+/_/g;
13873: my %newhash = (
13874: 'turnindir' => $turnindir,
13875: );
13876: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13877: }
13878: }
13879: if ($turnindir ne '') {
13880: $path = '/'.$turnindir.'/';
13881: my ($multipart,$turnin,@pathitems);
13882: my $navmap = Apache::lonnavmaps::navmap->new();
13883: if (defined($navmap)) {
13884: my $mapres = $navmap->getResourceByUrl($map);
13885: if (ref($mapres)) {
13886: my $pcslist = $mapres->map_hierarchy();
13887: if ($pcslist ne '') {
13888: foreach my $pc (split(/,/,$pcslist)) {
13889: my $res = $navmap->getByMapPc($pc);
13890: if (ref($res)) {
13891: my $title = $res->compTitle();
13892: $title =~ s/\W+/_/g;
13893: if ($title ne '') {
1.1149 raeburn 13894: if (($pc > 1) && (length($title) > 12)) {
13895: $title = substr($title,0,12);
13896: }
1.1015 raeburn 13897: push(@pathitems,$title);
13898: }
13899: }
13900: }
13901: }
13902: my $maptitle = $mapres->compTitle();
13903: $maptitle =~ s/\W+/_/g;
13904: if ($maptitle ne '') {
1.1149 raeburn 13905: if (length($maptitle) > 12) {
13906: $maptitle = substr($maptitle,0,12);
13907: }
1.1015 raeburn 13908: push(@pathitems,$maptitle);
13909: }
13910: unless ($env{'request.state'} eq 'construct') {
13911: my $res = $navmap->getBySymb($symb);
13912: if (ref($res)) {
13913: my $partlist = $res->parts();
13914: my $totaluploads = 0;
13915: if (ref($partlist) eq 'ARRAY') {
13916: foreach my $part (@{$partlist}) {
13917: my @types = $res->responseType($part);
13918: my @ids = $res->responseIds($part);
13919: for (my $i=0; $i < scalar(@ids); $i++) {
13920: if ($types[$i] eq 'essay') {
13921: my $partid = $part.'_'.$ids[$i];
13922: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13923: $totaluploads ++;
13924: }
13925: }
13926: }
13927: }
13928: if ($totaluploads > 1) {
13929: $multiresp = 1;
13930: }
13931: }
13932: }
13933: }
13934: } else {
13935: return;
13936: }
13937: } else {
13938: return;
13939: }
13940: my $restitle=&Apache::lonnet::gettitle($symb);
13941: $restitle =~ s/\W+/_/g;
13942: if ($restitle eq '') {
13943: $restitle = ($resurl =~ m{/[^/]+$});
13944: if ($restitle eq '') {
13945: $restitle = time;
13946: }
13947: }
1.1149 raeburn 13948: if (length($restitle) > 12) {
13949: $restitle = substr($restitle,0,12);
13950: }
1.1015 raeburn 13951: push(@pathitems,$restitle);
13952: $path .= join('/',@pathitems);
13953: }
13954: return ($path,$multiresp);
13955: }
13956:
13957: =pod
13958:
1.464 albertel 13959: =back
1.41 ng 13960:
1.112 bowersj2 13961: =head1 CSV Upload/Handling functions
1.38 albertel 13962:
1.41 ng 13963: =over 4
13964:
1.648 raeburn 13965: =item * &upfile_store($r)
1.41 ng 13966:
13967: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13968: needs $env{'form.upfile'}
1.41 ng 13969: returns $datatoken to be put into hidden field
13970:
13971: =cut
1.31 albertel 13972:
13973: sub upfile_store {
13974: my $r=shift;
1.258 albertel 13975: $env{'form.upfile'}=~s/\r/\n/gs;
13976: $env{'form.upfile'}=~s/\f/\n/gs;
13977: $env{'form.upfile'}=~s/\n+/\n/gs;
13978: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13979:
1.1299 raeburn 13980: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13981: '_enroll_'.$env{'request.course.id'}.'_'.
13982: time.'_'.$$);
13983: return if ($datatoken eq '');
13984:
1.31 albertel 13985: {
1.158 raeburn 13986: my $datafile = $r->dir_config('lonDaemons').
13987: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 13988: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13989: print $fh $env{'form.upfile'};
1.158 raeburn 13990: close($fh);
13991: }
1.31 albertel 13992: }
13993: return $datatoken;
13994: }
13995:
1.56 matthew 13996: =pod
13997:
1.1290 raeburn 13998: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13999:
14000: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 14001: $datatoken is the name to assign to the temporary file.
1.258 albertel 14002: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14003:
14004: =cut
1.31 albertel 14005:
14006: sub load_tmp_file {
1.1290 raeburn 14007: my ($r,$datatoken) = @_;
14008: return if ($datatoken eq '');
1.31 albertel 14009: my @studentdata=();
14010: {
1.158 raeburn 14011: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 14012: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14013: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14014: @studentdata=<$fh>;
14015: close($fh);
14016: }
1.31 albertel 14017: }
1.258 albertel 14018: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14019: }
14020:
1.1290 raeburn 14021: sub valid_datatoken {
14022: my ($datatoken) = @_;
1.1325 raeburn 14023: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1290 raeburn 14024: return $datatoken;
14025: }
14026: return;
14027: }
14028:
1.56 matthew 14029: =pod
14030:
1.648 raeburn 14031: =item * &upfile_record_sep()
1.41 ng 14032:
14033: Separate uploaded file into records
14034: returns array of records,
1.258 albertel 14035: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14036:
14037: =cut
1.31 albertel 14038:
14039: sub upfile_record_sep {
1.258 albertel 14040: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14041: } else {
1.248 albertel 14042: my @records;
1.258 albertel 14043: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14044: if ($line=~/^\s*$/) { next; }
14045: push(@records,$line);
14046: }
14047: return @records;
1.31 albertel 14048: }
14049: }
14050:
1.56 matthew 14051: =pod
14052:
1.648 raeburn 14053: =item * &record_sep($record)
1.41 ng 14054:
1.258 albertel 14055: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14056:
14057: =cut
14058:
1.263 www 14059: sub takeleft {
14060: my $index=shift;
14061: return substr('0000'.$index,-4,4);
14062: }
14063:
1.31 albertel 14064: sub record_sep {
14065: my $record=shift;
14066: my %components=();
1.258 albertel 14067: if ($env{'form.upfiletype'} eq 'xml') {
14068: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14069: my $i=0;
1.356 albertel 14070: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14071: $field=~s/^(\"|\')//;
14072: $field=~s/(\"|\')$//;
1.263 www 14073: $components{&takeleft($i)}=$field;
1.31 albertel 14074: $i++;
14075: }
1.258 albertel 14076: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14077: my $i=0;
1.356 albertel 14078: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14079: $field=~s/^(\"|\')//;
14080: $field=~s/(\"|\')$//;
1.263 www 14081: $components{&takeleft($i)}=$field;
1.31 albertel 14082: $i++;
14083: }
14084: } else {
1.561 www 14085: my $separator=',';
1.480 banghart 14086: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14087: $separator=';';
1.480 banghart 14088: }
1.31 albertel 14089: my $i=0;
1.561 www 14090: # the character we are looking for to indicate the end of a quote or a record
14091: my $looking_for=$separator;
14092: # do not add the characters to the fields
14093: my $ignore=0;
14094: # we just encountered a separator (or the beginning of the record)
14095: my $just_found_separator=1;
14096: # store the field we are working on here
14097: my $field='';
14098: # work our way through all characters in record
14099: foreach my $character ($record=~/(.)/g) {
14100: if ($character eq $looking_for) {
14101: if ($character ne $separator) {
14102: # Found the end of a quote, again looking for separator
14103: $looking_for=$separator;
14104: $ignore=1;
14105: } else {
14106: # Found a separator, store away what we got
14107: $components{&takeleft($i)}=$field;
14108: $i++;
14109: $just_found_separator=1;
14110: $ignore=0;
14111: $field='';
14112: }
14113: next;
14114: }
14115: # single or double quotation marks after a separator indicate beginning of a quote
14116: # we are now looking for the end of the quote and need to ignore separators
14117: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14118: $looking_for=$character;
14119: next;
14120: }
14121: # ignore would be true after we reached the end of a quote
14122: if ($ignore) { next; }
14123: if (($just_found_separator) && ($character=~/\s/)) { next; }
14124: $field.=$character;
14125: $just_found_separator=0;
1.31 albertel 14126: }
1.561 www 14127: # catch the very last entry, since we never encountered the separator
14128: $components{&takeleft($i)}=$field;
1.31 albertel 14129: }
14130: return %components;
14131: }
14132:
1.144 matthew 14133: ######################################################
14134: ######################################################
14135:
1.56 matthew 14136: =pod
14137:
1.648 raeburn 14138: =item * &upfile_select_html()
1.41 ng 14139:
1.144 matthew 14140: Return HTML code to select a file from the users machine and specify
14141: the file type.
1.41 ng 14142:
14143: =cut
14144:
1.144 matthew 14145: ######################################################
14146: ######################################################
1.31 albertel 14147: sub upfile_select_html {
1.144 matthew 14148: my %Types = (
14149: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14150: semisv => &mt('Semicolon separated values'),
1.144 matthew 14151: space => &mt('Space separated'),
14152: tab => &mt('Tabulator separated'),
14153: # xml => &mt('HTML/XML'),
14154: );
14155: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14156: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14157: foreach my $type (sort(keys(%Types))) {
14158: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14159: }
14160: $Str .= "</select>\n";
14161: return $Str;
1.31 albertel 14162: }
14163:
1.301 albertel 14164: sub get_samples {
14165: my ($records,$toget) = @_;
14166: my @samples=({});
14167: my $got=0;
14168: foreach my $rec (@$records) {
14169: my %temp = &record_sep($rec);
14170: if (! grep(/\S/, values(%temp))) { next; }
14171: if (%temp) {
14172: $samples[$got]=\%temp;
14173: $got++;
14174: if ($got == $toget) { last; }
14175: }
14176: }
14177: return \@samples;
14178: }
14179:
1.144 matthew 14180: ######################################################
14181: ######################################################
14182:
1.56 matthew 14183: =pod
14184:
1.648 raeburn 14185: =item * &csv_print_samples($r,$records)
1.41 ng 14186:
14187: Prints a table of sample values from each column uploaded $r is an
14188: Apache Request ref, $records is an arrayref from
14189: &Apache::loncommon::upfile_record_sep
14190:
14191: =cut
14192:
1.144 matthew 14193: ######################################################
14194: ######################################################
1.31 albertel 14195: sub csv_print_samples {
14196: my ($r,$records) = @_;
1.662 bisitz 14197: my $samples = &get_samples($records,5);
1.301 albertel 14198:
1.594 raeburn 14199: $r->print(&mt('Samples').'<br />'.&start_data_table().
14200: &start_data_table_header_row());
1.356 albertel 14201: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14202: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14203: $r->print(&end_data_table_header_row());
1.301 albertel 14204: foreach my $hash (@$samples) {
1.594 raeburn 14205: $r->print(&start_data_table_row());
1.356 albertel 14206: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14207: $r->print('<td>');
1.356 albertel 14208: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14209: $r->print('</td>');
14210: }
1.594 raeburn 14211: $r->print(&end_data_table_row());
1.31 albertel 14212: }
1.594 raeburn 14213: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14214: }
14215:
1.144 matthew 14216: ######################################################
14217: ######################################################
14218:
1.56 matthew 14219: =pod
14220:
1.648 raeburn 14221: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14222:
14223: Prints a table to create associations between values and table columns.
1.144 matthew 14224:
1.41 ng 14225: $r is an Apache Request ref,
14226: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14227: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14228:
14229: =cut
14230:
1.144 matthew 14231: ######################################################
14232: ######################################################
1.31 albertel 14233: sub csv_print_select_table {
14234: my ($r,$records,$d) = @_;
1.301 albertel 14235: my $i=0;
14236: my $samples = &get_samples($records,1);
1.144 matthew 14237: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14238: &start_data_table().&start_data_table_header_row().
1.144 matthew 14239: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14240: '<th>'.&mt('Column').'</th>'.
14241: &end_data_table_header_row()."\n");
1.356 albertel 14242: foreach my $array_ref (@$d) {
14243: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14244: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14245:
1.875 bisitz 14246: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14247: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14248: $r->print('<option value="none"></option>');
1.356 albertel 14249: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14250: $r->print('<option value="'.$sample.'"'.
14251: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14252: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14253: }
1.594 raeburn 14254: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14255: $i++;
14256: }
1.594 raeburn 14257: $r->print(&end_data_table());
1.31 albertel 14258: $i--;
14259: return $i;
14260: }
1.56 matthew 14261:
1.144 matthew 14262: ######################################################
14263: ######################################################
14264:
1.56 matthew 14265: =pod
1.31 albertel 14266:
1.648 raeburn 14267: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14268:
14269: Prints a table of sample values from the upload and can make associate samples to internal names.
14270:
14271: $r is an Apache Request ref,
14272: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14273: $d is an array of 2 element arrays (internal name, displayed name)
14274:
14275: =cut
14276:
1.144 matthew 14277: ######################################################
14278: ######################################################
1.31 albertel 14279: sub csv_samples_select_table {
14280: my ($r,$records,$d) = @_;
14281: my $i=0;
1.144 matthew 14282: #
1.662 bisitz 14283: my $max_samples = 5;
14284: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14285: $r->print(&start_data_table().
14286: &start_data_table_header_row().'<th>'.
14287: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14288: &end_data_table_header_row());
1.301 albertel 14289:
14290: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14291: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14292: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14293: foreach my $option (@$d) {
14294: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14295: $r->print('<option value="'.$value.'"'.
1.253 albertel 14296: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14297: $display.'</option>');
1.31 albertel 14298: }
14299: $r->print('</select></td><td>');
1.662 bisitz 14300: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14301: if (defined($samples->[$line]{$key})) {
14302: $r->print($samples->[$line]{$key}."<br />\n");
14303: }
14304: }
1.594 raeburn 14305: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14306: $i++;
14307: }
1.594 raeburn 14308: $r->print(&end_data_table());
1.31 albertel 14309: $i--;
14310: return($i);
1.115 matthew 14311: }
14312:
1.144 matthew 14313: ######################################################
14314: ######################################################
14315:
1.115 matthew 14316: =pod
14317:
1.648 raeburn 14318: =item * &clean_excel_name($name)
1.115 matthew 14319:
14320: Returns a replacement for $name which does not contain any illegal characters.
14321:
14322: =cut
14323:
1.144 matthew 14324: ######################################################
14325: ######################################################
1.115 matthew 14326: sub clean_excel_name {
14327: my ($name) = @_;
14328: $name =~ s/[:\*\?\/\\]//g;
14329: if (length($name) > 31) {
14330: $name = substr($name,0,31);
14331: }
14332: return $name;
1.25 albertel 14333: }
1.84 albertel 14334:
1.85 albertel 14335: =pod
14336:
1.648 raeburn 14337: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14338:
14339: Returns either 1 or undef
14340:
14341: 1 if the part is to be hidden, undef if it is to be shown
14342:
14343: Arguments are:
14344:
14345: $id the id of the part to be checked
14346: $symb, optional the symb of the resource to check
14347: $udom, optional the domain of the user to check for
14348: $uname, optional the username of the user to check for
14349:
14350: =cut
1.84 albertel 14351:
14352: sub check_if_partid_hidden {
14353: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14354: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14355: $symb,$udom,$uname);
1.141 albertel 14356: my $truth=1;
14357: #if the string starts with !, then the list is the list to show not hide
14358: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14359: my @hiddenlist=split(/,/,$hiddenparts);
14360: foreach my $checkid (@hiddenlist) {
1.141 albertel 14361: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14362: }
1.141 albertel 14363: return !$truth;
1.84 albertel 14364: }
1.127 matthew 14365:
1.138 matthew 14366:
14367: ############################################################
14368: ############################################################
14369:
14370: =pod
14371:
1.157 matthew 14372: =back
14373:
1.138 matthew 14374: =head1 cgi-bin script and graphing routines
14375:
1.157 matthew 14376: =over 4
14377:
1.648 raeburn 14378: =item * &get_cgi_id()
1.138 matthew 14379:
14380: Inputs: none
14381:
14382: Returns an id which can be used to pass environment variables
14383: to various cgi-bin scripts. These environment variables will
14384: be removed from the users environment after a given time by
14385: the routine &Apache::lonnet::transfer_profile_to_env.
14386:
14387: =cut
14388:
14389: ############################################################
14390: ############################################################
1.152 albertel 14391: my $uniq=0;
1.136 matthew 14392: sub get_cgi_id {
1.154 albertel 14393: $uniq=($uniq+1)%100000;
1.280 albertel 14394: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14395: }
14396:
1.127 matthew 14397: ############################################################
14398: ############################################################
14399:
14400: =pod
14401:
1.648 raeburn 14402: =item * &DrawBarGraph()
1.127 matthew 14403:
1.138 matthew 14404: Facilitates the plotting of data in a (stacked) bar graph.
14405: Puts plot definition data into the users environment in order for
14406: graph.png to plot it. Returns an <img> tag for the plot.
14407: The bars on the plot are labeled '1','2',...,'n'.
14408:
14409: Inputs:
14410:
14411: =over 4
14412:
14413: =item $Title: string, the title of the plot
14414:
14415: =item $xlabel: string, text describing the X-axis of the plot
14416:
14417: =item $ylabel: string, text describing the Y-axis of the plot
14418:
14419: =item $Max: scalar, the maximum Y value to use in the plot
14420: If $Max is < any data point, the graph will not be rendered.
14421:
1.140 matthew 14422: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14423: they are plotted. If undefined, default values will be used.
14424:
1.178 matthew 14425: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14426:
1.138 matthew 14427: =item @Values: An array of array references. Each array reference holds data
14428: to be plotted in a stacked bar chart.
14429:
1.239 matthew 14430: =item If the final element of @Values is a hash reference the key/value
14431: pairs will be added to the graph definition.
14432:
1.138 matthew 14433: =back
14434:
14435: Returns:
14436:
14437: An <img> tag which references graph.png and the appropriate identifying
14438: information for the plot.
14439:
1.127 matthew 14440: =cut
14441:
14442: ############################################################
14443: ############################################################
1.134 matthew 14444: sub DrawBarGraph {
1.178 matthew 14445: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14446: #
14447: if (! defined($colors)) {
14448: $colors = ['#33ff00',
14449: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14450: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14451: ];
14452: }
1.228 matthew 14453: my $extra_settings = {};
14454: if (ref($Values[-1]) eq 'HASH') {
14455: $extra_settings = pop(@Values);
14456: }
1.127 matthew 14457: #
1.136 matthew 14458: my $identifier = &get_cgi_id();
14459: my $id = 'cgi.'.$identifier;
1.129 matthew 14460: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14461: return '';
14462: }
1.225 matthew 14463: #
14464: my @Labels;
14465: if (defined($labels)) {
14466: @Labels = @$labels;
14467: } else {
14468: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 14469: push(@Labels,$i+1);
1.225 matthew 14470: }
14471: }
14472: #
1.129 matthew 14473: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14474: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14475: my %ValuesHash;
14476: my $NumSets=1;
14477: foreach my $array (@Values) {
14478: next if (! ref($array));
1.136 matthew 14479: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14480: join(',',@$array);
1.129 matthew 14481: }
1.127 matthew 14482: #
1.136 matthew 14483: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14484: if ($NumBars < 3) {
14485: $width = 120+$NumBars*32;
1.220 matthew 14486: $xskip = 1;
1.225 matthew 14487: $bar_width = 30;
14488: } elsif ($NumBars < 5) {
14489: $width = 120+$NumBars*20;
14490: $xskip = 1;
14491: $bar_width = 20;
1.220 matthew 14492: } elsif ($NumBars < 10) {
1.136 matthew 14493: $width = 120+$NumBars*15;
14494: $xskip = 1;
14495: $bar_width = 15;
14496: } elsif ($NumBars <= 25) {
14497: $width = 120+$NumBars*11;
14498: $xskip = 5;
14499: $bar_width = 8;
14500: } elsif ($NumBars <= 50) {
14501: $width = 120+$NumBars*8;
14502: $xskip = 5;
14503: $bar_width = 4;
14504: } else {
14505: $width = 120+$NumBars*8;
14506: $xskip = 5;
14507: $bar_width = 4;
14508: }
14509: #
1.137 matthew 14510: $Max = 1 if ($Max < 1);
14511: if ( int($Max) < $Max ) {
14512: $Max++;
14513: $Max = int($Max);
14514: }
1.127 matthew 14515: $Title = '' if (! defined($Title));
14516: $xlabel = '' if (! defined($xlabel));
14517: $ylabel = '' if (! defined($ylabel));
1.369 www 14518: $ValuesHash{$id.'.title'} = &escape($Title);
14519: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14520: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14521: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14522: $ValuesHash{$id.'.NumBars'} = $NumBars;
14523: $ValuesHash{$id.'.NumSets'} = $NumSets;
14524: $ValuesHash{$id.'.PlotType'} = 'bar';
14525: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14526: $ValuesHash{$id.'.height'} = $height;
14527: $ValuesHash{$id.'.width'} = $width;
14528: $ValuesHash{$id.'.xskip'} = $xskip;
14529: $ValuesHash{$id.'.bar_width'} = $bar_width;
14530: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14531: #
1.228 matthew 14532: # Deal with other parameters
14533: while (my ($key,$value) = each(%$extra_settings)) {
14534: $ValuesHash{$id.'.'.$key} = $value;
14535: }
14536: #
1.646 raeburn 14537: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14538: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14539: }
14540:
14541: ############################################################
14542: ############################################################
14543:
14544: =pod
14545:
1.648 raeburn 14546: =item * &DrawXYGraph()
1.137 matthew 14547:
1.138 matthew 14548: Facilitates the plotting of data in an XY graph.
14549: Puts plot definition data into the users environment in order for
14550: graph.png to plot it. Returns an <img> tag for the plot.
14551:
14552: Inputs:
14553:
14554: =over 4
14555:
14556: =item $Title: string, the title of the plot
14557:
14558: =item $xlabel: string, text describing the X-axis of the plot
14559:
14560: =item $ylabel: string, text describing the Y-axis of the plot
14561:
14562: =item $Max: scalar, the maximum Y value to use in the plot
14563: If $Max is < any data point, the graph will not be rendered.
14564:
14565: =item $colors: Array ref containing the hex color codes for the data to be
14566: plotted in. If undefined, default values will be used.
14567:
14568: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14569:
14570: =item $Ydata: Array ref containing Array refs.
1.185 www 14571: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14572:
14573: =item %Values: hash indicating or overriding any default values which are
14574: passed to graph.png.
14575: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14576:
14577: =back
14578:
14579: Returns:
14580:
14581: An <img> tag which references graph.png and the appropriate identifying
14582: information for the plot.
14583:
1.137 matthew 14584: =cut
14585:
14586: ############################################################
14587: ############################################################
14588: sub DrawXYGraph {
14589: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14590: #
14591: # Create the identifier for the graph
14592: my $identifier = &get_cgi_id();
14593: my $id = 'cgi.'.$identifier;
14594: #
14595: $Title = '' if (! defined($Title));
14596: $xlabel = '' if (! defined($xlabel));
14597: $ylabel = '' if (! defined($ylabel));
14598: my %ValuesHash =
14599: (
1.369 www 14600: $id.'.title' => &escape($Title),
14601: $id.'.xlabel' => &escape($xlabel),
14602: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14603: $id.'.y_max_value'=> $Max,
14604: $id.'.labels' => join(',',@$Xlabels),
14605: $id.'.PlotType' => 'XY',
14606: );
14607: #
14608: if (defined($colors) && ref($colors) eq 'ARRAY') {
14609: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14610: }
14611: #
14612: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14613: return '';
14614: }
14615: my $NumSets=1;
1.138 matthew 14616: foreach my $array (@{$Ydata}){
1.137 matthew 14617: next if (! ref($array));
14618: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14619: }
1.138 matthew 14620: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14621: #
14622: # Deal with other parameters
14623: while (my ($key,$value) = each(%Values)) {
14624: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14625: }
14626: #
1.646 raeburn 14627: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14628: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14629: }
14630:
14631: ############################################################
14632: ############################################################
14633:
14634: =pod
14635:
1.648 raeburn 14636: =item * &DrawXYYGraph()
1.138 matthew 14637:
14638: Facilitates the plotting of data in an XY graph with two Y axes.
14639: Puts plot definition data into the users environment in order for
14640: graph.png to plot it. Returns an <img> tag for the plot.
14641:
14642: Inputs:
14643:
14644: =over 4
14645:
14646: =item $Title: string, the title of the plot
14647:
14648: =item $xlabel: string, text describing the X-axis of the plot
14649:
14650: =item $ylabel: string, text describing the Y-axis of the plot
14651:
14652: =item $colors: Array ref containing the hex color codes for the data to be
14653: plotted in. If undefined, default values will be used.
14654:
14655: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14656:
14657: =item $Ydata1: The first data set
14658:
14659: =item $Min1: The minimum value of the left Y-axis
14660:
14661: =item $Max1: The maximum value of the left Y-axis
14662:
14663: =item $Ydata2: The second data set
14664:
14665: =item $Min2: The minimum value of the right Y-axis
14666:
14667: =item $Max2: The maximum value of the left Y-axis
14668:
14669: =item %Values: hash indicating or overriding any default values which are
14670: passed to graph.png.
14671: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14672:
14673: =back
14674:
14675: Returns:
14676:
14677: An <img> tag which references graph.png and the appropriate identifying
14678: information for the plot.
1.136 matthew 14679:
14680: =cut
14681:
14682: ############################################################
14683: ############################################################
1.137 matthew 14684: sub DrawXYYGraph {
14685: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14686: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14687: #
14688: # Create the identifier for the graph
14689: my $identifier = &get_cgi_id();
14690: my $id = 'cgi.'.$identifier;
14691: #
14692: $Title = '' if (! defined($Title));
14693: $xlabel = '' if (! defined($xlabel));
14694: $ylabel = '' if (! defined($ylabel));
14695: my %ValuesHash =
14696: (
1.369 www 14697: $id.'.title' => &escape($Title),
14698: $id.'.xlabel' => &escape($xlabel),
14699: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14700: $id.'.labels' => join(',',@$Xlabels),
14701: $id.'.PlotType' => 'XY',
14702: $id.'.NumSets' => 2,
1.137 matthew 14703: $id.'.two_axes' => 1,
14704: $id.'.y1_max_value' => $Max1,
14705: $id.'.y1_min_value' => $Min1,
14706: $id.'.y2_max_value' => $Max2,
14707: $id.'.y2_min_value' => $Min2,
1.136 matthew 14708: );
14709: #
1.137 matthew 14710: if (defined($colors) && ref($colors) eq 'ARRAY') {
14711: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14712: }
14713: #
14714: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14715: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14716: return '';
14717: }
14718: my $NumSets=1;
1.137 matthew 14719: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14720: next if (! ref($array));
14721: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14722: }
14723: #
14724: # Deal with other parameters
14725: while (my ($key,$value) = each(%Values)) {
14726: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14727: }
14728: #
1.646 raeburn 14729: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14730: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14731: }
14732:
14733: ############################################################
14734: ############################################################
14735:
14736: =pod
14737:
1.157 matthew 14738: =back
14739:
1.139 matthew 14740: =head1 Statistics helper routines?
14741:
14742: Bad place for them but what the hell.
14743:
1.157 matthew 14744: =over 4
14745:
1.648 raeburn 14746: =item * &chartlink()
1.139 matthew 14747:
14748: Returns a link to the chart for a specific student.
14749:
14750: Inputs:
14751:
14752: =over 4
14753:
14754: =item $linktext: The text of the link
14755:
14756: =item $sname: The students username
14757:
14758: =item $sdomain: The students domain
14759:
14760: =back
14761:
1.157 matthew 14762: =back
14763:
1.139 matthew 14764: =cut
14765:
14766: ############################################################
14767: ############################################################
14768: sub chartlink {
14769: my ($linktext, $sname, $sdomain) = @_;
14770: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14771: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14772: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14773: '">'.$linktext.'</a>';
1.153 matthew 14774: }
14775:
14776: #######################################################
14777: #######################################################
14778:
14779: =pod
14780:
14781: =head1 Course Environment Routines
1.157 matthew 14782:
14783: =over 4
1.153 matthew 14784:
1.648 raeburn 14785: =item * &restore_course_settings()
1.153 matthew 14786:
1.648 raeburn 14787: =item * &store_course_settings()
1.153 matthew 14788:
14789: Restores/Store indicated form parameters from the course environment.
14790: Will not overwrite existing values of the form parameters.
14791:
14792: Inputs:
14793: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14794:
14795: a hash ref describing the data to be stored. For example:
14796:
14797: %Save_Parameters = ('Status' => 'scalar',
14798: 'chartoutputmode' => 'scalar',
14799: 'chartoutputdata' => 'scalar',
14800: 'Section' => 'array',
1.373 raeburn 14801: 'Group' => 'array',
1.153 matthew 14802: 'StudentData' => 'array',
14803: 'Maps' => 'array');
14804:
14805: Returns: both routines return nothing
14806:
1.631 raeburn 14807: =back
14808:
1.153 matthew 14809: =cut
14810:
14811: #######################################################
14812: #######################################################
14813: sub store_course_settings {
1.496 albertel 14814: return &store_settings($env{'request.course.id'},@_);
14815: }
14816:
14817: sub store_settings {
1.153 matthew 14818: # save to the environment
14819: # appenv the same items, just to be safe
1.300 albertel 14820: my $udom = $env{'user.domain'};
14821: my $uname = $env{'user.name'};
1.496 albertel 14822: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14823: my %SaveHash;
14824: my %AppHash;
14825: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14826: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14827: my $envname = 'environment.'.$basename;
1.258 albertel 14828: if (exists($env{'form.'.$setting})) {
1.153 matthew 14829: # Save this value away
14830: if ($type eq 'scalar' &&
1.258 albertel 14831: (! exists($env{$envname}) ||
14832: $env{$envname} ne $env{'form.'.$setting})) {
14833: $SaveHash{$basename} = $env{'form.'.$setting};
14834: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14835: } elsif ($type eq 'array') {
14836: my $stored_form;
1.258 albertel 14837: if (ref($env{'form.'.$setting})) {
1.153 matthew 14838: $stored_form = join(',',
14839: map {
1.369 www 14840: &escape($_);
1.258 albertel 14841: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14842: } else {
14843: $stored_form =
1.369 www 14844: &escape($env{'form.'.$setting});
1.153 matthew 14845: }
14846: # Determine if the array contents are the same.
1.258 albertel 14847: if ($stored_form ne $env{$envname}) {
1.153 matthew 14848: $SaveHash{$basename} = $stored_form;
14849: $AppHash{$envname} = $stored_form;
14850: }
14851: }
14852: }
14853: }
14854: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14855: $udom,$uname);
1.153 matthew 14856: if ($put_result !~ /^(ok|delayed)/) {
14857: &Apache::lonnet::logthis('unable to save form parameters, '.
14858: 'got error:'.$put_result);
14859: }
14860: # Make sure these settings stick around in this session, too
1.646 raeburn 14861: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14862: return;
14863: }
14864:
14865: sub restore_course_settings {
1.499 albertel 14866: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14867: }
14868:
14869: sub restore_settings {
14870: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14871: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14872: next if (exists($env{'form.'.$setting}));
1.496 albertel 14873: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14874: '.'.$setting;
1.258 albertel 14875: if (exists($env{$envname})) {
1.153 matthew 14876: if ($type eq 'scalar') {
1.258 albertel 14877: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14878: } elsif ($type eq 'array') {
1.258 albertel 14879: $env{'form.'.$setting} = [
1.153 matthew 14880: map {
1.369 www 14881: &unescape($_);
1.258 albertel 14882: } split(',',$env{$envname})
1.153 matthew 14883: ];
14884: }
14885: }
14886: }
1.127 matthew 14887: }
14888:
1.618 raeburn 14889: #######################################################
14890: #######################################################
14891:
14892: =pod
14893:
14894: =head1 Domain E-mail Routines
14895:
14896: =over 4
14897:
1.648 raeburn 14898: =item * &build_recipient_list()
1.618 raeburn 14899:
1.1144 raeburn 14900: Build recipient lists for following types of e-mail:
1.766 raeburn 14901: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 14902: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14903: module change checking, student/employee ID conflict checks, as
14904: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14905: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14906:
14907: Inputs:
1.619 raeburn 14908: defmail (scalar - email address of default recipient),
1.1144 raeburn 14909: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14910: requestsmail, updatesmail, or idconflictsmail).
14911:
1.619 raeburn 14912: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 14913:
1.619 raeburn 14914: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 14915: i.e., predates configuration by DC via domainprefs.pm
14916:
14917: $requname username of requester (if mailing type is helpdeskmail)
14918:
14919: $requdom domain of requester (if mailing type is helpdeskmail)
14920:
14921: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14922:
1.618 raeburn 14923:
1.655 raeburn 14924: Returns: comma separated list of addresses to which to send e-mail.
14925:
14926: =back
1.618 raeburn 14927:
14928: =cut
14929:
14930: ############################################################
14931: ############################################################
14932: sub build_recipient_list {
1.1297 raeburn 14933: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14934: my @recipients;
1.1270 raeburn 14935: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14936: my %domconfig =
1.1270 raeburn 14937: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14938: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14939: if (exists($domconfig{'contacts'}{$mailing})) {
14940: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14941: my @contacts = ('adminemail','supportemail');
14942: foreach my $item (@contacts) {
14943: if ($domconfig{'contacts'}{$mailing}{$item}) {
14944: my $addr = $domconfig{'contacts'}{$item};
14945: if (!grep(/^\Q$addr\E$/,@recipients)) {
14946: push(@recipients,$addr);
14947: }
1.619 raeburn 14948: }
1.1270 raeburn 14949: }
14950: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14951: if ($mailing eq 'helpdeskmail') {
14952: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14953: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14954: my @ok_bccs;
14955: foreach my $bcc (@bccs) {
14956: $bcc =~ s/^\s+//g;
14957: $bcc =~ s/\s+$//g;
14958: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14959: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14960: push(@ok_bccs,$bcc);
14961: }
14962: }
14963: }
14964: if (@ok_bccs > 0) {
14965: $allbcc = join(', ',@ok_bccs);
14966: }
14967: }
14968: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14969: }
14970: }
1.766 raeburn 14971: } elsif ($origmail ne '') {
1.1270 raeburn 14972: $lastresort = $origmail;
1.618 raeburn 14973: }
1.1297 raeburn 14974: if ($mailing eq 'helpdeskmail') {
14975: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14976: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14977: my ($inststatus,$inststatus_checked);
14978: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14979: ($env{'user.domain'} ne 'public')) {
14980: $inststatus_checked = 1;
14981: $inststatus = $env{'environment.inststatus'};
14982: }
14983: unless ($inststatus_checked) {
14984: if (($requname ne '') && ($requdom ne '')) {
14985: if (($requname =~ /^$match_username$/) &&
14986: ($requdom =~ /^$match_domain$/) &&
14987: (&Apache::lonnet::domain($requdom))) {
14988: my $requhome = &Apache::lonnet::homeserver($requname,
14989: $requdom);
14990: unless ($requhome eq 'no_host') {
14991: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14992: $inststatus = $userenv{'inststatus'};
14993: $inststatus_checked = 1;
14994: }
14995: }
14996: }
14997: }
14998: unless ($inststatus_checked) {
14999: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15000: my %srch = (srchby => 'email',
15001: srchdomain => $defdom,
15002: srchterm => $reqemail,
15003: srchtype => 'exact');
15004: my %srch_results = &Apache::lonnet::usersearch(\%srch);
15005: foreach my $uname (keys(%srch_results)) {
15006: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15007: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15008: $inststatus_checked = 1;
15009: last;
15010: }
15011: }
15012: unless ($inststatus_checked) {
15013: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15014: if ($dirsrchres eq 'ok') {
15015: foreach my $uname (keys(%srch_results)) {
15016: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15017: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15018: $inststatus_checked = 1;
15019: last;
15020: }
15021: }
15022: }
15023: }
15024: }
15025: }
15026: if ($inststatus ne '') {
15027: foreach my $status (split(/\:/,$inststatus)) {
15028: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15029: my @contacts = ('adminemail','supportemail');
15030: foreach my $item (@contacts) {
15031: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15032: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15033: if (!grep(/^\Q$addr\E$/,@recipients)) {
15034: push(@recipients,$addr);
15035: }
15036: }
15037: }
15038: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15039: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15040: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15041: my @ok_bccs;
15042: foreach my $bcc (@bccs) {
15043: $bcc =~ s/^\s+//g;
15044: $bcc =~ s/\s+$//g;
15045: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15046: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15047: push(@ok_bccs,$bcc);
15048: }
15049: }
15050: }
15051: if (@ok_bccs > 0) {
15052: $allbcc = join(', ',@ok_bccs);
15053: }
15054: }
15055: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15056: last;
15057: }
15058: }
15059: }
15060: }
15061: }
1.619 raeburn 15062: } elsif ($origmail ne '') {
1.1270 raeburn 15063: $lastresort = $origmail;
15064: }
1.1297 raeburn 15065: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 15066: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15067: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15068: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15069: my %what = (
15070: perlvar => 1,
15071: );
15072: my $primary = &Apache::lonnet::domain($defdom,'primary');
15073: if ($primary) {
15074: my $gotaddr;
15075: my ($result,$returnhash) =
15076: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15077: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15078: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15079: $lastresort = $returnhash->{'lonSupportEMail'};
15080: $gotaddr = 1;
15081: }
15082: }
15083: unless ($gotaddr) {
15084: my $uintdom = &Apache::lonnet::internet_dom($primary);
15085: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15086: unless ($uintdom eq $intdom) {
15087: my %domconfig =
15088: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15089: if (ref($domconfig{'contacts'}) eq 'HASH') {
15090: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15091: my @contacts = ('adminemail','supportemail');
15092: foreach my $item (@contacts) {
15093: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15094: my $addr = $domconfig{'contacts'}{$item};
15095: if (!grep(/^\Q$addr\E$/,@recipients)) {
15096: push(@recipients,$addr);
15097: }
15098: }
15099: }
15100: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15101: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15102: }
15103: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15104: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15105: my @ok_bccs;
15106: foreach my $bcc (@bccs) {
15107: $bcc =~ s/^\s+//g;
15108: $bcc =~ s/\s+$//g;
15109: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15110: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15111: push(@ok_bccs,$bcc);
15112: }
15113: }
15114: }
15115: if (@ok_bccs > 0) {
15116: $allbcc = join(', ',@ok_bccs);
15117: }
15118: }
15119: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15120: }
15121: }
15122: }
15123: }
15124: }
15125: }
1.618 raeburn 15126: }
1.688 raeburn 15127: if (defined($defmail)) {
15128: if ($defmail ne '') {
15129: push(@recipients,$defmail);
15130: }
1.618 raeburn 15131: }
15132: if ($otheremails) {
1.619 raeburn 15133: my @others;
15134: if ($otheremails =~ /,/) {
15135: @others = split(/,/,$otheremails);
1.618 raeburn 15136: } else {
1.619 raeburn 15137: push(@others,$otheremails);
15138: }
15139: foreach my $addr (@others) {
15140: if (!grep(/^\Q$addr\E$/,@recipients)) {
15141: push(@recipients,$addr);
15142: }
1.618 raeburn 15143: }
15144: }
1.1298 raeburn 15145: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 15146: if ((!@recipients) && ($lastresort ne '')) {
15147: push(@recipients,$lastresort);
15148: }
15149: } elsif ($lastresort ne '') {
15150: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15151: push(@recipients,$lastresort);
15152: }
15153: }
1.1271 raeburn 15154: my $recipientlist = join(',',@recipients);
1.1270 raeburn 15155: if (wantarray) {
15156: return ($recipientlist,$allbcc,$addtext);
15157: } else {
15158: return $recipientlist;
15159: }
1.618 raeburn 15160: }
15161:
1.127 matthew 15162: ############################################################
15163: ############################################################
1.154 albertel 15164:
1.655 raeburn 15165: =pod
15166:
1.1224 musolffc 15167: =over 4
15168:
1.1223 musolffc 15169: =item * &mime_email()
15170:
15171: Sends an email with a possible attachment
15172:
15173: Inputs:
15174:
15175: =over 4
15176:
15177: from - Sender's email address
15178:
15179: to - Email address of recipient
15180:
15181: subject - Subject of email
15182:
15183: body - Body of email
15184:
15185: cc_string - Carbon copy email address
15186:
15187: bcc - Blind carbon copy email address
15188:
15189: type - File type of attachment
15190:
15191: attachment_path - Path of file to be attached
15192:
15193: file_name - Name of file to be attached
15194:
15195: attachment_text - The body of an attachment of type "TEXT"
15196:
15197: =back
15198:
15199: =back
15200:
15201: =cut
15202:
15203: ############################################################
15204: ############################################################
15205:
15206: sub mime_email {
15207: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
15208: $file_name, $attachment_text) = @_;
15209: my $msg = MIME::Lite->new(
15210: From => $from,
15211: To => $to,
15212: Subject => $subject,
15213: Type =>'TEXT',
15214: Data => $body,
15215: );
15216: if ($cc_string ne '') {
15217: $msg->add("Cc" => $cc_string);
15218: }
15219: if ($bcc ne '') {
15220: $msg->add("Bcc" => $bcc);
15221: }
15222: $msg->attr("content-type" => "text/plain");
15223: $msg->attr("content-type.charset" => "UTF-8");
15224: # Attach file if given
15225: if ($attachment_path) {
15226: unless ($file_name) {
15227: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
15228: }
15229: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
15230: $msg->attach(Type => $type,
15231: Path => $attachment_path,
15232: Filename => $file_name
15233: );
15234: # Otherwise attach text if given
15235: } elsif ($attachment_text) {
15236: $msg->attach(Type => 'TEXT',
15237: Data => $attachment_text);
15238: }
15239: # Send it
15240: $msg->send('sendmail');
15241: }
15242:
15243: ############################################################
15244: ############################################################
15245:
15246: =pod
15247:
1.655 raeburn 15248: =head1 Course Catalog Routines
15249:
15250: =over 4
15251:
15252: =item * &gather_categories()
15253:
15254: Converts category definitions - keys of categories hash stored in
15255: coursecategories in configuration.db on the primary library server in a
15256: domain - to an array. Also generates javascript and idx hash used to
15257: generate Domain Coordinator interface for editing Course Categories.
15258:
15259: Inputs:
1.663 raeburn 15260:
1.655 raeburn 15261: categories (reference to hash of category definitions).
1.663 raeburn 15262:
1.655 raeburn 15263: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15264: categories and subcategories).
1.663 raeburn 15265:
1.655 raeburn 15266: idx (reference to hash of counters used in Domain Coordinator interface for
15267: editing Course Categories).
1.663 raeburn 15268:
1.655 raeburn 15269: jsarray (reference to array of categories used to create Javascript arrays for
15270: Domain Coordinator interface for editing Course Categories).
15271:
15272: Returns: nothing
15273:
15274: Side effects: populates cats, idx and jsarray.
15275:
15276: =cut
15277:
15278: sub gather_categories {
15279: my ($categories,$cats,$idx,$jsarray) = @_;
15280: my %counters;
15281: my $num = 0;
15282: foreach my $item (keys(%{$categories})) {
15283: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15284: if ($container eq '' && $depth == 0) {
15285: $cats->[$depth][$categories->{$item}] = $cat;
15286: } else {
15287: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15288: }
15289: my ($escitem,$tail) = split(/:/,$item,2);
15290: if ($counters{$tail} eq '') {
15291: $counters{$tail} = $num;
15292: $num ++;
15293: }
15294: if (ref($idx) eq 'HASH') {
15295: $idx->{$item} = $counters{$tail};
15296: }
15297: if (ref($jsarray) eq 'ARRAY') {
15298: push(@{$jsarray->[$counters{$tail}]},$item);
15299: }
15300: }
15301: return;
15302: }
15303:
15304: =pod
15305:
15306: =item * &extract_categories()
15307:
15308: Used to generate breadcrumb trails for course categories.
15309:
15310: Inputs:
1.663 raeburn 15311:
1.655 raeburn 15312: categories (reference to hash of category definitions).
1.663 raeburn 15313:
1.655 raeburn 15314: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15315: categories and subcategories).
1.663 raeburn 15316:
1.655 raeburn 15317: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15318:
1.655 raeburn 15319: allitems (reference to hash - key is category key
15320: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15321:
1.655 raeburn 15322: idx (reference to hash of counters used in Domain Coordinator interface for
15323: editing Course Categories).
1.663 raeburn 15324:
1.655 raeburn 15325: jsarray (reference to array of categories used to create Javascript arrays for
15326: Domain Coordinator interface for editing Course Categories).
15327:
1.665 raeburn 15328: subcats (reference to hash of arrays containing all subcategories within each
15329: category, -recursive)
15330:
1.1321 raeburn 15331: maxd (reference to hash used to hold max depth for all top-level categories).
15332:
1.655 raeburn 15333: Returns: nothing
15334:
15335: Side effects: populates trails and allitems hash references.
15336:
15337: =cut
15338:
15339: sub extract_categories {
1.1321 raeburn 15340: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 15341: if (ref($categories) eq 'HASH') {
15342: &gather_categories($categories,$cats,$idx,$jsarray);
15343: if (ref($cats->[0]) eq 'ARRAY') {
15344: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15345: my $name = $cats->[0][$i];
15346: my $item = &escape($name).'::0';
15347: my $trailstr;
15348: if ($name eq 'instcode') {
15349: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15350: } elsif ($name eq 'communities') {
15351: $trailstr = &mt('Communities');
1.1239 raeburn 15352: } elsif ($name eq 'placement') {
15353: $trailstr = &mt('Placement Tests');
1.655 raeburn 15354: } else {
15355: $trailstr = $name;
15356: }
15357: if ($allitems->{$item} eq '') {
15358: push(@{$trails},$trailstr);
15359: $allitems->{$item} = scalar(@{$trails})-1;
15360: }
15361: my @parents = ($name);
15362: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15363: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15364: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15365: if (ref($subcats) eq 'HASH') {
15366: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15367: }
1.1321 raeburn 15368: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 15369: }
15370: } else {
15371: if (ref($subcats) eq 'HASH') {
15372: $subcats->{$item} = [];
1.655 raeburn 15373: }
1.1321 raeburn 15374: if (ref($maxd) eq 'HASH') {
15375: $maxd->{$name} = 1;
15376: }
1.655 raeburn 15377: }
15378: }
15379: }
15380: }
15381: return;
15382: }
15383:
15384: =pod
15385:
1.1162 raeburn 15386: =item * &recurse_categories()
1.655 raeburn 15387:
15388: Recursively used to generate breadcrumb trails for course categories.
15389:
15390: Inputs:
1.663 raeburn 15391:
1.655 raeburn 15392: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15393: categories and subcategories).
1.663 raeburn 15394:
1.655 raeburn 15395: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15396:
15397: category (current course category, for which breadcrumb trail is being generated).
15398:
15399: trails (reference to array of breadcrumb trails for each category).
15400:
1.655 raeburn 15401: allitems (reference to hash - key is category key
15402: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15403:
1.655 raeburn 15404: parents (array containing containers directories for current category,
15405: back to top level).
15406:
15407: Returns: nothing
15408:
15409: Side effects: populates trails and allitems hash references
15410:
15411: =cut
15412:
15413: sub recurse_categories {
1.1321 raeburn 15414: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 15415: my $shallower = $depth - 1;
15416: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
15417: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
15418: my $name = $cats->[$depth]{$category}[$k];
15419: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15420: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15421: if ($allitems->{$item} eq '') {
15422: push(@{$trails},$trailstr);
15423: $allitems->{$item} = scalar(@{$trails})-1;
15424: }
15425: my $deeper = $depth+1;
15426: push(@{$parents},$category);
1.665 raeburn 15427: if (ref($subcats) eq 'HASH') {
15428: my $subcat = &escape($name).':'.$category.':'.$depth;
15429: for (my $j=@{$parents}; $j>=0; $j--) {
15430: my $higher;
15431: if ($j > 0) {
15432: $higher = &escape($parents->[$j]).':'.
15433: &escape($parents->[$j-1]).':'.$j;
15434: } else {
15435: $higher = &escape($parents->[$j]).'::'.$j;
15436: }
15437: push(@{$subcats->{$higher}},$subcat);
15438: }
15439: }
15440: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 15441: $subcats,$maxd);
1.655 raeburn 15442: pop(@{$parents});
15443: }
15444: } else {
15445: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15446: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15447: if ($allitems->{$item} eq '') {
15448: push(@{$trails},$trailstr);
15449: $allitems->{$item} = scalar(@{$trails})-1;
15450: }
1.1321 raeburn 15451: if (ref($maxd) eq 'HASH') {
15452: if ($depth > $maxd->{$parents->[0]}) {
15453: $maxd->{$parents->[0]} = $depth;
15454: }
15455: }
1.655 raeburn 15456: }
15457: return;
15458: }
15459:
1.663 raeburn 15460: =pod
15461:
1.1162 raeburn 15462: =item * &assign_categories_table()
1.663 raeburn 15463:
15464: Create a datatable for display of hierarchical categories in a domain,
15465: with checkboxes to allow a course to be categorized.
15466:
15467: Inputs:
15468:
15469: cathash - reference to hash of categories defined for the domain (from
15470: configuration.db)
15471:
15472: currcat - scalar with an & separated list of categories assigned to a course.
15473:
1.919 raeburn 15474: type - scalar contains course type (Course or Community).
15475:
1.1260 raeburn 15476: disabled - scalar (optional) contains disabled="disabled" if input elements are
15477: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15478:
1.663 raeburn 15479: Returns: $output (markup to be displayed)
15480:
15481: =cut
15482:
15483: sub assign_categories_table {
1.1259 raeburn 15484: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15485: my $output;
15486: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 15487: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
15488: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 15489: $maxdepth = scalar(@cats);
15490: if (@cats > 0) {
15491: my $itemcount = 0;
15492: if (ref($cats[0]) eq 'ARRAY') {
15493: my @currcategories;
15494: if ($currcat ne '') {
15495: @currcategories = split('&',$currcat);
15496: }
1.919 raeburn 15497: my $table;
1.663 raeburn 15498: for (my $i=0; $i<@{$cats[0]}; $i++) {
15499: my $parent = $cats[0][$i];
1.919 raeburn 15500: next if ($parent eq 'instcode');
15501: if ($type eq 'Community') {
15502: next unless ($parent eq 'communities');
1.1239 raeburn 15503: } elsif ($type eq 'Placement') {
15504: next unless ($parent eq 'placement');
1.919 raeburn 15505: } else {
1.1239 raeburn 15506: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 15507: }
1.663 raeburn 15508: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15509: my $item = &escape($parent).'::0';
15510: my $checked = '';
15511: if (@currcategories > 0) {
15512: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15513: $checked = ' checked="checked"';
1.663 raeburn 15514: }
15515: }
1.919 raeburn 15516: my $parent_title = $parent;
15517: if ($parent eq 'communities') {
15518: $parent_title = &mt('Communities');
1.1239 raeburn 15519: } elsif ($parent eq 'placement') {
15520: $parent_title = &mt('Placement Tests');
1.919 raeburn 15521: }
15522: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15523: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15524: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15525: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15526: my $depth = 1;
15527: push(@path,$parent);
1.1259 raeburn 15528: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15529: pop(@path);
1.919 raeburn 15530: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15531: $itemcount ++;
15532: }
1.919 raeburn 15533: if ($itemcount) {
15534: $output = &Apache::loncommon::start_data_table().
15535: $table.
15536: &Apache::loncommon::end_data_table();
15537: }
1.663 raeburn 15538: }
15539: }
15540: }
15541: return $output;
15542: }
15543:
15544: =pod
15545:
1.1162 raeburn 15546: =item * &assign_category_rows()
1.663 raeburn 15547:
15548: Create a datatable row for display of nested categories in a domain,
15549: with checkboxes to allow a course to be categorized,called recursively.
15550:
15551: Inputs:
15552:
15553: itemcount - track row number for alternating colors
15554:
15555: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15556: categories and subcategories.
15557:
15558: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15559:
15560: parent - parent of current category item
15561:
15562: path - Array containing all categories back up through the hierarchy from the
15563: current category to the top level.
15564:
15565: currcategories - reference to array of current categories assigned to the course
15566:
1.1260 raeburn 15567: disabled - scalar (optional) contains disabled="disabled" if input elements are
15568: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15569:
1.663 raeburn 15570: Returns: $output (markup to be displayed).
15571:
15572: =cut
15573:
15574: sub assign_category_rows {
1.1259 raeburn 15575: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15576: my ($text,$name,$item,$chgstr);
15577: if (ref($cats) eq 'ARRAY') {
15578: my $maxdepth = scalar(@{$cats});
15579: if (ref($cats->[$depth]) eq 'HASH') {
15580: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15581: my $numchildren = @{$cats->[$depth]{$parent}};
15582: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 15583: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15584: for (my $j=0; $j<$numchildren; $j++) {
15585: $name = $cats->[$depth]{$parent}[$j];
15586: $item = &escape($name).':'.&escape($parent).':'.$depth;
15587: my $deeper = $depth+1;
15588: my $checked = '';
15589: if (ref($currcategories) eq 'ARRAY') {
15590: if (@{$currcategories} > 0) {
15591: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15592: $checked = ' checked="checked"';
1.663 raeburn 15593: }
15594: }
15595: }
1.664 raeburn 15596: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15597: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15598: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15599: '<input type="hidden" name="catname" value="'.$name.'" />'.
15600: '</td><td>';
1.663 raeburn 15601: if (ref($path) eq 'ARRAY') {
15602: push(@{$path},$name);
1.1259 raeburn 15603: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15604: pop(@{$path});
15605: }
15606: $text .= '</td></tr>';
15607: }
15608: $text .= '</table></td>';
15609: }
15610: }
15611: }
15612: return $text;
15613: }
15614:
1.1181 raeburn 15615: =pod
15616:
15617: =back
15618:
15619: =cut
15620:
1.655 raeburn 15621: ############################################################
15622: ############################################################
15623:
15624:
1.443 albertel 15625: sub commit_customrole {
1.664 raeburn 15626: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15627: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15628: ($start?', '.&mt('starting').' '.localtime($start):'').
15629: ($end?', ending '.localtime($end):'').': <b>'.
15630: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15631: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15632: '</b><br />';
15633: return $output;
15634: }
15635:
15636: sub commit_standardrole {
1.1116 raeburn 15637: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15638: my ($output,$logmsg,$linefeed);
15639: if ($context eq 'auto') {
15640: $linefeed = "\n";
15641: } else {
15642: $linefeed = "<br />\n";
15643: }
1.443 albertel 15644: if ($three eq 'st') {
1.541 raeburn 15645: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 15646: $one,$two,$sec,$context,$credits);
1.541 raeburn 15647: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15648: ($result eq 'unknown_course') || ($result eq 'refused')) {
15649: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15650: } else {
1.541 raeburn 15651: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15652: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15653: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15654: if ($context eq 'auto') {
15655: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15656: } else {
15657: $output .= '<b>'.$result.'</b>'.$linefeed.
15658: &mt('Add to classlist').': <b>ok</b>';
15659: }
15660: $output .= $linefeed;
1.443 albertel 15661: }
15662: } else {
15663: $output = &mt('Assigning').' '.$three.' in '.$url.
15664: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15665: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15666: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15667: if ($context eq 'auto') {
15668: $output .= $result.$linefeed;
15669: } else {
15670: $output .= '<b>'.$result.'</b>'.$linefeed;
15671: }
1.443 albertel 15672: }
15673: return $output;
15674: }
15675:
15676: sub commit_studentrole {
1.1116 raeburn 15677: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15678: $credits) = @_;
1.626 raeburn 15679: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15680: if ($context eq 'auto') {
15681: $linefeed = "\n";
15682: } else {
15683: $linefeed = '<br />'."\n";
15684: }
1.443 albertel 15685: if (defined($one) && defined($two)) {
15686: my $cid=$one.'_'.$two;
15687: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15688: my $secchange = 0;
15689: my $expire_role_result;
15690: my $modify_section_result;
1.628 raeburn 15691: if ($oldsec ne '-1') {
15692: if ($oldsec ne $sec) {
1.443 albertel 15693: $secchange = 1;
1.628 raeburn 15694: my $now = time;
1.443 albertel 15695: my $uurl='/'.$cid;
15696: $uurl=~s/\_/\//g;
15697: if ($oldsec) {
15698: $uurl.='/'.$oldsec;
15699: }
1.626 raeburn 15700: $oldsecurl = $uurl;
1.628 raeburn 15701: $expire_role_result =
1.652 raeburn 15702: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15703: if ($env{'request.course.sec'} ne '') {
15704: if ($expire_role_result eq 'refused') {
15705: my @roles = ('st');
15706: my @statuses = ('previous');
15707: my @roledoms = ($one);
15708: my $withsec = 1;
15709: my %roleshash =
15710: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15711: \@statuses,\@roles,\@roledoms,$withsec);
15712: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15713: my ($oldstart,$oldend) =
15714: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15715: if ($oldend > 0 && $oldend <= $now) {
15716: $expire_role_result = 'ok';
15717: }
15718: }
15719: }
15720: }
1.443 albertel 15721: $result = $expire_role_result;
15722: }
15723: }
15724: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 15725: $modify_section_result =
15726: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15727: undef,undef,undef,$sec,
15728: $end,$start,'','',$cid,
15729: '',$context,$credits);
1.443 albertel 15730: if ($modify_section_result =~ /^ok/) {
15731: if ($secchange == 1) {
1.628 raeburn 15732: if ($sec eq '') {
15733: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15734: } else {
15735: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15736: }
1.443 albertel 15737: } elsif ($oldsec eq '-1') {
1.628 raeburn 15738: if ($sec eq '') {
15739: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15740: } else {
15741: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15742: }
1.443 albertel 15743: } else {
1.628 raeburn 15744: if ($sec eq '') {
15745: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15746: } else {
15747: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15748: }
1.443 albertel 15749: }
15750: } else {
1.1115 raeburn 15751: if ($secchange) {
1.628 raeburn 15752: $$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;
15753: } else {
15754: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15755: }
1.443 albertel 15756: }
15757: $result = $modify_section_result;
15758: } elsif ($secchange == 1) {
1.628 raeburn 15759: if ($oldsec eq '') {
1.1103 raeburn 15760: $$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 15761: } else {
15762: $$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;
15763: }
1.626 raeburn 15764: if ($expire_role_result eq 'refused') {
15765: my $newsecurl = '/'.$cid;
15766: $newsecurl =~ s/\_/\//g;
15767: if ($sec ne '') {
15768: $newsecurl.='/'.$sec;
15769: }
15770: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15771: if ($sec eq '') {
15772: $$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;
15773: } else {
15774: $$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;
15775: }
15776: }
15777: }
1.443 albertel 15778: }
15779: } else {
1.626 raeburn 15780: $$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 15781: $result = "error: incomplete course id\n";
15782: }
15783: return $result;
15784: }
15785:
1.1108 raeburn 15786: sub show_role_extent {
15787: my ($scope,$context,$role) = @_;
15788: $scope =~ s{^/}{};
15789: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15790: push(@courseroles,'co');
15791: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15792: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15793: $scope =~ s{/}{_};
15794: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15795: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15796: my ($audom,$auname) = split(/\//,$scope);
15797: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15798: &Apache::loncommon::plainname($auname,$audom).'</span>');
15799: } else {
15800: $scope =~ s{/$}{};
15801: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15802: &Apache::lonnet::domain($scope,'description').'</span>');
15803: }
15804: }
15805:
1.443 albertel 15806: ############################################################
15807: ############################################################
15808:
1.566 albertel 15809: sub check_clone {
1.578 raeburn 15810: my ($args,$linefeed) = @_;
1.566 albertel 15811: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15812: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15813: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15814: my $clonemsg;
15815: my $can_clone = 0;
1.944 raeburn 15816: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15817: if ($lctype ne 'community') {
15818: $lctype = 'course';
15819: }
1.566 albertel 15820: if ($clonehome eq 'no_host') {
1.944 raeburn 15821: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15822: $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
15823: } else {
15824: $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'});
15825: }
1.566 albertel 15826: } else {
15827: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15828: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15829: if ($clonedesc{'type'} ne 'Community') {
1.1262 raeburn 15830: $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 15831: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15832: }
15833: }
1.1262 raeburn 15834: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15835: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15836: $can_clone = 1;
15837: } else {
1.1221 raeburn 15838: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15839: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 15840: if ($clonehash{'cloners'} eq '') {
15841: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15842: if ($domdefs{'canclone'}) {
15843: unless ($domdefs{'canclone'} eq 'none') {
15844: if ($domdefs{'canclone'} eq 'domain') {
15845: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15846: $can_clone = 1;
15847: }
15848: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15849: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15850: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15851: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15852: $can_clone = 1;
15853: }
15854: }
15855: }
15856: }
1.578 raeburn 15857: } else {
1.1221 raeburn 15858: my @cloners = split(/,/,$clonehash{'cloners'});
15859: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15860: $can_clone = 1;
1.1221 raeburn 15861: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15862: $can_clone = 1;
1.1225 raeburn 15863: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15864: $can_clone = 1;
1.1221 raeburn 15865: }
15866: unless ($can_clone) {
1.1225 raeburn 15867: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15868: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 15869: my (%gotdomdefaults,%gotcodedefaults);
15870: foreach my $cloner (@cloners) {
15871: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15872: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15873: my (%codedefaults,@code_order);
15874: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15875: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15876: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15877: }
15878: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15879: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15880: }
15881: } else {
15882: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15883: \%codedefaults,
15884: \@code_order);
15885: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15886: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15887: }
15888: if (@code_order > 0) {
15889: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15890: $cloner,$clonehash{'internal.coursecode'},
15891: $args->{'crscode'})) {
15892: $can_clone = 1;
15893: last;
15894: }
15895: }
15896: }
15897: }
15898: }
1.1225 raeburn 15899: }
15900: }
15901: unless ($can_clone) {
15902: my $ccrole = 'cc';
15903: if ($args->{'crstype'} eq 'Community') {
15904: $ccrole = 'co';
15905: }
15906: my %roleshash =
15907: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15908: $args->{'ccdomain'},
15909: 'userroles',['active'],[$ccrole],
15910: [$args->{'clonedomain'}]);
15911: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15912: $can_clone = 1;
15913: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15914: $args->{'ccuname'},$args->{'ccdomain'})) {
15915: $can_clone = 1;
1.1221 raeburn 15916: }
15917: }
15918: unless ($can_clone) {
15919: if ($args->{'crstype'} eq 'Community') {
15920: $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 15921: } else {
1.1221 raeburn 15922: $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'});
15923: }
1.566 albertel 15924: }
1.578 raeburn 15925: }
1.566 albertel 15926: }
15927: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15928: }
15929:
1.444 albertel 15930: sub construct_course {
1.1262 raeburn 15931: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15932: $cnum,$category,$coderef) = @_;
1.444 albertel 15933: my $outcome;
1.541 raeburn 15934: my $linefeed = '<br />'."\n";
15935: if ($context eq 'auto') {
15936: $linefeed = "\n";
15937: }
1.566 albertel 15938:
15939: #
15940: # Are we cloning?
15941: #
15942: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15943: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15944: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15945: if ($context ne 'auto') {
1.578 raeburn 15946: if ($clonemsg ne '') {
15947: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15948: }
1.566 albertel 15949: }
15950: $outcome .= $clonemsg.$linefeed;
15951:
15952: if (!$can_clone) {
15953: return (0,$outcome);
15954: }
15955: }
15956:
1.444 albertel 15957: #
15958: # Open course
15959: #
1.1239 raeburn 15960: my $showncrstype;
15961: if ($args->{'crstype'} eq 'Placement') {
15962: $showncrstype = 'placement test';
15963: } else {
15964: $showncrstype = lc($args->{'crstype'});
15965: }
1.444 albertel 15966: my %cenv=();
15967: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15968: $args->{'cdescr'},
15969: $args->{'curl'},
15970: $args->{'course_home'},
15971: $args->{'nonstandard'},
15972: $args->{'crscode'},
15973: $args->{'ccuname'}.':'.
15974: $args->{'ccdomain'},
1.882 raeburn 15975: $args->{'crstype'},
1.885 raeburn 15976: $cnum,$context,$category);
1.444 albertel 15977:
15978: # Note: The testing routines depend on this being output; see
15979: # Utils::Course. This needs to at least be output as a comment
15980: # if anyone ever decides to not show this, and Utils::Course::new
15981: # will need to be suitably modified.
1.1239 raeburn 15982: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
1.943 raeburn 15983: if ($$courseid =~ /^error:/) {
15984: return (0,$outcome);
15985: }
15986:
1.444 albertel 15987: #
15988: # Check if created correctly
15989: #
1.479 albertel 15990: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15991: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15992: if ($crsuhome eq 'no_host') {
15993: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15994: return (0,$outcome);
15995: }
1.541 raeburn 15996: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15997:
1.444 albertel 15998: #
1.566 albertel 15999: # Do the cloning
16000: #
16001: if ($can_clone && $cloneid) {
1.1239 raeburn 16002: $clonemsg = &mt('Cloning [_1] from [_2]',$showncrstype,$clonehome);
1.566 albertel 16003: if ($context ne 'auto') {
16004: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
16005: }
16006: $outcome .= $clonemsg.$linefeed;
16007: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 16008: # Copy all files
1.637 www 16009: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 16010: # Restore URL
1.566 albertel 16011: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16012: # Restore title
1.566 albertel 16013: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16014: # Restore creation date, creator and creation context.
16015: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16016: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16017: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16018: # Mark as cloned
1.566 albertel 16019: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16020: # Need to clone grading mode
16021: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16022: $cenv{'grading'}=$newenv{'grading'};
16023: # Do not clone these environment entries
16024: &Apache::lonnet::del('environment',
16025: ['default_enrollment_start_date',
16026: 'default_enrollment_end_date',
16027: 'question.email',
16028: 'policy.email',
16029: 'comment.email',
16030: 'pch.users.denied',
1.725 raeburn 16031: 'plc.users.denied',
16032: 'hidefromcat',
1.1121 raeburn 16033: 'checkforpriv',
1.1166 raeburn 16034: 'categories',
16035: 'internal.uniquecode'],
1.638 www 16036: $$crsudom,$$crsunum);
1.1170 raeburn 16037: if ($args->{'textbook'}) {
16038: $cenv{'internal.textbook'} = $args->{'textbook'};
16039: }
1.444 albertel 16040: }
1.566 albertel 16041:
1.444 albertel 16042: #
16043: # Set environment (will override cloned, if existing)
16044: #
16045: my @sections = ();
16046: my @xlists = ();
16047: if ($args->{'crstype'}) {
16048: $cenv{'type'}=$args->{'crstype'};
16049: }
16050: if ($args->{'crsid'}) {
16051: $cenv{'courseid'}=$args->{'crsid'};
16052: }
16053: if ($args->{'crscode'}) {
16054: $cenv{'internal.coursecode'}=$args->{'crscode'};
16055: }
16056: if ($args->{'crsquota'} ne '') {
16057: $cenv{'internal.coursequota'}=$args->{'crsquota'};
16058: } else {
16059: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
16060: }
16061: if ($args->{'ccuname'}) {
16062: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
16063: ':'.$args->{'ccdomain'};
16064: } else {
16065: $cenv{'internal.courseowner'} = $args->{'curruser'};
16066: }
1.1116 raeburn 16067: if ($args->{'defaultcredits'}) {
16068: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
16069: }
1.444 albertel 16070: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
16071: if ($args->{'crssections'}) {
16072: $cenv{'internal.sectionnums'} = '';
16073: if ($args->{'crssections'} =~ m/,/) {
16074: @sections = split/,/,$args->{'crssections'};
16075: } else {
16076: $sections[0] = $args->{'crssections'};
16077: }
16078: if (@sections > 0) {
16079: foreach my $item (@sections) {
16080: my ($sec,$gp) = split/:/,$item;
16081: my $class = $args->{'crscode'}.$sec;
16082: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16083: $cenv{'internal.sectionnums'} .= $item.',';
16084: unless ($addcheck eq 'ok') {
1.1263 raeburn 16085: push(@badclasses,$class);
1.444 albertel 16086: }
16087: }
16088: $cenv{'internal.sectionnums'} =~ s/,$//;
16089: }
16090: }
16091: # do not hide course coordinator from staff listing,
16092: # even if privileged
16093: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 16094: # add course coordinator's domain to domains to check for privileged users
16095: # if different to course domain
16096: if ($$crsudom ne $args->{'ccdomain'}) {
16097: $cenv{'checkforpriv'} = $args->{'ccdomain'};
16098: }
1.444 albertel 16099: # add crosslistings
16100: if ($args->{'crsxlist'}) {
16101: $cenv{'internal.crosslistings'}='';
16102: if ($args->{'crsxlist'} =~ m/,/) {
16103: @xlists = split/,/,$args->{'crsxlist'};
16104: } else {
16105: $xlists[0] = $args->{'crsxlist'};
16106: }
16107: if (@xlists > 0) {
16108: foreach my $item (@xlists) {
16109: my ($xl,$gp) = split/:/,$item;
16110: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
16111: $cenv{'internal.crosslistings'} .= $item.',';
16112: unless ($addcheck eq 'ok') {
1.1263 raeburn 16113: push(@badclasses,$xl);
1.444 albertel 16114: }
16115: }
16116: $cenv{'internal.crosslistings'} =~ s/,$//;
16117: }
16118: }
16119: if ($args->{'autoadds'}) {
16120: $cenv{'internal.autoadds'}=$args->{'autoadds'};
16121: }
16122: if ($args->{'autodrops'}) {
16123: $cenv{'internal.autodrops'}=$args->{'autodrops'};
16124: }
16125: # check for notification of enrollment changes
16126: my @notified = ();
16127: if ($args->{'notify_owner'}) {
16128: if ($args->{'ccuname'} ne '') {
16129: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
16130: }
16131: }
16132: if ($args->{'notify_dc'}) {
16133: if ($uname ne '') {
1.630 raeburn 16134: push(@notified,$uname.':'.$udom);
1.444 albertel 16135: }
16136: }
16137: if (@notified > 0) {
16138: my $notifylist;
16139: if (@notified > 1) {
16140: $notifylist = join(',',@notified);
16141: } else {
16142: $notifylist = $notified[0];
16143: }
16144: $cenv{'internal.notifylist'} = $notifylist;
16145: }
16146: if (@badclasses > 0) {
16147: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 16148: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16149: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16150: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16151: );
1.1264 raeburn 16152: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16153: &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 16154: if ($context eq 'auto') {
16155: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 16156: } else {
1.566 albertel 16157: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 16158: }
16159: foreach my $item (@badclasses) {
1.541 raeburn 16160: if ($context eq 'auto') {
1.1261 raeburn 16161: $outcome .= " - $item\n";
1.541 raeburn 16162: } else {
1.1261 raeburn 16163: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16164: }
1.1261 raeburn 16165: }
16166: if ($context eq 'auto') {
16167: $outcome .= $linefeed;
16168: } else {
16169: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 16170: }
1.444 albertel 16171: }
16172: if ($args->{'no_end_date'}) {
16173: $args->{'endaccess'} = 0;
16174: }
16175: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16176: $cenv{'internal.autoend'}=$args->{'enrollend'};
16177: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16178: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16179: if ($args->{'showphotos'}) {
16180: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16181: }
16182: $cenv{'internal.authtype'} = $args->{'authtype'};
16183: $cenv{'internal.autharg'} = $args->{'autharg'};
16184: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16185: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16186: 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');
16187: if ($context eq 'auto') {
16188: $outcome .= $krb_msg;
16189: } else {
1.566 albertel 16190: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16191: }
16192: $outcome .= $linefeed;
1.444 albertel 16193: }
16194: }
16195: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16196: if ($args->{'setpolicy'}) {
16197: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16198: }
16199: if ($args->{'setcontent'}) {
16200: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16201: }
1.1251 raeburn 16202: if ($args->{'setcomment'}) {
16203: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16204: }
1.444 albertel 16205: }
16206: if ($args->{'reshome'}) {
16207: $cenv{'reshome'}=$args->{'reshome'}.'/';
16208: $cenv{'reshome'}=~s/\/+$/\//;
16209: }
16210: #
16211: # course has keyed access
16212: #
16213: if ($args->{'setkeys'}) {
16214: $cenv{'keyaccess'}='yes';
16215: }
16216: # if specified, key authority is not course, but user
16217: # only active if keyaccess is yes
16218: if ($args->{'keyauth'}) {
1.487 albertel 16219: my ($user,$domain) = split(':',$args->{'keyauth'});
16220: $user = &LONCAPA::clean_username($user);
16221: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16222: if ($user ne '' && $domain ne '') {
1.487 albertel 16223: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16224: }
16225: }
16226:
1.1166 raeburn 16227: #
1.1167 raeburn 16228: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 16229: #
16230: if ($args->{'uniquecode'}) {
16231: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16232: if ($code) {
16233: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 16234: my %crsinfo =
16235: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16236: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16237: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16238: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16239: }
1.1166 raeburn 16240: if (ref($coderef)) {
16241: $$coderef = $code;
16242: }
16243: }
16244: }
16245:
1.444 albertel 16246: if ($args->{'disresdis'}) {
16247: $cenv{'pch.roles.denied'}='st';
16248: }
16249: if ($args->{'disablechat'}) {
16250: $cenv{'plc.roles.denied'}='st';
16251: }
16252:
16253: # Record we've not yet viewed the Course Initialization Helper for this
16254: # course
16255: $cenv{'course.helper.not.run'} = 1;
16256: #
16257: # Use new Randomseed
16258: #
16259: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16260: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16261: #
16262: # The encryption code and receipt prefix for this course
16263: #
16264: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16265: $cenv{'internal.encpref'}=100+int(9*rand(99));
16266: #
16267: # By default, use standard grading
16268: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16269:
1.541 raeburn 16270: $outcome .= $linefeed.&mt('Setting environment').': '.
16271: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16272: #
16273: # Open all assignments
16274: #
16275: if ($args->{'openall'}) {
16276: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
16277: my %storecontent = ($storeunder => time,
16278: $storeunder.'.type' => 'date_start');
16279:
16280: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 16281: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16282: }
16283: #
16284: # Set first page
16285: #
16286: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16287: || ($cloneid)) {
1.445 albertel 16288: use LONCAPA::map;
1.444 albertel 16289: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16290:
16291: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16292: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16293:
1.444 albertel 16294: $outcome .= ($fatal?$errtext:'read ok').' - ';
16295: my $title; my $url;
16296: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16297: $title=&mt('Syllabus');
1.444 albertel 16298: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16299: } else {
1.963 raeburn 16300: $title=&mt('Table of Contents');
1.444 albertel 16301: $url='/adm/navmaps';
16302: }
1.445 albertel 16303:
16304: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16305: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16306:
16307: if ($errtext) { $fatal=2; }
1.541 raeburn 16308: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16309: }
1.566 albertel 16310:
1.1237 raeburn 16311: #
16312: # Set params for Placement Tests
16313: #
1.1239 raeburn 16314: if ($args->{'crstype'} eq 'Placement') {
16315: my %storecontent;
16316: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
16317: my %defaults = (
16318: buttonshide => { value => 'yes',
16319: type => 'string_yesno',},
16320: type => { value => 'randomizetry',
16321: type => 'string_questiontype',},
16322: maxtries => { value => 1,
16323: type => 'int_pos',},
16324: problemstatus => { value => 'no',
16325: type => 'string_problemstatus',},
16326: );
16327: foreach my $key (keys(%defaults)) {
16328: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
16329: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
16330: }
1.1237 raeburn 16331: &Apache::lonnet::cput
16332: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
16333: }
16334:
1.566 albertel 16335: return (1,$outcome);
1.444 albertel 16336: }
16337:
1.1166 raeburn 16338: sub make_unique_code {
16339: my ($cdom,$cnum) = @_;
16340: # get lock on uniquecodes db
16341: my $lockhash = {
16342: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16343: ':'.$env{'user.domain'},
16344: };
16345: my $tries = 0;
16346: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16347: my ($code,$error);
16348:
16349: while (($gotlock ne 'ok') && ($tries<3)) {
16350: $tries ++;
16351: sleep 1;
16352: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16353: }
16354: if ($gotlock eq 'ok') {
16355: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
16356: my $gotcode;
16357: my $attempts = 0;
16358: while ((!$gotcode) && ($attempts < 100)) {
16359: $code = &generate_code();
16360: if (!exists($currcodes{$code})) {
16361: $gotcode = 1;
16362: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
16363: $error = 'nostore';
16364: }
16365: }
16366: $attempts ++;
16367: }
16368: my @del_lock = ($cnum."\0".'uniquecodes');
16369: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
16370: } else {
16371: $error = 'nolock';
16372: }
16373: return ($code,$error);
16374: }
16375:
16376: sub generate_code {
16377: my $code;
16378: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
16379: for (my $i=0; $i<6; $i++) {
16380: my $lettnum = int (rand 2);
16381: my $item = '';
16382: if ($lettnum) {
16383: $item = $letts[int( rand(18) )];
16384: } else {
16385: $item = 1+int( rand(8) );
16386: }
16387: $code .= $item;
16388: }
16389: return $code;
16390: }
16391:
1.444 albertel 16392: ############################################################
16393: ############################################################
16394:
1.1237 raeburn 16395: # Community, Course and Placement Test
1.378 raeburn 16396: sub course_type {
16397: my ($cid) = @_;
16398: if (!defined($cid)) {
16399: $cid = $env{'request.course.id'};
16400: }
1.404 albertel 16401: if (defined($env{'course.'.$cid.'.type'})) {
16402: return $env{'course.'.$cid.'.type'};
1.378 raeburn 16403: } else {
16404: return 'Course';
1.377 raeburn 16405: }
16406: }
1.156 albertel 16407:
1.406 raeburn 16408: sub group_term {
16409: my $crstype = &course_type();
16410: my %names = (
16411: 'Course' => 'group',
1.865 raeburn 16412: 'Community' => 'group',
1.1237 raeburn 16413: 'Placement' => 'group',
1.406 raeburn 16414: );
16415: return $names{$crstype};
16416: }
16417:
1.902 raeburn 16418: sub course_types {
1.1310 raeburn 16419: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 16420: my %typename = (
16421: official => 'Official course',
16422: unofficial => 'Unofficial course',
16423: community => 'Community',
1.1165 raeburn 16424: textbook => 'Textbook course',
1.1237 raeburn 16425: placement => 'Placement test',
1.1310 raeburn 16426: lti => 'LTI provider',
1.902 raeburn 16427: );
16428: return (\@types,\%typename);
16429: }
16430:
1.156 albertel 16431: sub icon {
16432: my ($file)=@_;
1.505 albertel 16433: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 16434: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 16435: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 16436: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
16437: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
16438: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16439: $curfext.".gif") {
16440: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16441: $curfext.".gif";
16442: }
16443: }
1.249 albertel 16444: return &lonhttpdurl($iconname);
1.154 albertel 16445: }
1.84 albertel 16446:
1.575 albertel 16447: sub lonhttpdurl {
1.692 www 16448: #
16449: # Had been used for "small fry" static images on separate port 8080.
16450: # Modify here if lightweight http functionality desired again.
16451: # Currently eliminated due to increasing firewall issues.
16452: #
1.575 albertel 16453: my ($url)=@_;
1.692 www 16454: return $url;
1.215 albertel 16455: }
16456:
1.213 albertel 16457: sub connection_aborted {
16458: my ($r)=@_;
16459: $r->print(" ");$r->rflush();
16460: my $c = $r->connection;
16461: return $c->aborted();
16462: }
16463:
1.221 foxr 16464: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 16465: # strings as 'strings'.
16466: sub escape_single {
1.221 foxr 16467: my ($input) = @_;
1.223 albertel 16468: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16469: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16470: return $input;
16471: }
1.223 albertel 16472:
1.222 foxr 16473: # Same as escape_single, but escape's "'s This
16474: # can be used for "strings"
16475: sub escape_double {
16476: my ($input) = @_;
16477: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16478: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16479: return $input;
16480: }
1.223 albertel 16481:
1.222 foxr 16482: # Escapes the last element of a full URL.
16483: sub escape_url {
16484: my ($url) = @_;
1.238 raeburn 16485: my @urlslices = split(/\//, $url,-1);
1.369 www 16486: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 16487: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16488: }
1.462 albertel 16489:
1.820 raeburn 16490: sub compare_arrays {
16491: my ($arrayref1,$arrayref2) = @_;
16492: my (@difference,%count);
16493: @difference = ();
16494: %count = ();
16495: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16496: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16497: foreach my $element (keys(%count)) {
16498: if ($count{$element} == 1) {
16499: push(@difference,$element);
16500: }
16501: }
16502: }
16503: return @difference;
16504: }
16505:
1.1322 raeburn 16506: sub lon_status_items {
16507: my %defaults = (
16508: E => 100,
16509: W => 4,
16510: N => 1,
1.1324 raeburn 16511: U => 5,
1.1322 raeburn 16512: threshold => 200,
16513: sysmail => 2500,
16514: );
16515: my %names = (
16516: E => 'Errors',
16517: W => 'Warnings',
16518: N => 'Notices',
1.1324 raeburn 16519: U => 'Unsent',
1.1322 raeburn 16520: );
16521: return (\%defaults,\%names);
16522: }
16523:
1.817 bisitz 16524: # -------------------------------------------------------- Initialize user login
1.462 albertel 16525: sub init_user_environment {
1.463 albertel 16526: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16527: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16528:
16529: my $public=($username eq 'public' && $domain eq 'public');
16530:
1.1062 raeburn 16531: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16532: my $now=time;
16533:
16534: if ($public) {
16535: my $max_public=100;
16536: my $oldest;
16537: my $oldest_time=0;
16538: for(my $next=1;$next<=$max_public;$next++) {
16539: if (-e $lonids."/publicuser_$next.id") {
16540: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16541: if ($mtime<$oldest_time || !$oldest_time) {
16542: $oldest_time=$mtime;
16543: $oldest=$next;
16544: }
16545: } else {
16546: $cookie="publicuser_$next";
16547: last;
16548: }
16549: }
16550: if (!$cookie) { $cookie="publicuser_$oldest"; }
16551: } else {
1.1275 raeburn 16552: # See if old ID present, if so, remove if this isn't a robot,
16553: # killing any existing non-robot sessions
1.463 albertel 16554: if (!$args->{'robot'}) {
16555: opendir(DIR,$lonids);
16556: while ($filename=readdir(DIR)) {
16557: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 16558: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
16559: &GDBM_READER(),0640)) {
1.1295 raeburn 16560: my $linkedfile;
1.1320 raeburn 16561: if (exists($oldenv{'user.linkedenv'})) {
16562: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 16563: }
1.1320 raeburn 16564: untie(%oldenv);
16565: if (unlink("$lonids/$filename")) {
16566: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
16567: if (-l "$lonids/$linkedfile.id") {
16568: unlink("$lonids/$linkedfile.id");
16569: }
1.1295 raeburn 16570: }
16571: }
16572: } else {
16573: unlink($lonids.'/'.$filename);
16574: }
1.463 albertel 16575: }
1.462 albertel 16576: }
1.463 albertel 16577: closedir(DIR);
1.1204 raeburn 16578: # If there is a undeleted lockfile for the user's paste buffer remove it.
16579: my $namespace = 'nohist_courseeditor';
16580: my $lockingkey = 'paste'."\0".'locked_num';
16581: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16582: $domain,$username);
16583: if (exists($lockhash{$lockingkey})) {
16584: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16585: unless ($delresult eq 'ok') {
16586: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16587: }
16588: }
1.462 albertel 16589: }
16590: # Give them a new cookie
1.463 albertel 16591: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16592: : $now.$$.int(rand(10000)));
1.463 albertel 16593: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16594:
16595: # Initialize roles
16596:
1.1062 raeburn 16597: ($userroles,$firstaccenv,$timerintenv) =
16598: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16599: }
16600: # ------------------------------------ Check browser type and MathML capability
16601:
1.1194 raeburn 16602: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16603: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16604:
16605: # ------------------------------------------------------------- Get environment
16606:
16607: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16608: my ($tmp) = keys(%userenv);
1.1275 raeburn 16609: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 16610: undef(%userenv);
16611: }
16612: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16613: $form->{'interface'}=$userenv{'interface'};
16614: }
16615: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16616:
16617: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16618: foreach my $option ('interface','localpath','localres') {
16619: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16620: }
16621: # --------------------------------------------------------- Write first profile
16622:
16623: {
16624: my %initial_env =
16625: ("user.name" => $username,
16626: "user.domain" => $domain,
16627: "user.home" => $authhost,
16628: "browser.type" => $clientbrowser,
16629: "browser.version" => $clientversion,
16630: "browser.mathml" => $clientmathml,
16631: "browser.unicode" => $clientunicode,
16632: "browser.os" => $clientos,
1.1137 raeburn 16633: "browser.mobile" => $clientmobile,
1.1141 raeburn 16634: "browser.info" => $clientinfo,
1.1194 raeburn 16635: "browser.osversion" => $clientosversion,
1.462 albertel 16636: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16637: "request.course.fn" => '',
16638: "request.course.uri" => '',
16639: "request.course.sec" => '',
16640: "request.role" => 'cm',
16641: "request.role.adv" => $env{'user.adv'},
16642: "request.host" => $ENV{'REMOTE_ADDR'},);
16643:
16644: if ($form->{'localpath'}) {
16645: $initial_env{"browser.localpath"} = $form->{'localpath'};
16646: $initial_env{"browser.localres"} = $form->{'localres'};
16647: }
16648:
16649: if ($form->{'interface'}) {
16650: $form->{'interface'}=~s/\W//gs;
16651: $initial_env{"browser.interface"} = $form->{'interface'};
16652: $env{'browser.interface'}=$form->{'interface'};
16653: }
16654:
1.1157 raeburn 16655: if ($form->{'iptoken'}) {
16656: my $lonhost = $r->dir_config('lonHostID');
16657: $initial_env{"user.noloadbalance"} = $lonhost;
16658: $env{'user.noloadbalance'} = $lonhost;
16659: }
16660:
1.1268 raeburn 16661: if ($form->{'noloadbalance'}) {
16662: my @hosts = &Apache::lonnet::current_machine_ids();
16663: my $hosthere = $form->{'noloadbalance'};
16664: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16665: $initial_env{"user.noloadbalance"} = $hosthere;
16666: $env{'user.noloadbalance'} = $hosthere;
16667: }
16668: }
16669:
1.1016 raeburn 16670: unless ($domain eq 'public') {
1.1273 raeburn 16671: my %is_adv = ( is_adv => $env{'user.adv'} );
16672: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
16673:
16674: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16675: $userenv{'availabletools.'.$tool} =
16676: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16677: undef,\%userenv,\%domdef,\%is_adv);
16678: }
1.980 raeburn 16679:
1.1311 raeburn 16680: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 16681: $userenv{'canrequest.'.$crstype} =
16682: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16683: 'reload','requestcourses',
16684: \%userenv,\%domdef,\%is_adv);
16685: }
1.724 raeburn 16686:
1.1273 raeburn 16687: $userenv{'canrequest.author'} =
16688: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16689: 'reload','requestauthor',
1.980 raeburn 16690: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 16691: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16692: $domain,$username);
16693: my $reqstatus = $reqauthor{'author_status'};
16694: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16695: if (ref($reqauthor{'author'}) eq 'HASH') {
16696: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16697: $reqauthor{'author'}{'timestamp'};
16698: }
1.1092 raeburn 16699: }
1.1287 raeburn 16700: my ($types,$typename) = &course_types();
16701: if (ref($types) eq 'ARRAY') {
16702: my @options = ('approval','validate','autolimit');
16703: my $optregex = join('|',@options);
16704: my (%willtrust,%trustchecked);
16705: foreach my $type (@{$types}) {
16706: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
16707: if ($dom_str ne '') {
16708: my $updatedstr = '';
16709: my @possdomains = split(',',$dom_str);
16710: foreach my $entry (@possdomains) {
16711: my ($extdom,$extopt) = split(':',$entry);
16712: unless ($trustchecked{$extdom}) {
16713: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
16714: $trustchecked{$extdom} = 1;
16715: }
16716: if ($willtrust{$extdom}) {
16717: $updatedstr .= $entry.',';
16718: }
16719: }
16720: $updatedstr =~ s/,$//;
16721: if ($updatedstr) {
16722: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
16723: } else {
16724: delete($userenv{'reqcrsotherdom.'.$type});
16725: }
16726: }
16727: }
16728: }
1.1092 raeburn 16729: }
1.462 albertel 16730: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16731:
1.462 albertel 16732: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16733: &GDBM_WRCREAT(),0640)) {
16734: &_add_to_env(\%disk_env,\%initial_env);
16735: &_add_to_env(\%disk_env,\%userenv,'environment.');
16736: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16737: if (ref($firstaccenv) eq 'HASH') {
16738: &_add_to_env(\%disk_env,$firstaccenv);
16739: }
16740: if (ref($timerintenv) eq 'HASH') {
16741: &_add_to_env(\%disk_env,$timerintenv);
16742: }
1.463 albertel 16743: if (ref($args->{'extra_env'})) {
16744: &_add_to_env(\%disk_env,$args->{'extra_env'});
16745: }
1.462 albertel 16746: untie(%disk_env);
16747: } else {
1.705 tempelho 16748: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16749: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16750: return 'error: '.$!;
16751: }
16752: }
16753: $env{'request.role'}='cm';
16754: $env{'request.role.adv'}=$env{'user.adv'};
16755: $env{'browser.type'}=$clientbrowser;
16756:
16757: return $cookie;
16758:
16759: }
16760:
16761: sub _add_to_env {
16762: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16763: if (ref($env_data) eq 'HASH') {
16764: while (my ($key,$value) = each(%$env_data)) {
16765: $idf->{$prefix.$key} = $value;
16766: $env{$prefix.$key} = $value;
16767: }
1.462 albertel 16768: }
16769: }
16770:
1.685 tempelho 16771: # --- Get the symbolic name of a problem and the url
16772: sub get_symb {
16773: my ($request,$silent) = @_;
1.726 raeburn 16774: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16775: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16776: if ($symb eq '') {
16777: if (!$silent) {
1.1071 raeburn 16778: if (ref($request)) {
16779: $request->print("Unable to handle ambiguous references:$url:.");
16780: }
1.685 tempelho 16781: return ();
16782: }
16783: }
16784: &Apache::lonenc::check_decrypt(\$symb);
16785: return ($symb);
16786: }
16787:
16788: # --------------------------------------------------------------Get annotation
16789:
16790: sub get_annotation {
16791: my ($symb,$enc) = @_;
16792:
16793: my $key = $symb;
16794: if (!$enc) {
16795: $key =
16796: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16797: }
16798: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16799: return $annotation{$key};
16800: }
16801:
16802: sub clean_symb {
1.731 raeburn 16803: my ($symb,$delete_enc) = @_;
1.685 tempelho 16804:
16805: &Apache::lonenc::check_decrypt(\$symb);
16806: my $enc = $env{'request.enc'};
1.731 raeburn 16807: if ($delete_enc) {
1.730 raeburn 16808: delete($env{'request.enc'});
16809: }
1.685 tempelho 16810:
16811: return ($symb,$enc);
16812: }
1.462 albertel 16813:
1.1181 raeburn 16814: ############################################################
16815: ############################################################
16816:
16817: =pod
16818:
16819: =head1 Routines for building display used to search for courses
16820:
16821:
16822: =over 4
16823:
16824: =item * &build_filters()
16825:
16826: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 16827: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16828: and quotacheck.pl
16829:
1.1181 raeburn 16830:
16831: Inputs:
16832:
16833: filterlist - anonymous array of fields to include as potential filters
16834:
16835: crstype - course type
16836:
16837: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16838: to pop-open a course selector (will contain "extra element").
16839:
16840: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16841:
16842: filter - anonymous hash of criteria and their values
16843:
16844: action - form action
16845:
16846: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16847:
1.1182 raeburn 16848: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 16849:
16850: cloneruname - username of owner of new course who wants to clone
16851:
16852: clonerudom - domain of owner of new course who wants to clone
16853:
16854: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16855:
16856: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16857:
16858: codedom - domain
16859:
16860: formname - value of form element named "form".
16861:
16862: fixeddom - domain, if fixed.
16863:
16864: prevphase - value to assign to form element named "phase" when going back to the previous screen
16865:
16866: cnameelement - name of form element in form on opener page which will receive title of selected course
16867:
16868: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16869:
16870: cdomelement - name of form element in form on opener page which will receive domain of selected course
16871:
16872: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16873:
16874: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16875:
16876: clonewarning - warning message about missing information for intended course owner when DC creates a course
16877:
1.1182 raeburn 16878:
1.1181 raeburn 16879: Returns: $output - HTML for display of search criteria, and hidden form elements.
16880:
1.1182 raeburn 16881:
1.1181 raeburn 16882: Side Effects: None
16883:
16884: =cut
16885:
16886: # ---------------------------------------------- search for courses based on last activity etc.
16887:
16888: sub build_filters {
16889: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16890: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16891: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16892: $cnameelement,$cnumelement,$cdomelement,$setroles,
16893: $clonetext,$clonewarning) = @_;
1.1182 raeburn 16894: my ($list,$jscript);
1.1181 raeburn 16895: my $onchange = 'javascript:updateFilters(this)';
16896: my ($domainselectform,$sincefilterform,$createdfilterform,
16897: $ownerdomselectform,$persondomselectform,$instcodeform,
16898: $typeselectform,$instcodetitle);
16899: if ($formname eq '') {
16900: $formname = $caller;
16901: }
16902: foreach my $item (@{$filterlist}) {
16903: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16904: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16905: if ($item eq 'domainfilter') {
16906: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16907: } elsif ($item eq 'coursefilter') {
16908: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16909: } elsif ($item eq 'ownerfilter') {
16910: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16911: } elsif ($item eq 'ownerdomfilter') {
16912: $filter->{'ownerdomfilter'} =
16913: &LONCAPA::clean_domain($filter->{$item});
16914: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16915: 'ownerdomfilter',1);
16916: } elsif ($item eq 'personfilter') {
16917: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16918: } elsif ($item eq 'persondomfilter') {
16919: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16920: 'persondomfilter',1);
16921: } else {
16922: $filter->{$item} =~ s/\W//g;
16923: }
16924: if (!$filter->{$item}) {
16925: $filter->{$item} = '';
16926: }
16927: }
16928: if ($item eq 'domainfilter') {
16929: my $allow_blank = 1;
16930: if ($formname eq 'portform') {
16931: $allow_blank=0;
16932: } elsif ($formname eq 'studentform') {
16933: $allow_blank=0;
16934: }
16935: if ($fixeddom) {
16936: $domainselectform = '<input type="hidden" name="domainfilter"'.
16937: ' value="'.$codedom.'" />'.
16938: &Apache::lonnet::domain($codedom,'description');
16939: } else {
16940: $domainselectform = &select_dom_form($filter->{$item},
16941: 'domainfilter',
16942: $allow_blank,'',$onchange);
16943: }
16944: } else {
16945: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16946: }
16947: }
16948:
16949: # last course activity filter and selection
16950: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16951:
16952: # course created filter and selection
16953: if (exists($filter->{'createdfilter'})) {
16954: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16955: }
16956:
1.1239 raeburn 16957: my $prefix = $crstype;
16958: if ($crstype eq 'Placement') {
16959: $prefix = 'Placement Test'
16960: }
1.1181 raeburn 16961: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 16962: 'cac' => "$prefix Activity",
16963: 'ccr' => "$prefix Created",
16964: 'cde' => "$prefix Title",
16965: 'cdo' => "$prefix Domain",
1.1181 raeburn 16966: 'ins' => 'Institutional Code',
16967: 'inc' => 'Institutional Categorization',
1.1239 raeburn 16968: 'cow' => "$prefix Owner/Co-owner",
16969: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 16970: 'cog' => 'Type',
16971: );
16972:
16973: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16974: my $typeval = 'Course';
16975: if ($crstype eq 'Community') {
16976: $typeval = 'Community';
1.1239 raeburn 16977: } elsif ($crstype eq 'Placement') {
16978: $typeval = 'Placement';
1.1181 raeburn 16979: }
16980: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16981: } else {
16982: $typeselectform = '<select name="type" size="1"';
16983: if ($onchange) {
16984: $typeselectform .= ' onchange="'.$onchange.'"';
16985: }
16986: $typeselectform .= '>'."\n";
1.1237 raeburn 16987: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 16988: my $shown;
16989: if ($posstype eq 'Placement') {
16990: $shown = &mt('Placement Test');
16991: } else {
16992: $shown = &mt($posstype);
16993: }
1.1181 raeburn 16994: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 16995: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 16996: }
16997: $typeselectform.="</select>";
16998: }
16999:
17000: my ($cloneableonlyform,$cloneabletitle);
17001: if (exists($filter->{'cloneableonly'})) {
17002: my $cloneableon = '';
17003: my $cloneableoff = ' checked="checked"';
17004: if ($filter->{'cloneableonly'}) {
17005: $cloneableon = $cloneableoff;
17006: $cloneableoff = '';
17007: }
17008: $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>';
17009: if ($formname eq 'ccrs') {
1.1187 bisitz 17010: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 17011: } else {
17012: $cloneabletitle = &mt('Cloneable by you');
17013: }
17014: }
17015: my $officialjs;
17016: if ($crstype eq 'Course') {
17017: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 17018: # if (($fixeddom) || ($formname eq 'requestcrs') ||
17019: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
17020: if ($codedom) {
1.1181 raeburn 17021: $officialjs = 1;
17022: ($instcodeform,$jscript,$$numtitlesref) =
17023: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
17024: $officialjs,$codetitlesref);
17025: if ($jscript) {
1.1182 raeburn 17026: $jscript = '<script type="text/javascript">'."\n".
17027: '// <![CDATA['."\n".
17028: $jscript."\n".
17029: '// ]]>'."\n".
17030: '</script>'."\n";
1.1181 raeburn 17031: }
17032: }
17033: if ($instcodeform eq '') {
17034: $instcodeform =
17035: '<input type="text" name="instcodefilter" size="10" value="'.
17036: $list->{'instcodefilter'}.'" />';
17037: $instcodetitle = $lt{'ins'};
17038: } else {
17039: $instcodetitle = $lt{'inc'};
17040: }
17041: if ($fixeddom) {
17042: $instcodetitle .= '<br />('.$codedom.')';
17043: }
17044: }
17045: }
17046: my $output = qq|
17047: <form method="post" name="filterpicker" action="$action">
17048: <input type="hidden" name="form" value="$formname" />
17049: |;
17050: if ($formname eq 'modifycourse') {
17051: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
17052: '<input type="hidden" name="prevphase" value="'.
17053: $prevphase.'" />'."\n";
1.1198 musolffc 17054: } elsif ($formname eq 'quotacheck') {
17055: $output .= qq|
17056: <input type="hidden" name="sortby" value="" />
17057: <input type="hidden" name="sortorder" value="" />
17058: |;
17059: } else {
1.1181 raeburn 17060: my $name_input;
17061: if ($cnameelement ne '') {
17062: $name_input = '<input type="hidden" name="cnameelement" value="'.
17063: $cnameelement.'" />';
17064: }
17065: $output .= qq|
1.1182 raeburn 17066: <input type="hidden" name="cnumelement" value="$cnumelement" />
17067: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 17068: $name_input
17069: $roleelement
17070: $multelement
17071: $typeelement
17072: |;
17073: if ($formname eq 'portform') {
17074: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
17075: }
17076: }
17077: if ($fixeddom) {
17078: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
17079: }
17080: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
17081: if ($sincefilterform) {
17082: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
17083: .$sincefilterform
17084: .&Apache::lonhtmlcommon::row_closure();
17085: }
17086: if ($createdfilterform) {
17087: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17088: .$createdfilterform
17089: .&Apache::lonhtmlcommon::row_closure();
17090: }
17091: if ($domainselectform) {
17092: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
17093: .$domainselectform
17094: .&Apache::lonhtmlcommon::row_closure();
17095: }
17096: if ($typeselectform) {
17097: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17098: $output .= $typeselectform;
17099: } else {
17100: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
17101: .$typeselectform
17102: .&Apache::lonhtmlcommon::row_closure();
17103: }
17104: }
17105: if ($instcodeform) {
17106: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
17107: .$instcodeform
17108: .&Apache::lonhtmlcommon::row_closure();
17109: }
17110: if (exists($filter->{'ownerfilter'})) {
17111: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
17112: '<table><tr><td>'.&mt('Username').'<br />'.
17113: '<input type="text" name="ownerfilter" size="20" value="'.
17114: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17115: $ownerdomselectform.'</td></tr></table>'.
17116: &Apache::lonhtmlcommon::row_closure();
17117: }
17118: if (exists($filter->{'personfilter'})) {
17119: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
17120: '<table><tr><td>'.&mt('Username').'<br />'.
17121: '<input type="text" name="personfilter" size="20" value="'.
17122: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17123: $persondomselectform.'</td></tr></table>'.
17124: &Apache::lonhtmlcommon::row_closure();
17125: }
17126: if (exists($filter->{'coursefilter'})) {
17127: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
17128: .'<input type="text" name="coursefilter" size="25" value="'
17129: .$list->{'coursefilter'}.'" />'
17130: .&Apache::lonhtmlcommon::row_closure();
17131: }
17132: if ($cloneableonlyform) {
17133: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
17134: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
17135: }
17136: if (exists($filter->{'descriptfilter'})) {
17137: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
17138: .'<input type="text" name="descriptfilter" size="40" value="'
17139: .$list->{'descriptfilter'}.'" />'
17140: .&Apache::lonhtmlcommon::row_closure(1);
17141: }
17142: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
17143: '<input type="hidden" name="updater" value="" />'."\n".
17144: '<input type="submit" name="gosearch" value="'.
17145: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
17146: return $jscript.$clonewarning.$output;
17147: }
17148:
17149: =pod
17150:
17151: =item * &timebased_select_form()
17152:
1.1182 raeburn 17153: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 17154: filter e.g., Course Activity, Course Created, when searching for courses
17155: or communities
17156:
17157: Inputs:
17158:
17159: item - name of form element (sincefilter or createdfilter)
17160:
17161: filter - anonymous hash of criteria and their values
17162:
17163: Returns: HTML for a select box contained a blank, then six time selections,
17164: with value set in incoming form variables currently selected.
17165:
17166: Side Effects: None
17167:
17168: =cut
17169:
17170: sub timebased_select_form {
17171: my ($item,$filter) = @_;
17172: if (ref($filter) eq 'HASH') {
17173: $filter->{$item} =~ s/[^\d-]//g;
17174: if (!$filter->{$item}) { $filter->{$item}=-1; }
17175: return &select_form(
17176: $filter->{$item},
17177: $item,
17178: { '-1' => '',
17179: '86400' => &mt('today'),
17180: '604800' => &mt('last week'),
17181: '2592000' => &mt('last month'),
17182: '7776000' => &mt('last three months'),
17183: '15552000' => &mt('last six months'),
17184: '31104000' => &mt('last year'),
17185: 'select_form_order' =>
17186: ['-1','86400','604800','2592000','7776000',
17187: '15552000','31104000']});
17188: }
17189: }
17190:
17191: =pod
17192:
17193: =item * &js_changer()
17194:
17195: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 17196: when course type or domain is changed, and also to hide 'Searching ...' on
17197: page load completion for page showing search result.
1.1181 raeburn 17198:
17199: Inputs: None
17200:
1.1183 raeburn 17201: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 17202:
17203: Side Effects: None
17204:
17205: =cut
17206:
17207: sub js_changer {
17208: return <<ENDJS;
17209: <script type="text/javascript">
17210: // <![CDATA[
17211: function updateFilters(caller) {
17212: if (typeof(caller) != "undefined") {
17213: document.filterpicker.updater.value = caller.name;
17214: }
17215: document.filterpicker.submit();
17216: }
1.1183 raeburn 17217:
17218: function hideSearching() {
17219: if (document.getElementById('searching')) {
17220: document.getElementById('searching').style.display = 'none';
17221: }
17222: return;
17223: }
17224:
1.1181 raeburn 17225: // ]]>
17226: </script>
17227:
17228: ENDJS
17229: }
17230:
17231: =pod
17232:
1.1182 raeburn 17233: =item * &search_courses()
17234:
17235: Process selected filters form course search form and pass to lonnet::courseiddump
17236: to retrieve a hash for which keys are courseIDs which match the selected filters.
17237:
17238: Inputs:
17239:
17240: dom - domain being searched
17241:
17242: type - course type ('Course' or 'Community' or '.' if any).
17243:
17244: filter - anonymous hash of criteria and their values
17245:
17246: numtitles - for institutional codes - number of categories
17247:
17248: cloneruname - optional username of new course owner
17249:
17250: clonerudom - optional domain of new course owner
17251:
1.1221 raeburn 17252: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 17253: (used when DC is using course creation form)
17254:
17255: codetitles - reference to array of titles of components in institutional codes (official courses).
17256:
1.1221 raeburn 17257: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17258: (and so can clone automatically)
17259:
17260: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17261:
17262: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17263: courses to clone
1.1182 raeburn 17264:
17265: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17266:
17267:
17268: Side Effects: None
17269:
17270: =cut
17271:
17272:
17273: sub search_courses {
1.1221 raeburn 17274: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17275: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 17276: my (%courses,%showcourses,$cloner);
17277: if (($filter->{'ownerfilter'} ne '') ||
17278: ($filter->{'ownerdomfilter'} ne '')) {
17279: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17280: $filter->{'ownerdomfilter'};
17281: }
17282: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17283: if (!$filter->{$item}) {
17284: $filter->{$item}='.';
17285: }
17286: }
17287: my $now = time;
17288: my $timefilter =
17289: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17290: my ($createdbefore,$createdafter);
17291: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17292: $createdbefore = $now;
17293: $createdafter = $now-$filter->{'createdfilter'};
17294: }
17295: my ($instcodefilter,$regexpok);
17296: if ($numtitles) {
17297: if ($env{'form.official'} eq 'on') {
17298: $instcodefilter =
17299: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17300: $regexpok = 1;
17301: } elsif ($env{'form.official'} eq 'off') {
17302: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17303: unless ($instcodefilter eq '') {
17304: $regexpok = -1;
17305: }
17306: }
17307: } else {
17308: $instcodefilter = $filter->{'instcodefilter'};
17309: }
17310: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17311: if ($type eq '') { $type = '.'; }
17312:
17313: if (($clonerudom ne '') && ($cloneruname ne '')) {
17314: $cloner = $cloneruname.':'.$clonerudom;
17315: }
17316: %courses = &Apache::lonnet::courseiddump($dom,
17317: $filter->{'descriptfilter'},
17318: $timefilter,
17319: $instcodefilter,
17320: $filter->{'combownerfilter'},
17321: $filter->{'coursefilter'},
17322: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 17323: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 17324: $filter->{'cloneableonly'},
17325: $createdbefore,$createdafter,undef,
1.1221 raeburn 17326: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 17327: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17328: my $ccrole;
17329: if ($type eq 'Community') {
17330: $ccrole = 'co';
17331: } else {
17332: $ccrole = 'cc';
17333: }
17334: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17335: $filter->{'persondomfilter'},
17336: 'userroles',undef,
17337: [$ccrole,'in','ad','ep','ta','cr'],
17338: $dom);
17339: foreach my $role (keys(%rolehash)) {
17340: my ($cnum,$cdom,$courserole) = split(':',$role);
17341: my $cid = $cdom.'_'.$cnum;
17342: if (exists($courses{$cid})) {
17343: if (ref($courses{$cid}) eq 'HASH') {
17344: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17345: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 17346: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 17347: }
17348: } else {
17349: $courses{$cid}{roles} = [$courserole];
17350: }
17351: $showcourses{$cid} = $courses{$cid};
17352: }
17353: }
17354: }
17355: %courses = %showcourses;
17356: }
17357: return %courses;
17358: }
17359:
17360: =pod
17361:
1.1181 raeburn 17362: =back
17363:
1.1207 raeburn 17364: =head1 Routines for version requirements for current course.
17365:
17366: =over 4
17367:
17368: =item * &check_release_required()
17369:
17370: Compares required LON-CAPA version with version on server, and
17371: if required version is newer looks for a server with the required version.
17372:
17373: Looks first at servers in user's owen domain; if none suitable, looks at
17374: servers in course's domain are permitted to host sessions for user's domain.
17375:
17376: Inputs:
17377:
17378: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17379:
17380: $courseid - Course ID of current course
17381:
17382: $rolecode - User's current role in course (for switchserver query string).
17383:
17384: $required - LON-CAPA version needed by course (format: Major.Minor).
17385:
17386:
17387: Returns:
17388:
17389: $switchserver - query string tp append to /adm/switchserver call (if
17390: current server's LON-CAPA version is too old.
17391:
17392: $warning - Message is displayed if no suitable server could be found.
17393:
17394: =cut
17395:
17396: sub check_release_required {
17397: my ($loncaparev,$courseid,$rolecode,$required) = @_;
17398: my ($switchserver,$warning);
17399: if ($required ne '') {
17400: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
17401: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17402: if ($reqdmajor ne '' && $reqdminor ne '') {
17403: my $otherserver;
17404: if (($major eq '' && $minor eq '') ||
17405: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
17406: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
17407: my $switchlcrev =
17408: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
17409: $userdomserver);
17410: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17411: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
17412: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
17413: my $cdom = $env{'course.'.$courseid.'.domain'};
17414: if ($cdom ne $env{'user.domain'}) {
17415: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
17416: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
17417: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17418: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
17419: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
17420: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
17421: my $canhost =
17422: &Apache::lonnet::can_host_session($env{'user.domain'},
17423: $coursedomserver,
17424: $remoterev,
17425: $udomdefaults{'remotesessions'},
17426: $defdomdefaults{'hostedsessions'});
17427:
17428: if ($canhost) {
17429: $otherserver = $coursedomserver;
17430: } else {
17431: $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.");
17432: }
17433: } else {
17434: $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).");
17435: }
17436: } else {
17437: $otherserver = $userdomserver;
17438: }
17439: }
17440: if ($otherserver ne '') {
17441: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
17442: }
17443: }
17444: }
17445: return ($switchserver,$warning);
17446: }
17447:
17448: =pod
17449:
17450: =item * &check_release_result()
17451:
17452: Inputs:
17453:
17454: $switchwarning - Warning message if no suitable server found to host session.
17455:
17456: $switchserver - query string to append to /adm/switchserver containing lonHostID
17457: and current role.
17458:
17459: Returns: HTML to display with information about requirement to switch server.
17460: Either displaying warning with link to Roles/Courses screen or
17461: display link to switchserver.
17462:
1.1181 raeburn 17463: =cut
17464:
1.1207 raeburn 17465: sub check_release_result {
17466: my ($switchwarning,$switchserver) = @_;
17467: my $output = &start_page('Selected course unavailable on this server').
17468: '<p class="LC_warning">';
17469: if ($switchwarning) {
17470: $output .= $switchwarning.'<br /><a href="/adm/roles">';
17471: if (&show_course()) {
17472: $output .= &mt('Display courses');
17473: } else {
17474: $output .= &mt('Display roles');
17475: }
17476: $output .= '</a>';
17477: } elsif ($switchserver) {
17478: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
17479: '<br />'.
17480: '<a href="/adm/switchserver?'.$switchserver.'">'.
17481: &mt('Switch Server').
17482: '</a>';
17483: }
17484: $output .= '</p>'.&end_page();
17485: return $output;
17486: }
17487:
17488: =pod
17489:
17490: =item * &needs_coursereinit()
17491:
17492: Determine if course contents stored for user's session needs to be
17493: refreshed, because content has changed since "Big Hash" last tied.
17494:
17495: Check for change is made if time last checked is more than 10 minutes ago
17496: (by default).
17497:
17498: Inputs:
17499:
17500: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17501:
17502: $interval (optional) - Time which may elapse (in s) between last check for content
17503: change in current course. (default: 600 s).
17504:
17505: Returns: an array; first element is:
17506:
17507: =over 4
17508:
17509: 'switch' - if content updates mean user's session
17510: needs to be switched to a server running a newer LON-CAPA version
17511:
17512: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
17513: on current server hosting user's session
17514:
17515: '' - if no action required.
17516:
17517: =back
17518:
17519: If first item element is 'switch':
17520:
17521: second item is $switchwarning - Warning message if no suitable server found to host session.
17522:
17523: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
17524: and current role.
17525:
17526: otherwise: no other elements returned.
17527:
17528: =back
17529:
17530: =cut
17531:
17532: sub needs_coursereinit {
17533: my ($loncaparev,$interval) = @_;
17534: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
17535: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17536: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17537: my $now = time;
17538: if ($interval eq '') {
17539: $interval = 600;
17540: }
17541: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 17542: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1283 raeburn 17543: my $blocked = &blocking_status('reinit',$cnum,$cdom,undef,1);
1.1282 raeburn 17544: if ($blocked) {
17545: return ();
17546: }
1.1207 raeburn 17547: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17548: if ($lastchange > $env{'request.course.tied'}) {
17549: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17550: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17551: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17552: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17553: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17554: $curr_reqd_hash{'internal.releaserequired'}});
17555: my ($switchserver,$switchwarning) =
17556: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17557: $curr_reqd_hash{'internal.releaserequired'});
17558: if ($switchwarning ne '' || $switchserver ne '') {
17559: return ('switch',$switchwarning,$switchserver);
17560: }
17561: }
17562: }
17563: return ('update');
17564: }
17565: }
17566: return ();
17567: }
1.1181 raeburn 17568:
1.1083 raeburn 17569: sub update_content_constraints {
1.1326 raeburn 17570: my ($cdom,$cnum,$chome,$cid,$keeporder) = @_;
1.1083 raeburn 17571: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17572: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 17573: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 17574: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 17575: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 17576: if ($item eq 'resourcetag') {
17577: if ($name eq 'responsetype') {
17578: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17579: }
1.1307 raeburn 17580: } elsif ($item eq 'course') {
17581: if ($name eq 'courserestype') {
17582: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
17583: }
1.1083 raeburn 17584: }
17585: }
17586: my $navmap = Apache::lonnavmaps::navmap->new();
17587: if (defined($navmap)) {
1.1307 raeburn 17588: my (%allresponses,%allcrsrestypes);
17589: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
17590: if ($res->is_tool()) {
17591: if ($allcrsrestypes{'exttool'}) {
17592: $allcrsrestypes{'exttool'} ++;
17593: } else {
17594: $allcrsrestypes{'exttool'} = 1;
17595: }
17596: next;
17597: }
1.1083 raeburn 17598: my %responses = $res->responseTypes();
17599: foreach my $key (keys(%responses)) {
17600: next unless(exists($checkresponsetypes{$key}));
17601: $allresponses{$key} += $responses{$key};
17602: }
17603: }
17604: foreach my $key (keys(%allresponses)) {
17605: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17606: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17607: ($reqdmajor,$reqdminor) = ($major,$minor);
17608: }
17609: }
1.1307 raeburn 17610: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 17611: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 17612: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17613: ($reqdmajor,$reqdminor) = ($major,$minor);
17614: }
17615: }
1.1083 raeburn 17616: undef($navmap);
17617: }
1.1326 raeburn 17618: my (@resources,@order,@resparms,@zombies);
17619: if ($keeporder) {
17620: use LONCAPA::map;
17621: @resources = @LONCAPA::map::resources;
17622: @order = @LONCAPA::map::order;
17623: @resparms = @LONCAPA::map::resparms;
17624: @zombies = @LONCAPA::map::zombies;
17625: }
1.1308 raeburn 17626: my $suppmap = 'supplemental.sequence';
17627: my ($suppcount,$supptools,$errors) = (0,0,0);
17628: ($suppcount,$supptools,$errors) = &recurse_supplemental($cnum,$cdom,$suppmap,
17629: $suppcount,$supptools,$errors);
1.1326 raeburn 17630: if ($keeporder) {
17631: @LONCAPA::map::resources = @resources;
17632: @LONCAPA::map::order = @order;
17633: @LONCAPA::map::resparms = @resparms;
17634: @LONCAPA::map::zombies = @zombies;
17635: }
1.1308 raeburn 17636: if ($supptools) {
17637: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
17638: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17639: ($reqdmajor,$reqdminor) = ($major,$minor);
17640: }
17641: }
1.1083 raeburn 17642: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17643: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17644: }
17645: return;
17646: }
17647:
1.1110 raeburn 17648: sub allmaps_incourse {
17649: my ($cdom,$cnum,$chome,$cid) = @_;
17650: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17651: $cid = $env{'request.course.id'};
17652: $cdom = $env{'course.'.$cid.'.domain'};
17653: $cnum = $env{'course.'.$cid.'.num'};
17654: $chome = $env{'course.'.$cid.'.home'};
17655: }
17656: my %allmaps = ();
17657: my $lastchange =
17658: &Apache::lonnet::get_coursechange($cdom,$cnum);
17659: if ($lastchange > $env{'request.course.tied'}) {
17660: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17661: unless ($ferr) {
1.1326 raeburn 17662: &update_content_constraints($cdom,$cnum,$chome,$cid,1);
1.1110 raeburn 17663: }
17664: }
17665: my $navmap = Apache::lonnavmaps::navmap->new();
17666: if (defined($navmap)) {
17667: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17668: $allmaps{$res->src()} = 1;
17669: }
17670: }
17671: return \%allmaps;
17672: }
17673:
1.1083 raeburn 17674: sub parse_supplemental_title {
17675: my ($title) = @_;
17676:
17677: my ($foldertitle,$renametitle);
17678: if ($title =~ /&&&/) {
17679: $title = &HTML::Entites::decode($title);
17680: }
17681: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17682: $renametitle=$4;
17683: my ($time,$uname,$udom) = ($1,$2,$3);
17684: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17685: my $name = &plainname($uname,$udom);
17686: $name = &HTML::Entities::encode($name,'"<>&\'');
17687: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17688: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17689: $name.': <br />'.$foldertitle;
17690: }
17691: if (wantarray) {
17692: return ($title,$foldertitle,$renametitle);
17693: }
17694: return $title;
17695: }
17696:
1.1143 raeburn 17697: sub recurse_supplemental {
1.1308 raeburn 17698: my ($cnum,$cdom,$suppmap,$numfiles,$numexttools,$errors) = @_;
1.1143 raeburn 17699: if ($suppmap) {
17700: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17701: if ($fatal) {
17702: $errors ++;
17703: } else {
17704: if ($#LONCAPA::map::resources > 0) {
17705: foreach my $res (@LONCAPA::map::resources) {
17706: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17707: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 17708: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1308 raeburn 17709: ($numfiles,$numexttools,$errors) = &recurse_supplemental($cnum,$cdom,$1,
17710: $numfiles,$numexttools,$errors);
1.1143 raeburn 17711: } else {
1.1308 raeburn 17712: if ($src =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
17713: $numexttools ++;
17714: }
1.1143 raeburn 17715: $numfiles ++;
17716: }
17717: }
17718: }
17719: }
17720: }
17721: }
1.1308 raeburn 17722: return ($numfiles,$numexttools,$errors);
1.1143 raeburn 17723: }
17724:
1.1101 raeburn 17725: sub symb_to_docspath {
1.1267 raeburn 17726: my ($symb,$navmapref) = @_;
17727: return unless ($symb && ref($navmapref));
1.1101 raeburn 17728: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17729: if ($resurl=~/\.(sequence|page)$/) {
17730: $mapurl=$resurl;
17731: } elsif ($resurl eq 'adm/navmaps') {
17732: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17733: }
17734: my $mapresobj;
1.1267 raeburn 17735: unless (ref($$navmapref)) {
17736: $$navmapref = Apache::lonnavmaps::navmap->new();
17737: }
17738: if (ref($$navmapref)) {
17739: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 17740: }
17741: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17742: my $type=$2;
17743: my $path;
17744: if (ref($mapresobj)) {
17745: my $pcslist = $mapresobj->map_hierarchy();
17746: if ($pcslist ne '') {
17747: foreach my $pc (split(/,/,$pcslist)) {
17748: next if ($pc <= 1);
1.1267 raeburn 17749: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 17750: if (ref($res)) {
17751: my $thisurl = $res->src();
17752: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17753: my $thistitle = $res->title();
17754: $path .= '&'.
17755: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 17756: &escape($thistitle).
1.1101 raeburn 17757: ':'.$res->randompick().
17758: ':'.$res->randomout().
17759: ':'.$res->encrypted().
17760: ':'.$res->randomorder().
17761: ':'.$res->is_page();
17762: }
17763: }
17764: }
17765: $path =~ s/^\&//;
17766: my $maptitle = $mapresobj->title();
17767: if ($mapurl eq 'default') {
1.1129 raeburn 17768: $maptitle = 'Main Content';
1.1101 raeburn 17769: }
17770: $path .= (($path ne '')? '&' : '').
17771: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17772: &escape($maptitle).
1.1101 raeburn 17773: ':'.$mapresobj->randompick().
17774: ':'.$mapresobj->randomout().
17775: ':'.$mapresobj->encrypted().
17776: ':'.$mapresobj->randomorder().
17777: ':'.$mapresobj->is_page();
17778: } else {
17779: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17780: my $ispage = (($type eq 'page')? 1 : '');
17781: if ($mapurl eq 'default') {
1.1129 raeburn 17782: $maptitle = 'Main Content';
1.1101 raeburn 17783: }
17784: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17785: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 17786: }
17787: unless ($mapurl eq 'default') {
17788: $path = 'default&'.
1.1146 raeburn 17789: &escape('Main Content').
1.1101 raeburn 17790: ':::::&'.$path;
17791: }
17792: return $path;
17793: }
17794:
1.1094 raeburn 17795: sub captcha_display {
1.1327 raeburn 17796: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 17797: my ($output,$error);
1.1234 raeburn 17798: my ($captcha,$pubkey,$privkey,$version) =
1.1327 raeburn 17799: &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 17800: if ($captcha eq 'original') {
1.1094 raeburn 17801: $output = &create_captcha();
17802: unless ($output) {
1.1172 raeburn 17803: $error = 'captcha';
1.1094 raeburn 17804: }
17805: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17806: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 17807: unless ($output) {
1.1172 raeburn 17808: $error = 'recaptcha';
1.1094 raeburn 17809: }
17810: }
1.1234 raeburn 17811: return ($output,$error,$captcha,$version);
1.1094 raeburn 17812: }
17813:
17814: sub captcha_response {
1.1327 raeburn 17815: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 17816: my ($captcha_chk,$captcha_error);
1.1327 raeburn 17817: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 17818: if ($captcha eq 'original') {
1.1094 raeburn 17819: ($captcha_chk,$captcha_error) = &check_captcha();
17820: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17821: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 17822: } else {
17823: $captcha_chk = 1;
17824: }
17825: return ($captcha_chk,$captcha_error);
17826: }
17827:
17828: sub get_captcha_config {
1.1327 raeburn 17829: my ($context,$lonhost,$dom_in_effect) = @_;
1.1234 raeburn 17830: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 17831: my $hostname = &Apache::lonnet::hostname($lonhost);
17832: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17833: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 17834: if ($context eq 'usercreation') {
17835: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17836: if (ref($domconfig{$context}) eq 'HASH') {
17837: $hashtocheck = $domconfig{$context}{'cancreate'};
17838: if (ref($hashtocheck) eq 'HASH') {
17839: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17840: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17841: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17842: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17843: }
17844: if ($privkey && $pubkey) {
17845: $captcha = 'recaptcha';
1.1234 raeburn 17846: $version = $hashtocheck->{'recaptchaversion'};
17847: if ($version ne '2') {
17848: $version = 1;
17849: }
1.1095 raeburn 17850: } else {
17851: $captcha = 'original';
17852: }
17853: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17854: $captcha = 'original';
17855: }
1.1094 raeburn 17856: }
1.1095 raeburn 17857: } else {
17858: $captcha = 'captcha';
17859: }
17860: } elsif ($context eq 'login') {
17861: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17862: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17863: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17864: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 17865: if ($privkey && $pubkey) {
17866: $captcha = 'recaptcha';
1.1234 raeburn 17867: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17868: if ($version ne '2') {
17869: $version = 1;
17870: }
1.1095 raeburn 17871: } else {
17872: $captcha = 'original';
1.1094 raeburn 17873: }
1.1095 raeburn 17874: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17875: $captcha = 'original';
1.1094 raeburn 17876: }
1.1327 raeburn 17877: } elsif ($context eq 'passwords') {
17878: if ($dom_in_effect) {
17879: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
17880: if ($passwdconf{'captcha'} eq 'recaptcha') {
17881: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
17882: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
17883: $privkey = $passwdconf{'recaptchakeys'}{'private'};
17884: }
17885: if ($privkey && $pubkey) {
17886: $captcha = 'recaptcha';
17887: $version = $passwdconf{'recaptchaversion'};
17888: if ($version ne '2') {
17889: $version = 1;
17890: }
17891: } else {
17892: $captcha = 'original';
17893: }
17894: } elsif ($passwdconf{'captcha'} ne 'notused') {
17895: $captcha = 'original';
17896: }
17897: }
17898: }
1.1234 raeburn 17899: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 17900: }
17901:
17902: sub create_captcha {
17903: my %captcha_params = &captcha_settings();
17904: my ($output,$maxtries,$tries) = ('',10,0);
17905: while ($tries < $maxtries) {
17906: $tries ++;
17907: my $captcha = Authen::Captcha->new (
17908: output_folder => $captcha_params{'output_dir'},
17909: data_folder => $captcha_params{'db_dir'},
17910: );
17911: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17912:
17913: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17914: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17915: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 17916: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17917: '<br />'.
17918: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 17919: last;
17920: }
17921: }
1.1323 raeburn 17922: if ($output eq '') {
17923: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
17924: }
1.1094 raeburn 17925: return $output;
17926: }
17927:
17928: sub captcha_settings {
17929: my %captcha_params = (
17930: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17931: www_output_dir => "/captchaspool",
17932: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17933: numchars => '5',
17934: );
17935: return %captcha_params;
17936: }
17937:
17938: sub check_captcha {
17939: my ($captcha_chk,$captcha_error);
17940: my $code = $env{'form.code'};
17941: my $md5sum = $env{'form.crypt'};
17942: my %captcha_params = &captcha_settings();
17943: my $captcha = Authen::Captcha->new(
17944: output_folder => $captcha_params{'output_dir'},
17945: data_folder => $captcha_params{'db_dir'},
17946: );
1.1109 raeburn 17947: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 17948: my %captcha_hash = (
17949: 0 => 'Code not checked (file error)',
17950: -1 => 'Failed: code expired',
17951: -2 => 'Failed: invalid code (not in database)',
17952: -3 => 'Failed: invalid code (code does not match crypt)',
17953: );
17954: if ($captcha_chk != 1) {
17955: $captcha_error = $captcha_hash{$captcha_chk}
17956: }
17957: return ($captcha_chk,$captcha_error);
17958: }
17959:
17960: sub create_recaptcha {
1.1234 raeburn 17961: my ($pubkey,$version) = @_;
17962: if ($version >= 2) {
17963: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17964: } else {
17965: my $use_ssl;
17966: if ($ENV{'SERVER_PORT'} == 443) {
17967: $use_ssl = 1;
17968: }
17969: my $captcha = Captcha::reCAPTCHA->new;
17970: return $captcha->get_options_setter({theme => 'white'})."\n".
17971: $captcha->get_html($pubkey,undef,$use_ssl).
17972: &mt('If the text is hard to read, [_1] will replace them.',
17973: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17974: '<br /><br />';
17975: }
1.1094 raeburn 17976: }
17977:
17978: sub check_recaptcha {
1.1234 raeburn 17979: my ($privkey,$version) = @_;
1.1094 raeburn 17980: my $captcha_chk;
1.1234 raeburn 17981: if ($version >= 2) {
17982: my %info = (
17983: secret => $privkey,
17984: response => $env{'form.g-recaptcha-response'},
17985: remoteip => $ENV{'REMOTE_ADDR'},
17986: );
1.1280 raeburn 17987: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
17988: $request->content(join('&',map {
17989: my $name = escape($_);
17990: "$name=" . ( ref($info{$_}) eq 'ARRAY'
17991: ? join("&$name=", map {escape($_) } @{$info{$_}})
17992: : &escape($info{$_}) );
17993: } keys(%info)));
17994: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 17995: if ($response->is_success) {
17996: my $data = JSON::DWIW->from_json($response->decoded_content);
17997: if (ref($data) eq 'HASH') {
17998: if ($data->{'success'}) {
17999: $captcha_chk = 1;
18000: }
18001: }
18002: }
18003: } else {
18004: my $captcha = Captcha::reCAPTCHA->new;
18005: my $captcha_result =
18006: $captcha->check_answer(
18007: $privkey,
18008: $ENV{'REMOTE_ADDR'},
18009: $env{'form.recaptcha_challenge_field'},
18010: $env{'form.recaptcha_response_field'},
18011: );
18012: if ($captcha_result->{is_valid}) {
18013: $captcha_chk = 1;
18014: }
1.1094 raeburn 18015: }
18016: return $captcha_chk;
18017: }
18018:
1.1174 raeburn 18019: sub emailusername_info {
1.1244 raeburn 18020: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 18021: my %titles = &Apache::lonlocal::texthash (
18022: lastname => 'Last Name',
18023: firstname => 'First Name',
18024: institution => 'School/college/university',
18025: location => "School's city, state/province, country",
18026: web => "School's web address",
18027: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 18028: id => 'Student/Employee ID',
1.1174 raeburn 18029: );
18030: return (\@fields,\%titles);
18031: }
18032:
1.1161 raeburn 18033: sub cleanup_html {
18034: my ($incoming) = @_;
18035: my $outgoing;
18036: if ($incoming ne '') {
18037: $outgoing = $incoming;
18038: $outgoing =~ s/;/;/g;
18039: $outgoing =~ s/\#/#/g;
18040: $outgoing =~ s/\&/&/g;
18041: $outgoing =~ s/</</g;
18042: $outgoing =~ s/>/>/g;
18043: $outgoing =~ s/\(/(/g;
18044: $outgoing =~ s/\)/)/g;
18045: $outgoing =~ s/"/"/g;
18046: $outgoing =~ s/'/'/g;
18047: $outgoing =~ s/\$/$/g;
18048: $outgoing =~ s{/}{/}g;
18049: $outgoing =~ s/=/=/g;
18050: $outgoing =~ s/\\/\/g
18051: }
18052: return $outgoing;
18053: }
18054:
1.1190 musolffc 18055: # Checks for critical messages and returns a redirect url if one exists.
18056: # $interval indicates how often to check for messages.
1.1282 raeburn 18057: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 18058: sub critical_redirect {
1.1282 raeburn 18059: my ($interval,$context) = @_;
1.1190 musolffc 18060: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 18061: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
18062: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18063: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18064: my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
18065: if ($blocked) {
18066: my $checkrole = "cm./$cdom/$cnum";
18067: if ($env{'request.course.sec'} ne '') {
18068: $checkrole .= "/$env{'request.course.sec'}";
18069: }
18070: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
18071: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
18072: return;
18073: }
18074: }
18075: }
1.1190 musolffc 18076: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
18077: $env{'user.name'});
18078: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 18079: my $redirecturl;
1.1190 musolffc 18080: if ($what[0]) {
18081: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
18082: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 18083: my $url=&Apache::lonnet::absolute_url().$redirecturl;
18084: return (1, $url);
1.1190 musolffc 18085: }
1.1191 raeburn 18086: }
18087: }
18088: return ();
1.1190 musolffc 18089: }
18090:
1.1174 raeburn 18091: # Use:
18092: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
18093: #
18094: ##################################################
18095: # password associated functions #
18096: ##################################################
18097: sub des_keys {
18098: # Make a new key for DES encryption.
18099: # Each key has two parts which are returned separately.
18100: # Please note: Each key must be passed through the &hex function
18101: # before it is output to the web browser. The hex versions cannot
18102: # be used to decrypt.
18103: my @hexstr=('0','1','2','3','4','5','6','7',
18104: '8','9','a','b','c','d','e','f');
18105: my $lkey='';
18106: for (0..7) {
18107: $lkey.=$hexstr[rand(15)];
18108: }
18109: my $ukey='';
18110: for (0..7) {
18111: $ukey.=$hexstr[rand(15)];
18112: }
18113: return ($lkey,$ukey);
18114: }
18115:
18116: sub des_decrypt {
18117: my ($key,$cyphertext) = @_;
18118: my $keybin=pack("H16",$key);
18119: my $cypher;
18120: if ($Crypt::DES::VERSION>=2.03) {
18121: $cypher=new Crypt::DES $keybin;
18122: } else {
18123: $cypher=new DES $keybin;
18124: }
1.1233 raeburn 18125: my $plaintext='';
18126: my $cypherlength = length($cyphertext);
18127: my $numchunks = int($cypherlength/32);
18128: for (my $j=0; $j<$numchunks; $j++) {
18129: my $start = $j*32;
18130: my $cypherblock = substr($cyphertext,$start,32);
18131: my $chunk =
18132: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
18133: $chunk .=
18134: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
18135: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
18136: $plaintext .= $chunk;
18137: }
1.1174 raeburn 18138: return $plaintext;
18139: }
18140:
1.1309 raeburn 18141: sub make_short_symbs {
18142: my ($cdom,$cnum,$navmap) = @_;
18143: return unless (ref($navmap));
18144: my ($numnew,@errors);
18145: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
18146: if (@toshorten) {
18147: my (%maps,%resources,%titles);
18148: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
18149: 'shorturls',$cdom,$cnum);
18150: my %tocreate;
18151: if (keys(%resources)) {
18152: foreach my $item (sort {$a <=> $b} (@toshorten)) {
18153: my $symb = $resources{$item};
18154: if ($symb) {
18155: $tocreate{$cnum.'&'.$symb} = 1;
18156: }
18157: }
18158: }
18159: if (keys(%tocreate)) {
18160: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
18161: my $su = Short::URL->new(no_vowels => 1);
18162: my $init = '';
18163: my (%newunique,%addcourse,%courseonly,%failed);
18164: # get lock on tiny db
18165: my $now = time;
18166: my $lockhash = {
18167: "lock\0$now" => $env{'user.name'}.
18168: ':'.$env{'user.domain'},
18169: };
18170: my $tries = 0;
18171: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18172: my ($code,$error);
18173: while (($gotlock ne 'ok') && ($tries<3)) {
18174: $tries ++;
18175: sleep 1;
1.1319 raeburn 18176: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 18177: }
18178: if ($gotlock eq 'ok') {
18179: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
18180: \%addcourse,\%courseonly,\%failed);
18181: if (keys(%failed)) {
18182: my $numfailed = scalar(keys(%failed));
18183: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
18184: }
18185: if (keys(%newunique)) {
18186: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
18187: if ($putres eq 'ok') {
18188: $numnew = scalar(keys(%newunique));
18189: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
18190: unless ($newputres eq 'ok') {
18191: push(@errors,&mt('error: could not store course look-up of short URLs'));
18192: }
18193: } else {
18194: push(@errors,&mt('error: could not store unique six character URLs'));
18195: }
18196: }
18197: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
18198: unless ($dellockres eq 'ok') {
18199: push(@errors,&mt('error: could not release lockfile'));
18200: }
18201: } else {
18202: push(@errors,&mt('error: could not obtain lockfile'));
18203: }
18204: if (keys(%courseonly)) {
18205: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
18206: if ($result ne 'ok') {
18207: push(@errors,&mt('error: could not update course look-up of short URLs'));
18208: }
18209: }
18210: }
18211: }
18212: return ($numnew,\@errors);
18213: }
18214:
18215: sub shorten_symbs {
18216: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
18217: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
18218: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
18219: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
18220: my (%possibles,%collisions);
18221: foreach my $key (keys(%{$tocreate})) {
18222: my $num = String::CRC32::crc32($key);
18223: my $tiny = $su->encode($num,$init);
18224: if ($tiny) {
18225: $possibles{$tiny} = $key;
18226: }
18227: }
18228: if (!$init) {
18229: $init = 1;
18230: } else {
18231: $init ++;
18232: }
18233: if (keys(%possibles)) {
18234: my @posstiny = keys(%possibles);
18235: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
18236: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
18237: if (keys(%currtiny)) {
18238: foreach my $key (keys(%currtiny)) {
18239: next if ($currtiny{$key} eq '');
18240: if ($currtiny{$key} eq $possibles{$key}) {
18241: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
18242: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18243: $courseonly->{$tsymb} = $key;
18244: }
18245: } else {
18246: $collisions{$possibles{$key}} = 1;
18247: }
18248: delete($possibles{$key});
18249: }
18250: }
18251: foreach my $key (keys(%possibles)) {
18252: $newunique->{$key} = $possibles{$key};
18253: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
18254: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18255: $addcourse->{$tsymb} = $key;
18256: }
18257: }
18258: }
18259: if (keys(%collisions)) {
18260: if ($init <5) {
18261: if (!$init) {
18262: $init = 1;
18263: } else {
18264: $init ++;
18265: }
18266: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
18267: $newunique,$addcourse,$courseonly,$failed);
18268: } else {
18269: foreach my $key (keys(%collisions)) {
18270: $failed->{$key} = 1;
18271: }
18272: }
18273: }
18274: return $init;
18275: }
18276:
1.1328 raeburn 18277: sub is_nonframeable {
1.1329 raeburn 18278: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
18279: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
1.1330 raeburn 18280: return if (($remprotocol eq '') || ($remhost eq ''));
1.1329 raeburn 18281:
18282: $remprotocol = lc($remprotocol);
18283: $remhost = lc($remhost);
18284: my $remport = 80;
18285: if ($remprotocol eq 'https') {
18286: $remport = 443;
18287: }
1.1330 raeburn 18288: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
1.1329 raeburn 18289: if ($cached) {
18290: unless ($nocache) {
18291: if ($result) {
18292: return 1;
18293: } else {
18294: return 0;
18295: }
18296: }
18297: }
1.1328 raeburn 18298: my $uselink;
18299: my $request = new HTTP::Request('HEAD',$url);
18300: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
18301: if ($response->is_success()) {
18302: my $secpolicy = lc($response->header('content-security-policy'));
18303: my $xframeop = lc($response->header('x-frame-options'));
18304: $secpolicy =~ s/^\s+|\s+$//g;
18305: $xframeop =~ s/^\s+|\s+$//g;
18306: if (($secpolicy ne '') || ($xframeop ne '')) {
1.1329 raeburn 18307: my $remotehost = $remprotocol.'://'.$remhost;
1.1328 raeburn 18308: my ($origin,$protocol,$port);
18309: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
18310: $port = $ENV{'SERVER_PORT'};
18311: } else {
18312: $port = 80;
18313: }
18314: if ($absolute eq '') {
18315: $protocol = 'http:';
18316: if ($port == 443) {
18317: $protocol = 'https:';
18318: }
18319: $origin = $protocol.'//'.lc($hostname);
18320: } else {
18321: $origin = lc($absolute);
18322: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
18323: }
18324: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
18325: my $framepolicy = $1;
18326: $framepolicy =~ s/^\s+|\s+$//g;
18327: my @policies = split(/\s+/,$framepolicy);
18328: if (@policies) {
18329: if (grep(/^\Q'none'\E$/,@policies)) {
18330: $uselink = 1;
18331: } else {
18332: $uselink = 1;
18333: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
18334: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
18335: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
18336: undef($uselink);
18337: }
18338: if ($uselink) {
18339: if (grep(/^\Q'self'\E$/,@policies)) {
18340: if (($origin ne '') && ($remotehost eq $origin)) {
18341: undef($uselink);
18342: }
18343: }
18344: }
18345: if ($uselink) {
18346: my @possok;
18347: if ($ip ne '') {
18348: push(@possok,$ip);
18349: }
18350: my $hoststr = '';
18351: foreach my $part (reverse(split(/\./,$hostname))) {
18352: if ($hoststr eq '') {
18353: $hoststr = $part;
18354: } else {
18355: $hoststr = "$part.$hoststr";
18356: }
18357: if ($hoststr eq $hostname) {
18358: push(@possok,$hostname);
18359: } else {
18360: push(@possok,"*.$hoststr");
18361: }
18362: }
18363: if (@possok) {
18364: foreach my $poss (@possok) {
18365: last if (!$uselink);
18366: foreach my $policy (@policies) {
18367: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
18368: undef($uselink);
18369: last;
18370: }
18371: }
18372: }
18373: }
18374: }
18375: }
18376: }
18377: } elsif ($xframeop ne '') {
18378: $uselink = 1;
18379: my @policies = split(/\s*,\s*/,$xframeop);
18380: if (@policies) {
18381: unless (grep(/^deny$/,@policies)) {
18382: if ($origin ne '') {
18383: if (grep(/^sameorigin$/,@policies)) {
18384: if ($remotehost eq $origin) {
18385: undef($uselink);
18386: }
18387: }
18388: if ($uselink) {
18389: foreach my $policy (@policies) {
18390: if ($policy =~ /^allow-from\s*(.+)$/) {
18391: my $allowfrom = $1;
18392: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
18393: undef($uselink);
18394: last;
18395: }
18396: }
18397: }
18398: }
18399: }
18400: }
18401: }
18402: }
18403: }
18404: }
1.1329 raeburn 18405: if ($nocache) {
18406: if ($cached) {
18407: my $devalidate;
18408: if ($uselink && !$result) {
18409: $devalidate = 1;
18410: } elsif (!$uselink && $result) {
18411: $devalidate = 1;
18412: }
18413: if ($devalidate) {
18414: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
18415: }
18416: }
18417: } else {
18418: if ($uselink) {
18419: $result = 1;
18420: } else {
18421: $result = 0;
18422: }
18423: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
18424: }
1.1328 raeburn 18425: return $uselink;
18426: }
18427:
1.112 bowersj2 18428: 1;
18429: __END__;
1.41 ng 18430:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>