Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.161.2.19
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1075.2.161. .19(raeb 4:-23): # $Id: loncommon.pm,v 1.1075.2.161.2.18 2023/09/06 16:09:14 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.1075.2.161. .7(raebu 64:22): use Apache::lonnavmaps();
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.1075.2.25 raeburn 70: use Apache::lonuserutils();
1.1075.2.27 raeburn 71: use Apache::lonuserstate();
1.1075.2.69 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1075.2.161. .13(raeb 74:-23): use LONCAPA::map();
1.1075.2.135 raeburn 75: use HTTP::Request;
1.657 raeburn 76: use DateTime::TimeZone;
1.1075.2.102 raeburn 77: use DateTime::Locale;
1.1075.2.94 raeburn 78: use Encode();
1.1075.2.14 raeburn 79: use Authen::Captcha;
80: use Captcha::reCAPTCHA;
1.1075.2.107 raeburn 81: use JSON::DWIW;
82: use LWP::UserAgent;
1.1075.2.64 raeburn 83: use Crypt::DES;
84: use DynaLoader; # for Crypt::DES version
1.1075.2.128 raeburn 85: use File::Copy();
86: use File::Path();
1.1075.2.161. .1(raebu 87:21): use String::CRC32();
88:21): use Short::URL();
1.117 www 89:
1.517 raeburn 90: # ---------------------------------------------- Designs
91: use vars qw(%defaultdesign);
92:
1.22 www 93: my $readit;
94:
1.517 raeburn 95:
1.157 matthew 96: ##
97: ## Global Variables
98: ##
1.46 matthew 99:
1.643 foxr 100:
101: # ----------------------------------------------- SSI with retries:
102: #
103:
104: =pod
105:
1.648 raeburn 106: =head1 Server Side include with retries:
1.643 foxr 107:
108: =over 4
109:
1.648 raeburn 110: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 111:
112: Performs an ssi with some number of retries. Retries continue either
113: until the result is ok or until the retry count supplied by the
114: caller is exhausted.
115:
116: Inputs:
1.648 raeburn 117:
118: =over 4
119:
1.643 foxr 120: resource - Identifies the resource to insert.
1.648 raeburn 121:
1.643 foxr 122: retries - Count of the number of retries allowed.
1.648 raeburn 123:
1.643 foxr 124: form - Hash that identifies the rendering options.
125:
1.648 raeburn 126: =back
127:
128: Returns:
129:
130: =over 4
131:
1.643 foxr 132: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 133:
1.643 foxr 134: response - The response from the last attempt (which may or may not have been successful.
135:
1.648 raeburn 136: =back
137:
138: =back
139:
1.643 foxr 140: =cut
141:
142: sub ssi_with_retries {
143: my ($resource, $retries, %form) = @_;
144:
145:
146: my $ok = 0; # True if we got a good response.
147: my $content;
148: my $response;
149:
150: # Try to get the ssi done. within the retries count:
151:
152: do {
153: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
154: $ok = $response->is_success;
1.650 www 155: if (!$ok) {
156: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
157: }
1.643 foxr 158: $retries--;
159: } while (!$ok && ($retries > 0));
160:
161: if (!$ok) {
162: $content = ''; # On error return an empty content.
163: }
164: return ($content, $response);
165:
166: }
167:
168:
169:
1.20 www 170: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 171: my %language;
1.124 www 172: my %supported_language;
1.1048 foxr 173: my %latex_language; # For choosing hyphenation in <transl..>
174: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 175: my %cprtag;
1.192 taceyjo1 176: my %scprtag;
1.351 www 177: my %fe; my %fd; my %fm;
1.41 ng 178: my %category_extensions;
1.12 harris41 179:
1.46 matthew 180: # ---------------------------------------------- Thesaurus variables
1.144 matthew 181: #
182: # %Keywords:
183: # A hash used by &keyword to determine if a word is considered a keyword.
184: # $thesaurus_db_file
185: # Scalar containing the full path to the thesaurus database.
1.46 matthew 186:
187: my %Keywords;
188: my $thesaurus_db_file;
189:
1.144 matthew 190: #
191: # Initialize values from language.tab, copyright.tab, filetypes.tab,
192: # thesaurus.tab, and filecategories.tab.
193: #
1.18 www 194: BEGIN {
1.46 matthew 195: # Variable initialization
196: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
197: #
1.22 www 198: unless ($readit) {
1.12 harris41 199: # ------------------------------------------------------------------- languages
200: {
1.158 raeburn 201: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
202: '/language.tab';
1.1075.2.128 raeburn 203: if ( open(my $fh,'<',$langtabfile) ) {
1.356 albertel 204: while (my $line = <$fh>) {
205: next if ($line=~/^\#/);
206: chomp($line);
1.1048 foxr 207: my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 208: $language{$key}=$val.' - '.$enc;
209: if ($sup) {
210: $supported_language{$key}=$sup;
211: }
1.1048 foxr 212: if ($latex) {
213: $latex_language_bykey{$key} = $latex;
214: $latex_language{$two} = $latex;
215: }
1.158 raeburn 216: }
217: close($fh);
218: }
1.12 harris41 219: }
220: # ------------------------------------------------------------------ copyrights
221: {
1.158 raeburn 222: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
223: '/copyright.tab';
1.1075.2.128 raeburn 224: if ( open (my $fh,'<',$copyrightfile) ) {
1.356 albertel 225: while (my $line = <$fh>) {
226: next if ($line=~/^\#/);
227: chomp($line);
228: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 229: $cprtag{$key}=$val;
230: }
231: close($fh);
232: }
1.12 harris41 233: }
1.351 www 234: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 235: {
236: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
237: '/source_copyright.tab';
1.1075.2.128 raeburn 238: if ( open (my $fh,'<',$sourcecopyrightfile) ) {
1.356 albertel 239: while (my $line = <$fh>) {
240: next if ($line =~ /^\#/);
241: chomp($line);
242: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 243: $scprtag{$key}=$val;
244: }
245: close($fh);
246: }
247: }
1.63 www 248:
1.517 raeburn 249: # -------------------------------------------------------------- default domain designs
1.63 www 250: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 251: my $designfile = $designdir.'/default.tab';
1.1075.2.128 raeburn 252: if ( open (my $fh,'<',$designfile) ) {
1.517 raeburn 253: while (my $line = <$fh>) {
254: next if ($line =~ /^\#/);
255: chomp($line);
256: my ($key,$val)=(split(/\=/,$line));
257: if ($val) { $defaultdesign{$key}=$val; }
258: }
259: close($fh);
1.63 www 260: }
261:
1.15 harris41 262: # ------------------------------------------------------------- file categories
263: {
1.158 raeburn 264: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
265: '/filecategories.tab';
1.1075.2.128 raeburn 266: if ( open (my $fh,'<',$categoryfile) ) {
1.356 albertel 267: while (my $line = <$fh>) {
268: next if ($line =~ /^\#/);
269: chomp($line);
270: my ($extension,$category)=(split(/\s+/,$line,2));
1.1075.2.119 raeburn 271: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 272: }
273: close($fh);
274: }
275:
1.15 harris41 276: }
1.12 harris41 277: # ------------------------------------------------------------------ file types
278: {
1.158 raeburn 279: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
280: '/filetypes.tab';
1.1075.2.128 raeburn 281: if ( open (my $fh,'<',$typesfile) ) {
1.356 albertel 282: while (my $line = <$fh>) {
283: next if ($line =~ /^\#/);
284: chomp($line);
285: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 286: if ($descr ne '') {
287: $fe{$ending}=lc($emb);
288: $fd{$ending}=$descr;
1.351 www 289: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 290: }
291: }
292: close($fh);
293: }
1.12 harris41 294: }
1.22 www 295: &Apache::lonnet::logthis(
1.705 tempelho 296: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 297: $readit=1;
1.46 matthew 298: } # end of unless($readit)
1.32 matthew 299:
300: }
1.112 bowersj2 301:
1.42 matthew 302: ###############################################################
303: ## HTML and Javascript Helper Functions ##
304: ###############################################################
305:
306: =pod
307:
1.112 bowersj2 308: =head1 HTML and Javascript Functions
1.42 matthew 309:
1.112 bowersj2 310: =over 4
311:
1.648 raeburn 312: =item * &browser_and_searcher_javascript()
1.112 bowersj2 313:
314: X<browsing, javascript>X<searching, javascript>Returns a string
315: containing javascript with two functions, C<openbrowser> and
316: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
317: tags.
1.42 matthew 318:
1.648 raeburn 319: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 320:
321: inputs: formname, elementname, only, omit
322:
323: formname and elementname indicate the name of the html form and name of
324: the element that the results of the browsing selection are to be placed in.
325:
326: Specifying 'only' will restrict the browser to displaying only files
1.185 www 327: with the given extension. Can be a comma separated list.
1.42 matthew 328:
329: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 330: with the given extension. Can be a comma separated list.
1.42 matthew 331:
1.648 raeburn 332: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 333:
334: Inputs: formname, elementname
335:
336: formname and elementname specify the name of the html form and the name
337: of the element the selection from the search results will be placed in.
1.542 raeburn 338:
1.42 matthew 339: =cut
340:
341: sub browser_and_searcher_javascript {
1.199 albertel 342: my ($mode)=@_;
343: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 344: my $resurl=&escape_single(&lastresurl());
1.42 matthew 345: return <<END;
1.219 albertel 346: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 347: var editbrowser = null;
1.135 albertel 348: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 349: var url = '$resurl/?';
1.42 matthew 350: if (editbrowser == null) {
351: url += 'launch=1&';
352: }
353: url += 'catalogmode=interactive&';
1.199 albertel 354: url += 'mode=$mode&';
1.611 albertel 355: url += 'inhibitmenu=yes&';
1.42 matthew 356: url += 'form=' + formname + '&';
357: if (only != null) {
358: url += 'only=' + only + '&';
1.217 albertel 359: } else {
360: url += 'only=&';
361: }
1.42 matthew 362: if (omit != null) {
363: url += 'omit=' + omit + '&';
1.217 albertel 364: } else {
365: url += 'omit=&';
366: }
1.135 albertel 367: if (titleelement != null) {
368: url += 'titleelement=' + titleelement + '&';
1.217 albertel 369: } else {
370: url += 'titleelement=&';
371: }
1.42 matthew 372: url += 'element=' + elementname + '';
373: var title = 'Browser';
1.435 albertel 374: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 375: options += ',width=700,height=600';
376: editbrowser = open(url,title,options,'1');
377: editbrowser.focus();
378: }
379: var editsearcher;
1.135 albertel 380: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 381: var url = '/adm/searchcat?';
382: if (editsearcher == null) {
383: url += 'launch=1&';
384: }
385: url += 'catalogmode=interactive&';
1.199 albertel 386: url += 'mode=$mode&';
1.42 matthew 387: url += 'form=' + formname + '&';
1.135 albertel 388: if (titleelement != null) {
389: url += 'titleelement=' + titleelement + '&';
1.217 albertel 390: } else {
391: url += 'titleelement=&';
392: }
1.42 matthew 393: url += 'element=' + elementname + '';
394: var title = 'Search';
1.435 albertel 395: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 396: options += ',width=700,height=600';
397: editsearcher = open(url,title,options,'1');
398: editsearcher.focus();
399: }
1.219 albertel 400: // END LON-CAPA Internal -->
1.42 matthew 401: END
1.170 www 402: }
403:
404: sub lastresurl {
1.258 albertel 405: if ($env{'environment.lastresurl'}) {
406: return $env{'environment.lastresurl'}
1.170 www 407: } else {
408: return '/res';
409: }
410: }
411:
412: sub storeresurl {
413: my $resurl=&Apache::lonnet::clutter(shift);
414: unless ($resurl=~/^\/res/) { return 0; }
415: $resurl=~s/\/$//;
416: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 417: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 418: return 1;
1.42 matthew 419: }
420:
1.74 www 421: sub studentbrowser_javascript {
1.111 www 422: unless (
1.258 albertel 423: (($env{'request.course.id'}) &&
1.302 albertel 424: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
425: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
426: '/'.$env{'request.course.sec'})
427: ))
1.258 albertel 428: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 429: ) { return ''; }
1.74 www 430: return (<<'ENDSTDBRW');
1.776 bisitz 431: <script type="text/javascript" language="Javascript">
1.824 bisitz 432: // <![CDATA[
1.74 www 433: var stdeditbrowser;
1.1075.2.143 raeburn 434: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadv) {
1.74 www 435: var url = '/adm/pickstudent?';
436: var filter;
1.558 albertel 437: if (!ignorefilter) {
438: eval('filter=document.'+formname+'.'+uname+'.value;');
439: }
1.74 www 440: if (filter != null) {
441: if (filter != '') {
442: url += 'filter='+filter+'&';
443: }
444: }
445: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 446: '&udomelement='+udom+
447: '&clicker='+clicker;
1.111 www 448: if (roleflag) { url+="&roles=1"; }
1.1075.2.143 raeburn 449: if (courseadv == 'condition') {
450: if (document.getElementById('courseadv')) {
451: courseadv = document.getElementById('courseadv').value;
452: }
453: }
454: if ((courseadv == 'only') || (courseadv == 'none')) { url+="&courseadv="+courseadv; }
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.1075.2.143 raeburn 486: my ($form,$unameele,$udomele,$courseadv,$clickerid)=@_;
1.999 www 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.1075.2.143 raeburn 497: if ($courseadv eq 'only') {
498: $callargs .= ",'',1,'$courseadv'";
499: } elsif ($courseadv eq 'none') {
500: $callargs .= ",'','','$courseadv'";
501: } elsif ($courseadv eq 'condition') {
502: $callargs .= ",'','','$courseadv'";
1.793 raeburn 503: }
504: return '<span class="LC_nobreak">'.
505: '<a href="javascript:openstdbrowser('.$callargs.');">'.
506: &mt('Select User').'</a></span>';
1.74 www 507: }
1.258 albertel 508: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 509: $callargs .= ",'',1";
1.793 raeburn 510: return '<span class="LC_nobreak">'.
511: '<a href="javascript:openstdbrowser('.$callargs.');">'.
512: &mt('Select User').'</a></span>';
1.111 www 513: }
514: return '';
1.91 www 515: }
516:
1.1004 www 517: sub selectresource_link {
518: my ($form,$reslink,$arg)=@_;
519:
520: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
521: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
522: unless ($env{'request.course.id'}) { return $arg; }
523: return '<span class="LC_nobreak">'.
524: '<a href="javascript:openresbrowser('.$callargs.');">'.
525: $arg.'</a></span>';
526: }
527:
528:
529:
1.653 raeburn 530: sub authorbrowser_javascript {
531: return <<"ENDAUTHORBRW";
1.776 bisitz 532: <script type="text/javascript" language="JavaScript">
1.824 bisitz 533: // <![CDATA[
1.653 raeburn 534: var stdeditbrowser;
535:
536: function openauthorbrowser(formname,udom) {
537: var url = '/adm/pickauthor?';
538: url += 'form='+formname+'&roledom='+udom;
539: var title = 'Author_Browser';
540: var options = 'scrollbars=1,resizable=1,menubar=0';
541: options += ',width=700,height=600';
542: stdeditbrowser = open(url,title,options,'1');
543: stdeditbrowser.focus();
544: }
545:
1.824 bisitz 546: // ]]>
1.653 raeburn 547: </script>
548: ENDAUTHORBRW
549: }
550:
1.91 www 551: sub coursebrowser_javascript {
1.1075.2.31 raeburn 552: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1075.2.95 raeburn 553: $credits_element,$instcode) = @_;
1.932 raeburn 554: my $wintitle = 'Course_Browser';
1.931 raeburn 555: if ($crstype eq 'Community') {
1.932 raeburn 556: $wintitle = 'Community_Browser';
1.909 raeburn 557: }
1.876 raeburn 558: my $id_functions = &javascript_index_functions();
559: my $output = '
1.776 bisitz 560: <script type="text/javascript" language="JavaScript">
1.824 bisitz 561: // <![CDATA[
1.468 raeburn 562: var stdeditbrowser;'."\n";
1.876 raeburn 563:
564: $output .= <<"ENDSTDBRW";
1.909 raeburn 565: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 566: var url = '/adm/pickcourse?';
1.895 raeburn 567: var formid = getFormIdByName(formname);
1.876 raeburn 568: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 569: if (domainfilter != null) {
570: if (domainfilter != '') {
571: url += 'domainfilter='+domainfilter+'&';
572: }
573: }
1.91 www 574: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 575: '&cdomelement='+udom+
576: '&cnameelement='+desc;
1.468 raeburn 577: if (extra_element !=null && extra_element != '') {
1.594 raeburn 578: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 579: url += '&roleelement='+extra_element;
580: if (domainfilter == null || domainfilter == '') {
581: url += '&domainfilter='+extra_element;
582: }
1.234 raeburn 583: }
1.468 raeburn 584: else {
585: if (formname == 'portform') {
586: url += '&setroles='+extra_element;
1.800 raeburn 587: } else {
588: if (formname == 'rules') {
589: url += '&fixeddom='+extra_element;
590: }
1.468 raeburn 591: }
592: }
1.230 raeburn 593: }
1.909 raeburn 594: if (type != null && type != '') {
595: url += '&type='+type;
596: }
597: if (type_elem != null && type_elem != '') {
598: url += '&typeelement='+type_elem;
599: }
1.872 raeburn 600: if (formname == 'ccrs') {
601: var ownername = document.forms[formid].ccuname.value;
602: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1075.2.101 raeburn 603: url += '&cloner='+ownername+':'+ownerdom;
604: if (type == 'Course') {
605: url += '&crscode='+document.forms[formid].crscode.value;
606: }
1.1075.2.95 raeburn 607: }
608: if (formname == 'requestcrs') {
609: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 610: }
1.293 raeburn 611: if (multflag !=null && multflag != '') {
612: url += '&multiple='+multflag;
613: }
1.909 raeburn 614: var title = '$wintitle';
1.91 www 615: var options = 'scrollbars=1,resizable=1,menubar=0';
616: options += ',width=700,height=600';
617: stdeditbrowser = open(url,title,options,'1');
618: stdeditbrowser.focus();
619: }
1.876 raeburn 620: $id_functions
621: ENDSTDBRW
1.1075.2.31 raeburn 622: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
623: $output .= &setsec_javascript($sec_element,$formname,$role_element,
624: $credits_element);
1.876 raeburn 625: }
626: $output .= '
627: // ]]>
628: </script>';
629: return $output;
630: }
631:
632: sub javascript_index_functions {
633: return <<"ENDJS";
634:
635: function getFormIdByName(formname) {
636: for (var i=0;i<document.forms.length;i++) {
637: if (document.forms[i].name == formname) {
638: return i;
639: }
640: }
641: return -1;
642: }
643:
644: function getIndexByName(formid,item) {
645: for (var i=0;i<document.forms[formid].elements.length;i++) {
646: if (document.forms[formid].elements[i].name == item) {
647: return i;
648: }
649: }
650: return -1;
651: }
1.468 raeburn 652:
1.876 raeburn 653: function getDomainFromSelectbox(formname,udom) {
654: var userdom;
655: var formid = getFormIdByName(formname);
656: if (formid > -1) {
657: var domid = getIndexByName(formid,udom);
658: if (domid > -1) {
659: if (document.forms[formid].elements[domid].type == 'select-one') {
660: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
661: }
662: if (document.forms[formid].elements[domid].type == 'hidden') {
663: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 664: }
665: }
666: }
1.876 raeburn 667: return userdom;
668: }
669:
670: ENDJS
1.468 raeburn 671:
1.876 raeburn 672: }
673:
1.1017 raeburn 674: sub javascript_array_indexof {
1.1018 raeburn 675: return <<ENDJS;
1.1017 raeburn 676: <script type="text/javascript" language="JavaScript">
677: // <![CDATA[
678:
679: if (!Array.prototype.indexOf) {
680: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
681: "use strict";
682: if (this === void 0 || this === null) {
683: throw new TypeError();
684: }
685: var t = Object(this);
686: var len = t.length >>> 0;
687: if (len === 0) {
688: return -1;
689: }
690: var n = 0;
691: if (arguments.length > 0) {
692: n = Number(arguments[1]);
693: if (n !== n) { // shortcut for verifying if it's NaN
694: n = 0;
695: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
696: n = (n > 0 || -1) * Math.floor(Math.abs(n));
697: }
698: }
699: if (n >= len) {
700: return -1;
701: }
702: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
703: for (; k < len; k++) {
704: if (k in t && t[k] === searchElement) {
705: return k;
706: }
707: }
708: return -1;
709: }
710: }
711:
712: // ]]>
713: </script>
714:
715: ENDJS
716:
717: }
718:
1.876 raeburn 719: sub userbrowser_javascript {
720: my $id_functions = &javascript_index_functions();
721: return <<"ENDUSERBRW";
722:
1.888 raeburn 723: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 724: var url = '/adm/pickuser?';
725: var userdom = getDomainFromSelectbox(formname,udom);
726: if (userdom != null) {
727: if (userdom != '') {
728: url += 'srchdom='+userdom+'&';
729: }
730: }
731: url += 'form=' + formname + '&unameelement='+uname+
732: '&udomelement='+udom+
733: '&ulastelement='+ulast+
734: '&ufirstelement='+ufirst+
735: '&uemailelement='+uemail+
1.881 raeburn 736: '&hideudomelement='+hideudom+
737: '&coursedom='+crsdom;
1.888 raeburn 738: if ((caller != null) && (caller != undefined)) {
739: url += '&caller='+caller;
740: }
1.876 raeburn 741: var title = 'User_Browser';
742: var options = 'scrollbars=1,resizable=1,menubar=0';
743: options += ',width=700,height=600';
744: var stdeditbrowser = open(url,title,options,'1');
745: stdeditbrowser.focus();
746: }
747:
1.888 raeburn 748: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 749: var formid = getFormIdByName(formname);
750: if (formid > -1) {
1.888 raeburn 751: var unameid = getIndexByName(formid,uname);
1.876 raeburn 752: var domid = getIndexByName(formid,udom);
753: var hidedomid = getIndexByName(formid,origdom);
754: if (hidedomid > -1) {
755: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 756: var unameval = document.forms[formid].elements[unameid].value;
757: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
758: if (domid > -1) {
759: var slct = document.forms[formid].elements[domid];
760: if (slct.type == 'select-one') {
761: var i;
762: for (i=0;i<slct.length;i++) {
763: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
764: }
765: }
766: if (slct.type == 'hidden') {
767: slct.value = fixeddom;
1.876 raeburn 768: }
769: }
1.468 raeburn 770: }
771: }
772: }
1.876 raeburn 773: return;
774: }
775:
776: $id_functions
777: ENDUSERBRW
1.468 raeburn 778: }
779:
780: sub setsec_javascript {
1.1075.2.31 raeburn 781: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 782: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
783: $communityrolestr);
784: if ($role_element ne '') {
785: my @allroles = ('st','ta','ep','in','ad');
786: foreach my $crstype ('Course','Community') {
787: if ($crstype eq 'Community') {
788: foreach my $role (@allroles) {
789: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
790: }
791: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
792: } else {
793: foreach my $role (@allroles) {
794: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
795: }
796: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
797: }
798: }
799: $rolestr = '"'.join('","',@allroles).'"';
800: $courserolestr = '"'.join('","',@courserolenames).'"';
801: $communityrolestr = '"'.join('","',@communityrolenames).'"';
802: }
1.468 raeburn 803: my $setsections = qq|
804: function setSect(sectionlist) {
1.629 raeburn 805: var sectionsArray = new Array();
806: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
807: sectionsArray = sectionlist.split(",");
808: }
1.468 raeburn 809: var numSections = sectionsArray.length;
810: document.$formname.$sec_element.length = 0;
811: if (numSections == 0) {
812: document.$formname.$sec_element.multiple=false;
813: document.$formname.$sec_element.size=1;
814: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
815: } else {
816: if (numSections == 1) {
817: document.$formname.$sec_element.multiple=false;
818: document.$formname.$sec_element.size=1;
819: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
820: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
821: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
822: } else {
823: for (var i=0; i<numSections; i++) {
824: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
825: }
826: document.$formname.$sec_element.multiple=true
827: if (numSections < 3) {
828: document.$formname.$sec_element.size=numSections;
829: } else {
830: document.$formname.$sec_element.size=3;
831: }
832: document.$formname.$sec_element.options[0].selected = false
833: }
834: }
1.91 www 835: }
1.905 raeburn 836:
837: function setRole(crstype) {
1.468 raeburn 838: |;
1.905 raeburn 839: if ($role_element eq '') {
840: $setsections .= ' return;
841: }
842: ';
843: } else {
844: $setsections .= qq|
845: var elementLength = document.$formname.$role_element.length;
846: var allroles = Array($rolestr);
847: var courserolenames = Array($courserolestr);
848: var communityrolenames = Array($communityrolestr);
849: if (elementLength != undefined) {
850: if (document.$formname.$role_element.options[5].value == 'cc') {
851: if (crstype == 'Course') {
852: return;
853: } else {
854: allroles[5] = 'co';
855: for (var i=0; i<6; i++) {
856: document.$formname.$role_element.options[i].value = allroles[i];
857: document.$formname.$role_element.options[i].text = communityrolenames[i];
858: }
859: }
860: } else {
861: if (crstype == 'Community') {
862: return;
863: } else {
864: allroles[5] = 'cc';
865: for (var i=0; i<6; i++) {
866: document.$formname.$role_element.options[i].value = allroles[i];
867: document.$formname.$role_element.options[i].text = courserolenames[i];
868: }
869: }
870: }
871: }
872: return;
873: }
874: |;
875: }
1.1075.2.31 raeburn 876: if ($credits_element) {
877: $setsections .= qq|
878: function setCredits(defaultcredits) {
879: document.$formname.$credits_element.value = defaultcredits;
880: return;
881: }
882: |;
883: }
1.468 raeburn 884: return $setsections;
885: }
886:
1.91 www 887: sub selectcourse_link {
1.909 raeburn 888: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
889: $typeelement) = @_;
890: my $type = $selecttype;
1.871 raeburn 891: my $linktext = &mt('Select Course');
892: if ($selecttype eq 'Community') {
1.909 raeburn 893: $linktext = &mt('Select Community');
1.906 raeburn 894: } elsif ($selecttype eq 'Course/Community') {
895: $linktext = &mt('Select Course/Community');
1.909 raeburn 896: $type = '';
1.1019 raeburn 897: } elsif ($selecttype eq 'Select') {
898: $linktext = &mt('Select');
899: $type = '';
1.871 raeburn 900: }
1.787 bisitz 901: return '<span class="LC_nobreak">'
902: ."<a href='"
903: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
904: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 905: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 906: ."'>".$linktext.'</a>'
1.787 bisitz 907: .'</span>';
1.74 www 908: }
1.42 matthew 909:
1.653 raeburn 910: sub selectauthor_link {
911: my ($form,$udom)=@_;
912: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
913: &mt('Select Author').'</a>';
914: }
915:
1.876 raeburn 916: sub selectuser_link {
1.881 raeburn 917: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 918: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 919: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 920: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 921: ');">'.$linktext.'</a>';
1.876 raeburn 922: }
923:
1.273 raeburn 924: sub check_uncheck_jscript {
925: my $jscript = <<"ENDSCRT";
926: function checkAll(field) {
927: if (field.length > 0) {
928: for (i = 0; i < field.length; i++) {
1.1075.2.14 raeburn 929: if (!field[i].disabled) {
930: field[i].checked = true;
931: }
1.273 raeburn 932: }
933: } else {
1.1075.2.14 raeburn 934: if (!field.disabled) {
935: field.checked = true;
936: }
1.273 raeburn 937: }
938: }
939:
940: function uncheckAll(field) {
941: if (field.length > 0) {
942: for (i = 0; i < field.length; i++) {
943: field[i].checked = false ;
1.543 albertel 944: }
945: } else {
1.273 raeburn 946: field.checked = false ;
947: }
948: }
949: ENDSCRT
950: return $jscript;
951: }
952:
1.656 www 953: sub select_timezone {
1.1075.2.161. .10(raeb 954:-22): my ($name,$selected,$onchange,$includeempty,$id,$disabled)=@_;
955:-22): my $output='<select name="'.$name.'" '.$id.$onchange.$disabled.'>'."\n";
1.659 raeburn 956: if ($includeempty) {
957: $output .= '<option value=""';
958: if (($selected eq '') || ($selected eq 'local')) {
959: $output .= ' selected="selected" ';
960: }
961: $output .= '> </option>';
962: }
1.657 raeburn 963: my @timezones = DateTime::TimeZone->all_names;
964: foreach my $tzone (@timezones) {
965: $output.= '<option value="'.$tzone.'"';
966: if ($tzone eq $selected) {
967: $output.=' selected="selected"';
968: }
969: $output.=">$tzone</option>\n";
1.656 www 970: }
971: $output.="</select>";
972: return $output;
973: }
1.273 raeburn 974:
1.687 raeburn 975: sub select_datelocale {
1.1075.2.115 raeburn 976: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
977: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 978: if ($includeempty) {
979: $output .= '<option value=""';
980: if ($selected eq '') {
981: $output .= ' selected="selected" ';
982: }
983: $output .= '> </option>';
984: }
1.1075.2.102 raeburn 985: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 986: my (@possibles,%locale_names);
1.1075.2.102 raeburn 987: my @locales = DateTime::Locale->ids();
988: foreach my $id (@locales) {
989: if ($id ne '') {
990: my ($en_terr,$native_terr);
991: my $loc = DateTime::Locale->load($id);
992: if (ref($loc)) {
993: $en_terr = $loc->name();
994: $native_terr = $loc->native_name();
1.687 raeburn 995: if (grep(/^en$/,@languages) || !@languages) {
996: if ($en_terr ne '') {
997: $locale_names{$id} = '('.$en_terr.')';
998: } elsif ($native_terr ne '') {
999: $locale_names{$id} = $native_terr;
1000: }
1001: } else {
1002: if ($native_terr ne '') {
1003: $locale_names{$id} = $native_terr.' ';
1004: } elsif ($en_terr ne '') {
1005: $locale_names{$id} = '('.$en_terr.')';
1006: }
1007: }
1.1075.2.94 raeburn 1008: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1075.2.102 raeburn 1009: push(@possibles,$id);
1.687 raeburn 1010: }
1011: }
1012: }
1013: foreach my $item (sort(@possibles)) {
1014: $output.= '<option value="'.$item.'"';
1015: if ($item eq $selected) {
1016: $output.=' selected="selected"';
1017: }
1018: $output.=">$item";
1019: if ($locale_names{$item} ne '') {
1.1075.2.94 raeburn 1020: $output.=' '.$locale_names{$item};
1.687 raeburn 1021: }
1022: $output.="</option>\n";
1023: }
1024: $output.="</select>";
1025: return $output;
1026: }
1027:
1.792 raeburn 1028: sub select_language {
1.1075.2.115 raeburn 1029: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1030: my %langchoices;
1031: if ($includeempty) {
1.1075.2.32 raeburn 1032: %langchoices = ('' => 'No language preference');
1.792 raeburn 1033: }
1034: foreach my $id (&languageids()) {
1035: my $code = &supportedlanguagecode($id);
1036: if ($code) {
1037: $langchoices{$code} = &plainlanguagedescription($id);
1038: }
1039: }
1.1075.2.32 raeburn 1040: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1075.2.115 raeburn 1041: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1042: }
1043:
1.42 matthew 1044: =pod
1.36 matthew 1045:
1.648 raeburn 1046: =item * &linked_select_forms(...)
1.36 matthew 1047:
1048: linked_select_forms returns a string containing a <script></script> block
1049: and html for two <select> menus. The select menus will be linked in that
1050: changing the value of the first menu will result in new values being placed
1051: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1052: order unless a defined order is provided.
1.36 matthew 1053:
1054: linked_select_forms takes the following ordered inputs:
1055:
1056: =over 4
1057:
1.112 bowersj2 1058: =item * $formname, the name of the <form> tag
1.36 matthew 1059:
1.112 bowersj2 1060: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1061:
1.112 bowersj2 1062: =item * $firstdefault, the default value for the first menu
1.36 matthew 1063:
1.112 bowersj2 1064: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1065:
1.112 bowersj2 1066: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1067:
1.112 bowersj2 1068: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1069:
1.609 raeburn 1070: =item * $menuorder, the order of values in the first menu
1071:
1.1075.2.31 raeburn 1072: =item * $onchangefirst, additional javascript call to execute for an onchange
1073: event for the first <select> tag
1074:
1075: =item * $onchangesecond, additional javascript call to execute for an onchange
1076: event for the second <select> tag
1077:
1.41 ng 1078: =back
1079:
1.36 matthew 1080: Below is an example of such a hash. Only the 'text', 'default', and
1081: 'select2' keys must appear as stated. keys(%menu) are the possible
1082: values for the first select menu. The text that coincides with the
1.41 ng 1083: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1084: and text for the second menu are given in the hash pointed to by
1085: $menu{$choice1}->{'select2'}.
1086:
1.112 bowersj2 1087: my %menu = ( A1 => { text =>"Choice A1" ,
1088: default => "B3",
1089: select2 => {
1090: B1 => "Choice B1",
1091: B2 => "Choice B2",
1092: B3 => "Choice B3",
1093: B4 => "Choice B4"
1.609 raeburn 1094: },
1095: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1096: },
1097: A2 => { text =>"Choice A2" ,
1098: default => "C2",
1099: select2 => {
1100: C1 => "Choice C1",
1101: C2 => "Choice C2",
1102: C3 => "Choice C3"
1.609 raeburn 1103: },
1104: order => ['C2','C1','C3'],
1.112 bowersj2 1105: },
1106: A3 => { text =>"Choice A3" ,
1107: default => "D6",
1108: select2 => {
1109: D1 => "Choice D1",
1110: D2 => "Choice D2",
1111: D3 => "Choice D3",
1112: D4 => "Choice D4",
1113: D5 => "Choice D5",
1114: D6 => "Choice D6",
1115: D7 => "Choice D7"
1.609 raeburn 1116: },
1117: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1118: }
1119: );
1.36 matthew 1120:
1121: =cut
1122:
1123: sub linked_select_forms {
1124: my ($formname,
1125: $middletext,
1126: $firstdefault,
1127: $firstselectname,
1128: $secondselectname,
1.609 raeburn 1129: $hashref,
1130: $menuorder,
1.1075.2.31 raeburn 1131: $onchangefirst,
1132: $onchangesecond
1.36 matthew 1133: ) = @_;
1134: my $second = "document.$formname.$secondselectname";
1135: my $first = "document.$formname.$firstselectname";
1136: # output the javascript to do the changing
1137: my $result = '';
1.776 bisitz 1138: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1139: $result.="// <![CDATA[\n";
1.36 matthew 1140: $result.="var select2data = new Object();\n";
1141: $" = '","';
1142: my $debug = '';
1143: foreach my $s1 (sort(keys(%$hashref))) {
1144: $result.="select2data.d_$s1 = new Object();\n";
1145: $result.="select2data.d_$s1.def = new String('".
1146: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1147: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1148: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1149: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1150: @s2values = @{$hashref->{$s1}->{'order'}};
1151: }
1.36 matthew 1152: $result.="\"@s2values\");\n";
1153: $result.="select2data.d_$s1.texts = new Array(";
1154: my @s2texts;
1155: foreach my $value (@s2values) {
1.1075.2.119 raeburn 1156: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1157: }
1158: $result.="\"@s2texts\");\n";
1159: }
1160: $"=' ';
1161: $result.= <<"END";
1162:
1163: function select1_changed() {
1164: // Determine new choice
1165: var newvalue = "d_" + $first.value;
1166: // update select2
1167: var values = select2data[newvalue].values;
1168: var texts = select2data[newvalue].texts;
1169: var select2def = select2data[newvalue].def;
1170: var i;
1171: // out with the old
1172: for (i = 0; i < $second.options.length; i++) {
1173: $second.options[i] = null;
1174: }
1175: // in with the nuclear
1176: for (i=0;i<values.length; i++) {
1177: $second.options[i] = new Option(values[i]);
1.143 matthew 1178: $second.options[i].value = values[i];
1.36 matthew 1179: $second.options[i].text = texts[i];
1180: if (values[i] == select2def) {
1181: $second.options[i].selected = true;
1182: }
1183: }
1184: }
1.824 bisitz 1185: // ]]>
1.36 matthew 1186: </script>
1187: END
1188: # output the initial values for the selection lists
1.1075.2.31 raeburn 1189: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1190: my @order = sort(keys(%{$hashref}));
1191: if (ref($menuorder) eq 'ARRAY') {
1192: @order = @{$menuorder};
1193: }
1194: foreach my $value (@order) {
1.36 matthew 1195: $result.=" <option value=\"$value\" ";
1.253 albertel 1196: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1197: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1198: }
1199: $result .= "</select>\n";
1200: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1201: $result .= $middletext;
1.1075.2.31 raeburn 1202: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1203: if ($onchangesecond) {
1204: $result .= ' onchange="'.$onchangesecond.'"';
1205: }
1206: $result .= ">\n";
1.36 matthew 1207: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1208:
1209: my @secondorder = sort(keys(%select2));
1210: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1211: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1212: }
1213: foreach my $value (@secondorder) {
1.36 matthew 1214: $result.=" <option value=\"$value\" ";
1.253 albertel 1215: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1216: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1217: }
1218: $result .= "</select>\n";
1219: # return $debug;
1220: return $result;
1221: } # end of sub linked_select_forms {
1222:
1.45 matthew 1223: =pod
1.44 bowersj2 1224:
1.1075.2.161. .6(raebu 1225:22): =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid,$links_target)
1.44 bowersj2 1226:
1.112 bowersj2 1227: Returns a string corresponding to an HTML link to the given help
1228: $topic, where $topic corresponds to the name of a .tex file in
1229: /home/httpd/html/adm/help/tex, with underscores replaced by
1230: spaces.
1231:
1232: $text will optionally be linked to the same topic, allowing you to
1233: link text in addition to the graphic. If you do not want to link
1234: text, but wish to specify one of the later parameters, pass an
1235: empty string.
1236:
1237: $stayOnPage is a value that will be interpreted as a boolean. If true,
1238: the link will not open a new window. If false, the link will open
1239: a new window using Javascript. (Default is false.)
1240:
1241: $width and $height are optional numerical parameters that will
1242: override the width and height of the popped up window, which may
1.973 raeburn 1243: be useful for certain help topics with big pictures included.
1244:
1245: $imgid is the id of the img tag used for the help icon. This may be
1246: used in a javascript call to switch the image src. See
1247: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1248:
1.1075.2.161. .6(raebu 1249:22): $links_target will optionally be set to a target (_top, _parent or _self).
1250:22):
1.44 bowersj2 1251: =cut
1252:
1253: sub help_open_topic {
1.1075.2.161. .6(raebu 1254:22): my ($topic, $text, $stayOnPage, $width, $height, $imgid, $links_target) = @_;
1.48 bowersj2 1255: $text = "" if (not defined $text);
1.44 bowersj2 1256: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1257: $width = 500 if (not defined $width);
1.44 bowersj2 1258: $height = 400 if (not defined $height);
1259: my $filename = $topic;
1260: $filename =~ s/ /_/g;
1261:
1.48 bowersj2 1262: my $template = "";
1263: my $link;
1.572 banghart 1264:
1.159 www 1265: $topic=~s/\W/\_/g;
1.44 bowersj2 1266:
1.572 banghart 1267: if (!$stayOnPage) {
1.1075.2.50 raeburn 1268: if ($env{'browser.mobile'}) {
1269: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1270: } else {
1271: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1272: }
1.1037 www 1273: } elsif ($stayOnPage eq 'popup') {
1274: $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 1275: } else {
1.48 bowersj2 1276: $link = "/adm/help/${filename}.hlp";
1277: }
1278:
1279: # Add the text
1.1075.2.161. .6(raebu 1280:22): my $target = ' target="_top"';
1281:22): if ($links_target) {
1282:22): $target = ' target="'.$links_target.'"';
.17(raeb 1283:-23): } elsif ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
1284:-23): (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
.6(raebu 1285:22): $target = '';
1286:22): }
1.755 neumanie 1287: if ($text ne "") {
1.763 bisitz 1288: $template.='<span class="LC_help_open_topic">'
1.1075.2.161. .6(raebu 1289:22): .'<a'.$target.' href="'.$link.'">'
1.763 bisitz 1290: .$text.'</a>';
1.48 bowersj2 1291: }
1292:
1.763 bisitz 1293: # (Always) Add the graphic
1.179 matthew 1294: my $title = &mt('Online Help');
1.667 raeburn 1295: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1296: if ($imgid ne '') {
1297: $imgid = ' id="'.$imgid.'"';
1298: }
1.1075.2.161. .6(raebu 1299:22): $template.=' <a'.$target.' href="'.$link.'" title="'.$title.'">'
1.763 bisitz 1300: .'<img src="'.$helpicon.'" border="0"'
1301: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1302: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1303: .' /></a>';
1304: if ($text ne "") {
1305: $template.='</span>';
1306: }
1.44 bowersj2 1307: return $template;
1308:
1.106 bowersj2 1309: }
1310:
1311: # This is a quicky function for Latex cheatsheet editing, since it
1312: # appears in at least four places
1313: sub helpLatexCheatsheet {
1.1037 www 1314: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1315: my $out;
1.106 bowersj2 1316: my $addOther = '';
1.732 raeburn 1317: if ($topic) {
1.1037 www 1318: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1319: }
1320: $out = '<span>' # Start cheatsheet
1321: .$addOther
1322: .'<span>'
1.1037 www 1323: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1324: .'</span> <span>'
1.1037 www 1325: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1326: .'</span>';
1.732 raeburn 1327: unless ($not_author) {
1.763 bisitz 1328: $out .= ' <span>'
1.1037 www 1329: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1330: .'</span> <span>'
1.1075.2.78 raeburn 1331: .&help_open_topic('Authoring_Multilingual_Problems',&mt('Languages'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1332: .'</span>';
1.732 raeburn 1333: }
1.763 bisitz 1334: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1335: return $out;
1.172 www 1336: }
1337:
1.430 albertel 1338: sub general_help {
1339: my $helptopic='Student_Intro';
1340: if ($env{'request.role'}=~/^(ca|au)/) {
1341: $helptopic='Authoring_Intro';
1.907 raeburn 1342: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1343: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1344: } elsif ($env{'request.role'}=~/^dc/) {
1345: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1346: }
1347: return $helptopic;
1348: }
1349:
1350: sub update_help_link {
1351: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1352: my $origurl = $ENV{'REQUEST_URI'};
1353: $origurl=~s|^/~|/priv/|;
1354: my $timestamp = time;
1355: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1356: $$datum = &escape($$datum);
1357: }
1358:
1359: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1360: my $output .= <<"ENDOUTPUT";
1361: <script type="text/javascript">
1.824 bisitz 1362: // <![CDATA[
1.430 albertel 1363: banner_link = '$banner_link';
1.824 bisitz 1364: // ]]>
1.430 albertel 1365: </script>
1366: ENDOUTPUT
1367: return $output;
1368: }
1369:
1370: # now just updates the help link and generates a blue icon
1.193 raeburn 1371: sub help_open_menu {
1.1075.2.161. .6(raebu 1372:22): my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text,$links_target)
1.552 banghart 1373: = @_;
1.949 droeschl 1374: $stayOnPage = 1;
1.430 albertel 1375: my $output;
1376: if ($component_help) {
1377: if (!$text) {
1378: $output=&help_open_topic($component_help,undef,$stayOnPage,
1.1075.2.161. .6(raebu 1379:22): $width,$height,'',$links_target);
1.430 albertel 1380: } else {
1381: my $help_text;
1382: $help_text=&unescape($topic);
1383: $output='<table><tr><td>'.
1384: &help_open_topic($component_help,$help_text,$stayOnPage,
1.1075.2.161. .6(raebu 1385:22): $width,$height,'',$links_target).'</td></tr></table>';
1.430 albertel 1386: }
1387: }
1388: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1389: return $output.$banner_link;
1390: }
1391:
1392: sub top_nav_help {
1.1075.2.158 raeburn 1393: my ($text,$linkattr) = @_;
1.436 albertel 1394: $text = &mt($text);
1.1075.2.60 raeburn 1395: my $stay_on_page;
1396: unless ($env{'environment.remote'} eq 'on') {
1397: $stay_on_page = 1;
1398: }
1.1075.2.61 raeburn 1399: my ($link,$banner_link);
1400: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1401: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1402: : "javascript:helpMenu('open')";
1403: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1404: }
1.201 raeburn 1405: my $title = &mt('Get help');
1.1075.2.61 raeburn 1406: if ($link) {
1407: return <<"END";
1.436 albertel 1408: $banner_link
1.1075.2.158 raeburn 1409: <a href="$link" title="$title" $linkattr>$text</a>
1.436 albertel 1410: END
1.1075.2.61 raeburn 1411: } else {
1412: return ' '.$text.' ';
1413: }
1.436 albertel 1414: }
1415:
1416: sub help_menu_js {
1.1075.2.52 raeburn 1417: my ($httphost) = @_;
1.949 droeschl 1418: my $stayOnPage = 1;
1.436 albertel 1419: my $width = 620;
1420: my $height = 600;
1.430 albertel 1421: my $helptopic=&general_help();
1.1075.2.52 raeburn 1422: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1423: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1424: my $start_page =
1425: &Apache::loncommon::start_page('Help Menu', undef,
1426: {'frameset' => 1,
1427: 'js_ready' => 1,
1.1075.2.136 raeburn 1428: 'use_absolute' => $httphost,
1.331 albertel 1429: 'add_entries' => {
1430: 'border' => '0',
1.579 raeburn 1431: 'rows' => "110,*",},});
1.331 albertel 1432: my $end_page =
1433: &Apache::loncommon::end_page({'frameset' => 1,
1434: 'js_ready' => 1,});
1435:
1.436 albertel 1436: my $template .= <<"ENDTEMPLATE";
1437: <script type="text/javascript">
1.877 bisitz 1438: // <![CDATA[
1.253 albertel 1439: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1440: var banner_link = '';
1.243 raeburn 1441: function helpMenu(target) {
1442: var caller = this;
1443: if (target == 'open') {
1444: var newWindow = null;
1445: try {
1.262 albertel 1446: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1447: }
1448: catch(error) {
1449: writeHelp(caller);
1450: return;
1451: }
1452: if (newWindow) {
1453: caller = newWindow;
1454: }
1.193 raeburn 1455: }
1.243 raeburn 1456: writeHelp(caller);
1457: return;
1458: }
1459: function writeHelp(caller) {
1.1075.2.61 raeburn 1460: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1461: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1462: caller.document.close();
1463: caller.focus();
1.193 raeburn 1464: }
1.877 bisitz 1465: // END LON-CAPA Internal -->
1.253 albertel 1466: // ]]>
1.436 albertel 1467: </script>
1.193 raeburn 1468: ENDTEMPLATE
1469: return $template;
1470: }
1471:
1.172 www 1472: sub help_open_bug {
1473: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1474: unless ($env{'user.adv'}) { return ''; }
1.172 www 1475: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1476: $text = "" if (not defined $text);
1477: $stayOnPage=1;
1.184 albertel 1478: $width = 600 if (not defined $width);
1479: $height = 600 if (not defined $height);
1.172 www 1480:
1481: $topic=~s/\W+/\+/g;
1482: my $link='';
1483: my $template='';
1.379 albertel 1484: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1485: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1486: if (!$stayOnPage)
1487: {
1488: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1489: }
1490: else
1491: {
1492: $link = $url;
1493: }
1.1075.2.161. .6(raebu 1494:22):
1495:22): my $target = '_top';
1496:22): if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
1497:22): (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
1498:22): $target = '_blank';
1499:22): }
1500:22):
1.172 www 1501: # Add the text
1502: if ($text ne "")
1503: {
1504: $template .=
1505: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.1075.2.161. .6(raebu 1506:22): "<td bgcolor='#FF5555'><a target=\"$target\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1507: }
1508:
1509: # Add the graphic
1.179 matthew 1510: my $title = &mt('Report a Bug');
1.215 albertel 1511: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1512: $template .= <<"ENDTEMPLATE";
1.1075.2.161. .6(raebu 1513:22): <a target="$target" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1514: ENDTEMPLATE
1515: if ($text ne '') { $template.='</td></tr></table>' };
1516: return $template;
1517:
1518: }
1519:
1520: sub help_open_faq {
1521: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1522: unless ($env{'user.adv'}) { return ''; }
1.172 www 1523: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1524: $text = "" if (not defined $text);
1525: $stayOnPage=1;
1526: $width = 350 if (not defined $width);
1527: $height = 400 if (not defined $height);
1528:
1529: $topic=~s/\W+/\+/g;
1530: my $link='';
1531: my $template='';
1532: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1533: if (!$stayOnPage)
1534: {
1535: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1536: }
1537: else
1538: {
1539: $link = $url;
1540: }
1541:
1542: # Add the text
1543: if ($text ne "")
1544: {
1545: $template .=
1.173 www 1546: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1547: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1548: }
1549:
1550: # Add the graphic
1.179 matthew 1551: my $title = &mt('View the FAQ');
1.215 albertel 1552: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1553: $template .= <<"ENDTEMPLATE";
1.436 albertel 1554: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1555: ENDTEMPLATE
1556: if ($text ne '') { $template.='</td></tr></table>' };
1557: return $template;
1558:
1.44 bowersj2 1559: }
1.37 matthew 1560:
1.180 matthew 1561: ###############################################################
1562: ###############################################################
1563:
1.45 matthew 1564: =pod
1565:
1.648 raeburn 1566: =item * &change_content_javascript():
1.256 matthew 1567:
1568: This and the next function allow you to create small sections of an
1569: otherwise static HTML page that you can update on the fly with
1570: Javascript, even in Netscape 4.
1571:
1572: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1573: must be written to the HTML page once. It will prove the Javascript
1574: function "change(name, content)". Calling the change function with the
1575: name of the section
1576: you want to update, matching the name passed to C<changable_area>, and
1577: the new content you want to put in there, will put the content into
1578: that area.
1579:
1580: B<Note>: Netscape 4 only reserves enough space for the changable area
1581: to contain room for the original contents. You need to "make space"
1582: for whatever changes you wish to make, and be B<sure> to check your
1583: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1584: it's adequate for updating a one-line status display, but little more.
1585: This script will set the space to 100% width, so you only need to
1586: worry about height in Netscape 4.
1587:
1588: Modern browsers are much less limiting, and if you can commit to the
1589: user not using Netscape 4, this feature may be used freely with
1590: pretty much any HTML.
1591:
1592: =cut
1593:
1594: sub change_content_javascript {
1595: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1596: if ($env{'browser.type'} eq 'netscape' &&
1597: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1598: return (<<NETSCAPE4);
1599: function change(name, content) {
1600: doc = document.layers[name+"___escape"].layers[0].document;
1601: doc.open();
1602: doc.write(content);
1603: doc.close();
1604: }
1605: NETSCAPE4
1606: } else {
1607: # Otherwise, we need to use semi-standards-compliant code
1608: # (technically, "innerHTML" isn't standard but the equivalent
1609: # is really scary, and every useful browser supports it
1610: return (<<DOMBASED);
1611: function change(name, content) {
1612: element = document.getElementById(name);
1613: element.innerHTML = content;
1614: }
1615: DOMBASED
1616: }
1617: }
1618:
1619: =pod
1620:
1.648 raeburn 1621: =item * &changable_area($name,$origContent):
1.256 matthew 1622:
1623: This provides a "changable area" that can be modified on the fly via
1624: the Javascript code provided in C<change_content_javascript>. $name is
1625: the name you will use to reference the area later; do not repeat the
1626: same name on a given HTML page more then once. $origContent is what
1627: the area will originally contain, which can be left blank.
1628:
1629: =cut
1630:
1631: sub changable_area {
1632: my ($name, $origContent) = @_;
1633:
1.258 albertel 1634: if ($env{'browser.type'} eq 'netscape' &&
1635: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1636: # If this is netscape 4, we need to use the Layer tag
1637: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1638: } else {
1639: return "<span id='$name'>$origContent</span>";
1640: }
1641: }
1642:
1643: =pod
1644:
1.648 raeburn 1645: =item * &viewport_geometry_js
1.590 raeburn 1646:
1647: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1648:
1649: =cut
1650:
1651:
1652: sub viewport_geometry_js {
1653: return <<"GEOMETRY";
1654: var Geometry = {};
1655: function init_geometry() {
1656: if (Geometry.init) { return };
1657: Geometry.init=1;
1658: if (window.innerHeight) {
1659: Geometry.getViewportHeight = function() { return window.innerHeight; };
1660: Geometry.getViewportWidth = function() { return window.innerWidth; };
1661: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1662: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1663: }
1664: else if (document.documentElement && document.documentElement.clientHeight) {
1665: Geometry.getViewportHeight =
1666: function() { return document.documentElement.clientHeight; };
1667: Geometry.getViewportWidth =
1668: function() { return document.documentElement.clientWidth; };
1669:
1670: Geometry.getHorizontalScroll =
1671: function() { return document.documentElement.scrollLeft; };
1672: Geometry.getVerticalScroll =
1673: function() { return document.documentElement.scrollTop; };
1674: }
1675: else if (document.body.clientHeight) {
1676: Geometry.getViewportHeight =
1677: function() { return document.body.clientHeight; };
1678: Geometry.getViewportWidth =
1679: function() { return document.body.clientWidth; };
1680: Geometry.getHorizontalScroll =
1681: function() { return document.body.scrollLeft; };
1682: Geometry.getVerticalScroll =
1683: function() { return document.body.scrollTop; };
1684: }
1685: }
1686:
1687: GEOMETRY
1688: }
1689:
1690: =pod
1691:
1.648 raeburn 1692: =item * &viewport_size_js()
1.590 raeburn 1693:
1694: 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.
1695:
1696: =cut
1697:
1698: sub viewport_size_js {
1699: my $geometry = &viewport_geometry_js();
1700: return <<"DIMS";
1701:
1702: $geometry
1703:
1704: function getViewportDims(width,height) {
1705: init_geometry();
1706: width.value = Geometry.getViewportWidth();
1707: height.value = Geometry.getViewportHeight();
1708: return;
1709: }
1710:
1711: DIMS
1712: }
1713:
1714: =pod
1715:
1.648 raeburn 1716: =item * &resize_textarea_js()
1.565 albertel 1717:
1718: emits the needed javascript to resize a textarea to be as big as possible
1719:
1720: creates a function resize_textrea that takes two IDs first should be
1721: the id of the element to resize, second should be the id of a div that
1722: surrounds everything that comes after the textarea, this routine needs
1723: to be attached to the <body> for the onload and onresize events.
1724:
1.648 raeburn 1725: =back
1.565 albertel 1726:
1727: =cut
1728:
1729: sub resize_textarea_js {
1.590 raeburn 1730: my $geometry = &viewport_geometry_js();
1.565 albertel 1731: return <<"RESIZE";
1732: <script type="text/javascript">
1.824 bisitz 1733: // <![CDATA[
1.590 raeburn 1734: $geometry
1.565 albertel 1735:
1.588 albertel 1736: function getX(element) {
1737: var x = 0;
1738: while (element) {
1739: x += element.offsetLeft;
1740: element = element.offsetParent;
1741: }
1742: return x;
1743: }
1744: function getY(element) {
1745: var y = 0;
1746: while (element) {
1747: y += element.offsetTop;
1748: element = element.offsetParent;
1749: }
1750: return y;
1751: }
1752:
1753:
1.565 albertel 1754: function resize_textarea(textarea_id,bottom_id) {
1755: init_geometry();
1756: var textarea = document.getElementById(textarea_id);
1757: //alert(textarea);
1758:
1.588 albertel 1759: var textarea_top = getY(textarea);
1.565 albertel 1760: var textarea_height = textarea.offsetHeight;
1761: var bottom = document.getElementById(bottom_id);
1.588 albertel 1762: var bottom_top = getY(bottom);
1.565 albertel 1763: var bottom_height = bottom.offsetHeight;
1764: var window_height = Geometry.getViewportHeight();
1.588 albertel 1765: var fudge = 23;
1.565 albertel 1766: var new_height = window_height-fudge-textarea_top-bottom_height;
1767: if (new_height < 300) {
1768: new_height = 300;
1769: }
1770: textarea.style.height=new_height+'px';
1771: }
1.824 bisitz 1772: // ]]>
1.565 albertel 1773: </script>
1774: RESIZE
1775:
1776: }
1777:
1.1075.2.112 raeburn 1778: sub colorfuleditor_js {
1779: return <<"COLORFULEDIT"
1780: <script type="text/javascript">
1781: // <![CDATA[>
1782: function fold_box(curDepth, lastresource){
1783:
1784: // we need a list because there can be several blocks you need to fold in one tag
1785: var block = document.getElementsByName('foldblock_'+curDepth);
1786: // but there is only one folding button per tag
1787: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1788:
1789: if(block.item(0).style.display == 'none'){
1790:
1791: foldbutton.value = '@{[&mt("Hide")]}';
1792: for (i = 0; i < block.length; i++){
1793: block.item(i).style.display = '';
1794: }
1795: }else{
1796:
1797: foldbutton.value = '@{[&mt("Show")]}';
1798: for (i = 0; i < block.length; i++){
1799: // block.item(i).style.visibility = 'collapse';
1800: block.item(i).style.display = 'none';
1801: }
1802: };
1803: saveState(lastresource);
1804: }
1805:
1806: function saveState (lastresource) {
1807:
1808: var tag_list = getTagList();
1809: if(tag_list != null){
1810: var timestamp = new Date().getTime();
1811: var key = lastresource;
1812:
1813: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1814: // starting with timestamp
1815: var value = timestamp+';';
1816:
1817: // building the list of key-value pairs
1818: for(var i = 0; i < tag_list.length; i++){
1819: value += tag_list[i]+',';
1820: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1821: }
1822:
1823: // only iterate whole storage if nothing to override
1824: if(localStorage.getItem(key) == null){
1825:
1826: // prevent storage from growing large
1827: if(localStorage.length > 50){
1828: var regex_getTimestamp = /^(?:\d)+;/;
1829: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1830: var oldest_key;
1831:
1832: for(var i = 1; i < localStorage.length; i++){
1833: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1834: oldest_key = localStorage.key(i);
1835: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1836: }
1837: }
1838: localStorage.removeItem(oldest_key);
1839: }
1840: }
1841: localStorage.setItem(key,value);
1842: }
1843: }
1844:
1845: // restore folding status of blocks (on page load)
1846: function restoreState (lastresource) {
1847: if(localStorage.getItem(lastresource) != null){
1848: var key = lastresource;
1849: var value = localStorage.getItem(key);
1850: var regex_delTimestamp = /^\d+;/;
1851:
1852: value.replace(regex_delTimestamp, '');
1853:
1854: var valueArr = value.split(';');
1855: var pairs;
1856: var elements;
1857: for (var i = 0; i < valueArr.length; i++){
1858: pairs = valueArr[i].split(',');
1859: elements = document.getElementsByName(pairs[0]);
1860:
1861: for (var j = 0; j < elements.length; j++){
1862: elements[j].style.display = pairs[1];
1863: if (pairs[1] == "none"){
1864: var regex_id = /([_\\d]+)\$/;
1865: regex_id.exec(pairs[0]);
1866: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
1867: }
1868: }
1869: }
1870: }
1871: }
1872:
1873: function getTagList () {
1874:
1875: var stringToSearch = document.lonhomework.innerHTML;
1876:
1877: var ret = new Array();
1878: var regex_findBlock = /(foldblock_.*?)"/g;
1879: var tag_list = stringToSearch.match(regex_findBlock);
1880:
1881: if(tag_list != null){
1882: for(var i = 0; i < tag_list.length; i++){
1883: ret.push(tag_list[i].replace(/"/, ''));
1884: }
1885: }
1886: return ret;
1887: }
1888:
1889: function saveScrollPosition (resource) {
1890: var tag_list = getTagList();
1891:
1892: // we dont always want to jump to the first block
1893: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
1894: if(\$(window).scrollTop() > 170){
1895: if(tag_list != null){
1896: var result;
1897: for(var i = 0; i < tag_list.length; i++){
1898: if(isElementInViewport(tag_list[i])){
1899: result += tag_list[i]+';';
1900: }
1901: }
1902: sessionStorage.setItem('anchor_'+resource, result);
1903: }
1904: } else {
1905: // we dont need to save zero, just delete the item to leave everything tidy
1906: sessionStorage.removeItem('anchor_'+resource);
1907: }
1908: }
1909:
1910: function restoreScrollPosition(resource){
1911:
1912: var elem = sessionStorage.getItem('anchor_'+resource);
1913: if(elem != null){
1914: var tag_list = elem.split(';');
1915: var elem_list;
1916:
1917: for(var i = 0; i < tag_list.length; i++){
1918: elem_list = document.getElementsByName(tag_list[i]);
1919:
1920: if(elem_list.length > 0){
1921: elem = elem_list[0];
1922: break;
1923: }
1924: }
1925: elem.scrollIntoView();
1926: }
1927: }
1928:
1929: function isElementInViewport(el) {
1930:
1931: // change to last element instead of first
1932: var elem = document.getElementsByName(el);
1933: var rect = elem[0].getBoundingClientRect();
1934:
1935: return (
1936: rect.top >= 0 &&
1937: rect.left >= 0 &&
1938: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1939: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1940: );
1941: }
1942:
1943: function autosize(depth){
1944: var cmInst = window['cm'+depth];
1945: var fitsizeButton = document.getElementById('fitsize'+depth);
1946:
1947: // is fixed size, switching to dynamic
1948: if (sessionStorage.getItem("autosized_"+depth) == null) {
1949: cmInst.setSize("","auto");
1950: fitsizeButton.value = "@{[&mt('Fixed size')]}";
1951: sessionStorage.setItem("autosized_"+depth, "yes");
1952:
1953: // is dynamic size, switching to fixed
1954: } else {
1955: cmInst.setSize("","300px");
1956: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
1957: sessionStorage.removeItem("autosized_"+depth);
1958: }
1959: }
1960:
1961:
1962:
1963: // ]]>
1964: </script>
1965: COLORFULEDIT
1966: }
1967:
1968: sub xmleditor_js {
1969: return <<XMLEDIT
1970: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
1971: <script type="text/javascript">
1972: // <![CDATA[>
1973:
1974: function saveScrollPosition (resource) {
1975:
1976: var scrollPos = \$(window).scrollTop();
1977: sessionStorage.setItem(resource,scrollPos);
1978: }
1979:
1980: function restoreScrollPosition(resource){
1981:
1982: var scrollPos = sessionStorage.getItem(resource);
1983: \$(window).scrollTop(scrollPos);
1984: }
1985:
1986: // unless internet explorer
1987: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
1988:
1989: \$(document).ready(function() {
1990: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
1991: });
1992: }
1993:
1994: // inserts text at cursor position into codemirror (xml editor only)
1995: function insertText(text){
1996: cm.focus();
1997: var curPos = cm.getCursor();
1998: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
1999: }
2000: // ]]>
2001: </script>
2002: XMLEDIT
2003: }
2004:
2005: sub insert_folding_button {
2006: my $curDepth = $Apache::lonxml::curdepth;
2007: my $lastresource = $env{'request.ambiguous'};
2008:
2009: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2010: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2011: }
2012:
2013:
1.565 albertel 2014: =pod
2015:
1.256 matthew 2016: =head1 Excel and CSV file utility routines
2017:
2018: =cut
2019:
2020: ###############################################################
2021: ###############################################################
2022:
2023: =pod
2024:
1.1075.2.56 raeburn 2025: =over 4
2026:
1.648 raeburn 2027: =item * &csv_translate($text)
1.37 matthew 2028:
1.185 www 2029: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2030: format.
2031:
2032: =cut
2033:
1.180 matthew 2034: ###############################################################
2035: ###############################################################
1.37 matthew 2036: sub csv_translate {
2037: my $text = shift;
2038: $text =~ s/\"/\"\"/g;
1.209 albertel 2039: $text =~ s/\n/ /g;
1.37 matthew 2040: return $text;
2041: }
1.180 matthew 2042:
2043: ###############################################################
2044: ###############################################################
2045:
2046: =pod
2047:
1.648 raeburn 2048: =item * &define_excel_formats()
1.180 matthew 2049:
2050: Define some commonly used Excel cell formats.
2051:
2052: Currently supported formats:
2053:
2054: =over 4
2055:
2056: =item header
2057:
2058: =item bold
2059:
2060: =item h1
2061:
2062: =item h2
2063:
2064: =item h3
2065:
1.256 matthew 2066: =item h4
2067:
2068: =item i
2069:
1.180 matthew 2070: =item date
2071:
2072: =back
2073:
2074: Inputs: $workbook
2075:
2076: Returns: $format, a hash reference.
2077:
1.1057 foxr 2078:
1.180 matthew 2079: =cut
2080:
2081: ###############################################################
2082: ###############################################################
2083: sub define_excel_formats {
2084: my ($workbook) = @_;
2085: my $format;
2086: $format->{'header'} = $workbook->add_format(bold => 1,
2087: bottom => 1,
2088: align => 'center');
2089: $format->{'bold'} = $workbook->add_format(bold=>1);
2090: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2091: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2092: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2093: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2094: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2095: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2096: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2097: return $format;
2098: }
2099:
2100: ###############################################################
2101: ###############################################################
1.113 bowersj2 2102:
2103: =pod
2104:
1.648 raeburn 2105: =item * &create_workbook()
1.255 matthew 2106:
2107: Create an Excel worksheet. If it fails, output message on the
2108: request object and return undefs.
2109:
2110: Inputs: Apache request object
2111:
2112: Returns (undef) on failure,
2113: Excel worksheet object, scalar with filename, and formats
2114: from &Apache::loncommon::define_excel_formats on success
2115:
2116: =cut
2117:
2118: ###############################################################
2119: ###############################################################
2120: sub create_workbook {
2121: my ($r) = @_;
2122: #
2123: # Create the excel spreadsheet
2124: my $filename = '/prtspool/'.
1.258 albertel 2125: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2126: time.'_'.rand(1000000000).'.xls';
2127: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2128: if (! defined($workbook)) {
2129: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2130: $r->print(
2131: '<p class="LC_error">'
2132: .&mt('Problems occurred in creating the new Excel file.')
2133: .' '.&mt('This error has been logged.')
2134: .' '.&mt('Please alert your LON-CAPA administrator.')
2135: .'</p>'
2136: );
1.255 matthew 2137: return (undef);
2138: }
2139: #
1.1014 foxr 2140: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2141: #
2142: my $format = &Apache::loncommon::define_excel_formats($workbook);
2143: return ($workbook,$filename,$format);
2144: }
2145:
2146: ###############################################################
2147: ###############################################################
2148:
2149: =pod
2150:
1.648 raeburn 2151: =item * &create_text_file()
1.113 bowersj2 2152:
1.542 raeburn 2153: Create a file to write to and eventually make available to the user.
1.256 matthew 2154: If file creation fails, outputs an error message on the request object and
2155: return undefs.
1.113 bowersj2 2156:
1.256 matthew 2157: Inputs: Apache request object, and file suffix
1.113 bowersj2 2158:
1.256 matthew 2159: Returns (undef) on failure,
2160: Filehandle and filename on success.
1.113 bowersj2 2161:
2162: =cut
2163:
1.256 matthew 2164: ###############################################################
2165: ###############################################################
2166: sub create_text_file {
2167: my ($r,$suffix) = @_;
2168: if (! defined($suffix)) { $suffix = 'txt'; };
2169: my $fh;
2170: my $filename = '/prtspool/'.
1.258 albertel 2171: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2172: time.'_'.rand(1000000000).'.'.$suffix;
2173: $fh = Apache::File->new('>/home/httpd'.$filename);
2174: if (! defined($fh)) {
2175: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2176: $r->print(
2177: '<p class="LC_error">'
2178: .&mt('Problems occurred in creating the output file.')
2179: .' '.&mt('This error has been logged.')
2180: .' '.&mt('Please alert your LON-CAPA administrator.')
2181: .'</p>'
2182: );
1.113 bowersj2 2183: }
1.256 matthew 2184: return ($fh,$filename)
1.113 bowersj2 2185: }
2186:
2187:
1.256 matthew 2188: =pod
1.113 bowersj2 2189:
2190: =back
2191:
2192: =cut
1.37 matthew 2193:
2194: ###############################################################
1.33 matthew 2195: ## Home server <option> list generating code ##
2196: ###############################################################
1.35 matthew 2197:
1.169 www 2198: # ------------------------------------------
2199:
2200: sub domain_select {
2201: my ($name,$value,$multiple)=@_;
2202: my %domains=map {
1.514 albertel 2203: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2204: } &Apache::lonnet::all_domains();
1.169 www 2205: if ($multiple) {
2206: $domains{''}=&mt('Any domain');
1.550 albertel 2207: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2208: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2209: } else {
1.550 albertel 2210: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2211: return &select_form($name,$value,\%domains);
1.169 www 2212: }
2213: }
2214:
1.282 albertel 2215: #-------------------------------------------
2216:
2217: =pod
2218:
1.519 raeburn 2219: =head1 Routines for form select boxes
2220:
2221: =over 4
2222:
1.648 raeburn 2223: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2224:
2225: Returns a string containing a <select> element int multiple mode
2226:
2227:
2228: Args:
2229: $name - name of the <select> element
1.506 raeburn 2230: $value - scalar or array ref of values that should already be selected
1.282 albertel 2231: $size - number of rows long the select element is
1.283 albertel 2232: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2233: (shown text should already have been &mt())
1.506 raeburn 2234: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2235:
1.282 albertel 2236: =cut
2237:
2238: #-------------------------------------------
1.169 www 2239: sub multiple_select_form {
1.284 albertel 2240: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2241: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2242: my $output='';
1.191 matthew 2243: if (! defined($size)) {
2244: $size = 4;
1.283 albertel 2245: if (scalar(keys(%$hash))<4) {
2246: $size = scalar(keys(%$hash));
1.191 matthew 2247: }
2248: }
1.734 bisitz 2249: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2250: my @order;
1.506 raeburn 2251: if (ref($order) eq 'ARRAY') {
2252: @order = @{$order};
2253: } else {
2254: @order = sort(keys(%$hash));
1.501 banghart 2255: }
2256: if (exists($$hash{'select_form_order'})) {
2257: @order = @{$$hash{'select_form_order'}};
2258: }
2259:
1.284 albertel 2260: foreach my $key (@order) {
1.356 albertel 2261: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2262: $output.='selected="selected" ' if ($selected{$key});
2263: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2264: }
2265: $output.="</select>\n";
2266: return $output;
2267: }
2268:
1.88 www 2269: #-------------------------------------------
2270:
2271: =pod
2272:
1.1075.2.115 raeburn 2273: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2274:
2275: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2276: allow a user to select options from a ref to a hash containing:
2277: option_name => displayed text. An optional $onchange can include
1.1075.2.115 raeburn 2278: a javascript onchange item, e.g., onchange="this.form.submit();".
2279: An optional arg -- $readonly -- if true will cause the select form
2280: to be disabled, e.g., for the case where an instructor has a section-
2281: specific role, and is viewing/modifying parameters.
1.970 raeburn 2282:
1.88 www 2283: See lonrights.pm for an example invocation and use.
2284:
2285: =cut
2286:
2287: #-------------------------------------------
2288: sub select_form {
1.1075.2.115 raeburn 2289: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2290: return unless (ref($hashref) eq 'HASH');
2291: if ($onchange) {
2292: $onchange = ' onchange="'.$onchange.'"';
2293: }
1.1075.2.129 raeburn 2294: my $disabled;
2295: if ($readonly) {
2296: $disabled = ' disabled="disabled"';
2297: }
2298: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2299: my @keys;
1.970 raeburn 2300: if (exists($hashref->{'select_form_order'})) {
2301: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2302: } else {
1.970 raeburn 2303: @keys=sort(keys(%{$hashref}));
1.128 albertel 2304: }
1.356 albertel 2305: foreach my $key (@keys) {
2306: $selectform.=
2307: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2308: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2309: ">".$hashref->{$key}."</option>\n";
1.88 www 2310: }
2311: $selectform.="</select>";
2312: return $selectform;
2313: }
2314:
1.475 www 2315: # For display filters
2316:
2317: sub display_filter {
1.1074 raeburn 2318: my ($context) = @_;
1.475 www 2319: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2320: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2321: my $phraseinput = 'hidden';
2322: my $includeinput = 'hidden';
2323: my ($checked,$includetypestext);
2324: if ($env{'form.displayfilter'} eq 'containing') {
2325: $phraseinput = 'text';
2326: if ($context eq 'parmslog') {
2327: $includeinput = 'checkbox';
2328: if ($env{'form.includetypes'}) {
2329: $checked = ' checked="checked"';
2330: }
2331: $includetypestext = &mt('Include parameter types');
2332: }
2333: } else {
2334: $includetypestext = ' ';
2335: }
2336: my ($additional,$secondid,$thirdid);
2337: if ($context eq 'parmslog') {
2338: $additional =
2339: '<label><input type="'.$includeinput.'" name="includetypes"'.
2340: $checked.' name="includetypes" value="1" id="includetypes" />'.
2341: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2342: '</label>';
2343: $secondid = 'includetypes';
2344: $thirdid = 'includetypestext';
2345: }
2346: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2347: '$secondid','$thirdid')";
2348: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2349: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2350: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2351: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2352: &mt('Filter: [_1]',
1.477 www 2353: &select_form($env{'form.displayfilter'},
2354: 'displayfilter',
1.970 raeburn 2355: {'currentfolder' => 'Current folder/page',
1.477 www 2356: 'containing' => 'Containing phrase',
1.1074 raeburn 2357: 'none' => 'None'},$onchange)).' '.
2358: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2359: &HTML::Entities::encode($env{'form.containingphrase'}).
2360: '" />'.$additional;
2361: }
2362:
2363: sub display_filter_js {
2364: my $includetext = &mt('Include parameter types');
2365: return <<"ENDJS";
2366:
2367: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2368: var firstType = 'hidden';
2369: if (setter.options[setter.selectedIndex].value == 'containing') {
2370: firstType = 'text';
2371: }
2372: firstObject = document.getElementById(firstid);
2373: if (typeof(firstObject) == 'object') {
2374: if (firstObject.type != firstType) {
2375: changeInputType(firstObject,firstType);
2376: }
2377: }
2378: if (context == 'parmslog') {
2379: var secondType = 'hidden';
2380: if (firstType == 'text') {
2381: secondType = 'checkbox';
2382: }
2383: secondObject = document.getElementById(secondid);
2384: if (typeof(secondObject) == 'object') {
2385: if (secondObject.type != secondType) {
2386: changeInputType(secondObject,secondType);
2387: }
2388: }
2389: var textItem = document.getElementById(thirdid);
2390: var currtext = textItem.innerHTML;
2391: var newtext;
2392: if (firstType == 'text') {
2393: newtext = '$includetext';
2394: } else {
2395: newtext = ' ';
2396: }
2397: if (currtext != newtext) {
2398: textItem.innerHTML = newtext;
2399: }
2400: }
2401: return;
2402: }
2403:
2404: function changeInputType(oldObject,newType) {
2405: var newObject = document.createElement('input');
2406: newObject.type = newType;
2407: if (oldObject.size) {
2408: newObject.size = oldObject.size;
2409: }
2410: if (oldObject.value) {
2411: newObject.value = oldObject.value;
2412: }
2413: if (oldObject.name) {
2414: newObject.name = oldObject.name;
2415: }
2416: if (oldObject.id) {
2417: newObject.id = oldObject.id;
2418: }
2419: oldObject.parentNode.replaceChild(newObject,oldObject);
2420: return;
2421: }
2422:
2423: ENDJS
1.475 www 2424: }
2425:
1.167 www 2426: sub gradeleveldescription {
2427: my $gradelevel=shift;
2428: my %gradelevels=(0 => 'Not specified',
2429: 1 => 'Grade 1',
2430: 2 => 'Grade 2',
2431: 3 => 'Grade 3',
2432: 4 => 'Grade 4',
2433: 5 => 'Grade 5',
2434: 6 => 'Grade 6',
2435: 7 => 'Grade 7',
2436: 8 => 'Grade 8',
2437: 9 => 'Grade 9',
2438: 10 => 'Grade 10',
2439: 11 => 'Grade 11',
2440: 12 => 'Grade 12',
2441: 13 => 'Grade 13',
2442: 14 => '100 Level',
2443: 15 => '200 Level',
2444: 16 => '300 Level',
2445: 17 => '400 Level',
2446: 18 => 'Graduate Level');
2447: return &mt($gradelevels{$gradelevel});
2448: }
2449:
1.163 www 2450: sub select_level_form {
2451: my ($deflevel,$name)=@_;
2452: unless ($deflevel) { $deflevel=0; }
1.167 www 2453: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2454: for (my $i=0; $i<=18; $i++) {
2455: $selectform.="<option value=\"$i\" ".
1.253 albertel 2456: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2457: ">".&gradeleveldescription($i)."</option>\n";
2458: }
2459: $selectform.="</select>";
2460: return $selectform;
1.163 www 2461: }
1.167 www 2462:
1.35 matthew 2463: #-------------------------------------------
2464:
1.45 matthew 2465: =pod
2466:
1.1075.2.115 raeburn 2467: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2468:
2469: Returns a string containing a <select name='$name' size='1'> form to
2470: allow a user to select the domain to preform an operation in.
2471: See loncreateuser.pm for an example invocation and use.
2472:
1.90 www 2473: If the $includeempty flag is set, it also includes an empty choice ("no domain
2474: selected");
2475:
1.743 raeburn 2476: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2477:
1.910 raeburn 2478: 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.
2479:
1.1075.2.36 raeburn 2480: The optional $incdoms is a reference to an array of domains which will be the only available options.
2481:
1.1075.2.115 raeburn 2482: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
2483:
2484: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
1.563 raeburn 2485:
1.35 matthew 2486: =cut
2487:
2488: #-------------------------------------------
1.34 matthew 2489: sub select_dom_form {
1.1075.2.115 raeburn 2490: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2491: if ($onchange) {
1.874 raeburn 2492: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2493: }
1.1075.2.115 raeburn 2494: if ($disabled) {
2495: $disabled = ' disabled="disabled"';
2496: }
1.1075.2.36 raeburn 2497: my (@domains,%exclude);
1.910 raeburn 2498: if (ref($incdoms) eq 'ARRAY') {
2499: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2500: } else {
2501: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2502: }
1.90 www 2503: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2504: if (ref($excdoms) eq 'ARRAY') {
2505: map { $exclude{$_} = 1; } @{$excdoms};
2506: }
1.1075.2.115 raeburn 2507: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2508: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2509: next if ($exclude{$dom});
1.356 albertel 2510: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2511: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2512: if ($showdomdesc) {
2513: if ($dom ne '') {
2514: my $domdesc = &Apache::lonnet::domain($dom,'description');
2515: if ($domdesc ne '') {
2516: $selectdomain .= ' ('.$domdesc.')';
2517: }
2518: }
2519: }
2520: $selectdomain .= "</option>\n";
1.34 matthew 2521: }
2522: $selectdomain.="</select>";
2523: return $selectdomain;
2524: }
2525:
1.35 matthew 2526: #-------------------------------------------
2527:
1.45 matthew 2528: =pod
2529:
1.648 raeburn 2530: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2531:
1.586 raeburn 2532: input: 4 arguments (two required, two optional) -
2533: $domain - domain of new user
2534: $name - name of form element
2535: $default - Value of 'default' causes a default item to be first
2536: option, and selected by default.
2537: $hide - Value of 'hide' causes hiding of the name of the server,
2538: if 1 server found, or default, if 0 found.
1.594 raeburn 2539: output: returns 2 items:
1.586 raeburn 2540: (a) form element which contains either:
2541: (i) <select name="$name">
2542: <option value="$hostid1">$hostid $servers{$hostid}</option>
2543: <option value="$hostid2">$hostid $servers{$hostid}</option>
2544: </select>
2545: form item if there are multiple library servers in $domain, or
2546: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2547: if there is only one library server in $domain.
2548:
2549: (b) number of library servers found.
2550:
2551: See loncreateuser.pm for example of use.
1.35 matthew 2552:
2553: =cut
2554:
2555: #-------------------------------------------
1.586 raeburn 2556: sub home_server_form_item {
2557: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2558: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2559: my $result;
2560: my $numlib = keys(%servers);
2561: if ($numlib > 1) {
2562: $result .= '<select name="'.$name.'" />'."\n";
2563: if ($default) {
1.804 bisitz 2564: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2565: '</option>'."\n";
2566: }
2567: foreach my $hostid (sort(keys(%servers))) {
2568: $result.= '<option value="'.$hostid.'">'.
2569: $hostid.' '.$servers{$hostid}."</option>\n";
2570: }
2571: $result .= '</select>'."\n";
2572: } elsif ($numlib == 1) {
2573: my $hostid;
2574: foreach my $item (keys(%servers)) {
2575: $hostid = $item;
2576: }
2577: $result .= '<input type="hidden" name="'.$name.'" value="'.
2578: $hostid.'" />';
2579: if (!$hide) {
2580: $result .= $hostid.' '.$servers{$hostid};
2581: }
2582: $result .= "\n";
2583: } elsif ($default) {
2584: $result .= '<input type="hidden" name="'.$name.
2585: '" value="default" />';
2586: if (!$hide) {
2587: $result .= &mt('default');
2588: }
2589: $result .= "\n";
1.33 matthew 2590: }
1.586 raeburn 2591: return ($result,$numlib);
1.33 matthew 2592: }
1.112 bowersj2 2593:
2594: =pod
2595:
1.534 albertel 2596: =back
2597:
1.112 bowersj2 2598: =cut
1.87 matthew 2599:
2600: ###############################################################
1.112 bowersj2 2601: ## Decoding User Agent ##
1.87 matthew 2602: ###############################################################
2603:
2604: =pod
2605:
1.112 bowersj2 2606: =head1 Decoding the User Agent
2607:
2608: =over 4
2609:
2610: =item * &decode_user_agent()
1.87 matthew 2611:
2612: Inputs: $r
2613:
2614: Outputs:
2615:
2616: =over 4
2617:
1.112 bowersj2 2618: =item * $httpbrowser
1.87 matthew 2619:
1.112 bowersj2 2620: =item * $clientbrowser
1.87 matthew 2621:
1.112 bowersj2 2622: =item * $clientversion
1.87 matthew 2623:
1.112 bowersj2 2624: =item * $clientmathml
1.87 matthew 2625:
1.112 bowersj2 2626: =item * $clientunicode
1.87 matthew 2627:
1.112 bowersj2 2628: =item * $clientos
1.87 matthew 2629:
1.1075.2.42 raeburn 2630: =item * $clientmobile
2631:
2632: =item * $clientinfo
2633:
1.1075.2.77 raeburn 2634: =item * $clientosversion
2635:
1.87 matthew 2636: =back
2637:
1.157 matthew 2638: =back
2639:
1.87 matthew 2640: =cut
2641:
2642: ###############################################################
2643: ###############################################################
2644: sub decode_user_agent {
1.247 albertel 2645: my ($r)=@_;
1.87 matthew 2646: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2647: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2648: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2649: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2650: my $clientbrowser='unknown';
2651: my $clientversion='0';
2652: my $clientmathml='';
2653: my $clientunicode='0';
1.1075.2.42 raeburn 2654: my $clientmobile=0;
1.1075.2.77 raeburn 2655: my $clientosversion='';
1.87 matthew 2656: for (my $i=0;$i<=$#browsertype;$i++) {
1.1075.2.76 raeburn 2657: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2658: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2659: $clientbrowser=$bname;
2660: $httpbrowser=~/$vreg/i;
2661: $clientversion=$1;
2662: $clientmathml=($clientversion>=$minv);
2663: $clientunicode=($clientversion>=$univ);
2664: }
2665: }
2666: my $clientos='unknown';
1.1075.2.42 raeburn 2667: my $clientinfo;
1.87 matthew 2668: if (($httpbrowser=~/linux/i) ||
2669: ($httpbrowser=~/unix/i) ||
2670: ($httpbrowser=~/ux/i) ||
2671: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2672: if (($httpbrowser=~/vax/i) ||
2673: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2674: if ($httpbrowser=~/next/i) { $clientos='next'; }
2675: if (($httpbrowser=~/mac/i) ||
2676: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1075.2.77 raeburn 2677: if ($httpbrowser=~/win/i) {
2678: $clientos='win';
2679: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2680: $clientosversion = $1;
2681: }
2682: }
1.87 matthew 2683: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2684: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2685: $clientmobile=lc($1);
2686: }
2687: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2688: $clientinfo = 'firefox-'.$1;
2689: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2690: $clientinfo = 'chromeframe-'.$1;
2691: }
1.87 matthew 2692: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.77 raeburn 2693: $clientunicode,$clientos,$clientmobile,$clientinfo,
2694: $clientosversion);
1.87 matthew 2695: }
2696:
1.32 matthew 2697: ###############################################################
2698: ## Authentication changing form generation subroutines ##
2699: ###############################################################
2700: ##
2701: ## All of the authform_xxxxxxx subroutines take their inputs in a
2702: ## hash, and have reasonable default values.
2703: ##
2704: ## formname = the name given in the <form> tag.
1.35 matthew 2705: #-------------------------------------------
2706:
1.45 matthew 2707: =pod
2708:
1.112 bowersj2 2709: =head1 Authentication Routines
2710:
2711: =over 4
2712:
1.648 raeburn 2713: =item * &authform_xxxxxx()
1.35 matthew 2714:
2715: The authform_xxxxxx subroutines provide javascript and html forms which
2716: handle some of the conveniences required for authentication forms.
2717: This is not an optimal method, but it works.
2718:
2719: =over 4
2720:
1.112 bowersj2 2721: =item * authform_header
1.35 matthew 2722:
1.112 bowersj2 2723: =item * authform_authorwarning
1.35 matthew 2724:
1.112 bowersj2 2725: =item * authform_nochange
1.35 matthew 2726:
1.112 bowersj2 2727: =item * authform_kerberos
1.35 matthew 2728:
1.112 bowersj2 2729: =item * authform_internal
1.35 matthew 2730:
1.112 bowersj2 2731: =item * authform_filesystem
1.35 matthew 2732:
1.1075.2.161. .17(raeb 2733:-23): =item * authform_lti
2734:-23):
1.35 matthew 2735: =back
2736:
1.648 raeburn 2737: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2738:
1.35 matthew 2739: =cut
2740:
2741: #-------------------------------------------
1.32 matthew 2742: sub authform_header{
2743: my %in = (
2744: formname => 'cu',
1.80 albertel 2745: kerb_def_dom => '',
1.32 matthew 2746: @_,
2747: );
2748: $in{'formname'} = 'document.' . $in{'formname'};
2749: my $result='';
1.80 albertel 2750:
2751: #---------------------------------------------- Code for upper case translation
2752: my $Javascript_toUpperCase;
2753: unless ($in{kerb_def_dom}) {
2754: $Javascript_toUpperCase =<<"END";
2755: switch (choice) {
2756: case 'krb': currentform.elements[choicearg].value =
2757: currentform.elements[choicearg].value.toUpperCase();
2758: break;
2759: default:
2760: }
2761: END
2762: } else {
2763: $Javascript_toUpperCase = "";
2764: }
2765:
1.165 raeburn 2766: my $radioval = "'nochange'";
1.591 raeburn 2767: if (defined($in{'curr_authtype'})) {
2768: if ($in{'curr_authtype'} ne '') {
2769: $radioval = "'".$in{'curr_authtype'}."arg'";
2770: }
1.174 matthew 2771: }
1.165 raeburn 2772: my $argfield = 'null';
1.591 raeburn 2773: if (defined($in{'mode'})) {
1.165 raeburn 2774: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2775: if (defined($in{'curr_autharg'})) {
2776: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2777: $argfield = "'$in{'curr_autharg'}'";
2778: }
2779: }
2780: }
2781: }
2782:
1.32 matthew 2783: $result.=<<"END";
2784: var current = new Object();
1.165 raeburn 2785: current.radiovalue = $radioval;
2786: current.argfield = $argfield;
1.32 matthew 2787:
2788: function changed_radio(choice,currentform) {
2789: var choicearg = choice + 'arg';
2790: // If a radio button in changed, we need to change the argfield
2791: if (current.radiovalue != choice) {
2792: current.radiovalue = choice;
2793: if (current.argfield != null) {
2794: currentform.elements[current.argfield].value = '';
2795: }
2796: if (choice == 'nochange') {
2797: current.argfield = null;
2798: } else {
2799: current.argfield = choicearg;
2800: switch(choice) {
2801: case 'krb':
2802: currentform.elements[current.argfield].value =
2803: "$in{'kerb_def_dom'}";
2804: break;
2805: default:
2806: break;
2807: }
2808: }
2809: }
2810: return;
2811: }
1.22 www 2812:
1.32 matthew 2813: function changed_text(choice,currentform) {
2814: var choicearg = choice + 'arg';
2815: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2816: $Javascript_toUpperCase
1.32 matthew 2817: // clear old field
2818: if ((current.argfield != choicearg) && (current.argfield != null)) {
2819: currentform.elements[current.argfield].value = '';
2820: }
2821: current.argfield = choicearg;
2822: }
2823: set_auth_radio_buttons(choice,currentform);
2824: return;
1.20 www 2825: }
1.32 matthew 2826:
2827: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2828: var numauthchoices = currentform.login.length;
2829: if (typeof numauthchoices == "undefined") {
2830: return;
2831: }
1.32 matthew 2832: var i=0;
1.986 raeburn 2833: while (i < numauthchoices) {
1.32 matthew 2834: if (currentform.login[i].value == newvalue) { break; }
2835: i++;
2836: }
1.986 raeburn 2837: if (i == numauthchoices) {
1.32 matthew 2838: return;
2839: }
2840: current.radiovalue = newvalue;
2841: currentform.login[i].checked = true;
2842: return;
2843: }
2844: END
2845: return $result;
2846: }
2847:
1.1075.2.20 raeburn 2848: sub authform_authorwarning {
1.32 matthew 2849: my $result='';
1.144 matthew 2850: $result='<i>'.
2851: &mt('As a general rule, only authors or co-authors should be '.
2852: 'filesystem authenticated '.
2853: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2854: return $result;
2855: }
2856:
1.1075.2.20 raeburn 2857: sub authform_nochange {
1.32 matthew 2858: my %in = (
2859: formname => 'document.cu',
2860: kerb_def_dom => 'MSU.EDU',
2861: @_,
2862: );
1.1075.2.20 raeburn 2863: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2864: my $result;
1.1075.2.20 raeburn 2865: if (!$authnum) {
2866: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2867: } else {
2868: $result = '<label>'.&mt('[_1] Do not change login data',
2869: '<input type="radio" name="login" value="nochange" '.
2870: 'checked="checked" onclick="'.
1.281 albertel 2871: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2872: '</label>';
1.586 raeburn 2873: }
1.32 matthew 2874: return $result;
2875: }
2876:
1.591 raeburn 2877: sub authform_kerberos {
1.32 matthew 2878: my %in = (
2879: formname => 'document.cu',
2880: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2881: kerb_def_auth => 'krb4',
1.32 matthew 2882: @_,
2883: );
1.586 raeburn 2884: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1075.2.117 raeburn 2885: $autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2886: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2887: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2888: $check5 = ' checked="checked"';
1.80 albertel 2889: } else {
1.772 bisitz 2890: $check4 = ' checked="checked"';
1.80 albertel 2891: }
1.1075.2.117 raeburn 2892: if ($in{'readonly'}) {
2893: $disabled = ' disabled="disabled"';
2894: }
1.165 raeburn 2895: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2896: if (defined($in{'curr_authtype'})) {
2897: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2898: $krbcheck = ' checked="checked"';
1.623 raeburn 2899: if (defined($in{'mode'})) {
2900: if ($in{'mode'} eq 'modifyuser') {
2901: $krbcheck = '';
2902: }
2903: }
1.591 raeburn 2904: if (defined($in{'curr_kerb_ver'})) {
2905: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2906: $check5 = ' checked="checked"';
1.591 raeburn 2907: $check4 = '';
2908: } else {
1.772 bisitz 2909: $check4 = ' checked="checked"';
1.591 raeburn 2910: $check5 = '';
2911: }
1.586 raeburn 2912: }
1.591 raeburn 2913: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2914: $krbarg = $in{'curr_autharg'};
2915: }
1.586 raeburn 2916: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2917: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2918: $result =
2919: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2920: $in{'curr_autharg'},$krbver);
2921: } else {
2922: $result =
2923: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2924: }
2925: return $result;
2926: }
2927: }
2928: } else {
2929: if ($authnum == 1) {
1.784 bisitz 2930: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2931: }
2932: }
1.586 raeburn 2933: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2934: return;
1.587 raeburn 2935: } elsif ($authtype eq '') {
1.591 raeburn 2936: if (defined($in{'mode'})) {
1.587 raeburn 2937: if ($in{'mode'} eq 'modifycourse') {
2938: if ($authnum == 1) {
1.1075.2.117 raeburn 2939: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 2940: }
2941: }
2942: }
1.586 raeburn 2943: }
2944: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2945: if ($authtype eq '') {
2946: $authtype = '<input type="radio" name="login" value="krb" '.
2947: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1075.2.117 raeburn 2948: $krbcheck.$disabled.' />';
1.586 raeburn 2949: }
2950: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2951: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2952: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2953: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2954: $in{'curr_authtype'} eq 'krb4')) {
2955: $result .= &mt
1.144 matthew 2956: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2957: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2958: '<label>'.$authtype,
1.281 albertel 2959: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2960: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2961: 'onchange="'.$jscall.'"'.$disabled.' />',
2962: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
2963: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 2964: '</label>');
1.586 raeburn 2965: } elsif ($can_assign{'krb4'}) {
2966: $result .= &mt
2967: ('[_1] Kerberos authenticated with domain [_2] '.
2968: '[_3] Version 4 [_4]',
2969: '<label>'.$authtype,
2970: '</label><input type="text" size="10" name="krbarg" '.
2971: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2972: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2973: '<label><input type="hidden" name="krbver" value="4" />',
2974: '</label>');
2975: } elsif ($can_assign{'krb5'}) {
2976: $result .= &mt
2977: ('[_1] Kerberos authenticated with domain [_2] '.
2978: '[_3] Version 5 [_4]',
2979: '<label>'.$authtype,
2980: '</label><input type="text" size="10" name="krbarg" '.
2981: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2982: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2983: '<label><input type="hidden" name="krbver" value="5" />',
2984: '</label>');
2985: }
1.32 matthew 2986: return $result;
2987: }
2988:
1.1075.2.20 raeburn 2989: sub authform_internal {
1.586 raeburn 2990: my %in = (
1.32 matthew 2991: formname => 'document.cu',
2992: kerb_def_dom => 'MSU.EDU',
2993: @_,
2994: );
1.1075.2.117 raeburn 2995: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2996: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 2997: if ($in{'readonly'}) {
2998: $disabled = ' disabled="disabled"';
2999: }
1.591 raeburn 3000: if (defined($in{'curr_authtype'})) {
3001: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3002: if ($can_assign{'int'}) {
1.772 bisitz 3003: $intcheck = 'checked="checked" ';
1.623 raeburn 3004: if (defined($in{'mode'})) {
3005: if ($in{'mode'} eq 'modifyuser') {
3006: $intcheck = '';
3007: }
3008: }
1.591 raeburn 3009: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3010: $intarg = $in{'curr_autharg'};
3011: }
3012: } else {
3013: $result = &mt('Currently internally authenticated.');
3014: return $result;
1.165 raeburn 3015: }
3016: }
1.586 raeburn 3017: } else {
3018: if ($authnum == 1) {
1.784 bisitz 3019: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3020: }
3021: }
3022: if (!$can_assign{'int'}) {
3023: return;
1.587 raeburn 3024: } elsif ($authtype eq '') {
1.591 raeburn 3025: if (defined($in{'mode'})) {
1.587 raeburn 3026: if ($in{'mode'} eq 'modifycourse') {
3027: if ($authnum == 1) {
1.1075.2.117 raeburn 3028: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3029: }
3030: }
3031: }
1.165 raeburn 3032: }
1.586 raeburn 3033: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3034: if ($authtype eq '') {
3035: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1075.2.117 raeburn 3036: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3037: }
1.605 bisitz 3038: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1075.2.117 raeburn 3039: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3040: $result = &mt
1.144 matthew 3041: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3042: '<label>'.$authtype,'</label>'.$autharg);
1.1075.2.118 raeburn 3043: $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 3044: return $result;
3045: }
3046:
1.1075.2.20 raeburn 3047: sub authform_local {
1.32 matthew 3048: my %in = (
3049: formname => 'document.cu',
3050: kerb_def_dom => 'MSU.EDU',
3051: @_,
3052: );
1.1075.2.117 raeburn 3053: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3054: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3055: if ($in{'readonly'}) {
3056: $disabled = ' disabled="disabled"';
3057: }
1.591 raeburn 3058: if (defined($in{'curr_authtype'})) {
3059: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3060: if ($can_assign{'loc'}) {
1.772 bisitz 3061: $loccheck = 'checked="checked" ';
1.623 raeburn 3062: if (defined($in{'mode'})) {
3063: if ($in{'mode'} eq 'modifyuser') {
3064: $loccheck = '';
3065: }
3066: }
1.591 raeburn 3067: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3068: $locarg = $in{'curr_autharg'};
3069: }
3070: } else {
3071: $result = &mt('Currently using local (institutional) authentication.');
3072: return $result;
1.165 raeburn 3073: }
3074: }
1.586 raeburn 3075: } else {
3076: if ($authnum == 1) {
1.784 bisitz 3077: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3078: }
3079: }
3080: if (!$can_assign{'loc'}) {
3081: return;
1.587 raeburn 3082: } elsif ($authtype eq '') {
1.591 raeburn 3083: if (defined($in{'mode'})) {
1.587 raeburn 3084: if ($in{'mode'} eq 'modifycourse') {
3085: if ($authnum == 1) {
1.1075.2.117 raeburn 3086: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3087: }
3088: }
3089: }
1.165 raeburn 3090: }
1.586 raeburn 3091: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3092: if ($authtype eq '') {
3093: $authtype = '<input type="radio" name="login" value="loc" '.
3094: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3095: $jscall.'"'.$disabled.' />';
1.586 raeburn 3096: }
3097: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1075.2.117 raeburn 3098: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3099: $result = &mt('[_1] Local Authentication with argument [_2]',
3100: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3101: return $result;
3102: }
3103:
1.1075.2.20 raeburn 3104: sub authform_filesystem {
1.32 matthew 3105: my %in = (
3106: formname => 'document.cu',
3107: kerb_def_dom => 'MSU.EDU',
3108: @_,
3109: );
1.1075.2.117 raeburn 3110: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3111: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3112: if ($in{'readonly'}) {
3113: $disabled = ' disabled="disabled"';
3114: }
1.591 raeburn 3115: if (defined($in{'curr_authtype'})) {
3116: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3117: if ($can_assign{'fsys'}) {
1.772 bisitz 3118: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3119: if (defined($in{'mode'})) {
3120: if ($in{'mode'} eq 'modifyuser') {
3121: $fsyscheck = '';
3122: }
3123: }
1.586 raeburn 3124: } else {
3125: $result = &mt('Currently Filesystem Authenticated.');
3126: return $result;
3127: }
3128: }
3129: } else {
3130: if ($authnum == 1) {
1.784 bisitz 3131: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3132: }
3133: }
3134: if (!$can_assign{'fsys'}) {
3135: return;
1.587 raeburn 3136: } elsif ($authtype eq '') {
1.591 raeburn 3137: if (defined($in{'mode'})) {
1.587 raeburn 3138: if ($in{'mode'} eq 'modifycourse') {
3139: if ($authnum == 1) {
1.1075.2.117 raeburn 3140: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3141: }
3142: }
3143: }
1.586 raeburn 3144: }
3145: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3146: if ($authtype eq '') {
3147: $authtype = '<input type="radio" name="login" value="fsys" '.
3148: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3149: $jscall.'"'.$disabled.' />';
1.586 raeburn 3150: }
1.1075.2.158 raeburn 3151: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1075.2.117 raeburn 3152: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3153: $result = &mt
1.144 matthew 3154: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1075.2.158 raeburn 3155: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3156: return $result;
3157: }
3158:
1.1075.2.161. .17(raeb 3159:-23): sub authform_lti {
3160:-23): my %in = (
3161:-23): formname => 'document.cu',
3162:-23): kerb_def_dom => 'MSU.EDU',
3163:-23): @_,
3164:-23): );
3165:-23): my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);
3166:-23): my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
3167:-23): if ($in{'readonly'}) {
3168:-23): $disabled = ' disabled="disabled"';
3169:-23): }
3170:-23): if (defined($in{'curr_authtype'})) {
3171:-23): if ($in{'curr_authtype'} eq 'lti') {
3172:-23): if ($can_assign{'lti'}) {
3173:-23): $lticheck = 'checked="checked" ';
3174:-23): if (defined($in{'mode'})) {
3175:-23): if ($in{'mode'} eq 'modifyuser') {
3176:-23): $lticheck = '';
3177:-23): }
3178:-23): }
3179:-23): } else {
3180:-23): $result = &mt('Currently LTI Authenticated.');
3181:-23): return $result;
3182:-23): }
3183:-23): }
3184:-23): } else {
3185:-23): if ($authnum == 1) {
3186:-23): $authtype = '<input type="hidden" name="login" value="lti" />';
3187:-23): }
3188:-23): }
3189:-23): if (!$can_assign{'lti'}) {
3190:-23): return;
3191:-23): } elsif ($authtype eq '') {
3192:-23): if (defined($in{'mode'})) {
3193:-23): if ($in{'mode'} eq 'modifycourse') {
3194:-23): if ($authnum == 1) {
3195:-23): $authtype = '<input type="radio" name="login" value="lti"'.$disabled.' />';
3196:-23): }
3197:-23): }
3198:-23): }
3199:-23): }
3200:-23): $jscall = "javascript:changed_radio('lti',$in{'formname'});";
3201:-23): if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {
3202:-23): $authtype = '<input type="radio" name="login" value="lti" '.
3203:-23): $lticheck.' onchange="'.$jscall.'" onclick="'.
3204:-23): $jscall.'"'.$disabled.' />';
3205:-23): }
3206:-23): $autharg = '<input type="hidden" name="ltiarg" value="" />';
3207:-23): if ($authtype) {
3208:-23): $result = &mt('[_1] LTI Authenticated',
3209:-23): '<label>'.$authtype.'</label>'.$autharg);
3210:-23): } else {
3211:-23): $result = '<b>'.&mt('LTI Authenticated').'</b>'.
3212:-23): $autharg;
3213:-23): }
3214:-23): return $result;
3215:-23): }
3216:-23):
1.586 raeburn 3217: sub get_assignable_auth {
3218: my ($dom) = @_;
3219: if ($dom eq '') {
3220: $dom = $env{'request.role.domain'};
3221: }
3222: my %can_assign = (
3223: krb4 => 1,
3224: krb5 => 1,
3225: int => 1,
3226: loc => 1,
3227: );
3228: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3229: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3230: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3231: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3232: my $context;
3233: if ($env{'request.role'} =~ /^au/) {
3234: $context = 'author';
1.1075.2.117 raeburn 3235: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3236: $context = 'domain';
3237: } elsif ($env{'request.course.id'}) {
3238: $context = 'course';
3239: }
3240: if ($context) {
3241: if (ref($authhash->{$context}) eq 'HASH') {
3242: %can_assign = %{$authhash->{$context}};
3243: }
3244: }
3245: }
3246: }
3247: my $authnum = 0;
3248: foreach my $key (keys(%can_assign)) {
3249: if ($can_assign{$key}) {
3250: $authnum ++;
3251: }
3252: }
3253: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3254: $authnum --;
3255: }
3256: return ($authnum,%can_assign);
3257: }
3258:
1.1075.2.137 raeburn 3259: sub check_passwd_rules {
3260: my ($domain,$plainpass) = @_;
3261: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3262: my ($min,$max,@chars,@brokerule,$warning);
1.1075.2.138 raeburn 3263: $min = $Apache::lonnet::passwdmin;
1.1075.2.137 raeburn 3264: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3265: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1075.2.138 raeburn 3266: if ($passwdconf{'min'} > $min) {
3267: $min = $passwdconf{'min'};
3268: }
1.1075.2.137 raeburn 3269: }
3270: if ($passwdconf{'max'} =~ /^\d+$/) {
3271: $max = $passwdconf{'max'};
3272: }
3273: @chars = @{$passwdconf{'chars'}};
3274: }
3275: if (($min) && (length($plainpass) < $min)) {
3276: push(@brokerule,'min');
3277: }
3278: if (($max) && (length($plainpass) > $max)) {
3279: push(@brokerule,'max');
3280: }
3281: if (@chars) {
3282: my %rules;
3283: map { $rules{$_} = 1; } @chars;
3284: if ($rules{'uc'}) {
3285: unless ($plainpass =~ /[A-Z]/) {
3286: push(@brokerule,'uc');
3287: }
3288: }
3289: if ($rules{'lc'}) {
3290: unless ($plainpass =~ /[a-z]/) {
3291: push(@brokerule,'lc');
3292: }
3293: }
3294: if ($rules{'num'}) {
3295: unless ($plainpass =~ /\d/) {
3296: push(@brokerule,'num');
3297: }
3298: }
3299: if ($rules{'spec'}) {
3300: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3301: push(@brokerule,'spec');
3302: }
3303: }
3304: }
3305: if (@brokerule) {
3306: my %rulenames = &Apache::lonlocal::texthash(
3307: uc => 'At least one upper case letter',
3308: lc => 'At least one lower case letter',
3309: num => 'At least one number',
3310: spec => 'At least one non-alphanumeric',
3311: );
3312: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3313: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3314: $rulenames{'num'} .= ': 0123456789';
3315: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3316: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3317: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3318: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1075.2.143 raeburn 3319: foreach my $rule ('min','max','uc','lc','num','spec') {
1.1075.2.137 raeburn 3320: if (grep(/^$rule$/,@brokerule)) {
3321: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3322: }
3323: }
3324: $warning .= '</ul>';
3325: }
3326: if (wantarray) {
3327: return @brokerule;
3328: }
3329: return $warning;
3330: }
3331:
1.1075.2.161. .5(raebu 3332:22): sub passwd_validation_js {
3333:22): my ($currpasswdval,$domain,$context,$id) = @_;
3334:22): my (%passwdconf,$alertmsg);
3335:22): if ($context eq 'linkprot') {
3336:22): my %domconfig = &Apache::lonnet::get_dom('configuration',['ltisec'],$domain);
3337:22): if (ref($domconfig{'ltisec'}) eq 'HASH') {
3338:22): if (ref($domconfig{'ltisec'}{'rules'}) eq 'HASH') {
3339:22): %passwdconf = %{$domconfig{'ltisec'}{'rules'}};
3340:22): }
3341:22): }
3342:22): if ($id eq 'add') {
3343:22): $alertmsg = &mt('Secret for added launcher did not satisfy requirement(s):').'\n\n';
3344:22): } elsif ($id =~ /^\d+$/) {
3345:22): my $pos = $id+1;
3346:22): $alertmsg = &mt('Secret for launcher [_1] did not satisfy requirement(s):','#'.$pos).'\n\n';
3347:22): } else {
3348:22): $alertmsg = &mt('A secret did not satisfy requirement(s):').'\n\n';
3349:22): }
3350:22): } else {
3351:22): %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3352:22): $alertmsg = &mt('Initial password did not satisfy requirement(s):').'\n\n';
3353:22): }
3354:22): my ($min,$max,@chars,$numrules,$intargjs,%alert);
3355:22): $numrules = 0;
3356:22): $min = $Apache::lonnet::passwdmin;
3357:22): if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3358:22): if ($passwdconf{'min'} =~ /^\d+$/) {
3359:22): if ($passwdconf{'min'} > $min) {
3360:22): $min = $passwdconf{'min'};
3361:22): }
3362:22): }
3363:22): if ($passwdconf{'max'} =~ /^\d+$/) {
3364:22): $max = $passwdconf{'max'};
3365:22): $numrules ++;
3366:22): }
3367:22): @chars = @{$passwdconf{'chars'}};
3368:22): if (@chars) {
3369:22): $numrules ++;
3370:22): }
3371:22): }
3372:22): if ($min > 0) {
3373:22): $numrules ++;
3374:22): }
3375:22): if (($min > 0) || ($max ne '') || (@chars > 0)) {
3376:22): if ($min) {
3377:22): $alert{'min'} = &mt('minimum [quant,_1,character]',$min).'\n';
3378:22): }
3379:22): if ($max) {
3380:22): $alert{'max'} = &mt('maximum [quant,_1,character]',$max).'\n';
3381:22): }
3382:22): my (@charalerts,@charrules);
3383:22): if (@chars) {
3384:22): if (grep(/^uc$/,@chars)) {
3385:22): push(@charalerts,&mt('contain at least one upper case letter'));
3386:22): push(@charrules,'uc');
3387:22): }
3388:22): if (grep(/^lc$/,@chars)) {
3389:22): push(@charalerts,&mt('contain at least one lower case letter'));
3390:22): push(@charrules,'lc');
3391:22): }
3392:22): if (grep(/^num$/,@chars)) {
3393:22): push(@charalerts,&mt('contain at least one number'));
3394:22): push(@charrules,'num');
3395:22): }
3396:22): if (grep(/^spec$/,@chars)) {
3397:22): push(@charalerts,&mt('contain at least one non-alphanumeric'));
3398:22): push(@charrules,'spec');
3399:22): }
3400:22): }
3401:22): $intargjs = qq| var rulesmsg = '';\n|.
3402:22): qq| var currpwval = $currpasswdval;\n|;
3403:22): if ($min) {
3404:22): $intargjs .= qq|
3405:22): if (currpwval.length < $min) {
3406:22): rulesmsg += ' - $alert{min}';
3407:22): }
3408:22): |;
3409:22): }
3410:22): if ($max) {
3411:22): $intargjs .= qq|
3412:22): if (currpwval.length > $max) {
3413:22): rulesmsg += ' - $alert{max}';
3414:22): }
3415:22): |;
3416:22): }
3417:22): if (@chars > 0) {
3418:22): my $charrulestr = '"'.join('","',@charrules).'"';
3419:22): my $charalertstr = '"'.join('","',@charalerts).'"';
3420:22): $intargjs .= qq| var brokerules = new Array();\n|.
3421:22): qq| var charrules = new Array($charrulestr);\n|.
3422:22): qq| var charalerts = new Array($charalertstr);\n|;
3423:22): my %rules;
3424:22): map { $rules{$_} = 1; } @chars;
3425:22): if ($rules{'uc'}) {
3426:22): $intargjs .= qq|
3427:22): var ucRegExp = /[A-Z]/;
3428:22): if (!ucRegExp.test(currpwval)) {
3429:22): brokerules.push('uc');
3430:22): }
3431:22): |;
3432:22): }
3433:22): if ($rules{'lc'}) {
3434:22): $intargjs .= qq|
3435:22): var lcRegExp = /[a-z]/;
3436:22): if (!lcRegExp.test(currpwval)) {
3437:22): brokerules.push('lc');
3438:22): }
3439:22): |;
3440:22): }
3441:22): if ($rules{'num'}) {
3442:22): $intargjs .= qq|
3443:22): var numRegExp = /[0-9]/;
3444:22): if (!numRegExp.test(currpwval)) {
3445:22): brokerules.push('num');
3446:22): }
3447:22): |;
3448:22): }
3449:22): if ($rules{'spec'}) {
3450:22): $intargjs .= q|
3451:22): var specRegExp = /[!"#$%&'()*+,\-.\/:;<=>?@[\\^\]_`{\|}~]/;
3452:22): if (!specRegExp.test(currpwval)) {
3453:22): brokerules.push('spec');
3454:22): }
3455:22): |;
3456:22): }
3457:22): $intargjs .= qq|
3458:22): if (brokerules.length > 0) {
3459:22): for (var i=0; i<brokerules.length; i++) {
3460:22): for (var j=0; j<charrules.length; j++) {
3461:22): if (brokerules[i] == charrules[j]) {
3462:22): rulesmsg += ' - '+charalerts[j]+'\\n';
3463:22): break;
3464:22): }
3465:22): }
3466:22): }
3467:22): }
3468:22): |;
3469:22): }
3470:22): $intargjs .= qq|
3471:22): if (rulesmsg != '') {
3472:22): rulesmsg = '$alertmsg'+rulesmsg;
3473:22): alert(rulesmsg);
3474:22): return false;
3475:22): }
3476:22): |;
3477:22): }
3478:22): return ($numrules,$intargjs);
3479:22): }
3480:22):
1.80 albertel 3481: ###############################################################
3482: ## Get Kerberos Defaults for Domain ##
3483: ###############################################################
3484: ##
3485: ## Returns default kerberos version and an associated argument
3486: ## as listed in file domain.tab. If not listed, provides
3487: ## appropriate default domain and kerberos version.
3488: ##
3489: #-------------------------------------------
3490:
3491: =pod
3492:
1.648 raeburn 3493: =item * &get_kerberos_defaults()
1.80 albertel 3494:
3495: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3496: version and domain. If not found, it defaults to version 4 and the
3497: domain of the server.
1.80 albertel 3498:
1.648 raeburn 3499: =over 4
3500:
1.80 albertel 3501: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3502:
1.648 raeburn 3503: =back
3504:
3505: =back
3506:
1.80 albertel 3507: =cut
3508:
3509: #-------------------------------------------
3510: sub get_kerberos_defaults {
3511: my $domain=shift;
1.641 raeburn 3512: my ($krbdef,$krbdefdom);
3513: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3514: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3515: $krbdef = $domdefaults{'auth_def'};
3516: $krbdefdom = $domdefaults{'auth_arg_def'};
3517: } else {
1.80 albertel 3518: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3519: my $krbdefdom=$1;
3520: $krbdefdom=~tr/a-z/A-Z/;
3521: $krbdef = "krb4";
3522: }
3523: return ($krbdef,$krbdefdom);
3524: }
1.112 bowersj2 3525:
1.32 matthew 3526:
1.46 matthew 3527: ###############################################################
3528: ## Thesaurus Functions ##
3529: ###############################################################
1.20 www 3530:
1.46 matthew 3531: =pod
1.20 www 3532:
1.112 bowersj2 3533: =head1 Thesaurus Functions
3534:
3535: =over 4
3536:
1.648 raeburn 3537: =item * &initialize_keywords()
1.46 matthew 3538:
3539: Initializes the package variable %Keywords if it is empty. Uses the
3540: package variable $thesaurus_db_file.
3541:
3542: =cut
3543:
3544: ###################################################
3545:
3546: sub initialize_keywords {
3547: return 1 if (scalar keys(%Keywords));
3548: # If we are here, %Keywords is empty, so fill it up
3549: # Make sure the file we need exists...
3550: if (! -e $thesaurus_db_file) {
3551: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3552: " failed because it does not exist");
3553: return 0;
3554: }
3555: # Set up the hash as a database
3556: my %thesaurus_db;
3557: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3558: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3559: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3560: $thesaurus_db_file);
3561: return 0;
3562: }
3563: # Get the average number of appearances of a word.
3564: my $avecount = $thesaurus_db{'average.count'};
3565: # Put keywords (those that appear > average) into %Keywords
3566: while (my ($word,$data)=each (%thesaurus_db)) {
3567: my ($count,undef) = split /:/,$data;
3568: $Keywords{$word}++ if ($count > $avecount);
3569: }
3570: untie %thesaurus_db;
3571: # Remove special values from %Keywords.
1.356 albertel 3572: foreach my $value ('total.count','average.count') {
3573: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3574: }
1.46 matthew 3575: return 1;
3576: }
3577:
3578: ###################################################
3579:
3580: =pod
3581:
1.648 raeburn 3582: =item * &keyword($word)
1.46 matthew 3583:
3584: Returns true if $word is a keyword. A keyword is a word that appears more
3585: than the average number of times in the thesaurus database. Calls
3586: &initialize_keywords
3587:
3588: =cut
3589:
3590: ###################################################
1.20 www 3591:
3592: sub keyword {
1.46 matthew 3593: return if (!&initialize_keywords());
3594: my $word=lc(shift());
3595: $word=~s/\W//g;
3596: return exists($Keywords{$word});
1.20 www 3597: }
1.46 matthew 3598:
3599: ###############################################################
3600:
3601: =pod
1.20 www 3602:
1.648 raeburn 3603: =item * &get_related_words()
1.46 matthew 3604:
1.160 matthew 3605: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3606: an array of words. If the keyword is not in the thesaurus, an empty array
3607: will be returned. The order of the words returned is determined by the
3608: database which holds them.
3609:
3610: Uses global $thesaurus_db_file.
3611:
1.1057 foxr 3612:
1.46 matthew 3613: =cut
3614:
3615: ###############################################################
3616: sub get_related_words {
3617: my $keyword = shift;
3618: my %thesaurus_db;
3619: if (! -e $thesaurus_db_file) {
3620: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3621: "failed because the file does not exist");
3622: return ();
3623: }
3624: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3625: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3626: return ();
3627: }
3628: my @Words=();
1.429 www 3629: my $count=0;
1.46 matthew 3630: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3631: # The first element is the number of times
3632: # the word appears. We do not need it now.
1.429 www 3633: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3634: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3635: my $threshold=$mostfrequentcount/10;
3636: foreach my $possibleword (@RelatedWords) {
3637: my ($word,$wordcount)=split(/\,/,$possibleword);
3638: if ($wordcount>$threshold) {
3639: push(@Words,$word);
3640: $count++;
3641: if ($count>10) { last; }
3642: }
1.20 www 3643: }
3644: }
1.46 matthew 3645: untie %thesaurus_db;
3646: return @Words;
1.14 harris41 3647: }
1.46 matthew 3648:
1.112 bowersj2 3649: =pod
3650:
3651: =back
3652:
3653: =cut
1.61 www 3654:
3655: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3656: =pod
3657:
1.112 bowersj2 3658: =head1 User Name Functions
3659:
3660: =over 4
3661:
1.648 raeburn 3662: =item * &plainname($uname,$udom,$first)
1.81 albertel 3663:
1.112 bowersj2 3664: Takes a users logon name and returns it as a string in
1.226 albertel 3665: "first middle last generation" form
3666: if $first is set to 'lastname' then it returns it as
3667: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3668:
3669: =cut
1.61 www 3670:
1.295 www 3671:
1.81 albertel 3672: ###############################################################
1.61 www 3673: sub plainname {
1.226 albertel 3674: my ($uname,$udom,$first)=@_;
1.537 albertel 3675: return if (!defined($uname) || !defined($udom));
1.295 www 3676: my %names=&getnames($uname,$udom);
1.226 albertel 3677: my $name=&Apache::lonnet::format_name($names{'firstname'},
3678: $names{'middlename'},
3679: $names{'lastname'},
3680: $names{'generation'},$first);
3681: $name=~s/^\s+//;
1.62 www 3682: $name=~s/\s+$//;
3683: $name=~s/\s+/ /g;
1.353 albertel 3684: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3685: return $name;
1.61 www 3686: }
1.66 www 3687:
3688: # -------------------------------------------------------------------- Nickname
1.81 albertel 3689: =pod
3690:
1.648 raeburn 3691: =item * &nickname($uname,$udom)
1.81 albertel 3692:
3693: Gets a users name and returns it as a string as
3694:
3695: ""nickname""
1.66 www 3696:
1.81 albertel 3697: if the user has a nickname or
3698:
3699: "first middle last generation"
3700:
3701: if the user does not
3702:
3703: =cut
1.66 www 3704:
3705: sub nickname {
3706: my ($uname,$udom)=@_;
1.537 albertel 3707: return if (!defined($uname) || !defined($udom));
1.295 www 3708: my %names=&getnames($uname,$udom);
1.68 albertel 3709: my $name=$names{'nickname'};
1.66 www 3710: if ($name) {
3711: $name='"'.$name.'"';
3712: } else {
3713: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3714: $names{'lastname'}.' '.$names{'generation'};
3715: $name=~s/\s+$//;
3716: $name=~s/\s+/ /g;
3717: }
3718: return $name;
3719: }
3720:
1.295 www 3721: sub getnames {
3722: my ($uname,$udom)=@_;
1.537 albertel 3723: return if (!defined($uname) || !defined($udom));
1.433 albertel 3724: if ($udom eq 'public' && $uname eq 'public') {
3725: return ('lastname' => &mt('Public'));
3726: }
1.295 www 3727: my $id=$uname.':'.$udom;
3728: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3729: if ($cached) {
3730: return %{$names};
3731: } else {
3732: my %loadnames=&Apache::lonnet::get('environment',
3733: ['firstname','middlename','lastname','generation','nickname'],
3734: $udom,$uname);
3735: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3736: return %loadnames;
3737: }
3738: }
1.61 www 3739:
1.542 raeburn 3740: # -------------------------------------------------------------------- getemails
1.648 raeburn 3741:
1.542 raeburn 3742: =pod
3743:
1.648 raeburn 3744: =item * &getemails($uname,$udom)
1.542 raeburn 3745:
3746: Gets a user's email information and returns it as a hash with keys:
3747: notification, critnotification, permanentemail
3748:
3749: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3750: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3751:
1.648 raeburn 3752:
1.542 raeburn 3753: =cut
3754:
1.648 raeburn 3755:
1.466 albertel 3756: sub getemails {
3757: my ($uname,$udom)=@_;
3758: if ($udom eq 'public' && $uname eq 'public') {
3759: return;
3760: }
1.467 www 3761: if (!$udom) { $udom=$env{'user.domain'}; }
3762: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3763: my $id=$uname.':'.$udom;
3764: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3765: if ($cached) {
3766: return %{$names};
3767: } else {
3768: my %loadnames=&Apache::lonnet::get('environment',
3769: ['notification','critnotification',
3770: 'permanentemail'],
3771: $udom,$uname);
3772: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3773: return %loadnames;
3774: }
3775: }
3776:
1.551 albertel 3777: sub flush_email_cache {
3778: my ($uname,$udom)=@_;
3779: if (!$udom) { $udom =$env{'user.domain'}; }
3780: if (!$uname) { $uname=$env{'user.name'}; }
3781: return if ($udom eq 'public' && $uname eq 'public');
3782: my $id=$uname.':'.$udom;
3783: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3784: }
3785:
1.728 raeburn 3786: # -------------------------------------------------------------------- getlangs
3787:
3788: =pod
3789:
3790: =item * &getlangs($uname,$udom)
3791:
3792: Gets a user's language preference and returns it as a hash with key:
3793: language.
3794:
3795: =cut
3796:
3797:
3798: sub getlangs {
3799: my ($uname,$udom) = @_;
3800: if (!$udom) { $udom =$env{'user.domain'}; }
3801: if (!$uname) { $uname=$env{'user.name'}; }
3802: my $id=$uname.':'.$udom;
3803: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3804: if ($cached) {
3805: return %{$langs};
3806: } else {
3807: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3808: $udom,$uname);
3809: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3810: return %loadlangs;
3811: }
3812: }
3813:
3814: sub flush_langs_cache {
3815: my ($uname,$udom)=@_;
3816: if (!$udom) { $udom =$env{'user.domain'}; }
3817: if (!$uname) { $uname=$env{'user.name'}; }
3818: return if ($udom eq 'public' && $uname eq 'public');
3819: my $id=$uname.':'.$udom;
3820: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3821: }
3822:
1.61 www 3823: # ------------------------------------------------------------------ Screenname
1.81 albertel 3824:
3825: =pod
3826:
1.648 raeburn 3827: =item * &screenname($uname,$udom)
1.81 albertel 3828:
3829: Gets a users screenname and returns it as a string
3830:
3831: =cut
1.61 www 3832:
3833: sub screenname {
3834: my ($uname,$udom)=@_;
1.258 albertel 3835: if ($uname eq $env{'user.name'} &&
3836: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3837: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3838: return $names{'screenname'};
1.62 www 3839: }
3840:
1.212 albertel 3841:
1.802 bisitz 3842: # ------------------------------------------------------------- Confirm Wrapper
3843: =pod
3844:
1.1075.2.42 raeburn 3845: =item * &confirmwrapper($message)
1.802 bisitz 3846:
3847: Wrap messages about completion of operation in box
3848:
3849: =cut
3850:
3851: sub confirmwrapper {
3852: my ($message)=@_;
3853: if ($message) {
3854: return "\n".'<div class="LC_confirm_box">'."\n"
3855: .$message."\n"
3856: .'</div>'."\n";
3857: } else {
3858: return $message;
3859: }
3860: }
3861:
1.62 www 3862: # ------------------------------------------------------------- Message Wrapper
3863:
3864: sub messagewrapper {
1.369 www 3865: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3866: return
1.441 albertel 3867: '<a href="/adm/email?compose=individual&'.
3868: 'recname='.$username.'&recdom='.$domain.
3869: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3870: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3871: }
1.802 bisitz 3872:
1.74 www 3873: # --------------------------------------------------------------- Notes Wrapper
3874:
3875: sub noteswrapper {
3876: my ($link,$un,$do)=@_;
3877: return
1.896 amueller 3878: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3879: }
1.802 bisitz 3880:
1.62 www 3881: # ------------------------------------------------------------- Aboutme Wrapper
3882:
3883: sub aboutmewrapper {
1.1070 raeburn 3884: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3885: if (!defined($username) && !defined($domain)) {
3886: return;
3887: }
1.1075.2.15 raeburn 3888: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3889: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3890: }
3891:
3892: # ------------------------------------------------------------ Syllabus Wrapper
3893:
3894: sub syllabuswrapper {
1.707 bisitz 3895: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3896: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3897: }
1.14 harris41 3898:
1.1075.2.161. .11(raeb 3899:-22): sub aboutme_on {
3900:-22): my ($uname,$udom)=@_;
3901:-22): unless ($uname) { $uname=$env{'user.name'}; }
3902:-22): unless ($udom) { $udom=$env{'user.domain'}; }
3903:-22): return if ($udom eq 'public' && $uname eq 'public');
3904:-22): my $hashkey=$uname.':'.$udom;
3905:-22): my ($aboutme,$cached)=&Apache::lonnet::is_cached_new('aboutme',$hashkey);
3906:-22): if ($cached) {
3907:-22): return $aboutme;
3908:-22): }
3909:-22): $aboutme = &Apache::lonnet::usertools_access($uname,$udom,'aboutme');
3910:-22): &Apache::lonnet::do_cache_new('aboutme',$hashkey,$aboutme,3600);
3911:-22): return $aboutme;
3912:-22): }
3913:-22):
3914:-22): sub devalidate_aboutme_cache {
3915:-22): my ($uname,$udom)=@_;
3916:-22): if (!$udom) { $udom =$env{'user.domain'}; }
3917:-22): if (!$uname) { $uname=$env{'user.name'}; }
3918:-22): return if ($udom eq 'public' && $uname eq 'public');
3919:-22): my $id=$uname.':'.$udom;
3920:-22): &Apache::lonnet::devalidate_cache_new('aboutme',$id);
3921:-22): }
3922:-22):
1.802 bisitz 3923: # -----------------------------------------------------------------------------
3924:
1.208 matthew 3925: sub track_student_link {
1.887 raeburn 3926: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3927: my $link ="/adm/trackstudent?";
1.208 matthew 3928: my $title = 'View recent activity';
3929: if (defined($sname) && $sname !~ /^\s*$/ &&
3930: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3931: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3932: $title .= ' of this student';
1.268 albertel 3933: }
1.208 matthew 3934: if (defined($target) && $target !~ /^\s*$/) {
3935: $target = qq{target="$target"};
3936: } else {
3937: $target = '';
3938: }
1.268 albertel 3939: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3940: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3941: $title = &mt($title);
3942: $linktext = &mt($linktext);
1.448 albertel 3943: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3944: &help_open_topic('View_recent_activity');
1.208 matthew 3945: }
3946:
1.781 raeburn 3947: sub slot_reservations_link {
3948: my ($linktext,$sname,$sdom,$target) = @_;
3949: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3950: my $title = 'View slot reservation history';
3951: if (defined($sname) && $sname !~ /^\s*$/ &&
3952: defined($sdom) && $sdom !~ /^\s*$/) {
3953: $link .= "&uname=$sname&udom=$sdom";
3954: $title .= ' of this student';
3955: }
3956: if (defined($target) && $target !~ /^\s*$/) {
3957: $target = qq{target="$target"};
3958: } else {
3959: $target = '';
3960: }
3961: $title = &mt($title);
3962: $linktext = &mt($linktext);
3963: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3964: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3965:
3966: }
3967:
1.508 www 3968: # ===================================================== Display a student photo
3969:
3970:
1.509 albertel 3971: sub student_image_tag {
1.508 www 3972: my ($domain,$user)=@_;
3973: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3974: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3975: return '<img src="'.$imgsrc.'" align="right" />';
3976: } else {
3977: return '';
3978: }
3979: }
3980:
1.112 bowersj2 3981: =pod
3982:
3983: =back
3984:
3985: =head1 Access .tab File Data
3986:
3987: =over 4
3988:
1.648 raeburn 3989: =item * &languageids()
1.112 bowersj2 3990:
3991: returns list of all language ids
3992:
3993: =cut
3994:
1.14 harris41 3995: sub languageids {
1.16 harris41 3996: return sort(keys(%language));
1.14 harris41 3997: }
3998:
1.112 bowersj2 3999: =pod
4000:
1.648 raeburn 4001: =item * &languagedescription()
1.112 bowersj2 4002:
4003: returns description of a specified language id
4004:
4005: =cut
4006:
1.14 harris41 4007: sub languagedescription {
1.125 www 4008: my $code=shift;
4009: return ($supported_language{$code}?'* ':'').
4010: $language{$code}.
1.126 www 4011: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4012: }
4013:
1.1048 foxr 4014: =pod
4015:
4016: =item * &plainlanguagedescription
4017:
4018: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4019: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4020:
4021: =cut
4022:
1.145 www 4023: sub plainlanguagedescription {
4024: my $code=shift;
4025: return $language{$code};
4026: }
4027:
1.1048 foxr 4028: =pod
4029:
4030: =item * &supportedlanguagecode
4031:
4032: Returns the supported language code (e.g. sptutf maps to pt) given a language
4033: code.
4034:
4035: =cut
4036:
1.145 www 4037: sub supportedlanguagecode {
4038: my $code=shift;
4039: return $supported_language{$code};
1.97 www 4040: }
4041:
1.112 bowersj2 4042: =pod
4043:
1.1048 foxr 4044: =item * &latexlanguage()
4045:
4046: Given a language key code returns the correspondnig language to use
4047: to select the correct hyphenation on LaTeX printouts. This is undef if there
4048: is no supported hyphenation for the language code.
4049:
4050: =cut
4051:
4052: sub latexlanguage {
4053: my $code = shift;
4054: return $latex_language{$code};
4055: }
4056:
4057: =pod
4058:
4059: =item * &latexhyphenation()
4060:
4061: Same as above but what's supplied is the language as it might be stored
4062: in the metadata.
4063:
4064: =cut
4065:
4066: sub latexhyphenation {
4067: my $key = shift;
4068: return $latex_language_bykey{$key};
4069: }
4070:
4071: =pod
4072:
1.648 raeburn 4073: =item * ©rightids()
1.112 bowersj2 4074:
4075: returns list of all copyrights
4076:
4077: =cut
4078:
4079: sub copyrightids {
4080: return sort(keys(%cprtag));
4081: }
4082:
4083: =pod
4084:
1.648 raeburn 4085: =item * ©rightdescription()
1.112 bowersj2 4086:
4087: returns description of a specified copyright id
4088:
4089: =cut
4090:
4091: sub copyrightdescription {
1.166 www 4092: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4093: }
1.197 matthew 4094:
4095: =pod
4096:
1.648 raeburn 4097: =item * &source_copyrightids()
1.192 taceyjo1 4098:
4099: returns list of all source copyrights
4100:
4101: =cut
4102:
4103: sub source_copyrightids {
4104: return sort(keys(%scprtag));
4105: }
4106:
4107: =pod
4108:
1.648 raeburn 4109: =item * &source_copyrightdescription()
1.192 taceyjo1 4110:
4111: returns description of a specified source copyright id
4112:
4113: =cut
4114:
4115: sub source_copyrightdescription {
4116: return &mt($scprtag{shift(@_)});
4117: }
1.112 bowersj2 4118:
4119: =pod
4120:
1.648 raeburn 4121: =item * &filecategories()
1.112 bowersj2 4122:
4123: returns list of all file categories
4124:
4125: =cut
4126:
4127: sub filecategories {
4128: return sort(keys(%category_extensions));
4129: }
4130:
4131: =pod
4132:
1.648 raeburn 4133: =item * &filecategorytypes()
1.112 bowersj2 4134:
4135: returns list of file types belonging to a given file
4136: category
4137:
4138: =cut
4139:
4140: sub filecategorytypes {
1.356 albertel 4141: my ($cat) = @_;
4142: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 4143: }
4144:
4145: =pod
4146:
1.648 raeburn 4147: =item * &fileembstyle()
1.112 bowersj2 4148:
4149: returns embedding style for a specified file type
4150:
4151: =cut
4152:
4153: sub fileembstyle {
4154: return $fe{lc(shift(@_))};
1.169 www 4155: }
4156:
1.351 www 4157: sub filemimetype {
4158: return $fm{lc(shift(@_))};
4159: }
4160:
1.169 www 4161:
4162: sub filecategoryselect {
4163: my ($name,$value)=@_;
1.189 matthew 4164: return &select_form($value,$name,
1.970 raeburn 4165: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4166: }
4167:
4168: =pod
4169:
1.648 raeburn 4170: =item * &filedescription()
1.112 bowersj2 4171:
4172: returns description for a specified file type
4173:
4174: =cut
4175:
4176: sub filedescription {
1.188 matthew 4177: my $file_description = $fd{lc(shift())};
4178: $file_description =~ s:([\[\]]):~$1:g;
4179: return &mt($file_description);
1.112 bowersj2 4180: }
4181:
4182: =pod
4183:
1.648 raeburn 4184: =item * &filedescriptionex()
1.112 bowersj2 4185:
4186: returns description for a specified file type with
4187: extra formatting
4188:
4189: =cut
4190:
4191: sub filedescriptionex {
4192: my $ex=shift;
1.188 matthew 4193: my $file_description = $fd{lc($ex)};
4194: $file_description =~ s:([\[\]]):~$1:g;
4195: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4196: }
4197:
4198: # End of .tab access
4199: =pod
4200:
4201: =back
4202:
4203: =cut
4204:
4205: # ------------------------------------------------------------------ File Types
4206: sub fileextensions {
4207: return sort(keys(%fe));
4208: }
4209:
1.97 www 4210: # ----------------------------------------------------------- Display Languages
4211: # returns a hash with all desired display languages
4212: #
4213:
4214: sub display_languages {
4215: my %languages=();
1.695 raeburn 4216: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4217: $languages{$lang}=1;
1.97 www 4218: }
4219: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4220: if ($env{'form.displaylanguage'}) {
1.356 albertel 4221: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4222: $languages{$lang}=1;
1.97 www 4223: }
4224: }
4225: return %languages;
1.14 harris41 4226: }
4227:
1.582 albertel 4228: sub languages {
4229: my ($possible_langs) = @_;
1.695 raeburn 4230: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4231: if (!ref($possible_langs)) {
4232: if( wantarray ) {
4233: return @preferred_langs;
4234: } else {
4235: return $preferred_langs[0];
4236: }
4237: }
4238: my %possibilities = map { $_ => 1 } (@$possible_langs);
4239: my @preferred_possibilities;
4240: foreach my $preferred_lang (@preferred_langs) {
4241: if (exists($possibilities{$preferred_lang})) {
4242: push(@preferred_possibilities, $preferred_lang);
4243: }
4244: }
4245: if( wantarray ) {
4246: return @preferred_possibilities;
4247: }
4248: return $preferred_possibilities[0];
4249: }
4250:
1.742 raeburn 4251: sub user_lang {
4252: my ($touname,$toudom,$fromcid) = @_;
4253: my @userlangs;
4254: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4255: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4256: $env{'course.'.$fromcid.'.languages'}));
4257: } else {
4258: my %langhash = &getlangs($touname,$toudom);
4259: if ($langhash{'languages'} ne '') {
4260: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4261: } else {
4262: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4263: if ($domdefs{'lang_def'} ne '') {
4264: @userlangs = ($domdefs{'lang_def'});
4265: }
4266: }
4267: }
4268: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4269: my $user_lh = Apache::localize->get_handle(@languages);
4270: return $user_lh;
4271: }
4272:
4273:
1.112 bowersj2 4274: ###############################################################
4275: ## Student Answer Attempts ##
4276: ###############################################################
4277:
4278: =pod
4279:
4280: =head1 Alternate Problem Views
4281:
4282: =over 4
4283:
1.648 raeburn 4284: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1075.2.86 raeburn 4285: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4286:
4287: Return string with previous attempt on problem. Arguments:
4288:
4289: =over 4
4290:
4291: =item * $symb: Problem, including path
4292:
4293: =item * $username: username of the desired student
4294:
4295: =item * $domain: domain of the desired student
1.14 harris41 4296:
1.112 bowersj2 4297: =item * $course: Course ID
1.14 harris41 4298:
1.112 bowersj2 4299: =item * $getattempt: Leave blank for all attempts, otherwise put
4300: something
1.14 harris41 4301:
1.112 bowersj2 4302: =item * $regexp: if string matches this regexp, the string will be
4303: sent to $gradesub
1.14 harris41 4304:
1.112 bowersj2 4305: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4306:
1.1075.2.86 raeburn 4307: =item * $usec: section of the desired student
4308:
4309: =item * $identifier: counter for student (multiple students one problem) or
4310: problem (one student; whole sequence).
4311:
1.112 bowersj2 4312: =back
1.14 harris41 4313:
1.112 bowersj2 4314: The output string is a table containing all desired attempts, if any.
1.16 harris41 4315:
1.112 bowersj2 4316: =cut
1.1 albertel 4317:
4318: sub get_previous_attempt {
1.1075.2.86 raeburn 4319: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4320: my $prevattempts='';
1.43 ng 4321: no strict 'refs';
1.1 albertel 4322: if ($symb) {
1.3 albertel 4323: my (%returnhash)=
4324: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4325: if ($returnhash{'version'}) {
4326: my %lasthash=();
4327: my $version;
4328: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.91 raeburn 4329: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4330: if ($key =~ /\.rawrndseed$/) {
4331: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4332: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4333: } else {
4334: $lasthash{$key}=$returnhash{$version.':'.$key};
4335: }
1.19 harris41 4336: }
1.1 albertel 4337: }
1.596 albertel 4338: $prevattempts=&start_data_table().&start_data_table_header_row();
4339: $prevattempts.='<th>'.&mt('History').'</th>';
1.1075.2.86 raeburn 4340: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4341: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4342: foreach my $key (sort(keys(%lasthash))) {
4343: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4344: if ($#parts > 0) {
1.31 albertel 4345: my $data=$parts[-1];
1.989 raeburn 4346: next if ($data eq 'foilorder');
1.31 albertel 4347: pop(@parts);
1.1010 www 4348: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4349: if ($data eq 'type') {
4350: unless ($showsurv) {
4351: my $id = join(',',@parts);
4352: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4353: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4354: $lasthidden{$ign.'.'.$id} = 1;
4355: }
1.945 raeburn 4356: }
1.1075.2.86 raeburn 4357: if ($identifier ne '') {
4358: my $id = join(',',@parts);
4359: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4360: $domain,$username,$usec,undef,$course) =~ /^no/) {
4361: $hidestatus{$ign.'.'.$id} = 1;
4362: }
4363: }
4364: } elsif ($data eq 'regrader') {
4365: if (($identifier ne '') && (@parts)) {
4366: my $id = join(',',@parts);
4367: $regraded{$ign.'.'.$id} = 1;
4368: }
1.1010 www 4369: }
1.31 albertel 4370: } else {
1.41 ng 4371: if ($#parts == 0) {
4372: $prevattempts.='<th>'.$parts[0].'</th>';
4373: } else {
4374: $prevattempts.='<th>'.$ign.'</th>';
4375: }
1.31 albertel 4376: }
1.16 harris41 4377: }
1.596 albertel 4378: $prevattempts.=&end_data_table_header_row();
1.40 ng 4379: if ($getattempt eq '') {
1.1075.2.86 raeburn 4380: my (%solved,%resets,%probstatus);
4381: if (($identifier ne '') && (keys(%regraded) > 0)) {
4382: for ($version=1;$version<=$returnhash{'version'};$version++) {
4383: foreach my $id (keys(%regraded)) {
4384: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4385: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4386: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4387: push(@{$resets{$id}},$version);
4388: }
4389: }
4390: }
4391: }
1.40 ng 4392: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.86 raeburn 4393: my (@hidden,@unsolved);
1.945 raeburn 4394: if (%typeparts) {
4395: foreach my $id (keys(%typeparts)) {
1.1075.2.86 raeburn 4396: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4397: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4398: push(@hidden,$id);
1.1075.2.86 raeburn 4399: } elsif ($identifier ne '') {
4400: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4401: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4402: ($hidestatus{$id})) {
4403: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
4404: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4405: push(@{$solved{$id}},$version);
4406: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4407: (ref($solved{$id}) eq 'ARRAY')) {
4408: my $skip;
4409: if (ref($resets{$id}) eq 'ARRAY') {
4410: foreach my $reset (@{$resets{$id}}) {
4411: if ($reset > $solved{$id}[-1]) {
4412: $skip=1;
4413: last;
4414: }
4415: }
4416: }
4417: unless ($skip) {
4418: my ($ign,$partslist) = split(/\./,$id,2);
4419: push(@unsolved,$partslist);
4420: }
4421: }
4422: }
1.945 raeburn 4423: }
4424: }
4425: }
4426: $prevattempts.=&start_data_table_row().
1.1075.2.86 raeburn 4427: '<td>'.&mt('Transaction [_1]',$version);
4428: if (@unsolved) {
4429: $prevattempts .= '<span class="LC_nobreak"><label>'.
4430: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4431: &mt('Hide').'</label></span>';
4432: }
4433: $prevattempts .= '</td>';
1.945 raeburn 4434: if (@hidden) {
4435: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4436: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4437: my $hide;
4438: foreach my $id (@hidden) {
4439: if ($key =~ /^\Q$id\E/) {
4440: $hide = 1;
4441: last;
4442: }
4443: }
4444: if ($hide) {
4445: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4446: if (($data eq 'award') || ($data eq 'awarddetail')) {
4447: my $value = &format_previous_attempt_value($key,
4448: $returnhash{$version.':'.$key});
4449: $prevattempts.='<td>'.$value.' </td>';
4450: } else {
4451: $prevattempts.='<td> </td>';
4452: }
4453: } else {
4454: if ($key =~ /\./) {
1.1075.2.91 raeburn 4455: my $value = $returnhash{$version.':'.$key};
4456: if ($key =~ /\.rndseed$/) {
4457: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4458: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4459: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4460: }
4461: }
4462: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4463: ' </td>';
1.945 raeburn 4464: } else {
4465: $prevattempts.='<td> </td>';
4466: }
4467: }
4468: }
4469: } else {
4470: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4471: next if ($key =~ /\.foilorder$/);
1.1075.2.91 raeburn 4472: my $value = $returnhash{$version.':'.$key};
4473: if ($key =~ /\.rndseed$/) {
4474: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4475: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4476: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4477: }
4478: }
4479: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4480: ' </td>';
1.945 raeburn 4481: }
4482: }
4483: $prevattempts.=&end_data_table_row();
1.40 ng 4484: }
1.1 albertel 4485: }
1.945 raeburn 4486: my @currhidden = keys(%lasthidden);
1.596 albertel 4487: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4488: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4489: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4490: if (%typeparts) {
4491: my $hidden;
4492: foreach my $id (@currhidden) {
4493: if ($key =~ /^\Q$id\E/) {
4494: $hidden = 1;
4495: last;
4496: }
4497: }
4498: if ($hidden) {
4499: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4500: if (($data eq 'award') || ($data eq 'awarddetail')) {
4501: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4502: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4503: $value = &$gradesub($value);
4504: }
4505: $prevattempts.='<td>'.$value.' </td>';
4506: } else {
4507: $prevattempts.='<td> </td>';
4508: }
4509: } else {
4510: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4511: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4512: $value = &$gradesub($value);
4513: }
4514: $prevattempts.='<td>'.$value.' </td>';
4515: }
4516: } else {
4517: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4518: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4519: $value = &$gradesub($value);
4520: }
4521: $prevattempts.='<td>'.$value.' </td>';
4522: }
1.16 harris41 4523: }
1.596 albertel 4524: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4525: } else {
1.1075.2.161. .17(raeb 4526:-23): my $msg;
4527:-23): if ($symb =~ /ext\.tool$/) {
4528:-23): $msg = &mt('No grade passed back.');
4529:-23): } else {
4530:-23): $msg = &mt('Nothing submitted - no attempts.');
4531:-23): }
1.596 albertel 4532: $prevattempts=
4533: &start_data_table().&start_data_table_row().
1.1075.2.161. .17(raeb 4534:-23): '<td>'.$msg.'</td>'.
1.596 albertel 4535: &end_data_table_row().&end_data_table();
1.1 albertel 4536: }
4537: } else {
1.596 albertel 4538: $prevattempts=
4539: &start_data_table().&start_data_table_row().
4540: '<td>'.&mt('No data.').'</td>'.
4541: &end_data_table_row().&end_data_table();
1.1 albertel 4542: }
1.10 albertel 4543: }
4544:
1.581 albertel 4545: sub format_previous_attempt_value {
4546: my ($key,$value) = @_;
1.1011 www 4547: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 4548: $value = &Apache::lonlocal::locallocaltime($value);
4549: } elsif (ref($value) eq 'ARRAY') {
4550: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 4551: } elsif ($key =~ /answerstring$/) {
4552: my %answers = &Apache::lonnet::str2hash($value);
4553: my @anskeys = sort(keys(%answers));
4554: if (@anskeys == 1) {
4555: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4556: if ($answer =~ m{\0}) {
4557: $answer =~ s{\0}{,}g;
1.988 raeburn 4558: }
4559: my $tag_internal_answer_name = 'INTERNAL';
4560: if ($anskeys[0] eq $tag_internal_answer_name) {
4561: $value = $answer;
4562: } else {
4563: $value = $anskeys[0].'='.$answer;
4564: }
4565: } else {
4566: foreach my $ans (@anskeys) {
4567: my $answer = $answers{$ans};
1.1001 raeburn 4568: if ($answer =~ m{\0}) {
4569: $answer =~ s{\0}{,}g;
1.988 raeburn 4570: }
4571: $value .= $ans.'='.$answer.'<br />';;
4572: }
4573: }
1.581 albertel 4574: } else {
4575: $value = &unescape($value);
4576: }
4577: return $value;
4578: }
4579:
4580:
1.107 albertel 4581: sub relative_to_absolute {
4582: my ($url,$output)=@_;
4583: my $parser=HTML::TokeParser->new(\$output);
4584: my $token;
4585: my $thisdir=$url;
4586: my @rlinks=();
4587: while ($token=$parser->get_token) {
4588: if ($token->[0] eq 'S') {
4589: if ($token->[1] eq 'a') {
4590: if ($token->[2]->{'href'}) {
4591: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4592: }
4593: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4594: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4595: } elsif ($token->[1] eq 'base') {
4596: $thisdir=$token->[2]->{'href'};
4597: }
4598: }
4599: }
4600: $thisdir=~s-/[^/]*$--;
1.356 albertel 4601: foreach my $link (@rlinks) {
1.726 raeburn 4602: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4603: ($link=~/^\//) ||
4604: ($link=~/^javascript:/i) ||
4605: ($link=~/^mailto:/i) ||
4606: ($link=~/^\#/)) {
4607: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4608: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4609: }
4610: }
4611: # -------------------------------------------------- Deal with Applet codebases
4612: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4613: return $output;
4614: }
4615:
1.112 bowersj2 4616: =pod
4617:
1.648 raeburn 4618: =item * &get_student_view()
1.112 bowersj2 4619:
4620: show a snapshot of what student was looking at
4621:
4622: =cut
4623:
1.10 albertel 4624: sub get_student_view {
1.186 albertel 4625: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4626: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4627: my (%form);
1.10 albertel 4628: my @elements=('symb','courseid','domain','username');
4629: foreach my $element (@elements) {
1.186 albertel 4630: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4631: }
1.186 albertel 4632: if (defined($moreenv)) {
4633: %form=(%form,%{$moreenv});
4634: }
1.236 albertel 4635: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4636: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4637: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4638: $userview=~s/\<body[^\>]*\>//gi;
4639: $userview=~s/\<\/body\>//gi;
4640: $userview=~s/\<html\>//gi;
4641: $userview=~s/\<\/html\>//gi;
4642: $userview=~s/\<head\>//gi;
4643: $userview=~s/\<\/head\>//gi;
4644: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4645: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4646: if (wantarray) {
4647: return ($userview,$response);
4648: } else {
4649: return $userview;
4650: }
4651: }
4652:
4653: sub get_student_view_with_retries {
4654: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4655:
4656: my $ok = 0; # True if we got a good response.
4657: my $content;
4658: my $response;
4659:
4660: # Try to get the student_view done. within the retries count:
4661:
4662: do {
4663: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4664: $ok = $response->is_success;
4665: if (!$ok) {
4666: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4667: }
4668: $retries--;
4669: } while (!$ok && ($retries > 0));
4670:
4671: if (!$ok) {
4672: $content = ''; # On error return an empty content.
4673: }
1.651 www 4674: if (wantarray) {
4675: return ($content, $response);
4676: } else {
4677: return $content;
4678: }
1.11 albertel 4679: }
4680:
1.1075.2.149 raeburn 4681: sub css_links {
4682: my ($currsymb,$level) = @_;
4683: my ($links,@symbs,%cssrefs,%httpref);
4684: if ($level eq 'map') {
4685: my $navmap = Apache::lonnavmaps::navmap->new();
4686: if (ref($navmap)) {
4687: my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb);
4688: my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0);
4689: foreach my $res (@resources) {
4690: if (ref($res) && $res->symb()) {
4691: push(@symbs,$res->symb());
4692: }
4693: }
4694: }
4695: } else {
4696: @symbs = ($currsymb);
4697: }
4698: foreach my $symb (@symbs) {
4699: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb);
4700: if ($css_href =~ /\S/) {
4701: unless ($css_href =~ m{https?://}) {
4702: my $url = (&Apache::lonnet::decode_symb($symb))[-1];
4703: my $proburl = &Apache::lonnet::clutter($url);
4704: my ($probdir) = ($proburl =~ m{(.+)/[^/]+$});
4705: unless ($css_href =~ m{^/}) {
4706: $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
4707: }
4708: if ($css_href =~ m{^/(res|uploaded)/}) {
4709: unless (($httpref{'httpref.'.$css_href}) ||
4710: (&Apache::lonnet::is_on_map($css_href))) {
4711: my $thisurl = $proburl;
4712: if ($env{'httpref.'.$proburl}) {
4713: $thisurl = $env{'httpref.'.$proburl};
4714: }
4715: $httpref{'httpref.'.$css_href} = $thisurl;
4716: }
4717: }
4718: }
4719: $cssrefs{$css_href} = 1;
4720: }
4721: }
4722: if (keys(%httpref)) {
4723: &Apache::lonnet::appenv(\%httpref);
4724: }
4725: if (keys(%cssrefs)) {
4726: foreach my $css_href (keys(%cssrefs)) {
4727: next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
4728: $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
4729: }
4730: }
4731: return $links;
4732: }
4733:
1.112 bowersj2 4734: =pod
4735:
1.648 raeburn 4736: =item * &get_student_answers()
1.112 bowersj2 4737:
4738: show a snapshot of how student was answering problem
4739:
4740: =cut
4741:
1.11 albertel 4742: sub get_student_answers {
1.100 sakharuk 4743: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4744: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4745: my (%moreenv);
1.11 albertel 4746: my @elements=('symb','courseid','domain','username');
4747: foreach my $element (@elements) {
1.186 albertel 4748: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4749: }
1.186 albertel 4750: $moreenv{'grade_target'}='answer';
4751: %moreenv=(%form,%moreenv);
1.497 raeburn 4752: $feedurl = &Apache::lonnet::clutter($feedurl);
4753: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4754: return $userview;
1.1 albertel 4755: }
1.116 albertel 4756:
4757: =pod
4758:
4759: =item * &submlink()
4760:
1.242 albertel 4761: Inputs: $text $uname $udom $symb $target
1.116 albertel 4762:
4763: Returns: A link to grades.pm such as to see the SUBM view of a student
4764:
4765: =cut
4766:
4767: ###############################################
4768: sub submlink {
1.242 albertel 4769: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4770: if (!($uname && $udom)) {
4771: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4772: &Apache::lonnet::whichuser($symb);
1.116 albertel 4773: if (!$symb) { $symb=$cursymb; }
4774: }
1.254 matthew 4775: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4776: $symb=&escape($symb);
1.960 bisitz 4777: if ($target) { $target=" target=\"$target\""; }
4778: return
4779: '<a href="/adm/grades?command=submission'.
4780: '&symb='.$symb.
4781: '&student='.$uname.
4782: '&userdom='.$udom.'"'.
4783: $target.'>'.$text.'</a>';
1.242 albertel 4784: }
4785: ##############################################
4786:
4787: =pod
4788:
4789: =item * &pgrdlink()
4790:
4791: Inputs: $text $uname $udom $symb $target
4792:
4793: Returns: A link to grades.pm such as to see the PGRD view of a student
4794:
4795: =cut
4796:
4797: ###############################################
4798: sub pgrdlink {
4799: my $link=&submlink(@_);
4800: $link=~s/(&command=submission)/$1&showgrading=yes/;
4801: return $link;
4802: }
4803: ##############################################
4804:
4805: =pod
4806:
4807: =item * &pprmlink()
4808:
4809: Inputs: $text $uname $udom $symb $target
4810:
4811: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4812: student and a specific resource
1.242 albertel 4813:
4814: =cut
4815:
4816: ###############################################
4817: sub pprmlink {
4818: my ($text,$uname,$udom,$symb,$target)=@_;
4819: if (!($uname && $udom)) {
4820: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4821: &Apache::lonnet::whichuser($symb);
1.242 albertel 4822: if (!$symb) { $symb=$cursymb; }
4823: }
1.254 matthew 4824: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4825: $symb=&escape($symb);
1.242 albertel 4826: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4827: return '<a href="/adm/parmset?command=set&'.
4828: 'symb='.$symb.'&uname='.$uname.
4829: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4830: }
4831: ##############################################
1.37 matthew 4832:
1.112 bowersj2 4833: =pod
4834:
4835: =back
4836:
4837: =cut
4838:
1.37 matthew 4839: ###############################################
1.51 www 4840:
4841:
4842: sub timehash {
1.687 raeburn 4843: my ($thistime) = @_;
4844: my $timezone = &Apache::lonlocal::gettimezone();
4845: my $dt = DateTime->from_epoch(epoch => $thistime)
4846: ->set_time_zone($timezone);
4847: my $wday = $dt->day_of_week();
4848: if ($wday == 7) { $wday = 0; }
4849: return ( 'second' => $dt->second(),
4850: 'minute' => $dt->minute(),
4851: 'hour' => $dt->hour(),
4852: 'day' => $dt->day_of_month(),
4853: 'month' => $dt->month(),
4854: 'year' => $dt->year(),
4855: 'weekday' => $wday,
4856: 'dayyear' => $dt->day_of_year(),
4857: 'dlsav' => $dt->is_dst() );
1.51 www 4858: }
4859:
1.370 www 4860: sub utc_string {
4861: my ($date)=@_;
1.371 www 4862: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4863: }
4864:
1.51 www 4865: sub maketime {
4866: my %th=@_;
1.687 raeburn 4867: my ($epoch_time,$timezone,$dt);
4868: $timezone = &Apache::lonlocal::gettimezone();
4869: eval {
4870: $dt = DateTime->new( year => $th{'year'},
4871: month => $th{'month'},
4872: day => $th{'day'},
4873: hour => $th{'hour'},
4874: minute => $th{'minute'},
4875: second => $th{'second'},
4876: time_zone => $timezone,
4877: );
4878: };
4879: if (!$@) {
4880: $epoch_time = $dt->epoch;
4881: if ($epoch_time) {
4882: return $epoch_time;
4883: }
4884: }
1.51 www 4885: return POSIX::mktime(
4886: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4887: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4888: }
4889:
4890: #########################################
1.51 www 4891:
4892: sub findallcourses {
1.482 raeburn 4893: my ($roles,$uname,$udom) = @_;
1.355 albertel 4894: my %roles;
4895: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4896: my %courses;
1.51 www 4897: my $now=time;
1.482 raeburn 4898: if (!defined($uname)) {
4899: $uname = $env{'user.name'};
4900: }
4901: if (!defined($udom)) {
4902: $udom = $env{'user.domain'};
4903: }
4904: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4905: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4906: if (!%roles) {
4907: %roles = (
4908: cc => 1,
1.907 raeburn 4909: co => 1,
1.482 raeburn 4910: in => 1,
4911: ep => 1,
4912: ta => 1,
4913: cr => 1,
4914: st => 1,
4915: );
4916: }
4917: foreach my $entry (keys(%roleshash)) {
4918: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4919: if ($trole =~ /^cr/) {
4920: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4921: } else {
4922: next if (!exists($roles{$trole}));
4923: }
4924: if ($tend) {
4925: next if ($tend < $now);
4926: }
4927: if ($tstart) {
4928: next if ($tstart > $now);
4929: }
1.1058 raeburn 4930: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4931: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4932: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4933: if ($secpart eq '') {
4934: ($cnum,$role) = split(/_/,$cnumpart);
4935: $sec = 'none';
1.1058 raeburn 4936: $value .= $cnum.'/';
1.482 raeburn 4937: } else {
4938: $cnum = $cnumpart;
4939: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4940: $value .= $cnum.'/'.$sec;
4941: }
4942: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4943: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4944: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4945: }
4946: } else {
4947: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4948: }
1.482 raeburn 4949: }
4950: } else {
4951: foreach my $key (keys(%env)) {
1.483 albertel 4952: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4953: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4954: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4955: next if ($role eq 'ca' || $role eq 'aa');
4956: next if (%roles && !exists($roles{$role}));
4957: my ($starttime,$endtime)=split(/\./,$env{$key});
4958: my $active=1;
4959: if ($starttime) {
4960: if ($now<$starttime) { $active=0; }
4961: }
4962: if ($endtime) {
4963: if ($now>$endtime) { $active=0; }
4964: }
4965: if ($active) {
1.1058 raeburn 4966: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4967: if ($sec eq '') {
4968: $sec = 'none';
1.1058 raeburn 4969: } else {
4970: $value .= $sec;
4971: }
4972: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4973: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4974: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4975: }
4976: } else {
4977: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4978: }
1.474 raeburn 4979: }
4980: }
1.51 www 4981: }
4982: }
1.474 raeburn 4983: return %courses;
1.51 www 4984: }
1.37 matthew 4985:
1.54 www 4986: ###############################################
1.474 raeburn 4987:
4988: sub blockcheck {
1.1075.2.158 raeburn 4989: my ($setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.490 raeburn 4990:
1.1075.2.161. .4(raebu 4991:22): unless (($activity eq 'docs') || ($activity eq 'reinit') || ($activity eq 'alert')) {
1.1075.2.158 raeburn 4992: my ($has_evb,$check_ipaccess);
4993: my $dom = $env{'user.domain'};
4994: if ($env{'request.course.id'}) {
4995: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4996: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4997: my $checkrole = "cm./$cdom/$cnum";
4998: my $sec = $env{'request.course.sec'};
4999: if ($sec ne '') {
5000: $checkrole .= "/$sec";
5001: }
5002: if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
5003: ($env{'request.role'} !~ /^st/)) {
5004: $has_evb = 1;
5005: }
5006: unless ($has_evb) {
5007: if (($activity eq 'printout') || ($activity eq 'grades') || ($activity eq 'search') ||
5008: ($activity eq 'boards') || ($activity eq 'groups') || ($activity eq 'chat')) {
5009: if ($udom eq $cdom) {
5010: $check_ipaccess = 1;
5011: }
5012: }
5013: }
1.1075.2.161. .3(raebu 5014:22): } elsif (($activity eq 'com') || ($activity eq 'port') || ($activity eq 'blogs') ||
5015:22): ($activity eq 'about') || ($activity eq 'wishlist') || ($activity eq 'passwd')) {
5016:22): my $checkrole;
5017:22): if ($env{'request.role.domain'} eq '') {
5018:22): $checkrole = "cm./$env{'user.domain'}/";
5019:22): } else {
5020:22): $checkrole = "cm./$env{'request.role.domain'}/";
5021:22): }
5022:22): if (($checkrole) && (&Apache::lonnet::allowed('evb',undef,undef,$checkrole))) {
5023:22): $has_evb = 1;
5024:22): }
1.1075.2.158 raeburn 5025: }
5026: unless ($has_evb || $check_ipaccess) {
5027: my @machinedoms = &Apache::lonnet::current_machine_domains();
5028: if (($dom eq 'public') && ($activity eq 'port')) {
5029: $dom = $udom;
5030: }
5031: if (($dom ne '') && (grep(/^\Q$dom\E$/,@machinedoms))) {
5032: $check_ipaccess = 1;
5033: } else {
5034: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
5035: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
5036: my $prim = &Apache::lonnet::domain($dom,'primary');
5037: my $intdom = &Apache::lonnet::internet_dom($prim);
5038: if (($intdom ne '') && (ref($internet_names) eq 'ARRAY')) {
5039: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5040: $check_ipaccess = 1;
5041: }
5042: }
5043: }
5044: }
5045: if ($check_ipaccess) {
5046: my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$dom);
5047: unless (defined($cached)) {
5048: my %domconfig =
5049: &Apache::lonnet::get_dom('configuration',['ipaccess'],$dom);
5050: $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$dom,$domconfig{'ipaccess'},1800);
5051: }
5052: if ((ref($ipaccessref) eq 'HASH') && ($clientip)) {
5053: foreach my $id (keys(%{$ipaccessref})) {
5054: if (ref($ipaccessref->{$id}) eq 'HASH') {
5055: my $range = $ipaccessref->{$id}->{'ip'};
5056: if ($range) {
5057: if (&Apache::lonnet::ip_match($clientip,$range)) {
5058: if (ref($ipaccessref->{$id}->{'commblocks'}) eq 'HASH') {
5059: if ($ipaccessref->{$id}->{'commblocks'}->{$activity} eq 'on') {
5060: return ('','','',$id,$dom);
5061: last;
5062: }
5063: }
5064: }
5065: }
5066: }
5067: }
5068: }
5069: }
1.1075.2.161. .4(raebu 5070:22): if (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5071:22): return ();
5072:22): }
1.1075.2.158 raeburn 5073: }
1.1075.2.73 raeburn 5074: if (defined($udom) && defined($uname)) {
5075: # If uname and udom are for a course, check for blocks in the course.
5076: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5077: my ($startblock,$endblock,$triggerblock) =
1.1075.2.147 raeburn 5078: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1075.2.73 raeburn 5079: return ($startblock,$endblock,$triggerblock);
5080: }
5081: } else {
1.490 raeburn 5082: $udom = $env{'user.domain'};
5083: $uname = $env{'user.name'};
5084: }
5085:
1.502 raeburn 5086: my $startblock = 0;
5087: my $endblock = 0;
1.1062 raeburn 5088: my $triggerblock = '';
1.1075.2.160 raeburn 5089: my %live_courses;
5090: unless (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5091: %live_courses = &findallcourses(undef,$uname,$udom);
5092: }
1.474 raeburn 5093:
1.490 raeburn 5094: # If uname is for a user, and activity is course-specific, i.e.,
5095: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5096:
1.490 raeburn 5097: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.161. .1(raebu 5098:21): $activity eq 'groups' || $activity eq 'printout' ||
5099:21): $activity eq 'search' || $activity eq 'reinit' ||
5100:21): $activity eq 'alert') && ($env{'request.course.id'})) {
1.490 raeburn 5101: foreach my $key (keys(%live_courses)) {
5102: if ($key ne $env{'request.course.id'}) {
5103: delete($live_courses{$key});
5104: }
5105: }
5106: }
5107:
5108: my $otheruser = 0;
5109: my %own_courses;
5110: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5111: # Resource belongs to user other than current user.
5112: $otheruser = 1;
5113: # Gather courses for current user
5114: %own_courses =
5115: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5116: }
5117:
5118: # Gather active course roles - course coordinator, instructor,
5119: # exam proctor, ta, student, or custom role.
1.474 raeburn 5120:
5121: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5122: my ($cdom,$cnum);
5123: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5124: $cdom = $env{'course.'.$course.'.domain'};
5125: $cnum = $env{'course.'.$course.'.num'};
5126: } else {
1.490 raeburn 5127: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5128: }
5129: my $no_ownblock = 0;
5130: my $no_userblock = 0;
1.533 raeburn 5131: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5132: # Check if current user has 'evb' priv for this
5133: if (defined($own_courses{$course})) {
5134: foreach my $sec (keys(%{$own_courses{$course}})) {
5135: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5136: if ($sec ne 'none') {
5137: $checkrole .= '/'.$sec;
5138: }
5139: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5140: $no_ownblock = 1;
5141: last;
5142: }
5143: }
5144: }
5145: # if they have 'evb' priv and are currently not playing student
5146: next if (($no_ownblock) &&
5147: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5148: }
1.474 raeburn 5149: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5150: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5151: if ($sec ne 'none') {
1.482 raeburn 5152: $checkrole .= '/'.$sec;
1.474 raeburn 5153: }
1.490 raeburn 5154: if ($otheruser) {
5155: # Resource belongs to user other than current user.
5156: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5157: my (%allroles,%userroles);
5158: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5159: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5160: my ($trole,$tdom,$tnum,$tsec);
5161: if ($entry =~ /^cr/) {
5162: ($trole,$tdom,$tnum,$tsec) =
5163: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5164: } else {
5165: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5166: }
5167: my ($spec,$area,$trest);
5168: $area = '/'.$tdom.'/'.$tnum;
5169: $trest = $tnum;
5170: if ($tsec ne '') {
5171: $area .= '/'.$tsec;
5172: $trest .= '/'.$tsec;
5173: }
5174: $spec = $trole.'.'.$area;
5175: if ($trole =~ /^cr/) {
5176: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5177: $tdom,$spec,$trest,$area);
5178: } else {
5179: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5180: $tdom,$spec,$trest,$area);
5181: }
5182: }
1.1075.2.124 raeburn 5183: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5184: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5185: if ($1) {
5186: $no_userblock = 1;
5187: last;
5188: }
1.486 raeburn 5189: }
5190: }
1.490 raeburn 5191: } else {
5192: # Resource belongs to current user
5193: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5194: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5195: $no_ownblock = 1;
5196: last;
5197: }
1.474 raeburn 5198: }
5199: }
5200: # if they have the evb priv and are currently not playing student
1.482 raeburn 5201: next if (($no_ownblock) &&
1.491 albertel 5202: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5203: next if ($no_userblock);
1.474 raeburn 5204:
1.1075.2.128 raeburn 5205: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5206: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 5207:
1.1062 raeburn 5208: my ($start,$end,$trigger) =
1.1075.2.147 raeburn 5209: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 5210: if (($start != 0) &&
5211: (($startblock == 0) || ($startblock > $start))) {
5212: $startblock = $start;
1.1062 raeburn 5213: if ($trigger ne '') {
5214: $triggerblock = $trigger;
5215: }
1.502 raeburn 5216: }
5217: if (($end != 0) &&
5218: (($endblock == 0) || ($endblock < $end))) {
5219: $endblock = $end;
1.1062 raeburn 5220: if ($trigger ne '') {
5221: $triggerblock = $trigger;
5222: }
1.502 raeburn 5223: }
1.490 raeburn 5224: }
1.1062 raeburn 5225: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5226: }
5227:
5228: sub get_blocks {
1.1075.2.147 raeburn 5229: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 5230: my $startblock = 0;
5231: my $endblock = 0;
1.1062 raeburn 5232: my $triggerblock = '';
1.490 raeburn 5233: my $course = $cdom.'_'.$cnum;
5234: $setters->{$course} = {};
5235: $setters->{$course}{'staff'} = [];
5236: $setters->{$course}{'times'} = [];
1.1062 raeburn 5237: $setters->{$course}{'triggers'} = [];
5238: my (@blockers,%triggered);
5239: my $now = time;
5240: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5241: if ($activity eq 'docs') {
1.1075.2.148 raeburn 5242: my ($blocked,$nosymbcache,$noenccheck);
1.1075.2.147 raeburn 5243: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
5244: $blocked = 1;
5245: $nosymbcache = 1;
1.1075.2.148 raeburn 5246: $noenccheck = 1;
1.1075.2.147 raeburn 5247: }
1.1075.2.148 raeburn 5248: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 5249: foreach my $block (@blockers) {
5250: if ($block =~ /^firstaccess____(.+)$/) {
5251: my $item = $1;
5252: my $type = 'map';
5253: my $timersymb = $item;
5254: if ($item eq 'course') {
5255: $type = 'course';
5256: } elsif ($item =~ /___\d+___/) {
5257: $type = 'resource';
5258: } else {
5259: $timersymb = &Apache::lonnet::symbread($item);
5260: }
5261: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5262: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5263: $triggered{$block} = {
5264: start => $start,
5265: end => $end,
5266: type => $type,
5267: };
5268: }
5269: }
5270: } else {
5271: foreach my $block (keys(%commblocks)) {
5272: if ($block =~ m/^(\d+)____(\d+)$/) {
5273: my ($start,$end) = ($1,$2);
5274: if ($start <= time && $end >= time) {
5275: if (ref($commblocks{$block}) eq 'HASH') {
5276: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5277: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5278: unless(grep(/^\Q$block\E$/,@blockers)) {
5279: push(@blockers,$block);
5280: }
5281: }
5282: }
5283: }
5284: }
5285: } elsif ($block =~ /^firstaccess____(.+)$/) {
5286: my $item = $1;
5287: my $timersymb = $item;
5288: my $type = 'map';
5289: if ($item eq 'course') {
5290: $type = 'course';
5291: } elsif ($item =~ /___\d+___/) {
5292: $type = 'resource';
5293: } else {
5294: $timersymb = &Apache::lonnet::symbread($item);
5295: }
5296: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5297: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5298: if ($start && $end) {
5299: if (($start <= time) && ($end >= time)) {
1.1075.2.158 raeburn 5300: if (ref($commblocks{$block}) eq 'HASH') {
5301: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5302: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5303: unless(grep(/^\Q$block\E$/,@blockers)) {
5304: push(@blockers,$block);
5305: $triggered{$block} = {
5306: start => $start,
5307: end => $end,
5308: type => $type,
5309: };
5310: }
5311: }
5312: }
1.1062 raeburn 5313: }
5314: }
1.490 raeburn 5315: }
1.1062 raeburn 5316: }
5317: }
5318: }
5319: foreach my $blocker (@blockers) {
5320: my ($staff_name,$staff_dom,$title,$blocks) =
5321: &parse_block_record($commblocks{$blocker});
5322: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5323: my ($start,$end,$triggertype);
5324: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5325: ($start,$end) = ($1,$2);
5326: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5327: $start = $triggered{$blocker}{'start'};
5328: $end = $triggered{$blocker}{'end'};
5329: $triggertype = $triggered{$blocker}{'type'};
5330: }
5331: if ($start) {
5332: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5333: if ($triggertype) {
5334: push(@{$$setters{$course}{'triggers'}},$triggertype);
5335: } else {
5336: push(@{$$setters{$course}{'triggers'}},0);
5337: }
5338: if ( ($startblock == 0) || ($startblock > $start) ) {
5339: $startblock = $start;
5340: if ($triggertype) {
5341: $triggerblock = $blocker;
1.474 raeburn 5342: }
5343: }
1.1062 raeburn 5344: if ( ($endblock == 0) || ($endblock < $end) ) {
5345: $endblock = $end;
5346: if ($triggertype) {
5347: $triggerblock = $blocker;
5348: }
5349: }
1.474 raeburn 5350: }
5351: }
1.1062 raeburn 5352: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5353: }
5354:
5355: sub parse_block_record {
5356: my ($record) = @_;
5357: my ($setuname,$setudom,$title,$blocks);
5358: if (ref($record) eq 'HASH') {
5359: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5360: $title = &unescape($record->{'event'});
5361: $blocks = $record->{'blocks'};
5362: } else {
5363: my @data = split(/:/,$record,3);
5364: if (scalar(@data) eq 2) {
5365: $title = $data[1];
5366: ($setuname,$setudom) = split(/@/,$data[0]);
5367: } else {
5368: ($setuname,$setudom,$title) = @data;
5369: }
5370: $blocks = { 'com' => 'on' };
5371: }
5372: return ($setuname,$setudom,$title,$blocks);
5373: }
5374:
1.854 kalberla 5375: sub blocking_status {
1.1075.2.158 raeburn 5376: my ($activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 5377: my %setters;
1.890 droeschl 5378:
1.1061 raeburn 5379: # check for active blocking
1.1075.2.158 raeburn 5380: if ($clientip eq '') {
5381: $clientip = &Apache::lonnet::get_requestor_ip();
5382: }
5383: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
5384: &blockcheck(\%setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 5385: my $blocked = 0;
1.1075.2.158 raeburn 5386: if (($startblock && $endblock) || ($by_ip)) {
1.1062 raeburn 5387: $blocked = 1;
5388: }
1.890 droeschl 5389:
1.1061 raeburn 5390: # caller just wants to know whether a block is active
5391: if (!wantarray) { return $blocked; }
5392:
5393: # build a link to a popup window containing the details
5394: my $querystring = "?activity=$activity";
1.1075.2.158 raeburn 5395: # $uname and $udom decide whose portfolio (or information page) the user is trying to look at
5396: if (($activity eq 'port') || ($activity eq 'about') || ($activity eq 'passwd')) {
1.1075.2.97 raeburn 5397: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5398: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5399: } elsif ($activity eq 'docs') {
1.1075.2.147 raeburn 5400: my $showurl = &Apache::lonenc::check_encrypt($url);
5401: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
5402: if ($symb) {
5403: my $showsymb = &Apache::lonenc::check_encrypt($symb);
5404: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
5405: }
1.1062 raeburn 5406: }
1.1061 raeburn 5407:
5408: my $output .= <<'END_MYBLOCK';
5409: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5410: var options = "width=" + w + ",height=" + h + ",";
5411: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5412: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5413: var newWin = window.open(url, wdwName, options);
5414: newWin.focus();
5415: }
1.890 droeschl 5416: END_MYBLOCK
1.854 kalberla 5417:
1.1061 raeburn 5418: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5419:
1.1061 raeburn 5420: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5421: my $text = &mt('Communication Blocked');
1.1075.2.93 raeburn 5422: my $class = 'LC_comblock';
1.1062 raeburn 5423: if ($activity eq 'docs') {
5424: $text = &mt('Content Access Blocked');
1.1075.2.93 raeburn 5425: $class = '';
1.1063 raeburn 5426: } elsif ($activity eq 'printout') {
5427: $text = &mt('Printing Blocked');
1.1075.2.97 raeburn 5428: } elsif ($activity eq 'passwd') {
5429: $text = &mt('Password Changing Blocked');
1.1075.2.158 raeburn 5430: } elsif ($activity eq 'grades') {
5431: $text = &mt('Gradebook Blocked');
5432: } elsif ($activity eq 'search') {
5433: $text = &mt('Search Blocked');
1.1075.2.161. .1(raebu 5434:21): } elsif ($activity eq 'alert') {
5435:21): $text = &mt('Checking Critical Messages Blocked');
5436:21): } elsif ($activity eq 'reinit') {
5437:21): $text = &mt('Checking Course Update Blocked');
1.1075.2.158 raeburn 5438: } elsif ($activity eq 'about') {
5439: $text = &mt('Access to User Information Pages Blocked');
1.1075.2.160 raeburn 5440: } elsif ($activity eq 'wishlist') {
5441: $text = &mt('Access to Stored Links Blocked');
5442: } elsif ($activity eq 'annotate') {
5443: $text = &mt('Access to Annotations Blocked');
1.1062 raeburn 5444: }
1.1061 raeburn 5445: $output .= <<"END_BLOCK";
1.1075.2.93 raeburn 5446: <div class='$class'>
1.869 kalberla 5447: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5448: title='$text'>
5449: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5450: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5451: title='$text'>$text</a>
1.867 kalberla 5452: </div>
5453:
5454: END_BLOCK
1.474 raeburn 5455:
1.1061 raeburn 5456: return ($blocked, $output);
1.854 kalberla 5457: }
1.490 raeburn 5458:
1.60 matthew 5459: ###############################################
5460:
1.682 raeburn 5461: sub check_ip_acc {
1.1075.2.105 raeburn 5462: my ($acc,$clientip)=@_;
1.682 raeburn 5463: &Apache::lonxml::debug("acc is $acc");
5464: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5465: return 1;
5466: }
5467: my $allowed=0;
1.1075.2.144 raeburn 5468: my $ip;
5469: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5470: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5471: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5472: } else {
1.1075.2.150 raeburn 5473: my $remote_ip = &Apache::lonnet::get_requestor_ip();
5474: $ip = $remote_ip || $env{'request.host'} || $clientip;
1.1075.2.144 raeburn 5475: }
1.682 raeburn 5476:
5477: my $name;
1.1075.2.161. .1(raebu 5478:21): my %access = (
5479:21): allowfrom => 1,
5480:21): denyfrom => 0,
5481:21): );
5482:21): my @allows;
5483:21): my @denies;
5484:21): foreach my $item (split(',',$acc)) {
5485:21): $item =~ s/^\s*//;
5486:21): $item =~ s/\s*$//;
5487:21): if ($item =~ /^\!(.+)$/) {
5488:21): push(@denies,$1);
5489:21): } else {
5490:21): push(@allows,$item);
5491:21): }
5492:21): }
5493:21): my $numdenies = scalar(@denies);
5494:21): my $numallows = scalar(@allows);
5495:21): my $count = 0;
5496:21): foreach my $pattern (@denies,@allows) {
5497:21): $count ++;
5498:21): my $acctype = 'allowfrom';
5499:21): if ($count <= $numdenies) {
5500:21): $acctype = 'denyfrom';
5501:21): }
1.682 raeburn 5502: if ($pattern =~ /\*$/) {
5503: #35.8.*
5504: $pattern=~s/\*//;
1.1075.2.161. .1(raebu 5505:21): if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5506: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5507: #35.8.3.[34-56]
5508: my $low=$2;
5509: my $high=$3;
5510: $pattern=$1;
5511: if ($ip =~ /^\Q$pattern\E/) {
5512: my $last=(split(/\./,$ip))[3];
1.1075.2.161. .1(raebu 5513:21): if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5514: }
5515: } elsif ($pattern =~ /^\*/) {
5516: #*.msu.edu
5517: $pattern=~s/\*//;
5518: if (!defined($name)) {
5519: use Socket;
5520: my $netaddr=inet_aton($ip);
5521: ($name)=gethostbyaddr($netaddr,AF_INET);
5522: }
1.1075.2.161. .1(raebu 5523:21): if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5524: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5525: #127.0.0.1
1.1075.2.161. .1(raebu 5526:21): if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5527: } else {
5528: #some.name.com
5529: if (!defined($name)) {
5530: use Socket;
5531: my $netaddr=inet_aton($ip);
5532: ($name)=gethostbyaddr($netaddr,AF_INET);
5533: }
1.1075.2.161. .1(raebu 5534:21): if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5535:21): }
5536:21): if ($allowed =~ /^(0|1)$/) { last; }
5537:21): }
5538:21): if ($allowed eq '') {
5539:21): if ($numdenies && !$numallows) {
5540:21): $allowed = 1;
5541:21): } else {
5542:21): $allowed = 0;
1.682 raeburn 5543: }
5544: }
5545: return $allowed;
5546: }
5547:
5548: ###############################################
5549:
1.60 matthew 5550: =pod
5551:
1.112 bowersj2 5552: =head1 Domain Template Functions
5553:
5554: =over 4
5555:
5556: =item * &determinedomain()
1.60 matthew 5557:
5558: Inputs: $domain (usually will be undef)
5559:
1.63 www 5560: Returns: Determines which domain should be used for designs
1.60 matthew 5561:
5562: =cut
1.54 www 5563:
1.60 matthew 5564: ###############################################
1.63 www 5565: sub determinedomain {
5566: my $domain=shift;
1.531 albertel 5567: if (! $domain) {
1.60 matthew 5568: # Determine domain if we have not been given one
1.893 raeburn 5569: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5570: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5571: if ($env{'request.role.domain'}) {
5572: $domain=$env{'request.role.domain'};
1.60 matthew 5573: }
5574: }
1.63 www 5575: return $domain;
5576: }
5577: ###############################################
1.517 raeburn 5578:
1.518 albertel 5579: sub devalidate_domconfig_cache {
5580: my ($udom)=@_;
5581: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5582: }
5583:
5584: # ---------------------- Get domain configuration for a domain
5585: sub get_domainconf {
5586: my ($udom) = @_;
5587: my $cachetime=1800;
5588: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5589: if (defined($cached)) { return %{$result}; }
5590:
5591: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5592: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5593: my (%designhash,%legacy);
1.518 albertel 5594: if (keys(%domconfig) > 0) {
5595: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5596: if (keys(%{$domconfig{'login'}})) {
5597: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5598: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 5599: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5600: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5601: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5602: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5603: if ($key eq 'loginvia') {
5604: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5605: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5606: $designhash{$udom.'.login.loginvia'} = $server;
5607: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5608: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5609: } else {
5610: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5611: }
1.948 raeburn 5612: }
1.1075.2.87 raeburn 5613: } elsif ($key eq 'headtag') {
5614: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5615: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5616: }
1.946 raeburn 5617: }
1.1075.2.87 raeburn 5618: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5619: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5620: }
1.946 raeburn 5621: }
5622: }
5623: }
1.1075.2.158 raeburn 5624: } elsif ($key eq 'saml') {
5625: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5626: foreach my $host (keys(%{$domconfig{'login'}{$key}})) {
5627: if (ref($domconfig{'login'}{$key}{$host}) eq 'HASH') {
5628: $designhash{$udom.'.login.'.$key.'_'.$host} = 1;
1.1075.2.161. .9(raebu 5629:22): foreach my $item ('text','img','alt','url','title','window','notsso') {
1.1075.2.158 raeburn 5630: $designhash{$udom.'.login.'.$key.'_'.$item.'_'.$host} = $domconfig{'login'}{$key}{$host}{$item};
5631: }
5632: }
5633: }
5634: }
1.946 raeburn 5635: } else {
5636: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5637: $designhash{$udom.'.login.'.$key.'_'.$img} =
5638: $domconfig{'login'}{$key}{$img};
5639: }
1.699 raeburn 5640: }
5641: } else {
5642: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5643: }
1.632 raeburn 5644: }
5645: } else {
5646: $legacy{'login'} = 1;
1.518 albertel 5647: }
1.632 raeburn 5648: } else {
5649: $legacy{'login'} = 1;
1.518 albertel 5650: }
5651: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5652: if (keys(%{$domconfig{'rolecolors'}})) {
5653: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5654: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5655: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5656: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5657: }
1.518 albertel 5658: }
5659: }
1.632 raeburn 5660: } else {
5661: $legacy{'rolecolors'} = 1;
1.518 albertel 5662: }
1.632 raeburn 5663: } else {
5664: $legacy{'rolecolors'} = 1;
1.518 albertel 5665: }
1.948 raeburn 5666: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5667: if ($domconfig{'autoenroll'}{'co-owners'}) {
5668: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5669: }
5670: }
1.632 raeburn 5671: if (keys(%legacy) > 0) {
5672: my %legacyhash = &get_legacy_domconf($udom);
5673: foreach my $item (keys(%legacyhash)) {
5674: if ($item =~ /^\Q$udom\E\.login/) {
5675: if ($legacy{'login'}) {
5676: $designhash{$item} = $legacyhash{$item};
5677: }
5678: } else {
5679: if ($legacy{'rolecolors'}) {
5680: $designhash{$item} = $legacyhash{$item};
5681: }
1.518 albertel 5682: }
5683: }
5684: }
1.632 raeburn 5685: } else {
5686: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5687: }
5688: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5689: $cachetime);
5690: return %designhash;
5691: }
5692:
1.632 raeburn 5693: sub get_legacy_domconf {
5694: my ($udom) = @_;
5695: my %legacyhash;
5696: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5697: my $designfile = $designdir.'/'.$udom.'.tab';
5698: if (-e $designfile) {
1.1075.2.128 raeburn 5699: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5700: while (my $line = <$fh>) {
5701: next if ($line =~ /^\#/);
5702: chomp($line);
5703: my ($key,$val)=(split(/\=/,$line));
5704: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5705: }
5706: close($fh);
5707: }
5708: }
1.1026 raeburn 5709: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5710: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5711: }
5712: return %legacyhash;
5713: }
5714:
1.63 www 5715: =pod
5716:
1.112 bowersj2 5717: =item * &domainlogo()
1.63 www 5718:
5719: Inputs: $domain (usually will be undef)
5720:
5721: Returns: A link to a domain logo, if the domain logo exists.
5722: If the domain logo does not exist, a description of the domain.
5723:
5724: =cut
1.112 bowersj2 5725:
1.63 www 5726: ###############################################
5727: sub domainlogo {
1.517 raeburn 5728: my $domain = &determinedomain(shift);
1.518 albertel 5729: my %designhash = &get_domainconf($domain);
1.517 raeburn 5730: # See if there is a logo
5731: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5732: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5733: if ($imgsrc =~ m{^/(adm|res)/}) {
5734: if ($imgsrc =~ m{^/res/}) {
5735: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5736: &Apache::lonnet::repcopy($local_name);
5737: }
5738: $imgsrc = &lonhttpdurl($imgsrc);
1.1075.2.161. .2(raebu 5739:22): }
5740:22): my $alttext = $domain;
5741:22): if ($designhash{$domain.'.login.alttext_domlogo'} ne '') {
5742:22): $alttext = $designhash{$domain.'.login.alttext_domlogo'};
5743:22): }
5744:22): return '<img src="'.$imgsrc.'" alt="'.$alttext.'" id="lclogindomlogo" />';
1.514 albertel 5745: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5746: return &Apache::lonnet::domain($domain,'description');
1.59 www 5747: } else {
1.60 matthew 5748: return '';
1.59 www 5749: }
5750: }
1.63 www 5751: ##############################################
5752:
5753: =pod
5754:
1.112 bowersj2 5755: =item * &designparm()
1.63 www 5756:
5757: Inputs: $which parameter; $domain (usually will be undef)
5758:
5759: Returns: value of designparamter $which
5760:
5761: =cut
1.112 bowersj2 5762:
1.397 albertel 5763:
1.400 albertel 5764: ##############################################
1.397 albertel 5765: sub designparm {
5766: my ($which,$domain)=@_;
5767: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5768: return $env{'environment.color.'.$which};
1.96 www 5769: }
1.63 www 5770: $domain=&determinedomain($domain);
1.1016 raeburn 5771: my %domdesign;
5772: unless ($domain eq 'public') {
5773: %domdesign = &get_domainconf($domain);
5774: }
1.520 raeburn 5775: my $output;
1.517 raeburn 5776: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5777: $output = $domdesign{$domain.'.'.$which};
1.63 www 5778: } else {
1.520 raeburn 5779: $output = $defaultdesign{$which};
5780: }
5781: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5782: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5783: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5784: if ($output =~ m{^/res/}) {
5785: my $local_name = &Apache::lonnet::filelocation('',$output);
5786: &Apache::lonnet::repcopy($local_name);
5787: }
1.520 raeburn 5788: $output = &lonhttpdurl($output);
5789: }
1.63 www 5790: }
1.520 raeburn 5791: return $output;
1.63 www 5792: }
1.59 www 5793:
1.822 bisitz 5794: ##############################################
5795: =pod
5796:
1.832 bisitz 5797: =item * &authorspace()
5798:
1.1028 raeburn 5799: Inputs: $url (usually will be undef).
1.832 bisitz 5800:
1.1075.2.40 raeburn 5801: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5802: directory being viewed (or for which action is being taken).
5803: If $url is provided, and begins /priv/<domain>/<uname>
5804: the path will be that portion of the $context argument.
5805: Otherwise the path will be for the author space of the current
5806: user when the current role is author, or for that of the
5807: co-author/assistant co-author space when the current role
5808: is co-author or assistant co-author.
1.832 bisitz 5809:
5810: =cut
5811:
5812: sub authorspace {
1.1028 raeburn 5813: my ($url) = @_;
5814: if ($url ne '') {
5815: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5816: return $1;
5817: }
5818: }
1.832 bisitz 5819: my $caname = '';
1.1024 www 5820: my $cadom = '';
1.1028 raeburn 5821: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5822: ($cadom,$caname) =
1.832 bisitz 5823: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5824: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5825: $caname = $env{'user.name'};
1.1024 www 5826: $cadom = $env{'user.domain'};
1.832 bisitz 5827: }
1.1028 raeburn 5828: if (($caname ne '') && ($cadom ne '')) {
5829: return "/priv/$cadom/$caname/";
5830: }
5831: return;
1.832 bisitz 5832: }
5833:
5834: ##############################################
5835: =pod
5836:
1.822 bisitz 5837: =item * &head_subbox()
5838:
5839: Inputs: $content (contains HTML code with page functions, etc.)
5840:
5841: Returns: HTML div with $content
5842: To be included in page header
5843:
5844: =cut
5845:
5846: sub head_subbox {
5847: my ($content)=@_;
5848: my $output =
1.993 raeburn 5849: '<div class="LC_head_subbox">'
1.822 bisitz 5850: .$content
5851: .'</div>'
5852: }
5853:
5854: ##############################################
5855: =pod
5856:
5857: =item * &CSTR_pageheader()
5858:
1.1026 raeburn 5859: Input: (optional) filename from which breadcrumb trail is built.
5860: In most cases no input as needed, as $env{'request.filename'}
5861: is appropriate for use in building the breadcrumb trail.
1.1075.2.161. .6(raebu 5862:22): frameset flag
5863:22): If page header is being requested for use in a frameset, then
5864:22): the second (option) argument -- frameset will be true, and
5865:22): the target attribute set for links should be target="_parent".
1.822 bisitz 5866:
5867: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5868: To be included on Authoring Space pages
1.822 bisitz 5869:
5870: =cut
5871:
5872: sub CSTR_pageheader {
1.1075.2.161. .6(raebu 5873:22): my ($trailfile,$frameset) = @_;
1.1026 raeburn 5874: if ($trailfile eq '') {
5875: $trailfile = $env{'request.filename'};
5876: }
5877:
5878: # this is for resources; directories have customtitle, and crumbs
5879: # and select recent are created in lonpubdir.pm
5880:
5881: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5882: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5883: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5884: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5885: $formaction =~ s{/+}{/}g;
1.822 bisitz 5886:
5887: my $parentpath = '';
5888: my $lastitem = '';
5889: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5890: $parentpath = $1;
5891: $lastitem = $2;
5892: } else {
5893: $lastitem = $thisdisfn;
5894: }
1.921 bisitz 5895:
1.1075.2.161. .6(raebu 5896:22): my ($target,$crumbtarget) = (' target="_top"','_top');
5897:22): if ($frameset) {
5898:22): $target = ' target="_parent"';
5899:22): $crumbtarget = '_parent';
.17(raeb 5900:-23): } elsif (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
5901:-23): $target = '';
5902:-23): $crumbtarget = '';
.6(raebu 5903:22): } elsif (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'})) {
5904:22): $target = ' target="'.$env{'request.deeplink.target'}.'"';
5905:22): $crumbtarget = $env{'request.deeplink.target'};
5906:22): }
5907:22):
1.921 bisitz 5908: my $output =
1.822 bisitz 5909: '<div>'
5910: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5911: .'<b>'.&mt('Authoring Space:').'</b> '
1.1075.2.161. .6(raebu 5912:22): .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
5913:22): .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 5914:
5915: if ($lastitem) {
5916: $output .=
5917: '<span class="LC_filename">'
5918: .$lastitem
5919: .'</span>';
5920: }
5921: $output .=
5922: '<br />'
1.1075.2.161. .6(raebu 5923:22): #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.822 bisitz 5924: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5925: .'</form>'
1.1075.2.161. .6(raebu 5926:22): .&Apache::lonmenu::constspaceform($frameset)
1.822 bisitz 5927: .'</div>';
1.921 bisitz 5928:
5929: return $output;
1.822 bisitz 5930: }
5931:
1.60 matthew 5932: ###############################################
5933: ###############################################
5934:
5935: =pod
5936:
1.112 bowersj2 5937: =back
5938:
1.549 albertel 5939: =head1 HTML Helpers
1.112 bowersj2 5940:
5941: =over 4
5942:
5943: =item * &bodytag()
1.60 matthew 5944:
5945: Returns a uniform header for LON-CAPA web pages.
5946:
5947: Inputs:
5948:
1.112 bowersj2 5949: =over 4
5950:
5951: =item * $title, A title to be displayed on the page.
5952:
5953: =item * $function, the current role (can be undef).
5954:
5955: =item * $addentries, extra parameters for the <body> tag.
5956:
5957: =item * $bodyonly, if defined, only return the <body> tag.
5958:
5959: =item * $domain, if defined, force a given domain.
5960:
5961: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5962: text interface only)
1.60 matthew 5963:
1.814 bisitz 5964: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5965: navigational links
1.317 albertel 5966:
1.338 albertel 5967: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5968:
1.1075.2.12 raeburn 5969: =item * $no_inline_link, if true and in remote mode, don't show the
5970: 'Switch To Inline Menu' link
5971:
1.460 albertel 5972: =item * $args, optional argument valid values are
5973: no_auto_mt_title -> prevents &mt()ing the title arg
1.1075.2.133 raeburn 5974: use_absolute -> for external resource or syllabus, this will
5975: contain https://<hostname> if server uses
5976: https (as per hosts.tab), but request is for http
5977: hostname -> hostname, from $r->hostname().
1.460 albertel 5978:
1.1075.2.15 raeburn 5979: =item * $advtoolsref, optional argument, ref to an array containing
5980: inlineremote items to be added in "Functions" menu below
5981: breadcrumbs.
5982:
1.1075.2.161. .1(raebu 5983:21): =item * $ltiscope, optional argument, will be one of: resource, map or
5984:21): course, if LON-CAPA is in LTI Provider context. Value is
5985:21): the scope of use, i.e., launch was for access to a single, a map
5986:21): or the entire course.
5987:21):
5988:21): =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
5989:21): context, this will contain the URL for the landing item in
5990:21): the course, after launch from an LTI Consumer
5991:21):
5992:21): =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
5993:21): context, this will contain a reference to hash of items
5994:21): to be included in the page header and/or inline menu.
5995:21):
.8(raebu 5996:22): =item * $menucoll, optional argument, if specific menu collection is in
5997:22): effect, either set as the default for the course, or set for
5998:22): the deeplink paramater for $env{'request.deeplink.login'}
5999:22): then $menucoll will be the number of that collection.
6000:22):
6001:22): =item * $menuref, optional argument, reference to a hash, containing the
6002:22): menu options included for the menu in effect, based on the
6003:22): configuration for the numbered menu collection in use.
6004:22):
6005:22): =item * $showncrumbsref, reference to a scalar. Calls to lonmenu::innerregister
6006:22): within &bodytag() can result in calls to lonhtmlcommon::breadcrumbs(),
6007:22): if so, $showncrumbsref is set there to 1, and will propagate back
6008:22): via &bodytag() to &start_page(), to prevent lonhtmlcommon::breadcrumbs()
6009:22): being called a second time.
6010:22):
1.112 bowersj2 6011: =back
6012:
1.60 matthew 6013: Returns: A uniform header for LON-CAPA web pages.
6014: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6015: If $bodyonly is undef or zero, an html string containing a <body> tag and
6016: other decorations will be returned.
6017:
6018: =cut
6019:
1.54 www 6020: sub bodytag {
1.831 bisitz 6021: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.161. .1(raebu 6022:21): $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref,
.8(raebu 6023:22): $ltiscope,$ltiuri,$ltimenu,$menucoll,$menuref,$showncrumbsref)=@_;
1.339 albertel 6024:
1.954 raeburn 6025: my $public;
6026: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6027: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6028: $public = 1;
6029: }
1.460 albertel 6030: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 6031: my $httphost = $args->{'use_absolute'};
1.1075.2.133 raeburn 6032: my $hostname = $args->{'hostname'};
1.339 albertel 6033:
1.183 matthew 6034: $function = &get_users_function() if (!$function);
1.339 albertel 6035: my $img = &designparm($function.'.img',$domain);
6036: my $font = &designparm($function.'.font',$domain);
6037: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6038:
1.803 bisitz 6039: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6040: 'bgcolor' => $pgbg,
1.339 albertel 6041: 'text' => $font,
6042: 'alink' => &designparm($function.'.alink',$domain),
6043: 'vlink' => &designparm($function.'.vlink',$domain),
6044: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6045: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6046:
1.63 www 6047: # role and realm
1.1075.2.68 raeburn 6048: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6049: if ($realm) {
6050: $realm = '/'.$realm;
6051: }
1.1075.2.159 raeburn 6052: if ($role eq 'ca') {
1.479 albertel 6053: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6054: $realm = &plainname($rname,$rdom);
1.378 raeburn 6055: }
1.55 www 6056: # realm
1.1075.2.158 raeburn 6057: my ($cid,$sec);
1.258 albertel 6058: if ($env{'request.course.id'}) {
1.1075.2.158 raeburn 6059: $cid = $env{'request.course.id'};
6060: if ($env{'request.course.sec'}) {
6061: $sec = $env{'request.course.sec'};
6062: }
6063: } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
6064: if (&Apache::lonnet::is_course($1,$2)) {
6065: $cid = $1.'_'.$2;
6066: $sec = $3;
6067: }
6068: }
6069: if ($cid) {
1.378 raeburn 6070: if ($env{'request.role'} !~ /^cr/) {
6071: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1075.2.115 raeburn 6072: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1075.2.121 raeburn 6073: if ($env{'request.role.desc'}) {
6074: $role = $env{'request.role.desc'};
6075: } else {
6076: $role = &mt('Helpdesk[_1]',' '.$2);
6077: }
1.1075.2.115 raeburn 6078: } else {
6079: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6080: }
1.1075.2.158 raeburn 6081: if ($sec) {
6082: $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
1.898 raeburn 6083: }
1.1075.2.158 raeburn 6084: $realm = $env{'course.'.$cid.'.description'};
1.378 raeburn 6085: } else {
6086: $role = &Apache::lonnet::plaintext($role);
1.54 www 6087: }
1.433 albertel 6088:
1.359 albertel 6089: if (!$realm) { $realm=' '; }
1.330 albertel 6090:
1.438 albertel 6091: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6092:
1.101 www 6093: # construct main body tag
1.359 albertel 6094: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 6095: &Apache::lontexconvert::init_math_support();
1.252 albertel 6096:
1.1075.2.38 raeburn 6097: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6098:
6099: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6100: return $bodytag;
1.1075.2.38 raeburn 6101: }
1.359 albertel 6102:
1.954 raeburn 6103: if ($public) {
1.433 albertel 6104: undef($role);
6105: }
1.1075.2.158 raeburn 6106:
1.1075.2.161. .1(raebu 6107:21): my $showcrstitle = 1;
6108:21): if (($cid) && ($env{'request.lti.login'})) {
6109:21): if (ref($ltimenu) eq 'HASH') {
6110:21): unless ($ltimenu->{'role'}) {
6111:21): undef($role);
6112:21): }
6113:21): unless ($ltimenu->{'coursetitle'}) {
6114:21): $realm=' ';
6115:21): $showcrstitle = 0;
6116:21): }
6117:21): }
6118:21): } elsif (($cid) && ($menucoll)) {
6119:21): if (ref($menuref) eq 'HASH') {
6120:21): unless ($menuref->{'role'}) {
6121:21): undef($role);
6122:21): }
6123:21): unless ($menuref->{'crs'}) {
6124:21): $realm=' ';
6125:21): $showcrstitle = 0;
6126:21): }
6127:21): }
6128:21): }
6129:21):
1.762 bisitz 6130: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6131: #
6132: # Extra info if you are the DC
6133: my $dc_info = '';
1.1075.2.161. .1(raebu 6134:21): if (($env{'user.adv'}) && ($env{'request.course.id'}) && $showcrstitle &&
1.1075.2.158 raeburn 6135: (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
1.917 raeburn 6136: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6137: $dc_info =~ s/\s+$//;
1.359 albertel 6138: }
6139:
1.1075.2.161. .1(raebu 6140:21): my $crstype;
6141:21): if ($cid) {
6142:21): $crstype = $env{'course.'.$cid.'.type'};
6143:21): } elsif ($args->{'crstype'}) {
6144:21): $crstype = $args->{'crstype'};
6145:21): }
6146:21):
1.1075.2.108 raeburn 6147: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903 droeschl 6148:
1.1075.2.13 raeburn 6149: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6150:
1.1075.2.38 raeburn 6151:
6152:
1.1075.2.21 raeburn 6153: my $funclist;
6154: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 6155: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 6156: Apache::lonmenu::serverform();
6157: my $forbodytag;
6158: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6159: $forcereg,$args->{'group'},
6160: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 6161: $advtoolsref,'','',\$forbodytag);
1.1075.2.21 raeburn 6162: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6163: $funclist = $forbodytag;
6164: }
6165: } else {
1.903 droeschl 6166:
6167: # if ($env{'request.state'} eq 'construct') {
6168: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6169: # }
6170:
1.1075.2.38 raeburn 6171: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 6172: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6173:
1.1075.2.161. .1(raebu 6174:21): unless ($args->{'no_primary_menu'}) {
.4(raebu 6175:22): my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref,
.6(raebu 6176:22): $args->{'links_disabled'},
6177:22): $args->{'links_target'});
.1(raebu 6178:21): if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6179:21): if ($dc_info) {
6180:21): $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6181:21): }
6182:21): $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6183:21): <em>$realm</em> $dc_info</div>|;
6184:21): return $bodytag;
1.1075.2.1 raeburn 6185: }
1.894 droeschl 6186:
1.1075.2.161. .1(raebu 6187:21): unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6188:21): $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6189:21): }
1.916 droeschl 6190:
1.1075.2.161. .1(raebu 6191:21): $bodytag .= $right;
1.852 droeschl 6192:
1.1075.2.161. .1(raebu 6193:21): if ($dc_info) {
6194:21): $dc_info = &dc_courseid_toggle($dc_info);
6195:21): }
6196:21): $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6197: }
1.916 droeschl 6198:
1.1075.2.61 raeburn 6199: #if directed to not display the secondary menu, don't.
6200: if ($args->{'no_secondary_menu'}) {
6201: return $bodytag;
6202: }
1.903 droeschl 6203: #don't show menus for public users
1.954 raeburn 6204: if (!$public){
1.1075.2.161. .1(raebu 6205:21): unless ($args->{'no_inline_menu'}) {
6206:21): $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
6207:21): $args->{'no_primary_menu'},
6208:21): $menucoll,$menuref,
.6(raebu 6209:22): $args->{'links_disabled'},
6210:22): $args->{'links_target'});
.1(raebu 6211:21): }
1.903 droeschl 6212: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6213: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6214: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6215: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1075.2.161. .8(raebu 6216:22): $args->{'bread_crumbs'},'','',$hostname,
6217:22): $ltiscope,$ltiuri,$showncrumbsref);
1.1075.2.116 raeburn 6218: } elsif ($forcereg) {
1.1075.2.22 raeburn 6219: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.161. .8(raebu 6220:22): $args->{'group'},$args->{'hide_buttons'},
6221:22): $hostname,$ltiscope,$ltiuri,$showncrumbsref);
1.1075.2.15 raeburn 6222: } else {
1.1075.2.21 raeburn 6223: my $forbodytag;
6224: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6225: $forcereg,$args->{'group'},
6226: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 6227: $advtoolsref,'',$hostname,
6228: \$forbodytag);
1.1075.2.21 raeburn 6229: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6230: $bodytag .= $forbodytag;
6231: }
1.920 raeburn 6232: }
1.903 droeschl 6233: }else{
6234: # this is to seperate menu from content when there's no secondary
6235: # menu. Especially needed for public accessible ressources.
6236: $bodytag .= '<hr style="clear:both" />';
6237: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6238: }
1.903 droeschl 6239:
1.235 raeburn 6240: return $bodytag;
1.1075.2.12 raeburn 6241: }
6242:
6243: #
6244: # Top frame rendering, Remote is up
6245: #
6246:
6247: my $imgsrc = $img;
6248: if ($img =~ /^\/adm/) {
6249: $imgsrc = &lonhttpdurl($img);
6250: }
6251: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
6252:
1.1075.2.60 raeburn 6253: my $help=($no_inline_link?''
6254: :&Apache::loncommon::top_nav_help('Help'));
6255:
1.1075.2.12 raeburn 6256: # Explicit link to get inline menu
6257: my $menu= ($no_inline_link?''
6258: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
6259:
6260: if ($dc_info) {
6261: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
6262: }
6263:
1.1075.2.38 raeburn 6264: my $name = &plainname($env{'user.name'},$env{'user.domain'});
6265: unless ($public) {
6266: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
6267: undef,'LC_menubuttons_link');
6268: }
6269:
1.1075.2.12 raeburn 6270: unless ($env{'form.inhibitmenu'}) {
6271: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 6272: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 6273: <li>$help</li>
1.1075.2.12 raeburn 6274: <li>$menu</li>
6275: </ol><div id="LC_realm"> $realm $dc_info</div>|;
6276: }
1.1075.2.13 raeburn 6277: if ($env{'request.state'} eq 'construct') {
6278: if (!$public){
6279: if ($env{'request.state'} eq 'construct') {
6280: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 6281: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 6282: &Apache::lonhtmlcommon::scripttag('','end').
6283: &Apache::lonmenu::innerregister($forcereg,
6284: $args->{'bread_crumbs'});
6285: }
6286: }
6287: }
1.1075.2.21 raeburn 6288: return $bodytag."\n".$funclist;
1.182 matthew 6289: }
6290:
1.917 raeburn 6291: sub dc_courseid_toggle {
6292: my ($dc_info) = @_;
1.980 raeburn 6293: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6294: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6295: &mt('(More ...)').'</a></span>'.
6296: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6297: }
6298:
1.330 albertel 6299: sub make_attr_string {
6300: my ($register,$attr_ref) = @_;
6301:
6302: if ($attr_ref && !ref($attr_ref)) {
6303: die("addentries Must be a hash ref ".
6304: join(':',caller(1))." ".
6305: join(':',caller(0))." ");
6306: }
6307:
6308: if ($register) {
1.339 albertel 6309: my ($on_load,$on_unload);
6310: foreach my $key (keys(%{$attr_ref})) {
6311: if (lc($key) eq 'onload') {
6312: $on_load.=$attr_ref->{$key}.';';
6313: delete($attr_ref->{$key});
6314:
6315: } elsif (lc($key) eq 'onunload') {
6316: $on_unload.=$attr_ref->{$key}.';';
6317: delete($attr_ref->{$key});
6318: }
6319: }
1.1075.2.12 raeburn 6320: if ($env{'environment.remote'} eq 'on') {
6321: $attr_ref->{'onload'} =
6322: &Apache::lonmenu::loadevents(). $on_load;
6323: $attr_ref->{'onunload'}=
6324: &Apache::lonmenu::unloadevents().$on_unload;
6325: } else {
6326: $attr_ref->{'onload'} = $on_load;
6327: $attr_ref->{'onunload'}= $on_unload;
6328: }
1.330 albertel 6329: }
1.339 albertel 6330:
1.330 albertel 6331: my $attr_string;
1.1075.2.56 raeburn 6332: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6333: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6334: }
6335: return $attr_string;
6336: }
6337:
6338:
1.182 matthew 6339: ###############################################
1.251 albertel 6340: ###############################################
6341:
6342: =pod
6343:
6344: =item * &endbodytag()
6345:
6346: Returns a uniform footer for LON-CAPA web pages.
6347:
1.635 raeburn 6348: Inputs: 1 - optional reference to an args hash
6349: If in the hash, key for noredirectlink has a value which evaluates to true,
6350: a 'Continue' link is not displayed if the page contains an
6351: internal redirect in the <head></head> section,
6352: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6353:
6354: =cut
6355:
6356: sub endbodytag {
1.635 raeburn 6357: my ($args) = @_;
1.1075.2.6 raeburn 6358: my $endbodytag;
6359: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6360: $endbodytag='</body>';
6361: }
1.315 albertel 6362: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6363: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
1.1075.2.161. .9(raebu 6364:22): my ($endbodyjs,$idattr);
6365:22): if ($env{'internal.head.to_opener'}) {
6366:22): my $linkid = 'LC_continue_link';
6367:22): $idattr = ' id="'.$linkid.'"';
6368:22): my $redirect_for_js = &js_escape($env{'internal.head.redirect'});
6369:22): $endbodyjs=<<ENDJS;
6370:22): <script type="text/javascript">
6371:22): // <![CDATA[
6372:22): function ebFunction(evt) {
6373:22): evt.preventDefault();
6374:22): var dest = '$redirect_for_js';
6375:22): if (window.opener != null && !window.opener.closed) {
6376:22): window.opener.location.href=dest;
6377:22): window.close();
6378:22): } else {
6379:22): window.location.href=dest;
6380:22): }
6381:22): return false;
6382:22): }
6383:22):
6384:22): \$(document).ready(function () {
6385:22): if (document.getElementById('$linkid')) {
6386:22): var clickelem = document.getElementById('$linkid');
6387:22): clickelem.addEventListener('click',ebFunction,false);
6388:22): }
6389:22): });
6390:22): // ]]>
6391:22): </script>
6392:22): ENDJS
6393:22): }
1.635 raeburn 6394: $endbodytag=
1.1075.2.161. .9(raebu 6395:22): "$endbodyjs<br /><a href=\"$env{'internal.head.redirect'}\"$idattr>".
1.635 raeburn 6396: &mt('Continue').'</a>'.
6397: $endbodytag;
6398: }
1.315 albertel 6399: }
1.1075.2.161. .19(raeb 6400:-23): if ((ref($args) eq 'HASH') && ($args->{'dashjs'})) {
6401:-23): $endbodytag = &Apache::lonhtmlcommon::dash_to_minus_js().$endbodytag;
6402:-23): }
1.251 albertel 6403: return $endbodytag;
6404: }
6405:
1.352 albertel 6406: =pod
6407:
6408: =item * &standard_css()
6409:
6410: Returns a style sheet
6411:
6412: Inputs: (all optional)
6413: domain -> force to color decorate a page for a specific
6414: domain
6415: function -> force usage of a specific rolish color scheme
6416: bgcolor -> override the default page bgcolor
6417:
6418: =cut
6419:
1.343 albertel 6420: sub standard_css {
1.345 albertel 6421: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6422: $function = &get_users_function() if (!$function);
6423: my $img = &designparm($function.'.img', $domain);
6424: my $tabbg = &designparm($function.'.tabbg', $domain);
6425: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6426: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6427: #second colour for later usage
1.345 albertel 6428: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6429: my $pgbg_or_bgcolor =
6430: $bgcolor ||
1.352 albertel 6431: &designparm($function.'.pgbg', $domain);
1.382 albertel 6432: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6433: my $alink = &designparm($function.'.alink', $domain);
6434: my $vlink = &designparm($function.'.vlink', $domain);
6435: my $link = &designparm($function.'.link', $domain);
6436:
1.602 albertel 6437: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6438: my $mono = 'monospace';
1.850 bisitz 6439: my $data_table_head = $sidebg;
6440: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6441: my $data_table_dark = '#E0E0E0';
1.470 banghart 6442: my $data_table_darker = '#CCCCCC';
1.349 albertel 6443: my $data_table_highlight = '#FFFF00';
1.352 albertel 6444: my $mail_new = '#FFBB77';
6445: my $mail_new_hover = '#DD9955';
6446: my $mail_read = '#BBBB77';
6447: my $mail_read_hover = '#999944';
6448: my $mail_replied = '#AAAA88';
6449: my $mail_replied_hover = '#888855';
6450: my $mail_other = '#99BBBB';
6451: my $mail_other_hover = '#669999';
1.391 albertel 6452: my $table_header = '#DDDDDD';
1.489 raeburn 6453: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6454: my $lg_border_color = '#C8C8C8';
1.952 onken 6455: my $button_hover = '#BF2317';
1.392 albertel 6456:
1.608 albertel 6457: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6458: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6459: : '0 3px 0 4px';
1.448 albertel 6460:
1.523 albertel 6461:
1.343 albertel 6462: return <<END;
1.947 droeschl 6463:
6464: /* needed for iframe to allow 100% height in FF */
6465: body, html {
6466: margin: 0;
6467: padding: 0 0.5%;
6468: height: 99%; /* to avoid scrollbars */
6469: }
6470:
1.795 www 6471: body {
1.911 bisitz 6472: font-family: $sans;
6473: line-height:130%;
6474: font-size:0.83em;
6475: color:$font;
1.795 www 6476: }
6477:
1.959 onken 6478: a:focus,
6479: a:focus img {
1.795 www 6480: color: red;
6481: }
1.698 harmsja 6482:
1.911 bisitz 6483: form, .inline {
6484: display: inline;
1.795 www 6485: }
1.721 harmsja 6486:
1.795 www 6487: .LC_right {
1.911 bisitz 6488: text-align:right;
1.795 www 6489: }
6490:
6491: .LC_middle {
1.911 bisitz 6492: vertical-align:middle;
1.795 www 6493: }
1.721 harmsja 6494:
1.1075.2.38 raeburn 6495: .LC_floatleft {
6496: float: left;
6497: }
6498:
6499: .LC_floatright {
6500: float: right;
6501: }
6502:
1.911 bisitz 6503: .LC_400Box {
6504: width:400px;
6505: }
1.721 harmsja 6506:
1.947 droeschl 6507: .LC_iframecontainer {
6508: width: 98%;
6509: margin: 0;
6510: position: fixed;
6511: top: 8.5em;
6512: bottom: 0;
6513: }
6514:
6515: .LC_iframecontainer iframe{
6516: border: none;
6517: width: 100%;
6518: height: 100%;
6519: }
6520:
1.778 bisitz 6521: .LC_filename {
6522: font-family: $mono;
6523: white-space:pre;
1.921 bisitz 6524: font-size: 120%;
1.778 bisitz 6525: }
6526:
6527: .LC_fileicon {
6528: border: none;
6529: height: 1.3em;
6530: vertical-align: text-bottom;
6531: margin-right: 0.3em;
6532: text-decoration:none;
6533: }
6534:
1.1008 www 6535: .LC_setting {
6536: text-decoration:underline;
6537: }
6538:
1.350 albertel 6539: .LC_error {
6540: color: red;
6541: }
1.795 www 6542:
1.1075.2.15 raeburn 6543: .LC_warning {
6544: color: darkorange;
6545: }
6546:
1.457 albertel 6547: .LC_diff_removed {
1.733 bisitz 6548: color: red;
1.394 albertel 6549: }
1.532 albertel 6550:
6551: .LC_info,
1.457 albertel 6552: .LC_success,
6553: .LC_diff_added {
1.350 albertel 6554: color: green;
6555: }
1.795 www 6556:
1.802 bisitz 6557: div.LC_confirm_box {
6558: background-color: #FAFAFA;
6559: border: 1px solid $lg_border_color;
6560: margin-right: 0;
6561: padding: 5px;
6562: }
6563:
6564: div.LC_confirm_box .LC_error img,
6565: div.LC_confirm_box .LC_success img {
6566: vertical-align: middle;
6567: }
6568:
1.1075.2.108 raeburn 6569: .LC_maxwidth {
6570: max-width: 100%;
6571: height: auto;
6572: }
6573:
6574: .LC_textsize_mobile {
6575: \@media only screen and (max-device-width: 480px) {
6576: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6577: }
6578: }
6579:
1.440 albertel 6580: .LC_icon {
1.771 droeschl 6581: border: none;
1.790 droeschl 6582: vertical-align: middle;
1.771 droeschl 6583: }
6584:
1.543 albertel 6585: .LC_docs_spacer {
6586: width: 25px;
6587: height: 1px;
1.771 droeschl 6588: border: none;
1.543 albertel 6589: }
1.346 albertel 6590:
1.532 albertel 6591: .LC_internal_info {
1.735 bisitz 6592: color: #999999;
1.532 albertel 6593: }
6594:
1.794 www 6595: .LC_discussion {
1.1050 www 6596: background: $data_table_dark;
1.911 bisitz 6597: border: 1px solid black;
6598: margin: 2px;
1.794 www 6599: }
6600:
6601: .LC_disc_action_left {
1.1050 www 6602: background: $sidebg;
1.911 bisitz 6603: text-align: left;
1.1050 www 6604: padding: 4px;
6605: margin: 2px;
1.794 www 6606: }
6607:
6608: .LC_disc_action_right {
1.1050 www 6609: background: $sidebg;
1.911 bisitz 6610: text-align: right;
1.1050 www 6611: padding: 4px;
6612: margin: 2px;
1.794 www 6613: }
6614:
6615: .LC_disc_new_item {
1.911 bisitz 6616: background: white;
6617: border: 2px solid red;
1.1050 www 6618: margin: 4px;
6619: padding: 4px;
1.794 www 6620: }
6621:
6622: .LC_disc_old_item {
1.911 bisitz 6623: background: white;
1.1050 www 6624: margin: 4px;
6625: padding: 4px;
1.794 www 6626: }
6627:
1.458 albertel 6628: table.LC_pastsubmission {
6629: border: 1px solid black;
6630: margin: 2px;
6631: }
6632:
1.924 bisitz 6633: table#LC_menubuttons {
1.345 albertel 6634: width: 100%;
6635: background: $pgbg;
1.392 albertel 6636: border: 2px;
1.402 albertel 6637: border-collapse: separate;
1.803 bisitz 6638: padding: 0;
1.345 albertel 6639: }
1.392 albertel 6640:
1.801 tempelho 6641: table#LC_title_bar a {
6642: color: $fontmenu;
6643: }
1.836 bisitz 6644:
1.807 droeschl 6645: table#LC_title_bar {
1.819 tempelho 6646: clear: both;
1.836 bisitz 6647: display: none;
1.807 droeschl 6648: }
6649:
1.795 www 6650: table#LC_title_bar,
1.933 droeschl 6651: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6652: table#LC_title_bar.LC_with_remote {
1.359 albertel 6653: width: 100%;
1.392 albertel 6654: border-color: $pgbg;
6655: border-style: solid;
6656: border-width: $border;
1.379 albertel 6657: background: $pgbg;
1.801 tempelho 6658: color: $fontmenu;
1.392 albertel 6659: border-collapse: collapse;
1.803 bisitz 6660: padding: 0;
1.819 tempelho 6661: margin: 0;
1.359 albertel 6662: }
1.795 www 6663:
1.933 droeschl 6664: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6665: margin: 0;
6666: padding: 0;
1.933 droeschl 6667: position: relative;
6668: list-style: none;
1.913 droeschl 6669: }
1.933 droeschl 6670: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6671: display: inline;
6672: }
1.933 droeschl 6673:
6674: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6675: padding: 0;
1.933 droeschl 6676: margin: 0;
6677: float: left;
1.913 droeschl 6678: }
1.933 droeschl 6679: .LC_breadcrumb_tools_tools {
6680: padding: 0;
6681: margin: 0;
1.913 droeschl 6682: float: right;
6683: }
6684:
1.359 albertel 6685: table#LC_title_bar td {
6686: background: $tabbg;
6687: }
1.795 www 6688:
1.911 bisitz 6689: table#LC_menubuttons img {
1.803 bisitz 6690: border: none;
1.346 albertel 6691: }
1.795 www 6692:
1.842 droeschl 6693: .LC_breadcrumbs_component {
1.911 bisitz 6694: float: right;
6695: margin: 0 1em;
1.357 albertel 6696: }
1.842 droeschl 6697: .LC_breadcrumbs_component img {
1.911 bisitz 6698: vertical-align: middle;
1.777 tempelho 6699: }
1.795 www 6700:
1.1075.2.108 raeburn 6701: .LC_breadcrumbs_hoverable {
6702: background: $sidebg;
6703: }
6704:
1.383 albertel 6705: td.LC_table_cell_checkbox {
6706: text-align: center;
6707: }
1.795 www 6708:
6709: .LC_fontsize_small {
1.911 bisitz 6710: font-size: 70%;
1.705 tempelho 6711: }
6712:
1.844 bisitz 6713: #LC_breadcrumbs {
1.911 bisitz 6714: clear:both;
6715: background: $sidebg;
6716: border-bottom: 1px solid $lg_border_color;
6717: line-height: 2.5em;
1.933 droeschl 6718: overflow: hidden;
1.911 bisitz 6719: margin: 0;
6720: padding: 0;
1.995 raeburn 6721: text-align: left;
1.819 tempelho 6722: }
1.862 bisitz 6723:
1.1075.2.16 raeburn 6724: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6725: clear:both;
6726: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6727: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6728: margin: 0 0 10px 0;
1.966 bisitz 6729: padding: 3px;
1.995 raeburn 6730: text-align: left;
1.822 bisitz 6731: }
6732:
1.795 www 6733: .LC_fontsize_medium {
1.911 bisitz 6734: font-size: 85%;
1.705 tempelho 6735: }
6736:
1.795 www 6737: .LC_fontsize_large {
1.911 bisitz 6738: font-size: 120%;
1.705 tempelho 6739: }
6740:
1.346 albertel 6741: .LC_menubuttons_inline_text {
6742: color: $font;
1.698 harmsja 6743: font-size: 90%;
1.701 harmsja 6744: padding-left:3px;
1.346 albertel 6745: }
6746:
1.934 droeschl 6747: .LC_menubuttons_inline_text img{
6748: vertical-align: middle;
6749: }
6750:
1.1051 www 6751: li.LC_menubuttons_inline_text img {
1.951 onken 6752: cursor:pointer;
1.1002 droeschl 6753: text-decoration: none;
1.951 onken 6754: }
6755:
1.526 www 6756: .LC_menubuttons_link {
6757: text-decoration: none;
6758: }
1.795 www 6759:
1.522 albertel 6760: .LC_menubuttons_category {
1.521 www 6761: color: $font;
1.526 www 6762: background: $pgbg;
1.521 www 6763: font-size: larger;
6764: font-weight: bold;
6765: }
6766:
1.346 albertel 6767: td.LC_menubuttons_text {
1.911 bisitz 6768: color: $font;
1.346 albertel 6769: }
1.706 harmsja 6770:
1.346 albertel 6771: .LC_current_location {
6772: background: $tabbg;
6773: }
1.795 www 6774:
1.1075.2.134 raeburn 6775: td.LC_zero_height {
6776: line-height: 0;
6777: cellpadding: 0;
6778: }
6779:
1.938 bisitz 6780: table.LC_data_table {
1.347 albertel 6781: border: 1px solid #000000;
1.402 albertel 6782: border-collapse: separate;
1.426 albertel 6783: border-spacing: 1px;
1.610 albertel 6784: background: $pgbg;
1.347 albertel 6785: }
1.795 www 6786:
1.422 albertel 6787: .LC_data_table_dense {
6788: font-size: small;
6789: }
1.795 www 6790:
1.507 raeburn 6791: table.LC_nested_outer {
6792: border: 1px solid #000000;
1.589 raeburn 6793: border-collapse: collapse;
1.803 bisitz 6794: border-spacing: 0;
1.507 raeburn 6795: width: 100%;
6796: }
1.795 www 6797:
1.879 raeburn 6798: table.LC_innerpickbox,
1.507 raeburn 6799: table.LC_nested {
1.803 bisitz 6800: border: none;
1.589 raeburn 6801: border-collapse: collapse;
1.803 bisitz 6802: border-spacing: 0;
1.507 raeburn 6803: width: 100%;
6804: }
1.795 www 6805:
1.911 bisitz 6806: table.LC_data_table tr th,
6807: table.LC_calendar tr th,
1.879 raeburn 6808: table.LC_prior_tries tr th,
6809: table.LC_innerpickbox tr th {
1.349 albertel 6810: font-weight: bold;
6811: background-color: $data_table_head;
1.801 tempelho 6812: color:$fontmenu;
1.701 harmsja 6813: font-size:90%;
1.347 albertel 6814: }
1.795 www 6815:
1.879 raeburn 6816: table.LC_innerpickbox tr th,
6817: table.LC_innerpickbox tr td {
6818: vertical-align: top;
6819: }
6820:
1.711 raeburn 6821: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6822: background-color: #CCCCCC;
1.711 raeburn 6823: font-weight: bold;
6824: text-align: left;
6825: }
1.795 www 6826:
1.912 bisitz 6827: table.LC_data_table tr.LC_odd_row > td {
6828: background-color: $data_table_light;
6829: padding: 2px;
6830: vertical-align: top;
6831: }
6832:
1.809 bisitz 6833: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6834: background-color: $data_table_light;
1.912 bisitz 6835: vertical-align: top;
6836: }
6837:
6838: table.LC_data_table tr.LC_even_row > td {
6839: background-color: $data_table_dark;
1.425 albertel 6840: padding: 2px;
1.900 bisitz 6841: vertical-align: top;
1.347 albertel 6842: }
1.795 www 6843:
1.809 bisitz 6844: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6845: background-color: $data_table_dark;
1.900 bisitz 6846: vertical-align: top;
1.347 albertel 6847: }
1.795 www 6848:
1.425 albertel 6849: table.LC_data_table tr.LC_data_table_highlight td {
6850: background-color: $data_table_darker;
6851: }
1.795 www 6852:
1.639 raeburn 6853: table.LC_data_table tr td.LC_leftcol_header {
6854: background-color: $data_table_head;
6855: font-weight: bold;
6856: }
1.795 www 6857:
1.451 albertel 6858: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6859: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6860: font-weight: bold;
6861: font-style: italic;
6862: text-align: center;
6863: padding: 8px;
1.347 albertel 6864: }
1.795 www 6865:
1.1075.2.30 raeburn 6866: table.LC_data_table tr.LC_empty_row td,
6867: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6868: background-color: $sidebg;
6869: }
6870:
6871: table.LC_nested tr.LC_empty_row td {
6872: background-color: #FFFFFF;
6873: }
6874:
1.890 droeschl 6875: table.LC_caption {
6876: }
6877:
1.507 raeburn 6878: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6879: padding: 4ex
6880: }
1.795 www 6881:
1.507 raeburn 6882: table.LC_nested_outer tr th {
6883: font-weight: bold;
1.801 tempelho 6884: color:$fontmenu;
1.507 raeburn 6885: background-color: $data_table_head;
1.701 harmsja 6886: font-size: small;
1.507 raeburn 6887: border-bottom: 1px solid #000000;
6888: }
1.795 www 6889:
1.507 raeburn 6890: table.LC_nested_outer tr td.LC_subheader {
6891: background-color: $data_table_head;
6892: font-weight: bold;
6893: font-size: small;
6894: border-bottom: 1px solid #000000;
6895: text-align: right;
1.451 albertel 6896: }
1.795 www 6897:
1.507 raeburn 6898: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6899: background-color: #CCCCCC;
1.451 albertel 6900: font-weight: bold;
6901: font-size: small;
1.507 raeburn 6902: text-align: center;
6903: }
1.795 www 6904:
1.589 raeburn 6905: table.LC_nested tr.LC_info_row td.LC_left_item,
6906: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6907: text-align: left;
1.451 albertel 6908: }
1.795 www 6909:
1.507 raeburn 6910: table.LC_nested td {
1.735 bisitz 6911: background-color: #FFFFFF;
1.451 albertel 6912: font-size: small;
1.507 raeburn 6913: }
1.795 www 6914:
1.507 raeburn 6915: table.LC_nested_outer tr th.LC_right_item,
6916: table.LC_nested tr.LC_info_row td.LC_right_item,
6917: table.LC_nested tr.LC_odd_row td.LC_right_item,
6918: table.LC_nested tr td.LC_right_item {
1.451 albertel 6919: text-align: right;
6920: }
6921:
1.507 raeburn 6922: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6923: background-color: #EEEEEE;
1.451 albertel 6924: }
6925:
1.473 raeburn 6926: table.LC_createuser {
6927: }
6928:
6929: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6930: font-size: small;
1.473 raeburn 6931: }
6932:
6933: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6934: background-color: #CCCCCC;
1.473 raeburn 6935: font-weight: bold;
6936: text-align: center;
6937: }
6938:
1.349 albertel 6939: table.LC_calendar {
6940: border: 1px solid #000000;
6941: border-collapse: collapse;
1.917 raeburn 6942: width: 98%;
1.349 albertel 6943: }
1.795 www 6944:
1.349 albertel 6945: table.LC_calendar_pickdate {
6946: font-size: xx-small;
6947: }
1.795 www 6948:
1.349 albertel 6949: table.LC_calendar tr td {
6950: border: 1px solid #000000;
6951: vertical-align: top;
1.917 raeburn 6952: width: 14%;
1.349 albertel 6953: }
1.795 www 6954:
1.349 albertel 6955: table.LC_calendar tr td.LC_calendar_day_empty {
6956: background-color: $data_table_dark;
6957: }
1.795 www 6958:
1.779 bisitz 6959: table.LC_calendar tr td.LC_calendar_day_current {
6960: background-color: $data_table_highlight;
1.777 tempelho 6961: }
1.795 www 6962:
1.938 bisitz 6963: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6964: background-color: $mail_new;
6965: }
1.795 www 6966:
1.938 bisitz 6967: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6968: background-color: $mail_new_hover;
6969: }
1.795 www 6970:
1.938 bisitz 6971: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6972: background-color: $mail_read;
6973: }
1.795 www 6974:
1.938 bisitz 6975: /*
6976: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6977: background-color: $mail_read_hover;
6978: }
1.938 bisitz 6979: */
1.795 www 6980:
1.938 bisitz 6981: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6982: background-color: $mail_replied;
6983: }
1.795 www 6984:
1.938 bisitz 6985: /*
6986: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6987: background-color: $mail_replied_hover;
6988: }
1.938 bisitz 6989: */
1.795 www 6990:
1.938 bisitz 6991: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6992: background-color: $mail_other;
6993: }
1.795 www 6994:
1.938 bisitz 6995: /*
6996: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6997: background-color: $mail_other_hover;
6998: }
1.938 bisitz 6999: */
1.494 raeburn 7000:
1.777 tempelho 7001: table.LC_data_table tr > td.LC_browser_file,
7002: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 7003: background: #AAEE77;
1.389 albertel 7004: }
1.795 www 7005:
1.777 tempelho 7006: table.LC_data_table tr > td.LC_browser_file_locked,
7007: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 7008: background: #FFAA99;
1.387 albertel 7009: }
1.795 www 7010:
1.777 tempelho 7011: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 7012: background: #888888;
1.779 bisitz 7013: }
1.795 www 7014:
1.777 tempelho 7015: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 7016: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 7017: background: #F8F866;
1.777 tempelho 7018: }
1.795 www 7019:
1.696 bisitz 7020: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 7021: background: #E0E8FF;
1.387 albertel 7022: }
1.696 bisitz 7023:
1.707 bisitz 7024: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 7025: /* background: #77FF77; */
1.707 bisitz 7026: }
1.795 www 7027:
1.707 bisitz 7028: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 7029: border-right: 8px solid #FFFF77;
1.707 bisitz 7030: }
1.795 www 7031:
1.707 bisitz 7032: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 7033: border-right: 8px solid #FFAA77;
1.707 bisitz 7034: }
1.795 www 7035:
1.707 bisitz 7036: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 7037: border-right: 8px solid #FF7777;
1.707 bisitz 7038: }
1.795 www 7039:
1.707 bisitz 7040: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 7041: border-right: 8px solid #AAFF77;
1.707 bisitz 7042: }
1.795 www 7043:
1.707 bisitz 7044: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 7045: border-right: 8px solid #11CC55;
1.707 bisitz 7046: }
7047:
1.388 albertel 7048: span.LC_current_location {
1.701 harmsja 7049: font-size:larger;
1.388 albertel 7050: background: $pgbg;
7051: }
1.387 albertel 7052:
1.1029 www 7053: span.LC_current_nav_location {
7054: font-weight:bold;
7055: background: $sidebg;
7056: }
7057:
1.395 albertel 7058: span.LC_parm_menu_item {
7059: font-size: larger;
7060: }
1.795 www 7061:
1.395 albertel 7062: span.LC_parm_scope_all {
7063: color: red;
7064: }
1.795 www 7065:
1.395 albertel 7066: span.LC_parm_scope_folder {
7067: color: green;
7068: }
1.795 www 7069:
1.395 albertel 7070: span.LC_parm_scope_resource {
7071: color: orange;
7072: }
1.795 www 7073:
1.395 albertel 7074: span.LC_parm_part {
7075: color: blue;
7076: }
1.795 www 7077:
1.911 bisitz 7078: span.LC_parm_folder,
7079: span.LC_parm_symb {
1.395 albertel 7080: font-size: x-small;
7081: font-family: $mono;
7082: color: #AAAAAA;
7083: }
7084:
1.977 bisitz 7085: ul.LC_parm_parmlist li {
7086: display: inline-block;
7087: padding: 0.3em 0.8em;
7088: vertical-align: top;
7089: width: 150px;
7090: border-top:1px solid $lg_border_color;
7091: }
7092:
1.795 www 7093: td.LC_parm_overview_level_menu,
7094: td.LC_parm_overview_map_menu,
7095: td.LC_parm_overview_parm_selectors,
7096: td.LC_parm_overview_restrictions {
1.396 albertel 7097: border: 1px solid black;
7098: border-collapse: collapse;
7099: }
1.795 www 7100:
1.396 albertel 7101: table.LC_parm_overview_restrictions td {
7102: border-width: 1px 4px 1px 4px;
7103: border-style: solid;
7104: border-color: $pgbg;
7105: text-align: center;
7106: }
1.795 www 7107:
1.396 albertel 7108: table.LC_parm_overview_restrictions th {
7109: background: $tabbg;
7110: border-width: 1px 4px 1px 4px;
7111: border-style: solid;
7112: border-color: $pgbg;
7113: }
1.795 www 7114:
1.398 albertel 7115: table#LC_helpmenu {
1.803 bisitz 7116: border: none;
1.398 albertel 7117: height: 55px;
1.803 bisitz 7118: border-spacing: 0;
1.398 albertel 7119: }
7120:
7121: table#LC_helpmenu fieldset legend {
7122: font-size: larger;
7123: }
1.795 www 7124:
1.397 albertel 7125: table#LC_helpmenu_links {
7126: width: 100%;
7127: border: 1px solid black;
7128: background: $pgbg;
1.803 bisitz 7129: padding: 0;
1.397 albertel 7130: border-spacing: 1px;
7131: }
1.795 www 7132:
1.397 albertel 7133: table#LC_helpmenu_links tr td {
7134: padding: 1px;
7135: background: $tabbg;
1.399 albertel 7136: text-align: center;
7137: font-weight: bold;
1.397 albertel 7138: }
1.396 albertel 7139:
1.795 www 7140: table#LC_helpmenu_links a:link,
7141: table#LC_helpmenu_links a:visited,
1.397 albertel 7142: table#LC_helpmenu_links a:active {
7143: text-decoration: none;
7144: color: $font;
7145: }
1.795 www 7146:
1.397 albertel 7147: table#LC_helpmenu_links a:hover {
7148: text-decoration: underline;
7149: color: $vlink;
7150: }
1.396 albertel 7151:
1.417 albertel 7152: .LC_chrt_popup_exists {
7153: border: 1px solid #339933;
7154: margin: -1px;
7155: }
1.795 www 7156:
1.417 albertel 7157: .LC_chrt_popup_up {
7158: border: 1px solid yellow;
7159: margin: -1px;
7160: }
1.795 www 7161:
1.417 albertel 7162: .LC_chrt_popup {
7163: border: 1px solid #8888FF;
7164: background: #CCCCFF;
7165: }
1.795 www 7166:
1.421 albertel 7167: table.LC_pick_box {
7168: border-collapse: separate;
7169: background: white;
7170: border: 1px solid black;
7171: border-spacing: 1px;
7172: }
1.795 www 7173:
1.421 albertel 7174: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7175: background: $sidebg;
1.421 albertel 7176: font-weight: bold;
1.900 bisitz 7177: text-align: left;
1.740 bisitz 7178: vertical-align: top;
1.421 albertel 7179: width: 184px;
7180: padding: 8px;
7181: }
1.795 www 7182:
1.579 raeburn 7183: table.LC_pick_box td.LC_pick_box_value {
7184: text-align: left;
7185: padding: 8px;
7186: }
1.795 www 7187:
1.579 raeburn 7188: table.LC_pick_box td.LC_pick_box_select {
7189: text-align: left;
7190: padding: 8px;
7191: }
1.795 www 7192:
1.424 albertel 7193: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7194: padding: 0;
1.421 albertel 7195: height: 1px;
7196: background: black;
7197: }
1.795 www 7198:
1.421 albertel 7199: table.LC_pick_box td.LC_pick_box_submit {
7200: text-align: right;
7201: }
1.795 www 7202:
1.579 raeburn 7203: table.LC_pick_box td.LC_evenrow_value {
7204: text-align: left;
7205: padding: 8px;
7206: background-color: $data_table_light;
7207: }
1.795 www 7208:
1.579 raeburn 7209: table.LC_pick_box td.LC_oddrow_value {
7210: text-align: left;
7211: padding: 8px;
7212: background-color: $data_table_light;
7213: }
1.795 www 7214:
1.579 raeburn 7215: span.LC_helpform_receipt_cat {
7216: font-weight: bold;
7217: }
1.795 www 7218:
1.424 albertel 7219: table.LC_group_priv_box {
7220: background: white;
7221: border: 1px solid black;
7222: border-spacing: 1px;
7223: }
1.795 www 7224:
1.424 albertel 7225: table.LC_group_priv_box td.LC_pick_box_title {
7226: background: $tabbg;
7227: font-weight: bold;
7228: text-align: right;
7229: width: 184px;
7230: }
1.795 www 7231:
1.424 albertel 7232: table.LC_group_priv_box td.LC_groups_fixed {
7233: background: $data_table_light;
7234: text-align: center;
7235: }
1.795 www 7236:
1.424 albertel 7237: table.LC_group_priv_box td.LC_groups_optional {
7238: background: $data_table_dark;
7239: text-align: center;
7240: }
1.795 www 7241:
1.424 albertel 7242: table.LC_group_priv_box td.LC_groups_functionality {
7243: background: $data_table_darker;
7244: text-align: center;
7245: font-weight: bold;
7246: }
1.795 www 7247:
1.424 albertel 7248: table.LC_group_priv td {
7249: text-align: left;
1.803 bisitz 7250: padding: 0;
1.424 albertel 7251: }
7252:
7253: .LC_navbuttons {
7254: margin: 2ex 0ex 2ex 0ex;
7255: }
1.795 www 7256:
1.423 albertel 7257: .LC_topic_bar {
7258: font-weight: bold;
7259: background: $tabbg;
1.918 wenzelju 7260: margin: 1em 0em 1em 2em;
1.805 bisitz 7261: padding: 3px;
1.918 wenzelju 7262: font-size: 1.2em;
1.423 albertel 7263: }
1.795 www 7264:
1.423 albertel 7265: .LC_topic_bar span {
1.918 wenzelju 7266: left: 0.5em;
7267: position: absolute;
1.423 albertel 7268: vertical-align: middle;
1.918 wenzelju 7269: font-size: 1.2em;
1.423 albertel 7270: }
1.795 www 7271:
1.423 albertel 7272: table.LC_course_group_status {
7273: margin: 20px;
7274: }
1.795 www 7275:
1.423 albertel 7276: table.LC_status_selector td {
7277: vertical-align: top;
7278: text-align: center;
1.424 albertel 7279: padding: 4px;
7280: }
1.795 www 7281:
1.599 albertel 7282: div.LC_feedback_link {
1.616 albertel 7283: clear: both;
1.829 kalberla 7284: background: $sidebg;
1.779 bisitz 7285: width: 100%;
1.829 kalberla 7286: padding-bottom: 10px;
7287: border: 1px $tabbg solid;
1.833 kalberla 7288: height: 22px;
7289: line-height: 22px;
7290: padding-top: 5px;
7291: }
7292:
7293: div.LC_feedback_link img {
7294: height: 22px;
1.867 kalberla 7295: vertical-align:middle;
1.829 kalberla 7296: }
7297:
1.911 bisitz 7298: div.LC_feedback_link a {
1.829 kalberla 7299: text-decoration: none;
1.489 raeburn 7300: }
1.795 www 7301:
1.867 kalberla 7302: div.LC_comblock {
1.911 bisitz 7303: display:inline;
1.867 kalberla 7304: color:$font;
7305: font-size:90%;
7306: }
7307:
7308: div.LC_feedback_link div.LC_comblock {
7309: padding-left:5px;
7310: }
7311:
7312: div.LC_feedback_link div.LC_comblock a {
7313: color:$font;
7314: }
7315:
1.489 raeburn 7316: span.LC_feedback_link {
1.858 bisitz 7317: /* background: $feedback_link_bg; */
1.599 albertel 7318: font-size: larger;
7319: }
1.795 www 7320:
1.599 albertel 7321: span.LC_message_link {
1.858 bisitz 7322: /* background: $feedback_link_bg; */
1.599 albertel 7323: font-size: larger;
7324: position: absolute;
7325: right: 1em;
1.489 raeburn 7326: }
1.421 albertel 7327:
1.515 albertel 7328: table.LC_prior_tries {
1.524 albertel 7329: border: 1px solid #000000;
7330: border-collapse: separate;
7331: border-spacing: 1px;
1.515 albertel 7332: }
1.523 albertel 7333:
1.515 albertel 7334: table.LC_prior_tries td {
1.524 albertel 7335: padding: 2px;
1.515 albertel 7336: }
1.523 albertel 7337:
7338: .LC_answer_correct {
1.795 www 7339: background: lightgreen;
7340: color: darkgreen;
7341: padding: 6px;
1.523 albertel 7342: }
1.795 www 7343:
1.523 albertel 7344: .LC_answer_charged_try {
1.797 www 7345: background: #FFAAAA;
1.795 www 7346: color: darkred;
7347: padding: 6px;
1.523 albertel 7348: }
1.795 www 7349:
1.779 bisitz 7350: .LC_answer_not_charged_try,
1.523 albertel 7351: .LC_answer_no_grade,
7352: .LC_answer_late {
1.795 www 7353: background: lightyellow;
1.523 albertel 7354: color: black;
1.795 www 7355: padding: 6px;
1.523 albertel 7356: }
1.795 www 7357:
1.523 albertel 7358: .LC_answer_previous {
1.795 www 7359: background: lightblue;
7360: color: darkblue;
7361: padding: 6px;
1.523 albertel 7362: }
1.795 www 7363:
1.779 bisitz 7364: .LC_answer_no_message {
1.777 tempelho 7365: background: #FFFFFF;
7366: color: black;
1.795 www 7367: padding: 6px;
1.779 bisitz 7368: }
1.795 www 7369:
1.1075.2.140 raeburn 7370: .LC_answer_unknown,
7371: .LC_answer_warning {
1.779 bisitz 7372: background: orange;
7373: color: black;
1.795 www 7374: padding: 6px;
1.777 tempelho 7375: }
1.795 www 7376:
1.529 albertel 7377: span.LC_prior_numerical,
7378: span.LC_prior_string,
7379: span.LC_prior_custom,
7380: span.LC_prior_reaction,
7381: span.LC_prior_math {
1.925 bisitz 7382: font-family: $mono;
1.523 albertel 7383: white-space: pre;
7384: }
7385:
1.525 albertel 7386: span.LC_prior_string {
1.925 bisitz 7387: font-family: $mono;
1.525 albertel 7388: white-space: pre;
7389: }
7390:
1.523 albertel 7391: table.LC_prior_option {
7392: width: 100%;
7393: border-collapse: collapse;
7394: }
1.795 www 7395:
1.911 bisitz 7396: table.LC_prior_rank,
1.795 www 7397: table.LC_prior_match {
1.528 albertel 7398: border-collapse: collapse;
7399: }
1.795 www 7400:
1.528 albertel 7401: table.LC_prior_option tr td,
7402: table.LC_prior_rank tr td,
7403: table.LC_prior_match tr td {
1.524 albertel 7404: border: 1px solid #000000;
1.515 albertel 7405: }
7406:
1.855 bisitz 7407: .LC_nobreak {
1.544 albertel 7408: white-space: nowrap;
1.519 raeburn 7409: }
7410:
1.576 raeburn 7411: span.LC_cusr_emph {
7412: font-style: italic;
7413: }
7414:
1.633 raeburn 7415: span.LC_cusr_subheading {
7416: font-weight: normal;
7417: font-size: 85%;
7418: }
7419:
1.861 bisitz 7420: div.LC_docs_entry_move {
1.859 bisitz 7421: border: 1px solid #BBBBBB;
1.545 albertel 7422: background: #DDDDDD;
1.861 bisitz 7423: width: 22px;
1.859 bisitz 7424: padding: 1px;
7425: margin: 0;
1.545 albertel 7426: }
7427:
1.861 bisitz 7428: table.LC_data_table tr > td.LC_docs_entry_commands,
7429: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7430: font-size: x-small;
7431: }
1.795 www 7432:
1.861 bisitz 7433: .LC_docs_entry_parameter {
7434: white-space: nowrap;
7435: }
7436:
1.544 albertel 7437: .LC_docs_copy {
1.545 albertel 7438: color: #000099;
1.544 albertel 7439: }
1.795 www 7440:
1.544 albertel 7441: .LC_docs_cut {
1.545 albertel 7442: color: #550044;
1.544 albertel 7443: }
1.795 www 7444:
1.544 albertel 7445: .LC_docs_rename {
1.545 albertel 7446: color: #009900;
1.544 albertel 7447: }
1.795 www 7448:
1.544 albertel 7449: .LC_docs_remove {
1.545 albertel 7450: color: #990000;
7451: }
7452:
1.1075.2.134 raeburn 7453: .LC_domprefs_email,
1.547 albertel 7454: .LC_docs_reinit_warn,
7455: .LC_docs_ext_edit {
7456: font-size: x-small;
7457: }
7458:
1.545 albertel 7459: table.LC_docs_adddocs td,
7460: table.LC_docs_adddocs th {
7461: border: 1px solid #BBBBBB;
7462: padding: 4px;
7463: background: #DDDDDD;
1.543 albertel 7464: }
7465:
1.584 albertel 7466: table.LC_sty_begin {
7467: background: #BBFFBB;
7468: }
1.795 www 7469:
1.584 albertel 7470: table.LC_sty_end {
7471: background: #FFBBBB;
7472: }
7473:
1.589 raeburn 7474: table.LC_double_column {
1.803 bisitz 7475: border-width: 0;
1.589 raeburn 7476: border-collapse: collapse;
7477: width: 100%;
7478: padding: 2px;
7479: }
7480:
7481: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7482: top: 2px;
1.589 raeburn 7483: left: 2px;
7484: width: 47%;
7485: vertical-align: top;
7486: }
7487:
7488: table.LC_double_column tr td.LC_right_col {
7489: top: 2px;
1.779 bisitz 7490: right: 2px;
1.589 raeburn 7491: width: 47%;
7492: vertical-align: top;
7493: }
7494:
1.591 raeburn 7495: div.LC_left_float {
7496: float: left;
7497: padding-right: 5%;
1.597 albertel 7498: padding-bottom: 4px;
1.591 raeburn 7499: }
7500:
7501: div.LC_clear_float_header {
1.597 albertel 7502: padding-bottom: 2px;
1.591 raeburn 7503: }
7504:
7505: div.LC_clear_float_footer {
1.597 albertel 7506: padding-top: 10px;
1.591 raeburn 7507: clear: both;
7508: }
7509:
1.597 albertel 7510: div.LC_grade_show_user {
1.941 bisitz 7511: /* border-left: 5px solid $sidebg; */
7512: border-top: 5px solid #000000;
7513: margin: 50px 0 0 0;
1.936 bisitz 7514: padding: 15px 0 5px 10px;
1.597 albertel 7515: }
1.795 www 7516:
1.936 bisitz 7517: div.LC_grade_show_user_odd_row {
1.941 bisitz 7518: /* border-left: 5px solid #000000; */
7519: }
7520:
7521: div.LC_grade_show_user div.LC_Box {
7522: margin-right: 50px;
1.597 albertel 7523: }
7524:
7525: div.LC_grade_submissions,
7526: div.LC_grade_message_center,
1.936 bisitz 7527: div.LC_grade_info_links {
1.597 albertel 7528: margin: 5px;
7529: width: 99%;
7530: background: #FFFFFF;
7531: }
1.795 www 7532:
1.597 albertel 7533: div.LC_grade_submissions_header,
1.936 bisitz 7534: div.LC_grade_message_center_header {
1.705 tempelho 7535: font-weight: bold;
7536: font-size: large;
1.597 albertel 7537: }
1.795 www 7538:
1.597 albertel 7539: div.LC_grade_submissions_body,
1.936 bisitz 7540: div.LC_grade_message_center_body {
1.597 albertel 7541: border: 1px solid black;
7542: width: 99%;
7543: background: #FFFFFF;
7544: }
1.795 www 7545:
1.613 albertel 7546: table.LC_scantron_action {
7547: width: 100%;
7548: }
1.795 www 7549:
1.613 albertel 7550: table.LC_scantron_action tr th {
1.698 harmsja 7551: font-weight:bold;
7552: font-style:normal;
1.613 albertel 7553: }
1.795 www 7554:
1.779 bisitz 7555: .LC_edit_problem_header,
1.614 albertel 7556: div.LC_edit_problem_footer {
1.705 tempelho 7557: font-weight: normal;
7558: font-size: medium;
1.602 albertel 7559: margin: 2px;
1.1060 bisitz 7560: background-color: $sidebg;
1.600 albertel 7561: }
1.795 www 7562:
1.600 albertel 7563: div.LC_edit_problem_header,
1.602 albertel 7564: div.LC_edit_problem_header div,
1.614 albertel 7565: div.LC_edit_problem_footer,
7566: div.LC_edit_problem_footer div,
1.602 albertel 7567: div.LC_edit_problem_editxml_header,
7568: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 7569: z-index: 100;
1.600 albertel 7570: }
1.795 www 7571:
1.600 albertel 7572: div.LC_edit_problem_header_title {
1.705 tempelho 7573: font-weight: bold;
7574: font-size: larger;
1.602 albertel 7575: background: $tabbg;
7576: padding: 3px;
1.1060 bisitz 7577: margin: 0 0 5px 0;
1.602 albertel 7578: }
1.795 www 7579:
1.602 albertel 7580: table.LC_edit_problem_header_title {
7581: width: 100%;
1.600 albertel 7582: background: $tabbg;
1.602 albertel 7583: }
7584:
1.1075.2.112 raeburn 7585: div.LC_edit_actionbar {
7586: background-color: $sidebg;
7587: margin: 0;
7588: padding: 0;
7589: line-height: 200%;
1.602 albertel 7590: }
1.795 www 7591:
1.1075.2.112 raeburn 7592: div.LC_edit_actionbar div{
7593: padding: 0;
7594: margin: 0;
7595: display: inline-block;
1.600 albertel 7596: }
1.795 www 7597:
1.1075.2.34 raeburn 7598: .LC_edit_opt {
7599: padding-left: 1em;
7600: white-space: nowrap;
7601: }
7602:
1.1075.2.57 raeburn 7603: .LC_edit_problem_latexhelper{
7604: text-align: right;
7605: }
7606:
7607: #LC_edit_problem_colorful div{
7608: margin-left: 40px;
7609: }
7610:
1.1075.2.112 raeburn 7611: #LC_edit_problem_codemirror div{
7612: margin-left: 0px;
7613: }
7614:
1.911 bisitz 7615: img.stift {
1.803 bisitz 7616: border-width: 0;
7617: vertical-align: middle;
1.677 riegler 7618: }
1.680 riegler 7619:
1.923 bisitz 7620: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7621: vertical-align: top;
1.777 tempelho 7622: }
1.795 www 7623:
1.716 raeburn 7624: div.LC_createcourse {
1.911 bisitz 7625: margin: 10px 10px 10px 10px;
1.716 raeburn 7626: }
7627:
1.917 raeburn 7628: .LC_dccid {
1.1075.2.38 raeburn 7629: float: right;
1.917 raeburn 7630: margin: 0.2em 0 0 0;
7631: padding: 0;
7632: font-size: 90%;
7633: display:none;
7634: }
7635:
1.897 wenzelju 7636: ol.LC_primary_menu a:hover,
1.721 harmsja 7637: ol#LC_MenuBreadcrumbs a:hover,
7638: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7639: ul#LC_secondary_menu a:hover,
1.721 harmsja 7640: .LC_FormSectionClearButton input:hover
1.795 www 7641: ul.LC_TabContent li:hover a {
1.952 onken 7642: color:$button_hover;
1.911 bisitz 7643: text-decoration:none;
1.693 droeschl 7644: }
7645:
1.779 bisitz 7646: h1 {
1.911 bisitz 7647: padding: 0;
7648: line-height:130%;
1.693 droeschl 7649: }
1.698 harmsja 7650:
1.911 bisitz 7651: h2,
7652: h3,
7653: h4,
7654: h5,
7655: h6 {
7656: margin: 5px 0 5px 0;
7657: padding: 0;
7658: line-height:130%;
1.693 droeschl 7659: }
1.795 www 7660:
7661: .LC_hcell {
1.911 bisitz 7662: padding:3px 15px 3px 15px;
7663: margin: 0;
7664: background-color:$tabbg;
7665: color:$fontmenu;
7666: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7667: }
1.795 www 7668:
1.840 bisitz 7669: .LC_Box > .LC_hcell {
1.911 bisitz 7670: margin: 0 -10px 10px -10px;
1.835 bisitz 7671: }
7672:
1.721 harmsja 7673: .LC_noBorder {
1.911 bisitz 7674: border: 0;
1.698 harmsja 7675: }
1.693 droeschl 7676:
1.721 harmsja 7677: .LC_FormSectionClearButton input {
1.911 bisitz 7678: background-color:transparent;
7679: border: none;
7680: cursor:pointer;
7681: text-decoration:underline;
1.693 droeschl 7682: }
1.763 bisitz 7683:
7684: .LC_help_open_topic {
1.911 bisitz 7685: color: #FFFFFF;
7686: background-color: #EEEEFF;
7687: margin: 1px;
7688: padding: 4px;
7689: border: 1px solid #000033;
7690: white-space: nowrap;
7691: /* vertical-align: middle; */
1.759 neumanie 7692: }
1.693 droeschl 7693:
1.911 bisitz 7694: dl,
7695: ul,
7696: div,
7697: fieldset {
7698: margin: 10px 10px 10px 0;
7699: /* overflow: hidden; */
1.693 droeschl 7700: }
1.795 www 7701:
1.1075.2.161. .18(raeb 7702:-23): fieldset#LC_selectuser {
7703:-23): margin: 0;
7704:-23): padding: 0;
7705:-23): }
7706:-23):
1.1075.2.90 raeburn 7707: article.geogebraweb div {
7708: margin: 0;
7709: }
7710:
1.838 bisitz 7711: fieldset > legend {
1.911 bisitz 7712: font-weight: bold;
7713: padding: 0 5px 0 5px;
1.838 bisitz 7714: }
7715:
1.813 bisitz 7716: #LC_nav_bar {
1.911 bisitz 7717: float: left;
1.995 raeburn 7718: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7719: margin: 0 0 2px 0;
1.807 droeschl 7720: }
7721:
1.916 droeschl 7722: #LC_realm {
7723: margin: 0.2em 0 0 0;
7724: padding: 0;
7725: font-weight: bold;
7726: text-align: center;
1.995 raeburn 7727: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7728: }
7729:
1.911 bisitz 7730: #LC_nav_bar em {
7731: font-weight: bold;
7732: font-style: normal;
1.807 droeschl 7733: }
7734:
1.897 wenzelju 7735: ol.LC_primary_menu {
1.934 droeschl 7736: margin: 0;
1.1075.2.2 raeburn 7737: padding: 0;
1.807 droeschl 7738: }
7739:
1.852 droeschl 7740: ol#LC_PathBreadcrumbs {
1.911 bisitz 7741: margin: 0;
1.693 droeschl 7742: }
7743:
1.897 wenzelju 7744: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7745: color: RGB(80, 80, 80);
7746: vertical-align: middle;
7747: text-align: left;
7748: list-style: none;
1.1075.2.112 raeburn 7749: position: relative;
1.1075.2.2 raeburn 7750: float: left;
1.1075.2.112 raeburn 7751: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7752: line-height: 1.5em;
1.1075.2.2 raeburn 7753: }
7754:
1.1075.2.113 raeburn 7755: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7756: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7757: display: block;
7758: margin: 0;
7759: padding: 0 5px 0 10px;
7760: text-decoration: none;
7761: }
7762:
1.1075.2.112 raeburn 7763: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7764: display: inline-block;
7765: width: 95%;
7766: text-align: left;
7767: }
7768:
7769: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7770: display: inline-block;
7771: width: 5%;
7772: float: right;
7773: text-align: right;
7774: font-size: 70%;
7775: }
7776:
7777: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7778: display: none;
1.1075.2.112 raeburn 7779: width: 15em;
1.1075.2.2 raeburn 7780: background-color: $data_table_light;
1.1075.2.112 raeburn 7781: position: absolute;
7782: top: 100%;
7783: }
7784:
7785: ol.LC_primary_menu ul ul {
7786: left: 100%;
7787: top: 0;
1.1075.2.2 raeburn 7788: }
7789:
1.1075.2.112 raeburn 7790: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7791: display: block;
7792: position: absolute;
7793: margin: 0;
7794: padding: 0;
1.1075.2.5 raeburn 7795: z-index: 2;
1.1075.2.2 raeburn 7796: }
7797:
7798: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7799: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7800: font-size: 90%;
1.911 bisitz 7801: vertical-align: top;
1.1075.2.2 raeburn 7802: float: none;
1.1075.2.5 raeburn 7803: border-left: 1px solid black;
7804: border-right: 1px solid black;
1.1075.2.112 raeburn 7805: /* A dark bottom border to visualize different menu options;
7806: overwritten in the create_submenu routine for the last border-bottom of the menu */
7807: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7808: }
7809:
1.1075.2.112 raeburn 7810: ol.LC_primary_menu li li p:hover {
7811: color:$button_hover;
7812: text-decoration:none;
7813: background-color:$data_table_dark;
1.1075.2.2 raeburn 7814: }
7815:
7816: ol.LC_primary_menu li li a:hover {
7817: color:$button_hover;
7818: background-color:$data_table_dark;
1.693 droeschl 7819: }
7820:
1.1075.2.112 raeburn 7821: /* Font-size equal to the size of the predecessors*/
7822: ol.LC_primary_menu li:hover li li {
7823: font-size: 100%;
7824: }
7825:
1.897 wenzelju 7826: ol.LC_primary_menu li img {
1.911 bisitz 7827: vertical-align: bottom;
1.934 droeschl 7828: height: 1.1em;
1.1075.2.3 raeburn 7829: margin: 0.2em 0 0 0;
1.693 droeschl 7830: }
7831:
1.897 wenzelju 7832: ol.LC_primary_menu a {
1.911 bisitz 7833: color: RGB(80, 80, 80);
7834: text-decoration: none;
1.693 droeschl 7835: }
1.795 www 7836:
1.949 droeschl 7837: ol.LC_primary_menu a.LC_new_message {
7838: font-weight:bold;
7839: color: darkred;
7840: }
7841:
1.975 raeburn 7842: ol.LC_docs_parameters {
7843: margin-left: 0;
7844: padding: 0;
7845: list-style: none;
7846: }
7847:
7848: ol.LC_docs_parameters li {
7849: margin: 0;
7850: padding-right: 20px;
7851: display: inline;
7852: }
7853:
1.976 raeburn 7854: ol.LC_docs_parameters li:before {
7855: content: "\\002022 \\0020";
7856: }
7857:
7858: li.LC_docs_parameters_title {
7859: font-weight: bold;
7860: }
7861:
7862: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7863: content: "";
7864: }
7865:
1.897 wenzelju 7866: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7867: clear: right;
1.911 bisitz 7868: color: $fontmenu;
7869: background: $tabbg;
7870: list-style: none;
7871: padding: 0;
7872: margin: 0;
7873: width: 100%;
1.995 raeburn 7874: text-align: left;
1.1075.2.4 raeburn 7875: float: left;
1.808 droeschl 7876: }
7877:
1.897 wenzelju 7878: ul#LC_secondary_menu li {
1.911 bisitz 7879: font-weight: bold;
7880: line-height: 1.8em;
7881: border-right: 1px solid black;
1.1075.2.4 raeburn 7882: float: left;
7883: }
7884:
7885: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7886: background-color: $data_table_light;
7887: }
7888:
7889: ul#LC_secondary_menu li a {
7890: padding: 0 0.8em;
7891: }
7892:
7893: ul#LC_secondary_menu li ul {
7894: display: none;
7895: }
7896:
7897: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7898: display: block;
7899: position: absolute;
7900: margin: 0;
7901: padding: 0;
7902: list-style:none;
7903: float: none;
7904: background-color: $data_table_light;
1.1075.2.5 raeburn 7905: z-index: 2;
1.1075.2.10 raeburn 7906: margin-left: -1px;
1.1075.2.4 raeburn 7907: }
7908:
7909: ul#LC_secondary_menu li ul li {
7910: font-size: 90%;
7911: vertical-align: top;
7912: border-left: 1px solid black;
7913: border-right: 1px solid black;
1.1075.2.33 raeburn 7914: background-color: $data_table_light;
1.1075.2.4 raeburn 7915: list-style:none;
7916: float: none;
7917: }
7918:
7919: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7920: background-color: $data_table_dark;
1.807 droeschl 7921: }
7922:
1.847 tempelho 7923: ul.LC_TabContent {
1.911 bisitz 7924: display:block;
7925: background: $sidebg;
7926: border-bottom: solid 1px $lg_border_color;
7927: list-style:none;
1.1020 raeburn 7928: margin: -1px -10px 0 -10px;
1.911 bisitz 7929: padding: 0;
1.693 droeschl 7930: }
7931:
1.795 www 7932: ul.LC_TabContent li,
7933: ul.LC_TabContentBigger li {
1.911 bisitz 7934: float:left;
1.741 harmsja 7935: }
1.795 www 7936:
1.897 wenzelju 7937: ul#LC_secondary_menu li a {
1.911 bisitz 7938: color: $fontmenu;
7939: text-decoration: none;
1.693 droeschl 7940: }
1.795 www 7941:
1.721 harmsja 7942: ul.LC_TabContent {
1.952 onken 7943: min-height:20px;
1.721 harmsja 7944: }
1.795 www 7945:
7946: ul.LC_TabContent li {
1.911 bisitz 7947: vertical-align:middle;
1.959 onken 7948: padding: 0 16px 0 10px;
1.911 bisitz 7949: background-color:$tabbg;
7950: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7951: border-left: solid 1px $font;
1.721 harmsja 7952: }
1.795 www 7953:
1.847 tempelho 7954: ul.LC_TabContent .right {
1.911 bisitz 7955: float:right;
1.847 tempelho 7956: }
7957:
1.911 bisitz 7958: ul.LC_TabContent li a,
7959: ul.LC_TabContent li {
7960: color:rgb(47,47,47);
7961: text-decoration:none;
7962: font-size:95%;
7963: font-weight:bold;
1.952 onken 7964: min-height:20px;
7965: }
7966:
1.959 onken 7967: ul.LC_TabContent li a:hover,
7968: ul.LC_TabContent li a:focus {
1.952 onken 7969: color: $button_hover;
1.959 onken 7970: background:none;
7971: outline:none;
1.952 onken 7972: }
7973:
7974: ul.LC_TabContent li:hover {
7975: color: $button_hover;
7976: cursor:pointer;
1.721 harmsja 7977: }
1.795 www 7978:
1.911 bisitz 7979: ul.LC_TabContent li.active {
1.952 onken 7980: color: $font;
1.911 bisitz 7981: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7982: border-bottom:solid 1px #FFFFFF;
7983: cursor: default;
1.744 ehlerst 7984: }
1.795 www 7985:
1.959 onken 7986: ul.LC_TabContent li.active a {
7987: color:$font;
7988: background:#FFFFFF;
7989: outline: none;
7990: }
1.1047 raeburn 7991:
7992: ul.LC_TabContent li.goback {
7993: float: left;
7994: border-left: none;
7995: }
7996:
1.870 tempelho 7997: #maincoursedoc {
1.911 bisitz 7998: clear:both;
1.870 tempelho 7999: }
8000:
8001: ul.LC_TabContentBigger {
1.911 bisitz 8002: display:block;
8003: list-style:none;
8004: padding: 0;
1.870 tempelho 8005: }
8006:
1.795 www 8007: ul.LC_TabContentBigger li {
1.911 bisitz 8008: vertical-align:bottom;
8009: height: 30px;
8010: font-size:110%;
8011: font-weight:bold;
8012: color: #737373;
1.841 tempelho 8013: }
8014:
1.957 onken 8015: ul.LC_TabContentBigger li.active {
8016: position: relative;
8017: top: 1px;
8018: }
8019:
1.870 tempelho 8020: ul.LC_TabContentBigger li a {
1.911 bisitz 8021: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
8022: height: 30px;
8023: line-height: 30px;
8024: text-align: center;
8025: display: block;
8026: text-decoration: none;
1.958 onken 8027: outline: none;
1.741 harmsja 8028: }
1.795 www 8029:
1.870 tempelho 8030: ul.LC_TabContentBigger li.active a {
1.911 bisitz 8031: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
8032: color:$font;
1.744 ehlerst 8033: }
1.795 www 8034:
1.870 tempelho 8035: ul.LC_TabContentBigger li b {
1.911 bisitz 8036: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
8037: display: block;
8038: float: left;
8039: padding: 0 30px;
1.957 onken 8040: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 8041: }
8042:
1.956 onken 8043: ul.LC_TabContentBigger li:hover b {
8044: color:$button_hover;
8045: }
8046:
1.870 tempelho 8047: ul.LC_TabContentBigger li.active b {
1.911 bisitz 8048: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
8049: color:$font;
1.957 onken 8050: border: 0;
1.741 harmsja 8051: }
1.693 droeschl 8052:
1.870 tempelho 8053:
1.862 bisitz 8054: ul.LC_CourseBreadcrumbs {
8055: background: $sidebg;
1.1020 raeburn 8056: height: 2em;
1.862 bisitz 8057: padding-left: 10px;
1.1020 raeburn 8058: margin: 0;
1.862 bisitz 8059: list-style-position: inside;
8060: }
8061:
1.911 bisitz 8062: ol#LC_MenuBreadcrumbs,
1.862 bisitz 8063: ol#LC_PathBreadcrumbs {
1.911 bisitz 8064: padding-left: 10px;
8065: margin: 0;
1.933 droeschl 8066: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 8067: }
8068:
1.911 bisitz 8069: ol#LC_MenuBreadcrumbs li,
8070: ol#LC_PathBreadcrumbs li,
1.862 bisitz 8071: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 8072: display: inline;
1.933 droeschl 8073: white-space: normal;
1.693 droeschl 8074: }
8075:
1.823 bisitz 8076: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 8077: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 8078: text-decoration: none;
8079: font-size:90%;
1.693 droeschl 8080: }
1.795 www 8081:
1.969 droeschl 8082: ol#LC_MenuBreadcrumbs h1 {
8083: display: inline;
8084: font-size: 90%;
8085: line-height: 2.5em;
8086: margin: 0;
8087: padding: 0;
8088: }
8089:
1.795 www 8090: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 8091: text-decoration:none;
8092: font-size:100%;
8093: font-weight:bold;
1.693 droeschl 8094: }
1.795 www 8095:
1.840 bisitz 8096: .LC_Box {
1.911 bisitz 8097: border: solid 1px $lg_border_color;
8098: padding: 0 10px 10px 10px;
1.746 neumanie 8099: }
1.795 www 8100:
1.1020 raeburn 8101: .LC_DocsBox {
8102: border: solid 1px $lg_border_color;
8103: padding: 0 0 10px 10px;
8104: }
8105:
1.795 www 8106: .LC_AboutMe_Image {
1.911 bisitz 8107: float:left;
8108: margin-right:10px;
1.747 neumanie 8109: }
1.795 www 8110:
8111: .LC_Clear_AboutMe_Image {
1.911 bisitz 8112: clear:left;
1.747 neumanie 8113: }
1.795 www 8114:
1.721 harmsja 8115: dl.LC_ListStyleClean dt {
1.911 bisitz 8116: padding-right: 5px;
8117: display: table-header-group;
1.693 droeschl 8118: }
8119:
1.721 harmsja 8120: dl.LC_ListStyleClean dd {
1.911 bisitz 8121: display: table-row;
1.693 droeschl 8122: }
8123:
1.721 harmsja 8124: .LC_ListStyleClean,
8125: .LC_ListStyleSimple,
8126: .LC_ListStyleNormal,
1.795 www 8127: .LC_ListStyleSpecial {
1.911 bisitz 8128: /* display:block; */
8129: list-style-position: inside;
8130: list-style-type: none;
8131: overflow: hidden;
8132: padding: 0;
1.693 droeschl 8133: }
8134:
1.721 harmsja 8135: .LC_ListStyleSimple li,
8136: .LC_ListStyleSimple dd,
8137: .LC_ListStyleNormal li,
8138: .LC_ListStyleNormal dd,
8139: .LC_ListStyleSpecial li,
1.795 www 8140: .LC_ListStyleSpecial dd {
1.911 bisitz 8141: margin: 0;
8142: padding: 5px 5px 5px 10px;
8143: clear: both;
1.693 droeschl 8144: }
8145:
1.721 harmsja 8146: .LC_ListStyleClean li,
8147: .LC_ListStyleClean dd {
1.911 bisitz 8148: padding-top: 0;
8149: padding-bottom: 0;
1.693 droeschl 8150: }
8151:
1.721 harmsja 8152: .LC_ListStyleSimple dd,
1.795 www 8153: .LC_ListStyleSimple li {
1.911 bisitz 8154: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8155: }
8156:
1.721 harmsja 8157: .LC_ListStyleSpecial li,
8158: .LC_ListStyleSpecial dd {
1.911 bisitz 8159: list-style-type: none;
8160: background-color: RGB(220, 220, 220);
8161: margin-bottom: 4px;
1.693 droeschl 8162: }
8163:
1.721 harmsja 8164: table.LC_SimpleTable {
1.911 bisitz 8165: margin:5px;
8166: border:solid 1px $lg_border_color;
1.795 www 8167: }
1.693 droeschl 8168:
1.721 harmsja 8169: table.LC_SimpleTable tr {
1.911 bisitz 8170: padding: 0;
8171: border:solid 1px $lg_border_color;
1.693 droeschl 8172: }
1.795 www 8173:
8174: table.LC_SimpleTable thead {
1.911 bisitz 8175: background:rgb(220,220,220);
1.693 droeschl 8176: }
8177:
1.721 harmsja 8178: div.LC_columnSection {
1.911 bisitz 8179: display: block;
8180: clear: both;
8181: overflow: hidden;
8182: margin: 0;
1.693 droeschl 8183: }
8184:
1.721 harmsja 8185: div.LC_columnSection>* {
1.911 bisitz 8186: float: left;
8187: margin: 10px 20px 10px 0;
8188: overflow:hidden;
1.693 droeschl 8189: }
1.721 harmsja 8190:
1.795 www 8191: table em {
1.911 bisitz 8192: font-weight: bold;
8193: font-style: normal;
1.748 schulted 8194: }
1.795 www 8195:
1.779 bisitz 8196: table.LC_tableBrowseRes,
1.795 www 8197: table.LC_tableOfContent {
1.911 bisitz 8198: border:none;
8199: border-spacing: 1px;
8200: padding: 3px;
8201: background-color: #FFFFFF;
8202: font-size: 90%;
1.753 droeschl 8203: }
1.789 droeschl 8204:
1.911 bisitz 8205: table.LC_tableOfContent {
8206: border-collapse: collapse;
1.789 droeschl 8207: }
8208:
1.771 droeschl 8209: table.LC_tableBrowseRes a,
1.768 schulted 8210: table.LC_tableOfContent a {
1.911 bisitz 8211: background-color: transparent;
8212: text-decoration: none;
1.753 droeschl 8213: }
8214:
1.795 www 8215: table.LC_tableOfContent img {
1.911 bisitz 8216: border: none;
8217: height: 1.3em;
8218: vertical-align: text-bottom;
8219: margin-right: 0.3em;
1.753 droeschl 8220: }
1.757 schulted 8221:
1.795 www 8222: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8223: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8224: }
8225:
1.795 www 8226: a#LC_content_toolbar_everything {
1.911 bisitz 8227: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8228: }
8229:
1.795 www 8230: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8231: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8232: }
8233:
1.795 www 8234: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8235: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8236: }
8237:
1.795 www 8238: a#LC_content_toolbar_changefolder {
1.911 bisitz 8239: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8240: }
8241:
1.795 www 8242: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8243: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8244: }
8245:
1.1043 raeburn 8246: a#LC_content_toolbar_edittoplevel {
8247: background-image:url(/res/adm/pages/edittoplevel.gif);
8248: }
8249:
1.1075.2.161. .12(raeb 8250:-23): a#LC_content_toolbar_printout {
8251:-23): background-image:url(/res/adm/pages/printout.gif);
8252:-23): }
8253:-23):
1.795 www 8254: ul#LC_toolbar li a:hover {
1.911 bisitz 8255: background-position: bottom center;
1.757 schulted 8256: }
8257:
1.795 www 8258: ul#LC_toolbar {
1.911 bisitz 8259: padding: 0;
8260: margin: 2px;
8261: list-style:none;
8262: position:relative;
8263: background-color:white;
1.1075.2.9 raeburn 8264: overflow: auto;
1.757 schulted 8265: }
8266:
1.795 www 8267: ul#LC_toolbar li {
1.911 bisitz 8268: border:1px solid white;
8269: padding: 0;
8270: margin: 0;
8271: float: left;
8272: display:inline;
8273: vertical-align:middle;
1.1075.2.9 raeburn 8274: white-space: nowrap;
1.911 bisitz 8275: }
1.757 schulted 8276:
1.783 amueller 8277:
1.795 www 8278: a.LC_toolbarItem {
1.911 bisitz 8279: display:block;
8280: padding: 0;
8281: margin: 0;
8282: height: 32px;
8283: width: 32px;
8284: color:white;
8285: border: none;
8286: background-repeat:no-repeat;
8287: background-color:transparent;
1.757 schulted 8288: }
8289:
1.915 droeschl 8290: ul.LC_funclist {
8291: margin: 0;
8292: padding: 0.5em 1em 0.5em 0;
8293: }
8294:
1.933 droeschl 8295: ul.LC_funclist > li:first-child {
8296: font-weight:bold;
8297: margin-left:0.8em;
8298: }
8299:
1.915 droeschl 8300: ul.LC_funclist + ul.LC_funclist {
8301: /*
8302: left border as a seperator if we have more than
8303: one list
8304: */
8305: border-left: 1px solid $sidebg;
8306: /*
8307: this hides the left border behind the border of the
8308: outer box if element is wrapped to the next 'line'
8309: */
8310: margin-left: -1px;
8311: }
8312:
1.843 bisitz 8313: ul.LC_funclist li {
1.915 droeschl 8314: display: inline;
1.782 bisitz 8315: white-space: nowrap;
1.915 droeschl 8316: margin: 0 0 0 25px;
8317: line-height: 150%;
1.782 bisitz 8318: }
8319:
1.974 wenzelju 8320: .LC_hidden {
8321: display: none;
8322: }
8323:
1.1030 www 8324: .LCmodal-overlay {
8325: position:fixed;
8326: top:0;
8327: right:0;
8328: bottom:0;
8329: left:0;
8330: height:100%;
8331: width:100%;
8332: margin:0;
8333: padding:0;
8334: background:#999;
8335: opacity:.75;
8336: filter: alpha(opacity=75);
8337: -moz-opacity: 0.75;
8338: z-index:101;
8339: }
8340:
8341: * html .LCmodal-overlay {
8342: position: absolute;
8343: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8344: }
8345:
8346: .LCmodal-window {
8347: position:fixed;
8348: top:50%;
8349: left:50%;
8350: margin:0;
8351: padding:0;
8352: z-index:102;
8353: }
8354:
8355: * html .LCmodal-window {
8356: position:absolute;
8357: }
8358:
8359: .LCclose-window {
8360: position:absolute;
8361: width:32px;
8362: height:32px;
8363: right:8px;
8364: top:8px;
8365: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8366: text-indent:-99999px;
8367: overflow:hidden;
8368: cursor:pointer;
8369: }
8370:
1.1075.2.158 raeburn 8371: .LCisDisabled {
8372: cursor: not-allowed;
8373: opacity: 0.5;
8374: }
8375:
8376: a[aria-disabled="true"] {
8377: color: currentColor;
8378: display: inline-block; /* For IE11/ MS Edge bug */
8379: pointer-events: none;
8380: text-decoration: none;
8381: }
8382:
1.1075.2.141 raeburn 8383: pre.LC_wordwrap {
8384: white-space: pre-wrap;
8385: white-space: -moz-pre-wrap;
8386: white-space: -pre-wrap;
8387: white-space: -o-pre-wrap;
8388: word-wrap: break-word;
8389: }
8390:
1.1075.2.17 raeburn 8391: /*
8392: styles used by TTH when "Default set of options to pass to tth/m
8393: when converting TeX" in course settings has been set
8394:
8395: option passed: -t
8396:
8397: */
8398:
8399: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8400: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8401: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8402: td div.norm {line-height:normal;}
8403:
8404: /*
8405: option passed -y3
8406: */
8407:
8408: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8409: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8410: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8411:
1.1075.2.121 raeburn 8412: #LC_minitab_header {
8413: float:left;
8414: width:100%;
8415: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8416: font-size:93%;
8417: line-height:normal;
8418: margin: 0.5em 0 0.5em 0;
8419: }
8420: #LC_minitab_header ul {
8421: margin:0;
8422: padding:10px 10px 0;
8423: list-style:none;
8424: }
8425: #LC_minitab_header li {
8426: float:left;
8427: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8428: margin:0;
8429: padding:0 0 0 9px;
8430: }
8431: #LC_minitab_header a {
8432: display:block;
8433: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8434: padding:5px 15px 4px 6px;
8435: }
8436: #LC_minitab_header #LC_current_minitab {
8437: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8438: }
8439: #LC_minitab_header #LC_current_minitab a {
8440: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8441: padding-bottom:5px;
8442: }
8443:
8444:
1.343 albertel 8445: END
8446: }
8447:
1.306 albertel 8448: =pod
8449:
8450: =item * &headtag()
8451:
8452: Returns a uniform footer for LON-CAPA web pages.
8453:
1.307 albertel 8454: Inputs: $title - optional title for the head
8455: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8456: $args - optional arguments
1.319 albertel 8457: force_register - if is true call registerurl so the remote is
8458: informed
1.415 albertel 8459: redirect -> array ref of
8460: 1- seconds before redirect occurs
8461: 2- url to redirect to
8462: 3- whether the side effect should occur
1.315 albertel 8463: (side effect of setting
8464: $env{'internal.head.redirect'} to the url
1.1075.2.161. .9(raebu 8465:22): redirected to)
8466:22): 4- whether the redirect target should be
8467:22): the opener of the current (pop-up)
8468:22): window (side effect of setting
8469:22): $env{'internal.head.to_opener'} to
8470:22): 1, if true.
.10(raeb 8471:-22): 5- whether encrypt check should be skipped
1.352 albertel 8472: domain -> force to color decorate a page for a specific
8473: domain
8474: function -> force usage of a specific rolish color scheme
8475: bgcolor -> override the default page bgcolor
1.460 albertel 8476: no_auto_mt_title
8477: -> prevent &mt()ing the title arg
1.464 albertel 8478:
1.306 albertel 8479: =cut
8480:
8481: sub headtag {
1.313 albertel 8482: my ($title,$head_extra,$args) = @_;
1.306 albertel 8483:
1.363 albertel 8484: my $function = $args->{'function'} || &get_users_function();
8485: my $domain = $args->{'domain'} || &determinedomain();
8486: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 8487: my $httphost = $args->{'use_absolute'};
1.418 albertel 8488: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8489: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8490: #time(),
1.418 albertel 8491: $env{'environment.color.timestamp'},
1.363 albertel 8492: $function,$domain,$bgcolor);
8493:
1.369 www 8494: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8495:
1.308 albertel 8496: my $result =
8497: '<head>'.
1.1075.2.56 raeburn 8498: &font_settings($args);
1.319 albertel 8499:
1.1075.2.72 raeburn 8500: my $inhibitprint;
8501: if ($args->{'print_suppress'}) {
8502: $inhibitprint = &print_suppression();
8503: }
1.1064 raeburn 8504:
1.461 albertel 8505: if (!$args->{'frameset'}) {
8506: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8507: }
1.1075.2.12 raeburn 8508: if ($args->{'force_register'}) {
8509: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 8510: }
1.436 albertel 8511: if (!$args->{'no_nav_bar'}
8512: && !$args->{'only_body'}
8513: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 8514: $result .= &help_menu_js($httphost);
1.1032 www 8515: $result.=&modal_window();
1.1038 www 8516: $result.=&togglebox_script();
1.1034 www 8517: $result.=&wishlist_window();
1.1041 www 8518: $result.=&LCprogressbarUpdate_script();
1.1034 www 8519: } else {
8520: if ($args->{'add_modal'}) {
8521: $result.=&modal_window();
8522: }
8523: if ($args->{'add_wishlist'}) {
8524: $result.=&wishlist_window();
8525: }
1.1038 www 8526: if ($args->{'add_togglebox'}) {
8527: $result.=&togglebox_script();
8528: }
1.1041 www 8529: if ($args->{'add_progressbar'}) {
8530: $result.=&LCprogressbarUpdate_script();
8531: }
1.436 albertel 8532: }
1.314 albertel 8533: if (ref($args->{'redirect'})) {
1.1075.2.161. .10(raeb 8534:-22): my ($time,$url,$inhibit_continue,$to_opener,$skip_enc_check) = @{$args->{'redirect'}};
8535:-22): if (!$skip_enc_check) {
8536:-22): $url = &Apache::lonenc::check_encrypt($url);
8537:-22): }
1.414 albertel 8538: if (!$inhibit_continue) {
8539: $env{'internal.head.redirect'} = $url;
8540: }
1.1075.2.161. .9(raebu 8541:22): $result.=<<"ADDMETA";
1.313 albertel 8542: <meta http-equiv="pragma" content="no-cache" />
1.1075.2.161. .9(raebu 8543:22): ADDMETA
8544:22): if ($to_opener) {
8545:22): $env{'internal.head.to_opener'} = 1;
8546:22): my $dest = &js_escape($url);
8547:22): my $timeout = int($time * 1000);
8548:22): $result .=<<"ENDJS";
8549:22): <script type="text/javascript">
8550:22): // <![CDATA[
8551:22): function LC_To_Opener() {
8552:22): var dest = '$dest';
8553:22): if (dest != '') {
8554:22): if (window.opener != null && !window.opener.closed) {
8555:22): window.opener.location.href=dest;
8556:22): window.close();
8557:22): } else {
8558:22): window.location.href=dest;
8559:22): }
8560:22): }
8561:22): }
8562:22): \$(document).ready(function () {
8563:22): setTimeout('LC_To_Opener()',$timeout);
8564:22): });
8565:22): // ]]>
8566:22): </script>
8567:22): ENDJS
8568:22): } else {
8569:22): $result.=<<"ADDMETA";
1.344 albertel 8570: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8571: ADDMETA
1.1075.2.161. .9(raebu 8572:22): }
1.1075.2.89 raeburn 8573: } else {
8574: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8575: my $requrl = $env{'request.uri'};
8576: if ($requrl eq '') {
8577: $requrl = $ENV{'REQUEST_URI'};
8578: $requrl =~ s/\?.+$//;
8579: }
8580: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8581: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8582: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8583: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8584: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8585: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1075.2.145 raeburn 8586: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1075.2.151 raeburn 8587: my ($offload,$offloadoth);
1.1075.2.89 raeburn 8588: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8589: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1075.2.145 raeburn 8590: $offload = 1;
1.1075.2.151 raeburn 8591: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8592: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8593: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8594: $offloadoth = 1;
8595: $dom_in_use = $env{'user.domain'};
8596: }
8597: }
1.1075.2.145 raeburn 8598: }
8599: }
8600: unless ($offload) {
8601: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8602: if ($domdefs{'offloadoth'}{$lonhost}) {
8603: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8604: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8605: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8606: $offload = 1;
1.1075.2.151 raeburn 8607: $offloadoth = 1;
1.1075.2.145 raeburn 8608: $dom_in_use = $env{'user.domain'};
8609: }
1.1075.2.89 raeburn 8610: }
1.1075.2.145 raeburn 8611: }
8612: }
8613: }
8614: if ($offload) {
1.1075.2.158 raeburn 8615: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1075.2.151 raeburn 8616: if (($newserver eq '') && ($offloadoth)) {
8617: my @domains = &Apache::lonnet::current_machine_domains();
1.1075.2.161. .1(raebu 8618:21): if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
1.1075.2.151 raeburn 8619: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
8620: }
8621: }
1.1075.2.145 raeburn 8622: if (($newserver) && ($newserver ne $lonhost)) {
8623: my $numsec = 5;
8624: my $timeout = $numsec * 1000;
8625: my ($newurl,$locknum,%locks,$msg);
8626: if ($env{'request.role.adv'}) {
8627: ($locknum,%locks) = &Apache::lonnet::get_locks();
8628: }
8629: my $disable_submit = 0;
8630: if ($requrl =~ /$LONCAPA::assess_re/) {
8631: $disable_submit = 1;
8632: }
8633: if ($locknum) {
8634: my @lockinfo = sort(values(%locks));
1.1075.2.153 raeburn 8635: $msg = &mt('Once the following tasks are complete:')." \n".
1.1075.2.145 raeburn 8636: join(", ",sort(values(%locks)))."\n";
8637: if (&show_course()) {
8638: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
1.1075.2.89 raeburn 8639: } else {
1.1075.2.145 raeburn 8640: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
8641: }
8642: } else {
8643: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8644: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8645: }
8646: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8647: $newurl = '/adm/switchserver?otherserver='.$newserver;
8648: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8649: $newurl .= '&role='.$env{'request.role'};
8650: }
8651: if ($env{'request.symb'}) {
8652: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8653: if ($shownsymb =~ m{^/enc/}) {
8654: my $reqdmajor = 2;
8655: my $reqdminor = 11;
8656: my $reqdsubminor = 3;
8657: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8658: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8659: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8660: if (($major eq '' && $minor eq '') ||
8661: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8662: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8663: ($reqdsubminor > $subminor))))) {
8664: undef($shownsymb);
8665: }
1.1075.2.89 raeburn 8666: }
1.1075.2.145 raeburn 8667: if ($shownsymb) {
8668: &js_escape(\$shownsymb);
8669: $newurl .= '&symb='.$shownsymb;
1.1075.2.89 raeburn 8670: }
1.1075.2.145 raeburn 8671: } else {
8672: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8673: &js_escape(\$shownurl);
8674: $newurl .= '&origurl='.$shownurl;
1.1075.2.89 raeburn 8675: }
1.1075.2.145 raeburn 8676: }
8677: &js_escape(\$msg);
8678: $result.=<<OFFLOAD
1.1075.2.89 raeburn 8679: <meta http-equiv="pragma" content="no-cache" />
8680: <script type="text/javascript">
1.1075.2.92 raeburn 8681: // <![CDATA[
1.1075.2.89 raeburn 8682: function LC_Offload_Now() {
8683: var dest = "$newurl";
8684: if (dest != '') {
8685: window.location.href="$newurl";
8686: }
8687: }
1.1075.2.92 raeburn 8688: \$(document).ready(function () {
8689: window.alert('$msg');
8690: if ($disable_submit) {
1.1075.2.89 raeburn 8691: \$(".LC_hwk_submit").prop("disabled", true);
8692: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 8693: }
8694: setTimeout('LC_Offload_Now()', $timeout);
8695: });
8696: // ]]>
1.1075.2.89 raeburn 8697: </script>
8698: OFFLOAD
8699: }
8700: }
8701: }
8702: }
8703: }
1.313 albertel 8704: }
1.306 albertel 8705: if (!defined($title)) {
8706: $title = 'The LearningOnline Network with CAPA';
8707: }
1.460 albertel 8708: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8709: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 8710: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8711: if (!$args->{'frameset'}) {
8712: $result .= ' /';
8713: }
8714: $result .= '>'
1.1064 raeburn 8715: .$inhibitprint
1.414 albertel 8716: .$head_extra;
1.1075.2.108 raeburn 8717: my $clientmobile;
8718: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8719: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8720: } else {
8721: $clientmobile = $env{'browser.mobile'};
8722: }
8723: if ($clientmobile) {
1.1075.2.42 raeburn 8724: $result .= '
8725: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8726: <meta name="apple-mobile-web-app-capable" content="yes" />';
8727: }
1.1075.2.126 raeburn 8728: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8729: return $result.'</head>';
1.306 albertel 8730: }
8731:
8732: =pod
8733:
1.340 albertel 8734: =item * &font_settings()
8735:
8736: Returns neccessary <meta> to set the proper encoding
8737:
1.1075.2.56 raeburn 8738: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8739:
8740: =cut
8741:
8742: sub font_settings {
1.1075.2.56 raeburn 8743: my ($args) = @_;
1.340 albertel 8744: my $headerstring='';
1.1075.2.56 raeburn 8745: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8746: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 8747: $headerstring.=
1.1075.2.61 raeburn 8748: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8749: if (!$args->{'frameset'}) {
8750: $headerstring.= ' /';
8751: }
8752: $headerstring .= '>'."\n";
1.340 albertel 8753: }
8754: return $headerstring;
8755: }
8756:
1.341 albertel 8757: =pod
8758:
1.1064 raeburn 8759: =item * &print_suppression()
8760:
8761: In course context returns css which causes the body to be blank when media="print",
8762: if printout generation is unavailable for the current resource.
8763:
8764: This could be because:
8765:
8766: (a) printstartdate is in the future
8767:
8768: (b) printenddate is in the past
8769:
8770: (c) there is an active exam block with "printout"
8771: functionality blocked
8772:
8773: Users with pav, pfo or evb privileges are exempt.
8774:
8775: Inputs: none
8776:
8777: =cut
8778:
8779:
8780: sub print_suppression {
8781: my $noprint;
8782: if ($env{'request.course.id'}) {
8783: my $scope = $env{'request.course.id'};
8784: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8785: (&Apache::lonnet::allowed('pfo',$scope))) {
8786: return;
8787: }
8788: if ($env{'request.course.sec'} ne '') {
8789: $scope .= "/$env{'request.course.sec'}";
8790: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8791: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8792: return;
1.1064 raeburn 8793: }
8794: }
8795: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8796: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.158 raeburn 8797: my $clientip = &Apache::lonnet::get_requestor_ip();
8798: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 8799: if ($blocked) {
8800: my $checkrole = "cm./$cdom/$cnum";
8801: if ($env{'request.course.sec'} ne '') {
8802: $checkrole .= "/$env{'request.course.sec'}";
8803: }
8804: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8805: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8806: $noprint = 1;
8807: }
8808: }
8809: unless ($noprint) {
8810: my $symb = &Apache::lonnet::symbread();
8811: if ($symb ne '') {
8812: my $navmap = Apache::lonnavmaps::navmap->new();
8813: if (ref($navmap)) {
8814: my $res = $navmap->getBySymb($symb);
8815: if (ref($res)) {
8816: if (!$res->resprintable()) {
8817: $noprint = 1;
8818: }
8819: }
8820: }
8821: }
8822: }
8823: if ($noprint) {
8824: return <<"ENDSTYLE";
8825: <style type="text/css" media="print">
8826: body { display:none }
8827: </style>
8828: ENDSTYLE
8829: }
8830: }
8831: return;
8832: }
8833:
8834: =pod
8835:
1.341 albertel 8836: =item * &xml_begin()
8837:
8838: Returns the needed doctype and <html>
8839:
8840: Inputs: none
8841:
8842: =cut
8843:
8844: sub xml_begin {
1.1075.2.61 raeburn 8845: my ($is_frameset) = @_;
1.341 albertel 8846: my $output='';
8847:
8848: if ($env{'browser.mathml'}) {
8849: $output='<?xml version="1.0"?>'
8850: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8851: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8852:
8853: # .'<!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">] >'
8854: .'<!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">'
8855: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8856: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8857: } elsif ($is_frameset) {
8858: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8859: '<html>'."\n";
1.341 albertel 8860: } else {
1.1075.2.61 raeburn 8861: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8862: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8863: }
8864: return $output;
8865: }
1.340 albertel 8866:
8867: =pod
8868:
1.306 albertel 8869: =item * &start_page()
8870:
8871: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8872:
1.648 raeburn 8873: Inputs:
8874:
8875: =over 4
8876:
8877: $title - optional title for the page
8878:
8879: $head_extra - optional extra HTML to incude inside the <head>
8880:
8881: $args - additional optional args supported are:
8882:
8883: =over 8
8884:
8885: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8886: arg on
1.814 bisitz 8887: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8888: add_entries -> additional attributes to add to the <body>
8889: domain -> force to color decorate a page for a
1.317 albertel 8890: specific domain
1.648 raeburn 8891: function -> force usage of a specific rolish color
1.317 albertel 8892: scheme
1.648 raeburn 8893: redirect -> see &headtag()
8894: bgcolor -> override the default page bg color
8895: js_ready -> return a string ready for being used in
1.317 albertel 8896: a javascript writeln
1.648 raeburn 8897: html_encode -> return a string ready for being used in
1.320 albertel 8898: a html attribute
1.648 raeburn 8899: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8900: $forcereg arg
1.648 raeburn 8901: frameset -> if true will start with a <frameset>
1.330 albertel 8902: rather than <body>
1.648 raeburn 8903: skip_phases -> hash ref of
1.338 albertel 8904: head -> skip the <html><head> generation
8905: body -> skip all <body> generation
1.1075.2.12 raeburn 8906: no_inline_link -> if true and in remote mode, don't show the
8907: 'Switch To Inline Menu' link
1.648 raeburn 8908: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8909: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8910: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 8911: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8912: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8913: group -> includes the current group, if page is for a
8914: specific group
1.1075.2.133 raeburn 8915: use_absolute -> for request for external resource or syllabus, this
8916: will contain https://<hostname> if server uses
8917: https (as per hosts.tab), but request is for http
8918: hostname -> hostname, originally from $r->hostname(), (optional).
1.1075.2.158 raeburn 8919: links_disabled -> Links in primary and secondary menus are disabled
8920: (Can enable them once page has loaded - see lonroles.pm
8921: for an example).
1.1075.2.161. .6(raebu 8922:22): links_target -> Target for links, e.g., _parent (optional).
1.361 albertel 8923:
1.648 raeburn 8924: =back
1.460 albertel 8925:
1.648 raeburn 8926: =back
1.562 albertel 8927:
1.306 albertel 8928: =cut
8929:
8930: sub start_page {
1.309 albertel 8931: my ($title,$head_extra,$args) = @_;
1.318 albertel 8932: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8933:
1.315 albertel 8934: $env{'internal.start_page'}++;
1.1075.2.161. .1(raebu 8935:21): my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu,$menucoll,%menu);
1.964 droeschl 8936:
1.338 albertel 8937: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8938: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8939: }
1.1075.2.161. .1(raebu 8940:21):
8941:21): if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
8942:21): if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
8943:21): unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
8944:21): $args->{'no_primary_menu'} = 1;
8945:21): }
8946:21): unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
8947:21): $args->{'no_inline_menu'} = 1;
8948:21): }
8949:21): if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
8950:21): map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
8951:21): }
8952:21): } else {
8953:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8954:21): my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
8955:21): if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
8956:21): unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
8957:21): $args->{'no_primary_menu'} = 1;
8958:21): }
8959:21): unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
8960:21): $args->{'no_inline_menu'} = 1;
8961:21): }
8962:21): if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
8963:21): map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
8964:21): }
8965:21): }
8966:21): }
8967:21): ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
8968:21): $env{'course.'.$env{'request.course.id'}.'.domain'},
8969:21): $env{'course.'.$env{'request.course.id'}.'.num'});
8970:21): } elsif ($env{'request.course.id'}) {
8971:21): my $expiretime=600;
8972:21): if ((time-$env{'course.'.$env{'request.course.id'}.'.last_cache'}) > $expiretime) {
8973:21): &Apache::lonnet::coursedescription($env{'request.course.id'},{'freshen_cache' => 1});
8974:21): }
8975:21): my ($deeplinkmenu,$menuref);
8976:21): ($menucoll,$deeplinkmenu,$menuref) = &menucoll_in_effect();
8977:21): if ($menucoll) {
8978:21): if (ref($menuref) eq 'HASH') {
8979:21): %menu = %{$menuref};
8980:21): }
8981:21): if ($menu{'top'} eq 'n') {
8982:21): $args->{'no_primary_menu'} = 1;
8983:21): }
8984:21): if ($menu{'inline'} eq 'n') {
8985:21): unless (&Apache::lonnet::allowed('opa')) {
8986:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8987:21): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8988:21): my $crstype = &course_type();
8989:21): my $now = time;
8990:21): my $ccrole;
8991:21): if ($crstype eq 'Community') {
8992:21): $ccrole = 'co';
8993:21): } else {
8994:21): $ccrole = 'cc';
8995:21): }
8996:21): if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
8997:21): my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
8998:21): if ((($start) && ($start<0)) ||
8999:21): (($end) && ($end<$now)) ||
9000:21): (($start) && ($now<$start))) {
9001:21): $args->{'no_inline_menu'} = 1;
9002:21): }
9003:21): } else {
9004:21): $args->{'no_inline_menu'} = 1;
9005:21): }
9006:21): }
9007:21): }
9008:21): }
9009:21): }
.4(raebu 9010:22):
.8(raebu 9011:22): my $showncrumbs;
1.338 albertel 9012: if (! exists($args->{'skip_phases'}{'body'}) ) {
9013: if ($args->{'frameset'}) {
9014: my $attr_string = &make_attr_string($args->{'force_register'},
9015: $args->{'add_entries'});
9016: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 9017: } else {
9018: $result .=
9019: &bodytag($title,
9020: $args->{'function'}, $args->{'add_entries'},
9021: $args->{'only_body'}, $args->{'domain'},
9022: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 9023: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.161. .1(raebu 9024:21): $args, \@advtools,
.8(raebu 9025:22): $ltiscope,$ltiuri,\%ltimenu,$menucoll,\%menu,\$showncrumbs);
1.831 bisitz 9026: }
1.330 albertel 9027: }
1.338 albertel 9028:
1.315 albertel 9029: if ($args->{'js_ready'}) {
1.713 kaisler 9030: $result = &js_ready($result);
1.315 albertel 9031: }
1.320 albertel 9032: if ($args->{'html_encode'}) {
1.713 kaisler 9033: $result = &html_encode($result);
9034: }
9035:
1.813 bisitz 9036: # Preparation for new and consistent functionlist at top of screen
9037: # if ($args->{'functionlist'}) {
9038: # $result .= &build_functionlist();
9039: #}
9040:
1.964 droeschl 9041: # Don't add anything more if only_body wanted or in const space
9042: return $result if $args->{'only_body'}
9043: || $env{'request.state'} eq 'construct';
1.813 bisitz 9044:
9045: #Breadcrumbs
1.758 kaisler 9046: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
1.1075.2.161. .8(raebu 9047:22): unless ($showncrumbs) {
1.758 kaisler 9048: &Apache::lonhtmlcommon::clear_breadcrumbs();
9049: #if any br links exists, add them to the breadcrumbs
9050: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
9051: foreach my $crumb (@{$args->{'bread_crumbs'}}){
9052: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
9053: }
9054: }
1.1075.2.19 raeburn 9055: # if @advtools array contains items add then to the breadcrumbs
9056: if (@advtools > 0) {
9057: &Apache::lonmenu::advtools_crumbs(@advtools);
9058: }
1.1075.2.123 raeburn 9059: my $menulink;
9060: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
1.1075.2.161. .1(raebu 9061:21): if ((exists($args->{'bread_crumbs_nomenu'})) ||
9062:21): ($ltiscope eq 'map') || ($ltiscope eq 'resource')) {
1.1075.2.123 raeburn 9063: $menulink = 0;
9064: } else {
9065: undef($menulink);
9066: }
1.1075.2.161. .8(raebu 9067:22): my $linkprotout;
9068:22): if ($env{'request.deeplink.login'}) {
9069:22): my $linkprotout = &Apache::lonmenu::linkprot_exit();
9070:22): if ($linkprotout) {
9071:22): &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
9072:22): }
9073:22): }
1.758 kaisler 9074: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
9075: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 9076: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1075.2.161. .1(raebu 9077:21): } else {
1.1075.2.123 raeburn 9078: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 9079: }
1.1075.2.161. .8(raebu 9080:22): }
1.1075.2.24 raeburn 9081: } elsif (($env{'environment.remote'} eq 'on') &&
9082: ($env{'form.inhibitmenu'} ne 'yes') &&
9083: ($env{'request.noversionuri'} =~ m{^/res/}) &&
9084: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 9085: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 9086: }
1.315 albertel 9087: return $result;
1.306 albertel 9088: }
9089:
9090: sub end_page {
1.315 albertel 9091: my ($args) = @_;
9092: $env{'internal.end_page'}++;
1.330 albertel 9093: my $result;
1.335 albertel 9094: if ($args->{'discussion'}) {
9095: my ($target,$parser);
9096: if (ref($args->{'discussion'})) {
9097: ($target,$parser) =($args->{'discussion'}{'target'},
9098: $args->{'discussion'}{'parser'});
9099: }
9100: $result .= &Apache::lonxml::xmlend($target,$parser);
9101: }
1.330 albertel 9102: if ($args->{'frameset'}) {
9103: $result .= '</frameset>';
9104: } else {
1.635 raeburn 9105: $result .= &endbodytag($args);
1.330 albertel 9106: }
1.1075.2.6 raeburn 9107: unless ($args->{'notbody'}) {
9108: $result .= "\n</html>";
9109: }
1.330 albertel 9110:
1.315 albertel 9111: if ($args->{'js_ready'}) {
1.317 albertel 9112: $result = &js_ready($result);
1.315 albertel 9113: }
1.335 albertel 9114:
1.320 albertel 9115: if ($args->{'html_encode'}) {
9116: $result = &html_encode($result);
9117: }
1.335 albertel 9118:
1.315 albertel 9119: return $result;
9120: }
9121:
1.1075.2.161. .1(raebu 9122:21): sub menucoll_in_effect {
9123:21): my ($menucoll,$deeplinkmenu,%menu);
9124:21): if ($env{'request.course.id'}) {
9125:21): $menucoll = $env{'course.'.$env{'request.course.id'}.'.menudefault'};
9126:21): if ($env{'request.deeplink.login'}) {
9127:21): my ($deeplink_symb,$deeplink,$check_login_symb);
9128:21): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9129:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9130:21): if ($env{'request.noversionuri'} =~ m{^/(res|uploaded)/}) {
9131:21): if ($env{'request.noversionuri'} =~ /\.(page|sequence)$/) {
9132:21): my $navmap = Apache::lonnavmaps::navmap->new();
9133:21): if (ref($navmap)) {
9134:21): $deeplink = $navmap->get_mapparam(undef,
9135:21): &Apache::lonnet::declutter($env{'request.noversionuri'}),
9136:21): '0.deeplink');
9137:21): } else {
9138:21): $check_login_symb = 1;
9139:21): }
9140:21): } else {
9141:21): my $symb=&Apache::lonnet::symbread();
9142:21): if ($symb) {
9143:21): $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
9144:21): } else {
9145:21): $check_login_symb = 1;
9146:21): }
9147:21): }
9148:21): } else {
9149:21): $check_login_symb = 1;
9150:21): }
9151:21): if ($check_login_symb) {
9152:21): $deeplink_symb = &deeplink_login_symb($cnum,$cdom);
9153:21): if ($deeplink_symb =~ /\.(page|sequence)$/) {
9154:21): my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
9155:21): my $navmap = Apache::lonnavmaps::navmap->new();
9156:21): if (ref($navmap)) {
9157:21): $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
9158:21): }
9159:21): } else {
9160:21): $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
9161:21): }
9162:21): }
9163:21): if ($deeplink ne '') {
.6(raebu 9164:22): my ($state,$others,$listed,$scope,$protect,$display,$target) = split(/,/,$deeplink);
.1(raebu 9165:21): if ($display =~ /^\d+$/) {
9166:21): $deeplinkmenu = 1;
9167:21): $menucoll = $display;
9168:21): }
9169:21): }
9170:21): }
9171:21): if ($menucoll) {
9172:21): %menu = &page_menu($env{'course.'.$env{'request.course.id'}.'.menucollections'},$menucoll);
9173:21): }
9174:21): }
9175:21): return ($menucoll,$deeplinkmenu,\%menu);
9176:21): }
9177:21):
9178:21): sub deeplink_login_symb {
9179:21): my ($cnum,$cdom) = @_;
9180:21): my $login_symb;
9181:21): if ($env{'request.deeplink.login'}) {
9182:21): $login_symb = &symb_from_tinyurl($env{'request.deeplink.login'},$cnum,$cdom);
9183:21): }
9184:21): return $login_symb;
9185:21): }
9186:21):
9187:21): sub symb_from_tinyurl {
9188:21): my ($url,$cnum,$cdom) = @_;
9189:21): if ($url =~ m{^\Q/tiny/$cdom/\E(\w+)$}) {
9190:21): my $key = $1;
9191:21): my ($tinyurl,$login);
9192:21): my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
9193:21): if (defined($cached)) {
9194:21): $tinyurl = $result;
9195:21): } else {
9196:21): my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
9197:21): my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
9198:21): if ($currtiny{$key} ne '') {
9199:21): $tinyurl = $currtiny{$key};
9200:21): &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
9201:21): }
9202:21): }
9203:21): if ($tinyurl ne '') {
9204:21): my ($cnumreq,$symb) = split(/\&/,$tinyurl);
9205:21): if (wantarray) {
9206:21): return ($cnumreq,$symb);
9207:21): } elsif ($cnumreq eq $cnum) {
9208:21): return $symb;
9209:21): }
9210:21): }
9211:21): }
9212:21): if (wantarray) {
9213:21): return ();
9214:21): } else {
9215:21): return;
9216:21): }
9217:21): }
9218:21):
.17(raeb 9219:-23): sub usable_exttools {
9220:-23): my %tooltypes;
9221:-23): if ($env{'request.course.id'}) {
9222:-23): if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'}) {
9223:-23): if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'both') {
9224:-23): %tooltypes = (
9225:-23): crs => 1,
9226:-23): dom => 1,
9227:-23): );
9228:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'crs') {
9229:-23): $tooltypes{'crs'} = 1;
9230:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'dom') {
9231:-23): $tooltypes{'dom'} = 1;
9232:-23): }
9233:-23): } else {
9234:-23): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9235:-23): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9236:-23): my $crstype = lc($env{'course.'.$env{'request.course.id'}.'.type'});
9237:-23): if ($crstype eq '') {
9238:-23): $crstype = 'course';
9239:-23): }
9240:-23): if ($crstype eq 'course') {
9241:-23): if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'}) {
9242:-23): $crstype = 'official';
9243:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.textbook'}) {
9244:-23): $crstype = 'textbook';
9245:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.lti'}) {
9246:-23): $crstype = 'lti';
9247:-23): } else {
9248:-23): $crstype = 'unofficial';
9249:-23): }
9250:-23): }
9251:-23): my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
9252:-23): if ($domdefaults{$crstype.'domexttool'}) {
9253:-23): $tooltypes{'dom'} = 1;
9254:-23): }
9255:-23): if ($domdefaults{$crstype.'exttool'}) {
9256:-23): $tooltypes{'crs'} = 1;
9257:-23): }
9258:-23): }
9259:-23): }
9260:-23): return %tooltypes;
9261:-23): }
9262:-23):
1.1034 www 9263: sub wishlist_window {
9264: return(<<'ENDWISHLIST');
1.1046 raeburn 9265: <script type="text/javascript">
1.1034 www 9266: // <![CDATA[
9267: // <!-- BEGIN LON-CAPA Internal
9268: function set_wishlistlink(title, path) {
9269: if (!title) {
9270: title = document.title;
9271: title = title.replace(/^LON-CAPA /,'');
9272: }
1.1075.2.65 raeburn 9273: title = encodeURIComponent(title);
1.1075.2.83 raeburn 9274: title = title.replace("'","\\\'");
1.1034 www 9275: if (!path) {
9276: path = location.pathname;
9277: }
1.1075.2.65 raeburn 9278: path = encodeURIComponent(path);
1.1075.2.83 raeburn 9279: path = path.replace("'","\\\'");
1.1034 www 9280: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
9281: 'wishlistNewLink','width=560,height=350,scrollbars=0');
9282: }
9283: // END LON-CAPA Internal -->
9284: // ]]>
9285: </script>
9286: ENDWISHLIST
9287: }
9288:
1.1030 www 9289: sub modal_window {
9290: return(<<'ENDMODAL');
1.1046 raeburn 9291: <script type="text/javascript">
1.1030 www 9292: // <![CDATA[
9293: // <!-- BEGIN LON-CAPA Internal
9294: var modalWindow = {
9295: parent:"body",
9296: windowId:null,
9297: content:null,
9298: width:null,
9299: height:null,
9300: close:function()
9301: {
9302: $(".LCmodal-window").remove();
9303: $(".LCmodal-overlay").remove();
9304: },
9305: open:function()
9306: {
9307: var modal = "";
9308: modal += "<div class=\"LCmodal-overlay\"></div>";
9309: 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;\">";
9310: modal += this.content;
9311: modal += "</div>";
9312:
9313: $(this.parent).append(modal);
9314:
9315: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
9316: $(".LCclose-window").click(function(){modalWindow.close();});
9317: $(".LCmodal-overlay").click(function(){modalWindow.close();});
9318: }
9319: };
1.1075.2.42 raeburn 9320: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 9321: {
1.1075.2.119 raeburn 9322: source = source.replace(/'/g,"'");
1.1030 www 9323: modalWindow.windowId = "myModal";
9324: modalWindow.width = width;
9325: modalWindow.height = height;
1.1075.2.80 raeburn 9326: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9327: modalWindow.open();
1.1075.2.87 raeburn 9328: };
1.1030 www 9329: // END LON-CAPA Internal -->
9330: // ]]>
9331: </script>
9332: ENDMODAL
9333: }
9334:
9335: sub modal_link {
1.1075.2.42 raeburn 9336: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9337: unless ($width) { $width=480; }
9338: unless ($height) { $height=400; }
1.1031 www 9339: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 9340: unless ($transparency) { $transparency='true'; }
9341:
1.1074 raeburn 9342: my $target_attr;
9343: if (defined($target)) {
9344: $target_attr = 'target="'.$target.'"';
9345: }
9346: return <<"ENDLINK";
1.1075.2.143 raeburn 9347: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 9348: ENDLINK
1.1030 www 9349: }
9350:
1.1032 www 9351: sub modal_adhoc_script {
1.1075.2.155 raeburn 9352: my ($funcname,$width,$height,$content,$possmathjax)=@_;
9353: my $mathjax;
9354: if ($possmathjax) {
9355: $mathjax = <<'ENDJAX';
9356: if (typeof MathJax == 'object') {
9357: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
9358: }
9359: ENDJAX
9360: }
1.1032 www 9361: return (<<ENDADHOC);
1.1046 raeburn 9362: <script type="text/javascript">
1.1032 www 9363: // <![CDATA[
9364: var $funcname = function()
9365: {
9366: modalWindow.windowId = "myModal";
9367: modalWindow.width = $width;
9368: modalWindow.height = $height;
9369: modalWindow.content = '$content';
9370: modalWindow.open();
1.1075.2.155 raeburn 9371: $mathjax
1.1032 www 9372: };
9373: // ]]>
9374: </script>
9375: ENDADHOC
9376: }
9377:
1.1041 www 9378: sub modal_adhoc_inner {
1.1075.2.155 raeburn 9379: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 9380: my $innerwidth=$width-20;
9381: $content=&js_ready(
1.1042 www 9382: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 9383: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9384: $content.
1.1041 www 9385: &end_scrollbox().
1.1075.2.42 raeburn 9386: &end_page()
1.1041 www 9387: );
1.1075.2.155 raeburn 9388: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 9389: }
9390:
9391: sub modal_adhoc_window {
1.1075.2.155 raeburn 9392: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
9393: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 9394: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9395: }
9396:
9397: sub modal_adhoc_launch {
9398: my ($funcname,$width,$height,$content)=@_;
9399: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9400: <script type="text/javascript">
9401: // <![CDATA[
9402: $funcname();
9403: // ]]>
9404: </script>
9405: ENDLAUNCH
9406: }
9407:
9408: sub modal_adhoc_close {
9409: return (<<ENDCLOSE);
9410: <script type="text/javascript">
9411: // <![CDATA[
9412: modalWindow.close();
9413: // ]]>
9414: </script>
9415: ENDCLOSE
9416: }
9417:
1.1038 www 9418: sub togglebox_script {
9419: return(<<ENDTOGGLE);
9420: <script type="text/javascript">
9421: // <![CDATA[
9422: function LCtoggleDisplay(id,hidetext,showtext) {
9423: link = document.getElementById(id + "link").childNodes[0];
9424: with (document.getElementById(id).style) {
9425: if (display == "none" ) {
9426: display = "inline";
9427: link.nodeValue = hidetext;
9428: } else {
9429: display = "none";
9430: link.nodeValue = showtext;
9431: }
9432: }
9433: }
9434: // ]]>
9435: </script>
9436: ENDTOGGLE
9437: }
9438:
1.1039 www 9439: sub start_togglebox {
9440: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9441: unless ($heading) { $heading=''; } else { $heading.=' '; }
9442: unless ($showtext) { $showtext=&mt('show'); }
9443: unless ($hidetext) { $hidetext=&mt('hide'); }
9444: unless ($headerbg) { $headerbg='#FFFFFF'; }
9445: return &start_data_table().
9446: &start_data_table_header_row().
9447: '<td bgcolor="'.$headerbg.'">'.$heading.
9448: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9449: $showtext.'\')">'.$showtext.'</a>]</td>'.
9450: &end_data_table_header_row().
9451: '<tr id="'.$id.'" style="display:none""><td>';
9452: }
9453:
9454: sub end_togglebox {
9455: return '</td></tr>'.&end_data_table();
9456: }
9457:
1.1041 www 9458: sub LCprogressbar_script {
1.1075.2.130 raeburn 9459: my ($id,$number_to_do)=@_;
9460: if ($number_to_do) {
9461: return(<<ENDPROGRESS);
1.1041 www 9462: <script type="text/javascript">
9463: // <![CDATA[
1.1045 www 9464: \$('#progressbar$id').progressbar({
1.1041 www 9465: value: 0,
9466: change: function(event, ui) {
9467: var newVal = \$(this).progressbar('option', 'value');
9468: \$('.pblabel', this).text(LCprogressTxt);
9469: }
9470: });
9471: // ]]>
9472: </script>
9473: ENDPROGRESS
1.1075.2.130 raeburn 9474: } else {
9475: return(<<ENDPROGRESS);
9476: <script type="text/javascript">
9477: // <![CDATA[
9478: \$('#progressbar$id').progressbar({
9479: value: false,
9480: create: function(event, ui) {
9481: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9482: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9483: }
9484: });
9485: // ]]>
9486: </script>
9487: ENDPROGRESS
9488: }
1.1041 www 9489: }
9490:
9491: sub LCprogressbarUpdate_script {
9492: return(<<ENDPROGRESSUPDATE);
9493: <style type="text/css">
9494: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 9495: .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 9496: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9497: </style>
9498: <script type="text/javascript">
9499: // <![CDATA[
1.1045 www 9500: var LCprogressTxt='---';
9501:
1.1075.2.130 raeburn 9502: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9503: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 9504: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9505: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9506: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
9507: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9508: } else {
9509: \$('#progressbar'+id).progressbar('value',percent);
9510: }
1.1041 www 9511: }
9512: // ]]>
9513: </script>
9514: ENDPROGRESSUPDATE
9515: }
9516:
1.1042 www 9517: my $LClastpercent;
1.1045 www 9518: my $LCidcnt;
9519: my $LCcurrentid;
1.1042 www 9520:
1.1041 www 9521: sub LCprogressbar {
1.1075.2.130 raeburn 9522: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9523: $LClastpercent=0;
1.1045 www 9524: $LCidcnt++;
9525: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 9526: my ($starting,$content);
9527: if ($number_to_do) {
9528: $starting=&mt('Starting');
9529: $content=(<<ENDPROGBAR);
9530: $preamble
1.1045 www 9531: <div id="progressbar$LCcurrentid">
1.1041 www 9532: <span class="pblabel">$starting</span>
9533: </div>
9534: ENDPROGBAR
1.1075.2.130 raeburn 9535: } else {
9536: $starting=&mt('Loading...');
9537: $LClastpercent='false';
9538: $content=(<<ENDPROGBAR);
9539: $preamble
9540: <div id="progressbar$LCcurrentid">
9541: <div class="progress-label">$starting</div>
9542: </div>
9543: ENDPROGBAR
9544: }
9545: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9546: }
9547:
9548: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 9549: my ($r,$val,$text,$number_to_do)=@_;
9550: if ($number_to_do) {
9551: unless ($val) {
9552: if ($LClastpercent) {
9553: $val=$LClastpercent;
9554: } else {
9555: $val=0;
9556: }
9557: }
9558: if ($val<0) { $val=0; }
9559: if ($val>100) { $val=0; }
9560: $LClastpercent=$val;
9561: unless ($text) { $text=$val.'%'; }
9562: } else {
9563: $val = 'false';
1.1042 www 9564: }
1.1041 www 9565: $text=&js_ready($text);
1.1044 www 9566: &r_print($r,<<ENDUPDATE);
1.1041 www 9567: <script type="text/javascript">
9568: // <![CDATA[
1.1075.2.130 raeburn 9569: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9570: // ]]>
9571: </script>
9572: ENDUPDATE
1.1035 www 9573: }
9574:
1.1042 www 9575: sub LCprogressbarClose {
9576: my ($r)=@_;
9577: $LClastpercent=0;
1.1044 www 9578: &r_print($r,<<ENDCLOSE);
1.1042 www 9579: <script type="text/javascript">
9580: // <![CDATA[
1.1045 www 9581: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9582: // ]]>
9583: </script>
9584: ENDCLOSE
1.1044 www 9585: }
9586:
9587: sub r_print {
9588: my ($r,$to_print)=@_;
9589: if ($r) {
9590: $r->print($to_print);
9591: $r->rflush();
9592: } else {
9593: print($to_print);
9594: }
1.1042 www 9595: }
9596:
1.320 albertel 9597: sub html_encode {
9598: my ($result) = @_;
9599:
1.322 albertel 9600: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9601:
9602: return $result;
9603: }
1.1044 www 9604:
1.317 albertel 9605: sub js_ready {
9606: my ($result) = @_;
9607:
1.323 albertel 9608: $result =~ s/[\n\r]/ /xmsg;
9609: $result =~ s/\\/\\\\/xmsg;
9610: $result =~ s/'/\\'/xmsg;
1.372 albertel 9611: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9612:
9613: return $result;
9614: }
9615:
1.315 albertel 9616: sub validate_page {
9617: if ( exists($env{'internal.start_page'})
1.316 albertel 9618: && $env{'internal.start_page'} > 1) {
9619: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9620: $env{'internal.start_page'}.' '.
1.316 albertel 9621: $ENV{'request.filename'});
1.315 albertel 9622: }
9623: if ( exists($env{'internal.end_page'})
1.316 albertel 9624: && $env{'internal.end_page'} > 1) {
9625: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9626: $env{'internal.end_page'}.' '.
1.316 albertel 9627: $env{'request.filename'});
1.315 albertel 9628: }
9629: if ( exists($env{'internal.start_page'})
9630: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9631: &Apache::lonnet::logthis('start_page called without end_page '.
9632: $env{'request.filename'});
1.315 albertel 9633: }
9634: if ( ! exists($env{'internal.start_page'})
9635: && exists($env{'internal.end_page'})) {
1.316 albertel 9636: &Apache::lonnet::logthis('end_page called without start_page'.
9637: $env{'request.filename'});
1.315 albertel 9638: }
1.306 albertel 9639: }
1.315 albertel 9640:
1.996 www 9641:
9642: sub start_scrollbox {
1.1075.2.56 raeburn 9643: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9644: unless ($outerwidth) { $outerwidth='520px'; }
9645: unless ($width) { $width='500px'; }
9646: unless ($height) { $height='200px'; }
1.1075 raeburn 9647: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9648: if ($id ne '') {
1.1075.2.42 raeburn 9649: $table_id = ' id="table_'.$id.'"';
9650: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9651: }
1.1075 raeburn 9652: if ($bgcolor ne '') {
9653: $tdcol = "background-color: $bgcolor;";
9654: }
1.1075.2.42 raeburn 9655: my $nicescroll_js;
9656: if ($env{'browser.mobile'}) {
9657: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9658: }
1.1075 raeburn 9659: return <<"END";
1.1075.2.42 raeburn 9660: $nicescroll_js
9661:
9662: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 9663: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 9664: END
1.996 www 9665: }
9666:
9667: sub end_scrollbox {
1.1036 www 9668: return '</div></td></tr></table>';
1.996 www 9669: }
9670:
1.1075.2.42 raeburn 9671: sub nicescroll_javascript {
9672: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9673: my %options;
9674: if (ref($cursor) eq 'HASH') {
9675: %options = %{$cursor};
9676: }
9677: unless ($options{'railalign'} =~ /^left|right$/) {
9678: $options{'railalign'} = 'left';
9679: }
9680: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9681: my $function = &get_users_function();
9682: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
9683: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9684: $options{'cursorcolor'} = '#00F';
9685: }
9686: }
9687: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9688: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
9689: $options{'cursoropacity'}='1.0';
9690: }
9691: } else {
9692: $options{'cursoropacity'}='1.0';
9693: }
9694: if ($options{'cursorfixedheight'} eq 'none') {
9695: delete($options{'cursorfixedheight'});
9696: } else {
9697: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9698: }
9699: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9700: delete($options{'railoffset'});
9701: }
9702: my @niceoptions;
9703: while (my($key,$value) = each(%options)) {
9704: if ($value =~ /^\{.+\}$/) {
9705: push(@niceoptions,$key.':'.$value);
9706: } else {
9707: push(@niceoptions,$key.':"'.$value.'"');
9708: }
9709: }
9710: my $nicescroll_js = '
9711: $(document).ready(
9712: function() {
9713: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9714: }
9715: );
9716: ';
9717: if ($framecheck) {
9718: $nicescroll_js .= '
9719: function expand_div(caller) {
9720: if (top === self) {
9721: document.getElementById("'.$id.'").style.width = "auto";
9722: document.getElementById("'.$id.'").style.height = "auto";
9723: } else {
9724: try {
9725: if (parent.frames) {
9726: if (parent.frames.length > 1) {
9727: var framesrc = parent.frames[1].location.href;
9728: var currsrc = framesrc.replace(/\#.*$/,"");
9729: if ((caller == "search") || (currsrc == "'.$location.'")) {
9730: document.getElementById("'.$id.'").style.width = "auto";
9731: document.getElementById("'.$id.'").style.height = "auto";
9732: }
9733: }
9734: }
9735: } catch (e) {
9736: return;
9737: }
9738: }
9739: return;
9740: }
9741: ';
9742: }
9743: if ($needjsready) {
9744: $nicescroll_js = '
9745: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9746: } else {
9747: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9748: }
9749: return $nicescroll_js;
9750: }
9751:
1.318 albertel 9752: sub simple_error_page {
1.1075.2.49 raeburn 9753: my ($r,$title,$msg,$args) = @_;
1.1075.2.161. .4(raebu 9754:22): my %displayargs;
1.1075.2.49 raeburn 9755: if (ref($args) eq 'HASH') {
9756: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1075.2.161. .4(raebu 9757:22): if ($args->{'only_body'}) {
9758:22): $displayargs{'only_body'} = 1;
9759:22): }
9760:22): if ($args->{'no_nav_bar'}) {
9761:22): $displayargs{'no_nav_bar'} = 1;
9762:22): }
1.1075.2.49 raeburn 9763: } else {
9764: $msg = &mt($msg);
9765: }
9766:
1.318 albertel 9767: my $page =
1.1075.2.161. .4(raebu 9768:22): &Apache::loncommon::start_page($title,'',\%displayargs).
1.1075.2.49 raeburn 9769: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9770: &Apache::loncommon::end_page();
9771: if (ref($r)) {
9772: $r->print($page);
1.327 albertel 9773: return;
1.318 albertel 9774: }
9775: return $page;
9776: }
1.347 albertel 9777:
9778: {
1.610 albertel 9779: my @row_count;
1.961 onken 9780:
9781: sub start_data_table_count {
9782: unshift(@row_count, 0);
9783: return;
9784: }
9785:
9786: sub end_data_table_count {
9787: shift(@row_count);
9788: return;
9789: }
9790:
1.347 albertel 9791: sub start_data_table {
1.1018 raeburn 9792: my ($add_class,$id) = @_;
1.422 albertel 9793: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9794: my $table_id;
9795: if (defined($id)) {
9796: $table_id = ' id="'.$id.'"';
9797: }
1.961 onken 9798: &start_data_table_count();
1.1018 raeburn 9799: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9800: }
9801:
9802: sub end_data_table {
1.961 onken 9803: &end_data_table_count();
1.389 albertel 9804: return '</table>'."\n";;
1.347 albertel 9805: }
9806:
9807: sub start_data_table_row {
1.974 wenzelju 9808: my ($add_class, $id) = @_;
1.610 albertel 9809: $row_count[0]++;
9810: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9811: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9812: $id = (' id="'.$id.'"') unless ($id eq '');
9813: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9814: }
1.471 banghart 9815:
9816: sub continue_data_table_row {
1.974 wenzelju 9817: my ($add_class, $id) = @_;
1.610 albertel 9818: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9819: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9820: $id = (' id="'.$id.'"') unless ($id eq '');
9821: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9822: }
1.347 albertel 9823:
9824: sub end_data_table_row {
1.389 albertel 9825: return '</tr>'."\n";;
1.347 albertel 9826: }
1.367 www 9827:
1.421 albertel 9828: sub start_data_table_empty_row {
1.707 bisitz 9829: # $row_count[0]++;
1.421 albertel 9830: return '<tr class="LC_empty_row" >'."\n";;
9831: }
9832:
9833: sub end_data_table_empty_row {
9834: return '</tr>'."\n";;
9835: }
9836:
1.367 www 9837: sub start_data_table_header_row {
1.389 albertel 9838: return '<tr class="LC_header_row">'."\n";;
1.367 www 9839: }
9840:
9841: sub end_data_table_header_row {
1.389 albertel 9842: return '</tr>'."\n";;
1.367 www 9843: }
1.890 droeschl 9844:
9845: sub data_table_caption {
9846: my $caption = shift;
9847: return "<caption class=\"LC_caption\">$caption</caption>";
9848: }
1.347 albertel 9849: }
9850:
1.548 albertel 9851: =pod
9852:
9853: =item * &inhibit_menu_check($arg)
9854:
9855: Checks for a inhibitmenu state and generates output to preserve it
9856:
9857: Inputs: $arg - can be any of
9858: - undef - in which case the return value is a string
9859: to add into arguments list of a uri
9860: - 'input' - in which case the return value is a HTML
9861: <form> <input> field of type hidden to
9862: preserve the value
9863: - a url - in which case the return value is the url with
9864: the neccesary cgi args added to preserve the
9865: inhibitmenu state
9866: - a ref to a url - no return value, but the string is
9867: updated to include the neccessary cgi
9868: args to preserve the inhibitmenu state
9869:
9870: =cut
9871:
9872: sub inhibit_menu_check {
9873: my ($arg) = @_;
9874: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9875: if ($arg eq 'input') {
9876: if ($env{'form.inhibitmenu'}) {
9877: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9878: } else {
9879: return
9880: }
9881: }
9882: if ($env{'form.inhibitmenu'}) {
9883: if (ref($arg)) {
9884: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9885: } elsif ($arg eq '') {
9886: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9887: } else {
9888: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9889: }
9890: }
9891: if (!ref($arg)) {
9892: return $arg;
9893: }
9894: }
9895:
1.251 albertel 9896: ###############################################
1.182 matthew 9897:
9898: =pod
9899:
1.549 albertel 9900: =back
9901:
9902: =head1 User Information Routines
9903:
9904: =over 4
9905:
1.405 albertel 9906: =item * &get_users_function()
1.182 matthew 9907:
9908: Used by &bodytag to determine the current users primary role.
9909: Returns either 'student','coordinator','admin', or 'author'.
9910:
9911: =cut
9912:
9913: ###############################################
9914: sub get_users_function {
1.815 tempelho 9915: my $function = 'norole';
1.818 tempelho 9916: if ($env{'request.role'}=~/^(st)/) {
9917: $function='student';
9918: }
1.907 raeburn 9919: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9920: $function='coordinator';
9921: }
1.258 albertel 9922: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9923: $function='admin';
9924: }
1.826 bisitz 9925: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9926: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9927: $function='author';
9928: }
9929: return $function;
1.54 www 9930: }
1.99 www 9931:
9932: ###############################################
9933:
1.233 raeburn 9934: =pod
9935:
1.821 raeburn 9936: =item * &show_course()
9937:
9938: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9939: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9940:
9941: Inputs:
9942: None
9943:
9944: Outputs:
9945: Scalar: 1 if 'Course' to be used, 0 otherwise.
9946:
9947: =cut
9948:
9949: ###############################################
9950: sub show_course {
9951: my $course = !$env{'user.adv'};
9952: if (!$env{'user.adv'}) {
9953: foreach my $env (keys(%env)) {
9954: next if ($env !~ m/^user\.priv\./);
9955: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9956: $course = 0;
9957: last;
9958: }
9959: }
9960: }
9961: return $course;
9962: }
9963:
9964: ###############################################
9965:
9966: =pod
9967:
1.542 raeburn 9968: =item * &check_user_status()
1.274 raeburn 9969:
9970: Determines current status of supplied role for a
9971: specific user. Roles can be active, previous or future.
9972:
9973: Inputs:
9974: user's domain, user's username, course's domain,
1.375 raeburn 9975: course's number, optional section ID.
1.274 raeburn 9976:
9977: Outputs:
9978: role status: active, previous or future.
9979:
9980: =cut
9981:
9982: sub check_user_status {
1.412 raeburn 9983: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9984: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 9985: my @uroles = keys(%userinfo);
1.274 raeburn 9986: my $srchstr;
9987: my $active_chk = 'none';
1.412 raeburn 9988: my $now = time;
1.274 raeburn 9989: if (@uroles > 0) {
1.908 raeburn 9990: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9991: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9992: } else {
1.412 raeburn 9993: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9994: }
9995: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9996: my $role_end = 0;
9997: my $role_start = 0;
9998: $active_chk = 'active';
1.412 raeburn 9999: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
10000: $role_end = $1;
10001: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
10002: $role_start = $1;
1.274 raeburn 10003: }
10004: }
10005: if ($role_start > 0) {
1.412 raeburn 10006: if ($now < $role_start) {
1.274 raeburn 10007: $active_chk = 'future';
10008: }
10009: }
10010: if ($role_end > 0) {
1.412 raeburn 10011: if ($now > $role_end) {
1.274 raeburn 10012: $active_chk = 'previous';
10013: }
10014: }
10015: }
10016: }
10017: return $active_chk;
10018: }
10019:
10020: ###############################################
10021:
10022: =pod
10023:
1.405 albertel 10024: =item * &get_sections()
1.233 raeburn 10025:
10026: Determines all the sections for a course including
10027: sections with students and sections containing other roles.
1.419 raeburn 10028: Incoming parameters:
10029:
10030: 1. domain
10031: 2. course number
10032: 3. reference to array containing roles for which sections should
10033: be gathered (optional).
10034: 4. reference to array containing status types for which sections
10035: should be gathered (optional).
10036:
10037: If the third argument is undefined, sections are gathered for any role.
10038: If the fourth argument is undefined, sections are gathered for any status.
10039: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 10040:
1.374 raeburn 10041: Returns section hash (keys are section IDs, values are
10042: number of users in each section), subject to the
1.419 raeburn 10043: optional roles filter, optional status filter
1.233 raeburn 10044:
10045: =cut
10046:
10047: ###############################################
10048: sub get_sections {
1.419 raeburn 10049: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 10050: if (!defined($cdom) || !defined($cnum)) {
10051: my $cid = $env{'request.course.id'};
10052:
10053: return if (!defined($cid));
10054:
10055: $cdom = $env{'course.'.$cid.'.domain'};
10056: $cnum = $env{'course.'.$cid.'.num'};
10057: }
10058:
10059: my %sectioncount;
1.419 raeburn 10060: my $now = time;
1.240 albertel 10061:
1.1075.2.33 raeburn 10062: my $check_students = 1;
10063: my $only_students = 0;
10064: if (ref($possible_roles) eq 'ARRAY') {
10065: if (grep(/^st$/,@{$possible_roles})) {
10066: if (@{$possible_roles} == 1) {
10067: $only_students = 1;
10068: }
10069: } else {
10070: $check_students = 0;
10071: }
10072: }
10073:
10074: if ($check_students) {
1.276 albertel 10075: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 10076: my $sec_index = &Apache::loncoursedata::CL_SECTION();
10077: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 10078: my $start_index = &Apache::loncoursedata::CL_START();
10079: my $end_index = &Apache::loncoursedata::CL_END();
10080: my $status;
1.366 albertel 10081: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 10082: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
10083: $data->[$status_index],
10084: $data->[$start_index],
10085: $data->[$end_index]);
10086: if ($stu_status eq 'Active') {
10087: $status = 'active';
10088: } elsif ($end < $now) {
10089: $status = 'previous';
10090: } elsif ($start > $now) {
10091: $status = 'future';
10092: }
10093: if ($section ne '-1' && $section !~ /^\s*$/) {
10094: if ((!defined($possible_status)) || (($status ne '') &&
10095: (grep/^\Q$status\E$/,@{$possible_status}))) {
10096: $sectioncount{$section}++;
10097: }
1.240 albertel 10098: }
10099: }
10100: }
1.1075.2.33 raeburn 10101: if ($only_students) {
10102: return %sectioncount;
10103: }
1.240 albertel 10104: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10105: foreach my $user (sort(keys(%courseroles))) {
10106: if ($user !~ /^(\w{2})/) { next; }
10107: my ($role) = ($user =~ /^(\w{2})/);
10108: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 10109: my ($section,$status);
1.240 albertel 10110: if ($role eq 'cr' &&
10111: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
10112: $section=$1;
10113: }
10114: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
10115: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 10116: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
10117: if ($end == -1 && $start == -1) {
10118: next; #deleted role
10119: }
10120: if (!defined($possible_status)) {
10121: $sectioncount{$section}++;
10122: } else {
10123: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
10124: $status = 'active';
10125: } elsif ($end < $now) {
10126: $status = 'future';
10127: } elsif ($start > $now) {
10128: $status = 'previous';
10129: }
10130: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
10131: $sectioncount{$section}++;
10132: }
10133: }
1.233 raeburn 10134: }
1.366 albertel 10135: return %sectioncount;
1.233 raeburn 10136: }
10137:
1.274 raeburn 10138: ###############################################
1.294 raeburn 10139:
10140: =pod
1.405 albertel 10141:
10142: =item * &get_course_users()
10143:
1.275 raeburn 10144: Retrieves usernames:domains for users in the specified course
10145: with specific role(s), and access status.
10146:
10147: Incoming parameters:
1.277 albertel 10148: 1. course domain
10149: 2. course number
10150: 3. access status: users must have - either active,
1.275 raeburn 10151: previous, future, or all.
1.277 albertel 10152: 4. reference to array of permissible roles
1.288 raeburn 10153: 5. reference to array of section restrictions (optional)
10154: 6. reference to results object (hash of hashes).
10155: 7. reference to optional userdata hash
1.609 raeburn 10156: 8. reference to optional statushash
1.630 raeburn 10157: 9. flag if privileged users (except those set to unhide in
10158: course settings) should be excluded
1.609 raeburn 10159: Keys of top level results hash are roles.
1.275 raeburn 10160: Keys of inner hashes are username:domain, with
10161: values set to access type.
1.288 raeburn 10162: Optional userdata hash returns an array with arguments in the
10163: same order as loncoursedata::get_classlist() for student data.
10164:
1.609 raeburn 10165: Optional statushash returns
10166:
1.288 raeburn 10167: Entries for end, start, section and status are blank because
10168: of the possibility of multiple values for non-student roles.
10169:
1.275 raeburn 10170: =cut
1.405 albertel 10171:
1.275 raeburn 10172: ###############################################
1.405 albertel 10173:
1.275 raeburn 10174: sub get_course_users {
1.630 raeburn 10175: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 10176: my %idx = ();
1.419 raeburn 10177: my %seclists;
1.288 raeburn 10178:
10179: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
10180: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
10181: $idx{end} = &Apache::loncoursedata::CL_END();
10182: $idx{start} = &Apache::loncoursedata::CL_START();
10183: $idx{id} = &Apache::loncoursedata::CL_ID();
10184: $idx{section} = &Apache::loncoursedata::CL_SECTION();
10185: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
10186: $idx{status} = &Apache::loncoursedata::CL_STATUS();
10187:
1.290 albertel 10188: if (grep(/^st$/,@{$roles})) {
1.276 albertel 10189: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 10190: my $now = time;
1.277 albertel 10191: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 10192: my $match = 0;
1.412 raeburn 10193: my $secmatch = 0;
1.419 raeburn 10194: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 10195: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 10196: if ($section eq '') {
10197: $section = 'none';
10198: }
1.291 albertel 10199: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10200: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10201: $secmatch = 1;
10202: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 10203: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10204: $secmatch = 1;
10205: }
10206: } else {
1.419 raeburn 10207: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 10208: $secmatch = 1;
10209: }
1.290 albertel 10210: }
1.412 raeburn 10211: if (!$secmatch) {
10212: next;
10213: }
1.419 raeburn 10214: }
1.275 raeburn 10215: if (defined($$types{'active'})) {
1.288 raeburn 10216: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 10217: push(@{$$users{st}{$student}},'active');
1.288 raeburn 10218: $match = 1;
1.275 raeburn 10219: }
10220: }
10221: if (defined($$types{'previous'})) {
1.609 raeburn 10222: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 10223: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 10224: $match = 1;
1.275 raeburn 10225: }
10226: }
10227: if (defined($$types{'future'})) {
1.609 raeburn 10228: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 10229: push(@{$$users{st}{$student}},'future');
1.288 raeburn 10230: $match = 1;
1.275 raeburn 10231: }
10232: }
1.609 raeburn 10233: if ($match) {
10234: push(@{$seclists{$student}},$section);
10235: if (ref($userdata) eq 'HASH') {
10236: $$userdata{$student} = $$classlist{$student};
10237: }
10238: if (ref($statushash) eq 'HASH') {
10239: $statushash->{$student}{'st'}{$section} = $status;
10240: }
1.288 raeburn 10241: }
1.275 raeburn 10242: }
10243: }
1.412 raeburn 10244: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 10245: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10246: my $now = time;
1.609 raeburn 10247: my %displaystatus = ( previous => 'Expired',
10248: active => 'Active',
10249: future => 'Future',
10250: );
1.1075.2.36 raeburn 10251: my (%nothide,@possdoms);
1.630 raeburn 10252: if ($hidepriv) {
10253: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
10254: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
10255: if ($user !~ /:/) {
10256: $nothide{join(':',split(/[\@]/,$user))}=1;
10257: } else {
10258: $nothide{$user} = 1;
10259: }
10260: }
1.1075.2.36 raeburn 10261: my @possdoms = ($cdom);
10262: if ($coursehash{'checkforpriv'}) {
10263: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
10264: }
1.630 raeburn 10265: }
1.439 raeburn 10266: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 10267: my $match = 0;
1.412 raeburn 10268: my $secmatch = 0;
1.439 raeburn 10269: my $status;
1.412 raeburn 10270: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 10271: $user =~ s/:$//;
1.439 raeburn 10272: my ($end,$start) = split(/:/,$coursepersonnel{$person});
10273: if ($end == -1 || $start == -1) {
10274: next;
10275: }
10276: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
10277: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 10278: my ($uname,$udom) = split(/:/,$user);
10279: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10280: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10281: $secmatch = 1;
10282: } elsif ($usec eq '') {
1.420 albertel 10283: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10284: $secmatch = 1;
10285: }
10286: } else {
10287: if (grep(/^\Q$usec\E$/,@{$sections})) {
10288: $secmatch = 1;
10289: }
10290: }
10291: if (!$secmatch) {
10292: next;
10293: }
1.288 raeburn 10294: }
1.419 raeburn 10295: if ($usec eq '') {
10296: $usec = 'none';
10297: }
1.275 raeburn 10298: if ($uname ne '' && $udom ne '') {
1.630 raeburn 10299: if ($hidepriv) {
1.1075.2.36 raeburn 10300: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 10301: (!$nothide{$uname.':'.$udom})) {
10302: next;
10303: }
10304: }
1.503 raeburn 10305: if ($end > 0 && $end < $now) {
1.439 raeburn 10306: $status = 'previous';
10307: } elsif ($start > $now) {
10308: $status = 'future';
10309: } else {
10310: $status = 'active';
10311: }
1.277 albertel 10312: foreach my $type (keys(%{$types})) {
1.275 raeburn 10313: if ($status eq $type) {
1.420 albertel 10314: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 10315: push(@{$$users{$role}{$user}},$type);
10316: }
1.288 raeburn 10317: $match = 1;
10318: }
10319: }
1.419 raeburn 10320: if (($match) && (ref($userdata) eq 'HASH')) {
10321: if (!exists($$userdata{$uname.':'.$udom})) {
10322: &get_user_info($udom,$uname,\%idx,$userdata);
10323: }
1.420 albertel 10324: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 10325: push(@{$seclists{$uname.':'.$udom}},$usec);
10326: }
1.609 raeburn 10327: if (ref($statushash) eq 'HASH') {
10328: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
10329: }
1.275 raeburn 10330: }
10331: }
10332: }
10333: }
1.290 albertel 10334: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10335: if ((defined($cdom)) && (defined($cnum))) {
10336: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10337: if ( defined($csettings{'internal.courseowner'}) ) {
10338: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10339: next if ($owner eq '');
10340: my ($ownername,$ownerdom);
10341: if ($owner =~ /^([^:]+):([^:]+)$/) {
10342: $ownername = $1;
10343: $ownerdom = $2;
10344: } else {
10345: $ownername = $owner;
10346: $ownerdom = $cdom;
10347: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10348: }
10349: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10350: if (defined($userdata) &&
1.609 raeburn 10351: !exists($$userdata{$owner})) {
10352: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10353: if (!grep(/^none$/,@{$seclists{$owner}})) {
10354: push(@{$seclists{$owner}},'none');
10355: }
10356: if (ref($statushash) eq 'HASH') {
10357: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10358: }
1.290 albertel 10359: }
1.279 raeburn 10360: }
10361: }
10362: }
1.419 raeburn 10363: foreach my $user (keys(%seclists)) {
10364: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10365: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10366: }
1.275 raeburn 10367: }
10368: return;
10369: }
10370:
1.288 raeburn 10371: sub get_user_info {
10372: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10373: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10374: &plainname($uname,$udom,'lastname');
1.291 albertel 10375: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10376: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10377: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10378: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10379: return;
10380: }
1.275 raeburn 10381:
1.472 raeburn 10382: ###############################################
10383:
10384: =pod
10385:
10386: =item * &get_user_quota()
10387:
1.1075.2.41 raeburn 10388: Retrieves quota assigned for storage of user files.
10389: Default is to report quota for portfolio files.
1.472 raeburn 10390:
10391: Incoming parameters:
10392: 1. user's username
10393: 2. user's domain
1.1075.2.41 raeburn 10394: 3. quota name - portfolio, author, or course
10395: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 10396: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 10397: course
1.472 raeburn 10398:
10399: Returns:
1.1075.2.58 raeburn 10400: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10401: 2. (Optional) Type of setting: custom or default
10402: (individually assigned or default for user's
10403: institutional status).
10404: 3. (Optional) - User's institutional status (e.g., faculty, staff
10405: or student - types as defined in localenroll::inst_usertypes
10406: for user's domain, which determines default quota for user.
10407: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10408:
10409: If a value has been stored in the user's environment,
1.536 raeburn 10410: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 10411: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10412:
10413: =cut
10414:
10415: ###############################################
10416:
10417:
10418: sub get_user_quota {
1.1075.2.42 raeburn 10419: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10420: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10421: if (!defined($udom)) {
10422: $udom = $env{'user.domain'};
10423: }
10424: if (!defined($uname)) {
10425: $uname = $env{'user.name'};
10426: }
10427: if (($udom eq '' || $uname eq '') ||
10428: ($udom eq 'public') && ($uname eq 'public')) {
10429: $quota = 0;
1.536 raeburn 10430: $quotatype = 'default';
10431: $defquota = 0;
1.472 raeburn 10432: } else {
1.536 raeburn 10433: my $inststatus;
1.1075.2.41 raeburn 10434: if ($quotaname eq 'course') {
10435: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10436: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10437: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10438: } else {
10439: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10440: $quota = $cenv{'internal.uploadquota'};
10441: }
1.536 raeburn 10442: } else {
1.1075.2.41 raeburn 10443: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10444: if ($quotaname eq 'author') {
10445: $quota = $env{'environment.authorquota'};
10446: } else {
10447: $quota = $env{'environment.portfolioquota'};
10448: }
10449: $inststatus = $env{'environment.inststatus'};
10450: } else {
10451: my %userenv =
10452: &Apache::lonnet::get('environment',['portfolioquota',
10453: 'authorquota','inststatus'],$udom,$uname);
10454: my ($tmp) = keys(%userenv);
10455: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10456: if ($quotaname eq 'author') {
10457: $quota = $userenv{'authorquota'};
10458: } else {
10459: $quota = $userenv{'portfolioquota'};
10460: }
10461: $inststatus = $userenv{'inststatus'};
10462: } else {
10463: undef(%userenv);
10464: }
10465: }
10466: }
10467: if ($quota eq '' || wantarray) {
10468: if ($quotaname eq 'course') {
10469: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 10470: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
10471: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 10472: $defquota = $domdefs{$crstype.'quota'};
10473: }
10474: if ($defquota eq '') {
10475: $defquota = 500;
10476: }
1.1075.2.41 raeburn 10477: } else {
10478: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10479: }
10480: if ($quota eq '') {
10481: $quota = $defquota;
10482: $quotatype = 'default';
10483: } else {
10484: $quotatype = 'custom';
10485: }
1.472 raeburn 10486: }
10487: }
1.536 raeburn 10488: if (wantarray) {
10489: return ($quota,$quotatype,$settingstatus,$defquota);
10490: } else {
10491: return $quota;
10492: }
1.472 raeburn 10493: }
10494:
10495: ###############################################
10496:
10497: =pod
10498:
10499: =item * &default_quota()
10500:
1.536 raeburn 10501: Retrieves default quota assigned for storage of user portfolio files,
10502: given an (optional) user's institutional status.
1.472 raeburn 10503:
10504: Incoming parameters:
1.1075.2.42 raeburn 10505:
1.472 raeburn 10506: 1. domain
1.536 raeburn 10507: 2. (Optional) institutional status(es). This is a : separated list of
10508: status types (e.g., faculty, staff, student etc.)
10509: which apply to the user for whom the default is being retrieved.
10510: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 10511: default quota will be returned.
10512: 3. quota name - portfolio, author, or course
10513: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10514:
10515: Returns:
1.1075.2.42 raeburn 10516:
1.1075.2.58 raeburn 10517: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10518: 2. (Optional) institutional type which determined the value of the
10519: default quota.
1.472 raeburn 10520:
10521: If a value has been stored in the domain's configuration db,
10522: it will return that, otherwise it returns 20 (for backwards
10523: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 10524: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10525:
1.536 raeburn 10526: If the user's status includes multiple types (e.g., staff and student),
10527: the largest default quota which applies to the user determines the
10528: default quota returned.
10529:
1.472 raeburn 10530: =cut
10531:
10532: ###############################################
10533:
10534:
10535: sub default_quota {
1.1075.2.41 raeburn 10536: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10537: my ($defquota,$settingstatus);
10538: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10539: ['quotas'],$udom);
1.1075.2.41 raeburn 10540: my $key = 'defaultquota';
10541: if ($quotaname eq 'author') {
10542: $key = 'authorquota';
10543: }
1.622 raeburn 10544: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10545: if ($inststatus ne '') {
1.765 raeburn 10546: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10547: foreach my $item (@statuses) {
1.1075.2.41 raeburn 10548: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10549: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10550: if ($defquota eq '') {
1.1075.2.41 raeburn 10551: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10552: $settingstatus = $item;
1.1075.2.41 raeburn 10553: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10554: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10555: $settingstatus = $item;
10556: }
10557: }
1.1075.2.41 raeburn 10558: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10559: if ($quotahash{'quotas'}{$item} ne '') {
10560: if ($defquota eq '') {
10561: $defquota = $quotahash{'quotas'}{$item};
10562: $settingstatus = $item;
10563: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10564: $defquota = $quotahash{'quotas'}{$item};
10565: $settingstatus = $item;
10566: }
1.536 raeburn 10567: }
10568: }
10569: }
10570: }
10571: if ($defquota eq '') {
1.1075.2.41 raeburn 10572: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10573: $defquota = $quotahash{'quotas'}{$key}{'default'};
10574: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10575: $defquota = $quotahash{'quotas'}{'default'};
10576: }
1.536 raeburn 10577: $settingstatus = 'default';
1.1075.2.42 raeburn 10578: if ($defquota eq '') {
10579: if ($quotaname eq 'author') {
10580: $defquota = 500;
10581: }
10582: }
1.536 raeburn 10583: }
10584: } else {
10585: $settingstatus = 'default';
1.1075.2.41 raeburn 10586: if ($quotaname eq 'author') {
10587: $defquota = 500;
10588: } else {
10589: $defquota = 20;
10590: }
1.536 raeburn 10591: }
10592: if (wantarray) {
10593: return ($defquota,$settingstatus);
1.472 raeburn 10594: } else {
1.536 raeburn 10595: return $defquota;
1.472 raeburn 10596: }
10597: }
10598:
1.1075.2.41 raeburn 10599: ###############################################
10600:
10601: =pod
10602:
1.1075.2.42 raeburn 10603: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 10604:
10605: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 10606: of existing file within authoring space will cause quota for the authoring
10607: space to be exceeded.
10608:
10609: Same, if upload of a file directly to a course/community via Course Editor
10610: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 10611:
1.1075.2.61 raeburn 10612: Inputs: 7
1.1075.2.42 raeburn 10613: 1. username or coursenum
1.1075.2.41 raeburn 10614: 2. domain
1.1075.2.42 raeburn 10615: 3. context ('author' or 'course')
1.1075.2.41 raeburn 10616: 4. filename of file for which action is being requested
10617: 5. filesize (kB) of file
10618: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 10619: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 10620:
10621: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
10622: otherwise return null.
10623:
1.1075.2.42 raeburn 10624: =back
10625:
1.1075.2.41 raeburn 10626: =cut
10627:
1.1075.2.42 raeburn 10628: sub excess_filesize_warning {
1.1075.2.59 raeburn 10629: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 10630: my $current_disk_usage = 0;
1.1075.2.59 raeburn 10631: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 10632: if ($context eq 'author') {
10633: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10634: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10635: } else {
10636: foreach my $subdir ('docs','supplemental') {
10637: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10638: }
10639: }
1.1075.2.41 raeburn 10640: $disk_quota = int($disk_quota * 1000);
10641: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 10642: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 10643: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 10644: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10645: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 10646: $disk_quota,$current_disk_usage).
10647: '</p>';
10648: }
10649: return;
10650: }
10651:
10652: ###############################################
10653:
10654:
1.384 raeburn 10655: sub get_secgrprole_info {
10656: my ($cdom,$cnum,$needroles,$type) = @_;
10657: my %sections_count = &get_sections($cdom,$cnum);
10658: my @sections = (sort {$a <=> $b} keys(%sections_count));
10659: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10660: my @groups = sort(keys(%curr_groups));
10661: my $allroles = [];
10662: my $rolehash;
10663: my $accesshash = {
10664: active => 'Currently has access',
10665: future => 'Will have future access',
10666: previous => 'Previously had access',
10667: };
10668: if ($needroles) {
10669: $rolehash = {'all' => 'all'};
1.385 albertel 10670: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10671: if (&Apache::lonnet::error(%user_roles)) {
10672: undef(%user_roles);
10673: }
10674: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10675: my ($role)=split(/\:/,$item,2);
10676: if ($role eq 'cr') { next; }
10677: if ($role =~ /^cr/) {
10678: $$rolehash{$role} = (split('/',$role))[3];
10679: } else {
10680: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10681: }
10682: }
10683: foreach my $key (sort(keys(%{$rolehash}))) {
10684: push(@{$allroles},$key);
10685: }
10686: push (@{$allroles},'st');
10687: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10688: }
10689: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10690: }
10691:
1.555 raeburn 10692: sub user_picker {
1.1075.2.127 raeburn 10693: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10694: my $currdom = $dom;
1.1075.2.114 raeburn 10695: my @alldoms = &Apache::lonnet::all_domains();
10696: if (@alldoms == 1) {
10697: my %domsrch = &Apache::lonnet::get_dom('configuration',
10698: ['directorysrch'],$alldoms[0]);
10699: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10700: my $showdom = $domdesc;
10701: if ($showdom eq '') {
10702: $showdom = $dom;
10703: }
10704: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10705: if ((!$domsrch{'directorysrch'}{'available'}) &&
10706: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10707: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10708: }
10709: }
10710: }
1.555 raeburn 10711: my %curr_selected = (
10712: srchin => 'dom',
1.580 raeburn 10713: srchby => 'lastname',
1.555 raeburn 10714: );
10715: my $srchterm;
1.625 raeburn 10716: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10717: if ($srch->{'srchby'} ne '') {
10718: $curr_selected{'srchby'} = $srch->{'srchby'};
10719: }
10720: if ($srch->{'srchin'} ne '') {
10721: $curr_selected{'srchin'} = $srch->{'srchin'};
10722: }
10723: if ($srch->{'srchtype'} ne '') {
10724: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10725: }
10726: if ($srch->{'srchdomain'} ne '') {
10727: $currdom = $srch->{'srchdomain'};
10728: }
10729: $srchterm = $srch->{'srchterm'};
10730: }
1.1075.2.98 raeburn 10731: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10732: 'usr' => 'Search criteria',
1.563 raeburn 10733: 'doma' => 'Domain/institution to search',
1.558 albertel 10734: 'uname' => 'username',
10735: 'lastname' => 'last name',
1.555 raeburn 10736: 'lastfirst' => 'last name, first name',
1.558 albertel 10737: 'crs' => 'in this course',
1.576 raeburn 10738: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10739: 'alc' => 'all LON-CAPA',
1.573 raeburn 10740: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10741: 'exact' => 'is',
10742: 'contains' => 'contains',
1.569 raeburn 10743: 'begins' => 'begins with',
1.1075.2.98 raeburn 10744: );
10745: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10746: 'youm' => "You must include some text to search for.",
10747: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10748: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10749: 'yomc' => "You must choose a domain when using an institutional directory search.",
10750: 'ymcd' => "You must choose a domain when using a domain search.",
10751: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10752: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10753: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10754: );
1.1075.2.98 raeburn 10755: &html_escape(\%html_lt);
10756: &js_escape(\%js_lt);
1.1075.2.115 raeburn 10757: my $domform;
1.1075.2.126 raeburn 10758: my $allow_blank = 1;
1.1075.2.115 raeburn 10759: if ($fixeddom) {
1.1075.2.126 raeburn 10760: $allow_blank = 0;
10761: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 10762: } else {
1.1075.2.126 raeburn 10763: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 10764: }
1.563 raeburn 10765: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10766:
10767: my @srchins = ('crs','dom','alc','instd');
10768:
10769: foreach my $option (@srchins) {
10770: # FIXME 'alc' option unavailable until
10771: # loncreateuser::print_user_query_page()
10772: # has been completed.
10773: next if ($option eq 'alc');
1.880 raeburn 10774: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10775: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 10776: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10777: if ($curr_selected{'srchin'} eq $option) {
10778: $srchinsel .= '
1.1075.2.98 raeburn 10779: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10780: } else {
10781: $srchinsel .= '
1.1075.2.98 raeburn 10782: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10783: }
1.555 raeburn 10784: }
1.563 raeburn 10785: $srchinsel .= "\n </select>\n";
1.555 raeburn 10786:
10787: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10788: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10789: if ($curr_selected{'srchby'} eq $option) {
10790: $srchbysel .= '
1.1075.2.98 raeburn 10791: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10792: } else {
10793: $srchbysel .= '
1.1075.2.98 raeburn 10794: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10795: }
10796: }
10797: $srchbysel .= "\n </select>\n";
10798:
10799: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10800: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10801: if ($curr_selected{'srchtype'} eq $option) {
10802: $srchtypesel .= '
1.1075.2.98 raeburn 10803: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10804: } else {
10805: $srchtypesel .= '
1.1075.2.98 raeburn 10806: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10807: }
10808: }
10809: $srchtypesel .= "\n </select>\n";
10810:
1.558 albertel 10811: my ($newuserscript,$new_user_create);
1.994 raeburn 10812: my $context_dom = $env{'request.role.domain'};
10813: if ($context eq 'requestcrs') {
10814: if ($env{'form.coursedom'} ne '') {
10815: $context_dom = $env{'form.coursedom'};
10816: }
10817: }
1.556 raeburn 10818: if ($forcenewuser) {
1.576 raeburn 10819: if (ref($srch) eq 'HASH') {
1.994 raeburn 10820: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10821: if ($cancreate) {
10822: $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>';
10823: } else {
1.799 bisitz 10824: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10825: my %usertypetext = (
10826: official => 'institutional',
10827: unofficial => 'non-institutional',
10828: );
1.799 bisitz 10829: $new_user_create = '<p class="LC_warning">'
10830: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10831: .' '
10832: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10833: ,'<a href="'.$helplink.'">','</a>')
10834: .'</p><br />';
1.627 raeburn 10835: }
1.576 raeburn 10836: }
10837: }
10838:
1.556 raeburn 10839: $newuserscript = <<"ENDSCRIPT";
10840:
1.570 raeburn 10841: function setSearch(createnew,callingForm) {
1.556 raeburn 10842: if (createnew == 1) {
1.570 raeburn 10843: for (var i=0; i<callingForm.srchby.length; i++) {
10844: if (callingForm.srchby.options[i].value == 'uname') {
10845: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10846: }
10847: }
1.570 raeburn 10848: for (var i=0; i<callingForm.srchin.length; i++) {
10849: if ( callingForm.srchin.options[i].value == 'dom') {
10850: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10851: }
10852: }
1.570 raeburn 10853: for (var i=0; i<callingForm.srchtype.length; i++) {
10854: if (callingForm.srchtype.options[i].value == 'exact') {
10855: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10856: }
10857: }
1.570 raeburn 10858: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10859: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10860: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10861: }
10862: }
10863: }
10864: }
10865: ENDSCRIPT
1.558 albertel 10866:
1.556 raeburn 10867: }
10868:
1.555 raeburn 10869: my $output = <<"END_BLOCK";
1.556 raeburn 10870: <script type="text/javascript">
1.824 bisitz 10871: // <![CDATA[
1.570 raeburn 10872: function validateEntry(callingForm) {
1.558 albertel 10873:
1.556 raeburn 10874: var checkok = 1;
1.558 albertel 10875: var srchin;
1.570 raeburn 10876: for (var i=0; i<callingForm.srchin.length; i++) {
10877: if ( callingForm.srchin[i].checked ) {
10878: srchin = callingForm.srchin[i].value;
1.558 albertel 10879: }
10880: }
10881:
1.570 raeburn 10882: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10883: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10884: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10885: var srchterm = callingForm.srchterm.value;
10886: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10887: var msg = "";
10888:
10889: if (srchterm == "") {
10890: checkok = 0;
1.1075.2.98 raeburn 10891: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10892: }
10893:
1.569 raeburn 10894: if (srchtype== 'begins') {
10895: if (srchterm.length < 2) {
10896: checkok = 0;
1.1075.2.98 raeburn 10897: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10898: }
10899: }
10900:
1.556 raeburn 10901: if (srchtype== 'contains') {
10902: if (srchterm.length < 3) {
10903: checkok = 0;
1.1075.2.98 raeburn 10904: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10905: }
10906: }
10907: if (srchin == 'instd') {
10908: if (srchdomain == '') {
10909: checkok = 0;
1.1075.2.98 raeburn 10910: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10911: }
10912: }
10913: if (srchin == 'dom') {
10914: if (srchdomain == '') {
10915: checkok = 0;
1.1075.2.98 raeburn 10916: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10917: }
10918: }
10919: if (srchby == 'lastfirst') {
10920: if (srchterm.indexOf(",") == -1) {
10921: checkok = 0;
1.1075.2.98 raeburn 10922: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10923: }
10924: if (srchterm.indexOf(",") == srchterm.length -1) {
10925: checkok = 0;
1.1075.2.98 raeburn 10926: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10927: }
10928: }
10929: if (checkok == 0) {
1.1075.2.98 raeburn 10930: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10931: return;
10932: }
10933: if (checkok == 1) {
1.570 raeburn 10934: callingForm.submit();
1.556 raeburn 10935: }
10936: }
10937:
10938: $newuserscript
10939:
1.824 bisitz 10940: // ]]>
1.556 raeburn 10941: </script>
1.558 albertel 10942:
10943: $new_user_create
10944:
1.555 raeburn 10945: END_BLOCK
1.558 albertel 10946:
1.876 raeburn 10947: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 10948: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10949: $domform.
10950: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 10951: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10952: $srchbysel.
10953: $srchtypesel.
10954: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10955: $srchinsel.
10956: &Apache::lonhtmlcommon::row_closure(1).
10957: &Apache::lonhtmlcommon::end_pick_box().
10958: '<br />';
1.1075.2.114 raeburn 10959: return ($output,1);
1.555 raeburn 10960: }
10961:
1.612 raeburn 10962: sub user_rule_check {
1.615 raeburn 10963: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 10964: my ($response,%inst_response);
1.612 raeburn 10965: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 10966: if (keys(%{$usershash}) > 1) {
10967: my (%by_username,%by_id,%userdoms);
10968: my $checkid;
1.612 raeburn 10969: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 10970: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10971: $checkid = 1;
10972: }
10973: }
10974: foreach my $user (keys(%{$usershash})) {
10975: my ($uname,$udom) = split(/:/,$user);
10976: if ($checkid) {
10977: if (ref($usershash->{$user}) eq 'HASH') {
10978: if ($usershash->{$user}->{'id'} ne '') {
10979: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
10980: $userdoms{$udom} = 1;
10981: if (ref($inst_results) eq 'HASH') {
10982: $inst_results->{$uname.':'.$udom} = {};
10983: }
10984: }
10985: }
10986: } else {
10987: $by_username{$udom}{$uname} = 1;
10988: $userdoms{$udom} = 1;
10989: if (ref($inst_results) eq 'HASH') {
10990: $inst_results->{$uname.':'.$udom} = {};
10991: }
10992: }
10993: }
10994: foreach my $udom (keys(%userdoms)) {
10995: if (!$got_rules->{$udom}) {
10996: my %domconfig = &Apache::lonnet::get_dom('configuration',
10997: ['usercreation'],$udom);
10998: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10999: foreach my $item ('username','id') {
11000: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
11001: $$curr_rules{$udom}{$item} =
11002: $domconfig{'usercreation'}{$item.'_rule'};
11003: }
11004: }
11005: }
11006: $got_rules->{$udom} = 1;
11007: }
11008: }
11009: if ($checkid) {
11010: foreach my $udom (keys(%by_id)) {
11011: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
11012: if ($outcome eq 'ok') {
11013: foreach my $id (keys(%{$by_id{$udom}})) {
11014: my $uname = $by_id{$udom}{$id};
11015: $inst_response{$uname.':'.$udom} = $outcome;
11016: }
11017: if (ref($results) eq 'HASH') {
11018: foreach my $uname (keys(%{$results})) {
11019: if (exists($inst_response{$uname.':'.$udom})) {
11020: $inst_response{$uname.':'.$udom} = $outcome;
11021: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11022: }
11023: }
11024: }
11025: }
1.612 raeburn 11026: }
1.615 raeburn 11027: } else {
1.1075.2.99 raeburn 11028: foreach my $udom (keys(%by_username)) {
11029: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
11030: if ($outcome eq 'ok') {
11031: foreach my $uname (keys(%{$by_username{$udom}})) {
11032: $inst_response{$uname.':'.$udom} = $outcome;
11033: }
11034: if (ref($results) eq 'HASH') {
11035: foreach my $uname (keys(%{$results})) {
11036: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11037: }
11038: }
11039: }
11040: }
1.612 raeburn 11041: }
1.1075.2.99 raeburn 11042: } elsif (keys(%{$usershash}) == 1) {
11043: my $user = (keys(%{$usershash}))[0];
11044: my ($uname,$udom) = split(/:/,$user);
11045: if (($udom ne '') && ($uname ne '')) {
11046: if (ref($usershash->{$user}) eq 'HASH') {
11047: if (ref($checks) eq 'HASH') {
11048: if (defined($checks->{'username'})) {
11049: ($inst_response{$user},%{$inst_results->{$user}}) =
11050: &Apache::lonnet::get_instuser($udom,$uname);
11051: } elsif (defined($checks->{'id'})) {
11052: if ($usershash->{$user}->{'id'} ne '') {
11053: ($inst_response{$user},%{$inst_results->{$user}}) =
11054: &Apache::lonnet::get_instuser($udom,undef,
11055: $usershash->{$user}->{'id'});
11056: } else {
11057: ($inst_response{$user},%{$inst_results->{$user}}) =
11058: &Apache::lonnet::get_instuser($udom,$uname);
11059: }
11060: }
11061: } else {
11062: ($inst_response{$user},%{$inst_results->{$user}}) =
11063: &Apache::lonnet::get_instuser($udom,$uname);
11064: return;
11065: }
11066: if (!$got_rules->{$udom}) {
11067: my %domconfig = &Apache::lonnet::get_dom('configuration',
11068: ['usercreation'],$udom);
11069: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11070: foreach my $item ('username','id') {
11071: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
11072: $$curr_rules{$udom}{$item} =
11073: $domconfig{'usercreation'}{$item.'_rule'};
11074: }
11075: }
1.585 raeburn 11076: }
1.1075.2.99 raeburn 11077: $got_rules->{$udom} = 1;
1.585 raeburn 11078: }
11079: }
1.1075.2.99 raeburn 11080: } else {
11081: return;
11082: }
11083: } else {
11084: return;
11085: }
11086: foreach my $user (keys(%{$usershash})) {
11087: my ($uname,$udom) = split(/:/,$user);
11088: next if (($udom eq '') || ($uname eq ''));
11089: my $id;
11090: if (ref($inst_results) eq 'HASH') {
11091: if (ref($inst_results->{$user}) eq 'HASH') {
11092: $id = $inst_results->{$user}->{'id'};
11093: }
11094: }
11095: if ($id eq '') {
11096: if (ref($usershash->{$user})) {
11097: $id = $usershash->{$user}->{'id'};
11098: }
1.585 raeburn 11099: }
1.612 raeburn 11100: foreach my $item (keys(%{$checks})) {
11101: if (ref($$curr_rules{$udom}) eq 'HASH') {
11102: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
11103: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 11104: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
11105: $$curr_rules{$udom}{$item});
1.612 raeburn 11106: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
11107: if ($rule_check{$rule}) {
11108: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 11109: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 11110: if (ref($inst_results) eq 'HASH') {
11111: if (ref($inst_results->{$user}) eq 'HASH') {
11112: if (keys(%{$inst_results->{$user}}) == 0) {
11113: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 11114: } elsif ($item eq 'id') {
11115: if ($inst_results->{$user}->{'id'} eq '') {
11116: $$alerts{$item}{$udom}{$uname} = 1;
11117: }
1.615 raeburn 11118: }
1.612 raeburn 11119: }
11120: }
1.615 raeburn 11121: }
11122: last;
1.585 raeburn 11123: }
11124: }
11125: }
11126: }
11127: }
11128: }
11129: }
11130: }
1.612 raeburn 11131: return;
11132: }
11133:
11134: sub user_rule_formats {
11135: my ($domain,$domdesc,$curr_rules,$check) = @_;
11136: my %text = (
11137: 'username' => 'Usernames',
11138: 'id' => 'IDs',
11139: );
11140: my $output;
11141: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
11142: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
11143: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 11144: $output = '<br />'.
11145: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
11146: '<span class="LC_cusr_emph">','</span>',$domdesc).
11147: ' <ul>';
1.612 raeburn 11148: foreach my $rule (@{$ruleorder}) {
11149: if (ref($curr_rules) eq 'ARRAY') {
11150: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
11151: if (ref($rules->{$rule}) eq 'HASH') {
11152: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
11153: $rules->{$rule}{'desc'}.'</li>';
11154: }
11155: }
11156: }
11157: }
11158: $output .= '</ul>';
11159: }
11160: }
11161: return $output;
11162: }
11163:
11164: sub instrule_disallow_msg {
1.615 raeburn 11165: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 11166: my $response;
11167: my %text = (
11168: item => 'username',
11169: items => 'usernames',
11170: match => 'matches',
11171: do => 'does',
11172: action => 'a username',
11173: one => 'one',
11174: );
11175: if ($count > 1) {
11176: $text{'item'} = 'usernames';
11177: $text{'match'} ='match';
11178: $text{'do'} = 'do';
11179: $text{'action'} = 'usernames',
11180: $text{'one'} = 'ones';
11181: }
11182: if ($checkitem eq 'id') {
11183: $text{'items'} = 'IDs';
11184: $text{'item'} = 'ID';
11185: $text{'action'} = 'an ID';
1.615 raeburn 11186: if ($count > 1) {
11187: $text{'item'} = 'IDs';
11188: $text{'action'} = 'IDs';
11189: }
1.612 raeburn 11190: }
1.674 bisitz 11191: $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 11192: if ($mode eq 'upload') {
11193: if ($checkitem eq 'username') {
11194: $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'}.");
11195: } elsif ($checkitem eq 'id') {
1.674 bisitz 11196: $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 11197: }
1.669 raeburn 11198: } elsif ($mode eq 'selfcreate') {
11199: if ($checkitem eq 'id') {
11200: $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.");
11201: }
1.615 raeburn 11202: } else {
11203: if ($checkitem eq 'username') {
11204: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
11205: } elsif ($checkitem eq 'id') {
11206: $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.");
11207: }
1.612 raeburn 11208: }
11209: return $response;
1.585 raeburn 11210: }
11211:
1.624 raeburn 11212: sub personal_data_fieldtitles {
11213: my %fieldtitles = &Apache::lonlocal::texthash (
11214: id => 'Student/Employee ID',
11215: permanentemail => 'E-mail address',
11216: lastname => 'Last Name',
11217: firstname => 'First Name',
11218: middlename => 'Middle Name',
11219: generation => 'Generation',
11220: gen => 'Generation',
1.765 raeburn 11221: inststatus => 'Affiliation',
1.624 raeburn 11222: );
11223: return %fieldtitles;
11224: }
11225:
1.642 raeburn 11226: sub sorted_inst_types {
11227: my ($dom) = @_;
1.1075.2.70 raeburn 11228: my ($usertypes,$order);
11229: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11230: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
11231: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
11232: $order = $domdefaults{'inststatus'}{'inststatusorder'};
11233: } else {
11234: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
11235: }
1.642 raeburn 11236: my $othertitle = &mt('All users');
11237: if ($env{'request.course.id'}) {
1.668 raeburn 11238: $othertitle = &mt('Any users');
1.642 raeburn 11239: }
11240: my @types;
11241: if (ref($order) eq 'ARRAY') {
11242: @types = @{$order};
11243: }
11244: if (@types == 0) {
11245: if (ref($usertypes) eq 'HASH') {
11246: @types = sort(keys(%{$usertypes}));
11247: }
11248: }
11249: if (keys(%{$usertypes}) > 0) {
11250: $othertitle = &mt('Other users');
11251: }
11252: return ($othertitle,$usertypes,\@types);
11253: }
11254:
1.645 raeburn 11255: sub get_institutional_codes {
1.1075.2.157 raeburn 11256: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 11257: # Get complete list of course sections to update
11258: my @currsections = ();
11259: my @currxlists = ();
1.1075.2.157 raeburn 11260: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 11261: my $coursecode = $$settings{'internal.coursecode'};
1.1075.2.157 raeburn 11262: my $crskey = $crs.':'.$coursecode;
11263: @{$unclutteredsec{$crskey}} = ();
11264: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 11265:
11266: if ($$settings{'internal.sectionnums'} ne '') {
11267: @currsections = split(/,/,$$settings{'internal.sectionnums'});
11268: }
11269:
11270: if ($$settings{'internal.crosslistings'} ne '') {
11271: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
11272: }
11273:
11274: if (@currxlists > 0) {
1.1075.2.157 raeburn 11275: foreach my $xl (@currxlists) {
11276: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 11277: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 11278: push(@{$allcourses},$1);
1.645 raeburn 11279: $$LC_code{$1} = $2;
11280: }
11281: }
11282: }
11283: }
1.1075.2.157 raeburn 11284:
1.645 raeburn 11285: if (@currsections > 0) {
1.1075.2.157 raeburn 11286: foreach my $sec (@currsections) {
11287: if ($sec =~ m/^(\w+):(\w*)$/ ) {
11288: my $instsec = $1;
1.645 raeburn 11289: my $lc_sec = $2;
1.1075.2.157 raeburn 11290: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
11291: push(@{$unclutteredsec{$crskey}},$instsec);
11292: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
11293: }
11294: }
11295: }
11296: }
11297:
11298: if (@{$unclutteredsec{$crskey}} > 0) {
11299: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
11300: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
11301: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
11302: my $sec = $coursecode.$formattedsec{$crskey}[$i];
11303: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1075.2.119 raeburn 11304: push(@{$allcourses},$sec);
1.1075.2.157 raeburn 11305: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 11306: }
11307: }
11308: }
11309: }
11310: return;
11311: }
11312:
1.971 raeburn 11313: sub get_standard_codeitems {
11314: return ('Year','Semester','Department','Number','Section');
11315: }
11316:
1.112 bowersj2 11317: =pod
11318:
1.780 raeburn 11319: =head1 Slot Helpers
11320:
11321: =over 4
11322:
11323: =item * sorted_slots()
11324:
1.1040 raeburn 11325: Sorts an array of slot names in order of an optional sort key,
11326: default sort is by slot start time (earliest first).
1.780 raeburn 11327:
11328: Inputs:
11329:
11330: =over 4
11331:
11332: slotsarr - Reference to array of unsorted slot names.
11333:
11334: slots - Reference to hash of hash, where outer hash keys are slot names.
11335:
1.1040 raeburn 11336: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
11337:
1.549 albertel 11338: =back
11339:
1.780 raeburn 11340: Returns:
11341:
11342: =over 4
11343:
1.1040 raeburn 11344: sorted - An array of slot names sorted by a specified sort key
11345: (default sort key is start time of the slot).
1.780 raeburn 11346:
11347: =back
11348:
11349: =cut
11350:
11351:
11352: sub sorted_slots {
1.1040 raeburn 11353: my ($slotsarr,$slots,$sortkey) = @_;
11354: if ($sortkey eq '') {
11355: $sortkey = 'starttime';
11356: }
1.780 raeburn 11357: my @sorted;
11358: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11359: @sorted =
11360: sort {
11361: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11362: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11363: }
11364: if (ref($slots->{$a})) { return -1;}
11365: if (ref($slots->{$b})) { return 1;}
11366: return 0;
11367: } @{$slotsarr};
11368: }
11369: return @sorted;
11370: }
11371:
1.1040 raeburn 11372: =pod
11373:
11374: =item * get_future_slots()
11375:
11376: Inputs:
11377:
11378: =over 4
11379:
11380: cnum - course number
11381:
11382: cdom - course domain
11383:
11384: now - current UNIX time
11385:
11386: symb - optional symb
11387:
11388: =back
11389:
11390: Returns:
11391:
11392: =over 4
11393:
11394: sorted_reservable - ref to array of student_schedulable slots currently
11395: reservable, ordered by end date of reservation period.
11396:
11397: reservable_now - ref to hash of student_schedulable slots currently
11398: reservable.
11399:
11400: Keys in inner hash are:
11401: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 11402: (b) endreserve: end date of reservation period.
11403: (c) uniqueperiod: start,end dates when slot is to be uniquely
11404: selected.
1.1040 raeburn 11405:
11406: sorted_future - ref to array of student_schedulable slots reservable in
11407: the future, ordered by start date of reservation period.
11408:
11409: future_reservable - ref to hash of student_schedulable slots reservable
11410: in the future.
11411:
11412: Keys in inner hash are:
11413: (a) symb: either blank or symb to which slot use is restricted.
11414: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 11415: (c) uniqueperiod: start,end dates when slot is to be uniquely
11416: selected.
1.1040 raeburn 11417:
11418: =back
11419:
11420: =cut
11421:
11422: sub get_future_slots {
11423: my ($cnum,$cdom,$now,$symb) = @_;
11424: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11425: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11426: foreach my $slot (keys(%slots)) {
11427: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11428: if ($symb) {
11429: next if (($slots{$slot}->{'symb'} ne '') &&
11430: ($slots{$slot}->{'symb'} ne $symb));
11431: }
11432: if (($slots{$slot}->{'starttime'} > $now) &&
11433: ($slots{$slot}->{'endtime'} > $now)) {
11434: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11435: my $userallowed = 0;
11436: if ($slots{$slot}->{'allowedsections'}) {
11437: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11438: if (!defined($env{'request.role.sec'})
11439: && grep(/^No section assigned$/,@allowed_sec)) {
11440: $userallowed=1;
11441: } else {
11442: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11443: $userallowed=1;
11444: }
11445: }
11446: unless ($userallowed) {
11447: if (defined($env{'request.course.groups'})) {
11448: my @groups = split(/:/,$env{'request.course.groups'});
11449: foreach my $group (@groups) {
11450: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11451: $userallowed=1;
11452: last;
11453: }
11454: }
11455: }
11456: }
11457: }
11458: if ($slots{$slot}->{'allowedusers'}) {
11459: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11460: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11461: if (grep(/^\Q$user\E$/,@allowed_users)) {
11462: $userallowed = 1;
11463: }
11464: }
11465: next unless($userallowed);
11466: }
11467: my $startreserve = $slots{$slot}->{'startreserve'};
11468: my $endreserve = $slots{$slot}->{'endreserve'};
11469: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 11470: my $uniqueperiod;
11471: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11472: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11473: }
1.1040 raeburn 11474: if (($startreserve < $now) &&
11475: (!$endreserve || $endreserve > $now)) {
11476: my $lastres = $endreserve;
11477: if (!$lastres) {
11478: $lastres = $slots{$slot}->{'starttime'};
11479: }
11480: $reservable_now{$slot} = {
11481: symb => $symb,
1.1075.2.104 raeburn 11482: endreserve => $lastres,
11483: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11484: };
11485: } elsif (($startreserve > $now) &&
11486: (!$endreserve || $endreserve > $startreserve)) {
11487: $future_reservable{$slot} = {
11488: symb => $symb,
1.1075.2.104 raeburn 11489: startreserve => $startreserve,
11490: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11491: };
11492: }
11493: }
11494: }
11495: my @unsorted_reservable = keys(%reservable_now);
11496: if (@unsorted_reservable > 0) {
11497: @sorted_reservable =
11498: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11499: }
11500: my @unsorted_future = keys(%future_reservable);
11501: if (@unsorted_future > 0) {
11502: @sorted_future =
11503: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11504: }
11505: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11506: }
1.780 raeburn 11507:
11508: =pod
11509:
1.1057 foxr 11510: =back
11511:
1.549 albertel 11512: =head1 HTTP Helpers
11513:
11514: =over 4
11515:
1.648 raeburn 11516: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11517:
1.258 albertel 11518: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11519: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11520: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11521:
11522: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11523: $possible_names is an ref to an array of form element names. As an example:
11524: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11525: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11526:
11527: =cut
1.1 albertel 11528:
1.6 albertel 11529: sub get_unprocessed_cgi {
1.25 albertel 11530: my ($query,$possible_names)= @_;
1.26 matthew 11531: # $Apache::lonxml::debug=1;
1.356 albertel 11532: foreach my $pair (split(/&/,$query)) {
11533: my ($name, $value) = split(/=/,$pair);
1.369 www 11534: $name = &unescape($name);
1.25 albertel 11535: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11536: $value =~ tr/+/ /;
11537: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11538: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11539: }
1.16 harris41 11540: }
1.6 albertel 11541: }
11542:
1.112 bowersj2 11543: =pod
11544:
1.648 raeburn 11545: =item * &cacheheader()
1.112 bowersj2 11546:
11547: returns cache-controlling header code
11548:
11549: =cut
11550:
1.7 albertel 11551: sub cacheheader {
1.258 albertel 11552: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11553: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11554: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11555: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11556: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11557: return $output;
1.7 albertel 11558: }
11559:
1.112 bowersj2 11560: =pod
11561:
1.648 raeburn 11562: =item * &no_cache($r)
1.112 bowersj2 11563:
11564: specifies header code to not have cache
11565:
11566: =cut
11567:
1.9 albertel 11568: sub no_cache {
1.216 albertel 11569: my ($r) = @_;
11570: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11571: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11572: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11573: $r->no_cache(1);
11574: $r->header_out("Expires" => $date);
11575: $r->header_out("Pragma" => "no-cache");
1.123 www 11576: }
11577:
11578: sub content_type {
1.181 albertel 11579: my ($r,$type,$charset) = @_;
1.299 foxr 11580: if ($r) {
11581: # Note that printout.pl calls this with undef for $r.
11582: &no_cache($r);
11583: }
1.258 albertel 11584: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11585: unless ($charset) {
11586: $charset=&Apache::lonlocal::current_encoding;
11587: }
11588: if ($charset) { $type.='; charset='.$charset; }
11589: if ($r) {
11590: $r->content_type($type);
11591: } else {
11592: print("Content-type: $type\n\n");
11593: }
1.9 albertel 11594: }
1.25 albertel 11595:
1.112 bowersj2 11596: =pod
11597:
1.648 raeburn 11598: =item * &add_to_env($name,$value)
1.112 bowersj2 11599:
1.258 albertel 11600: adds $name to the %env hash with value
1.112 bowersj2 11601: $value, if $name already exists, the entry is converted to an array
11602: reference and $value is added to the array.
11603:
11604: =cut
11605:
1.25 albertel 11606: sub add_to_env {
11607: my ($name,$value)=@_;
1.258 albertel 11608: if (defined($env{$name})) {
11609: if (ref($env{$name})) {
1.25 albertel 11610: #already have multiple values
1.258 albertel 11611: push(@{ $env{$name} },$value);
1.25 albertel 11612: } else {
11613: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11614: my $first=$env{$name};
11615: undef($env{$name});
11616: push(@{ $env{$name} },$first,$value);
1.25 albertel 11617: }
11618: } else {
1.258 albertel 11619: $env{$name}=$value;
1.25 albertel 11620: }
1.31 albertel 11621: }
1.149 albertel 11622:
11623: =pod
11624:
1.648 raeburn 11625: =item * &get_env_multiple($name)
1.149 albertel 11626:
1.258 albertel 11627: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11628: values may be defined and end up as an array ref.
11629:
11630: returns an array of values
11631:
11632: =cut
11633:
11634: sub get_env_multiple {
11635: my ($name) = @_;
11636: my @values;
1.258 albertel 11637: if (defined($env{$name})) {
1.149 albertel 11638: # exists is it an array
1.258 albertel 11639: if (ref($env{$name})) {
11640: @values=@{ $env{$name} };
1.149 albertel 11641: } else {
1.258 albertel 11642: $values[0]=$env{$name};
1.149 albertel 11643: }
11644: }
11645: return(@values);
11646: }
11647:
1.660 raeburn 11648: sub ask_for_embedded_content {
11649: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11650: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 11651: %currsubfile,%unused,$rem);
1.1071 raeburn 11652: my $counter = 0;
11653: my $numnew = 0;
1.987 raeburn 11654: my $numremref = 0;
11655: my $numinvalid = 0;
11656: my $numpathchg = 0;
11657: my $numexisting = 0;
1.1071 raeburn 11658: my $numunused = 0;
11659: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 11660: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11661: my $heading = &mt('Upload embedded files');
11662: my $buttontext = &mt('Upload');
11663:
1.1075.2.11 raeburn 11664: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 11665: if ($actionurl eq '/adm/dependencies') {
11666: $navmap = Apache::lonnavmaps::navmap->new();
11667: }
11668: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11669: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 11670: }
1.1075.2.35 raeburn 11671: if (($actionurl eq '/adm/portfolio') ||
11672: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11673: my $current_path='/';
11674: if ($env{'form.currentpath'}) {
11675: $current_path = $env{'form.currentpath'};
11676: }
11677: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 11678: $udom = $cdom;
11679: $uname = $cnum;
1.984 raeburn 11680: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11681: } else {
11682: $udom = $env{'user.domain'};
11683: $uname = $env{'user.name'};
11684: $url = '/userfiles/portfolio';
11685: }
1.987 raeburn 11686: $toplevel = $url.'/';
1.984 raeburn 11687: $url .= $current_path;
11688: $getpropath = 1;
1.987 raeburn 11689: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11690: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11691: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11692: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11693: $toplevel = $url;
1.984 raeburn 11694: if ($rest ne '') {
1.987 raeburn 11695: $url .= $rest;
11696: }
11697: } elsif ($actionurl eq '/adm/coursedocs') {
11698: if (ref($args) eq 'HASH') {
1.1071 raeburn 11699: $url = $args->{'docs_url'};
11700: $toplevel = $url;
1.1075.2.11 raeburn 11701: if ($args->{'context'} eq 'paste') {
11702: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11703: ($path) =
11704: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11705: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11706: $fileloc =~ s{^/}{};
11707: }
1.1071 raeburn 11708: }
11709: } elsif ($actionurl eq '/adm/dependencies') {
11710: if ($env{'request.course.id'} ne '') {
11711: if (ref($args) eq 'HASH') {
11712: $url = $args->{'docs_url'};
11713: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 11714: $toplevel = $url;
11715: unless ($toplevel =~ m{^/}) {
11716: $toplevel = "/$url";
11717: }
1.1075.2.11 raeburn 11718: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 11719: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11720: $path = $1;
11721: } else {
11722: ($path) =
11723: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11724: }
1.1075.2.79 raeburn 11725: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11726: $fileloc = $toplevel;
11727: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11728: my ($udom,$uname,$fname) =
11729: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11730: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11731: } else {
11732: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11733: }
1.1071 raeburn 11734: $fileloc =~ s{^/}{};
11735: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11736: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11737: }
1.987 raeburn 11738: }
1.1075.2.35 raeburn 11739: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11740: $udom = $cdom;
11741: $uname = $cnum;
11742: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11743: $toplevel = $url;
11744: $path = $url;
11745: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11746: $fileloc =~ s{^/}{};
11747: }
11748: foreach my $file (keys(%{$allfiles})) {
11749: my $embed_file;
11750: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11751: $embed_file = $1;
11752: } else {
11753: $embed_file = $file;
11754: }
1.1075.2.55 raeburn 11755: my ($absolutepath,$cleaned_file);
11756: if ($embed_file =~ m{^\w+://}) {
11757: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 11758: $newfiles{$cleaned_file} = 1;
11759: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11760: } else {
1.1075.2.55 raeburn 11761: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11762: if ($embed_file =~ m{^/}) {
11763: $absolutepath = $embed_file;
11764: }
1.1075.2.47 raeburn 11765: if ($cleaned_file =~ m{/}) {
11766: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11767: $path = &check_for_traversal($path,$url,$toplevel);
11768: my $item = $fname;
11769: if ($path ne '') {
11770: $item = $path.'/'.$fname;
11771: $subdependencies{$path}{$fname} = 1;
11772: } else {
11773: $dependencies{$item} = 1;
11774: }
11775: if ($absolutepath) {
11776: $mapping{$item} = $absolutepath;
11777: } else {
11778: $mapping{$item} = $embed_file;
11779: }
11780: } else {
11781: $dependencies{$embed_file} = 1;
11782: if ($absolutepath) {
1.1075.2.47 raeburn 11783: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11784: } else {
1.1075.2.47 raeburn 11785: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11786: }
11787: }
1.984 raeburn 11788: }
11789: }
1.1071 raeburn 11790: my $dirptr = 16384;
1.984 raeburn 11791: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11792: $currsubfile{$path} = {};
1.1075.2.35 raeburn 11793: if (($actionurl eq '/adm/portfolio') ||
11794: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11795: my ($sublistref,$listerror) =
11796: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11797: if (ref($sublistref) eq 'ARRAY') {
11798: foreach my $line (@{$sublistref}) {
11799: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11800: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11801: }
1.984 raeburn 11802: }
1.987 raeburn 11803: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11804: if (opendir(my $dir,$url.'/'.$path)) {
11805: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11806: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11807: }
1.1075.2.11 raeburn 11808: } elsif (($actionurl eq '/adm/dependencies') ||
11809: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 11810: ($args->{'context'} eq 'paste')) ||
11811: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11812: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 11813: my $dir;
11814: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11815: $dir = $fileloc;
11816: } else {
11817: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11818: }
1.1071 raeburn 11819: if ($dir ne '') {
11820: my ($sublistref,$listerror) =
11821: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11822: if (ref($sublistref) eq 'ARRAY') {
11823: foreach my $line (@{$sublistref}) {
11824: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11825: undef,$mtime)=split(/\&/,$line,12);
11826: unless (($testdir&$dirptr) ||
11827: ($file_name =~ /^\.\.?$/)) {
11828: $currsubfile{$path}{$file_name} = [$size,$mtime];
11829: }
11830: }
11831: }
11832: }
1.984 raeburn 11833: }
11834: }
11835: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11836: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11837: my $item = $path.'/'.$file;
11838: unless ($mapping{$item} eq $item) {
11839: $pathchanges{$item} = 1;
11840: }
11841: $existing{$item} = 1;
11842: $numexisting ++;
11843: } else {
11844: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11845: }
11846: }
1.1071 raeburn 11847: if ($actionurl eq '/adm/dependencies') {
11848: foreach my $path (keys(%currsubfile)) {
11849: if (ref($currsubfile{$path}) eq 'HASH') {
11850: foreach my $file (keys(%{$currsubfile{$path}})) {
11851: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 11852: next if (($rem ne '') &&
11853: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11854: (ref($navmap) &&
11855: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11856: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11857: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11858: $unused{$path.'/'.$file} = 1;
11859: }
11860: }
11861: }
11862: }
11863: }
1.984 raeburn 11864: }
1.987 raeburn 11865: my %currfile;
1.1075.2.35 raeburn 11866: if (($actionurl eq '/adm/portfolio') ||
11867: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11868: my ($dirlistref,$listerror) =
11869: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11870: if (ref($dirlistref) eq 'ARRAY') {
11871: foreach my $line (@{$dirlistref}) {
11872: my ($file_name,$rest) = split(/\&/,$line,2);
11873: $currfile{$file_name} = 1;
11874: }
1.984 raeburn 11875: }
1.987 raeburn 11876: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11877: if (opendir(my $dir,$url)) {
1.987 raeburn 11878: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11879: map {$currfile{$_} = 1;} @dir_list;
11880: }
1.1075.2.11 raeburn 11881: } elsif (($actionurl eq '/adm/dependencies') ||
11882: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 11883: ($args->{'context'} eq 'paste')) ||
11884: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11885: if ($env{'request.course.id'} ne '') {
11886: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11887: if ($dir ne '') {
11888: my ($dirlistref,$listerror) =
11889: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11890: if (ref($dirlistref) eq 'ARRAY') {
11891: foreach my $line (@{$dirlistref}) {
11892: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11893: $size,undef,$mtime)=split(/\&/,$line,12);
11894: unless (($testdir&$dirptr) ||
11895: ($file_name =~ /^\.\.?$/)) {
11896: $currfile{$file_name} = [$size,$mtime];
11897: }
11898: }
11899: }
11900: }
11901: }
1.984 raeburn 11902: }
11903: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11904: if (exists($currfile{$file})) {
1.987 raeburn 11905: unless ($mapping{$file} eq $file) {
11906: $pathchanges{$file} = 1;
11907: }
11908: $existing{$file} = 1;
11909: $numexisting ++;
11910: } else {
1.984 raeburn 11911: $newfiles{$file} = 1;
11912: }
11913: }
1.1071 raeburn 11914: foreach my $file (keys(%currfile)) {
11915: unless (($file eq $filename) ||
11916: ($file eq $filename.'.bak') ||
11917: ($dependencies{$file})) {
1.1075.2.11 raeburn 11918: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 11919: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11920: next if (($rem ne '') &&
11921: (($env{"httpref.$rem".$file} ne '') ||
11922: (ref($navmap) &&
11923: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11924: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11925: ($navmap->getResourceByUrl($rem.$1)))))));
11926: }
1.1075.2.11 raeburn 11927: }
1.1071 raeburn 11928: $unused{$file} = 1;
11929: }
11930: }
1.1075.2.11 raeburn 11931: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11932: ($args->{'context'} eq 'paste')) {
11933: $counter = scalar(keys(%existing));
11934: $numpathchg = scalar(keys(%pathchanges));
11935: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 11936: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11937: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11938: $counter = scalar(keys(%existing));
11939: $numpathchg = scalar(keys(%pathchanges));
11940: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 11941: }
1.984 raeburn 11942: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11943: if ($actionurl eq '/adm/dependencies') {
11944: next if ($embed_file =~ m{^\w+://});
11945: }
1.660 raeburn 11946: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11947: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11948: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11949: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 11950: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11951: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11952: }
1.1075.2.35 raeburn 11953: $upload_output .= '</td>';
1.1071 raeburn 11954: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 11955: $upload_output.='<td align="right">'.
11956: '<span class="LC_info LC_fontsize_medium">'.
11957: &mt("URL points to web address").'</span>';
1.987 raeburn 11958: $numremref++;
1.660 raeburn 11959: } elsif ($args->{'error_on_invalid_names'}
11960: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 11961: $upload_output.='<td align="right"><span class="LC_warning">'.
11962: &mt('Invalid characters').'</span>';
1.987 raeburn 11963: $numinvalid++;
1.660 raeburn 11964: } else {
1.1075.2.35 raeburn 11965: $upload_output .= '<td>'.
11966: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11967: $embed_file,\%mapping,
1.1071 raeburn 11968: $allfiles,$codebase,'upload');
11969: $counter ++;
11970: $numnew ++;
1.987 raeburn 11971: }
11972: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11973: }
11974: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11975: if ($actionurl eq '/adm/dependencies') {
11976: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11977: $modify_output .= &start_data_table_row().
11978: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11979: '<img src="'.&icon($embed_file).'" border="0" />'.
11980: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11981: '<td>'.$size.'</td>'.
11982: '<td>'.$mtime.'</td>'.
11983: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11984: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11985: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11986: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11987: &embedded_file_element('upload_embedded',$counter,
11988: $embed_file,\%mapping,
11989: $allfiles,$codebase,'modify').
11990: '</div></td>'.
11991: &end_data_table_row()."\n";
11992: $counter ++;
11993: } else {
11994: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11995: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11996: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11997: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11998: &Apache::loncommon::end_data_table_row()."\n";
11999: }
12000: }
12001: my $delidx = $counter;
12002: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
12003: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
12004: $delete_output .= &start_data_table_row().
12005: '<td><img src="'.&icon($oldfile).'" />'.
12006: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
12007: '<td>'.$size.'</td>'.
12008: '<td>'.$mtime.'</td>'.
12009: '<td><label><input type="checkbox" name="del_upload_dep" '.
12010: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
12011: &embedded_file_element('upload_embedded',$delidx,
12012: $oldfile,\%mapping,$allfiles,
12013: $codebase,'delete').'</td>'.
12014: &end_data_table_row()."\n";
12015: $numunused ++;
12016: $delidx ++;
1.987 raeburn 12017: }
12018: if ($upload_output) {
12019: $upload_output = &start_data_table().
12020: $upload_output.
12021: &end_data_table()."\n";
12022: }
1.1071 raeburn 12023: if ($modify_output) {
12024: $modify_output = &start_data_table().
12025: &start_data_table_header_row().
12026: '<th>'.&mt('File').'</th>'.
12027: '<th>'.&mt('Size (KB)').'</th>'.
12028: '<th>'.&mt('Modified').'</th>'.
12029: '<th>'.&mt('Upload replacement?').'</th>'.
12030: &end_data_table_header_row().
12031: $modify_output.
12032: &end_data_table()."\n";
12033: }
12034: if ($delete_output) {
12035: $delete_output = &start_data_table().
12036: &start_data_table_header_row().
12037: '<th>'.&mt('File').'</th>'.
12038: '<th>'.&mt('Size (KB)').'</th>'.
12039: '<th>'.&mt('Modified').'</th>'.
12040: '<th>'.&mt('Delete?').'</th>'.
12041: &end_data_table_header_row().
12042: $delete_output.
12043: &end_data_table()."\n";
12044: }
1.987 raeburn 12045: my $applies = 0;
12046: if ($numremref) {
12047: $applies ++;
12048: }
12049: if ($numinvalid) {
12050: $applies ++;
12051: }
12052: if ($numexisting) {
12053: $applies ++;
12054: }
1.1071 raeburn 12055: if ($counter || $numunused) {
1.987 raeburn 12056: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
12057: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 12058: $state.'<h3>'.$heading.'</h3>';
12059: if ($actionurl eq '/adm/dependencies') {
12060: if ($numnew) {
12061: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
12062: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
12063: $upload_output.'<br />'."\n";
12064: }
12065: if ($numexisting) {
12066: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
12067: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
12068: $modify_output.'<br />'."\n";
12069: $buttontext = &mt('Save changes');
12070: }
12071: if ($numunused) {
12072: $output .= '<h4>'.&mt('Unused files').'</h4>'.
12073: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
12074: $delete_output.'<br />'."\n";
12075: $buttontext = &mt('Save changes');
12076: }
12077: } else {
12078: $output .= $upload_output.'<br />'."\n";
12079: }
12080: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
12081: $counter.'" />'."\n";
12082: if ($actionurl eq '/adm/dependencies') {
12083: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
12084: $numnew.'" />'."\n";
12085: } elsif ($actionurl eq '') {
1.987 raeburn 12086: $output .= '<input type="hidden" name="phase" value="three" />';
12087: }
12088: } elsif ($applies) {
12089: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
12090: if ($applies > 1) {
12091: $output .=
1.1075.2.35 raeburn 12092: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 12093: if ($numremref) {
12094: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
12095: }
12096: if ($numinvalid) {
12097: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
12098: }
12099: if ($numexisting) {
12100: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
12101: }
12102: $output .= '</ul><br />';
12103: } elsif ($numremref) {
12104: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
12105: } elsif ($numinvalid) {
12106: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
12107: } elsif ($numexisting) {
12108: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
12109: }
12110: $output .= $upload_output.'<br />';
12111: }
12112: my ($pathchange_output,$chgcount);
1.1071 raeburn 12113: $chgcount = $counter;
1.987 raeburn 12114: if (keys(%pathchanges) > 0) {
12115: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 12116: if ($counter) {
1.987 raeburn 12117: $output .= &embedded_file_element('pathchange',$chgcount,
12118: $embed_file,\%mapping,
1.1071 raeburn 12119: $allfiles,$codebase,'change');
1.987 raeburn 12120: } else {
12121: $pathchange_output .=
12122: &start_data_table_row().
12123: '<td><input type ="checkbox" name="namechange" value="'.
12124: $chgcount.'" checked="checked" /></td>'.
12125: '<td>'.$mapping{$embed_file}.'</td>'.
12126: '<td>'.$embed_file.
12127: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 12128: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 12129: '</td>'.&end_data_table_row();
1.660 raeburn 12130: }
1.987 raeburn 12131: $numpathchg ++;
12132: $chgcount ++;
1.660 raeburn 12133: }
12134: }
1.1075.2.35 raeburn 12135: if (($counter) || ($numunused)) {
1.987 raeburn 12136: if ($numpathchg) {
12137: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
12138: $numpathchg.'" />'."\n";
12139: }
12140: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12141: ($actionurl eq '/adm/imsimport')) {
12142: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
12143: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
12144: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 12145: } elsif ($actionurl eq '/adm/dependencies') {
12146: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 12147: }
1.1075.2.35 raeburn 12148: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 12149: } elsif ($numpathchg) {
12150: my %pathchange = ();
12151: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
12152: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12153: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 12154: }
1.987 raeburn 12155: }
1.1071 raeburn 12156: return ($output,$counter,$numpathchg);
1.987 raeburn 12157: }
12158:
1.1075.2.47 raeburn 12159: =pod
12160:
12161: =item * clean_path($name)
12162:
12163: Performs clean-up of directories, subdirectories and filename in an
12164: embedded object, referenced in an HTML file which is being uploaded
12165: to a course or portfolio, where
12166: "Upload embedded images/multimedia files if HTML file" checkbox was
12167: checked.
12168:
12169: Clean-up is similar to replacements in lonnet::clean_filename()
12170: except each / between sub-directory and next level is preserved.
12171:
12172: =cut
12173:
12174: sub clean_path {
12175: my ($embed_file) = @_;
12176: $embed_file =~s{^/+}{};
12177: my @contents;
12178: if ($embed_file =~ m{/}) {
12179: @contents = split(/\//,$embed_file);
12180: } else {
12181: @contents = ($embed_file);
12182: }
12183: my $lastidx = scalar(@contents)-1;
12184: for (my $i=0; $i<=$lastidx; $i++) {
12185: $contents[$i]=~s{\\}{/}g;
12186: $contents[$i]=~s/\s+/\_/g;
12187: $contents[$i]=~s{[^/\w\.\-]}{}g;
12188: if ($i == $lastidx) {
12189: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
12190: }
12191: }
12192: if ($lastidx > 0) {
12193: return join('/',@contents);
12194: } else {
12195: return $contents[0];
12196: }
12197: }
12198:
1.987 raeburn 12199: sub embedded_file_element {
1.1071 raeburn 12200: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 12201: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
12202: (ref($codebase) eq 'HASH'));
12203: my $output;
1.1071 raeburn 12204: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 12205: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
12206: }
12207: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
12208: &escape($embed_file).'" />';
12209: unless (($context eq 'upload_embedded') &&
12210: ($mapping->{$embed_file} eq $embed_file)) {
12211: $output .='
12212: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
12213: }
12214: my $attrib;
12215: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
12216: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
12217: }
12218: $output .=
12219: "\n\t\t".
12220: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
12221: $attrib.'" />';
12222: if (exists($codebase->{$mapping->{$embed_file}})) {
12223: $output .=
12224: "\n\t\t".
12225: '<input name="codebase_'.$num.'" type="hidden" value="'.
12226: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 12227: }
1.987 raeburn 12228: return $output;
1.660 raeburn 12229: }
12230:
1.1071 raeburn 12231: sub get_dependency_details {
12232: my ($currfile,$currsubfile,$embed_file) = @_;
12233: my ($size,$mtime,$showsize,$showmtime);
12234: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
12235: if ($embed_file =~ m{/}) {
12236: my ($path,$fname) = split(/\//,$embed_file);
12237: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
12238: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
12239: }
12240: } else {
12241: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
12242: ($size,$mtime) = @{$currfile->{$embed_file}};
12243: }
12244: }
12245: $showsize = $size/1024.0;
12246: $showsize = sprintf("%.1f",$showsize);
12247: if ($mtime > 0) {
12248: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
12249: }
12250: }
12251: return ($showsize,$showmtime);
12252: }
12253:
12254: sub ask_embedded_js {
12255: return <<"END";
12256: <script type="text/javascript"">
12257: // <![CDATA[
12258: function toggleBrowse(counter) {
12259: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
12260: var fileid = document.getElementById('embedded_item_'+counter);
12261: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12262: if (chkboxid.checked == true) {
12263: uploaddivid.style.display='block';
12264: } else {
12265: uploaddivid.style.display='none';
12266: fileid.value = '';
12267: }
12268: }
12269: // ]]>
12270: </script>
12271:
12272: END
12273: }
12274:
1.661 raeburn 12275: sub upload_embedded {
12276: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12277: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12278: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12279: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12280: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12281: my $orig_uploaded_filename =
12282: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12283: foreach my $type ('orig','ref','attrib','codebase') {
12284: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12285: $env{'form.embedded_'.$type.'_'.$i} =
12286: &unescape($env{'form.embedded_'.$type.'_'.$i});
12287: }
12288: }
1.661 raeburn 12289: my ($path,$fname) =
12290: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12291: # no path, whole string is fname
12292: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12293: $fname = &Apache::lonnet::clean_filename($fname);
12294: # See if there is anything left
12295: next if ($fname eq '');
12296:
12297: # Check if file already exists as a file or directory.
12298: my ($state,$msg);
12299: if ($context eq 'portfolio') {
12300: my $port_path = $dirpath;
12301: if ($group ne '') {
12302: $port_path = "groups/$group/$port_path";
12303: }
1.987 raeburn 12304: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12305: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12306: $dir_root,$port_path,$disk_quota,
12307: $current_disk_usage,$uname,$udom);
12308: if ($state eq 'will_exceed_quota'
1.984 raeburn 12309: || $state eq 'file_locked') {
1.661 raeburn 12310: $output .= $msg;
12311: next;
12312: }
12313: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12314: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12315: if ($state eq 'exists') {
12316: $output .= $msg;
12317: next;
12318: }
12319: }
12320: # Check if extension is valid
12321: if (($fname =~ /\.(\w+)$/) &&
12322: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 12323: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12324: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12325: next;
12326: } elsif (($fname =~ /\.(\w+)$/) &&
12327: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12328: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12329: next;
12330: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 12331: $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 12332: next;
12333: }
12334: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 12335: my $subdir = $path;
12336: $subdir =~ s{/+$}{};
1.661 raeburn 12337: if ($context eq 'portfolio') {
1.984 raeburn 12338: my $result;
12339: if ($state eq 'existingfile') {
12340: $result=
12341: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 12342: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12343: } else {
1.984 raeburn 12344: $result=
12345: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12346: $dirpath.
1.1075.2.35 raeburn 12347: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12348: if ($result !~ m|^/uploaded/|) {
12349: $output .= '<span class="LC_error">'
12350: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12351: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12352: .'</span><br />';
12353: next;
12354: } else {
1.987 raeburn 12355: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12356: $path.$fname.'</span>').'<br />';
1.984 raeburn 12357: }
1.661 raeburn 12358: }
1.1075.2.35 raeburn 12359: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
12360: my $extendedsubdir = $dirpath.'/'.$subdir;
12361: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12362: my $result =
1.1075.2.35 raeburn 12363: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12364: if ($result !~ m|^/uploaded/|) {
12365: $output .= '<span class="LC_error">'
12366: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12367: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12368: .'</span><br />';
12369: next;
12370: } else {
12371: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12372: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 12373: if ($context eq 'syllabus') {
12374: &Apache::lonnet::make_public_indefinitely($result);
12375: }
1.987 raeburn 12376: }
1.661 raeburn 12377: } else {
12378: # Save the file
12379: my $target = $env{'form.embedded_item_'.$i};
12380: my $fullpath = $dir_root.$dirpath.'/'.$path;
12381: my $dest = $fullpath.$fname;
12382: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12383: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12384: my $count;
12385: my $filepath = $dir_root;
1.1027 raeburn 12386: foreach my $subdir (@parts) {
12387: $filepath .= "/$subdir";
12388: if (!-e $filepath) {
1.661 raeburn 12389: mkdir($filepath,0770);
12390: }
12391: }
12392: my $fh;
12393: if (!open($fh,'>'.$dest)) {
12394: &Apache::lonnet::logthis('Failed to create '.$dest);
12395: $output .= '<span class="LC_error">'.
1.1071 raeburn 12396: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12397: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12398: '</span><br />';
12399: } else {
12400: if (!print $fh $env{'form.embedded_item_'.$i}) {
12401: &Apache::lonnet::logthis('Failed to write to '.$dest);
12402: $output .= '<span class="LC_error">'.
1.1071 raeburn 12403: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12404: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12405: '</span><br />';
12406: } else {
1.987 raeburn 12407: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12408: $url.'</span>').'<br />';
12409: unless ($context eq 'testbank') {
12410: $footer .= &mt('View embedded file: [_1]',
12411: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12412: }
12413: }
12414: close($fh);
12415: }
12416: }
12417: if ($env{'form.embedded_ref_'.$i}) {
12418: $pathchange{$i} = 1;
12419: }
12420: }
12421: if ($output) {
12422: $output = '<p>'.$output.'</p>';
12423: }
12424: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12425: $returnflag = 'ok';
1.1071 raeburn 12426: my $numpathchgs = scalar(keys(%pathchange));
12427: if ($numpathchgs > 0) {
1.987 raeburn 12428: if ($context eq 'portfolio') {
12429: $output .= '<p>'.&mt('or').'</p>';
12430: } elsif ($context eq 'testbank') {
1.1071 raeburn 12431: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12432: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12433: $returnflag = 'modify_orightml';
12434: }
12435: }
1.1071 raeburn 12436: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12437: }
12438:
12439: sub modify_html_form {
12440: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12441: my $end = 0;
12442: my $modifyform;
12443: if ($context eq 'upload_embedded') {
12444: return unless (ref($pathchange) eq 'HASH');
12445: if ($env{'form.number_embedded_items'}) {
12446: $end += $env{'form.number_embedded_items'};
12447: }
12448: if ($env{'form.number_pathchange_items'}) {
12449: $end += $env{'form.number_pathchange_items'};
12450: }
12451: if ($end) {
12452: for (my $i=0; $i<$end; $i++) {
12453: if ($i < $env{'form.number_embedded_items'}) {
12454: next unless($pathchange->{$i});
12455: }
12456: $modifyform .=
12457: &start_data_table_row().
12458: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12459: 'checked="checked" /></td>'.
12460: '<td>'.$env{'form.embedded_ref_'.$i}.
12461: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12462: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12463: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12464: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12465: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12466: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12467: '<td>'.$env{'form.embedded_orig_'.$i}.
12468: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12469: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12470: &end_data_table_row();
1.1071 raeburn 12471: }
1.987 raeburn 12472: }
12473: } else {
12474: $modifyform = $pathchgtable;
12475: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12476: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12477: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12478: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12479: }
12480: }
12481: if ($modifyform) {
1.1071 raeburn 12482: if ($actionurl eq '/adm/dependencies') {
12483: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12484: }
1.987 raeburn 12485: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12486: '<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".
12487: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12488: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12489: '</ol></p>'."\n".'<p>'.
12490: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12491: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12492: &start_data_table()."\n".
12493: &start_data_table_header_row().
12494: '<th>'.&mt('Change?').'</th>'.
12495: '<th>'.&mt('Current reference').'</th>'.
12496: '<th>'.&mt('Required reference').'</th>'.
12497: &end_data_table_header_row()."\n".
12498: $modifyform.
12499: &end_data_table().'<br />'."\n".$hiddenstate.
12500: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12501: '</form>'."\n";
12502: }
12503: return;
12504: }
12505:
12506: sub modify_html_refs {
1.1075.2.35 raeburn 12507: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12508: my $container;
12509: if ($context eq 'portfolio') {
12510: $container = $env{'form.container'};
12511: } elsif ($context eq 'coursedoc') {
12512: $container = $env{'form.primaryurl'};
1.1071 raeburn 12513: } elsif ($context eq 'manage_dependencies') {
12514: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12515: $container = "/$container";
1.1075.2.35 raeburn 12516: } elsif ($context eq 'syllabus') {
12517: $container = $url;
1.987 raeburn 12518: } else {
1.1027 raeburn 12519: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12520: }
12521: my (%allfiles,%codebase,$output,$content);
12522: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 12523: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12524: if (wantarray) {
12525: return ('',0,0);
12526: } else {
12527: return;
12528: }
12529: }
12530: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 12531: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12532: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12533: if (wantarray) {
12534: return ('',0,0);
12535: } else {
12536: return;
12537: }
12538: }
1.987 raeburn 12539: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12540: if ($content eq '-1') {
12541: if (wantarray) {
12542: return ('',0,0);
12543: } else {
12544: return;
12545: }
12546: }
1.987 raeburn 12547: } else {
1.1071 raeburn 12548: unless ($container =~ /^\Q$dir_root\E/) {
12549: if (wantarray) {
12550: return ('',0,0);
12551: } else {
12552: return;
12553: }
12554: }
1.1075.2.128 raeburn 12555: if (open(my $fh,'<',$container)) {
1.987 raeburn 12556: $content = join('', <$fh>);
12557: close($fh);
12558: } else {
1.1071 raeburn 12559: if (wantarray) {
12560: return ('',0,0);
12561: } else {
12562: return;
12563: }
1.987 raeburn 12564: }
12565: }
12566: my ($count,$codebasecount) = (0,0);
12567: my $mm = new File::MMagic;
12568: my $mime_type = $mm->checktype_contents($content);
12569: if ($mime_type eq 'text/html') {
12570: my $parse_result =
12571: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12572: \%codebase,\$content);
12573: if ($parse_result eq 'ok') {
12574: foreach my $i (@changes) {
12575: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12576: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12577: if ($allfiles{$ref}) {
12578: my $newname = $orig;
12579: my ($attrib_regexp,$codebase);
1.1006 raeburn 12580: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12581: if ($attrib_regexp =~ /:/) {
12582: $attrib_regexp =~ s/\:/|/g;
12583: }
12584: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12585: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12586: $count += $numchg;
1.1075.2.35 raeburn 12587: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 12588: delete($allfiles{$ref});
1.987 raeburn 12589: }
12590: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12591: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12592: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12593: $codebasecount ++;
12594: }
12595: }
12596: }
1.1075.2.35 raeburn 12597: my $skiprewrites;
1.987 raeburn 12598: if ($count || $codebasecount) {
12599: my $saveresult;
1.1071 raeburn 12600: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 12601: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12602: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12603: if ($url eq $container) {
12604: my ($fname) = ($container =~ m{/([^/]+)$});
12605: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12606: $count,'<span class="LC_filename">'.
1.1071 raeburn 12607: $fname.'</span>').'</p>';
1.987 raeburn 12608: } else {
12609: $output = '<p class="LC_error">'.
12610: &mt('Error: update failed for: [_1].',
12611: '<span class="LC_filename">'.
12612: $container.'</span>').'</p>';
12613: }
1.1075.2.35 raeburn 12614: if ($context eq 'syllabus') {
12615: unless ($saveresult eq 'ok') {
12616: $skiprewrites = 1;
12617: }
12618: }
1.987 raeburn 12619: } else {
1.1075.2.128 raeburn 12620: if (open(my $fh,'>',$container)) {
1.987 raeburn 12621: print $fh $content;
12622: close($fh);
12623: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12624: $count,'<span class="LC_filename">'.
12625: $container.'</span>').'</p>';
1.661 raeburn 12626: } else {
1.987 raeburn 12627: $output = '<p class="LC_error">'.
12628: &mt('Error: could not update [_1].',
12629: '<span class="LC_filename">'.
12630: $container.'</span>').'</p>';
1.661 raeburn 12631: }
12632: }
12633: }
1.1075.2.35 raeburn 12634: if (($context eq 'syllabus') && (!$skiprewrites)) {
12635: my ($actionurl,$state);
12636: $actionurl = "/public/$udom/$uname/syllabus";
12637: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12638: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12639: \%codebase,
12640: {'context' => 'rewrites',
12641: 'ignore_remote_references' => 1,});
12642: if (ref($mapping) eq 'HASH') {
12643: my $rewrites = 0;
12644: foreach my $key (keys(%{$mapping})) {
12645: next if ($key =~ m{^https?://});
12646: my $ref = $mapping->{$key};
12647: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12648: my $attrib;
12649: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12650: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12651: }
12652: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12653: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12654: $rewrites += $numchg;
12655: }
12656: }
12657: if ($rewrites) {
12658: my $saveresult;
12659: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12660: if ($url eq $container) {
12661: my ($fname) = ($container =~ m{/([^/]+)$});
12662: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12663: $count,'<span class="LC_filename">'.
12664: $fname.'</span>').'</p>';
12665: } else {
12666: $output .= '<p class="LC_error">'.
12667: &mt('Error: could not update links in [_1].',
12668: '<span class="LC_filename">'.
12669: $container.'</span>').'</p>';
12670:
12671: }
12672: }
12673: }
12674: }
1.987 raeburn 12675: } else {
12676: &logthis('Failed to parse '.$container.
12677: ' to modify references: '.$parse_result);
1.661 raeburn 12678: }
12679: }
1.1071 raeburn 12680: if (wantarray) {
12681: return ($output,$count,$codebasecount);
12682: } else {
12683: return $output;
12684: }
1.661 raeburn 12685: }
12686:
12687: sub check_for_existing {
12688: my ($path,$fname,$element) = @_;
12689: my ($state,$msg);
12690: if (-d $path.'/'.$fname) {
12691: $state = 'exists';
12692: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12693: } elsif (-e $path.'/'.$fname) {
12694: $state = 'exists';
12695: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12696: }
12697: if ($state eq 'exists') {
12698: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12699: }
12700: return ($state,$msg);
12701: }
12702:
12703: sub check_for_upload {
12704: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12705: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12706: my $filesize = length($env{'form.'.$element});
12707: if (!$filesize) {
12708: my $msg = '<span class="LC_error">'.
12709: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12710: '<span class="LC_filename">'.$fname.'</span>',
12711: $filesize).'<br />'.
1.1007 raeburn 12712: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12713: '</span>';
12714: return ('zero_bytes',$msg);
12715: }
12716: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12717: my $getpropath = 1;
1.1021 raeburn 12718: my ($dirlistref,$listerror) =
12719: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12720: my $found_file = 0;
12721: my $locked_file = 0;
1.991 raeburn 12722: my @lockers;
12723: my $navmap;
12724: if ($env{'request.course.id'}) {
12725: $navmap = Apache::lonnavmaps::navmap->new();
12726: }
1.1021 raeburn 12727: if (ref($dirlistref) eq 'ARRAY') {
12728: foreach my $line (@{$dirlistref}) {
12729: my ($file_name,$rest)=split(/\&/,$line,2);
12730: if ($file_name eq $fname){
12731: $file_name = $path.$file_name;
12732: if ($group ne '') {
12733: $file_name = $group.$file_name;
12734: }
12735: $found_file = 1;
12736: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12737: foreach my $lock (@lockers) {
12738: if (ref($lock) eq 'ARRAY') {
12739: my ($symb,$crsid) = @{$lock};
12740: if ($crsid eq $env{'request.course.id'}) {
12741: if (ref($navmap)) {
12742: my $res = $navmap->getBySymb($symb);
12743: foreach my $part (@{$res->parts()}) {
12744: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12745: unless (($slot_status == $res->RESERVED) ||
12746: ($slot_status == $res->RESERVED_LOCATION)) {
12747: $locked_file = 1;
12748: }
1.991 raeburn 12749: }
1.1021 raeburn 12750: } else {
12751: $locked_file = 1;
1.991 raeburn 12752: }
12753: } else {
12754: $locked_file = 1;
12755: }
12756: }
1.1021 raeburn 12757: }
12758: } else {
12759: my @info = split(/\&/,$rest);
12760: my $currsize = $info[6]/1000;
12761: if ($currsize < $filesize) {
12762: my $extra = $filesize - $currsize;
12763: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 12764: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12765: &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.1075.2.69 raeburn 12766: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12767: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12768: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12769: return ('will_exceed_quota',$msg);
12770: }
1.984 raeburn 12771: }
12772: }
1.661 raeburn 12773: }
12774: }
12775: }
12776: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 12777: my $msg = '<p class="LC_warning">'.
12778: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
12779: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12780: return ('will_exceed_quota',$msg);
12781: } elsif ($found_file) {
12782: if ($locked_file) {
1.1075.2.69 raeburn 12783: my $msg = '<p class="LC_warning">';
1.661 raeburn 12784: $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.1075.2.69 raeburn 12785: $msg .= '</p>';
1.661 raeburn 12786: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12787: return ('file_locked',$msg);
12788: } else {
1.1075.2.69 raeburn 12789: my $msg = '<p class="LC_error">';
1.984 raeburn 12790: $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.1075.2.69 raeburn 12791: $msg .= '</p>';
1.984 raeburn 12792: return ('existingfile',$msg);
1.661 raeburn 12793: }
12794: }
12795: }
12796:
1.987 raeburn 12797: sub check_for_traversal {
12798: my ($path,$url,$toplevel) = @_;
12799: my @parts=split(/\//,$path);
12800: my $cleanpath;
12801: my $fullpath = $url;
12802: for (my $i=0;$i<@parts;$i++) {
12803: next if ($parts[$i] eq '.');
12804: if ($parts[$i] eq '..') {
12805: $fullpath =~ s{([^/]+/)$}{};
12806: } else {
12807: $fullpath .= $parts[$i].'/';
12808: }
12809: }
12810: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12811: $cleanpath = $1;
12812: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12813: my $curr_toprel = $1;
12814: my @parts = split(/\//,$curr_toprel);
12815: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12816: my @urlparts = split(/\//,$url_toprel);
12817: my $doubledots;
12818: my $startdiff = -1;
12819: for (my $i=0; $i<@urlparts; $i++) {
12820: if ($startdiff == -1) {
12821: unless ($urlparts[$i] eq $parts[$i]) {
12822: $startdiff = $i;
12823: $doubledots .= '../';
12824: }
12825: } else {
12826: $doubledots .= '../';
12827: }
12828: }
12829: if ($startdiff > -1) {
12830: $cleanpath = $doubledots;
12831: for (my $i=$startdiff; $i<@parts; $i++) {
12832: $cleanpath .= $parts[$i].'/';
12833: }
12834: }
12835: }
12836: $cleanpath =~ s{(/)$}{};
12837: return $cleanpath;
12838: }
1.31 albertel 12839:
1.1053 raeburn 12840: sub is_archive_file {
12841: my ($mimetype) = @_;
12842: if (($mimetype eq 'application/octet-stream') ||
12843: ($mimetype eq 'application/x-stuffit') ||
12844: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12845: return 1;
12846: }
12847: return;
12848: }
12849:
12850: sub decompress_form {
1.1065 raeburn 12851: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12852: my %lt = &Apache::lonlocal::texthash (
12853: this => 'This file is an archive file.',
1.1067 raeburn 12854: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12855: itsc => 'Its contents are as follows:',
1.1053 raeburn 12856: youm => 'You may wish to extract its contents.',
12857: extr => 'Extract contents',
1.1067 raeburn 12858: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12859: proa => 'Process automatically?',
1.1053 raeburn 12860: yes => 'Yes',
12861: no => 'No',
1.1067 raeburn 12862: fold => 'Title for folder containing movie',
12863: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12864: );
1.1065 raeburn 12865: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12866: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12867: my $info = &list_archive_contents($fileloc,\@paths);
12868: if (@paths) {
12869: foreach my $path (@paths) {
12870: $path =~ s{^/}{};
1.1067 raeburn 12871: if ($path =~ m{^([^/]+)/$}) {
12872: $topdir = $1;
12873: }
1.1065 raeburn 12874: if ($path =~ m{^([^/]+)/}) {
12875: $toplevel{$1} = $path;
12876: } else {
12877: $toplevel{$path} = $path;
12878: }
12879: }
12880: }
1.1067 raeburn 12881: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 12882: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12883: "$topdir/media/",
12884: "$topdir/media/$topdir.mp4",
12885: "$topdir/media/FirstFrame.png",
12886: "$topdir/media/player.swf",
12887: "$topdir/media/swfobject.js",
12888: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 12889: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 12890: "$topdir/$topdir.mp4",
12891: "$topdir/$topdir\_config.xml",
12892: "$topdir/$topdir\_controller.swf",
12893: "$topdir/$topdir\_embed.css",
12894: "$topdir/$topdir\_First_Frame.png",
12895: "$topdir/$topdir\_player.html",
12896: "$topdir/$topdir\_Thumbnails.png",
12897: "$topdir/playerProductInstall.swf",
12898: "$topdir/scripts/",
12899: "$topdir/scripts/config_xml.js",
12900: "$topdir/scripts/handlebars.js",
12901: "$topdir/scripts/jquery-1.7.1.min.js",
12902: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12903: "$topdir/scripts/modernizr.js",
12904: "$topdir/scripts/player-min.js",
12905: "$topdir/scripts/swfobject.js",
12906: "$topdir/skins/",
12907: "$topdir/skins/configuration_express.xml",
12908: "$topdir/skins/express_show/",
12909: "$topdir/skins/express_show/player-min.css",
12910: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 12911: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12912: "$topdir/$topdir.mp4",
12913: "$topdir/$topdir\_config.xml",
12914: "$topdir/$topdir\_controller.swf",
12915: "$topdir/$topdir\_embed.css",
12916: "$topdir/$topdir\_First_Frame.png",
12917: "$topdir/$topdir\_player.html",
12918: "$topdir/$topdir\_Thumbnails.png",
12919: "$topdir/playerProductInstall.swf",
12920: "$topdir/scripts/",
12921: "$topdir/scripts/config_xml.js",
12922: "$topdir/scripts/techsmith-smart-player.min.js",
12923: "$topdir/skins/",
12924: "$topdir/skins/configuration_express.xml",
12925: "$topdir/skins/express_show/",
12926: "$topdir/skins/express_show/spritesheet.min.css",
12927: "$topdir/skins/express_show/spritesheet.png",
12928: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 12929: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12930: if (@diffs == 0) {
1.1075.2.59 raeburn 12931: $is_camtasia = 6;
12932: } else {
1.1075.2.81 raeburn 12933: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 12934: if (@diffs == 0) {
12935: $is_camtasia = 8;
1.1075.2.81 raeburn 12936: } else {
12937: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12938: if (@diffs == 0) {
12939: $is_camtasia = 8;
12940: }
1.1075.2.59 raeburn 12941: }
1.1067 raeburn 12942: }
12943: }
12944: my $output;
12945: if ($is_camtasia) {
12946: $output = <<"ENDCAM";
12947: <script type="text/javascript" language="Javascript">
12948: // <![CDATA[
12949:
12950: function camtasiaToggle() {
12951: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12952: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 12953: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12954: document.getElementById('camtasia_titles').style.display='block';
12955: } else {
12956: document.getElementById('camtasia_titles').style.display='none';
12957: }
12958: }
12959: }
12960: return;
12961: }
12962:
12963: // ]]>
12964: </script>
12965: <p>$lt{'camt'}</p>
12966: ENDCAM
1.1065 raeburn 12967: } else {
1.1067 raeburn 12968: $output = '<p>'.$lt{'this'};
12969: if ($info eq '') {
12970: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12971: } else {
12972: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12973: '<div><pre>'.$info.'</pre></div>';
12974: }
1.1065 raeburn 12975: }
1.1067 raeburn 12976: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12977: my $duplicates;
12978: my $num = 0;
12979: if (ref($dirlist) eq 'ARRAY') {
12980: foreach my $item (@{$dirlist}) {
12981: if (ref($item) eq 'ARRAY') {
12982: if (exists($toplevel{$item->[0]})) {
12983: $duplicates .=
12984: &start_data_table_row().
12985: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12986: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12987: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12988: 'value="1" />'.&mt('Yes').'</label>'.
12989: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12990: '<td>'.$item->[0].'</td>';
12991: if ($item->[2]) {
12992: $duplicates .= '<td>'.&mt('Directory').'</td>';
12993: } else {
12994: $duplicates .= '<td>'.&mt('File').'</td>';
12995: }
12996: $duplicates .= '<td>'.$item->[3].'</td>'.
12997: '<td>'.
12998: &Apache::lonlocal::locallocaltime($item->[4]).
12999: '</td>'.
13000: &end_data_table_row();
13001: $num ++;
13002: }
13003: }
13004: }
13005: }
13006: my $itemcount;
13007: if (@paths > 0) {
13008: $itemcount = scalar(@paths);
13009: } else {
13010: $itemcount = 1;
13011: }
1.1067 raeburn 13012: if ($is_camtasia) {
13013: $output .= $lt{'auto'}.'<br />'.
13014: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 13015: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 13016: $lt{'yes'}.'</label> <label>'.
13017: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
13018: $lt{'no'}.'</label></span><br />'.
13019: '<div id="camtasia_titles" style="display:block">'.
13020: &Apache::lonhtmlcommon::start_pick_box().
13021: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
13022: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
13023: &Apache::lonhtmlcommon::row_closure().
13024: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
13025: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
13026: &Apache::lonhtmlcommon::row_closure(1).
13027: &Apache::lonhtmlcommon::end_pick_box().
13028: '</div>';
13029: }
1.1065 raeburn 13030: $output .=
13031: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 13032: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
13033: "\n";
1.1065 raeburn 13034: if ($duplicates ne '') {
13035: $output .= '<p><span class="LC_warning">'.
13036: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
13037: &start_data_table().
13038: &start_data_table_header_row().
13039: '<th>'.&mt('Overwrite?').'</th>'.
13040: '<th>'.&mt('Name').'</th>'.
13041: '<th>'.&mt('Type').'</th>'.
13042: '<th>'.&mt('Size').'</th>'.
13043: '<th>'.&mt('Last modified').'</th>'.
13044: &end_data_table_header_row().
13045: $duplicates.
13046: &end_data_table().
13047: '</p>';
13048: }
1.1067 raeburn 13049: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 13050: if (ref($hiddenelements) eq 'HASH') {
13051: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
13052: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
13053: }
13054: }
13055: $output .= <<"END";
1.1067 raeburn 13056: <br />
1.1053 raeburn 13057: <input type="submit" name="decompress" value="$lt{'extr'}" />
13058: </form>
13059: $noextract
13060: END
13061: return $output;
13062: }
13063:
1.1065 raeburn 13064: sub decompression_utility {
13065: my ($program) = @_;
13066: my @utilities = ('tar','gunzip','bunzip2','unzip');
13067: my $location;
13068: if (grep(/^\Q$program\E$/,@utilities)) {
13069: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
13070: '/usr/sbin/') {
13071: if (-x $dir.$program) {
13072: $location = $dir.$program;
13073: last;
13074: }
13075: }
13076: }
13077: return $location;
13078: }
13079:
13080: sub list_archive_contents {
13081: my ($file,$pathsref) = @_;
13082: my (@cmd,$output);
13083: my $needsregexp;
13084: if ($file =~ /\.zip$/) {
13085: @cmd = (&decompression_utility('unzip'),"-l");
13086: $needsregexp = 1;
13087: } elsif (($file =~ m/\.tar\.gz$/) ||
13088: ($file =~ /\.tgz$/)) {
13089: @cmd = (&decompression_utility('tar'),"-ztf");
13090: } elsif ($file =~ /\.tar\.bz2$/) {
13091: @cmd = (&decompression_utility('tar'),"-jtf");
13092: } elsif ($file =~ m|\.tar$|) {
13093: @cmd = (&decompression_utility('tar'),"-tf");
13094: }
13095: if (@cmd) {
13096: undef($!);
13097: undef($@);
13098: if (open(my $fh,"-|", @cmd, $file)) {
13099: while (my $line = <$fh>) {
13100: $output .= $line;
13101: chomp($line);
13102: my $item;
13103: if ($needsregexp) {
13104: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
13105: } else {
13106: $item = $line;
13107: }
13108: if ($item ne '') {
13109: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
13110: push(@{$pathsref},$item);
13111: }
13112: }
13113: }
13114: close($fh);
13115: }
13116: }
13117: return $output;
13118: }
13119:
1.1053 raeburn 13120: sub decompress_uploaded_file {
13121: my ($file,$dir) = @_;
13122: &Apache::lonnet::appenv({'cgi.file' => $file});
13123: &Apache::lonnet::appenv({'cgi.dir' => $dir});
13124: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
13125: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
13126: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
13127: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
13128: my $decompressed = $env{'cgi.decompressed'};
13129: &Apache::lonnet::delenv('cgi.file');
13130: &Apache::lonnet::delenv('cgi.dir');
13131: &Apache::lonnet::delenv('cgi.decompressed');
13132: return ($decompressed,$result);
13133: }
13134:
1.1055 raeburn 13135: sub process_decompression {
13136: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 13137: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
13138: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13139: &mt('Unexpected file path.').'</p>'."\n";
13140: }
13141: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
13142: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13143: &mt('Unexpected course context.').'</p>'."\n";
13144: }
13145: unless ($file eq &Apache::lonnet::clean_filename($file)) {
13146: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13147: &mt('Filename contained unexpected characters.').'</p>'."\n";
13148: }
1.1055 raeburn 13149: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 13150: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 13151: $error = &mt('Filename not a supported archive file type.').
13152: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 13153: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
13154: } else {
13155: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13156: if ($docuhome eq 'no_host') {
13157: $error = &mt('Could not determine home server for course.');
13158: } else {
13159: my @ids=&Apache::lonnet::current_machine_ids();
13160: my $currdir = "$dir_root/$destination";
13161: if (grep(/^\Q$docuhome\E$/,@ids)) {
13162: $dir = &LONCAPA::propath($docudom,$docuname).
13163: "$dir_root/$destination";
13164: } else {
13165: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
13166: "$dir_root/$docudom/$docuname/$destination";
13167: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
13168: $error = &mt('Archive file not found.');
13169: }
13170: }
1.1065 raeburn 13171: my (@to_overwrite,@to_skip);
13172: if ($env{'form.archive_overwrite_total'} > 0) {
13173: my $total = $env{'form.archive_overwrite_total'};
13174: for (my $i=0; $i<$total; $i++) {
13175: if ($env{'form.archive_overwrite_'.$i} == 1) {
13176: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
13177: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
13178: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
13179: }
13180: }
13181: }
13182: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 13183: my $numoverwrite = scalar(@to_overwrite);
13184: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 13185: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
13186: } elsif ($dir eq '') {
1.1055 raeburn 13187: $error = &mt('Directory containing archive file unavailable.');
13188: } elsif (!$error) {
1.1065 raeburn 13189: my ($decompressed,$display);
1.1075.2.128 raeburn 13190: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 13191: my $tempdir = time.'_'.$$.int(rand(10000));
13192: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 13193: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
13194: ($decompressed,$display) =
13195: &decompress_uploaded_file($file,"$dir/$tempdir");
13196: foreach my $item (@to_skip) {
13197: if (($item ne '') && ($item !~ /\.\./)) {
13198: if (-f "$dir/$tempdir/$item") {
13199: unlink("$dir/$tempdir/$item");
13200: } elsif (-d "$dir/$tempdir/$item") {
13201: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
13202: }
13203: }
13204: }
13205: foreach my $item (@to_overwrite) {
13206: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
13207: if (($item ne '') && ($item !~ /\.\./)) {
13208: if (-f "$dir/$item") {
13209: unlink("$dir/$item");
13210: } elsif (-d "$dir/$item") {
13211: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
13212: }
13213: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
13214: }
1.1065 raeburn 13215: }
13216: }
1.1075.2.128 raeburn 13217: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
13218: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
13219: }
1.1065 raeburn 13220: }
13221: } else {
13222: ($decompressed,$display) =
13223: &decompress_uploaded_file($file,$dir);
13224: }
1.1055 raeburn 13225: if ($decompressed eq 'ok') {
1.1065 raeburn 13226: $output = '<p class="LC_info">'.
13227: &mt('Files extracted successfully from archive.').
13228: '</p>'."\n";
1.1055 raeburn 13229: my ($warning,$result,@contents);
13230: my ($newdirlistref,$newlisterror) =
13231: &Apache::lonnet::dirlist($currdir,$docudom,
13232: $docuname,1);
13233: my (%is_dir,%changes,@newitems);
13234: my $dirptr = 16384;
1.1065 raeburn 13235: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 13236: foreach my $dir_line (@{$newdirlistref}) {
13237: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 13238: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 13239: push(@newitems,$item);
13240: if ($dirptr&$testdir) {
13241: $is_dir{$item} = 1;
13242: }
13243: $changes{$item} = 1;
13244: }
13245: }
13246: }
13247: if (keys(%changes) > 0) {
13248: foreach my $item (sort(@newitems)) {
13249: if ($changes{$item}) {
13250: push(@contents,$item);
13251: }
13252: }
13253: }
13254: if (@contents > 0) {
1.1067 raeburn 13255: my $wantform;
13256: unless ($env{'form.autoextract_camtasia'}) {
13257: $wantform = 1;
13258: }
1.1056 raeburn 13259: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 13260: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13261: $currdir,\%is_dir,
13262: \%children,\%parent,
1.1056 raeburn 13263: \@contents,\%dirorder,
13264: \%titles,$wantform);
1.1055 raeburn 13265: if ($datatable ne '') {
13266: $output .= &archive_options_form('decompressed',$datatable,
13267: $count,$hiddenelem);
1.1065 raeburn 13268: my $startcount = 6;
1.1055 raeburn 13269: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13270: \%titles,\%children);
1.1055 raeburn 13271: }
1.1067 raeburn 13272: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 13273: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13274: my %displayed;
13275: my $total = 1;
13276: $env{'form.archive_directory'} = [];
13277: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13278: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13279: $path =~ s{/$}{};
13280: my $item;
13281: if ($path ne '') {
13282: $item = "$path/$titles{$i}";
13283: } else {
13284: $item = $titles{$i};
13285: }
13286: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13287: if ($item eq $contents[0]) {
13288: push(@{$env{'form.archive_directory'}},$i);
13289: $env{'form.archive_'.$i} = 'display';
13290: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13291: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 13292: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13293: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13294: $env{'form.archive_'.$i} = 'display';
13295: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13296: $displayed{'web'} = $i;
13297: } else {
1.1075.2.59 raeburn 13298: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13299: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13300: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13301: push(@{$env{'form.archive_directory'}},$i);
13302: }
13303: $env{'form.archive_'.$i} = 'dependency';
13304: }
13305: $total ++;
13306: }
13307: for (my $i=1; $i<$total; $i++) {
13308: next if ($i == $displayed{'web'});
13309: next if ($i == $displayed{'folder'});
13310: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13311: }
13312: $env{'form.phase'} = 'decompress_cleanup';
13313: $env{'form.archivedelete'} = 1;
13314: $env{'form.archive_count'} = $total-1;
13315: $output .=
13316: &process_extracted_files('coursedocs',$docudom,
13317: $docuname,$destination,
13318: $dir_root,$hiddenelem);
13319: }
1.1055 raeburn 13320: } else {
13321: $warning = &mt('No new items extracted from archive file.');
13322: }
13323: } else {
13324: $output = $display;
13325: $error = &mt('An error occurred during extraction from the archive file.');
13326: }
13327: }
13328: }
13329: }
13330: if ($error) {
13331: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13332: $error.'</p>'."\n";
13333: }
13334: if ($warning) {
13335: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13336: }
13337: return $output;
13338: }
13339:
13340: sub get_extracted {
1.1056 raeburn 13341: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13342: $titles,$wantform) = @_;
1.1055 raeburn 13343: my $count = 0;
13344: my $depth = 0;
13345: my $datatable;
1.1056 raeburn 13346: my @hierarchy;
1.1055 raeburn 13347: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13348: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13349: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13350: foreach my $item (@{$contents}) {
13351: $count ++;
1.1056 raeburn 13352: @{$dirorder->{$count}} = @hierarchy;
13353: $titles->{$count} = $item;
1.1055 raeburn 13354: &archive_hierarchy($depth,$count,$parent,$children);
13355: if ($wantform) {
13356: $datatable .= &archive_row($is_dir->{$item},$item,
13357: $currdir,$depth,$count);
13358: }
13359: if ($is_dir->{$item}) {
13360: $depth ++;
1.1056 raeburn 13361: push(@hierarchy,$count);
13362: $parent->{$depth} = $count;
1.1055 raeburn 13363: $datatable .=
13364: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13365: \$depth,\$count,\@hierarchy,$dirorder,
13366: $children,$parent,$titles,$wantform);
1.1055 raeburn 13367: $depth --;
1.1056 raeburn 13368: pop(@hierarchy);
1.1055 raeburn 13369: }
13370: }
13371: return ($count,$datatable);
13372: }
13373:
13374: sub recurse_extracted_archive {
1.1056 raeburn 13375: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13376: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13377: my $result='';
1.1056 raeburn 13378: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13379: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13380: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13381: return $result;
13382: }
13383: my $dirptr = 16384;
13384: my ($newdirlistref,$newlisterror) =
13385: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13386: if (ref($newdirlistref) eq 'ARRAY') {
13387: foreach my $dir_line (@{$newdirlistref}) {
13388: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13389: unless ($item =~ /^\.+$/) {
13390: $$count ++;
1.1056 raeburn 13391: @{$dirorder->{$$count}} = @{$hierarchy};
13392: $titles->{$$count} = $item;
1.1055 raeburn 13393: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13394:
1.1055 raeburn 13395: my $is_dir;
13396: if ($dirptr&$testdir) {
13397: $is_dir = 1;
13398: }
13399: if ($wantform) {
13400: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13401: }
13402: if ($is_dir) {
13403: $$depth ++;
1.1056 raeburn 13404: push(@{$hierarchy},$$count);
13405: $parent->{$$depth} = $$count;
1.1055 raeburn 13406: $result .=
13407: &recurse_extracted_archive("$currdir/$item",$docudom,
13408: $docuname,$depth,$count,
1.1056 raeburn 13409: $hierarchy,$dirorder,$children,
13410: $parent,$titles,$wantform);
1.1055 raeburn 13411: $$depth --;
1.1056 raeburn 13412: pop(@{$hierarchy});
1.1055 raeburn 13413: }
13414: }
13415: }
13416: }
13417: return $result;
13418: }
13419:
13420: sub archive_hierarchy {
13421: my ($depth,$count,$parent,$children) =@_;
13422: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13423: if (exists($parent->{$depth})) {
13424: $children->{$parent->{$depth}} .= $count.':';
13425: }
13426: }
13427: return;
13428: }
13429:
13430: sub archive_row {
13431: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13432: my ($name) = ($item =~ m{([^/]+)$});
13433: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13434: 'display' => 'Add as file',
1.1055 raeburn 13435: 'dependency' => 'Include as dependency',
13436: 'discard' => 'Discard',
13437: );
13438: if ($is_dir) {
1.1059 raeburn 13439: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13440: }
1.1056 raeburn 13441: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13442: my $offset = 0;
1.1055 raeburn 13443: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13444: $offset ++;
1.1065 raeburn 13445: if ($action ne 'display') {
13446: $offset ++;
13447: }
1.1055 raeburn 13448: $output .= '<td><span class="LC_nobreak">'.
13449: '<label><input type="radio" name="archive_'.$count.
13450: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13451: my $text = $choices{$action};
13452: if ($is_dir) {
13453: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13454: if ($action eq 'display') {
1.1059 raeburn 13455: $text = &mt('Add as folder');
1.1055 raeburn 13456: }
1.1056 raeburn 13457: } else {
13458: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13459:
13460: }
13461: $output .= ' /> '.$choices{$action}.'</label></span>';
13462: if ($action eq 'dependency') {
13463: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13464: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13465: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13466: '<option value=""></option>'."\n".
13467: '</select>'."\n".
13468: '</div>';
1.1059 raeburn 13469: } elsif ($action eq 'display') {
13470: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13471: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13472: '</div>';
1.1055 raeburn 13473: }
1.1056 raeburn 13474: $output .= '</td>';
1.1055 raeburn 13475: }
13476: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13477: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13478: for (my $i=0; $i<$depth; $i++) {
13479: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13480: }
13481: if ($is_dir) {
13482: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13483: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13484: } else {
13485: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13486: }
13487: $output .= ' '.$name.'</td>'."\n".
13488: &end_data_table_row();
13489: return $output;
13490: }
13491:
13492: sub archive_options_form {
1.1065 raeburn 13493: my ($form,$display,$count,$hiddenelem) = @_;
13494: my %lt = &Apache::lonlocal::texthash(
13495: perm => 'Permanently remove archive file?',
13496: hows => 'How should each extracted item be incorporated in the course?',
13497: cont => 'Content actions for all',
13498: addf => 'Add as folder/file',
13499: incd => 'Include as dependency for a displayed file',
13500: disc => 'Discard',
13501: no => 'No',
13502: yes => 'Yes',
13503: save => 'Save',
13504: );
13505: my $output = <<"END";
13506: <form name="$form" method="post" action="">
13507: <p><span class="LC_nobreak">$lt{'perm'}
13508: <label>
13509: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13510: </label>
13511:
13512: <label>
13513: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13514: </span>
13515: </p>
13516: <input type="hidden" name="phase" value="decompress_cleanup" />
13517: <br />$lt{'hows'}
13518: <div class="LC_columnSection">
13519: <fieldset>
13520: <legend>$lt{'cont'}</legend>
13521: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13522: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13523: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13524: </fieldset>
13525: </div>
13526: END
13527: return $output.
1.1055 raeburn 13528: &start_data_table()."\n".
1.1065 raeburn 13529: $display."\n".
1.1055 raeburn 13530: &end_data_table()."\n".
13531: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13532: $hiddenelem.
1.1065 raeburn 13533: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13534: '</form>';
13535: }
13536:
13537: sub archive_javascript {
1.1056 raeburn 13538: my ($startcount,$numitems,$titles,$children) = @_;
13539: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13540: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13541: my $scripttag = <<START;
13542: <script type="text/javascript">
13543: // <![CDATA[
13544:
13545: function checkAll(form,prefix) {
13546: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13547: for (var i=0; i < form.elements.length; i++) {
13548: var id = form.elements[i].id;
13549: if ((id != '') && (id != undefined)) {
13550: if (idstr.test(id)) {
13551: if (form.elements[i].type == 'radio') {
13552: form.elements[i].checked = true;
1.1056 raeburn 13553: var nostart = i-$startcount;
1.1059 raeburn 13554: var offset = nostart%7;
13555: var count = (nostart-offset)/7;
1.1056 raeburn 13556: dependencyCheck(form,count,offset);
1.1055 raeburn 13557: }
13558: }
13559: }
13560: }
13561: }
13562:
13563: function propagateCheck(form,count) {
13564: if (count > 0) {
1.1059 raeburn 13565: var startelement = $startcount + ((count-1) * 7);
13566: for (var j=1; j<6; j++) {
13567: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13568: var item = startelement + j;
13569: if (form.elements[item].type == 'radio') {
13570: if (form.elements[item].checked) {
13571: containerCheck(form,count,j);
13572: break;
13573: }
1.1055 raeburn 13574: }
13575: }
13576: }
13577: }
13578: }
13579:
13580: numitems = $numitems
1.1056 raeburn 13581: var titles = new Array(numitems);
13582: var parents = new Array(numitems);
1.1055 raeburn 13583: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13584: parents[i] = new Array;
1.1055 raeburn 13585: }
1.1059 raeburn 13586: var maintitle = '$maintitle';
1.1055 raeburn 13587:
13588: START
13589:
1.1056 raeburn 13590: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13591: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13592: for (my $i=0; $i<@contents; $i ++) {
13593: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13594: }
13595: }
13596:
1.1056 raeburn 13597: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13598: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13599: }
13600:
1.1055 raeburn 13601: $scripttag .= <<END;
13602:
13603: function containerCheck(form,count,offset) {
13604: if (count > 0) {
1.1056 raeburn 13605: dependencyCheck(form,count,offset);
1.1059 raeburn 13606: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13607: form.elements[item].checked = true;
13608: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13609: if (parents[count].length > 0) {
13610: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13611: containerCheck(form,parents[count][j],offset);
13612: }
13613: }
13614: }
13615: }
13616: }
13617:
13618: function dependencyCheck(form,count,offset) {
13619: if (count > 0) {
1.1059 raeburn 13620: var chosen = (offset+$startcount)+7*(count-1);
13621: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13622: var currtype = form.elements[depitem].type;
13623: if (form.elements[chosen].value == 'dependency') {
13624: document.getElementById('arc_depon_'+count).style.display='block';
13625: form.elements[depitem].options.length = 0;
13626: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 13627: for (var i=1; i<=numitems; i++) {
13628: if (i == count) {
13629: continue;
13630: }
1.1059 raeburn 13631: var startelement = $startcount + (i-1) * 7;
13632: for (var j=1; j<6; j++) {
13633: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13634: var item = startelement + j;
13635: if (form.elements[item].type == 'radio') {
13636: if (form.elements[item].checked) {
13637: if (form.elements[item].value == 'display') {
13638: var n = form.elements[depitem].options.length;
13639: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13640: }
13641: }
13642: }
13643: }
13644: }
13645: }
13646: } else {
13647: document.getElementById('arc_depon_'+count).style.display='none';
13648: form.elements[depitem].options.length = 0;
13649: form.elements[depitem].options[0] = new Option('Select','',true,true);
13650: }
1.1059 raeburn 13651: titleCheck(form,count,offset);
1.1056 raeburn 13652: }
13653: }
13654:
13655: function propagateSelect(form,count,offset) {
13656: if (count > 0) {
1.1065 raeburn 13657: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13658: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13659: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13660: if (parents[count].length > 0) {
13661: for (var j=0; j<parents[count].length; j++) {
13662: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13663: }
13664: }
13665: }
13666: }
13667: }
1.1056 raeburn 13668:
13669: function containerSelect(form,count,offset,picked) {
13670: if (count > 0) {
1.1065 raeburn 13671: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13672: if (form.elements[item].type == 'radio') {
13673: if (form.elements[item].value == 'dependency') {
13674: if (form.elements[item+1].type == 'select-one') {
13675: for (var i=0; i<form.elements[item+1].options.length; i++) {
13676: if (form.elements[item+1].options[i].value == picked) {
13677: form.elements[item+1].selectedIndex = i;
13678: break;
13679: }
13680: }
13681: }
13682: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13683: if (parents[count].length > 0) {
13684: for (var j=0; j<parents[count].length; j++) {
13685: containerSelect(form,parents[count][j],offset,picked);
13686: }
13687: }
13688: }
13689: }
13690: }
13691: }
13692: }
13693:
1.1059 raeburn 13694: function titleCheck(form,count,offset) {
13695: if (count > 0) {
13696: var chosen = (offset+$startcount)+7*(count-1);
13697: var depitem = $startcount + ((count-1) * 7) + 2;
13698: var currtype = form.elements[depitem].type;
13699: if (form.elements[chosen].value == 'display') {
13700: document.getElementById('arc_title_'+count).style.display='block';
13701: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13702: document.getElementById('archive_title_'+count).value=maintitle;
13703: }
13704: } else {
13705: document.getElementById('arc_title_'+count).style.display='none';
13706: if (currtype == 'text') {
13707: document.getElementById('archive_title_'+count).value='';
13708: }
13709: }
13710: }
13711: return;
13712: }
13713:
1.1055 raeburn 13714: // ]]>
13715: </script>
13716: END
13717: return $scripttag;
13718: }
13719:
13720: sub process_extracted_files {
1.1067 raeburn 13721: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13722: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 13723: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13724: my @ids=&Apache::lonnet::current_machine_ids();
13725: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13726: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13727: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13728: if (grep(/^\Q$docuhome\E$/,@ids)) {
13729: $prefix = &LONCAPA::propath($docudom,$docuname);
13730: $pathtocheck = "$dir_root/$destination";
13731: $dir = $dir_root;
13732: $ishome = 1;
13733: } else {
13734: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13735: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 13736: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13737: }
13738: my $currdir = "$dir_root/$destination";
13739: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13740: if ($env{'form.folderpath'}) {
13741: my @items = split('&',$env{'form.folderpath'});
13742: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 13743: if ($env{'form.folderpath'} =~ /\:1$/) {
13744: $containers{'0'}='page';
13745: } else {
13746: $containers{'0'}='sequence';
13747: }
1.1055 raeburn 13748: }
13749: my @archdirs = &get_env_multiple('form.archive_directory');
13750: if ($numitems) {
13751: for (my $i=1; $i<=$numitems; $i++) {
13752: my $path = $env{'form.archive_content_'.$i};
13753: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13754: my $item = $1;
13755: $toplevelitems{$item} = $i;
13756: if (grep(/^\Q$i\E$/,@archdirs)) {
13757: $is_dir{$item} = 1;
13758: }
13759: }
13760: }
13761: }
1.1067 raeburn 13762: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13763: if (keys(%toplevelitems) > 0) {
13764: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13765: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13766: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13767: }
1.1066 raeburn 13768: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13769: if ($numitems) {
13770: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 13771: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13772: my $path = $env{'form.archive_content_'.$i};
13773: if ($path =~ /^\Q$pathtocheck\E/) {
13774: if ($env{'form.archive_'.$i} eq 'discard') {
13775: if ($prefix ne '' && $path ne '') {
13776: if (-e $prefix.$path) {
1.1066 raeburn 13777: if ((@archdirs > 0) &&
13778: (grep(/^\Q$i\E$/,@archdirs))) {
13779: $todeletedir{$prefix.$path} = 1;
13780: } else {
13781: $todelete{$prefix.$path} = 1;
13782: }
1.1055 raeburn 13783: }
13784: }
13785: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13786: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13787: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13788: $docstitle = $env{'form.archive_title_'.$i};
13789: if ($docstitle eq '') {
13790: $docstitle = $title;
13791: }
1.1055 raeburn 13792: $outer = 0;
1.1056 raeburn 13793: if (ref($dirorder{$i}) eq 'ARRAY') {
13794: if (@{$dirorder{$i}} > 0) {
13795: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13796: if ($env{'form.archive_'.$item} eq 'display') {
13797: $outer = $item;
13798: last;
13799: }
13800: }
13801: }
13802: }
13803: my ($errtext,$fatal) =
13804: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13805: '/'.$folders{$outer}.'.'.
13806: $containers{$outer});
13807: next if ($fatal);
13808: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13809: if ($context eq 'coursedocs') {
1.1056 raeburn 13810: $mapinner{$i} = time;
1.1055 raeburn 13811: $folders{$i} = 'default_'.$mapinner{$i};
13812: $containers{$i} = 'sequence';
13813: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13814: $folders{$i}.'.'.$containers{$i};
13815: my $newidx = &LONCAPA::map::getresidx();
13816: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13817: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13818: push(@LONCAPA::map::order,$newidx);
13819: my ($outtext,$errtext) =
13820: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13821: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 13822: '.'.$containers{$outer},1,1);
1.1056 raeburn 13823: $newseqid{$i} = $newidx;
1.1067 raeburn 13824: unless ($errtext) {
1.1075.2.128 raeburn 13825: $result .= '<li>'.&mt('Folder: [_1] added to course',
13826: &HTML::Entities::encode($docstitle,'<>&"'))..
13827: '</li>'."\n";
1.1067 raeburn 13828: }
1.1055 raeburn 13829: }
13830: } else {
13831: if ($context eq 'coursedocs') {
13832: my $newidx=&LONCAPA::map::getresidx();
13833: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13834: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13835: $title;
1.1075.2.161. .13(raeb 13836:-23): if (($outer !~ /\D/) &&
13837:-23): (($mapinner{$outer} eq 'default') || ($mapinner{$outer} !~ /\D/)) &&
13838:-23): ($newidx !~ /\D/)) {
1.1075.2.128 raeburn 13839: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13840: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 13841: }
1.1075.2.128 raeburn 13842: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13843: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13844: }
13845: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13846: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13847: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13848: unless ($ishome) {
13849: my $fetch = "$newdest{$i}/$title";
13850: $fetch =~ s/^\Q$prefix$dir\E//;
13851: $prompttofetch{$fetch} = 1;
13852: }
13853: }
13854: }
13855: $LONCAPA::map::resources[$newidx]=
13856: $docstitle.':'.$url.':false:normal:res';
13857: push(@LONCAPA::map::order, $newidx);
13858: my ($outtext,$errtext)=
13859: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13860: $docuname.'/'.$folders{$outer}.
13861: '.'.$containers{$outer},1,1);
13862: unless ($errtext) {
13863: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13864: $result .= '<li>'.&mt('File: [_1] added to course',
13865: &HTML::Entities::encode($docstitle,'<>&"')).
13866: '</li>'."\n";
13867: }
1.1067 raeburn 13868: }
1.1075.2.128 raeburn 13869: } else {
13870: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13871: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 13872: }
1.1055 raeburn 13873: }
13874: }
1.1075.2.11 raeburn 13875: }
13876: } else {
1.1075.2.128 raeburn 13877: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13878: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 13879: }
13880: }
13881: for (my $i=1; $i<=$numitems; $i++) {
13882: next unless ($env{'form.archive_'.$i} eq 'dependency');
13883: my $path = $env{'form.archive_content_'.$i};
13884: if ($path =~ /^\Q$pathtocheck\E/) {
13885: my ($title) = ($path =~ m{/([^/]+)$});
13886: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13887: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13888: if (ref($dirorder{$i}) eq 'ARRAY') {
13889: my ($itemidx,$fullpath,$relpath);
13890: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13891: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13892: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 13893: if ($dirorder{$i}->[$j] eq $container) {
13894: $itemidx = $j;
1.1056 raeburn 13895: }
13896: }
1.1075.2.11 raeburn 13897: }
13898: if ($itemidx eq '') {
13899: $itemidx = 0;
13900: }
13901: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13902: if ($mapinner{$referrer{$i}}) {
13903: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13904: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13905: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13906: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13907: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13908: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13909: if (!-e $fullpath) {
13910: mkdir($fullpath,0755);
1.1056 raeburn 13911: }
13912: }
1.1075.2.11 raeburn 13913: } else {
13914: last;
1.1056 raeburn 13915: }
1.1075.2.11 raeburn 13916: }
13917: }
13918: } elsif ($newdest{$referrer{$i}}) {
13919: $fullpath = $newdest{$referrer{$i}};
13920: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13921: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13922: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13923: last;
13924: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13925: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13926: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13927: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13928: if (!-e $fullpath) {
13929: mkdir($fullpath,0755);
1.1056 raeburn 13930: }
13931: }
1.1075.2.11 raeburn 13932: } else {
13933: last;
1.1056 raeburn 13934: }
1.1075.2.11 raeburn 13935: }
13936: }
13937: if ($fullpath ne '') {
13938: if (-e "$prefix$path") {
1.1075.2.128 raeburn 13939: unless (rename("$prefix$path","$fullpath/$title")) {
13940: $warning .= &mt('Failed to rename dependency').'<br />';
13941: }
1.1075.2.11 raeburn 13942: }
13943: if (-e "$fullpath/$title") {
13944: my $showpath;
13945: if ($relpath ne '') {
13946: $showpath = "$relpath/$title";
13947: } else {
13948: $showpath = "/$title";
1.1056 raeburn 13949: }
1.1075.2.128 raeburn 13950: $result .= '<li>'.&mt('[_1] included as a dependency',
13951: &HTML::Entities::encode($showpath,'<>&"')).
13952: '</li>'."\n";
13953: unless ($ishome) {
13954: my $fetch = "$fullpath/$title";
13955: $fetch =~ s/^\Q$prefix$dir\E//;
13956: $prompttofetch{$fetch} = 1;
13957: }
1.1055 raeburn 13958: }
13959: }
13960: }
1.1075.2.11 raeburn 13961: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13962: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 13963: &HTML::Entities::encode($path,'<>&"'),
13964: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13965: '<br />';
1.1055 raeburn 13966: }
13967: } else {
1.1075.2.128 raeburn 13968: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13969: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13970: }
13971: }
13972: if (keys(%todelete)) {
13973: foreach my $key (keys(%todelete)) {
13974: unlink($key);
1.1066 raeburn 13975: }
13976: }
13977: if (keys(%todeletedir)) {
13978: foreach my $key (keys(%todeletedir)) {
13979: rmdir($key);
13980: }
13981: }
13982: foreach my $dir (sort(keys(%is_dir))) {
13983: if (($pathtocheck ne '') && ($dir ne '')) {
13984: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13985: }
13986: }
1.1067 raeburn 13987: if ($result ne '') {
13988: $output .= '<ul>'."\n".
13989: $result."\n".
13990: '</ul>';
13991: }
13992: unless ($ishome) {
13993: my $replicationfail;
13994: foreach my $item (keys(%prompttofetch)) {
13995: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13996: unless ($fetchresult eq 'ok') {
13997: $replicationfail .= '<li>'.$item.'</li>'."\n";
13998: }
13999: }
14000: if ($replicationfail) {
14001: $output .= '<p class="LC_error">'.
14002: &mt('Course home server failed to retrieve:').'<ul>'.
14003: $replicationfail.
14004: '</ul></p>';
14005: }
14006: }
1.1055 raeburn 14007: } else {
14008: $warning = &mt('No items found in archive.');
14009: }
14010: if ($error) {
14011: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14012: $error.'</p>'."\n";
14013: }
14014: if ($warning) {
14015: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
14016: }
14017: return $output;
14018: }
14019:
1.1066 raeburn 14020: sub cleanup_empty_dirs {
14021: my ($path) = @_;
14022: if (($path ne '') && (-d $path)) {
14023: if (opendir(my $dirh,$path)) {
14024: my @dircontents = grep(!/^\./,readdir($dirh));
14025: my $numitems = 0;
14026: foreach my $item (@dircontents) {
14027: if (-d "$path/$item") {
1.1075.2.28 raeburn 14028: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 14029: if (-e "$path/$item") {
14030: $numitems ++;
14031: }
14032: } else {
14033: $numitems ++;
14034: }
14035: }
14036: if ($numitems == 0) {
14037: rmdir($path);
14038: }
14039: closedir($dirh);
14040: }
14041: }
14042: return;
14043: }
14044:
1.41 ng 14045: =pod
1.45 matthew 14046:
1.1075.2.56 raeburn 14047: =item * &get_folder_hierarchy()
1.1068 raeburn 14048:
14049: Provides hierarchy of names of folders/sub-folders containing the current
14050: item,
14051:
14052: Inputs: 3
14053: - $navmap - navmaps object
14054:
14055: - $map - url for map (either the trigger itself, or map containing
14056: the resource, which is the trigger).
14057:
14058: - $showitem - 1 => show title for map itself; 0 => do not show.
14059:
14060: Outputs: 1 @pathitems - array of folder/subfolder names.
14061:
14062: =cut
14063:
14064: sub get_folder_hierarchy {
14065: my ($navmap,$map,$showitem) = @_;
14066: my @pathitems;
14067: if (ref($navmap)) {
14068: my $mapres = $navmap->getResourceByUrl($map);
14069: if (ref($mapres)) {
14070: my $pcslist = $mapres->map_hierarchy();
14071: if ($pcslist ne '') {
14072: my @pcs = split(/,/,$pcslist);
14073: foreach my $pc (@pcs) {
14074: if ($pc == 1) {
1.1075.2.38 raeburn 14075: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 14076: } else {
14077: my $res = $navmap->getByMapPc($pc);
14078: if (ref($res)) {
14079: my $title = $res->compTitle();
14080: $title =~ s/\W+/_/g;
14081: if ($title ne '') {
14082: push(@pathitems,$title);
14083: }
14084: }
14085: }
14086: }
14087: }
1.1071 raeburn 14088: if ($showitem) {
14089: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 14090: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 14091: } else {
14092: my $maptitle = $mapres->compTitle();
14093: $maptitle =~ s/\W+/_/g;
14094: if ($maptitle ne '') {
14095: push(@pathitems,$maptitle);
14096: }
1.1068 raeburn 14097: }
14098: }
14099: }
14100: }
14101: return @pathitems;
14102: }
14103:
14104: =pod
14105:
1.1015 raeburn 14106: =item * &get_turnedin_filepath()
14107:
14108: Determines path in a user's portfolio file for storage of files uploaded
14109: to a specific essayresponse or dropbox item.
14110:
14111: Inputs: 3 required + 1 optional.
14112: $symb is symb for resource, $uname and $udom are for current user (required).
14113: $caller is optional (can be "submission", if routine is called when storing
14114: an upoaded file when "Submit Answer" button was pressed).
14115:
14116: Returns array containing $path and $multiresp.
14117: $path is path in portfolio. $multiresp is 1 if this resource contains more
14118: than one file upload item. Callers of routine should append partid as a
14119: subdirectory to $path in cases where $multiresp is 1.
14120:
14121: Called by: homework/essayresponse.pm and homework/structuretags.pm
14122:
14123: =cut
14124:
14125: sub get_turnedin_filepath {
14126: my ($symb,$uname,$udom,$caller) = @_;
14127: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
14128: my $turnindir;
14129: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
14130: $turnindir = $userhash{'turnindir'};
14131: my ($path,$multiresp);
14132: if ($turnindir eq '') {
14133: if ($caller eq 'submission') {
14134: $turnindir = &mt('turned in');
14135: $turnindir =~ s/\W+/_/g;
14136: my %newhash = (
14137: 'turnindir' => $turnindir,
14138: );
14139: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
14140: }
14141: }
14142: if ($turnindir ne '') {
14143: $path = '/'.$turnindir.'/';
14144: my ($multipart,$turnin,@pathitems);
14145: my $navmap = Apache::lonnavmaps::navmap->new();
14146: if (defined($navmap)) {
14147: my $mapres = $navmap->getResourceByUrl($map);
14148: if (ref($mapres)) {
14149: my $pcslist = $mapres->map_hierarchy();
14150: if ($pcslist ne '') {
14151: foreach my $pc (split(/,/,$pcslist)) {
14152: my $res = $navmap->getByMapPc($pc);
14153: if (ref($res)) {
14154: my $title = $res->compTitle();
14155: $title =~ s/\W+/_/g;
14156: if ($title ne '') {
1.1075.2.48 raeburn 14157: if (($pc > 1) && (length($title) > 12)) {
14158: $title = substr($title,0,12);
14159: }
1.1015 raeburn 14160: push(@pathitems,$title);
14161: }
14162: }
14163: }
14164: }
14165: my $maptitle = $mapres->compTitle();
14166: $maptitle =~ s/\W+/_/g;
14167: if ($maptitle ne '') {
1.1075.2.48 raeburn 14168: if (length($maptitle) > 12) {
14169: $maptitle = substr($maptitle,0,12);
14170: }
1.1015 raeburn 14171: push(@pathitems,$maptitle);
14172: }
14173: unless ($env{'request.state'} eq 'construct') {
14174: my $res = $navmap->getBySymb($symb);
14175: if (ref($res)) {
14176: my $partlist = $res->parts();
14177: my $totaluploads = 0;
14178: if (ref($partlist) eq 'ARRAY') {
14179: foreach my $part (@{$partlist}) {
14180: my @types = $res->responseType($part);
14181: my @ids = $res->responseIds($part);
14182: for (my $i=0; $i < scalar(@ids); $i++) {
14183: if ($types[$i] eq 'essay') {
14184: my $partid = $part.'_'.$ids[$i];
14185: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
14186: $totaluploads ++;
14187: }
14188: }
14189: }
14190: }
14191: if ($totaluploads > 1) {
14192: $multiresp = 1;
14193: }
14194: }
14195: }
14196: }
14197: } else {
14198: return;
14199: }
14200: } else {
14201: return;
14202: }
14203: my $restitle=&Apache::lonnet::gettitle($symb);
14204: $restitle =~ s/\W+/_/g;
14205: if ($restitle eq '') {
14206: $restitle = ($resurl =~ m{/[^/]+$});
14207: if ($restitle eq '') {
14208: $restitle = time;
14209: }
14210: }
1.1075.2.48 raeburn 14211: if (length($restitle) > 12) {
14212: $restitle = substr($restitle,0,12);
14213: }
1.1015 raeburn 14214: push(@pathitems,$restitle);
14215: $path .= join('/',@pathitems);
14216: }
14217: return ($path,$multiresp);
14218: }
14219:
14220: =pod
14221:
1.464 albertel 14222: =back
1.41 ng 14223:
1.112 bowersj2 14224: =head1 CSV Upload/Handling functions
1.38 albertel 14225:
1.41 ng 14226: =over 4
14227:
1.648 raeburn 14228: =item * &upfile_store($r)
1.41 ng 14229:
14230: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 14231: needs $env{'form.upfile'}
1.41 ng 14232: returns $datatoken to be put into hidden field
14233:
14234: =cut
1.31 albertel 14235:
14236: sub upfile_store {
14237: my $r=shift;
1.258 albertel 14238: $env{'form.upfile'}=~s/\r/\n/gs;
14239: $env{'form.upfile'}=~s/\f/\n/gs;
14240: $env{'form.upfile'}=~s/\n+/\n/gs;
14241: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 14242:
1.1075.2.128 raeburn 14243: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
14244: '_enroll_'.$env{'request.course.id'}.'_'.
14245: time.'_'.$$);
14246: return if ($datatoken eq '');
14247:
1.31 albertel 14248: {
1.158 raeburn 14249: my $datafile = $r->dir_config('lonDaemons').
14250: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 14251: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 14252: print $fh $env{'form.upfile'};
1.158 raeburn 14253: close($fh);
14254: }
1.31 albertel 14255: }
14256: return $datatoken;
14257: }
14258:
1.56 matthew 14259: =pod
14260:
1.1075.2.128 raeburn 14261: =item * &load_tmp_file($r,$datatoken)
1.41 ng 14262:
14263: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 14264: $datatoken is the name to assign to the temporary file.
1.258 albertel 14265: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14266:
14267: =cut
1.31 albertel 14268:
14269: sub load_tmp_file {
1.1075.2.128 raeburn 14270: my ($r,$datatoken) = @_;
14271: return if ($datatoken eq '');
1.31 albertel 14272: my @studentdata=();
14273: {
1.158 raeburn 14274: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 14275: '/tmp/'.$datatoken.'.tmp';
14276: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14277: @studentdata=<$fh>;
14278: close($fh);
14279: }
1.31 albertel 14280: }
1.258 albertel 14281: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14282: }
14283:
1.1075.2.128 raeburn 14284: sub valid_datatoken {
14285: my ($datatoken) = @_;
1.1075.2.131 raeburn 14286: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 14287: return $datatoken;
14288: }
14289: return;
14290: }
14291:
1.56 matthew 14292: =pod
14293:
1.648 raeburn 14294: =item * &upfile_record_sep()
1.41 ng 14295:
14296: Separate uploaded file into records
14297: returns array of records,
1.258 albertel 14298: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14299:
14300: =cut
1.31 albertel 14301:
14302: sub upfile_record_sep {
1.258 albertel 14303: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14304: } else {
1.248 albertel 14305: my @records;
1.258 albertel 14306: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14307: if ($line=~/^\s*$/) { next; }
14308: push(@records,$line);
14309: }
14310: return @records;
1.31 albertel 14311: }
14312: }
14313:
1.56 matthew 14314: =pod
14315:
1.648 raeburn 14316: =item * &record_sep($record)
1.41 ng 14317:
1.258 albertel 14318: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14319:
14320: =cut
14321:
1.263 www 14322: sub takeleft {
14323: my $index=shift;
14324: return substr('0000'.$index,-4,4);
14325: }
14326:
1.31 albertel 14327: sub record_sep {
14328: my $record=shift;
14329: my %components=();
1.258 albertel 14330: if ($env{'form.upfiletype'} eq 'xml') {
14331: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14332: my $i=0;
1.356 albertel 14333: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14334: $field=~s/^(\"|\')//;
14335: $field=~s/(\"|\')$//;
1.263 www 14336: $components{&takeleft($i)}=$field;
1.31 albertel 14337: $i++;
14338: }
1.258 albertel 14339: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14340: my $i=0;
1.356 albertel 14341: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14342: $field=~s/^(\"|\')//;
14343: $field=~s/(\"|\')$//;
1.263 www 14344: $components{&takeleft($i)}=$field;
1.31 albertel 14345: $i++;
14346: }
14347: } else {
1.561 www 14348: my $separator=',';
1.480 banghart 14349: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14350: $separator=';';
1.480 banghart 14351: }
1.31 albertel 14352: my $i=0;
1.561 www 14353: # the character we are looking for to indicate the end of a quote or a record
14354: my $looking_for=$separator;
14355: # do not add the characters to the fields
14356: my $ignore=0;
14357: # we just encountered a separator (or the beginning of the record)
14358: my $just_found_separator=1;
14359: # store the field we are working on here
14360: my $field='';
14361: # work our way through all characters in record
14362: foreach my $character ($record=~/(.)/g) {
14363: if ($character eq $looking_for) {
14364: if ($character ne $separator) {
14365: # Found the end of a quote, again looking for separator
14366: $looking_for=$separator;
14367: $ignore=1;
14368: } else {
14369: # Found a separator, store away what we got
14370: $components{&takeleft($i)}=$field;
14371: $i++;
14372: $just_found_separator=1;
14373: $ignore=0;
14374: $field='';
14375: }
14376: next;
14377: }
14378: # single or double quotation marks after a separator indicate beginning of a quote
14379: # we are now looking for the end of the quote and need to ignore separators
14380: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14381: $looking_for=$character;
14382: next;
14383: }
14384: # ignore would be true after we reached the end of a quote
14385: if ($ignore) { next; }
14386: if (($just_found_separator) && ($character=~/\s/)) { next; }
14387: $field.=$character;
14388: $just_found_separator=0;
1.31 albertel 14389: }
1.561 www 14390: # catch the very last entry, since we never encountered the separator
14391: $components{&takeleft($i)}=$field;
1.31 albertel 14392: }
14393: return %components;
14394: }
14395:
1.144 matthew 14396: ######################################################
14397: ######################################################
14398:
1.56 matthew 14399: =pod
14400:
1.648 raeburn 14401: =item * &upfile_select_html()
1.41 ng 14402:
1.144 matthew 14403: Return HTML code to select a file from the users machine and specify
14404: the file type.
1.41 ng 14405:
14406: =cut
14407:
1.144 matthew 14408: ######################################################
14409: ######################################################
1.31 albertel 14410: sub upfile_select_html {
1.144 matthew 14411: my %Types = (
14412: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14413: semisv => &mt('Semicolon separated values'),
1.144 matthew 14414: space => &mt('Space separated'),
14415: tab => &mt('Tabulator separated'),
14416: # xml => &mt('HTML/XML'),
14417: );
14418: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14419: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14420: foreach my $type (sort(keys(%Types))) {
14421: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14422: }
14423: $Str .= "</select>\n";
14424: return $Str;
1.31 albertel 14425: }
14426:
1.301 albertel 14427: sub get_samples {
14428: my ($records,$toget) = @_;
14429: my @samples=({});
14430: my $got=0;
14431: foreach my $rec (@$records) {
14432: my %temp = &record_sep($rec);
14433: if (! grep(/\S/, values(%temp))) { next; }
14434: if (%temp) {
14435: $samples[$got]=\%temp;
14436: $got++;
14437: if ($got == $toget) { last; }
14438: }
14439: }
14440: return \@samples;
14441: }
14442:
1.144 matthew 14443: ######################################################
14444: ######################################################
14445:
1.56 matthew 14446: =pod
14447:
1.648 raeburn 14448: =item * &csv_print_samples($r,$records)
1.41 ng 14449:
14450: Prints a table of sample values from each column uploaded $r is an
14451: Apache Request ref, $records is an arrayref from
14452: &Apache::loncommon::upfile_record_sep
14453:
14454: =cut
14455:
1.144 matthew 14456: ######################################################
14457: ######################################################
1.31 albertel 14458: sub csv_print_samples {
14459: my ($r,$records) = @_;
1.662 bisitz 14460: my $samples = &get_samples($records,5);
1.301 albertel 14461:
1.594 raeburn 14462: $r->print(&mt('Samples').'<br />'.&start_data_table().
14463: &start_data_table_header_row());
1.356 albertel 14464: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14465: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14466: $r->print(&end_data_table_header_row());
1.301 albertel 14467: foreach my $hash (@$samples) {
1.594 raeburn 14468: $r->print(&start_data_table_row());
1.356 albertel 14469: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14470: $r->print('<td>');
1.356 albertel 14471: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14472: $r->print('</td>');
14473: }
1.594 raeburn 14474: $r->print(&end_data_table_row());
1.31 albertel 14475: }
1.594 raeburn 14476: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14477: }
14478:
1.144 matthew 14479: ######################################################
14480: ######################################################
14481:
1.56 matthew 14482: =pod
14483:
1.648 raeburn 14484: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14485:
14486: Prints a table to create associations between values and table columns.
1.144 matthew 14487:
1.41 ng 14488: $r is an Apache Request ref,
14489: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14490: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14491:
14492: =cut
14493:
1.144 matthew 14494: ######################################################
14495: ######################################################
1.31 albertel 14496: sub csv_print_select_table {
14497: my ($r,$records,$d) = @_;
1.301 albertel 14498: my $i=0;
14499: my $samples = &get_samples($records,1);
1.144 matthew 14500: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14501: &start_data_table().&start_data_table_header_row().
1.144 matthew 14502: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14503: '<th>'.&mt('Column').'</th>'.
14504: &end_data_table_header_row()."\n");
1.356 albertel 14505: foreach my $array_ref (@$d) {
14506: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14507: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14508:
1.875 bisitz 14509: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14510: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14511: $r->print('<option value="none"></option>');
1.356 albertel 14512: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14513: $r->print('<option value="'.$sample.'"'.
14514: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14515: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14516: }
1.594 raeburn 14517: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14518: $i++;
14519: }
1.594 raeburn 14520: $r->print(&end_data_table());
1.31 albertel 14521: $i--;
14522: return $i;
14523: }
1.56 matthew 14524:
1.144 matthew 14525: ######################################################
14526: ######################################################
14527:
1.56 matthew 14528: =pod
1.31 albertel 14529:
1.648 raeburn 14530: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14531:
14532: Prints a table of sample values from the upload and can make associate samples to internal names.
14533:
14534: $r is an Apache Request ref,
14535: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14536: $d is an array of 2 element arrays (internal name, displayed name)
14537:
14538: =cut
14539:
1.144 matthew 14540: ######################################################
14541: ######################################################
1.31 albertel 14542: sub csv_samples_select_table {
14543: my ($r,$records,$d) = @_;
14544: my $i=0;
1.144 matthew 14545: #
1.662 bisitz 14546: my $max_samples = 5;
14547: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14548: $r->print(&start_data_table().
14549: &start_data_table_header_row().'<th>'.
14550: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14551: &end_data_table_header_row());
1.301 albertel 14552:
14553: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14554: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14555: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14556: foreach my $option (@$d) {
14557: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14558: $r->print('<option value="'.$value.'"'.
1.253 albertel 14559: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14560: $display.'</option>');
1.31 albertel 14561: }
14562: $r->print('</select></td><td>');
1.662 bisitz 14563: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14564: if (defined($samples->[$line]{$key})) {
14565: $r->print($samples->[$line]{$key}."<br />\n");
14566: }
14567: }
1.594 raeburn 14568: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14569: $i++;
14570: }
1.594 raeburn 14571: $r->print(&end_data_table());
1.31 albertel 14572: $i--;
14573: return($i);
1.115 matthew 14574: }
14575:
1.144 matthew 14576: ######################################################
14577: ######################################################
14578:
1.115 matthew 14579: =pod
14580:
1.648 raeburn 14581: =item * &clean_excel_name($name)
1.115 matthew 14582:
14583: Returns a replacement for $name which does not contain any illegal characters.
14584:
14585: =cut
14586:
1.144 matthew 14587: ######################################################
14588: ######################################################
1.115 matthew 14589: sub clean_excel_name {
14590: my ($name) = @_;
14591: $name =~ s/[:\*\?\/\\]//g;
14592: if (length($name) > 31) {
14593: $name = substr($name,0,31);
14594: }
14595: return $name;
1.25 albertel 14596: }
1.84 albertel 14597:
1.85 albertel 14598: =pod
14599:
1.648 raeburn 14600: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14601:
14602: Returns either 1 or undef
14603:
14604: 1 if the part is to be hidden, undef if it is to be shown
14605:
14606: Arguments are:
14607:
14608: $id the id of the part to be checked
14609: $symb, optional the symb of the resource to check
14610: $udom, optional the domain of the user to check for
14611: $uname, optional the username of the user to check for
14612:
14613: =cut
1.84 albertel 14614:
14615: sub check_if_partid_hidden {
14616: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14617: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14618: $symb,$udom,$uname);
1.141 albertel 14619: my $truth=1;
14620: #if the string starts with !, then the list is the list to show not hide
14621: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14622: my @hiddenlist=split(/,/,$hiddenparts);
14623: foreach my $checkid (@hiddenlist) {
1.141 albertel 14624: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14625: }
1.141 albertel 14626: return !$truth;
1.84 albertel 14627: }
1.127 matthew 14628:
1.138 matthew 14629:
14630: ############################################################
14631: ############################################################
14632:
14633: =pod
14634:
1.157 matthew 14635: =back
14636:
1.138 matthew 14637: =head1 cgi-bin script and graphing routines
14638:
1.157 matthew 14639: =over 4
14640:
1.648 raeburn 14641: =item * &get_cgi_id()
1.138 matthew 14642:
14643: Inputs: none
14644:
14645: Returns an id which can be used to pass environment variables
14646: to various cgi-bin scripts. These environment variables will
14647: be removed from the users environment after a given time by
14648: the routine &Apache::lonnet::transfer_profile_to_env.
14649:
14650: =cut
14651:
14652: ############################################################
14653: ############################################################
1.152 albertel 14654: my $uniq=0;
1.136 matthew 14655: sub get_cgi_id {
1.154 albertel 14656: $uniq=($uniq+1)%100000;
1.280 albertel 14657: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14658: }
14659:
1.127 matthew 14660: ############################################################
14661: ############################################################
14662:
14663: =pod
14664:
1.648 raeburn 14665: =item * &DrawBarGraph()
1.127 matthew 14666:
1.138 matthew 14667: Facilitates the plotting of data in a (stacked) bar graph.
14668: Puts plot definition data into the users environment in order for
14669: graph.png to plot it. Returns an <img> tag for the plot.
14670: The bars on the plot are labeled '1','2',...,'n'.
14671:
14672: Inputs:
14673:
14674: =over 4
14675:
14676: =item $Title: string, the title of the plot
14677:
14678: =item $xlabel: string, text describing the X-axis of the plot
14679:
14680: =item $ylabel: string, text describing the Y-axis of the plot
14681:
14682: =item $Max: scalar, the maximum Y value to use in the plot
14683: If $Max is < any data point, the graph will not be rendered.
14684:
1.140 matthew 14685: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14686: they are plotted. If undefined, default values will be used.
14687:
1.178 matthew 14688: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14689:
1.138 matthew 14690: =item @Values: An array of array references. Each array reference holds data
14691: to be plotted in a stacked bar chart.
14692:
1.239 matthew 14693: =item If the final element of @Values is a hash reference the key/value
14694: pairs will be added to the graph definition.
14695:
1.138 matthew 14696: =back
14697:
14698: Returns:
14699:
14700: An <img> tag which references graph.png and the appropriate identifying
14701: information for the plot.
14702:
1.127 matthew 14703: =cut
14704:
14705: ############################################################
14706: ############################################################
1.134 matthew 14707: sub DrawBarGraph {
1.178 matthew 14708: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14709: #
14710: if (! defined($colors)) {
14711: $colors = ['#33ff00',
14712: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14713: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14714: ];
14715: }
1.228 matthew 14716: my $extra_settings = {};
14717: if (ref($Values[-1]) eq 'HASH') {
14718: $extra_settings = pop(@Values);
14719: }
1.127 matthew 14720: #
1.136 matthew 14721: my $identifier = &get_cgi_id();
14722: my $id = 'cgi.'.$identifier;
1.129 matthew 14723: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14724: return '';
14725: }
1.225 matthew 14726: #
14727: my @Labels;
14728: if (defined($labels)) {
14729: @Labels = @$labels;
14730: } else {
14731: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 14732: push(@Labels,$i+1);
1.225 matthew 14733: }
14734: }
14735: #
1.129 matthew 14736: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14737: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14738: my %ValuesHash;
14739: my $NumSets=1;
14740: foreach my $array (@Values) {
14741: next if (! ref($array));
1.136 matthew 14742: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14743: join(',',@$array);
1.129 matthew 14744: }
1.127 matthew 14745: #
1.136 matthew 14746: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14747: if ($NumBars < 3) {
14748: $width = 120+$NumBars*32;
1.220 matthew 14749: $xskip = 1;
1.225 matthew 14750: $bar_width = 30;
14751: } elsif ($NumBars < 5) {
14752: $width = 120+$NumBars*20;
14753: $xskip = 1;
14754: $bar_width = 20;
1.220 matthew 14755: } elsif ($NumBars < 10) {
1.136 matthew 14756: $width = 120+$NumBars*15;
14757: $xskip = 1;
14758: $bar_width = 15;
14759: } elsif ($NumBars <= 25) {
14760: $width = 120+$NumBars*11;
14761: $xskip = 5;
14762: $bar_width = 8;
14763: } elsif ($NumBars <= 50) {
14764: $width = 120+$NumBars*8;
14765: $xskip = 5;
14766: $bar_width = 4;
14767: } else {
14768: $width = 120+$NumBars*8;
14769: $xskip = 5;
14770: $bar_width = 4;
14771: }
14772: #
1.137 matthew 14773: $Max = 1 if ($Max < 1);
14774: if ( int($Max) < $Max ) {
14775: $Max++;
14776: $Max = int($Max);
14777: }
1.127 matthew 14778: $Title = '' if (! defined($Title));
14779: $xlabel = '' if (! defined($xlabel));
14780: $ylabel = '' if (! defined($ylabel));
1.369 www 14781: $ValuesHash{$id.'.title'} = &escape($Title);
14782: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14783: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14784: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14785: $ValuesHash{$id.'.NumBars'} = $NumBars;
14786: $ValuesHash{$id.'.NumSets'} = $NumSets;
14787: $ValuesHash{$id.'.PlotType'} = 'bar';
14788: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14789: $ValuesHash{$id.'.height'} = $height;
14790: $ValuesHash{$id.'.width'} = $width;
14791: $ValuesHash{$id.'.xskip'} = $xskip;
14792: $ValuesHash{$id.'.bar_width'} = $bar_width;
14793: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14794: #
1.228 matthew 14795: # Deal with other parameters
14796: while (my ($key,$value) = each(%$extra_settings)) {
14797: $ValuesHash{$id.'.'.$key} = $value;
14798: }
14799: #
1.646 raeburn 14800: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14801: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14802: }
14803:
14804: ############################################################
14805: ############################################################
14806:
14807: =pod
14808:
1.648 raeburn 14809: =item * &DrawXYGraph()
1.137 matthew 14810:
1.138 matthew 14811: Facilitates the plotting of data in an XY graph.
14812: Puts plot definition data into the users environment in order for
14813: graph.png to plot it. Returns an <img> tag for the plot.
14814:
14815: Inputs:
14816:
14817: =over 4
14818:
14819: =item $Title: string, the title of the plot
14820:
14821: =item $xlabel: string, text describing the X-axis of the plot
14822:
14823: =item $ylabel: string, text describing the Y-axis of the plot
14824:
14825: =item $Max: scalar, the maximum Y value to use in the plot
14826: If $Max is < any data point, the graph will not be rendered.
14827:
14828: =item $colors: Array ref containing the hex color codes for the data to be
14829: plotted in. If undefined, default values will be used.
14830:
14831: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14832:
14833: =item $Ydata: Array ref containing Array refs.
1.185 www 14834: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14835:
14836: =item %Values: hash indicating or overriding any default values which are
14837: passed to graph.png.
14838: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14839:
14840: =back
14841:
14842: Returns:
14843:
14844: An <img> tag which references graph.png and the appropriate identifying
14845: information for the plot.
14846:
1.137 matthew 14847: =cut
14848:
14849: ############################################################
14850: ############################################################
14851: sub DrawXYGraph {
14852: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14853: #
14854: # Create the identifier for the graph
14855: my $identifier = &get_cgi_id();
14856: my $id = 'cgi.'.$identifier;
14857: #
14858: $Title = '' if (! defined($Title));
14859: $xlabel = '' if (! defined($xlabel));
14860: $ylabel = '' if (! defined($ylabel));
14861: my %ValuesHash =
14862: (
1.369 www 14863: $id.'.title' => &escape($Title),
14864: $id.'.xlabel' => &escape($xlabel),
14865: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14866: $id.'.y_max_value'=> $Max,
14867: $id.'.labels' => join(',',@$Xlabels),
14868: $id.'.PlotType' => 'XY',
14869: );
14870: #
14871: if (defined($colors) && ref($colors) eq 'ARRAY') {
14872: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14873: }
14874: #
14875: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14876: return '';
14877: }
14878: my $NumSets=1;
1.138 matthew 14879: foreach my $array (@{$Ydata}){
1.137 matthew 14880: next if (! ref($array));
14881: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14882: }
1.138 matthew 14883: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14884: #
14885: # Deal with other parameters
14886: while (my ($key,$value) = each(%Values)) {
14887: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14888: }
14889: #
1.646 raeburn 14890: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14891: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14892: }
14893:
14894: ############################################################
14895: ############################################################
14896:
14897: =pod
14898:
1.648 raeburn 14899: =item * &DrawXYYGraph()
1.138 matthew 14900:
14901: Facilitates the plotting of data in an XY graph with two Y axes.
14902: Puts plot definition data into the users environment in order for
14903: graph.png to plot it. Returns an <img> tag for the plot.
14904:
14905: Inputs:
14906:
14907: =over 4
14908:
14909: =item $Title: string, the title of the plot
14910:
14911: =item $xlabel: string, text describing the X-axis of the plot
14912:
14913: =item $ylabel: string, text describing the Y-axis of the plot
14914:
14915: =item $colors: Array ref containing the hex color codes for the data to be
14916: plotted in. If undefined, default values will be used.
14917:
14918: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14919:
14920: =item $Ydata1: The first data set
14921:
14922: =item $Min1: The minimum value of the left Y-axis
14923:
14924: =item $Max1: The maximum value of the left Y-axis
14925:
14926: =item $Ydata2: The second data set
14927:
14928: =item $Min2: The minimum value of the right Y-axis
14929:
14930: =item $Max2: The maximum value of the left Y-axis
14931:
14932: =item %Values: hash indicating or overriding any default values which are
14933: passed to graph.png.
14934: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14935:
14936: =back
14937:
14938: Returns:
14939:
14940: An <img> tag which references graph.png and the appropriate identifying
14941: information for the plot.
1.136 matthew 14942:
14943: =cut
14944:
14945: ############################################################
14946: ############################################################
1.137 matthew 14947: sub DrawXYYGraph {
14948: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14949: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14950: #
14951: # Create the identifier for the graph
14952: my $identifier = &get_cgi_id();
14953: my $id = 'cgi.'.$identifier;
14954: #
14955: $Title = '' if (! defined($Title));
14956: $xlabel = '' if (! defined($xlabel));
14957: $ylabel = '' if (! defined($ylabel));
14958: my %ValuesHash =
14959: (
1.369 www 14960: $id.'.title' => &escape($Title),
14961: $id.'.xlabel' => &escape($xlabel),
14962: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14963: $id.'.labels' => join(',',@$Xlabels),
14964: $id.'.PlotType' => 'XY',
14965: $id.'.NumSets' => 2,
1.137 matthew 14966: $id.'.two_axes' => 1,
14967: $id.'.y1_max_value' => $Max1,
14968: $id.'.y1_min_value' => $Min1,
14969: $id.'.y2_max_value' => $Max2,
14970: $id.'.y2_min_value' => $Min2,
1.136 matthew 14971: );
14972: #
1.137 matthew 14973: if (defined($colors) && ref($colors) eq 'ARRAY') {
14974: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14975: }
14976: #
14977: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14978: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14979: return '';
14980: }
14981: my $NumSets=1;
1.137 matthew 14982: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14983: next if (! ref($array));
14984: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14985: }
14986: #
14987: # Deal with other parameters
14988: while (my ($key,$value) = each(%Values)) {
14989: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14990: }
14991: #
1.646 raeburn 14992: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14993: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14994: }
14995:
14996: ############################################################
14997: ############################################################
14998:
14999: =pod
15000:
1.157 matthew 15001: =back
15002:
1.139 matthew 15003: =head1 Statistics helper routines?
15004:
15005: Bad place for them but what the hell.
15006:
1.157 matthew 15007: =over 4
15008:
1.648 raeburn 15009: =item * &chartlink()
1.139 matthew 15010:
15011: Returns a link to the chart for a specific student.
15012:
15013: Inputs:
15014:
15015: =over 4
15016:
15017: =item $linktext: The text of the link
15018:
15019: =item $sname: The students username
15020:
15021: =item $sdomain: The students domain
15022:
15023: =back
15024:
1.157 matthew 15025: =back
15026:
1.139 matthew 15027: =cut
15028:
15029: ############################################################
15030: ############################################################
15031: sub chartlink {
15032: my ($linktext, $sname, $sdomain) = @_;
15033: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 15034: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 15035: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 15036: '">'.$linktext.'</a>';
1.153 matthew 15037: }
15038:
15039: #######################################################
15040: #######################################################
15041:
15042: =pod
15043:
15044: =head1 Course Environment Routines
1.157 matthew 15045:
15046: =over 4
1.153 matthew 15047:
1.648 raeburn 15048: =item * &restore_course_settings()
1.153 matthew 15049:
1.648 raeburn 15050: =item * &store_course_settings()
1.153 matthew 15051:
15052: Restores/Store indicated form parameters from the course environment.
15053: Will not overwrite existing values of the form parameters.
15054:
15055: Inputs:
15056: a scalar describing the data (e.g. 'chart', 'problem_analysis')
15057:
15058: a hash ref describing the data to be stored. For example:
15059:
15060: %Save_Parameters = ('Status' => 'scalar',
15061: 'chartoutputmode' => 'scalar',
15062: 'chartoutputdata' => 'scalar',
15063: 'Section' => 'array',
1.373 raeburn 15064: 'Group' => 'array',
1.153 matthew 15065: 'StudentData' => 'array',
15066: 'Maps' => 'array');
15067:
15068: Returns: both routines return nothing
15069:
1.631 raeburn 15070: =back
15071:
1.153 matthew 15072: =cut
15073:
15074: #######################################################
15075: #######################################################
15076: sub store_course_settings {
1.496 albertel 15077: return &store_settings($env{'request.course.id'},@_);
15078: }
15079:
15080: sub store_settings {
1.153 matthew 15081: # save to the environment
15082: # appenv the same items, just to be safe
1.300 albertel 15083: my $udom = $env{'user.domain'};
15084: my $uname = $env{'user.name'};
1.496 albertel 15085: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15086: my %SaveHash;
15087: my %AppHash;
15088: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 15089: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 15090: my $envname = 'environment.'.$basename;
1.258 albertel 15091: if (exists($env{'form.'.$setting})) {
1.153 matthew 15092: # Save this value away
15093: if ($type eq 'scalar' &&
1.258 albertel 15094: (! exists($env{$envname}) ||
15095: $env{$envname} ne $env{'form.'.$setting})) {
15096: $SaveHash{$basename} = $env{'form.'.$setting};
15097: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 15098: } elsif ($type eq 'array') {
15099: my $stored_form;
1.258 albertel 15100: if (ref($env{'form.'.$setting})) {
1.153 matthew 15101: $stored_form = join(',',
15102: map {
1.369 www 15103: &escape($_);
1.258 albertel 15104: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 15105: } else {
15106: $stored_form =
1.369 www 15107: &escape($env{'form.'.$setting});
1.153 matthew 15108: }
15109: # Determine if the array contents are the same.
1.258 albertel 15110: if ($stored_form ne $env{$envname}) {
1.153 matthew 15111: $SaveHash{$basename} = $stored_form;
15112: $AppHash{$envname} = $stored_form;
15113: }
15114: }
15115: }
15116: }
15117: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 15118: $udom,$uname);
1.153 matthew 15119: if ($put_result !~ /^(ok|delayed)/) {
15120: &Apache::lonnet::logthis('unable to save form parameters, '.
15121: 'got error:'.$put_result);
15122: }
15123: # Make sure these settings stick around in this session, too
1.646 raeburn 15124: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 15125: return;
15126: }
15127:
15128: sub restore_course_settings {
1.499 albertel 15129: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 15130: }
15131:
15132: sub restore_settings {
15133: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15134: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 15135: next if (exists($env{'form.'.$setting}));
1.496 albertel 15136: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 15137: '.'.$setting;
1.258 albertel 15138: if (exists($env{$envname})) {
1.153 matthew 15139: if ($type eq 'scalar') {
1.258 albertel 15140: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 15141: } elsif ($type eq 'array') {
1.258 albertel 15142: $env{'form.'.$setting} = [
1.153 matthew 15143: map {
1.369 www 15144: &unescape($_);
1.258 albertel 15145: } split(',',$env{$envname})
1.153 matthew 15146: ];
15147: }
15148: }
15149: }
1.127 matthew 15150: }
15151:
1.618 raeburn 15152: #######################################################
15153: #######################################################
15154:
15155: =pod
15156:
15157: =head1 Domain E-mail Routines
15158:
15159: =over 4
15160:
1.648 raeburn 15161: =item * &build_recipient_list()
1.618 raeburn 15162:
1.1075.2.44 raeburn 15163: Build recipient lists for following types of e-mail:
1.766 raeburn 15164: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 15165: (d) Help requests, (e) Course requests needing approval, (f) loncapa
15166: module change checking, student/employee ID conflict checks, as
15167: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
15168: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 15169:
15170: Inputs:
1.1075.2.44 raeburn 15171: defmail (scalar - email address of default recipient),
15172: mailing type (scalar: errormail, packagesmail, helpdeskmail,
15173: requestsmail, updatesmail, or idconflictsmail).
15174:
1.619 raeburn 15175: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 15176:
15177: origmail (scalar - email address of recipient from loncapa.conf,
15178: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 15179:
1.1075.2.139 raeburn 15180: $requname username of requester (if mailing type is helpdeskmail)
15181:
15182: $requdom domain of requester (if mailing type is helpdeskmail)
15183:
15184: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
15185:
1.655 raeburn 15186: Returns: comma separated list of addresses to which to send e-mail.
15187:
15188: =back
1.618 raeburn 15189:
15190: =cut
15191:
15192: ############################################################
15193: ############################################################
15194: sub build_recipient_list {
1.1075.2.139 raeburn 15195: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 15196: my @recipients;
1.1075.2.122 raeburn 15197: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 15198: my %domconfig =
1.1075.2.122 raeburn 15199: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 15200: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 15201: if (exists($domconfig{'contacts'}{$mailing})) {
15202: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
15203: my @contacts = ('adminemail','supportemail');
15204: foreach my $item (@contacts) {
15205: if ($domconfig{'contacts'}{$mailing}{$item}) {
15206: my $addr = $domconfig{'contacts'}{$item};
15207: if (!grep(/^\Q$addr\E$/,@recipients)) {
15208: push(@recipients,$addr);
15209: }
1.619 raeburn 15210: }
1.1075.2.122 raeburn 15211: }
15212: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
15213: if ($mailing eq 'helpdeskmail') {
15214: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
15215: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
15216: my @ok_bccs;
15217: foreach my $bcc (@bccs) {
15218: $bcc =~ s/^\s+//g;
15219: $bcc =~ s/\s+$//g;
15220: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15221: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15222: push(@ok_bccs,$bcc);
15223: }
15224: }
15225: }
15226: if (@ok_bccs > 0) {
15227: $allbcc = join(', ',@ok_bccs);
15228: }
15229: }
15230: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 15231: }
15232: }
1.766 raeburn 15233: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 15234: $lastresort = $origmail;
1.618 raeburn 15235: }
1.1075.2.139 raeburn 15236: if ($mailing eq 'helpdeskmail') {
15237: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
15238: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
15239: my ($inststatus,$inststatus_checked);
15240: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
15241: ($env{'user.domain'} ne 'public')) {
15242: $inststatus_checked = 1;
15243: $inststatus = $env{'environment.inststatus'};
15244: }
15245: unless ($inststatus_checked) {
15246: if (($requname ne '') && ($requdom ne '')) {
15247: if (($requname =~ /^$match_username$/) &&
15248: ($requdom =~ /^$match_domain$/) &&
15249: (&Apache::lonnet::domain($requdom))) {
15250: my $requhome = &Apache::lonnet::homeserver($requname,
15251: $requdom);
15252: unless ($requhome eq 'no_host') {
15253: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
15254: $inststatus = $userenv{'inststatus'};
15255: $inststatus_checked = 1;
15256: }
15257: }
15258: }
15259: }
15260: unless ($inststatus_checked) {
15261: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15262: my %srch = (srchby => 'email',
15263: srchdomain => $defdom,
15264: srchterm => $reqemail,
15265: srchtype => 'exact');
15266: my %srch_results = &Apache::lonnet::usersearch(\%srch);
15267: foreach my $uname (keys(%srch_results)) {
15268: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15269: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15270: $inststatus_checked = 1;
15271: last;
15272: }
15273: }
15274: unless ($inststatus_checked) {
15275: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15276: if ($dirsrchres eq 'ok') {
15277: foreach my $uname (keys(%srch_results)) {
15278: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15279: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15280: $inststatus_checked = 1;
15281: last;
15282: }
15283: }
15284: }
15285: }
15286: }
15287: }
15288: if ($inststatus ne '') {
15289: foreach my $status (split(/\:/,$inststatus)) {
15290: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15291: my @contacts = ('adminemail','supportemail');
15292: foreach my $item (@contacts) {
15293: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15294: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15295: if (!grep(/^\Q$addr\E$/,@recipients)) {
15296: push(@recipients,$addr);
15297: }
15298: }
15299: }
15300: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15301: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15302: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15303: my @ok_bccs;
15304: foreach my $bcc (@bccs) {
15305: $bcc =~ s/^\s+//g;
15306: $bcc =~ s/\s+$//g;
15307: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15308: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15309: push(@ok_bccs,$bcc);
15310: }
15311: }
15312: }
15313: if (@ok_bccs > 0) {
15314: $allbcc = join(', ',@ok_bccs);
15315: }
15316: }
15317: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15318: last;
15319: }
15320: }
15321: }
15322: }
15323: }
1.619 raeburn 15324: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 15325: $lastresort = $origmail;
15326: }
1.1075.2.128 raeburn 15327: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 15328: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15329: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15330: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15331: my %what = (
15332: perlvar => 1,
15333: );
15334: my $primary = &Apache::lonnet::domain($defdom,'primary');
15335: if ($primary) {
15336: my $gotaddr;
15337: my ($result,$returnhash) =
15338: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15339: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15340: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15341: $lastresort = $returnhash->{'lonSupportEMail'};
15342: $gotaddr = 1;
15343: }
15344: }
15345: unless ($gotaddr) {
15346: my $uintdom = &Apache::lonnet::internet_dom($primary);
15347: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15348: unless ($uintdom eq $intdom) {
15349: my %domconfig =
15350: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15351: if (ref($domconfig{'contacts'}) eq 'HASH') {
15352: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15353: my @contacts = ('adminemail','supportemail');
15354: foreach my $item (@contacts) {
15355: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15356: my $addr = $domconfig{'contacts'}{$item};
15357: if (!grep(/^\Q$addr\E$/,@recipients)) {
15358: push(@recipients,$addr);
15359: }
15360: }
15361: }
15362: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15363: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15364: }
15365: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15366: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15367: my @ok_bccs;
15368: foreach my $bcc (@bccs) {
15369: $bcc =~ s/^\s+//g;
15370: $bcc =~ s/\s+$//g;
15371: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15372: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15373: push(@ok_bccs,$bcc);
15374: }
15375: }
15376: }
15377: if (@ok_bccs > 0) {
15378: $allbcc = join(', ',@ok_bccs);
15379: }
15380: }
15381: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15382: }
15383: }
15384: }
15385: }
15386: }
15387: }
1.618 raeburn 15388: }
1.688 raeburn 15389: if (defined($defmail)) {
15390: if ($defmail ne '') {
15391: push(@recipients,$defmail);
15392: }
1.618 raeburn 15393: }
15394: if ($otheremails) {
1.619 raeburn 15395: my @others;
15396: if ($otheremails =~ /,/) {
15397: @others = split(/,/,$otheremails);
1.618 raeburn 15398: } else {
1.619 raeburn 15399: push(@others,$otheremails);
15400: }
15401: foreach my $addr (@others) {
15402: if (!grep(/^\Q$addr\E$/,@recipients)) {
15403: push(@recipients,$addr);
15404: }
1.618 raeburn 15405: }
15406: }
1.1075.2.128 raeburn 15407: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 15408: if ((!@recipients) && ($lastresort ne '')) {
15409: push(@recipients,$lastresort);
15410: }
15411: } elsif ($lastresort ne '') {
15412: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15413: push(@recipients,$lastresort);
15414: }
15415: }
15416: my $recipientlist = join(',',@recipients);
15417: if (wantarray) {
15418: return ($recipientlist,$allbcc,$addtext);
15419: } else {
15420: return $recipientlist;
15421: }
1.618 raeburn 15422: }
15423:
1.127 matthew 15424: ############################################################
15425: ############################################################
1.154 albertel 15426:
1.655 raeburn 15427: =pod
15428:
15429: =head1 Course Catalog Routines
15430:
15431: =over 4
15432:
15433: =item * &gather_categories()
15434:
15435: Converts category definitions - keys of categories hash stored in
15436: coursecategories in configuration.db on the primary library server in a
15437: domain - to an array. Also generates javascript and idx hash used to
15438: generate Domain Coordinator interface for editing Course Categories.
15439:
15440: Inputs:
1.663 raeburn 15441:
1.655 raeburn 15442: categories (reference to hash of category definitions).
1.663 raeburn 15443:
1.655 raeburn 15444: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15445: categories and subcategories).
1.663 raeburn 15446:
1.655 raeburn 15447: idx (reference to hash of counters used in Domain Coordinator interface for
15448: editing Course Categories).
1.663 raeburn 15449:
1.655 raeburn 15450: jsarray (reference to array of categories used to create Javascript arrays for
15451: Domain Coordinator interface for editing Course Categories).
15452:
15453: Returns: nothing
15454:
15455: Side effects: populates cats, idx and jsarray.
15456:
15457: =cut
15458:
15459: sub gather_categories {
15460: my ($categories,$cats,$idx,$jsarray) = @_;
15461: my %counters;
15462: my $num = 0;
15463: foreach my $item (keys(%{$categories})) {
15464: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15465: if ($container eq '' && $depth == 0) {
15466: $cats->[$depth][$categories->{$item}] = $cat;
15467: } else {
15468: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15469: }
15470: my ($escitem,$tail) = split(/:/,$item,2);
15471: if ($counters{$tail} eq '') {
15472: $counters{$tail} = $num;
15473: $num ++;
15474: }
15475: if (ref($idx) eq 'HASH') {
15476: $idx->{$item} = $counters{$tail};
15477: }
15478: if (ref($jsarray) eq 'ARRAY') {
15479: push(@{$jsarray->[$counters{$tail}]},$item);
15480: }
15481: }
15482: return;
15483: }
15484:
15485: =pod
15486:
15487: =item * &extract_categories()
15488:
15489: Used to generate breadcrumb trails for course categories.
15490:
15491: Inputs:
1.663 raeburn 15492:
1.655 raeburn 15493: categories (reference to hash of category definitions).
1.663 raeburn 15494:
1.655 raeburn 15495: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15496: categories and subcategories).
1.663 raeburn 15497:
1.655 raeburn 15498: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15499:
1.655 raeburn 15500: allitems (reference to hash - key is category key
15501: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15502:
1.655 raeburn 15503: idx (reference to hash of counters used in Domain Coordinator interface for
15504: editing Course Categories).
1.663 raeburn 15505:
1.655 raeburn 15506: jsarray (reference to array of categories used to create Javascript arrays for
15507: Domain Coordinator interface for editing Course Categories).
15508:
1.665 raeburn 15509: subcats (reference to hash of arrays containing all subcategories within each
15510: category, -recursive)
15511:
1.1075.2.132 raeburn 15512: maxd (reference to hash used to hold max depth for all top-level categories).
15513:
1.655 raeburn 15514: Returns: nothing
15515:
15516: Side effects: populates trails and allitems hash references.
15517:
15518: =cut
15519:
15520: sub extract_categories {
1.1075.2.132 raeburn 15521: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 15522: if (ref($categories) eq 'HASH') {
15523: &gather_categories($categories,$cats,$idx,$jsarray);
15524: if (ref($cats->[0]) eq 'ARRAY') {
15525: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15526: my $name = $cats->[0][$i];
15527: my $item = &escape($name).'::0';
15528: my $trailstr;
15529: if ($name eq 'instcode') {
15530: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15531: } elsif ($name eq 'communities') {
15532: $trailstr = &mt('Communities');
1.655 raeburn 15533: } else {
15534: $trailstr = $name;
15535: }
15536: if ($allitems->{$item} eq '') {
15537: push(@{$trails},$trailstr);
15538: $allitems->{$item} = scalar(@{$trails})-1;
15539: }
15540: my @parents = ($name);
15541: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15542: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15543: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15544: if (ref($subcats) eq 'HASH') {
15545: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15546: }
1.1075.2.132 raeburn 15547: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 15548: }
15549: } else {
15550: if (ref($subcats) eq 'HASH') {
15551: $subcats->{$item} = [];
1.655 raeburn 15552: }
1.1075.2.132 raeburn 15553: if (ref($maxd) eq 'HASH') {
15554: $maxd->{$name} = 1;
15555: }
1.655 raeburn 15556: }
15557: }
15558: }
15559: }
15560: return;
15561: }
15562:
15563: =pod
15564:
1.1075.2.56 raeburn 15565: =item * &recurse_categories()
1.655 raeburn 15566:
15567: Recursively used to generate breadcrumb trails for course categories.
15568:
15569: Inputs:
1.663 raeburn 15570:
1.655 raeburn 15571: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15572: categories and subcategories).
1.663 raeburn 15573:
1.655 raeburn 15574: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15575:
15576: category (current course category, for which breadcrumb trail is being generated).
15577:
15578: trails (reference to array of breadcrumb trails for each category).
15579:
1.655 raeburn 15580: allitems (reference to hash - key is category key
15581: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15582:
1.655 raeburn 15583: parents (array containing containers directories for current category,
15584: back to top level).
15585:
15586: Returns: nothing
15587:
15588: Side effects: populates trails and allitems hash references
15589:
15590: =cut
15591:
15592: sub recurse_categories {
1.1075.2.132 raeburn 15593: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 15594: my $shallower = $depth - 1;
15595: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
15596: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
15597: my $name = $cats->[$depth]{$category}[$k];
15598: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.161. .4(raebu 15599:22): my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15600: if ($allitems->{$item} eq '') {
15601: push(@{$trails},$trailstr);
15602: $allitems->{$item} = scalar(@{$trails})-1;
15603: }
15604: my $deeper = $depth+1;
15605: push(@{$parents},$category);
1.665 raeburn 15606: if (ref($subcats) eq 'HASH') {
15607: my $subcat = &escape($name).':'.$category.':'.$depth;
15608: for (my $j=@{$parents}; $j>=0; $j--) {
15609: my $higher;
15610: if ($j > 0) {
15611: $higher = &escape($parents->[$j]).':'.
15612: &escape($parents->[$j-1]).':'.$j;
15613: } else {
15614: $higher = &escape($parents->[$j]).'::'.$j;
15615: }
15616: push(@{$subcats->{$higher}},$subcat);
15617: }
15618: }
15619: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 15620: $subcats,$maxd);
1.655 raeburn 15621: pop(@{$parents});
15622: }
15623: } else {
15624: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 15625: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15626: if ($allitems->{$item} eq '') {
15627: push(@{$trails},$trailstr);
15628: $allitems->{$item} = scalar(@{$trails})-1;
15629: }
1.1075.2.132 raeburn 15630: if (ref($maxd) eq 'HASH') {
15631: if ($depth > $maxd->{$parents->[0]}) {
15632: $maxd->{$parents->[0]} = $depth;
15633: }
15634: }
1.655 raeburn 15635: }
15636: return;
15637: }
15638:
1.663 raeburn 15639: =pod
15640:
1.1075.2.56 raeburn 15641: =item * &assign_categories_table()
1.663 raeburn 15642:
15643: Create a datatable for display of hierarchical categories in a domain,
15644: with checkboxes to allow a course to be categorized.
15645:
15646: Inputs:
15647:
15648: cathash - reference to hash of categories defined for the domain (from
15649: configuration.db)
15650:
15651: currcat - scalar with an & separated list of categories assigned to a course.
15652:
1.919 raeburn 15653: type - scalar contains course type (Course or Community).
15654:
1.1075.2.117 raeburn 15655: disabled - scalar (optional) contains disabled="disabled" if input elements are
15656: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15657:
1.663 raeburn 15658: Returns: $output (markup to be displayed)
15659:
15660: =cut
15661:
15662: sub assign_categories_table {
1.1075.2.117 raeburn 15663: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15664: my $output;
15665: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 15666: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
15667: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 15668: $maxdepth = scalar(@cats);
15669: if (@cats > 0) {
15670: my $itemcount = 0;
15671: if (ref($cats[0]) eq 'ARRAY') {
15672: my @currcategories;
15673: if ($currcat ne '') {
15674: @currcategories = split('&',$currcat);
15675: }
1.919 raeburn 15676: my $table;
1.663 raeburn 15677: for (my $i=0; $i<@{$cats[0]}; $i++) {
15678: my $parent = $cats[0][$i];
1.919 raeburn 15679: next if ($parent eq 'instcode');
15680: if ($type eq 'Community') {
15681: next unless ($parent eq 'communities');
15682: } else {
15683: next if ($parent eq 'communities');
15684: }
1.663 raeburn 15685: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15686: my $item = &escape($parent).'::0';
15687: my $checked = '';
15688: if (@currcategories > 0) {
15689: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15690: $checked = ' checked="checked"';
1.663 raeburn 15691: }
15692: }
1.919 raeburn 15693: my $parent_title = $parent;
15694: if ($parent eq 'communities') {
15695: $parent_title = &mt('Communities');
15696: }
15697: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15698: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 15699: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15700: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15701: my $depth = 1;
15702: push(@path,$parent);
1.1075.2.117 raeburn 15703: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15704: pop(@path);
1.919 raeburn 15705: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15706: $itemcount ++;
15707: }
1.919 raeburn 15708: if ($itemcount) {
15709: $output = &Apache::loncommon::start_data_table().
15710: $table.
15711: &Apache::loncommon::end_data_table();
15712: }
1.663 raeburn 15713: }
15714: }
15715: }
15716: return $output;
15717: }
15718:
15719: =pod
15720:
1.1075.2.56 raeburn 15721: =item * &assign_category_rows()
1.663 raeburn 15722:
15723: Create a datatable row for display of nested categories in a domain,
15724: with checkboxes to allow a course to be categorized,called recursively.
15725:
15726: Inputs:
15727:
15728: itemcount - track row number for alternating colors
15729:
15730: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15731: categories and subcategories.
15732:
15733: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15734:
15735: parent - parent of current category item
15736:
15737: path - Array containing all categories back up through the hierarchy from the
15738: current category to the top level.
15739:
15740: currcategories - reference to array of current categories assigned to the course
15741:
1.1075.2.117 raeburn 15742: disabled - scalar (optional) contains disabled="disabled" if input elements are
15743: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15744:
1.663 raeburn 15745: Returns: $output (markup to be displayed).
15746:
15747: =cut
15748:
15749: sub assign_category_rows {
1.1075.2.117 raeburn 15750: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15751: my ($text,$name,$item,$chgstr);
15752: if (ref($cats) eq 'ARRAY') {
15753: my $maxdepth = scalar(@{$cats});
15754: if (ref($cats->[$depth]) eq 'HASH') {
15755: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15756: my $numchildren = @{$cats->[$depth]{$parent}};
15757: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 15758: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15759: for (my $j=0; $j<$numchildren; $j++) {
15760: $name = $cats->[$depth]{$parent}[$j];
15761: $item = &escape($name).':'.&escape($parent).':'.$depth;
15762: my $deeper = $depth+1;
15763: my $checked = '';
15764: if (ref($currcategories) eq 'ARRAY') {
15765: if (@{$currcategories} > 0) {
15766: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15767: $checked = ' checked="checked"';
1.663 raeburn 15768: }
15769: }
15770: }
1.664 raeburn 15771: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15772: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 15773: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15774: '<input type="hidden" name="catname" value="'.$name.'" />'.
15775: '</td><td>';
1.663 raeburn 15776: if (ref($path) eq 'ARRAY') {
15777: push(@{$path},$name);
1.1075.2.117 raeburn 15778: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15779: pop(@{$path});
15780: }
15781: $text .= '</td></tr>';
15782: }
15783: $text .= '</table></td>';
15784: }
15785: }
15786: }
15787: return $text;
15788: }
15789:
1.1075.2.69 raeburn 15790: =pod
15791:
15792: =back
15793:
15794: =cut
15795:
1.655 raeburn 15796: ############################################################
15797: ############################################################
15798:
15799:
1.443 albertel 15800: sub commit_customrole {
1.664 raeburn 15801: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15802: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15803: ($start?', '.&mt('starting').' '.localtime($start):'').
15804: ($end?', ending '.localtime($end):'').': <b>'.
15805: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15806: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15807: '</b><br />';
15808: return $output;
15809: }
15810:
15811: sub commit_standardrole {
1.1075.2.31 raeburn 15812: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15813: my ($output,$logmsg,$linefeed);
15814: if ($context eq 'auto') {
15815: $linefeed = "\n";
15816: } else {
15817: $linefeed = "<br />\n";
15818: }
1.443 albertel 15819: if ($three eq 'st') {
1.541 raeburn 15820: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 15821: $one,$two,$sec,$context,$credits);
1.541 raeburn 15822: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15823: ($result eq 'unknown_course') || ($result eq 'refused')) {
15824: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15825: } else {
1.541 raeburn 15826: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15827: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15828: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15829: if ($context eq 'auto') {
15830: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15831: } else {
15832: $output .= '<b>'.$result.'</b>'.$linefeed.
15833: &mt('Add to classlist').': <b>ok</b>';
15834: }
15835: $output .= $linefeed;
1.443 albertel 15836: }
15837: } else {
15838: $output = &mt('Assigning').' '.$three.' in '.$url.
15839: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15840: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15841: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15842: if ($context eq 'auto') {
15843: $output .= $result.$linefeed;
15844: } else {
15845: $output .= '<b>'.$result.'</b>'.$linefeed;
15846: }
1.443 albertel 15847: }
15848: return $output;
15849: }
15850:
15851: sub commit_studentrole {
1.1075.2.31 raeburn 15852: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15853: $credits) = @_;
1.626 raeburn 15854: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15855: if ($context eq 'auto') {
15856: $linefeed = "\n";
15857: } else {
15858: $linefeed = '<br />'."\n";
15859: }
1.443 albertel 15860: if (defined($one) && defined($two)) {
15861: my $cid=$one.'_'.$two;
15862: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15863: my $secchange = 0;
15864: my $expire_role_result;
15865: my $modify_section_result;
1.628 raeburn 15866: if ($oldsec ne '-1') {
15867: if ($oldsec ne $sec) {
1.443 albertel 15868: $secchange = 1;
1.628 raeburn 15869: my $now = time;
1.443 albertel 15870: my $uurl='/'.$cid;
15871: $uurl=~s/\_/\//g;
15872: if ($oldsec) {
15873: $uurl.='/'.$oldsec;
15874: }
1.626 raeburn 15875: $oldsecurl = $uurl;
1.628 raeburn 15876: $expire_role_result =
1.1075.2.161. .14(raeb 15877:-23): &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','','',$context);
1.628 raeburn 15878: if ($env{'request.course.sec'} ne '') {
15879: if ($expire_role_result eq 'refused') {
15880: my @roles = ('st');
15881: my @statuses = ('previous');
15882: my @roledoms = ($one);
15883: my $withsec = 1;
15884: my %roleshash =
15885: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15886: \@statuses,\@roles,\@roledoms,$withsec);
15887: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15888: my ($oldstart,$oldend) =
15889: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15890: if ($oldend > 0 && $oldend <= $now) {
15891: $expire_role_result = 'ok';
15892: }
15893: }
15894: }
15895: }
1.443 albertel 15896: $result = $expire_role_result;
15897: }
15898: }
15899: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 15900: $modify_section_result =
15901: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15902: undef,undef,undef,$sec,
15903: $end,$start,'','',$cid,
15904: '',$context,$credits);
1.443 albertel 15905: if ($modify_section_result =~ /^ok/) {
15906: if ($secchange == 1) {
1.628 raeburn 15907: if ($sec eq '') {
15908: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15909: } else {
15910: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15911: }
1.443 albertel 15912: } elsif ($oldsec eq '-1') {
1.628 raeburn 15913: if ($sec eq '') {
15914: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15915: } else {
15916: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15917: }
1.443 albertel 15918: } else {
1.628 raeburn 15919: if ($sec eq '') {
15920: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15921: } else {
15922: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15923: }
1.443 albertel 15924: }
15925: } else {
1.628 raeburn 15926: if ($secchange) {
15927: $$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;
15928: } else {
15929: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15930: }
1.443 albertel 15931: }
15932: $result = $modify_section_result;
15933: } elsif ($secchange == 1) {
1.628 raeburn 15934: if ($oldsec eq '') {
1.1075.2.20 raeburn 15935: $$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 15936: } else {
15937: $$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;
15938: }
1.626 raeburn 15939: if ($expire_role_result eq 'refused') {
15940: my $newsecurl = '/'.$cid;
15941: $newsecurl =~ s/\_/\//g;
15942: if ($sec ne '') {
15943: $newsecurl.='/'.$sec;
15944: }
15945: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15946: if ($sec eq '') {
15947: $$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;
15948: } else {
15949: $$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;
15950: }
15951: }
15952: }
1.443 albertel 15953: }
15954: } else {
1.626 raeburn 15955: $$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 15956: $result = "error: incomplete course id\n";
15957: }
15958: return $result;
15959: }
15960:
1.1075.2.25 raeburn 15961: sub show_role_extent {
15962: my ($scope,$context,$role) = @_;
15963: $scope =~ s{^/}{};
15964: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15965: push(@courseroles,'co');
15966: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15967: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15968: $scope =~ s{/}{_};
15969: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15970: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15971: my ($audom,$auname) = split(/\//,$scope);
15972: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15973: &Apache::loncommon::plainname($auname,$audom).'</span>');
15974: } else {
15975: $scope =~ s{/$}{};
15976: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15977: &Apache::lonnet::domain($scope,'description').'</span>');
15978: }
15979: }
15980:
1.443 albertel 15981: ############################################################
15982: ############################################################
15983:
1.566 albertel 15984: sub check_clone {
1.578 raeburn 15985: my ($args,$linefeed) = @_;
1.566 albertel 15986: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15987: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15988: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1075.2.161. .1(raebu 15989:21): my $clonetitle;
15990:21): my @clonemsg;
1.566 albertel 15991: my $can_clone = 0;
1.944 raeburn 15992: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15993: if ($lctype ne 'community') {
15994: $lctype = 'course';
15995: }
1.566 albertel 15996: if ($clonehome eq 'no_host') {
1.944 raeburn 15997: if ($args->{'crstype'} eq 'Community') {
1.1075.2.161. .1(raebu 15998:21): push(@clonemsg,({
15999:21): mt => 'No new community created.',
16000:21): args => [],
16001:21): },
16002:21): {
16003:21): mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
16004:21): args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
16005:21): }));
1.908 raeburn 16006: } else {
1.1075.2.161. .1(raebu 16007:21): push(@clonemsg,({
16008:21): mt => 'No new course created.',
16009:21): args => [],
16010:21): },
16011:21): {
16012:21): mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
16013:21): args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16014:21): }));
16015:21): }
1.566 albertel 16016: } else {
16017: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1075.2.161. .1(raebu 16018:21): $clonetitle = $clonedesc{'description'};
1.944 raeburn 16019: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 16020: if ($clonedesc{'type'} ne 'Community') {
1.1075.2.161. .1(raebu 16021:21): push(@clonemsg,({
16022:21): mt => 'No new community created.',
16023:21): args => [],
16024:21): },
16025:21): {
16026:21): mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
16027:21): args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16028:21): }));
16029:21): return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 16030: }
16031: }
1.1075.2.119 raeburn 16032: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 16033: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 16034: $can_clone = 1;
16035: } else {
1.1075.2.95 raeburn 16036: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 16037: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 16038: if ($clonehash{'cloners'} eq '') {
16039: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
16040: if ($domdefs{'canclone'}) {
16041: unless ($domdefs{'canclone'} eq 'none') {
16042: if ($domdefs{'canclone'} eq 'domain') {
16043: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
16044: $can_clone = 1;
16045: }
16046: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16047: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
16048: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
16049: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
16050: $can_clone = 1;
16051: }
16052: }
16053: }
1.908 raeburn 16054: }
1.1075.2.95 raeburn 16055: } else {
16056: my @cloners = split(/,/,$clonehash{'cloners'});
16057: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 16058: $can_clone = 1;
1.1075.2.95 raeburn 16059: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 16060: $can_clone = 1;
1.1075.2.96 raeburn 16061: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
16062: $can_clone = 1;
1.1075.2.95 raeburn 16063: }
16064: unless ($can_clone) {
1.1075.2.96 raeburn 16065: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16066: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 16067: my (%gotdomdefaults,%gotcodedefaults);
16068: foreach my $cloner (@cloners) {
16069: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
16070: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
16071: my (%codedefaults,@code_order);
16072: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
16073: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
16074: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
16075: }
16076: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
16077: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
16078: }
16079: } else {
16080: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
16081: \%codedefaults,
16082: \@code_order);
16083: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
16084: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
16085: }
16086: if (@code_order > 0) {
16087: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
16088: $cloner,$clonehash{'internal.coursecode'},
16089: $args->{'crscode'})) {
16090: $can_clone = 1;
16091: last;
16092: }
16093: }
16094: }
16095: }
16096: }
1.1075.2.96 raeburn 16097: }
16098: }
16099: unless ($can_clone) {
16100: my $ccrole = 'cc';
16101: if ($args->{'crstype'} eq 'Community') {
16102: $ccrole = 'co';
16103: }
16104: my %roleshash =
16105: &Apache::lonnet::get_my_roles($args->{'ccuname'},
16106: $args->{'ccdomain'},
16107: 'userroles',['active'],[$ccrole],
16108: [$args->{'clonedomain'}]);
16109: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
16110: $can_clone = 1;
16111: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
16112: $args->{'ccuname'},$args->{'ccdomain'})) {
16113: $can_clone = 1;
1.1075.2.95 raeburn 16114: }
16115: }
16116: unless ($can_clone) {
16117: if ($args->{'crstype'} eq 'Community') {
1.1075.2.161. .1(raebu 16118:21): push(@clonemsg,({
16119:21): mt => 'No new community created.',
16120:21): args => [],
16121:21): },
16122:21): {
16123:21): 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]).',
16124:21): args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16125:21): }));
1.1075.2.95 raeburn 16126: } else {
1.1075.2.161. .1(raebu 16127:21): push(@clonemsg,({
16128:21): mt => 'No new course created.',
16129:21): args => [],
16130:21): },
16131:21): {
16132:21): 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]).',
16133:21): args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16134:21): }));
1.578 raeburn 16135: }
1.566 albertel 16136: }
1.578 raeburn 16137: }
1.566 albertel 16138: }
1.1075.2.161. .1(raebu 16139:21): return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16140: }
16141:
1.444 albertel 16142: sub construct_course {
1.1075.2.119 raeburn 16143: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1075.2.161. .1(raebu 16144:21): $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
16145:21): my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 16146: my $linefeed = '<br />'."\n";
16147: if ($context eq 'auto') {
16148: $linefeed = "\n";
16149: }
1.566 albertel 16150:
16151: #
16152: # Are we cloning?
16153: #
1.1075.2.161. .1(raebu 16154:21): my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16155: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1075.2.161. .1(raebu 16156:21): ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 16157: if (!$can_clone) {
1.1075.2.161. .1(raebu 16158:21): return (0,$outcome,$clonemsgref);
1.566 albertel 16159: }
16160: }
16161:
1.444 albertel 16162: #
16163: # Open course
16164: #
16165: my $crstype = lc($args->{'crstype'});
16166: my %cenv=();
16167: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
16168: $args->{'cdescr'},
16169: $args->{'curl'},
16170: $args->{'course_home'},
16171: $args->{'nonstandard'},
16172: $args->{'crscode'},
16173: $args->{'ccuname'}.':'.
16174: $args->{'ccdomain'},
1.882 raeburn 16175: $args->{'crstype'},
1.1075.2.161. .1(raebu 16176:21): $cnum,$context,$category,
16177:21): $callercontext);
1.444 albertel 16178:
16179: # Note: The testing routines depend on this being output; see
16180: # Utils::Course. This needs to at least be output as a comment
16181: # if anyone ever decides to not show this, and Utils::Course::new
16182: # will need to be suitably modified.
1.1075.2.161. .1(raebu 16183:21): if (($callercontext eq 'auto') && ($user_lh ne '')) {
16184:21): $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
16185:21): } else {
16186:21): $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
16187:21): }
1.943 raeburn 16188: if ($$courseid =~ /^error:/) {
1.1075.2.161. .1(raebu 16189:21): return (0,$outcome,$clonemsgref);
1.943 raeburn 16190: }
16191:
1.444 albertel 16192: #
16193: # Check if created correctly
16194: #
1.479 albertel 16195: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 16196: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 16197: if ($crsuhome eq 'no_host') {
1.1075.2.161. .1(raebu 16198:21): if (($callercontext eq 'auto') && ($user_lh ne '')) {
16199:21): $outcome .= &mt_user($user_lh,
16200:21): 'Course creation failed, unrecognized course home server.');
16201:21): } else {
16202:21): $outcome .= &mt('Course creation failed, unrecognized course home server.');
16203:21): }
16204:21): $outcome .= $linefeed;
16205:21): return (0,$outcome,$clonemsgref);
1.943 raeburn 16206: }
1.541 raeburn 16207: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 16208:
1.444 albertel 16209: #
1.566 albertel 16210: # Do the cloning
1.1075.2.161. .1(raebu 16211:21): #
16212:21): my @clonemsg;
1.566 albertel 16213: if ($can_clone && $cloneid) {
1.1075.2.161. .1(raebu 16214:21): push(@clonemsg,
16215:21): {
16216:21): mt => 'Created [_1] by cloning from [_2]',
16217:21): args => [$crstype,$clonetitle],
16218:21): });
1.566 albertel 16219: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 16220: # Copy all files
1.1075.2.161. .1(raebu 16221:21): my @info =
16222:21): &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
16223:21): $args->{'dateshift'},$args->{'crscode'},
16224:21): $args->{'ccuname'}.':'.$args->{'ccdomain'},
16225:21): $args->{'tinyurls'});
16226:21): if (@info) {
16227:21): push(@clonemsg,@info);
16228:21): }
1.444 albertel 16229: # Restore URL
1.566 albertel 16230: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16231: # Restore title
1.566 albertel 16232: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16233: # Restore creation date, creator and creation context.
16234: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16235: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16236: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16237: # Mark as cloned
1.566 albertel 16238: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16239: # Need to clone grading mode
16240: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16241: $cenv{'grading'}=$newenv{'grading'};
16242: # Do not clone these environment entries
16243: &Apache::lonnet::del('environment',
16244: ['default_enrollment_start_date',
16245: 'default_enrollment_end_date',
16246: 'question.email',
16247: 'policy.email',
16248: 'comment.email',
16249: 'pch.users.denied',
1.725 raeburn 16250: 'plc.users.denied',
16251: 'hidefromcat',
1.1075.2.36 raeburn 16252: 'checkforpriv',
1.1075.2.158 raeburn 16253: 'categories'],
1.638 www 16254: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 16255: if ($args->{'textbook'}) {
16256: $cenv{'internal.textbook'} = $args->{'textbook'};
16257: }
1.444 albertel 16258: }
1.566 albertel 16259:
1.444 albertel 16260: #
16261: # Set environment (will override cloned, if existing)
16262: #
16263: my @sections = ();
16264: my @xlists = ();
16265: if ($args->{'crstype'}) {
16266: $cenv{'type'}=$args->{'crstype'};
16267: }
1.1075.2.161. .17(raeb 16268:-23): if ($args->{'lti'}) {
16269:-23): $cenv{'internal.lti'}=$args->{'lti'};
16270:-23): }
1.444 albertel 16271: if ($args->{'crsid'}) {
16272: $cenv{'courseid'}=$args->{'crsid'};
16273: }
16274: if ($args->{'crscode'}) {
16275: $cenv{'internal.coursecode'}=$args->{'crscode'};
16276: }
16277: if ($args->{'crsquota'} ne '') {
16278: $cenv{'internal.coursequota'}=$args->{'crsquota'};
16279: } else {
16280: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
16281: }
16282: if ($args->{'ccuname'}) {
16283: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
16284: ':'.$args->{'ccdomain'};
16285: } else {
16286: $cenv{'internal.courseowner'} = $args->{'curruser'};
16287: }
1.1075.2.31 raeburn 16288: if ($args->{'defaultcredits'}) {
16289: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
16290: }
1.444 albertel 16291: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
16292: if ($args->{'crssections'}) {
16293: $cenv{'internal.sectionnums'} = '';
16294: if ($args->{'crssections'} =~ m/,/) {
16295: @sections = split/,/,$args->{'crssections'};
16296: } else {
16297: $sections[0] = $args->{'crssections'};
16298: }
16299: if (@sections > 0) {
16300: foreach my $item (@sections) {
16301: my ($sec,$gp) = split/:/,$item;
16302: my $class = $args->{'crscode'}.$sec;
16303: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16304: $cenv{'internal.sectionnums'} .= $item.',';
16305: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 16306: push(@badclasses,$class);
1.444 albertel 16307: }
16308: }
16309: $cenv{'internal.sectionnums'} =~ s/,$//;
16310: }
16311: }
16312: # do not hide course coordinator from staff listing,
16313: # even if privileged
16314: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 16315: # add course coordinator's domain to domains to check for privileged users
16316: # if different to course domain
16317: if ($$crsudom ne $args->{'ccdomain'}) {
16318: $cenv{'checkforpriv'} = $args->{'ccdomain'};
16319: }
1.444 albertel 16320: # add crosslistings
16321: if ($args->{'crsxlist'}) {
16322: $cenv{'internal.crosslistings'}='';
16323: if ($args->{'crsxlist'} =~ m/,/) {
16324: @xlists = split/,/,$args->{'crsxlist'};
16325: } else {
16326: $xlists[0] = $args->{'crsxlist'};
16327: }
16328: if (@xlists > 0) {
16329: foreach my $item (@xlists) {
16330: my ($xl,$gp) = split/:/,$item;
16331: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
16332: $cenv{'internal.crosslistings'} .= $item.',';
16333: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 16334: push(@badclasses,$xl);
1.444 albertel 16335: }
16336: }
16337: $cenv{'internal.crosslistings'} =~ s/,$//;
16338: }
16339: }
16340: if ($args->{'autoadds'}) {
16341: $cenv{'internal.autoadds'}=$args->{'autoadds'};
16342: }
16343: if ($args->{'autodrops'}) {
16344: $cenv{'internal.autodrops'}=$args->{'autodrops'};
16345: }
16346: # check for notification of enrollment changes
16347: my @notified = ();
16348: if ($args->{'notify_owner'}) {
16349: if ($args->{'ccuname'} ne '') {
16350: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
16351: }
16352: }
16353: if ($args->{'notify_dc'}) {
16354: if ($uname ne '') {
1.630 raeburn 16355: push(@notified,$uname.':'.$udom);
1.444 albertel 16356: }
16357: }
16358: if (@notified > 0) {
16359: my $notifylist;
16360: if (@notified > 1) {
16361: $notifylist = join(',',@notified);
16362: } else {
16363: $notifylist = $notified[0];
16364: }
16365: $cenv{'internal.notifylist'} = $notifylist;
16366: }
16367: if (@badclasses > 0) {
16368: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 16369: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16370: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16371: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16372: );
1.1075.2.119 raeburn 16373: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16374: &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 16375: if ($context eq 'auto') {
16376: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 16377: } else {
1.566 albertel 16378: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 16379: }
16380: foreach my $item (@badclasses) {
1.541 raeburn 16381: if ($context eq 'auto') {
1.1075.2.119 raeburn 16382: $outcome .= " - $item\n";
1.541 raeburn 16383: } else {
1.1075.2.119 raeburn 16384: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16385: }
1.1075.2.119 raeburn 16386: }
16387: if ($context eq 'auto') {
16388: $outcome .= $linefeed;
16389: } else {
16390: $outcome .= "</ul><br /><br /></div>\n";
16391: }
1.444 albertel 16392: }
16393: if ($args->{'no_end_date'}) {
16394: $args->{'endaccess'} = 0;
16395: }
16396: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16397: $cenv{'internal.autoend'}=$args->{'enrollend'};
16398: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16399: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16400: if ($args->{'showphotos'}) {
16401: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16402: }
16403: $cenv{'internal.authtype'} = $args->{'authtype'};
16404: $cenv{'internal.autharg'} = $args->{'autharg'};
16405: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16406: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16407: 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');
16408: if ($context eq 'auto') {
16409: $outcome .= $krb_msg;
16410: } else {
1.566 albertel 16411: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16412: }
16413: $outcome .= $linefeed;
1.444 albertel 16414: }
16415: }
16416: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16417: if ($args->{'setpolicy'}) {
16418: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16419: }
16420: if ($args->{'setcontent'}) {
16421: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16422: }
1.1075.2.110 raeburn 16423: if ($args->{'setcomment'}) {
16424: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16425: }
1.444 albertel 16426: }
16427: if ($args->{'reshome'}) {
16428: $cenv{'reshome'}=$args->{'reshome'}.'/';
16429: $cenv{'reshome'}=~s/\/+$/\//;
16430: }
16431: #
16432: # course has keyed access
16433: #
16434: if ($args->{'setkeys'}) {
16435: $cenv{'keyaccess'}='yes';
16436: }
16437: # if specified, key authority is not course, but user
16438: # only active if keyaccess is yes
16439: if ($args->{'keyauth'}) {
1.487 albertel 16440: my ($user,$domain) = split(':',$args->{'keyauth'});
16441: $user = &LONCAPA::clean_username($user);
16442: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16443: if ($user ne '' && $domain ne '') {
1.487 albertel 16444: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16445: }
16446: }
16447:
1.1075.2.59 raeburn 16448: #
16449: # generate and store uniquecode (available to course requester), if course should have one.
16450: #
16451: if ($args->{'uniquecode'}) {
16452: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16453: if ($code) {
16454: $cenv{'internal.uniquecode'} = $code;
16455: my %crsinfo =
16456: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16457: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16458: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16459: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16460: }
16461: if (ref($coderef)) {
16462: $$coderef = $code;
16463: }
16464: }
16465: }
16466:
1.444 albertel 16467: if ($args->{'disresdis'}) {
16468: $cenv{'pch.roles.denied'}='st';
16469: }
16470: if ($args->{'disablechat'}) {
16471: $cenv{'plc.roles.denied'}='st';
16472: }
16473:
16474: # Record we've not yet viewed the Course Initialization Helper for this
16475: # course
16476: $cenv{'course.helper.not.run'} = 1;
16477: #
16478: # Use new Randomseed
16479: #
16480: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16481: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16482: #
16483: # The encryption code and receipt prefix for this course
16484: #
16485: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16486: $cenv{'internal.encpref'}=100+int(9*rand(99));
16487: #
16488: # By default, use standard grading
16489: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16490:
1.541 raeburn 16491: $outcome .= $linefeed.&mt('Setting environment').': '.
16492: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16493: #
16494: # Open all assignments
16495: #
16496: if ($args->{'openall'}) {
1.1075.2.146 raeburn 16497: my $opendate = time;
16498: if ($args->{'openallfrom'} =~ /^\d+$/) {
16499: $opendate = $args->{'openallfrom'};
16500: }
1.444 albertel 16501: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1075.2.146 raeburn 16502: my %storecontent = ($storeunder => $opendate,
1.444 albertel 16503: $storeunder.'.type' => 'date_start');
1.1075.2.146 raeburn 16504: $outcome .= &mt('All assignments open starting [_1]',
16505: &Apache::lonlocal::locallocaltime($opendate)).': '.
16506: &Apache::lonnet::cput
16507: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16508: }
16509: #
16510: # Set first page
16511: #
16512: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16513: || ($cloneid)) {
16514: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16515:
16516: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16517: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16518:
1.444 albertel 16519: $outcome .= ($fatal?$errtext:'read ok').' - ';
16520: my $title; my $url;
16521: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16522: $title=&mt('Syllabus');
1.444 albertel 16523: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16524: } else {
1.963 raeburn 16525: $title=&mt('Table of Contents');
1.444 albertel 16526: $url='/adm/navmaps';
16527: }
1.445 albertel 16528:
16529: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16530: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16531:
16532: if ($errtext) { $fatal=2; }
1.541 raeburn 16533: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16534: }
1.566 albertel 16535:
1.1075.2.161. .1(raebu 16536:21): return (1,$outcome,\@clonemsg);
1.444 albertel 16537: }
16538:
1.1075.2.59 raeburn 16539: sub make_unique_code {
16540: my ($cdom,$cnum) = @_;
16541: # get lock on uniquecodes db
16542: my $lockhash = {
16543: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16544: ':'.$env{'user.domain'},
16545: };
16546: my $tries = 0;
16547: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16548: my ($code,$error);
16549:
16550: while (($gotlock ne 'ok') && ($tries<3)) {
16551: $tries ++;
16552: sleep 1;
16553: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16554: }
16555: if ($gotlock eq 'ok') {
16556: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
16557: my $gotcode;
16558: my $attempts = 0;
16559: while ((!$gotcode) && ($attempts < 100)) {
16560: $code = &generate_code();
16561: if (!exists($currcodes{$code})) {
16562: $gotcode = 1;
16563: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
16564: $error = 'nostore';
16565: }
16566: }
16567: $attempts ++;
16568: }
16569: my @del_lock = ($cnum."\0".'uniquecodes');
16570: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
16571: } else {
16572: $error = 'nolock';
16573: }
16574: return ($code,$error);
16575: }
16576:
16577: sub generate_code {
16578: my $code;
16579: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
16580: for (my $i=0; $i<6; $i++) {
16581: my $lettnum = int (rand 2);
16582: my $item = '';
16583: if ($lettnum) {
16584: $item = $letts[int( rand(18) )];
16585: } else {
16586: $item = 1+int( rand(8) );
16587: }
16588: $code .= $item;
16589: }
16590: return $code;
16591: }
16592:
1.444 albertel 16593: ############################################################
16594: ############################################################
16595:
1.953 droeschl 16596: #SD
16597: # only Community and Course, or anything else?
1.378 raeburn 16598: sub course_type {
16599: my ($cid) = @_;
16600: if (!defined($cid)) {
16601: $cid = $env{'request.course.id'};
16602: }
1.404 albertel 16603: if (defined($env{'course.'.$cid.'.type'})) {
16604: return $env{'course.'.$cid.'.type'};
1.378 raeburn 16605: } else {
16606: return 'Course';
1.377 raeburn 16607: }
16608: }
1.156 albertel 16609:
1.406 raeburn 16610: sub group_term {
16611: my $crstype = &course_type();
16612: my %names = (
16613: 'Course' => 'group',
1.865 raeburn 16614: 'Community' => 'group',
1.406 raeburn 16615: );
16616: return $names{$crstype};
16617: }
16618:
1.902 raeburn 16619: sub course_types {
1.1075.2.161. .17(raeb 16620:-23): my @types = ('official','unofficial','community','textbook','lti');
1.902 raeburn 16621: my %typename = (
16622: official => 'Official course',
16623: unofficial => 'Unofficial course',
16624: community => 'Community',
1.1075.2.59 raeburn 16625: textbook => 'Textbook course',
1.1075.2.161. .17(raeb 16626:-23): lti => 'LTI provider',
1.902 raeburn 16627: );
16628: return (\@types,\%typename);
16629: }
16630:
1.156 albertel 16631: sub icon {
16632: my ($file)=@_;
1.505 albertel 16633: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 16634: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 16635: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 16636: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
16637: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
16638: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16639: $curfext.".gif") {
16640: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16641: $curfext.".gif";
16642: }
16643: }
1.249 albertel 16644: return &lonhttpdurl($iconname);
1.154 albertel 16645: }
1.84 albertel 16646:
1.575 albertel 16647: sub lonhttpdurl {
1.692 www 16648: #
16649: # Had been used for "small fry" static images on separate port 8080.
16650: # Modify here if lightweight http functionality desired again.
16651: # Currently eliminated due to increasing firewall issues.
16652: #
1.575 albertel 16653: my ($url)=@_;
1.692 www 16654: return $url;
1.215 albertel 16655: }
16656:
1.213 albertel 16657: sub connection_aborted {
16658: my ($r)=@_;
16659: $r->print(" ");$r->rflush();
16660: my $c = $r->connection;
16661: return $c->aborted();
16662: }
16663:
1.221 foxr 16664: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 16665: # strings as 'strings'.
16666: sub escape_single {
1.221 foxr 16667: my ($input) = @_;
1.223 albertel 16668: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16669: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16670: return $input;
16671: }
1.223 albertel 16672:
1.222 foxr 16673: # Same as escape_single, but escape's "'s This
16674: # can be used for "strings"
16675: sub escape_double {
16676: my ($input) = @_;
16677: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16678: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16679: return $input;
16680: }
1.223 albertel 16681:
1.222 foxr 16682: # Escapes the last element of a full URL.
16683: sub escape_url {
16684: my ($url) = @_;
1.238 raeburn 16685: my @urlslices = split(/\//, $url,-1);
1.369 www 16686: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 16687: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16688: }
1.462 albertel 16689:
1.820 raeburn 16690: sub compare_arrays {
16691: my ($arrayref1,$arrayref2) = @_;
16692: my (@difference,%count);
16693: @difference = ();
16694: %count = ();
16695: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16696: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16697: foreach my $element (keys(%count)) {
16698: if ($count{$element} == 1) {
16699: push(@difference,$element);
16700: }
16701: }
16702: }
16703: return @difference;
16704: }
16705:
1.1075.2.152 raeburn 16706: sub lon_status_items {
16707: my %defaults = (
16708: E => 100,
16709: W => 4,
16710: N => 1,
16711: U => 5,
16712: threshold => 200,
16713: sysmail => 2500,
16714: );
16715: my %names = (
16716: E => 'Errors',
16717: W => 'Warnings',
16718: N => 'Notices',
16719: U => 'Unsent',
16720: );
16721: return (\%defaults,\%names);
16722: }
16723:
1.817 bisitz 16724: # -------------------------------------------------------- Initialize user login
1.462 albertel 16725: sub init_user_environment {
1.463 albertel 16726: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16727: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16728:
16729: my $public=($username eq 'public' && $domain eq 'public');
16730:
16731: # See if old ID present, if so, remove
16732:
1.1062 raeburn 16733: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16734: my $now=time;
16735:
16736: if ($public) {
16737: my $max_public=100;
16738: my $oldest;
16739: my $oldest_time=0;
16740: for(my $next=1;$next<=$max_public;$next++) {
16741: if (-e $lonids."/publicuser_$next.id") {
16742: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16743: if ($mtime<$oldest_time || !$oldest_time) {
16744: $oldest_time=$mtime;
16745: $oldest=$next;
16746: }
16747: } else {
16748: $cookie="publicuser_$next";
16749: last;
16750: }
16751: }
16752: if (!$cookie) { $cookie="publicuser_$oldest"; }
16753: } else {
1.463 albertel 16754: # if this isn't a robot, kill any existing non-robot sessions
16755: if (!$args->{'robot'}) {
16756: opendir(DIR,$lonids);
16757: while ($filename=readdir(DIR)) {
16758: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136 raeburn 16759: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
16760: &GDBM_READER(),0640)) {
16761: my $linkedfile;
16762: if (exists($oldenv{'user.linkedenv'})) {
16763: $linkedfile = $oldenv{'user.linkedenv'};
16764: }
16765: untie(%oldenv);
16766: if (unlink("$lonids/$filename")) {
16767: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
16768: if (-l "$lonids/$linkedfile.id") {
16769: unlink("$lonids/$linkedfile.id");
16770: }
16771: }
16772: }
16773: } else {
16774: unlink($lonids.'/'.$filename);
16775: }
1.463 albertel 16776: }
1.462 albertel 16777: }
1.463 albertel 16778: closedir(DIR);
1.1075.2.84 raeburn 16779: # If there is a undeleted lockfile for the user's paste buffer remove it.
16780: my $namespace = 'nohist_courseeditor';
16781: my $lockingkey = 'paste'."\0".'locked_num';
16782: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16783: $domain,$username);
16784: if (exists($lockhash{$lockingkey})) {
16785: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16786: unless ($delresult eq 'ok') {
16787: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16788: }
16789: }
1.462 albertel 16790: }
16791: # Give them a new cookie
1.463 albertel 16792: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16793: : $now.$$.int(rand(10000)));
1.463 albertel 16794: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16795:
16796: # Initialize roles
16797:
1.1062 raeburn 16798: ($userroles,$firstaccenv,$timerintenv) =
16799: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16800: }
16801: # ------------------------------------ Check browser type and MathML capability
16802:
1.1075.2.77 raeburn 16803: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16804: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16805:
16806: # ------------------------------------------------------------- Get environment
16807:
16808: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16809: my ($tmp) = keys(%userenv);
16810: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
16811: } else {
16812: undef(%userenv);
16813: }
16814: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16815: $form->{'interface'}=$userenv{'interface'};
16816: }
16817: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16818:
16819: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16820: foreach my $option ('interface','localpath','localres') {
16821: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16822: }
16823: # --------------------------------------------------------- Write first profile
16824:
16825: {
1.1075.2.150 raeburn 16826: my $ip = &Apache::lonnet::get_requestor_ip();
1.462 albertel 16827: my %initial_env =
16828: ("user.name" => $username,
16829: "user.domain" => $domain,
16830: "user.home" => $authhost,
16831: "browser.type" => $clientbrowser,
16832: "browser.version" => $clientversion,
16833: "browser.mathml" => $clientmathml,
16834: "browser.unicode" => $clientunicode,
16835: "browser.os" => $clientos,
1.1075.2.42 raeburn 16836: "browser.mobile" => $clientmobile,
16837: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 16838: "browser.osversion" => $clientosversion,
1.462 albertel 16839: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16840: "request.course.fn" => '',
16841: "request.course.uri" => '',
16842: "request.course.sec" => '',
16843: "request.role" => 'cm',
16844: "request.role.adv" => $env{'user.adv'},
1.1075.2.150 raeburn 16845: "request.host" => $ip,);
1.462 albertel 16846:
16847: if ($form->{'localpath'}) {
16848: $initial_env{"browser.localpath"} = $form->{'localpath'};
16849: $initial_env{"browser.localres"} = $form->{'localres'};
16850: }
16851:
16852: if ($form->{'interface'}) {
16853: $form->{'interface'}=~s/\W//gs;
16854: $initial_env{"browser.interface"} = $form->{'interface'};
16855: $env{'browser.interface'}=$form->{'interface'};
16856: }
16857:
1.1075.2.54 raeburn 16858: if ($form->{'iptoken'}) {
16859: my $lonhost = $r->dir_config('lonHostID');
16860: $initial_env{"user.noloadbalance"} = $lonhost;
16861: $env{'user.noloadbalance'} = $lonhost;
16862: }
16863:
1.1075.2.120 raeburn 16864: if ($form->{'noloadbalance'}) {
16865: my @hosts = &Apache::lonnet::current_machine_ids();
16866: my $hosthere = $form->{'noloadbalance'};
16867: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16868: $initial_env{"user.noloadbalance"} = $hosthere;
16869: $env{'user.noloadbalance'} = $hosthere;
16870: }
16871: }
16872:
1.1016 raeburn 16873: unless ($domain eq 'public') {
1.1075.2.125 raeburn 16874: my %is_adv = ( is_adv => $env{'user.adv'} );
16875: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 16876:
1.1075.2.161. .10(raeb 16877:-22): foreach my $tool ('aboutme','blog','webdav','portfolio','timezone') {
1.1075.2.125 raeburn 16878: $userenv{'availabletools.'.$tool} =
16879: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16880: undef,\%userenv,\%domdef,\%is_adv);
16881: }
1.724 raeburn 16882:
1.1075.2.161. .17(raeb 16883:-23): foreach my $crstype ('official','unofficial','community','textbook','lti') {
1.1075.2.125 raeburn 16884: $userenv{'canrequest.'.$crstype} =
16885: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16886: 'reload','requestcourses',
16887: \%userenv,\%domdef,\%is_adv);
16888: }
1.765 raeburn 16889:
1.1075.2.125 raeburn 16890: $userenv{'canrequest.author'} =
16891: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16892: 'reload','requestauthor',
16893: \%userenv,\%domdef,\%is_adv);
16894: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16895: $domain,$username);
16896: my $reqstatus = $reqauthor{'author_status'};
16897: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16898: if (ref($reqauthor{'author'}) eq 'HASH') {
16899: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16900: $reqauthor{'author'}{'timestamp'};
16901: }
1.1075.2.14 raeburn 16902: }
16903: }
16904:
1.462 albertel 16905: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16906:
1.462 albertel 16907: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16908: &GDBM_WRCREAT(),0640)) {
16909: &_add_to_env(\%disk_env,\%initial_env);
16910: &_add_to_env(\%disk_env,\%userenv,'environment.');
16911: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16912: if (ref($firstaccenv) eq 'HASH') {
16913: &_add_to_env(\%disk_env,$firstaccenv);
16914: }
16915: if (ref($timerintenv) eq 'HASH') {
16916: &_add_to_env(\%disk_env,$timerintenv);
16917: }
1.463 albertel 16918: if (ref($args->{'extra_env'})) {
16919: &_add_to_env(\%disk_env,$args->{'extra_env'});
16920: }
1.462 albertel 16921: untie(%disk_env);
16922: } else {
1.705 tempelho 16923: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16924: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16925: return 'error: '.$!;
16926: }
16927: }
16928: $env{'request.role'}='cm';
16929: $env{'request.role.adv'}=$env{'user.adv'};
16930: $env{'browser.type'}=$clientbrowser;
16931:
16932: return $cookie;
16933:
16934: }
16935:
16936: sub _add_to_env {
16937: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16938: if (ref($env_data) eq 'HASH') {
16939: while (my ($key,$value) = each(%$env_data)) {
16940: $idf->{$prefix.$key} = $value;
16941: $env{$prefix.$key} = $value;
16942: }
1.462 albertel 16943: }
16944: }
16945:
1.685 tempelho 16946: # --- Get the symbolic name of a problem and the url
16947: sub get_symb {
16948: my ($request,$silent) = @_;
1.726 raeburn 16949: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16950: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16951: if ($symb eq '') {
16952: if (!$silent) {
1.1071 raeburn 16953: if (ref($request)) {
16954: $request->print("Unable to handle ambiguous references:$url:.");
16955: }
1.685 tempelho 16956: return ();
16957: }
16958: }
16959: &Apache::lonenc::check_decrypt(\$symb);
16960: return ($symb);
16961: }
16962:
16963: # --------------------------------------------------------------Get annotation
16964:
16965: sub get_annotation {
16966: my ($symb,$enc) = @_;
16967:
16968: my $key = $symb;
16969: if (!$enc) {
16970: $key =
16971: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16972: }
16973: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16974: return $annotation{$key};
16975: }
16976:
16977: sub clean_symb {
1.731 raeburn 16978: my ($symb,$delete_enc) = @_;
1.685 tempelho 16979:
16980: &Apache::lonenc::check_decrypt(\$symb);
16981: my $enc = $env{'request.enc'};
1.731 raeburn 16982: if ($delete_enc) {
1.730 raeburn 16983: delete($env{'request.enc'});
16984: }
1.685 tempelho 16985:
16986: return ($symb,$enc);
16987: }
1.462 albertel 16988:
1.1075.2.69 raeburn 16989: ############################################################
16990: ############################################################
16991:
16992: =pod
16993:
16994: =head1 Routines for building display used to search for courses
16995:
16996:
16997: =over 4
16998:
16999: =item * &build_filters()
17000:
17001: Create markup for a table used to set filters to use when selecting
17002: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
17003: and quotacheck.pl
17004:
17005:
17006: Inputs:
17007:
17008: filterlist - anonymous array of fields to include as potential filters
17009:
17010: crstype - course type
17011:
17012: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
17013: to pop-open a course selector (will contain "extra element").
17014:
17015: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
17016:
17017: filter - anonymous hash of criteria and their values
17018:
17019: action - form action
17020:
17021: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
17022:
17023: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
17024:
17025: cloneruname - username of owner of new course who wants to clone
17026:
17027: clonerudom - domain of owner of new course who wants to clone
17028:
17029: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
17030:
17031: codetitlesref - reference to array of titles of components in institutional codes (official courses)
17032:
17033: codedom - domain
17034:
17035: formname - value of form element named "form".
17036:
17037: fixeddom - domain, if fixed.
17038:
17039: prevphase - value to assign to form element named "phase" when going back to the previous screen
17040:
17041: cnameelement - name of form element in form on opener page which will receive title of selected course
17042:
17043: cnumelement - name of form element in form on opener page which will receive courseID of selected course
17044:
17045: cdomelement - name of form element in form on opener page which will receive domain of selected course
17046:
17047: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
17048:
17049: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
17050:
17051: clonewarning - warning message about missing information for intended course owner when DC creates a course
17052:
17053:
17054: Returns: $output - HTML for display of search criteria, and hidden form elements.
17055:
17056:
17057: Side Effects: None
17058:
17059: =cut
17060:
17061: # ---------------------------------------------- search for courses based on last activity etc.
17062:
17063: sub build_filters {
17064: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
17065: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
17066: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
17067: $cnameelement,$cnumelement,$cdomelement,$setroles,
17068: $clonetext,$clonewarning) = @_;
17069: my ($list,$jscript);
17070: my $onchange = 'javascript:updateFilters(this)';
17071: my ($domainselectform,$sincefilterform,$createdfilterform,
17072: $ownerdomselectform,$persondomselectform,$instcodeform,
17073: $typeselectform,$instcodetitle);
17074: if ($formname eq '') {
17075: $formname = $caller;
17076: }
17077: foreach my $item (@{$filterlist}) {
17078: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
17079: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
17080: if ($item eq 'domainfilter') {
17081: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
17082: } elsif ($item eq 'coursefilter') {
17083: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
17084: } elsif ($item eq 'ownerfilter') {
17085: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17086: } elsif ($item eq 'ownerdomfilter') {
17087: $filter->{'ownerdomfilter'} =
17088: &LONCAPA::clean_domain($filter->{$item});
17089: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
17090: 'ownerdomfilter',1);
17091: } elsif ($item eq 'personfilter') {
17092: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17093: } elsif ($item eq 'persondomfilter') {
17094: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
17095: 'persondomfilter',1);
17096: } else {
17097: $filter->{$item} =~ s/\W//g;
17098: }
17099: if (!$filter->{$item}) {
17100: $filter->{$item} = '';
17101: }
17102: }
17103: if ($item eq 'domainfilter') {
17104: my $allow_blank = 1;
17105: if ($formname eq 'portform') {
17106: $allow_blank=0;
17107: } elsif ($formname eq 'studentform') {
17108: $allow_blank=0;
17109: }
17110: if ($fixeddom) {
17111: $domainselectform = '<input type="hidden" name="domainfilter"'.
17112: ' value="'.$codedom.'" />'.
17113: &Apache::lonnet::domain($codedom,'description');
17114: } else {
17115: $domainselectform = &select_dom_form($filter->{$item},
17116: 'domainfilter',
17117: $allow_blank,'',$onchange);
17118: }
17119: } else {
17120: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
17121: }
17122: }
17123:
17124: # last course activity filter and selection
17125: $sincefilterform = &timebased_select_form('sincefilter',$filter);
17126:
17127: # course created filter and selection
17128: if (exists($filter->{'createdfilter'})) {
17129: $createdfilterform = &timebased_select_form('createdfilter',$filter);
17130: }
17131:
17132: my %lt = &Apache::lonlocal::texthash(
17133: 'cac' => "$crstype Activity",
17134: 'ccr' => "$crstype Created",
17135: 'cde' => "$crstype Title",
17136: 'cdo' => "$crstype Domain",
17137: 'ins' => 'Institutional Code',
17138: 'inc' => 'Institutional Categorization',
17139: 'cow' => "$crstype Owner/Co-owner",
17140: 'cop' => "$crstype Personnel Includes",
17141: 'cog' => 'Type',
17142: );
17143:
17144: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17145: my $typeval = 'Course';
17146: if ($crstype eq 'Community') {
17147: $typeval = 'Community';
17148: }
17149: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
17150: } else {
17151: $typeselectform = '<select name="type" size="1"';
17152: if ($onchange) {
17153: $typeselectform .= ' onchange="'.$onchange.'"';
17154: }
17155: $typeselectform .= '>'."\n";
17156: foreach my $posstype ('Course','Community') {
17157: $typeselectform.='<option value="'.$posstype.'"'.
17158: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
17159: }
17160: $typeselectform.="</select>";
17161: }
17162:
17163: my ($cloneableonlyform,$cloneabletitle);
17164: if (exists($filter->{'cloneableonly'})) {
17165: my $cloneableon = '';
17166: my $cloneableoff = ' checked="checked"';
17167: if ($filter->{'cloneableonly'}) {
17168: $cloneableon = $cloneableoff;
17169: $cloneableoff = '';
17170: }
17171: $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>';
17172: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 17173: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 17174: } else {
17175: $cloneabletitle = &mt('Cloneable by you');
17176: }
17177: }
17178: my $officialjs;
17179: if ($crstype eq 'Course') {
17180: if (exists($filter->{'instcodefilter'})) {
17181: # if (($fixeddom) || ($formname eq 'requestcrs') ||
17182: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
17183: if ($codedom) {
17184: $officialjs = 1;
17185: ($instcodeform,$jscript,$$numtitlesref) =
17186: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
17187: $officialjs,$codetitlesref);
17188: if ($jscript) {
17189: $jscript = '<script type="text/javascript">'."\n".
17190: '// <![CDATA['."\n".
17191: $jscript."\n".
17192: '// ]]>'."\n".
17193: '</script>'."\n";
17194: }
17195: }
17196: if ($instcodeform eq '') {
17197: $instcodeform =
17198: '<input type="text" name="instcodefilter" size="10" value="'.
17199: $list->{'instcodefilter'}.'" />';
17200: $instcodetitle = $lt{'ins'};
17201: } else {
17202: $instcodetitle = $lt{'inc'};
17203: }
17204: if ($fixeddom) {
17205: $instcodetitle .= '<br />('.$codedom.')';
17206: }
17207: }
17208: }
17209: my $output = qq|
17210: <form method="post" name="filterpicker" action="$action">
17211: <input type="hidden" name="form" value="$formname" />
17212: |;
17213: if ($formname eq 'modifycourse') {
17214: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
17215: '<input type="hidden" name="prevphase" value="'.
17216: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 17217: } elsif ($formname eq 'quotacheck') {
17218: $output .= qq|
17219: <input type="hidden" name="sortby" value="" />
17220: <input type="hidden" name="sortorder" value="" />
17221: |;
17222: } else {
1.1075.2.69 raeburn 17223: my $name_input;
17224: if ($cnameelement ne '') {
17225: $name_input = '<input type="hidden" name="cnameelement" value="'.
17226: $cnameelement.'" />';
17227: }
17228: $output .= qq|
17229: <input type="hidden" name="cnumelement" value="$cnumelement" />
17230: <input type="hidden" name="cdomelement" value="$cdomelement" />
17231: $name_input
17232: $roleelement
17233: $multelement
17234: $typeelement
17235: |;
17236: if ($formname eq 'portform') {
17237: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
17238: }
17239: }
17240: if ($fixeddom) {
17241: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
17242: }
17243: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
17244: if ($sincefilterform) {
17245: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
17246: .$sincefilterform
17247: .&Apache::lonhtmlcommon::row_closure();
17248: }
17249: if ($createdfilterform) {
17250: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17251: .$createdfilterform
17252: .&Apache::lonhtmlcommon::row_closure();
17253: }
17254: if ($domainselectform) {
17255: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
17256: .$domainselectform
17257: .&Apache::lonhtmlcommon::row_closure();
17258: }
17259: if ($typeselectform) {
17260: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17261: $output .= $typeselectform;
17262: } else {
17263: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
17264: .$typeselectform
17265: .&Apache::lonhtmlcommon::row_closure();
17266: }
17267: }
17268: if ($instcodeform) {
17269: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
17270: .$instcodeform
17271: .&Apache::lonhtmlcommon::row_closure();
17272: }
17273: if (exists($filter->{'ownerfilter'})) {
17274: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
17275: '<table><tr><td>'.&mt('Username').'<br />'.
17276: '<input type="text" name="ownerfilter" size="20" value="'.
17277: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17278: $ownerdomselectform.'</td></tr></table>'.
17279: &Apache::lonhtmlcommon::row_closure();
17280: }
17281: if (exists($filter->{'personfilter'})) {
17282: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
17283: '<table><tr><td>'.&mt('Username').'<br />'.
17284: '<input type="text" name="personfilter" size="20" value="'.
17285: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17286: $persondomselectform.'</td></tr></table>'.
17287: &Apache::lonhtmlcommon::row_closure();
17288: }
17289: if (exists($filter->{'coursefilter'})) {
17290: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
17291: .'<input type="text" name="coursefilter" size="25" value="'
17292: .$list->{'coursefilter'}.'" />'
17293: .&Apache::lonhtmlcommon::row_closure();
17294: }
17295: if ($cloneableonlyform) {
17296: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
17297: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
17298: }
17299: if (exists($filter->{'descriptfilter'})) {
17300: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
17301: .'<input type="text" name="descriptfilter" size="40" value="'
17302: .$list->{'descriptfilter'}.'" />'
17303: .&Apache::lonhtmlcommon::row_closure(1);
17304: }
17305: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
17306: '<input type="hidden" name="updater" value="" />'."\n".
17307: '<input type="submit" name="gosearch" value="'.
17308: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
17309: return $jscript.$clonewarning.$output;
17310: }
17311:
17312: =pod
17313:
17314: =item * &timebased_select_form()
17315:
17316: Create markup for a dropdown list used to select a time-based
17317: filter e.g., Course Activity, Course Created, when searching for courses
17318: or communities
17319:
17320: Inputs:
17321:
17322: item - name of form element (sincefilter or createdfilter)
17323:
17324: filter - anonymous hash of criteria and their values
17325:
17326: Returns: HTML for a select box contained a blank, then six time selections,
17327: with value set in incoming form variables currently selected.
17328:
17329: Side Effects: None
17330:
17331: =cut
17332:
17333: sub timebased_select_form {
17334: my ($item,$filter) = @_;
17335: if (ref($filter) eq 'HASH') {
17336: $filter->{$item} =~ s/[^\d-]//g;
17337: if (!$filter->{$item}) { $filter->{$item}=-1; }
17338: return &select_form(
17339: $filter->{$item},
17340: $item,
17341: { '-1' => '',
17342: '86400' => &mt('today'),
17343: '604800' => &mt('last week'),
17344: '2592000' => &mt('last month'),
17345: '7776000' => &mt('last three months'),
17346: '15552000' => &mt('last six months'),
17347: '31104000' => &mt('last year'),
17348: 'select_form_order' =>
17349: ['-1','86400','604800','2592000','7776000',
17350: '15552000','31104000']});
17351: }
17352: }
17353:
17354: =pod
17355:
17356: =item * &js_changer()
17357:
17358: Create script tag containing Javascript used to submit course search form
17359: when course type or domain is changed, and also to hide 'Searching ...' on
17360: page load completion for page showing search result.
17361:
17362: Inputs: None
17363:
17364: Returns: markup containing updateFilters() and hideSearching() javascript functions.
17365:
17366: Side Effects: None
17367:
17368: =cut
17369:
17370: sub js_changer {
17371: return <<ENDJS;
17372: <script type="text/javascript">
17373: // <![CDATA[
17374: function updateFilters(caller) {
17375: if (typeof(caller) != "undefined") {
17376: document.filterpicker.updater.value = caller.name;
17377: }
17378: document.filterpicker.submit();
17379: }
17380:
17381: function hideSearching() {
17382: if (document.getElementById('searching')) {
17383: document.getElementById('searching').style.display = 'none';
17384: }
17385: return;
17386: }
17387:
17388: // ]]>
17389: </script>
17390:
17391: ENDJS
17392: }
17393:
17394: =pod
17395:
17396: =item * &search_courses()
17397:
17398: Process selected filters form course search form and pass to lonnet::courseiddump
17399: to retrieve a hash for which keys are courseIDs which match the selected filters.
17400:
17401: Inputs:
17402:
17403: dom - domain being searched
17404:
17405: type - course type ('Course' or 'Community' or '.' if any).
17406:
17407: filter - anonymous hash of criteria and their values
17408:
17409: numtitles - for institutional codes - number of categories
17410:
17411: cloneruname - optional username of new course owner
17412:
17413: clonerudom - optional domain of new course owner
17414:
1.1075.2.95 raeburn 17415: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 17416: (used when DC is using course creation form)
17417:
17418: codetitles - reference to array of titles of components in institutional codes (official courses).
17419:
1.1075.2.95 raeburn 17420: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17421: (and so can clone automatically)
17422:
17423: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17424:
17425: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17426: courses to clone
1.1075.2.69 raeburn 17427:
17428: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17429:
17430:
17431: Side Effects: None
17432:
17433: =cut
17434:
17435:
17436: sub search_courses {
1.1075.2.95 raeburn 17437: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17438: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 17439: my (%courses,%showcourses,$cloner);
17440: if (($filter->{'ownerfilter'} ne '') ||
17441: ($filter->{'ownerdomfilter'} ne '')) {
17442: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17443: $filter->{'ownerdomfilter'};
17444: }
17445: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17446: if (!$filter->{$item}) {
17447: $filter->{$item}='.';
17448: }
17449: }
17450: my $now = time;
17451: my $timefilter =
17452: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17453: my ($createdbefore,$createdafter);
17454: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17455: $createdbefore = $now;
17456: $createdafter = $now-$filter->{'createdfilter'};
17457: }
17458: my ($instcodefilter,$regexpok);
17459: if ($numtitles) {
17460: if ($env{'form.official'} eq 'on') {
17461: $instcodefilter =
17462: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17463: $regexpok = 1;
17464: } elsif ($env{'form.official'} eq 'off') {
17465: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17466: unless ($instcodefilter eq '') {
17467: $regexpok = -1;
17468: }
17469: }
17470: } else {
17471: $instcodefilter = $filter->{'instcodefilter'};
17472: }
17473: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17474: if ($type eq '') { $type = '.'; }
17475:
17476: if (($clonerudom ne '') && ($cloneruname ne '')) {
17477: $cloner = $cloneruname.':'.$clonerudom;
17478: }
17479: %courses = &Apache::lonnet::courseiddump($dom,
17480: $filter->{'descriptfilter'},
17481: $timefilter,
17482: $instcodefilter,
17483: $filter->{'combownerfilter'},
17484: $filter->{'coursefilter'},
17485: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 17486: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 17487: $filter->{'cloneableonly'},
17488: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 17489: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 17490: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17491: my $ccrole;
17492: if ($type eq 'Community') {
17493: $ccrole = 'co';
17494: } else {
17495: $ccrole = 'cc';
17496: }
17497: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17498: $filter->{'persondomfilter'},
17499: 'userroles',undef,
17500: [$ccrole,'in','ad','ep','ta','cr'],
17501: $dom);
17502: foreach my $role (keys(%rolehash)) {
17503: my ($cnum,$cdom,$courserole) = split(':',$role);
17504: my $cid = $cdom.'_'.$cnum;
17505: if (exists($courses{$cid})) {
17506: if (ref($courses{$cid}) eq 'HASH') {
17507: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17508: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 17509: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 17510: }
17511: } else {
17512: $courses{$cid}{roles} = [$courserole];
17513: }
17514: $showcourses{$cid} = $courses{$cid};
17515: }
17516: }
17517: }
17518: %courses = %showcourses;
17519: }
17520: return %courses;
17521: }
17522:
17523: =pod
17524:
17525: =back
17526:
1.1075.2.88 raeburn 17527: =head1 Routines for version requirements for current course.
17528:
17529: =over 4
17530:
17531: =item * &check_release_required()
17532:
17533: Compares required LON-CAPA version with version on server, and
17534: if required version is newer looks for a server with the required version.
17535:
17536: Looks first at servers in user's owen domain; if none suitable, looks at
17537: servers in course's domain are permitted to host sessions for user's domain.
17538:
17539: Inputs:
17540:
17541: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17542:
17543: $courseid - Course ID of current course
17544:
17545: $rolecode - User's current role in course (for switchserver query string).
17546:
17547: $required - LON-CAPA version needed by course (format: Major.Minor).
17548:
17549:
17550: Returns:
17551:
17552: $switchserver - query string tp append to /adm/switchserver call (if
17553: current server's LON-CAPA version is too old.
17554:
17555: $warning - Message is displayed if no suitable server could be found.
17556:
17557: =cut
17558:
17559: sub check_release_required {
17560: my ($loncaparev,$courseid,$rolecode,$required) = @_;
17561: my ($switchserver,$warning);
17562: if ($required ne '') {
17563: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
17564: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17565: if ($reqdmajor ne '' && $reqdminor ne '') {
17566: my $otherserver;
17567: if (($major eq '' && $minor eq '') ||
17568: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
17569: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
17570: my $switchlcrev =
17571: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
17572: $userdomserver);
17573: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17574: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
17575: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
17576: my $cdom = $env{'course.'.$courseid.'.domain'};
17577: if ($cdom ne $env{'user.domain'}) {
17578: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
17579: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
17580: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17581: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
17582: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
17583: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
17584: my $canhost =
17585: &Apache::lonnet::can_host_session($env{'user.domain'},
17586: $coursedomserver,
17587: $remoterev,
17588: $udomdefaults{'remotesessions'},
17589: $defdomdefaults{'hostedsessions'});
17590:
17591: if ($canhost) {
17592: $otherserver = $coursedomserver;
17593: } else {
17594: $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.");
17595: }
17596: } else {
17597: $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).");
17598: }
17599: } else {
17600: $otherserver = $userdomserver;
17601: }
17602: }
17603: if ($otherserver ne '') {
17604: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
17605: }
17606: }
17607: }
17608: return ($switchserver,$warning);
17609: }
17610:
17611: =pod
17612:
17613: =item * &check_release_result()
17614:
17615: Inputs:
17616:
17617: $switchwarning - Warning message if no suitable server found to host session.
17618:
17619: $switchserver - query string to append to /adm/switchserver containing lonHostID
17620: and current role.
17621:
17622: Returns: HTML to display with information about requirement to switch server.
17623: Either displaying warning with link to Roles/Courses screen or
17624: display link to switchserver.
17625:
1.1075.2.69 raeburn 17626: =cut
17627:
1.1075.2.88 raeburn 17628: sub check_release_result {
17629: my ($switchwarning,$switchserver) = @_;
17630: my $output = &start_page('Selected course unavailable on this server').
17631: '<p class="LC_warning">';
17632: if ($switchwarning) {
17633: $output .= $switchwarning.'<br /><a href="/adm/roles">';
17634: if (&show_course()) {
17635: $output .= &mt('Display courses');
17636: } else {
17637: $output .= &mt('Display roles');
17638: }
17639: $output .= '</a>';
17640: } elsif ($switchserver) {
17641: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
17642: '<br />'.
17643: '<a href="/adm/switchserver?'.$switchserver.'">'.
17644: &mt('Switch Server').
17645: '</a>';
17646: }
17647: $output .= '</p>'.&end_page();
17648: return $output;
17649: }
17650:
17651: =pod
17652:
17653: =item * &needs_coursereinit()
17654:
17655: Determine if course contents stored for user's session needs to be
17656: refreshed, because content has changed since "Big Hash" last tied.
17657:
17658: Check for change is made if time last checked is more than 10 minutes ago
17659: (by default).
17660:
17661: Inputs:
17662:
17663: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17664:
17665: $interval (optional) - Time which may elapse (in s) between last check for content
17666: change in current course. (default: 600 s).
17667:
17668: Returns: an array; first element is:
17669:
17670: =over 4
17671:
17672: 'switch' - if content updates mean user's session
17673: needs to be switched to a server running a newer LON-CAPA version
17674:
17675: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
17676: on current server hosting user's session
17677:
17678: '' - if no action required.
17679:
17680: =back
17681:
17682: If first item element is 'switch':
17683:
17684: second item is $switchwarning - Warning message if no suitable server found to host session.
17685:
17686: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
17687: and current role.
17688:
17689: otherwise: no other elements returned.
17690:
17691: =back
17692:
17693: =cut
17694:
17695: sub needs_coursereinit {
17696: my ($loncaparev,$interval) = @_;
17697: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
17698: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17699: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17700: my $now = time;
17701: if ($interval eq '') {
17702: $interval = 600;
17703: }
17704: if (($now-$env{'request.course.timechecked'})>$interval) {
17705: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1075.2.161. .4(raebu 17706:22): my $blocked = &blocking_status('reinit',undef,$cnum,$cdom,undef,1);
.1(raebu 17707:21): if ($blocked) {
17708:21): return ();
17709:21): }
.13(raeb 17710:-23): my $update;
17711:-23): my $lastmainchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17712:-23): my $lastsuppchange = &Apache::lonnet::get_suppchange($cdom,$cnum);
17713:-23): if ($lastmainchange > $env{'request.course.tied'}) {
17714:-23): my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
17715:-23): if ($needswitch) {
17716:-23): return ('switch',$switchwarning,$switchserver);
17717:-23): }
17718:-23): $update = 'main';
17719:-23): }
17720:-23): if ($lastsuppchange > $env{'request.course.suppupdated'}) {
17721:-23): if ($update) {
17722:-23): $update = 'both';
17723:-23): } else {
17724:-23): my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
17725:-23): if ($needswitch) {
17726:-23): return ('switch',$switchwarning,$switchserver);
17727:-23): } else {
17728:-23): $update = 'supp';
1.1075.2.88 raeburn 17729: }
17730: }
1.1075.2.161. .13(raeb 17731:-23): return ($update);
17732:-23): }
17733:-23): }
17734:-23): return ();
17735:-23): }
17736:-23):
17737:-23): sub switch_for_update {
17738:-23): my ($loncaparev,$cdom,$cnum) = @_;
17739:-23): my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17740:-23): if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17741:-23): my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17742:-23): if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17743:-23): &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17744:-23): $curr_reqd_hash{'internal.releaserequired'}});
17745:-23): my ($switchserver,$switchwarning) =
17746:-23): &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17747:-23): $curr_reqd_hash{'internal.releaserequired'});
17748:-23): if ($switchwarning ne '' || $switchserver ne '') {
17749:-23): return ('switch',$switchwarning,$switchserver);
17750:-23): }
1.1075.2.88 raeburn 17751: }
17752: }
17753: return ();
17754: }
1.1075.2.69 raeburn 17755:
1.1075.2.11 raeburn 17756: sub update_content_constraints {
17757: my ($cdom,$cnum,$chome,$cid) = @_;
17758: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17759: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
17760: my %checkresponsetypes;
17761: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
17762: my ($item,$name,$value) = split(/:/,$key);
17763: if ($item eq 'resourcetag') {
17764: if ($name eq 'responsetype') {
17765: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17766: }
17767: }
17768: }
17769: my $navmap = Apache::lonnavmaps::navmap->new();
17770: if (defined($navmap)) {
17771: my %allresponses;
17772: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
17773: my %responses = $res->responseTypes();
17774: foreach my $key (keys(%responses)) {
17775: next unless(exists($checkresponsetypes{$key}));
17776: $allresponses{$key} += $responses{$key};
17777: }
17778: }
17779: foreach my $key (keys(%allresponses)) {
17780: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17781: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17782: ($reqdmajor,$reqdminor) = ($major,$minor);
17783: }
17784: }
17785: undef($navmap);
17786: }
17787: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17788: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17789: }
17790: return;
17791: }
17792:
1.1075.2.27 raeburn 17793: sub allmaps_incourse {
17794: my ($cdom,$cnum,$chome,$cid) = @_;
17795: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17796: $cid = $env{'request.course.id'};
17797: $cdom = $env{'course.'.$cid.'.domain'};
17798: $cnum = $env{'course.'.$cid.'.num'};
17799: $chome = $env{'course.'.$cid.'.home'};
17800: }
17801: my %allmaps = ();
17802: my $lastchange =
17803: &Apache::lonnet::get_coursechange($cdom,$cnum);
17804: if ($lastchange > $env{'request.course.tied'}) {
17805: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17806: unless ($ferr) {
17807: &update_content_constraints($cdom,$cnum,$chome,$cid);
17808: }
17809: }
17810: my $navmap = Apache::lonnavmaps::navmap->new();
17811: if (defined($navmap)) {
17812: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17813: $allmaps{$res->src()} = 1;
17814: }
17815: }
17816: return \%allmaps;
17817: }
17818:
1.1075.2.11 raeburn 17819: sub parse_supplemental_title {
17820: my ($title) = @_;
17821:
17822: my ($foldertitle,$renametitle);
17823: if ($title =~ /&&&/) {
17824: $title = &HTML::Entites::decode($title);
17825: }
17826: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17827: $renametitle=$4;
17828: my ($time,$uname,$udom) = ($1,$2,$3);
17829: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17830: my $name = &plainname($uname,$udom);
17831: $name = &HTML::Entities::encode($name,'"<>&\'');
17832: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
1.1075.2.161. .16(raeb 17833:-23): $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.$name;
17834:-23): if ($foldertitle ne '') {
17835:-23): $title .= ': <br />'.$foldertitle;
17836:-23): }
1.1075.2.11 raeburn 17837: }
17838: if (wantarray) {
17839: return ($title,$foldertitle,$renametitle);
17840: }
17841: return $title;
17842: }
17843:
1.1075.2.161. .13(raeb 17844:-23): sub get_supplemental {
17845:-23): my ($cnum,$cdom,$ignorecache,$possdel)=@_;
17846:-23): my $hashid=$cnum.':'.$cdom;
17847:-23): my ($supplemental,$cached,$set_httprefs);
17848:-23): unless ($ignorecache) {
17849:-23): ($supplemental,$cached) = &Apache::lonnet::is_cached_new('supplemental',$hashid);
17850:-23): }
17851:-23): unless (defined($cached)) {
17852:-23): my $chome=&Apache::lonnet::homeserver($cnum,$cdom);
17853:-23): unless ($chome eq 'no_host') {
17854:-23): my @order = @LONCAPA::map::order;
17855:-23): my @resources = @LONCAPA::map::resources;
17856:-23): my @resparms = @LONCAPA::map::resparms;
17857:-23): my @zombies = @LONCAPA::map::zombies;
17858:-23): my ($errors,%ids,%hidden);
17859:-23): $errors =
17860:-23): &recurse_supplemental($cnum,$cdom,'supplemental.sequence',
17861:-23): $errors,$possdel,\%ids,\%hidden);
17862:-23): @LONCAPA::map::order = @order;
17863:-23): @LONCAPA::map::resources = @resources;
17864:-23): @LONCAPA::map::resparms = @resparms;
17865:-23): @LONCAPA::map::zombies = @zombies;
17866:-23): $set_httprefs = 1;
17867:-23): if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
17868:-23): &Apache::lonnet::appenv({'request.course.suppupdated' => time});
17869:-23): }
17870:-23): $supplemental = {
17871:-23): ids => \%ids,
17872:-23): hidden => \%hidden,
17873:-23): };
17874:-23): &Apache::lonnet::do_cache_new('supplemental',$hashid,$supplemental,600);
17875:-23): }
17876:-23): }
17877:-23): return ($supplemental,$set_httprefs);
17878:-23): }
17879:-23):
1.1075.2.43 raeburn 17880: sub recurse_supplemental {
1.1075.2.161. .13(raeb 17881:-23): my ($cnum,$cdom,$suppmap,$errors,$possdel,$suppids,$hiddensupp,$hidden) = @_;
17882:-23): if (($suppmap) && (ref($suppids) eq 'HASH') && (ref($hiddensupp) eq 'HASH')) {
17883:-23): my $mapnum;
17884:-23): if ($suppmap eq 'supplemental.sequence') {
17885:-23): $mapnum = 0;
17886:-23): } else {
17887:-23): ($mapnum) = ($suppmap =~ /^supplemental_(\d+)\.sequence$/);
17888:-23): }
1.1075.2.43 raeburn 17889: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17890: if ($fatal) {
17891: $errors ++;
17892: } else {
1.1075.2.161. .13(raeb 17893:-23): my @order = @LONCAPA::map::order;
17894:-23): if (@order > 0) {
17895:-23): my @resources = @LONCAPA::map::resources;
17896:-23): my @resparms = @LONCAPA::map::resparms;
17897:-23): foreach my $idx (@order) {
17898:-23): my ($title,$src,$ext,$type,$status)=split(/\:/,$resources[$idx]);
1.1075.2.43 raeburn 17899: if (($src ne '') && ($status eq 'res')) {
1.1075.2.161. .13(raeb 17900:-23): my $id = $mapnum.':'.$idx;
17901:-23): push(@{$suppids->{$src}},$id);
17902:-23): if (($hidden) || (&get_supp_parameter($resparms[$idx],'parameter_hiddenresource') =~ /^yes/i)) {
17903:-23): $hiddensupp->{$id} = 1;
17904:-23): }
1.1075.2.46 raeburn 17905: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1075.2.161. .13(raeb 17906:-23): $errors = &recurse_supplemental($cnum,$cdom,$1,$errors,$possdel,$suppids,
17907:-23): $hiddensupp,$hiddensupp->{$id});
1.1075.2.43 raeburn 17908: } else {
1.1075.2.161. .13(raeb 17909:-23): my $allowed;
17910:-23): if (($env{'request.role.adv'}) || (!$hiddensupp->{$id})) {
17911:-23): $allowed = 1;
17912:-23): } elsif ($possdel) {
17913:-23): foreach my $item (@{$suppids->{$src}}) {
17914:-23): next if ($item eq $id);
17915:-23): unless ($hiddensupp->{$item}) {
17916:-23): $allowed = 1;
17917:-23): last;
17918:-23): }
17919:-23): }
17920:-23): if ((!$allowed) && (exists($env{'httpref.'.$src}))) {
17921:-23): &Apache::lonnet::delenv('httpref.'.$src);
17922:-23): }
17923:-23): }
17924:-23): if ($allowed && (!exists($env{'httpref.'.$src}))) {
17925:-23): &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
17926:-23): }
17927:-23): }
17928:-23): }
17929:-23): }
17930:-23): }
17931:-23): }
17932:-23): }
17933:-23): return $errors;
17934:-23): }
17935:-23):
17936:-23): sub set_supp_httprefs {
17937:-23): my ($cnum,$cdom,$supplemental,$possdel) = @_;
17938:-23): if (ref($supplemental) eq 'HASH') {
17939:-23): if ((ref($supplemental->{'ids'}) eq 'HASH') && (ref($supplemental->{'hidden'}) eq 'HASH')) {
17940:-23): foreach my $src (keys(%{$supplemental->{'ids'}})) {
17941:-23): next if ($src =~ /\.sequence$/);
17942:-23): if (ref($supplemental->{'ids'}->{$src}) eq 'ARRAY') {
17943:-23): my $allowed;
17944:-23): if ($env{'request.role.adv'}) {
17945:-23): $allowed = 1;
17946:-23): } else {
17947:-23): foreach my $id (@{$supplemental->{'ids'}->{$src}}) {
17948:-23): unless ($supplemental->{'hidden'}->{$id}) {
17949:-23): $allowed = 1;
17950:-23): last;
17951:-23): }
17952:-23): }
17953:-23): }
17954:-23): if (exists($env{'httpref.'.$src})) {
17955:-23): if ($possdel) {
17956:-23): unless ($allowed) {
17957:-23): &Apache::lonnet::delenv('httpref.'.$src);
17958:-23): }
1.1075.2.43 raeburn 17959: }
1.1075.2.161. .13(raeb 17960:-23): } elsif ($allowed) {
17961:-23): &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
1.1075.2.43 raeburn 17962: }
17963: }
17964: }
1.1075.2.161. .13(raeb 17965:-23): if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
17966:-23): &Apache::lonnet::appenv({'request.course.suppupdated' => time});
17967:-23): }
1.1075.2.43 raeburn 17968: }
17969: }
1.1075.2.161. .13(raeb 17970:-23): }
17971:-23):
17972:-23): sub get_supp_parameter {
17973:-23): my ($resparm,$name)=@_;
17974:-23): return if ($resparm eq '');
17975:-23): my $value=undef;
17976:-23): my $ptype=undef;
17977:-23): foreach (split('&&&',$resparm)) {
17978:-23): my ($thistype,$thisname,$thisvalue)=split('___',$_);
17979:-23): if ($thisname eq $name) {
17980:-23): $value=$thisvalue;
17981:-23): $ptype=$thistype;
17982:-23): }
17983:-23): }
17984:-23): return $value;
1.1075.2.43 raeburn 17985: }
17986:
1.1075.2.18 raeburn 17987: sub symb_to_docspath {
1.1075.2.119 raeburn 17988: my ($symb,$navmapref) = @_;
17989: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 17990: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17991: if ($resurl=~/\.(sequence|page)$/) {
17992: $mapurl=$resurl;
17993: } elsif ($resurl eq 'adm/navmaps') {
17994: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17995: }
17996: my $mapresobj;
1.1075.2.119 raeburn 17997: unless (ref($$navmapref)) {
17998: $$navmapref = Apache::lonnavmaps::navmap->new();
17999: }
18000: if (ref($$navmapref)) {
18001: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 18002: }
18003: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
18004: my $type=$2;
18005: my $path;
18006: if (ref($mapresobj)) {
18007: my $pcslist = $mapresobj->map_hierarchy();
18008: if ($pcslist ne '') {
18009: foreach my $pc (split(/,/,$pcslist)) {
18010: next if ($pc <= 1);
1.1075.2.119 raeburn 18011: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 18012: if (ref($res)) {
18013: my $thisurl = $res->src();
18014: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
18015: my $thistitle = $res->title();
18016: $path .= '&'.
18017: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 18018: &escape($thistitle).
1.1075.2.18 raeburn 18019: ':'.$res->randompick().
18020: ':'.$res->randomout().
18021: ':'.$res->encrypted().
18022: ':'.$res->randomorder().
18023: ':'.$res->is_page();
18024: }
18025: }
18026: }
18027: $path =~ s/^\&//;
18028: my $maptitle = $mapresobj->title();
18029: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 18030: $maptitle = 'Main Content';
1.1075.2.18 raeburn 18031: }
18032: $path .= (($path ne '')? '&' : '').
18033: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 18034: &escape($maptitle).
1.1075.2.18 raeburn 18035: ':'.$mapresobj->randompick().
18036: ':'.$mapresobj->randomout().
18037: ':'.$mapresobj->encrypted().
18038: ':'.$mapresobj->randomorder().
18039: ':'.$mapresobj->is_page();
18040: } else {
18041: my $maptitle = &Apache::lonnet::gettitle($mapurl);
18042: my $ispage = (($type eq 'page')? 1 : '');
18043: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 18044: $maptitle = 'Main Content';
1.1075.2.18 raeburn 18045: }
18046: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 18047: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 18048: }
18049: unless ($mapurl eq 'default') {
18050: $path = 'default&'.
1.1075.2.46 raeburn 18051: &escape('Main Content').
1.1075.2.18 raeburn 18052: ':::::&'.$path;
18053: }
18054: return $path;
18055: }
18056:
1.1075.2.161. .13(raeb 18057:-23): sub validate_folderpath {
18058:-23): my ($supplementalflag,$allowed,$coursenum,$coursedom) = @_;
18059:-23): if ($env{'form.folderpath'} ne '') {
18060:-23): my @items = split(/\&/,$env{'form.folderpath'});
18061:-23): my ($badpath,$changed,$got_supp,$supppath,%supphidden,%suppids);
18062:-23): for (my $i=0; $i<@items; $i++) {
18063:-23): my $odd = $i%2;
18064:-23): if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
18065:-23): $badpath = 1;
18066:-23): } elsif ($odd && $supplementalflag) {
18067:-23): my $idx = $i-1;
18068:-23): if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
18069:-23): my $esc_name = $1;
18070:-23): if ((!$allowed) || ($items[$idx] eq 'supplemental')) {
18071:-23): $supppath .= '&'.$esc_name;
18072:-23): $changed = 1;
18073:-23): } else {
18074:-23): $supppath .= '&'.$items[$i];
18075:-23): }
18076:-23): } elsif (($allowed) && ($items[$idx] ne 'supplemental')) {
18077:-23): $changed = 1;
18078:-23): my $is_hidden;
18079:-23): unless ($got_supp) {
18080:-23): my ($supplemental) = &get_supplemental($coursenum,$coursedom);
18081:-23): if (ref($supplemental) eq 'HASH') {
18082:-23): if (ref($supplemental->{'hidden'}) eq 'HASH') {
18083:-23): %supphidden = %{$supplemental->{'hidden'}};
18084:-23): }
18085:-23): if (ref($supplemental->{'ids'}) eq 'HASH') {
18086:-23): %suppids = %{$supplemental->{'ids'}};
18087:-23): }
18088:-23): }
18089:-23): $got_supp = 1;
18090:-23): }
18091:-23): if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
18092:-23): my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
18093:-23): if ($supphidden{$mapid}) {
18094:-23): $is_hidden = 1;
18095:-23): }
18096:-23): }
18097:-23): $supppath .= '&'.$items[$i].'::'.$is_hidden.':::';
18098:-23): } else {
18099:-23): $supppath .= '&'.$items[$i];
18100:-23): }
18101:-23): } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
18102:-23): $badpath = 1;
18103:-23): } elsif ($supplementalflag) {
18104:-23): $supppath .= '&'.$items[$i];
18105:-23): }
18106:-23): last if ($badpath);
18107:-23): }
18108:-23): if ($badpath) {
18109:-23): delete($env{'form.folderpath'});
18110:-23): } elsif ($changed && $supplementalflag) {
18111:-23): $supppath =~ s/^\&//;
18112:-23): $env{'form.folderpath'} = $supppath;
18113:-23): }
18114:-23): }
18115:-23): return;
18116:-23): }
18117:-23):
1.1075.2.14 raeburn 18118: sub captcha_display {
1.1075.2.137 raeburn 18119: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 18120: my ($output,$error);
1.1075.2.107 raeburn 18121: my ($captcha,$pubkey,$privkey,$version) =
1.1075.2.137 raeburn 18122: &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 18123: if ($captcha eq 'original') {
18124: $output = &create_captcha();
18125: unless ($output) {
18126: $error = 'captcha';
18127: }
18128: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 18129: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 18130: unless ($output) {
18131: $error = 'recaptcha';
18132: }
18133: }
1.1075.2.107 raeburn 18134: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 18135: }
18136:
18137: sub captcha_response {
1.1075.2.137 raeburn 18138: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 18139: my ($captcha_chk,$captcha_error);
1.1075.2.137 raeburn 18140: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 18141: if ($captcha eq 'original') {
18142: ($captcha_chk,$captcha_error) = &check_captcha();
18143: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 18144: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 18145: } else {
18146: $captcha_chk = 1;
18147: }
18148: return ($captcha_chk,$captcha_error);
18149: }
18150:
18151: sub get_captcha_config {
1.1075.2.137 raeburn 18152: my ($context,$lonhost,$dom_in_effect) = @_;
1.1075.2.107 raeburn 18153: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 18154: my $hostname = &Apache::lonnet::hostname($lonhost);
18155: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
18156: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
18157: if ($context eq 'usercreation') {
18158: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
18159: if (ref($domconfig{$context}) eq 'HASH') {
18160: $hashtocheck = $domconfig{$context}{'cancreate'};
18161: if (ref($hashtocheck) eq 'HASH') {
18162: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
18163: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
18164: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
18165: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
18166: }
18167: if ($privkey && $pubkey) {
18168: $captcha = 'recaptcha';
1.1075.2.107 raeburn 18169: $version = $hashtocheck->{'recaptchaversion'};
18170: if ($version ne '2') {
18171: $version = 1;
18172: }
1.1075.2.14 raeburn 18173: } else {
18174: $captcha = 'original';
18175: }
18176: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
18177: $captcha = 'original';
18178: }
18179: }
18180: } else {
18181: $captcha = 'captcha';
18182: }
18183: } elsif ($context eq 'login') {
18184: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
18185: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
18186: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
18187: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
18188: if ($privkey && $pubkey) {
18189: $captcha = 'recaptcha';
1.1075.2.107 raeburn 18190: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
18191: if ($version ne '2') {
18192: $version = 1;
18193: }
1.1075.2.14 raeburn 18194: } else {
18195: $captcha = 'original';
18196: }
18197: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
18198: $captcha = 'original';
18199: }
1.1075.2.137 raeburn 18200: } elsif ($context eq 'passwords') {
18201: if ($dom_in_effect) {
18202: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
18203: if ($passwdconf{'captcha'} eq 'recaptcha') {
18204: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
18205: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
18206: $privkey = $passwdconf{'recaptchakeys'}{'private'};
18207: }
18208: if ($privkey && $pubkey) {
18209: $captcha = 'recaptcha';
18210: $version = $passwdconf{'recaptchaversion'};
18211: if ($version ne '2') {
18212: $version = 1;
18213: }
18214: } else {
18215: $captcha = 'original';
18216: }
18217: } elsif ($passwdconf{'captcha'} ne 'notused') {
18218: $captcha = 'original';
18219: }
18220: }
1.1075.2.14 raeburn 18221: }
1.1075.2.107 raeburn 18222: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 18223: }
18224:
18225: sub create_captcha {
18226: my %captcha_params = &captcha_settings();
18227: my ($output,$maxtries,$tries) = ('',10,0);
18228: while ($tries < $maxtries) {
18229: $tries ++;
18230: my $captcha = Authen::Captcha->new (
18231: output_folder => $captcha_params{'output_dir'},
18232: data_folder => $captcha_params{'db_dir'},
18233: );
18234: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
18235:
18236: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
18237: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1075.2.158 raeburn 18238: '<span class="LC_nobreak">'.
1.1075.2.14 raeburn 18239: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.161. .15(raeb 18240:-23): '<input type="text" size="5" name="code" value="" autocomplete="new-password" />'.
1.1075.2.158 raeburn 18241: '</span><br />'.
1.1075.2.66 raeburn 18242: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 18243: last;
18244: }
18245: }
1.1075.2.158 raeburn 18246: if ($output eq '') {
18247: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
18248: }
1.1075.2.14 raeburn 18249: return $output;
18250: }
18251:
18252: sub captcha_settings {
18253: my %captcha_params = (
18254: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
18255: www_output_dir => "/captchaspool",
18256: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
18257: numchars => '5',
18258: );
18259: return %captcha_params;
18260: }
18261:
18262: sub check_captcha {
18263: my ($captcha_chk,$captcha_error);
18264: my $code = $env{'form.code'};
18265: my $md5sum = $env{'form.crypt'};
18266: my %captcha_params = &captcha_settings();
18267: my $captcha = Authen::Captcha->new(
18268: output_folder => $captcha_params{'output_dir'},
18269: data_folder => $captcha_params{'db_dir'},
18270: );
1.1075.2.26 raeburn 18271: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 18272: my %captcha_hash = (
18273: 0 => 'Code not checked (file error)',
18274: -1 => 'Failed: code expired',
18275: -2 => 'Failed: invalid code (not in database)',
18276: -3 => 'Failed: invalid code (code does not match crypt)',
18277: );
18278: if ($captcha_chk != 1) {
18279: $captcha_error = $captcha_hash{$captcha_chk}
18280: }
18281: return ($captcha_chk,$captcha_error);
18282: }
18283:
18284: sub create_recaptcha {
1.1075.2.107 raeburn 18285: my ($pubkey,$version) = @_;
18286: if ($version >= 2) {
1.1075.2.158 raeburn 18287: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
18288: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1075.2.107 raeburn 18289: } else {
18290: my $use_ssl;
18291: if ($ENV{'SERVER_PORT'} == 443) {
18292: $use_ssl = 1;
18293: }
18294: my $captcha = Captcha::reCAPTCHA->new;
18295: return $captcha->get_options_setter({theme => 'white'})."\n".
18296: $captcha->get_html($pubkey,undef,$use_ssl).
18297: &mt('If the text is hard to read, [_1] will replace them.',
18298: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
18299: '<br /><br />';
18300: }
1.1075.2.14 raeburn 18301: }
18302:
18303: sub check_recaptcha {
1.1075.2.107 raeburn 18304: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 18305: my $captcha_chk;
1.1075.2.150 raeburn 18306: my $ip = &Apache::lonnet::get_requestor_ip();
1.1075.2.107 raeburn 18307: if ($version >= 2) {
18308: my $ua = LWP::UserAgent->new;
18309: $ua->timeout(10);
18310: my %info = (
18311: secret => $privkey,
18312: response => $env{'form.g-recaptcha-response'},
1.1075.2.150 raeburn 18313: remoteip => $ip,
1.1075.2.107 raeburn 18314: );
18315: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
18316: if ($response->is_success) {
18317: my $data = JSON::DWIW->from_json($response->decoded_content);
18318: if (ref($data) eq 'HASH') {
18319: if ($data->{'success'}) {
18320: $captcha_chk = 1;
18321: }
18322: }
18323: }
18324: } else {
18325: my $captcha = Captcha::reCAPTCHA->new;
18326: my $captcha_result =
18327: $captcha->check_answer(
18328: $privkey,
1.1075.2.150 raeburn 18329: $ip,
1.1075.2.107 raeburn 18330: $env{'form.recaptcha_challenge_field'},
18331: $env{'form.recaptcha_response_field'},
18332: );
18333: if ($captcha_result->{is_valid}) {
18334: $captcha_chk = 1;
18335: }
1.1075.2.14 raeburn 18336: }
18337: return $captcha_chk;
18338: }
18339:
1.1075.2.64 raeburn 18340: sub emailusername_info {
1.1075.2.103 raeburn 18341: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 18342: my %titles = &Apache::lonlocal::texthash (
18343: lastname => 'Last Name',
18344: firstname => 'First Name',
18345: institution => 'School/college/university',
18346: location => "School's city, state/province, country",
18347: web => "School's web address",
18348: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 18349: id => 'Student/Employee ID',
1.1075.2.64 raeburn 18350: );
18351: return (\@fields,\%titles);
18352: }
18353:
1.1075.2.56 raeburn 18354: sub cleanup_html {
18355: my ($incoming) = @_;
18356: my $outgoing;
18357: if ($incoming ne '') {
18358: $outgoing = $incoming;
18359: $outgoing =~ s/;/;/g;
18360: $outgoing =~ s/\#/#/g;
18361: $outgoing =~ s/\&/&/g;
18362: $outgoing =~ s/</</g;
18363: $outgoing =~ s/>/>/g;
18364: $outgoing =~ s/\(/(/g;
18365: $outgoing =~ s/\)/)/g;
18366: $outgoing =~ s/"/"/g;
18367: $outgoing =~ s/'/'/g;
18368: $outgoing =~ s/\$/$/g;
18369: $outgoing =~ s{/}{/}g;
18370: $outgoing =~ s/=/=/g;
18371: $outgoing =~ s/\\/\/g
18372: }
18373: return $outgoing;
18374: }
18375:
1.1075.2.74 raeburn 18376: # Checks for critical messages and returns a redirect url if one exists.
18377: # $interval indicates how often to check for messages.
1.1075.2.161. .1(raebu 18378:21): # $context is the calling context -- roles, grades, contents, menu or flip.
1.1075.2.74 raeburn 18379: sub critical_redirect {
1.1075.2.161. .1(raebu 18380:21): my ($interval,$context) = @_;
1.1075.2.158 raeburn 18381: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
18382: return ();
18383: }
1.1075.2.74 raeburn 18384: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1075.2.161. .1(raebu 18385:21): if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
18386:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18387:21): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
.4(raebu 18388:22): my $blocked = &blocking_status('alert',undef,$cnum,$cdom,undef,1);
.1(raebu 18389:21): if ($blocked) {
18390:21): my $checkrole = "cm./$cdom/$cnum";
18391:21): if ($env{'request.course.sec'} ne '') {
18392:21): $checkrole .= "/$env{'request.course.sec'}";
18393:21): }
18394:21): unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
18395:21): ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
18396:21): return;
18397:21): }
18398:21): }
18399:21): }
1.1075.2.74 raeburn 18400: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
18401: $env{'user.name'});
18402: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
18403: my $redirecturl;
18404: if ($what[0]) {
1.1075.2.158 raeburn 18405: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1075.2.74 raeburn 18406: $redirecturl='/adm/email?critical=display';
18407: my $url=&Apache::lonnet::absolute_url().$redirecturl;
18408: return (1, $url);
18409: }
18410: }
18411: }
18412: return ();
18413: }
18414:
1.1075.2.64 raeburn 18415: # Use:
18416: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
18417: #
18418: ##################################################
18419: # password associated functions #
18420: ##################################################
18421: sub des_keys {
18422: # Make a new key for DES encryption.
18423: # Each key has two parts which are returned separately.
18424: # Please note: Each key must be passed through the &hex function
18425: # before it is output to the web browser. The hex versions cannot
18426: # be used to decrypt.
18427: my @hexstr=('0','1','2','3','4','5','6','7',
18428: '8','9','a','b','c','d','e','f');
18429: my $lkey='';
18430: for (0..7) {
18431: $lkey.=$hexstr[rand(15)];
18432: }
18433: my $ukey='';
18434: for (0..7) {
18435: $ukey.=$hexstr[rand(15)];
18436: }
18437: return ($lkey,$ukey);
18438: }
18439:
18440: sub des_decrypt {
18441: my ($key,$cyphertext) = @_;
18442: my $keybin=pack("H16",$key);
18443: my $cypher;
18444: if ($Crypt::DES::VERSION>=2.03) {
18445: $cypher=new Crypt::DES $keybin;
18446: } else {
18447: $cypher=new DES $keybin;
18448: }
1.1075.2.106 raeburn 18449: my $plaintext='';
18450: my $cypherlength = length($cyphertext);
18451: my $numchunks = int($cypherlength/32);
18452: for (my $j=0; $j<$numchunks; $j++) {
18453: my $start = $j*32;
18454: my $cypherblock = substr($cyphertext,$start,32);
18455: my $chunk =
18456: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
18457: $chunk .=
18458: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
18459: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
18460: $plaintext .= $chunk;
18461: }
1.1075.2.64 raeburn 18462: return $plaintext;
18463: }
18464:
1.1075.2.161. .1(raebu 18465:21): sub get_requested_shorturls {
18466:21): my ($cdom,$cnum,$navmap) = @_;
18467:21): return unless (ref($navmap));
18468:21): my ($numnew,$errors);
18469:21): my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
18470:21): if (@toshorten) {
18471:21): my (%maps,%resources,%titles);
18472:21): &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
18473:21): 'shorturls',$cdom,$cnum);
18474:21): if (keys(%resources)) {
18475:21): my %tocreate;
18476:21): foreach my $item (sort {$a <=> $b} (@toshorten)) {
18477:21): my $symb = $resources{$item};
18478:21): if ($symb) {
18479:21): $tocreate{$cnum.'&'.$symb} = 1;
18480:21): }
18481:21): }
18482:21): if (keys(%tocreate)) {
18483:21): ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
18484:21): \%tocreate);
18485:21): }
18486:21): }
18487:21): }
18488:21): return ($numnew,$errors);
18489:21): }
18490:21):
18491:21): sub make_short_symbs {
18492:21): my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
18493:21): my ($numnew,@errors);
18494:21): if (ref($tocreateref) eq 'HASH') {
18495:21): my %tocreate = %{$tocreateref};
18496:21): if (keys(%tocreate)) {
18497:21): my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
18498:21): my $su = Short::URL->new(no_vowels => 1);
18499:21): my $init = '';
18500:21): my (%newunique,%addcourse,%courseonly,%failed);
18501:21): # get lock on tiny db
18502:21): my $now = time;
18503:21): if ($lockuser eq '') {
18504:21): $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
18505:21): }
18506:21): my $lockhash = {
18507:21): "lock\0$now" => $lockuser,
18508:21): };
18509:21): my $tries = 0;
18510:21): my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18511:21): my ($code,$error);
18512:21): while (($gotlock ne 'ok') && ($tries<3)) {
18513:21): $tries ++;
18514:21): sleep 1;
18515:21): $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18516:21): }
18517:21): if ($gotlock eq 'ok') {
18518:21): $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
18519:21): \%addcourse,\%courseonly,\%failed);
18520:21): if (keys(%failed)) {
18521:21): my $numfailed = scalar(keys(%failed));
18522:21): push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
18523:21): }
18524:21): if (keys(%newunique)) {
18525:21): my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
18526:21): if ($putres eq 'ok') {
18527:21): $numnew = scalar(keys(%newunique));
18528:21): my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
18529:21): unless ($newputres eq 'ok') {
18530:21): push(@errors,&mt('error: could not store course look-up of short URLs'));
18531:21): }
18532:21): } else {
18533:21): push(@errors,&mt('error: could not store unique six character URLs'));
18534:21): }
18535:21): }
18536:21): my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
18537:21): unless ($dellockres eq 'ok') {
18538:21): push(@errors,&mt('error: could not release lockfile'));
18539:21): }
18540:21): } else {
18541:21): push(@errors,&mt('error: could not obtain lockfile'));
18542:21): }
18543:21): if (keys(%courseonly)) {
18544:21): my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
18545:21): if ($result ne 'ok') {
18546:21): push(@errors,&mt('error: could not update course look-up of short URLs'));
18547:21): }
18548:21): }
18549:21): }
18550:21): }
18551:21): return ($numnew,\@errors);
18552:21): }
18553:21):
18554:21): sub shorten_symbs {
18555:21): my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
18556:21): return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
18557:21): (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
18558:21): (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
18559:21): my (%possibles,%collisions);
18560:21): foreach my $key (keys(%{$tocreate})) {
18561:21): my $num = String::CRC32::crc32($key);
18562:21): my $tiny = $su->encode($num,$init);
18563:21): if ($tiny) {
18564:21): $possibles{$tiny} = $key;
18565:21): }
18566:21): }
18567:21): if (!$init) {
18568:21): $init = 1;
18569:21): } else {
18570:21): $init ++;
18571:21): }
18572:21): if (keys(%possibles)) {
18573:21): my @posstiny = keys(%possibles);
18574:21): my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
18575:21): my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
18576:21): if (keys(%currtiny)) {
18577:21): foreach my $key (keys(%currtiny)) {
18578:21): next if ($currtiny{$key} eq '');
18579:21): if ($currtiny{$key} eq $possibles{$key}) {
18580:21): my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
18581:21): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18582:21): $courseonly->{$tsymb} = $key;
18583:21): }
18584:21): } else {
18585:21): $collisions{$possibles{$key}} = 1;
18586:21): }
18587:21): delete($possibles{$key});
18588:21): }
18589:21): }
18590:21): foreach my $key (keys(%possibles)) {
18591:21): $newunique->{$key} = $possibles{$key};
18592:21): my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
18593:21): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18594:21): $addcourse->{$tsymb} = $key;
18595:21): }
18596:21): }
18597:21): }
18598:21): if (keys(%collisions)) {
18599:21): if ($init <5) {
18600:21): if (!$init) {
18601:21): $init = 1;
18602:21): } else {
18603:21): $init ++;
18604:21): }
18605:21): $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
18606:21): $newunique,$addcourse,$courseonly,$failed);
18607:21): } else {
18608:21): foreach my $key (keys(%collisions)) {
18609:21): $failed->{$key} = 1;
18610:21): $failed->{$key} = 1;
18611:21): }
18612:21): }
18613:21): }
18614:21): return $init;
18615:21): }
18616:21):
1.1075.2.135 raeburn 18617: sub is_nonframeable {
18618: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
18619: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
18620: return if (($remprotocol eq '') || ($remhost eq ''));
18621:
18622: $remprotocol = lc($remprotocol);
18623: $remhost = lc($remhost);
18624: my $remport = 80;
18625: if ($remprotocol eq 'https') {
18626: $remport = 443;
18627: }
18628: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
18629: if ($cached) {
18630: unless ($nocache) {
18631: if ($result) {
18632: return 1;
18633: } else {
18634: return 0;
18635: }
18636: }
18637: }
18638: my $uselink;
18639: my $request = new HTTP::Request('HEAD',$url);
1.1075.2.142 raeburn 18640: my $ua = LWP::UserAgent->new;
18641: $ua->timeout(5);
18642: my $response=$ua->request($request);
1.1075.2.135 raeburn 18643: if ($response->is_success()) {
18644: my $secpolicy = lc($response->header('content-security-policy'));
18645: my $xframeop = lc($response->header('x-frame-options'));
18646: $secpolicy =~ s/^\s+|\s+$//g;
18647: $xframeop =~ s/^\s+|\s+$//g;
18648: if (($secpolicy ne '') || ($xframeop ne '')) {
18649: my $remotehost = $remprotocol.'://'.$remhost;
18650: my ($origin,$protocol,$port);
18651: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
18652: $port = $ENV{'SERVER_PORT'};
18653: } else {
18654: $port = 80;
18655: }
18656: if ($absolute eq '') {
18657: $protocol = 'http:';
18658: if ($port == 443) {
18659: $protocol = 'https:';
18660: }
18661: $origin = $protocol.'//'.lc($hostname);
18662: } else {
18663: $origin = lc($absolute);
18664: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
18665: }
18666: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
18667: my $framepolicy = $1;
18668: $framepolicy =~ s/^\s+|\s+$//g;
18669: my @policies = split(/\s+/,$framepolicy);
18670: if (@policies) {
18671: if (grep(/^\Q'none'\E$/,@policies)) {
18672: $uselink = 1;
18673: } else {
18674: $uselink = 1;
18675: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
18676: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
18677: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
18678: undef($uselink);
18679: }
18680: if ($uselink) {
18681: if (grep(/^\Q'self'\E$/,@policies)) {
18682: if (($origin ne '') && ($remotehost eq $origin)) {
18683: undef($uselink);
18684: }
18685: }
18686: }
18687: if ($uselink) {
18688: my @possok;
18689: if ($ip ne '') {
18690: push(@possok,$ip);
18691: }
18692: my $hoststr = '';
18693: foreach my $part (reverse(split(/\./,$hostname))) {
18694: if ($hoststr eq '') {
18695: $hoststr = $part;
18696: } else {
18697: $hoststr = "$part.$hoststr";
18698: }
18699: if ($hoststr eq $hostname) {
18700: push(@possok,$hostname);
18701: } else {
18702: push(@possok,"*.$hoststr");
18703: }
18704: }
18705: if (@possok) {
18706: foreach my $poss (@possok) {
18707: last if (!$uselink);
18708: foreach my $policy (@policies) {
18709: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
18710: undef($uselink);
18711: last;
18712: }
18713: }
18714: }
18715: }
18716: }
18717: }
18718: }
18719: } elsif ($xframeop ne '') {
18720: $uselink = 1;
18721: my @policies = split(/\s*,\s*/,$xframeop);
18722: if (@policies) {
18723: unless (grep(/^deny$/,@policies)) {
18724: if ($origin ne '') {
18725: if (grep(/^sameorigin$/,@policies)) {
18726: if ($remotehost eq $origin) {
18727: undef($uselink);
18728: }
18729: }
18730: if ($uselink) {
18731: foreach my $policy (@policies) {
18732: if ($policy =~ /^allow-from\s*(.+)$/) {
18733: my $allowfrom = $1;
18734: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
18735: undef($uselink);
18736: last;
18737: }
18738: }
18739: }
18740: }
18741: }
18742: }
18743: }
18744: }
18745: }
18746: }
18747: if ($nocache) {
18748: if ($cached) {
18749: my $devalidate;
18750: if ($uselink && !$result) {
18751: $devalidate = 1;
18752: } elsif (!$uselink && $result) {
18753: $devalidate = 1;
18754: }
18755: if ($devalidate) {
18756: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
18757: }
18758: }
18759: } else {
18760: if ($uselink) {
18761: $result = 1;
18762: } else {
18763: $result = 0;
18764: }
18765: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
18766: }
18767: return $uselink;
18768: }
18769:
1.1075.2.161. .1(raebu 18770:21): sub page_menu {
18771:21): my ($menucolls,$menunum) = @_;
18772:21): my %menu;
18773:21): foreach my $item (split(/;/,$menucolls)) {
18774:21): my ($num,$value) = split(/\%/,$item);
18775:21): if ($num eq $menunum) {
18776:21): my @entries = split(/\&/,$value);
18777:21): foreach my $entry (@entries) {
18778:21): my ($name,$fields) = split(/=/,$entry);
18779:21): if (($name eq 'top') || ($name eq 'inline') || ($name eq 'foot') || ($name eq 'main')) {
18780:21): $menu{$name} = $fields;
18781:21): } else {
18782:21): my @shown;
18783:21): if ($fields =~ /,/) {
18784:21): @shown = split(/,/,$fields);
18785:21): } else {
18786:21): @shown = ($fields);
18787:21): }
18788:21): if (@shown) {
18789:21): foreach my $field (@shown) {
18790:21): next if ($field eq '');
18791:21): $menu{$field} = 1;
18792:21): }
18793:21): }
18794:21): }
18795:21): }
18796:21): }
18797:21): }
18798:21): return %menu;
18799:21): }
18800:21):
1.112 bowersj2 18801: 1;
18802: __END__;
1.41 ng 18803:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>