Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.161.2.17
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. .17(raeb 4:-23): # $Id: loncommon.pm,v 1.1075.2.161.2.16 2023/03/12 02:20:43 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.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.251 albertel 6400: return $endbodytag;
6401: }
6402:
1.352 albertel 6403: =pod
6404:
6405: =item * &standard_css()
6406:
6407: Returns a style sheet
6408:
6409: Inputs: (all optional)
6410: domain -> force to color decorate a page for a specific
6411: domain
6412: function -> force usage of a specific rolish color scheme
6413: bgcolor -> override the default page bgcolor
6414:
6415: =cut
6416:
1.343 albertel 6417: sub standard_css {
1.345 albertel 6418: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6419: $function = &get_users_function() if (!$function);
6420: my $img = &designparm($function.'.img', $domain);
6421: my $tabbg = &designparm($function.'.tabbg', $domain);
6422: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6423: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6424: #second colour for later usage
1.345 albertel 6425: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6426: my $pgbg_or_bgcolor =
6427: $bgcolor ||
1.352 albertel 6428: &designparm($function.'.pgbg', $domain);
1.382 albertel 6429: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6430: my $alink = &designparm($function.'.alink', $domain);
6431: my $vlink = &designparm($function.'.vlink', $domain);
6432: my $link = &designparm($function.'.link', $domain);
6433:
1.602 albertel 6434: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6435: my $mono = 'monospace';
1.850 bisitz 6436: my $data_table_head = $sidebg;
6437: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6438: my $data_table_dark = '#E0E0E0';
1.470 banghart 6439: my $data_table_darker = '#CCCCCC';
1.349 albertel 6440: my $data_table_highlight = '#FFFF00';
1.352 albertel 6441: my $mail_new = '#FFBB77';
6442: my $mail_new_hover = '#DD9955';
6443: my $mail_read = '#BBBB77';
6444: my $mail_read_hover = '#999944';
6445: my $mail_replied = '#AAAA88';
6446: my $mail_replied_hover = '#888855';
6447: my $mail_other = '#99BBBB';
6448: my $mail_other_hover = '#669999';
1.391 albertel 6449: my $table_header = '#DDDDDD';
1.489 raeburn 6450: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6451: my $lg_border_color = '#C8C8C8';
1.952 onken 6452: my $button_hover = '#BF2317';
1.392 albertel 6453:
1.608 albertel 6454: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6455: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6456: : '0 3px 0 4px';
1.448 albertel 6457:
1.523 albertel 6458:
1.343 albertel 6459: return <<END;
1.947 droeschl 6460:
6461: /* needed for iframe to allow 100% height in FF */
6462: body, html {
6463: margin: 0;
6464: padding: 0 0.5%;
6465: height: 99%; /* to avoid scrollbars */
6466: }
6467:
1.795 www 6468: body {
1.911 bisitz 6469: font-family: $sans;
6470: line-height:130%;
6471: font-size:0.83em;
6472: color:$font;
1.795 www 6473: }
6474:
1.959 onken 6475: a:focus,
6476: a:focus img {
1.795 www 6477: color: red;
6478: }
1.698 harmsja 6479:
1.911 bisitz 6480: form, .inline {
6481: display: inline;
1.795 www 6482: }
1.721 harmsja 6483:
1.795 www 6484: .LC_right {
1.911 bisitz 6485: text-align:right;
1.795 www 6486: }
6487:
6488: .LC_middle {
1.911 bisitz 6489: vertical-align:middle;
1.795 www 6490: }
1.721 harmsja 6491:
1.1075.2.38 raeburn 6492: .LC_floatleft {
6493: float: left;
6494: }
6495:
6496: .LC_floatright {
6497: float: right;
6498: }
6499:
1.911 bisitz 6500: .LC_400Box {
6501: width:400px;
6502: }
1.721 harmsja 6503:
1.947 droeschl 6504: .LC_iframecontainer {
6505: width: 98%;
6506: margin: 0;
6507: position: fixed;
6508: top: 8.5em;
6509: bottom: 0;
6510: }
6511:
6512: .LC_iframecontainer iframe{
6513: border: none;
6514: width: 100%;
6515: height: 100%;
6516: }
6517:
1.778 bisitz 6518: .LC_filename {
6519: font-family: $mono;
6520: white-space:pre;
1.921 bisitz 6521: font-size: 120%;
1.778 bisitz 6522: }
6523:
6524: .LC_fileicon {
6525: border: none;
6526: height: 1.3em;
6527: vertical-align: text-bottom;
6528: margin-right: 0.3em;
6529: text-decoration:none;
6530: }
6531:
1.1008 www 6532: .LC_setting {
6533: text-decoration:underline;
6534: }
6535:
1.350 albertel 6536: .LC_error {
6537: color: red;
6538: }
1.795 www 6539:
1.1075.2.15 raeburn 6540: .LC_warning {
6541: color: darkorange;
6542: }
6543:
1.457 albertel 6544: .LC_diff_removed {
1.733 bisitz 6545: color: red;
1.394 albertel 6546: }
1.532 albertel 6547:
6548: .LC_info,
1.457 albertel 6549: .LC_success,
6550: .LC_diff_added {
1.350 albertel 6551: color: green;
6552: }
1.795 www 6553:
1.802 bisitz 6554: div.LC_confirm_box {
6555: background-color: #FAFAFA;
6556: border: 1px solid $lg_border_color;
6557: margin-right: 0;
6558: padding: 5px;
6559: }
6560:
6561: div.LC_confirm_box .LC_error img,
6562: div.LC_confirm_box .LC_success img {
6563: vertical-align: middle;
6564: }
6565:
1.1075.2.108 raeburn 6566: .LC_maxwidth {
6567: max-width: 100%;
6568: height: auto;
6569: }
6570:
6571: .LC_textsize_mobile {
6572: \@media only screen and (max-device-width: 480px) {
6573: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6574: }
6575: }
6576:
1.440 albertel 6577: .LC_icon {
1.771 droeschl 6578: border: none;
1.790 droeschl 6579: vertical-align: middle;
1.771 droeschl 6580: }
6581:
1.543 albertel 6582: .LC_docs_spacer {
6583: width: 25px;
6584: height: 1px;
1.771 droeschl 6585: border: none;
1.543 albertel 6586: }
1.346 albertel 6587:
1.532 albertel 6588: .LC_internal_info {
1.735 bisitz 6589: color: #999999;
1.532 albertel 6590: }
6591:
1.794 www 6592: .LC_discussion {
1.1050 www 6593: background: $data_table_dark;
1.911 bisitz 6594: border: 1px solid black;
6595: margin: 2px;
1.794 www 6596: }
6597:
6598: .LC_disc_action_left {
1.1050 www 6599: background: $sidebg;
1.911 bisitz 6600: text-align: left;
1.1050 www 6601: padding: 4px;
6602: margin: 2px;
1.794 www 6603: }
6604:
6605: .LC_disc_action_right {
1.1050 www 6606: background: $sidebg;
1.911 bisitz 6607: text-align: right;
1.1050 www 6608: padding: 4px;
6609: margin: 2px;
1.794 www 6610: }
6611:
6612: .LC_disc_new_item {
1.911 bisitz 6613: background: white;
6614: border: 2px solid red;
1.1050 www 6615: margin: 4px;
6616: padding: 4px;
1.794 www 6617: }
6618:
6619: .LC_disc_old_item {
1.911 bisitz 6620: background: white;
1.1050 www 6621: margin: 4px;
6622: padding: 4px;
1.794 www 6623: }
6624:
1.458 albertel 6625: table.LC_pastsubmission {
6626: border: 1px solid black;
6627: margin: 2px;
6628: }
6629:
1.924 bisitz 6630: table#LC_menubuttons {
1.345 albertel 6631: width: 100%;
6632: background: $pgbg;
1.392 albertel 6633: border: 2px;
1.402 albertel 6634: border-collapse: separate;
1.803 bisitz 6635: padding: 0;
1.345 albertel 6636: }
1.392 albertel 6637:
1.801 tempelho 6638: table#LC_title_bar a {
6639: color: $fontmenu;
6640: }
1.836 bisitz 6641:
1.807 droeschl 6642: table#LC_title_bar {
1.819 tempelho 6643: clear: both;
1.836 bisitz 6644: display: none;
1.807 droeschl 6645: }
6646:
1.795 www 6647: table#LC_title_bar,
1.933 droeschl 6648: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6649: table#LC_title_bar.LC_with_remote {
1.359 albertel 6650: width: 100%;
1.392 albertel 6651: border-color: $pgbg;
6652: border-style: solid;
6653: border-width: $border;
1.379 albertel 6654: background: $pgbg;
1.801 tempelho 6655: color: $fontmenu;
1.392 albertel 6656: border-collapse: collapse;
1.803 bisitz 6657: padding: 0;
1.819 tempelho 6658: margin: 0;
1.359 albertel 6659: }
1.795 www 6660:
1.933 droeschl 6661: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6662: margin: 0;
6663: padding: 0;
1.933 droeschl 6664: position: relative;
6665: list-style: none;
1.913 droeschl 6666: }
1.933 droeschl 6667: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6668: display: inline;
6669: }
1.933 droeschl 6670:
6671: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6672: padding: 0;
1.933 droeschl 6673: margin: 0;
6674: float: left;
1.913 droeschl 6675: }
1.933 droeschl 6676: .LC_breadcrumb_tools_tools {
6677: padding: 0;
6678: margin: 0;
1.913 droeschl 6679: float: right;
6680: }
6681:
1.359 albertel 6682: table#LC_title_bar td {
6683: background: $tabbg;
6684: }
1.795 www 6685:
1.911 bisitz 6686: table#LC_menubuttons img {
1.803 bisitz 6687: border: none;
1.346 albertel 6688: }
1.795 www 6689:
1.842 droeschl 6690: .LC_breadcrumbs_component {
1.911 bisitz 6691: float: right;
6692: margin: 0 1em;
1.357 albertel 6693: }
1.842 droeschl 6694: .LC_breadcrumbs_component img {
1.911 bisitz 6695: vertical-align: middle;
1.777 tempelho 6696: }
1.795 www 6697:
1.1075.2.108 raeburn 6698: .LC_breadcrumbs_hoverable {
6699: background: $sidebg;
6700: }
6701:
1.383 albertel 6702: td.LC_table_cell_checkbox {
6703: text-align: center;
6704: }
1.795 www 6705:
6706: .LC_fontsize_small {
1.911 bisitz 6707: font-size: 70%;
1.705 tempelho 6708: }
6709:
1.844 bisitz 6710: #LC_breadcrumbs {
1.911 bisitz 6711: clear:both;
6712: background: $sidebg;
6713: border-bottom: 1px solid $lg_border_color;
6714: line-height: 2.5em;
1.933 droeschl 6715: overflow: hidden;
1.911 bisitz 6716: margin: 0;
6717: padding: 0;
1.995 raeburn 6718: text-align: left;
1.819 tempelho 6719: }
1.862 bisitz 6720:
1.1075.2.16 raeburn 6721: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6722: clear:both;
6723: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6724: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6725: margin: 0 0 10px 0;
1.966 bisitz 6726: padding: 3px;
1.995 raeburn 6727: text-align: left;
1.822 bisitz 6728: }
6729:
1.795 www 6730: .LC_fontsize_medium {
1.911 bisitz 6731: font-size: 85%;
1.705 tempelho 6732: }
6733:
1.795 www 6734: .LC_fontsize_large {
1.911 bisitz 6735: font-size: 120%;
1.705 tempelho 6736: }
6737:
1.346 albertel 6738: .LC_menubuttons_inline_text {
6739: color: $font;
1.698 harmsja 6740: font-size: 90%;
1.701 harmsja 6741: padding-left:3px;
1.346 albertel 6742: }
6743:
1.934 droeschl 6744: .LC_menubuttons_inline_text img{
6745: vertical-align: middle;
6746: }
6747:
1.1051 www 6748: li.LC_menubuttons_inline_text img {
1.951 onken 6749: cursor:pointer;
1.1002 droeschl 6750: text-decoration: none;
1.951 onken 6751: }
6752:
1.526 www 6753: .LC_menubuttons_link {
6754: text-decoration: none;
6755: }
1.795 www 6756:
1.522 albertel 6757: .LC_menubuttons_category {
1.521 www 6758: color: $font;
1.526 www 6759: background: $pgbg;
1.521 www 6760: font-size: larger;
6761: font-weight: bold;
6762: }
6763:
1.346 albertel 6764: td.LC_menubuttons_text {
1.911 bisitz 6765: color: $font;
1.346 albertel 6766: }
1.706 harmsja 6767:
1.346 albertel 6768: .LC_current_location {
6769: background: $tabbg;
6770: }
1.795 www 6771:
1.1075.2.134 raeburn 6772: td.LC_zero_height {
6773: line-height: 0;
6774: cellpadding: 0;
6775: }
6776:
1.938 bisitz 6777: table.LC_data_table {
1.347 albertel 6778: border: 1px solid #000000;
1.402 albertel 6779: border-collapse: separate;
1.426 albertel 6780: border-spacing: 1px;
1.610 albertel 6781: background: $pgbg;
1.347 albertel 6782: }
1.795 www 6783:
1.422 albertel 6784: .LC_data_table_dense {
6785: font-size: small;
6786: }
1.795 www 6787:
1.507 raeburn 6788: table.LC_nested_outer {
6789: border: 1px solid #000000;
1.589 raeburn 6790: border-collapse: collapse;
1.803 bisitz 6791: border-spacing: 0;
1.507 raeburn 6792: width: 100%;
6793: }
1.795 www 6794:
1.879 raeburn 6795: table.LC_innerpickbox,
1.507 raeburn 6796: table.LC_nested {
1.803 bisitz 6797: border: none;
1.589 raeburn 6798: border-collapse: collapse;
1.803 bisitz 6799: border-spacing: 0;
1.507 raeburn 6800: width: 100%;
6801: }
1.795 www 6802:
1.911 bisitz 6803: table.LC_data_table tr th,
6804: table.LC_calendar tr th,
1.879 raeburn 6805: table.LC_prior_tries tr th,
6806: table.LC_innerpickbox tr th {
1.349 albertel 6807: font-weight: bold;
6808: background-color: $data_table_head;
1.801 tempelho 6809: color:$fontmenu;
1.701 harmsja 6810: font-size:90%;
1.347 albertel 6811: }
1.795 www 6812:
1.879 raeburn 6813: table.LC_innerpickbox tr th,
6814: table.LC_innerpickbox tr td {
6815: vertical-align: top;
6816: }
6817:
1.711 raeburn 6818: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6819: background-color: #CCCCCC;
1.711 raeburn 6820: font-weight: bold;
6821: text-align: left;
6822: }
1.795 www 6823:
1.912 bisitz 6824: table.LC_data_table tr.LC_odd_row > td {
6825: background-color: $data_table_light;
6826: padding: 2px;
6827: vertical-align: top;
6828: }
6829:
1.809 bisitz 6830: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6831: background-color: $data_table_light;
1.912 bisitz 6832: vertical-align: top;
6833: }
6834:
6835: table.LC_data_table tr.LC_even_row > td {
6836: background-color: $data_table_dark;
1.425 albertel 6837: padding: 2px;
1.900 bisitz 6838: vertical-align: top;
1.347 albertel 6839: }
1.795 www 6840:
1.809 bisitz 6841: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6842: background-color: $data_table_dark;
1.900 bisitz 6843: vertical-align: top;
1.347 albertel 6844: }
1.795 www 6845:
1.425 albertel 6846: table.LC_data_table tr.LC_data_table_highlight td {
6847: background-color: $data_table_darker;
6848: }
1.795 www 6849:
1.639 raeburn 6850: table.LC_data_table tr td.LC_leftcol_header {
6851: background-color: $data_table_head;
6852: font-weight: bold;
6853: }
1.795 www 6854:
1.451 albertel 6855: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6856: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6857: font-weight: bold;
6858: font-style: italic;
6859: text-align: center;
6860: padding: 8px;
1.347 albertel 6861: }
1.795 www 6862:
1.1075.2.30 raeburn 6863: table.LC_data_table tr.LC_empty_row td,
6864: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6865: background-color: $sidebg;
6866: }
6867:
6868: table.LC_nested tr.LC_empty_row td {
6869: background-color: #FFFFFF;
6870: }
6871:
1.890 droeschl 6872: table.LC_caption {
6873: }
6874:
1.507 raeburn 6875: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6876: padding: 4ex
6877: }
1.795 www 6878:
1.507 raeburn 6879: table.LC_nested_outer tr th {
6880: font-weight: bold;
1.801 tempelho 6881: color:$fontmenu;
1.507 raeburn 6882: background-color: $data_table_head;
1.701 harmsja 6883: font-size: small;
1.507 raeburn 6884: border-bottom: 1px solid #000000;
6885: }
1.795 www 6886:
1.507 raeburn 6887: table.LC_nested_outer tr td.LC_subheader {
6888: background-color: $data_table_head;
6889: font-weight: bold;
6890: font-size: small;
6891: border-bottom: 1px solid #000000;
6892: text-align: right;
1.451 albertel 6893: }
1.795 www 6894:
1.507 raeburn 6895: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6896: background-color: #CCCCCC;
1.451 albertel 6897: font-weight: bold;
6898: font-size: small;
1.507 raeburn 6899: text-align: center;
6900: }
1.795 www 6901:
1.589 raeburn 6902: table.LC_nested tr.LC_info_row td.LC_left_item,
6903: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6904: text-align: left;
1.451 albertel 6905: }
1.795 www 6906:
1.507 raeburn 6907: table.LC_nested td {
1.735 bisitz 6908: background-color: #FFFFFF;
1.451 albertel 6909: font-size: small;
1.507 raeburn 6910: }
1.795 www 6911:
1.507 raeburn 6912: table.LC_nested_outer tr th.LC_right_item,
6913: table.LC_nested tr.LC_info_row td.LC_right_item,
6914: table.LC_nested tr.LC_odd_row td.LC_right_item,
6915: table.LC_nested tr td.LC_right_item {
1.451 albertel 6916: text-align: right;
6917: }
6918:
1.507 raeburn 6919: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6920: background-color: #EEEEEE;
1.451 albertel 6921: }
6922:
1.473 raeburn 6923: table.LC_createuser {
6924: }
6925:
6926: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6927: font-size: small;
1.473 raeburn 6928: }
6929:
6930: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6931: background-color: #CCCCCC;
1.473 raeburn 6932: font-weight: bold;
6933: text-align: center;
6934: }
6935:
1.349 albertel 6936: table.LC_calendar {
6937: border: 1px solid #000000;
6938: border-collapse: collapse;
1.917 raeburn 6939: width: 98%;
1.349 albertel 6940: }
1.795 www 6941:
1.349 albertel 6942: table.LC_calendar_pickdate {
6943: font-size: xx-small;
6944: }
1.795 www 6945:
1.349 albertel 6946: table.LC_calendar tr td {
6947: border: 1px solid #000000;
6948: vertical-align: top;
1.917 raeburn 6949: width: 14%;
1.349 albertel 6950: }
1.795 www 6951:
1.349 albertel 6952: table.LC_calendar tr td.LC_calendar_day_empty {
6953: background-color: $data_table_dark;
6954: }
1.795 www 6955:
1.779 bisitz 6956: table.LC_calendar tr td.LC_calendar_day_current {
6957: background-color: $data_table_highlight;
1.777 tempelho 6958: }
1.795 www 6959:
1.938 bisitz 6960: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6961: background-color: $mail_new;
6962: }
1.795 www 6963:
1.938 bisitz 6964: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6965: background-color: $mail_new_hover;
6966: }
1.795 www 6967:
1.938 bisitz 6968: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6969: background-color: $mail_read;
6970: }
1.795 www 6971:
1.938 bisitz 6972: /*
6973: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6974: background-color: $mail_read_hover;
6975: }
1.938 bisitz 6976: */
1.795 www 6977:
1.938 bisitz 6978: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6979: background-color: $mail_replied;
6980: }
1.795 www 6981:
1.938 bisitz 6982: /*
6983: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6984: background-color: $mail_replied_hover;
6985: }
1.938 bisitz 6986: */
1.795 www 6987:
1.938 bisitz 6988: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6989: background-color: $mail_other;
6990: }
1.795 www 6991:
1.938 bisitz 6992: /*
6993: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6994: background-color: $mail_other_hover;
6995: }
1.938 bisitz 6996: */
1.494 raeburn 6997:
1.777 tempelho 6998: table.LC_data_table tr > td.LC_browser_file,
6999: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 7000: background: #AAEE77;
1.389 albertel 7001: }
1.795 www 7002:
1.777 tempelho 7003: table.LC_data_table tr > td.LC_browser_file_locked,
7004: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 7005: background: #FFAA99;
1.387 albertel 7006: }
1.795 www 7007:
1.777 tempelho 7008: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 7009: background: #888888;
1.779 bisitz 7010: }
1.795 www 7011:
1.777 tempelho 7012: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 7013: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 7014: background: #F8F866;
1.777 tempelho 7015: }
1.795 www 7016:
1.696 bisitz 7017: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 7018: background: #E0E8FF;
1.387 albertel 7019: }
1.696 bisitz 7020:
1.707 bisitz 7021: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 7022: /* background: #77FF77; */
1.707 bisitz 7023: }
1.795 www 7024:
1.707 bisitz 7025: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 7026: border-right: 8px solid #FFFF77;
1.707 bisitz 7027: }
1.795 www 7028:
1.707 bisitz 7029: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 7030: border-right: 8px solid #FFAA77;
1.707 bisitz 7031: }
1.795 www 7032:
1.707 bisitz 7033: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 7034: border-right: 8px solid #FF7777;
1.707 bisitz 7035: }
1.795 www 7036:
1.707 bisitz 7037: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 7038: border-right: 8px solid #AAFF77;
1.707 bisitz 7039: }
1.795 www 7040:
1.707 bisitz 7041: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 7042: border-right: 8px solid #11CC55;
1.707 bisitz 7043: }
7044:
1.388 albertel 7045: span.LC_current_location {
1.701 harmsja 7046: font-size:larger;
1.388 albertel 7047: background: $pgbg;
7048: }
1.387 albertel 7049:
1.1029 www 7050: span.LC_current_nav_location {
7051: font-weight:bold;
7052: background: $sidebg;
7053: }
7054:
1.395 albertel 7055: span.LC_parm_menu_item {
7056: font-size: larger;
7057: }
1.795 www 7058:
1.395 albertel 7059: span.LC_parm_scope_all {
7060: color: red;
7061: }
1.795 www 7062:
1.395 albertel 7063: span.LC_parm_scope_folder {
7064: color: green;
7065: }
1.795 www 7066:
1.395 albertel 7067: span.LC_parm_scope_resource {
7068: color: orange;
7069: }
1.795 www 7070:
1.395 albertel 7071: span.LC_parm_part {
7072: color: blue;
7073: }
1.795 www 7074:
1.911 bisitz 7075: span.LC_parm_folder,
7076: span.LC_parm_symb {
1.395 albertel 7077: font-size: x-small;
7078: font-family: $mono;
7079: color: #AAAAAA;
7080: }
7081:
1.977 bisitz 7082: ul.LC_parm_parmlist li {
7083: display: inline-block;
7084: padding: 0.3em 0.8em;
7085: vertical-align: top;
7086: width: 150px;
7087: border-top:1px solid $lg_border_color;
7088: }
7089:
1.795 www 7090: td.LC_parm_overview_level_menu,
7091: td.LC_parm_overview_map_menu,
7092: td.LC_parm_overview_parm_selectors,
7093: td.LC_parm_overview_restrictions {
1.396 albertel 7094: border: 1px solid black;
7095: border-collapse: collapse;
7096: }
1.795 www 7097:
1.396 albertel 7098: table.LC_parm_overview_restrictions td {
7099: border-width: 1px 4px 1px 4px;
7100: border-style: solid;
7101: border-color: $pgbg;
7102: text-align: center;
7103: }
1.795 www 7104:
1.396 albertel 7105: table.LC_parm_overview_restrictions th {
7106: background: $tabbg;
7107: border-width: 1px 4px 1px 4px;
7108: border-style: solid;
7109: border-color: $pgbg;
7110: }
1.795 www 7111:
1.398 albertel 7112: table#LC_helpmenu {
1.803 bisitz 7113: border: none;
1.398 albertel 7114: height: 55px;
1.803 bisitz 7115: border-spacing: 0;
1.398 albertel 7116: }
7117:
7118: table#LC_helpmenu fieldset legend {
7119: font-size: larger;
7120: }
1.795 www 7121:
1.397 albertel 7122: table#LC_helpmenu_links {
7123: width: 100%;
7124: border: 1px solid black;
7125: background: $pgbg;
1.803 bisitz 7126: padding: 0;
1.397 albertel 7127: border-spacing: 1px;
7128: }
1.795 www 7129:
1.397 albertel 7130: table#LC_helpmenu_links tr td {
7131: padding: 1px;
7132: background: $tabbg;
1.399 albertel 7133: text-align: center;
7134: font-weight: bold;
1.397 albertel 7135: }
1.396 albertel 7136:
1.795 www 7137: table#LC_helpmenu_links a:link,
7138: table#LC_helpmenu_links a:visited,
1.397 albertel 7139: table#LC_helpmenu_links a:active {
7140: text-decoration: none;
7141: color: $font;
7142: }
1.795 www 7143:
1.397 albertel 7144: table#LC_helpmenu_links a:hover {
7145: text-decoration: underline;
7146: color: $vlink;
7147: }
1.396 albertel 7148:
1.417 albertel 7149: .LC_chrt_popup_exists {
7150: border: 1px solid #339933;
7151: margin: -1px;
7152: }
1.795 www 7153:
1.417 albertel 7154: .LC_chrt_popup_up {
7155: border: 1px solid yellow;
7156: margin: -1px;
7157: }
1.795 www 7158:
1.417 albertel 7159: .LC_chrt_popup {
7160: border: 1px solid #8888FF;
7161: background: #CCCCFF;
7162: }
1.795 www 7163:
1.421 albertel 7164: table.LC_pick_box {
7165: border-collapse: separate;
7166: background: white;
7167: border: 1px solid black;
7168: border-spacing: 1px;
7169: }
1.795 www 7170:
1.421 albertel 7171: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7172: background: $sidebg;
1.421 albertel 7173: font-weight: bold;
1.900 bisitz 7174: text-align: left;
1.740 bisitz 7175: vertical-align: top;
1.421 albertel 7176: width: 184px;
7177: padding: 8px;
7178: }
1.795 www 7179:
1.579 raeburn 7180: table.LC_pick_box td.LC_pick_box_value {
7181: text-align: left;
7182: padding: 8px;
7183: }
1.795 www 7184:
1.579 raeburn 7185: table.LC_pick_box td.LC_pick_box_select {
7186: text-align: left;
7187: padding: 8px;
7188: }
1.795 www 7189:
1.424 albertel 7190: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7191: padding: 0;
1.421 albertel 7192: height: 1px;
7193: background: black;
7194: }
1.795 www 7195:
1.421 albertel 7196: table.LC_pick_box td.LC_pick_box_submit {
7197: text-align: right;
7198: }
1.795 www 7199:
1.579 raeburn 7200: table.LC_pick_box td.LC_evenrow_value {
7201: text-align: left;
7202: padding: 8px;
7203: background-color: $data_table_light;
7204: }
1.795 www 7205:
1.579 raeburn 7206: table.LC_pick_box td.LC_oddrow_value {
7207: text-align: left;
7208: padding: 8px;
7209: background-color: $data_table_light;
7210: }
1.795 www 7211:
1.579 raeburn 7212: span.LC_helpform_receipt_cat {
7213: font-weight: bold;
7214: }
1.795 www 7215:
1.424 albertel 7216: table.LC_group_priv_box {
7217: background: white;
7218: border: 1px solid black;
7219: border-spacing: 1px;
7220: }
1.795 www 7221:
1.424 albertel 7222: table.LC_group_priv_box td.LC_pick_box_title {
7223: background: $tabbg;
7224: font-weight: bold;
7225: text-align: right;
7226: width: 184px;
7227: }
1.795 www 7228:
1.424 albertel 7229: table.LC_group_priv_box td.LC_groups_fixed {
7230: background: $data_table_light;
7231: text-align: center;
7232: }
1.795 www 7233:
1.424 albertel 7234: table.LC_group_priv_box td.LC_groups_optional {
7235: background: $data_table_dark;
7236: text-align: center;
7237: }
1.795 www 7238:
1.424 albertel 7239: table.LC_group_priv_box td.LC_groups_functionality {
7240: background: $data_table_darker;
7241: text-align: center;
7242: font-weight: bold;
7243: }
1.795 www 7244:
1.424 albertel 7245: table.LC_group_priv td {
7246: text-align: left;
1.803 bisitz 7247: padding: 0;
1.424 albertel 7248: }
7249:
7250: .LC_navbuttons {
7251: margin: 2ex 0ex 2ex 0ex;
7252: }
1.795 www 7253:
1.423 albertel 7254: .LC_topic_bar {
7255: font-weight: bold;
7256: background: $tabbg;
1.918 wenzelju 7257: margin: 1em 0em 1em 2em;
1.805 bisitz 7258: padding: 3px;
1.918 wenzelju 7259: font-size: 1.2em;
1.423 albertel 7260: }
1.795 www 7261:
1.423 albertel 7262: .LC_topic_bar span {
1.918 wenzelju 7263: left: 0.5em;
7264: position: absolute;
1.423 albertel 7265: vertical-align: middle;
1.918 wenzelju 7266: font-size: 1.2em;
1.423 albertel 7267: }
1.795 www 7268:
1.423 albertel 7269: table.LC_course_group_status {
7270: margin: 20px;
7271: }
1.795 www 7272:
1.423 albertel 7273: table.LC_status_selector td {
7274: vertical-align: top;
7275: text-align: center;
1.424 albertel 7276: padding: 4px;
7277: }
1.795 www 7278:
1.599 albertel 7279: div.LC_feedback_link {
1.616 albertel 7280: clear: both;
1.829 kalberla 7281: background: $sidebg;
1.779 bisitz 7282: width: 100%;
1.829 kalberla 7283: padding-bottom: 10px;
7284: border: 1px $tabbg solid;
1.833 kalberla 7285: height: 22px;
7286: line-height: 22px;
7287: padding-top: 5px;
7288: }
7289:
7290: div.LC_feedback_link img {
7291: height: 22px;
1.867 kalberla 7292: vertical-align:middle;
1.829 kalberla 7293: }
7294:
1.911 bisitz 7295: div.LC_feedback_link a {
1.829 kalberla 7296: text-decoration: none;
1.489 raeburn 7297: }
1.795 www 7298:
1.867 kalberla 7299: div.LC_comblock {
1.911 bisitz 7300: display:inline;
1.867 kalberla 7301: color:$font;
7302: font-size:90%;
7303: }
7304:
7305: div.LC_feedback_link div.LC_comblock {
7306: padding-left:5px;
7307: }
7308:
7309: div.LC_feedback_link div.LC_comblock a {
7310: color:$font;
7311: }
7312:
1.489 raeburn 7313: span.LC_feedback_link {
1.858 bisitz 7314: /* background: $feedback_link_bg; */
1.599 albertel 7315: font-size: larger;
7316: }
1.795 www 7317:
1.599 albertel 7318: span.LC_message_link {
1.858 bisitz 7319: /* background: $feedback_link_bg; */
1.599 albertel 7320: font-size: larger;
7321: position: absolute;
7322: right: 1em;
1.489 raeburn 7323: }
1.421 albertel 7324:
1.515 albertel 7325: table.LC_prior_tries {
1.524 albertel 7326: border: 1px solid #000000;
7327: border-collapse: separate;
7328: border-spacing: 1px;
1.515 albertel 7329: }
1.523 albertel 7330:
1.515 albertel 7331: table.LC_prior_tries td {
1.524 albertel 7332: padding: 2px;
1.515 albertel 7333: }
1.523 albertel 7334:
7335: .LC_answer_correct {
1.795 www 7336: background: lightgreen;
7337: color: darkgreen;
7338: padding: 6px;
1.523 albertel 7339: }
1.795 www 7340:
1.523 albertel 7341: .LC_answer_charged_try {
1.797 www 7342: background: #FFAAAA;
1.795 www 7343: color: darkred;
7344: padding: 6px;
1.523 albertel 7345: }
1.795 www 7346:
1.779 bisitz 7347: .LC_answer_not_charged_try,
1.523 albertel 7348: .LC_answer_no_grade,
7349: .LC_answer_late {
1.795 www 7350: background: lightyellow;
1.523 albertel 7351: color: black;
1.795 www 7352: padding: 6px;
1.523 albertel 7353: }
1.795 www 7354:
1.523 albertel 7355: .LC_answer_previous {
1.795 www 7356: background: lightblue;
7357: color: darkblue;
7358: padding: 6px;
1.523 albertel 7359: }
1.795 www 7360:
1.779 bisitz 7361: .LC_answer_no_message {
1.777 tempelho 7362: background: #FFFFFF;
7363: color: black;
1.795 www 7364: padding: 6px;
1.779 bisitz 7365: }
1.795 www 7366:
1.1075.2.140 raeburn 7367: .LC_answer_unknown,
7368: .LC_answer_warning {
1.779 bisitz 7369: background: orange;
7370: color: black;
1.795 www 7371: padding: 6px;
1.777 tempelho 7372: }
1.795 www 7373:
1.529 albertel 7374: span.LC_prior_numerical,
7375: span.LC_prior_string,
7376: span.LC_prior_custom,
7377: span.LC_prior_reaction,
7378: span.LC_prior_math {
1.925 bisitz 7379: font-family: $mono;
1.523 albertel 7380: white-space: pre;
7381: }
7382:
1.525 albertel 7383: span.LC_prior_string {
1.925 bisitz 7384: font-family: $mono;
1.525 albertel 7385: white-space: pre;
7386: }
7387:
1.523 albertel 7388: table.LC_prior_option {
7389: width: 100%;
7390: border-collapse: collapse;
7391: }
1.795 www 7392:
1.911 bisitz 7393: table.LC_prior_rank,
1.795 www 7394: table.LC_prior_match {
1.528 albertel 7395: border-collapse: collapse;
7396: }
1.795 www 7397:
1.528 albertel 7398: table.LC_prior_option tr td,
7399: table.LC_prior_rank tr td,
7400: table.LC_prior_match tr td {
1.524 albertel 7401: border: 1px solid #000000;
1.515 albertel 7402: }
7403:
1.855 bisitz 7404: .LC_nobreak {
1.544 albertel 7405: white-space: nowrap;
1.519 raeburn 7406: }
7407:
1.576 raeburn 7408: span.LC_cusr_emph {
7409: font-style: italic;
7410: }
7411:
1.633 raeburn 7412: span.LC_cusr_subheading {
7413: font-weight: normal;
7414: font-size: 85%;
7415: }
7416:
1.861 bisitz 7417: div.LC_docs_entry_move {
1.859 bisitz 7418: border: 1px solid #BBBBBB;
1.545 albertel 7419: background: #DDDDDD;
1.861 bisitz 7420: width: 22px;
1.859 bisitz 7421: padding: 1px;
7422: margin: 0;
1.545 albertel 7423: }
7424:
1.861 bisitz 7425: table.LC_data_table tr > td.LC_docs_entry_commands,
7426: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7427: font-size: x-small;
7428: }
1.795 www 7429:
1.861 bisitz 7430: .LC_docs_entry_parameter {
7431: white-space: nowrap;
7432: }
7433:
1.544 albertel 7434: .LC_docs_copy {
1.545 albertel 7435: color: #000099;
1.544 albertel 7436: }
1.795 www 7437:
1.544 albertel 7438: .LC_docs_cut {
1.545 albertel 7439: color: #550044;
1.544 albertel 7440: }
1.795 www 7441:
1.544 albertel 7442: .LC_docs_rename {
1.545 albertel 7443: color: #009900;
1.544 albertel 7444: }
1.795 www 7445:
1.544 albertel 7446: .LC_docs_remove {
1.545 albertel 7447: color: #990000;
7448: }
7449:
1.1075.2.134 raeburn 7450: .LC_domprefs_email,
1.547 albertel 7451: .LC_docs_reinit_warn,
7452: .LC_docs_ext_edit {
7453: font-size: x-small;
7454: }
7455:
1.545 albertel 7456: table.LC_docs_adddocs td,
7457: table.LC_docs_adddocs th {
7458: border: 1px solid #BBBBBB;
7459: padding: 4px;
7460: background: #DDDDDD;
1.543 albertel 7461: }
7462:
1.584 albertel 7463: table.LC_sty_begin {
7464: background: #BBFFBB;
7465: }
1.795 www 7466:
1.584 albertel 7467: table.LC_sty_end {
7468: background: #FFBBBB;
7469: }
7470:
1.589 raeburn 7471: table.LC_double_column {
1.803 bisitz 7472: border-width: 0;
1.589 raeburn 7473: border-collapse: collapse;
7474: width: 100%;
7475: padding: 2px;
7476: }
7477:
7478: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7479: top: 2px;
1.589 raeburn 7480: left: 2px;
7481: width: 47%;
7482: vertical-align: top;
7483: }
7484:
7485: table.LC_double_column tr td.LC_right_col {
7486: top: 2px;
1.779 bisitz 7487: right: 2px;
1.589 raeburn 7488: width: 47%;
7489: vertical-align: top;
7490: }
7491:
1.591 raeburn 7492: div.LC_left_float {
7493: float: left;
7494: padding-right: 5%;
1.597 albertel 7495: padding-bottom: 4px;
1.591 raeburn 7496: }
7497:
7498: div.LC_clear_float_header {
1.597 albertel 7499: padding-bottom: 2px;
1.591 raeburn 7500: }
7501:
7502: div.LC_clear_float_footer {
1.597 albertel 7503: padding-top: 10px;
1.591 raeburn 7504: clear: both;
7505: }
7506:
1.597 albertel 7507: div.LC_grade_show_user {
1.941 bisitz 7508: /* border-left: 5px solid $sidebg; */
7509: border-top: 5px solid #000000;
7510: margin: 50px 0 0 0;
1.936 bisitz 7511: padding: 15px 0 5px 10px;
1.597 albertel 7512: }
1.795 www 7513:
1.936 bisitz 7514: div.LC_grade_show_user_odd_row {
1.941 bisitz 7515: /* border-left: 5px solid #000000; */
7516: }
7517:
7518: div.LC_grade_show_user div.LC_Box {
7519: margin-right: 50px;
1.597 albertel 7520: }
7521:
7522: div.LC_grade_submissions,
7523: div.LC_grade_message_center,
1.936 bisitz 7524: div.LC_grade_info_links {
1.597 albertel 7525: margin: 5px;
7526: width: 99%;
7527: background: #FFFFFF;
7528: }
1.795 www 7529:
1.597 albertel 7530: div.LC_grade_submissions_header,
1.936 bisitz 7531: div.LC_grade_message_center_header {
1.705 tempelho 7532: font-weight: bold;
7533: font-size: large;
1.597 albertel 7534: }
1.795 www 7535:
1.597 albertel 7536: div.LC_grade_submissions_body,
1.936 bisitz 7537: div.LC_grade_message_center_body {
1.597 albertel 7538: border: 1px solid black;
7539: width: 99%;
7540: background: #FFFFFF;
7541: }
1.795 www 7542:
1.613 albertel 7543: table.LC_scantron_action {
7544: width: 100%;
7545: }
1.795 www 7546:
1.613 albertel 7547: table.LC_scantron_action tr th {
1.698 harmsja 7548: font-weight:bold;
7549: font-style:normal;
1.613 albertel 7550: }
1.795 www 7551:
1.779 bisitz 7552: .LC_edit_problem_header,
1.614 albertel 7553: div.LC_edit_problem_footer {
1.705 tempelho 7554: font-weight: normal;
7555: font-size: medium;
1.602 albertel 7556: margin: 2px;
1.1060 bisitz 7557: background-color: $sidebg;
1.600 albertel 7558: }
1.795 www 7559:
1.600 albertel 7560: div.LC_edit_problem_header,
1.602 albertel 7561: div.LC_edit_problem_header div,
1.614 albertel 7562: div.LC_edit_problem_footer,
7563: div.LC_edit_problem_footer div,
1.602 albertel 7564: div.LC_edit_problem_editxml_header,
7565: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 7566: z-index: 100;
1.600 albertel 7567: }
1.795 www 7568:
1.600 albertel 7569: div.LC_edit_problem_header_title {
1.705 tempelho 7570: font-weight: bold;
7571: font-size: larger;
1.602 albertel 7572: background: $tabbg;
7573: padding: 3px;
1.1060 bisitz 7574: margin: 0 0 5px 0;
1.602 albertel 7575: }
1.795 www 7576:
1.602 albertel 7577: table.LC_edit_problem_header_title {
7578: width: 100%;
1.600 albertel 7579: background: $tabbg;
1.602 albertel 7580: }
7581:
1.1075.2.112 raeburn 7582: div.LC_edit_actionbar {
7583: background-color: $sidebg;
7584: margin: 0;
7585: padding: 0;
7586: line-height: 200%;
1.602 albertel 7587: }
1.795 www 7588:
1.1075.2.112 raeburn 7589: div.LC_edit_actionbar div{
7590: padding: 0;
7591: margin: 0;
7592: display: inline-block;
1.600 albertel 7593: }
1.795 www 7594:
1.1075.2.34 raeburn 7595: .LC_edit_opt {
7596: padding-left: 1em;
7597: white-space: nowrap;
7598: }
7599:
1.1075.2.57 raeburn 7600: .LC_edit_problem_latexhelper{
7601: text-align: right;
7602: }
7603:
7604: #LC_edit_problem_colorful div{
7605: margin-left: 40px;
7606: }
7607:
1.1075.2.112 raeburn 7608: #LC_edit_problem_codemirror div{
7609: margin-left: 0px;
7610: }
7611:
1.911 bisitz 7612: img.stift {
1.803 bisitz 7613: border-width: 0;
7614: vertical-align: middle;
1.677 riegler 7615: }
1.680 riegler 7616:
1.923 bisitz 7617: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7618: vertical-align: top;
1.777 tempelho 7619: }
1.795 www 7620:
1.716 raeburn 7621: div.LC_createcourse {
1.911 bisitz 7622: margin: 10px 10px 10px 10px;
1.716 raeburn 7623: }
7624:
1.917 raeburn 7625: .LC_dccid {
1.1075.2.38 raeburn 7626: float: right;
1.917 raeburn 7627: margin: 0.2em 0 0 0;
7628: padding: 0;
7629: font-size: 90%;
7630: display:none;
7631: }
7632:
1.897 wenzelju 7633: ol.LC_primary_menu a:hover,
1.721 harmsja 7634: ol#LC_MenuBreadcrumbs a:hover,
7635: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7636: ul#LC_secondary_menu a:hover,
1.721 harmsja 7637: .LC_FormSectionClearButton input:hover
1.795 www 7638: ul.LC_TabContent li:hover a {
1.952 onken 7639: color:$button_hover;
1.911 bisitz 7640: text-decoration:none;
1.693 droeschl 7641: }
7642:
1.779 bisitz 7643: h1 {
1.911 bisitz 7644: padding: 0;
7645: line-height:130%;
1.693 droeschl 7646: }
1.698 harmsja 7647:
1.911 bisitz 7648: h2,
7649: h3,
7650: h4,
7651: h5,
7652: h6 {
7653: margin: 5px 0 5px 0;
7654: padding: 0;
7655: line-height:130%;
1.693 droeschl 7656: }
1.795 www 7657:
7658: .LC_hcell {
1.911 bisitz 7659: padding:3px 15px 3px 15px;
7660: margin: 0;
7661: background-color:$tabbg;
7662: color:$fontmenu;
7663: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7664: }
1.795 www 7665:
1.840 bisitz 7666: .LC_Box > .LC_hcell {
1.911 bisitz 7667: margin: 0 -10px 10px -10px;
1.835 bisitz 7668: }
7669:
1.721 harmsja 7670: .LC_noBorder {
1.911 bisitz 7671: border: 0;
1.698 harmsja 7672: }
1.693 droeschl 7673:
1.721 harmsja 7674: .LC_FormSectionClearButton input {
1.911 bisitz 7675: background-color:transparent;
7676: border: none;
7677: cursor:pointer;
7678: text-decoration:underline;
1.693 droeschl 7679: }
1.763 bisitz 7680:
7681: .LC_help_open_topic {
1.911 bisitz 7682: color: #FFFFFF;
7683: background-color: #EEEEFF;
7684: margin: 1px;
7685: padding: 4px;
7686: border: 1px solid #000033;
7687: white-space: nowrap;
7688: /* vertical-align: middle; */
1.759 neumanie 7689: }
1.693 droeschl 7690:
1.911 bisitz 7691: dl,
7692: ul,
7693: div,
7694: fieldset {
7695: margin: 10px 10px 10px 0;
7696: /* overflow: hidden; */
1.693 droeschl 7697: }
1.795 www 7698:
1.1075.2.90 raeburn 7699: article.geogebraweb div {
7700: margin: 0;
7701: }
7702:
1.838 bisitz 7703: fieldset > legend {
1.911 bisitz 7704: font-weight: bold;
7705: padding: 0 5px 0 5px;
1.838 bisitz 7706: }
7707:
1.813 bisitz 7708: #LC_nav_bar {
1.911 bisitz 7709: float: left;
1.995 raeburn 7710: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7711: margin: 0 0 2px 0;
1.807 droeschl 7712: }
7713:
1.916 droeschl 7714: #LC_realm {
7715: margin: 0.2em 0 0 0;
7716: padding: 0;
7717: font-weight: bold;
7718: text-align: center;
1.995 raeburn 7719: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7720: }
7721:
1.911 bisitz 7722: #LC_nav_bar em {
7723: font-weight: bold;
7724: font-style: normal;
1.807 droeschl 7725: }
7726:
1.897 wenzelju 7727: ol.LC_primary_menu {
1.934 droeschl 7728: margin: 0;
1.1075.2.2 raeburn 7729: padding: 0;
1.807 droeschl 7730: }
7731:
1.852 droeschl 7732: ol#LC_PathBreadcrumbs {
1.911 bisitz 7733: margin: 0;
1.693 droeschl 7734: }
7735:
1.897 wenzelju 7736: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7737: color: RGB(80, 80, 80);
7738: vertical-align: middle;
7739: text-align: left;
7740: list-style: none;
1.1075.2.112 raeburn 7741: position: relative;
1.1075.2.2 raeburn 7742: float: left;
1.1075.2.112 raeburn 7743: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7744: line-height: 1.5em;
1.1075.2.2 raeburn 7745: }
7746:
1.1075.2.113 raeburn 7747: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7748: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7749: display: block;
7750: margin: 0;
7751: padding: 0 5px 0 10px;
7752: text-decoration: none;
7753: }
7754:
1.1075.2.112 raeburn 7755: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7756: display: inline-block;
7757: width: 95%;
7758: text-align: left;
7759: }
7760:
7761: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7762: display: inline-block;
7763: width: 5%;
7764: float: right;
7765: text-align: right;
7766: font-size: 70%;
7767: }
7768:
7769: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7770: display: none;
1.1075.2.112 raeburn 7771: width: 15em;
1.1075.2.2 raeburn 7772: background-color: $data_table_light;
1.1075.2.112 raeburn 7773: position: absolute;
7774: top: 100%;
7775: }
7776:
7777: ol.LC_primary_menu ul ul {
7778: left: 100%;
7779: top: 0;
1.1075.2.2 raeburn 7780: }
7781:
1.1075.2.112 raeburn 7782: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7783: display: block;
7784: position: absolute;
7785: margin: 0;
7786: padding: 0;
1.1075.2.5 raeburn 7787: z-index: 2;
1.1075.2.2 raeburn 7788: }
7789:
7790: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7791: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7792: font-size: 90%;
1.911 bisitz 7793: vertical-align: top;
1.1075.2.2 raeburn 7794: float: none;
1.1075.2.5 raeburn 7795: border-left: 1px solid black;
7796: border-right: 1px solid black;
1.1075.2.112 raeburn 7797: /* A dark bottom border to visualize different menu options;
7798: overwritten in the create_submenu routine for the last border-bottom of the menu */
7799: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7800: }
7801:
1.1075.2.112 raeburn 7802: ol.LC_primary_menu li li p:hover {
7803: color:$button_hover;
7804: text-decoration:none;
7805: background-color:$data_table_dark;
1.1075.2.2 raeburn 7806: }
7807:
7808: ol.LC_primary_menu li li a:hover {
7809: color:$button_hover;
7810: background-color:$data_table_dark;
1.693 droeschl 7811: }
7812:
1.1075.2.112 raeburn 7813: /* Font-size equal to the size of the predecessors*/
7814: ol.LC_primary_menu li:hover li li {
7815: font-size: 100%;
7816: }
7817:
1.897 wenzelju 7818: ol.LC_primary_menu li img {
1.911 bisitz 7819: vertical-align: bottom;
1.934 droeschl 7820: height: 1.1em;
1.1075.2.3 raeburn 7821: margin: 0.2em 0 0 0;
1.693 droeschl 7822: }
7823:
1.897 wenzelju 7824: ol.LC_primary_menu a {
1.911 bisitz 7825: color: RGB(80, 80, 80);
7826: text-decoration: none;
1.693 droeschl 7827: }
1.795 www 7828:
1.949 droeschl 7829: ol.LC_primary_menu a.LC_new_message {
7830: font-weight:bold;
7831: color: darkred;
7832: }
7833:
1.975 raeburn 7834: ol.LC_docs_parameters {
7835: margin-left: 0;
7836: padding: 0;
7837: list-style: none;
7838: }
7839:
7840: ol.LC_docs_parameters li {
7841: margin: 0;
7842: padding-right: 20px;
7843: display: inline;
7844: }
7845:
1.976 raeburn 7846: ol.LC_docs_parameters li:before {
7847: content: "\\002022 \\0020";
7848: }
7849:
7850: li.LC_docs_parameters_title {
7851: font-weight: bold;
7852: }
7853:
7854: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7855: content: "";
7856: }
7857:
1.897 wenzelju 7858: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7859: clear: right;
1.911 bisitz 7860: color: $fontmenu;
7861: background: $tabbg;
7862: list-style: none;
7863: padding: 0;
7864: margin: 0;
7865: width: 100%;
1.995 raeburn 7866: text-align: left;
1.1075.2.4 raeburn 7867: float: left;
1.808 droeschl 7868: }
7869:
1.897 wenzelju 7870: ul#LC_secondary_menu li {
1.911 bisitz 7871: font-weight: bold;
7872: line-height: 1.8em;
7873: border-right: 1px solid black;
1.1075.2.4 raeburn 7874: float: left;
7875: }
7876:
7877: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7878: background-color: $data_table_light;
7879: }
7880:
7881: ul#LC_secondary_menu li a {
7882: padding: 0 0.8em;
7883: }
7884:
7885: ul#LC_secondary_menu li ul {
7886: display: none;
7887: }
7888:
7889: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7890: display: block;
7891: position: absolute;
7892: margin: 0;
7893: padding: 0;
7894: list-style:none;
7895: float: none;
7896: background-color: $data_table_light;
1.1075.2.5 raeburn 7897: z-index: 2;
1.1075.2.10 raeburn 7898: margin-left: -1px;
1.1075.2.4 raeburn 7899: }
7900:
7901: ul#LC_secondary_menu li ul li {
7902: font-size: 90%;
7903: vertical-align: top;
7904: border-left: 1px solid black;
7905: border-right: 1px solid black;
1.1075.2.33 raeburn 7906: background-color: $data_table_light;
1.1075.2.4 raeburn 7907: list-style:none;
7908: float: none;
7909: }
7910:
7911: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7912: background-color: $data_table_dark;
1.807 droeschl 7913: }
7914:
1.847 tempelho 7915: ul.LC_TabContent {
1.911 bisitz 7916: display:block;
7917: background: $sidebg;
7918: border-bottom: solid 1px $lg_border_color;
7919: list-style:none;
1.1020 raeburn 7920: margin: -1px -10px 0 -10px;
1.911 bisitz 7921: padding: 0;
1.693 droeschl 7922: }
7923:
1.795 www 7924: ul.LC_TabContent li,
7925: ul.LC_TabContentBigger li {
1.911 bisitz 7926: float:left;
1.741 harmsja 7927: }
1.795 www 7928:
1.897 wenzelju 7929: ul#LC_secondary_menu li a {
1.911 bisitz 7930: color: $fontmenu;
7931: text-decoration: none;
1.693 droeschl 7932: }
1.795 www 7933:
1.721 harmsja 7934: ul.LC_TabContent {
1.952 onken 7935: min-height:20px;
1.721 harmsja 7936: }
1.795 www 7937:
7938: ul.LC_TabContent li {
1.911 bisitz 7939: vertical-align:middle;
1.959 onken 7940: padding: 0 16px 0 10px;
1.911 bisitz 7941: background-color:$tabbg;
7942: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7943: border-left: solid 1px $font;
1.721 harmsja 7944: }
1.795 www 7945:
1.847 tempelho 7946: ul.LC_TabContent .right {
1.911 bisitz 7947: float:right;
1.847 tempelho 7948: }
7949:
1.911 bisitz 7950: ul.LC_TabContent li a,
7951: ul.LC_TabContent li {
7952: color:rgb(47,47,47);
7953: text-decoration:none;
7954: font-size:95%;
7955: font-weight:bold;
1.952 onken 7956: min-height:20px;
7957: }
7958:
1.959 onken 7959: ul.LC_TabContent li a:hover,
7960: ul.LC_TabContent li a:focus {
1.952 onken 7961: color: $button_hover;
1.959 onken 7962: background:none;
7963: outline:none;
1.952 onken 7964: }
7965:
7966: ul.LC_TabContent li:hover {
7967: color: $button_hover;
7968: cursor:pointer;
1.721 harmsja 7969: }
1.795 www 7970:
1.911 bisitz 7971: ul.LC_TabContent li.active {
1.952 onken 7972: color: $font;
1.911 bisitz 7973: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7974: border-bottom:solid 1px #FFFFFF;
7975: cursor: default;
1.744 ehlerst 7976: }
1.795 www 7977:
1.959 onken 7978: ul.LC_TabContent li.active a {
7979: color:$font;
7980: background:#FFFFFF;
7981: outline: none;
7982: }
1.1047 raeburn 7983:
7984: ul.LC_TabContent li.goback {
7985: float: left;
7986: border-left: none;
7987: }
7988:
1.870 tempelho 7989: #maincoursedoc {
1.911 bisitz 7990: clear:both;
1.870 tempelho 7991: }
7992:
7993: ul.LC_TabContentBigger {
1.911 bisitz 7994: display:block;
7995: list-style:none;
7996: padding: 0;
1.870 tempelho 7997: }
7998:
1.795 www 7999: ul.LC_TabContentBigger li {
1.911 bisitz 8000: vertical-align:bottom;
8001: height: 30px;
8002: font-size:110%;
8003: font-weight:bold;
8004: color: #737373;
1.841 tempelho 8005: }
8006:
1.957 onken 8007: ul.LC_TabContentBigger li.active {
8008: position: relative;
8009: top: 1px;
8010: }
8011:
1.870 tempelho 8012: ul.LC_TabContentBigger li a {
1.911 bisitz 8013: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
8014: height: 30px;
8015: line-height: 30px;
8016: text-align: center;
8017: display: block;
8018: text-decoration: none;
1.958 onken 8019: outline: none;
1.741 harmsja 8020: }
1.795 www 8021:
1.870 tempelho 8022: ul.LC_TabContentBigger li.active a {
1.911 bisitz 8023: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
8024: color:$font;
1.744 ehlerst 8025: }
1.795 www 8026:
1.870 tempelho 8027: ul.LC_TabContentBigger li b {
1.911 bisitz 8028: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
8029: display: block;
8030: float: left;
8031: padding: 0 30px;
1.957 onken 8032: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 8033: }
8034:
1.956 onken 8035: ul.LC_TabContentBigger li:hover b {
8036: color:$button_hover;
8037: }
8038:
1.870 tempelho 8039: ul.LC_TabContentBigger li.active b {
1.911 bisitz 8040: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
8041: color:$font;
1.957 onken 8042: border: 0;
1.741 harmsja 8043: }
1.693 droeschl 8044:
1.870 tempelho 8045:
1.862 bisitz 8046: ul.LC_CourseBreadcrumbs {
8047: background: $sidebg;
1.1020 raeburn 8048: height: 2em;
1.862 bisitz 8049: padding-left: 10px;
1.1020 raeburn 8050: margin: 0;
1.862 bisitz 8051: list-style-position: inside;
8052: }
8053:
1.911 bisitz 8054: ol#LC_MenuBreadcrumbs,
1.862 bisitz 8055: ol#LC_PathBreadcrumbs {
1.911 bisitz 8056: padding-left: 10px;
8057: margin: 0;
1.933 droeschl 8058: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 8059: }
8060:
1.911 bisitz 8061: ol#LC_MenuBreadcrumbs li,
8062: ol#LC_PathBreadcrumbs li,
1.862 bisitz 8063: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 8064: display: inline;
1.933 droeschl 8065: white-space: normal;
1.693 droeschl 8066: }
8067:
1.823 bisitz 8068: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 8069: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 8070: text-decoration: none;
8071: font-size:90%;
1.693 droeschl 8072: }
1.795 www 8073:
1.969 droeschl 8074: ol#LC_MenuBreadcrumbs h1 {
8075: display: inline;
8076: font-size: 90%;
8077: line-height: 2.5em;
8078: margin: 0;
8079: padding: 0;
8080: }
8081:
1.795 www 8082: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 8083: text-decoration:none;
8084: font-size:100%;
8085: font-weight:bold;
1.693 droeschl 8086: }
1.795 www 8087:
1.840 bisitz 8088: .LC_Box {
1.911 bisitz 8089: border: solid 1px $lg_border_color;
8090: padding: 0 10px 10px 10px;
1.746 neumanie 8091: }
1.795 www 8092:
1.1020 raeburn 8093: .LC_DocsBox {
8094: border: solid 1px $lg_border_color;
8095: padding: 0 0 10px 10px;
8096: }
8097:
1.795 www 8098: .LC_AboutMe_Image {
1.911 bisitz 8099: float:left;
8100: margin-right:10px;
1.747 neumanie 8101: }
1.795 www 8102:
8103: .LC_Clear_AboutMe_Image {
1.911 bisitz 8104: clear:left;
1.747 neumanie 8105: }
1.795 www 8106:
1.721 harmsja 8107: dl.LC_ListStyleClean dt {
1.911 bisitz 8108: padding-right: 5px;
8109: display: table-header-group;
1.693 droeschl 8110: }
8111:
1.721 harmsja 8112: dl.LC_ListStyleClean dd {
1.911 bisitz 8113: display: table-row;
1.693 droeschl 8114: }
8115:
1.721 harmsja 8116: .LC_ListStyleClean,
8117: .LC_ListStyleSimple,
8118: .LC_ListStyleNormal,
1.795 www 8119: .LC_ListStyleSpecial {
1.911 bisitz 8120: /* display:block; */
8121: list-style-position: inside;
8122: list-style-type: none;
8123: overflow: hidden;
8124: padding: 0;
1.693 droeschl 8125: }
8126:
1.721 harmsja 8127: .LC_ListStyleSimple li,
8128: .LC_ListStyleSimple dd,
8129: .LC_ListStyleNormal li,
8130: .LC_ListStyleNormal dd,
8131: .LC_ListStyleSpecial li,
1.795 www 8132: .LC_ListStyleSpecial dd {
1.911 bisitz 8133: margin: 0;
8134: padding: 5px 5px 5px 10px;
8135: clear: both;
1.693 droeschl 8136: }
8137:
1.721 harmsja 8138: .LC_ListStyleClean li,
8139: .LC_ListStyleClean dd {
1.911 bisitz 8140: padding-top: 0;
8141: padding-bottom: 0;
1.693 droeschl 8142: }
8143:
1.721 harmsja 8144: .LC_ListStyleSimple dd,
1.795 www 8145: .LC_ListStyleSimple li {
1.911 bisitz 8146: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8147: }
8148:
1.721 harmsja 8149: .LC_ListStyleSpecial li,
8150: .LC_ListStyleSpecial dd {
1.911 bisitz 8151: list-style-type: none;
8152: background-color: RGB(220, 220, 220);
8153: margin-bottom: 4px;
1.693 droeschl 8154: }
8155:
1.721 harmsja 8156: table.LC_SimpleTable {
1.911 bisitz 8157: margin:5px;
8158: border:solid 1px $lg_border_color;
1.795 www 8159: }
1.693 droeschl 8160:
1.721 harmsja 8161: table.LC_SimpleTable tr {
1.911 bisitz 8162: padding: 0;
8163: border:solid 1px $lg_border_color;
1.693 droeschl 8164: }
1.795 www 8165:
8166: table.LC_SimpleTable thead {
1.911 bisitz 8167: background:rgb(220,220,220);
1.693 droeschl 8168: }
8169:
1.721 harmsja 8170: div.LC_columnSection {
1.911 bisitz 8171: display: block;
8172: clear: both;
8173: overflow: hidden;
8174: margin: 0;
1.693 droeschl 8175: }
8176:
1.721 harmsja 8177: div.LC_columnSection>* {
1.911 bisitz 8178: float: left;
8179: margin: 10px 20px 10px 0;
8180: overflow:hidden;
1.693 droeschl 8181: }
1.721 harmsja 8182:
1.795 www 8183: table em {
1.911 bisitz 8184: font-weight: bold;
8185: font-style: normal;
1.748 schulted 8186: }
1.795 www 8187:
1.779 bisitz 8188: table.LC_tableBrowseRes,
1.795 www 8189: table.LC_tableOfContent {
1.911 bisitz 8190: border:none;
8191: border-spacing: 1px;
8192: padding: 3px;
8193: background-color: #FFFFFF;
8194: font-size: 90%;
1.753 droeschl 8195: }
1.789 droeschl 8196:
1.911 bisitz 8197: table.LC_tableOfContent {
8198: border-collapse: collapse;
1.789 droeschl 8199: }
8200:
1.771 droeschl 8201: table.LC_tableBrowseRes a,
1.768 schulted 8202: table.LC_tableOfContent a {
1.911 bisitz 8203: background-color: transparent;
8204: text-decoration: none;
1.753 droeschl 8205: }
8206:
1.795 www 8207: table.LC_tableOfContent img {
1.911 bisitz 8208: border: none;
8209: height: 1.3em;
8210: vertical-align: text-bottom;
8211: margin-right: 0.3em;
1.753 droeschl 8212: }
1.757 schulted 8213:
1.795 www 8214: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8215: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8216: }
8217:
1.795 www 8218: a#LC_content_toolbar_everything {
1.911 bisitz 8219: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8220: }
8221:
1.795 www 8222: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8223: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8224: }
8225:
1.795 www 8226: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8227: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8228: }
8229:
1.795 www 8230: a#LC_content_toolbar_changefolder {
1.911 bisitz 8231: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8232: }
8233:
1.795 www 8234: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8235: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8236: }
8237:
1.1043 raeburn 8238: a#LC_content_toolbar_edittoplevel {
8239: background-image:url(/res/adm/pages/edittoplevel.gif);
8240: }
8241:
1.1075.2.161. .12(raeb 8242:-23): a#LC_content_toolbar_printout {
8243:-23): background-image:url(/res/adm/pages/printout.gif);
8244:-23): }
8245:-23):
1.795 www 8246: ul#LC_toolbar li a:hover {
1.911 bisitz 8247: background-position: bottom center;
1.757 schulted 8248: }
8249:
1.795 www 8250: ul#LC_toolbar {
1.911 bisitz 8251: padding: 0;
8252: margin: 2px;
8253: list-style:none;
8254: position:relative;
8255: background-color:white;
1.1075.2.9 raeburn 8256: overflow: auto;
1.757 schulted 8257: }
8258:
1.795 www 8259: ul#LC_toolbar li {
1.911 bisitz 8260: border:1px solid white;
8261: padding: 0;
8262: margin: 0;
8263: float: left;
8264: display:inline;
8265: vertical-align:middle;
1.1075.2.9 raeburn 8266: white-space: nowrap;
1.911 bisitz 8267: }
1.757 schulted 8268:
1.783 amueller 8269:
1.795 www 8270: a.LC_toolbarItem {
1.911 bisitz 8271: display:block;
8272: padding: 0;
8273: margin: 0;
8274: height: 32px;
8275: width: 32px;
8276: color:white;
8277: border: none;
8278: background-repeat:no-repeat;
8279: background-color:transparent;
1.757 schulted 8280: }
8281:
1.915 droeschl 8282: ul.LC_funclist {
8283: margin: 0;
8284: padding: 0.5em 1em 0.5em 0;
8285: }
8286:
1.933 droeschl 8287: ul.LC_funclist > li:first-child {
8288: font-weight:bold;
8289: margin-left:0.8em;
8290: }
8291:
1.915 droeschl 8292: ul.LC_funclist + ul.LC_funclist {
8293: /*
8294: left border as a seperator if we have more than
8295: one list
8296: */
8297: border-left: 1px solid $sidebg;
8298: /*
8299: this hides the left border behind the border of the
8300: outer box if element is wrapped to the next 'line'
8301: */
8302: margin-left: -1px;
8303: }
8304:
1.843 bisitz 8305: ul.LC_funclist li {
1.915 droeschl 8306: display: inline;
1.782 bisitz 8307: white-space: nowrap;
1.915 droeschl 8308: margin: 0 0 0 25px;
8309: line-height: 150%;
1.782 bisitz 8310: }
8311:
1.974 wenzelju 8312: .LC_hidden {
8313: display: none;
8314: }
8315:
1.1030 www 8316: .LCmodal-overlay {
8317: position:fixed;
8318: top:0;
8319: right:0;
8320: bottom:0;
8321: left:0;
8322: height:100%;
8323: width:100%;
8324: margin:0;
8325: padding:0;
8326: background:#999;
8327: opacity:.75;
8328: filter: alpha(opacity=75);
8329: -moz-opacity: 0.75;
8330: z-index:101;
8331: }
8332:
8333: * html .LCmodal-overlay {
8334: position: absolute;
8335: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8336: }
8337:
8338: .LCmodal-window {
8339: position:fixed;
8340: top:50%;
8341: left:50%;
8342: margin:0;
8343: padding:0;
8344: z-index:102;
8345: }
8346:
8347: * html .LCmodal-window {
8348: position:absolute;
8349: }
8350:
8351: .LCclose-window {
8352: position:absolute;
8353: width:32px;
8354: height:32px;
8355: right:8px;
8356: top:8px;
8357: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8358: text-indent:-99999px;
8359: overflow:hidden;
8360: cursor:pointer;
8361: }
8362:
1.1075.2.158 raeburn 8363: .LCisDisabled {
8364: cursor: not-allowed;
8365: opacity: 0.5;
8366: }
8367:
8368: a[aria-disabled="true"] {
8369: color: currentColor;
8370: display: inline-block; /* For IE11/ MS Edge bug */
8371: pointer-events: none;
8372: text-decoration: none;
8373: }
8374:
1.1075.2.141 raeburn 8375: pre.LC_wordwrap {
8376: white-space: pre-wrap;
8377: white-space: -moz-pre-wrap;
8378: white-space: -pre-wrap;
8379: white-space: -o-pre-wrap;
8380: word-wrap: break-word;
8381: }
8382:
1.1075.2.17 raeburn 8383: /*
8384: styles used by TTH when "Default set of options to pass to tth/m
8385: when converting TeX" in course settings has been set
8386:
8387: option passed: -t
8388:
8389: */
8390:
8391: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8392: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8393: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8394: td div.norm {line-height:normal;}
8395:
8396: /*
8397: option passed -y3
8398: */
8399:
8400: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8401: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8402: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8403:
1.1075.2.121 raeburn 8404: #LC_minitab_header {
8405: float:left;
8406: width:100%;
8407: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8408: font-size:93%;
8409: line-height:normal;
8410: margin: 0.5em 0 0.5em 0;
8411: }
8412: #LC_minitab_header ul {
8413: margin:0;
8414: padding:10px 10px 0;
8415: list-style:none;
8416: }
8417: #LC_minitab_header li {
8418: float:left;
8419: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8420: margin:0;
8421: padding:0 0 0 9px;
8422: }
8423: #LC_minitab_header a {
8424: display:block;
8425: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8426: padding:5px 15px 4px 6px;
8427: }
8428: #LC_minitab_header #LC_current_minitab {
8429: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8430: }
8431: #LC_minitab_header #LC_current_minitab a {
8432: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8433: padding-bottom:5px;
8434: }
8435:
8436:
1.343 albertel 8437: END
8438: }
8439:
1.306 albertel 8440: =pod
8441:
8442: =item * &headtag()
8443:
8444: Returns a uniform footer for LON-CAPA web pages.
8445:
1.307 albertel 8446: Inputs: $title - optional title for the head
8447: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8448: $args - optional arguments
1.319 albertel 8449: force_register - if is true call registerurl so the remote is
8450: informed
1.415 albertel 8451: redirect -> array ref of
8452: 1- seconds before redirect occurs
8453: 2- url to redirect to
8454: 3- whether the side effect should occur
1.315 albertel 8455: (side effect of setting
8456: $env{'internal.head.redirect'} to the url
1.1075.2.161. .9(raebu 8457:22): redirected to)
8458:22): 4- whether the redirect target should be
8459:22): the opener of the current (pop-up)
8460:22): window (side effect of setting
8461:22): $env{'internal.head.to_opener'} to
8462:22): 1, if true.
.10(raeb 8463:-22): 5- whether encrypt check should be skipped
1.352 albertel 8464: domain -> force to color decorate a page for a specific
8465: domain
8466: function -> force usage of a specific rolish color scheme
8467: bgcolor -> override the default page bgcolor
1.460 albertel 8468: no_auto_mt_title
8469: -> prevent &mt()ing the title arg
1.464 albertel 8470:
1.306 albertel 8471: =cut
8472:
8473: sub headtag {
1.313 albertel 8474: my ($title,$head_extra,$args) = @_;
1.306 albertel 8475:
1.363 albertel 8476: my $function = $args->{'function'} || &get_users_function();
8477: my $domain = $args->{'domain'} || &determinedomain();
8478: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 8479: my $httphost = $args->{'use_absolute'};
1.418 albertel 8480: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8481: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8482: #time(),
1.418 albertel 8483: $env{'environment.color.timestamp'},
1.363 albertel 8484: $function,$domain,$bgcolor);
8485:
1.369 www 8486: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8487:
1.308 albertel 8488: my $result =
8489: '<head>'.
1.1075.2.56 raeburn 8490: &font_settings($args);
1.319 albertel 8491:
1.1075.2.72 raeburn 8492: my $inhibitprint;
8493: if ($args->{'print_suppress'}) {
8494: $inhibitprint = &print_suppression();
8495: }
1.1064 raeburn 8496:
1.461 albertel 8497: if (!$args->{'frameset'}) {
8498: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8499: }
1.1075.2.12 raeburn 8500: if ($args->{'force_register'}) {
8501: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 8502: }
1.436 albertel 8503: if (!$args->{'no_nav_bar'}
8504: && !$args->{'only_body'}
8505: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 8506: $result .= &help_menu_js($httphost);
1.1032 www 8507: $result.=&modal_window();
1.1038 www 8508: $result.=&togglebox_script();
1.1034 www 8509: $result.=&wishlist_window();
1.1041 www 8510: $result.=&LCprogressbarUpdate_script();
1.1034 www 8511: } else {
8512: if ($args->{'add_modal'}) {
8513: $result.=&modal_window();
8514: }
8515: if ($args->{'add_wishlist'}) {
8516: $result.=&wishlist_window();
8517: }
1.1038 www 8518: if ($args->{'add_togglebox'}) {
8519: $result.=&togglebox_script();
8520: }
1.1041 www 8521: if ($args->{'add_progressbar'}) {
8522: $result.=&LCprogressbarUpdate_script();
8523: }
1.436 albertel 8524: }
1.314 albertel 8525: if (ref($args->{'redirect'})) {
1.1075.2.161. .10(raeb 8526:-22): my ($time,$url,$inhibit_continue,$to_opener,$skip_enc_check) = @{$args->{'redirect'}};
8527:-22): if (!$skip_enc_check) {
8528:-22): $url = &Apache::lonenc::check_encrypt($url);
8529:-22): }
1.414 albertel 8530: if (!$inhibit_continue) {
8531: $env{'internal.head.redirect'} = $url;
8532: }
1.1075.2.161. .9(raebu 8533:22): $result.=<<"ADDMETA";
1.313 albertel 8534: <meta http-equiv="pragma" content="no-cache" />
1.1075.2.161. .9(raebu 8535:22): ADDMETA
8536:22): if ($to_opener) {
8537:22): $env{'internal.head.to_opener'} = 1;
8538:22): my $dest = &js_escape($url);
8539:22): my $timeout = int($time * 1000);
8540:22): $result .=<<"ENDJS";
8541:22): <script type="text/javascript">
8542:22): // <![CDATA[
8543:22): function LC_To_Opener() {
8544:22): var dest = '$dest';
8545:22): if (dest != '') {
8546:22): if (window.opener != null && !window.opener.closed) {
8547:22): window.opener.location.href=dest;
8548:22): window.close();
8549:22): } else {
8550:22): window.location.href=dest;
8551:22): }
8552:22): }
8553:22): }
8554:22): \$(document).ready(function () {
8555:22): setTimeout('LC_To_Opener()',$timeout);
8556:22): });
8557:22): // ]]>
8558:22): </script>
8559:22): ENDJS
8560:22): } else {
8561:22): $result.=<<"ADDMETA";
1.344 albertel 8562: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8563: ADDMETA
1.1075.2.161. .9(raebu 8564:22): }
1.1075.2.89 raeburn 8565: } else {
8566: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8567: my $requrl = $env{'request.uri'};
8568: if ($requrl eq '') {
8569: $requrl = $ENV{'REQUEST_URI'};
8570: $requrl =~ s/\?.+$//;
8571: }
8572: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8573: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8574: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8575: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8576: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8577: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1075.2.145 raeburn 8578: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1075.2.151 raeburn 8579: my ($offload,$offloadoth);
1.1075.2.89 raeburn 8580: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8581: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1075.2.145 raeburn 8582: $offload = 1;
1.1075.2.151 raeburn 8583: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8584: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8585: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8586: $offloadoth = 1;
8587: $dom_in_use = $env{'user.domain'};
8588: }
8589: }
1.1075.2.145 raeburn 8590: }
8591: }
8592: unless ($offload) {
8593: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8594: if ($domdefs{'offloadoth'}{$lonhost}) {
8595: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8596: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8597: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8598: $offload = 1;
1.1075.2.151 raeburn 8599: $offloadoth = 1;
1.1075.2.145 raeburn 8600: $dom_in_use = $env{'user.domain'};
8601: }
1.1075.2.89 raeburn 8602: }
1.1075.2.145 raeburn 8603: }
8604: }
8605: }
8606: if ($offload) {
1.1075.2.158 raeburn 8607: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1075.2.151 raeburn 8608: if (($newserver eq '') && ($offloadoth)) {
8609: my @domains = &Apache::lonnet::current_machine_domains();
1.1075.2.161. .1(raebu 8610:21): if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
1.1075.2.151 raeburn 8611: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
8612: }
8613: }
1.1075.2.145 raeburn 8614: if (($newserver) && ($newserver ne $lonhost)) {
8615: my $numsec = 5;
8616: my $timeout = $numsec * 1000;
8617: my ($newurl,$locknum,%locks,$msg);
8618: if ($env{'request.role.adv'}) {
8619: ($locknum,%locks) = &Apache::lonnet::get_locks();
8620: }
8621: my $disable_submit = 0;
8622: if ($requrl =~ /$LONCAPA::assess_re/) {
8623: $disable_submit = 1;
8624: }
8625: if ($locknum) {
8626: my @lockinfo = sort(values(%locks));
1.1075.2.153 raeburn 8627: $msg = &mt('Once the following tasks are complete:')." \n".
1.1075.2.145 raeburn 8628: join(", ",sort(values(%locks)))."\n";
8629: if (&show_course()) {
8630: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
1.1075.2.89 raeburn 8631: } else {
1.1075.2.145 raeburn 8632: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
8633: }
8634: } else {
8635: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8636: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8637: }
8638: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8639: $newurl = '/adm/switchserver?otherserver='.$newserver;
8640: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8641: $newurl .= '&role='.$env{'request.role'};
8642: }
8643: if ($env{'request.symb'}) {
8644: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8645: if ($shownsymb =~ m{^/enc/}) {
8646: my $reqdmajor = 2;
8647: my $reqdminor = 11;
8648: my $reqdsubminor = 3;
8649: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8650: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8651: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8652: if (($major eq '' && $minor eq '') ||
8653: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8654: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8655: ($reqdsubminor > $subminor))))) {
8656: undef($shownsymb);
8657: }
1.1075.2.89 raeburn 8658: }
1.1075.2.145 raeburn 8659: if ($shownsymb) {
8660: &js_escape(\$shownsymb);
8661: $newurl .= '&symb='.$shownsymb;
1.1075.2.89 raeburn 8662: }
1.1075.2.145 raeburn 8663: } else {
8664: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8665: &js_escape(\$shownurl);
8666: $newurl .= '&origurl='.$shownurl;
1.1075.2.89 raeburn 8667: }
1.1075.2.145 raeburn 8668: }
8669: &js_escape(\$msg);
8670: $result.=<<OFFLOAD
1.1075.2.89 raeburn 8671: <meta http-equiv="pragma" content="no-cache" />
8672: <script type="text/javascript">
1.1075.2.92 raeburn 8673: // <![CDATA[
1.1075.2.89 raeburn 8674: function LC_Offload_Now() {
8675: var dest = "$newurl";
8676: if (dest != '') {
8677: window.location.href="$newurl";
8678: }
8679: }
1.1075.2.92 raeburn 8680: \$(document).ready(function () {
8681: window.alert('$msg');
8682: if ($disable_submit) {
1.1075.2.89 raeburn 8683: \$(".LC_hwk_submit").prop("disabled", true);
8684: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 8685: }
8686: setTimeout('LC_Offload_Now()', $timeout);
8687: });
8688: // ]]>
1.1075.2.89 raeburn 8689: </script>
8690: OFFLOAD
8691: }
8692: }
8693: }
8694: }
8695: }
1.313 albertel 8696: }
1.306 albertel 8697: if (!defined($title)) {
8698: $title = 'The LearningOnline Network with CAPA';
8699: }
1.460 albertel 8700: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8701: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 8702: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8703: if (!$args->{'frameset'}) {
8704: $result .= ' /';
8705: }
8706: $result .= '>'
1.1064 raeburn 8707: .$inhibitprint
1.414 albertel 8708: .$head_extra;
1.1075.2.108 raeburn 8709: my $clientmobile;
8710: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8711: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8712: } else {
8713: $clientmobile = $env{'browser.mobile'};
8714: }
8715: if ($clientmobile) {
1.1075.2.42 raeburn 8716: $result .= '
8717: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8718: <meta name="apple-mobile-web-app-capable" content="yes" />';
8719: }
1.1075.2.126 raeburn 8720: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8721: return $result.'</head>';
1.306 albertel 8722: }
8723:
8724: =pod
8725:
1.340 albertel 8726: =item * &font_settings()
8727:
8728: Returns neccessary <meta> to set the proper encoding
8729:
1.1075.2.56 raeburn 8730: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8731:
8732: =cut
8733:
8734: sub font_settings {
1.1075.2.56 raeburn 8735: my ($args) = @_;
1.340 albertel 8736: my $headerstring='';
1.1075.2.56 raeburn 8737: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8738: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 8739: $headerstring.=
1.1075.2.61 raeburn 8740: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8741: if (!$args->{'frameset'}) {
8742: $headerstring.= ' /';
8743: }
8744: $headerstring .= '>'."\n";
1.340 albertel 8745: }
8746: return $headerstring;
8747: }
8748:
1.341 albertel 8749: =pod
8750:
1.1064 raeburn 8751: =item * &print_suppression()
8752:
8753: In course context returns css which causes the body to be blank when media="print",
8754: if printout generation is unavailable for the current resource.
8755:
8756: This could be because:
8757:
8758: (a) printstartdate is in the future
8759:
8760: (b) printenddate is in the past
8761:
8762: (c) there is an active exam block with "printout"
8763: functionality blocked
8764:
8765: Users with pav, pfo or evb privileges are exempt.
8766:
8767: Inputs: none
8768:
8769: =cut
8770:
8771:
8772: sub print_suppression {
8773: my $noprint;
8774: if ($env{'request.course.id'}) {
8775: my $scope = $env{'request.course.id'};
8776: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8777: (&Apache::lonnet::allowed('pfo',$scope))) {
8778: return;
8779: }
8780: if ($env{'request.course.sec'} ne '') {
8781: $scope .= "/$env{'request.course.sec'}";
8782: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8783: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8784: return;
1.1064 raeburn 8785: }
8786: }
8787: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8788: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.158 raeburn 8789: my $clientip = &Apache::lonnet::get_requestor_ip();
8790: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 8791: if ($blocked) {
8792: my $checkrole = "cm./$cdom/$cnum";
8793: if ($env{'request.course.sec'} ne '') {
8794: $checkrole .= "/$env{'request.course.sec'}";
8795: }
8796: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8797: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8798: $noprint = 1;
8799: }
8800: }
8801: unless ($noprint) {
8802: my $symb = &Apache::lonnet::symbread();
8803: if ($symb ne '') {
8804: my $navmap = Apache::lonnavmaps::navmap->new();
8805: if (ref($navmap)) {
8806: my $res = $navmap->getBySymb($symb);
8807: if (ref($res)) {
8808: if (!$res->resprintable()) {
8809: $noprint = 1;
8810: }
8811: }
8812: }
8813: }
8814: }
8815: if ($noprint) {
8816: return <<"ENDSTYLE";
8817: <style type="text/css" media="print">
8818: body { display:none }
8819: </style>
8820: ENDSTYLE
8821: }
8822: }
8823: return;
8824: }
8825:
8826: =pod
8827:
1.341 albertel 8828: =item * &xml_begin()
8829:
8830: Returns the needed doctype and <html>
8831:
8832: Inputs: none
8833:
8834: =cut
8835:
8836: sub xml_begin {
1.1075.2.61 raeburn 8837: my ($is_frameset) = @_;
1.341 albertel 8838: my $output='';
8839:
8840: if ($env{'browser.mathml'}) {
8841: $output='<?xml version="1.0"?>'
8842: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8843: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8844:
8845: # .'<!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">] >'
8846: .'<!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">'
8847: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8848: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8849: } elsif ($is_frameset) {
8850: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8851: '<html>'."\n";
1.341 albertel 8852: } else {
1.1075.2.61 raeburn 8853: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8854: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8855: }
8856: return $output;
8857: }
1.340 albertel 8858:
8859: =pod
8860:
1.306 albertel 8861: =item * &start_page()
8862:
8863: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8864:
1.648 raeburn 8865: Inputs:
8866:
8867: =over 4
8868:
8869: $title - optional title for the page
8870:
8871: $head_extra - optional extra HTML to incude inside the <head>
8872:
8873: $args - additional optional args supported are:
8874:
8875: =over 8
8876:
8877: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8878: arg on
1.814 bisitz 8879: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8880: add_entries -> additional attributes to add to the <body>
8881: domain -> force to color decorate a page for a
1.317 albertel 8882: specific domain
1.648 raeburn 8883: function -> force usage of a specific rolish color
1.317 albertel 8884: scheme
1.648 raeburn 8885: redirect -> see &headtag()
8886: bgcolor -> override the default page bg color
8887: js_ready -> return a string ready for being used in
1.317 albertel 8888: a javascript writeln
1.648 raeburn 8889: html_encode -> return a string ready for being used in
1.320 albertel 8890: a html attribute
1.648 raeburn 8891: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8892: $forcereg arg
1.648 raeburn 8893: frameset -> if true will start with a <frameset>
1.330 albertel 8894: rather than <body>
1.648 raeburn 8895: skip_phases -> hash ref of
1.338 albertel 8896: head -> skip the <html><head> generation
8897: body -> skip all <body> generation
1.1075.2.12 raeburn 8898: no_inline_link -> if true and in remote mode, don't show the
8899: 'Switch To Inline Menu' link
1.648 raeburn 8900: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8901: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8902: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 8903: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8904: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8905: group -> includes the current group, if page is for a
8906: specific group
1.1075.2.133 raeburn 8907: use_absolute -> for request for external resource or syllabus, this
8908: will contain https://<hostname> if server uses
8909: https (as per hosts.tab), but request is for http
8910: hostname -> hostname, originally from $r->hostname(), (optional).
1.1075.2.158 raeburn 8911: links_disabled -> Links in primary and secondary menus are disabled
8912: (Can enable them once page has loaded - see lonroles.pm
8913: for an example).
1.1075.2.161. .6(raebu 8914:22): links_target -> Target for links, e.g., _parent (optional).
1.361 albertel 8915:
1.648 raeburn 8916: =back
1.460 albertel 8917:
1.648 raeburn 8918: =back
1.562 albertel 8919:
1.306 albertel 8920: =cut
8921:
8922: sub start_page {
1.309 albertel 8923: my ($title,$head_extra,$args) = @_;
1.318 albertel 8924: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8925:
1.315 albertel 8926: $env{'internal.start_page'}++;
1.1075.2.161. .1(raebu 8927:21): my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu,$menucoll,%menu);
1.964 droeschl 8928:
1.338 albertel 8929: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8930: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8931: }
1.1075.2.161. .1(raebu 8932:21):
8933:21): if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
8934:21): if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
8935:21): unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
8936:21): $args->{'no_primary_menu'} = 1;
8937:21): }
8938:21): unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
8939:21): $args->{'no_inline_menu'} = 1;
8940:21): }
8941:21): if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
8942:21): map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
8943:21): }
8944:21): } else {
8945:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8946:21): my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
8947:21): if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
8948:21): unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
8949:21): $args->{'no_primary_menu'} = 1;
8950:21): }
8951:21): unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
8952:21): $args->{'no_inline_menu'} = 1;
8953:21): }
8954:21): if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
8955:21): map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
8956:21): }
8957:21): }
8958:21): }
8959:21): ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
8960:21): $env{'course.'.$env{'request.course.id'}.'.domain'},
8961:21): $env{'course.'.$env{'request.course.id'}.'.num'});
8962:21): } elsif ($env{'request.course.id'}) {
8963:21): my $expiretime=600;
8964:21): if ((time-$env{'course.'.$env{'request.course.id'}.'.last_cache'}) > $expiretime) {
8965:21): &Apache::lonnet::coursedescription($env{'request.course.id'},{'freshen_cache' => 1});
8966:21): }
8967:21): my ($deeplinkmenu,$menuref);
8968:21): ($menucoll,$deeplinkmenu,$menuref) = &menucoll_in_effect();
8969:21): if ($menucoll) {
8970:21): if (ref($menuref) eq 'HASH') {
8971:21): %menu = %{$menuref};
8972:21): }
8973:21): if ($menu{'top'} eq 'n') {
8974:21): $args->{'no_primary_menu'} = 1;
8975:21): }
8976:21): if ($menu{'inline'} eq 'n') {
8977:21): unless (&Apache::lonnet::allowed('opa')) {
8978:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8979:21): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8980:21): my $crstype = &course_type();
8981:21): my $now = time;
8982:21): my $ccrole;
8983:21): if ($crstype eq 'Community') {
8984:21): $ccrole = 'co';
8985:21): } else {
8986:21): $ccrole = 'cc';
8987:21): }
8988:21): if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
8989:21): my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
8990:21): if ((($start) && ($start<0)) ||
8991:21): (($end) && ($end<$now)) ||
8992:21): (($start) && ($now<$start))) {
8993:21): $args->{'no_inline_menu'} = 1;
8994:21): }
8995:21): } else {
8996:21): $args->{'no_inline_menu'} = 1;
8997:21): }
8998:21): }
8999:21): }
9000:21): }
9001:21): }
.4(raebu 9002:22):
.8(raebu 9003:22): my $showncrumbs;
1.338 albertel 9004: if (! exists($args->{'skip_phases'}{'body'}) ) {
9005: if ($args->{'frameset'}) {
9006: my $attr_string = &make_attr_string($args->{'force_register'},
9007: $args->{'add_entries'});
9008: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 9009: } else {
9010: $result .=
9011: &bodytag($title,
9012: $args->{'function'}, $args->{'add_entries'},
9013: $args->{'only_body'}, $args->{'domain'},
9014: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 9015: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.161. .1(raebu 9016:21): $args, \@advtools,
.8(raebu 9017:22): $ltiscope,$ltiuri,\%ltimenu,$menucoll,\%menu,\$showncrumbs);
1.831 bisitz 9018: }
1.330 albertel 9019: }
1.338 albertel 9020:
1.315 albertel 9021: if ($args->{'js_ready'}) {
1.713 kaisler 9022: $result = &js_ready($result);
1.315 albertel 9023: }
1.320 albertel 9024: if ($args->{'html_encode'}) {
1.713 kaisler 9025: $result = &html_encode($result);
9026: }
9027:
1.813 bisitz 9028: # Preparation for new and consistent functionlist at top of screen
9029: # if ($args->{'functionlist'}) {
9030: # $result .= &build_functionlist();
9031: #}
9032:
1.964 droeschl 9033: # Don't add anything more if only_body wanted or in const space
9034: return $result if $args->{'only_body'}
9035: || $env{'request.state'} eq 'construct';
1.813 bisitz 9036:
9037: #Breadcrumbs
1.758 kaisler 9038: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
1.1075.2.161. .8(raebu 9039:22): unless ($showncrumbs) {
1.758 kaisler 9040: &Apache::lonhtmlcommon::clear_breadcrumbs();
9041: #if any br links exists, add them to the breadcrumbs
9042: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
9043: foreach my $crumb (@{$args->{'bread_crumbs'}}){
9044: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
9045: }
9046: }
1.1075.2.19 raeburn 9047: # if @advtools array contains items add then to the breadcrumbs
9048: if (@advtools > 0) {
9049: &Apache::lonmenu::advtools_crumbs(@advtools);
9050: }
1.1075.2.123 raeburn 9051: my $menulink;
9052: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
1.1075.2.161. .1(raebu 9053:21): if ((exists($args->{'bread_crumbs_nomenu'})) ||
9054:21): ($ltiscope eq 'map') || ($ltiscope eq 'resource')) {
1.1075.2.123 raeburn 9055: $menulink = 0;
9056: } else {
9057: undef($menulink);
9058: }
1.1075.2.161. .8(raebu 9059:22): my $linkprotout;
9060:22): if ($env{'request.deeplink.login'}) {
9061:22): my $linkprotout = &Apache::lonmenu::linkprot_exit();
9062:22): if ($linkprotout) {
9063:22): &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
9064:22): }
9065:22): }
1.758 kaisler 9066: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
9067: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 9068: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1075.2.161. .1(raebu 9069:21): } else {
1.1075.2.123 raeburn 9070: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 9071: }
1.1075.2.161. .8(raebu 9072:22): }
1.1075.2.24 raeburn 9073: } elsif (($env{'environment.remote'} eq 'on') &&
9074: ($env{'form.inhibitmenu'} ne 'yes') &&
9075: ($env{'request.noversionuri'} =~ m{^/res/}) &&
9076: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 9077: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 9078: }
1.315 albertel 9079: return $result;
1.306 albertel 9080: }
9081:
9082: sub end_page {
1.315 albertel 9083: my ($args) = @_;
9084: $env{'internal.end_page'}++;
1.330 albertel 9085: my $result;
1.335 albertel 9086: if ($args->{'discussion'}) {
9087: my ($target,$parser);
9088: if (ref($args->{'discussion'})) {
9089: ($target,$parser) =($args->{'discussion'}{'target'},
9090: $args->{'discussion'}{'parser'});
9091: }
9092: $result .= &Apache::lonxml::xmlend($target,$parser);
9093: }
1.330 albertel 9094: if ($args->{'frameset'}) {
9095: $result .= '</frameset>';
9096: } else {
1.635 raeburn 9097: $result .= &endbodytag($args);
1.330 albertel 9098: }
1.1075.2.6 raeburn 9099: unless ($args->{'notbody'}) {
9100: $result .= "\n</html>";
9101: }
1.330 albertel 9102:
1.315 albertel 9103: if ($args->{'js_ready'}) {
1.317 albertel 9104: $result = &js_ready($result);
1.315 albertel 9105: }
1.335 albertel 9106:
1.320 albertel 9107: if ($args->{'html_encode'}) {
9108: $result = &html_encode($result);
9109: }
1.335 albertel 9110:
1.315 albertel 9111: return $result;
9112: }
9113:
1.1075.2.161. .1(raebu 9114:21): sub menucoll_in_effect {
9115:21): my ($menucoll,$deeplinkmenu,%menu);
9116:21): if ($env{'request.course.id'}) {
9117:21): $menucoll = $env{'course.'.$env{'request.course.id'}.'.menudefault'};
9118:21): if ($env{'request.deeplink.login'}) {
9119:21): my ($deeplink_symb,$deeplink,$check_login_symb);
9120:21): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9121:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9122:21): if ($env{'request.noversionuri'} =~ m{^/(res|uploaded)/}) {
9123:21): if ($env{'request.noversionuri'} =~ /\.(page|sequence)$/) {
9124:21): my $navmap = Apache::lonnavmaps::navmap->new();
9125:21): if (ref($navmap)) {
9126:21): $deeplink = $navmap->get_mapparam(undef,
9127:21): &Apache::lonnet::declutter($env{'request.noversionuri'}),
9128:21): '0.deeplink');
9129:21): } else {
9130:21): $check_login_symb = 1;
9131:21): }
9132:21): } else {
9133:21): my $symb=&Apache::lonnet::symbread();
9134:21): if ($symb) {
9135:21): $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
9136:21): } else {
9137:21): $check_login_symb = 1;
9138:21): }
9139:21): }
9140:21): } else {
9141:21): $check_login_symb = 1;
9142:21): }
9143:21): if ($check_login_symb) {
9144:21): $deeplink_symb = &deeplink_login_symb($cnum,$cdom);
9145:21): if ($deeplink_symb =~ /\.(page|sequence)$/) {
9146:21): my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
9147:21): my $navmap = Apache::lonnavmaps::navmap->new();
9148:21): if (ref($navmap)) {
9149:21): $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
9150:21): }
9151:21): } else {
9152:21): $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
9153:21): }
9154:21): }
9155:21): if ($deeplink ne '') {
.6(raebu 9156:22): my ($state,$others,$listed,$scope,$protect,$display,$target) = split(/,/,$deeplink);
.1(raebu 9157:21): if ($display =~ /^\d+$/) {
9158:21): $deeplinkmenu = 1;
9159:21): $menucoll = $display;
9160:21): }
9161:21): }
9162:21): }
9163:21): if ($menucoll) {
9164:21): %menu = &page_menu($env{'course.'.$env{'request.course.id'}.'.menucollections'},$menucoll);
9165:21): }
9166:21): }
9167:21): return ($menucoll,$deeplinkmenu,\%menu);
9168:21): }
9169:21):
9170:21): sub deeplink_login_symb {
9171:21): my ($cnum,$cdom) = @_;
9172:21): my $login_symb;
9173:21): if ($env{'request.deeplink.login'}) {
9174:21): $login_symb = &symb_from_tinyurl($env{'request.deeplink.login'},$cnum,$cdom);
9175:21): }
9176:21): return $login_symb;
9177:21): }
9178:21):
9179:21): sub symb_from_tinyurl {
9180:21): my ($url,$cnum,$cdom) = @_;
9181:21): if ($url =~ m{^\Q/tiny/$cdom/\E(\w+)$}) {
9182:21): my $key = $1;
9183:21): my ($tinyurl,$login);
9184:21): my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
9185:21): if (defined($cached)) {
9186:21): $tinyurl = $result;
9187:21): } else {
9188:21): my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
9189:21): my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
9190:21): if ($currtiny{$key} ne '') {
9191:21): $tinyurl = $currtiny{$key};
9192:21): &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
9193:21): }
9194:21): }
9195:21): if ($tinyurl ne '') {
9196:21): my ($cnumreq,$symb) = split(/\&/,$tinyurl);
9197:21): if (wantarray) {
9198:21): return ($cnumreq,$symb);
9199:21): } elsif ($cnumreq eq $cnum) {
9200:21): return $symb;
9201:21): }
9202:21): }
9203:21): }
9204:21): if (wantarray) {
9205:21): return ();
9206:21): } else {
9207:21): return;
9208:21): }
9209:21): }
9210:21):
.17(raeb 9211:-23): sub usable_exttools {
9212:-23): my %tooltypes;
9213:-23): if ($env{'request.course.id'}) {
9214:-23): if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'}) {
9215:-23): if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'both') {
9216:-23): %tooltypes = (
9217:-23): crs => 1,
9218:-23): dom => 1,
9219:-23): );
9220:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'crs') {
9221:-23): $tooltypes{'crs'} = 1;
9222:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'dom') {
9223:-23): $tooltypes{'dom'} = 1;
9224:-23): }
9225:-23): } else {
9226:-23): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9227:-23): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9228:-23): my $crstype = lc($env{'course.'.$env{'request.course.id'}.'.type'});
9229:-23): if ($crstype eq '') {
9230:-23): $crstype = 'course';
9231:-23): }
9232:-23): if ($crstype eq 'course') {
9233:-23): if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'}) {
9234:-23): $crstype = 'official';
9235:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.textbook'}) {
9236:-23): $crstype = 'textbook';
9237:-23): } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.lti'}) {
9238:-23): $crstype = 'lti';
9239:-23): } else {
9240:-23): $crstype = 'unofficial';
9241:-23): }
9242:-23): }
9243:-23): my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
9244:-23): if ($domdefaults{$crstype.'domexttool'}) {
9245:-23): $tooltypes{'dom'} = 1;
9246:-23): }
9247:-23): if ($domdefaults{$crstype.'exttool'}) {
9248:-23): $tooltypes{'crs'} = 1;
9249:-23): }
9250:-23): }
9251:-23): }
9252:-23): return %tooltypes;
9253:-23): }
9254:-23):
1.1034 www 9255: sub wishlist_window {
9256: return(<<'ENDWISHLIST');
1.1046 raeburn 9257: <script type="text/javascript">
1.1034 www 9258: // <![CDATA[
9259: // <!-- BEGIN LON-CAPA Internal
9260: function set_wishlistlink(title, path) {
9261: if (!title) {
9262: title = document.title;
9263: title = title.replace(/^LON-CAPA /,'');
9264: }
1.1075.2.65 raeburn 9265: title = encodeURIComponent(title);
1.1075.2.83 raeburn 9266: title = title.replace("'","\\\'");
1.1034 www 9267: if (!path) {
9268: path = location.pathname;
9269: }
1.1075.2.65 raeburn 9270: path = encodeURIComponent(path);
1.1075.2.83 raeburn 9271: path = path.replace("'","\\\'");
1.1034 www 9272: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
9273: 'wishlistNewLink','width=560,height=350,scrollbars=0');
9274: }
9275: // END LON-CAPA Internal -->
9276: // ]]>
9277: </script>
9278: ENDWISHLIST
9279: }
9280:
1.1030 www 9281: sub modal_window {
9282: return(<<'ENDMODAL');
1.1046 raeburn 9283: <script type="text/javascript">
1.1030 www 9284: // <![CDATA[
9285: // <!-- BEGIN LON-CAPA Internal
9286: var modalWindow = {
9287: parent:"body",
9288: windowId:null,
9289: content:null,
9290: width:null,
9291: height:null,
9292: close:function()
9293: {
9294: $(".LCmodal-window").remove();
9295: $(".LCmodal-overlay").remove();
9296: },
9297: open:function()
9298: {
9299: var modal = "";
9300: modal += "<div class=\"LCmodal-overlay\"></div>";
9301: 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;\">";
9302: modal += this.content;
9303: modal += "</div>";
9304:
9305: $(this.parent).append(modal);
9306:
9307: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
9308: $(".LCclose-window").click(function(){modalWindow.close();});
9309: $(".LCmodal-overlay").click(function(){modalWindow.close();});
9310: }
9311: };
1.1075.2.42 raeburn 9312: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 9313: {
1.1075.2.119 raeburn 9314: source = source.replace(/'/g,"'");
1.1030 www 9315: modalWindow.windowId = "myModal";
9316: modalWindow.width = width;
9317: modalWindow.height = height;
1.1075.2.80 raeburn 9318: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9319: modalWindow.open();
1.1075.2.87 raeburn 9320: };
1.1030 www 9321: // END LON-CAPA Internal -->
9322: // ]]>
9323: </script>
9324: ENDMODAL
9325: }
9326:
9327: sub modal_link {
1.1075.2.42 raeburn 9328: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9329: unless ($width) { $width=480; }
9330: unless ($height) { $height=400; }
1.1031 www 9331: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 9332: unless ($transparency) { $transparency='true'; }
9333:
1.1074 raeburn 9334: my $target_attr;
9335: if (defined($target)) {
9336: $target_attr = 'target="'.$target.'"';
9337: }
9338: return <<"ENDLINK";
1.1075.2.143 raeburn 9339: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 9340: ENDLINK
1.1030 www 9341: }
9342:
1.1032 www 9343: sub modal_adhoc_script {
1.1075.2.155 raeburn 9344: my ($funcname,$width,$height,$content,$possmathjax)=@_;
9345: my $mathjax;
9346: if ($possmathjax) {
9347: $mathjax = <<'ENDJAX';
9348: if (typeof MathJax == 'object') {
9349: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
9350: }
9351: ENDJAX
9352: }
1.1032 www 9353: return (<<ENDADHOC);
1.1046 raeburn 9354: <script type="text/javascript">
1.1032 www 9355: // <![CDATA[
9356: var $funcname = function()
9357: {
9358: modalWindow.windowId = "myModal";
9359: modalWindow.width = $width;
9360: modalWindow.height = $height;
9361: modalWindow.content = '$content';
9362: modalWindow.open();
1.1075.2.155 raeburn 9363: $mathjax
1.1032 www 9364: };
9365: // ]]>
9366: </script>
9367: ENDADHOC
9368: }
9369:
1.1041 www 9370: sub modal_adhoc_inner {
1.1075.2.155 raeburn 9371: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 9372: my $innerwidth=$width-20;
9373: $content=&js_ready(
1.1042 www 9374: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 9375: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9376: $content.
1.1041 www 9377: &end_scrollbox().
1.1075.2.42 raeburn 9378: &end_page()
1.1041 www 9379: );
1.1075.2.155 raeburn 9380: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 9381: }
9382:
9383: sub modal_adhoc_window {
1.1075.2.155 raeburn 9384: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
9385: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 9386: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9387: }
9388:
9389: sub modal_adhoc_launch {
9390: my ($funcname,$width,$height,$content)=@_;
9391: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9392: <script type="text/javascript">
9393: // <![CDATA[
9394: $funcname();
9395: // ]]>
9396: </script>
9397: ENDLAUNCH
9398: }
9399:
9400: sub modal_adhoc_close {
9401: return (<<ENDCLOSE);
9402: <script type="text/javascript">
9403: // <![CDATA[
9404: modalWindow.close();
9405: // ]]>
9406: </script>
9407: ENDCLOSE
9408: }
9409:
1.1038 www 9410: sub togglebox_script {
9411: return(<<ENDTOGGLE);
9412: <script type="text/javascript">
9413: // <![CDATA[
9414: function LCtoggleDisplay(id,hidetext,showtext) {
9415: link = document.getElementById(id + "link").childNodes[0];
9416: with (document.getElementById(id).style) {
9417: if (display == "none" ) {
9418: display = "inline";
9419: link.nodeValue = hidetext;
9420: } else {
9421: display = "none";
9422: link.nodeValue = showtext;
9423: }
9424: }
9425: }
9426: // ]]>
9427: </script>
9428: ENDTOGGLE
9429: }
9430:
1.1039 www 9431: sub start_togglebox {
9432: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9433: unless ($heading) { $heading=''; } else { $heading.=' '; }
9434: unless ($showtext) { $showtext=&mt('show'); }
9435: unless ($hidetext) { $hidetext=&mt('hide'); }
9436: unless ($headerbg) { $headerbg='#FFFFFF'; }
9437: return &start_data_table().
9438: &start_data_table_header_row().
9439: '<td bgcolor="'.$headerbg.'">'.$heading.
9440: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9441: $showtext.'\')">'.$showtext.'</a>]</td>'.
9442: &end_data_table_header_row().
9443: '<tr id="'.$id.'" style="display:none""><td>';
9444: }
9445:
9446: sub end_togglebox {
9447: return '</td></tr>'.&end_data_table();
9448: }
9449:
1.1041 www 9450: sub LCprogressbar_script {
1.1075.2.130 raeburn 9451: my ($id,$number_to_do)=@_;
9452: if ($number_to_do) {
9453: return(<<ENDPROGRESS);
1.1041 www 9454: <script type="text/javascript">
9455: // <![CDATA[
1.1045 www 9456: \$('#progressbar$id').progressbar({
1.1041 www 9457: value: 0,
9458: change: function(event, ui) {
9459: var newVal = \$(this).progressbar('option', 'value');
9460: \$('.pblabel', this).text(LCprogressTxt);
9461: }
9462: });
9463: // ]]>
9464: </script>
9465: ENDPROGRESS
1.1075.2.130 raeburn 9466: } else {
9467: return(<<ENDPROGRESS);
9468: <script type="text/javascript">
9469: // <![CDATA[
9470: \$('#progressbar$id').progressbar({
9471: value: false,
9472: create: function(event, ui) {
9473: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9474: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9475: }
9476: });
9477: // ]]>
9478: </script>
9479: ENDPROGRESS
9480: }
1.1041 www 9481: }
9482:
9483: sub LCprogressbarUpdate_script {
9484: return(<<ENDPROGRESSUPDATE);
9485: <style type="text/css">
9486: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 9487: .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 9488: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9489: </style>
9490: <script type="text/javascript">
9491: // <![CDATA[
1.1045 www 9492: var LCprogressTxt='---';
9493:
1.1075.2.130 raeburn 9494: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9495: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 9496: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9497: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9498: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
9499: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9500: } else {
9501: \$('#progressbar'+id).progressbar('value',percent);
9502: }
1.1041 www 9503: }
9504: // ]]>
9505: </script>
9506: ENDPROGRESSUPDATE
9507: }
9508:
1.1042 www 9509: my $LClastpercent;
1.1045 www 9510: my $LCidcnt;
9511: my $LCcurrentid;
1.1042 www 9512:
1.1041 www 9513: sub LCprogressbar {
1.1075.2.130 raeburn 9514: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9515: $LClastpercent=0;
1.1045 www 9516: $LCidcnt++;
9517: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 9518: my ($starting,$content);
9519: if ($number_to_do) {
9520: $starting=&mt('Starting');
9521: $content=(<<ENDPROGBAR);
9522: $preamble
1.1045 www 9523: <div id="progressbar$LCcurrentid">
1.1041 www 9524: <span class="pblabel">$starting</span>
9525: </div>
9526: ENDPROGBAR
1.1075.2.130 raeburn 9527: } else {
9528: $starting=&mt('Loading...');
9529: $LClastpercent='false';
9530: $content=(<<ENDPROGBAR);
9531: $preamble
9532: <div id="progressbar$LCcurrentid">
9533: <div class="progress-label">$starting</div>
9534: </div>
9535: ENDPROGBAR
9536: }
9537: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9538: }
9539:
9540: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 9541: my ($r,$val,$text,$number_to_do)=@_;
9542: if ($number_to_do) {
9543: unless ($val) {
9544: if ($LClastpercent) {
9545: $val=$LClastpercent;
9546: } else {
9547: $val=0;
9548: }
9549: }
9550: if ($val<0) { $val=0; }
9551: if ($val>100) { $val=0; }
9552: $LClastpercent=$val;
9553: unless ($text) { $text=$val.'%'; }
9554: } else {
9555: $val = 'false';
1.1042 www 9556: }
1.1041 www 9557: $text=&js_ready($text);
1.1044 www 9558: &r_print($r,<<ENDUPDATE);
1.1041 www 9559: <script type="text/javascript">
9560: // <![CDATA[
1.1075.2.130 raeburn 9561: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9562: // ]]>
9563: </script>
9564: ENDUPDATE
1.1035 www 9565: }
9566:
1.1042 www 9567: sub LCprogressbarClose {
9568: my ($r)=@_;
9569: $LClastpercent=0;
1.1044 www 9570: &r_print($r,<<ENDCLOSE);
1.1042 www 9571: <script type="text/javascript">
9572: // <![CDATA[
1.1045 www 9573: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9574: // ]]>
9575: </script>
9576: ENDCLOSE
1.1044 www 9577: }
9578:
9579: sub r_print {
9580: my ($r,$to_print)=@_;
9581: if ($r) {
9582: $r->print($to_print);
9583: $r->rflush();
9584: } else {
9585: print($to_print);
9586: }
1.1042 www 9587: }
9588:
1.320 albertel 9589: sub html_encode {
9590: my ($result) = @_;
9591:
1.322 albertel 9592: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9593:
9594: return $result;
9595: }
1.1044 www 9596:
1.317 albertel 9597: sub js_ready {
9598: my ($result) = @_;
9599:
1.323 albertel 9600: $result =~ s/[\n\r]/ /xmsg;
9601: $result =~ s/\\/\\\\/xmsg;
9602: $result =~ s/'/\\'/xmsg;
1.372 albertel 9603: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9604:
9605: return $result;
9606: }
9607:
1.315 albertel 9608: sub validate_page {
9609: if ( exists($env{'internal.start_page'})
1.316 albertel 9610: && $env{'internal.start_page'} > 1) {
9611: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9612: $env{'internal.start_page'}.' '.
1.316 albertel 9613: $ENV{'request.filename'});
1.315 albertel 9614: }
9615: if ( exists($env{'internal.end_page'})
1.316 albertel 9616: && $env{'internal.end_page'} > 1) {
9617: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9618: $env{'internal.end_page'}.' '.
1.316 albertel 9619: $env{'request.filename'});
1.315 albertel 9620: }
9621: if ( exists($env{'internal.start_page'})
9622: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9623: &Apache::lonnet::logthis('start_page called without end_page '.
9624: $env{'request.filename'});
1.315 albertel 9625: }
9626: if ( ! exists($env{'internal.start_page'})
9627: && exists($env{'internal.end_page'})) {
1.316 albertel 9628: &Apache::lonnet::logthis('end_page called without start_page'.
9629: $env{'request.filename'});
1.315 albertel 9630: }
1.306 albertel 9631: }
1.315 albertel 9632:
1.996 www 9633:
9634: sub start_scrollbox {
1.1075.2.56 raeburn 9635: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9636: unless ($outerwidth) { $outerwidth='520px'; }
9637: unless ($width) { $width='500px'; }
9638: unless ($height) { $height='200px'; }
1.1075 raeburn 9639: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9640: if ($id ne '') {
1.1075.2.42 raeburn 9641: $table_id = ' id="table_'.$id.'"';
9642: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9643: }
1.1075 raeburn 9644: if ($bgcolor ne '') {
9645: $tdcol = "background-color: $bgcolor;";
9646: }
1.1075.2.42 raeburn 9647: my $nicescroll_js;
9648: if ($env{'browser.mobile'}) {
9649: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9650: }
1.1075 raeburn 9651: return <<"END";
1.1075.2.42 raeburn 9652: $nicescroll_js
9653:
9654: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 9655: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 9656: END
1.996 www 9657: }
9658:
9659: sub end_scrollbox {
1.1036 www 9660: return '</div></td></tr></table>';
1.996 www 9661: }
9662:
1.1075.2.42 raeburn 9663: sub nicescroll_javascript {
9664: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9665: my %options;
9666: if (ref($cursor) eq 'HASH') {
9667: %options = %{$cursor};
9668: }
9669: unless ($options{'railalign'} =~ /^left|right$/) {
9670: $options{'railalign'} = 'left';
9671: }
9672: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9673: my $function = &get_users_function();
9674: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
9675: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9676: $options{'cursorcolor'} = '#00F';
9677: }
9678: }
9679: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9680: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
9681: $options{'cursoropacity'}='1.0';
9682: }
9683: } else {
9684: $options{'cursoropacity'}='1.0';
9685: }
9686: if ($options{'cursorfixedheight'} eq 'none') {
9687: delete($options{'cursorfixedheight'});
9688: } else {
9689: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9690: }
9691: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9692: delete($options{'railoffset'});
9693: }
9694: my @niceoptions;
9695: while (my($key,$value) = each(%options)) {
9696: if ($value =~ /^\{.+\}$/) {
9697: push(@niceoptions,$key.':'.$value);
9698: } else {
9699: push(@niceoptions,$key.':"'.$value.'"');
9700: }
9701: }
9702: my $nicescroll_js = '
9703: $(document).ready(
9704: function() {
9705: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9706: }
9707: );
9708: ';
9709: if ($framecheck) {
9710: $nicescroll_js .= '
9711: function expand_div(caller) {
9712: if (top === self) {
9713: document.getElementById("'.$id.'").style.width = "auto";
9714: document.getElementById("'.$id.'").style.height = "auto";
9715: } else {
9716: try {
9717: if (parent.frames) {
9718: if (parent.frames.length > 1) {
9719: var framesrc = parent.frames[1].location.href;
9720: var currsrc = framesrc.replace(/\#.*$/,"");
9721: if ((caller == "search") || (currsrc == "'.$location.'")) {
9722: document.getElementById("'.$id.'").style.width = "auto";
9723: document.getElementById("'.$id.'").style.height = "auto";
9724: }
9725: }
9726: }
9727: } catch (e) {
9728: return;
9729: }
9730: }
9731: return;
9732: }
9733: ';
9734: }
9735: if ($needjsready) {
9736: $nicescroll_js = '
9737: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9738: } else {
9739: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9740: }
9741: return $nicescroll_js;
9742: }
9743:
1.318 albertel 9744: sub simple_error_page {
1.1075.2.49 raeburn 9745: my ($r,$title,$msg,$args) = @_;
1.1075.2.161. .4(raebu 9746:22): my %displayargs;
1.1075.2.49 raeburn 9747: if (ref($args) eq 'HASH') {
9748: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1075.2.161. .4(raebu 9749:22): if ($args->{'only_body'}) {
9750:22): $displayargs{'only_body'} = 1;
9751:22): }
9752:22): if ($args->{'no_nav_bar'}) {
9753:22): $displayargs{'no_nav_bar'} = 1;
9754:22): }
1.1075.2.49 raeburn 9755: } else {
9756: $msg = &mt($msg);
9757: }
9758:
1.318 albertel 9759: my $page =
1.1075.2.161. .4(raebu 9760:22): &Apache::loncommon::start_page($title,'',\%displayargs).
1.1075.2.49 raeburn 9761: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9762: &Apache::loncommon::end_page();
9763: if (ref($r)) {
9764: $r->print($page);
1.327 albertel 9765: return;
1.318 albertel 9766: }
9767: return $page;
9768: }
1.347 albertel 9769:
9770: {
1.610 albertel 9771: my @row_count;
1.961 onken 9772:
9773: sub start_data_table_count {
9774: unshift(@row_count, 0);
9775: return;
9776: }
9777:
9778: sub end_data_table_count {
9779: shift(@row_count);
9780: return;
9781: }
9782:
1.347 albertel 9783: sub start_data_table {
1.1018 raeburn 9784: my ($add_class,$id) = @_;
1.422 albertel 9785: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9786: my $table_id;
9787: if (defined($id)) {
9788: $table_id = ' id="'.$id.'"';
9789: }
1.961 onken 9790: &start_data_table_count();
1.1018 raeburn 9791: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9792: }
9793:
9794: sub end_data_table {
1.961 onken 9795: &end_data_table_count();
1.389 albertel 9796: return '</table>'."\n";;
1.347 albertel 9797: }
9798:
9799: sub start_data_table_row {
1.974 wenzelju 9800: my ($add_class, $id) = @_;
1.610 albertel 9801: $row_count[0]++;
9802: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9803: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9804: $id = (' id="'.$id.'"') unless ($id eq '');
9805: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9806: }
1.471 banghart 9807:
9808: sub continue_data_table_row {
1.974 wenzelju 9809: my ($add_class, $id) = @_;
1.610 albertel 9810: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9811: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9812: $id = (' id="'.$id.'"') unless ($id eq '');
9813: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9814: }
1.347 albertel 9815:
9816: sub end_data_table_row {
1.389 albertel 9817: return '</tr>'."\n";;
1.347 albertel 9818: }
1.367 www 9819:
1.421 albertel 9820: sub start_data_table_empty_row {
1.707 bisitz 9821: # $row_count[0]++;
1.421 albertel 9822: return '<tr class="LC_empty_row" >'."\n";;
9823: }
9824:
9825: sub end_data_table_empty_row {
9826: return '</tr>'."\n";;
9827: }
9828:
1.367 www 9829: sub start_data_table_header_row {
1.389 albertel 9830: return '<tr class="LC_header_row">'."\n";;
1.367 www 9831: }
9832:
9833: sub end_data_table_header_row {
1.389 albertel 9834: return '</tr>'."\n";;
1.367 www 9835: }
1.890 droeschl 9836:
9837: sub data_table_caption {
9838: my $caption = shift;
9839: return "<caption class=\"LC_caption\">$caption</caption>";
9840: }
1.347 albertel 9841: }
9842:
1.548 albertel 9843: =pod
9844:
9845: =item * &inhibit_menu_check($arg)
9846:
9847: Checks for a inhibitmenu state and generates output to preserve it
9848:
9849: Inputs: $arg - can be any of
9850: - undef - in which case the return value is a string
9851: to add into arguments list of a uri
9852: - 'input' - in which case the return value is a HTML
9853: <form> <input> field of type hidden to
9854: preserve the value
9855: - a url - in which case the return value is the url with
9856: the neccesary cgi args added to preserve the
9857: inhibitmenu state
9858: - a ref to a url - no return value, but the string is
9859: updated to include the neccessary cgi
9860: args to preserve the inhibitmenu state
9861:
9862: =cut
9863:
9864: sub inhibit_menu_check {
9865: my ($arg) = @_;
9866: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9867: if ($arg eq 'input') {
9868: if ($env{'form.inhibitmenu'}) {
9869: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9870: } else {
9871: return
9872: }
9873: }
9874: if ($env{'form.inhibitmenu'}) {
9875: if (ref($arg)) {
9876: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9877: } elsif ($arg eq '') {
9878: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9879: } else {
9880: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9881: }
9882: }
9883: if (!ref($arg)) {
9884: return $arg;
9885: }
9886: }
9887:
1.251 albertel 9888: ###############################################
1.182 matthew 9889:
9890: =pod
9891:
1.549 albertel 9892: =back
9893:
9894: =head1 User Information Routines
9895:
9896: =over 4
9897:
1.405 albertel 9898: =item * &get_users_function()
1.182 matthew 9899:
9900: Used by &bodytag to determine the current users primary role.
9901: Returns either 'student','coordinator','admin', or 'author'.
9902:
9903: =cut
9904:
9905: ###############################################
9906: sub get_users_function {
1.815 tempelho 9907: my $function = 'norole';
1.818 tempelho 9908: if ($env{'request.role'}=~/^(st)/) {
9909: $function='student';
9910: }
1.907 raeburn 9911: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9912: $function='coordinator';
9913: }
1.258 albertel 9914: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9915: $function='admin';
9916: }
1.826 bisitz 9917: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9918: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9919: $function='author';
9920: }
9921: return $function;
1.54 www 9922: }
1.99 www 9923:
9924: ###############################################
9925:
1.233 raeburn 9926: =pod
9927:
1.821 raeburn 9928: =item * &show_course()
9929:
9930: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9931: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9932:
9933: Inputs:
9934: None
9935:
9936: Outputs:
9937: Scalar: 1 if 'Course' to be used, 0 otherwise.
9938:
9939: =cut
9940:
9941: ###############################################
9942: sub show_course {
9943: my $course = !$env{'user.adv'};
9944: if (!$env{'user.adv'}) {
9945: foreach my $env (keys(%env)) {
9946: next if ($env !~ m/^user\.priv\./);
9947: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9948: $course = 0;
9949: last;
9950: }
9951: }
9952: }
9953: return $course;
9954: }
9955:
9956: ###############################################
9957:
9958: =pod
9959:
1.542 raeburn 9960: =item * &check_user_status()
1.274 raeburn 9961:
9962: Determines current status of supplied role for a
9963: specific user. Roles can be active, previous or future.
9964:
9965: Inputs:
9966: user's domain, user's username, course's domain,
1.375 raeburn 9967: course's number, optional section ID.
1.274 raeburn 9968:
9969: Outputs:
9970: role status: active, previous or future.
9971:
9972: =cut
9973:
9974: sub check_user_status {
1.412 raeburn 9975: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9976: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 9977: my @uroles = keys(%userinfo);
1.274 raeburn 9978: my $srchstr;
9979: my $active_chk = 'none';
1.412 raeburn 9980: my $now = time;
1.274 raeburn 9981: if (@uroles > 0) {
1.908 raeburn 9982: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9983: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9984: } else {
1.412 raeburn 9985: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9986: }
9987: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9988: my $role_end = 0;
9989: my $role_start = 0;
9990: $active_chk = 'active';
1.412 raeburn 9991: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9992: $role_end = $1;
9993: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9994: $role_start = $1;
1.274 raeburn 9995: }
9996: }
9997: if ($role_start > 0) {
1.412 raeburn 9998: if ($now < $role_start) {
1.274 raeburn 9999: $active_chk = 'future';
10000: }
10001: }
10002: if ($role_end > 0) {
1.412 raeburn 10003: if ($now > $role_end) {
1.274 raeburn 10004: $active_chk = 'previous';
10005: }
10006: }
10007: }
10008: }
10009: return $active_chk;
10010: }
10011:
10012: ###############################################
10013:
10014: =pod
10015:
1.405 albertel 10016: =item * &get_sections()
1.233 raeburn 10017:
10018: Determines all the sections for a course including
10019: sections with students and sections containing other roles.
1.419 raeburn 10020: Incoming parameters:
10021:
10022: 1. domain
10023: 2. course number
10024: 3. reference to array containing roles for which sections should
10025: be gathered (optional).
10026: 4. reference to array containing status types for which sections
10027: should be gathered (optional).
10028:
10029: If the third argument is undefined, sections are gathered for any role.
10030: If the fourth argument is undefined, sections are gathered for any status.
10031: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 10032:
1.374 raeburn 10033: Returns section hash (keys are section IDs, values are
10034: number of users in each section), subject to the
1.419 raeburn 10035: optional roles filter, optional status filter
1.233 raeburn 10036:
10037: =cut
10038:
10039: ###############################################
10040: sub get_sections {
1.419 raeburn 10041: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 10042: if (!defined($cdom) || !defined($cnum)) {
10043: my $cid = $env{'request.course.id'};
10044:
10045: return if (!defined($cid));
10046:
10047: $cdom = $env{'course.'.$cid.'.domain'};
10048: $cnum = $env{'course.'.$cid.'.num'};
10049: }
10050:
10051: my %sectioncount;
1.419 raeburn 10052: my $now = time;
1.240 albertel 10053:
1.1075.2.33 raeburn 10054: my $check_students = 1;
10055: my $only_students = 0;
10056: if (ref($possible_roles) eq 'ARRAY') {
10057: if (grep(/^st$/,@{$possible_roles})) {
10058: if (@{$possible_roles} == 1) {
10059: $only_students = 1;
10060: }
10061: } else {
10062: $check_students = 0;
10063: }
10064: }
10065:
10066: if ($check_students) {
1.276 albertel 10067: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 10068: my $sec_index = &Apache::loncoursedata::CL_SECTION();
10069: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 10070: my $start_index = &Apache::loncoursedata::CL_START();
10071: my $end_index = &Apache::loncoursedata::CL_END();
10072: my $status;
1.366 albertel 10073: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 10074: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
10075: $data->[$status_index],
10076: $data->[$start_index],
10077: $data->[$end_index]);
10078: if ($stu_status eq 'Active') {
10079: $status = 'active';
10080: } elsif ($end < $now) {
10081: $status = 'previous';
10082: } elsif ($start > $now) {
10083: $status = 'future';
10084: }
10085: if ($section ne '-1' && $section !~ /^\s*$/) {
10086: if ((!defined($possible_status)) || (($status ne '') &&
10087: (grep/^\Q$status\E$/,@{$possible_status}))) {
10088: $sectioncount{$section}++;
10089: }
1.240 albertel 10090: }
10091: }
10092: }
1.1075.2.33 raeburn 10093: if ($only_students) {
10094: return %sectioncount;
10095: }
1.240 albertel 10096: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10097: foreach my $user (sort(keys(%courseroles))) {
10098: if ($user !~ /^(\w{2})/) { next; }
10099: my ($role) = ($user =~ /^(\w{2})/);
10100: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 10101: my ($section,$status);
1.240 albertel 10102: if ($role eq 'cr' &&
10103: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
10104: $section=$1;
10105: }
10106: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
10107: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 10108: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
10109: if ($end == -1 && $start == -1) {
10110: next; #deleted role
10111: }
10112: if (!defined($possible_status)) {
10113: $sectioncount{$section}++;
10114: } else {
10115: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
10116: $status = 'active';
10117: } elsif ($end < $now) {
10118: $status = 'future';
10119: } elsif ($start > $now) {
10120: $status = 'previous';
10121: }
10122: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
10123: $sectioncount{$section}++;
10124: }
10125: }
1.233 raeburn 10126: }
1.366 albertel 10127: return %sectioncount;
1.233 raeburn 10128: }
10129:
1.274 raeburn 10130: ###############################################
1.294 raeburn 10131:
10132: =pod
1.405 albertel 10133:
10134: =item * &get_course_users()
10135:
1.275 raeburn 10136: Retrieves usernames:domains for users in the specified course
10137: with specific role(s), and access status.
10138:
10139: Incoming parameters:
1.277 albertel 10140: 1. course domain
10141: 2. course number
10142: 3. access status: users must have - either active,
1.275 raeburn 10143: previous, future, or all.
1.277 albertel 10144: 4. reference to array of permissible roles
1.288 raeburn 10145: 5. reference to array of section restrictions (optional)
10146: 6. reference to results object (hash of hashes).
10147: 7. reference to optional userdata hash
1.609 raeburn 10148: 8. reference to optional statushash
1.630 raeburn 10149: 9. flag if privileged users (except those set to unhide in
10150: course settings) should be excluded
1.609 raeburn 10151: Keys of top level results hash are roles.
1.275 raeburn 10152: Keys of inner hashes are username:domain, with
10153: values set to access type.
1.288 raeburn 10154: Optional userdata hash returns an array with arguments in the
10155: same order as loncoursedata::get_classlist() for student data.
10156:
1.609 raeburn 10157: Optional statushash returns
10158:
1.288 raeburn 10159: Entries for end, start, section and status are blank because
10160: of the possibility of multiple values for non-student roles.
10161:
1.275 raeburn 10162: =cut
1.405 albertel 10163:
1.275 raeburn 10164: ###############################################
1.405 albertel 10165:
1.275 raeburn 10166: sub get_course_users {
1.630 raeburn 10167: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 10168: my %idx = ();
1.419 raeburn 10169: my %seclists;
1.288 raeburn 10170:
10171: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
10172: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
10173: $idx{end} = &Apache::loncoursedata::CL_END();
10174: $idx{start} = &Apache::loncoursedata::CL_START();
10175: $idx{id} = &Apache::loncoursedata::CL_ID();
10176: $idx{section} = &Apache::loncoursedata::CL_SECTION();
10177: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
10178: $idx{status} = &Apache::loncoursedata::CL_STATUS();
10179:
1.290 albertel 10180: if (grep(/^st$/,@{$roles})) {
1.276 albertel 10181: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 10182: my $now = time;
1.277 albertel 10183: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 10184: my $match = 0;
1.412 raeburn 10185: my $secmatch = 0;
1.419 raeburn 10186: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 10187: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 10188: if ($section eq '') {
10189: $section = 'none';
10190: }
1.291 albertel 10191: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10192: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10193: $secmatch = 1;
10194: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 10195: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10196: $secmatch = 1;
10197: }
10198: } else {
1.419 raeburn 10199: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 10200: $secmatch = 1;
10201: }
1.290 albertel 10202: }
1.412 raeburn 10203: if (!$secmatch) {
10204: next;
10205: }
1.419 raeburn 10206: }
1.275 raeburn 10207: if (defined($$types{'active'})) {
1.288 raeburn 10208: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 10209: push(@{$$users{st}{$student}},'active');
1.288 raeburn 10210: $match = 1;
1.275 raeburn 10211: }
10212: }
10213: if (defined($$types{'previous'})) {
1.609 raeburn 10214: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 10215: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 10216: $match = 1;
1.275 raeburn 10217: }
10218: }
10219: if (defined($$types{'future'})) {
1.609 raeburn 10220: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 10221: push(@{$$users{st}{$student}},'future');
1.288 raeburn 10222: $match = 1;
1.275 raeburn 10223: }
10224: }
1.609 raeburn 10225: if ($match) {
10226: push(@{$seclists{$student}},$section);
10227: if (ref($userdata) eq 'HASH') {
10228: $$userdata{$student} = $$classlist{$student};
10229: }
10230: if (ref($statushash) eq 'HASH') {
10231: $statushash->{$student}{'st'}{$section} = $status;
10232: }
1.288 raeburn 10233: }
1.275 raeburn 10234: }
10235: }
1.412 raeburn 10236: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 10237: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10238: my $now = time;
1.609 raeburn 10239: my %displaystatus = ( previous => 'Expired',
10240: active => 'Active',
10241: future => 'Future',
10242: );
1.1075.2.36 raeburn 10243: my (%nothide,@possdoms);
1.630 raeburn 10244: if ($hidepriv) {
10245: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
10246: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
10247: if ($user !~ /:/) {
10248: $nothide{join(':',split(/[\@]/,$user))}=1;
10249: } else {
10250: $nothide{$user} = 1;
10251: }
10252: }
1.1075.2.36 raeburn 10253: my @possdoms = ($cdom);
10254: if ($coursehash{'checkforpriv'}) {
10255: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
10256: }
1.630 raeburn 10257: }
1.439 raeburn 10258: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 10259: my $match = 0;
1.412 raeburn 10260: my $secmatch = 0;
1.439 raeburn 10261: my $status;
1.412 raeburn 10262: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 10263: $user =~ s/:$//;
1.439 raeburn 10264: my ($end,$start) = split(/:/,$coursepersonnel{$person});
10265: if ($end == -1 || $start == -1) {
10266: next;
10267: }
10268: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
10269: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 10270: my ($uname,$udom) = split(/:/,$user);
10271: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10272: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10273: $secmatch = 1;
10274: } elsif ($usec eq '') {
1.420 albertel 10275: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10276: $secmatch = 1;
10277: }
10278: } else {
10279: if (grep(/^\Q$usec\E$/,@{$sections})) {
10280: $secmatch = 1;
10281: }
10282: }
10283: if (!$secmatch) {
10284: next;
10285: }
1.288 raeburn 10286: }
1.419 raeburn 10287: if ($usec eq '') {
10288: $usec = 'none';
10289: }
1.275 raeburn 10290: if ($uname ne '' && $udom ne '') {
1.630 raeburn 10291: if ($hidepriv) {
1.1075.2.36 raeburn 10292: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 10293: (!$nothide{$uname.':'.$udom})) {
10294: next;
10295: }
10296: }
1.503 raeburn 10297: if ($end > 0 && $end < $now) {
1.439 raeburn 10298: $status = 'previous';
10299: } elsif ($start > $now) {
10300: $status = 'future';
10301: } else {
10302: $status = 'active';
10303: }
1.277 albertel 10304: foreach my $type (keys(%{$types})) {
1.275 raeburn 10305: if ($status eq $type) {
1.420 albertel 10306: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 10307: push(@{$$users{$role}{$user}},$type);
10308: }
1.288 raeburn 10309: $match = 1;
10310: }
10311: }
1.419 raeburn 10312: if (($match) && (ref($userdata) eq 'HASH')) {
10313: if (!exists($$userdata{$uname.':'.$udom})) {
10314: &get_user_info($udom,$uname,\%idx,$userdata);
10315: }
1.420 albertel 10316: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 10317: push(@{$seclists{$uname.':'.$udom}},$usec);
10318: }
1.609 raeburn 10319: if (ref($statushash) eq 'HASH') {
10320: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
10321: }
1.275 raeburn 10322: }
10323: }
10324: }
10325: }
1.290 albertel 10326: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10327: if ((defined($cdom)) && (defined($cnum))) {
10328: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10329: if ( defined($csettings{'internal.courseowner'}) ) {
10330: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10331: next if ($owner eq '');
10332: my ($ownername,$ownerdom);
10333: if ($owner =~ /^([^:]+):([^:]+)$/) {
10334: $ownername = $1;
10335: $ownerdom = $2;
10336: } else {
10337: $ownername = $owner;
10338: $ownerdom = $cdom;
10339: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10340: }
10341: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10342: if (defined($userdata) &&
1.609 raeburn 10343: !exists($$userdata{$owner})) {
10344: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10345: if (!grep(/^none$/,@{$seclists{$owner}})) {
10346: push(@{$seclists{$owner}},'none');
10347: }
10348: if (ref($statushash) eq 'HASH') {
10349: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10350: }
1.290 albertel 10351: }
1.279 raeburn 10352: }
10353: }
10354: }
1.419 raeburn 10355: foreach my $user (keys(%seclists)) {
10356: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10357: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10358: }
1.275 raeburn 10359: }
10360: return;
10361: }
10362:
1.288 raeburn 10363: sub get_user_info {
10364: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10365: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10366: &plainname($uname,$udom,'lastname');
1.291 albertel 10367: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10368: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10369: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10370: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10371: return;
10372: }
1.275 raeburn 10373:
1.472 raeburn 10374: ###############################################
10375:
10376: =pod
10377:
10378: =item * &get_user_quota()
10379:
1.1075.2.41 raeburn 10380: Retrieves quota assigned for storage of user files.
10381: Default is to report quota for portfolio files.
1.472 raeburn 10382:
10383: Incoming parameters:
10384: 1. user's username
10385: 2. user's domain
1.1075.2.41 raeburn 10386: 3. quota name - portfolio, author, or course
10387: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 10388: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 10389: course
1.472 raeburn 10390:
10391: Returns:
1.1075.2.58 raeburn 10392: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10393: 2. (Optional) Type of setting: custom or default
10394: (individually assigned or default for user's
10395: institutional status).
10396: 3. (Optional) - User's institutional status (e.g., faculty, staff
10397: or student - types as defined in localenroll::inst_usertypes
10398: for user's domain, which determines default quota for user.
10399: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10400:
10401: If a value has been stored in the user's environment,
1.536 raeburn 10402: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 10403: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10404:
10405: =cut
10406:
10407: ###############################################
10408:
10409:
10410: sub get_user_quota {
1.1075.2.42 raeburn 10411: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10412: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10413: if (!defined($udom)) {
10414: $udom = $env{'user.domain'};
10415: }
10416: if (!defined($uname)) {
10417: $uname = $env{'user.name'};
10418: }
10419: if (($udom eq '' || $uname eq '') ||
10420: ($udom eq 'public') && ($uname eq 'public')) {
10421: $quota = 0;
1.536 raeburn 10422: $quotatype = 'default';
10423: $defquota = 0;
1.472 raeburn 10424: } else {
1.536 raeburn 10425: my $inststatus;
1.1075.2.41 raeburn 10426: if ($quotaname eq 'course') {
10427: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10428: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10429: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10430: } else {
10431: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10432: $quota = $cenv{'internal.uploadquota'};
10433: }
1.536 raeburn 10434: } else {
1.1075.2.41 raeburn 10435: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10436: if ($quotaname eq 'author') {
10437: $quota = $env{'environment.authorquota'};
10438: } else {
10439: $quota = $env{'environment.portfolioquota'};
10440: }
10441: $inststatus = $env{'environment.inststatus'};
10442: } else {
10443: my %userenv =
10444: &Apache::lonnet::get('environment',['portfolioquota',
10445: 'authorquota','inststatus'],$udom,$uname);
10446: my ($tmp) = keys(%userenv);
10447: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10448: if ($quotaname eq 'author') {
10449: $quota = $userenv{'authorquota'};
10450: } else {
10451: $quota = $userenv{'portfolioquota'};
10452: }
10453: $inststatus = $userenv{'inststatus'};
10454: } else {
10455: undef(%userenv);
10456: }
10457: }
10458: }
10459: if ($quota eq '' || wantarray) {
10460: if ($quotaname eq 'course') {
10461: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 10462: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
10463: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 10464: $defquota = $domdefs{$crstype.'quota'};
10465: }
10466: if ($defquota eq '') {
10467: $defquota = 500;
10468: }
1.1075.2.41 raeburn 10469: } else {
10470: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10471: }
10472: if ($quota eq '') {
10473: $quota = $defquota;
10474: $quotatype = 'default';
10475: } else {
10476: $quotatype = 'custom';
10477: }
1.472 raeburn 10478: }
10479: }
1.536 raeburn 10480: if (wantarray) {
10481: return ($quota,$quotatype,$settingstatus,$defquota);
10482: } else {
10483: return $quota;
10484: }
1.472 raeburn 10485: }
10486:
10487: ###############################################
10488:
10489: =pod
10490:
10491: =item * &default_quota()
10492:
1.536 raeburn 10493: Retrieves default quota assigned for storage of user portfolio files,
10494: given an (optional) user's institutional status.
1.472 raeburn 10495:
10496: Incoming parameters:
1.1075.2.42 raeburn 10497:
1.472 raeburn 10498: 1. domain
1.536 raeburn 10499: 2. (Optional) institutional status(es). This is a : separated list of
10500: status types (e.g., faculty, staff, student etc.)
10501: which apply to the user for whom the default is being retrieved.
10502: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 10503: default quota will be returned.
10504: 3. quota name - portfolio, author, or course
10505: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10506:
10507: Returns:
1.1075.2.42 raeburn 10508:
1.1075.2.58 raeburn 10509: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10510: 2. (Optional) institutional type which determined the value of the
10511: default quota.
1.472 raeburn 10512:
10513: If a value has been stored in the domain's configuration db,
10514: it will return that, otherwise it returns 20 (for backwards
10515: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 10516: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10517:
1.536 raeburn 10518: If the user's status includes multiple types (e.g., staff and student),
10519: the largest default quota which applies to the user determines the
10520: default quota returned.
10521:
1.472 raeburn 10522: =cut
10523:
10524: ###############################################
10525:
10526:
10527: sub default_quota {
1.1075.2.41 raeburn 10528: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10529: my ($defquota,$settingstatus);
10530: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10531: ['quotas'],$udom);
1.1075.2.41 raeburn 10532: my $key = 'defaultquota';
10533: if ($quotaname eq 'author') {
10534: $key = 'authorquota';
10535: }
1.622 raeburn 10536: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10537: if ($inststatus ne '') {
1.765 raeburn 10538: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10539: foreach my $item (@statuses) {
1.1075.2.41 raeburn 10540: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10541: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10542: if ($defquota eq '') {
1.1075.2.41 raeburn 10543: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10544: $settingstatus = $item;
1.1075.2.41 raeburn 10545: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10546: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10547: $settingstatus = $item;
10548: }
10549: }
1.1075.2.41 raeburn 10550: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10551: if ($quotahash{'quotas'}{$item} ne '') {
10552: if ($defquota eq '') {
10553: $defquota = $quotahash{'quotas'}{$item};
10554: $settingstatus = $item;
10555: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10556: $defquota = $quotahash{'quotas'}{$item};
10557: $settingstatus = $item;
10558: }
1.536 raeburn 10559: }
10560: }
10561: }
10562: }
10563: if ($defquota eq '') {
1.1075.2.41 raeburn 10564: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10565: $defquota = $quotahash{'quotas'}{$key}{'default'};
10566: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10567: $defquota = $quotahash{'quotas'}{'default'};
10568: }
1.536 raeburn 10569: $settingstatus = 'default';
1.1075.2.42 raeburn 10570: if ($defquota eq '') {
10571: if ($quotaname eq 'author') {
10572: $defquota = 500;
10573: }
10574: }
1.536 raeburn 10575: }
10576: } else {
10577: $settingstatus = 'default';
1.1075.2.41 raeburn 10578: if ($quotaname eq 'author') {
10579: $defquota = 500;
10580: } else {
10581: $defquota = 20;
10582: }
1.536 raeburn 10583: }
10584: if (wantarray) {
10585: return ($defquota,$settingstatus);
1.472 raeburn 10586: } else {
1.536 raeburn 10587: return $defquota;
1.472 raeburn 10588: }
10589: }
10590:
1.1075.2.41 raeburn 10591: ###############################################
10592:
10593: =pod
10594:
1.1075.2.42 raeburn 10595: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 10596:
10597: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 10598: of existing file within authoring space will cause quota for the authoring
10599: space to be exceeded.
10600:
10601: Same, if upload of a file directly to a course/community via Course Editor
10602: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 10603:
1.1075.2.61 raeburn 10604: Inputs: 7
1.1075.2.42 raeburn 10605: 1. username or coursenum
1.1075.2.41 raeburn 10606: 2. domain
1.1075.2.42 raeburn 10607: 3. context ('author' or 'course')
1.1075.2.41 raeburn 10608: 4. filename of file for which action is being requested
10609: 5. filesize (kB) of file
10610: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 10611: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 10612:
10613: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
10614: otherwise return null.
10615:
1.1075.2.42 raeburn 10616: =back
10617:
1.1075.2.41 raeburn 10618: =cut
10619:
1.1075.2.42 raeburn 10620: sub excess_filesize_warning {
1.1075.2.59 raeburn 10621: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 10622: my $current_disk_usage = 0;
1.1075.2.59 raeburn 10623: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 10624: if ($context eq 'author') {
10625: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10626: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10627: } else {
10628: foreach my $subdir ('docs','supplemental') {
10629: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10630: }
10631: }
1.1075.2.41 raeburn 10632: $disk_quota = int($disk_quota * 1000);
10633: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 10634: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 10635: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 10636: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10637: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 10638: $disk_quota,$current_disk_usage).
10639: '</p>';
10640: }
10641: return;
10642: }
10643:
10644: ###############################################
10645:
10646:
1.384 raeburn 10647: sub get_secgrprole_info {
10648: my ($cdom,$cnum,$needroles,$type) = @_;
10649: my %sections_count = &get_sections($cdom,$cnum);
10650: my @sections = (sort {$a <=> $b} keys(%sections_count));
10651: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10652: my @groups = sort(keys(%curr_groups));
10653: my $allroles = [];
10654: my $rolehash;
10655: my $accesshash = {
10656: active => 'Currently has access',
10657: future => 'Will have future access',
10658: previous => 'Previously had access',
10659: };
10660: if ($needroles) {
10661: $rolehash = {'all' => 'all'};
1.385 albertel 10662: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10663: if (&Apache::lonnet::error(%user_roles)) {
10664: undef(%user_roles);
10665: }
10666: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10667: my ($role)=split(/\:/,$item,2);
10668: if ($role eq 'cr') { next; }
10669: if ($role =~ /^cr/) {
10670: $$rolehash{$role} = (split('/',$role))[3];
10671: } else {
10672: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10673: }
10674: }
10675: foreach my $key (sort(keys(%{$rolehash}))) {
10676: push(@{$allroles},$key);
10677: }
10678: push (@{$allroles},'st');
10679: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10680: }
10681: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10682: }
10683:
1.555 raeburn 10684: sub user_picker {
1.1075.2.127 raeburn 10685: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10686: my $currdom = $dom;
1.1075.2.114 raeburn 10687: my @alldoms = &Apache::lonnet::all_domains();
10688: if (@alldoms == 1) {
10689: my %domsrch = &Apache::lonnet::get_dom('configuration',
10690: ['directorysrch'],$alldoms[0]);
10691: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10692: my $showdom = $domdesc;
10693: if ($showdom eq '') {
10694: $showdom = $dom;
10695: }
10696: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10697: if ((!$domsrch{'directorysrch'}{'available'}) &&
10698: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10699: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10700: }
10701: }
10702: }
1.555 raeburn 10703: my %curr_selected = (
10704: srchin => 'dom',
1.580 raeburn 10705: srchby => 'lastname',
1.555 raeburn 10706: );
10707: my $srchterm;
1.625 raeburn 10708: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10709: if ($srch->{'srchby'} ne '') {
10710: $curr_selected{'srchby'} = $srch->{'srchby'};
10711: }
10712: if ($srch->{'srchin'} ne '') {
10713: $curr_selected{'srchin'} = $srch->{'srchin'};
10714: }
10715: if ($srch->{'srchtype'} ne '') {
10716: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10717: }
10718: if ($srch->{'srchdomain'} ne '') {
10719: $currdom = $srch->{'srchdomain'};
10720: }
10721: $srchterm = $srch->{'srchterm'};
10722: }
1.1075.2.98 raeburn 10723: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10724: 'usr' => 'Search criteria',
1.563 raeburn 10725: 'doma' => 'Domain/institution to search',
1.558 albertel 10726: 'uname' => 'username',
10727: 'lastname' => 'last name',
1.555 raeburn 10728: 'lastfirst' => 'last name, first name',
1.558 albertel 10729: 'crs' => 'in this course',
1.576 raeburn 10730: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10731: 'alc' => 'all LON-CAPA',
1.573 raeburn 10732: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10733: 'exact' => 'is',
10734: 'contains' => 'contains',
1.569 raeburn 10735: 'begins' => 'begins with',
1.1075.2.98 raeburn 10736: );
10737: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10738: 'youm' => "You must include some text to search for.",
10739: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10740: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10741: 'yomc' => "You must choose a domain when using an institutional directory search.",
10742: 'ymcd' => "You must choose a domain when using a domain search.",
10743: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10744: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10745: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10746: );
1.1075.2.98 raeburn 10747: &html_escape(\%html_lt);
10748: &js_escape(\%js_lt);
1.1075.2.115 raeburn 10749: my $domform;
1.1075.2.126 raeburn 10750: my $allow_blank = 1;
1.1075.2.115 raeburn 10751: if ($fixeddom) {
1.1075.2.126 raeburn 10752: $allow_blank = 0;
10753: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 10754: } else {
1.1075.2.126 raeburn 10755: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 10756: }
1.563 raeburn 10757: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10758:
10759: my @srchins = ('crs','dom','alc','instd');
10760:
10761: foreach my $option (@srchins) {
10762: # FIXME 'alc' option unavailable until
10763: # loncreateuser::print_user_query_page()
10764: # has been completed.
10765: next if ($option eq 'alc');
1.880 raeburn 10766: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10767: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 10768: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10769: if ($curr_selected{'srchin'} eq $option) {
10770: $srchinsel .= '
1.1075.2.98 raeburn 10771: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10772: } else {
10773: $srchinsel .= '
1.1075.2.98 raeburn 10774: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10775: }
1.555 raeburn 10776: }
1.563 raeburn 10777: $srchinsel .= "\n </select>\n";
1.555 raeburn 10778:
10779: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10780: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10781: if ($curr_selected{'srchby'} eq $option) {
10782: $srchbysel .= '
1.1075.2.98 raeburn 10783: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10784: } else {
10785: $srchbysel .= '
1.1075.2.98 raeburn 10786: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10787: }
10788: }
10789: $srchbysel .= "\n </select>\n";
10790:
10791: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10792: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10793: if ($curr_selected{'srchtype'} eq $option) {
10794: $srchtypesel .= '
1.1075.2.98 raeburn 10795: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10796: } else {
10797: $srchtypesel .= '
1.1075.2.98 raeburn 10798: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10799: }
10800: }
10801: $srchtypesel .= "\n </select>\n";
10802:
1.558 albertel 10803: my ($newuserscript,$new_user_create);
1.994 raeburn 10804: my $context_dom = $env{'request.role.domain'};
10805: if ($context eq 'requestcrs') {
10806: if ($env{'form.coursedom'} ne '') {
10807: $context_dom = $env{'form.coursedom'};
10808: }
10809: }
1.556 raeburn 10810: if ($forcenewuser) {
1.576 raeburn 10811: if (ref($srch) eq 'HASH') {
1.994 raeburn 10812: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10813: if ($cancreate) {
10814: $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>';
10815: } else {
1.799 bisitz 10816: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10817: my %usertypetext = (
10818: official => 'institutional',
10819: unofficial => 'non-institutional',
10820: );
1.799 bisitz 10821: $new_user_create = '<p class="LC_warning">'
10822: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10823: .' '
10824: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10825: ,'<a href="'.$helplink.'">','</a>')
10826: .'</p><br />';
1.627 raeburn 10827: }
1.576 raeburn 10828: }
10829: }
10830:
1.556 raeburn 10831: $newuserscript = <<"ENDSCRIPT";
10832:
1.570 raeburn 10833: function setSearch(createnew,callingForm) {
1.556 raeburn 10834: if (createnew == 1) {
1.570 raeburn 10835: for (var i=0; i<callingForm.srchby.length; i++) {
10836: if (callingForm.srchby.options[i].value == 'uname') {
10837: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10838: }
10839: }
1.570 raeburn 10840: for (var i=0; i<callingForm.srchin.length; i++) {
10841: if ( callingForm.srchin.options[i].value == 'dom') {
10842: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10843: }
10844: }
1.570 raeburn 10845: for (var i=0; i<callingForm.srchtype.length; i++) {
10846: if (callingForm.srchtype.options[i].value == 'exact') {
10847: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10848: }
10849: }
1.570 raeburn 10850: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10851: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10852: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10853: }
10854: }
10855: }
10856: }
10857: ENDSCRIPT
1.558 albertel 10858:
1.556 raeburn 10859: }
10860:
1.555 raeburn 10861: my $output = <<"END_BLOCK";
1.556 raeburn 10862: <script type="text/javascript">
1.824 bisitz 10863: // <![CDATA[
1.570 raeburn 10864: function validateEntry(callingForm) {
1.558 albertel 10865:
1.556 raeburn 10866: var checkok = 1;
1.558 albertel 10867: var srchin;
1.570 raeburn 10868: for (var i=0; i<callingForm.srchin.length; i++) {
10869: if ( callingForm.srchin[i].checked ) {
10870: srchin = callingForm.srchin[i].value;
1.558 albertel 10871: }
10872: }
10873:
1.570 raeburn 10874: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10875: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10876: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10877: var srchterm = callingForm.srchterm.value;
10878: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10879: var msg = "";
10880:
10881: if (srchterm == "") {
10882: checkok = 0;
1.1075.2.98 raeburn 10883: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10884: }
10885:
1.569 raeburn 10886: if (srchtype== 'begins') {
10887: if (srchterm.length < 2) {
10888: checkok = 0;
1.1075.2.98 raeburn 10889: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10890: }
10891: }
10892:
1.556 raeburn 10893: if (srchtype== 'contains') {
10894: if (srchterm.length < 3) {
10895: checkok = 0;
1.1075.2.98 raeburn 10896: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10897: }
10898: }
10899: if (srchin == 'instd') {
10900: if (srchdomain == '') {
10901: checkok = 0;
1.1075.2.98 raeburn 10902: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10903: }
10904: }
10905: if (srchin == 'dom') {
10906: if (srchdomain == '') {
10907: checkok = 0;
1.1075.2.98 raeburn 10908: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10909: }
10910: }
10911: if (srchby == 'lastfirst') {
10912: if (srchterm.indexOf(",") == -1) {
10913: checkok = 0;
1.1075.2.98 raeburn 10914: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10915: }
10916: if (srchterm.indexOf(",") == srchterm.length -1) {
10917: checkok = 0;
1.1075.2.98 raeburn 10918: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10919: }
10920: }
10921: if (checkok == 0) {
1.1075.2.98 raeburn 10922: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10923: return;
10924: }
10925: if (checkok == 1) {
1.570 raeburn 10926: callingForm.submit();
1.556 raeburn 10927: }
10928: }
10929:
10930: $newuserscript
10931:
1.824 bisitz 10932: // ]]>
1.556 raeburn 10933: </script>
1.558 albertel 10934:
10935: $new_user_create
10936:
1.555 raeburn 10937: END_BLOCK
1.558 albertel 10938:
1.876 raeburn 10939: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 10940: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10941: $domform.
10942: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 10943: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10944: $srchbysel.
10945: $srchtypesel.
10946: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10947: $srchinsel.
10948: &Apache::lonhtmlcommon::row_closure(1).
10949: &Apache::lonhtmlcommon::end_pick_box().
10950: '<br />';
1.1075.2.114 raeburn 10951: return ($output,1);
1.555 raeburn 10952: }
10953:
1.612 raeburn 10954: sub user_rule_check {
1.615 raeburn 10955: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 10956: my ($response,%inst_response);
1.612 raeburn 10957: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 10958: if (keys(%{$usershash}) > 1) {
10959: my (%by_username,%by_id,%userdoms);
10960: my $checkid;
1.612 raeburn 10961: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 10962: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10963: $checkid = 1;
10964: }
10965: }
10966: foreach my $user (keys(%{$usershash})) {
10967: my ($uname,$udom) = split(/:/,$user);
10968: if ($checkid) {
10969: if (ref($usershash->{$user}) eq 'HASH') {
10970: if ($usershash->{$user}->{'id'} ne '') {
10971: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
10972: $userdoms{$udom} = 1;
10973: if (ref($inst_results) eq 'HASH') {
10974: $inst_results->{$uname.':'.$udom} = {};
10975: }
10976: }
10977: }
10978: } else {
10979: $by_username{$udom}{$uname} = 1;
10980: $userdoms{$udom} = 1;
10981: if (ref($inst_results) eq 'HASH') {
10982: $inst_results->{$uname.':'.$udom} = {};
10983: }
10984: }
10985: }
10986: foreach my $udom (keys(%userdoms)) {
10987: if (!$got_rules->{$udom}) {
10988: my %domconfig = &Apache::lonnet::get_dom('configuration',
10989: ['usercreation'],$udom);
10990: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10991: foreach my $item ('username','id') {
10992: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10993: $$curr_rules{$udom}{$item} =
10994: $domconfig{'usercreation'}{$item.'_rule'};
10995: }
10996: }
10997: }
10998: $got_rules->{$udom} = 1;
10999: }
11000: }
11001: if ($checkid) {
11002: foreach my $udom (keys(%by_id)) {
11003: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
11004: if ($outcome eq 'ok') {
11005: foreach my $id (keys(%{$by_id{$udom}})) {
11006: my $uname = $by_id{$udom}{$id};
11007: $inst_response{$uname.':'.$udom} = $outcome;
11008: }
11009: if (ref($results) eq 'HASH') {
11010: foreach my $uname (keys(%{$results})) {
11011: if (exists($inst_response{$uname.':'.$udom})) {
11012: $inst_response{$uname.':'.$udom} = $outcome;
11013: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11014: }
11015: }
11016: }
11017: }
1.612 raeburn 11018: }
1.615 raeburn 11019: } else {
1.1075.2.99 raeburn 11020: foreach my $udom (keys(%by_username)) {
11021: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
11022: if ($outcome eq 'ok') {
11023: foreach my $uname (keys(%{$by_username{$udom}})) {
11024: $inst_response{$uname.':'.$udom} = $outcome;
11025: }
11026: if (ref($results) eq 'HASH') {
11027: foreach my $uname (keys(%{$results})) {
11028: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11029: }
11030: }
11031: }
11032: }
1.612 raeburn 11033: }
1.1075.2.99 raeburn 11034: } elsif (keys(%{$usershash}) == 1) {
11035: my $user = (keys(%{$usershash}))[0];
11036: my ($uname,$udom) = split(/:/,$user);
11037: if (($udom ne '') && ($uname ne '')) {
11038: if (ref($usershash->{$user}) eq 'HASH') {
11039: if (ref($checks) eq 'HASH') {
11040: if (defined($checks->{'username'})) {
11041: ($inst_response{$user},%{$inst_results->{$user}}) =
11042: &Apache::lonnet::get_instuser($udom,$uname);
11043: } elsif (defined($checks->{'id'})) {
11044: if ($usershash->{$user}->{'id'} ne '') {
11045: ($inst_response{$user},%{$inst_results->{$user}}) =
11046: &Apache::lonnet::get_instuser($udom,undef,
11047: $usershash->{$user}->{'id'});
11048: } else {
11049: ($inst_response{$user},%{$inst_results->{$user}}) =
11050: &Apache::lonnet::get_instuser($udom,$uname);
11051: }
11052: }
11053: } else {
11054: ($inst_response{$user},%{$inst_results->{$user}}) =
11055: &Apache::lonnet::get_instuser($udom,$uname);
11056: return;
11057: }
11058: if (!$got_rules->{$udom}) {
11059: my %domconfig = &Apache::lonnet::get_dom('configuration',
11060: ['usercreation'],$udom);
11061: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11062: foreach my $item ('username','id') {
11063: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
11064: $$curr_rules{$udom}{$item} =
11065: $domconfig{'usercreation'}{$item.'_rule'};
11066: }
11067: }
1.585 raeburn 11068: }
1.1075.2.99 raeburn 11069: $got_rules->{$udom} = 1;
1.585 raeburn 11070: }
11071: }
1.1075.2.99 raeburn 11072: } else {
11073: return;
11074: }
11075: } else {
11076: return;
11077: }
11078: foreach my $user (keys(%{$usershash})) {
11079: my ($uname,$udom) = split(/:/,$user);
11080: next if (($udom eq '') || ($uname eq ''));
11081: my $id;
11082: if (ref($inst_results) eq 'HASH') {
11083: if (ref($inst_results->{$user}) eq 'HASH') {
11084: $id = $inst_results->{$user}->{'id'};
11085: }
11086: }
11087: if ($id eq '') {
11088: if (ref($usershash->{$user})) {
11089: $id = $usershash->{$user}->{'id'};
11090: }
1.585 raeburn 11091: }
1.612 raeburn 11092: foreach my $item (keys(%{$checks})) {
11093: if (ref($$curr_rules{$udom}) eq 'HASH') {
11094: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
11095: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 11096: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
11097: $$curr_rules{$udom}{$item});
1.612 raeburn 11098: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
11099: if ($rule_check{$rule}) {
11100: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 11101: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 11102: if (ref($inst_results) eq 'HASH') {
11103: if (ref($inst_results->{$user}) eq 'HASH') {
11104: if (keys(%{$inst_results->{$user}}) == 0) {
11105: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 11106: } elsif ($item eq 'id') {
11107: if ($inst_results->{$user}->{'id'} eq '') {
11108: $$alerts{$item}{$udom}{$uname} = 1;
11109: }
1.615 raeburn 11110: }
1.612 raeburn 11111: }
11112: }
1.615 raeburn 11113: }
11114: last;
1.585 raeburn 11115: }
11116: }
11117: }
11118: }
11119: }
11120: }
11121: }
11122: }
1.612 raeburn 11123: return;
11124: }
11125:
11126: sub user_rule_formats {
11127: my ($domain,$domdesc,$curr_rules,$check) = @_;
11128: my %text = (
11129: 'username' => 'Usernames',
11130: 'id' => 'IDs',
11131: );
11132: my $output;
11133: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
11134: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
11135: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 11136: $output = '<br />'.
11137: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
11138: '<span class="LC_cusr_emph">','</span>',$domdesc).
11139: ' <ul>';
1.612 raeburn 11140: foreach my $rule (@{$ruleorder}) {
11141: if (ref($curr_rules) eq 'ARRAY') {
11142: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
11143: if (ref($rules->{$rule}) eq 'HASH') {
11144: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
11145: $rules->{$rule}{'desc'}.'</li>';
11146: }
11147: }
11148: }
11149: }
11150: $output .= '</ul>';
11151: }
11152: }
11153: return $output;
11154: }
11155:
11156: sub instrule_disallow_msg {
1.615 raeburn 11157: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 11158: my $response;
11159: my %text = (
11160: item => 'username',
11161: items => 'usernames',
11162: match => 'matches',
11163: do => 'does',
11164: action => 'a username',
11165: one => 'one',
11166: );
11167: if ($count > 1) {
11168: $text{'item'} = 'usernames';
11169: $text{'match'} ='match';
11170: $text{'do'} = 'do';
11171: $text{'action'} = 'usernames',
11172: $text{'one'} = 'ones';
11173: }
11174: if ($checkitem eq 'id') {
11175: $text{'items'} = 'IDs';
11176: $text{'item'} = 'ID';
11177: $text{'action'} = 'an ID';
1.615 raeburn 11178: if ($count > 1) {
11179: $text{'item'} = 'IDs';
11180: $text{'action'} = 'IDs';
11181: }
1.612 raeburn 11182: }
1.674 bisitz 11183: $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 11184: if ($mode eq 'upload') {
11185: if ($checkitem eq 'username') {
11186: $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'}.");
11187: } elsif ($checkitem eq 'id') {
1.674 bisitz 11188: $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 11189: }
1.669 raeburn 11190: } elsif ($mode eq 'selfcreate') {
11191: if ($checkitem eq 'id') {
11192: $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.");
11193: }
1.615 raeburn 11194: } else {
11195: if ($checkitem eq 'username') {
11196: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
11197: } elsif ($checkitem eq 'id') {
11198: $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.");
11199: }
1.612 raeburn 11200: }
11201: return $response;
1.585 raeburn 11202: }
11203:
1.624 raeburn 11204: sub personal_data_fieldtitles {
11205: my %fieldtitles = &Apache::lonlocal::texthash (
11206: id => 'Student/Employee ID',
11207: permanentemail => 'E-mail address',
11208: lastname => 'Last Name',
11209: firstname => 'First Name',
11210: middlename => 'Middle Name',
11211: generation => 'Generation',
11212: gen => 'Generation',
1.765 raeburn 11213: inststatus => 'Affiliation',
1.624 raeburn 11214: );
11215: return %fieldtitles;
11216: }
11217:
1.642 raeburn 11218: sub sorted_inst_types {
11219: my ($dom) = @_;
1.1075.2.70 raeburn 11220: my ($usertypes,$order);
11221: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11222: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
11223: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
11224: $order = $domdefaults{'inststatus'}{'inststatusorder'};
11225: } else {
11226: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
11227: }
1.642 raeburn 11228: my $othertitle = &mt('All users');
11229: if ($env{'request.course.id'}) {
1.668 raeburn 11230: $othertitle = &mt('Any users');
1.642 raeburn 11231: }
11232: my @types;
11233: if (ref($order) eq 'ARRAY') {
11234: @types = @{$order};
11235: }
11236: if (@types == 0) {
11237: if (ref($usertypes) eq 'HASH') {
11238: @types = sort(keys(%{$usertypes}));
11239: }
11240: }
11241: if (keys(%{$usertypes}) > 0) {
11242: $othertitle = &mt('Other users');
11243: }
11244: return ($othertitle,$usertypes,\@types);
11245: }
11246:
1.645 raeburn 11247: sub get_institutional_codes {
1.1075.2.157 raeburn 11248: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 11249: # Get complete list of course sections to update
11250: my @currsections = ();
11251: my @currxlists = ();
1.1075.2.157 raeburn 11252: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 11253: my $coursecode = $$settings{'internal.coursecode'};
1.1075.2.157 raeburn 11254: my $crskey = $crs.':'.$coursecode;
11255: @{$unclutteredsec{$crskey}} = ();
11256: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 11257:
11258: if ($$settings{'internal.sectionnums'} ne '') {
11259: @currsections = split(/,/,$$settings{'internal.sectionnums'});
11260: }
11261:
11262: if ($$settings{'internal.crosslistings'} ne '') {
11263: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
11264: }
11265:
11266: if (@currxlists > 0) {
1.1075.2.157 raeburn 11267: foreach my $xl (@currxlists) {
11268: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 11269: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 11270: push(@{$allcourses},$1);
1.645 raeburn 11271: $$LC_code{$1} = $2;
11272: }
11273: }
11274: }
11275: }
1.1075.2.157 raeburn 11276:
1.645 raeburn 11277: if (@currsections > 0) {
1.1075.2.157 raeburn 11278: foreach my $sec (@currsections) {
11279: if ($sec =~ m/^(\w+):(\w*)$/ ) {
11280: my $instsec = $1;
1.645 raeburn 11281: my $lc_sec = $2;
1.1075.2.157 raeburn 11282: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
11283: push(@{$unclutteredsec{$crskey}},$instsec);
11284: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
11285: }
11286: }
11287: }
11288: }
11289:
11290: if (@{$unclutteredsec{$crskey}} > 0) {
11291: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
11292: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
11293: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
11294: my $sec = $coursecode.$formattedsec{$crskey}[$i];
11295: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1075.2.119 raeburn 11296: push(@{$allcourses},$sec);
1.1075.2.157 raeburn 11297: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 11298: }
11299: }
11300: }
11301: }
11302: return;
11303: }
11304:
1.971 raeburn 11305: sub get_standard_codeitems {
11306: return ('Year','Semester','Department','Number','Section');
11307: }
11308:
1.112 bowersj2 11309: =pod
11310:
1.780 raeburn 11311: =head1 Slot Helpers
11312:
11313: =over 4
11314:
11315: =item * sorted_slots()
11316:
1.1040 raeburn 11317: Sorts an array of slot names in order of an optional sort key,
11318: default sort is by slot start time (earliest first).
1.780 raeburn 11319:
11320: Inputs:
11321:
11322: =over 4
11323:
11324: slotsarr - Reference to array of unsorted slot names.
11325:
11326: slots - Reference to hash of hash, where outer hash keys are slot names.
11327:
1.1040 raeburn 11328: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
11329:
1.549 albertel 11330: =back
11331:
1.780 raeburn 11332: Returns:
11333:
11334: =over 4
11335:
1.1040 raeburn 11336: sorted - An array of slot names sorted by a specified sort key
11337: (default sort key is start time of the slot).
1.780 raeburn 11338:
11339: =back
11340:
11341: =cut
11342:
11343:
11344: sub sorted_slots {
1.1040 raeburn 11345: my ($slotsarr,$slots,$sortkey) = @_;
11346: if ($sortkey eq '') {
11347: $sortkey = 'starttime';
11348: }
1.780 raeburn 11349: my @sorted;
11350: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11351: @sorted =
11352: sort {
11353: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11354: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11355: }
11356: if (ref($slots->{$a})) { return -1;}
11357: if (ref($slots->{$b})) { return 1;}
11358: return 0;
11359: } @{$slotsarr};
11360: }
11361: return @sorted;
11362: }
11363:
1.1040 raeburn 11364: =pod
11365:
11366: =item * get_future_slots()
11367:
11368: Inputs:
11369:
11370: =over 4
11371:
11372: cnum - course number
11373:
11374: cdom - course domain
11375:
11376: now - current UNIX time
11377:
11378: symb - optional symb
11379:
11380: =back
11381:
11382: Returns:
11383:
11384: =over 4
11385:
11386: sorted_reservable - ref to array of student_schedulable slots currently
11387: reservable, ordered by end date of reservation period.
11388:
11389: reservable_now - ref to hash of student_schedulable slots currently
11390: reservable.
11391:
11392: Keys in inner hash are:
11393: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 11394: (b) endreserve: end date of reservation period.
11395: (c) uniqueperiod: start,end dates when slot is to be uniquely
11396: selected.
1.1040 raeburn 11397:
11398: sorted_future - ref to array of student_schedulable slots reservable in
11399: the future, ordered by start date of reservation period.
11400:
11401: future_reservable - ref to hash of student_schedulable slots reservable
11402: in the future.
11403:
11404: Keys in inner hash are:
11405: (a) symb: either blank or symb to which slot use is restricted.
11406: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 11407: (c) uniqueperiod: start,end dates when slot is to be uniquely
11408: selected.
1.1040 raeburn 11409:
11410: =back
11411:
11412: =cut
11413:
11414: sub get_future_slots {
11415: my ($cnum,$cdom,$now,$symb) = @_;
11416: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11417: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11418: foreach my $slot (keys(%slots)) {
11419: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11420: if ($symb) {
11421: next if (($slots{$slot}->{'symb'} ne '') &&
11422: ($slots{$slot}->{'symb'} ne $symb));
11423: }
11424: if (($slots{$slot}->{'starttime'} > $now) &&
11425: ($slots{$slot}->{'endtime'} > $now)) {
11426: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11427: my $userallowed = 0;
11428: if ($slots{$slot}->{'allowedsections'}) {
11429: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11430: if (!defined($env{'request.role.sec'})
11431: && grep(/^No section assigned$/,@allowed_sec)) {
11432: $userallowed=1;
11433: } else {
11434: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11435: $userallowed=1;
11436: }
11437: }
11438: unless ($userallowed) {
11439: if (defined($env{'request.course.groups'})) {
11440: my @groups = split(/:/,$env{'request.course.groups'});
11441: foreach my $group (@groups) {
11442: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11443: $userallowed=1;
11444: last;
11445: }
11446: }
11447: }
11448: }
11449: }
11450: if ($slots{$slot}->{'allowedusers'}) {
11451: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11452: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11453: if (grep(/^\Q$user\E$/,@allowed_users)) {
11454: $userallowed = 1;
11455: }
11456: }
11457: next unless($userallowed);
11458: }
11459: my $startreserve = $slots{$slot}->{'startreserve'};
11460: my $endreserve = $slots{$slot}->{'endreserve'};
11461: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 11462: my $uniqueperiod;
11463: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11464: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11465: }
1.1040 raeburn 11466: if (($startreserve < $now) &&
11467: (!$endreserve || $endreserve > $now)) {
11468: my $lastres = $endreserve;
11469: if (!$lastres) {
11470: $lastres = $slots{$slot}->{'starttime'};
11471: }
11472: $reservable_now{$slot} = {
11473: symb => $symb,
1.1075.2.104 raeburn 11474: endreserve => $lastres,
11475: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11476: };
11477: } elsif (($startreserve > $now) &&
11478: (!$endreserve || $endreserve > $startreserve)) {
11479: $future_reservable{$slot} = {
11480: symb => $symb,
1.1075.2.104 raeburn 11481: startreserve => $startreserve,
11482: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11483: };
11484: }
11485: }
11486: }
11487: my @unsorted_reservable = keys(%reservable_now);
11488: if (@unsorted_reservable > 0) {
11489: @sorted_reservable =
11490: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11491: }
11492: my @unsorted_future = keys(%future_reservable);
11493: if (@unsorted_future > 0) {
11494: @sorted_future =
11495: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11496: }
11497: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11498: }
1.780 raeburn 11499:
11500: =pod
11501:
1.1057 foxr 11502: =back
11503:
1.549 albertel 11504: =head1 HTTP Helpers
11505:
11506: =over 4
11507:
1.648 raeburn 11508: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11509:
1.258 albertel 11510: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11511: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11512: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11513:
11514: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11515: $possible_names is an ref to an array of form element names. As an example:
11516: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11517: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11518:
11519: =cut
1.1 albertel 11520:
1.6 albertel 11521: sub get_unprocessed_cgi {
1.25 albertel 11522: my ($query,$possible_names)= @_;
1.26 matthew 11523: # $Apache::lonxml::debug=1;
1.356 albertel 11524: foreach my $pair (split(/&/,$query)) {
11525: my ($name, $value) = split(/=/,$pair);
1.369 www 11526: $name = &unescape($name);
1.25 albertel 11527: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11528: $value =~ tr/+/ /;
11529: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11530: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11531: }
1.16 harris41 11532: }
1.6 albertel 11533: }
11534:
1.112 bowersj2 11535: =pod
11536:
1.648 raeburn 11537: =item * &cacheheader()
1.112 bowersj2 11538:
11539: returns cache-controlling header code
11540:
11541: =cut
11542:
1.7 albertel 11543: sub cacheheader {
1.258 albertel 11544: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11545: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11546: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11547: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11548: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11549: return $output;
1.7 albertel 11550: }
11551:
1.112 bowersj2 11552: =pod
11553:
1.648 raeburn 11554: =item * &no_cache($r)
1.112 bowersj2 11555:
11556: specifies header code to not have cache
11557:
11558: =cut
11559:
1.9 albertel 11560: sub no_cache {
1.216 albertel 11561: my ($r) = @_;
11562: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11563: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11564: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11565: $r->no_cache(1);
11566: $r->header_out("Expires" => $date);
11567: $r->header_out("Pragma" => "no-cache");
1.123 www 11568: }
11569:
11570: sub content_type {
1.181 albertel 11571: my ($r,$type,$charset) = @_;
1.299 foxr 11572: if ($r) {
11573: # Note that printout.pl calls this with undef for $r.
11574: &no_cache($r);
11575: }
1.258 albertel 11576: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11577: unless ($charset) {
11578: $charset=&Apache::lonlocal::current_encoding;
11579: }
11580: if ($charset) { $type.='; charset='.$charset; }
11581: if ($r) {
11582: $r->content_type($type);
11583: } else {
11584: print("Content-type: $type\n\n");
11585: }
1.9 albertel 11586: }
1.25 albertel 11587:
1.112 bowersj2 11588: =pod
11589:
1.648 raeburn 11590: =item * &add_to_env($name,$value)
1.112 bowersj2 11591:
1.258 albertel 11592: adds $name to the %env hash with value
1.112 bowersj2 11593: $value, if $name already exists, the entry is converted to an array
11594: reference and $value is added to the array.
11595:
11596: =cut
11597:
1.25 albertel 11598: sub add_to_env {
11599: my ($name,$value)=@_;
1.258 albertel 11600: if (defined($env{$name})) {
11601: if (ref($env{$name})) {
1.25 albertel 11602: #already have multiple values
1.258 albertel 11603: push(@{ $env{$name} },$value);
1.25 albertel 11604: } else {
11605: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11606: my $first=$env{$name};
11607: undef($env{$name});
11608: push(@{ $env{$name} },$first,$value);
1.25 albertel 11609: }
11610: } else {
1.258 albertel 11611: $env{$name}=$value;
1.25 albertel 11612: }
1.31 albertel 11613: }
1.149 albertel 11614:
11615: =pod
11616:
1.648 raeburn 11617: =item * &get_env_multiple($name)
1.149 albertel 11618:
1.258 albertel 11619: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11620: values may be defined and end up as an array ref.
11621:
11622: returns an array of values
11623:
11624: =cut
11625:
11626: sub get_env_multiple {
11627: my ($name) = @_;
11628: my @values;
1.258 albertel 11629: if (defined($env{$name})) {
1.149 albertel 11630: # exists is it an array
1.258 albertel 11631: if (ref($env{$name})) {
11632: @values=@{ $env{$name} };
1.149 albertel 11633: } else {
1.258 albertel 11634: $values[0]=$env{$name};
1.149 albertel 11635: }
11636: }
11637: return(@values);
11638: }
11639:
1.660 raeburn 11640: sub ask_for_embedded_content {
11641: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11642: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 11643: %currsubfile,%unused,$rem);
1.1071 raeburn 11644: my $counter = 0;
11645: my $numnew = 0;
1.987 raeburn 11646: my $numremref = 0;
11647: my $numinvalid = 0;
11648: my $numpathchg = 0;
11649: my $numexisting = 0;
1.1071 raeburn 11650: my $numunused = 0;
11651: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 11652: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11653: my $heading = &mt('Upload embedded files');
11654: my $buttontext = &mt('Upload');
11655:
1.1075.2.11 raeburn 11656: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 11657: if ($actionurl eq '/adm/dependencies') {
11658: $navmap = Apache::lonnavmaps::navmap->new();
11659: }
11660: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11661: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 11662: }
1.1075.2.35 raeburn 11663: if (($actionurl eq '/adm/portfolio') ||
11664: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11665: my $current_path='/';
11666: if ($env{'form.currentpath'}) {
11667: $current_path = $env{'form.currentpath'};
11668: }
11669: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 11670: $udom = $cdom;
11671: $uname = $cnum;
1.984 raeburn 11672: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11673: } else {
11674: $udom = $env{'user.domain'};
11675: $uname = $env{'user.name'};
11676: $url = '/userfiles/portfolio';
11677: }
1.987 raeburn 11678: $toplevel = $url.'/';
1.984 raeburn 11679: $url .= $current_path;
11680: $getpropath = 1;
1.987 raeburn 11681: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11682: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11683: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11684: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11685: $toplevel = $url;
1.984 raeburn 11686: if ($rest ne '') {
1.987 raeburn 11687: $url .= $rest;
11688: }
11689: } elsif ($actionurl eq '/adm/coursedocs') {
11690: if (ref($args) eq 'HASH') {
1.1071 raeburn 11691: $url = $args->{'docs_url'};
11692: $toplevel = $url;
1.1075.2.11 raeburn 11693: if ($args->{'context'} eq 'paste') {
11694: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11695: ($path) =
11696: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11697: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11698: $fileloc =~ s{^/}{};
11699: }
1.1071 raeburn 11700: }
11701: } elsif ($actionurl eq '/adm/dependencies') {
11702: if ($env{'request.course.id'} ne '') {
11703: if (ref($args) eq 'HASH') {
11704: $url = $args->{'docs_url'};
11705: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 11706: $toplevel = $url;
11707: unless ($toplevel =~ m{^/}) {
11708: $toplevel = "/$url";
11709: }
1.1075.2.11 raeburn 11710: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 11711: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11712: $path = $1;
11713: } else {
11714: ($path) =
11715: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11716: }
1.1075.2.79 raeburn 11717: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11718: $fileloc = $toplevel;
11719: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11720: my ($udom,$uname,$fname) =
11721: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11722: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11723: } else {
11724: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11725: }
1.1071 raeburn 11726: $fileloc =~ s{^/}{};
11727: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11728: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11729: }
1.987 raeburn 11730: }
1.1075.2.35 raeburn 11731: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11732: $udom = $cdom;
11733: $uname = $cnum;
11734: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11735: $toplevel = $url;
11736: $path = $url;
11737: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11738: $fileloc =~ s{^/}{};
11739: }
11740: foreach my $file (keys(%{$allfiles})) {
11741: my $embed_file;
11742: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11743: $embed_file = $1;
11744: } else {
11745: $embed_file = $file;
11746: }
1.1075.2.55 raeburn 11747: my ($absolutepath,$cleaned_file);
11748: if ($embed_file =~ m{^\w+://}) {
11749: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 11750: $newfiles{$cleaned_file} = 1;
11751: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11752: } else {
1.1075.2.55 raeburn 11753: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11754: if ($embed_file =~ m{^/}) {
11755: $absolutepath = $embed_file;
11756: }
1.1075.2.47 raeburn 11757: if ($cleaned_file =~ m{/}) {
11758: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11759: $path = &check_for_traversal($path,$url,$toplevel);
11760: my $item = $fname;
11761: if ($path ne '') {
11762: $item = $path.'/'.$fname;
11763: $subdependencies{$path}{$fname} = 1;
11764: } else {
11765: $dependencies{$item} = 1;
11766: }
11767: if ($absolutepath) {
11768: $mapping{$item} = $absolutepath;
11769: } else {
11770: $mapping{$item} = $embed_file;
11771: }
11772: } else {
11773: $dependencies{$embed_file} = 1;
11774: if ($absolutepath) {
1.1075.2.47 raeburn 11775: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11776: } else {
1.1075.2.47 raeburn 11777: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11778: }
11779: }
1.984 raeburn 11780: }
11781: }
1.1071 raeburn 11782: my $dirptr = 16384;
1.984 raeburn 11783: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11784: $currsubfile{$path} = {};
1.1075.2.35 raeburn 11785: if (($actionurl eq '/adm/portfolio') ||
11786: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11787: my ($sublistref,$listerror) =
11788: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11789: if (ref($sublistref) eq 'ARRAY') {
11790: foreach my $line (@{$sublistref}) {
11791: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11792: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11793: }
1.984 raeburn 11794: }
1.987 raeburn 11795: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11796: if (opendir(my $dir,$url.'/'.$path)) {
11797: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11798: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11799: }
1.1075.2.11 raeburn 11800: } elsif (($actionurl eq '/adm/dependencies') ||
11801: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 11802: ($args->{'context'} eq 'paste')) ||
11803: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11804: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 11805: my $dir;
11806: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11807: $dir = $fileloc;
11808: } else {
11809: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11810: }
1.1071 raeburn 11811: if ($dir ne '') {
11812: my ($sublistref,$listerror) =
11813: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11814: if (ref($sublistref) eq 'ARRAY') {
11815: foreach my $line (@{$sublistref}) {
11816: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11817: undef,$mtime)=split(/\&/,$line,12);
11818: unless (($testdir&$dirptr) ||
11819: ($file_name =~ /^\.\.?$/)) {
11820: $currsubfile{$path}{$file_name} = [$size,$mtime];
11821: }
11822: }
11823: }
11824: }
1.984 raeburn 11825: }
11826: }
11827: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11828: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11829: my $item = $path.'/'.$file;
11830: unless ($mapping{$item} eq $item) {
11831: $pathchanges{$item} = 1;
11832: }
11833: $existing{$item} = 1;
11834: $numexisting ++;
11835: } else {
11836: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11837: }
11838: }
1.1071 raeburn 11839: if ($actionurl eq '/adm/dependencies') {
11840: foreach my $path (keys(%currsubfile)) {
11841: if (ref($currsubfile{$path}) eq 'HASH') {
11842: foreach my $file (keys(%{$currsubfile{$path}})) {
11843: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 11844: next if (($rem ne '') &&
11845: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11846: (ref($navmap) &&
11847: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11848: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11849: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11850: $unused{$path.'/'.$file} = 1;
11851: }
11852: }
11853: }
11854: }
11855: }
1.984 raeburn 11856: }
1.987 raeburn 11857: my %currfile;
1.1075.2.35 raeburn 11858: if (($actionurl eq '/adm/portfolio') ||
11859: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11860: my ($dirlistref,$listerror) =
11861: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11862: if (ref($dirlistref) eq 'ARRAY') {
11863: foreach my $line (@{$dirlistref}) {
11864: my ($file_name,$rest) = split(/\&/,$line,2);
11865: $currfile{$file_name} = 1;
11866: }
1.984 raeburn 11867: }
1.987 raeburn 11868: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11869: if (opendir(my $dir,$url)) {
1.987 raeburn 11870: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11871: map {$currfile{$_} = 1;} @dir_list;
11872: }
1.1075.2.11 raeburn 11873: } elsif (($actionurl eq '/adm/dependencies') ||
11874: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 11875: ($args->{'context'} eq 'paste')) ||
11876: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11877: if ($env{'request.course.id'} ne '') {
11878: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11879: if ($dir ne '') {
11880: my ($dirlistref,$listerror) =
11881: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11882: if (ref($dirlistref) eq 'ARRAY') {
11883: foreach my $line (@{$dirlistref}) {
11884: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11885: $size,undef,$mtime)=split(/\&/,$line,12);
11886: unless (($testdir&$dirptr) ||
11887: ($file_name =~ /^\.\.?$/)) {
11888: $currfile{$file_name} = [$size,$mtime];
11889: }
11890: }
11891: }
11892: }
11893: }
1.984 raeburn 11894: }
11895: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11896: if (exists($currfile{$file})) {
1.987 raeburn 11897: unless ($mapping{$file} eq $file) {
11898: $pathchanges{$file} = 1;
11899: }
11900: $existing{$file} = 1;
11901: $numexisting ++;
11902: } else {
1.984 raeburn 11903: $newfiles{$file} = 1;
11904: }
11905: }
1.1071 raeburn 11906: foreach my $file (keys(%currfile)) {
11907: unless (($file eq $filename) ||
11908: ($file eq $filename.'.bak') ||
11909: ($dependencies{$file})) {
1.1075.2.11 raeburn 11910: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 11911: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11912: next if (($rem ne '') &&
11913: (($env{"httpref.$rem".$file} ne '') ||
11914: (ref($navmap) &&
11915: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11916: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11917: ($navmap->getResourceByUrl($rem.$1)))))));
11918: }
1.1075.2.11 raeburn 11919: }
1.1071 raeburn 11920: $unused{$file} = 1;
11921: }
11922: }
1.1075.2.11 raeburn 11923: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11924: ($args->{'context'} eq 'paste')) {
11925: $counter = scalar(keys(%existing));
11926: $numpathchg = scalar(keys(%pathchanges));
11927: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 11928: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11929: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11930: $counter = scalar(keys(%existing));
11931: $numpathchg = scalar(keys(%pathchanges));
11932: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 11933: }
1.984 raeburn 11934: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11935: if ($actionurl eq '/adm/dependencies') {
11936: next if ($embed_file =~ m{^\w+://});
11937: }
1.660 raeburn 11938: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11939: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11940: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11941: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 11942: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11943: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11944: }
1.1075.2.35 raeburn 11945: $upload_output .= '</td>';
1.1071 raeburn 11946: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 11947: $upload_output.='<td align="right">'.
11948: '<span class="LC_info LC_fontsize_medium">'.
11949: &mt("URL points to web address").'</span>';
1.987 raeburn 11950: $numremref++;
1.660 raeburn 11951: } elsif ($args->{'error_on_invalid_names'}
11952: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 11953: $upload_output.='<td align="right"><span class="LC_warning">'.
11954: &mt('Invalid characters').'</span>';
1.987 raeburn 11955: $numinvalid++;
1.660 raeburn 11956: } else {
1.1075.2.35 raeburn 11957: $upload_output .= '<td>'.
11958: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11959: $embed_file,\%mapping,
1.1071 raeburn 11960: $allfiles,$codebase,'upload');
11961: $counter ++;
11962: $numnew ++;
1.987 raeburn 11963: }
11964: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11965: }
11966: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11967: if ($actionurl eq '/adm/dependencies') {
11968: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11969: $modify_output .= &start_data_table_row().
11970: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11971: '<img src="'.&icon($embed_file).'" border="0" />'.
11972: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11973: '<td>'.$size.'</td>'.
11974: '<td>'.$mtime.'</td>'.
11975: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11976: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11977: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11978: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11979: &embedded_file_element('upload_embedded',$counter,
11980: $embed_file,\%mapping,
11981: $allfiles,$codebase,'modify').
11982: '</div></td>'.
11983: &end_data_table_row()."\n";
11984: $counter ++;
11985: } else {
11986: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11987: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11988: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11989: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11990: &Apache::loncommon::end_data_table_row()."\n";
11991: }
11992: }
11993: my $delidx = $counter;
11994: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11995: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11996: $delete_output .= &start_data_table_row().
11997: '<td><img src="'.&icon($oldfile).'" />'.
11998: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11999: '<td>'.$size.'</td>'.
12000: '<td>'.$mtime.'</td>'.
12001: '<td><label><input type="checkbox" name="del_upload_dep" '.
12002: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
12003: &embedded_file_element('upload_embedded',$delidx,
12004: $oldfile,\%mapping,$allfiles,
12005: $codebase,'delete').'</td>'.
12006: &end_data_table_row()."\n";
12007: $numunused ++;
12008: $delidx ++;
1.987 raeburn 12009: }
12010: if ($upload_output) {
12011: $upload_output = &start_data_table().
12012: $upload_output.
12013: &end_data_table()."\n";
12014: }
1.1071 raeburn 12015: if ($modify_output) {
12016: $modify_output = &start_data_table().
12017: &start_data_table_header_row().
12018: '<th>'.&mt('File').'</th>'.
12019: '<th>'.&mt('Size (KB)').'</th>'.
12020: '<th>'.&mt('Modified').'</th>'.
12021: '<th>'.&mt('Upload replacement?').'</th>'.
12022: &end_data_table_header_row().
12023: $modify_output.
12024: &end_data_table()."\n";
12025: }
12026: if ($delete_output) {
12027: $delete_output = &start_data_table().
12028: &start_data_table_header_row().
12029: '<th>'.&mt('File').'</th>'.
12030: '<th>'.&mt('Size (KB)').'</th>'.
12031: '<th>'.&mt('Modified').'</th>'.
12032: '<th>'.&mt('Delete?').'</th>'.
12033: &end_data_table_header_row().
12034: $delete_output.
12035: &end_data_table()."\n";
12036: }
1.987 raeburn 12037: my $applies = 0;
12038: if ($numremref) {
12039: $applies ++;
12040: }
12041: if ($numinvalid) {
12042: $applies ++;
12043: }
12044: if ($numexisting) {
12045: $applies ++;
12046: }
1.1071 raeburn 12047: if ($counter || $numunused) {
1.987 raeburn 12048: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
12049: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 12050: $state.'<h3>'.$heading.'</h3>';
12051: if ($actionurl eq '/adm/dependencies') {
12052: if ($numnew) {
12053: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
12054: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
12055: $upload_output.'<br />'."\n";
12056: }
12057: if ($numexisting) {
12058: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
12059: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
12060: $modify_output.'<br />'."\n";
12061: $buttontext = &mt('Save changes');
12062: }
12063: if ($numunused) {
12064: $output .= '<h4>'.&mt('Unused files').'</h4>'.
12065: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
12066: $delete_output.'<br />'."\n";
12067: $buttontext = &mt('Save changes');
12068: }
12069: } else {
12070: $output .= $upload_output.'<br />'."\n";
12071: }
12072: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
12073: $counter.'" />'."\n";
12074: if ($actionurl eq '/adm/dependencies') {
12075: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
12076: $numnew.'" />'."\n";
12077: } elsif ($actionurl eq '') {
1.987 raeburn 12078: $output .= '<input type="hidden" name="phase" value="three" />';
12079: }
12080: } elsif ($applies) {
12081: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
12082: if ($applies > 1) {
12083: $output .=
1.1075.2.35 raeburn 12084: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 12085: if ($numremref) {
12086: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
12087: }
12088: if ($numinvalid) {
12089: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
12090: }
12091: if ($numexisting) {
12092: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
12093: }
12094: $output .= '</ul><br />';
12095: } elsif ($numremref) {
12096: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
12097: } elsif ($numinvalid) {
12098: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
12099: } elsif ($numexisting) {
12100: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
12101: }
12102: $output .= $upload_output.'<br />';
12103: }
12104: my ($pathchange_output,$chgcount);
1.1071 raeburn 12105: $chgcount = $counter;
1.987 raeburn 12106: if (keys(%pathchanges) > 0) {
12107: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 12108: if ($counter) {
1.987 raeburn 12109: $output .= &embedded_file_element('pathchange',$chgcount,
12110: $embed_file,\%mapping,
1.1071 raeburn 12111: $allfiles,$codebase,'change');
1.987 raeburn 12112: } else {
12113: $pathchange_output .=
12114: &start_data_table_row().
12115: '<td><input type ="checkbox" name="namechange" value="'.
12116: $chgcount.'" checked="checked" /></td>'.
12117: '<td>'.$mapping{$embed_file}.'</td>'.
12118: '<td>'.$embed_file.
12119: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 12120: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 12121: '</td>'.&end_data_table_row();
1.660 raeburn 12122: }
1.987 raeburn 12123: $numpathchg ++;
12124: $chgcount ++;
1.660 raeburn 12125: }
12126: }
1.1075.2.35 raeburn 12127: if (($counter) || ($numunused)) {
1.987 raeburn 12128: if ($numpathchg) {
12129: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
12130: $numpathchg.'" />'."\n";
12131: }
12132: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12133: ($actionurl eq '/adm/imsimport')) {
12134: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
12135: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
12136: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 12137: } elsif ($actionurl eq '/adm/dependencies') {
12138: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 12139: }
1.1075.2.35 raeburn 12140: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 12141: } elsif ($numpathchg) {
12142: my %pathchange = ();
12143: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
12144: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12145: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 12146: }
1.987 raeburn 12147: }
1.1071 raeburn 12148: return ($output,$counter,$numpathchg);
1.987 raeburn 12149: }
12150:
1.1075.2.47 raeburn 12151: =pod
12152:
12153: =item * clean_path($name)
12154:
12155: Performs clean-up of directories, subdirectories and filename in an
12156: embedded object, referenced in an HTML file which is being uploaded
12157: to a course or portfolio, where
12158: "Upload embedded images/multimedia files if HTML file" checkbox was
12159: checked.
12160:
12161: Clean-up is similar to replacements in lonnet::clean_filename()
12162: except each / between sub-directory and next level is preserved.
12163:
12164: =cut
12165:
12166: sub clean_path {
12167: my ($embed_file) = @_;
12168: $embed_file =~s{^/+}{};
12169: my @contents;
12170: if ($embed_file =~ m{/}) {
12171: @contents = split(/\//,$embed_file);
12172: } else {
12173: @contents = ($embed_file);
12174: }
12175: my $lastidx = scalar(@contents)-1;
12176: for (my $i=0; $i<=$lastidx; $i++) {
12177: $contents[$i]=~s{\\}{/}g;
12178: $contents[$i]=~s/\s+/\_/g;
12179: $contents[$i]=~s{[^/\w\.\-]}{}g;
12180: if ($i == $lastidx) {
12181: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
12182: }
12183: }
12184: if ($lastidx > 0) {
12185: return join('/',@contents);
12186: } else {
12187: return $contents[0];
12188: }
12189: }
12190:
1.987 raeburn 12191: sub embedded_file_element {
1.1071 raeburn 12192: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 12193: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
12194: (ref($codebase) eq 'HASH'));
12195: my $output;
1.1071 raeburn 12196: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 12197: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
12198: }
12199: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
12200: &escape($embed_file).'" />';
12201: unless (($context eq 'upload_embedded') &&
12202: ($mapping->{$embed_file} eq $embed_file)) {
12203: $output .='
12204: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
12205: }
12206: my $attrib;
12207: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
12208: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
12209: }
12210: $output .=
12211: "\n\t\t".
12212: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
12213: $attrib.'" />';
12214: if (exists($codebase->{$mapping->{$embed_file}})) {
12215: $output .=
12216: "\n\t\t".
12217: '<input name="codebase_'.$num.'" type="hidden" value="'.
12218: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 12219: }
1.987 raeburn 12220: return $output;
1.660 raeburn 12221: }
12222:
1.1071 raeburn 12223: sub get_dependency_details {
12224: my ($currfile,$currsubfile,$embed_file) = @_;
12225: my ($size,$mtime,$showsize,$showmtime);
12226: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
12227: if ($embed_file =~ m{/}) {
12228: my ($path,$fname) = split(/\//,$embed_file);
12229: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
12230: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
12231: }
12232: } else {
12233: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
12234: ($size,$mtime) = @{$currfile->{$embed_file}};
12235: }
12236: }
12237: $showsize = $size/1024.0;
12238: $showsize = sprintf("%.1f",$showsize);
12239: if ($mtime > 0) {
12240: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
12241: }
12242: }
12243: return ($showsize,$showmtime);
12244: }
12245:
12246: sub ask_embedded_js {
12247: return <<"END";
12248: <script type="text/javascript"">
12249: // <![CDATA[
12250: function toggleBrowse(counter) {
12251: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
12252: var fileid = document.getElementById('embedded_item_'+counter);
12253: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12254: if (chkboxid.checked == true) {
12255: uploaddivid.style.display='block';
12256: } else {
12257: uploaddivid.style.display='none';
12258: fileid.value = '';
12259: }
12260: }
12261: // ]]>
12262: </script>
12263:
12264: END
12265: }
12266:
1.661 raeburn 12267: sub upload_embedded {
12268: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12269: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12270: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12271: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12272: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12273: my $orig_uploaded_filename =
12274: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12275: foreach my $type ('orig','ref','attrib','codebase') {
12276: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12277: $env{'form.embedded_'.$type.'_'.$i} =
12278: &unescape($env{'form.embedded_'.$type.'_'.$i});
12279: }
12280: }
1.661 raeburn 12281: my ($path,$fname) =
12282: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12283: # no path, whole string is fname
12284: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12285: $fname = &Apache::lonnet::clean_filename($fname);
12286: # See if there is anything left
12287: next if ($fname eq '');
12288:
12289: # Check if file already exists as a file or directory.
12290: my ($state,$msg);
12291: if ($context eq 'portfolio') {
12292: my $port_path = $dirpath;
12293: if ($group ne '') {
12294: $port_path = "groups/$group/$port_path";
12295: }
1.987 raeburn 12296: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12297: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12298: $dir_root,$port_path,$disk_quota,
12299: $current_disk_usage,$uname,$udom);
12300: if ($state eq 'will_exceed_quota'
1.984 raeburn 12301: || $state eq 'file_locked') {
1.661 raeburn 12302: $output .= $msg;
12303: next;
12304: }
12305: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12306: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12307: if ($state eq 'exists') {
12308: $output .= $msg;
12309: next;
12310: }
12311: }
12312: # Check if extension is valid
12313: if (($fname =~ /\.(\w+)$/) &&
12314: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 12315: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12316: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12317: next;
12318: } elsif (($fname =~ /\.(\w+)$/) &&
12319: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12320: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12321: next;
12322: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 12323: $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 12324: next;
12325: }
12326: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 12327: my $subdir = $path;
12328: $subdir =~ s{/+$}{};
1.661 raeburn 12329: if ($context eq 'portfolio') {
1.984 raeburn 12330: my $result;
12331: if ($state eq 'existingfile') {
12332: $result=
12333: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 12334: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12335: } else {
1.984 raeburn 12336: $result=
12337: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12338: $dirpath.
1.1075.2.35 raeburn 12339: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12340: if ($result !~ m|^/uploaded/|) {
12341: $output .= '<span class="LC_error">'
12342: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12343: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12344: .'</span><br />';
12345: next;
12346: } else {
1.987 raeburn 12347: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12348: $path.$fname.'</span>').'<br />';
1.984 raeburn 12349: }
1.661 raeburn 12350: }
1.1075.2.35 raeburn 12351: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
12352: my $extendedsubdir = $dirpath.'/'.$subdir;
12353: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12354: my $result =
1.1075.2.35 raeburn 12355: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12356: if ($result !~ m|^/uploaded/|) {
12357: $output .= '<span class="LC_error">'
12358: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12359: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12360: .'</span><br />';
12361: next;
12362: } else {
12363: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12364: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 12365: if ($context eq 'syllabus') {
12366: &Apache::lonnet::make_public_indefinitely($result);
12367: }
1.987 raeburn 12368: }
1.661 raeburn 12369: } else {
12370: # Save the file
12371: my $target = $env{'form.embedded_item_'.$i};
12372: my $fullpath = $dir_root.$dirpath.'/'.$path;
12373: my $dest = $fullpath.$fname;
12374: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12375: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12376: my $count;
12377: my $filepath = $dir_root;
1.1027 raeburn 12378: foreach my $subdir (@parts) {
12379: $filepath .= "/$subdir";
12380: if (!-e $filepath) {
1.661 raeburn 12381: mkdir($filepath,0770);
12382: }
12383: }
12384: my $fh;
12385: if (!open($fh,'>'.$dest)) {
12386: &Apache::lonnet::logthis('Failed to create '.$dest);
12387: $output .= '<span class="LC_error">'.
1.1071 raeburn 12388: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12389: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12390: '</span><br />';
12391: } else {
12392: if (!print $fh $env{'form.embedded_item_'.$i}) {
12393: &Apache::lonnet::logthis('Failed to write to '.$dest);
12394: $output .= '<span class="LC_error">'.
1.1071 raeburn 12395: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12396: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12397: '</span><br />';
12398: } else {
1.987 raeburn 12399: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12400: $url.'</span>').'<br />';
12401: unless ($context eq 'testbank') {
12402: $footer .= &mt('View embedded file: [_1]',
12403: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12404: }
12405: }
12406: close($fh);
12407: }
12408: }
12409: if ($env{'form.embedded_ref_'.$i}) {
12410: $pathchange{$i} = 1;
12411: }
12412: }
12413: if ($output) {
12414: $output = '<p>'.$output.'</p>';
12415: }
12416: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12417: $returnflag = 'ok';
1.1071 raeburn 12418: my $numpathchgs = scalar(keys(%pathchange));
12419: if ($numpathchgs > 0) {
1.987 raeburn 12420: if ($context eq 'portfolio') {
12421: $output .= '<p>'.&mt('or').'</p>';
12422: } elsif ($context eq 'testbank') {
1.1071 raeburn 12423: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12424: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12425: $returnflag = 'modify_orightml';
12426: }
12427: }
1.1071 raeburn 12428: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12429: }
12430:
12431: sub modify_html_form {
12432: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12433: my $end = 0;
12434: my $modifyform;
12435: if ($context eq 'upload_embedded') {
12436: return unless (ref($pathchange) eq 'HASH');
12437: if ($env{'form.number_embedded_items'}) {
12438: $end += $env{'form.number_embedded_items'};
12439: }
12440: if ($env{'form.number_pathchange_items'}) {
12441: $end += $env{'form.number_pathchange_items'};
12442: }
12443: if ($end) {
12444: for (my $i=0; $i<$end; $i++) {
12445: if ($i < $env{'form.number_embedded_items'}) {
12446: next unless($pathchange->{$i});
12447: }
12448: $modifyform .=
12449: &start_data_table_row().
12450: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12451: 'checked="checked" /></td>'.
12452: '<td>'.$env{'form.embedded_ref_'.$i}.
12453: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12454: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12455: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12456: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12457: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12458: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12459: '<td>'.$env{'form.embedded_orig_'.$i}.
12460: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12461: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12462: &end_data_table_row();
1.1071 raeburn 12463: }
1.987 raeburn 12464: }
12465: } else {
12466: $modifyform = $pathchgtable;
12467: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12468: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12469: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12470: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12471: }
12472: }
12473: if ($modifyform) {
1.1071 raeburn 12474: if ($actionurl eq '/adm/dependencies') {
12475: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12476: }
1.987 raeburn 12477: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12478: '<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".
12479: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12480: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12481: '</ol></p>'."\n".'<p>'.
12482: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12483: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12484: &start_data_table()."\n".
12485: &start_data_table_header_row().
12486: '<th>'.&mt('Change?').'</th>'.
12487: '<th>'.&mt('Current reference').'</th>'.
12488: '<th>'.&mt('Required reference').'</th>'.
12489: &end_data_table_header_row()."\n".
12490: $modifyform.
12491: &end_data_table().'<br />'."\n".$hiddenstate.
12492: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12493: '</form>'."\n";
12494: }
12495: return;
12496: }
12497:
12498: sub modify_html_refs {
1.1075.2.35 raeburn 12499: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12500: my $container;
12501: if ($context eq 'portfolio') {
12502: $container = $env{'form.container'};
12503: } elsif ($context eq 'coursedoc') {
12504: $container = $env{'form.primaryurl'};
1.1071 raeburn 12505: } elsif ($context eq 'manage_dependencies') {
12506: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12507: $container = "/$container";
1.1075.2.35 raeburn 12508: } elsif ($context eq 'syllabus') {
12509: $container = $url;
1.987 raeburn 12510: } else {
1.1027 raeburn 12511: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12512: }
12513: my (%allfiles,%codebase,$output,$content);
12514: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 12515: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12516: if (wantarray) {
12517: return ('',0,0);
12518: } else {
12519: return;
12520: }
12521: }
12522: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 12523: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12524: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12525: if (wantarray) {
12526: return ('',0,0);
12527: } else {
12528: return;
12529: }
12530: }
1.987 raeburn 12531: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12532: if ($content eq '-1') {
12533: if (wantarray) {
12534: return ('',0,0);
12535: } else {
12536: return;
12537: }
12538: }
1.987 raeburn 12539: } else {
1.1071 raeburn 12540: unless ($container =~ /^\Q$dir_root\E/) {
12541: if (wantarray) {
12542: return ('',0,0);
12543: } else {
12544: return;
12545: }
12546: }
1.1075.2.128 raeburn 12547: if (open(my $fh,'<',$container)) {
1.987 raeburn 12548: $content = join('', <$fh>);
12549: close($fh);
12550: } else {
1.1071 raeburn 12551: if (wantarray) {
12552: return ('',0,0);
12553: } else {
12554: return;
12555: }
1.987 raeburn 12556: }
12557: }
12558: my ($count,$codebasecount) = (0,0);
12559: my $mm = new File::MMagic;
12560: my $mime_type = $mm->checktype_contents($content);
12561: if ($mime_type eq 'text/html') {
12562: my $parse_result =
12563: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12564: \%codebase,\$content);
12565: if ($parse_result eq 'ok') {
12566: foreach my $i (@changes) {
12567: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12568: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12569: if ($allfiles{$ref}) {
12570: my $newname = $orig;
12571: my ($attrib_regexp,$codebase);
1.1006 raeburn 12572: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12573: if ($attrib_regexp =~ /:/) {
12574: $attrib_regexp =~ s/\:/|/g;
12575: }
12576: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12577: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12578: $count += $numchg;
1.1075.2.35 raeburn 12579: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 12580: delete($allfiles{$ref});
1.987 raeburn 12581: }
12582: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12583: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12584: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12585: $codebasecount ++;
12586: }
12587: }
12588: }
1.1075.2.35 raeburn 12589: my $skiprewrites;
1.987 raeburn 12590: if ($count || $codebasecount) {
12591: my $saveresult;
1.1071 raeburn 12592: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 12593: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12594: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12595: if ($url eq $container) {
12596: my ($fname) = ($container =~ m{/([^/]+)$});
12597: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12598: $count,'<span class="LC_filename">'.
1.1071 raeburn 12599: $fname.'</span>').'</p>';
1.987 raeburn 12600: } else {
12601: $output = '<p class="LC_error">'.
12602: &mt('Error: update failed for: [_1].',
12603: '<span class="LC_filename">'.
12604: $container.'</span>').'</p>';
12605: }
1.1075.2.35 raeburn 12606: if ($context eq 'syllabus') {
12607: unless ($saveresult eq 'ok') {
12608: $skiprewrites = 1;
12609: }
12610: }
1.987 raeburn 12611: } else {
1.1075.2.128 raeburn 12612: if (open(my $fh,'>',$container)) {
1.987 raeburn 12613: print $fh $content;
12614: close($fh);
12615: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12616: $count,'<span class="LC_filename">'.
12617: $container.'</span>').'</p>';
1.661 raeburn 12618: } else {
1.987 raeburn 12619: $output = '<p class="LC_error">'.
12620: &mt('Error: could not update [_1].',
12621: '<span class="LC_filename">'.
12622: $container.'</span>').'</p>';
1.661 raeburn 12623: }
12624: }
12625: }
1.1075.2.35 raeburn 12626: if (($context eq 'syllabus') && (!$skiprewrites)) {
12627: my ($actionurl,$state);
12628: $actionurl = "/public/$udom/$uname/syllabus";
12629: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12630: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12631: \%codebase,
12632: {'context' => 'rewrites',
12633: 'ignore_remote_references' => 1,});
12634: if (ref($mapping) eq 'HASH') {
12635: my $rewrites = 0;
12636: foreach my $key (keys(%{$mapping})) {
12637: next if ($key =~ m{^https?://});
12638: my $ref = $mapping->{$key};
12639: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12640: my $attrib;
12641: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12642: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12643: }
12644: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12645: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12646: $rewrites += $numchg;
12647: }
12648: }
12649: if ($rewrites) {
12650: my $saveresult;
12651: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12652: if ($url eq $container) {
12653: my ($fname) = ($container =~ m{/([^/]+)$});
12654: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12655: $count,'<span class="LC_filename">'.
12656: $fname.'</span>').'</p>';
12657: } else {
12658: $output .= '<p class="LC_error">'.
12659: &mt('Error: could not update links in [_1].',
12660: '<span class="LC_filename">'.
12661: $container.'</span>').'</p>';
12662:
12663: }
12664: }
12665: }
12666: }
1.987 raeburn 12667: } else {
12668: &logthis('Failed to parse '.$container.
12669: ' to modify references: '.$parse_result);
1.661 raeburn 12670: }
12671: }
1.1071 raeburn 12672: if (wantarray) {
12673: return ($output,$count,$codebasecount);
12674: } else {
12675: return $output;
12676: }
1.661 raeburn 12677: }
12678:
12679: sub check_for_existing {
12680: my ($path,$fname,$element) = @_;
12681: my ($state,$msg);
12682: if (-d $path.'/'.$fname) {
12683: $state = 'exists';
12684: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12685: } elsif (-e $path.'/'.$fname) {
12686: $state = 'exists';
12687: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12688: }
12689: if ($state eq 'exists') {
12690: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12691: }
12692: return ($state,$msg);
12693: }
12694:
12695: sub check_for_upload {
12696: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12697: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12698: my $filesize = length($env{'form.'.$element});
12699: if (!$filesize) {
12700: my $msg = '<span class="LC_error">'.
12701: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12702: '<span class="LC_filename">'.$fname.'</span>',
12703: $filesize).'<br />'.
1.1007 raeburn 12704: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12705: '</span>';
12706: return ('zero_bytes',$msg);
12707: }
12708: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12709: my $getpropath = 1;
1.1021 raeburn 12710: my ($dirlistref,$listerror) =
12711: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12712: my $found_file = 0;
12713: my $locked_file = 0;
1.991 raeburn 12714: my @lockers;
12715: my $navmap;
12716: if ($env{'request.course.id'}) {
12717: $navmap = Apache::lonnavmaps::navmap->new();
12718: }
1.1021 raeburn 12719: if (ref($dirlistref) eq 'ARRAY') {
12720: foreach my $line (@{$dirlistref}) {
12721: my ($file_name,$rest)=split(/\&/,$line,2);
12722: if ($file_name eq $fname){
12723: $file_name = $path.$file_name;
12724: if ($group ne '') {
12725: $file_name = $group.$file_name;
12726: }
12727: $found_file = 1;
12728: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12729: foreach my $lock (@lockers) {
12730: if (ref($lock) eq 'ARRAY') {
12731: my ($symb,$crsid) = @{$lock};
12732: if ($crsid eq $env{'request.course.id'}) {
12733: if (ref($navmap)) {
12734: my $res = $navmap->getBySymb($symb);
12735: foreach my $part (@{$res->parts()}) {
12736: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12737: unless (($slot_status == $res->RESERVED) ||
12738: ($slot_status == $res->RESERVED_LOCATION)) {
12739: $locked_file = 1;
12740: }
1.991 raeburn 12741: }
1.1021 raeburn 12742: } else {
12743: $locked_file = 1;
1.991 raeburn 12744: }
12745: } else {
12746: $locked_file = 1;
12747: }
12748: }
1.1021 raeburn 12749: }
12750: } else {
12751: my @info = split(/\&/,$rest);
12752: my $currsize = $info[6]/1000;
12753: if ($currsize < $filesize) {
12754: my $extra = $filesize - $currsize;
12755: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 12756: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12757: &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 12758: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12759: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12760: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12761: return ('will_exceed_quota',$msg);
12762: }
1.984 raeburn 12763: }
12764: }
1.661 raeburn 12765: }
12766: }
12767: }
12768: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 12769: my $msg = '<p class="LC_warning">'.
12770: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
12771: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12772: return ('will_exceed_quota',$msg);
12773: } elsif ($found_file) {
12774: if ($locked_file) {
1.1075.2.69 raeburn 12775: my $msg = '<p class="LC_warning">';
1.661 raeburn 12776: $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 12777: $msg .= '</p>';
1.661 raeburn 12778: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12779: return ('file_locked',$msg);
12780: } else {
1.1075.2.69 raeburn 12781: my $msg = '<p class="LC_error">';
1.984 raeburn 12782: $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 12783: $msg .= '</p>';
1.984 raeburn 12784: return ('existingfile',$msg);
1.661 raeburn 12785: }
12786: }
12787: }
12788:
1.987 raeburn 12789: sub check_for_traversal {
12790: my ($path,$url,$toplevel) = @_;
12791: my @parts=split(/\//,$path);
12792: my $cleanpath;
12793: my $fullpath = $url;
12794: for (my $i=0;$i<@parts;$i++) {
12795: next if ($parts[$i] eq '.');
12796: if ($parts[$i] eq '..') {
12797: $fullpath =~ s{([^/]+/)$}{};
12798: } else {
12799: $fullpath .= $parts[$i].'/';
12800: }
12801: }
12802: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12803: $cleanpath = $1;
12804: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12805: my $curr_toprel = $1;
12806: my @parts = split(/\//,$curr_toprel);
12807: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12808: my @urlparts = split(/\//,$url_toprel);
12809: my $doubledots;
12810: my $startdiff = -1;
12811: for (my $i=0; $i<@urlparts; $i++) {
12812: if ($startdiff == -1) {
12813: unless ($urlparts[$i] eq $parts[$i]) {
12814: $startdiff = $i;
12815: $doubledots .= '../';
12816: }
12817: } else {
12818: $doubledots .= '../';
12819: }
12820: }
12821: if ($startdiff > -1) {
12822: $cleanpath = $doubledots;
12823: for (my $i=$startdiff; $i<@parts; $i++) {
12824: $cleanpath .= $parts[$i].'/';
12825: }
12826: }
12827: }
12828: $cleanpath =~ s{(/)$}{};
12829: return $cleanpath;
12830: }
1.31 albertel 12831:
1.1053 raeburn 12832: sub is_archive_file {
12833: my ($mimetype) = @_;
12834: if (($mimetype eq 'application/octet-stream') ||
12835: ($mimetype eq 'application/x-stuffit') ||
12836: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12837: return 1;
12838: }
12839: return;
12840: }
12841:
12842: sub decompress_form {
1.1065 raeburn 12843: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12844: my %lt = &Apache::lonlocal::texthash (
12845: this => 'This file is an archive file.',
1.1067 raeburn 12846: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12847: itsc => 'Its contents are as follows:',
1.1053 raeburn 12848: youm => 'You may wish to extract its contents.',
12849: extr => 'Extract contents',
1.1067 raeburn 12850: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12851: proa => 'Process automatically?',
1.1053 raeburn 12852: yes => 'Yes',
12853: no => 'No',
1.1067 raeburn 12854: fold => 'Title for folder containing movie',
12855: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12856: );
1.1065 raeburn 12857: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12858: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12859: my $info = &list_archive_contents($fileloc,\@paths);
12860: if (@paths) {
12861: foreach my $path (@paths) {
12862: $path =~ s{^/}{};
1.1067 raeburn 12863: if ($path =~ m{^([^/]+)/$}) {
12864: $topdir = $1;
12865: }
1.1065 raeburn 12866: if ($path =~ m{^([^/]+)/}) {
12867: $toplevel{$1} = $path;
12868: } else {
12869: $toplevel{$path} = $path;
12870: }
12871: }
12872: }
1.1067 raeburn 12873: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 12874: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12875: "$topdir/media/",
12876: "$topdir/media/$topdir.mp4",
12877: "$topdir/media/FirstFrame.png",
12878: "$topdir/media/player.swf",
12879: "$topdir/media/swfobject.js",
12880: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 12881: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 12882: "$topdir/$topdir.mp4",
12883: "$topdir/$topdir\_config.xml",
12884: "$topdir/$topdir\_controller.swf",
12885: "$topdir/$topdir\_embed.css",
12886: "$topdir/$topdir\_First_Frame.png",
12887: "$topdir/$topdir\_player.html",
12888: "$topdir/$topdir\_Thumbnails.png",
12889: "$topdir/playerProductInstall.swf",
12890: "$topdir/scripts/",
12891: "$topdir/scripts/config_xml.js",
12892: "$topdir/scripts/handlebars.js",
12893: "$topdir/scripts/jquery-1.7.1.min.js",
12894: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12895: "$topdir/scripts/modernizr.js",
12896: "$topdir/scripts/player-min.js",
12897: "$topdir/scripts/swfobject.js",
12898: "$topdir/skins/",
12899: "$topdir/skins/configuration_express.xml",
12900: "$topdir/skins/express_show/",
12901: "$topdir/skins/express_show/player-min.css",
12902: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 12903: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12904: "$topdir/$topdir.mp4",
12905: "$topdir/$topdir\_config.xml",
12906: "$topdir/$topdir\_controller.swf",
12907: "$topdir/$topdir\_embed.css",
12908: "$topdir/$topdir\_First_Frame.png",
12909: "$topdir/$topdir\_player.html",
12910: "$topdir/$topdir\_Thumbnails.png",
12911: "$topdir/playerProductInstall.swf",
12912: "$topdir/scripts/",
12913: "$topdir/scripts/config_xml.js",
12914: "$topdir/scripts/techsmith-smart-player.min.js",
12915: "$topdir/skins/",
12916: "$topdir/skins/configuration_express.xml",
12917: "$topdir/skins/express_show/",
12918: "$topdir/skins/express_show/spritesheet.min.css",
12919: "$topdir/skins/express_show/spritesheet.png",
12920: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 12921: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12922: if (@diffs == 0) {
1.1075.2.59 raeburn 12923: $is_camtasia = 6;
12924: } else {
1.1075.2.81 raeburn 12925: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 12926: if (@diffs == 0) {
12927: $is_camtasia = 8;
1.1075.2.81 raeburn 12928: } else {
12929: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12930: if (@diffs == 0) {
12931: $is_camtasia = 8;
12932: }
1.1075.2.59 raeburn 12933: }
1.1067 raeburn 12934: }
12935: }
12936: my $output;
12937: if ($is_camtasia) {
12938: $output = <<"ENDCAM";
12939: <script type="text/javascript" language="Javascript">
12940: // <![CDATA[
12941:
12942: function camtasiaToggle() {
12943: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12944: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 12945: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12946: document.getElementById('camtasia_titles').style.display='block';
12947: } else {
12948: document.getElementById('camtasia_titles').style.display='none';
12949: }
12950: }
12951: }
12952: return;
12953: }
12954:
12955: // ]]>
12956: </script>
12957: <p>$lt{'camt'}</p>
12958: ENDCAM
1.1065 raeburn 12959: } else {
1.1067 raeburn 12960: $output = '<p>'.$lt{'this'};
12961: if ($info eq '') {
12962: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12963: } else {
12964: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12965: '<div><pre>'.$info.'</pre></div>';
12966: }
1.1065 raeburn 12967: }
1.1067 raeburn 12968: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12969: my $duplicates;
12970: my $num = 0;
12971: if (ref($dirlist) eq 'ARRAY') {
12972: foreach my $item (@{$dirlist}) {
12973: if (ref($item) eq 'ARRAY') {
12974: if (exists($toplevel{$item->[0]})) {
12975: $duplicates .=
12976: &start_data_table_row().
12977: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12978: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12979: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12980: 'value="1" />'.&mt('Yes').'</label>'.
12981: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12982: '<td>'.$item->[0].'</td>';
12983: if ($item->[2]) {
12984: $duplicates .= '<td>'.&mt('Directory').'</td>';
12985: } else {
12986: $duplicates .= '<td>'.&mt('File').'</td>';
12987: }
12988: $duplicates .= '<td>'.$item->[3].'</td>'.
12989: '<td>'.
12990: &Apache::lonlocal::locallocaltime($item->[4]).
12991: '</td>'.
12992: &end_data_table_row();
12993: $num ++;
12994: }
12995: }
12996: }
12997: }
12998: my $itemcount;
12999: if (@paths > 0) {
13000: $itemcount = scalar(@paths);
13001: } else {
13002: $itemcount = 1;
13003: }
1.1067 raeburn 13004: if ($is_camtasia) {
13005: $output .= $lt{'auto'}.'<br />'.
13006: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 13007: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 13008: $lt{'yes'}.'</label> <label>'.
13009: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
13010: $lt{'no'}.'</label></span><br />'.
13011: '<div id="camtasia_titles" style="display:block">'.
13012: &Apache::lonhtmlcommon::start_pick_box().
13013: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
13014: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
13015: &Apache::lonhtmlcommon::row_closure().
13016: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
13017: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
13018: &Apache::lonhtmlcommon::row_closure(1).
13019: &Apache::lonhtmlcommon::end_pick_box().
13020: '</div>';
13021: }
1.1065 raeburn 13022: $output .=
13023: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 13024: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
13025: "\n";
1.1065 raeburn 13026: if ($duplicates ne '') {
13027: $output .= '<p><span class="LC_warning">'.
13028: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
13029: &start_data_table().
13030: &start_data_table_header_row().
13031: '<th>'.&mt('Overwrite?').'</th>'.
13032: '<th>'.&mt('Name').'</th>'.
13033: '<th>'.&mt('Type').'</th>'.
13034: '<th>'.&mt('Size').'</th>'.
13035: '<th>'.&mt('Last modified').'</th>'.
13036: &end_data_table_header_row().
13037: $duplicates.
13038: &end_data_table().
13039: '</p>';
13040: }
1.1067 raeburn 13041: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 13042: if (ref($hiddenelements) eq 'HASH') {
13043: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
13044: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
13045: }
13046: }
13047: $output .= <<"END";
1.1067 raeburn 13048: <br />
1.1053 raeburn 13049: <input type="submit" name="decompress" value="$lt{'extr'}" />
13050: </form>
13051: $noextract
13052: END
13053: return $output;
13054: }
13055:
1.1065 raeburn 13056: sub decompression_utility {
13057: my ($program) = @_;
13058: my @utilities = ('tar','gunzip','bunzip2','unzip');
13059: my $location;
13060: if (grep(/^\Q$program\E$/,@utilities)) {
13061: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
13062: '/usr/sbin/') {
13063: if (-x $dir.$program) {
13064: $location = $dir.$program;
13065: last;
13066: }
13067: }
13068: }
13069: return $location;
13070: }
13071:
13072: sub list_archive_contents {
13073: my ($file,$pathsref) = @_;
13074: my (@cmd,$output);
13075: my $needsregexp;
13076: if ($file =~ /\.zip$/) {
13077: @cmd = (&decompression_utility('unzip'),"-l");
13078: $needsregexp = 1;
13079: } elsif (($file =~ m/\.tar\.gz$/) ||
13080: ($file =~ /\.tgz$/)) {
13081: @cmd = (&decompression_utility('tar'),"-ztf");
13082: } elsif ($file =~ /\.tar\.bz2$/) {
13083: @cmd = (&decompression_utility('tar'),"-jtf");
13084: } elsif ($file =~ m|\.tar$|) {
13085: @cmd = (&decompression_utility('tar'),"-tf");
13086: }
13087: if (@cmd) {
13088: undef($!);
13089: undef($@);
13090: if (open(my $fh,"-|", @cmd, $file)) {
13091: while (my $line = <$fh>) {
13092: $output .= $line;
13093: chomp($line);
13094: my $item;
13095: if ($needsregexp) {
13096: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
13097: } else {
13098: $item = $line;
13099: }
13100: if ($item ne '') {
13101: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
13102: push(@{$pathsref},$item);
13103: }
13104: }
13105: }
13106: close($fh);
13107: }
13108: }
13109: return $output;
13110: }
13111:
1.1053 raeburn 13112: sub decompress_uploaded_file {
13113: my ($file,$dir) = @_;
13114: &Apache::lonnet::appenv({'cgi.file' => $file});
13115: &Apache::lonnet::appenv({'cgi.dir' => $dir});
13116: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
13117: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
13118: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
13119: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
13120: my $decompressed = $env{'cgi.decompressed'};
13121: &Apache::lonnet::delenv('cgi.file');
13122: &Apache::lonnet::delenv('cgi.dir');
13123: &Apache::lonnet::delenv('cgi.decompressed');
13124: return ($decompressed,$result);
13125: }
13126:
1.1055 raeburn 13127: sub process_decompression {
13128: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 13129: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
13130: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13131: &mt('Unexpected file path.').'</p>'."\n";
13132: }
13133: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
13134: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13135: &mt('Unexpected course context.').'</p>'."\n";
13136: }
13137: unless ($file eq &Apache::lonnet::clean_filename($file)) {
13138: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13139: &mt('Filename contained unexpected characters.').'</p>'."\n";
13140: }
1.1055 raeburn 13141: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 13142: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 13143: $error = &mt('Filename not a supported archive file type.').
13144: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 13145: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
13146: } else {
13147: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13148: if ($docuhome eq 'no_host') {
13149: $error = &mt('Could not determine home server for course.');
13150: } else {
13151: my @ids=&Apache::lonnet::current_machine_ids();
13152: my $currdir = "$dir_root/$destination";
13153: if (grep(/^\Q$docuhome\E$/,@ids)) {
13154: $dir = &LONCAPA::propath($docudom,$docuname).
13155: "$dir_root/$destination";
13156: } else {
13157: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
13158: "$dir_root/$docudom/$docuname/$destination";
13159: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
13160: $error = &mt('Archive file not found.');
13161: }
13162: }
1.1065 raeburn 13163: my (@to_overwrite,@to_skip);
13164: if ($env{'form.archive_overwrite_total'} > 0) {
13165: my $total = $env{'form.archive_overwrite_total'};
13166: for (my $i=0; $i<$total; $i++) {
13167: if ($env{'form.archive_overwrite_'.$i} == 1) {
13168: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
13169: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
13170: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
13171: }
13172: }
13173: }
13174: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 13175: my $numoverwrite = scalar(@to_overwrite);
13176: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 13177: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
13178: } elsif ($dir eq '') {
1.1055 raeburn 13179: $error = &mt('Directory containing archive file unavailable.');
13180: } elsif (!$error) {
1.1065 raeburn 13181: my ($decompressed,$display);
1.1075.2.128 raeburn 13182: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 13183: my $tempdir = time.'_'.$$.int(rand(10000));
13184: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 13185: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
13186: ($decompressed,$display) =
13187: &decompress_uploaded_file($file,"$dir/$tempdir");
13188: foreach my $item (@to_skip) {
13189: if (($item ne '') && ($item !~ /\.\./)) {
13190: if (-f "$dir/$tempdir/$item") {
13191: unlink("$dir/$tempdir/$item");
13192: } elsif (-d "$dir/$tempdir/$item") {
13193: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
13194: }
13195: }
13196: }
13197: foreach my $item (@to_overwrite) {
13198: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
13199: if (($item ne '') && ($item !~ /\.\./)) {
13200: if (-f "$dir/$item") {
13201: unlink("$dir/$item");
13202: } elsif (-d "$dir/$item") {
13203: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
13204: }
13205: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
13206: }
1.1065 raeburn 13207: }
13208: }
1.1075.2.128 raeburn 13209: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
13210: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
13211: }
1.1065 raeburn 13212: }
13213: } else {
13214: ($decompressed,$display) =
13215: &decompress_uploaded_file($file,$dir);
13216: }
1.1055 raeburn 13217: if ($decompressed eq 'ok') {
1.1065 raeburn 13218: $output = '<p class="LC_info">'.
13219: &mt('Files extracted successfully from archive.').
13220: '</p>'."\n";
1.1055 raeburn 13221: my ($warning,$result,@contents);
13222: my ($newdirlistref,$newlisterror) =
13223: &Apache::lonnet::dirlist($currdir,$docudom,
13224: $docuname,1);
13225: my (%is_dir,%changes,@newitems);
13226: my $dirptr = 16384;
1.1065 raeburn 13227: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 13228: foreach my $dir_line (@{$newdirlistref}) {
13229: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 13230: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 13231: push(@newitems,$item);
13232: if ($dirptr&$testdir) {
13233: $is_dir{$item} = 1;
13234: }
13235: $changes{$item} = 1;
13236: }
13237: }
13238: }
13239: if (keys(%changes) > 0) {
13240: foreach my $item (sort(@newitems)) {
13241: if ($changes{$item}) {
13242: push(@contents,$item);
13243: }
13244: }
13245: }
13246: if (@contents > 0) {
1.1067 raeburn 13247: my $wantform;
13248: unless ($env{'form.autoextract_camtasia'}) {
13249: $wantform = 1;
13250: }
1.1056 raeburn 13251: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 13252: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13253: $currdir,\%is_dir,
13254: \%children,\%parent,
1.1056 raeburn 13255: \@contents,\%dirorder,
13256: \%titles,$wantform);
1.1055 raeburn 13257: if ($datatable ne '') {
13258: $output .= &archive_options_form('decompressed',$datatable,
13259: $count,$hiddenelem);
1.1065 raeburn 13260: my $startcount = 6;
1.1055 raeburn 13261: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13262: \%titles,\%children);
1.1055 raeburn 13263: }
1.1067 raeburn 13264: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 13265: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13266: my %displayed;
13267: my $total = 1;
13268: $env{'form.archive_directory'} = [];
13269: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13270: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13271: $path =~ s{/$}{};
13272: my $item;
13273: if ($path ne '') {
13274: $item = "$path/$titles{$i}";
13275: } else {
13276: $item = $titles{$i};
13277: }
13278: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13279: if ($item eq $contents[0]) {
13280: push(@{$env{'form.archive_directory'}},$i);
13281: $env{'form.archive_'.$i} = 'display';
13282: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13283: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 13284: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13285: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13286: $env{'form.archive_'.$i} = 'display';
13287: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13288: $displayed{'web'} = $i;
13289: } else {
1.1075.2.59 raeburn 13290: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13291: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13292: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13293: push(@{$env{'form.archive_directory'}},$i);
13294: }
13295: $env{'form.archive_'.$i} = 'dependency';
13296: }
13297: $total ++;
13298: }
13299: for (my $i=1; $i<$total; $i++) {
13300: next if ($i == $displayed{'web'});
13301: next if ($i == $displayed{'folder'});
13302: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13303: }
13304: $env{'form.phase'} = 'decompress_cleanup';
13305: $env{'form.archivedelete'} = 1;
13306: $env{'form.archive_count'} = $total-1;
13307: $output .=
13308: &process_extracted_files('coursedocs',$docudom,
13309: $docuname,$destination,
13310: $dir_root,$hiddenelem);
13311: }
1.1055 raeburn 13312: } else {
13313: $warning = &mt('No new items extracted from archive file.');
13314: }
13315: } else {
13316: $output = $display;
13317: $error = &mt('An error occurred during extraction from the archive file.');
13318: }
13319: }
13320: }
13321: }
13322: if ($error) {
13323: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13324: $error.'</p>'."\n";
13325: }
13326: if ($warning) {
13327: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13328: }
13329: return $output;
13330: }
13331:
13332: sub get_extracted {
1.1056 raeburn 13333: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13334: $titles,$wantform) = @_;
1.1055 raeburn 13335: my $count = 0;
13336: my $depth = 0;
13337: my $datatable;
1.1056 raeburn 13338: my @hierarchy;
1.1055 raeburn 13339: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13340: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13341: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13342: foreach my $item (@{$contents}) {
13343: $count ++;
1.1056 raeburn 13344: @{$dirorder->{$count}} = @hierarchy;
13345: $titles->{$count} = $item;
1.1055 raeburn 13346: &archive_hierarchy($depth,$count,$parent,$children);
13347: if ($wantform) {
13348: $datatable .= &archive_row($is_dir->{$item},$item,
13349: $currdir,$depth,$count);
13350: }
13351: if ($is_dir->{$item}) {
13352: $depth ++;
1.1056 raeburn 13353: push(@hierarchy,$count);
13354: $parent->{$depth} = $count;
1.1055 raeburn 13355: $datatable .=
13356: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13357: \$depth,\$count,\@hierarchy,$dirorder,
13358: $children,$parent,$titles,$wantform);
1.1055 raeburn 13359: $depth --;
1.1056 raeburn 13360: pop(@hierarchy);
1.1055 raeburn 13361: }
13362: }
13363: return ($count,$datatable);
13364: }
13365:
13366: sub recurse_extracted_archive {
1.1056 raeburn 13367: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13368: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13369: my $result='';
1.1056 raeburn 13370: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13371: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13372: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13373: return $result;
13374: }
13375: my $dirptr = 16384;
13376: my ($newdirlistref,$newlisterror) =
13377: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13378: if (ref($newdirlistref) eq 'ARRAY') {
13379: foreach my $dir_line (@{$newdirlistref}) {
13380: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13381: unless ($item =~ /^\.+$/) {
13382: $$count ++;
1.1056 raeburn 13383: @{$dirorder->{$$count}} = @{$hierarchy};
13384: $titles->{$$count} = $item;
1.1055 raeburn 13385: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13386:
1.1055 raeburn 13387: my $is_dir;
13388: if ($dirptr&$testdir) {
13389: $is_dir = 1;
13390: }
13391: if ($wantform) {
13392: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13393: }
13394: if ($is_dir) {
13395: $$depth ++;
1.1056 raeburn 13396: push(@{$hierarchy},$$count);
13397: $parent->{$$depth} = $$count;
1.1055 raeburn 13398: $result .=
13399: &recurse_extracted_archive("$currdir/$item",$docudom,
13400: $docuname,$depth,$count,
1.1056 raeburn 13401: $hierarchy,$dirorder,$children,
13402: $parent,$titles,$wantform);
1.1055 raeburn 13403: $$depth --;
1.1056 raeburn 13404: pop(@{$hierarchy});
1.1055 raeburn 13405: }
13406: }
13407: }
13408: }
13409: return $result;
13410: }
13411:
13412: sub archive_hierarchy {
13413: my ($depth,$count,$parent,$children) =@_;
13414: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13415: if (exists($parent->{$depth})) {
13416: $children->{$parent->{$depth}} .= $count.':';
13417: }
13418: }
13419: return;
13420: }
13421:
13422: sub archive_row {
13423: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13424: my ($name) = ($item =~ m{([^/]+)$});
13425: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13426: 'display' => 'Add as file',
1.1055 raeburn 13427: 'dependency' => 'Include as dependency',
13428: 'discard' => 'Discard',
13429: );
13430: if ($is_dir) {
1.1059 raeburn 13431: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13432: }
1.1056 raeburn 13433: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13434: my $offset = 0;
1.1055 raeburn 13435: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13436: $offset ++;
1.1065 raeburn 13437: if ($action ne 'display') {
13438: $offset ++;
13439: }
1.1055 raeburn 13440: $output .= '<td><span class="LC_nobreak">'.
13441: '<label><input type="radio" name="archive_'.$count.
13442: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13443: my $text = $choices{$action};
13444: if ($is_dir) {
13445: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13446: if ($action eq 'display') {
1.1059 raeburn 13447: $text = &mt('Add as folder');
1.1055 raeburn 13448: }
1.1056 raeburn 13449: } else {
13450: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13451:
13452: }
13453: $output .= ' /> '.$choices{$action}.'</label></span>';
13454: if ($action eq 'dependency') {
13455: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13456: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13457: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13458: '<option value=""></option>'."\n".
13459: '</select>'."\n".
13460: '</div>';
1.1059 raeburn 13461: } elsif ($action eq 'display') {
13462: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13463: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13464: '</div>';
1.1055 raeburn 13465: }
1.1056 raeburn 13466: $output .= '</td>';
1.1055 raeburn 13467: }
13468: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13469: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13470: for (my $i=0; $i<$depth; $i++) {
13471: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13472: }
13473: if ($is_dir) {
13474: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13475: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13476: } else {
13477: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13478: }
13479: $output .= ' '.$name.'</td>'."\n".
13480: &end_data_table_row();
13481: return $output;
13482: }
13483:
13484: sub archive_options_form {
1.1065 raeburn 13485: my ($form,$display,$count,$hiddenelem) = @_;
13486: my %lt = &Apache::lonlocal::texthash(
13487: perm => 'Permanently remove archive file?',
13488: hows => 'How should each extracted item be incorporated in the course?',
13489: cont => 'Content actions for all',
13490: addf => 'Add as folder/file',
13491: incd => 'Include as dependency for a displayed file',
13492: disc => 'Discard',
13493: no => 'No',
13494: yes => 'Yes',
13495: save => 'Save',
13496: );
13497: my $output = <<"END";
13498: <form name="$form" method="post" action="">
13499: <p><span class="LC_nobreak">$lt{'perm'}
13500: <label>
13501: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13502: </label>
13503:
13504: <label>
13505: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13506: </span>
13507: </p>
13508: <input type="hidden" name="phase" value="decompress_cleanup" />
13509: <br />$lt{'hows'}
13510: <div class="LC_columnSection">
13511: <fieldset>
13512: <legend>$lt{'cont'}</legend>
13513: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13514: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13515: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13516: </fieldset>
13517: </div>
13518: END
13519: return $output.
1.1055 raeburn 13520: &start_data_table()."\n".
1.1065 raeburn 13521: $display."\n".
1.1055 raeburn 13522: &end_data_table()."\n".
13523: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13524: $hiddenelem.
1.1065 raeburn 13525: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13526: '</form>';
13527: }
13528:
13529: sub archive_javascript {
1.1056 raeburn 13530: my ($startcount,$numitems,$titles,$children) = @_;
13531: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13532: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13533: my $scripttag = <<START;
13534: <script type="text/javascript">
13535: // <![CDATA[
13536:
13537: function checkAll(form,prefix) {
13538: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13539: for (var i=0; i < form.elements.length; i++) {
13540: var id = form.elements[i].id;
13541: if ((id != '') && (id != undefined)) {
13542: if (idstr.test(id)) {
13543: if (form.elements[i].type == 'radio') {
13544: form.elements[i].checked = true;
1.1056 raeburn 13545: var nostart = i-$startcount;
1.1059 raeburn 13546: var offset = nostart%7;
13547: var count = (nostart-offset)/7;
1.1056 raeburn 13548: dependencyCheck(form,count,offset);
1.1055 raeburn 13549: }
13550: }
13551: }
13552: }
13553: }
13554:
13555: function propagateCheck(form,count) {
13556: if (count > 0) {
1.1059 raeburn 13557: var startelement = $startcount + ((count-1) * 7);
13558: for (var j=1; j<6; j++) {
13559: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13560: var item = startelement + j;
13561: if (form.elements[item].type == 'radio') {
13562: if (form.elements[item].checked) {
13563: containerCheck(form,count,j);
13564: break;
13565: }
1.1055 raeburn 13566: }
13567: }
13568: }
13569: }
13570: }
13571:
13572: numitems = $numitems
1.1056 raeburn 13573: var titles = new Array(numitems);
13574: var parents = new Array(numitems);
1.1055 raeburn 13575: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13576: parents[i] = new Array;
1.1055 raeburn 13577: }
1.1059 raeburn 13578: var maintitle = '$maintitle';
1.1055 raeburn 13579:
13580: START
13581:
1.1056 raeburn 13582: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13583: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13584: for (my $i=0; $i<@contents; $i ++) {
13585: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13586: }
13587: }
13588:
1.1056 raeburn 13589: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13590: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13591: }
13592:
1.1055 raeburn 13593: $scripttag .= <<END;
13594:
13595: function containerCheck(form,count,offset) {
13596: if (count > 0) {
1.1056 raeburn 13597: dependencyCheck(form,count,offset);
1.1059 raeburn 13598: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13599: form.elements[item].checked = true;
13600: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13601: if (parents[count].length > 0) {
13602: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13603: containerCheck(form,parents[count][j],offset);
13604: }
13605: }
13606: }
13607: }
13608: }
13609:
13610: function dependencyCheck(form,count,offset) {
13611: if (count > 0) {
1.1059 raeburn 13612: var chosen = (offset+$startcount)+7*(count-1);
13613: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13614: var currtype = form.elements[depitem].type;
13615: if (form.elements[chosen].value == 'dependency') {
13616: document.getElementById('arc_depon_'+count).style.display='block';
13617: form.elements[depitem].options.length = 0;
13618: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 13619: for (var i=1; i<=numitems; i++) {
13620: if (i == count) {
13621: continue;
13622: }
1.1059 raeburn 13623: var startelement = $startcount + (i-1) * 7;
13624: for (var j=1; j<6; j++) {
13625: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13626: var item = startelement + j;
13627: if (form.elements[item].type == 'radio') {
13628: if (form.elements[item].checked) {
13629: if (form.elements[item].value == 'display') {
13630: var n = form.elements[depitem].options.length;
13631: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13632: }
13633: }
13634: }
13635: }
13636: }
13637: }
13638: } else {
13639: document.getElementById('arc_depon_'+count).style.display='none';
13640: form.elements[depitem].options.length = 0;
13641: form.elements[depitem].options[0] = new Option('Select','',true,true);
13642: }
1.1059 raeburn 13643: titleCheck(form,count,offset);
1.1056 raeburn 13644: }
13645: }
13646:
13647: function propagateSelect(form,count,offset) {
13648: if (count > 0) {
1.1065 raeburn 13649: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13650: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13651: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13652: if (parents[count].length > 0) {
13653: for (var j=0; j<parents[count].length; j++) {
13654: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13655: }
13656: }
13657: }
13658: }
13659: }
1.1056 raeburn 13660:
13661: function containerSelect(form,count,offset,picked) {
13662: if (count > 0) {
1.1065 raeburn 13663: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13664: if (form.elements[item].type == 'radio') {
13665: if (form.elements[item].value == 'dependency') {
13666: if (form.elements[item+1].type == 'select-one') {
13667: for (var i=0; i<form.elements[item+1].options.length; i++) {
13668: if (form.elements[item+1].options[i].value == picked) {
13669: form.elements[item+1].selectedIndex = i;
13670: break;
13671: }
13672: }
13673: }
13674: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13675: if (parents[count].length > 0) {
13676: for (var j=0; j<parents[count].length; j++) {
13677: containerSelect(form,parents[count][j],offset,picked);
13678: }
13679: }
13680: }
13681: }
13682: }
13683: }
13684: }
13685:
1.1059 raeburn 13686: function titleCheck(form,count,offset) {
13687: if (count > 0) {
13688: var chosen = (offset+$startcount)+7*(count-1);
13689: var depitem = $startcount + ((count-1) * 7) + 2;
13690: var currtype = form.elements[depitem].type;
13691: if (form.elements[chosen].value == 'display') {
13692: document.getElementById('arc_title_'+count).style.display='block';
13693: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13694: document.getElementById('archive_title_'+count).value=maintitle;
13695: }
13696: } else {
13697: document.getElementById('arc_title_'+count).style.display='none';
13698: if (currtype == 'text') {
13699: document.getElementById('archive_title_'+count).value='';
13700: }
13701: }
13702: }
13703: return;
13704: }
13705:
1.1055 raeburn 13706: // ]]>
13707: </script>
13708: END
13709: return $scripttag;
13710: }
13711:
13712: sub process_extracted_files {
1.1067 raeburn 13713: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13714: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 13715: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13716: my @ids=&Apache::lonnet::current_machine_ids();
13717: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13718: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13719: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13720: if (grep(/^\Q$docuhome\E$/,@ids)) {
13721: $prefix = &LONCAPA::propath($docudom,$docuname);
13722: $pathtocheck = "$dir_root/$destination";
13723: $dir = $dir_root;
13724: $ishome = 1;
13725: } else {
13726: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13727: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 13728: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13729: }
13730: my $currdir = "$dir_root/$destination";
13731: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13732: if ($env{'form.folderpath'}) {
13733: my @items = split('&',$env{'form.folderpath'});
13734: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 13735: if ($env{'form.folderpath'} =~ /\:1$/) {
13736: $containers{'0'}='page';
13737: } else {
13738: $containers{'0'}='sequence';
13739: }
1.1055 raeburn 13740: }
13741: my @archdirs = &get_env_multiple('form.archive_directory');
13742: if ($numitems) {
13743: for (my $i=1; $i<=$numitems; $i++) {
13744: my $path = $env{'form.archive_content_'.$i};
13745: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13746: my $item = $1;
13747: $toplevelitems{$item} = $i;
13748: if (grep(/^\Q$i\E$/,@archdirs)) {
13749: $is_dir{$item} = 1;
13750: }
13751: }
13752: }
13753: }
1.1067 raeburn 13754: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13755: if (keys(%toplevelitems) > 0) {
13756: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13757: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13758: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13759: }
1.1066 raeburn 13760: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13761: if ($numitems) {
13762: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 13763: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13764: my $path = $env{'form.archive_content_'.$i};
13765: if ($path =~ /^\Q$pathtocheck\E/) {
13766: if ($env{'form.archive_'.$i} eq 'discard') {
13767: if ($prefix ne '' && $path ne '') {
13768: if (-e $prefix.$path) {
1.1066 raeburn 13769: if ((@archdirs > 0) &&
13770: (grep(/^\Q$i\E$/,@archdirs))) {
13771: $todeletedir{$prefix.$path} = 1;
13772: } else {
13773: $todelete{$prefix.$path} = 1;
13774: }
1.1055 raeburn 13775: }
13776: }
13777: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13778: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13779: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13780: $docstitle = $env{'form.archive_title_'.$i};
13781: if ($docstitle eq '') {
13782: $docstitle = $title;
13783: }
1.1055 raeburn 13784: $outer = 0;
1.1056 raeburn 13785: if (ref($dirorder{$i}) eq 'ARRAY') {
13786: if (@{$dirorder{$i}} > 0) {
13787: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13788: if ($env{'form.archive_'.$item} eq 'display') {
13789: $outer = $item;
13790: last;
13791: }
13792: }
13793: }
13794: }
13795: my ($errtext,$fatal) =
13796: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13797: '/'.$folders{$outer}.'.'.
13798: $containers{$outer});
13799: next if ($fatal);
13800: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13801: if ($context eq 'coursedocs') {
1.1056 raeburn 13802: $mapinner{$i} = time;
1.1055 raeburn 13803: $folders{$i} = 'default_'.$mapinner{$i};
13804: $containers{$i} = 'sequence';
13805: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13806: $folders{$i}.'.'.$containers{$i};
13807: my $newidx = &LONCAPA::map::getresidx();
13808: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13809: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13810: push(@LONCAPA::map::order,$newidx);
13811: my ($outtext,$errtext) =
13812: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13813: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 13814: '.'.$containers{$outer},1,1);
1.1056 raeburn 13815: $newseqid{$i} = $newidx;
1.1067 raeburn 13816: unless ($errtext) {
1.1075.2.128 raeburn 13817: $result .= '<li>'.&mt('Folder: [_1] added to course',
13818: &HTML::Entities::encode($docstitle,'<>&"'))..
13819: '</li>'."\n";
1.1067 raeburn 13820: }
1.1055 raeburn 13821: }
13822: } else {
13823: if ($context eq 'coursedocs') {
13824: my $newidx=&LONCAPA::map::getresidx();
13825: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13826: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13827: $title;
1.1075.2.161. .13(raeb 13828:-23): if (($outer !~ /\D/) &&
13829:-23): (($mapinner{$outer} eq 'default') || ($mapinner{$outer} !~ /\D/)) &&
13830:-23): ($newidx !~ /\D/)) {
1.1075.2.128 raeburn 13831: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13832: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 13833: }
1.1075.2.128 raeburn 13834: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13835: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13836: }
13837: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13838: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13839: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13840: unless ($ishome) {
13841: my $fetch = "$newdest{$i}/$title";
13842: $fetch =~ s/^\Q$prefix$dir\E//;
13843: $prompttofetch{$fetch} = 1;
13844: }
13845: }
13846: }
13847: $LONCAPA::map::resources[$newidx]=
13848: $docstitle.':'.$url.':false:normal:res';
13849: push(@LONCAPA::map::order, $newidx);
13850: my ($outtext,$errtext)=
13851: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13852: $docuname.'/'.$folders{$outer}.
13853: '.'.$containers{$outer},1,1);
13854: unless ($errtext) {
13855: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13856: $result .= '<li>'.&mt('File: [_1] added to course',
13857: &HTML::Entities::encode($docstitle,'<>&"')).
13858: '</li>'."\n";
13859: }
1.1067 raeburn 13860: }
1.1075.2.128 raeburn 13861: } else {
13862: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13863: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 13864: }
1.1055 raeburn 13865: }
13866: }
1.1075.2.11 raeburn 13867: }
13868: } else {
1.1075.2.128 raeburn 13869: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13870: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 13871: }
13872: }
13873: for (my $i=1; $i<=$numitems; $i++) {
13874: next unless ($env{'form.archive_'.$i} eq 'dependency');
13875: my $path = $env{'form.archive_content_'.$i};
13876: if ($path =~ /^\Q$pathtocheck\E/) {
13877: my ($title) = ($path =~ m{/([^/]+)$});
13878: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13879: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13880: if (ref($dirorder{$i}) eq 'ARRAY') {
13881: my ($itemidx,$fullpath,$relpath);
13882: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13883: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13884: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 13885: if ($dirorder{$i}->[$j] eq $container) {
13886: $itemidx = $j;
1.1056 raeburn 13887: }
13888: }
1.1075.2.11 raeburn 13889: }
13890: if ($itemidx eq '') {
13891: $itemidx = 0;
13892: }
13893: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13894: if ($mapinner{$referrer{$i}}) {
13895: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13896: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13897: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13898: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13899: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13900: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13901: if (!-e $fullpath) {
13902: mkdir($fullpath,0755);
1.1056 raeburn 13903: }
13904: }
1.1075.2.11 raeburn 13905: } else {
13906: last;
1.1056 raeburn 13907: }
1.1075.2.11 raeburn 13908: }
13909: }
13910: } elsif ($newdest{$referrer{$i}}) {
13911: $fullpath = $newdest{$referrer{$i}};
13912: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13913: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13914: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13915: last;
13916: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13917: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13918: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13919: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13920: if (!-e $fullpath) {
13921: mkdir($fullpath,0755);
1.1056 raeburn 13922: }
13923: }
1.1075.2.11 raeburn 13924: } else {
13925: last;
1.1056 raeburn 13926: }
1.1075.2.11 raeburn 13927: }
13928: }
13929: if ($fullpath ne '') {
13930: if (-e "$prefix$path") {
1.1075.2.128 raeburn 13931: unless (rename("$prefix$path","$fullpath/$title")) {
13932: $warning .= &mt('Failed to rename dependency').'<br />';
13933: }
1.1075.2.11 raeburn 13934: }
13935: if (-e "$fullpath/$title") {
13936: my $showpath;
13937: if ($relpath ne '') {
13938: $showpath = "$relpath/$title";
13939: } else {
13940: $showpath = "/$title";
1.1056 raeburn 13941: }
1.1075.2.128 raeburn 13942: $result .= '<li>'.&mt('[_1] included as a dependency',
13943: &HTML::Entities::encode($showpath,'<>&"')).
13944: '</li>'."\n";
13945: unless ($ishome) {
13946: my $fetch = "$fullpath/$title";
13947: $fetch =~ s/^\Q$prefix$dir\E//;
13948: $prompttofetch{$fetch} = 1;
13949: }
1.1055 raeburn 13950: }
13951: }
13952: }
1.1075.2.11 raeburn 13953: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13954: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 13955: &HTML::Entities::encode($path,'<>&"'),
13956: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13957: '<br />';
1.1055 raeburn 13958: }
13959: } else {
1.1075.2.128 raeburn 13960: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13961: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13962: }
13963: }
13964: if (keys(%todelete)) {
13965: foreach my $key (keys(%todelete)) {
13966: unlink($key);
1.1066 raeburn 13967: }
13968: }
13969: if (keys(%todeletedir)) {
13970: foreach my $key (keys(%todeletedir)) {
13971: rmdir($key);
13972: }
13973: }
13974: foreach my $dir (sort(keys(%is_dir))) {
13975: if (($pathtocheck ne '') && ($dir ne '')) {
13976: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13977: }
13978: }
1.1067 raeburn 13979: if ($result ne '') {
13980: $output .= '<ul>'."\n".
13981: $result."\n".
13982: '</ul>';
13983: }
13984: unless ($ishome) {
13985: my $replicationfail;
13986: foreach my $item (keys(%prompttofetch)) {
13987: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13988: unless ($fetchresult eq 'ok') {
13989: $replicationfail .= '<li>'.$item.'</li>'."\n";
13990: }
13991: }
13992: if ($replicationfail) {
13993: $output .= '<p class="LC_error">'.
13994: &mt('Course home server failed to retrieve:').'<ul>'.
13995: $replicationfail.
13996: '</ul></p>';
13997: }
13998: }
1.1055 raeburn 13999: } else {
14000: $warning = &mt('No items found in archive.');
14001: }
14002: if ($error) {
14003: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14004: $error.'</p>'."\n";
14005: }
14006: if ($warning) {
14007: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
14008: }
14009: return $output;
14010: }
14011:
1.1066 raeburn 14012: sub cleanup_empty_dirs {
14013: my ($path) = @_;
14014: if (($path ne '') && (-d $path)) {
14015: if (opendir(my $dirh,$path)) {
14016: my @dircontents = grep(!/^\./,readdir($dirh));
14017: my $numitems = 0;
14018: foreach my $item (@dircontents) {
14019: if (-d "$path/$item") {
1.1075.2.28 raeburn 14020: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 14021: if (-e "$path/$item") {
14022: $numitems ++;
14023: }
14024: } else {
14025: $numitems ++;
14026: }
14027: }
14028: if ($numitems == 0) {
14029: rmdir($path);
14030: }
14031: closedir($dirh);
14032: }
14033: }
14034: return;
14035: }
14036:
1.41 ng 14037: =pod
1.45 matthew 14038:
1.1075.2.56 raeburn 14039: =item * &get_folder_hierarchy()
1.1068 raeburn 14040:
14041: Provides hierarchy of names of folders/sub-folders containing the current
14042: item,
14043:
14044: Inputs: 3
14045: - $navmap - navmaps object
14046:
14047: - $map - url for map (either the trigger itself, or map containing
14048: the resource, which is the trigger).
14049:
14050: - $showitem - 1 => show title for map itself; 0 => do not show.
14051:
14052: Outputs: 1 @pathitems - array of folder/subfolder names.
14053:
14054: =cut
14055:
14056: sub get_folder_hierarchy {
14057: my ($navmap,$map,$showitem) = @_;
14058: my @pathitems;
14059: if (ref($navmap)) {
14060: my $mapres = $navmap->getResourceByUrl($map);
14061: if (ref($mapres)) {
14062: my $pcslist = $mapres->map_hierarchy();
14063: if ($pcslist ne '') {
14064: my @pcs = split(/,/,$pcslist);
14065: foreach my $pc (@pcs) {
14066: if ($pc == 1) {
1.1075.2.38 raeburn 14067: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 14068: } else {
14069: my $res = $navmap->getByMapPc($pc);
14070: if (ref($res)) {
14071: my $title = $res->compTitle();
14072: $title =~ s/\W+/_/g;
14073: if ($title ne '') {
14074: push(@pathitems,$title);
14075: }
14076: }
14077: }
14078: }
14079: }
1.1071 raeburn 14080: if ($showitem) {
14081: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 14082: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 14083: } else {
14084: my $maptitle = $mapres->compTitle();
14085: $maptitle =~ s/\W+/_/g;
14086: if ($maptitle ne '') {
14087: push(@pathitems,$maptitle);
14088: }
1.1068 raeburn 14089: }
14090: }
14091: }
14092: }
14093: return @pathitems;
14094: }
14095:
14096: =pod
14097:
1.1015 raeburn 14098: =item * &get_turnedin_filepath()
14099:
14100: Determines path in a user's portfolio file for storage of files uploaded
14101: to a specific essayresponse or dropbox item.
14102:
14103: Inputs: 3 required + 1 optional.
14104: $symb is symb for resource, $uname and $udom are for current user (required).
14105: $caller is optional (can be "submission", if routine is called when storing
14106: an upoaded file when "Submit Answer" button was pressed).
14107:
14108: Returns array containing $path and $multiresp.
14109: $path is path in portfolio. $multiresp is 1 if this resource contains more
14110: than one file upload item. Callers of routine should append partid as a
14111: subdirectory to $path in cases where $multiresp is 1.
14112:
14113: Called by: homework/essayresponse.pm and homework/structuretags.pm
14114:
14115: =cut
14116:
14117: sub get_turnedin_filepath {
14118: my ($symb,$uname,$udom,$caller) = @_;
14119: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
14120: my $turnindir;
14121: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
14122: $turnindir = $userhash{'turnindir'};
14123: my ($path,$multiresp);
14124: if ($turnindir eq '') {
14125: if ($caller eq 'submission') {
14126: $turnindir = &mt('turned in');
14127: $turnindir =~ s/\W+/_/g;
14128: my %newhash = (
14129: 'turnindir' => $turnindir,
14130: );
14131: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
14132: }
14133: }
14134: if ($turnindir ne '') {
14135: $path = '/'.$turnindir.'/';
14136: my ($multipart,$turnin,@pathitems);
14137: my $navmap = Apache::lonnavmaps::navmap->new();
14138: if (defined($navmap)) {
14139: my $mapres = $navmap->getResourceByUrl($map);
14140: if (ref($mapres)) {
14141: my $pcslist = $mapres->map_hierarchy();
14142: if ($pcslist ne '') {
14143: foreach my $pc (split(/,/,$pcslist)) {
14144: my $res = $navmap->getByMapPc($pc);
14145: if (ref($res)) {
14146: my $title = $res->compTitle();
14147: $title =~ s/\W+/_/g;
14148: if ($title ne '') {
1.1075.2.48 raeburn 14149: if (($pc > 1) && (length($title) > 12)) {
14150: $title = substr($title,0,12);
14151: }
1.1015 raeburn 14152: push(@pathitems,$title);
14153: }
14154: }
14155: }
14156: }
14157: my $maptitle = $mapres->compTitle();
14158: $maptitle =~ s/\W+/_/g;
14159: if ($maptitle ne '') {
1.1075.2.48 raeburn 14160: if (length($maptitle) > 12) {
14161: $maptitle = substr($maptitle,0,12);
14162: }
1.1015 raeburn 14163: push(@pathitems,$maptitle);
14164: }
14165: unless ($env{'request.state'} eq 'construct') {
14166: my $res = $navmap->getBySymb($symb);
14167: if (ref($res)) {
14168: my $partlist = $res->parts();
14169: my $totaluploads = 0;
14170: if (ref($partlist) eq 'ARRAY') {
14171: foreach my $part (@{$partlist}) {
14172: my @types = $res->responseType($part);
14173: my @ids = $res->responseIds($part);
14174: for (my $i=0; $i < scalar(@ids); $i++) {
14175: if ($types[$i] eq 'essay') {
14176: my $partid = $part.'_'.$ids[$i];
14177: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
14178: $totaluploads ++;
14179: }
14180: }
14181: }
14182: }
14183: if ($totaluploads > 1) {
14184: $multiresp = 1;
14185: }
14186: }
14187: }
14188: }
14189: } else {
14190: return;
14191: }
14192: } else {
14193: return;
14194: }
14195: my $restitle=&Apache::lonnet::gettitle($symb);
14196: $restitle =~ s/\W+/_/g;
14197: if ($restitle eq '') {
14198: $restitle = ($resurl =~ m{/[^/]+$});
14199: if ($restitle eq '') {
14200: $restitle = time;
14201: }
14202: }
1.1075.2.48 raeburn 14203: if (length($restitle) > 12) {
14204: $restitle = substr($restitle,0,12);
14205: }
1.1015 raeburn 14206: push(@pathitems,$restitle);
14207: $path .= join('/',@pathitems);
14208: }
14209: return ($path,$multiresp);
14210: }
14211:
14212: =pod
14213:
1.464 albertel 14214: =back
1.41 ng 14215:
1.112 bowersj2 14216: =head1 CSV Upload/Handling functions
1.38 albertel 14217:
1.41 ng 14218: =over 4
14219:
1.648 raeburn 14220: =item * &upfile_store($r)
1.41 ng 14221:
14222: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 14223: needs $env{'form.upfile'}
1.41 ng 14224: returns $datatoken to be put into hidden field
14225:
14226: =cut
1.31 albertel 14227:
14228: sub upfile_store {
14229: my $r=shift;
1.258 albertel 14230: $env{'form.upfile'}=~s/\r/\n/gs;
14231: $env{'form.upfile'}=~s/\f/\n/gs;
14232: $env{'form.upfile'}=~s/\n+/\n/gs;
14233: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 14234:
1.1075.2.128 raeburn 14235: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
14236: '_enroll_'.$env{'request.course.id'}.'_'.
14237: time.'_'.$$);
14238: return if ($datatoken eq '');
14239:
1.31 albertel 14240: {
1.158 raeburn 14241: my $datafile = $r->dir_config('lonDaemons').
14242: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 14243: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 14244: print $fh $env{'form.upfile'};
1.158 raeburn 14245: close($fh);
14246: }
1.31 albertel 14247: }
14248: return $datatoken;
14249: }
14250:
1.56 matthew 14251: =pod
14252:
1.1075.2.128 raeburn 14253: =item * &load_tmp_file($r,$datatoken)
1.41 ng 14254:
14255: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 14256: $datatoken is the name to assign to the temporary file.
1.258 albertel 14257: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14258:
14259: =cut
1.31 albertel 14260:
14261: sub load_tmp_file {
1.1075.2.128 raeburn 14262: my ($r,$datatoken) = @_;
14263: return if ($datatoken eq '');
1.31 albertel 14264: my @studentdata=();
14265: {
1.158 raeburn 14266: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 14267: '/tmp/'.$datatoken.'.tmp';
14268: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14269: @studentdata=<$fh>;
14270: close($fh);
14271: }
1.31 albertel 14272: }
1.258 albertel 14273: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14274: }
14275:
1.1075.2.128 raeburn 14276: sub valid_datatoken {
14277: my ($datatoken) = @_;
1.1075.2.131 raeburn 14278: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 14279: return $datatoken;
14280: }
14281: return;
14282: }
14283:
1.56 matthew 14284: =pod
14285:
1.648 raeburn 14286: =item * &upfile_record_sep()
1.41 ng 14287:
14288: Separate uploaded file into records
14289: returns array of records,
1.258 albertel 14290: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14291:
14292: =cut
1.31 albertel 14293:
14294: sub upfile_record_sep {
1.258 albertel 14295: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14296: } else {
1.248 albertel 14297: my @records;
1.258 albertel 14298: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14299: if ($line=~/^\s*$/) { next; }
14300: push(@records,$line);
14301: }
14302: return @records;
1.31 albertel 14303: }
14304: }
14305:
1.56 matthew 14306: =pod
14307:
1.648 raeburn 14308: =item * &record_sep($record)
1.41 ng 14309:
1.258 albertel 14310: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14311:
14312: =cut
14313:
1.263 www 14314: sub takeleft {
14315: my $index=shift;
14316: return substr('0000'.$index,-4,4);
14317: }
14318:
1.31 albertel 14319: sub record_sep {
14320: my $record=shift;
14321: my %components=();
1.258 albertel 14322: if ($env{'form.upfiletype'} eq 'xml') {
14323: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14324: my $i=0;
1.356 albertel 14325: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14326: $field=~s/^(\"|\')//;
14327: $field=~s/(\"|\')$//;
1.263 www 14328: $components{&takeleft($i)}=$field;
1.31 albertel 14329: $i++;
14330: }
1.258 albertel 14331: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14332: my $i=0;
1.356 albertel 14333: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14334: $field=~s/^(\"|\')//;
14335: $field=~s/(\"|\')$//;
1.263 www 14336: $components{&takeleft($i)}=$field;
1.31 albertel 14337: $i++;
14338: }
14339: } else {
1.561 www 14340: my $separator=',';
1.480 banghart 14341: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14342: $separator=';';
1.480 banghart 14343: }
1.31 albertel 14344: my $i=0;
1.561 www 14345: # the character we are looking for to indicate the end of a quote or a record
14346: my $looking_for=$separator;
14347: # do not add the characters to the fields
14348: my $ignore=0;
14349: # we just encountered a separator (or the beginning of the record)
14350: my $just_found_separator=1;
14351: # store the field we are working on here
14352: my $field='';
14353: # work our way through all characters in record
14354: foreach my $character ($record=~/(.)/g) {
14355: if ($character eq $looking_for) {
14356: if ($character ne $separator) {
14357: # Found the end of a quote, again looking for separator
14358: $looking_for=$separator;
14359: $ignore=1;
14360: } else {
14361: # Found a separator, store away what we got
14362: $components{&takeleft($i)}=$field;
14363: $i++;
14364: $just_found_separator=1;
14365: $ignore=0;
14366: $field='';
14367: }
14368: next;
14369: }
14370: # single or double quotation marks after a separator indicate beginning of a quote
14371: # we are now looking for the end of the quote and need to ignore separators
14372: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14373: $looking_for=$character;
14374: next;
14375: }
14376: # ignore would be true after we reached the end of a quote
14377: if ($ignore) { next; }
14378: if (($just_found_separator) && ($character=~/\s/)) { next; }
14379: $field.=$character;
14380: $just_found_separator=0;
1.31 albertel 14381: }
1.561 www 14382: # catch the very last entry, since we never encountered the separator
14383: $components{&takeleft($i)}=$field;
1.31 albertel 14384: }
14385: return %components;
14386: }
14387:
1.144 matthew 14388: ######################################################
14389: ######################################################
14390:
1.56 matthew 14391: =pod
14392:
1.648 raeburn 14393: =item * &upfile_select_html()
1.41 ng 14394:
1.144 matthew 14395: Return HTML code to select a file from the users machine and specify
14396: the file type.
1.41 ng 14397:
14398: =cut
14399:
1.144 matthew 14400: ######################################################
14401: ######################################################
1.31 albertel 14402: sub upfile_select_html {
1.144 matthew 14403: my %Types = (
14404: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14405: semisv => &mt('Semicolon separated values'),
1.144 matthew 14406: space => &mt('Space separated'),
14407: tab => &mt('Tabulator separated'),
14408: # xml => &mt('HTML/XML'),
14409: );
14410: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14411: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14412: foreach my $type (sort(keys(%Types))) {
14413: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14414: }
14415: $Str .= "</select>\n";
14416: return $Str;
1.31 albertel 14417: }
14418:
1.301 albertel 14419: sub get_samples {
14420: my ($records,$toget) = @_;
14421: my @samples=({});
14422: my $got=0;
14423: foreach my $rec (@$records) {
14424: my %temp = &record_sep($rec);
14425: if (! grep(/\S/, values(%temp))) { next; }
14426: if (%temp) {
14427: $samples[$got]=\%temp;
14428: $got++;
14429: if ($got == $toget) { last; }
14430: }
14431: }
14432: return \@samples;
14433: }
14434:
1.144 matthew 14435: ######################################################
14436: ######################################################
14437:
1.56 matthew 14438: =pod
14439:
1.648 raeburn 14440: =item * &csv_print_samples($r,$records)
1.41 ng 14441:
14442: Prints a table of sample values from each column uploaded $r is an
14443: Apache Request ref, $records is an arrayref from
14444: &Apache::loncommon::upfile_record_sep
14445:
14446: =cut
14447:
1.144 matthew 14448: ######################################################
14449: ######################################################
1.31 albertel 14450: sub csv_print_samples {
14451: my ($r,$records) = @_;
1.662 bisitz 14452: my $samples = &get_samples($records,5);
1.301 albertel 14453:
1.594 raeburn 14454: $r->print(&mt('Samples').'<br />'.&start_data_table().
14455: &start_data_table_header_row());
1.356 albertel 14456: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14457: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14458: $r->print(&end_data_table_header_row());
1.301 albertel 14459: foreach my $hash (@$samples) {
1.594 raeburn 14460: $r->print(&start_data_table_row());
1.356 albertel 14461: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14462: $r->print('<td>');
1.356 albertel 14463: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14464: $r->print('</td>');
14465: }
1.594 raeburn 14466: $r->print(&end_data_table_row());
1.31 albertel 14467: }
1.594 raeburn 14468: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14469: }
14470:
1.144 matthew 14471: ######################################################
14472: ######################################################
14473:
1.56 matthew 14474: =pod
14475:
1.648 raeburn 14476: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14477:
14478: Prints a table to create associations between values and table columns.
1.144 matthew 14479:
1.41 ng 14480: $r is an Apache Request ref,
14481: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14482: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14483:
14484: =cut
14485:
1.144 matthew 14486: ######################################################
14487: ######################################################
1.31 albertel 14488: sub csv_print_select_table {
14489: my ($r,$records,$d) = @_;
1.301 albertel 14490: my $i=0;
14491: my $samples = &get_samples($records,1);
1.144 matthew 14492: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14493: &start_data_table().&start_data_table_header_row().
1.144 matthew 14494: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14495: '<th>'.&mt('Column').'</th>'.
14496: &end_data_table_header_row()."\n");
1.356 albertel 14497: foreach my $array_ref (@$d) {
14498: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14499: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14500:
1.875 bisitz 14501: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14502: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14503: $r->print('<option value="none"></option>');
1.356 albertel 14504: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14505: $r->print('<option value="'.$sample.'"'.
14506: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14507: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14508: }
1.594 raeburn 14509: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14510: $i++;
14511: }
1.594 raeburn 14512: $r->print(&end_data_table());
1.31 albertel 14513: $i--;
14514: return $i;
14515: }
1.56 matthew 14516:
1.144 matthew 14517: ######################################################
14518: ######################################################
14519:
1.56 matthew 14520: =pod
1.31 albertel 14521:
1.648 raeburn 14522: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14523:
14524: Prints a table of sample values from the upload and can make associate samples to internal names.
14525:
14526: $r is an Apache Request ref,
14527: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14528: $d is an array of 2 element arrays (internal name, displayed name)
14529:
14530: =cut
14531:
1.144 matthew 14532: ######################################################
14533: ######################################################
1.31 albertel 14534: sub csv_samples_select_table {
14535: my ($r,$records,$d) = @_;
14536: my $i=0;
1.144 matthew 14537: #
1.662 bisitz 14538: my $max_samples = 5;
14539: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14540: $r->print(&start_data_table().
14541: &start_data_table_header_row().'<th>'.
14542: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14543: &end_data_table_header_row());
1.301 albertel 14544:
14545: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14546: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14547: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14548: foreach my $option (@$d) {
14549: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14550: $r->print('<option value="'.$value.'"'.
1.253 albertel 14551: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14552: $display.'</option>');
1.31 albertel 14553: }
14554: $r->print('</select></td><td>');
1.662 bisitz 14555: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14556: if (defined($samples->[$line]{$key})) {
14557: $r->print($samples->[$line]{$key}."<br />\n");
14558: }
14559: }
1.594 raeburn 14560: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14561: $i++;
14562: }
1.594 raeburn 14563: $r->print(&end_data_table());
1.31 albertel 14564: $i--;
14565: return($i);
1.115 matthew 14566: }
14567:
1.144 matthew 14568: ######################################################
14569: ######################################################
14570:
1.115 matthew 14571: =pod
14572:
1.648 raeburn 14573: =item * &clean_excel_name($name)
1.115 matthew 14574:
14575: Returns a replacement for $name which does not contain any illegal characters.
14576:
14577: =cut
14578:
1.144 matthew 14579: ######################################################
14580: ######################################################
1.115 matthew 14581: sub clean_excel_name {
14582: my ($name) = @_;
14583: $name =~ s/[:\*\?\/\\]//g;
14584: if (length($name) > 31) {
14585: $name = substr($name,0,31);
14586: }
14587: return $name;
1.25 albertel 14588: }
1.84 albertel 14589:
1.85 albertel 14590: =pod
14591:
1.648 raeburn 14592: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14593:
14594: Returns either 1 or undef
14595:
14596: 1 if the part is to be hidden, undef if it is to be shown
14597:
14598: Arguments are:
14599:
14600: $id the id of the part to be checked
14601: $symb, optional the symb of the resource to check
14602: $udom, optional the domain of the user to check for
14603: $uname, optional the username of the user to check for
14604:
14605: =cut
1.84 albertel 14606:
14607: sub check_if_partid_hidden {
14608: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14609: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14610: $symb,$udom,$uname);
1.141 albertel 14611: my $truth=1;
14612: #if the string starts with !, then the list is the list to show not hide
14613: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14614: my @hiddenlist=split(/,/,$hiddenparts);
14615: foreach my $checkid (@hiddenlist) {
1.141 albertel 14616: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14617: }
1.141 albertel 14618: return !$truth;
1.84 albertel 14619: }
1.127 matthew 14620:
1.138 matthew 14621:
14622: ############################################################
14623: ############################################################
14624:
14625: =pod
14626:
1.157 matthew 14627: =back
14628:
1.138 matthew 14629: =head1 cgi-bin script and graphing routines
14630:
1.157 matthew 14631: =over 4
14632:
1.648 raeburn 14633: =item * &get_cgi_id()
1.138 matthew 14634:
14635: Inputs: none
14636:
14637: Returns an id which can be used to pass environment variables
14638: to various cgi-bin scripts. These environment variables will
14639: be removed from the users environment after a given time by
14640: the routine &Apache::lonnet::transfer_profile_to_env.
14641:
14642: =cut
14643:
14644: ############################################################
14645: ############################################################
1.152 albertel 14646: my $uniq=0;
1.136 matthew 14647: sub get_cgi_id {
1.154 albertel 14648: $uniq=($uniq+1)%100000;
1.280 albertel 14649: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14650: }
14651:
1.127 matthew 14652: ############################################################
14653: ############################################################
14654:
14655: =pod
14656:
1.648 raeburn 14657: =item * &DrawBarGraph()
1.127 matthew 14658:
1.138 matthew 14659: Facilitates the plotting of data in a (stacked) bar graph.
14660: Puts plot definition data into the users environment in order for
14661: graph.png to plot it. Returns an <img> tag for the plot.
14662: The bars on the plot are labeled '1','2',...,'n'.
14663:
14664: Inputs:
14665:
14666: =over 4
14667:
14668: =item $Title: string, the title of the plot
14669:
14670: =item $xlabel: string, text describing the X-axis of the plot
14671:
14672: =item $ylabel: string, text describing the Y-axis of the plot
14673:
14674: =item $Max: scalar, the maximum Y value to use in the plot
14675: If $Max is < any data point, the graph will not be rendered.
14676:
1.140 matthew 14677: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14678: they are plotted. If undefined, default values will be used.
14679:
1.178 matthew 14680: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14681:
1.138 matthew 14682: =item @Values: An array of array references. Each array reference holds data
14683: to be plotted in a stacked bar chart.
14684:
1.239 matthew 14685: =item If the final element of @Values is a hash reference the key/value
14686: pairs will be added to the graph definition.
14687:
1.138 matthew 14688: =back
14689:
14690: Returns:
14691:
14692: An <img> tag which references graph.png and the appropriate identifying
14693: information for the plot.
14694:
1.127 matthew 14695: =cut
14696:
14697: ############################################################
14698: ############################################################
1.134 matthew 14699: sub DrawBarGraph {
1.178 matthew 14700: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14701: #
14702: if (! defined($colors)) {
14703: $colors = ['#33ff00',
14704: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14705: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14706: ];
14707: }
1.228 matthew 14708: my $extra_settings = {};
14709: if (ref($Values[-1]) eq 'HASH') {
14710: $extra_settings = pop(@Values);
14711: }
1.127 matthew 14712: #
1.136 matthew 14713: my $identifier = &get_cgi_id();
14714: my $id = 'cgi.'.$identifier;
1.129 matthew 14715: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14716: return '';
14717: }
1.225 matthew 14718: #
14719: my @Labels;
14720: if (defined($labels)) {
14721: @Labels = @$labels;
14722: } else {
14723: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 14724: push(@Labels,$i+1);
1.225 matthew 14725: }
14726: }
14727: #
1.129 matthew 14728: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14729: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14730: my %ValuesHash;
14731: my $NumSets=1;
14732: foreach my $array (@Values) {
14733: next if (! ref($array));
1.136 matthew 14734: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14735: join(',',@$array);
1.129 matthew 14736: }
1.127 matthew 14737: #
1.136 matthew 14738: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14739: if ($NumBars < 3) {
14740: $width = 120+$NumBars*32;
1.220 matthew 14741: $xskip = 1;
1.225 matthew 14742: $bar_width = 30;
14743: } elsif ($NumBars < 5) {
14744: $width = 120+$NumBars*20;
14745: $xskip = 1;
14746: $bar_width = 20;
1.220 matthew 14747: } elsif ($NumBars < 10) {
1.136 matthew 14748: $width = 120+$NumBars*15;
14749: $xskip = 1;
14750: $bar_width = 15;
14751: } elsif ($NumBars <= 25) {
14752: $width = 120+$NumBars*11;
14753: $xskip = 5;
14754: $bar_width = 8;
14755: } elsif ($NumBars <= 50) {
14756: $width = 120+$NumBars*8;
14757: $xskip = 5;
14758: $bar_width = 4;
14759: } else {
14760: $width = 120+$NumBars*8;
14761: $xskip = 5;
14762: $bar_width = 4;
14763: }
14764: #
1.137 matthew 14765: $Max = 1 if ($Max < 1);
14766: if ( int($Max) < $Max ) {
14767: $Max++;
14768: $Max = int($Max);
14769: }
1.127 matthew 14770: $Title = '' if (! defined($Title));
14771: $xlabel = '' if (! defined($xlabel));
14772: $ylabel = '' if (! defined($ylabel));
1.369 www 14773: $ValuesHash{$id.'.title'} = &escape($Title);
14774: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14775: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14776: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14777: $ValuesHash{$id.'.NumBars'} = $NumBars;
14778: $ValuesHash{$id.'.NumSets'} = $NumSets;
14779: $ValuesHash{$id.'.PlotType'} = 'bar';
14780: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14781: $ValuesHash{$id.'.height'} = $height;
14782: $ValuesHash{$id.'.width'} = $width;
14783: $ValuesHash{$id.'.xskip'} = $xskip;
14784: $ValuesHash{$id.'.bar_width'} = $bar_width;
14785: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14786: #
1.228 matthew 14787: # Deal with other parameters
14788: while (my ($key,$value) = each(%$extra_settings)) {
14789: $ValuesHash{$id.'.'.$key} = $value;
14790: }
14791: #
1.646 raeburn 14792: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14793: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14794: }
14795:
14796: ############################################################
14797: ############################################################
14798:
14799: =pod
14800:
1.648 raeburn 14801: =item * &DrawXYGraph()
1.137 matthew 14802:
1.138 matthew 14803: Facilitates the plotting of data in an XY graph.
14804: Puts plot definition data into the users environment in order for
14805: graph.png to plot it. Returns an <img> tag for the plot.
14806:
14807: Inputs:
14808:
14809: =over 4
14810:
14811: =item $Title: string, the title of the plot
14812:
14813: =item $xlabel: string, text describing the X-axis of the plot
14814:
14815: =item $ylabel: string, text describing the Y-axis of the plot
14816:
14817: =item $Max: scalar, the maximum Y value to use in the plot
14818: If $Max is < any data point, the graph will not be rendered.
14819:
14820: =item $colors: Array ref containing the hex color codes for the data to be
14821: plotted in. If undefined, default values will be used.
14822:
14823: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14824:
14825: =item $Ydata: Array ref containing Array refs.
1.185 www 14826: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14827:
14828: =item %Values: hash indicating or overriding any default values which are
14829: passed to graph.png.
14830: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14831:
14832: =back
14833:
14834: Returns:
14835:
14836: An <img> tag which references graph.png and the appropriate identifying
14837: information for the plot.
14838:
1.137 matthew 14839: =cut
14840:
14841: ############################################################
14842: ############################################################
14843: sub DrawXYGraph {
14844: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14845: #
14846: # Create the identifier for the graph
14847: my $identifier = &get_cgi_id();
14848: my $id = 'cgi.'.$identifier;
14849: #
14850: $Title = '' if (! defined($Title));
14851: $xlabel = '' if (! defined($xlabel));
14852: $ylabel = '' if (! defined($ylabel));
14853: my %ValuesHash =
14854: (
1.369 www 14855: $id.'.title' => &escape($Title),
14856: $id.'.xlabel' => &escape($xlabel),
14857: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14858: $id.'.y_max_value'=> $Max,
14859: $id.'.labels' => join(',',@$Xlabels),
14860: $id.'.PlotType' => 'XY',
14861: );
14862: #
14863: if (defined($colors) && ref($colors) eq 'ARRAY') {
14864: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14865: }
14866: #
14867: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14868: return '';
14869: }
14870: my $NumSets=1;
1.138 matthew 14871: foreach my $array (@{$Ydata}){
1.137 matthew 14872: next if (! ref($array));
14873: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14874: }
1.138 matthew 14875: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14876: #
14877: # Deal with other parameters
14878: while (my ($key,$value) = each(%Values)) {
14879: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14880: }
14881: #
1.646 raeburn 14882: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14883: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14884: }
14885:
14886: ############################################################
14887: ############################################################
14888:
14889: =pod
14890:
1.648 raeburn 14891: =item * &DrawXYYGraph()
1.138 matthew 14892:
14893: Facilitates the plotting of data in an XY graph with two Y axes.
14894: Puts plot definition data into the users environment in order for
14895: graph.png to plot it. Returns an <img> tag for the plot.
14896:
14897: Inputs:
14898:
14899: =over 4
14900:
14901: =item $Title: string, the title of the plot
14902:
14903: =item $xlabel: string, text describing the X-axis of the plot
14904:
14905: =item $ylabel: string, text describing the Y-axis of the plot
14906:
14907: =item $colors: Array ref containing the hex color codes for the data to be
14908: plotted in. If undefined, default values will be used.
14909:
14910: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14911:
14912: =item $Ydata1: The first data set
14913:
14914: =item $Min1: The minimum value of the left Y-axis
14915:
14916: =item $Max1: The maximum value of the left Y-axis
14917:
14918: =item $Ydata2: The second data set
14919:
14920: =item $Min2: The minimum value of the right Y-axis
14921:
14922: =item $Max2: The maximum value of the left Y-axis
14923:
14924: =item %Values: hash indicating or overriding any default values which are
14925: passed to graph.png.
14926: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14927:
14928: =back
14929:
14930: Returns:
14931:
14932: An <img> tag which references graph.png and the appropriate identifying
14933: information for the plot.
1.136 matthew 14934:
14935: =cut
14936:
14937: ############################################################
14938: ############################################################
1.137 matthew 14939: sub DrawXYYGraph {
14940: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14941: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14942: #
14943: # Create the identifier for the graph
14944: my $identifier = &get_cgi_id();
14945: my $id = 'cgi.'.$identifier;
14946: #
14947: $Title = '' if (! defined($Title));
14948: $xlabel = '' if (! defined($xlabel));
14949: $ylabel = '' if (! defined($ylabel));
14950: my %ValuesHash =
14951: (
1.369 www 14952: $id.'.title' => &escape($Title),
14953: $id.'.xlabel' => &escape($xlabel),
14954: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14955: $id.'.labels' => join(',',@$Xlabels),
14956: $id.'.PlotType' => 'XY',
14957: $id.'.NumSets' => 2,
1.137 matthew 14958: $id.'.two_axes' => 1,
14959: $id.'.y1_max_value' => $Max1,
14960: $id.'.y1_min_value' => $Min1,
14961: $id.'.y2_max_value' => $Max2,
14962: $id.'.y2_min_value' => $Min2,
1.136 matthew 14963: );
14964: #
1.137 matthew 14965: if (defined($colors) && ref($colors) eq 'ARRAY') {
14966: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14967: }
14968: #
14969: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14970: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14971: return '';
14972: }
14973: my $NumSets=1;
1.137 matthew 14974: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14975: next if (! ref($array));
14976: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14977: }
14978: #
14979: # Deal with other parameters
14980: while (my ($key,$value) = each(%Values)) {
14981: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14982: }
14983: #
1.646 raeburn 14984: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14985: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14986: }
14987:
14988: ############################################################
14989: ############################################################
14990:
14991: =pod
14992:
1.157 matthew 14993: =back
14994:
1.139 matthew 14995: =head1 Statistics helper routines?
14996:
14997: Bad place for them but what the hell.
14998:
1.157 matthew 14999: =over 4
15000:
1.648 raeburn 15001: =item * &chartlink()
1.139 matthew 15002:
15003: Returns a link to the chart for a specific student.
15004:
15005: Inputs:
15006:
15007: =over 4
15008:
15009: =item $linktext: The text of the link
15010:
15011: =item $sname: The students username
15012:
15013: =item $sdomain: The students domain
15014:
15015: =back
15016:
1.157 matthew 15017: =back
15018:
1.139 matthew 15019: =cut
15020:
15021: ############################################################
15022: ############################################################
15023: sub chartlink {
15024: my ($linktext, $sname, $sdomain) = @_;
15025: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 15026: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 15027: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 15028: '">'.$linktext.'</a>';
1.153 matthew 15029: }
15030:
15031: #######################################################
15032: #######################################################
15033:
15034: =pod
15035:
15036: =head1 Course Environment Routines
1.157 matthew 15037:
15038: =over 4
1.153 matthew 15039:
1.648 raeburn 15040: =item * &restore_course_settings()
1.153 matthew 15041:
1.648 raeburn 15042: =item * &store_course_settings()
1.153 matthew 15043:
15044: Restores/Store indicated form parameters from the course environment.
15045: Will not overwrite existing values of the form parameters.
15046:
15047: Inputs:
15048: a scalar describing the data (e.g. 'chart', 'problem_analysis')
15049:
15050: a hash ref describing the data to be stored. For example:
15051:
15052: %Save_Parameters = ('Status' => 'scalar',
15053: 'chartoutputmode' => 'scalar',
15054: 'chartoutputdata' => 'scalar',
15055: 'Section' => 'array',
1.373 raeburn 15056: 'Group' => 'array',
1.153 matthew 15057: 'StudentData' => 'array',
15058: 'Maps' => 'array');
15059:
15060: Returns: both routines return nothing
15061:
1.631 raeburn 15062: =back
15063:
1.153 matthew 15064: =cut
15065:
15066: #######################################################
15067: #######################################################
15068: sub store_course_settings {
1.496 albertel 15069: return &store_settings($env{'request.course.id'},@_);
15070: }
15071:
15072: sub store_settings {
1.153 matthew 15073: # save to the environment
15074: # appenv the same items, just to be safe
1.300 albertel 15075: my $udom = $env{'user.domain'};
15076: my $uname = $env{'user.name'};
1.496 albertel 15077: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15078: my %SaveHash;
15079: my %AppHash;
15080: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 15081: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 15082: my $envname = 'environment.'.$basename;
1.258 albertel 15083: if (exists($env{'form.'.$setting})) {
1.153 matthew 15084: # Save this value away
15085: if ($type eq 'scalar' &&
1.258 albertel 15086: (! exists($env{$envname}) ||
15087: $env{$envname} ne $env{'form.'.$setting})) {
15088: $SaveHash{$basename} = $env{'form.'.$setting};
15089: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 15090: } elsif ($type eq 'array') {
15091: my $stored_form;
1.258 albertel 15092: if (ref($env{'form.'.$setting})) {
1.153 matthew 15093: $stored_form = join(',',
15094: map {
1.369 www 15095: &escape($_);
1.258 albertel 15096: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 15097: } else {
15098: $stored_form =
1.369 www 15099: &escape($env{'form.'.$setting});
1.153 matthew 15100: }
15101: # Determine if the array contents are the same.
1.258 albertel 15102: if ($stored_form ne $env{$envname}) {
1.153 matthew 15103: $SaveHash{$basename} = $stored_form;
15104: $AppHash{$envname} = $stored_form;
15105: }
15106: }
15107: }
15108: }
15109: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 15110: $udom,$uname);
1.153 matthew 15111: if ($put_result !~ /^(ok|delayed)/) {
15112: &Apache::lonnet::logthis('unable to save form parameters, '.
15113: 'got error:'.$put_result);
15114: }
15115: # Make sure these settings stick around in this session, too
1.646 raeburn 15116: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 15117: return;
15118: }
15119:
15120: sub restore_course_settings {
1.499 albertel 15121: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 15122: }
15123:
15124: sub restore_settings {
15125: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15126: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 15127: next if (exists($env{'form.'.$setting}));
1.496 albertel 15128: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 15129: '.'.$setting;
1.258 albertel 15130: if (exists($env{$envname})) {
1.153 matthew 15131: if ($type eq 'scalar') {
1.258 albertel 15132: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 15133: } elsif ($type eq 'array') {
1.258 albertel 15134: $env{'form.'.$setting} = [
1.153 matthew 15135: map {
1.369 www 15136: &unescape($_);
1.258 albertel 15137: } split(',',$env{$envname})
1.153 matthew 15138: ];
15139: }
15140: }
15141: }
1.127 matthew 15142: }
15143:
1.618 raeburn 15144: #######################################################
15145: #######################################################
15146:
15147: =pod
15148:
15149: =head1 Domain E-mail Routines
15150:
15151: =over 4
15152:
1.648 raeburn 15153: =item * &build_recipient_list()
1.618 raeburn 15154:
1.1075.2.44 raeburn 15155: Build recipient lists for following types of e-mail:
1.766 raeburn 15156: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 15157: (d) Help requests, (e) Course requests needing approval, (f) loncapa
15158: module change checking, student/employee ID conflict checks, as
15159: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
15160: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 15161:
15162: Inputs:
1.1075.2.44 raeburn 15163: defmail (scalar - email address of default recipient),
15164: mailing type (scalar: errormail, packagesmail, helpdeskmail,
15165: requestsmail, updatesmail, or idconflictsmail).
15166:
1.619 raeburn 15167: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 15168:
15169: origmail (scalar - email address of recipient from loncapa.conf,
15170: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 15171:
1.1075.2.139 raeburn 15172: $requname username of requester (if mailing type is helpdeskmail)
15173:
15174: $requdom domain of requester (if mailing type is helpdeskmail)
15175:
15176: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
15177:
1.655 raeburn 15178: Returns: comma separated list of addresses to which to send e-mail.
15179:
15180: =back
1.618 raeburn 15181:
15182: =cut
15183:
15184: ############################################################
15185: ############################################################
15186: sub build_recipient_list {
1.1075.2.139 raeburn 15187: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 15188: my @recipients;
1.1075.2.122 raeburn 15189: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 15190: my %domconfig =
1.1075.2.122 raeburn 15191: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 15192: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 15193: if (exists($domconfig{'contacts'}{$mailing})) {
15194: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
15195: my @contacts = ('adminemail','supportemail');
15196: foreach my $item (@contacts) {
15197: if ($domconfig{'contacts'}{$mailing}{$item}) {
15198: my $addr = $domconfig{'contacts'}{$item};
15199: if (!grep(/^\Q$addr\E$/,@recipients)) {
15200: push(@recipients,$addr);
15201: }
1.619 raeburn 15202: }
1.1075.2.122 raeburn 15203: }
15204: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
15205: if ($mailing eq 'helpdeskmail') {
15206: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
15207: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
15208: my @ok_bccs;
15209: foreach my $bcc (@bccs) {
15210: $bcc =~ s/^\s+//g;
15211: $bcc =~ s/\s+$//g;
15212: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15213: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15214: push(@ok_bccs,$bcc);
15215: }
15216: }
15217: }
15218: if (@ok_bccs > 0) {
15219: $allbcc = join(', ',@ok_bccs);
15220: }
15221: }
15222: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 15223: }
15224: }
1.766 raeburn 15225: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 15226: $lastresort = $origmail;
1.618 raeburn 15227: }
1.1075.2.139 raeburn 15228: if ($mailing eq 'helpdeskmail') {
15229: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
15230: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
15231: my ($inststatus,$inststatus_checked);
15232: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
15233: ($env{'user.domain'} ne 'public')) {
15234: $inststatus_checked = 1;
15235: $inststatus = $env{'environment.inststatus'};
15236: }
15237: unless ($inststatus_checked) {
15238: if (($requname ne '') && ($requdom ne '')) {
15239: if (($requname =~ /^$match_username$/) &&
15240: ($requdom =~ /^$match_domain$/) &&
15241: (&Apache::lonnet::domain($requdom))) {
15242: my $requhome = &Apache::lonnet::homeserver($requname,
15243: $requdom);
15244: unless ($requhome eq 'no_host') {
15245: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
15246: $inststatus = $userenv{'inststatus'};
15247: $inststatus_checked = 1;
15248: }
15249: }
15250: }
15251: }
15252: unless ($inststatus_checked) {
15253: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15254: my %srch = (srchby => 'email',
15255: srchdomain => $defdom,
15256: srchterm => $reqemail,
15257: srchtype => 'exact');
15258: my %srch_results = &Apache::lonnet::usersearch(\%srch);
15259: foreach my $uname (keys(%srch_results)) {
15260: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15261: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15262: $inststatus_checked = 1;
15263: last;
15264: }
15265: }
15266: unless ($inststatus_checked) {
15267: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15268: if ($dirsrchres eq 'ok') {
15269: foreach my $uname (keys(%srch_results)) {
15270: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15271: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15272: $inststatus_checked = 1;
15273: last;
15274: }
15275: }
15276: }
15277: }
15278: }
15279: }
15280: if ($inststatus ne '') {
15281: foreach my $status (split(/\:/,$inststatus)) {
15282: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15283: my @contacts = ('adminemail','supportemail');
15284: foreach my $item (@contacts) {
15285: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15286: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15287: if (!grep(/^\Q$addr\E$/,@recipients)) {
15288: push(@recipients,$addr);
15289: }
15290: }
15291: }
15292: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15293: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15294: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15295: my @ok_bccs;
15296: foreach my $bcc (@bccs) {
15297: $bcc =~ s/^\s+//g;
15298: $bcc =~ s/\s+$//g;
15299: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15300: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15301: push(@ok_bccs,$bcc);
15302: }
15303: }
15304: }
15305: if (@ok_bccs > 0) {
15306: $allbcc = join(', ',@ok_bccs);
15307: }
15308: }
15309: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15310: last;
15311: }
15312: }
15313: }
15314: }
15315: }
1.619 raeburn 15316: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 15317: $lastresort = $origmail;
15318: }
1.1075.2.128 raeburn 15319: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 15320: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15321: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15322: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15323: my %what = (
15324: perlvar => 1,
15325: );
15326: my $primary = &Apache::lonnet::domain($defdom,'primary');
15327: if ($primary) {
15328: my $gotaddr;
15329: my ($result,$returnhash) =
15330: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15331: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15332: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15333: $lastresort = $returnhash->{'lonSupportEMail'};
15334: $gotaddr = 1;
15335: }
15336: }
15337: unless ($gotaddr) {
15338: my $uintdom = &Apache::lonnet::internet_dom($primary);
15339: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15340: unless ($uintdom eq $intdom) {
15341: my %domconfig =
15342: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15343: if (ref($domconfig{'contacts'}) eq 'HASH') {
15344: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15345: my @contacts = ('adminemail','supportemail');
15346: foreach my $item (@contacts) {
15347: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15348: my $addr = $domconfig{'contacts'}{$item};
15349: if (!grep(/^\Q$addr\E$/,@recipients)) {
15350: push(@recipients,$addr);
15351: }
15352: }
15353: }
15354: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15355: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15356: }
15357: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15358: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15359: my @ok_bccs;
15360: foreach my $bcc (@bccs) {
15361: $bcc =~ s/^\s+//g;
15362: $bcc =~ s/\s+$//g;
15363: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15364: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15365: push(@ok_bccs,$bcc);
15366: }
15367: }
15368: }
15369: if (@ok_bccs > 0) {
15370: $allbcc = join(', ',@ok_bccs);
15371: }
15372: }
15373: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15374: }
15375: }
15376: }
15377: }
15378: }
15379: }
1.618 raeburn 15380: }
1.688 raeburn 15381: if (defined($defmail)) {
15382: if ($defmail ne '') {
15383: push(@recipients,$defmail);
15384: }
1.618 raeburn 15385: }
15386: if ($otheremails) {
1.619 raeburn 15387: my @others;
15388: if ($otheremails =~ /,/) {
15389: @others = split(/,/,$otheremails);
1.618 raeburn 15390: } else {
1.619 raeburn 15391: push(@others,$otheremails);
15392: }
15393: foreach my $addr (@others) {
15394: if (!grep(/^\Q$addr\E$/,@recipients)) {
15395: push(@recipients,$addr);
15396: }
1.618 raeburn 15397: }
15398: }
1.1075.2.128 raeburn 15399: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 15400: if ((!@recipients) && ($lastresort ne '')) {
15401: push(@recipients,$lastresort);
15402: }
15403: } elsif ($lastresort ne '') {
15404: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15405: push(@recipients,$lastresort);
15406: }
15407: }
15408: my $recipientlist = join(',',@recipients);
15409: if (wantarray) {
15410: return ($recipientlist,$allbcc,$addtext);
15411: } else {
15412: return $recipientlist;
15413: }
1.618 raeburn 15414: }
15415:
1.127 matthew 15416: ############################################################
15417: ############################################################
1.154 albertel 15418:
1.655 raeburn 15419: =pod
15420:
15421: =head1 Course Catalog Routines
15422:
15423: =over 4
15424:
15425: =item * &gather_categories()
15426:
15427: Converts category definitions - keys of categories hash stored in
15428: coursecategories in configuration.db on the primary library server in a
15429: domain - to an array. Also generates javascript and idx hash used to
15430: generate Domain Coordinator interface for editing Course Categories.
15431:
15432: Inputs:
1.663 raeburn 15433:
1.655 raeburn 15434: categories (reference to hash of category definitions).
1.663 raeburn 15435:
1.655 raeburn 15436: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15437: categories and subcategories).
1.663 raeburn 15438:
1.655 raeburn 15439: idx (reference to hash of counters used in Domain Coordinator interface for
15440: editing Course Categories).
1.663 raeburn 15441:
1.655 raeburn 15442: jsarray (reference to array of categories used to create Javascript arrays for
15443: Domain Coordinator interface for editing Course Categories).
15444:
15445: Returns: nothing
15446:
15447: Side effects: populates cats, idx and jsarray.
15448:
15449: =cut
15450:
15451: sub gather_categories {
15452: my ($categories,$cats,$idx,$jsarray) = @_;
15453: my %counters;
15454: my $num = 0;
15455: foreach my $item (keys(%{$categories})) {
15456: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15457: if ($container eq '' && $depth == 0) {
15458: $cats->[$depth][$categories->{$item}] = $cat;
15459: } else {
15460: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15461: }
15462: my ($escitem,$tail) = split(/:/,$item,2);
15463: if ($counters{$tail} eq '') {
15464: $counters{$tail} = $num;
15465: $num ++;
15466: }
15467: if (ref($idx) eq 'HASH') {
15468: $idx->{$item} = $counters{$tail};
15469: }
15470: if (ref($jsarray) eq 'ARRAY') {
15471: push(@{$jsarray->[$counters{$tail}]},$item);
15472: }
15473: }
15474: return;
15475: }
15476:
15477: =pod
15478:
15479: =item * &extract_categories()
15480:
15481: Used to generate breadcrumb trails for course categories.
15482:
15483: Inputs:
1.663 raeburn 15484:
1.655 raeburn 15485: categories (reference to hash of category definitions).
1.663 raeburn 15486:
1.655 raeburn 15487: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15488: categories and subcategories).
1.663 raeburn 15489:
1.655 raeburn 15490: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15491:
1.655 raeburn 15492: allitems (reference to hash - key is category key
15493: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15494:
1.655 raeburn 15495: idx (reference to hash of counters used in Domain Coordinator interface for
15496: editing Course Categories).
1.663 raeburn 15497:
1.655 raeburn 15498: jsarray (reference to array of categories used to create Javascript arrays for
15499: Domain Coordinator interface for editing Course Categories).
15500:
1.665 raeburn 15501: subcats (reference to hash of arrays containing all subcategories within each
15502: category, -recursive)
15503:
1.1075.2.132 raeburn 15504: maxd (reference to hash used to hold max depth for all top-level categories).
15505:
1.655 raeburn 15506: Returns: nothing
15507:
15508: Side effects: populates trails and allitems hash references.
15509:
15510: =cut
15511:
15512: sub extract_categories {
1.1075.2.132 raeburn 15513: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 15514: if (ref($categories) eq 'HASH') {
15515: &gather_categories($categories,$cats,$idx,$jsarray);
15516: if (ref($cats->[0]) eq 'ARRAY') {
15517: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15518: my $name = $cats->[0][$i];
15519: my $item = &escape($name).'::0';
15520: my $trailstr;
15521: if ($name eq 'instcode') {
15522: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15523: } elsif ($name eq 'communities') {
15524: $trailstr = &mt('Communities');
1.655 raeburn 15525: } else {
15526: $trailstr = $name;
15527: }
15528: if ($allitems->{$item} eq '') {
15529: push(@{$trails},$trailstr);
15530: $allitems->{$item} = scalar(@{$trails})-1;
15531: }
15532: my @parents = ($name);
15533: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15534: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15535: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15536: if (ref($subcats) eq 'HASH') {
15537: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15538: }
1.1075.2.132 raeburn 15539: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 15540: }
15541: } else {
15542: if (ref($subcats) eq 'HASH') {
15543: $subcats->{$item} = [];
1.655 raeburn 15544: }
1.1075.2.132 raeburn 15545: if (ref($maxd) eq 'HASH') {
15546: $maxd->{$name} = 1;
15547: }
1.655 raeburn 15548: }
15549: }
15550: }
15551: }
15552: return;
15553: }
15554:
15555: =pod
15556:
1.1075.2.56 raeburn 15557: =item * &recurse_categories()
1.655 raeburn 15558:
15559: Recursively used to generate breadcrumb trails for course categories.
15560:
15561: Inputs:
1.663 raeburn 15562:
1.655 raeburn 15563: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15564: categories and subcategories).
1.663 raeburn 15565:
1.655 raeburn 15566: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15567:
15568: category (current course category, for which breadcrumb trail is being generated).
15569:
15570: trails (reference to array of breadcrumb trails for each category).
15571:
1.655 raeburn 15572: allitems (reference to hash - key is category key
15573: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15574:
1.655 raeburn 15575: parents (array containing containers directories for current category,
15576: back to top level).
15577:
15578: Returns: nothing
15579:
15580: Side effects: populates trails and allitems hash references
15581:
15582: =cut
15583:
15584: sub recurse_categories {
1.1075.2.132 raeburn 15585: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 15586: my $shallower = $depth - 1;
15587: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
15588: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
15589: my $name = $cats->[$depth]{$category}[$k];
15590: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.161. .4(raebu 15591:22): my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15592: if ($allitems->{$item} eq '') {
15593: push(@{$trails},$trailstr);
15594: $allitems->{$item} = scalar(@{$trails})-1;
15595: }
15596: my $deeper = $depth+1;
15597: push(@{$parents},$category);
1.665 raeburn 15598: if (ref($subcats) eq 'HASH') {
15599: my $subcat = &escape($name).':'.$category.':'.$depth;
15600: for (my $j=@{$parents}; $j>=0; $j--) {
15601: my $higher;
15602: if ($j > 0) {
15603: $higher = &escape($parents->[$j]).':'.
15604: &escape($parents->[$j-1]).':'.$j;
15605: } else {
15606: $higher = &escape($parents->[$j]).'::'.$j;
15607: }
15608: push(@{$subcats->{$higher}},$subcat);
15609: }
15610: }
15611: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 15612: $subcats,$maxd);
1.655 raeburn 15613: pop(@{$parents});
15614: }
15615: } else {
15616: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 15617: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15618: if ($allitems->{$item} eq '') {
15619: push(@{$trails},$trailstr);
15620: $allitems->{$item} = scalar(@{$trails})-1;
15621: }
1.1075.2.132 raeburn 15622: if (ref($maxd) eq 'HASH') {
15623: if ($depth > $maxd->{$parents->[0]}) {
15624: $maxd->{$parents->[0]} = $depth;
15625: }
15626: }
1.655 raeburn 15627: }
15628: return;
15629: }
15630:
1.663 raeburn 15631: =pod
15632:
1.1075.2.56 raeburn 15633: =item * &assign_categories_table()
1.663 raeburn 15634:
15635: Create a datatable for display of hierarchical categories in a domain,
15636: with checkboxes to allow a course to be categorized.
15637:
15638: Inputs:
15639:
15640: cathash - reference to hash of categories defined for the domain (from
15641: configuration.db)
15642:
15643: currcat - scalar with an & separated list of categories assigned to a course.
15644:
1.919 raeburn 15645: type - scalar contains course type (Course or Community).
15646:
1.1075.2.117 raeburn 15647: disabled - scalar (optional) contains disabled="disabled" if input elements are
15648: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15649:
1.663 raeburn 15650: Returns: $output (markup to be displayed)
15651:
15652: =cut
15653:
15654: sub assign_categories_table {
1.1075.2.117 raeburn 15655: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15656: my $output;
15657: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 15658: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
15659: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 15660: $maxdepth = scalar(@cats);
15661: if (@cats > 0) {
15662: my $itemcount = 0;
15663: if (ref($cats[0]) eq 'ARRAY') {
15664: my @currcategories;
15665: if ($currcat ne '') {
15666: @currcategories = split('&',$currcat);
15667: }
1.919 raeburn 15668: my $table;
1.663 raeburn 15669: for (my $i=0; $i<@{$cats[0]}; $i++) {
15670: my $parent = $cats[0][$i];
1.919 raeburn 15671: next if ($parent eq 'instcode');
15672: if ($type eq 'Community') {
15673: next unless ($parent eq 'communities');
15674: } else {
15675: next if ($parent eq 'communities');
15676: }
1.663 raeburn 15677: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15678: my $item = &escape($parent).'::0';
15679: my $checked = '';
15680: if (@currcategories > 0) {
15681: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15682: $checked = ' checked="checked"';
1.663 raeburn 15683: }
15684: }
1.919 raeburn 15685: my $parent_title = $parent;
15686: if ($parent eq 'communities') {
15687: $parent_title = &mt('Communities');
15688: }
15689: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15690: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 15691: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15692: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15693: my $depth = 1;
15694: push(@path,$parent);
1.1075.2.117 raeburn 15695: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15696: pop(@path);
1.919 raeburn 15697: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15698: $itemcount ++;
15699: }
1.919 raeburn 15700: if ($itemcount) {
15701: $output = &Apache::loncommon::start_data_table().
15702: $table.
15703: &Apache::loncommon::end_data_table();
15704: }
1.663 raeburn 15705: }
15706: }
15707: }
15708: return $output;
15709: }
15710:
15711: =pod
15712:
1.1075.2.56 raeburn 15713: =item * &assign_category_rows()
1.663 raeburn 15714:
15715: Create a datatable row for display of nested categories in a domain,
15716: with checkboxes to allow a course to be categorized,called recursively.
15717:
15718: Inputs:
15719:
15720: itemcount - track row number for alternating colors
15721:
15722: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15723: categories and subcategories.
15724:
15725: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15726:
15727: parent - parent of current category item
15728:
15729: path - Array containing all categories back up through the hierarchy from the
15730: current category to the top level.
15731:
15732: currcategories - reference to array of current categories assigned to the course
15733:
1.1075.2.117 raeburn 15734: disabled - scalar (optional) contains disabled="disabled" if input elements are
15735: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15736:
1.663 raeburn 15737: Returns: $output (markup to be displayed).
15738:
15739: =cut
15740:
15741: sub assign_category_rows {
1.1075.2.117 raeburn 15742: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15743: my ($text,$name,$item,$chgstr);
15744: if (ref($cats) eq 'ARRAY') {
15745: my $maxdepth = scalar(@{$cats});
15746: if (ref($cats->[$depth]) eq 'HASH') {
15747: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15748: my $numchildren = @{$cats->[$depth]{$parent}};
15749: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 15750: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15751: for (my $j=0; $j<$numchildren; $j++) {
15752: $name = $cats->[$depth]{$parent}[$j];
15753: $item = &escape($name).':'.&escape($parent).':'.$depth;
15754: my $deeper = $depth+1;
15755: my $checked = '';
15756: if (ref($currcategories) eq 'ARRAY') {
15757: if (@{$currcategories} > 0) {
15758: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15759: $checked = ' checked="checked"';
1.663 raeburn 15760: }
15761: }
15762: }
1.664 raeburn 15763: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15764: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 15765: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15766: '<input type="hidden" name="catname" value="'.$name.'" />'.
15767: '</td><td>';
1.663 raeburn 15768: if (ref($path) eq 'ARRAY') {
15769: push(@{$path},$name);
1.1075.2.117 raeburn 15770: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15771: pop(@{$path});
15772: }
15773: $text .= '</td></tr>';
15774: }
15775: $text .= '</table></td>';
15776: }
15777: }
15778: }
15779: return $text;
15780: }
15781:
1.1075.2.69 raeburn 15782: =pod
15783:
15784: =back
15785:
15786: =cut
15787:
1.655 raeburn 15788: ############################################################
15789: ############################################################
15790:
15791:
1.443 albertel 15792: sub commit_customrole {
1.664 raeburn 15793: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15794: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15795: ($start?', '.&mt('starting').' '.localtime($start):'').
15796: ($end?', ending '.localtime($end):'').': <b>'.
15797: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15798: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15799: '</b><br />';
15800: return $output;
15801: }
15802:
15803: sub commit_standardrole {
1.1075.2.31 raeburn 15804: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15805: my ($output,$logmsg,$linefeed);
15806: if ($context eq 'auto') {
15807: $linefeed = "\n";
15808: } else {
15809: $linefeed = "<br />\n";
15810: }
1.443 albertel 15811: if ($three eq 'st') {
1.541 raeburn 15812: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 15813: $one,$two,$sec,$context,$credits);
1.541 raeburn 15814: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15815: ($result eq 'unknown_course') || ($result eq 'refused')) {
15816: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15817: } else {
1.541 raeburn 15818: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15819: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15820: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15821: if ($context eq 'auto') {
15822: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15823: } else {
15824: $output .= '<b>'.$result.'</b>'.$linefeed.
15825: &mt('Add to classlist').': <b>ok</b>';
15826: }
15827: $output .= $linefeed;
1.443 albertel 15828: }
15829: } else {
15830: $output = &mt('Assigning').' '.$three.' in '.$url.
15831: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15832: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15833: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15834: if ($context eq 'auto') {
15835: $output .= $result.$linefeed;
15836: } else {
15837: $output .= '<b>'.$result.'</b>'.$linefeed;
15838: }
1.443 albertel 15839: }
15840: return $output;
15841: }
15842:
15843: sub commit_studentrole {
1.1075.2.31 raeburn 15844: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15845: $credits) = @_;
1.626 raeburn 15846: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15847: if ($context eq 'auto') {
15848: $linefeed = "\n";
15849: } else {
15850: $linefeed = '<br />'."\n";
15851: }
1.443 albertel 15852: if (defined($one) && defined($two)) {
15853: my $cid=$one.'_'.$two;
15854: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15855: my $secchange = 0;
15856: my $expire_role_result;
15857: my $modify_section_result;
1.628 raeburn 15858: if ($oldsec ne '-1') {
15859: if ($oldsec ne $sec) {
1.443 albertel 15860: $secchange = 1;
1.628 raeburn 15861: my $now = time;
1.443 albertel 15862: my $uurl='/'.$cid;
15863: $uurl=~s/\_/\//g;
15864: if ($oldsec) {
15865: $uurl.='/'.$oldsec;
15866: }
1.626 raeburn 15867: $oldsecurl = $uurl;
1.628 raeburn 15868: $expire_role_result =
1.1075.2.161. .14(raeb 15869:-23): &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','','',$context);
1.628 raeburn 15870: if ($env{'request.course.sec'} ne '') {
15871: if ($expire_role_result eq 'refused') {
15872: my @roles = ('st');
15873: my @statuses = ('previous');
15874: my @roledoms = ($one);
15875: my $withsec = 1;
15876: my %roleshash =
15877: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15878: \@statuses,\@roles,\@roledoms,$withsec);
15879: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15880: my ($oldstart,$oldend) =
15881: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15882: if ($oldend > 0 && $oldend <= $now) {
15883: $expire_role_result = 'ok';
15884: }
15885: }
15886: }
15887: }
1.443 albertel 15888: $result = $expire_role_result;
15889: }
15890: }
15891: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 15892: $modify_section_result =
15893: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15894: undef,undef,undef,$sec,
15895: $end,$start,'','',$cid,
15896: '',$context,$credits);
1.443 albertel 15897: if ($modify_section_result =~ /^ok/) {
15898: if ($secchange == 1) {
1.628 raeburn 15899: if ($sec eq '') {
15900: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15901: } else {
15902: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15903: }
1.443 albertel 15904: } elsif ($oldsec eq '-1') {
1.628 raeburn 15905: if ($sec eq '') {
15906: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15907: } else {
15908: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15909: }
1.443 albertel 15910: } else {
1.628 raeburn 15911: if ($sec eq '') {
15912: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15913: } else {
15914: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15915: }
1.443 albertel 15916: }
15917: } else {
1.628 raeburn 15918: if ($secchange) {
15919: $$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;
15920: } else {
15921: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15922: }
1.443 albertel 15923: }
15924: $result = $modify_section_result;
15925: } elsif ($secchange == 1) {
1.628 raeburn 15926: if ($oldsec eq '') {
1.1075.2.20 raeburn 15927: $$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 15928: } else {
15929: $$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;
15930: }
1.626 raeburn 15931: if ($expire_role_result eq 'refused') {
15932: my $newsecurl = '/'.$cid;
15933: $newsecurl =~ s/\_/\//g;
15934: if ($sec ne '') {
15935: $newsecurl.='/'.$sec;
15936: }
15937: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15938: if ($sec eq '') {
15939: $$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;
15940: } else {
15941: $$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;
15942: }
15943: }
15944: }
1.443 albertel 15945: }
15946: } else {
1.626 raeburn 15947: $$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 15948: $result = "error: incomplete course id\n";
15949: }
15950: return $result;
15951: }
15952:
1.1075.2.25 raeburn 15953: sub show_role_extent {
15954: my ($scope,$context,$role) = @_;
15955: $scope =~ s{^/}{};
15956: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15957: push(@courseroles,'co');
15958: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15959: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15960: $scope =~ s{/}{_};
15961: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15962: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15963: my ($audom,$auname) = split(/\//,$scope);
15964: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15965: &Apache::loncommon::plainname($auname,$audom).'</span>');
15966: } else {
15967: $scope =~ s{/$}{};
15968: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15969: &Apache::lonnet::domain($scope,'description').'</span>');
15970: }
15971: }
15972:
1.443 albertel 15973: ############################################################
15974: ############################################################
15975:
1.566 albertel 15976: sub check_clone {
1.578 raeburn 15977: my ($args,$linefeed) = @_;
1.566 albertel 15978: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15979: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15980: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1075.2.161. .1(raebu 15981:21): my $clonetitle;
15982:21): my @clonemsg;
1.566 albertel 15983: my $can_clone = 0;
1.944 raeburn 15984: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15985: if ($lctype ne 'community') {
15986: $lctype = 'course';
15987: }
1.566 albertel 15988: if ($clonehome eq 'no_host') {
1.944 raeburn 15989: if ($args->{'crstype'} eq 'Community') {
1.1075.2.161. .1(raebu 15990:21): push(@clonemsg,({
15991:21): mt => 'No new community created.',
15992:21): args => [],
15993:21): },
15994:21): {
15995:21): mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
15996:21): args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
15997:21): }));
1.908 raeburn 15998: } else {
1.1075.2.161. .1(raebu 15999:21): push(@clonemsg,({
16000:21): mt => 'No new course created.',
16001:21): args => [],
16002:21): },
16003:21): {
16004:21): mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
16005:21): args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16006:21): }));
16007:21): }
1.566 albertel 16008: } else {
16009: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1075.2.161. .1(raebu 16010:21): $clonetitle = $clonedesc{'description'};
1.944 raeburn 16011: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 16012: if ($clonedesc{'type'} ne 'Community') {
1.1075.2.161. .1(raebu 16013:21): push(@clonemsg,({
16014:21): mt => 'No new community created.',
16015:21): args => [],
16016:21): },
16017:21): {
16018:21): mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
16019:21): args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16020:21): }));
16021:21): return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 16022: }
16023: }
1.1075.2.119 raeburn 16024: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 16025: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 16026: $can_clone = 1;
16027: } else {
1.1075.2.95 raeburn 16028: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 16029: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 16030: if ($clonehash{'cloners'} eq '') {
16031: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
16032: if ($domdefs{'canclone'}) {
16033: unless ($domdefs{'canclone'} eq 'none') {
16034: if ($domdefs{'canclone'} eq 'domain') {
16035: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
16036: $can_clone = 1;
16037: }
16038: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16039: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
16040: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
16041: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
16042: $can_clone = 1;
16043: }
16044: }
16045: }
1.908 raeburn 16046: }
1.1075.2.95 raeburn 16047: } else {
16048: my @cloners = split(/,/,$clonehash{'cloners'});
16049: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 16050: $can_clone = 1;
1.1075.2.95 raeburn 16051: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 16052: $can_clone = 1;
1.1075.2.96 raeburn 16053: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
16054: $can_clone = 1;
1.1075.2.95 raeburn 16055: }
16056: unless ($can_clone) {
1.1075.2.96 raeburn 16057: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16058: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 16059: my (%gotdomdefaults,%gotcodedefaults);
16060: foreach my $cloner (@cloners) {
16061: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
16062: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
16063: my (%codedefaults,@code_order);
16064: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
16065: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
16066: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
16067: }
16068: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
16069: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
16070: }
16071: } else {
16072: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
16073: \%codedefaults,
16074: \@code_order);
16075: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
16076: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
16077: }
16078: if (@code_order > 0) {
16079: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
16080: $cloner,$clonehash{'internal.coursecode'},
16081: $args->{'crscode'})) {
16082: $can_clone = 1;
16083: last;
16084: }
16085: }
16086: }
16087: }
16088: }
1.1075.2.96 raeburn 16089: }
16090: }
16091: unless ($can_clone) {
16092: my $ccrole = 'cc';
16093: if ($args->{'crstype'} eq 'Community') {
16094: $ccrole = 'co';
16095: }
16096: my %roleshash =
16097: &Apache::lonnet::get_my_roles($args->{'ccuname'},
16098: $args->{'ccdomain'},
16099: 'userroles',['active'],[$ccrole],
16100: [$args->{'clonedomain'}]);
16101: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
16102: $can_clone = 1;
16103: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
16104: $args->{'ccuname'},$args->{'ccdomain'})) {
16105: $can_clone = 1;
1.1075.2.95 raeburn 16106: }
16107: }
16108: unless ($can_clone) {
16109: if ($args->{'crstype'} eq 'Community') {
1.1075.2.161. .1(raebu 16110:21): push(@clonemsg,({
16111:21): mt => 'No new community created.',
16112:21): args => [],
16113:21): },
16114:21): {
16115: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]).',
16116:21): args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16117:21): }));
1.1075.2.95 raeburn 16118: } else {
1.1075.2.161. .1(raebu 16119:21): push(@clonemsg,({
16120:21): mt => 'No new course created.',
16121:21): args => [],
16122:21): },
16123:21): {
16124: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]).',
16125:21): args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16126:21): }));
1.578 raeburn 16127: }
1.566 albertel 16128: }
1.578 raeburn 16129: }
1.566 albertel 16130: }
1.1075.2.161. .1(raebu 16131:21): return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16132: }
16133:
1.444 albertel 16134: sub construct_course {
1.1075.2.119 raeburn 16135: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1075.2.161. .1(raebu 16136:21): $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
16137:21): my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 16138: my $linefeed = '<br />'."\n";
16139: if ($context eq 'auto') {
16140: $linefeed = "\n";
16141: }
1.566 albertel 16142:
16143: #
16144: # Are we cloning?
16145: #
1.1075.2.161. .1(raebu 16146:21): my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16147: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1075.2.161. .1(raebu 16148:21): ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 16149: if (!$can_clone) {
1.1075.2.161. .1(raebu 16150:21): return (0,$outcome,$clonemsgref);
1.566 albertel 16151: }
16152: }
16153:
1.444 albertel 16154: #
16155: # Open course
16156: #
16157: my $crstype = lc($args->{'crstype'});
16158: my %cenv=();
16159: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
16160: $args->{'cdescr'},
16161: $args->{'curl'},
16162: $args->{'course_home'},
16163: $args->{'nonstandard'},
16164: $args->{'crscode'},
16165: $args->{'ccuname'}.':'.
16166: $args->{'ccdomain'},
1.882 raeburn 16167: $args->{'crstype'},
1.1075.2.161. .1(raebu 16168:21): $cnum,$context,$category,
16169:21): $callercontext);
1.444 albertel 16170:
16171: # Note: The testing routines depend on this being output; see
16172: # Utils::Course. This needs to at least be output as a comment
16173: # if anyone ever decides to not show this, and Utils::Course::new
16174: # will need to be suitably modified.
1.1075.2.161. .1(raebu 16175:21): if (($callercontext eq 'auto') && ($user_lh ne '')) {
16176:21): $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
16177:21): } else {
16178:21): $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
16179:21): }
1.943 raeburn 16180: if ($$courseid =~ /^error:/) {
1.1075.2.161. .1(raebu 16181:21): return (0,$outcome,$clonemsgref);
1.943 raeburn 16182: }
16183:
1.444 albertel 16184: #
16185: # Check if created correctly
16186: #
1.479 albertel 16187: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 16188: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 16189: if ($crsuhome eq 'no_host') {
1.1075.2.161. .1(raebu 16190:21): if (($callercontext eq 'auto') && ($user_lh ne '')) {
16191:21): $outcome .= &mt_user($user_lh,
16192:21): 'Course creation failed, unrecognized course home server.');
16193:21): } else {
16194:21): $outcome .= &mt('Course creation failed, unrecognized course home server.');
16195:21): }
16196:21): $outcome .= $linefeed;
16197:21): return (0,$outcome,$clonemsgref);
1.943 raeburn 16198: }
1.541 raeburn 16199: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 16200:
1.444 albertel 16201: #
1.566 albertel 16202: # Do the cloning
1.1075.2.161. .1(raebu 16203:21): #
16204:21): my @clonemsg;
1.566 albertel 16205: if ($can_clone && $cloneid) {
1.1075.2.161. .1(raebu 16206:21): push(@clonemsg,
16207:21): {
16208:21): mt => 'Created [_1] by cloning from [_2]',
16209:21): args => [$crstype,$clonetitle],
16210:21): });
1.566 albertel 16211: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 16212: # Copy all files
1.1075.2.161. .1(raebu 16213:21): my @info =
16214:21): &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
16215:21): $args->{'dateshift'},$args->{'crscode'},
16216:21): $args->{'ccuname'}.':'.$args->{'ccdomain'},
16217:21): $args->{'tinyurls'});
16218:21): if (@info) {
16219:21): push(@clonemsg,@info);
16220:21): }
1.444 albertel 16221: # Restore URL
1.566 albertel 16222: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16223: # Restore title
1.566 albertel 16224: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16225: # Restore creation date, creator and creation context.
16226: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16227: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16228: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16229: # Mark as cloned
1.566 albertel 16230: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16231: # Need to clone grading mode
16232: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16233: $cenv{'grading'}=$newenv{'grading'};
16234: # Do not clone these environment entries
16235: &Apache::lonnet::del('environment',
16236: ['default_enrollment_start_date',
16237: 'default_enrollment_end_date',
16238: 'question.email',
16239: 'policy.email',
16240: 'comment.email',
16241: 'pch.users.denied',
1.725 raeburn 16242: 'plc.users.denied',
16243: 'hidefromcat',
1.1075.2.36 raeburn 16244: 'checkforpriv',
1.1075.2.158 raeburn 16245: 'categories'],
1.638 www 16246: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 16247: if ($args->{'textbook'}) {
16248: $cenv{'internal.textbook'} = $args->{'textbook'};
16249: }
1.444 albertel 16250: }
1.566 albertel 16251:
1.444 albertel 16252: #
16253: # Set environment (will override cloned, if existing)
16254: #
16255: my @sections = ();
16256: my @xlists = ();
16257: if ($args->{'crstype'}) {
16258: $cenv{'type'}=$args->{'crstype'};
16259: }
1.1075.2.161. .17(raeb 16260:-23): if ($args->{'lti'}) {
16261:-23): $cenv{'internal.lti'}=$args->{'lti'};
16262:-23): }
1.444 albertel 16263: if ($args->{'crsid'}) {
16264: $cenv{'courseid'}=$args->{'crsid'};
16265: }
16266: if ($args->{'crscode'}) {
16267: $cenv{'internal.coursecode'}=$args->{'crscode'};
16268: }
16269: if ($args->{'crsquota'} ne '') {
16270: $cenv{'internal.coursequota'}=$args->{'crsquota'};
16271: } else {
16272: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
16273: }
16274: if ($args->{'ccuname'}) {
16275: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
16276: ':'.$args->{'ccdomain'};
16277: } else {
16278: $cenv{'internal.courseowner'} = $args->{'curruser'};
16279: }
1.1075.2.31 raeburn 16280: if ($args->{'defaultcredits'}) {
16281: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
16282: }
1.444 albertel 16283: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
16284: if ($args->{'crssections'}) {
16285: $cenv{'internal.sectionnums'} = '';
16286: if ($args->{'crssections'} =~ m/,/) {
16287: @sections = split/,/,$args->{'crssections'};
16288: } else {
16289: $sections[0] = $args->{'crssections'};
16290: }
16291: if (@sections > 0) {
16292: foreach my $item (@sections) {
16293: my ($sec,$gp) = split/:/,$item;
16294: my $class = $args->{'crscode'}.$sec;
16295: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16296: $cenv{'internal.sectionnums'} .= $item.',';
16297: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 16298: push(@badclasses,$class);
1.444 albertel 16299: }
16300: }
16301: $cenv{'internal.sectionnums'} =~ s/,$//;
16302: }
16303: }
16304: # do not hide course coordinator from staff listing,
16305: # even if privileged
16306: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 16307: # add course coordinator's domain to domains to check for privileged users
16308: # if different to course domain
16309: if ($$crsudom ne $args->{'ccdomain'}) {
16310: $cenv{'checkforpriv'} = $args->{'ccdomain'};
16311: }
1.444 albertel 16312: # add crosslistings
16313: if ($args->{'crsxlist'}) {
16314: $cenv{'internal.crosslistings'}='';
16315: if ($args->{'crsxlist'} =~ m/,/) {
16316: @xlists = split/,/,$args->{'crsxlist'};
16317: } else {
16318: $xlists[0] = $args->{'crsxlist'};
16319: }
16320: if (@xlists > 0) {
16321: foreach my $item (@xlists) {
16322: my ($xl,$gp) = split/:/,$item;
16323: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
16324: $cenv{'internal.crosslistings'} .= $item.',';
16325: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 16326: push(@badclasses,$xl);
1.444 albertel 16327: }
16328: }
16329: $cenv{'internal.crosslistings'} =~ s/,$//;
16330: }
16331: }
16332: if ($args->{'autoadds'}) {
16333: $cenv{'internal.autoadds'}=$args->{'autoadds'};
16334: }
16335: if ($args->{'autodrops'}) {
16336: $cenv{'internal.autodrops'}=$args->{'autodrops'};
16337: }
16338: # check for notification of enrollment changes
16339: my @notified = ();
16340: if ($args->{'notify_owner'}) {
16341: if ($args->{'ccuname'} ne '') {
16342: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
16343: }
16344: }
16345: if ($args->{'notify_dc'}) {
16346: if ($uname ne '') {
1.630 raeburn 16347: push(@notified,$uname.':'.$udom);
1.444 albertel 16348: }
16349: }
16350: if (@notified > 0) {
16351: my $notifylist;
16352: if (@notified > 1) {
16353: $notifylist = join(',',@notified);
16354: } else {
16355: $notifylist = $notified[0];
16356: }
16357: $cenv{'internal.notifylist'} = $notifylist;
16358: }
16359: if (@badclasses > 0) {
16360: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 16361: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16362: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16363: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16364: );
1.1075.2.119 raeburn 16365: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16366: &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 16367: if ($context eq 'auto') {
16368: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 16369: } else {
1.566 albertel 16370: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 16371: }
16372: foreach my $item (@badclasses) {
1.541 raeburn 16373: if ($context eq 'auto') {
1.1075.2.119 raeburn 16374: $outcome .= " - $item\n";
1.541 raeburn 16375: } else {
1.1075.2.119 raeburn 16376: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16377: }
1.1075.2.119 raeburn 16378: }
16379: if ($context eq 'auto') {
16380: $outcome .= $linefeed;
16381: } else {
16382: $outcome .= "</ul><br /><br /></div>\n";
16383: }
1.444 albertel 16384: }
16385: if ($args->{'no_end_date'}) {
16386: $args->{'endaccess'} = 0;
16387: }
16388: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16389: $cenv{'internal.autoend'}=$args->{'enrollend'};
16390: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16391: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16392: if ($args->{'showphotos'}) {
16393: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16394: }
16395: $cenv{'internal.authtype'} = $args->{'authtype'};
16396: $cenv{'internal.autharg'} = $args->{'autharg'};
16397: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16398: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16399: 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');
16400: if ($context eq 'auto') {
16401: $outcome .= $krb_msg;
16402: } else {
1.566 albertel 16403: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16404: }
16405: $outcome .= $linefeed;
1.444 albertel 16406: }
16407: }
16408: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16409: if ($args->{'setpolicy'}) {
16410: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16411: }
16412: if ($args->{'setcontent'}) {
16413: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16414: }
1.1075.2.110 raeburn 16415: if ($args->{'setcomment'}) {
16416: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16417: }
1.444 albertel 16418: }
16419: if ($args->{'reshome'}) {
16420: $cenv{'reshome'}=$args->{'reshome'}.'/';
16421: $cenv{'reshome'}=~s/\/+$/\//;
16422: }
16423: #
16424: # course has keyed access
16425: #
16426: if ($args->{'setkeys'}) {
16427: $cenv{'keyaccess'}='yes';
16428: }
16429: # if specified, key authority is not course, but user
16430: # only active if keyaccess is yes
16431: if ($args->{'keyauth'}) {
1.487 albertel 16432: my ($user,$domain) = split(':',$args->{'keyauth'});
16433: $user = &LONCAPA::clean_username($user);
16434: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16435: if ($user ne '' && $domain ne '') {
1.487 albertel 16436: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16437: }
16438: }
16439:
1.1075.2.59 raeburn 16440: #
16441: # generate and store uniquecode (available to course requester), if course should have one.
16442: #
16443: if ($args->{'uniquecode'}) {
16444: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16445: if ($code) {
16446: $cenv{'internal.uniquecode'} = $code;
16447: my %crsinfo =
16448: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16449: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16450: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16451: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16452: }
16453: if (ref($coderef)) {
16454: $$coderef = $code;
16455: }
16456: }
16457: }
16458:
1.444 albertel 16459: if ($args->{'disresdis'}) {
16460: $cenv{'pch.roles.denied'}='st';
16461: }
16462: if ($args->{'disablechat'}) {
16463: $cenv{'plc.roles.denied'}='st';
16464: }
16465:
16466: # Record we've not yet viewed the Course Initialization Helper for this
16467: # course
16468: $cenv{'course.helper.not.run'} = 1;
16469: #
16470: # Use new Randomseed
16471: #
16472: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16473: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16474: #
16475: # The encryption code and receipt prefix for this course
16476: #
16477: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16478: $cenv{'internal.encpref'}=100+int(9*rand(99));
16479: #
16480: # By default, use standard grading
16481: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16482:
1.541 raeburn 16483: $outcome .= $linefeed.&mt('Setting environment').': '.
16484: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16485: #
16486: # Open all assignments
16487: #
16488: if ($args->{'openall'}) {
1.1075.2.146 raeburn 16489: my $opendate = time;
16490: if ($args->{'openallfrom'} =~ /^\d+$/) {
16491: $opendate = $args->{'openallfrom'};
16492: }
1.444 albertel 16493: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1075.2.146 raeburn 16494: my %storecontent = ($storeunder => $opendate,
1.444 albertel 16495: $storeunder.'.type' => 'date_start');
1.1075.2.146 raeburn 16496: $outcome .= &mt('All assignments open starting [_1]',
16497: &Apache::lonlocal::locallocaltime($opendate)).': '.
16498: &Apache::lonnet::cput
16499: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16500: }
16501: #
16502: # Set first page
16503: #
16504: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16505: || ($cloneid)) {
16506: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16507:
16508: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16509: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16510:
1.444 albertel 16511: $outcome .= ($fatal?$errtext:'read ok').' - ';
16512: my $title; my $url;
16513: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16514: $title=&mt('Syllabus');
1.444 albertel 16515: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16516: } else {
1.963 raeburn 16517: $title=&mt('Table of Contents');
1.444 albertel 16518: $url='/adm/navmaps';
16519: }
1.445 albertel 16520:
16521: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16522: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16523:
16524: if ($errtext) { $fatal=2; }
1.541 raeburn 16525: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16526: }
1.566 albertel 16527:
1.1075.2.161. .1(raebu 16528:21): return (1,$outcome,\@clonemsg);
1.444 albertel 16529: }
16530:
1.1075.2.59 raeburn 16531: sub make_unique_code {
16532: my ($cdom,$cnum) = @_;
16533: # get lock on uniquecodes db
16534: my $lockhash = {
16535: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16536: ':'.$env{'user.domain'},
16537: };
16538: my $tries = 0;
16539: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16540: my ($code,$error);
16541:
16542: while (($gotlock ne 'ok') && ($tries<3)) {
16543: $tries ++;
16544: sleep 1;
16545: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16546: }
16547: if ($gotlock eq 'ok') {
16548: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
16549: my $gotcode;
16550: my $attempts = 0;
16551: while ((!$gotcode) && ($attempts < 100)) {
16552: $code = &generate_code();
16553: if (!exists($currcodes{$code})) {
16554: $gotcode = 1;
16555: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
16556: $error = 'nostore';
16557: }
16558: }
16559: $attempts ++;
16560: }
16561: my @del_lock = ($cnum."\0".'uniquecodes');
16562: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
16563: } else {
16564: $error = 'nolock';
16565: }
16566: return ($code,$error);
16567: }
16568:
16569: sub generate_code {
16570: my $code;
16571: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
16572: for (my $i=0; $i<6; $i++) {
16573: my $lettnum = int (rand 2);
16574: my $item = '';
16575: if ($lettnum) {
16576: $item = $letts[int( rand(18) )];
16577: } else {
16578: $item = 1+int( rand(8) );
16579: }
16580: $code .= $item;
16581: }
16582: return $code;
16583: }
16584:
1.444 albertel 16585: ############################################################
16586: ############################################################
16587:
1.953 droeschl 16588: #SD
16589: # only Community and Course, or anything else?
1.378 raeburn 16590: sub course_type {
16591: my ($cid) = @_;
16592: if (!defined($cid)) {
16593: $cid = $env{'request.course.id'};
16594: }
1.404 albertel 16595: if (defined($env{'course.'.$cid.'.type'})) {
16596: return $env{'course.'.$cid.'.type'};
1.378 raeburn 16597: } else {
16598: return 'Course';
1.377 raeburn 16599: }
16600: }
1.156 albertel 16601:
1.406 raeburn 16602: sub group_term {
16603: my $crstype = &course_type();
16604: my %names = (
16605: 'Course' => 'group',
1.865 raeburn 16606: 'Community' => 'group',
1.406 raeburn 16607: );
16608: return $names{$crstype};
16609: }
16610:
1.902 raeburn 16611: sub course_types {
1.1075.2.161. .17(raeb 16612:-23): my @types = ('official','unofficial','community','textbook','lti');
1.902 raeburn 16613: my %typename = (
16614: official => 'Official course',
16615: unofficial => 'Unofficial course',
16616: community => 'Community',
1.1075.2.59 raeburn 16617: textbook => 'Textbook course',
1.1075.2.161. .17(raeb 16618:-23): lti => 'LTI provider',
1.902 raeburn 16619: );
16620: return (\@types,\%typename);
16621: }
16622:
1.156 albertel 16623: sub icon {
16624: my ($file)=@_;
1.505 albertel 16625: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 16626: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 16627: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 16628: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
16629: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
16630: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16631: $curfext.".gif") {
16632: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16633: $curfext.".gif";
16634: }
16635: }
1.249 albertel 16636: return &lonhttpdurl($iconname);
1.154 albertel 16637: }
1.84 albertel 16638:
1.575 albertel 16639: sub lonhttpdurl {
1.692 www 16640: #
16641: # Had been used for "small fry" static images on separate port 8080.
16642: # Modify here if lightweight http functionality desired again.
16643: # Currently eliminated due to increasing firewall issues.
16644: #
1.575 albertel 16645: my ($url)=@_;
1.692 www 16646: return $url;
1.215 albertel 16647: }
16648:
1.213 albertel 16649: sub connection_aborted {
16650: my ($r)=@_;
16651: $r->print(" ");$r->rflush();
16652: my $c = $r->connection;
16653: return $c->aborted();
16654: }
16655:
1.221 foxr 16656: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 16657: # strings as 'strings'.
16658: sub escape_single {
1.221 foxr 16659: my ($input) = @_;
1.223 albertel 16660: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16661: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16662: return $input;
16663: }
1.223 albertel 16664:
1.222 foxr 16665: # Same as escape_single, but escape's "'s This
16666: # can be used for "strings"
16667: sub escape_double {
16668: my ($input) = @_;
16669: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16670: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16671: return $input;
16672: }
1.223 albertel 16673:
1.222 foxr 16674: # Escapes the last element of a full URL.
16675: sub escape_url {
16676: my ($url) = @_;
1.238 raeburn 16677: my @urlslices = split(/\//, $url,-1);
1.369 www 16678: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 16679: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16680: }
1.462 albertel 16681:
1.820 raeburn 16682: sub compare_arrays {
16683: my ($arrayref1,$arrayref2) = @_;
16684: my (@difference,%count);
16685: @difference = ();
16686: %count = ();
16687: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16688: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16689: foreach my $element (keys(%count)) {
16690: if ($count{$element} == 1) {
16691: push(@difference,$element);
16692: }
16693: }
16694: }
16695: return @difference;
16696: }
16697:
1.1075.2.152 raeburn 16698: sub lon_status_items {
16699: my %defaults = (
16700: E => 100,
16701: W => 4,
16702: N => 1,
16703: U => 5,
16704: threshold => 200,
16705: sysmail => 2500,
16706: );
16707: my %names = (
16708: E => 'Errors',
16709: W => 'Warnings',
16710: N => 'Notices',
16711: U => 'Unsent',
16712: );
16713: return (\%defaults,\%names);
16714: }
16715:
1.817 bisitz 16716: # -------------------------------------------------------- Initialize user login
1.462 albertel 16717: sub init_user_environment {
1.463 albertel 16718: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16719: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16720:
16721: my $public=($username eq 'public' && $domain eq 'public');
16722:
16723: # See if old ID present, if so, remove
16724:
1.1062 raeburn 16725: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16726: my $now=time;
16727:
16728: if ($public) {
16729: my $max_public=100;
16730: my $oldest;
16731: my $oldest_time=0;
16732: for(my $next=1;$next<=$max_public;$next++) {
16733: if (-e $lonids."/publicuser_$next.id") {
16734: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16735: if ($mtime<$oldest_time || !$oldest_time) {
16736: $oldest_time=$mtime;
16737: $oldest=$next;
16738: }
16739: } else {
16740: $cookie="publicuser_$next";
16741: last;
16742: }
16743: }
16744: if (!$cookie) { $cookie="publicuser_$oldest"; }
16745: } else {
1.463 albertel 16746: # if this isn't a robot, kill any existing non-robot sessions
16747: if (!$args->{'robot'}) {
16748: opendir(DIR,$lonids);
16749: while ($filename=readdir(DIR)) {
16750: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136 raeburn 16751: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
16752: &GDBM_READER(),0640)) {
16753: my $linkedfile;
16754: if (exists($oldenv{'user.linkedenv'})) {
16755: $linkedfile = $oldenv{'user.linkedenv'};
16756: }
16757: untie(%oldenv);
16758: if (unlink("$lonids/$filename")) {
16759: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
16760: if (-l "$lonids/$linkedfile.id") {
16761: unlink("$lonids/$linkedfile.id");
16762: }
16763: }
16764: }
16765: } else {
16766: unlink($lonids.'/'.$filename);
16767: }
1.463 albertel 16768: }
1.462 albertel 16769: }
1.463 albertel 16770: closedir(DIR);
1.1075.2.84 raeburn 16771: # If there is a undeleted lockfile for the user's paste buffer remove it.
16772: my $namespace = 'nohist_courseeditor';
16773: my $lockingkey = 'paste'."\0".'locked_num';
16774: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16775: $domain,$username);
16776: if (exists($lockhash{$lockingkey})) {
16777: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16778: unless ($delresult eq 'ok') {
16779: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16780: }
16781: }
1.462 albertel 16782: }
16783: # Give them a new cookie
1.463 albertel 16784: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16785: : $now.$$.int(rand(10000)));
1.463 albertel 16786: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16787:
16788: # Initialize roles
16789:
1.1062 raeburn 16790: ($userroles,$firstaccenv,$timerintenv) =
16791: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16792: }
16793: # ------------------------------------ Check browser type and MathML capability
16794:
1.1075.2.77 raeburn 16795: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16796: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16797:
16798: # ------------------------------------------------------------- Get environment
16799:
16800: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16801: my ($tmp) = keys(%userenv);
16802: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
16803: } else {
16804: undef(%userenv);
16805: }
16806: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16807: $form->{'interface'}=$userenv{'interface'};
16808: }
16809: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16810:
16811: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16812: foreach my $option ('interface','localpath','localres') {
16813: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16814: }
16815: # --------------------------------------------------------- Write first profile
16816:
16817: {
1.1075.2.150 raeburn 16818: my $ip = &Apache::lonnet::get_requestor_ip();
1.462 albertel 16819: my %initial_env =
16820: ("user.name" => $username,
16821: "user.domain" => $domain,
16822: "user.home" => $authhost,
16823: "browser.type" => $clientbrowser,
16824: "browser.version" => $clientversion,
16825: "browser.mathml" => $clientmathml,
16826: "browser.unicode" => $clientunicode,
16827: "browser.os" => $clientos,
1.1075.2.42 raeburn 16828: "browser.mobile" => $clientmobile,
16829: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 16830: "browser.osversion" => $clientosversion,
1.462 albertel 16831: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16832: "request.course.fn" => '',
16833: "request.course.uri" => '',
16834: "request.course.sec" => '',
16835: "request.role" => 'cm',
16836: "request.role.adv" => $env{'user.adv'},
1.1075.2.150 raeburn 16837: "request.host" => $ip,);
1.462 albertel 16838:
16839: if ($form->{'localpath'}) {
16840: $initial_env{"browser.localpath"} = $form->{'localpath'};
16841: $initial_env{"browser.localres"} = $form->{'localres'};
16842: }
16843:
16844: if ($form->{'interface'}) {
16845: $form->{'interface'}=~s/\W//gs;
16846: $initial_env{"browser.interface"} = $form->{'interface'};
16847: $env{'browser.interface'}=$form->{'interface'};
16848: }
16849:
1.1075.2.54 raeburn 16850: if ($form->{'iptoken'}) {
16851: my $lonhost = $r->dir_config('lonHostID');
16852: $initial_env{"user.noloadbalance"} = $lonhost;
16853: $env{'user.noloadbalance'} = $lonhost;
16854: }
16855:
1.1075.2.120 raeburn 16856: if ($form->{'noloadbalance'}) {
16857: my @hosts = &Apache::lonnet::current_machine_ids();
16858: my $hosthere = $form->{'noloadbalance'};
16859: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16860: $initial_env{"user.noloadbalance"} = $hosthere;
16861: $env{'user.noloadbalance'} = $hosthere;
16862: }
16863: }
16864:
1.1016 raeburn 16865: unless ($domain eq 'public') {
1.1075.2.125 raeburn 16866: my %is_adv = ( is_adv => $env{'user.adv'} );
16867: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 16868:
1.1075.2.161. .10(raeb 16869:-22): foreach my $tool ('aboutme','blog','webdav','portfolio','timezone') {
1.1075.2.125 raeburn 16870: $userenv{'availabletools.'.$tool} =
16871: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16872: undef,\%userenv,\%domdef,\%is_adv);
16873: }
1.724 raeburn 16874:
1.1075.2.161. .17(raeb 16875:-23): foreach my $crstype ('official','unofficial','community','textbook','lti') {
1.1075.2.125 raeburn 16876: $userenv{'canrequest.'.$crstype} =
16877: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16878: 'reload','requestcourses',
16879: \%userenv,\%domdef,\%is_adv);
16880: }
1.765 raeburn 16881:
1.1075.2.125 raeburn 16882: $userenv{'canrequest.author'} =
16883: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16884: 'reload','requestauthor',
16885: \%userenv,\%domdef,\%is_adv);
16886: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16887: $domain,$username);
16888: my $reqstatus = $reqauthor{'author_status'};
16889: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16890: if (ref($reqauthor{'author'}) eq 'HASH') {
16891: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16892: $reqauthor{'author'}{'timestamp'};
16893: }
1.1075.2.14 raeburn 16894: }
16895: }
16896:
1.462 albertel 16897: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16898:
1.462 albertel 16899: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16900: &GDBM_WRCREAT(),0640)) {
16901: &_add_to_env(\%disk_env,\%initial_env);
16902: &_add_to_env(\%disk_env,\%userenv,'environment.');
16903: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16904: if (ref($firstaccenv) eq 'HASH') {
16905: &_add_to_env(\%disk_env,$firstaccenv);
16906: }
16907: if (ref($timerintenv) eq 'HASH') {
16908: &_add_to_env(\%disk_env,$timerintenv);
16909: }
1.463 albertel 16910: if (ref($args->{'extra_env'})) {
16911: &_add_to_env(\%disk_env,$args->{'extra_env'});
16912: }
1.462 albertel 16913: untie(%disk_env);
16914: } else {
1.705 tempelho 16915: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16916: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16917: return 'error: '.$!;
16918: }
16919: }
16920: $env{'request.role'}='cm';
16921: $env{'request.role.adv'}=$env{'user.adv'};
16922: $env{'browser.type'}=$clientbrowser;
16923:
16924: return $cookie;
16925:
16926: }
16927:
16928: sub _add_to_env {
16929: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16930: if (ref($env_data) eq 'HASH') {
16931: while (my ($key,$value) = each(%$env_data)) {
16932: $idf->{$prefix.$key} = $value;
16933: $env{$prefix.$key} = $value;
16934: }
1.462 albertel 16935: }
16936: }
16937:
1.685 tempelho 16938: # --- Get the symbolic name of a problem and the url
16939: sub get_symb {
16940: my ($request,$silent) = @_;
1.726 raeburn 16941: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16942: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16943: if ($symb eq '') {
16944: if (!$silent) {
1.1071 raeburn 16945: if (ref($request)) {
16946: $request->print("Unable to handle ambiguous references:$url:.");
16947: }
1.685 tempelho 16948: return ();
16949: }
16950: }
16951: &Apache::lonenc::check_decrypt(\$symb);
16952: return ($symb);
16953: }
16954:
16955: # --------------------------------------------------------------Get annotation
16956:
16957: sub get_annotation {
16958: my ($symb,$enc) = @_;
16959:
16960: my $key = $symb;
16961: if (!$enc) {
16962: $key =
16963: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16964: }
16965: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16966: return $annotation{$key};
16967: }
16968:
16969: sub clean_symb {
1.731 raeburn 16970: my ($symb,$delete_enc) = @_;
1.685 tempelho 16971:
16972: &Apache::lonenc::check_decrypt(\$symb);
16973: my $enc = $env{'request.enc'};
1.731 raeburn 16974: if ($delete_enc) {
1.730 raeburn 16975: delete($env{'request.enc'});
16976: }
1.685 tempelho 16977:
16978: return ($symb,$enc);
16979: }
1.462 albertel 16980:
1.1075.2.69 raeburn 16981: ############################################################
16982: ############################################################
16983:
16984: =pod
16985:
16986: =head1 Routines for building display used to search for courses
16987:
16988:
16989: =over 4
16990:
16991: =item * &build_filters()
16992:
16993: Create markup for a table used to set filters to use when selecting
16994: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16995: and quotacheck.pl
16996:
16997:
16998: Inputs:
16999:
17000: filterlist - anonymous array of fields to include as potential filters
17001:
17002: crstype - course type
17003:
17004: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
17005: to pop-open a course selector (will contain "extra element").
17006:
17007: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
17008:
17009: filter - anonymous hash of criteria and their values
17010:
17011: action - form action
17012:
17013: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
17014:
17015: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
17016:
17017: cloneruname - username of owner of new course who wants to clone
17018:
17019: clonerudom - domain of owner of new course who wants to clone
17020:
17021: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
17022:
17023: codetitlesref - reference to array of titles of components in institutional codes (official courses)
17024:
17025: codedom - domain
17026:
17027: formname - value of form element named "form".
17028:
17029: fixeddom - domain, if fixed.
17030:
17031: prevphase - value to assign to form element named "phase" when going back to the previous screen
17032:
17033: cnameelement - name of form element in form on opener page which will receive title of selected course
17034:
17035: cnumelement - name of form element in form on opener page which will receive courseID of selected course
17036:
17037: cdomelement - name of form element in form on opener page which will receive domain of selected course
17038:
17039: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
17040:
17041: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
17042:
17043: clonewarning - warning message about missing information for intended course owner when DC creates a course
17044:
17045:
17046: Returns: $output - HTML for display of search criteria, and hidden form elements.
17047:
17048:
17049: Side Effects: None
17050:
17051: =cut
17052:
17053: # ---------------------------------------------- search for courses based on last activity etc.
17054:
17055: sub build_filters {
17056: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
17057: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
17058: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
17059: $cnameelement,$cnumelement,$cdomelement,$setroles,
17060: $clonetext,$clonewarning) = @_;
17061: my ($list,$jscript);
17062: my $onchange = 'javascript:updateFilters(this)';
17063: my ($domainselectform,$sincefilterform,$createdfilterform,
17064: $ownerdomselectform,$persondomselectform,$instcodeform,
17065: $typeselectform,$instcodetitle);
17066: if ($formname eq '') {
17067: $formname = $caller;
17068: }
17069: foreach my $item (@{$filterlist}) {
17070: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
17071: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
17072: if ($item eq 'domainfilter') {
17073: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
17074: } elsif ($item eq 'coursefilter') {
17075: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
17076: } elsif ($item eq 'ownerfilter') {
17077: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17078: } elsif ($item eq 'ownerdomfilter') {
17079: $filter->{'ownerdomfilter'} =
17080: &LONCAPA::clean_domain($filter->{$item});
17081: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
17082: 'ownerdomfilter',1);
17083: } elsif ($item eq 'personfilter') {
17084: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17085: } elsif ($item eq 'persondomfilter') {
17086: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
17087: 'persondomfilter',1);
17088: } else {
17089: $filter->{$item} =~ s/\W//g;
17090: }
17091: if (!$filter->{$item}) {
17092: $filter->{$item} = '';
17093: }
17094: }
17095: if ($item eq 'domainfilter') {
17096: my $allow_blank = 1;
17097: if ($formname eq 'portform') {
17098: $allow_blank=0;
17099: } elsif ($formname eq 'studentform') {
17100: $allow_blank=0;
17101: }
17102: if ($fixeddom) {
17103: $domainselectform = '<input type="hidden" name="domainfilter"'.
17104: ' value="'.$codedom.'" />'.
17105: &Apache::lonnet::domain($codedom,'description');
17106: } else {
17107: $domainselectform = &select_dom_form($filter->{$item},
17108: 'domainfilter',
17109: $allow_blank,'',$onchange);
17110: }
17111: } else {
17112: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
17113: }
17114: }
17115:
17116: # last course activity filter and selection
17117: $sincefilterform = &timebased_select_form('sincefilter',$filter);
17118:
17119: # course created filter and selection
17120: if (exists($filter->{'createdfilter'})) {
17121: $createdfilterform = &timebased_select_form('createdfilter',$filter);
17122: }
17123:
17124: my %lt = &Apache::lonlocal::texthash(
17125: 'cac' => "$crstype Activity",
17126: 'ccr' => "$crstype Created",
17127: 'cde' => "$crstype Title",
17128: 'cdo' => "$crstype Domain",
17129: 'ins' => 'Institutional Code',
17130: 'inc' => 'Institutional Categorization',
17131: 'cow' => "$crstype Owner/Co-owner",
17132: 'cop' => "$crstype Personnel Includes",
17133: 'cog' => 'Type',
17134: );
17135:
17136: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17137: my $typeval = 'Course';
17138: if ($crstype eq 'Community') {
17139: $typeval = 'Community';
17140: }
17141: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
17142: } else {
17143: $typeselectform = '<select name="type" size="1"';
17144: if ($onchange) {
17145: $typeselectform .= ' onchange="'.$onchange.'"';
17146: }
17147: $typeselectform .= '>'."\n";
17148: foreach my $posstype ('Course','Community') {
17149: $typeselectform.='<option value="'.$posstype.'"'.
17150: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
17151: }
17152: $typeselectform.="</select>";
17153: }
17154:
17155: my ($cloneableonlyform,$cloneabletitle);
17156: if (exists($filter->{'cloneableonly'})) {
17157: my $cloneableon = '';
17158: my $cloneableoff = ' checked="checked"';
17159: if ($filter->{'cloneableonly'}) {
17160: $cloneableon = $cloneableoff;
17161: $cloneableoff = '';
17162: }
17163: $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>';
17164: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 17165: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 17166: } else {
17167: $cloneabletitle = &mt('Cloneable by you');
17168: }
17169: }
17170: my $officialjs;
17171: if ($crstype eq 'Course') {
17172: if (exists($filter->{'instcodefilter'})) {
17173: # if (($fixeddom) || ($formname eq 'requestcrs') ||
17174: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
17175: if ($codedom) {
17176: $officialjs = 1;
17177: ($instcodeform,$jscript,$$numtitlesref) =
17178: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
17179: $officialjs,$codetitlesref);
17180: if ($jscript) {
17181: $jscript = '<script type="text/javascript">'."\n".
17182: '// <![CDATA['."\n".
17183: $jscript."\n".
17184: '// ]]>'."\n".
17185: '</script>'."\n";
17186: }
17187: }
17188: if ($instcodeform eq '') {
17189: $instcodeform =
17190: '<input type="text" name="instcodefilter" size="10" value="'.
17191: $list->{'instcodefilter'}.'" />';
17192: $instcodetitle = $lt{'ins'};
17193: } else {
17194: $instcodetitle = $lt{'inc'};
17195: }
17196: if ($fixeddom) {
17197: $instcodetitle .= '<br />('.$codedom.')';
17198: }
17199: }
17200: }
17201: my $output = qq|
17202: <form method="post" name="filterpicker" action="$action">
17203: <input type="hidden" name="form" value="$formname" />
17204: |;
17205: if ($formname eq 'modifycourse') {
17206: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
17207: '<input type="hidden" name="prevphase" value="'.
17208: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 17209: } elsif ($formname eq 'quotacheck') {
17210: $output .= qq|
17211: <input type="hidden" name="sortby" value="" />
17212: <input type="hidden" name="sortorder" value="" />
17213: |;
17214: } else {
1.1075.2.69 raeburn 17215: my $name_input;
17216: if ($cnameelement ne '') {
17217: $name_input = '<input type="hidden" name="cnameelement" value="'.
17218: $cnameelement.'" />';
17219: }
17220: $output .= qq|
17221: <input type="hidden" name="cnumelement" value="$cnumelement" />
17222: <input type="hidden" name="cdomelement" value="$cdomelement" />
17223: $name_input
17224: $roleelement
17225: $multelement
17226: $typeelement
17227: |;
17228: if ($formname eq 'portform') {
17229: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
17230: }
17231: }
17232: if ($fixeddom) {
17233: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
17234: }
17235: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
17236: if ($sincefilterform) {
17237: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
17238: .$sincefilterform
17239: .&Apache::lonhtmlcommon::row_closure();
17240: }
17241: if ($createdfilterform) {
17242: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17243: .$createdfilterform
17244: .&Apache::lonhtmlcommon::row_closure();
17245: }
17246: if ($domainselectform) {
17247: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
17248: .$domainselectform
17249: .&Apache::lonhtmlcommon::row_closure();
17250: }
17251: if ($typeselectform) {
17252: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17253: $output .= $typeselectform;
17254: } else {
17255: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
17256: .$typeselectform
17257: .&Apache::lonhtmlcommon::row_closure();
17258: }
17259: }
17260: if ($instcodeform) {
17261: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
17262: .$instcodeform
17263: .&Apache::lonhtmlcommon::row_closure();
17264: }
17265: if (exists($filter->{'ownerfilter'})) {
17266: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
17267: '<table><tr><td>'.&mt('Username').'<br />'.
17268: '<input type="text" name="ownerfilter" size="20" value="'.
17269: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17270: $ownerdomselectform.'</td></tr></table>'.
17271: &Apache::lonhtmlcommon::row_closure();
17272: }
17273: if (exists($filter->{'personfilter'})) {
17274: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
17275: '<table><tr><td>'.&mt('Username').'<br />'.
17276: '<input type="text" name="personfilter" size="20" value="'.
17277: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17278: $persondomselectform.'</td></tr></table>'.
17279: &Apache::lonhtmlcommon::row_closure();
17280: }
17281: if (exists($filter->{'coursefilter'})) {
17282: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
17283: .'<input type="text" name="coursefilter" size="25" value="'
17284: .$list->{'coursefilter'}.'" />'
17285: .&Apache::lonhtmlcommon::row_closure();
17286: }
17287: if ($cloneableonlyform) {
17288: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
17289: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
17290: }
17291: if (exists($filter->{'descriptfilter'})) {
17292: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
17293: .'<input type="text" name="descriptfilter" size="40" value="'
17294: .$list->{'descriptfilter'}.'" />'
17295: .&Apache::lonhtmlcommon::row_closure(1);
17296: }
17297: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
17298: '<input type="hidden" name="updater" value="" />'."\n".
17299: '<input type="submit" name="gosearch" value="'.
17300: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
17301: return $jscript.$clonewarning.$output;
17302: }
17303:
17304: =pod
17305:
17306: =item * &timebased_select_form()
17307:
17308: Create markup for a dropdown list used to select a time-based
17309: filter e.g., Course Activity, Course Created, when searching for courses
17310: or communities
17311:
17312: Inputs:
17313:
17314: item - name of form element (sincefilter or createdfilter)
17315:
17316: filter - anonymous hash of criteria and their values
17317:
17318: Returns: HTML for a select box contained a blank, then six time selections,
17319: with value set in incoming form variables currently selected.
17320:
17321: Side Effects: None
17322:
17323: =cut
17324:
17325: sub timebased_select_form {
17326: my ($item,$filter) = @_;
17327: if (ref($filter) eq 'HASH') {
17328: $filter->{$item} =~ s/[^\d-]//g;
17329: if (!$filter->{$item}) { $filter->{$item}=-1; }
17330: return &select_form(
17331: $filter->{$item},
17332: $item,
17333: { '-1' => '',
17334: '86400' => &mt('today'),
17335: '604800' => &mt('last week'),
17336: '2592000' => &mt('last month'),
17337: '7776000' => &mt('last three months'),
17338: '15552000' => &mt('last six months'),
17339: '31104000' => &mt('last year'),
17340: 'select_form_order' =>
17341: ['-1','86400','604800','2592000','7776000',
17342: '15552000','31104000']});
17343: }
17344: }
17345:
17346: =pod
17347:
17348: =item * &js_changer()
17349:
17350: Create script tag containing Javascript used to submit course search form
17351: when course type or domain is changed, and also to hide 'Searching ...' on
17352: page load completion for page showing search result.
17353:
17354: Inputs: None
17355:
17356: Returns: markup containing updateFilters() and hideSearching() javascript functions.
17357:
17358: Side Effects: None
17359:
17360: =cut
17361:
17362: sub js_changer {
17363: return <<ENDJS;
17364: <script type="text/javascript">
17365: // <![CDATA[
17366: function updateFilters(caller) {
17367: if (typeof(caller) != "undefined") {
17368: document.filterpicker.updater.value = caller.name;
17369: }
17370: document.filterpicker.submit();
17371: }
17372:
17373: function hideSearching() {
17374: if (document.getElementById('searching')) {
17375: document.getElementById('searching').style.display = 'none';
17376: }
17377: return;
17378: }
17379:
17380: // ]]>
17381: </script>
17382:
17383: ENDJS
17384: }
17385:
17386: =pod
17387:
17388: =item * &search_courses()
17389:
17390: Process selected filters form course search form and pass to lonnet::courseiddump
17391: to retrieve a hash for which keys are courseIDs which match the selected filters.
17392:
17393: Inputs:
17394:
17395: dom - domain being searched
17396:
17397: type - course type ('Course' or 'Community' or '.' if any).
17398:
17399: filter - anonymous hash of criteria and their values
17400:
17401: numtitles - for institutional codes - number of categories
17402:
17403: cloneruname - optional username of new course owner
17404:
17405: clonerudom - optional domain of new course owner
17406:
1.1075.2.95 raeburn 17407: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 17408: (used when DC is using course creation form)
17409:
17410: codetitles - reference to array of titles of components in institutional codes (official courses).
17411:
1.1075.2.95 raeburn 17412: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17413: (and so can clone automatically)
17414:
17415: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17416:
17417: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17418: courses to clone
1.1075.2.69 raeburn 17419:
17420: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17421:
17422:
17423: Side Effects: None
17424:
17425: =cut
17426:
17427:
17428: sub search_courses {
1.1075.2.95 raeburn 17429: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17430: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 17431: my (%courses,%showcourses,$cloner);
17432: if (($filter->{'ownerfilter'} ne '') ||
17433: ($filter->{'ownerdomfilter'} ne '')) {
17434: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17435: $filter->{'ownerdomfilter'};
17436: }
17437: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17438: if (!$filter->{$item}) {
17439: $filter->{$item}='.';
17440: }
17441: }
17442: my $now = time;
17443: my $timefilter =
17444: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17445: my ($createdbefore,$createdafter);
17446: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17447: $createdbefore = $now;
17448: $createdafter = $now-$filter->{'createdfilter'};
17449: }
17450: my ($instcodefilter,$regexpok);
17451: if ($numtitles) {
17452: if ($env{'form.official'} eq 'on') {
17453: $instcodefilter =
17454: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17455: $regexpok = 1;
17456: } elsif ($env{'form.official'} eq 'off') {
17457: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17458: unless ($instcodefilter eq '') {
17459: $regexpok = -1;
17460: }
17461: }
17462: } else {
17463: $instcodefilter = $filter->{'instcodefilter'};
17464: }
17465: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17466: if ($type eq '') { $type = '.'; }
17467:
17468: if (($clonerudom ne '') && ($cloneruname ne '')) {
17469: $cloner = $cloneruname.':'.$clonerudom;
17470: }
17471: %courses = &Apache::lonnet::courseiddump($dom,
17472: $filter->{'descriptfilter'},
17473: $timefilter,
17474: $instcodefilter,
17475: $filter->{'combownerfilter'},
17476: $filter->{'coursefilter'},
17477: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 17478: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 17479: $filter->{'cloneableonly'},
17480: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 17481: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 17482: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17483: my $ccrole;
17484: if ($type eq 'Community') {
17485: $ccrole = 'co';
17486: } else {
17487: $ccrole = 'cc';
17488: }
17489: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17490: $filter->{'persondomfilter'},
17491: 'userroles',undef,
17492: [$ccrole,'in','ad','ep','ta','cr'],
17493: $dom);
17494: foreach my $role (keys(%rolehash)) {
17495: my ($cnum,$cdom,$courserole) = split(':',$role);
17496: my $cid = $cdom.'_'.$cnum;
17497: if (exists($courses{$cid})) {
17498: if (ref($courses{$cid}) eq 'HASH') {
17499: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17500: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 17501: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 17502: }
17503: } else {
17504: $courses{$cid}{roles} = [$courserole];
17505: }
17506: $showcourses{$cid} = $courses{$cid};
17507: }
17508: }
17509: }
17510: %courses = %showcourses;
17511: }
17512: return %courses;
17513: }
17514:
17515: =pod
17516:
17517: =back
17518:
1.1075.2.88 raeburn 17519: =head1 Routines for version requirements for current course.
17520:
17521: =over 4
17522:
17523: =item * &check_release_required()
17524:
17525: Compares required LON-CAPA version with version on server, and
17526: if required version is newer looks for a server with the required version.
17527:
17528: Looks first at servers in user's owen domain; if none suitable, looks at
17529: servers in course's domain are permitted to host sessions for user's domain.
17530:
17531: Inputs:
17532:
17533: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17534:
17535: $courseid - Course ID of current course
17536:
17537: $rolecode - User's current role in course (for switchserver query string).
17538:
17539: $required - LON-CAPA version needed by course (format: Major.Minor).
17540:
17541:
17542: Returns:
17543:
17544: $switchserver - query string tp append to /adm/switchserver call (if
17545: current server's LON-CAPA version is too old.
17546:
17547: $warning - Message is displayed if no suitable server could be found.
17548:
17549: =cut
17550:
17551: sub check_release_required {
17552: my ($loncaparev,$courseid,$rolecode,$required) = @_;
17553: my ($switchserver,$warning);
17554: if ($required ne '') {
17555: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
17556: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17557: if ($reqdmajor ne '' && $reqdminor ne '') {
17558: my $otherserver;
17559: if (($major eq '' && $minor eq '') ||
17560: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
17561: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
17562: my $switchlcrev =
17563: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
17564: $userdomserver);
17565: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17566: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
17567: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
17568: my $cdom = $env{'course.'.$courseid.'.domain'};
17569: if ($cdom ne $env{'user.domain'}) {
17570: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
17571: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
17572: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17573: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
17574: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
17575: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
17576: my $canhost =
17577: &Apache::lonnet::can_host_session($env{'user.domain'},
17578: $coursedomserver,
17579: $remoterev,
17580: $udomdefaults{'remotesessions'},
17581: $defdomdefaults{'hostedsessions'});
17582:
17583: if ($canhost) {
17584: $otherserver = $coursedomserver;
17585: } else {
17586: $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.");
17587: }
17588: } else {
17589: $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).");
17590: }
17591: } else {
17592: $otherserver = $userdomserver;
17593: }
17594: }
17595: if ($otherserver ne '') {
17596: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
17597: }
17598: }
17599: }
17600: return ($switchserver,$warning);
17601: }
17602:
17603: =pod
17604:
17605: =item * &check_release_result()
17606:
17607: Inputs:
17608:
17609: $switchwarning - Warning message if no suitable server found to host session.
17610:
17611: $switchserver - query string to append to /adm/switchserver containing lonHostID
17612: and current role.
17613:
17614: Returns: HTML to display with information about requirement to switch server.
17615: Either displaying warning with link to Roles/Courses screen or
17616: display link to switchserver.
17617:
1.1075.2.69 raeburn 17618: =cut
17619:
1.1075.2.88 raeburn 17620: sub check_release_result {
17621: my ($switchwarning,$switchserver) = @_;
17622: my $output = &start_page('Selected course unavailable on this server').
17623: '<p class="LC_warning">';
17624: if ($switchwarning) {
17625: $output .= $switchwarning.'<br /><a href="/adm/roles">';
17626: if (&show_course()) {
17627: $output .= &mt('Display courses');
17628: } else {
17629: $output .= &mt('Display roles');
17630: }
17631: $output .= '</a>';
17632: } elsif ($switchserver) {
17633: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
17634: '<br />'.
17635: '<a href="/adm/switchserver?'.$switchserver.'">'.
17636: &mt('Switch Server').
17637: '</a>';
17638: }
17639: $output .= '</p>'.&end_page();
17640: return $output;
17641: }
17642:
17643: =pod
17644:
17645: =item * &needs_coursereinit()
17646:
17647: Determine if course contents stored for user's session needs to be
17648: refreshed, because content has changed since "Big Hash" last tied.
17649:
17650: Check for change is made if time last checked is more than 10 minutes ago
17651: (by default).
17652:
17653: Inputs:
17654:
17655: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17656:
17657: $interval (optional) - Time which may elapse (in s) between last check for content
17658: change in current course. (default: 600 s).
17659:
17660: Returns: an array; first element is:
17661:
17662: =over 4
17663:
17664: 'switch' - if content updates mean user's session
17665: needs to be switched to a server running a newer LON-CAPA version
17666:
17667: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
17668: on current server hosting user's session
17669:
17670: '' - if no action required.
17671:
17672: =back
17673:
17674: If first item element is 'switch':
17675:
17676: second item is $switchwarning - Warning message if no suitable server found to host session.
17677:
17678: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
17679: and current role.
17680:
17681: otherwise: no other elements returned.
17682:
17683: =back
17684:
17685: =cut
17686:
17687: sub needs_coursereinit {
17688: my ($loncaparev,$interval) = @_;
17689: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
17690: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17691: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17692: my $now = time;
17693: if ($interval eq '') {
17694: $interval = 600;
17695: }
17696: if (($now-$env{'request.course.timechecked'})>$interval) {
17697: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1075.2.161. .4(raebu 17698:22): my $blocked = &blocking_status('reinit',undef,$cnum,$cdom,undef,1);
.1(raebu 17699:21): if ($blocked) {
17700:21): return ();
17701:21): }
.13(raeb 17702:-23): my $update;
17703:-23): my $lastmainchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17704:-23): my $lastsuppchange = &Apache::lonnet::get_suppchange($cdom,$cnum);
17705:-23): if ($lastmainchange > $env{'request.course.tied'}) {
17706:-23): my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
17707:-23): if ($needswitch) {
17708:-23): return ('switch',$switchwarning,$switchserver);
17709:-23): }
17710:-23): $update = 'main';
17711:-23): }
17712:-23): if ($lastsuppchange > $env{'request.course.suppupdated'}) {
17713:-23): if ($update) {
17714:-23): $update = 'both';
17715:-23): } else {
17716:-23): my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
17717:-23): if ($needswitch) {
17718:-23): return ('switch',$switchwarning,$switchserver);
17719:-23): } else {
17720:-23): $update = 'supp';
1.1075.2.88 raeburn 17721: }
17722: }
1.1075.2.161. .13(raeb 17723:-23): return ($update);
17724:-23): }
17725:-23): }
17726:-23): return ();
17727:-23): }
17728:-23):
17729:-23): sub switch_for_update {
17730:-23): my ($loncaparev,$cdom,$cnum) = @_;
17731:-23): my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17732:-23): if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17733:-23): my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17734:-23): if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17735:-23): &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17736:-23): $curr_reqd_hash{'internal.releaserequired'}});
17737:-23): my ($switchserver,$switchwarning) =
17738:-23): &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17739:-23): $curr_reqd_hash{'internal.releaserequired'});
17740:-23): if ($switchwarning ne '' || $switchserver ne '') {
17741:-23): return ('switch',$switchwarning,$switchserver);
17742:-23): }
1.1075.2.88 raeburn 17743: }
17744: }
17745: return ();
17746: }
1.1075.2.69 raeburn 17747:
1.1075.2.11 raeburn 17748: sub update_content_constraints {
17749: my ($cdom,$cnum,$chome,$cid) = @_;
17750: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17751: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
17752: my %checkresponsetypes;
17753: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
17754: my ($item,$name,$value) = split(/:/,$key);
17755: if ($item eq 'resourcetag') {
17756: if ($name eq 'responsetype') {
17757: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17758: }
17759: }
17760: }
17761: my $navmap = Apache::lonnavmaps::navmap->new();
17762: if (defined($navmap)) {
17763: my %allresponses;
17764: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
17765: my %responses = $res->responseTypes();
17766: foreach my $key (keys(%responses)) {
17767: next unless(exists($checkresponsetypes{$key}));
17768: $allresponses{$key} += $responses{$key};
17769: }
17770: }
17771: foreach my $key (keys(%allresponses)) {
17772: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17773: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17774: ($reqdmajor,$reqdminor) = ($major,$minor);
17775: }
17776: }
17777: undef($navmap);
17778: }
17779: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17780: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17781: }
17782: return;
17783: }
17784:
1.1075.2.27 raeburn 17785: sub allmaps_incourse {
17786: my ($cdom,$cnum,$chome,$cid) = @_;
17787: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17788: $cid = $env{'request.course.id'};
17789: $cdom = $env{'course.'.$cid.'.domain'};
17790: $cnum = $env{'course.'.$cid.'.num'};
17791: $chome = $env{'course.'.$cid.'.home'};
17792: }
17793: my %allmaps = ();
17794: my $lastchange =
17795: &Apache::lonnet::get_coursechange($cdom,$cnum);
17796: if ($lastchange > $env{'request.course.tied'}) {
17797: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17798: unless ($ferr) {
17799: &update_content_constraints($cdom,$cnum,$chome,$cid);
17800: }
17801: }
17802: my $navmap = Apache::lonnavmaps::navmap->new();
17803: if (defined($navmap)) {
17804: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17805: $allmaps{$res->src()} = 1;
17806: }
17807: }
17808: return \%allmaps;
17809: }
17810:
1.1075.2.11 raeburn 17811: sub parse_supplemental_title {
17812: my ($title) = @_;
17813:
17814: my ($foldertitle,$renametitle);
17815: if ($title =~ /&&&/) {
17816: $title = &HTML::Entites::decode($title);
17817: }
17818: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17819: $renametitle=$4;
17820: my ($time,$uname,$udom) = ($1,$2,$3);
17821: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17822: my $name = &plainname($uname,$udom);
17823: $name = &HTML::Entities::encode($name,'"<>&\'');
17824: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
1.1075.2.161. .16(raeb 17825:-23): $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.$name;
17826:-23): if ($foldertitle ne '') {
17827:-23): $title .= ': <br />'.$foldertitle;
17828:-23): }
1.1075.2.11 raeburn 17829: }
17830: if (wantarray) {
17831: return ($title,$foldertitle,$renametitle);
17832: }
17833: return $title;
17834: }
17835:
1.1075.2.161. .13(raeb 17836:-23): sub get_supplemental {
17837:-23): my ($cnum,$cdom,$ignorecache,$possdel)=@_;
17838:-23): my $hashid=$cnum.':'.$cdom;
17839:-23): my ($supplemental,$cached,$set_httprefs);
17840:-23): unless ($ignorecache) {
17841:-23): ($supplemental,$cached) = &Apache::lonnet::is_cached_new('supplemental',$hashid);
17842:-23): }
17843:-23): unless (defined($cached)) {
17844:-23): my $chome=&Apache::lonnet::homeserver($cnum,$cdom);
17845:-23): unless ($chome eq 'no_host') {
17846:-23): my @order = @LONCAPA::map::order;
17847:-23): my @resources = @LONCAPA::map::resources;
17848:-23): my @resparms = @LONCAPA::map::resparms;
17849:-23): my @zombies = @LONCAPA::map::zombies;
17850:-23): my ($errors,%ids,%hidden);
17851:-23): $errors =
17852:-23): &recurse_supplemental($cnum,$cdom,'supplemental.sequence',
17853:-23): $errors,$possdel,\%ids,\%hidden);
17854:-23): @LONCAPA::map::order = @order;
17855:-23): @LONCAPA::map::resources = @resources;
17856:-23): @LONCAPA::map::resparms = @resparms;
17857:-23): @LONCAPA::map::zombies = @zombies;
17858:-23): $set_httprefs = 1;
17859:-23): if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
17860:-23): &Apache::lonnet::appenv({'request.course.suppupdated' => time});
17861:-23): }
17862:-23): $supplemental = {
17863:-23): ids => \%ids,
17864:-23): hidden => \%hidden,
17865:-23): };
17866:-23): &Apache::lonnet::do_cache_new('supplemental',$hashid,$supplemental,600);
17867:-23): }
17868:-23): }
17869:-23): return ($supplemental,$set_httprefs);
17870:-23): }
17871:-23):
1.1075.2.43 raeburn 17872: sub recurse_supplemental {
1.1075.2.161. .13(raeb 17873:-23): my ($cnum,$cdom,$suppmap,$errors,$possdel,$suppids,$hiddensupp,$hidden) = @_;
17874:-23): if (($suppmap) && (ref($suppids) eq 'HASH') && (ref($hiddensupp) eq 'HASH')) {
17875:-23): my $mapnum;
17876:-23): if ($suppmap eq 'supplemental.sequence') {
17877:-23): $mapnum = 0;
17878:-23): } else {
17879:-23): ($mapnum) = ($suppmap =~ /^supplemental_(\d+)\.sequence$/);
17880:-23): }
1.1075.2.43 raeburn 17881: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17882: if ($fatal) {
17883: $errors ++;
17884: } else {
1.1075.2.161. .13(raeb 17885:-23): my @order = @LONCAPA::map::order;
17886:-23): if (@order > 0) {
17887:-23): my @resources = @LONCAPA::map::resources;
17888:-23): my @resparms = @LONCAPA::map::resparms;
17889:-23): foreach my $idx (@order) {
17890:-23): my ($title,$src,$ext,$type,$status)=split(/\:/,$resources[$idx]);
1.1075.2.43 raeburn 17891: if (($src ne '') && ($status eq 'res')) {
1.1075.2.161. .13(raeb 17892:-23): my $id = $mapnum.':'.$idx;
17893:-23): push(@{$suppids->{$src}},$id);
17894:-23): if (($hidden) || (&get_supp_parameter($resparms[$idx],'parameter_hiddenresource') =~ /^yes/i)) {
17895:-23): $hiddensupp->{$id} = 1;
17896:-23): }
1.1075.2.46 raeburn 17897: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1075.2.161. .13(raeb 17898:-23): $errors = &recurse_supplemental($cnum,$cdom,$1,$errors,$possdel,$suppids,
17899:-23): $hiddensupp,$hiddensupp->{$id});
1.1075.2.43 raeburn 17900: } else {
1.1075.2.161. .13(raeb 17901:-23): my $allowed;
17902:-23): if (($env{'request.role.adv'}) || (!$hiddensupp->{$id})) {
17903:-23): $allowed = 1;
17904:-23): } elsif ($possdel) {
17905:-23): foreach my $item (@{$suppids->{$src}}) {
17906:-23): next if ($item eq $id);
17907:-23): unless ($hiddensupp->{$item}) {
17908:-23): $allowed = 1;
17909:-23): last;
17910:-23): }
17911:-23): }
17912:-23): if ((!$allowed) && (exists($env{'httpref.'.$src}))) {
17913:-23): &Apache::lonnet::delenv('httpref.'.$src);
17914:-23): }
17915:-23): }
17916:-23): if ($allowed && (!exists($env{'httpref.'.$src}))) {
17917:-23): &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
17918:-23): }
17919:-23): }
17920:-23): }
17921:-23): }
17922:-23): }
17923:-23): }
17924:-23): }
17925:-23): return $errors;
17926:-23): }
17927:-23):
17928:-23): sub set_supp_httprefs {
17929:-23): my ($cnum,$cdom,$supplemental,$possdel) = @_;
17930:-23): if (ref($supplemental) eq 'HASH') {
17931:-23): if ((ref($supplemental->{'ids'}) eq 'HASH') && (ref($supplemental->{'hidden'}) eq 'HASH')) {
17932:-23): foreach my $src (keys(%{$supplemental->{'ids'}})) {
17933:-23): next if ($src =~ /\.sequence$/);
17934:-23): if (ref($supplemental->{'ids'}->{$src}) eq 'ARRAY') {
17935:-23): my $allowed;
17936:-23): if ($env{'request.role.adv'}) {
17937:-23): $allowed = 1;
17938:-23): } else {
17939:-23): foreach my $id (@{$supplemental->{'ids'}->{$src}}) {
17940:-23): unless ($supplemental->{'hidden'}->{$id}) {
17941:-23): $allowed = 1;
17942:-23): last;
17943:-23): }
17944:-23): }
17945:-23): }
17946:-23): if (exists($env{'httpref.'.$src})) {
17947:-23): if ($possdel) {
17948:-23): unless ($allowed) {
17949:-23): &Apache::lonnet::delenv('httpref.'.$src);
17950:-23): }
1.1075.2.43 raeburn 17951: }
1.1075.2.161. .13(raeb 17952:-23): } elsif ($allowed) {
17953:-23): &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
1.1075.2.43 raeburn 17954: }
17955: }
17956: }
1.1075.2.161. .13(raeb 17957:-23): if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
17958:-23): &Apache::lonnet::appenv({'request.course.suppupdated' => time});
17959:-23): }
1.1075.2.43 raeburn 17960: }
17961: }
1.1075.2.161. .13(raeb 17962:-23): }
17963:-23):
17964:-23): sub get_supp_parameter {
17965:-23): my ($resparm,$name)=@_;
17966:-23): return if ($resparm eq '');
17967:-23): my $value=undef;
17968:-23): my $ptype=undef;
17969:-23): foreach (split('&&&',$resparm)) {
17970:-23): my ($thistype,$thisname,$thisvalue)=split('___',$_);
17971:-23): if ($thisname eq $name) {
17972:-23): $value=$thisvalue;
17973:-23): $ptype=$thistype;
17974:-23): }
17975:-23): }
17976:-23): return $value;
1.1075.2.43 raeburn 17977: }
17978:
1.1075.2.18 raeburn 17979: sub symb_to_docspath {
1.1075.2.119 raeburn 17980: my ($symb,$navmapref) = @_;
17981: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 17982: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17983: if ($resurl=~/\.(sequence|page)$/) {
17984: $mapurl=$resurl;
17985: } elsif ($resurl eq 'adm/navmaps') {
17986: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17987: }
17988: my $mapresobj;
1.1075.2.119 raeburn 17989: unless (ref($$navmapref)) {
17990: $$navmapref = Apache::lonnavmaps::navmap->new();
17991: }
17992: if (ref($$navmapref)) {
17993: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 17994: }
17995: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17996: my $type=$2;
17997: my $path;
17998: if (ref($mapresobj)) {
17999: my $pcslist = $mapresobj->map_hierarchy();
18000: if ($pcslist ne '') {
18001: foreach my $pc (split(/,/,$pcslist)) {
18002: next if ($pc <= 1);
1.1075.2.119 raeburn 18003: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 18004: if (ref($res)) {
18005: my $thisurl = $res->src();
18006: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
18007: my $thistitle = $res->title();
18008: $path .= '&'.
18009: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 18010: &escape($thistitle).
1.1075.2.18 raeburn 18011: ':'.$res->randompick().
18012: ':'.$res->randomout().
18013: ':'.$res->encrypted().
18014: ':'.$res->randomorder().
18015: ':'.$res->is_page();
18016: }
18017: }
18018: }
18019: $path =~ s/^\&//;
18020: my $maptitle = $mapresobj->title();
18021: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 18022: $maptitle = 'Main Content';
1.1075.2.18 raeburn 18023: }
18024: $path .= (($path ne '')? '&' : '').
18025: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 18026: &escape($maptitle).
1.1075.2.18 raeburn 18027: ':'.$mapresobj->randompick().
18028: ':'.$mapresobj->randomout().
18029: ':'.$mapresobj->encrypted().
18030: ':'.$mapresobj->randomorder().
18031: ':'.$mapresobj->is_page();
18032: } else {
18033: my $maptitle = &Apache::lonnet::gettitle($mapurl);
18034: my $ispage = (($type eq 'page')? 1 : '');
18035: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 18036: $maptitle = 'Main Content';
1.1075.2.18 raeburn 18037: }
18038: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 18039: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 18040: }
18041: unless ($mapurl eq 'default') {
18042: $path = 'default&'.
1.1075.2.46 raeburn 18043: &escape('Main Content').
1.1075.2.18 raeburn 18044: ':::::&'.$path;
18045: }
18046: return $path;
18047: }
18048:
1.1075.2.161. .13(raeb 18049:-23): sub validate_folderpath {
18050:-23): my ($supplementalflag,$allowed,$coursenum,$coursedom) = @_;
18051:-23): if ($env{'form.folderpath'} ne '') {
18052:-23): my @items = split(/\&/,$env{'form.folderpath'});
18053:-23): my ($badpath,$changed,$got_supp,$supppath,%supphidden,%suppids);
18054:-23): for (my $i=0; $i<@items; $i++) {
18055:-23): my $odd = $i%2;
18056:-23): if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
18057:-23): $badpath = 1;
18058:-23): } elsif ($odd && $supplementalflag) {
18059:-23): my $idx = $i-1;
18060:-23): if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
18061:-23): my $esc_name = $1;
18062:-23): if ((!$allowed) || ($items[$idx] eq 'supplemental')) {
18063:-23): $supppath .= '&'.$esc_name;
18064:-23): $changed = 1;
18065:-23): } else {
18066:-23): $supppath .= '&'.$items[$i];
18067:-23): }
18068:-23): } elsif (($allowed) && ($items[$idx] ne 'supplemental')) {
18069:-23): $changed = 1;
18070:-23): my $is_hidden;
18071:-23): unless ($got_supp) {
18072:-23): my ($supplemental) = &get_supplemental($coursenum,$coursedom);
18073:-23): if (ref($supplemental) eq 'HASH') {
18074:-23): if (ref($supplemental->{'hidden'}) eq 'HASH') {
18075:-23): %supphidden = %{$supplemental->{'hidden'}};
18076:-23): }
18077:-23): if (ref($supplemental->{'ids'}) eq 'HASH') {
18078:-23): %suppids = %{$supplemental->{'ids'}};
18079:-23): }
18080:-23): }
18081:-23): $got_supp = 1;
18082:-23): }
18083:-23): if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
18084:-23): my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
18085:-23): if ($supphidden{$mapid}) {
18086:-23): $is_hidden = 1;
18087:-23): }
18088:-23): }
18089:-23): $supppath .= '&'.$items[$i].'::'.$is_hidden.':::';
18090:-23): } else {
18091:-23): $supppath .= '&'.$items[$i];
18092:-23): }
18093:-23): } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
18094:-23): $badpath = 1;
18095:-23): } elsif ($supplementalflag) {
18096:-23): $supppath .= '&'.$items[$i];
18097:-23): }
18098:-23): last if ($badpath);
18099:-23): }
18100:-23): if ($badpath) {
18101:-23): delete($env{'form.folderpath'});
18102:-23): } elsif ($changed && $supplementalflag) {
18103:-23): $supppath =~ s/^\&//;
18104:-23): $env{'form.folderpath'} = $supppath;
18105:-23): }
18106:-23): }
18107:-23): return;
18108:-23): }
18109:-23):
1.1075.2.14 raeburn 18110: sub captcha_display {
1.1075.2.137 raeburn 18111: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 18112: my ($output,$error);
1.1075.2.107 raeburn 18113: my ($captcha,$pubkey,$privkey,$version) =
1.1075.2.137 raeburn 18114: &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 18115: if ($captcha eq 'original') {
18116: $output = &create_captcha();
18117: unless ($output) {
18118: $error = 'captcha';
18119: }
18120: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 18121: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 18122: unless ($output) {
18123: $error = 'recaptcha';
18124: }
18125: }
1.1075.2.107 raeburn 18126: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 18127: }
18128:
18129: sub captcha_response {
1.1075.2.137 raeburn 18130: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 18131: my ($captcha_chk,$captcha_error);
1.1075.2.137 raeburn 18132: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 18133: if ($captcha eq 'original') {
18134: ($captcha_chk,$captcha_error) = &check_captcha();
18135: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 18136: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 18137: } else {
18138: $captcha_chk = 1;
18139: }
18140: return ($captcha_chk,$captcha_error);
18141: }
18142:
18143: sub get_captcha_config {
1.1075.2.137 raeburn 18144: my ($context,$lonhost,$dom_in_effect) = @_;
1.1075.2.107 raeburn 18145: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 18146: my $hostname = &Apache::lonnet::hostname($lonhost);
18147: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
18148: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
18149: if ($context eq 'usercreation') {
18150: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
18151: if (ref($domconfig{$context}) eq 'HASH') {
18152: $hashtocheck = $domconfig{$context}{'cancreate'};
18153: if (ref($hashtocheck) eq 'HASH') {
18154: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
18155: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
18156: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
18157: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
18158: }
18159: if ($privkey && $pubkey) {
18160: $captcha = 'recaptcha';
1.1075.2.107 raeburn 18161: $version = $hashtocheck->{'recaptchaversion'};
18162: if ($version ne '2') {
18163: $version = 1;
18164: }
1.1075.2.14 raeburn 18165: } else {
18166: $captcha = 'original';
18167: }
18168: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
18169: $captcha = 'original';
18170: }
18171: }
18172: } else {
18173: $captcha = 'captcha';
18174: }
18175: } elsif ($context eq 'login') {
18176: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
18177: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
18178: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
18179: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
18180: if ($privkey && $pubkey) {
18181: $captcha = 'recaptcha';
1.1075.2.107 raeburn 18182: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
18183: if ($version ne '2') {
18184: $version = 1;
18185: }
1.1075.2.14 raeburn 18186: } else {
18187: $captcha = 'original';
18188: }
18189: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
18190: $captcha = 'original';
18191: }
1.1075.2.137 raeburn 18192: } elsif ($context eq 'passwords') {
18193: if ($dom_in_effect) {
18194: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
18195: if ($passwdconf{'captcha'} eq 'recaptcha') {
18196: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
18197: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
18198: $privkey = $passwdconf{'recaptchakeys'}{'private'};
18199: }
18200: if ($privkey && $pubkey) {
18201: $captcha = 'recaptcha';
18202: $version = $passwdconf{'recaptchaversion'};
18203: if ($version ne '2') {
18204: $version = 1;
18205: }
18206: } else {
18207: $captcha = 'original';
18208: }
18209: } elsif ($passwdconf{'captcha'} ne 'notused') {
18210: $captcha = 'original';
18211: }
18212: }
1.1075.2.14 raeburn 18213: }
1.1075.2.107 raeburn 18214: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 18215: }
18216:
18217: sub create_captcha {
18218: my %captcha_params = &captcha_settings();
18219: my ($output,$maxtries,$tries) = ('',10,0);
18220: while ($tries < $maxtries) {
18221: $tries ++;
18222: my $captcha = Authen::Captcha->new (
18223: output_folder => $captcha_params{'output_dir'},
18224: data_folder => $captcha_params{'db_dir'},
18225: );
18226: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
18227:
18228: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
18229: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1075.2.158 raeburn 18230: '<span class="LC_nobreak">'.
1.1075.2.14 raeburn 18231: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.161. .15(raeb 18232:-23): '<input type="text" size="5" name="code" value="" autocomplete="new-password" />'.
1.1075.2.158 raeburn 18233: '</span><br />'.
1.1075.2.66 raeburn 18234: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 18235: last;
18236: }
18237: }
1.1075.2.158 raeburn 18238: if ($output eq '') {
18239: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
18240: }
1.1075.2.14 raeburn 18241: return $output;
18242: }
18243:
18244: sub captcha_settings {
18245: my %captcha_params = (
18246: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
18247: www_output_dir => "/captchaspool",
18248: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
18249: numchars => '5',
18250: );
18251: return %captcha_params;
18252: }
18253:
18254: sub check_captcha {
18255: my ($captcha_chk,$captcha_error);
18256: my $code = $env{'form.code'};
18257: my $md5sum = $env{'form.crypt'};
18258: my %captcha_params = &captcha_settings();
18259: my $captcha = Authen::Captcha->new(
18260: output_folder => $captcha_params{'output_dir'},
18261: data_folder => $captcha_params{'db_dir'},
18262: );
1.1075.2.26 raeburn 18263: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 18264: my %captcha_hash = (
18265: 0 => 'Code not checked (file error)',
18266: -1 => 'Failed: code expired',
18267: -2 => 'Failed: invalid code (not in database)',
18268: -3 => 'Failed: invalid code (code does not match crypt)',
18269: );
18270: if ($captcha_chk != 1) {
18271: $captcha_error = $captcha_hash{$captcha_chk}
18272: }
18273: return ($captcha_chk,$captcha_error);
18274: }
18275:
18276: sub create_recaptcha {
1.1075.2.107 raeburn 18277: my ($pubkey,$version) = @_;
18278: if ($version >= 2) {
1.1075.2.158 raeburn 18279: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
18280: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1075.2.107 raeburn 18281: } else {
18282: my $use_ssl;
18283: if ($ENV{'SERVER_PORT'} == 443) {
18284: $use_ssl = 1;
18285: }
18286: my $captcha = Captcha::reCAPTCHA->new;
18287: return $captcha->get_options_setter({theme => 'white'})."\n".
18288: $captcha->get_html($pubkey,undef,$use_ssl).
18289: &mt('If the text is hard to read, [_1] will replace them.',
18290: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
18291: '<br /><br />';
18292: }
1.1075.2.14 raeburn 18293: }
18294:
18295: sub check_recaptcha {
1.1075.2.107 raeburn 18296: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 18297: my $captcha_chk;
1.1075.2.150 raeburn 18298: my $ip = &Apache::lonnet::get_requestor_ip();
1.1075.2.107 raeburn 18299: if ($version >= 2) {
18300: my $ua = LWP::UserAgent->new;
18301: $ua->timeout(10);
18302: my %info = (
18303: secret => $privkey,
18304: response => $env{'form.g-recaptcha-response'},
1.1075.2.150 raeburn 18305: remoteip => $ip,
1.1075.2.107 raeburn 18306: );
18307: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
18308: if ($response->is_success) {
18309: my $data = JSON::DWIW->from_json($response->decoded_content);
18310: if (ref($data) eq 'HASH') {
18311: if ($data->{'success'}) {
18312: $captcha_chk = 1;
18313: }
18314: }
18315: }
18316: } else {
18317: my $captcha = Captcha::reCAPTCHA->new;
18318: my $captcha_result =
18319: $captcha->check_answer(
18320: $privkey,
1.1075.2.150 raeburn 18321: $ip,
1.1075.2.107 raeburn 18322: $env{'form.recaptcha_challenge_field'},
18323: $env{'form.recaptcha_response_field'},
18324: );
18325: if ($captcha_result->{is_valid}) {
18326: $captcha_chk = 1;
18327: }
1.1075.2.14 raeburn 18328: }
18329: return $captcha_chk;
18330: }
18331:
1.1075.2.64 raeburn 18332: sub emailusername_info {
1.1075.2.103 raeburn 18333: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 18334: my %titles = &Apache::lonlocal::texthash (
18335: lastname => 'Last Name',
18336: firstname => 'First Name',
18337: institution => 'School/college/university',
18338: location => "School's city, state/province, country",
18339: web => "School's web address",
18340: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 18341: id => 'Student/Employee ID',
1.1075.2.64 raeburn 18342: );
18343: return (\@fields,\%titles);
18344: }
18345:
1.1075.2.56 raeburn 18346: sub cleanup_html {
18347: my ($incoming) = @_;
18348: my $outgoing;
18349: if ($incoming ne '') {
18350: $outgoing = $incoming;
18351: $outgoing =~ s/;/;/g;
18352: $outgoing =~ s/\#/#/g;
18353: $outgoing =~ s/\&/&/g;
18354: $outgoing =~ s/</</g;
18355: $outgoing =~ s/>/>/g;
18356: $outgoing =~ s/\(/(/g;
18357: $outgoing =~ s/\)/)/g;
18358: $outgoing =~ s/"/"/g;
18359: $outgoing =~ s/'/'/g;
18360: $outgoing =~ s/\$/$/g;
18361: $outgoing =~ s{/}{/}g;
18362: $outgoing =~ s/=/=/g;
18363: $outgoing =~ s/\\/\/g
18364: }
18365: return $outgoing;
18366: }
18367:
1.1075.2.74 raeburn 18368: # Checks for critical messages and returns a redirect url if one exists.
18369: # $interval indicates how often to check for messages.
1.1075.2.161. .1(raebu 18370:21): # $context is the calling context -- roles, grades, contents, menu or flip.
1.1075.2.74 raeburn 18371: sub critical_redirect {
1.1075.2.161. .1(raebu 18372:21): my ($interval,$context) = @_;
1.1075.2.158 raeburn 18373: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
18374: return ();
18375: }
1.1075.2.74 raeburn 18376: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1075.2.161. .1(raebu 18377:21): if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
18378:21): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18379:21): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
.4(raebu 18380:22): my $blocked = &blocking_status('alert',undef,$cnum,$cdom,undef,1);
.1(raebu 18381:21): if ($blocked) {
18382:21): my $checkrole = "cm./$cdom/$cnum";
18383:21): if ($env{'request.course.sec'} ne '') {
18384:21): $checkrole .= "/$env{'request.course.sec'}";
18385:21): }
18386:21): unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
18387:21): ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
18388:21): return;
18389:21): }
18390:21): }
18391:21): }
1.1075.2.74 raeburn 18392: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
18393: $env{'user.name'});
18394: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
18395: my $redirecturl;
18396: if ($what[0]) {
1.1075.2.158 raeburn 18397: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1075.2.74 raeburn 18398: $redirecturl='/adm/email?critical=display';
18399: my $url=&Apache::lonnet::absolute_url().$redirecturl;
18400: return (1, $url);
18401: }
18402: }
18403: }
18404: return ();
18405: }
18406:
1.1075.2.64 raeburn 18407: # Use:
18408: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
18409: #
18410: ##################################################
18411: # password associated functions #
18412: ##################################################
18413: sub des_keys {
18414: # Make a new key for DES encryption.
18415: # Each key has two parts which are returned separately.
18416: # Please note: Each key must be passed through the &hex function
18417: # before it is output to the web browser. The hex versions cannot
18418: # be used to decrypt.
18419: my @hexstr=('0','1','2','3','4','5','6','7',
18420: '8','9','a','b','c','d','e','f');
18421: my $lkey='';
18422: for (0..7) {
18423: $lkey.=$hexstr[rand(15)];
18424: }
18425: my $ukey='';
18426: for (0..7) {
18427: $ukey.=$hexstr[rand(15)];
18428: }
18429: return ($lkey,$ukey);
18430: }
18431:
18432: sub des_decrypt {
18433: my ($key,$cyphertext) = @_;
18434: my $keybin=pack("H16",$key);
18435: my $cypher;
18436: if ($Crypt::DES::VERSION>=2.03) {
18437: $cypher=new Crypt::DES $keybin;
18438: } else {
18439: $cypher=new DES $keybin;
18440: }
1.1075.2.106 raeburn 18441: my $plaintext='';
18442: my $cypherlength = length($cyphertext);
18443: my $numchunks = int($cypherlength/32);
18444: for (my $j=0; $j<$numchunks; $j++) {
18445: my $start = $j*32;
18446: my $cypherblock = substr($cyphertext,$start,32);
18447: my $chunk =
18448: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
18449: $chunk .=
18450: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
18451: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
18452: $plaintext .= $chunk;
18453: }
1.1075.2.64 raeburn 18454: return $plaintext;
18455: }
18456:
1.1075.2.161. .1(raebu 18457:21): sub get_requested_shorturls {
18458:21): my ($cdom,$cnum,$navmap) = @_;
18459:21): return unless (ref($navmap));
18460:21): my ($numnew,$errors);
18461:21): my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
18462:21): if (@toshorten) {
18463:21): my (%maps,%resources,%titles);
18464:21): &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
18465:21): 'shorturls',$cdom,$cnum);
18466:21): if (keys(%resources)) {
18467:21): my %tocreate;
18468:21): foreach my $item (sort {$a <=> $b} (@toshorten)) {
18469:21): my $symb = $resources{$item};
18470:21): if ($symb) {
18471:21): $tocreate{$cnum.'&'.$symb} = 1;
18472:21): }
18473:21): }
18474:21): if (keys(%tocreate)) {
18475:21): ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
18476:21): \%tocreate);
18477:21): }
18478:21): }
18479:21): }
18480:21): return ($numnew,$errors);
18481:21): }
18482:21):
18483:21): sub make_short_symbs {
18484:21): my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
18485:21): my ($numnew,@errors);
18486:21): if (ref($tocreateref) eq 'HASH') {
18487:21): my %tocreate = %{$tocreateref};
18488:21): if (keys(%tocreate)) {
18489:21): my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
18490:21): my $su = Short::URL->new(no_vowels => 1);
18491:21): my $init = '';
18492:21): my (%newunique,%addcourse,%courseonly,%failed);
18493:21): # get lock on tiny db
18494:21): my $now = time;
18495:21): if ($lockuser eq '') {
18496:21): $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
18497:21): }
18498:21): my $lockhash = {
18499:21): "lock\0$now" => $lockuser,
18500:21): };
18501:21): my $tries = 0;
18502:21): my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18503:21): my ($code,$error);
18504:21): while (($gotlock ne 'ok') && ($tries<3)) {
18505:21): $tries ++;
18506:21): sleep 1;
18507:21): $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18508:21): }
18509:21): if ($gotlock eq 'ok') {
18510:21): $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
18511:21): \%addcourse,\%courseonly,\%failed);
18512:21): if (keys(%failed)) {
18513:21): my $numfailed = scalar(keys(%failed));
18514:21): push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
18515:21): }
18516:21): if (keys(%newunique)) {
18517:21): my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
18518:21): if ($putres eq 'ok') {
18519:21): $numnew = scalar(keys(%newunique));
18520:21): my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
18521:21): unless ($newputres eq 'ok') {
18522:21): push(@errors,&mt('error: could not store course look-up of short URLs'));
18523:21): }
18524:21): } else {
18525:21): push(@errors,&mt('error: could not store unique six character URLs'));
18526:21): }
18527:21): }
18528:21): my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
18529:21): unless ($dellockres eq 'ok') {
18530:21): push(@errors,&mt('error: could not release lockfile'));
18531:21): }
18532:21): } else {
18533:21): push(@errors,&mt('error: could not obtain lockfile'));
18534:21): }
18535:21): if (keys(%courseonly)) {
18536:21): my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
18537:21): if ($result ne 'ok') {
18538:21): push(@errors,&mt('error: could not update course look-up of short URLs'));
18539:21): }
18540:21): }
18541:21): }
18542:21): }
18543:21): return ($numnew,\@errors);
18544:21): }
18545:21):
18546:21): sub shorten_symbs {
18547:21): my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
18548:21): return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
18549:21): (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
18550:21): (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
18551:21): my (%possibles,%collisions);
18552:21): foreach my $key (keys(%{$tocreate})) {
18553:21): my $num = String::CRC32::crc32($key);
18554:21): my $tiny = $su->encode($num,$init);
18555:21): if ($tiny) {
18556:21): $possibles{$tiny} = $key;
18557:21): }
18558:21): }
18559:21): if (!$init) {
18560:21): $init = 1;
18561:21): } else {
18562:21): $init ++;
18563:21): }
18564:21): if (keys(%possibles)) {
18565:21): my @posstiny = keys(%possibles);
18566:21): my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
18567:21): my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
18568:21): if (keys(%currtiny)) {
18569:21): foreach my $key (keys(%currtiny)) {
18570:21): next if ($currtiny{$key} eq '');
18571:21): if ($currtiny{$key} eq $possibles{$key}) {
18572:21): my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
18573:21): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18574:21): $courseonly->{$tsymb} = $key;
18575:21): }
18576:21): } else {
18577:21): $collisions{$possibles{$key}} = 1;
18578:21): }
18579:21): delete($possibles{$key});
18580:21): }
18581:21): }
18582:21): foreach my $key (keys(%possibles)) {
18583:21): $newunique->{$key} = $possibles{$key};
18584:21): my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
18585:21): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18586:21): $addcourse->{$tsymb} = $key;
18587:21): }
18588:21): }
18589:21): }
18590:21): if (keys(%collisions)) {
18591:21): if ($init <5) {
18592:21): if (!$init) {
18593:21): $init = 1;
18594:21): } else {
18595:21): $init ++;
18596:21): }
18597:21): $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
18598:21): $newunique,$addcourse,$courseonly,$failed);
18599:21): } else {
18600:21): foreach my $key (keys(%collisions)) {
18601:21): $failed->{$key} = 1;
18602:21): $failed->{$key} = 1;
18603:21): }
18604:21): }
18605:21): }
18606:21): return $init;
18607:21): }
18608:21):
1.1075.2.135 raeburn 18609: sub is_nonframeable {
18610: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
18611: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
18612: return if (($remprotocol eq '') || ($remhost eq ''));
18613:
18614: $remprotocol = lc($remprotocol);
18615: $remhost = lc($remhost);
18616: my $remport = 80;
18617: if ($remprotocol eq 'https') {
18618: $remport = 443;
18619: }
18620: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
18621: if ($cached) {
18622: unless ($nocache) {
18623: if ($result) {
18624: return 1;
18625: } else {
18626: return 0;
18627: }
18628: }
18629: }
18630: my $uselink;
18631: my $request = new HTTP::Request('HEAD',$url);
1.1075.2.142 raeburn 18632: my $ua = LWP::UserAgent->new;
18633: $ua->timeout(5);
18634: my $response=$ua->request($request);
1.1075.2.135 raeburn 18635: if ($response->is_success()) {
18636: my $secpolicy = lc($response->header('content-security-policy'));
18637: my $xframeop = lc($response->header('x-frame-options'));
18638: $secpolicy =~ s/^\s+|\s+$//g;
18639: $xframeop =~ s/^\s+|\s+$//g;
18640: if (($secpolicy ne '') || ($xframeop ne '')) {
18641: my $remotehost = $remprotocol.'://'.$remhost;
18642: my ($origin,$protocol,$port);
18643: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
18644: $port = $ENV{'SERVER_PORT'};
18645: } else {
18646: $port = 80;
18647: }
18648: if ($absolute eq '') {
18649: $protocol = 'http:';
18650: if ($port == 443) {
18651: $protocol = 'https:';
18652: }
18653: $origin = $protocol.'//'.lc($hostname);
18654: } else {
18655: $origin = lc($absolute);
18656: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
18657: }
18658: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
18659: my $framepolicy = $1;
18660: $framepolicy =~ s/^\s+|\s+$//g;
18661: my @policies = split(/\s+/,$framepolicy);
18662: if (@policies) {
18663: if (grep(/^\Q'none'\E$/,@policies)) {
18664: $uselink = 1;
18665: } else {
18666: $uselink = 1;
18667: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
18668: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
18669: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
18670: undef($uselink);
18671: }
18672: if ($uselink) {
18673: if (grep(/^\Q'self'\E$/,@policies)) {
18674: if (($origin ne '') && ($remotehost eq $origin)) {
18675: undef($uselink);
18676: }
18677: }
18678: }
18679: if ($uselink) {
18680: my @possok;
18681: if ($ip ne '') {
18682: push(@possok,$ip);
18683: }
18684: my $hoststr = '';
18685: foreach my $part (reverse(split(/\./,$hostname))) {
18686: if ($hoststr eq '') {
18687: $hoststr = $part;
18688: } else {
18689: $hoststr = "$part.$hoststr";
18690: }
18691: if ($hoststr eq $hostname) {
18692: push(@possok,$hostname);
18693: } else {
18694: push(@possok,"*.$hoststr");
18695: }
18696: }
18697: if (@possok) {
18698: foreach my $poss (@possok) {
18699: last if (!$uselink);
18700: foreach my $policy (@policies) {
18701: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
18702: undef($uselink);
18703: last;
18704: }
18705: }
18706: }
18707: }
18708: }
18709: }
18710: }
18711: } elsif ($xframeop ne '') {
18712: $uselink = 1;
18713: my @policies = split(/\s*,\s*/,$xframeop);
18714: if (@policies) {
18715: unless (grep(/^deny$/,@policies)) {
18716: if ($origin ne '') {
18717: if (grep(/^sameorigin$/,@policies)) {
18718: if ($remotehost eq $origin) {
18719: undef($uselink);
18720: }
18721: }
18722: if ($uselink) {
18723: foreach my $policy (@policies) {
18724: if ($policy =~ /^allow-from\s*(.+)$/) {
18725: my $allowfrom = $1;
18726: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
18727: undef($uselink);
18728: last;
18729: }
18730: }
18731: }
18732: }
18733: }
18734: }
18735: }
18736: }
18737: }
18738: }
18739: if ($nocache) {
18740: if ($cached) {
18741: my $devalidate;
18742: if ($uselink && !$result) {
18743: $devalidate = 1;
18744: } elsif (!$uselink && $result) {
18745: $devalidate = 1;
18746: }
18747: if ($devalidate) {
18748: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
18749: }
18750: }
18751: } else {
18752: if ($uselink) {
18753: $result = 1;
18754: } else {
18755: $result = 0;
18756: }
18757: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
18758: }
18759: return $uselink;
18760: }
18761:
1.1075.2.161. .1(raebu 18762:21): sub page_menu {
18763:21): my ($menucolls,$menunum) = @_;
18764:21): my %menu;
18765:21): foreach my $item (split(/;/,$menucolls)) {
18766:21): my ($num,$value) = split(/\%/,$item);
18767:21): if ($num eq $menunum) {
18768:21): my @entries = split(/\&/,$value);
18769:21): foreach my $entry (@entries) {
18770:21): my ($name,$fields) = split(/=/,$entry);
18771:21): if (($name eq 'top') || ($name eq 'inline') || ($name eq 'foot') || ($name eq 'main')) {
18772:21): $menu{$name} = $fields;
18773:21): } else {
18774:21): my @shown;
18775:21): if ($fields =~ /,/) {
18776:21): @shown = split(/,/,$fields);
18777:21): } else {
18778:21): @shown = ($fields);
18779:21): }
18780:21): if (@shown) {
18781:21): foreach my $field (@shown) {
18782:21): next if ($field eq '');
18783:21): $menu{$field} = 1;
18784:21): }
18785:21): }
18786:21): }
18787:21): }
18788:21): }
18789:21): }
18790:21): return %menu;
18791:21): }
18792:21):
1.112 bowersj2 18793: 1;
18794: __END__;
1.41 ng 18795:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>