Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.141.2.9
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.141. .9(raebu 4:20): # $Id: loncommon.pm,v 1.1075.2.141.2.8 2020/09/29 19:02:00 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.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.135 raeburn 74: use HTTP::Request;
1.657 raeburn 75: use DateTime::TimeZone;
1.1075.2.102 raeburn 76: use DateTime::Locale;
1.1075.2.94 raeburn 77: use Encode();
1.1075.2.14 raeburn 78: use Authen::Captcha;
79: use Captcha::reCAPTCHA;
1.1075.2.107 raeburn 80: use JSON::DWIW;
81: use LWP::UserAgent;
1.1075.2.64 raeburn 82: use Crypt::DES;
83: use DynaLoader; # for Crypt::DES version
1.1075.2.128 raeburn 84: use File::Copy();
85: use File::Path();
1.1075.2.141. .1(raebu 86:20): use String::CRC32();
87:20): use Short::URL();
1.117 www 88:
1.517 raeburn 89: # ---------------------------------------------- Designs
90: use vars qw(%defaultdesign);
91:
1.22 www 92: my $readit;
93:
1.517 raeburn 94:
1.157 matthew 95: ##
96: ## Global Variables
97: ##
1.46 matthew 98:
1.643 foxr 99:
100: # ----------------------------------------------- SSI with retries:
101: #
102:
103: =pod
104:
1.648 raeburn 105: =head1 Server Side include with retries:
1.643 foxr 106:
107: =over 4
108:
1.648 raeburn 109: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 110:
111: Performs an ssi with some number of retries. Retries continue either
112: until the result is ok or until the retry count supplied by the
113: caller is exhausted.
114:
115: Inputs:
1.648 raeburn 116:
117: =over 4
118:
1.643 foxr 119: resource - Identifies the resource to insert.
1.648 raeburn 120:
1.643 foxr 121: retries - Count of the number of retries allowed.
1.648 raeburn 122:
1.643 foxr 123: form - Hash that identifies the rendering options.
124:
1.648 raeburn 125: =back
126:
127: Returns:
128:
129: =over 4
130:
1.643 foxr 131: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 132:
1.643 foxr 133: response - The response from the last attempt (which may or may not have been successful.
134:
1.648 raeburn 135: =back
136:
137: =back
138:
1.643 foxr 139: =cut
140:
141: sub ssi_with_retries {
142: my ($resource, $retries, %form) = @_;
143:
144:
145: my $ok = 0; # True if we got a good response.
146: my $content;
147: my $response;
148:
149: # Try to get the ssi done. within the retries count:
150:
151: do {
152: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
153: $ok = $response->is_success;
1.650 www 154: if (!$ok) {
155: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
156: }
1.643 foxr 157: $retries--;
158: } while (!$ok && ($retries > 0));
159:
160: if (!$ok) {
161: $content = ''; # On error return an empty content.
162: }
163: return ($content, $response);
164:
165: }
166:
167:
168:
1.20 www 169: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 170: my %language;
1.124 www 171: my %supported_language;
1.1048 foxr 172: my %latex_language; # For choosing hyphenation in <transl..>
173: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 174: my %cprtag;
1.192 taceyjo1 175: my %scprtag;
1.351 www 176: my %fe; my %fd; my %fm;
1.41 ng 177: my %category_extensions;
1.12 harris41 178:
1.46 matthew 179: # ---------------------------------------------- Thesaurus variables
1.144 matthew 180: #
181: # %Keywords:
182: # A hash used by &keyword to determine if a word is considered a keyword.
183: # $thesaurus_db_file
184: # Scalar containing the full path to the thesaurus database.
1.46 matthew 185:
186: my %Keywords;
187: my $thesaurus_db_file;
188:
1.144 matthew 189: #
190: # Initialize values from language.tab, copyright.tab, filetypes.tab,
191: # thesaurus.tab, and filecategories.tab.
192: #
1.18 www 193: BEGIN {
1.46 matthew 194: # Variable initialization
195: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
196: #
1.22 www 197: unless ($readit) {
1.12 harris41 198: # ------------------------------------------------------------------- languages
199: {
1.158 raeburn 200: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
201: '/language.tab';
1.1075.2.128 raeburn 202: if ( open(my $fh,'<',$langtabfile) ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
1.1048 foxr 206: my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 207: $language{$key}=$val.' - '.$enc;
208: if ($sup) {
209: $supported_language{$key}=$sup;
210: }
1.1048 foxr 211: if ($latex) {
212: $latex_language_bykey{$key} = $latex;
213: $latex_language{$two} = $latex;
214: }
1.158 raeburn 215: }
216: close($fh);
217: }
1.12 harris41 218: }
219: # ------------------------------------------------------------------ copyrights
220: {
1.158 raeburn 221: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
222: '/copyright.tab';
1.1075.2.128 raeburn 223: if ( open (my $fh,'<',$copyrightfile) ) {
1.356 albertel 224: while (my $line = <$fh>) {
225: next if ($line=~/^\#/);
226: chomp($line);
227: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 228: $cprtag{$key}=$val;
229: }
230: close($fh);
231: }
1.12 harris41 232: }
1.351 www 233: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 234: {
235: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
236: '/source_copyright.tab';
1.1075.2.128 raeburn 237: if ( open (my $fh,'<',$sourcecopyrightfile) ) {
1.356 albertel 238: while (my $line = <$fh>) {
239: next if ($line =~ /^\#/);
240: chomp($line);
241: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 242: $scprtag{$key}=$val;
243: }
244: close($fh);
245: }
246: }
1.63 www 247:
1.517 raeburn 248: # -------------------------------------------------------------- default domain designs
1.63 www 249: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 250: my $designfile = $designdir.'/default.tab';
1.1075.2.128 raeburn 251: if ( open (my $fh,'<',$designfile) ) {
1.517 raeburn 252: while (my $line = <$fh>) {
253: next if ($line =~ /^\#/);
254: chomp($line);
255: my ($key,$val)=(split(/\=/,$line));
256: if ($val) { $defaultdesign{$key}=$val; }
257: }
258: close($fh);
1.63 www 259: }
260:
1.15 harris41 261: # ------------------------------------------------------------- file categories
262: {
1.158 raeburn 263: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
264: '/filecategories.tab';
1.1075.2.128 raeburn 265: if ( open (my $fh,'<',$categoryfile) ) {
1.356 albertel 266: while (my $line = <$fh>) {
267: next if ($line =~ /^\#/);
268: chomp($line);
269: my ($extension,$category)=(split(/\s+/,$line,2));
1.1075.2.119 raeburn 270: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 271: }
272: close($fh);
273: }
274:
1.15 harris41 275: }
1.12 harris41 276: # ------------------------------------------------------------------ file types
277: {
1.158 raeburn 278: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
279: '/filetypes.tab';
1.1075.2.128 raeburn 280: if ( open (my $fh,'<',$typesfile) ) {
1.356 albertel 281: while (my $line = <$fh>) {
282: next if ($line =~ /^\#/);
283: chomp($line);
284: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 285: if ($descr ne '') {
286: $fe{$ending}=lc($emb);
287: $fd{$ending}=$descr;
1.351 www 288: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 289: }
290: }
291: close($fh);
292: }
1.12 harris41 293: }
1.22 www 294: &Apache::lonnet::logthis(
1.705 tempelho 295: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 296: $readit=1;
1.46 matthew 297: } # end of unless($readit)
1.32 matthew 298:
299: }
1.112 bowersj2 300:
1.42 matthew 301: ###############################################################
302: ## HTML and Javascript Helper Functions ##
303: ###############################################################
304:
305: =pod
306:
1.112 bowersj2 307: =head1 HTML and Javascript Functions
1.42 matthew 308:
1.112 bowersj2 309: =over 4
310:
1.648 raeburn 311: =item * &browser_and_searcher_javascript()
1.112 bowersj2 312:
313: X<browsing, javascript>X<searching, javascript>Returns a string
314: containing javascript with two functions, C<openbrowser> and
315: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
316: tags.
1.42 matthew 317:
1.648 raeburn 318: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 319:
320: inputs: formname, elementname, only, omit
321:
322: formname and elementname indicate the name of the html form and name of
323: the element that the results of the browsing selection are to be placed in.
324:
325: Specifying 'only' will restrict the browser to displaying only files
1.185 www 326: with the given extension. Can be a comma separated list.
1.42 matthew 327:
328: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 329: with the given extension. Can be a comma separated list.
1.42 matthew 330:
1.648 raeburn 331: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 332:
333: Inputs: formname, elementname
334:
335: formname and elementname specify the name of the html form and the name
336: of the element the selection from the search results will be placed in.
1.542 raeburn 337:
1.42 matthew 338: =cut
339:
340: sub browser_and_searcher_javascript {
1.199 albertel 341: my ($mode)=@_;
342: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 343: my $resurl=&escape_single(&lastresurl());
1.42 matthew 344: return <<END;
1.219 albertel 345: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 346: var editbrowser = null;
1.135 albertel 347: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 348: var url = '$resurl/?';
1.42 matthew 349: if (editbrowser == null) {
350: url += 'launch=1&';
351: }
352: url += 'catalogmode=interactive&';
1.199 albertel 353: url += 'mode=$mode&';
1.611 albertel 354: url += 'inhibitmenu=yes&';
1.42 matthew 355: url += 'form=' + formname + '&';
356: if (only != null) {
357: url += 'only=' + only + '&';
1.217 albertel 358: } else {
359: url += 'only=&';
360: }
1.42 matthew 361: if (omit != null) {
362: url += 'omit=' + omit + '&';
1.217 albertel 363: } else {
364: url += 'omit=&';
365: }
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Browser';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editbrowser = open(url,title,options,'1');
376: editbrowser.focus();
377: }
378: var editsearcher;
1.135 albertel 379: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 380: var url = '/adm/searchcat?';
381: if (editsearcher == null) {
382: url += 'launch=1&';
383: }
384: url += 'catalogmode=interactive&';
1.199 albertel 385: url += 'mode=$mode&';
1.42 matthew 386: url += 'form=' + formname + '&';
1.135 albertel 387: if (titleelement != null) {
388: url += 'titleelement=' + titleelement + '&';
1.217 albertel 389: } else {
390: url += 'titleelement=&';
391: }
1.42 matthew 392: url += 'element=' + elementname + '';
393: var title = 'Search';
1.435 albertel 394: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 395: options += ',width=700,height=600';
396: editsearcher = open(url,title,options,'1');
397: editsearcher.focus();
398: }
1.219 albertel 399: // END LON-CAPA Internal -->
1.42 matthew 400: END
1.170 www 401: }
402:
403: sub lastresurl {
1.258 albertel 404: if ($env{'environment.lastresurl'}) {
405: return $env{'environment.lastresurl'}
1.170 www 406: } else {
407: return '/res';
408: }
409: }
410:
411: sub storeresurl {
412: my $resurl=&Apache::lonnet::clutter(shift);
413: unless ($resurl=~/^\/res/) { return 0; }
414: $resurl=~s/\/$//;
415: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 416: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 417: return 1;
1.42 matthew 418: }
419:
1.74 www 420: sub studentbrowser_javascript {
1.111 www 421: unless (
1.258 albertel 422: (($env{'request.course.id'}) &&
1.302 albertel 423: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
424: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
425: '/'.$env{'request.course.sec'})
426: ))
1.258 albertel 427: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 428: ) { return ''; }
1.74 www 429: return (<<'ENDSTDBRW');
1.776 bisitz 430: <script type="text/javascript" language="Javascript">
1.824 bisitz 431: // <![CDATA[
1.74 www 432: var stdeditbrowser;
1.1075.2.141. .3(raebu 433:20): function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadv) {
1.74 www 434: var url = '/adm/pickstudent?';
435: var filter;
1.558 albertel 436: if (!ignorefilter) {
437: eval('filter=document.'+formname+'.'+uname+'.value;');
438: }
1.74 www 439: if (filter != null) {
440: if (filter != '') {
441: url += 'filter='+filter+'&';
442: }
443: }
444: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 445: '&udomelement='+udom+
446: '&clicker='+clicker;
1.111 www 447: if (roleflag) { url+="&roles=1"; }
1.1075.2.141. .3(raebu 448:20): if (courseadv == 'condition') {
449:20): if (document.getElementById('courseadv')) {
450:20): courseadv = document.getElementById('courseadv').value;
451:20): }
452:20): }
453:20): if ((courseadv == 'only') || (courseadv == 'none')) { url+="&courseadv="+courseadv; }
1.102 www 454: var title = 'Student_Browser';
1.74 www 455: var options = 'scrollbars=1,resizable=1,menubar=0';
456: options += ',width=700,height=600';
457: stdeditbrowser = open(url,title,options,'1');
458: stdeditbrowser.focus();
459: }
1.824 bisitz 460: // ]]>
1.74 www 461: </script>
462: ENDSTDBRW
463: }
1.42 matthew 464:
1.1003 www 465: sub resourcebrowser_javascript {
466: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 467: return (<<'ENDRESBRW');
1.1003 www 468: <script type="text/javascript" language="Javascript">
469: // <![CDATA[
470: var reseditbrowser;
1.1004 www 471: function openresbrowser(formname,reslink) {
1.1005 www 472: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 473: var title = 'Resource_Browser';
474: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 475: options += ',width=700,height=500';
1.1004 www 476: reseditbrowser = open(url,title,options,'1');
477: reseditbrowser.focus();
1.1003 www 478: }
479: // ]]>
480: </script>
1.1004 www 481: ENDRESBRW
1.1003 www 482: }
483:
1.74 www 484: sub selectstudent_link {
1.1075.2.141. .3(raebu 485:20): my ($form,$unameele,$udomele,$courseadv,$clickerid)=@_;
1.999 www 486: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
487: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
488: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 489: if ($env{'request.course.id'}) {
1.302 albertel 490: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
491: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
492: '/'.$env{'request.course.sec'})) {
1.111 www 493: return '';
494: }
1.999 www 495: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.1075.2.141. .3(raebu 496:20): if ($courseadv eq 'only') {
497:20): $callargs .= ",'',1,'$courseadv'";
498:20): } elsif ($courseadv eq 'none') {
499:20): $callargs .= ",'','','$courseadv'";
500:20): } elsif ($courseadv eq 'condition') {
501:20): $callargs .= ",'','','$courseadv'";
1.793 raeburn 502: }
503: return '<span class="LC_nobreak">'.
504: '<a href="javascript:openstdbrowser('.$callargs.');">'.
505: &mt('Select User').'</a></span>';
1.74 www 506: }
1.258 albertel 507: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 508: $callargs .= ",'',1";
1.793 raeburn 509: return '<span class="LC_nobreak">'.
510: '<a href="javascript:openstdbrowser('.$callargs.');">'.
511: &mt('Select User').'</a></span>';
1.111 www 512: }
513: return '';
1.91 www 514: }
515:
1.1004 www 516: sub selectresource_link {
517: my ($form,$reslink,$arg)=@_;
518:
519: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
520: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
521: unless ($env{'request.course.id'}) { return $arg; }
522: return '<span class="LC_nobreak">'.
523: '<a href="javascript:openresbrowser('.$callargs.');">'.
524: $arg.'</a></span>';
525: }
526:
527:
528:
1.653 raeburn 529: sub authorbrowser_javascript {
530: return <<"ENDAUTHORBRW";
1.776 bisitz 531: <script type="text/javascript" language="JavaScript">
1.824 bisitz 532: // <![CDATA[
1.653 raeburn 533: var stdeditbrowser;
534:
535: function openauthorbrowser(formname,udom) {
536: var url = '/adm/pickauthor?';
537: url += 'form='+formname+'&roledom='+udom;
538: var title = 'Author_Browser';
539: var options = 'scrollbars=1,resizable=1,menubar=0';
540: options += ',width=700,height=600';
541: stdeditbrowser = open(url,title,options,'1');
542: stdeditbrowser.focus();
543: }
544:
1.824 bisitz 545: // ]]>
1.653 raeburn 546: </script>
547: ENDAUTHORBRW
548: }
549:
1.91 www 550: sub coursebrowser_javascript {
1.1075.2.31 raeburn 551: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1075.2.95 raeburn 552: $credits_element,$instcode) = @_;
1.932 raeburn 553: my $wintitle = 'Course_Browser';
1.931 raeburn 554: if ($crstype eq 'Community') {
1.932 raeburn 555: $wintitle = 'Community_Browser';
1.909 raeburn 556: }
1.876 raeburn 557: my $id_functions = &javascript_index_functions();
558: my $output = '
1.776 bisitz 559: <script type="text/javascript" language="JavaScript">
1.824 bisitz 560: // <![CDATA[
1.468 raeburn 561: var stdeditbrowser;'."\n";
1.876 raeburn 562:
563: $output .= <<"ENDSTDBRW";
1.909 raeburn 564: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 565: var url = '/adm/pickcourse?';
1.895 raeburn 566: var formid = getFormIdByName(formname);
1.876 raeburn 567: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 568: if (domainfilter != null) {
569: if (domainfilter != '') {
570: url += 'domainfilter='+domainfilter+'&';
571: }
572: }
1.91 www 573: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 574: '&cdomelement='+udom+
575: '&cnameelement='+desc;
1.468 raeburn 576: if (extra_element !=null && extra_element != '') {
1.594 raeburn 577: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 578: url += '&roleelement='+extra_element;
579: if (domainfilter == null || domainfilter == '') {
580: url += '&domainfilter='+extra_element;
581: }
1.234 raeburn 582: }
1.468 raeburn 583: else {
584: if (formname == 'portform') {
585: url += '&setroles='+extra_element;
1.800 raeburn 586: } else {
587: if (formname == 'rules') {
588: url += '&fixeddom='+extra_element;
589: }
1.468 raeburn 590: }
591: }
1.230 raeburn 592: }
1.909 raeburn 593: if (type != null && type != '') {
594: url += '&type='+type;
595: }
596: if (type_elem != null && type_elem != '') {
597: url += '&typeelement='+type_elem;
598: }
1.872 raeburn 599: if (formname == 'ccrs') {
600: var ownername = document.forms[formid].ccuname.value;
601: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1075.2.101 raeburn 602: url += '&cloner='+ownername+':'+ownerdom;
603: if (type == 'Course') {
604: url += '&crscode='+document.forms[formid].crscode.value;
605: }
1.1075.2.95 raeburn 606: }
607: if (formname == 'requestcrs') {
608: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 609: }
1.293 raeburn 610: if (multflag !=null && multflag != '') {
611: url += '&multiple='+multflag;
612: }
1.909 raeburn 613: var title = '$wintitle';
1.91 www 614: var options = 'scrollbars=1,resizable=1,menubar=0';
615: options += ',width=700,height=600';
616: stdeditbrowser = open(url,title,options,'1');
617: stdeditbrowser.focus();
618: }
1.876 raeburn 619: $id_functions
620: ENDSTDBRW
1.1075.2.31 raeburn 621: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
622: $output .= &setsec_javascript($sec_element,$formname,$role_element,
623: $credits_element);
1.876 raeburn 624: }
625: $output .= '
626: // ]]>
627: </script>';
628: return $output;
629: }
630:
631: sub javascript_index_functions {
632: return <<"ENDJS";
633:
634: function getFormIdByName(formname) {
635: for (var i=0;i<document.forms.length;i++) {
636: if (document.forms[i].name == formname) {
637: return i;
638: }
639: }
640: return -1;
641: }
642:
643: function getIndexByName(formid,item) {
644: for (var i=0;i<document.forms[formid].elements.length;i++) {
645: if (document.forms[formid].elements[i].name == item) {
646: return i;
647: }
648: }
649: return -1;
650: }
1.468 raeburn 651:
1.876 raeburn 652: function getDomainFromSelectbox(formname,udom) {
653: var userdom;
654: var formid = getFormIdByName(formname);
655: if (formid > -1) {
656: var domid = getIndexByName(formid,udom);
657: if (domid > -1) {
658: if (document.forms[formid].elements[domid].type == 'select-one') {
659: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
660: }
661: if (document.forms[formid].elements[domid].type == 'hidden') {
662: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 663: }
664: }
665: }
1.876 raeburn 666: return userdom;
667: }
668:
669: ENDJS
1.468 raeburn 670:
1.876 raeburn 671: }
672:
1.1017 raeburn 673: sub javascript_array_indexof {
1.1018 raeburn 674: return <<ENDJS;
1.1017 raeburn 675: <script type="text/javascript" language="JavaScript">
676: // <![CDATA[
677:
678: if (!Array.prototype.indexOf) {
679: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
680: "use strict";
681: if (this === void 0 || this === null) {
682: throw new TypeError();
683: }
684: var t = Object(this);
685: var len = t.length >>> 0;
686: if (len === 0) {
687: return -1;
688: }
689: var n = 0;
690: if (arguments.length > 0) {
691: n = Number(arguments[1]);
692: if (n !== n) { // shortcut for verifying if it's NaN
693: n = 0;
694: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
695: n = (n > 0 || -1) * Math.floor(Math.abs(n));
696: }
697: }
698: if (n >= len) {
699: return -1;
700: }
701: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
702: for (; k < len; k++) {
703: if (k in t && t[k] === searchElement) {
704: return k;
705: }
706: }
707: return -1;
708: }
709: }
710:
711: // ]]>
712: </script>
713:
714: ENDJS
715:
716: }
717:
1.876 raeburn 718: sub userbrowser_javascript {
719: my $id_functions = &javascript_index_functions();
720: return <<"ENDUSERBRW";
721:
1.888 raeburn 722: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 723: var url = '/adm/pickuser?';
724: var userdom = getDomainFromSelectbox(formname,udom);
725: if (userdom != null) {
726: if (userdom != '') {
727: url += 'srchdom='+userdom+'&';
728: }
729: }
730: url += 'form=' + formname + '&unameelement='+uname+
731: '&udomelement='+udom+
732: '&ulastelement='+ulast+
733: '&ufirstelement='+ufirst+
734: '&uemailelement='+uemail+
1.881 raeburn 735: '&hideudomelement='+hideudom+
736: '&coursedom='+crsdom;
1.888 raeburn 737: if ((caller != null) && (caller != undefined)) {
738: url += '&caller='+caller;
739: }
1.876 raeburn 740: var title = 'User_Browser';
741: var options = 'scrollbars=1,resizable=1,menubar=0';
742: options += ',width=700,height=600';
743: var stdeditbrowser = open(url,title,options,'1');
744: stdeditbrowser.focus();
745: }
746:
1.888 raeburn 747: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 748: var formid = getFormIdByName(formname);
749: if (formid > -1) {
1.888 raeburn 750: var unameid = getIndexByName(formid,uname);
1.876 raeburn 751: var domid = getIndexByName(formid,udom);
752: var hidedomid = getIndexByName(formid,origdom);
753: if (hidedomid > -1) {
754: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 755: var unameval = document.forms[formid].elements[unameid].value;
756: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
757: if (domid > -1) {
758: var slct = document.forms[formid].elements[domid];
759: if (slct.type == 'select-one') {
760: var i;
761: for (i=0;i<slct.length;i++) {
762: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
763: }
764: }
765: if (slct.type == 'hidden') {
766: slct.value = fixeddom;
1.876 raeburn 767: }
768: }
1.468 raeburn 769: }
770: }
771: }
1.876 raeburn 772: return;
773: }
774:
775: $id_functions
776: ENDUSERBRW
1.468 raeburn 777: }
778:
779: sub setsec_javascript {
1.1075.2.31 raeburn 780: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 781: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
782: $communityrolestr);
783: if ($role_element ne '') {
784: my @allroles = ('st','ta','ep','in','ad');
785: foreach my $crstype ('Course','Community') {
786: if ($crstype eq 'Community') {
787: foreach my $role (@allroles) {
788: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
789: }
790: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
791: } else {
792: foreach my $role (@allroles) {
793: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
794: }
795: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
796: }
797: }
798: $rolestr = '"'.join('","',@allroles).'"';
799: $courserolestr = '"'.join('","',@courserolenames).'"';
800: $communityrolestr = '"'.join('","',@communityrolenames).'"';
801: }
1.468 raeburn 802: my $setsections = qq|
803: function setSect(sectionlist) {
1.629 raeburn 804: var sectionsArray = new Array();
805: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
806: sectionsArray = sectionlist.split(",");
807: }
1.468 raeburn 808: var numSections = sectionsArray.length;
809: document.$formname.$sec_element.length = 0;
810: if (numSections == 0) {
811: document.$formname.$sec_element.multiple=false;
812: document.$formname.$sec_element.size=1;
813: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
814: } else {
815: if (numSections == 1) {
816: document.$formname.$sec_element.multiple=false;
817: document.$formname.$sec_element.size=1;
818: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
819: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
820: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
821: } else {
822: for (var i=0; i<numSections; i++) {
823: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
824: }
825: document.$formname.$sec_element.multiple=true
826: if (numSections < 3) {
827: document.$formname.$sec_element.size=numSections;
828: } else {
829: document.$formname.$sec_element.size=3;
830: }
831: document.$formname.$sec_element.options[0].selected = false
832: }
833: }
1.91 www 834: }
1.905 raeburn 835:
836: function setRole(crstype) {
1.468 raeburn 837: |;
1.905 raeburn 838: if ($role_element eq '') {
839: $setsections .= ' return;
840: }
841: ';
842: } else {
843: $setsections .= qq|
844: var elementLength = document.$formname.$role_element.length;
845: var allroles = Array($rolestr);
846: var courserolenames = Array($courserolestr);
847: var communityrolenames = Array($communityrolestr);
848: if (elementLength != undefined) {
849: if (document.$formname.$role_element.options[5].value == 'cc') {
850: if (crstype == 'Course') {
851: return;
852: } else {
853: allroles[5] = 'co';
854: for (var i=0; i<6; i++) {
855: document.$formname.$role_element.options[i].value = allroles[i];
856: document.$formname.$role_element.options[i].text = communityrolenames[i];
857: }
858: }
859: } else {
860: if (crstype == 'Community') {
861: return;
862: } else {
863: allroles[5] = 'cc';
864: for (var i=0; i<6; i++) {
865: document.$formname.$role_element.options[i].value = allroles[i];
866: document.$formname.$role_element.options[i].text = courserolenames[i];
867: }
868: }
869: }
870: }
871: return;
872: }
873: |;
874: }
1.1075.2.31 raeburn 875: if ($credits_element) {
876: $setsections .= qq|
877: function setCredits(defaultcredits) {
878: document.$formname.$credits_element.value = defaultcredits;
879: return;
880: }
881: |;
882: }
1.468 raeburn 883: return $setsections;
884: }
885:
1.91 www 886: sub selectcourse_link {
1.909 raeburn 887: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
888: $typeelement) = @_;
889: my $type = $selecttype;
1.871 raeburn 890: my $linktext = &mt('Select Course');
891: if ($selecttype eq 'Community') {
1.909 raeburn 892: $linktext = &mt('Select Community');
1.906 raeburn 893: } elsif ($selecttype eq 'Course/Community') {
894: $linktext = &mt('Select Course/Community');
1.909 raeburn 895: $type = '';
1.1019 raeburn 896: } elsif ($selecttype eq 'Select') {
897: $linktext = &mt('Select');
898: $type = '';
1.871 raeburn 899: }
1.787 bisitz 900: return '<span class="LC_nobreak">'
901: ."<a href='"
902: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
903: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 904: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 905: ."'>".$linktext.'</a>'
1.787 bisitz 906: .'</span>';
1.74 www 907: }
1.42 matthew 908:
1.653 raeburn 909: sub selectauthor_link {
910: my ($form,$udom)=@_;
911: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
912: &mt('Select Author').'</a>';
913: }
914:
1.876 raeburn 915: sub selectuser_link {
1.881 raeburn 916: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 917: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 918: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 919: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 920: ');">'.$linktext.'</a>';
1.876 raeburn 921: }
922:
1.273 raeburn 923: sub check_uncheck_jscript {
924: my $jscript = <<"ENDSCRT";
925: function checkAll(field) {
926: if (field.length > 0) {
927: for (i = 0; i < field.length; i++) {
1.1075.2.14 raeburn 928: if (!field[i].disabled) {
929: field[i].checked = true;
930: }
1.273 raeburn 931: }
932: } else {
1.1075.2.14 raeburn 933: if (!field.disabled) {
934: field.checked = true;
935: }
1.273 raeburn 936: }
937: }
938:
939: function uncheckAll(field) {
940: if (field.length > 0) {
941: for (i = 0; i < field.length; i++) {
942: field[i].checked = false ;
1.543 albertel 943: }
944: } else {
1.273 raeburn 945: field.checked = false ;
946: }
947: }
948: ENDSCRT
949: return $jscript;
950: }
951:
1.656 www 952: sub select_timezone {
1.1075.2.115 raeburn 953: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
954: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 955: if ($includeempty) {
956: $output .= '<option value=""';
957: if (($selected eq '') || ($selected eq 'local')) {
958: $output .= ' selected="selected" ';
959: }
960: $output .= '> </option>';
961: }
1.657 raeburn 962: my @timezones = DateTime::TimeZone->all_names;
963: foreach my $tzone (@timezones) {
964: $output.= '<option value="'.$tzone.'"';
965: if ($tzone eq $selected) {
966: $output.=' selected="selected"';
967: }
968: $output.=">$tzone</option>\n";
1.656 www 969: }
970: $output.="</select>";
971: return $output;
972: }
1.273 raeburn 973:
1.687 raeburn 974: sub select_datelocale {
1.1075.2.115 raeburn 975: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
976: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 977: if ($includeempty) {
978: $output .= '<option value=""';
979: if ($selected eq '') {
980: $output .= ' selected="selected" ';
981: }
982: $output .= '> </option>';
983: }
1.1075.2.102 raeburn 984: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 985: my (@possibles,%locale_names);
1.1075.2.102 raeburn 986: my @locales = DateTime::Locale->ids();
987: foreach my $id (@locales) {
988: if ($id ne '') {
989: my ($en_terr,$native_terr);
990: my $loc = DateTime::Locale->load($id);
991: if (ref($loc)) {
992: $en_terr = $loc->name();
993: $native_terr = $loc->native_name();
1.687 raeburn 994: if (grep(/^en$/,@languages) || !@languages) {
995: if ($en_terr ne '') {
996: $locale_names{$id} = '('.$en_terr.')';
997: } elsif ($native_terr ne '') {
998: $locale_names{$id} = $native_terr;
999: }
1000: } else {
1001: if ($native_terr ne '') {
1002: $locale_names{$id} = $native_terr.' ';
1003: } elsif ($en_terr ne '') {
1004: $locale_names{$id} = '('.$en_terr.')';
1005: }
1006: }
1.1075.2.94 raeburn 1007: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1075.2.102 raeburn 1008: push(@possibles,$id);
1.687 raeburn 1009: }
1010: }
1011: }
1012: foreach my $item (sort(@possibles)) {
1013: $output.= '<option value="'.$item.'"';
1014: if ($item eq $selected) {
1015: $output.=' selected="selected"';
1016: }
1017: $output.=">$item";
1018: if ($locale_names{$item} ne '') {
1.1075.2.94 raeburn 1019: $output.=' '.$locale_names{$item};
1.687 raeburn 1020: }
1021: $output.="</option>\n";
1022: }
1023: $output.="</select>";
1024: return $output;
1025: }
1026:
1.792 raeburn 1027: sub select_language {
1.1075.2.115 raeburn 1028: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1029: my %langchoices;
1030: if ($includeempty) {
1.1075.2.32 raeburn 1031: %langchoices = ('' => 'No language preference');
1.792 raeburn 1032: }
1033: foreach my $id (&languageids()) {
1034: my $code = &supportedlanguagecode($id);
1035: if ($code) {
1036: $langchoices{$code} = &plainlanguagedescription($id);
1037: }
1038: }
1.1075.2.32 raeburn 1039: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1075.2.115 raeburn 1040: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1041: }
1042:
1.42 matthew 1043: =pod
1.36 matthew 1044:
1.648 raeburn 1045: =item * &linked_select_forms(...)
1.36 matthew 1046:
1047: linked_select_forms returns a string containing a <script></script> block
1048: and html for two <select> menus. The select menus will be linked in that
1049: changing the value of the first menu will result in new values being placed
1050: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1051: order unless a defined order is provided.
1.36 matthew 1052:
1053: linked_select_forms takes the following ordered inputs:
1054:
1055: =over 4
1056:
1.112 bowersj2 1057: =item * $formname, the name of the <form> tag
1.36 matthew 1058:
1.112 bowersj2 1059: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1060:
1.112 bowersj2 1061: =item * $firstdefault, the default value for the first menu
1.36 matthew 1062:
1.112 bowersj2 1063: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1064:
1.112 bowersj2 1065: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1066:
1.112 bowersj2 1067: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1068:
1.609 raeburn 1069: =item * $menuorder, the order of values in the first menu
1070:
1.1075.2.31 raeburn 1071: =item * $onchangefirst, additional javascript call to execute for an onchange
1072: event for the first <select> tag
1073:
1074: =item * $onchangesecond, additional javascript call to execute for an onchange
1075: event for the second <select> tag
1076:
1.41 ng 1077: =back
1078:
1.36 matthew 1079: Below is an example of such a hash. Only the 'text', 'default', and
1080: 'select2' keys must appear as stated. keys(%menu) are the possible
1081: values for the first select menu. The text that coincides with the
1.41 ng 1082: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1083: and text for the second menu are given in the hash pointed to by
1084: $menu{$choice1}->{'select2'}.
1085:
1.112 bowersj2 1086: my %menu = ( A1 => { text =>"Choice A1" ,
1087: default => "B3",
1088: select2 => {
1089: B1 => "Choice B1",
1090: B2 => "Choice B2",
1091: B3 => "Choice B3",
1092: B4 => "Choice B4"
1.609 raeburn 1093: },
1094: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1095: },
1096: A2 => { text =>"Choice A2" ,
1097: default => "C2",
1098: select2 => {
1099: C1 => "Choice C1",
1100: C2 => "Choice C2",
1101: C3 => "Choice C3"
1.609 raeburn 1102: },
1103: order => ['C2','C1','C3'],
1.112 bowersj2 1104: },
1105: A3 => { text =>"Choice A3" ,
1106: default => "D6",
1107: select2 => {
1108: D1 => "Choice D1",
1109: D2 => "Choice D2",
1110: D3 => "Choice D3",
1111: D4 => "Choice D4",
1112: D5 => "Choice D5",
1113: D6 => "Choice D6",
1114: D7 => "Choice D7"
1.609 raeburn 1115: },
1116: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1117: }
1118: );
1.36 matthew 1119:
1120: =cut
1121:
1122: sub linked_select_forms {
1123: my ($formname,
1124: $middletext,
1125: $firstdefault,
1126: $firstselectname,
1127: $secondselectname,
1.609 raeburn 1128: $hashref,
1129: $menuorder,
1.1075.2.31 raeburn 1130: $onchangefirst,
1131: $onchangesecond
1.36 matthew 1132: ) = @_;
1133: my $second = "document.$formname.$secondselectname";
1134: my $first = "document.$formname.$firstselectname";
1135: # output the javascript to do the changing
1136: my $result = '';
1.776 bisitz 1137: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1138: $result.="// <![CDATA[\n";
1.36 matthew 1139: $result.="var select2data = new Object();\n";
1140: $" = '","';
1141: my $debug = '';
1142: foreach my $s1 (sort(keys(%$hashref))) {
1143: $result.="select2data.d_$s1 = new Object();\n";
1144: $result.="select2data.d_$s1.def = new String('".
1145: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1146: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1147: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1148: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1149: @s2values = @{$hashref->{$s1}->{'order'}};
1150: }
1.36 matthew 1151: $result.="\"@s2values\");\n";
1152: $result.="select2data.d_$s1.texts = new Array(";
1153: my @s2texts;
1154: foreach my $value (@s2values) {
1.1075.2.119 raeburn 1155: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1156: }
1157: $result.="\"@s2texts\");\n";
1158: }
1159: $"=' ';
1160: $result.= <<"END";
1161:
1162: function select1_changed() {
1163: // Determine new choice
1164: var newvalue = "d_" + $first.value;
1165: // update select2
1166: var values = select2data[newvalue].values;
1167: var texts = select2data[newvalue].texts;
1168: var select2def = select2data[newvalue].def;
1169: var i;
1170: // out with the old
1171: for (i = 0; i < $second.options.length; i++) {
1172: $second.options[i] = null;
1173: }
1174: // in with the nuclear
1175: for (i=0;i<values.length; i++) {
1176: $second.options[i] = new Option(values[i]);
1.143 matthew 1177: $second.options[i].value = values[i];
1.36 matthew 1178: $second.options[i].text = texts[i];
1179: if (values[i] == select2def) {
1180: $second.options[i].selected = true;
1181: }
1182: }
1183: }
1.824 bisitz 1184: // ]]>
1.36 matthew 1185: </script>
1186: END
1187: # output the initial values for the selection lists
1.1075.2.31 raeburn 1188: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1189: my @order = sort(keys(%{$hashref}));
1190: if (ref($menuorder) eq 'ARRAY') {
1191: @order = @{$menuorder};
1192: }
1193: foreach my $value (@order) {
1.36 matthew 1194: $result.=" <option value=\"$value\" ";
1.253 albertel 1195: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1196: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1197: }
1198: $result .= "</select>\n";
1199: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1200: $result .= $middletext;
1.1075.2.31 raeburn 1201: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1202: if ($onchangesecond) {
1203: $result .= ' onchange="'.$onchangesecond.'"';
1204: }
1205: $result .= ">\n";
1.36 matthew 1206: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1207:
1208: my @secondorder = sort(keys(%select2));
1209: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1210: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1211: }
1212: foreach my $value (@secondorder) {
1.36 matthew 1213: $result.=" <option value=\"$value\" ";
1.253 albertel 1214: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1215: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1216: }
1217: $result .= "</select>\n";
1218: # return $debug;
1219: return $result;
1220: } # end of sub linked_select_forms {
1221:
1.45 matthew 1222: =pod
1.44 bowersj2 1223:
1.973 raeburn 1224: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1225:
1.112 bowersj2 1226: Returns a string corresponding to an HTML link to the given help
1227: $topic, where $topic corresponds to the name of a .tex file in
1228: /home/httpd/html/adm/help/tex, with underscores replaced by
1229: spaces.
1230:
1231: $text will optionally be linked to the same topic, allowing you to
1232: link text in addition to the graphic. If you do not want to link
1233: text, but wish to specify one of the later parameters, pass an
1234: empty string.
1235:
1236: $stayOnPage is a value that will be interpreted as a boolean. If true,
1237: the link will not open a new window. If false, the link will open
1238: a new window using Javascript. (Default is false.)
1239:
1240: $width and $height are optional numerical parameters that will
1241: override the width and height of the popped up window, which may
1.973 raeburn 1242: be useful for certain help topics with big pictures included.
1243:
1244: $imgid is the id of the img tag used for the help icon. This may be
1245: used in a javascript call to switch the image src. See
1246: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1247:
1248: =cut
1249:
1250: sub help_open_topic {
1.973 raeburn 1251: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1252: $text = "" if (not defined $text);
1.44 bowersj2 1253: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1254: $width = 500 if (not defined $width);
1.44 bowersj2 1255: $height = 400 if (not defined $height);
1256: my $filename = $topic;
1257: $filename =~ s/ /_/g;
1258:
1.48 bowersj2 1259: my $template = "";
1260: my $link;
1.572 banghart 1261:
1.159 www 1262: $topic=~s/\W/\_/g;
1.44 bowersj2 1263:
1.572 banghart 1264: if (!$stayOnPage) {
1.1075.2.50 raeburn 1265: if ($env{'browser.mobile'}) {
1266: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1267: } else {
1268: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1269: }
1.1037 www 1270: } elsif ($stayOnPage eq 'popup') {
1271: $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 1272: } else {
1.48 bowersj2 1273: $link = "/adm/help/${filename}.hlp";
1274: }
1275:
1276: # Add the text
1.755 neumanie 1277: if ($text ne "") {
1.763 bisitz 1278: $template.='<span class="LC_help_open_topic">'
1279: .'<a target="_top" href="'.$link.'">'
1280: .$text.'</a>';
1.48 bowersj2 1281: }
1282:
1.763 bisitz 1283: # (Always) Add the graphic
1.179 matthew 1284: my $title = &mt('Online Help');
1.667 raeburn 1285: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1286: if ($imgid ne '') {
1287: $imgid = ' id="'.$imgid.'"';
1288: }
1.763 bisitz 1289: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1290: .'<img src="'.$helpicon.'" border="0"'
1291: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1292: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1293: .' /></a>';
1294: if ($text ne "") {
1295: $template.='</span>';
1296: }
1.44 bowersj2 1297: return $template;
1298:
1.106 bowersj2 1299: }
1300:
1301: # This is a quicky function for Latex cheatsheet editing, since it
1302: # appears in at least four places
1303: sub helpLatexCheatsheet {
1.1037 www 1304: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1305: my $out;
1.106 bowersj2 1306: my $addOther = '';
1.732 raeburn 1307: if ($topic) {
1.1037 www 1308: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1309: }
1310: $out = '<span>' # Start cheatsheet
1311: .$addOther
1312: .'<span>'
1.1037 www 1313: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1314: .'</span> <span>'
1.1037 www 1315: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1316: .'</span>';
1.732 raeburn 1317: unless ($not_author) {
1.763 bisitz 1318: $out .= ' <span>'
1.1037 www 1319: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1320: .'</span> <span>'
1.1075.2.78 raeburn 1321: .&help_open_topic('Authoring_Multilingual_Problems',&mt('Languages'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1322: .'</span>';
1.732 raeburn 1323: }
1.763 bisitz 1324: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1325: return $out;
1.172 www 1326: }
1327:
1.430 albertel 1328: sub general_help {
1329: my $helptopic='Student_Intro';
1330: if ($env{'request.role'}=~/^(ca|au)/) {
1331: $helptopic='Authoring_Intro';
1.907 raeburn 1332: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1333: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1334: } elsif ($env{'request.role'}=~/^dc/) {
1335: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1336: }
1337: return $helptopic;
1338: }
1339:
1340: sub update_help_link {
1341: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1342: my $origurl = $ENV{'REQUEST_URI'};
1343: $origurl=~s|^/~|/priv/|;
1344: my $timestamp = time;
1345: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1346: $$datum = &escape($$datum);
1347: }
1348:
1349: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1350: my $output .= <<"ENDOUTPUT";
1351: <script type="text/javascript">
1.824 bisitz 1352: // <![CDATA[
1.430 albertel 1353: banner_link = '$banner_link';
1.824 bisitz 1354: // ]]>
1.430 albertel 1355: </script>
1356: ENDOUTPUT
1357: return $output;
1358: }
1359:
1360: # now just updates the help link and generates a blue icon
1.193 raeburn 1361: sub help_open_menu {
1.430 albertel 1362: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1363: = @_;
1.949 droeschl 1364: $stayOnPage = 1;
1.430 albertel 1365: my $output;
1366: if ($component_help) {
1367: if (!$text) {
1368: $output=&help_open_topic($component_help,undef,$stayOnPage,
1369: $width,$height);
1370: } else {
1371: my $help_text;
1372: $help_text=&unescape($topic);
1373: $output='<table><tr><td>'.
1374: &help_open_topic($component_help,$help_text,$stayOnPage,
1375: $width,$height).'</td></tr></table>';
1376: }
1377: }
1378: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1379: return $output.$banner_link;
1380: }
1381:
1382: sub top_nav_help {
1383: my ($text) = @_;
1.436 albertel 1384: $text = &mt($text);
1.1075.2.60 raeburn 1385: my $stay_on_page;
1386: unless ($env{'environment.remote'} eq 'on') {
1387: $stay_on_page = 1;
1388: }
1.1075.2.61 raeburn 1389: my ($link,$banner_link);
1390: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1391: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1392: : "javascript:helpMenu('open')";
1393: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1394: }
1.201 raeburn 1395: my $title = &mt('Get help');
1.1075.2.61 raeburn 1396: if ($link) {
1397: return <<"END";
1.436 albertel 1398: $banner_link
1.1075.2.56 raeburn 1399: <a href="$link" title="$title">$text</a>
1.436 albertel 1400: END
1.1075.2.61 raeburn 1401: } else {
1402: return ' '.$text.' ';
1403: }
1.436 albertel 1404: }
1405:
1406: sub help_menu_js {
1.1075.2.52 raeburn 1407: my ($httphost) = @_;
1.949 droeschl 1408: my $stayOnPage = 1;
1.436 albertel 1409: my $width = 620;
1410: my $height = 600;
1.430 albertel 1411: my $helptopic=&general_help();
1.1075.2.52 raeburn 1412: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1413: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1414: my $start_page =
1415: &Apache::loncommon::start_page('Help Menu', undef,
1416: {'frameset' => 1,
1417: 'js_ready' => 1,
1.1075.2.136 raeburn 1418: 'use_absolute' => $httphost,
1.331 albertel 1419: 'add_entries' => {
1420: 'border' => '0',
1.579 raeburn 1421: 'rows' => "110,*",},});
1.331 albertel 1422: my $end_page =
1423: &Apache::loncommon::end_page({'frameset' => 1,
1424: 'js_ready' => 1,});
1425:
1.436 albertel 1426: my $template .= <<"ENDTEMPLATE";
1427: <script type="text/javascript">
1.877 bisitz 1428: // <![CDATA[
1.253 albertel 1429: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1430: var banner_link = '';
1.243 raeburn 1431: function helpMenu(target) {
1432: var caller = this;
1433: if (target == 'open') {
1434: var newWindow = null;
1435: try {
1.262 albertel 1436: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1437: }
1438: catch(error) {
1439: writeHelp(caller);
1440: return;
1441: }
1442: if (newWindow) {
1443: caller = newWindow;
1444: }
1.193 raeburn 1445: }
1.243 raeburn 1446: writeHelp(caller);
1447: return;
1448: }
1449: function writeHelp(caller) {
1.1075.2.61 raeburn 1450: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1451: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1452: caller.document.close();
1453: caller.focus();
1.193 raeburn 1454: }
1.877 bisitz 1455: // END LON-CAPA Internal -->
1.253 albertel 1456: // ]]>
1.436 albertel 1457: </script>
1.193 raeburn 1458: ENDTEMPLATE
1459: return $template;
1460: }
1461:
1.172 www 1462: sub help_open_bug {
1463: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1464: unless ($env{'user.adv'}) { return ''; }
1.172 www 1465: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1466: $text = "" if (not defined $text);
1467: $stayOnPage=1;
1.184 albertel 1468: $width = 600 if (not defined $width);
1469: $height = 600 if (not defined $height);
1.172 www 1470:
1471: $topic=~s/\W+/\+/g;
1472: my $link='';
1473: my $template='';
1.379 albertel 1474: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1475: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1476: if (!$stayOnPage)
1477: {
1478: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1479: }
1480: else
1481: {
1482: $link = $url;
1483: }
1484: # Add the text
1485: if ($text ne "")
1486: {
1487: $template .=
1488: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1489: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1490: }
1491:
1492: # Add the graphic
1.179 matthew 1493: my $title = &mt('Report a Bug');
1.215 albertel 1494: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1495: $template .= <<"ENDTEMPLATE";
1.436 albertel 1496: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1497: ENDTEMPLATE
1498: if ($text ne '') { $template.='</td></tr></table>' };
1499: return $template;
1500:
1501: }
1502:
1503: sub help_open_faq {
1504: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1505: unless ($env{'user.adv'}) { return ''; }
1.172 www 1506: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1507: $text = "" if (not defined $text);
1508: $stayOnPage=1;
1509: $width = 350 if (not defined $width);
1510: $height = 400 if (not defined $height);
1511:
1512: $topic=~s/\W+/\+/g;
1513: my $link='';
1514: my $template='';
1515: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1516: if (!$stayOnPage)
1517: {
1518: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1519: }
1520: else
1521: {
1522: $link = $url;
1523: }
1524:
1525: # Add the text
1526: if ($text ne "")
1527: {
1528: $template .=
1.173 www 1529: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1530: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1531: }
1532:
1533: # Add the graphic
1.179 matthew 1534: my $title = &mt('View the FAQ');
1.215 albertel 1535: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1536: $template .= <<"ENDTEMPLATE";
1.436 albertel 1537: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1538: ENDTEMPLATE
1539: if ($text ne '') { $template.='</td></tr></table>' };
1540: return $template;
1541:
1.44 bowersj2 1542: }
1.37 matthew 1543:
1.180 matthew 1544: ###############################################################
1545: ###############################################################
1546:
1.45 matthew 1547: =pod
1548:
1.648 raeburn 1549: =item * &change_content_javascript():
1.256 matthew 1550:
1551: This and the next function allow you to create small sections of an
1552: otherwise static HTML page that you can update on the fly with
1553: Javascript, even in Netscape 4.
1554:
1555: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1556: must be written to the HTML page once. It will prove the Javascript
1557: function "change(name, content)". Calling the change function with the
1558: name of the section
1559: you want to update, matching the name passed to C<changable_area>, and
1560: the new content you want to put in there, will put the content into
1561: that area.
1562:
1563: B<Note>: Netscape 4 only reserves enough space for the changable area
1564: to contain room for the original contents. You need to "make space"
1565: for whatever changes you wish to make, and be B<sure> to check your
1566: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1567: it's adequate for updating a one-line status display, but little more.
1568: This script will set the space to 100% width, so you only need to
1569: worry about height in Netscape 4.
1570:
1571: Modern browsers are much less limiting, and if you can commit to the
1572: user not using Netscape 4, this feature may be used freely with
1573: pretty much any HTML.
1574:
1575: =cut
1576:
1577: sub change_content_javascript {
1578: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1579: if ($env{'browser.type'} eq 'netscape' &&
1580: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1581: return (<<NETSCAPE4);
1582: function change(name, content) {
1583: doc = document.layers[name+"___escape"].layers[0].document;
1584: doc.open();
1585: doc.write(content);
1586: doc.close();
1587: }
1588: NETSCAPE4
1589: } else {
1590: # Otherwise, we need to use semi-standards-compliant code
1591: # (technically, "innerHTML" isn't standard but the equivalent
1592: # is really scary, and every useful browser supports it
1593: return (<<DOMBASED);
1594: function change(name, content) {
1595: element = document.getElementById(name);
1596: element.innerHTML = content;
1597: }
1598: DOMBASED
1599: }
1600: }
1601:
1602: =pod
1603:
1.648 raeburn 1604: =item * &changable_area($name,$origContent):
1.256 matthew 1605:
1606: This provides a "changable area" that can be modified on the fly via
1607: the Javascript code provided in C<change_content_javascript>. $name is
1608: the name you will use to reference the area later; do not repeat the
1609: same name on a given HTML page more then once. $origContent is what
1610: the area will originally contain, which can be left blank.
1611:
1612: =cut
1613:
1614: sub changable_area {
1615: my ($name, $origContent) = @_;
1616:
1.258 albertel 1617: if ($env{'browser.type'} eq 'netscape' &&
1618: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1619: # If this is netscape 4, we need to use the Layer tag
1620: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1621: } else {
1622: return "<span id='$name'>$origContent</span>";
1623: }
1624: }
1625:
1626: =pod
1627:
1.648 raeburn 1628: =item * &viewport_geometry_js
1.590 raeburn 1629:
1630: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1631:
1632: =cut
1633:
1634:
1635: sub viewport_geometry_js {
1636: return <<"GEOMETRY";
1637: var Geometry = {};
1638: function init_geometry() {
1639: if (Geometry.init) { return };
1640: Geometry.init=1;
1641: if (window.innerHeight) {
1642: Geometry.getViewportHeight = function() { return window.innerHeight; };
1643: Geometry.getViewportWidth = function() { return window.innerWidth; };
1644: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1645: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1646: }
1647: else if (document.documentElement && document.documentElement.clientHeight) {
1648: Geometry.getViewportHeight =
1649: function() { return document.documentElement.clientHeight; };
1650: Geometry.getViewportWidth =
1651: function() { return document.documentElement.clientWidth; };
1652:
1653: Geometry.getHorizontalScroll =
1654: function() { return document.documentElement.scrollLeft; };
1655: Geometry.getVerticalScroll =
1656: function() { return document.documentElement.scrollTop; };
1657: }
1658: else if (document.body.clientHeight) {
1659: Geometry.getViewportHeight =
1660: function() { return document.body.clientHeight; };
1661: Geometry.getViewportWidth =
1662: function() { return document.body.clientWidth; };
1663: Geometry.getHorizontalScroll =
1664: function() { return document.body.scrollLeft; };
1665: Geometry.getVerticalScroll =
1666: function() { return document.body.scrollTop; };
1667: }
1668: }
1669:
1670: GEOMETRY
1671: }
1672:
1673: =pod
1674:
1.648 raeburn 1675: =item * &viewport_size_js()
1.590 raeburn 1676:
1677: 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.
1678:
1679: =cut
1680:
1681: sub viewport_size_js {
1682: my $geometry = &viewport_geometry_js();
1683: return <<"DIMS";
1684:
1685: $geometry
1686:
1687: function getViewportDims(width,height) {
1688: init_geometry();
1689: width.value = Geometry.getViewportWidth();
1690: height.value = Geometry.getViewportHeight();
1691: return;
1692: }
1693:
1694: DIMS
1695: }
1696:
1697: =pod
1698:
1.648 raeburn 1699: =item * &resize_textarea_js()
1.565 albertel 1700:
1701: emits the needed javascript to resize a textarea to be as big as possible
1702:
1703: creates a function resize_textrea that takes two IDs first should be
1704: the id of the element to resize, second should be the id of a div that
1705: surrounds everything that comes after the textarea, this routine needs
1706: to be attached to the <body> for the onload and onresize events.
1707:
1.648 raeburn 1708: =back
1.565 albertel 1709:
1710: =cut
1711:
1712: sub resize_textarea_js {
1.590 raeburn 1713: my $geometry = &viewport_geometry_js();
1.565 albertel 1714: return <<"RESIZE";
1715: <script type="text/javascript">
1.824 bisitz 1716: // <![CDATA[
1.590 raeburn 1717: $geometry
1.565 albertel 1718:
1.588 albertel 1719: function getX(element) {
1720: var x = 0;
1721: while (element) {
1722: x += element.offsetLeft;
1723: element = element.offsetParent;
1724: }
1725: return x;
1726: }
1727: function getY(element) {
1728: var y = 0;
1729: while (element) {
1730: y += element.offsetTop;
1731: element = element.offsetParent;
1732: }
1733: return y;
1734: }
1735:
1736:
1.565 albertel 1737: function resize_textarea(textarea_id,bottom_id) {
1738: init_geometry();
1739: var textarea = document.getElementById(textarea_id);
1740: //alert(textarea);
1741:
1.588 albertel 1742: var textarea_top = getY(textarea);
1.565 albertel 1743: var textarea_height = textarea.offsetHeight;
1744: var bottom = document.getElementById(bottom_id);
1.588 albertel 1745: var bottom_top = getY(bottom);
1.565 albertel 1746: var bottom_height = bottom.offsetHeight;
1747: var window_height = Geometry.getViewportHeight();
1.588 albertel 1748: var fudge = 23;
1.565 albertel 1749: var new_height = window_height-fudge-textarea_top-bottom_height;
1750: if (new_height < 300) {
1751: new_height = 300;
1752: }
1753: textarea.style.height=new_height+'px';
1754: }
1.824 bisitz 1755: // ]]>
1.565 albertel 1756: </script>
1757: RESIZE
1758:
1759: }
1760:
1.1075.2.112 raeburn 1761: sub colorfuleditor_js {
1762: return <<"COLORFULEDIT"
1763: <script type="text/javascript">
1764: // <![CDATA[>
1765: function fold_box(curDepth, lastresource){
1766:
1767: // we need a list because there can be several blocks you need to fold in one tag
1768: var block = document.getElementsByName('foldblock_'+curDepth);
1769: // but there is only one folding button per tag
1770: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1771:
1772: if(block.item(0).style.display == 'none'){
1773:
1774: foldbutton.value = '@{[&mt("Hide")]}';
1775: for (i = 0; i < block.length; i++){
1776: block.item(i).style.display = '';
1777: }
1778: }else{
1779:
1780: foldbutton.value = '@{[&mt("Show")]}';
1781: for (i = 0; i < block.length; i++){
1782: // block.item(i).style.visibility = 'collapse';
1783: block.item(i).style.display = 'none';
1784: }
1785: };
1786: saveState(lastresource);
1787: }
1788:
1789: function saveState (lastresource) {
1790:
1791: var tag_list = getTagList();
1792: if(tag_list != null){
1793: var timestamp = new Date().getTime();
1794: var key = lastresource;
1795:
1796: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1797: // starting with timestamp
1798: var value = timestamp+';';
1799:
1800: // building the list of key-value pairs
1801: for(var i = 0; i < tag_list.length; i++){
1802: value += tag_list[i]+',';
1803: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1804: }
1805:
1806: // only iterate whole storage if nothing to override
1807: if(localStorage.getItem(key) == null){
1808:
1809: // prevent storage from growing large
1810: if(localStorage.length > 50){
1811: var regex_getTimestamp = /^(?:\d)+;/;
1812: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1813: var oldest_key;
1814:
1815: for(var i = 1; i < localStorage.length; i++){
1816: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1817: oldest_key = localStorage.key(i);
1818: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1819: }
1820: }
1821: localStorage.removeItem(oldest_key);
1822: }
1823: }
1824: localStorage.setItem(key,value);
1825: }
1826: }
1827:
1828: // restore folding status of blocks (on page load)
1829: function restoreState (lastresource) {
1830: if(localStorage.getItem(lastresource) != null){
1831: var key = lastresource;
1832: var value = localStorage.getItem(key);
1833: var regex_delTimestamp = /^\d+;/;
1834:
1835: value.replace(regex_delTimestamp, '');
1836:
1837: var valueArr = value.split(';');
1838: var pairs;
1839: var elements;
1840: for (var i = 0; i < valueArr.length; i++){
1841: pairs = valueArr[i].split(',');
1842: elements = document.getElementsByName(pairs[0]);
1843:
1844: for (var j = 0; j < elements.length; j++){
1845: elements[j].style.display = pairs[1];
1846: if (pairs[1] == "none"){
1847: var regex_id = /([_\\d]+)\$/;
1848: regex_id.exec(pairs[0]);
1849: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
1850: }
1851: }
1852: }
1853: }
1854: }
1855:
1856: function getTagList () {
1857:
1858: var stringToSearch = document.lonhomework.innerHTML;
1859:
1860: var ret = new Array();
1861: var regex_findBlock = /(foldblock_.*?)"/g;
1862: var tag_list = stringToSearch.match(regex_findBlock);
1863:
1864: if(tag_list != null){
1865: for(var i = 0; i < tag_list.length; i++){
1866: ret.push(tag_list[i].replace(/"/, ''));
1867: }
1868: }
1869: return ret;
1870: }
1871:
1872: function saveScrollPosition (resource) {
1873: var tag_list = getTagList();
1874:
1875: // we dont always want to jump to the first block
1876: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
1877: if(\$(window).scrollTop() > 170){
1878: if(tag_list != null){
1879: var result;
1880: for(var i = 0; i < tag_list.length; i++){
1881: if(isElementInViewport(tag_list[i])){
1882: result += tag_list[i]+';';
1883: }
1884: }
1885: sessionStorage.setItem('anchor_'+resource, result);
1886: }
1887: } else {
1888: // we dont need to save zero, just delete the item to leave everything tidy
1889: sessionStorage.removeItem('anchor_'+resource);
1890: }
1891: }
1892:
1893: function restoreScrollPosition(resource){
1894:
1895: var elem = sessionStorage.getItem('anchor_'+resource);
1896: if(elem != null){
1897: var tag_list = elem.split(';');
1898: var elem_list;
1899:
1900: for(var i = 0; i < tag_list.length; i++){
1901: elem_list = document.getElementsByName(tag_list[i]);
1902:
1903: if(elem_list.length > 0){
1904: elem = elem_list[0];
1905: break;
1906: }
1907: }
1908: elem.scrollIntoView();
1909: }
1910: }
1911:
1912: function isElementInViewport(el) {
1913:
1914: // change to last element instead of first
1915: var elem = document.getElementsByName(el);
1916: var rect = elem[0].getBoundingClientRect();
1917:
1918: return (
1919: rect.top >= 0 &&
1920: rect.left >= 0 &&
1921: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1922: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1923: );
1924: }
1925:
1926: function autosize(depth){
1927: var cmInst = window['cm'+depth];
1928: var fitsizeButton = document.getElementById('fitsize'+depth);
1929:
1930: // is fixed size, switching to dynamic
1931: if (sessionStorage.getItem("autosized_"+depth) == null) {
1932: cmInst.setSize("","auto");
1933: fitsizeButton.value = "@{[&mt('Fixed size')]}";
1934: sessionStorage.setItem("autosized_"+depth, "yes");
1935:
1936: // is dynamic size, switching to fixed
1937: } else {
1938: cmInst.setSize("","300px");
1939: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
1940: sessionStorage.removeItem("autosized_"+depth);
1941: }
1942: }
1943:
1944:
1945:
1946: // ]]>
1947: </script>
1948: COLORFULEDIT
1949: }
1950:
1951: sub xmleditor_js {
1952: return <<XMLEDIT
1953: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
1954: <script type="text/javascript">
1955: // <![CDATA[>
1956:
1957: function saveScrollPosition (resource) {
1958:
1959: var scrollPos = \$(window).scrollTop();
1960: sessionStorage.setItem(resource,scrollPos);
1961: }
1962:
1963: function restoreScrollPosition(resource){
1964:
1965: var scrollPos = sessionStorage.getItem(resource);
1966: \$(window).scrollTop(scrollPos);
1967: }
1968:
1969: // unless internet explorer
1970: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
1971:
1972: \$(document).ready(function() {
1973: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
1974: });
1975: }
1976:
1977: // inserts text at cursor position into codemirror (xml editor only)
1978: function insertText(text){
1979: cm.focus();
1980: var curPos = cm.getCursor();
1981: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
1982: }
1983: // ]]>
1984: </script>
1985: XMLEDIT
1986: }
1987:
1988: sub insert_folding_button {
1989: my $curDepth = $Apache::lonxml::curdepth;
1990: my $lastresource = $env{'request.ambiguous'};
1991:
1992: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
1993: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
1994: }
1995:
1996:
1.565 albertel 1997: =pod
1998:
1.256 matthew 1999: =head1 Excel and CSV file utility routines
2000:
2001: =cut
2002:
2003: ###############################################################
2004: ###############################################################
2005:
2006: =pod
2007:
1.1075.2.56 raeburn 2008: =over 4
2009:
1.648 raeburn 2010: =item * &csv_translate($text)
1.37 matthew 2011:
1.185 www 2012: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2013: format.
2014:
2015: =cut
2016:
1.180 matthew 2017: ###############################################################
2018: ###############################################################
1.37 matthew 2019: sub csv_translate {
2020: my $text = shift;
2021: $text =~ s/\"/\"\"/g;
1.209 albertel 2022: $text =~ s/\n/ /g;
1.37 matthew 2023: return $text;
2024: }
1.180 matthew 2025:
2026: ###############################################################
2027: ###############################################################
2028:
2029: =pod
2030:
1.648 raeburn 2031: =item * &define_excel_formats()
1.180 matthew 2032:
2033: Define some commonly used Excel cell formats.
2034:
2035: Currently supported formats:
2036:
2037: =over 4
2038:
2039: =item header
2040:
2041: =item bold
2042:
2043: =item h1
2044:
2045: =item h2
2046:
2047: =item h3
2048:
1.256 matthew 2049: =item h4
2050:
2051: =item i
2052:
1.180 matthew 2053: =item date
2054:
2055: =back
2056:
2057: Inputs: $workbook
2058:
2059: Returns: $format, a hash reference.
2060:
1.1057 foxr 2061:
1.180 matthew 2062: =cut
2063:
2064: ###############################################################
2065: ###############################################################
2066: sub define_excel_formats {
2067: my ($workbook) = @_;
2068: my $format;
2069: $format->{'header'} = $workbook->add_format(bold => 1,
2070: bottom => 1,
2071: align => 'center');
2072: $format->{'bold'} = $workbook->add_format(bold=>1);
2073: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2074: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2075: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2076: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2077: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2078: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2079: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2080: return $format;
2081: }
2082:
2083: ###############################################################
2084: ###############################################################
1.113 bowersj2 2085:
2086: =pod
2087:
1.648 raeburn 2088: =item * &create_workbook()
1.255 matthew 2089:
2090: Create an Excel worksheet. If it fails, output message on the
2091: request object and return undefs.
2092:
2093: Inputs: Apache request object
2094:
2095: Returns (undef) on failure,
2096: Excel worksheet object, scalar with filename, and formats
2097: from &Apache::loncommon::define_excel_formats on success
2098:
2099: =cut
2100:
2101: ###############################################################
2102: ###############################################################
2103: sub create_workbook {
2104: my ($r) = @_;
2105: #
2106: # Create the excel spreadsheet
2107: my $filename = '/prtspool/'.
1.258 albertel 2108: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2109: time.'_'.rand(1000000000).'.xls';
2110: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2111: if (! defined($workbook)) {
2112: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2113: $r->print(
2114: '<p class="LC_error">'
2115: .&mt('Problems occurred in creating the new Excel file.')
2116: .' '.&mt('This error has been logged.')
2117: .' '.&mt('Please alert your LON-CAPA administrator.')
2118: .'</p>'
2119: );
1.255 matthew 2120: return (undef);
2121: }
2122: #
1.1014 foxr 2123: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2124: #
2125: my $format = &Apache::loncommon::define_excel_formats($workbook);
2126: return ($workbook,$filename,$format);
2127: }
2128:
2129: ###############################################################
2130: ###############################################################
2131:
2132: =pod
2133:
1.648 raeburn 2134: =item * &create_text_file()
1.113 bowersj2 2135:
1.542 raeburn 2136: Create a file to write to and eventually make available to the user.
1.256 matthew 2137: If file creation fails, outputs an error message on the request object and
2138: return undefs.
1.113 bowersj2 2139:
1.256 matthew 2140: Inputs: Apache request object, and file suffix
1.113 bowersj2 2141:
1.256 matthew 2142: Returns (undef) on failure,
2143: Filehandle and filename on success.
1.113 bowersj2 2144:
2145: =cut
2146:
1.256 matthew 2147: ###############################################################
2148: ###############################################################
2149: sub create_text_file {
2150: my ($r,$suffix) = @_;
2151: if (! defined($suffix)) { $suffix = 'txt'; };
2152: my $fh;
2153: my $filename = '/prtspool/'.
1.258 albertel 2154: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2155: time.'_'.rand(1000000000).'.'.$suffix;
2156: $fh = Apache::File->new('>/home/httpd'.$filename);
2157: if (! defined($fh)) {
2158: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2159: $r->print(
2160: '<p class="LC_error">'
2161: .&mt('Problems occurred in creating the output file.')
2162: .' '.&mt('This error has been logged.')
2163: .' '.&mt('Please alert your LON-CAPA administrator.')
2164: .'</p>'
2165: );
1.113 bowersj2 2166: }
1.256 matthew 2167: return ($fh,$filename)
1.113 bowersj2 2168: }
2169:
2170:
1.256 matthew 2171: =pod
1.113 bowersj2 2172:
2173: =back
2174:
2175: =cut
1.37 matthew 2176:
2177: ###############################################################
1.33 matthew 2178: ## Home server <option> list generating code ##
2179: ###############################################################
1.35 matthew 2180:
1.169 www 2181: # ------------------------------------------
2182:
2183: sub domain_select {
2184: my ($name,$value,$multiple)=@_;
2185: my %domains=map {
1.514 albertel 2186: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2187: } &Apache::lonnet::all_domains();
1.169 www 2188: if ($multiple) {
2189: $domains{''}=&mt('Any domain');
1.550 albertel 2190: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2191: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2192: } else {
1.550 albertel 2193: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2194: return &select_form($name,$value,\%domains);
1.169 www 2195: }
2196: }
2197:
1.282 albertel 2198: #-------------------------------------------
2199:
2200: =pod
2201:
1.519 raeburn 2202: =head1 Routines for form select boxes
2203:
2204: =over 4
2205:
1.648 raeburn 2206: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2207:
2208: Returns a string containing a <select> element int multiple mode
2209:
2210:
2211: Args:
2212: $name - name of the <select> element
1.506 raeburn 2213: $value - scalar or array ref of values that should already be selected
1.282 albertel 2214: $size - number of rows long the select element is
1.283 albertel 2215: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2216: (shown text should already have been &mt())
1.506 raeburn 2217: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2218:
1.282 albertel 2219: =cut
2220:
2221: #-------------------------------------------
1.169 www 2222: sub multiple_select_form {
1.284 albertel 2223: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2224: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2225: my $output='';
1.191 matthew 2226: if (! defined($size)) {
2227: $size = 4;
1.283 albertel 2228: if (scalar(keys(%$hash))<4) {
2229: $size = scalar(keys(%$hash));
1.191 matthew 2230: }
2231: }
1.734 bisitz 2232: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2233: my @order;
1.506 raeburn 2234: if (ref($order) eq 'ARRAY') {
2235: @order = @{$order};
2236: } else {
2237: @order = sort(keys(%$hash));
1.501 banghart 2238: }
2239: if (exists($$hash{'select_form_order'})) {
2240: @order = @{$$hash{'select_form_order'}};
2241: }
2242:
1.284 albertel 2243: foreach my $key (@order) {
1.356 albertel 2244: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2245: $output.='selected="selected" ' if ($selected{$key});
2246: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2247: }
2248: $output.="</select>\n";
2249: return $output;
2250: }
2251:
1.88 www 2252: #-------------------------------------------
2253:
2254: =pod
2255:
1.1075.2.115 raeburn 2256: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2257:
2258: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2259: allow a user to select options from a ref to a hash containing:
2260: option_name => displayed text. An optional $onchange can include
1.1075.2.115 raeburn 2261: a javascript onchange item, e.g., onchange="this.form.submit();".
2262: An optional arg -- $readonly -- if true will cause the select form
2263: to be disabled, e.g., for the case where an instructor has a section-
2264: specific role, and is viewing/modifying parameters.
1.970 raeburn 2265:
1.88 www 2266: See lonrights.pm for an example invocation and use.
2267:
2268: =cut
2269:
2270: #-------------------------------------------
2271: sub select_form {
1.1075.2.115 raeburn 2272: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2273: return unless (ref($hashref) eq 'HASH');
2274: if ($onchange) {
2275: $onchange = ' onchange="'.$onchange.'"';
2276: }
1.1075.2.129 raeburn 2277: my $disabled;
2278: if ($readonly) {
2279: $disabled = ' disabled="disabled"';
2280: }
2281: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2282: my @keys;
1.970 raeburn 2283: if (exists($hashref->{'select_form_order'})) {
2284: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2285: } else {
1.970 raeburn 2286: @keys=sort(keys(%{$hashref}));
1.128 albertel 2287: }
1.356 albertel 2288: foreach my $key (@keys) {
2289: $selectform.=
2290: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2291: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2292: ">".$hashref->{$key}."</option>\n";
1.88 www 2293: }
2294: $selectform.="</select>";
2295: return $selectform;
2296: }
2297:
1.475 www 2298: # For display filters
2299:
2300: sub display_filter {
1.1074 raeburn 2301: my ($context) = @_;
1.475 www 2302: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2303: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2304: my $phraseinput = 'hidden';
2305: my $includeinput = 'hidden';
2306: my ($checked,$includetypestext);
2307: if ($env{'form.displayfilter'} eq 'containing') {
2308: $phraseinput = 'text';
2309: if ($context eq 'parmslog') {
2310: $includeinput = 'checkbox';
2311: if ($env{'form.includetypes'}) {
2312: $checked = ' checked="checked"';
2313: }
2314: $includetypestext = &mt('Include parameter types');
2315: }
2316: } else {
2317: $includetypestext = ' ';
2318: }
2319: my ($additional,$secondid,$thirdid);
2320: if ($context eq 'parmslog') {
2321: $additional =
2322: '<label><input type="'.$includeinput.'" name="includetypes"'.
2323: $checked.' name="includetypes" value="1" id="includetypes" />'.
2324: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2325: '</label>';
2326: $secondid = 'includetypes';
2327: $thirdid = 'includetypestext';
2328: }
2329: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2330: '$secondid','$thirdid')";
2331: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2332: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2333: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2334: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2335: &mt('Filter: [_1]',
1.477 www 2336: &select_form($env{'form.displayfilter'},
2337: 'displayfilter',
1.970 raeburn 2338: {'currentfolder' => 'Current folder/page',
1.477 www 2339: 'containing' => 'Containing phrase',
1.1074 raeburn 2340: 'none' => 'None'},$onchange)).' '.
2341: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2342: &HTML::Entities::encode($env{'form.containingphrase'}).
2343: '" />'.$additional;
2344: }
2345:
2346: sub display_filter_js {
2347: my $includetext = &mt('Include parameter types');
2348: return <<"ENDJS";
2349:
2350: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2351: var firstType = 'hidden';
2352: if (setter.options[setter.selectedIndex].value == 'containing') {
2353: firstType = 'text';
2354: }
2355: firstObject = document.getElementById(firstid);
2356: if (typeof(firstObject) == 'object') {
2357: if (firstObject.type != firstType) {
2358: changeInputType(firstObject,firstType);
2359: }
2360: }
2361: if (context == 'parmslog') {
2362: var secondType = 'hidden';
2363: if (firstType == 'text') {
2364: secondType = 'checkbox';
2365: }
2366: secondObject = document.getElementById(secondid);
2367: if (typeof(secondObject) == 'object') {
2368: if (secondObject.type != secondType) {
2369: changeInputType(secondObject,secondType);
2370: }
2371: }
2372: var textItem = document.getElementById(thirdid);
2373: var currtext = textItem.innerHTML;
2374: var newtext;
2375: if (firstType == 'text') {
2376: newtext = '$includetext';
2377: } else {
2378: newtext = ' ';
2379: }
2380: if (currtext != newtext) {
2381: textItem.innerHTML = newtext;
2382: }
2383: }
2384: return;
2385: }
2386:
2387: function changeInputType(oldObject,newType) {
2388: var newObject = document.createElement('input');
2389: newObject.type = newType;
2390: if (oldObject.size) {
2391: newObject.size = oldObject.size;
2392: }
2393: if (oldObject.value) {
2394: newObject.value = oldObject.value;
2395: }
2396: if (oldObject.name) {
2397: newObject.name = oldObject.name;
2398: }
2399: if (oldObject.id) {
2400: newObject.id = oldObject.id;
2401: }
2402: oldObject.parentNode.replaceChild(newObject,oldObject);
2403: return;
2404: }
2405:
2406: ENDJS
1.475 www 2407: }
2408:
1.167 www 2409: sub gradeleveldescription {
2410: my $gradelevel=shift;
2411: my %gradelevels=(0 => 'Not specified',
2412: 1 => 'Grade 1',
2413: 2 => 'Grade 2',
2414: 3 => 'Grade 3',
2415: 4 => 'Grade 4',
2416: 5 => 'Grade 5',
2417: 6 => 'Grade 6',
2418: 7 => 'Grade 7',
2419: 8 => 'Grade 8',
2420: 9 => 'Grade 9',
2421: 10 => 'Grade 10',
2422: 11 => 'Grade 11',
2423: 12 => 'Grade 12',
2424: 13 => 'Grade 13',
2425: 14 => '100 Level',
2426: 15 => '200 Level',
2427: 16 => '300 Level',
2428: 17 => '400 Level',
2429: 18 => 'Graduate Level');
2430: return &mt($gradelevels{$gradelevel});
2431: }
2432:
1.163 www 2433: sub select_level_form {
2434: my ($deflevel,$name)=@_;
2435: unless ($deflevel) { $deflevel=0; }
1.167 www 2436: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2437: for (my $i=0; $i<=18; $i++) {
2438: $selectform.="<option value=\"$i\" ".
1.253 albertel 2439: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2440: ">".&gradeleveldescription($i)."</option>\n";
2441: }
2442: $selectform.="</select>";
2443: return $selectform;
1.163 www 2444: }
1.167 www 2445:
1.35 matthew 2446: #-------------------------------------------
2447:
1.45 matthew 2448: =pod
2449:
1.1075.2.115 raeburn 2450: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2451:
2452: Returns a string containing a <select name='$name' size='1'> form to
2453: allow a user to select the domain to preform an operation in.
2454: See loncreateuser.pm for an example invocation and use.
2455:
1.90 www 2456: If the $includeempty flag is set, it also includes an empty choice ("no domain
2457: selected");
2458:
1.743 raeburn 2459: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2460:
1.910 raeburn 2461: 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.
2462:
1.1075.2.36 raeburn 2463: The optional $incdoms is a reference to an array of domains which will be the only available options.
2464:
1.1075.2.115 raeburn 2465: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
2466:
2467: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
1.563 raeburn 2468:
1.35 matthew 2469: =cut
2470:
2471: #-------------------------------------------
1.34 matthew 2472: sub select_dom_form {
1.1075.2.115 raeburn 2473: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2474: if ($onchange) {
1.874 raeburn 2475: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2476: }
1.1075.2.115 raeburn 2477: if ($disabled) {
2478: $disabled = ' disabled="disabled"';
2479: }
1.1075.2.36 raeburn 2480: my (@domains,%exclude);
1.910 raeburn 2481: if (ref($incdoms) eq 'ARRAY') {
2482: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2483: } else {
2484: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2485: }
1.90 www 2486: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2487: if (ref($excdoms) eq 'ARRAY') {
2488: map { $exclude{$_} = 1; } @{$excdoms};
2489: }
1.1075.2.115 raeburn 2490: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2491: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2492: next if ($exclude{$dom});
1.356 albertel 2493: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2494: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2495: if ($showdomdesc) {
2496: if ($dom ne '') {
2497: my $domdesc = &Apache::lonnet::domain($dom,'description');
2498: if ($domdesc ne '') {
2499: $selectdomain .= ' ('.$domdesc.')';
2500: }
2501: }
2502: }
2503: $selectdomain .= "</option>\n";
1.34 matthew 2504: }
2505: $selectdomain.="</select>";
2506: return $selectdomain;
2507: }
2508:
1.35 matthew 2509: #-------------------------------------------
2510:
1.45 matthew 2511: =pod
2512:
1.648 raeburn 2513: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2514:
1.586 raeburn 2515: input: 4 arguments (two required, two optional) -
2516: $domain - domain of new user
2517: $name - name of form element
2518: $default - Value of 'default' causes a default item to be first
2519: option, and selected by default.
2520: $hide - Value of 'hide' causes hiding of the name of the server,
2521: if 1 server found, or default, if 0 found.
1.594 raeburn 2522: output: returns 2 items:
1.586 raeburn 2523: (a) form element which contains either:
2524: (i) <select name="$name">
2525: <option value="$hostid1">$hostid $servers{$hostid}</option>
2526: <option value="$hostid2">$hostid $servers{$hostid}</option>
2527: </select>
2528: form item if there are multiple library servers in $domain, or
2529: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2530: if there is only one library server in $domain.
2531:
2532: (b) number of library servers found.
2533:
2534: See loncreateuser.pm for example of use.
1.35 matthew 2535:
2536: =cut
2537:
2538: #-------------------------------------------
1.586 raeburn 2539: sub home_server_form_item {
2540: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2541: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2542: my $result;
2543: my $numlib = keys(%servers);
2544: if ($numlib > 1) {
2545: $result .= '<select name="'.$name.'" />'."\n";
2546: if ($default) {
1.804 bisitz 2547: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2548: '</option>'."\n";
2549: }
2550: foreach my $hostid (sort(keys(%servers))) {
2551: $result.= '<option value="'.$hostid.'">'.
2552: $hostid.' '.$servers{$hostid}."</option>\n";
2553: }
2554: $result .= '</select>'."\n";
2555: } elsif ($numlib == 1) {
2556: my $hostid;
2557: foreach my $item (keys(%servers)) {
2558: $hostid = $item;
2559: }
2560: $result .= '<input type="hidden" name="'.$name.'" value="'.
2561: $hostid.'" />';
2562: if (!$hide) {
2563: $result .= $hostid.' '.$servers{$hostid};
2564: }
2565: $result .= "\n";
2566: } elsif ($default) {
2567: $result .= '<input type="hidden" name="'.$name.
2568: '" value="default" />';
2569: if (!$hide) {
2570: $result .= &mt('default');
2571: }
2572: $result .= "\n";
1.33 matthew 2573: }
1.586 raeburn 2574: return ($result,$numlib);
1.33 matthew 2575: }
1.112 bowersj2 2576:
2577: =pod
2578:
1.534 albertel 2579: =back
2580:
1.112 bowersj2 2581: =cut
1.87 matthew 2582:
2583: ###############################################################
1.112 bowersj2 2584: ## Decoding User Agent ##
1.87 matthew 2585: ###############################################################
2586:
2587: =pod
2588:
1.112 bowersj2 2589: =head1 Decoding the User Agent
2590:
2591: =over 4
2592:
2593: =item * &decode_user_agent()
1.87 matthew 2594:
2595: Inputs: $r
2596:
2597: Outputs:
2598:
2599: =over 4
2600:
1.112 bowersj2 2601: =item * $httpbrowser
1.87 matthew 2602:
1.112 bowersj2 2603: =item * $clientbrowser
1.87 matthew 2604:
1.112 bowersj2 2605: =item * $clientversion
1.87 matthew 2606:
1.112 bowersj2 2607: =item * $clientmathml
1.87 matthew 2608:
1.112 bowersj2 2609: =item * $clientunicode
1.87 matthew 2610:
1.112 bowersj2 2611: =item * $clientos
1.87 matthew 2612:
1.1075.2.42 raeburn 2613: =item * $clientmobile
2614:
2615: =item * $clientinfo
2616:
1.1075.2.77 raeburn 2617: =item * $clientosversion
2618:
1.87 matthew 2619: =back
2620:
1.157 matthew 2621: =back
2622:
1.87 matthew 2623: =cut
2624:
2625: ###############################################################
2626: ###############################################################
2627: sub decode_user_agent {
1.247 albertel 2628: my ($r)=@_;
1.87 matthew 2629: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2630: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2631: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2632: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2633: my $clientbrowser='unknown';
2634: my $clientversion='0';
2635: my $clientmathml='';
2636: my $clientunicode='0';
1.1075.2.42 raeburn 2637: my $clientmobile=0;
1.1075.2.77 raeburn 2638: my $clientosversion='';
1.87 matthew 2639: for (my $i=0;$i<=$#browsertype;$i++) {
1.1075.2.76 raeburn 2640: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2641: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2642: $clientbrowser=$bname;
2643: $httpbrowser=~/$vreg/i;
2644: $clientversion=$1;
2645: $clientmathml=($clientversion>=$minv);
2646: $clientunicode=($clientversion>=$univ);
2647: }
2648: }
2649: my $clientos='unknown';
1.1075.2.42 raeburn 2650: my $clientinfo;
1.87 matthew 2651: if (($httpbrowser=~/linux/i) ||
2652: ($httpbrowser=~/unix/i) ||
2653: ($httpbrowser=~/ux/i) ||
2654: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2655: if (($httpbrowser=~/vax/i) ||
2656: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2657: if ($httpbrowser=~/next/i) { $clientos='next'; }
2658: if (($httpbrowser=~/mac/i) ||
2659: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1075.2.77 raeburn 2660: if ($httpbrowser=~/win/i) {
2661: $clientos='win';
2662: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2663: $clientosversion = $1;
2664: }
2665: }
1.87 matthew 2666: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2667: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2668: $clientmobile=lc($1);
2669: }
2670: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2671: $clientinfo = 'firefox-'.$1;
2672: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2673: $clientinfo = 'chromeframe-'.$1;
2674: }
1.87 matthew 2675: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.77 raeburn 2676: $clientunicode,$clientos,$clientmobile,$clientinfo,
2677: $clientosversion);
1.87 matthew 2678: }
2679:
1.32 matthew 2680: ###############################################################
2681: ## Authentication changing form generation subroutines ##
2682: ###############################################################
2683: ##
2684: ## All of the authform_xxxxxxx subroutines take their inputs in a
2685: ## hash, and have reasonable default values.
2686: ##
2687: ## formname = the name given in the <form> tag.
1.35 matthew 2688: #-------------------------------------------
2689:
1.45 matthew 2690: =pod
2691:
1.112 bowersj2 2692: =head1 Authentication Routines
2693:
2694: =over 4
2695:
1.648 raeburn 2696: =item * &authform_xxxxxx()
1.35 matthew 2697:
2698: The authform_xxxxxx subroutines provide javascript and html forms which
2699: handle some of the conveniences required for authentication forms.
2700: This is not an optimal method, but it works.
2701:
2702: =over 4
2703:
1.112 bowersj2 2704: =item * authform_header
1.35 matthew 2705:
1.112 bowersj2 2706: =item * authform_authorwarning
1.35 matthew 2707:
1.112 bowersj2 2708: =item * authform_nochange
1.35 matthew 2709:
1.112 bowersj2 2710: =item * authform_kerberos
1.35 matthew 2711:
1.112 bowersj2 2712: =item * authform_internal
1.35 matthew 2713:
1.112 bowersj2 2714: =item * authform_filesystem
1.35 matthew 2715:
2716: =back
2717:
1.648 raeburn 2718: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2719:
1.35 matthew 2720: =cut
2721:
2722: #-------------------------------------------
1.32 matthew 2723: sub authform_header{
2724: my %in = (
2725: formname => 'cu',
1.80 albertel 2726: kerb_def_dom => '',
1.32 matthew 2727: @_,
2728: );
2729: $in{'formname'} = 'document.' . $in{'formname'};
2730: my $result='';
1.80 albertel 2731:
2732: #---------------------------------------------- Code for upper case translation
2733: my $Javascript_toUpperCase;
2734: unless ($in{kerb_def_dom}) {
2735: $Javascript_toUpperCase =<<"END";
2736: switch (choice) {
2737: case 'krb': currentform.elements[choicearg].value =
2738: currentform.elements[choicearg].value.toUpperCase();
2739: break;
2740: default:
2741: }
2742: END
2743: } else {
2744: $Javascript_toUpperCase = "";
2745: }
2746:
1.165 raeburn 2747: my $radioval = "'nochange'";
1.591 raeburn 2748: if (defined($in{'curr_authtype'})) {
2749: if ($in{'curr_authtype'} ne '') {
2750: $radioval = "'".$in{'curr_authtype'}."arg'";
2751: }
1.174 matthew 2752: }
1.165 raeburn 2753: my $argfield = 'null';
1.591 raeburn 2754: if (defined($in{'mode'})) {
1.165 raeburn 2755: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2756: if (defined($in{'curr_autharg'})) {
2757: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2758: $argfield = "'$in{'curr_autharg'}'";
2759: }
2760: }
2761: }
2762: }
2763:
1.32 matthew 2764: $result.=<<"END";
2765: var current = new Object();
1.165 raeburn 2766: current.radiovalue = $radioval;
2767: current.argfield = $argfield;
1.32 matthew 2768:
2769: function changed_radio(choice,currentform) {
2770: var choicearg = choice + 'arg';
2771: // If a radio button in changed, we need to change the argfield
2772: if (current.radiovalue != choice) {
2773: current.radiovalue = choice;
2774: if (current.argfield != null) {
2775: currentform.elements[current.argfield].value = '';
2776: }
2777: if (choice == 'nochange') {
2778: current.argfield = null;
2779: } else {
2780: current.argfield = choicearg;
2781: switch(choice) {
2782: case 'krb':
2783: currentform.elements[current.argfield].value =
2784: "$in{'kerb_def_dom'}";
2785: break;
2786: default:
2787: break;
2788: }
2789: }
2790: }
2791: return;
2792: }
1.22 www 2793:
1.32 matthew 2794: function changed_text(choice,currentform) {
2795: var choicearg = choice + 'arg';
2796: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2797: $Javascript_toUpperCase
1.32 matthew 2798: // clear old field
2799: if ((current.argfield != choicearg) && (current.argfield != null)) {
2800: currentform.elements[current.argfield].value = '';
2801: }
2802: current.argfield = choicearg;
2803: }
2804: set_auth_radio_buttons(choice,currentform);
2805: return;
1.20 www 2806: }
1.32 matthew 2807:
2808: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2809: var numauthchoices = currentform.login.length;
2810: if (typeof numauthchoices == "undefined") {
2811: return;
2812: }
1.32 matthew 2813: var i=0;
1.986 raeburn 2814: while (i < numauthchoices) {
1.32 matthew 2815: if (currentform.login[i].value == newvalue) { break; }
2816: i++;
2817: }
1.986 raeburn 2818: if (i == numauthchoices) {
1.32 matthew 2819: return;
2820: }
2821: current.radiovalue = newvalue;
2822: currentform.login[i].checked = true;
2823: return;
2824: }
2825: END
2826: return $result;
2827: }
2828:
1.1075.2.20 raeburn 2829: sub authform_authorwarning {
1.32 matthew 2830: my $result='';
1.144 matthew 2831: $result='<i>'.
2832: &mt('As a general rule, only authors or co-authors should be '.
2833: 'filesystem authenticated '.
2834: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2835: return $result;
2836: }
2837:
1.1075.2.20 raeburn 2838: sub authform_nochange {
1.32 matthew 2839: my %in = (
2840: formname => 'document.cu',
2841: kerb_def_dom => 'MSU.EDU',
2842: @_,
2843: );
1.1075.2.20 raeburn 2844: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2845: my $result;
1.1075.2.20 raeburn 2846: if (!$authnum) {
2847: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2848: } else {
2849: $result = '<label>'.&mt('[_1] Do not change login data',
2850: '<input type="radio" name="login" value="nochange" '.
2851: 'checked="checked" onclick="'.
1.281 albertel 2852: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2853: '</label>';
1.586 raeburn 2854: }
1.32 matthew 2855: return $result;
2856: }
2857:
1.591 raeburn 2858: sub authform_kerberos {
1.32 matthew 2859: my %in = (
2860: formname => 'document.cu',
2861: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2862: kerb_def_auth => 'krb4',
1.32 matthew 2863: @_,
2864: );
1.586 raeburn 2865: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1075.2.117 raeburn 2866: $autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2867: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2868: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2869: $check5 = ' checked="checked"';
1.80 albertel 2870: } else {
1.772 bisitz 2871: $check4 = ' checked="checked"';
1.80 albertel 2872: }
1.1075.2.117 raeburn 2873: if ($in{'readonly'}) {
2874: $disabled = ' disabled="disabled"';
2875: }
1.165 raeburn 2876: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2877: if (defined($in{'curr_authtype'})) {
2878: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2879: $krbcheck = ' checked="checked"';
1.623 raeburn 2880: if (defined($in{'mode'})) {
2881: if ($in{'mode'} eq 'modifyuser') {
2882: $krbcheck = '';
2883: }
2884: }
1.591 raeburn 2885: if (defined($in{'curr_kerb_ver'})) {
2886: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2887: $check5 = ' checked="checked"';
1.591 raeburn 2888: $check4 = '';
2889: } else {
1.772 bisitz 2890: $check4 = ' checked="checked"';
1.591 raeburn 2891: $check5 = '';
2892: }
1.586 raeburn 2893: }
1.591 raeburn 2894: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2895: $krbarg = $in{'curr_autharg'};
2896: }
1.586 raeburn 2897: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2898: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2899: $result =
2900: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2901: $in{'curr_autharg'},$krbver);
2902: } else {
2903: $result =
2904: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2905: }
2906: return $result;
2907: }
2908: }
2909: } else {
2910: if ($authnum == 1) {
1.784 bisitz 2911: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2912: }
2913: }
1.586 raeburn 2914: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2915: return;
1.587 raeburn 2916: } elsif ($authtype eq '') {
1.591 raeburn 2917: if (defined($in{'mode'})) {
1.587 raeburn 2918: if ($in{'mode'} eq 'modifycourse') {
2919: if ($authnum == 1) {
1.1075.2.117 raeburn 2920: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 2921: }
2922: }
2923: }
1.586 raeburn 2924: }
2925: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2926: if ($authtype eq '') {
2927: $authtype = '<input type="radio" name="login" value="krb" '.
2928: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1075.2.117 raeburn 2929: $krbcheck.$disabled.' />';
1.586 raeburn 2930: }
2931: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2932: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2933: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2934: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2935: $in{'curr_authtype'} eq 'krb4')) {
2936: $result .= &mt
1.144 matthew 2937: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2938: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2939: '<label>'.$authtype,
1.281 albertel 2940: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2941: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2942: 'onchange="'.$jscall.'"'.$disabled.' />',
2943: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
2944: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 2945: '</label>');
1.586 raeburn 2946: } elsif ($can_assign{'krb4'}) {
2947: $result .= &mt
2948: ('[_1] Kerberos authenticated with domain [_2] '.
2949: '[_3] Version 4 [_4]',
2950: '<label>'.$authtype,
2951: '</label><input type="text" size="10" name="krbarg" '.
2952: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2953: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2954: '<label><input type="hidden" name="krbver" value="4" />',
2955: '</label>');
2956: } elsif ($can_assign{'krb5'}) {
2957: $result .= &mt
2958: ('[_1] Kerberos authenticated with domain [_2] '.
2959: '[_3] Version 5 [_4]',
2960: '<label>'.$authtype,
2961: '</label><input type="text" size="10" name="krbarg" '.
2962: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2963: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2964: '<label><input type="hidden" name="krbver" value="5" />',
2965: '</label>');
2966: }
1.32 matthew 2967: return $result;
2968: }
2969:
1.1075.2.20 raeburn 2970: sub authform_internal {
1.586 raeburn 2971: my %in = (
1.32 matthew 2972: formname => 'document.cu',
2973: kerb_def_dom => 'MSU.EDU',
2974: @_,
2975: );
1.1075.2.117 raeburn 2976: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2977: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 2978: if ($in{'readonly'}) {
2979: $disabled = ' disabled="disabled"';
2980: }
1.591 raeburn 2981: if (defined($in{'curr_authtype'})) {
2982: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2983: if ($can_assign{'int'}) {
1.772 bisitz 2984: $intcheck = 'checked="checked" ';
1.623 raeburn 2985: if (defined($in{'mode'})) {
2986: if ($in{'mode'} eq 'modifyuser') {
2987: $intcheck = '';
2988: }
2989: }
1.591 raeburn 2990: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2991: $intarg = $in{'curr_autharg'};
2992: }
2993: } else {
2994: $result = &mt('Currently internally authenticated.');
2995: return $result;
1.165 raeburn 2996: }
2997: }
1.586 raeburn 2998: } else {
2999: if ($authnum == 1) {
1.784 bisitz 3000: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3001: }
3002: }
3003: if (!$can_assign{'int'}) {
3004: return;
1.587 raeburn 3005: } elsif ($authtype eq '') {
1.591 raeburn 3006: if (defined($in{'mode'})) {
1.587 raeburn 3007: if ($in{'mode'} eq 'modifycourse') {
3008: if ($authnum == 1) {
1.1075.2.117 raeburn 3009: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3010: }
3011: }
3012: }
1.165 raeburn 3013: }
1.586 raeburn 3014: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3015: if ($authtype eq '') {
3016: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1075.2.117 raeburn 3017: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3018: }
1.605 bisitz 3019: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1075.2.117 raeburn 3020: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3021: $result = &mt
1.144 matthew 3022: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3023: '<label>'.$authtype,'</label>'.$autharg);
1.1075.2.118 raeburn 3024: $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 3025: return $result;
3026: }
3027:
1.1075.2.20 raeburn 3028: sub authform_local {
1.32 matthew 3029: my %in = (
3030: formname => 'document.cu',
3031: kerb_def_dom => 'MSU.EDU',
3032: @_,
3033: );
1.1075.2.117 raeburn 3034: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3035: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3036: if ($in{'readonly'}) {
3037: $disabled = ' disabled="disabled"';
3038: }
1.591 raeburn 3039: if (defined($in{'curr_authtype'})) {
3040: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3041: if ($can_assign{'loc'}) {
1.772 bisitz 3042: $loccheck = 'checked="checked" ';
1.623 raeburn 3043: if (defined($in{'mode'})) {
3044: if ($in{'mode'} eq 'modifyuser') {
3045: $loccheck = '';
3046: }
3047: }
1.591 raeburn 3048: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3049: $locarg = $in{'curr_autharg'};
3050: }
3051: } else {
3052: $result = &mt('Currently using local (institutional) authentication.');
3053: return $result;
1.165 raeburn 3054: }
3055: }
1.586 raeburn 3056: } else {
3057: if ($authnum == 1) {
1.784 bisitz 3058: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3059: }
3060: }
3061: if (!$can_assign{'loc'}) {
3062: return;
1.587 raeburn 3063: } elsif ($authtype eq '') {
1.591 raeburn 3064: if (defined($in{'mode'})) {
1.587 raeburn 3065: if ($in{'mode'} eq 'modifycourse') {
3066: if ($authnum == 1) {
1.1075.2.117 raeburn 3067: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3068: }
3069: }
3070: }
1.165 raeburn 3071: }
1.586 raeburn 3072: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3073: if ($authtype eq '') {
3074: $authtype = '<input type="radio" name="login" value="loc" '.
3075: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3076: $jscall.'"'.$disabled.' />';
1.586 raeburn 3077: }
3078: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1075.2.117 raeburn 3079: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3080: $result = &mt('[_1] Local Authentication with argument [_2]',
3081: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3082: return $result;
3083: }
3084:
1.1075.2.20 raeburn 3085: sub authform_filesystem {
1.32 matthew 3086: my %in = (
3087: formname => 'document.cu',
3088: kerb_def_dom => 'MSU.EDU',
3089: @_,
3090: );
1.1075.2.117 raeburn 3091: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3092: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3093: if ($in{'readonly'}) {
3094: $disabled = ' disabled="disabled"';
3095: }
1.591 raeburn 3096: if (defined($in{'curr_authtype'})) {
3097: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3098: if ($can_assign{'fsys'}) {
1.772 bisitz 3099: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3100: if (defined($in{'mode'})) {
3101: if ($in{'mode'} eq 'modifyuser') {
3102: $fsyscheck = '';
3103: }
3104: }
1.586 raeburn 3105: } else {
3106: $result = &mt('Currently Filesystem Authenticated.');
3107: return $result;
3108: }
3109: }
3110: } else {
3111: if ($authnum == 1) {
1.784 bisitz 3112: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3113: }
3114: }
3115: if (!$can_assign{'fsys'}) {
3116: return;
1.587 raeburn 3117: } elsif ($authtype eq '') {
1.591 raeburn 3118: if (defined($in{'mode'})) {
1.587 raeburn 3119: if ($in{'mode'} eq 'modifycourse') {
3120: if ($authnum == 1) {
1.1075.2.117 raeburn 3121: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3122: }
3123: }
3124: }
1.586 raeburn 3125: }
3126: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3127: if ($authtype eq '') {
3128: $authtype = '<input type="radio" name="login" value="fsys" '.
3129: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3130: $jscall.'"'.$disabled.' />';
1.586 raeburn 3131: }
3132: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
1.1075.2.117 raeburn 3133: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3134: $result = &mt
1.144 matthew 3135: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 3136: '<label><input type="radio" name="login" value="fsys" '.
1.1075.2.117 raeburn 3137: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />',
1.605 bisitz 3138: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.1075.2.117 raeburn 3139: 'onchange="'.$jscall.'"'.$disabled.' />');
1.32 matthew 3140: return $result;
3141: }
3142:
1.586 raeburn 3143: sub get_assignable_auth {
3144: my ($dom) = @_;
3145: if ($dom eq '') {
3146: $dom = $env{'request.role.domain'};
3147: }
3148: my %can_assign = (
3149: krb4 => 1,
3150: krb5 => 1,
3151: int => 1,
3152: loc => 1,
3153: );
3154: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3155: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3156: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3157: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3158: my $context;
3159: if ($env{'request.role'} =~ /^au/) {
3160: $context = 'author';
1.1075.2.117 raeburn 3161: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3162: $context = 'domain';
3163: } elsif ($env{'request.course.id'}) {
3164: $context = 'course';
3165: }
3166: if ($context) {
3167: if (ref($authhash->{$context}) eq 'HASH') {
3168: %can_assign = %{$authhash->{$context}};
3169: }
3170: }
3171: }
3172: }
3173: my $authnum = 0;
3174: foreach my $key (keys(%can_assign)) {
3175: if ($can_assign{$key}) {
3176: $authnum ++;
3177: }
3178: }
3179: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3180: $authnum --;
3181: }
3182: return ($authnum,%can_assign);
3183: }
3184:
1.1075.2.137 raeburn 3185: sub check_passwd_rules {
3186: my ($domain,$plainpass) = @_;
3187: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3188: my ($min,$max,@chars,@brokerule,$warning);
1.1075.2.138 raeburn 3189: $min = $Apache::lonnet::passwdmin;
1.1075.2.137 raeburn 3190: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3191: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1075.2.138 raeburn 3192: if ($passwdconf{'min'} > $min) {
3193: $min = $passwdconf{'min'};
3194: }
1.1075.2.137 raeburn 3195: }
3196: if ($passwdconf{'max'} =~ /^\d+$/) {
3197: $max = $passwdconf{'max'};
3198: }
3199: @chars = @{$passwdconf{'chars'}};
3200: }
3201: if (($min) && (length($plainpass) < $min)) {
3202: push(@brokerule,'min');
3203: }
3204: if (($max) && (length($plainpass) > $max)) {
3205: push(@brokerule,'max');
3206: }
3207: if (@chars) {
3208: my %rules;
3209: map { $rules{$_} = 1; } @chars;
3210: if ($rules{'uc'}) {
3211: unless ($plainpass =~ /[A-Z]/) {
3212: push(@brokerule,'uc');
3213: }
3214: }
3215: if ($rules{'lc'}) {
3216: unless ($plainpass =~ /[a-z]/) {
3217: push(@brokerule,'lc');
3218: }
3219: }
3220: if ($rules{'num'}) {
3221: unless ($plainpass =~ /\d/) {
3222: push(@brokerule,'num');
3223: }
3224: }
3225: if ($rules{'spec'}) {
3226: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3227: push(@brokerule,'spec');
3228: }
3229: }
3230: }
3231: if (@brokerule) {
3232: my %rulenames = &Apache::lonlocal::texthash(
3233: uc => 'At least one upper case letter',
3234: lc => 'At least one lower case letter',
3235: num => 'At least one number',
3236: spec => 'At least one non-alphanumeric',
3237: );
3238: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3239: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3240: $rulenames{'num'} .= ': 0123456789';
3241: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3242: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3243: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3244: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1075.2.141. .3(raebu 3245:20): foreach my $rule ('min','max','uc','lc','num','spec') {
1.1075.2.137 raeburn 3246: if (grep(/^$rule$/,@brokerule)) {
3247: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3248: }
3249: }
3250: $warning .= '</ul>';
3251: }
3252: if (wantarray) {
3253: return @brokerule;
3254: }
3255: return $warning;
3256: }
3257:
1.80 albertel 3258: ###############################################################
3259: ## Get Kerberos Defaults for Domain ##
3260: ###############################################################
3261: ##
3262: ## Returns default kerberos version and an associated argument
3263: ## as listed in file domain.tab. If not listed, provides
3264: ## appropriate default domain and kerberos version.
3265: ##
3266: #-------------------------------------------
3267:
3268: =pod
3269:
1.648 raeburn 3270: =item * &get_kerberos_defaults()
1.80 albertel 3271:
3272: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3273: version and domain. If not found, it defaults to version 4 and the
3274: domain of the server.
1.80 albertel 3275:
1.648 raeburn 3276: =over 4
3277:
1.80 albertel 3278: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3279:
1.648 raeburn 3280: =back
3281:
3282: =back
3283:
1.80 albertel 3284: =cut
3285:
3286: #-------------------------------------------
3287: sub get_kerberos_defaults {
3288: my $domain=shift;
1.641 raeburn 3289: my ($krbdef,$krbdefdom);
3290: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3291: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3292: $krbdef = $domdefaults{'auth_def'};
3293: $krbdefdom = $domdefaults{'auth_arg_def'};
3294: } else {
1.80 albertel 3295: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3296: my $krbdefdom=$1;
3297: $krbdefdom=~tr/a-z/A-Z/;
3298: $krbdef = "krb4";
3299: }
3300: return ($krbdef,$krbdefdom);
3301: }
1.112 bowersj2 3302:
1.32 matthew 3303:
1.46 matthew 3304: ###############################################################
3305: ## Thesaurus Functions ##
3306: ###############################################################
1.20 www 3307:
1.46 matthew 3308: =pod
1.20 www 3309:
1.112 bowersj2 3310: =head1 Thesaurus Functions
3311:
3312: =over 4
3313:
1.648 raeburn 3314: =item * &initialize_keywords()
1.46 matthew 3315:
3316: Initializes the package variable %Keywords if it is empty. Uses the
3317: package variable $thesaurus_db_file.
3318:
3319: =cut
3320:
3321: ###################################################
3322:
3323: sub initialize_keywords {
3324: return 1 if (scalar keys(%Keywords));
3325: # If we are here, %Keywords is empty, so fill it up
3326: # Make sure the file we need exists...
3327: if (! -e $thesaurus_db_file) {
3328: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3329: " failed because it does not exist");
3330: return 0;
3331: }
3332: # Set up the hash as a database
3333: my %thesaurus_db;
3334: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3335: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3336: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3337: $thesaurus_db_file);
3338: return 0;
3339: }
3340: # Get the average number of appearances of a word.
3341: my $avecount = $thesaurus_db{'average.count'};
3342: # Put keywords (those that appear > average) into %Keywords
3343: while (my ($word,$data)=each (%thesaurus_db)) {
3344: my ($count,undef) = split /:/,$data;
3345: $Keywords{$word}++ if ($count > $avecount);
3346: }
3347: untie %thesaurus_db;
3348: # Remove special values from %Keywords.
1.356 albertel 3349: foreach my $value ('total.count','average.count') {
3350: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3351: }
1.46 matthew 3352: return 1;
3353: }
3354:
3355: ###################################################
3356:
3357: =pod
3358:
1.648 raeburn 3359: =item * &keyword($word)
1.46 matthew 3360:
3361: Returns true if $word is a keyword. A keyword is a word that appears more
3362: than the average number of times in the thesaurus database. Calls
3363: &initialize_keywords
3364:
3365: =cut
3366:
3367: ###################################################
1.20 www 3368:
3369: sub keyword {
1.46 matthew 3370: return if (!&initialize_keywords());
3371: my $word=lc(shift());
3372: $word=~s/\W//g;
3373: return exists($Keywords{$word});
1.20 www 3374: }
1.46 matthew 3375:
3376: ###############################################################
3377:
3378: =pod
1.20 www 3379:
1.648 raeburn 3380: =item * &get_related_words()
1.46 matthew 3381:
1.160 matthew 3382: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3383: an array of words. If the keyword is not in the thesaurus, an empty array
3384: will be returned. The order of the words returned is determined by the
3385: database which holds them.
3386:
3387: Uses global $thesaurus_db_file.
3388:
1.1057 foxr 3389:
1.46 matthew 3390: =cut
3391:
3392: ###############################################################
3393: sub get_related_words {
3394: my $keyword = shift;
3395: my %thesaurus_db;
3396: if (! -e $thesaurus_db_file) {
3397: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3398: "failed because the file does not exist");
3399: return ();
3400: }
3401: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3402: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3403: return ();
3404: }
3405: my @Words=();
1.429 www 3406: my $count=0;
1.46 matthew 3407: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3408: # The first element is the number of times
3409: # the word appears. We do not need it now.
1.429 www 3410: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3411: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3412: my $threshold=$mostfrequentcount/10;
3413: foreach my $possibleword (@RelatedWords) {
3414: my ($word,$wordcount)=split(/\,/,$possibleword);
3415: if ($wordcount>$threshold) {
3416: push(@Words,$word);
3417: $count++;
3418: if ($count>10) { last; }
3419: }
1.20 www 3420: }
3421: }
1.46 matthew 3422: untie %thesaurus_db;
3423: return @Words;
1.14 harris41 3424: }
1.46 matthew 3425:
1.112 bowersj2 3426: =pod
3427:
3428: =back
3429:
3430: =cut
1.61 www 3431:
3432: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3433: =pod
3434:
1.112 bowersj2 3435: =head1 User Name Functions
3436:
3437: =over 4
3438:
1.648 raeburn 3439: =item * &plainname($uname,$udom,$first)
1.81 albertel 3440:
1.112 bowersj2 3441: Takes a users logon name and returns it as a string in
1.226 albertel 3442: "first middle last generation" form
3443: if $first is set to 'lastname' then it returns it as
3444: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3445:
3446: =cut
1.61 www 3447:
1.295 www 3448:
1.81 albertel 3449: ###############################################################
1.61 www 3450: sub plainname {
1.226 albertel 3451: my ($uname,$udom,$first)=@_;
1.537 albertel 3452: return if (!defined($uname) || !defined($udom));
1.295 www 3453: my %names=&getnames($uname,$udom);
1.226 albertel 3454: my $name=&Apache::lonnet::format_name($names{'firstname'},
3455: $names{'middlename'},
3456: $names{'lastname'},
3457: $names{'generation'},$first);
3458: $name=~s/^\s+//;
1.62 www 3459: $name=~s/\s+$//;
3460: $name=~s/\s+/ /g;
1.353 albertel 3461: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3462: return $name;
1.61 www 3463: }
1.66 www 3464:
3465: # -------------------------------------------------------------------- Nickname
1.81 albertel 3466: =pod
3467:
1.648 raeburn 3468: =item * &nickname($uname,$udom)
1.81 albertel 3469:
3470: Gets a users name and returns it as a string as
3471:
3472: ""nickname""
1.66 www 3473:
1.81 albertel 3474: if the user has a nickname or
3475:
3476: "first middle last generation"
3477:
3478: if the user does not
3479:
3480: =cut
1.66 www 3481:
3482: sub nickname {
3483: my ($uname,$udom)=@_;
1.537 albertel 3484: return if (!defined($uname) || !defined($udom));
1.295 www 3485: my %names=&getnames($uname,$udom);
1.68 albertel 3486: my $name=$names{'nickname'};
1.66 www 3487: if ($name) {
3488: $name='"'.$name.'"';
3489: } else {
3490: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3491: $names{'lastname'}.' '.$names{'generation'};
3492: $name=~s/\s+$//;
3493: $name=~s/\s+/ /g;
3494: }
3495: return $name;
3496: }
3497:
1.295 www 3498: sub getnames {
3499: my ($uname,$udom)=@_;
1.537 albertel 3500: return if (!defined($uname) || !defined($udom));
1.433 albertel 3501: if ($udom eq 'public' && $uname eq 'public') {
3502: return ('lastname' => &mt('Public'));
3503: }
1.295 www 3504: my $id=$uname.':'.$udom;
3505: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3506: if ($cached) {
3507: return %{$names};
3508: } else {
3509: my %loadnames=&Apache::lonnet::get('environment',
3510: ['firstname','middlename','lastname','generation','nickname'],
3511: $udom,$uname);
3512: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3513: return %loadnames;
3514: }
3515: }
1.61 www 3516:
1.542 raeburn 3517: # -------------------------------------------------------------------- getemails
1.648 raeburn 3518:
1.542 raeburn 3519: =pod
3520:
1.648 raeburn 3521: =item * &getemails($uname,$udom)
1.542 raeburn 3522:
3523: Gets a user's email information and returns it as a hash with keys:
3524: notification, critnotification, permanentemail
3525:
3526: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3527: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3528:
1.648 raeburn 3529:
1.542 raeburn 3530: =cut
3531:
1.648 raeburn 3532:
1.466 albertel 3533: sub getemails {
3534: my ($uname,$udom)=@_;
3535: if ($udom eq 'public' && $uname eq 'public') {
3536: return;
3537: }
1.467 www 3538: if (!$udom) { $udom=$env{'user.domain'}; }
3539: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3540: my $id=$uname.':'.$udom;
3541: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3542: if ($cached) {
3543: return %{$names};
3544: } else {
3545: my %loadnames=&Apache::lonnet::get('environment',
3546: ['notification','critnotification',
3547: 'permanentemail'],
3548: $udom,$uname);
3549: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3550: return %loadnames;
3551: }
3552: }
3553:
1.551 albertel 3554: sub flush_email_cache {
3555: my ($uname,$udom)=@_;
3556: if (!$udom) { $udom =$env{'user.domain'}; }
3557: if (!$uname) { $uname=$env{'user.name'}; }
3558: return if ($udom eq 'public' && $uname eq 'public');
3559: my $id=$uname.':'.$udom;
3560: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3561: }
3562:
1.728 raeburn 3563: # -------------------------------------------------------------------- getlangs
3564:
3565: =pod
3566:
3567: =item * &getlangs($uname,$udom)
3568:
3569: Gets a user's language preference and returns it as a hash with key:
3570: language.
3571:
3572: =cut
3573:
3574:
3575: sub getlangs {
3576: my ($uname,$udom) = @_;
3577: if (!$udom) { $udom =$env{'user.domain'}; }
3578: if (!$uname) { $uname=$env{'user.name'}; }
3579: my $id=$uname.':'.$udom;
3580: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3581: if ($cached) {
3582: return %{$langs};
3583: } else {
3584: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3585: $udom,$uname);
3586: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3587: return %loadlangs;
3588: }
3589: }
3590:
3591: sub flush_langs_cache {
3592: my ($uname,$udom)=@_;
3593: if (!$udom) { $udom =$env{'user.domain'}; }
3594: if (!$uname) { $uname=$env{'user.name'}; }
3595: return if ($udom eq 'public' && $uname eq 'public');
3596: my $id=$uname.':'.$udom;
3597: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3598: }
3599:
1.61 www 3600: # ------------------------------------------------------------------ Screenname
1.81 albertel 3601:
3602: =pod
3603:
1.648 raeburn 3604: =item * &screenname($uname,$udom)
1.81 albertel 3605:
3606: Gets a users screenname and returns it as a string
3607:
3608: =cut
1.61 www 3609:
3610: sub screenname {
3611: my ($uname,$udom)=@_;
1.258 albertel 3612: if ($uname eq $env{'user.name'} &&
3613: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3614: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3615: return $names{'screenname'};
1.62 www 3616: }
3617:
1.212 albertel 3618:
1.802 bisitz 3619: # ------------------------------------------------------------- Confirm Wrapper
3620: =pod
3621:
1.1075.2.42 raeburn 3622: =item * &confirmwrapper($message)
1.802 bisitz 3623:
3624: Wrap messages about completion of operation in box
3625:
3626: =cut
3627:
3628: sub confirmwrapper {
3629: my ($message)=@_;
3630: if ($message) {
3631: return "\n".'<div class="LC_confirm_box">'."\n"
3632: .$message."\n"
3633: .'</div>'."\n";
3634: } else {
3635: return $message;
3636: }
3637: }
3638:
1.62 www 3639: # ------------------------------------------------------------- Message Wrapper
3640:
3641: sub messagewrapper {
1.369 www 3642: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3643: return
1.441 albertel 3644: '<a href="/adm/email?compose=individual&'.
3645: 'recname='.$username.'&recdom='.$domain.
3646: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3647: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3648: }
1.802 bisitz 3649:
1.74 www 3650: # --------------------------------------------------------------- Notes Wrapper
3651:
3652: sub noteswrapper {
3653: my ($link,$un,$do)=@_;
3654: return
1.896 amueller 3655: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3656: }
1.802 bisitz 3657:
1.62 www 3658: # ------------------------------------------------------------- Aboutme Wrapper
3659:
3660: sub aboutmewrapper {
1.1070 raeburn 3661: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3662: if (!defined($username) && !defined($domain)) {
3663: return;
3664: }
1.1075.2.15 raeburn 3665: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3666: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3667: }
3668:
3669: # ------------------------------------------------------------ Syllabus Wrapper
3670:
3671: sub syllabuswrapper {
1.707 bisitz 3672: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3673: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3674: }
1.14 harris41 3675:
1.802 bisitz 3676: # -----------------------------------------------------------------------------
3677:
1.208 matthew 3678: sub track_student_link {
1.887 raeburn 3679: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3680: my $link ="/adm/trackstudent?";
1.208 matthew 3681: my $title = 'View recent activity';
3682: if (defined($sname) && $sname !~ /^\s*$/ &&
3683: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3684: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3685: $title .= ' of this student';
1.268 albertel 3686: }
1.208 matthew 3687: if (defined($target) && $target !~ /^\s*$/) {
3688: $target = qq{target="$target"};
3689: } else {
3690: $target = '';
3691: }
1.268 albertel 3692: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3693: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3694: $title = &mt($title);
3695: $linktext = &mt($linktext);
1.448 albertel 3696: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3697: &help_open_topic('View_recent_activity');
1.208 matthew 3698: }
3699:
1.781 raeburn 3700: sub slot_reservations_link {
3701: my ($linktext,$sname,$sdom,$target) = @_;
3702: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3703: my $title = 'View slot reservation history';
3704: if (defined($sname) && $sname !~ /^\s*$/ &&
3705: defined($sdom) && $sdom !~ /^\s*$/) {
3706: $link .= "&uname=$sname&udom=$sdom";
3707: $title .= ' of this student';
3708: }
3709: if (defined($target) && $target !~ /^\s*$/) {
3710: $target = qq{target="$target"};
3711: } else {
3712: $target = '';
3713: }
3714: $title = &mt($title);
3715: $linktext = &mt($linktext);
3716: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3717: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3718:
3719: }
3720:
1.508 www 3721: # ===================================================== Display a student photo
3722:
3723:
1.509 albertel 3724: sub student_image_tag {
1.508 www 3725: my ($domain,$user)=@_;
3726: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3727: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3728: return '<img src="'.$imgsrc.'" align="right" />';
3729: } else {
3730: return '';
3731: }
3732: }
3733:
1.112 bowersj2 3734: =pod
3735:
3736: =back
3737:
3738: =head1 Access .tab File Data
3739:
3740: =over 4
3741:
1.648 raeburn 3742: =item * &languageids()
1.112 bowersj2 3743:
3744: returns list of all language ids
3745:
3746: =cut
3747:
1.14 harris41 3748: sub languageids {
1.16 harris41 3749: return sort(keys(%language));
1.14 harris41 3750: }
3751:
1.112 bowersj2 3752: =pod
3753:
1.648 raeburn 3754: =item * &languagedescription()
1.112 bowersj2 3755:
3756: returns description of a specified language id
3757:
3758: =cut
3759:
1.14 harris41 3760: sub languagedescription {
1.125 www 3761: my $code=shift;
3762: return ($supported_language{$code}?'* ':'').
3763: $language{$code}.
1.126 www 3764: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3765: }
3766:
1.1048 foxr 3767: =pod
3768:
3769: =item * &plainlanguagedescription
3770:
3771: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3772: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3773:
3774: =cut
3775:
1.145 www 3776: sub plainlanguagedescription {
3777: my $code=shift;
3778: return $language{$code};
3779: }
3780:
1.1048 foxr 3781: =pod
3782:
3783: =item * &supportedlanguagecode
3784:
3785: Returns the supported language code (e.g. sptutf maps to pt) given a language
3786: code.
3787:
3788: =cut
3789:
1.145 www 3790: sub supportedlanguagecode {
3791: my $code=shift;
3792: return $supported_language{$code};
1.97 www 3793: }
3794:
1.112 bowersj2 3795: =pod
3796:
1.1048 foxr 3797: =item * &latexlanguage()
3798:
3799: Given a language key code returns the correspondnig language to use
3800: to select the correct hyphenation on LaTeX printouts. This is undef if there
3801: is no supported hyphenation for the language code.
3802:
3803: =cut
3804:
3805: sub latexlanguage {
3806: my $code = shift;
3807: return $latex_language{$code};
3808: }
3809:
3810: =pod
3811:
3812: =item * &latexhyphenation()
3813:
3814: Same as above but what's supplied is the language as it might be stored
3815: in the metadata.
3816:
3817: =cut
3818:
3819: sub latexhyphenation {
3820: my $key = shift;
3821: return $latex_language_bykey{$key};
3822: }
3823:
3824: =pod
3825:
1.648 raeburn 3826: =item * ©rightids()
1.112 bowersj2 3827:
3828: returns list of all copyrights
3829:
3830: =cut
3831:
3832: sub copyrightids {
3833: return sort(keys(%cprtag));
3834: }
3835:
3836: =pod
3837:
1.648 raeburn 3838: =item * ©rightdescription()
1.112 bowersj2 3839:
3840: returns description of a specified copyright id
3841:
3842: =cut
3843:
3844: sub copyrightdescription {
1.166 www 3845: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3846: }
1.197 matthew 3847:
3848: =pod
3849:
1.648 raeburn 3850: =item * &source_copyrightids()
1.192 taceyjo1 3851:
3852: returns list of all source copyrights
3853:
3854: =cut
3855:
3856: sub source_copyrightids {
3857: return sort(keys(%scprtag));
3858: }
3859:
3860: =pod
3861:
1.648 raeburn 3862: =item * &source_copyrightdescription()
1.192 taceyjo1 3863:
3864: returns description of a specified source copyright id
3865:
3866: =cut
3867:
3868: sub source_copyrightdescription {
3869: return &mt($scprtag{shift(@_)});
3870: }
1.112 bowersj2 3871:
3872: =pod
3873:
1.648 raeburn 3874: =item * &filecategories()
1.112 bowersj2 3875:
3876: returns list of all file categories
3877:
3878: =cut
3879:
3880: sub filecategories {
3881: return sort(keys(%category_extensions));
3882: }
3883:
3884: =pod
3885:
1.648 raeburn 3886: =item * &filecategorytypes()
1.112 bowersj2 3887:
3888: returns list of file types belonging to a given file
3889: category
3890:
3891: =cut
3892:
3893: sub filecategorytypes {
1.356 albertel 3894: my ($cat) = @_;
3895: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3896: }
3897:
3898: =pod
3899:
1.648 raeburn 3900: =item * &fileembstyle()
1.112 bowersj2 3901:
3902: returns embedding style for a specified file type
3903:
3904: =cut
3905:
3906: sub fileembstyle {
3907: return $fe{lc(shift(@_))};
1.169 www 3908: }
3909:
1.351 www 3910: sub filemimetype {
3911: return $fm{lc(shift(@_))};
3912: }
3913:
1.169 www 3914:
3915: sub filecategoryselect {
3916: my ($name,$value)=@_;
1.189 matthew 3917: return &select_form($value,$name,
1.970 raeburn 3918: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3919: }
3920:
3921: =pod
3922:
1.648 raeburn 3923: =item * &filedescription()
1.112 bowersj2 3924:
3925: returns description for a specified file type
3926:
3927: =cut
3928:
3929: sub filedescription {
1.188 matthew 3930: my $file_description = $fd{lc(shift())};
3931: $file_description =~ s:([\[\]]):~$1:g;
3932: return &mt($file_description);
1.112 bowersj2 3933: }
3934:
3935: =pod
3936:
1.648 raeburn 3937: =item * &filedescriptionex()
1.112 bowersj2 3938:
3939: returns description for a specified file type with
3940: extra formatting
3941:
3942: =cut
3943:
3944: sub filedescriptionex {
3945: my $ex=shift;
1.188 matthew 3946: my $file_description = $fd{lc($ex)};
3947: $file_description =~ s:([\[\]]):~$1:g;
3948: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3949: }
3950:
3951: # End of .tab access
3952: =pod
3953:
3954: =back
3955:
3956: =cut
3957:
3958: # ------------------------------------------------------------------ File Types
3959: sub fileextensions {
3960: return sort(keys(%fe));
3961: }
3962:
1.97 www 3963: # ----------------------------------------------------------- Display Languages
3964: # returns a hash with all desired display languages
3965: #
3966:
3967: sub display_languages {
3968: my %languages=();
1.695 raeburn 3969: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3970: $languages{$lang}=1;
1.97 www 3971: }
3972: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3973: if ($env{'form.displaylanguage'}) {
1.356 albertel 3974: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3975: $languages{$lang}=1;
1.97 www 3976: }
3977: }
3978: return %languages;
1.14 harris41 3979: }
3980:
1.582 albertel 3981: sub languages {
3982: my ($possible_langs) = @_;
1.695 raeburn 3983: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3984: if (!ref($possible_langs)) {
3985: if( wantarray ) {
3986: return @preferred_langs;
3987: } else {
3988: return $preferred_langs[0];
3989: }
3990: }
3991: my %possibilities = map { $_ => 1 } (@$possible_langs);
3992: my @preferred_possibilities;
3993: foreach my $preferred_lang (@preferred_langs) {
3994: if (exists($possibilities{$preferred_lang})) {
3995: push(@preferred_possibilities, $preferred_lang);
3996: }
3997: }
3998: if( wantarray ) {
3999: return @preferred_possibilities;
4000: }
4001: return $preferred_possibilities[0];
4002: }
4003:
1.742 raeburn 4004: sub user_lang {
4005: my ($touname,$toudom,$fromcid) = @_;
4006: my @userlangs;
4007: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4008: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4009: $env{'course.'.$fromcid.'.languages'}));
4010: } else {
4011: my %langhash = &getlangs($touname,$toudom);
4012: if ($langhash{'languages'} ne '') {
4013: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4014: } else {
4015: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4016: if ($domdefs{'lang_def'} ne '') {
4017: @userlangs = ($domdefs{'lang_def'});
4018: }
4019: }
4020: }
4021: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4022: my $user_lh = Apache::localize->get_handle(@languages);
4023: return $user_lh;
4024: }
4025:
4026:
1.112 bowersj2 4027: ###############################################################
4028: ## Student Answer Attempts ##
4029: ###############################################################
4030:
4031: =pod
4032:
4033: =head1 Alternate Problem Views
4034:
4035: =over 4
4036:
1.648 raeburn 4037: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1075.2.86 raeburn 4038: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4039:
4040: Return string with previous attempt on problem. Arguments:
4041:
4042: =over 4
4043:
4044: =item * $symb: Problem, including path
4045:
4046: =item * $username: username of the desired student
4047:
4048: =item * $domain: domain of the desired student
1.14 harris41 4049:
1.112 bowersj2 4050: =item * $course: Course ID
1.14 harris41 4051:
1.112 bowersj2 4052: =item * $getattempt: Leave blank for all attempts, otherwise put
4053: something
1.14 harris41 4054:
1.112 bowersj2 4055: =item * $regexp: if string matches this regexp, the string will be
4056: sent to $gradesub
1.14 harris41 4057:
1.112 bowersj2 4058: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4059:
1.1075.2.86 raeburn 4060: =item * $usec: section of the desired student
4061:
4062: =item * $identifier: counter for student (multiple students one problem) or
4063: problem (one student; whole sequence).
4064:
1.112 bowersj2 4065: =back
1.14 harris41 4066:
1.112 bowersj2 4067: The output string is a table containing all desired attempts, if any.
1.16 harris41 4068:
1.112 bowersj2 4069: =cut
1.1 albertel 4070:
4071: sub get_previous_attempt {
1.1075.2.86 raeburn 4072: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4073: my $prevattempts='';
1.43 ng 4074: no strict 'refs';
1.1 albertel 4075: if ($symb) {
1.3 albertel 4076: my (%returnhash)=
4077: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4078: if ($returnhash{'version'}) {
4079: my %lasthash=();
4080: my $version;
4081: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.91 raeburn 4082: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4083: if ($key =~ /\.rawrndseed$/) {
4084: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4085: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4086: } else {
4087: $lasthash{$key}=$returnhash{$version.':'.$key};
4088: }
1.19 harris41 4089: }
1.1 albertel 4090: }
1.596 albertel 4091: $prevattempts=&start_data_table().&start_data_table_header_row();
4092: $prevattempts.='<th>'.&mt('History').'</th>';
1.1075.2.86 raeburn 4093: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4094: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4095: foreach my $key (sort(keys(%lasthash))) {
4096: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4097: if ($#parts > 0) {
1.31 albertel 4098: my $data=$parts[-1];
1.989 raeburn 4099: next if ($data eq 'foilorder');
1.31 albertel 4100: pop(@parts);
1.1010 www 4101: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4102: if ($data eq 'type') {
4103: unless ($showsurv) {
4104: my $id = join(',',@parts);
4105: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4106: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4107: $lasthidden{$ign.'.'.$id} = 1;
4108: }
1.945 raeburn 4109: }
1.1075.2.86 raeburn 4110: if ($identifier ne '') {
4111: my $id = join(',',@parts);
4112: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4113: $domain,$username,$usec,undef,$course) =~ /^no/) {
4114: $hidestatus{$ign.'.'.$id} = 1;
4115: }
4116: }
4117: } elsif ($data eq 'regrader') {
4118: if (($identifier ne '') && (@parts)) {
4119: my $id = join(',',@parts);
4120: $regraded{$ign.'.'.$id} = 1;
4121: }
1.1010 www 4122: }
1.31 albertel 4123: } else {
1.41 ng 4124: if ($#parts == 0) {
4125: $prevattempts.='<th>'.$parts[0].'</th>';
4126: } else {
4127: $prevattempts.='<th>'.$ign.'</th>';
4128: }
1.31 albertel 4129: }
1.16 harris41 4130: }
1.596 albertel 4131: $prevattempts.=&end_data_table_header_row();
1.40 ng 4132: if ($getattempt eq '') {
1.1075.2.86 raeburn 4133: my (%solved,%resets,%probstatus);
4134: if (($identifier ne '') && (keys(%regraded) > 0)) {
4135: for ($version=1;$version<=$returnhash{'version'};$version++) {
4136: foreach my $id (keys(%regraded)) {
4137: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4138: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4139: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4140: push(@{$resets{$id}},$version);
4141: }
4142: }
4143: }
4144: }
1.40 ng 4145: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.86 raeburn 4146: my (@hidden,@unsolved);
1.945 raeburn 4147: if (%typeparts) {
4148: foreach my $id (keys(%typeparts)) {
1.1075.2.86 raeburn 4149: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4150: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4151: push(@hidden,$id);
1.1075.2.86 raeburn 4152: } elsif ($identifier ne '') {
4153: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4154: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4155: ($hidestatus{$id})) {
4156: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
4157: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4158: push(@{$solved{$id}},$version);
4159: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4160: (ref($solved{$id}) eq 'ARRAY')) {
4161: my $skip;
4162: if (ref($resets{$id}) eq 'ARRAY') {
4163: foreach my $reset (@{$resets{$id}}) {
4164: if ($reset > $solved{$id}[-1]) {
4165: $skip=1;
4166: last;
4167: }
4168: }
4169: }
4170: unless ($skip) {
4171: my ($ign,$partslist) = split(/\./,$id,2);
4172: push(@unsolved,$partslist);
4173: }
4174: }
4175: }
1.945 raeburn 4176: }
4177: }
4178: }
4179: $prevattempts.=&start_data_table_row().
1.1075.2.86 raeburn 4180: '<td>'.&mt('Transaction [_1]',$version);
4181: if (@unsolved) {
4182: $prevattempts .= '<span class="LC_nobreak"><label>'.
4183: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4184: &mt('Hide').'</label></span>';
4185: }
4186: $prevattempts .= '</td>';
1.945 raeburn 4187: if (@hidden) {
4188: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4189: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4190: my $hide;
4191: foreach my $id (@hidden) {
4192: if ($key =~ /^\Q$id\E/) {
4193: $hide = 1;
4194: last;
4195: }
4196: }
4197: if ($hide) {
4198: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4199: if (($data eq 'award') || ($data eq 'awarddetail')) {
4200: my $value = &format_previous_attempt_value($key,
4201: $returnhash{$version.':'.$key});
4202: $prevattempts.='<td>'.$value.' </td>';
4203: } else {
4204: $prevattempts.='<td> </td>';
4205: }
4206: } else {
4207: if ($key =~ /\./) {
1.1075.2.91 raeburn 4208: my $value = $returnhash{$version.':'.$key};
4209: if ($key =~ /\.rndseed$/) {
4210: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4211: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4212: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4213: }
4214: }
4215: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4216: ' </td>';
1.945 raeburn 4217: } else {
4218: $prevattempts.='<td> </td>';
4219: }
4220: }
4221: }
4222: } else {
4223: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4224: next if ($key =~ /\.foilorder$/);
1.1075.2.91 raeburn 4225: my $value = $returnhash{$version.':'.$key};
4226: if ($key =~ /\.rndseed$/) {
4227: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4228: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4229: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4230: }
4231: }
4232: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4233: ' </td>';
1.945 raeburn 4234: }
4235: }
4236: $prevattempts.=&end_data_table_row();
1.40 ng 4237: }
1.1 albertel 4238: }
1.945 raeburn 4239: my @currhidden = keys(%lasthidden);
1.596 albertel 4240: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4241: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4242: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4243: if (%typeparts) {
4244: my $hidden;
4245: foreach my $id (@currhidden) {
4246: if ($key =~ /^\Q$id\E/) {
4247: $hidden = 1;
4248: last;
4249: }
4250: }
4251: if ($hidden) {
4252: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4253: if (($data eq 'award') || ($data eq 'awarddetail')) {
4254: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4255: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4256: $value = &$gradesub($value);
4257: }
4258: $prevattempts.='<td>'.$value.' </td>';
4259: } else {
4260: $prevattempts.='<td> </td>';
4261: }
4262: } else {
4263: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4264: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4265: $value = &$gradesub($value);
4266: }
4267: $prevattempts.='<td>'.$value.' </td>';
4268: }
4269: } else {
4270: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4271: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4272: $value = &$gradesub($value);
4273: }
4274: $prevattempts.='<td>'.$value.' </td>';
4275: }
1.16 harris41 4276: }
1.596 albertel 4277: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4278: } else {
1.596 albertel 4279: $prevattempts=
4280: &start_data_table().&start_data_table_row().
4281: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4282: &end_data_table_row().&end_data_table();
1.1 albertel 4283: }
4284: } else {
1.596 albertel 4285: $prevattempts=
4286: &start_data_table().&start_data_table_row().
4287: '<td>'.&mt('No data.').'</td>'.
4288: &end_data_table_row().&end_data_table();
1.1 albertel 4289: }
1.10 albertel 4290: }
4291:
1.581 albertel 4292: sub format_previous_attempt_value {
4293: my ($key,$value) = @_;
1.1011 www 4294: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 4295: $value = &Apache::lonlocal::locallocaltime($value);
4296: } elsif (ref($value) eq 'ARRAY') {
4297: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 4298: } elsif ($key =~ /answerstring$/) {
4299: my %answers = &Apache::lonnet::str2hash($value);
4300: my @anskeys = sort(keys(%answers));
4301: if (@anskeys == 1) {
4302: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4303: if ($answer =~ m{\0}) {
4304: $answer =~ s{\0}{,}g;
1.988 raeburn 4305: }
4306: my $tag_internal_answer_name = 'INTERNAL';
4307: if ($anskeys[0] eq $tag_internal_answer_name) {
4308: $value = $answer;
4309: } else {
4310: $value = $anskeys[0].'='.$answer;
4311: }
4312: } else {
4313: foreach my $ans (@anskeys) {
4314: my $answer = $answers{$ans};
1.1001 raeburn 4315: if ($answer =~ m{\0}) {
4316: $answer =~ s{\0}{,}g;
1.988 raeburn 4317: }
4318: $value .= $ans.'='.$answer.'<br />';;
4319: }
4320: }
1.581 albertel 4321: } else {
4322: $value = &unescape($value);
4323: }
4324: return $value;
4325: }
4326:
4327:
1.107 albertel 4328: sub relative_to_absolute {
4329: my ($url,$output)=@_;
4330: my $parser=HTML::TokeParser->new(\$output);
4331: my $token;
4332: my $thisdir=$url;
4333: my @rlinks=();
4334: while ($token=$parser->get_token) {
4335: if ($token->[0] eq 'S') {
4336: if ($token->[1] eq 'a') {
4337: if ($token->[2]->{'href'}) {
4338: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4339: }
4340: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4341: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4342: } elsif ($token->[1] eq 'base') {
4343: $thisdir=$token->[2]->{'href'};
4344: }
4345: }
4346: }
4347: $thisdir=~s-/[^/]*$--;
1.356 albertel 4348: foreach my $link (@rlinks) {
1.726 raeburn 4349: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4350: ($link=~/^\//) ||
4351: ($link=~/^javascript:/i) ||
4352: ($link=~/^mailto:/i) ||
4353: ($link=~/^\#/)) {
4354: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4355: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4356: }
4357: }
4358: # -------------------------------------------------- Deal with Applet codebases
4359: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4360: return $output;
4361: }
4362:
1.112 bowersj2 4363: =pod
4364:
1.648 raeburn 4365: =item * &get_student_view()
1.112 bowersj2 4366:
4367: show a snapshot of what student was looking at
4368:
4369: =cut
4370:
1.10 albertel 4371: sub get_student_view {
1.186 albertel 4372: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4373: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4374: my (%form);
1.10 albertel 4375: my @elements=('symb','courseid','domain','username');
4376: foreach my $element (@elements) {
1.186 albertel 4377: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4378: }
1.186 albertel 4379: if (defined($moreenv)) {
4380: %form=(%form,%{$moreenv});
4381: }
1.236 albertel 4382: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4383: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4384: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4385: $userview=~s/\<body[^\>]*\>//gi;
4386: $userview=~s/\<\/body\>//gi;
4387: $userview=~s/\<html\>//gi;
4388: $userview=~s/\<\/html\>//gi;
4389: $userview=~s/\<head\>//gi;
4390: $userview=~s/\<\/head\>//gi;
4391: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4392: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4393: if (wantarray) {
4394: return ($userview,$response);
4395: } else {
4396: return $userview;
4397: }
4398: }
4399:
4400: sub get_student_view_with_retries {
4401: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4402:
4403: my $ok = 0; # True if we got a good response.
4404: my $content;
4405: my $response;
4406:
4407: # Try to get the student_view done. within the retries count:
4408:
4409: do {
4410: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4411: $ok = $response->is_success;
4412: if (!$ok) {
4413: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4414: }
4415: $retries--;
4416: } while (!$ok && ($retries > 0));
4417:
4418: if (!$ok) {
4419: $content = ''; # On error return an empty content.
4420: }
1.651 www 4421: if (wantarray) {
4422: return ($content, $response);
4423: } else {
4424: return $content;
4425: }
1.11 albertel 4426: }
4427:
1.112 bowersj2 4428: =pod
4429:
1.648 raeburn 4430: =item * &get_student_answers()
1.112 bowersj2 4431:
4432: show a snapshot of how student was answering problem
4433:
4434: =cut
4435:
1.11 albertel 4436: sub get_student_answers {
1.100 sakharuk 4437: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4438: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4439: my (%moreenv);
1.11 albertel 4440: my @elements=('symb','courseid','domain','username');
4441: foreach my $element (@elements) {
1.186 albertel 4442: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4443: }
1.186 albertel 4444: $moreenv{'grade_target'}='answer';
4445: %moreenv=(%form,%moreenv);
1.497 raeburn 4446: $feedurl = &Apache::lonnet::clutter($feedurl);
4447: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4448: return $userview;
1.1 albertel 4449: }
1.116 albertel 4450:
4451: =pod
4452:
4453: =item * &submlink()
4454:
1.242 albertel 4455: Inputs: $text $uname $udom $symb $target
1.116 albertel 4456:
4457: Returns: A link to grades.pm such as to see the SUBM view of a student
4458:
4459: =cut
4460:
4461: ###############################################
4462: sub submlink {
1.242 albertel 4463: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4464: if (!($uname && $udom)) {
4465: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4466: &Apache::lonnet::whichuser($symb);
1.116 albertel 4467: if (!$symb) { $symb=$cursymb; }
4468: }
1.254 matthew 4469: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4470: $symb=&escape($symb);
1.960 bisitz 4471: if ($target) { $target=" target=\"$target\""; }
4472: return
4473: '<a href="/adm/grades?command=submission'.
4474: '&symb='.$symb.
4475: '&student='.$uname.
4476: '&userdom='.$udom.'"'.
4477: $target.'>'.$text.'</a>';
1.242 albertel 4478: }
4479: ##############################################
4480:
4481: =pod
4482:
4483: =item * &pgrdlink()
4484:
4485: Inputs: $text $uname $udom $symb $target
4486:
4487: Returns: A link to grades.pm such as to see the PGRD view of a student
4488:
4489: =cut
4490:
4491: ###############################################
4492: sub pgrdlink {
4493: my $link=&submlink(@_);
4494: $link=~s/(&command=submission)/$1&showgrading=yes/;
4495: return $link;
4496: }
4497: ##############################################
4498:
4499: =pod
4500:
4501: =item * &pprmlink()
4502:
4503: Inputs: $text $uname $udom $symb $target
4504:
4505: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4506: student and a specific resource
1.242 albertel 4507:
4508: =cut
4509:
4510: ###############################################
4511: sub pprmlink {
4512: my ($text,$uname,$udom,$symb,$target)=@_;
4513: if (!($uname && $udom)) {
4514: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4515: &Apache::lonnet::whichuser($symb);
1.242 albertel 4516: if (!$symb) { $symb=$cursymb; }
4517: }
1.254 matthew 4518: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4519: $symb=&escape($symb);
1.242 albertel 4520: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4521: return '<a href="/adm/parmset?command=set&'.
4522: 'symb='.$symb.'&uname='.$uname.
4523: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4524: }
4525: ##############################################
1.37 matthew 4526:
1.112 bowersj2 4527: =pod
4528:
4529: =back
4530:
4531: =cut
4532:
1.37 matthew 4533: ###############################################
1.51 www 4534:
4535:
4536: sub timehash {
1.687 raeburn 4537: my ($thistime) = @_;
4538: my $timezone = &Apache::lonlocal::gettimezone();
4539: my $dt = DateTime->from_epoch(epoch => $thistime)
4540: ->set_time_zone($timezone);
4541: my $wday = $dt->day_of_week();
4542: if ($wday == 7) { $wday = 0; }
4543: return ( 'second' => $dt->second(),
4544: 'minute' => $dt->minute(),
4545: 'hour' => $dt->hour(),
4546: 'day' => $dt->day_of_month(),
4547: 'month' => $dt->month(),
4548: 'year' => $dt->year(),
4549: 'weekday' => $wday,
4550: 'dayyear' => $dt->day_of_year(),
4551: 'dlsav' => $dt->is_dst() );
1.51 www 4552: }
4553:
1.370 www 4554: sub utc_string {
4555: my ($date)=@_;
1.371 www 4556: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4557: }
4558:
1.51 www 4559: sub maketime {
4560: my %th=@_;
1.687 raeburn 4561: my ($epoch_time,$timezone,$dt);
4562: $timezone = &Apache::lonlocal::gettimezone();
4563: eval {
4564: $dt = DateTime->new( year => $th{'year'},
4565: month => $th{'month'},
4566: day => $th{'day'},
4567: hour => $th{'hour'},
4568: minute => $th{'minute'},
4569: second => $th{'second'},
4570: time_zone => $timezone,
4571: );
4572: };
4573: if (!$@) {
4574: $epoch_time = $dt->epoch;
4575: if ($epoch_time) {
4576: return $epoch_time;
4577: }
4578: }
1.51 www 4579: return POSIX::mktime(
4580: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4581: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4582: }
4583:
4584: #########################################
1.51 www 4585:
4586: sub findallcourses {
1.482 raeburn 4587: my ($roles,$uname,$udom) = @_;
1.355 albertel 4588: my %roles;
4589: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4590: my %courses;
1.51 www 4591: my $now=time;
1.482 raeburn 4592: if (!defined($uname)) {
4593: $uname = $env{'user.name'};
4594: }
4595: if (!defined($udom)) {
4596: $udom = $env{'user.domain'};
4597: }
4598: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4599: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4600: if (!%roles) {
4601: %roles = (
4602: cc => 1,
1.907 raeburn 4603: co => 1,
1.482 raeburn 4604: in => 1,
4605: ep => 1,
4606: ta => 1,
4607: cr => 1,
4608: st => 1,
4609: );
4610: }
4611: foreach my $entry (keys(%roleshash)) {
4612: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4613: if ($trole =~ /^cr/) {
4614: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4615: } else {
4616: next if (!exists($roles{$trole}));
4617: }
4618: if ($tend) {
4619: next if ($tend < $now);
4620: }
4621: if ($tstart) {
4622: next if ($tstart > $now);
4623: }
1.1058 raeburn 4624: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4625: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4626: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4627: if ($secpart eq '') {
4628: ($cnum,$role) = split(/_/,$cnumpart);
4629: $sec = 'none';
1.1058 raeburn 4630: $value .= $cnum.'/';
1.482 raeburn 4631: } else {
4632: $cnum = $cnumpart;
4633: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4634: $value .= $cnum.'/'.$sec;
4635: }
4636: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4637: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4638: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4639: }
4640: } else {
4641: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4642: }
1.482 raeburn 4643: }
4644: } else {
4645: foreach my $key (keys(%env)) {
1.483 albertel 4646: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4647: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4648: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4649: next if ($role eq 'ca' || $role eq 'aa');
4650: next if (%roles && !exists($roles{$role}));
4651: my ($starttime,$endtime)=split(/\./,$env{$key});
4652: my $active=1;
4653: if ($starttime) {
4654: if ($now<$starttime) { $active=0; }
4655: }
4656: if ($endtime) {
4657: if ($now>$endtime) { $active=0; }
4658: }
4659: if ($active) {
1.1058 raeburn 4660: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4661: if ($sec eq '') {
4662: $sec = 'none';
1.1058 raeburn 4663: } else {
4664: $value .= $sec;
4665: }
4666: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4667: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4668: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4669: }
4670: } else {
4671: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4672: }
1.474 raeburn 4673: }
4674: }
1.51 www 4675: }
4676: }
1.474 raeburn 4677: return %courses;
1.51 www 4678: }
1.37 matthew 4679:
1.54 www 4680: ###############################################
1.474 raeburn 4681:
4682: sub blockcheck {
1.1075.2.141. .7(raebu 4683:20): my ($setters,$activity,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.490 raeburn 4684:
1.1075.2.73 raeburn 4685: if (defined($udom) && defined($uname)) {
4686: # If uname and udom are for a course, check for blocks in the course.
4687: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4688: my ($startblock,$endblock,$triggerblock) =
1.1075.2.141. .7(raebu 4689:20): &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1075.2.73 raeburn 4690: return ($startblock,$endblock,$triggerblock);
4691: }
4692: } else {
1.490 raeburn 4693: $udom = $env{'user.domain'};
4694: $uname = $env{'user.name'};
4695: }
4696:
1.502 raeburn 4697: my $startblock = 0;
4698: my $endblock = 0;
1.1062 raeburn 4699: my $triggerblock = '';
1.482 raeburn 4700: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4701:
1.490 raeburn 4702: # If uname is for a user, and activity is course-specific, i.e.,
4703: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4704:
1.490 raeburn 4705: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.141. .6(raebu 4706:20): $activity eq 'groups' || $activity eq 'printout' ||
.8(raebu 4707:20): $activity eq 'search' || $activity eq 'reinit' ||
4708:20): $activity eq 'alert') &&
1.1075.2.73 raeburn 4709: ($env{'request.course.id'})) {
1.490 raeburn 4710: foreach my $key (keys(%live_courses)) {
4711: if ($key ne $env{'request.course.id'}) {
4712: delete($live_courses{$key});
4713: }
4714: }
4715: }
4716:
4717: my $otheruser = 0;
4718: my %own_courses;
4719: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4720: # Resource belongs to user other than current user.
4721: $otheruser = 1;
4722: # Gather courses for current user
4723: %own_courses =
4724: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4725: }
4726:
4727: # Gather active course roles - course coordinator, instructor,
4728: # exam proctor, ta, student, or custom role.
1.474 raeburn 4729:
4730: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4731: my ($cdom,$cnum);
4732: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4733: $cdom = $env{'course.'.$course.'.domain'};
4734: $cnum = $env{'course.'.$course.'.num'};
4735: } else {
1.490 raeburn 4736: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4737: }
4738: my $no_ownblock = 0;
4739: my $no_userblock = 0;
1.533 raeburn 4740: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4741: # Check if current user has 'evb' priv for this
4742: if (defined($own_courses{$course})) {
4743: foreach my $sec (keys(%{$own_courses{$course}})) {
4744: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4745: if ($sec ne 'none') {
4746: $checkrole .= '/'.$sec;
4747: }
4748: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4749: $no_ownblock = 1;
4750: last;
4751: }
4752: }
4753: }
4754: # if they have 'evb' priv and are currently not playing student
4755: next if (($no_ownblock) &&
4756: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4757: }
1.474 raeburn 4758: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4759: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4760: if ($sec ne 'none') {
1.482 raeburn 4761: $checkrole .= '/'.$sec;
1.474 raeburn 4762: }
1.490 raeburn 4763: if ($otheruser) {
4764: # Resource belongs to user other than current user.
4765: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4766: my (%allroles,%userroles);
4767: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4768: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4769: my ($trole,$tdom,$tnum,$tsec);
4770: if ($entry =~ /^cr/) {
4771: ($trole,$tdom,$tnum,$tsec) =
4772: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4773: } else {
4774: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4775: }
4776: my ($spec,$area,$trest);
4777: $area = '/'.$tdom.'/'.$tnum;
4778: $trest = $tnum;
4779: if ($tsec ne '') {
4780: $area .= '/'.$tsec;
4781: $trest .= '/'.$tsec;
4782: }
4783: $spec = $trole.'.'.$area;
4784: if ($trole =~ /^cr/) {
4785: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4786: $tdom,$spec,$trest,$area);
4787: } else {
4788: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4789: $tdom,$spec,$trest,$area);
4790: }
4791: }
1.1075.2.124 raeburn 4792: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 4793: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4794: if ($1) {
4795: $no_userblock = 1;
4796: last;
4797: }
1.486 raeburn 4798: }
4799: }
1.490 raeburn 4800: } else {
4801: # Resource belongs to current user
4802: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4803: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4804: $no_ownblock = 1;
4805: last;
4806: }
1.474 raeburn 4807: }
4808: }
4809: # if they have the evb priv and are currently not playing student
1.482 raeburn 4810: next if (($no_ownblock) &&
1.491 albertel 4811: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4812: next if ($no_userblock);
1.474 raeburn 4813:
1.1075.2.128 raeburn 4814: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 4815: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4816:
1.1062 raeburn 4817: my ($start,$end,$trigger) =
1.1075.2.141. .7(raebu 4818:20): &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 4819: if (($start != 0) &&
4820: (($startblock == 0) || ($startblock > $start))) {
4821: $startblock = $start;
1.1062 raeburn 4822: if ($trigger ne '') {
4823: $triggerblock = $trigger;
4824: }
1.502 raeburn 4825: }
4826: if (($end != 0) &&
4827: (($endblock == 0) || ($endblock < $end))) {
4828: $endblock = $end;
1.1062 raeburn 4829: if ($trigger ne '') {
4830: $triggerblock = $trigger;
4831: }
1.502 raeburn 4832: }
1.490 raeburn 4833: }
1.1062 raeburn 4834: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4835: }
4836:
4837: sub get_blocks {
1.1075.2.141. .7(raebu 4838:20): my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 4839: my $startblock = 0;
4840: my $endblock = 0;
1.1062 raeburn 4841: my $triggerblock = '';
1.490 raeburn 4842: my $course = $cdom.'_'.$cnum;
4843: $setters->{$course} = {};
4844: $setters->{$course}{'staff'} = [];
4845: $setters->{$course}{'times'} = [];
1.1062 raeburn 4846: $setters->{$course}{'triggers'} = [];
4847: my (@blockers,%triggered);
4848: my $now = time;
4849: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4850: if ($activity eq 'docs') {
1.1075.2.141. .9(raebu 4851:20): my ($blocked,$nosymbcache,$noenccheck);
.7(raebu 4852:20): if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
4853:20): $blocked = 1;
4854:20): $nosymbcache = 1;
.9(raebu 4855:20): $noenccheck = 1;
.7(raebu 4856:20): }
.9(raebu 4857:20): @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 4858: foreach my $block (@blockers) {
4859: if ($block =~ /^firstaccess____(.+)$/) {
4860: my $item = $1;
4861: my $type = 'map';
4862: my $timersymb = $item;
4863: if ($item eq 'course') {
4864: $type = 'course';
4865: } elsif ($item =~ /___\d+___/) {
4866: $type = 'resource';
4867: } else {
4868: $timersymb = &Apache::lonnet::symbread($item);
4869: }
4870: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4871: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4872: $triggered{$block} = {
4873: start => $start,
4874: end => $end,
4875: type => $type,
4876: };
4877: }
4878: }
4879: } else {
4880: foreach my $block (keys(%commblocks)) {
4881: if ($block =~ m/^(\d+)____(\d+)$/) {
4882: my ($start,$end) = ($1,$2);
4883: if ($start <= time && $end >= time) {
4884: if (ref($commblocks{$block}) eq 'HASH') {
4885: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4886: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4887: unless(grep(/^\Q$block\E$/,@blockers)) {
4888: push(@blockers,$block);
4889: }
4890: }
4891: }
4892: }
4893: }
4894: } elsif ($block =~ /^firstaccess____(.+)$/) {
4895: my $item = $1;
4896: my $timersymb = $item;
4897: my $type = 'map';
4898: if ($item eq 'course') {
4899: $type = 'course';
4900: } elsif ($item =~ /___\d+___/) {
4901: $type = 'resource';
4902: } else {
4903: $timersymb = &Apache::lonnet::symbread($item);
4904: }
4905: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4906: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4907: if ($start && $end) {
4908: if (($start <= time) && ($end >= time)) {
4909: unless (grep(/^\Q$block\E$/,@blockers)) {
4910: push(@blockers,$block);
4911: $triggered{$block} = {
4912: start => $start,
4913: end => $end,
4914: type => $type,
4915: };
4916: }
4917: }
1.490 raeburn 4918: }
1.1062 raeburn 4919: }
4920: }
4921: }
4922: foreach my $blocker (@blockers) {
4923: my ($staff_name,$staff_dom,$title,$blocks) =
4924: &parse_block_record($commblocks{$blocker});
4925: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4926: my ($start,$end,$triggertype);
4927: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4928: ($start,$end) = ($1,$2);
4929: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4930: $start = $triggered{$blocker}{'start'};
4931: $end = $triggered{$blocker}{'end'};
4932: $triggertype = $triggered{$blocker}{'type'};
4933: }
4934: if ($start) {
4935: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4936: if ($triggertype) {
4937: push(@{$$setters{$course}{'triggers'}},$triggertype);
4938: } else {
4939: push(@{$$setters{$course}{'triggers'}},0);
4940: }
4941: if ( ($startblock == 0) || ($startblock > $start) ) {
4942: $startblock = $start;
4943: if ($triggertype) {
4944: $triggerblock = $blocker;
1.474 raeburn 4945: }
4946: }
1.1062 raeburn 4947: if ( ($endblock == 0) || ($endblock < $end) ) {
4948: $endblock = $end;
4949: if ($triggertype) {
4950: $triggerblock = $blocker;
4951: }
4952: }
1.474 raeburn 4953: }
4954: }
1.1062 raeburn 4955: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4956: }
4957:
4958: sub parse_block_record {
4959: my ($record) = @_;
4960: my ($setuname,$setudom,$title,$blocks);
4961: if (ref($record) eq 'HASH') {
4962: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4963: $title = &unescape($record->{'event'});
4964: $blocks = $record->{'blocks'};
4965: } else {
4966: my @data = split(/:/,$record,3);
4967: if (scalar(@data) eq 2) {
4968: $title = $data[1];
4969: ($setuname,$setudom) = split(/@/,$data[0]);
4970: } else {
4971: ($setuname,$setudom,$title) = @data;
4972: }
4973: $blocks = { 'com' => 'on' };
4974: }
4975: return ($setuname,$setudom,$title,$blocks);
4976: }
4977:
1.854 kalberla 4978: sub blocking_status {
1.1075.2.141. .7(raebu 4979:20): my ($activity,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 4980: my %setters;
1.890 droeschl 4981:
1.1061 raeburn 4982: # check for active blocking
1.1062 raeburn 4983: my ($startblock,$endblock,$triggerblock) =
1.1075.2.141. .7(raebu 4984:20): &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 4985: my $blocked = 0;
4986: if ($startblock && $endblock) {
4987: $blocked = 1;
4988: }
1.890 droeschl 4989:
1.1061 raeburn 4990: # caller just wants to know whether a block is active
4991: if (!wantarray) { return $blocked; }
4992:
4993: # build a link to a popup window containing the details
4994: my $querystring = "?activity=$activity";
4995: # $uname and $udom decide whose portfolio the user is trying to look at
1.1075.2.97 raeburn 4996: if (($activity eq 'port') || ($activity eq 'passwd')) {
4997: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
4998: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 4999: } elsif ($activity eq 'docs') {
1.1075.2.141. .7(raebu 5000:20): my $showurl = &Apache::lonenc::check_encrypt($url);
5001:20): $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
5002:20): if ($symb) {
5003:20): my $showsymb = &Apache::lonenc::check_encrypt($symb);
5004:20): $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
5005:20): }
1.1062 raeburn 5006: }
1.1061 raeburn 5007:
5008: my $output .= <<'END_MYBLOCK';
5009: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5010: var options = "width=" + w + ",height=" + h + ",";
5011: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5012: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5013: var newWin = window.open(url, wdwName, options);
5014: newWin.focus();
5015: }
1.890 droeschl 5016: END_MYBLOCK
1.854 kalberla 5017:
1.1061 raeburn 5018: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5019:
1.1061 raeburn 5020: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5021: my $text = &mt('Communication Blocked');
1.1075.2.93 raeburn 5022: my $class = 'LC_comblock';
1.1062 raeburn 5023: if ($activity eq 'docs') {
5024: $text = &mt('Content Access Blocked');
1.1075.2.93 raeburn 5025: $class = '';
1.1063 raeburn 5026: } elsif ($activity eq 'printout') {
5027: $text = &mt('Printing Blocked');
1.1075.2.97 raeburn 5028: } elsif ($activity eq 'passwd') {
5029: $text = &mt('Password Changing Blocked');
1.1075.2.141. .6(raebu 5030:20): } elsif ($activity eq 'grades') {
5031:20): $text = &mt('Gradebook Blocked');
.8(raebu 5032:20): } elsif ($activity eq 'search') {
5033:20): $text = &mt('Search Blocked');
.6(raebu 5034:20): } elsif ($activity eq 'alert') {
5035:20): $text = &mt('Checking Critical Messages Blocked');
5036:20): } elsif ($activity eq 'reinit') {
5037:20): $text = &mt('Checking Course Update Blocked');
1.1062 raeburn 5038: }
1.1061 raeburn 5039: $output .= <<"END_BLOCK";
1.1075.2.93 raeburn 5040: <div class='$class'>
1.869 kalberla 5041: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5042: title='$text'>
5043: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5044: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5045: title='$text'>$text</a>
1.867 kalberla 5046: </div>
5047:
5048: END_BLOCK
1.474 raeburn 5049:
1.1061 raeburn 5050: return ($blocked, $output);
1.854 kalberla 5051: }
1.490 raeburn 5052:
1.60 matthew 5053: ###############################################
5054:
1.682 raeburn 5055: sub check_ip_acc {
1.1075.2.105 raeburn 5056: my ($acc,$clientip)=@_;
1.682 raeburn 5057: &Apache::lonxml::debug("acc is $acc");
5058: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5059: return 1;
5060: }
1.1075.2.141. .4(raebu 5061:20): my ($ip,$allowed);
5062:20): if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5063:20): ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5064:20): $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5065:20): } else {
5066:20): $ip = $ENV{'REMOTE_ADDR'} || $env{'request.host'} || $clientip;
5067:20): }
1.682 raeburn 5068:
5069: my $name;
1.1075.2.141. .1(raebu 5070:20): my %access = (
5071:20): allowfrom => 1,
5072:20): denyfrom => 0,
5073:20): );
5074:20): my @allows;
5075:20): my @denies;
5076:20): foreach my $item (split(',',$acc)) {
5077:20): $item =~ s/^\s*//;
5078:20): $item =~ s/\s*$//;
5079:20): if ($item =~ /^\!(.+)$/) {
5080:20): push(@denies,$1);
5081:20): } else {
5082:20): push(@allows,$item);
5083:20): }
5084:20): }
5085:20): my $numdenies = scalar(@denies);
5086:20): my $numallows = scalar(@allows);
5087:20): my $count = 0;
5088:20): foreach my $pattern (@denies,@allows) {
5089:20): $count ++;
5090:20): my $acctype = 'allowfrom';
5091:20): if ($count <= $numdenies) {
5092:20): $acctype = 'denyfrom';
5093:20): }
1.682 raeburn 5094: if ($pattern =~ /\*$/) {
5095: #35.8.*
5096: $pattern=~s/\*//;
1.1075.2.141. .1(raebu 5097:20): if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5098: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5099: #35.8.3.[34-56]
5100: my $low=$2;
5101: my $high=$3;
5102: $pattern=$1;
5103: if ($ip =~ /^\Q$pattern\E/) {
5104: my $last=(split(/\./,$ip))[3];
1.1075.2.141. .1(raebu 5105:20): if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5106: }
5107: } elsif ($pattern =~ /^\*/) {
5108: #*.msu.edu
5109: $pattern=~s/\*//;
5110: if (!defined($name)) {
5111: use Socket;
5112: my $netaddr=inet_aton($ip);
5113: ($name)=gethostbyaddr($netaddr,AF_INET);
5114: }
1.1075.2.141. .1(raebu 5115:20): if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5116: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5117: #127.0.0.1
1.1075.2.141. .1(raebu 5118:20): if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5119: } else {
5120: #some.name.com
5121: if (!defined($name)) {
5122: use Socket;
5123: my $netaddr=inet_aton($ip);
5124: ($name)=gethostbyaddr($netaddr,AF_INET);
5125: }
1.1075.2.141. .1(raebu 5126:20): if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5127:20): }
5128:20): if ($allowed =~ /^(0|1)$/) { last; }
5129:20): }
5130:20): if ($allowed eq '') {
5131:20): if ($numdenies && !$numallows) {
5132:20): $allowed = 1;
5133:20): } else {
5134:20): $allowed = 0;
1.682 raeburn 5135: }
5136: }
5137: return $allowed;
5138: }
5139:
5140: ###############################################
5141:
1.60 matthew 5142: =pod
5143:
1.112 bowersj2 5144: =head1 Domain Template Functions
5145:
5146: =over 4
5147:
5148: =item * &determinedomain()
1.60 matthew 5149:
5150: Inputs: $domain (usually will be undef)
5151:
1.63 www 5152: Returns: Determines which domain should be used for designs
1.60 matthew 5153:
5154: =cut
1.54 www 5155:
1.60 matthew 5156: ###############################################
1.63 www 5157: sub determinedomain {
5158: my $domain=shift;
1.531 albertel 5159: if (! $domain) {
1.60 matthew 5160: # Determine domain if we have not been given one
1.893 raeburn 5161: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5162: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5163: if ($env{'request.role.domain'}) {
5164: $domain=$env{'request.role.domain'};
1.60 matthew 5165: }
5166: }
1.63 www 5167: return $domain;
5168: }
5169: ###############################################
1.517 raeburn 5170:
1.518 albertel 5171: sub devalidate_domconfig_cache {
5172: my ($udom)=@_;
5173: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5174: }
5175:
5176: # ---------------------- Get domain configuration for a domain
5177: sub get_domainconf {
5178: my ($udom) = @_;
5179: my $cachetime=1800;
5180: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5181: if (defined($cached)) { return %{$result}; }
5182:
5183: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5184: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5185: my (%designhash,%legacy);
1.518 albertel 5186: if (keys(%domconfig) > 0) {
5187: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5188: if (keys(%{$domconfig{'login'}})) {
5189: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5190: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 5191: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5192: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5193: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5194: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5195: if ($key eq 'loginvia') {
5196: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5197: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5198: $designhash{$udom.'.login.loginvia'} = $server;
5199: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5200: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5201: } else {
5202: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5203: }
1.948 raeburn 5204: }
1.1075.2.87 raeburn 5205: } elsif ($key eq 'headtag') {
5206: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5207: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5208: }
1.946 raeburn 5209: }
1.1075.2.87 raeburn 5210: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5211: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5212: }
1.946 raeburn 5213: }
5214: }
5215: }
5216: } else {
5217: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5218: $designhash{$udom.'.login.'.$key.'_'.$img} =
5219: $domconfig{'login'}{$key}{$img};
5220: }
1.699 raeburn 5221: }
5222: } else {
5223: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5224: }
1.632 raeburn 5225: }
5226: } else {
5227: $legacy{'login'} = 1;
1.518 albertel 5228: }
1.632 raeburn 5229: } else {
5230: $legacy{'login'} = 1;
1.518 albertel 5231: }
5232: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5233: if (keys(%{$domconfig{'rolecolors'}})) {
5234: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5235: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5236: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5237: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5238: }
1.518 albertel 5239: }
5240: }
1.632 raeburn 5241: } else {
5242: $legacy{'rolecolors'} = 1;
1.518 albertel 5243: }
1.632 raeburn 5244: } else {
5245: $legacy{'rolecolors'} = 1;
1.518 albertel 5246: }
1.948 raeburn 5247: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5248: if ($domconfig{'autoenroll'}{'co-owners'}) {
5249: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5250: }
5251: }
1.632 raeburn 5252: if (keys(%legacy) > 0) {
5253: my %legacyhash = &get_legacy_domconf($udom);
5254: foreach my $item (keys(%legacyhash)) {
5255: if ($item =~ /^\Q$udom\E\.login/) {
5256: if ($legacy{'login'}) {
5257: $designhash{$item} = $legacyhash{$item};
5258: }
5259: } else {
5260: if ($legacy{'rolecolors'}) {
5261: $designhash{$item} = $legacyhash{$item};
5262: }
1.518 albertel 5263: }
5264: }
5265: }
1.632 raeburn 5266: } else {
5267: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5268: }
5269: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5270: $cachetime);
5271: return %designhash;
5272: }
5273:
1.632 raeburn 5274: sub get_legacy_domconf {
5275: my ($udom) = @_;
5276: my %legacyhash;
5277: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5278: my $designfile = $designdir.'/'.$udom.'.tab';
5279: if (-e $designfile) {
1.1075.2.128 raeburn 5280: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5281: while (my $line = <$fh>) {
5282: next if ($line =~ /^\#/);
5283: chomp($line);
5284: my ($key,$val)=(split(/\=/,$line));
5285: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5286: }
5287: close($fh);
5288: }
5289: }
1.1026 raeburn 5290: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5291: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5292: }
5293: return %legacyhash;
5294: }
5295:
1.63 www 5296: =pod
5297:
1.112 bowersj2 5298: =item * &domainlogo()
1.63 www 5299:
5300: Inputs: $domain (usually will be undef)
5301:
5302: Returns: A link to a domain logo, if the domain logo exists.
5303: If the domain logo does not exist, a description of the domain.
5304:
5305: =cut
1.112 bowersj2 5306:
1.63 www 5307: ###############################################
5308: sub domainlogo {
1.517 raeburn 5309: my $domain = &determinedomain(shift);
1.518 albertel 5310: my %designhash = &get_domainconf($domain);
1.517 raeburn 5311: # See if there is a logo
5312: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5313: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5314: if ($imgsrc =~ m{^/(adm|res)/}) {
5315: if ($imgsrc =~ m{^/res/}) {
5316: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5317: &Apache::lonnet::repcopy($local_name);
5318: }
5319: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5320: }
5321: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5322: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5323: return &Apache::lonnet::domain($domain,'description');
1.59 www 5324: } else {
1.60 matthew 5325: return '';
1.59 www 5326: }
5327: }
1.63 www 5328: ##############################################
5329:
5330: =pod
5331:
1.112 bowersj2 5332: =item * &designparm()
1.63 www 5333:
5334: Inputs: $which parameter; $domain (usually will be undef)
5335:
5336: Returns: value of designparamter $which
5337:
5338: =cut
1.112 bowersj2 5339:
1.397 albertel 5340:
1.400 albertel 5341: ##############################################
1.397 albertel 5342: sub designparm {
5343: my ($which,$domain)=@_;
5344: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5345: return $env{'environment.color.'.$which};
1.96 www 5346: }
1.63 www 5347: $domain=&determinedomain($domain);
1.1016 raeburn 5348: my %domdesign;
5349: unless ($domain eq 'public') {
5350: %domdesign = &get_domainconf($domain);
5351: }
1.520 raeburn 5352: my $output;
1.517 raeburn 5353: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5354: $output = $domdesign{$domain.'.'.$which};
1.63 www 5355: } else {
1.520 raeburn 5356: $output = $defaultdesign{$which};
5357: }
5358: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5359: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5360: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5361: if ($output =~ m{^/res/}) {
5362: my $local_name = &Apache::lonnet::filelocation('',$output);
5363: &Apache::lonnet::repcopy($local_name);
5364: }
1.520 raeburn 5365: $output = &lonhttpdurl($output);
5366: }
1.63 www 5367: }
1.520 raeburn 5368: return $output;
1.63 www 5369: }
1.59 www 5370:
1.822 bisitz 5371: ##############################################
5372: =pod
5373:
1.832 bisitz 5374: =item * &authorspace()
5375:
1.1028 raeburn 5376: Inputs: $url (usually will be undef).
1.832 bisitz 5377:
1.1075.2.40 raeburn 5378: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5379: directory being viewed (or for which action is being taken).
5380: If $url is provided, and begins /priv/<domain>/<uname>
5381: the path will be that portion of the $context argument.
5382: Otherwise the path will be for the author space of the current
5383: user when the current role is author, or for that of the
5384: co-author/assistant co-author space when the current role
5385: is co-author or assistant co-author.
1.832 bisitz 5386:
5387: =cut
5388:
5389: sub authorspace {
1.1028 raeburn 5390: my ($url) = @_;
5391: if ($url ne '') {
5392: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5393: return $1;
5394: }
5395: }
1.832 bisitz 5396: my $caname = '';
1.1024 www 5397: my $cadom = '';
1.1028 raeburn 5398: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5399: ($cadom,$caname) =
1.832 bisitz 5400: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5401: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5402: $caname = $env{'user.name'};
1.1024 www 5403: $cadom = $env{'user.domain'};
1.832 bisitz 5404: }
1.1028 raeburn 5405: if (($caname ne '') && ($cadom ne '')) {
5406: return "/priv/$cadom/$caname/";
5407: }
5408: return;
1.832 bisitz 5409: }
5410:
5411: ##############################################
5412: =pod
5413:
1.822 bisitz 5414: =item * &head_subbox()
5415:
5416: Inputs: $content (contains HTML code with page functions, etc.)
5417:
5418: Returns: HTML div with $content
5419: To be included in page header
5420:
5421: =cut
5422:
5423: sub head_subbox {
5424: my ($content)=@_;
5425: my $output =
1.993 raeburn 5426: '<div class="LC_head_subbox">'
1.822 bisitz 5427: .$content
5428: .'</div>'
5429: }
5430:
5431: ##############################################
5432: =pod
5433:
5434: =item * &CSTR_pageheader()
5435:
1.1026 raeburn 5436: Input: (optional) filename from which breadcrumb trail is built.
5437: In most cases no input as needed, as $env{'request.filename'}
5438: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5439:
5440: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5441: To be included on Authoring Space pages
1.822 bisitz 5442:
5443: =cut
5444:
5445: sub CSTR_pageheader {
1.1026 raeburn 5446: my ($trailfile) = @_;
5447: if ($trailfile eq '') {
5448: $trailfile = $env{'request.filename'};
5449: }
5450:
5451: # this is for resources; directories have customtitle, and crumbs
5452: # and select recent are created in lonpubdir.pm
5453:
5454: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5455: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5456: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5457: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5458: $formaction =~ s{/+}{/}g;
1.822 bisitz 5459:
5460: my $parentpath = '';
5461: my $lastitem = '';
5462: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5463: $parentpath = $1;
5464: $lastitem = $2;
5465: } else {
5466: $lastitem = $thisdisfn;
5467: }
1.921 bisitz 5468:
5469: my $output =
1.822 bisitz 5470: '<div>'
5471: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5472: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5473: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5474: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5475: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5476:
5477: if ($lastitem) {
5478: $output .=
5479: '<span class="LC_filename">'
5480: .$lastitem
5481: .'</span>';
5482: }
5483: $output .=
5484: '<br />'
1.822 bisitz 5485: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5486: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5487: .'</form>'
5488: .&Apache::lonmenu::constspaceform()
5489: .'</div>';
1.921 bisitz 5490:
5491: return $output;
1.822 bisitz 5492: }
5493:
1.60 matthew 5494: ###############################################
5495: ###############################################
5496:
5497: =pod
5498:
1.112 bowersj2 5499: =back
5500:
1.549 albertel 5501: =head1 HTML Helpers
1.112 bowersj2 5502:
5503: =over 4
5504:
5505: =item * &bodytag()
1.60 matthew 5506:
5507: Returns a uniform header for LON-CAPA web pages.
5508:
5509: Inputs:
5510:
1.112 bowersj2 5511: =over 4
5512:
5513: =item * $title, A title to be displayed on the page.
5514:
5515: =item * $function, the current role (can be undef).
5516:
5517: =item * $addentries, extra parameters for the <body> tag.
5518:
5519: =item * $bodyonly, if defined, only return the <body> tag.
5520:
5521: =item * $domain, if defined, force a given domain.
5522:
5523: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5524: text interface only)
1.60 matthew 5525:
1.814 bisitz 5526: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5527: navigational links
1.317 albertel 5528:
1.338 albertel 5529: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5530:
1.1075.2.12 raeburn 5531: =item * $no_inline_link, if true and in remote mode, don't show the
5532: 'Switch To Inline Menu' link
5533:
1.460 albertel 5534: =item * $args, optional argument valid values are
5535: no_auto_mt_title -> prevents &mt()ing the title arg
1.1075.2.133 raeburn 5536: use_absolute -> for external resource or syllabus, this will
5537: contain https://<hostname> if server uses
5538: https (as per hosts.tab), but request is for http
5539: hostname -> hostname, from $r->hostname().
1.460 albertel 5540:
1.1075.2.15 raeburn 5541: =item * $advtoolsref, optional argument, ref to an array containing
5542: inlineremote items to be added in "Functions" menu below
5543: breadcrumbs.
5544:
1.112 bowersj2 5545: =back
5546:
1.60 matthew 5547: Returns: A uniform header for LON-CAPA web pages.
5548: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5549: If $bodyonly is undef or zero, an html string containing a <body> tag and
5550: other decorations will be returned.
5551:
5552: =cut
5553:
1.54 www 5554: sub bodytag {
1.831 bisitz 5555: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5556: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5557:
1.954 raeburn 5558: my $public;
5559: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5560: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5561: $public = 1;
5562: }
1.460 albertel 5563: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5564: my $httphost = $args->{'use_absolute'};
1.1075.2.133 raeburn 5565: my $hostname = $args->{'hostname'};
1.339 albertel 5566:
1.183 matthew 5567: $function = &get_users_function() if (!$function);
1.339 albertel 5568: my $img = &designparm($function.'.img',$domain);
5569: my $font = &designparm($function.'.font',$domain);
5570: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5571:
1.803 bisitz 5572: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5573: 'bgcolor' => $pgbg,
1.339 albertel 5574: 'text' => $font,
5575: 'alink' => &designparm($function.'.alink',$domain),
5576: 'vlink' => &designparm($function.'.vlink',$domain),
5577: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5578: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5579:
1.63 www 5580: # role and realm
1.1075.2.68 raeburn 5581: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5582: if ($realm) {
5583: $realm = '/'.$realm;
5584: }
1.378 raeburn 5585: if ($role eq 'ca') {
1.479 albertel 5586: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5587: $realm = &plainname($rname,$rdom);
1.378 raeburn 5588: }
1.55 www 5589: # realm
1.258 albertel 5590: if ($env{'request.course.id'}) {
1.378 raeburn 5591: if ($env{'request.role'} !~ /^cr/) {
5592: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1075.2.115 raeburn 5593: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1075.2.121 raeburn 5594: if ($env{'request.role.desc'}) {
5595: $role = $env{'request.role.desc'};
5596: } else {
5597: $role = &mt('Helpdesk[_1]',' '.$2);
5598: }
1.1075.2.115 raeburn 5599: } else {
5600: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5601: }
1.898 raeburn 5602: if ($env{'request.course.sec'}) {
5603: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5604: }
1.359 albertel 5605: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5606: } else {
5607: $role = &Apache::lonnet::plaintext($role);
1.54 www 5608: }
1.433 albertel 5609:
1.359 albertel 5610: if (!$realm) { $realm=' '; }
1.330 albertel 5611:
1.438 albertel 5612: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5613:
1.101 www 5614: # construct main body tag
1.359 albertel 5615: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 5616: &Apache::lontexconvert::init_math_support();
1.252 albertel 5617:
1.1075.2.38 raeburn 5618: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5619:
5620: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5621: return $bodytag;
1.1075.2.38 raeburn 5622: }
1.359 albertel 5623:
1.954 raeburn 5624: if ($public) {
1.433 albertel 5625: undef($role);
5626: }
1.359 albertel 5627:
1.762 bisitz 5628: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5629: #
5630: # Extra info if you are the DC
5631: my $dc_info = '';
5632: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5633: $env{'course.'.$env{'request.course.id'}.
5634: '.domain'}.'/'})) {
5635: my $cid = $env{'request.course.id'};
1.917 raeburn 5636: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5637: $dc_info =~ s/\s+$//;
1.359 albertel 5638: }
5639:
1.1075.2.108 raeburn 5640: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903 droeschl 5641:
1.1075.2.13 raeburn 5642: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5643:
1.1075.2.38 raeburn 5644:
5645:
1.1075.2.21 raeburn 5646: my $funclist;
5647: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5648: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5649: Apache::lonmenu::serverform();
5650: my $forbodytag;
5651: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5652: $forcereg,$args->{'group'},
5653: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5654: $advtoolsref,'','',\$forbodytag);
1.1075.2.21 raeburn 5655: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5656: $funclist = $forbodytag;
5657: }
5658: } else {
1.903 droeschl 5659:
5660: # if ($env{'request.state'} eq 'construct') {
5661: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5662: # }
5663:
1.1075.2.38 raeburn 5664: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5665: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5666:
1.1075.2.38 raeburn 5667: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5668:
1.916 droeschl 5669: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5670: if ($dc_info) {
5671: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5672: }
1.1075.2.38 raeburn 5673: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5674: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5675: return $bodytag;
5676: }
1.894 droeschl 5677:
1.927 raeburn 5678: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5679: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5680: }
1.916 droeschl 5681:
1.1075.2.38 raeburn 5682: $bodytag .= $right;
1.852 droeschl 5683:
1.917 raeburn 5684: if ($dc_info) {
5685: $dc_info = &dc_courseid_toggle($dc_info);
5686: }
5687: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5688:
1.1075.2.61 raeburn 5689: #if directed to not display the secondary menu, don't.
5690: if ($args->{'no_secondary_menu'}) {
5691: return $bodytag;
5692: }
1.903 droeschl 5693: #don't show menus for public users
1.954 raeburn 5694: if (!$public){
1.1075.2.52 raeburn 5695: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5696: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5697: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5698: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5699: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1075.2.133 raeburn 5700: $args->{'bread_crumbs'},'','',$hostname);
1.1075.2.116 raeburn 5701: } elsif ($forcereg) {
1.1075.2.22 raeburn 5702: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.116 raeburn 5703: $args->{'group'},
1.1075.2.133 raeburn 5704: $args->{'hide_buttons',
5705: $hostname});
1.1075.2.15 raeburn 5706: } else {
1.1075.2.21 raeburn 5707: my $forbodytag;
5708: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5709: $forcereg,$args->{'group'},
5710: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5711: $advtoolsref,'',$hostname,
5712: \$forbodytag);
1.1075.2.21 raeburn 5713: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5714: $bodytag .= $forbodytag;
5715: }
1.920 raeburn 5716: }
1.903 droeschl 5717: }else{
5718: # this is to seperate menu from content when there's no secondary
5719: # menu. Especially needed for public accessible ressources.
5720: $bodytag .= '<hr style="clear:both" />';
5721: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5722: }
1.903 droeschl 5723:
1.235 raeburn 5724: return $bodytag;
1.1075.2.12 raeburn 5725: }
5726:
5727: #
5728: # Top frame rendering, Remote is up
5729: #
5730:
5731: my $imgsrc = $img;
5732: if ($img =~ /^\/adm/) {
5733: $imgsrc = &lonhttpdurl($img);
5734: }
5735: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5736:
1.1075.2.60 raeburn 5737: my $help=($no_inline_link?''
5738: :&Apache::loncommon::top_nav_help('Help'));
5739:
1.1075.2.12 raeburn 5740: # Explicit link to get inline menu
5741: my $menu= ($no_inline_link?''
5742: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5743:
5744: if ($dc_info) {
5745: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5746: }
5747:
1.1075.2.38 raeburn 5748: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5749: unless ($public) {
5750: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5751: undef,'LC_menubuttons_link');
5752: }
5753:
1.1075.2.12 raeburn 5754: unless ($env{'form.inhibitmenu'}) {
5755: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5756: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5757: <li>$help</li>
1.1075.2.12 raeburn 5758: <li>$menu</li>
5759: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5760: }
1.1075.2.13 raeburn 5761: if ($env{'request.state'} eq 'construct') {
5762: if (!$public){
5763: if ($env{'request.state'} eq 'construct') {
5764: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5765: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5766: &Apache::lonhtmlcommon::scripttag('','end').
5767: &Apache::lonmenu::innerregister($forcereg,
5768: $args->{'bread_crumbs'});
5769: }
5770: }
5771: }
1.1075.2.21 raeburn 5772: return $bodytag."\n".$funclist;
1.182 matthew 5773: }
5774:
1.917 raeburn 5775: sub dc_courseid_toggle {
5776: my ($dc_info) = @_;
1.980 raeburn 5777: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5778: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5779: &mt('(More ...)').'</a></span>'.
5780: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5781: }
5782:
1.330 albertel 5783: sub make_attr_string {
5784: my ($register,$attr_ref) = @_;
5785:
5786: if ($attr_ref && !ref($attr_ref)) {
5787: die("addentries Must be a hash ref ".
5788: join(':',caller(1))." ".
5789: join(':',caller(0))." ");
5790: }
5791:
5792: if ($register) {
1.339 albertel 5793: my ($on_load,$on_unload);
5794: foreach my $key (keys(%{$attr_ref})) {
5795: if (lc($key) eq 'onload') {
5796: $on_load.=$attr_ref->{$key}.';';
5797: delete($attr_ref->{$key});
5798:
5799: } elsif (lc($key) eq 'onunload') {
5800: $on_unload.=$attr_ref->{$key}.';';
5801: delete($attr_ref->{$key});
5802: }
5803: }
1.1075.2.12 raeburn 5804: if ($env{'environment.remote'} eq 'on') {
5805: $attr_ref->{'onload'} =
5806: &Apache::lonmenu::loadevents(). $on_load;
5807: $attr_ref->{'onunload'}=
5808: &Apache::lonmenu::unloadevents().$on_unload;
5809: } else {
5810: $attr_ref->{'onload'} = $on_load;
5811: $attr_ref->{'onunload'}= $on_unload;
5812: }
1.330 albertel 5813: }
1.339 albertel 5814:
1.330 albertel 5815: my $attr_string;
1.1075.2.56 raeburn 5816: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5817: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5818: }
5819: return $attr_string;
5820: }
5821:
5822:
1.182 matthew 5823: ###############################################
1.251 albertel 5824: ###############################################
5825:
5826: =pod
5827:
5828: =item * &endbodytag()
5829:
5830: Returns a uniform footer for LON-CAPA web pages.
5831:
1.635 raeburn 5832: Inputs: 1 - optional reference to an args hash
5833: If in the hash, key for noredirectlink has a value which evaluates to true,
5834: a 'Continue' link is not displayed if the page contains an
5835: internal redirect in the <head></head> section,
5836: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5837:
5838: =cut
5839:
5840: sub endbodytag {
1.635 raeburn 5841: my ($args) = @_;
1.1075.2.6 raeburn 5842: my $endbodytag;
5843: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5844: $endbodytag='</body>';
5845: }
1.315 albertel 5846: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5847: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5848: $endbodytag=
5849: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5850: &mt('Continue').'</a>'.
5851: $endbodytag;
5852: }
1.315 albertel 5853: }
1.251 albertel 5854: return $endbodytag;
5855: }
5856:
1.352 albertel 5857: =pod
5858:
5859: =item * &standard_css()
5860:
5861: Returns a style sheet
5862:
5863: Inputs: (all optional)
5864: domain -> force to color decorate a page for a specific
5865: domain
5866: function -> force usage of a specific rolish color scheme
5867: bgcolor -> override the default page bgcolor
5868:
5869: =cut
5870:
1.343 albertel 5871: sub standard_css {
1.345 albertel 5872: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5873: $function = &get_users_function() if (!$function);
5874: my $img = &designparm($function.'.img', $domain);
5875: my $tabbg = &designparm($function.'.tabbg', $domain);
5876: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5877: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5878: #second colour for later usage
1.345 albertel 5879: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5880: my $pgbg_or_bgcolor =
5881: $bgcolor ||
1.352 albertel 5882: &designparm($function.'.pgbg', $domain);
1.382 albertel 5883: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5884: my $alink = &designparm($function.'.alink', $domain);
5885: my $vlink = &designparm($function.'.vlink', $domain);
5886: my $link = &designparm($function.'.link', $domain);
5887:
1.602 albertel 5888: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5889: my $mono = 'monospace';
1.850 bisitz 5890: my $data_table_head = $sidebg;
5891: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5892: my $data_table_dark = '#E0E0E0';
1.470 banghart 5893: my $data_table_darker = '#CCCCCC';
1.349 albertel 5894: my $data_table_highlight = '#FFFF00';
1.352 albertel 5895: my $mail_new = '#FFBB77';
5896: my $mail_new_hover = '#DD9955';
5897: my $mail_read = '#BBBB77';
5898: my $mail_read_hover = '#999944';
5899: my $mail_replied = '#AAAA88';
5900: my $mail_replied_hover = '#888855';
5901: my $mail_other = '#99BBBB';
5902: my $mail_other_hover = '#669999';
1.391 albertel 5903: my $table_header = '#DDDDDD';
1.489 raeburn 5904: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5905: my $lg_border_color = '#C8C8C8';
1.952 onken 5906: my $button_hover = '#BF2317';
1.392 albertel 5907:
1.608 albertel 5908: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5909: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5910: : '0 3px 0 4px';
1.448 albertel 5911:
1.523 albertel 5912:
1.343 albertel 5913: return <<END;
1.947 droeschl 5914:
5915: /* needed for iframe to allow 100% height in FF */
5916: body, html {
5917: margin: 0;
5918: padding: 0 0.5%;
5919: height: 99%; /* to avoid scrollbars */
5920: }
5921:
1.795 www 5922: body {
1.911 bisitz 5923: font-family: $sans;
5924: line-height:130%;
5925: font-size:0.83em;
5926: color:$font;
1.795 www 5927: }
5928:
1.959 onken 5929: a:focus,
5930: a:focus img {
1.795 www 5931: color: red;
5932: }
1.698 harmsja 5933:
1.911 bisitz 5934: form, .inline {
5935: display: inline;
1.795 www 5936: }
1.721 harmsja 5937:
1.795 www 5938: .LC_right {
1.911 bisitz 5939: text-align:right;
1.795 www 5940: }
5941:
5942: .LC_middle {
1.911 bisitz 5943: vertical-align:middle;
1.795 www 5944: }
1.721 harmsja 5945:
1.1075.2.38 raeburn 5946: .LC_floatleft {
5947: float: left;
5948: }
5949:
5950: .LC_floatright {
5951: float: right;
5952: }
5953:
1.911 bisitz 5954: .LC_400Box {
5955: width:400px;
5956: }
1.721 harmsja 5957:
1.947 droeschl 5958: .LC_iframecontainer {
5959: width: 98%;
5960: margin: 0;
5961: position: fixed;
5962: top: 8.5em;
5963: bottom: 0;
5964: }
5965:
5966: .LC_iframecontainer iframe{
5967: border: none;
5968: width: 100%;
5969: height: 100%;
5970: }
5971:
1.778 bisitz 5972: .LC_filename {
5973: font-family: $mono;
5974: white-space:pre;
1.921 bisitz 5975: font-size: 120%;
1.778 bisitz 5976: }
5977:
5978: .LC_fileicon {
5979: border: none;
5980: height: 1.3em;
5981: vertical-align: text-bottom;
5982: margin-right: 0.3em;
5983: text-decoration:none;
5984: }
5985:
1.1008 www 5986: .LC_setting {
5987: text-decoration:underline;
5988: }
5989:
1.350 albertel 5990: .LC_error {
5991: color: red;
5992: }
1.795 www 5993:
1.1075.2.15 raeburn 5994: .LC_warning {
5995: color: darkorange;
5996: }
5997:
1.457 albertel 5998: .LC_diff_removed {
1.733 bisitz 5999: color: red;
1.394 albertel 6000: }
1.532 albertel 6001:
6002: .LC_info,
1.457 albertel 6003: .LC_success,
6004: .LC_diff_added {
1.350 albertel 6005: color: green;
6006: }
1.795 www 6007:
1.802 bisitz 6008: div.LC_confirm_box {
6009: background-color: #FAFAFA;
6010: border: 1px solid $lg_border_color;
6011: margin-right: 0;
6012: padding: 5px;
6013: }
6014:
6015: div.LC_confirm_box .LC_error img,
6016: div.LC_confirm_box .LC_success img {
6017: vertical-align: middle;
6018: }
6019:
1.1075.2.108 raeburn 6020: .LC_maxwidth {
6021: max-width: 100%;
6022: height: auto;
6023: }
6024:
6025: .LC_textsize_mobile {
6026: \@media only screen and (max-device-width: 480px) {
6027: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6028: }
6029: }
6030:
1.440 albertel 6031: .LC_icon {
1.771 droeschl 6032: border: none;
1.790 droeschl 6033: vertical-align: middle;
1.771 droeschl 6034: }
6035:
1.543 albertel 6036: .LC_docs_spacer {
6037: width: 25px;
6038: height: 1px;
1.771 droeschl 6039: border: none;
1.543 albertel 6040: }
1.346 albertel 6041:
1.532 albertel 6042: .LC_internal_info {
1.735 bisitz 6043: color: #999999;
1.532 albertel 6044: }
6045:
1.794 www 6046: .LC_discussion {
1.1050 www 6047: background: $data_table_dark;
1.911 bisitz 6048: border: 1px solid black;
6049: margin: 2px;
1.794 www 6050: }
6051:
6052: .LC_disc_action_left {
1.1050 www 6053: background: $sidebg;
1.911 bisitz 6054: text-align: left;
1.1050 www 6055: padding: 4px;
6056: margin: 2px;
1.794 www 6057: }
6058:
6059: .LC_disc_action_right {
1.1050 www 6060: background: $sidebg;
1.911 bisitz 6061: text-align: right;
1.1050 www 6062: padding: 4px;
6063: margin: 2px;
1.794 www 6064: }
6065:
6066: .LC_disc_new_item {
1.911 bisitz 6067: background: white;
6068: border: 2px solid red;
1.1050 www 6069: margin: 4px;
6070: padding: 4px;
1.794 www 6071: }
6072:
6073: .LC_disc_old_item {
1.911 bisitz 6074: background: white;
1.1050 www 6075: margin: 4px;
6076: padding: 4px;
1.794 www 6077: }
6078:
1.458 albertel 6079: table.LC_pastsubmission {
6080: border: 1px solid black;
6081: margin: 2px;
6082: }
6083:
1.924 bisitz 6084: table#LC_menubuttons {
1.345 albertel 6085: width: 100%;
6086: background: $pgbg;
1.392 albertel 6087: border: 2px;
1.402 albertel 6088: border-collapse: separate;
1.803 bisitz 6089: padding: 0;
1.345 albertel 6090: }
1.392 albertel 6091:
1.801 tempelho 6092: table#LC_title_bar a {
6093: color: $fontmenu;
6094: }
1.836 bisitz 6095:
1.807 droeschl 6096: table#LC_title_bar {
1.819 tempelho 6097: clear: both;
1.836 bisitz 6098: display: none;
1.807 droeschl 6099: }
6100:
1.795 www 6101: table#LC_title_bar,
1.933 droeschl 6102: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6103: table#LC_title_bar.LC_with_remote {
1.359 albertel 6104: width: 100%;
1.392 albertel 6105: border-color: $pgbg;
6106: border-style: solid;
6107: border-width: $border;
1.379 albertel 6108: background: $pgbg;
1.801 tempelho 6109: color: $fontmenu;
1.392 albertel 6110: border-collapse: collapse;
1.803 bisitz 6111: padding: 0;
1.819 tempelho 6112: margin: 0;
1.359 albertel 6113: }
1.795 www 6114:
1.933 droeschl 6115: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6116: margin: 0;
6117: padding: 0;
1.933 droeschl 6118: position: relative;
6119: list-style: none;
1.913 droeschl 6120: }
1.933 droeschl 6121: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6122: display: inline;
6123: }
1.933 droeschl 6124:
6125: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6126: padding: 0;
1.933 droeschl 6127: margin: 0;
6128: float: left;
1.913 droeschl 6129: }
1.933 droeschl 6130: .LC_breadcrumb_tools_tools {
6131: padding: 0;
6132: margin: 0;
1.913 droeschl 6133: float: right;
6134: }
6135:
1.359 albertel 6136: table#LC_title_bar td {
6137: background: $tabbg;
6138: }
1.795 www 6139:
1.911 bisitz 6140: table#LC_menubuttons img {
1.803 bisitz 6141: border: none;
1.346 albertel 6142: }
1.795 www 6143:
1.842 droeschl 6144: .LC_breadcrumbs_component {
1.911 bisitz 6145: float: right;
6146: margin: 0 1em;
1.357 albertel 6147: }
1.842 droeschl 6148: .LC_breadcrumbs_component img {
1.911 bisitz 6149: vertical-align: middle;
1.777 tempelho 6150: }
1.795 www 6151:
1.1075.2.108 raeburn 6152: .LC_breadcrumbs_hoverable {
6153: background: $sidebg;
6154: }
6155:
1.383 albertel 6156: td.LC_table_cell_checkbox {
6157: text-align: center;
6158: }
1.795 www 6159:
6160: .LC_fontsize_small {
1.911 bisitz 6161: font-size: 70%;
1.705 tempelho 6162: }
6163:
1.844 bisitz 6164: #LC_breadcrumbs {
1.911 bisitz 6165: clear:both;
6166: background: $sidebg;
6167: border-bottom: 1px solid $lg_border_color;
6168: line-height: 2.5em;
1.933 droeschl 6169: overflow: hidden;
1.911 bisitz 6170: margin: 0;
6171: padding: 0;
1.995 raeburn 6172: text-align: left;
1.819 tempelho 6173: }
1.862 bisitz 6174:
1.1075.2.16 raeburn 6175: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6176: clear:both;
6177: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6178: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6179: margin: 0 0 10px 0;
1.966 bisitz 6180: padding: 3px;
1.995 raeburn 6181: text-align: left;
1.822 bisitz 6182: }
6183:
1.795 www 6184: .LC_fontsize_medium {
1.911 bisitz 6185: font-size: 85%;
1.705 tempelho 6186: }
6187:
1.795 www 6188: .LC_fontsize_large {
1.911 bisitz 6189: font-size: 120%;
1.705 tempelho 6190: }
6191:
1.346 albertel 6192: .LC_menubuttons_inline_text {
6193: color: $font;
1.698 harmsja 6194: font-size: 90%;
1.701 harmsja 6195: padding-left:3px;
1.346 albertel 6196: }
6197:
1.934 droeschl 6198: .LC_menubuttons_inline_text img{
6199: vertical-align: middle;
6200: }
6201:
1.1051 www 6202: li.LC_menubuttons_inline_text img {
1.951 onken 6203: cursor:pointer;
1.1002 droeschl 6204: text-decoration: none;
1.951 onken 6205: }
6206:
1.526 www 6207: .LC_menubuttons_link {
6208: text-decoration: none;
6209: }
1.795 www 6210:
1.522 albertel 6211: .LC_menubuttons_category {
1.521 www 6212: color: $font;
1.526 www 6213: background: $pgbg;
1.521 www 6214: font-size: larger;
6215: font-weight: bold;
6216: }
6217:
1.346 albertel 6218: td.LC_menubuttons_text {
1.911 bisitz 6219: color: $font;
1.346 albertel 6220: }
1.706 harmsja 6221:
1.346 albertel 6222: .LC_current_location {
6223: background: $tabbg;
6224: }
1.795 www 6225:
1.1075.2.134 raeburn 6226: td.LC_zero_height {
6227: line-height: 0;
6228: cellpadding: 0;
6229: }
6230:
1.938 bisitz 6231: table.LC_data_table {
1.347 albertel 6232: border: 1px solid #000000;
1.402 albertel 6233: border-collapse: separate;
1.426 albertel 6234: border-spacing: 1px;
1.610 albertel 6235: background: $pgbg;
1.347 albertel 6236: }
1.795 www 6237:
1.422 albertel 6238: .LC_data_table_dense {
6239: font-size: small;
6240: }
1.795 www 6241:
1.507 raeburn 6242: table.LC_nested_outer {
6243: border: 1px solid #000000;
1.589 raeburn 6244: border-collapse: collapse;
1.803 bisitz 6245: border-spacing: 0;
1.507 raeburn 6246: width: 100%;
6247: }
1.795 www 6248:
1.879 raeburn 6249: table.LC_innerpickbox,
1.507 raeburn 6250: table.LC_nested {
1.803 bisitz 6251: border: none;
1.589 raeburn 6252: border-collapse: collapse;
1.803 bisitz 6253: border-spacing: 0;
1.507 raeburn 6254: width: 100%;
6255: }
1.795 www 6256:
1.911 bisitz 6257: table.LC_data_table tr th,
6258: table.LC_calendar tr th,
1.879 raeburn 6259: table.LC_prior_tries tr th,
6260: table.LC_innerpickbox tr th {
1.349 albertel 6261: font-weight: bold;
6262: background-color: $data_table_head;
1.801 tempelho 6263: color:$fontmenu;
1.701 harmsja 6264: font-size:90%;
1.347 albertel 6265: }
1.795 www 6266:
1.879 raeburn 6267: table.LC_innerpickbox tr th,
6268: table.LC_innerpickbox tr td {
6269: vertical-align: top;
6270: }
6271:
1.711 raeburn 6272: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6273: background-color: #CCCCCC;
1.711 raeburn 6274: font-weight: bold;
6275: text-align: left;
6276: }
1.795 www 6277:
1.912 bisitz 6278: table.LC_data_table tr.LC_odd_row > td {
6279: background-color: $data_table_light;
6280: padding: 2px;
6281: vertical-align: top;
6282: }
6283:
1.809 bisitz 6284: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6285: background-color: $data_table_light;
1.912 bisitz 6286: vertical-align: top;
6287: }
6288:
6289: table.LC_data_table tr.LC_even_row > td {
6290: background-color: $data_table_dark;
1.425 albertel 6291: padding: 2px;
1.900 bisitz 6292: vertical-align: top;
1.347 albertel 6293: }
1.795 www 6294:
1.809 bisitz 6295: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6296: background-color: $data_table_dark;
1.900 bisitz 6297: vertical-align: top;
1.347 albertel 6298: }
1.795 www 6299:
1.425 albertel 6300: table.LC_data_table tr.LC_data_table_highlight td {
6301: background-color: $data_table_darker;
6302: }
1.795 www 6303:
1.639 raeburn 6304: table.LC_data_table tr td.LC_leftcol_header {
6305: background-color: $data_table_head;
6306: font-weight: bold;
6307: }
1.795 www 6308:
1.451 albertel 6309: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6310: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6311: font-weight: bold;
6312: font-style: italic;
6313: text-align: center;
6314: padding: 8px;
1.347 albertel 6315: }
1.795 www 6316:
1.1075.2.30 raeburn 6317: table.LC_data_table tr.LC_empty_row td,
6318: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6319: background-color: $sidebg;
6320: }
6321:
6322: table.LC_nested tr.LC_empty_row td {
6323: background-color: #FFFFFF;
6324: }
6325:
1.890 droeschl 6326: table.LC_caption {
6327: }
6328:
1.507 raeburn 6329: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6330: padding: 4ex
6331: }
1.795 www 6332:
1.507 raeburn 6333: table.LC_nested_outer tr th {
6334: font-weight: bold;
1.801 tempelho 6335: color:$fontmenu;
1.507 raeburn 6336: background-color: $data_table_head;
1.701 harmsja 6337: font-size: small;
1.507 raeburn 6338: border-bottom: 1px solid #000000;
6339: }
1.795 www 6340:
1.507 raeburn 6341: table.LC_nested_outer tr td.LC_subheader {
6342: background-color: $data_table_head;
6343: font-weight: bold;
6344: font-size: small;
6345: border-bottom: 1px solid #000000;
6346: text-align: right;
1.451 albertel 6347: }
1.795 www 6348:
1.507 raeburn 6349: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6350: background-color: #CCCCCC;
1.451 albertel 6351: font-weight: bold;
6352: font-size: small;
1.507 raeburn 6353: text-align: center;
6354: }
1.795 www 6355:
1.589 raeburn 6356: table.LC_nested tr.LC_info_row td.LC_left_item,
6357: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6358: text-align: left;
1.451 albertel 6359: }
1.795 www 6360:
1.507 raeburn 6361: table.LC_nested td {
1.735 bisitz 6362: background-color: #FFFFFF;
1.451 albertel 6363: font-size: small;
1.507 raeburn 6364: }
1.795 www 6365:
1.507 raeburn 6366: table.LC_nested_outer tr th.LC_right_item,
6367: table.LC_nested tr.LC_info_row td.LC_right_item,
6368: table.LC_nested tr.LC_odd_row td.LC_right_item,
6369: table.LC_nested tr td.LC_right_item {
1.451 albertel 6370: text-align: right;
6371: }
6372:
1.507 raeburn 6373: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6374: background-color: #EEEEEE;
1.451 albertel 6375: }
6376:
1.473 raeburn 6377: table.LC_createuser {
6378: }
6379:
6380: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6381: font-size: small;
1.473 raeburn 6382: }
6383:
6384: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6385: background-color: #CCCCCC;
1.473 raeburn 6386: font-weight: bold;
6387: text-align: center;
6388: }
6389:
1.349 albertel 6390: table.LC_calendar {
6391: border: 1px solid #000000;
6392: border-collapse: collapse;
1.917 raeburn 6393: width: 98%;
1.349 albertel 6394: }
1.795 www 6395:
1.349 albertel 6396: table.LC_calendar_pickdate {
6397: font-size: xx-small;
6398: }
1.795 www 6399:
1.349 albertel 6400: table.LC_calendar tr td {
6401: border: 1px solid #000000;
6402: vertical-align: top;
1.917 raeburn 6403: width: 14%;
1.349 albertel 6404: }
1.795 www 6405:
1.349 albertel 6406: table.LC_calendar tr td.LC_calendar_day_empty {
6407: background-color: $data_table_dark;
6408: }
1.795 www 6409:
1.779 bisitz 6410: table.LC_calendar tr td.LC_calendar_day_current {
6411: background-color: $data_table_highlight;
1.777 tempelho 6412: }
1.795 www 6413:
1.938 bisitz 6414: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6415: background-color: $mail_new;
6416: }
1.795 www 6417:
1.938 bisitz 6418: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6419: background-color: $mail_new_hover;
6420: }
1.795 www 6421:
1.938 bisitz 6422: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6423: background-color: $mail_read;
6424: }
1.795 www 6425:
1.938 bisitz 6426: /*
6427: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6428: background-color: $mail_read_hover;
6429: }
1.938 bisitz 6430: */
1.795 www 6431:
1.938 bisitz 6432: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6433: background-color: $mail_replied;
6434: }
1.795 www 6435:
1.938 bisitz 6436: /*
6437: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6438: background-color: $mail_replied_hover;
6439: }
1.938 bisitz 6440: */
1.795 www 6441:
1.938 bisitz 6442: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6443: background-color: $mail_other;
6444: }
1.795 www 6445:
1.938 bisitz 6446: /*
6447: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6448: background-color: $mail_other_hover;
6449: }
1.938 bisitz 6450: */
1.494 raeburn 6451:
1.777 tempelho 6452: table.LC_data_table tr > td.LC_browser_file,
6453: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6454: background: #AAEE77;
1.389 albertel 6455: }
1.795 www 6456:
1.777 tempelho 6457: table.LC_data_table tr > td.LC_browser_file_locked,
6458: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6459: background: #FFAA99;
1.387 albertel 6460: }
1.795 www 6461:
1.777 tempelho 6462: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6463: background: #888888;
1.779 bisitz 6464: }
1.795 www 6465:
1.777 tempelho 6466: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6467: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6468: background: #F8F866;
1.777 tempelho 6469: }
1.795 www 6470:
1.696 bisitz 6471: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6472: background: #E0E8FF;
1.387 albertel 6473: }
1.696 bisitz 6474:
1.707 bisitz 6475: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6476: /* background: #77FF77; */
1.707 bisitz 6477: }
1.795 www 6478:
1.707 bisitz 6479: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6480: border-right: 8px solid #FFFF77;
1.707 bisitz 6481: }
1.795 www 6482:
1.707 bisitz 6483: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6484: border-right: 8px solid #FFAA77;
1.707 bisitz 6485: }
1.795 www 6486:
1.707 bisitz 6487: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6488: border-right: 8px solid #FF7777;
1.707 bisitz 6489: }
1.795 www 6490:
1.707 bisitz 6491: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6492: border-right: 8px solid #AAFF77;
1.707 bisitz 6493: }
1.795 www 6494:
1.707 bisitz 6495: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6496: border-right: 8px solid #11CC55;
1.707 bisitz 6497: }
6498:
1.388 albertel 6499: span.LC_current_location {
1.701 harmsja 6500: font-size:larger;
1.388 albertel 6501: background: $pgbg;
6502: }
1.387 albertel 6503:
1.1029 www 6504: span.LC_current_nav_location {
6505: font-weight:bold;
6506: background: $sidebg;
6507: }
6508:
1.395 albertel 6509: span.LC_parm_menu_item {
6510: font-size: larger;
6511: }
1.795 www 6512:
1.395 albertel 6513: span.LC_parm_scope_all {
6514: color: red;
6515: }
1.795 www 6516:
1.395 albertel 6517: span.LC_parm_scope_folder {
6518: color: green;
6519: }
1.795 www 6520:
1.395 albertel 6521: span.LC_parm_scope_resource {
6522: color: orange;
6523: }
1.795 www 6524:
1.395 albertel 6525: span.LC_parm_part {
6526: color: blue;
6527: }
1.795 www 6528:
1.911 bisitz 6529: span.LC_parm_folder,
6530: span.LC_parm_symb {
1.395 albertel 6531: font-size: x-small;
6532: font-family: $mono;
6533: color: #AAAAAA;
6534: }
6535:
1.977 bisitz 6536: ul.LC_parm_parmlist li {
6537: display: inline-block;
6538: padding: 0.3em 0.8em;
6539: vertical-align: top;
6540: width: 150px;
6541: border-top:1px solid $lg_border_color;
6542: }
6543:
1.795 www 6544: td.LC_parm_overview_level_menu,
6545: td.LC_parm_overview_map_menu,
6546: td.LC_parm_overview_parm_selectors,
6547: td.LC_parm_overview_restrictions {
1.396 albertel 6548: border: 1px solid black;
6549: border-collapse: collapse;
6550: }
1.795 www 6551:
1.396 albertel 6552: table.LC_parm_overview_restrictions td {
6553: border-width: 1px 4px 1px 4px;
6554: border-style: solid;
6555: border-color: $pgbg;
6556: text-align: center;
6557: }
1.795 www 6558:
1.396 albertel 6559: table.LC_parm_overview_restrictions th {
6560: background: $tabbg;
6561: border-width: 1px 4px 1px 4px;
6562: border-style: solid;
6563: border-color: $pgbg;
6564: }
1.795 www 6565:
1.398 albertel 6566: table#LC_helpmenu {
1.803 bisitz 6567: border: none;
1.398 albertel 6568: height: 55px;
1.803 bisitz 6569: border-spacing: 0;
1.398 albertel 6570: }
6571:
6572: table#LC_helpmenu fieldset legend {
6573: font-size: larger;
6574: }
1.795 www 6575:
1.397 albertel 6576: table#LC_helpmenu_links {
6577: width: 100%;
6578: border: 1px solid black;
6579: background: $pgbg;
1.803 bisitz 6580: padding: 0;
1.397 albertel 6581: border-spacing: 1px;
6582: }
1.795 www 6583:
1.397 albertel 6584: table#LC_helpmenu_links tr td {
6585: padding: 1px;
6586: background: $tabbg;
1.399 albertel 6587: text-align: center;
6588: font-weight: bold;
1.397 albertel 6589: }
1.396 albertel 6590:
1.795 www 6591: table#LC_helpmenu_links a:link,
6592: table#LC_helpmenu_links a:visited,
1.397 albertel 6593: table#LC_helpmenu_links a:active {
6594: text-decoration: none;
6595: color: $font;
6596: }
1.795 www 6597:
1.397 albertel 6598: table#LC_helpmenu_links a:hover {
6599: text-decoration: underline;
6600: color: $vlink;
6601: }
1.396 albertel 6602:
1.417 albertel 6603: .LC_chrt_popup_exists {
6604: border: 1px solid #339933;
6605: margin: -1px;
6606: }
1.795 www 6607:
1.417 albertel 6608: .LC_chrt_popup_up {
6609: border: 1px solid yellow;
6610: margin: -1px;
6611: }
1.795 www 6612:
1.417 albertel 6613: .LC_chrt_popup {
6614: border: 1px solid #8888FF;
6615: background: #CCCCFF;
6616: }
1.795 www 6617:
1.421 albertel 6618: table.LC_pick_box {
6619: border-collapse: separate;
6620: background: white;
6621: border: 1px solid black;
6622: border-spacing: 1px;
6623: }
1.795 www 6624:
1.421 albertel 6625: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6626: background: $sidebg;
1.421 albertel 6627: font-weight: bold;
1.900 bisitz 6628: text-align: left;
1.740 bisitz 6629: vertical-align: top;
1.421 albertel 6630: width: 184px;
6631: padding: 8px;
6632: }
1.795 www 6633:
1.579 raeburn 6634: table.LC_pick_box td.LC_pick_box_value {
6635: text-align: left;
6636: padding: 8px;
6637: }
1.795 www 6638:
1.579 raeburn 6639: table.LC_pick_box td.LC_pick_box_select {
6640: text-align: left;
6641: padding: 8px;
6642: }
1.795 www 6643:
1.424 albertel 6644: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6645: padding: 0;
1.421 albertel 6646: height: 1px;
6647: background: black;
6648: }
1.795 www 6649:
1.421 albertel 6650: table.LC_pick_box td.LC_pick_box_submit {
6651: text-align: right;
6652: }
1.795 www 6653:
1.579 raeburn 6654: table.LC_pick_box td.LC_evenrow_value {
6655: text-align: left;
6656: padding: 8px;
6657: background-color: $data_table_light;
6658: }
1.795 www 6659:
1.579 raeburn 6660: table.LC_pick_box td.LC_oddrow_value {
6661: text-align: left;
6662: padding: 8px;
6663: background-color: $data_table_light;
6664: }
1.795 www 6665:
1.579 raeburn 6666: span.LC_helpform_receipt_cat {
6667: font-weight: bold;
6668: }
1.795 www 6669:
1.424 albertel 6670: table.LC_group_priv_box {
6671: background: white;
6672: border: 1px solid black;
6673: border-spacing: 1px;
6674: }
1.795 www 6675:
1.424 albertel 6676: table.LC_group_priv_box td.LC_pick_box_title {
6677: background: $tabbg;
6678: font-weight: bold;
6679: text-align: right;
6680: width: 184px;
6681: }
1.795 www 6682:
1.424 albertel 6683: table.LC_group_priv_box td.LC_groups_fixed {
6684: background: $data_table_light;
6685: text-align: center;
6686: }
1.795 www 6687:
1.424 albertel 6688: table.LC_group_priv_box td.LC_groups_optional {
6689: background: $data_table_dark;
6690: text-align: center;
6691: }
1.795 www 6692:
1.424 albertel 6693: table.LC_group_priv_box td.LC_groups_functionality {
6694: background: $data_table_darker;
6695: text-align: center;
6696: font-weight: bold;
6697: }
1.795 www 6698:
1.424 albertel 6699: table.LC_group_priv td {
6700: text-align: left;
1.803 bisitz 6701: padding: 0;
1.424 albertel 6702: }
6703:
6704: .LC_navbuttons {
6705: margin: 2ex 0ex 2ex 0ex;
6706: }
1.795 www 6707:
1.423 albertel 6708: .LC_topic_bar {
6709: font-weight: bold;
6710: background: $tabbg;
1.918 wenzelju 6711: margin: 1em 0em 1em 2em;
1.805 bisitz 6712: padding: 3px;
1.918 wenzelju 6713: font-size: 1.2em;
1.423 albertel 6714: }
1.795 www 6715:
1.423 albertel 6716: .LC_topic_bar span {
1.918 wenzelju 6717: left: 0.5em;
6718: position: absolute;
1.423 albertel 6719: vertical-align: middle;
1.918 wenzelju 6720: font-size: 1.2em;
1.423 albertel 6721: }
1.795 www 6722:
1.423 albertel 6723: table.LC_course_group_status {
6724: margin: 20px;
6725: }
1.795 www 6726:
1.423 albertel 6727: table.LC_status_selector td {
6728: vertical-align: top;
6729: text-align: center;
1.424 albertel 6730: padding: 4px;
6731: }
1.795 www 6732:
1.599 albertel 6733: div.LC_feedback_link {
1.616 albertel 6734: clear: both;
1.829 kalberla 6735: background: $sidebg;
1.779 bisitz 6736: width: 100%;
1.829 kalberla 6737: padding-bottom: 10px;
6738: border: 1px $tabbg solid;
1.833 kalberla 6739: height: 22px;
6740: line-height: 22px;
6741: padding-top: 5px;
6742: }
6743:
6744: div.LC_feedback_link img {
6745: height: 22px;
1.867 kalberla 6746: vertical-align:middle;
1.829 kalberla 6747: }
6748:
1.911 bisitz 6749: div.LC_feedback_link a {
1.829 kalberla 6750: text-decoration: none;
1.489 raeburn 6751: }
1.795 www 6752:
1.867 kalberla 6753: div.LC_comblock {
1.911 bisitz 6754: display:inline;
1.867 kalberla 6755: color:$font;
6756: font-size:90%;
6757: }
6758:
6759: div.LC_feedback_link div.LC_comblock {
6760: padding-left:5px;
6761: }
6762:
6763: div.LC_feedback_link div.LC_comblock a {
6764: color:$font;
6765: }
6766:
1.489 raeburn 6767: span.LC_feedback_link {
1.858 bisitz 6768: /* background: $feedback_link_bg; */
1.599 albertel 6769: font-size: larger;
6770: }
1.795 www 6771:
1.599 albertel 6772: span.LC_message_link {
1.858 bisitz 6773: /* background: $feedback_link_bg; */
1.599 albertel 6774: font-size: larger;
6775: position: absolute;
6776: right: 1em;
1.489 raeburn 6777: }
1.421 albertel 6778:
1.515 albertel 6779: table.LC_prior_tries {
1.524 albertel 6780: border: 1px solid #000000;
6781: border-collapse: separate;
6782: border-spacing: 1px;
1.515 albertel 6783: }
1.523 albertel 6784:
1.515 albertel 6785: table.LC_prior_tries td {
1.524 albertel 6786: padding: 2px;
1.515 albertel 6787: }
1.523 albertel 6788:
6789: .LC_answer_correct {
1.795 www 6790: background: lightgreen;
6791: color: darkgreen;
6792: padding: 6px;
1.523 albertel 6793: }
1.795 www 6794:
1.523 albertel 6795: .LC_answer_charged_try {
1.797 www 6796: background: #FFAAAA;
1.795 www 6797: color: darkred;
6798: padding: 6px;
1.523 albertel 6799: }
1.795 www 6800:
1.779 bisitz 6801: .LC_answer_not_charged_try,
1.523 albertel 6802: .LC_answer_no_grade,
6803: .LC_answer_late {
1.795 www 6804: background: lightyellow;
1.523 albertel 6805: color: black;
1.795 www 6806: padding: 6px;
1.523 albertel 6807: }
1.795 www 6808:
1.523 albertel 6809: .LC_answer_previous {
1.795 www 6810: background: lightblue;
6811: color: darkblue;
6812: padding: 6px;
1.523 albertel 6813: }
1.795 www 6814:
1.779 bisitz 6815: .LC_answer_no_message {
1.777 tempelho 6816: background: #FFFFFF;
6817: color: black;
1.795 www 6818: padding: 6px;
1.779 bisitz 6819: }
1.795 www 6820:
1.1075.2.140 raeburn 6821: .LC_answer_unknown,
6822: .LC_answer_warning {
1.779 bisitz 6823: background: orange;
6824: color: black;
1.795 www 6825: padding: 6px;
1.777 tempelho 6826: }
1.795 www 6827:
1.529 albertel 6828: span.LC_prior_numerical,
6829: span.LC_prior_string,
6830: span.LC_prior_custom,
6831: span.LC_prior_reaction,
6832: span.LC_prior_math {
1.925 bisitz 6833: font-family: $mono;
1.523 albertel 6834: white-space: pre;
6835: }
6836:
1.525 albertel 6837: span.LC_prior_string {
1.925 bisitz 6838: font-family: $mono;
1.525 albertel 6839: white-space: pre;
6840: }
6841:
1.523 albertel 6842: table.LC_prior_option {
6843: width: 100%;
6844: border-collapse: collapse;
6845: }
1.795 www 6846:
1.911 bisitz 6847: table.LC_prior_rank,
1.795 www 6848: table.LC_prior_match {
1.528 albertel 6849: border-collapse: collapse;
6850: }
1.795 www 6851:
1.528 albertel 6852: table.LC_prior_option tr td,
6853: table.LC_prior_rank tr td,
6854: table.LC_prior_match tr td {
1.524 albertel 6855: border: 1px solid #000000;
1.515 albertel 6856: }
6857:
1.855 bisitz 6858: .LC_nobreak {
1.544 albertel 6859: white-space: nowrap;
1.519 raeburn 6860: }
6861:
1.576 raeburn 6862: span.LC_cusr_emph {
6863: font-style: italic;
6864: }
6865:
1.633 raeburn 6866: span.LC_cusr_subheading {
6867: font-weight: normal;
6868: font-size: 85%;
6869: }
6870:
1.861 bisitz 6871: div.LC_docs_entry_move {
1.859 bisitz 6872: border: 1px solid #BBBBBB;
1.545 albertel 6873: background: #DDDDDD;
1.861 bisitz 6874: width: 22px;
1.859 bisitz 6875: padding: 1px;
6876: margin: 0;
1.545 albertel 6877: }
6878:
1.861 bisitz 6879: table.LC_data_table tr > td.LC_docs_entry_commands,
6880: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6881: font-size: x-small;
6882: }
1.795 www 6883:
1.861 bisitz 6884: .LC_docs_entry_parameter {
6885: white-space: nowrap;
6886: }
6887:
1.544 albertel 6888: .LC_docs_copy {
1.545 albertel 6889: color: #000099;
1.544 albertel 6890: }
1.795 www 6891:
1.544 albertel 6892: .LC_docs_cut {
1.545 albertel 6893: color: #550044;
1.544 albertel 6894: }
1.795 www 6895:
1.544 albertel 6896: .LC_docs_rename {
1.545 albertel 6897: color: #009900;
1.544 albertel 6898: }
1.795 www 6899:
1.544 albertel 6900: .LC_docs_remove {
1.545 albertel 6901: color: #990000;
6902: }
6903:
1.1075.2.134 raeburn 6904: .LC_domprefs_email,
1.547 albertel 6905: .LC_docs_reinit_warn,
6906: .LC_docs_ext_edit {
6907: font-size: x-small;
6908: }
6909:
1.545 albertel 6910: table.LC_docs_adddocs td,
6911: table.LC_docs_adddocs th {
6912: border: 1px solid #BBBBBB;
6913: padding: 4px;
6914: background: #DDDDDD;
1.543 albertel 6915: }
6916:
1.584 albertel 6917: table.LC_sty_begin {
6918: background: #BBFFBB;
6919: }
1.795 www 6920:
1.584 albertel 6921: table.LC_sty_end {
6922: background: #FFBBBB;
6923: }
6924:
1.589 raeburn 6925: table.LC_double_column {
1.803 bisitz 6926: border-width: 0;
1.589 raeburn 6927: border-collapse: collapse;
6928: width: 100%;
6929: padding: 2px;
6930: }
6931:
6932: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6933: top: 2px;
1.589 raeburn 6934: left: 2px;
6935: width: 47%;
6936: vertical-align: top;
6937: }
6938:
6939: table.LC_double_column tr td.LC_right_col {
6940: top: 2px;
1.779 bisitz 6941: right: 2px;
1.589 raeburn 6942: width: 47%;
6943: vertical-align: top;
6944: }
6945:
1.591 raeburn 6946: div.LC_left_float {
6947: float: left;
6948: padding-right: 5%;
1.597 albertel 6949: padding-bottom: 4px;
1.591 raeburn 6950: }
6951:
6952: div.LC_clear_float_header {
1.597 albertel 6953: padding-bottom: 2px;
1.591 raeburn 6954: }
6955:
6956: div.LC_clear_float_footer {
1.597 albertel 6957: padding-top: 10px;
1.591 raeburn 6958: clear: both;
6959: }
6960:
1.597 albertel 6961: div.LC_grade_show_user {
1.941 bisitz 6962: /* border-left: 5px solid $sidebg; */
6963: border-top: 5px solid #000000;
6964: margin: 50px 0 0 0;
1.936 bisitz 6965: padding: 15px 0 5px 10px;
1.597 albertel 6966: }
1.795 www 6967:
1.936 bisitz 6968: div.LC_grade_show_user_odd_row {
1.941 bisitz 6969: /* border-left: 5px solid #000000; */
6970: }
6971:
6972: div.LC_grade_show_user div.LC_Box {
6973: margin-right: 50px;
1.597 albertel 6974: }
6975:
6976: div.LC_grade_submissions,
6977: div.LC_grade_message_center,
1.936 bisitz 6978: div.LC_grade_info_links {
1.597 albertel 6979: margin: 5px;
6980: width: 99%;
6981: background: #FFFFFF;
6982: }
1.795 www 6983:
1.597 albertel 6984: div.LC_grade_submissions_header,
1.936 bisitz 6985: div.LC_grade_message_center_header {
1.705 tempelho 6986: font-weight: bold;
6987: font-size: large;
1.597 albertel 6988: }
1.795 www 6989:
1.597 albertel 6990: div.LC_grade_submissions_body,
1.936 bisitz 6991: div.LC_grade_message_center_body {
1.597 albertel 6992: border: 1px solid black;
6993: width: 99%;
6994: background: #FFFFFF;
6995: }
1.795 www 6996:
1.613 albertel 6997: table.LC_scantron_action {
6998: width: 100%;
6999: }
1.795 www 7000:
1.613 albertel 7001: table.LC_scantron_action tr th {
1.698 harmsja 7002: font-weight:bold;
7003: font-style:normal;
1.613 albertel 7004: }
1.795 www 7005:
1.779 bisitz 7006: .LC_edit_problem_header,
1.614 albertel 7007: div.LC_edit_problem_footer {
1.705 tempelho 7008: font-weight: normal;
7009: font-size: medium;
1.602 albertel 7010: margin: 2px;
1.1060 bisitz 7011: background-color: $sidebg;
1.600 albertel 7012: }
1.795 www 7013:
1.600 albertel 7014: div.LC_edit_problem_header,
1.602 albertel 7015: div.LC_edit_problem_header div,
1.614 albertel 7016: div.LC_edit_problem_footer,
7017: div.LC_edit_problem_footer div,
1.602 albertel 7018: div.LC_edit_problem_editxml_header,
7019: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 7020: z-index: 100;
1.600 albertel 7021: }
1.795 www 7022:
1.600 albertel 7023: div.LC_edit_problem_header_title {
1.705 tempelho 7024: font-weight: bold;
7025: font-size: larger;
1.602 albertel 7026: background: $tabbg;
7027: padding: 3px;
1.1060 bisitz 7028: margin: 0 0 5px 0;
1.602 albertel 7029: }
1.795 www 7030:
1.602 albertel 7031: table.LC_edit_problem_header_title {
7032: width: 100%;
1.600 albertel 7033: background: $tabbg;
1.602 albertel 7034: }
7035:
1.1075.2.112 raeburn 7036: div.LC_edit_actionbar {
7037: background-color: $sidebg;
7038: margin: 0;
7039: padding: 0;
7040: line-height: 200%;
1.602 albertel 7041: }
1.795 www 7042:
1.1075.2.112 raeburn 7043: div.LC_edit_actionbar div{
7044: padding: 0;
7045: margin: 0;
7046: display: inline-block;
1.600 albertel 7047: }
1.795 www 7048:
1.1075.2.34 raeburn 7049: .LC_edit_opt {
7050: padding-left: 1em;
7051: white-space: nowrap;
7052: }
7053:
1.1075.2.57 raeburn 7054: .LC_edit_problem_latexhelper{
7055: text-align: right;
7056: }
7057:
7058: #LC_edit_problem_colorful div{
7059: margin-left: 40px;
7060: }
7061:
1.1075.2.112 raeburn 7062: #LC_edit_problem_codemirror div{
7063: margin-left: 0px;
7064: }
7065:
1.911 bisitz 7066: img.stift {
1.803 bisitz 7067: border-width: 0;
7068: vertical-align: middle;
1.677 riegler 7069: }
1.680 riegler 7070:
1.923 bisitz 7071: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7072: vertical-align: top;
1.777 tempelho 7073: }
1.795 www 7074:
1.716 raeburn 7075: div.LC_createcourse {
1.911 bisitz 7076: margin: 10px 10px 10px 10px;
1.716 raeburn 7077: }
7078:
1.917 raeburn 7079: .LC_dccid {
1.1075.2.38 raeburn 7080: float: right;
1.917 raeburn 7081: margin: 0.2em 0 0 0;
7082: padding: 0;
7083: font-size: 90%;
7084: display:none;
7085: }
7086:
1.897 wenzelju 7087: ol.LC_primary_menu a:hover,
1.721 harmsja 7088: ol#LC_MenuBreadcrumbs a:hover,
7089: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7090: ul#LC_secondary_menu a:hover,
1.721 harmsja 7091: .LC_FormSectionClearButton input:hover
1.795 www 7092: ul.LC_TabContent li:hover a {
1.952 onken 7093: color:$button_hover;
1.911 bisitz 7094: text-decoration:none;
1.693 droeschl 7095: }
7096:
1.779 bisitz 7097: h1 {
1.911 bisitz 7098: padding: 0;
7099: line-height:130%;
1.693 droeschl 7100: }
1.698 harmsja 7101:
1.911 bisitz 7102: h2,
7103: h3,
7104: h4,
7105: h5,
7106: h6 {
7107: margin: 5px 0 5px 0;
7108: padding: 0;
7109: line-height:130%;
1.693 droeschl 7110: }
1.795 www 7111:
7112: .LC_hcell {
1.911 bisitz 7113: padding:3px 15px 3px 15px;
7114: margin: 0;
7115: background-color:$tabbg;
7116: color:$fontmenu;
7117: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7118: }
1.795 www 7119:
1.840 bisitz 7120: .LC_Box > .LC_hcell {
1.911 bisitz 7121: margin: 0 -10px 10px -10px;
1.835 bisitz 7122: }
7123:
1.721 harmsja 7124: .LC_noBorder {
1.911 bisitz 7125: border: 0;
1.698 harmsja 7126: }
1.693 droeschl 7127:
1.721 harmsja 7128: .LC_FormSectionClearButton input {
1.911 bisitz 7129: background-color:transparent;
7130: border: none;
7131: cursor:pointer;
7132: text-decoration:underline;
1.693 droeschl 7133: }
1.763 bisitz 7134:
7135: .LC_help_open_topic {
1.911 bisitz 7136: color: #FFFFFF;
7137: background-color: #EEEEFF;
7138: margin: 1px;
7139: padding: 4px;
7140: border: 1px solid #000033;
7141: white-space: nowrap;
7142: /* vertical-align: middle; */
1.759 neumanie 7143: }
1.693 droeschl 7144:
1.911 bisitz 7145: dl,
7146: ul,
7147: div,
7148: fieldset {
7149: margin: 10px 10px 10px 0;
7150: /* overflow: hidden; */
1.693 droeschl 7151: }
1.795 www 7152:
1.1075.2.90 raeburn 7153: article.geogebraweb div {
7154: margin: 0;
7155: }
7156:
1.838 bisitz 7157: fieldset > legend {
1.911 bisitz 7158: font-weight: bold;
7159: padding: 0 5px 0 5px;
1.838 bisitz 7160: }
7161:
1.813 bisitz 7162: #LC_nav_bar {
1.911 bisitz 7163: float: left;
1.995 raeburn 7164: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7165: margin: 0 0 2px 0;
1.807 droeschl 7166: }
7167:
1.916 droeschl 7168: #LC_realm {
7169: margin: 0.2em 0 0 0;
7170: padding: 0;
7171: font-weight: bold;
7172: text-align: center;
1.995 raeburn 7173: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7174: }
7175:
1.911 bisitz 7176: #LC_nav_bar em {
7177: font-weight: bold;
7178: font-style: normal;
1.807 droeschl 7179: }
7180:
1.897 wenzelju 7181: ol.LC_primary_menu {
1.934 droeschl 7182: margin: 0;
1.1075.2.2 raeburn 7183: padding: 0;
1.807 droeschl 7184: }
7185:
1.852 droeschl 7186: ol#LC_PathBreadcrumbs {
1.911 bisitz 7187: margin: 0;
1.693 droeschl 7188: }
7189:
1.897 wenzelju 7190: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7191: color: RGB(80, 80, 80);
7192: vertical-align: middle;
7193: text-align: left;
7194: list-style: none;
1.1075.2.112 raeburn 7195: position: relative;
1.1075.2.2 raeburn 7196: float: left;
1.1075.2.112 raeburn 7197: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7198: line-height: 1.5em;
1.1075.2.2 raeburn 7199: }
7200:
1.1075.2.113 raeburn 7201: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7202: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7203: display: block;
7204: margin: 0;
7205: padding: 0 5px 0 10px;
7206: text-decoration: none;
7207: }
7208:
1.1075.2.112 raeburn 7209: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7210: display: inline-block;
7211: width: 95%;
7212: text-align: left;
7213: }
7214:
7215: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7216: display: inline-block;
7217: width: 5%;
7218: float: right;
7219: text-align: right;
7220: font-size: 70%;
7221: }
7222:
7223: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7224: display: none;
1.1075.2.112 raeburn 7225: width: 15em;
1.1075.2.2 raeburn 7226: background-color: $data_table_light;
1.1075.2.112 raeburn 7227: position: absolute;
7228: top: 100%;
7229: }
7230:
7231: ol.LC_primary_menu ul ul {
7232: left: 100%;
7233: top: 0;
1.1075.2.2 raeburn 7234: }
7235:
1.1075.2.112 raeburn 7236: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7237: display: block;
7238: position: absolute;
7239: margin: 0;
7240: padding: 0;
1.1075.2.5 raeburn 7241: z-index: 2;
1.1075.2.2 raeburn 7242: }
7243:
7244: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7245: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7246: font-size: 90%;
1.911 bisitz 7247: vertical-align: top;
1.1075.2.2 raeburn 7248: float: none;
1.1075.2.5 raeburn 7249: border-left: 1px solid black;
7250: border-right: 1px solid black;
1.1075.2.112 raeburn 7251: /* A dark bottom border to visualize different menu options;
7252: overwritten in the create_submenu routine for the last border-bottom of the menu */
7253: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7254: }
7255:
1.1075.2.112 raeburn 7256: ol.LC_primary_menu li li p:hover {
7257: color:$button_hover;
7258: text-decoration:none;
7259: background-color:$data_table_dark;
1.1075.2.2 raeburn 7260: }
7261:
7262: ol.LC_primary_menu li li a:hover {
7263: color:$button_hover;
7264: background-color:$data_table_dark;
1.693 droeschl 7265: }
7266:
1.1075.2.112 raeburn 7267: /* Font-size equal to the size of the predecessors*/
7268: ol.LC_primary_menu li:hover li li {
7269: font-size: 100%;
7270: }
7271:
1.897 wenzelju 7272: ol.LC_primary_menu li img {
1.911 bisitz 7273: vertical-align: bottom;
1.934 droeschl 7274: height: 1.1em;
1.1075.2.3 raeburn 7275: margin: 0.2em 0 0 0;
1.693 droeschl 7276: }
7277:
1.897 wenzelju 7278: ol.LC_primary_menu a {
1.911 bisitz 7279: color: RGB(80, 80, 80);
7280: text-decoration: none;
1.693 droeschl 7281: }
1.795 www 7282:
1.949 droeschl 7283: ol.LC_primary_menu a.LC_new_message {
7284: font-weight:bold;
7285: color: darkred;
7286: }
7287:
1.975 raeburn 7288: ol.LC_docs_parameters {
7289: margin-left: 0;
7290: padding: 0;
7291: list-style: none;
7292: }
7293:
7294: ol.LC_docs_parameters li {
7295: margin: 0;
7296: padding-right: 20px;
7297: display: inline;
7298: }
7299:
1.976 raeburn 7300: ol.LC_docs_parameters li:before {
7301: content: "\\002022 \\0020";
7302: }
7303:
7304: li.LC_docs_parameters_title {
7305: font-weight: bold;
7306: }
7307:
7308: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7309: content: "";
7310: }
7311:
1.897 wenzelju 7312: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7313: clear: right;
1.911 bisitz 7314: color: $fontmenu;
7315: background: $tabbg;
7316: list-style: none;
7317: padding: 0;
7318: margin: 0;
7319: width: 100%;
1.995 raeburn 7320: text-align: left;
1.1075.2.4 raeburn 7321: float: left;
1.808 droeschl 7322: }
7323:
1.897 wenzelju 7324: ul#LC_secondary_menu li {
1.911 bisitz 7325: font-weight: bold;
7326: line-height: 1.8em;
7327: border-right: 1px solid black;
1.1075.2.4 raeburn 7328: float: left;
7329: }
7330:
7331: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7332: background-color: $data_table_light;
7333: }
7334:
7335: ul#LC_secondary_menu li a {
7336: padding: 0 0.8em;
7337: }
7338:
7339: ul#LC_secondary_menu li ul {
7340: display: none;
7341: }
7342:
7343: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7344: display: block;
7345: position: absolute;
7346: margin: 0;
7347: padding: 0;
7348: list-style:none;
7349: float: none;
7350: background-color: $data_table_light;
1.1075.2.5 raeburn 7351: z-index: 2;
1.1075.2.10 raeburn 7352: margin-left: -1px;
1.1075.2.4 raeburn 7353: }
7354:
7355: ul#LC_secondary_menu li ul li {
7356: font-size: 90%;
7357: vertical-align: top;
7358: border-left: 1px solid black;
7359: border-right: 1px solid black;
1.1075.2.33 raeburn 7360: background-color: $data_table_light;
1.1075.2.4 raeburn 7361: list-style:none;
7362: float: none;
7363: }
7364:
7365: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7366: background-color: $data_table_dark;
1.807 droeschl 7367: }
7368:
1.847 tempelho 7369: ul.LC_TabContent {
1.911 bisitz 7370: display:block;
7371: background: $sidebg;
7372: border-bottom: solid 1px $lg_border_color;
7373: list-style:none;
1.1020 raeburn 7374: margin: -1px -10px 0 -10px;
1.911 bisitz 7375: padding: 0;
1.693 droeschl 7376: }
7377:
1.795 www 7378: ul.LC_TabContent li,
7379: ul.LC_TabContentBigger li {
1.911 bisitz 7380: float:left;
1.741 harmsja 7381: }
1.795 www 7382:
1.897 wenzelju 7383: ul#LC_secondary_menu li a {
1.911 bisitz 7384: color: $fontmenu;
7385: text-decoration: none;
1.693 droeschl 7386: }
1.795 www 7387:
1.721 harmsja 7388: ul.LC_TabContent {
1.952 onken 7389: min-height:20px;
1.721 harmsja 7390: }
1.795 www 7391:
7392: ul.LC_TabContent li {
1.911 bisitz 7393: vertical-align:middle;
1.959 onken 7394: padding: 0 16px 0 10px;
1.911 bisitz 7395: background-color:$tabbg;
7396: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7397: border-left: solid 1px $font;
1.721 harmsja 7398: }
1.795 www 7399:
1.847 tempelho 7400: ul.LC_TabContent .right {
1.911 bisitz 7401: float:right;
1.847 tempelho 7402: }
7403:
1.911 bisitz 7404: ul.LC_TabContent li a,
7405: ul.LC_TabContent li {
7406: color:rgb(47,47,47);
7407: text-decoration:none;
7408: font-size:95%;
7409: font-weight:bold;
1.952 onken 7410: min-height:20px;
7411: }
7412:
1.959 onken 7413: ul.LC_TabContent li a:hover,
7414: ul.LC_TabContent li a:focus {
1.952 onken 7415: color: $button_hover;
1.959 onken 7416: background:none;
7417: outline:none;
1.952 onken 7418: }
7419:
7420: ul.LC_TabContent li:hover {
7421: color: $button_hover;
7422: cursor:pointer;
1.721 harmsja 7423: }
1.795 www 7424:
1.911 bisitz 7425: ul.LC_TabContent li.active {
1.952 onken 7426: color: $font;
1.911 bisitz 7427: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7428: border-bottom:solid 1px #FFFFFF;
7429: cursor: default;
1.744 ehlerst 7430: }
1.795 www 7431:
1.959 onken 7432: ul.LC_TabContent li.active a {
7433: color:$font;
7434: background:#FFFFFF;
7435: outline: none;
7436: }
1.1047 raeburn 7437:
7438: ul.LC_TabContent li.goback {
7439: float: left;
7440: border-left: none;
7441: }
7442:
1.870 tempelho 7443: #maincoursedoc {
1.911 bisitz 7444: clear:both;
1.870 tempelho 7445: }
7446:
7447: ul.LC_TabContentBigger {
1.911 bisitz 7448: display:block;
7449: list-style:none;
7450: padding: 0;
1.870 tempelho 7451: }
7452:
1.795 www 7453: ul.LC_TabContentBigger li {
1.911 bisitz 7454: vertical-align:bottom;
7455: height: 30px;
7456: font-size:110%;
7457: font-weight:bold;
7458: color: #737373;
1.841 tempelho 7459: }
7460:
1.957 onken 7461: ul.LC_TabContentBigger li.active {
7462: position: relative;
7463: top: 1px;
7464: }
7465:
1.870 tempelho 7466: ul.LC_TabContentBigger li a {
1.911 bisitz 7467: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7468: height: 30px;
7469: line-height: 30px;
7470: text-align: center;
7471: display: block;
7472: text-decoration: none;
1.958 onken 7473: outline: none;
1.741 harmsja 7474: }
1.795 www 7475:
1.870 tempelho 7476: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7477: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7478: color:$font;
1.744 ehlerst 7479: }
1.795 www 7480:
1.870 tempelho 7481: ul.LC_TabContentBigger li b {
1.911 bisitz 7482: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7483: display: block;
7484: float: left;
7485: padding: 0 30px;
1.957 onken 7486: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7487: }
7488:
1.956 onken 7489: ul.LC_TabContentBigger li:hover b {
7490: color:$button_hover;
7491: }
7492:
1.870 tempelho 7493: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7494: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7495: color:$font;
1.957 onken 7496: border: 0;
1.741 harmsja 7497: }
1.693 droeschl 7498:
1.870 tempelho 7499:
1.862 bisitz 7500: ul.LC_CourseBreadcrumbs {
7501: background: $sidebg;
1.1020 raeburn 7502: height: 2em;
1.862 bisitz 7503: padding-left: 10px;
1.1020 raeburn 7504: margin: 0;
1.862 bisitz 7505: list-style-position: inside;
7506: }
7507:
1.911 bisitz 7508: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7509: ol#LC_PathBreadcrumbs {
1.911 bisitz 7510: padding-left: 10px;
7511: margin: 0;
1.933 droeschl 7512: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7513: }
7514:
1.911 bisitz 7515: ol#LC_MenuBreadcrumbs li,
7516: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7517: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7518: display: inline;
1.933 droeschl 7519: white-space: normal;
1.693 droeschl 7520: }
7521:
1.823 bisitz 7522: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7523: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7524: text-decoration: none;
7525: font-size:90%;
1.693 droeschl 7526: }
1.795 www 7527:
1.969 droeschl 7528: ol#LC_MenuBreadcrumbs h1 {
7529: display: inline;
7530: font-size: 90%;
7531: line-height: 2.5em;
7532: margin: 0;
7533: padding: 0;
7534: }
7535:
1.795 www 7536: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7537: text-decoration:none;
7538: font-size:100%;
7539: font-weight:bold;
1.693 droeschl 7540: }
1.795 www 7541:
1.840 bisitz 7542: .LC_Box {
1.911 bisitz 7543: border: solid 1px $lg_border_color;
7544: padding: 0 10px 10px 10px;
1.746 neumanie 7545: }
1.795 www 7546:
1.1020 raeburn 7547: .LC_DocsBox {
7548: border: solid 1px $lg_border_color;
7549: padding: 0 0 10px 10px;
7550: }
7551:
1.795 www 7552: .LC_AboutMe_Image {
1.911 bisitz 7553: float:left;
7554: margin-right:10px;
1.747 neumanie 7555: }
1.795 www 7556:
7557: .LC_Clear_AboutMe_Image {
1.911 bisitz 7558: clear:left;
1.747 neumanie 7559: }
1.795 www 7560:
1.721 harmsja 7561: dl.LC_ListStyleClean dt {
1.911 bisitz 7562: padding-right: 5px;
7563: display: table-header-group;
1.693 droeschl 7564: }
7565:
1.721 harmsja 7566: dl.LC_ListStyleClean dd {
1.911 bisitz 7567: display: table-row;
1.693 droeschl 7568: }
7569:
1.721 harmsja 7570: .LC_ListStyleClean,
7571: .LC_ListStyleSimple,
7572: .LC_ListStyleNormal,
1.795 www 7573: .LC_ListStyleSpecial {
1.911 bisitz 7574: /* display:block; */
7575: list-style-position: inside;
7576: list-style-type: none;
7577: overflow: hidden;
7578: padding: 0;
1.693 droeschl 7579: }
7580:
1.721 harmsja 7581: .LC_ListStyleSimple li,
7582: .LC_ListStyleSimple dd,
7583: .LC_ListStyleNormal li,
7584: .LC_ListStyleNormal dd,
7585: .LC_ListStyleSpecial li,
1.795 www 7586: .LC_ListStyleSpecial dd {
1.911 bisitz 7587: margin: 0;
7588: padding: 5px 5px 5px 10px;
7589: clear: both;
1.693 droeschl 7590: }
7591:
1.721 harmsja 7592: .LC_ListStyleClean li,
7593: .LC_ListStyleClean dd {
1.911 bisitz 7594: padding-top: 0;
7595: padding-bottom: 0;
1.693 droeschl 7596: }
7597:
1.721 harmsja 7598: .LC_ListStyleSimple dd,
1.795 www 7599: .LC_ListStyleSimple li {
1.911 bisitz 7600: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7601: }
7602:
1.721 harmsja 7603: .LC_ListStyleSpecial li,
7604: .LC_ListStyleSpecial dd {
1.911 bisitz 7605: list-style-type: none;
7606: background-color: RGB(220, 220, 220);
7607: margin-bottom: 4px;
1.693 droeschl 7608: }
7609:
1.721 harmsja 7610: table.LC_SimpleTable {
1.911 bisitz 7611: margin:5px;
7612: border:solid 1px $lg_border_color;
1.795 www 7613: }
1.693 droeschl 7614:
1.721 harmsja 7615: table.LC_SimpleTable tr {
1.911 bisitz 7616: padding: 0;
7617: border:solid 1px $lg_border_color;
1.693 droeschl 7618: }
1.795 www 7619:
7620: table.LC_SimpleTable thead {
1.911 bisitz 7621: background:rgb(220,220,220);
1.693 droeschl 7622: }
7623:
1.721 harmsja 7624: div.LC_columnSection {
1.911 bisitz 7625: display: block;
7626: clear: both;
7627: overflow: hidden;
7628: margin: 0;
1.693 droeschl 7629: }
7630:
1.721 harmsja 7631: div.LC_columnSection>* {
1.911 bisitz 7632: float: left;
7633: margin: 10px 20px 10px 0;
7634: overflow:hidden;
1.693 droeschl 7635: }
1.721 harmsja 7636:
1.795 www 7637: table em {
1.911 bisitz 7638: font-weight: bold;
7639: font-style: normal;
1.748 schulted 7640: }
1.795 www 7641:
1.779 bisitz 7642: table.LC_tableBrowseRes,
1.795 www 7643: table.LC_tableOfContent {
1.911 bisitz 7644: border:none;
7645: border-spacing: 1px;
7646: padding: 3px;
7647: background-color: #FFFFFF;
7648: font-size: 90%;
1.753 droeschl 7649: }
1.789 droeschl 7650:
1.911 bisitz 7651: table.LC_tableOfContent {
7652: border-collapse: collapse;
1.789 droeschl 7653: }
7654:
1.771 droeschl 7655: table.LC_tableBrowseRes a,
1.768 schulted 7656: table.LC_tableOfContent a {
1.911 bisitz 7657: background-color: transparent;
7658: text-decoration: none;
1.753 droeschl 7659: }
7660:
1.795 www 7661: table.LC_tableOfContent img {
1.911 bisitz 7662: border: none;
7663: height: 1.3em;
7664: vertical-align: text-bottom;
7665: margin-right: 0.3em;
1.753 droeschl 7666: }
1.757 schulted 7667:
1.795 www 7668: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7669: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7670: }
7671:
1.795 www 7672: a#LC_content_toolbar_everything {
1.911 bisitz 7673: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7674: }
7675:
1.795 www 7676: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7677: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7678: }
7679:
1.795 www 7680: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7681: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7682: }
7683:
1.795 www 7684: a#LC_content_toolbar_changefolder {
1.911 bisitz 7685: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7686: }
7687:
1.795 www 7688: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7689: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7690: }
7691:
1.1043 raeburn 7692: a#LC_content_toolbar_edittoplevel {
7693: background-image:url(/res/adm/pages/edittoplevel.gif);
7694: }
7695:
1.795 www 7696: ul#LC_toolbar li a:hover {
1.911 bisitz 7697: background-position: bottom center;
1.757 schulted 7698: }
7699:
1.795 www 7700: ul#LC_toolbar {
1.911 bisitz 7701: padding: 0;
7702: margin: 2px;
7703: list-style:none;
7704: position:relative;
7705: background-color:white;
1.1075.2.9 raeburn 7706: overflow: auto;
1.757 schulted 7707: }
7708:
1.795 www 7709: ul#LC_toolbar li {
1.911 bisitz 7710: border:1px solid white;
7711: padding: 0;
7712: margin: 0;
7713: float: left;
7714: display:inline;
7715: vertical-align:middle;
1.1075.2.9 raeburn 7716: white-space: nowrap;
1.911 bisitz 7717: }
1.757 schulted 7718:
1.783 amueller 7719:
1.795 www 7720: a.LC_toolbarItem {
1.911 bisitz 7721: display:block;
7722: padding: 0;
7723: margin: 0;
7724: height: 32px;
7725: width: 32px;
7726: color:white;
7727: border: none;
7728: background-repeat:no-repeat;
7729: background-color:transparent;
1.757 schulted 7730: }
7731:
1.915 droeschl 7732: ul.LC_funclist {
7733: margin: 0;
7734: padding: 0.5em 1em 0.5em 0;
7735: }
7736:
1.933 droeschl 7737: ul.LC_funclist > li:first-child {
7738: font-weight:bold;
7739: margin-left:0.8em;
7740: }
7741:
1.915 droeschl 7742: ul.LC_funclist + ul.LC_funclist {
7743: /*
7744: left border as a seperator if we have more than
7745: one list
7746: */
7747: border-left: 1px solid $sidebg;
7748: /*
7749: this hides the left border behind the border of the
7750: outer box if element is wrapped to the next 'line'
7751: */
7752: margin-left: -1px;
7753: }
7754:
1.843 bisitz 7755: ul.LC_funclist li {
1.915 droeschl 7756: display: inline;
1.782 bisitz 7757: white-space: nowrap;
1.915 droeschl 7758: margin: 0 0 0 25px;
7759: line-height: 150%;
1.782 bisitz 7760: }
7761:
1.974 wenzelju 7762: .LC_hidden {
7763: display: none;
7764: }
7765:
1.1030 www 7766: .LCmodal-overlay {
7767: position:fixed;
7768: top:0;
7769: right:0;
7770: bottom:0;
7771: left:0;
7772: height:100%;
7773: width:100%;
7774: margin:0;
7775: padding:0;
7776: background:#999;
7777: opacity:.75;
7778: filter: alpha(opacity=75);
7779: -moz-opacity: 0.75;
7780: z-index:101;
7781: }
7782:
7783: * html .LCmodal-overlay {
7784: position: absolute;
7785: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7786: }
7787:
7788: .LCmodal-window {
7789: position:fixed;
7790: top:50%;
7791: left:50%;
7792: margin:0;
7793: padding:0;
7794: z-index:102;
7795: }
7796:
7797: * html .LCmodal-window {
7798: position:absolute;
7799: }
7800:
7801: .LCclose-window {
7802: position:absolute;
7803: width:32px;
7804: height:32px;
7805: right:8px;
7806: top:8px;
7807: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7808: text-indent:-99999px;
7809: overflow:hidden;
7810: cursor:pointer;
7811: }
7812:
1.1075.2.141 raeburn 7813: pre.LC_wordwrap {
7814: white-space: pre-wrap;
7815: white-space: -moz-pre-wrap;
7816: white-space: -pre-wrap;
7817: white-space: -o-pre-wrap;
7818: word-wrap: break-word;
7819: }
7820:
1.1075.2.17 raeburn 7821: /*
7822: styles used by TTH when "Default set of options to pass to tth/m
7823: when converting TeX" in course settings has been set
7824:
7825: option passed: -t
7826:
7827: */
7828:
7829: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7830: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7831: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7832: td div.norm {line-height:normal;}
7833:
7834: /*
7835: option passed -y3
7836: */
7837:
7838: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7839: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7840: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7841:
1.1075.2.121 raeburn 7842: #LC_minitab_header {
7843: float:left;
7844: width:100%;
7845: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
7846: font-size:93%;
7847: line-height:normal;
7848: margin: 0.5em 0 0.5em 0;
7849: }
7850: #LC_minitab_header ul {
7851: margin:0;
7852: padding:10px 10px 0;
7853: list-style:none;
7854: }
7855: #LC_minitab_header li {
7856: float:left;
7857: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
7858: margin:0;
7859: padding:0 0 0 9px;
7860: }
7861: #LC_minitab_header a {
7862: display:block;
7863: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
7864: padding:5px 15px 4px 6px;
7865: }
7866: #LC_minitab_header #LC_current_minitab {
7867: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
7868: }
7869: #LC_minitab_header #LC_current_minitab a {
7870: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
7871: padding-bottom:5px;
7872: }
7873:
7874:
1.343 albertel 7875: END
7876: }
7877:
1.306 albertel 7878: =pod
7879:
7880: =item * &headtag()
7881:
7882: Returns a uniform footer for LON-CAPA web pages.
7883:
1.307 albertel 7884: Inputs: $title - optional title for the head
7885: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7886: $args - optional arguments
1.319 albertel 7887: force_register - if is true call registerurl so the remote is
7888: informed
1.415 albertel 7889: redirect -> array ref of
7890: 1- seconds before redirect occurs
7891: 2- url to redirect to
7892: 3- whether the side effect should occur
1.315 albertel 7893: (side effect of setting
7894: $env{'internal.head.redirect'} to the url
7895: redirected too)
1.352 albertel 7896: domain -> force to color decorate a page for a specific
7897: domain
7898: function -> force usage of a specific rolish color scheme
7899: bgcolor -> override the default page bgcolor
1.460 albertel 7900: no_auto_mt_title
7901: -> prevent &mt()ing the title arg
1.464 albertel 7902:
1.306 albertel 7903: =cut
7904:
7905: sub headtag {
1.313 albertel 7906: my ($title,$head_extra,$args) = @_;
1.306 albertel 7907:
1.363 albertel 7908: my $function = $args->{'function'} || &get_users_function();
7909: my $domain = $args->{'domain'} || &determinedomain();
7910: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7911: my $httphost = $args->{'use_absolute'};
1.418 albertel 7912: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7913: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7914: #time(),
1.418 albertel 7915: $env{'environment.color.timestamp'},
1.363 albertel 7916: $function,$domain,$bgcolor);
7917:
1.369 www 7918: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7919:
1.308 albertel 7920: my $result =
7921: '<head>'.
1.1075.2.56 raeburn 7922: &font_settings($args);
1.319 albertel 7923:
1.1075.2.72 raeburn 7924: my $inhibitprint;
7925: if ($args->{'print_suppress'}) {
7926: $inhibitprint = &print_suppression();
7927: }
1.1064 raeburn 7928:
1.461 albertel 7929: if (!$args->{'frameset'}) {
7930: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7931: }
1.1075.2.12 raeburn 7932: if ($args->{'force_register'}) {
7933: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7934: }
1.436 albertel 7935: if (!$args->{'no_nav_bar'}
7936: && !$args->{'only_body'}
7937: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7938: $result .= &help_menu_js($httphost);
1.1032 www 7939: $result.=&modal_window();
1.1038 www 7940: $result.=&togglebox_script();
1.1034 www 7941: $result.=&wishlist_window();
1.1041 www 7942: $result.=&LCprogressbarUpdate_script();
1.1034 www 7943: } else {
7944: if ($args->{'add_modal'}) {
7945: $result.=&modal_window();
7946: }
7947: if ($args->{'add_wishlist'}) {
7948: $result.=&wishlist_window();
7949: }
1.1038 www 7950: if ($args->{'add_togglebox'}) {
7951: $result.=&togglebox_script();
7952: }
1.1041 www 7953: if ($args->{'add_progressbar'}) {
7954: $result.=&LCprogressbarUpdate_script();
7955: }
1.436 albertel 7956: }
1.314 albertel 7957: if (ref($args->{'redirect'})) {
1.414 albertel 7958: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7959: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7960: if (!$inhibit_continue) {
7961: $env{'internal.head.redirect'} = $url;
7962: }
1.313 albertel 7963: $result.=<<ADDMETA
7964: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7965: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7966: ADDMETA
1.1075.2.89 raeburn 7967: } else {
7968: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
7969: my $requrl = $env{'request.uri'};
7970: if ($requrl eq '') {
7971: $requrl = $ENV{'REQUEST_URI'};
7972: $requrl =~ s/\?.+$//;
7973: }
7974: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
7975: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
7976: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
7977: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
7978: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
7979: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1075.2.141. .4(raebu 7980:20): my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7981:20): my $offload;
1.1075.2.89 raeburn 7982: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
7983: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1075.2.141. .4(raebu 7984:20): $offload = 1;
7985:20): }
7986:20): }
7987:20): unless ($offload) {
7988:20): if (ref($domdefs{'offloadoth'}) eq 'HASH') {
7989:20): if ($domdefs{'offloadoth'}{$lonhost}) {
7990:20): if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
7991:20): (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
7992:20): unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
7993:20): $offload = 1;
7994:20): $dom_in_use = $env{'user.domain'};
7995:20): }
1.1075.2.89 raeburn 7996: }
1.1075.2.141. .4(raebu 7997:20): }
7998:20): }
7999:20): }
8000:20): if ($offload) {
8001:20): my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
8002:20): if (($newserver) && ($newserver ne $lonhost)) {
8003:20): my $numsec = 5;
8004:20): my $timeout = $numsec * 1000;
8005:20): my ($newurl,$locknum,%locks,$msg);
8006:20): if ($env{'request.role.adv'}) {
8007:20): ($locknum,%locks) = &Apache::lonnet::get_locks();
8008:20): }
8009:20): my $disable_submit = 0;
8010:20): if ($requrl =~ /$LONCAPA::assess_re/) {
8011:20): $disable_submit = 1;
8012:20): }
8013:20): if ($locknum) {
8014:20): my @lockinfo = sort(values(%locks));
8015:20): $msg = &mt('Once the following tasks are complete: ')."\n".
8016:20): join(", ",sort(values(%locks)))."\n";
8017:20): if (&show_course()) {
8018:20): $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
1.1075.2.89 raeburn 8019: } else {
1.1075.2.141. .4(raebu 8020:20): $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
8021:20): }
8022:20): } else {
8023:20): if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8024:20): $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8025:20): }
8026:20): $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8027:20): $newurl = '/adm/switchserver?otherserver='.$newserver;
8028:20): if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8029:20): $newurl .= '&role='.$env{'request.role'};
8030:20): }
8031:20): if ($env{'request.symb'}) {
8032:20): my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8033:20): if ($shownsymb =~ m{^/enc/}) {
8034:20): my $reqdmajor = 2;
8035:20): my $reqdminor = 11;
8036:20): my $reqdsubminor = 3;
8037:20): my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8038:20): my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8039:20): my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8040:20): if (($major eq '' && $minor eq '') ||
8041:20): (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8042:20): (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8043:20): ($reqdsubminor > $subminor))))) {
8044:20): undef($shownsymb);
8045:20): }
1.1075.2.89 raeburn 8046: }
1.1075.2.141. .4(raebu 8047:20): if ($shownsymb) {
8048:20): &js_escape(\$shownsymb);
8049:20): $newurl .= '&symb='.$shownsymb;
1.1075.2.89 raeburn 8050: }
1.1075.2.141. .4(raebu 8051:20): } else {
8052:20): my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8053:20): &js_escape(\$shownurl);
8054:20): $newurl .= '&origurl='.$shownurl;
1.1075.2.89 raeburn 8055: }
1.1075.2.141. .4(raebu 8056:20): }
8057:20): &js_escape(\$msg);
8058:20): $result.=<<OFFLOAD
1.1075.2.89 raeburn 8059: <meta http-equiv="pragma" content="no-cache" />
8060: <script type="text/javascript">
1.1075.2.92 raeburn 8061: // <![CDATA[
1.1075.2.89 raeburn 8062: function LC_Offload_Now() {
8063: var dest = "$newurl";
8064: if (dest != '') {
8065: window.location.href="$newurl";
8066: }
8067: }
1.1075.2.92 raeburn 8068: \$(document).ready(function () {
8069: window.alert('$msg');
8070: if ($disable_submit) {
1.1075.2.89 raeburn 8071: \$(".LC_hwk_submit").prop("disabled", true);
8072: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 8073: }
8074: setTimeout('LC_Offload_Now()', $timeout);
8075: });
8076: // ]]>
1.1075.2.89 raeburn 8077: </script>
8078: OFFLOAD
8079: }
8080: }
8081: }
8082: }
8083: }
1.313 albertel 8084: }
1.306 albertel 8085: if (!defined($title)) {
8086: $title = 'The LearningOnline Network with CAPA';
8087: }
1.460 albertel 8088: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8089: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 8090: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8091: if (!$args->{'frameset'}) {
8092: $result .= ' /';
8093: }
8094: $result .= '>'
1.1064 raeburn 8095: .$inhibitprint
1.414 albertel 8096: .$head_extra;
1.1075.2.108 raeburn 8097: my $clientmobile;
8098: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8099: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8100: } else {
8101: $clientmobile = $env{'browser.mobile'};
8102: }
8103: if ($clientmobile) {
1.1075.2.42 raeburn 8104: $result .= '
8105: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8106: <meta name="apple-mobile-web-app-capable" content="yes" />';
8107: }
1.1075.2.126 raeburn 8108: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8109: return $result.'</head>';
1.306 albertel 8110: }
8111:
8112: =pod
8113:
1.340 albertel 8114: =item * &font_settings()
8115:
8116: Returns neccessary <meta> to set the proper encoding
8117:
1.1075.2.56 raeburn 8118: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8119:
8120: =cut
8121:
8122: sub font_settings {
1.1075.2.56 raeburn 8123: my ($args) = @_;
1.340 albertel 8124: my $headerstring='';
1.1075.2.56 raeburn 8125: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8126: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 8127: $headerstring.=
1.1075.2.61 raeburn 8128: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8129: if (!$args->{'frameset'}) {
8130: $headerstring.= ' /';
8131: }
8132: $headerstring .= '>'."\n";
1.340 albertel 8133: }
8134: return $headerstring;
8135: }
8136:
1.341 albertel 8137: =pod
8138:
1.1064 raeburn 8139: =item * &print_suppression()
8140:
8141: In course context returns css which causes the body to be blank when media="print",
8142: if printout generation is unavailable for the current resource.
8143:
8144: This could be because:
8145:
8146: (a) printstartdate is in the future
8147:
8148: (b) printenddate is in the past
8149:
8150: (c) there is an active exam block with "printout"
8151: functionality blocked
8152:
8153: Users with pav, pfo or evb privileges are exempt.
8154:
8155: Inputs: none
8156:
8157: =cut
8158:
8159:
8160: sub print_suppression {
8161: my $noprint;
8162: if ($env{'request.course.id'}) {
8163: my $scope = $env{'request.course.id'};
8164: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8165: (&Apache::lonnet::allowed('pfo',$scope))) {
8166: return;
8167: }
8168: if ($env{'request.course.sec'} ne '') {
8169: $scope .= "/$env{'request.course.sec'}";
8170: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8171: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8172: return;
1.1064 raeburn 8173: }
8174: }
8175: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8176: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.73 raeburn 8177: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8178: if ($blocked) {
8179: my $checkrole = "cm./$cdom/$cnum";
8180: if ($env{'request.course.sec'} ne '') {
8181: $checkrole .= "/$env{'request.course.sec'}";
8182: }
8183: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8184: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8185: $noprint = 1;
8186: }
8187: }
8188: unless ($noprint) {
8189: my $symb = &Apache::lonnet::symbread();
8190: if ($symb ne '') {
8191: my $navmap = Apache::lonnavmaps::navmap->new();
8192: if (ref($navmap)) {
8193: my $res = $navmap->getBySymb($symb);
8194: if (ref($res)) {
8195: if (!$res->resprintable()) {
8196: $noprint = 1;
8197: }
8198: }
8199: }
8200: }
8201: }
8202: if ($noprint) {
8203: return <<"ENDSTYLE";
8204: <style type="text/css" media="print">
8205: body { display:none }
8206: </style>
8207: ENDSTYLE
8208: }
8209: }
8210: return;
8211: }
8212:
8213: =pod
8214:
1.341 albertel 8215: =item * &xml_begin()
8216:
8217: Returns the needed doctype and <html>
8218:
8219: Inputs: none
8220:
8221: =cut
8222:
8223: sub xml_begin {
1.1075.2.61 raeburn 8224: my ($is_frameset) = @_;
1.341 albertel 8225: my $output='';
8226:
8227: if ($env{'browser.mathml'}) {
8228: $output='<?xml version="1.0"?>'
8229: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8230: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8231:
8232: # .'<!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">] >'
8233: .'<!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">'
8234: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8235: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8236: } elsif ($is_frameset) {
8237: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8238: '<html>'."\n";
1.341 albertel 8239: } else {
1.1075.2.61 raeburn 8240: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8241: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8242: }
8243: return $output;
8244: }
1.340 albertel 8245:
8246: =pod
8247:
1.306 albertel 8248: =item * &start_page()
8249:
8250: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8251:
1.648 raeburn 8252: Inputs:
8253:
8254: =over 4
8255:
8256: $title - optional title for the page
8257:
8258: $head_extra - optional extra HTML to incude inside the <head>
8259:
8260: $args - additional optional args supported are:
8261:
8262: =over 8
8263:
8264: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8265: arg on
1.814 bisitz 8266: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8267: add_entries -> additional attributes to add to the <body>
8268: domain -> force to color decorate a page for a
1.317 albertel 8269: specific domain
1.648 raeburn 8270: function -> force usage of a specific rolish color
1.317 albertel 8271: scheme
1.648 raeburn 8272: redirect -> see &headtag()
8273: bgcolor -> override the default page bg color
8274: js_ready -> return a string ready for being used in
1.317 albertel 8275: a javascript writeln
1.648 raeburn 8276: html_encode -> return a string ready for being used in
1.320 albertel 8277: a html attribute
1.648 raeburn 8278: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8279: $forcereg arg
1.648 raeburn 8280: frameset -> if true will start with a <frameset>
1.330 albertel 8281: rather than <body>
1.648 raeburn 8282: skip_phases -> hash ref of
1.338 albertel 8283: head -> skip the <html><head> generation
8284: body -> skip all <body> generation
1.1075.2.12 raeburn 8285: no_inline_link -> if true and in remote mode, don't show the
8286: 'Switch To Inline Menu' link
1.648 raeburn 8287: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8288: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8289: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 8290: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8291: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8292: group -> includes the current group, if page is for a
8293: specific group
1.1075.2.133 raeburn 8294: use_absolute -> for request for external resource or syllabus, this
8295: will contain https://<hostname> if server uses
8296: https (as per hosts.tab), but request is for http
8297: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8298:
1.648 raeburn 8299: =back
1.460 albertel 8300:
1.648 raeburn 8301: =back
1.562 albertel 8302:
1.306 albertel 8303: =cut
8304:
8305: sub start_page {
1.309 albertel 8306: my ($title,$head_extra,$args) = @_;
1.318 albertel 8307: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8308:
1.315 albertel 8309: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 8310: my ($result,@advtools);
1.964 droeschl 8311:
1.338 albertel 8312: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8313: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8314: }
8315:
8316: if (! exists($args->{'skip_phases'}{'body'}) ) {
8317: if ($args->{'frameset'}) {
8318: my $attr_string = &make_attr_string($args->{'force_register'},
8319: $args->{'add_entries'});
8320: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8321: } else {
8322: $result .=
8323: &bodytag($title,
8324: $args->{'function'}, $args->{'add_entries'},
8325: $args->{'only_body'}, $args->{'domain'},
8326: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 8327: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 8328: $args, \@advtools);
1.831 bisitz 8329: }
1.330 albertel 8330: }
1.338 albertel 8331:
1.315 albertel 8332: if ($args->{'js_ready'}) {
1.713 kaisler 8333: $result = &js_ready($result);
1.315 albertel 8334: }
1.320 albertel 8335: if ($args->{'html_encode'}) {
1.713 kaisler 8336: $result = &html_encode($result);
8337: }
8338:
1.813 bisitz 8339: # Preparation for new and consistent functionlist at top of screen
8340: # if ($args->{'functionlist'}) {
8341: # $result .= &build_functionlist();
8342: #}
8343:
1.964 droeschl 8344: # Don't add anything more if only_body wanted or in const space
8345: return $result if $args->{'only_body'}
8346: || $env{'request.state'} eq 'construct';
1.813 bisitz 8347:
8348: #Breadcrumbs
1.758 kaisler 8349: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8350: &Apache::lonhtmlcommon::clear_breadcrumbs();
8351: #if any br links exists, add them to the breadcrumbs
8352: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8353: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8354: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8355: }
8356: }
1.1075.2.19 raeburn 8357: # if @advtools array contains items add then to the breadcrumbs
8358: if (@advtools > 0) {
8359: &Apache::lonmenu::advtools_crumbs(@advtools);
8360: }
1.1075.2.123 raeburn 8361: my $menulink;
8362: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8363: if (exists($args->{'bread_crumbs_nomenu'})) {
8364: $menulink = 0;
8365: } else {
8366: undef($menulink);
8367: }
1.758 kaisler 8368: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8369: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 8370: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.758 kaisler 8371: }else{
1.1075.2.123 raeburn 8372: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8373: }
1.1075.2.24 raeburn 8374: } elsif (($env{'environment.remote'} eq 'on') &&
8375: ($env{'form.inhibitmenu'} ne 'yes') &&
8376: ($env{'request.noversionuri'} =~ m{^/res/}) &&
8377: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 8378: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 8379: }
1.315 albertel 8380: return $result;
1.306 albertel 8381: }
8382:
8383: sub end_page {
1.315 albertel 8384: my ($args) = @_;
8385: $env{'internal.end_page'}++;
1.330 albertel 8386: my $result;
1.335 albertel 8387: if ($args->{'discussion'}) {
8388: my ($target,$parser);
8389: if (ref($args->{'discussion'})) {
8390: ($target,$parser) =($args->{'discussion'}{'target'},
8391: $args->{'discussion'}{'parser'});
8392: }
8393: $result .= &Apache::lonxml::xmlend($target,$parser);
8394: }
1.330 albertel 8395: if ($args->{'frameset'}) {
8396: $result .= '</frameset>';
8397: } else {
1.635 raeburn 8398: $result .= &endbodytag($args);
1.330 albertel 8399: }
1.1075.2.6 raeburn 8400: unless ($args->{'notbody'}) {
8401: $result .= "\n</html>";
8402: }
1.330 albertel 8403:
1.315 albertel 8404: if ($args->{'js_ready'}) {
1.317 albertel 8405: $result = &js_ready($result);
1.315 albertel 8406: }
1.335 albertel 8407:
1.320 albertel 8408: if ($args->{'html_encode'}) {
8409: $result = &html_encode($result);
8410: }
1.335 albertel 8411:
1.315 albertel 8412: return $result;
8413: }
8414:
1.1034 www 8415: sub wishlist_window {
8416: return(<<'ENDWISHLIST');
1.1046 raeburn 8417: <script type="text/javascript">
1.1034 www 8418: // <![CDATA[
8419: // <!-- BEGIN LON-CAPA Internal
8420: function set_wishlistlink(title, path) {
8421: if (!title) {
8422: title = document.title;
8423: title = title.replace(/^LON-CAPA /,'');
8424: }
1.1075.2.65 raeburn 8425: title = encodeURIComponent(title);
1.1075.2.83 raeburn 8426: title = title.replace("'","\\\'");
1.1034 www 8427: if (!path) {
8428: path = location.pathname;
8429: }
1.1075.2.65 raeburn 8430: path = encodeURIComponent(path);
1.1075.2.83 raeburn 8431: path = path.replace("'","\\\'");
1.1034 www 8432: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8433: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8434: }
8435: // END LON-CAPA Internal -->
8436: // ]]>
8437: </script>
8438: ENDWISHLIST
8439: }
8440:
1.1030 www 8441: sub modal_window {
8442: return(<<'ENDMODAL');
1.1046 raeburn 8443: <script type="text/javascript">
1.1030 www 8444: // <![CDATA[
8445: // <!-- BEGIN LON-CAPA Internal
8446: var modalWindow = {
8447: parent:"body",
8448: windowId:null,
8449: content:null,
8450: width:null,
8451: height:null,
8452: close:function()
8453: {
8454: $(".LCmodal-window").remove();
8455: $(".LCmodal-overlay").remove();
8456: },
8457: open:function()
8458: {
8459: var modal = "";
8460: modal += "<div class=\"LCmodal-overlay\"></div>";
8461: 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;\">";
8462: modal += this.content;
8463: modal += "</div>";
8464:
8465: $(this.parent).append(modal);
8466:
8467: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8468: $(".LCclose-window").click(function(){modalWindow.close();});
8469: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8470: }
8471: };
1.1075.2.42 raeburn 8472: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8473: {
1.1075.2.119 raeburn 8474: source = source.replace(/'/g,"'");
1.1030 www 8475: modalWindow.windowId = "myModal";
8476: modalWindow.width = width;
8477: modalWindow.height = height;
1.1075.2.80 raeburn 8478: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8479: modalWindow.open();
1.1075.2.87 raeburn 8480: };
1.1030 www 8481: // END LON-CAPA Internal -->
8482: // ]]>
8483: </script>
8484: ENDMODAL
8485: }
8486:
8487: sub modal_link {
1.1075.2.42 raeburn 8488: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8489: unless ($width) { $width=480; }
8490: unless ($height) { $height=400; }
1.1031 www 8491: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 8492: unless ($transparency) { $transparency='true'; }
8493:
1.1074 raeburn 8494: my $target_attr;
8495: if (defined($target)) {
8496: $target_attr = 'target="'.$target.'"';
8497: }
8498: return <<"ENDLINK";
1.1075.2.141. .3(raebu 8499:20): <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 8500: ENDLINK
1.1030 www 8501: }
8502:
1.1032 www 8503: sub modal_adhoc_script {
8504: my ($funcname,$width,$height,$content)=@_;
8505: return (<<ENDADHOC);
1.1046 raeburn 8506: <script type="text/javascript">
1.1032 www 8507: // <![CDATA[
8508: var $funcname = function()
8509: {
8510: modalWindow.windowId = "myModal";
8511: modalWindow.width = $width;
8512: modalWindow.height = $height;
8513: modalWindow.content = '$content';
8514: modalWindow.open();
8515: };
8516: // ]]>
8517: </script>
8518: ENDADHOC
8519: }
8520:
1.1041 www 8521: sub modal_adhoc_inner {
8522: my ($funcname,$width,$height,$content)=@_;
8523: my $innerwidth=$width-20;
8524: $content=&js_ready(
1.1042 www 8525: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 8526: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8527: $content.
1.1041 www 8528: &end_scrollbox().
1.1075.2.42 raeburn 8529: &end_page()
1.1041 www 8530: );
8531: return &modal_adhoc_script($funcname,$width,$height,$content);
8532: }
8533:
8534: sub modal_adhoc_window {
8535: my ($funcname,$width,$height,$content,$linktext)=@_;
8536: return &modal_adhoc_inner($funcname,$width,$height,$content).
8537: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8538: }
8539:
8540: sub modal_adhoc_launch {
8541: my ($funcname,$width,$height,$content)=@_;
8542: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8543: <script type="text/javascript">
8544: // <![CDATA[
8545: $funcname();
8546: // ]]>
8547: </script>
8548: ENDLAUNCH
8549: }
8550:
8551: sub modal_adhoc_close {
8552: return (<<ENDCLOSE);
8553: <script type="text/javascript">
8554: // <![CDATA[
8555: modalWindow.close();
8556: // ]]>
8557: </script>
8558: ENDCLOSE
8559: }
8560:
1.1038 www 8561: sub togglebox_script {
8562: return(<<ENDTOGGLE);
8563: <script type="text/javascript">
8564: // <![CDATA[
8565: function LCtoggleDisplay(id,hidetext,showtext) {
8566: link = document.getElementById(id + "link").childNodes[0];
8567: with (document.getElementById(id).style) {
8568: if (display == "none" ) {
8569: display = "inline";
8570: link.nodeValue = hidetext;
8571: } else {
8572: display = "none";
8573: link.nodeValue = showtext;
8574: }
8575: }
8576: }
8577: // ]]>
8578: </script>
8579: ENDTOGGLE
8580: }
8581:
1.1039 www 8582: sub start_togglebox {
8583: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8584: unless ($heading) { $heading=''; } else { $heading.=' '; }
8585: unless ($showtext) { $showtext=&mt('show'); }
8586: unless ($hidetext) { $hidetext=&mt('hide'); }
8587: unless ($headerbg) { $headerbg='#FFFFFF'; }
8588: return &start_data_table().
8589: &start_data_table_header_row().
8590: '<td bgcolor="'.$headerbg.'">'.$heading.
8591: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8592: $showtext.'\')">'.$showtext.'</a>]</td>'.
8593: &end_data_table_header_row().
8594: '<tr id="'.$id.'" style="display:none""><td>';
8595: }
8596:
8597: sub end_togglebox {
8598: return '</td></tr>'.&end_data_table();
8599: }
8600:
1.1041 www 8601: sub LCprogressbar_script {
1.1075.2.130 raeburn 8602: my ($id,$number_to_do)=@_;
8603: if ($number_to_do) {
8604: return(<<ENDPROGRESS);
1.1041 www 8605: <script type="text/javascript">
8606: // <![CDATA[
1.1045 www 8607: \$('#progressbar$id').progressbar({
1.1041 www 8608: value: 0,
8609: change: function(event, ui) {
8610: var newVal = \$(this).progressbar('option', 'value');
8611: \$('.pblabel', this).text(LCprogressTxt);
8612: }
8613: });
8614: // ]]>
8615: </script>
8616: ENDPROGRESS
1.1075.2.130 raeburn 8617: } else {
8618: return(<<ENDPROGRESS);
8619: <script type="text/javascript">
8620: // <![CDATA[
8621: \$('#progressbar$id').progressbar({
8622: value: false,
8623: create: function(event, ui) {
8624: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
8625: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
8626: }
8627: });
8628: // ]]>
8629: </script>
8630: ENDPROGRESS
8631: }
1.1041 www 8632: }
8633:
8634: sub LCprogressbarUpdate_script {
8635: return(<<ENDPROGRESSUPDATE);
8636: <style type="text/css">
8637: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 8638: .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 8639: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8640: </style>
8641: <script type="text/javascript">
8642: // <![CDATA[
1.1045 www 8643: var LCprogressTxt='---';
8644:
1.1075.2.130 raeburn 8645: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 8646: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 8647: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
8648: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
8649: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
8650: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
8651: } else {
8652: \$('#progressbar'+id).progressbar('value',percent);
8653: }
1.1041 www 8654: }
8655: // ]]>
8656: </script>
8657: ENDPROGRESSUPDATE
8658: }
8659:
1.1042 www 8660: my $LClastpercent;
1.1045 www 8661: my $LCidcnt;
8662: my $LCcurrentid;
1.1042 www 8663:
1.1041 www 8664: sub LCprogressbar {
1.1075.2.130 raeburn 8665: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 8666: $LClastpercent=0;
1.1045 www 8667: $LCidcnt++;
8668: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 8669: my ($starting,$content);
8670: if ($number_to_do) {
8671: $starting=&mt('Starting');
8672: $content=(<<ENDPROGBAR);
8673: $preamble
1.1045 www 8674: <div id="progressbar$LCcurrentid">
1.1041 www 8675: <span class="pblabel">$starting</span>
8676: </div>
8677: ENDPROGBAR
1.1075.2.130 raeburn 8678: } else {
8679: $starting=&mt('Loading...');
8680: $LClastpercent='false';
8681: $content=(<<ENDPROGBAR);
8682: $preamble
8683: <div id="progressbar$LCcurrentid">
8684: <div class="progress-label">$starting</div>
8685: </div>
8686: ENDPROGBAR
8687: }
8688: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 8689: }
8690:
8691: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 8692: my ($r,$val,$text,$number_to_do)=@_;
8693: if ($number_to_do) {
8694: unless ($val) {
8695: if ($LClastpercent) {
8696: $val=$LClastpercent;
8697: } else {
8698: $val=0;
8699: }
8700: }
8701: if ($val<0) { $val=0; }
8702: if ($val>100) { $val=0; }
8703: $LClastpercent=$val;
8704: unless ($text) { $text=$val.'%'; }
8705: } else {
8706: $val = 'false';
1.1042 www 8707: }
1.1041 www 8708: $text=&js_ready($text);
1.1044 www 8709: &r_print($r,<<ENDUPDATE);
1.1041 www 8710: <script type="text/javascript">
8711: // <![CDATA[
1.1075.2.130 raeburn 8712: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 8713: // ]]>
8714: </script>
8715: ENDUPDATE
1.1035 www 8716: }
8717:
1.1042 www 8718: sub LCprogressbarClose {
8719: my ($r)=@_;
8720: $LClastpercent=0;
1.1044 www 8721: &r_print($r,<<ENDCLOSE);
1.1042 www 8722: <script type="text/javascript">
8723: // <![CDATA[
1.1045 www 8724: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8725: // ]]>
8726: </script>
8727: ENDCLOSE
1.1044 www 8728: }
8729:
8730: sub r_print {
8731: my ($r,$to_print)=@_;
8732: if ($r) {
8733: $r->print($to_print);
8734: $r->rflush();
8735: } else {
8736: print($to_print);
8737: }
1.1042 www 8738: }
8739:
1.320 albertel 8740: sub html_encode {
8741: my ($result) = @_;
8742:
1.322 albertel 8743: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8744:
8745: return $result;
8746: }
1.1044 www 8747:
1.317 albertel 8748: sub js_ready {
8749: my ($result) = @_;
8750:
1.323 albertel 8751: $result =~ s/[\n\r]/ /xmsg;
8752: $result =~ s/\\/\\\\/xmsg;
8753: $result =~ s/'/\\'/xmsg;
1.372 albertel 8754: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8755:
8756: return $result;
8757: }
8758:
1.315 albertel 8759: sub validate_page {
8760: if ( exists($env{'internal.start_page'})
1.316 albertel 8761: && $env{'internal.start_page'} > 1) {
8762: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8763: $env{'internal.start_page'}.' '.
1.316 albertel 8764: $ENV{'request.filename'});
1.315 albertel 8765: }
8766: if ( exists($env{'internal.end_page'})
1.316 albertel 8767: && $env{'internal.end_page'} > 1) {
8768: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8769: $env{'internal.end_page'}.' '.
1.316 albertel 8770: $env{'request.filename'});
1.315 albertel 8771: }
8772: if ( exists($env{'internal.start_page'})
8773: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8774: &Apache::lonnet::logthis('start_page called without end_page '.
8775: $env{'request.filename'});
1.315 albertel 8776: }
8777: if ( ! exists($env{'internal.start_page'})
8778: && exists($env{'internal.end_page'})) {
1.316 albertel 8779: &Apache::lonnet::logthis('end_page called without start_page'.
8780: $env{'request.filename'});
1.315 albertel 8781: }
1.306 albertel 8782: }
1.315 albertel 8783:
1.996 www 8784:
8785: sub start_scrollbox {
1.1075.2.56 raeburn 8786: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8787: unless ($outerwidth) { $outerwidth='520px'; }
8788: unless ($width) { $width='500px'; }
8789: unless ($height) { $height='200px'; }
1.1075 raeburn 8790: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8791: if ($id ne '') {
1.1075.2.42 raeburn 8792: $table_id = ' id="table_'.$id.'"';
8793: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8794: }
1.1075 raeburn 8795: if ($bgcolor ne '') {
8796: $tdcol = "background-color: $bgcolor;";
8797: }
1.1075.2.42 raeburn 8798: my $nicescroll_js;
8799: if ($env{'browser.mobile'}) {
8800: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8801: }
1.1075 raeburn 8802: return <<"END";
1.1075.2.42 raeburn 8803: $nicescroll_js
8804:
8805: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8806: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8807: END
1.996 www 8808: }
8809:
8810: sub end_scrollbox {
1.1036 www 8811: return '</div></td></tr></table>';
1.996 www 8812: }
8813:
1.1075.2.42 raeburn 8814: sub nicescroll_javascript {
8815: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8816: my %options;
8817: if (ref($cursor) eq 'HASH') {
8818: %options = %{$cursor};
8819: }
8820: unless ($options{'railalign'} =~ /^left|right$/) {
8821: $options{'railalign'} = 'left';
8822: }
8823: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8824: my $function = &get_users_function();
8825: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8826: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8827: $options{'cursorcolor'} = '#00F';
8828: }
8829: }
8830: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8831: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8832: $options{'cursoropacity'}='1.0';
8833: }
8834: } else {
8835: $options{'cursoropacity'}='1.0';
8836: }
8837: if ($options{'cursorfixedheight'} eq 'none') {
8838: delete($options{'cursorfixedheight'});
8839: } else {
8840: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8841: }
8842: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8843: delete($options{'railoffset'});
8844: }
8845: my @niceoptions;
8846: while (my($key,$value) = each(%options)) {
8847: if ($value =~ /^\{.+\}$/) {
8848: push(@niceoptions,$key.':'.$value);
8849: } else {
8850: push(@niceoptions,$key.':"'.$value.'"');
8851: }
8852: }
8853: my $nicescroll_js = '
8854: $(document).ready(
8855: function() {
8856: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8857: }
8858: );
8859: ';
8860: if ($framecheck) {
8861: $nicescroll_js .= '
8862: function expand_div(caller) {
8863: if (top === self) {
8864: document.getElementById("'.$id.'").style.width = "auto";
8865: document.getElementById("'.$id.'").style.height = "auto";
8866: } else {
8867: try {
8868: if (parent.frames) {
8869: if (parent.frames.length > 1) {
8870: var framesrc = parent.frames[1].location.href;
8871: var currsrc = framesrc.replace(/\#.*$/,"");
8872: if ((caller == "search") || (currsrc == "'.$location.'")) {
8873: document.getElementById("'.$id.'").style.width = "auto";
8874: document.getElementById("'.$id.'").style.height = "auto";
8875: }
8876: }
8877: }
8878: } catch (e) {
8879: return;
8880: }
8881: }
8882: return;
8883: }
8884: ';
8885: }
8886: if ($needjsready) {
8887: $nicescroll_js = '
8888: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8889: } else {
8890: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8891: }
8892: return $nicescroll_js;
8893: }
8894:
1.318 albertel 8895: sub simple_error_page {
1.1075.2.49 raeburn 8896: my ($r,$title,$msg,$args) = @_;
8897: if (ref($args) eq 'HASH') {
8898: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8899: } else {
8900: $msg = &mt($msg);
8901: }
8902:
1.318 albertel 8903: my $page =
8904: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8905: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8906: &Apache::loncommon::end_page();
8907: if (ref($r)) {
8908: $r->print($page);
1.327 albertel 8909: return;
1.318 albertel 8910: }
8911: return $page;
8912: }
1.347 albertel 8913:
8914: {
1.610 albertel 8915: my @row_count;
1.961 onken 8916:
8917: sub start_data_table_count {
8918: unshift(@row_count, 0);
8919: return;
8920: }
8921:
8922: sub end_data_table_count {
8923: shift(@row_count);
8924: return;
8925: }
8926:
1.347 albertel 8927: sub start_data_table {
1.1018 raeburn 8928: my ($add_class,$id) = @_;
1.422 albertel 8929: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8930: my $table_id;
8931: if (defined($id)) {
8932: $table_id = ' id="'.$id.'"';
8933: }
1.961 onken 8934: &start_data_table_count();
1.1018 raeburn 8935: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8936: }
8937:
8938: sub end_data_table {
1.961 onken 8939: &end_data_table_count();
1.389 albertel 8940: return '</table>'."\n";;
1.347 albertel 8941: }
8942:
8943: sub start_data_table_row {
1.974 wenzelju 8944: my ($add_class, $id) = @_;
1.610 albertel 8945: $row_count[0]++;
8946: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8947: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8948: $id = (' id="'.$id.'"') unless ($id eq '');
8949: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8950: }
1.471 banghart 8951:
8952: sub continue_data_table_row {
1.974 wenzelju 8953: my ($add_class, $id) = @_;
1.610 albertel 8954: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8955: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8956: $id = (' id="'.$id.'"') unless ($id eq '');
8957: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8958: }
1.347 albertel 8959:
8960: sub end_data_table_row {
1.389 albertel 8961: return '</tr>'."\n";;
1.347 albertel 8962: }
1.367 www 8963:
1.421 albertel 8964: sub start_data_table_empty_row {
1.707 bisitz 8965: # $row_count[0]++;
1.421 albertel 8966: return '<tr class="LC_empty_row" >'."\n";;
8967: }
8968:
8969: sub end_data_table_empty_row {
8970: return '</tr>'."\n";;
8971: }
8972:
1.367 www 8973: sub start_data_table_header_row {
1.389 albertel 8974: return '<tr class="LC_header_row">'."\n";;
1.367 www 8975: }
8976:
8977: sub end_data_table_header_row {
1.389 albertel 8978: return '</tr>'."\n";;
1.367 www 8979: }
1.890 droeschl 8980:
8981: sub data_table_caption {
8982: my $caption = shift;
8983: return "<caption class=\"LC_caption\">$caption</caption>";
8984: }
1.347 albertel 8985: }
8986:
1.548 albertel 8987: =pod
8988:
8989: =item * &inhibit_menu_check($arg)
8990:
8991: Checks for a inhibitmenu state and generates output to preserve it
8992:
8993: Inputs: $arg - can be any of
8994: - undef - in which case the return value is a string
8995: to add into arguments list of a uri
8996: - 'input' - in which case the return value is a HTML
8997: <form> <input> field of type hidden to
8998: preserve the value
8999: - a url - in which case the return value is the url with
9000: the neccesary cgi args added to preserve the
9001: inhibitmenu state
9002: - a ref to a url - no return value, but the string is
9003: updated to include the neccessary cgi
9004: args to preserve the inhibitmenu state
9005:
9006: =cut
9007:
9008: sub inhibit_menu_check {
9009: my ($arg) = @_;
9010: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9011: if ($arg eq 'input') {
9012: if ($env{'form.inhibitmenu'}) {
9013: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9014: } else {
9015: return
9016: }
9017: }
9018: if ($env{'form.inhibitmenu'}) {
9019: if (ref($arg)) {
9020: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9021: } elsif ($arg eq '') {
9022: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9023: } else {
9024: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9025: }
9026: }
9027: if (!ref($arg)) {
9028: return $arg;
9029: }
9030: }
9031:
1.251 albertel 9032: ###############################################
1.182 matthew 9033:
9034: =pod
9035:
1.549 albertel 9036: =back
9037:
9038: =head1 User Information Routines
9039:
9040: =over 4
9041:
1.405 albertel 9042: =item * &get_users_function()
1.182 matthew 9043:
9044: Used by &bodytag to determine the current users primary role.
9045: Returns either 'student','coordinator','admin', or 'author'.
9046:
9047: =cut
9048:
9049: ###############################################
9050: sub get_users_function {
1.815 tempelho 9051: my $function = 'norole';
1.818 tempelho 9052: if ($env{'request.role'}=~/^(st)/) {
9053: $function='student';
9054: }
1.907 raeburn 9055: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9056: $function='coordinator';
9057: }
1.258 albertel 9058: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9059: $function='admin';
9060: }
1.826 bisitz 9061: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9062: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9063: $function='author';
9064: }
9065: return $function;
1.54 www 9066: }
1.99 www 9067:
9068: ###############################################
9069:
1.233 raeburn 9070: =pod
9071:
1.821 raeburn 9072: =item * &show_course()
9073:
9074: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9075: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9076:
9077: Inputs:
9078: None
9079:
9080: Outputs:
9081: Scalar: 1 if 'Course' to be used, 0 otherwise.
9082:
9083: =cut
9084:
9085: ###############################################
9086: sub show_course {
9087: my $course = !$env{'user.adv'};
9088: if (!$env{'user.adv'}) {
9089: foreach my $env (keys(%env)) {
9090: next if ($env !~ m/^user\.priv\./);
9091: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9092: $course = 0;
9093: last;
9094: }
9095: }
9096: }
9097: return $course;
9098: }
9099:
9100: ###############################################
9101:
9102: =pod
9103:
1.542 raeburn 9104: =item * &check_user_status()
1.274 raeburn 9105:
9106: Determines current status of supplied role for a
9107: specific user. Roles can be active, previous or future.
9108:
9109: Inputs:
9110: user's domain, user's username, course's domain,
1.375 raeburn 9111: course's number, optional section ID.
1.274 raeburn 9112:
9113: Outputs:
9114: role status: active, previous or future.
9115:
9116: =cut
9117:
9118: sub check_user_status {
1.412 raeburn 9119: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9120: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 9121: my @uroles = keys(%userinfo);
1.274 raeburn 9122: my $srchstr;
9123: my $active_chk = 'none';
1.412 raeburn 9124: my $now = time;
1.274 raeburn 9125: if (@uroles > 0) {
1.908 raeburn 9126: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9127: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9128: } else {
1.412 raeburn 9129: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9130: }
9131: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9132: my $role_end = 0;
9133: my $role_start = 0;
9134: $active_chk = 'active';
1.412 raeburn 9135: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9136: $role_end = $1;
9137: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9138: $role_start = $1;
1.274 raeburn 9139: }
9140: }
9141: if ($role_start > 0) {
1.412 raeburn 9142: if ($now < $role_start) {
1.274 raeburn 9143: $active_chk = 'future';
9144: }
9145: }
9146: if ($role_end > 0) {
1.412 raeburn 9147: if ($now > $role_end) {
1.274 raeburn 9148: $active_chk = 'previous';
9149: }
9150: }
9151: }
9152: }
9153: return $active_chk;
9154: }
9155:
9156: ###############################################
9157:
9158: =pod
9159:
1.405 albertel 9160: =item * &get_sections()
1.233 raeburn 9161:
9162: Determines all the sections for a course including
9163: sections with students and sections containing other roles.
1.419 raeburn 9164: Incoming parameters:
9165:
9166: 1. domain
9167: 2. course number
9168: 3. reference to array containing roles for which sections should
9169: be gathered (optional).
9170: 4. reference to array containing status types for which sections
9171: should be gathered (optional).
9172:
9173: If the third argument is undefined, sections are gathered for any role.
9174: If the fourth argument is undefined, sections are gathered for any status.
9175: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9176:
1.374 raeburn 9177: Returns section hash (keys are section IDs, values are
9178: number of users in each section), subject to the
1.419 raeburn 9179: optional roles filter, optional status filter
1.233 raeburn 9180:
9181: =cut
9182:
9183: ###############################################
9184: sub get_sections {
1.419 raeburn 9185: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9186: if (!defined($cdom) || !defined($cnum)) {
9187: my $cid = $env{'request.course.id'};
9188:
9189: return if (!defined($cid));
9190:
9191: $cdom = $env{'course.'.$cid.'.domain'};
9192: $cnum = $env{'course.'.$cid.'.num'};
9193: }
9194:
9195: my %sectioncount;
1.419 raeburn 9196: my $now = time;
1.240 albertel 9197:
1.1075.2.33 raeburn 9198: my $check_students = 1;
9199: my $only_students = 0;
9200: if (ref($possible_roles) eq 'ARRAY') {
9201: if (grep(/^st$/,@{$possible_roles})) {
9202: if (@{$possible_roles} == 1) {
9203: $only_students = 1;
9204: }
9205: } else {
9206: $check_students = 0;
9207: }
9208: }
9209:
9210: if ($check_students) {
1.276 albertel 9211: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9212: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9213: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9214: my $start_index = &Apache::loncoursedata::CL_START();
9215: my $end_index = &Apache::loncoursedata::CL_END();
9216: my $status;
1.366 albertel 9217: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9218: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9219: $data->[$status_index],
9220: $data->[$start_index],
9221: $data->[$end_index]);
9222: if ($stu_status eq 'Active') {
9223: $status = 'active';
9224: } elsif ($end < $now) {
9225: $status = 'previous';
9226: } elsif ($start > $now) {
9227: $status = 'future';
9228: }
9229: if ($section ne '-1' && $section !~ /^\s*$/) {
9230: if ((!defined($possible_status)) || (($status ne '') &&
9231: (grep/^\Q$status\E$/,@{$possible_status}))) {
9232: $sectioncount{$section}++;
9233: }
1.240 albertel 9234: }
9235: }
9236: }
1.1075.2.33 raeburn 9237: if ($only_students) {
9238: return %sectioncount;
9239: }
1.240 albertel 9240: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9241: foreach my $user (sort(keys(%courseroles))) {
9242: if ($user !~ /^(\w{2})/) { next; }
9243: my ($role) = ($user =~ /^(\w{2})/);
9244: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9245: my ($section,$status);
1.240 albertel 9246: if ($role eq 'cr' &&
9247: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9248: $section=$1;
9249: }
9250: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9251: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9252: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9253: if ($end == -1 && $start == -1) {
9254: next; #deleted role
9255: }
9256: if (!defined($possible_status)) {
9257: $sectioncount{$section}++;
9258: } else {
9259: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9260: $status = 'active';
9261: } elsif ($end < $now) {
9262: $status = 'future';
9263: } elsif ($start > $now) {
9264: $status = 'previous';
9265: }
9266: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9267: $sectioncount{$section}++;
9268: }
9269: }
1.233 raeburn 9270: }
1.366 albertel 9271: return %sectioncount;
1.233 raeburn 9272: }
9273:
1.274 raeburn 9274: ###############################################
1.294 raeburn 9275:
9276: =pod
1.405 albertel 9277:
9278: =item * &get_course_users()
9279:
1.275 raeburn 9280: Retrieves usernames:domains for users in the specified course
9281: with specific role(s), and access status.
9282:
9283: Incoming parameters:
1.277 albertel 9284: 1. course domain
9285: 2. course number
9286: 3. access status: users must have - either active,
1.275 raeburn 9287: previous, future, or all.
1.277 albertel 9288: 4. reference to array of permissible roles
1.288 raeburn 9289: 5. reference to array of section restrictions (optional)
9290: 6. reference to results object (hash of hashes).
9291: 7. reference to optional userdata hash
1.609 raeburn 9292: 8. reference to optional statushash
1.630 raeburn 9293: 9. flag if privileged users (except those set to unhide in
9294: course settings) should be excluded
1.609 raeburn 9295: Keys of top level results hash are roles.
1.275 raeburn 9296: Keys of inner hashes are username:domain, with
9297: values set to access type.
1.288 raeburn 9298: Optional userdata hash returns an array with arguments in the
9299: same order as loncoursedata::get_classlist() for student data.
9300:
1.609 raeburn 9301: Optional statushash returns
9302:
1.288 raeburn 9303: Entries for end, start, section and status are blank because
9304: of the possibility of multiple values for non-student roles.
9305:
1.275 raeburn 9306: =cut
1.405 albertel 9307:
1.275 raeburn 9308: ###############################################
1.405 albertel 9309:
1.275 raeburn 9310: sub get_course_users {
1.630 raeburn 9311: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9312: my %idx = ();
1.419 raeburn 9313: my %seclists;
1.288 raeburn 9314:
9315: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9316: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9317: $idx{end} = &Apache::loncoursedata::CL_END();
9318: $idx{start} = &Apache::loncoursedata::CL_START();
9319: $idx{id} = &Apache::loncoursedata::CL_ID();
9320: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9321: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9322: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9323:
1.290 albertel 9324: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9325: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9326: my $now = time;
1.277 albertel 9327: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9328: my $match = 0;
1.412 raeburn 9329: my $secmatch = 0;
1.419 raeburn 9330: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9331: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9332: if ($section eq '') {
9333: $section = 'none';
9334: }
1.291 albertel 9335: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9336: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9337: $secmatch = 1;
9338: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9339: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9340: $secmatch = 1;
9341: }
9342: } else {
1.419 raeburn 9343: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9344: $secmatch = 1;
9345: }
1.290 albertel 9346: }
1.412 raeburn 9347: if (!$secmatch) {
9348: next;
9349: }
1.419 raeburn 9350: }
1.275 raeburn 9351: if (defined($$types{'active'})) {
1.288 raeburn 9352: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9353: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9354: $match = 1;
1.275 raeburn 9355: }
9356: }
9357: if (defined($$types{'previous'})) {
1.609 raeburn 9358: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9359: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9360: $match = 1;
1.275 raeburn 9361: }
9362: }
9363: if (defined($$types{'future'})) {
1.609 raeburn 9364: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9365: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9366: $match = 1;
1.275 raeburn 9367: }
9368: }
1.609 raeburn 9369: if ($match) {
9370: push(@{$seclists{$student}},$section);
9371: if (ref($userdata) eq 'HASH') {
9372: $$userdata{$student} = $$classlist{$student};
9373: }
9374: if (ref($statushash) eq 'HASH') {
9375: $statushash->{$student}{'st'}{$section} = $status;
9376: }
1.288 raeburn 9377: }
1.275 raeburn 9378: }
9379: }
1.412 raeburn 9380: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9381: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9382: my $now = time;
1.609 raeburn 9383: my %displaystatus = ( previous => 'Expired',
9384: active => 'Active',
9385: future => 'Future',
9386: );
1.1075.2.36 raeburn 9387: my (%nothide,@possdoms);
1.630 raeburn 9388: if ($hidepriv) {
9389: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9390: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9391: if ($user !~ /:/) {
9392: $nothide{join(':',split(/[\@]/,$user))}=1;
9393: } else {
9394: $nothide{$user} = 1;
9395: }
9396: }
1.1075.2.36 raeburn 9397: my @possdoms = ($cdom);
9398: if ($coursehash{'checkforpriv'}) {
9399: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9400: }
1.630 raeburn 9401: }
1.439 raeburn 9402: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9403: my $match = 0;
1.412 raeburn 9404: my $secmatch = 0;
1.439 raeburn 9405: my $status;
1.412 raeburn 9406: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9407: $user =~ s/:$//;
1.439 raeburn 9408: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9409: if ($end == -1 || $start == -1) {
9410: next;
9411: }
9412: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9413: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9414: my ($uname,$udom) = split(/:/,$user);
9415: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9416: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9417: $secmatch = 1;
9418: } elsif ($usec eq '') {
1.420 albertel 9419: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9420: $secmatch = 1;
9421: }
9422: } else {
9423: if (grep(/^\Q$usec\E$/,@{$sections})) {
9424: $secmatch = 1;
9425: }
9426: }
9427: if (!$secmatch) {
9428: next;
9429: }
1.288 raeburn 9430: }
1.419 raeburn 9431: if ($usec eq '') {
9432: $usec = 'none';
9433: }
1.275 raeburn 9434: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9435: if ($hidepriv) {
1.1075.2.36 raeburn 9436: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9437: (!$nothide{$uname.':'.$udom})) {
9438: next;
9439: }
9440: }
1.503 raeburn 9441: if ($end > 0 && $end < $now) {
1.439 raeburn 9442: $status = 'previous';
9443: } elsif ($start > $now) {
9444: $status = 'future';
9445: } else {
9446: $status = 'active';
9447: }
1.277 albertel 9448: foreach my $type (keys(%{$types})) {
1.275 raeburn 9449: if ($status eq $type) {
1.420 albertel 9450: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9451: push(@{$$users{$role}{$user}},$type);
9452: }
1.288 raeburn 9453: $match = 1;
9454: }
9455: }
1.419 raeburn 9456: if (($match) && (ref($userdata) eq 'HASH')) {
9457: if (!exists($$userdata{$uname.':'.$udom})) {
9458: &get_user_info($udom,$uname,\%idx,$userdata);
9459: }
1.420 albertel 9460: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9461: push(@{$seclists{$uname.':'.$udom}},$usec);
9462: }
1.609 raeburn 9463: if (ref($statushash) eq 'HASH') {
9464: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9465: }
1.275 raeburn 9466: }
9467: }
9468: }
9469: }
1.290 albertel 9470: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9471: if ((defined($cdom)) && (defined($cnum))) {
9472: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9473: if ( defined($csettings{'internal.courseowner'}) ) {
9474: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9475: next if ($owner eq '');
9476: my ($ownername,$ownerdom);
9477: if ($owner =~ /^([^:]+):([^:]+)$/) {
9478: $ownername = $1;
9479: $ownerdom = $2;
9480: } else {
9481: $ownername = $owner;
9482: $ownerdom = $cdom;
9483: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9484: }
9485: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9486: if (defined($userdata) &&
1.609 raeburn 9487: !exists($$userdata{$owner})) {
9488: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9489: if (!grep(/^none$/,@{$seclists{$owner}})) {
9490: push(@{$seclists{$owner}},'none');
9491: }
9492: if (ref($statushash) eq 'HASH') {
9493: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9494: }
1.290 albertel 9495: }
1.279 raeburn 9496: }
9497: }
9498: }
1.419 raeburn 9499: foreach my $user (keys(%seclists)) {
9500: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9501: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9502: }
1.275 raeburn 9503: }
9504: return;
9505: }
9506:
1.288 raeburn 9507: sub get_user_info {
9508: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9509: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9510: &plainname($uname,$udom,'lastname');
1.291 albertel 9511: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9512: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9513: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9514: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9515: return;
9516: }
1.275 raeburn 9517:
1.472 raeburn 9518: ###############################################
9519:
9520: =pod
9521:
9522: =item * &get_user_quota()
9523:
1.1075.2.41 raeburn 9524: Retrieves quota assigned for storage of user files.
9525: Default is to report quota for portfolio files.
1.472 raeburn 9526:
9527: Incoming parameters:
9528: 1. user's username
9529: 2. user's domain
1.1075.2.41 raeburn 9530: 3. quota name - portfolio, author, or course
9531: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 9532: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 9533: course
1.472 raeburn 9534:
9535: Returns:
1.1075.2.58 raeburn 9536: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9537: 2. (Optional) Type of setting: custom or default
9538: (individually assigned or default for user's
9539: institutional status).
9540: 3. (Optional) - User's institutional status (e.g., faculty, staff
9541: or student - types as defined in localenroll::inst_usertypes
9542: for user's domain, which determines default quota for user.
9543: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9544:
9545: If a value has been stored in the user's environment,
1.536 raeburn 9546: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 9547: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9548:
9549: =cut
9550:
9551: ###############################################
9552:
9553:
9554: sub get_user_quota {
1.1075.2.42 raeburn 9555: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9556: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9557: if (!defined($udom)) {
9558: $udom = $env{'user.domain'};
9559: }
9560: if (!defined($uname)) {
9561: $uname = $env{'user.name'};
9562: }
9563: if (($udom eq '' || $uname eq '') ||
9564: ($udom eq 'public') && ($uname eq 'public')) {
9565: $quota = 0;
1.536 raeburn 9566: $quotatype = 'default';
9567: $defquota = 0;
1.472 raeburn 9568: } else {
1.536 raeburn 9569: my $inststatus;
1.1075.2.41 raeburn 9570: if ($quotaname eq 'course') {
9571: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9572: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9573: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9574: } else {
9575: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9576: $quota = $cenv{'internal.uploadquota'};
9577: }
1.536 raeburn 9578: } else {
1.1075.2.41 raeburn 9579: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9580: if ($quotaname eq 'author') {
9581: $quota = $env{'environment.authorquota'};
9582: } else {
9583: $quota = $env{'environment.portfolioquota'};
9584: }
9585: $inststatus = $env{'environment.inststatus'};
9586: } else {
9587: my %userenv =
9588: &Apache::lonnet::get('environment',['portfolioquota',
9589: 'authorquota','inststatus'],$udom,$uname);
9590: my ($tmp) = keys(%userenv);
9591: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9592: if ($quotaname eq 'author') {
9593: $quota = $userenv{'authorquota'};
9594: } else {
9595: $quota = $userenv{'portfolioquota'};
9596: }
9597: $inststatus = $userenv{'inststatus'};
9598: } else {
9599: undef(%userenv);
9600: }
9601: }
9602: }
9603: if ($quota eq '' || wantarray) {
9604: if ($quotaname eq 'course') {
9605: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 9606: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9607: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 9608: $defquota = $domdefs{$crstype.'quota'};
9609: }
9610: if ($defquota eq '') {
9611: $defquota = 500;
9612: }
1.1075.2.41 raeburn 9613: } else {
9614: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9615: }
9616: if ($quota eq '') {
9617: $quota = $defquota;
9618: $quotatype = 'default';
9619: } else {
9620: $quotatype = 'custom';
9621: }
1.472 raeburn 9622: }
9623: }
1.536 raeburn 9624: if (wantarray) {
9625: return ($quota,$quotatype,$settingstatus,$defquota);
9626: } else {
9627: return $quota;
9628: }
1.472 raeburn 9629: }
9630:
9631: ###############################################
9632:
9633: =pod
9634:
9635: =item * &default_quota()
9636:
1.536 raeburn 9637: Retrieves default quota assigned for storage of user portfolio files,
9638: given an (optional) user's institutional status.
1.472 raeburn 9639:
9640: Incoming parameters:
1.1075.2.42 raeburn 9641:
1.472 raeburn 9642: 1. domain
1.536 raeburn 9643: 2. (Optional) institutional status(es). This is a : separated list of
9644: status types (e.g., faculty, staff, student etc.)
9645: which apply to the user for whom the default is being retrieved.
9646: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9647: default quota will be returned.
9648: 3. quota name - portfolio, author, or course
9649: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9650:
9651: Returns:
1.1075.2.42 raeburn 9652:
1.1075.2.58 raeburn 9653: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9654: 2. (Optional) institutional type which determined the value of the
9655: default quota.
1.472 raeburn 9656:
9657: If a value has been stored in the domain's configuration db,
9658: it will return that, otherwise it returns 20 (for backwards
9659: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9660: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9661:
1.536 raeburn 9662: If the user's status includes multiple types (e.g., staff and student),
9663: the largest default quota which applies to the user determines the
9664: default quota returned.
9665:
1.472 raeburn 9666: =cut
9667:
9668: ###############################################
9669:
9670:
9671: sub default_quota {
1.1075.2.41 raeburn 9672: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9673: my ($defquota,$settingstatus);
9674: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9675: ['quotas'],$udom);
1.1075.2.41 raeburn 9676: my $key = 'defaultquota';
9677: if ($quotaname eq 'author') {
9678: $key = 'authorquota';
9679: }
1.622 raeburn 9680: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9681: if ($inststatus ne '') {
1.765 raeburn 9682: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9683: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9684: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9685: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9686: if ($defquota eq '') {
1.1075.2.41 raeburn 9687: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9688: $settingstatus = $item;
1.1075.2.41 raeburn 9689: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9690: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9691: $settingstatus = $item;
9692: }
9693: }
1.1075.2.41 raeburn 9694: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9695: if ($quotahash{'quotas'}{$item} ne '') {
9696: if ($defquota eq '') {
9697: $defquota = $quotahash{'quotas'}{$item};
9698: $settingstatus = $item;
9699: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9700: $defquota = $quotahash{'quotas'}{$item};
9701: $settingstatus = $item;
9702: }
1.536 raeburn 9703: }
9704: }
9705: }
9706: }
9707: if ($defquota eq '') {
1.1075.2.41 raeburn 9708: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9709: $defquota = $quotahash{'quotas'}{$key}{'default'};
9710: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9711: $defquota = $quotahash{'quotas'}{'default'};
9712: }
1.536 raeburn 9713: $settingstatus = 'default';
1.1075.2.42 raeburn 9714: if ($defquota eq '') {
9715: if ($quotaname eq 'author') {
9716: $defquota = 500;
9717: }
9718: }
1.536 raeburn 9719: }
9720: } else {
9721: $settingstatus = 'default';
1.1075.2.41 raeburn 9722: if ($quotaname eq 'author') {
9723: $defquota = 500;
9724: } else {
9725: $defquota = 20;
9726: }
1.536 raeburn 9727: }
9728: if (wantarray) {
9729: return ($defquota,$settingstatus);
1.472 raeburn 9730: } else {
1.536 raeburn 9731: return $defquota;
1.472 raeburn 9732: }
9733: }
9734:
1.1075.2.41 raeburn 9735: ###############################################
9736:
9737: =pod
9738:
1.1075.2.42 raeburn 9739: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9740:
9741: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9742: of existing file within authoring space will cause quota for the authoring
9743: space to be exceeded.
9744:
9745: Same, if upload of a file directly to a course/community via Course Editor
9746: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9747:
1.1075.2.61 raeburn 9748: Inputs: 7
1.1075.2.42 raeburn 9749: 1. username or coursenum
1.1075.2.41 raeburn 9750: 2. domain
1.1075.2.42 raeburn 9751: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9752: 4. filename of file for which action is being requested
9753: 5. filesize (kB) of file
9754: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9755: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9756:
9757: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9758: otherwise return null.
9759:
1.1075.2.42 raeburn 9760: =back
9761:
1.1075.2.41 raeburn 9762: =cut
9763:
1.1075.2.42 raeburn 9764: sub excess_filesize_warning {
1.1075.2.59 raeburn 9765: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9766: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9767: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9768: if ($context eq 'author') {
9769: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9770: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9771: } else {
9772: foreach my $subdir ('docs','supplemental') {
9773: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9774: }
9775: }
1.1075.2.41 raeburn 9776: $disk_quota = int($disk_quota * 1000);
9777: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9778: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9779: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9780: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9781: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9782: $disk_quota,$current_disk_usage).
9783: '</p>';
9784: }
9785: return;
9786: }
9787:
9788: ###############################################
9789:
9790:
1.384 raeburn 9791: sub get_secgrprole_info {
9792: my ($cdom,$cnum,$needroles,$type) = @_;
9793: my %sections_count = &get_sections($cdom,$cnum);
9794: my @sections = (sort {$a <=> $b} keys(%sections_count));
9795: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9796: my @groups = sort(keys(%curr_groups));
9797: my $allroles = [];
9798: my $rolehash;
9799: my $accesshash = {
9800: active => 'Currently has access',
9801: future => 'Will have future access',
9802: previous => 'Previously had access',
9803: };
9804: if ($needroles) {
9805: $rolehash = {'all' => 'all'};
1.385 albertel 9806: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9807: if (&Apache::lonnet::error(%user_roles)) {
9808: undef(%user_roles);
9809: }
9810: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9811: my ($role)=split(/\:/,$item,2);
9812: if ($role eq 'cr') { next; }
9813: if ($role =~ /^cr/) {
9814: $$rolehash{$role} = (split('/',$role))[3];
9815: } else {
9816: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9817: }
9818: }
9819: foreach my $key (sort(keys(%{$rolehash}))) {
9820: push(@{$allroles},$key);
9821: }
9822: push (@{$allroles},'st');
9823: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9824: }
9825: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9826: }
9827:
1.555 raeburn 9828: sub user_picker {
1.1075.2.127 raeburn 9829: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 9830: my $currdom = $dom;
1.1075.2.114 raeburn 9831: my @alldoms = &Apache::lonnet::all_domains();
9832: if (@alldoms == 1) {
9833: my %domsrch = &Apache::lonnet::get_dom('configuration',
9834: ['directorysrch'],$alldoms[0]);
9835: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
9836: my $showdom = $domdesc;
9837: if ($showdom eq '') {
9838: $showdom = $dom;
9839: }
9840: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
9841: if ((!$domsrch{'directorysrch'}{'available'}) &&
9842: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
9843: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
9844: }
9845: }
9846: }
1.555 raeburn 9847: my %curr_selected = (
9848: srchin => 'dom',
1.580 raeburn 9849: srchby => 'lastname',
1.555 raeburn 9850: );
9851: my $srchterm;
1.625 raeburn 9852: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9853: if ($srch->{'srchby'} ne '') {
9854: $curr_selected{'srchby'} = $srch->{'srchby'};
9855: }
9856: if ($srch->{'srchin'} ne '') {
9857: $curr_selected{'srchin'} = $srch->{'srchin'};
9858: }
9859: if ($srch->{'srchtype'} ne '') {
9860: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9861: }
9862: if ($srch->{'srchdomain'} ne '') {
9863: $currdom = $srch->{'srchdomain'};
9864: }
9865: $srchterm = $srch->{'srchterm'};
9866: }
1.1075.2.98 raeburn 9867: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 9868: 'usr' => 'Search criteria',
1.563 raeburn 9869: 'doma' => 'Domain/institution to search',
1.558 albertel 9870: 'uname' => 'username',
9871: 'lastname' => 'last name',
1.555 raeburn 9872: 'lastfirst' => 'last name, first name',
1.558 albertel 9873: 'crs' => 'in this course',
1.576 raeburn 9874: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9875: 'alc' => 'all LON-CAPA',
1.573 raeburn 9876: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9877: 'exact' => 'is',
9878: 'contains' => 'contains',
1.569 raeburn 9879: 'begins' => 'begins with',
1.1075.2.98 raeburn 9880: );
9881: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 9882: 'youm' => "You must include some text to search for.",
9883: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9884: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9885: 'yomc' => "You must choose a domain when using an institutional directory search.",
9886: 'ymcd' => "You must choose a domain when using a domain search.",
9887: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9888: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9889: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9890: );
1.1075.2.98 raeburn 9891: &html_escape(\%html_lt);
9892: &js_escape(\%js_lt);
1.1075.2.115 raeburn 9893: my $domform;
1.1075.2.126 raeburn 9894: my $allow_blank = 1;
1.1075.2.115 raeburn 9895: if ($fixeddom) {
1.1075.2.126 raeburn 9896: $allow_blank = 0;
9897: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 9898: } else {
1.1075.2.126 raeburn 9899: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 9900: }
1.563 raeburn 9901: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9902:
9903: my @srchins = ('crs','dom','alc','instd');
9904:
9905: foreach my $option (@srchins) {
9906: # FIXME 'alc' option unavailable until
9907: # loncreateuser::print_user_query_page()
9908: # has been completed.
9909: next if ($option eq 'alc');
1.880 raeburn 9910: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9911: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 9912: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 9913: if ($curr_selected{'srchin'} eq $option) {
9914: $srchinsel .= '
1.1075.2.98 raeburn 9915: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 9916: } else {
9917: $srchinsel .= '
1.1075.2.98 raeburn 9918: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 9919: }
1.555 raeburn 9920: }
1.563 raeburn 9921: $srchinsel .= "\n </select>\n";
1.555 raeburn 9922:
9923: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9924: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9925: if ($curr_selected{'srchby'} eq $option) {
9926: $srchbysel .= '
1.1075.2.98 raeburn 9927: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9928: } else {
9929: $srchbysel .= '
1.1075.2.98 raeburn 9930: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9931: }
9932: }
9933: $srchbysel .= "\n </select>\n";
9934:
9935: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9936: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9937: if ($curr_selected{'srchtype'} eq $option) {
9938: $srchtypesel .= '
1.1075.2.98 raeburn 9939: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9940: } else {
9941: $srchtypesel .= '
1.1075.2.98 raeburn 9942: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9943: }
9944: }
9945: $srchtypesel .= "\n </select>\n";
9946:
1.558 albertel 9947: my ($newuserscript,$new_user_create);
1.994 raeburn 9948: my $context_dom = $env{'request.role.domain'};
9949: if ($context eq 'requestcrs') {
9950: if ($env{'form.coursedom'} ne '') {
9951: $context_dom = $env{'form.coursedom'};
9952: }
9953: }
1.556 raeburn 9954: if ($forcenewuser) {
1.576 raeburn 9955: if (ref($srch) eq 'HASH') {
1.994 raeburn 9956: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9957: if ($cancreate) {
9958: $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>';
9959: } else {
1.799 bisitz 9960: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9961: my %usertypetext = (
9962: official => 'institutional',
9963: unofficial => 'non-institutional',
9964: );
1.799 bisitz 9965: $new_user_create = '<p class="LC_warning">'
9966: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9967: .' '
9968: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9969: ,'<a href="'.$helplink.'">','</a>')
9970: .'</p><br />';
1.627 raeburn 9971: }
1.576 raeburn 9972: }
9973: }
9974:
1.556 raeburn 9975: $newuserscript = <<"ENDSCRIPT";
9976:
1.570 raeburn 9977: function setSearch(createnew,callingForm) {
1.556 raeburn 9978: if (createnew == 1) {
1.570 raeburn 9979: for (var i=0; i<callingForm.srchby.length; i++) {
9980: if (callingForm.srchby.options[i].value == 'uname') {
9981: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9982: }
9983: }
1.570 raeburn 9984: for (var i=0; i<callingForm.srchin.length; i++) {
9985: if ( callingForm.srchin.options[i].value == 'dom') {
9986: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9987: }
9988: }
1.570 raeburn 9989: for (var i=0; i<callingForm.srchtype.length; i++) {
9990: if (callingForm.srchtype.options[i].value == 'exact') {
9991: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9992: }
9993: }
1.570 raeburn 9994: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9995: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9996: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9997: }
9998: }
9999: }
10000: }
10001: ENDSCRIPT
1.558 albertel 10002:
1.556 raeburn 10003: }
10004:
1.555 raeburn 10005: my $output = <<"END_BLOCK";
1.556 raeburn 10006: <script type="text/javascript">
1.824 bisitz 10007: // <![CDATA[
1.570 raeburn 10008: function validateEntry(callingForm) {
1.558 albertel 10009:
1.556 raeburn 10010: var checkok = 1;
1.558 albertel 10011: var srchin;
1.570 raeburn 10012: for (var i=0; i<callingForm.srchin.length; i++) {
10013: if ( callingForm.srchin[i].checked ) {
10014: srchin = callingForm.srchin[i].value;
1.558 albertel 10015: }
10016: }
10017:
1.570 raeburn 10018: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10019: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10020: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10021: var srchterm = callingForm.srchterm.value;
10022: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10023: var msg = "";
10024:
10025: if (srchterm == "") {
10026: checkok = 0;
1.1075.2.98 raeburn 10027: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10028: }
10029:
1.569 raeburn 10030: if (srchtype== 'begins') {
10031: if (srchterm.length < 2) {
10032: checkok = 0;
1.1075.2.98 raeburn 10033: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10034: }
10035: }
10036:
1.556 raeburn 10037: if (srchtype== 'contains') {
10038: if (srchterm.length < 3) {
10039: checkok = 0;
1.1075.2.98 raeburn 10040: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10041: }
10042: }
10043: if (srchin == 'instd') {
10044: if (srchdomain == '') {
10045: checkok = 0;
1.1075.2.98 raeburn 10046: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10047: }
10048: }
10049: if (srchin == 'dom') {
10050: if (srchdomain == '') {
10051: checkok = 0;
1.1075.2.98 raeburn 10052: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10053: }
10054: }
10055: if (srchby == 'lastfirst') {
10056: if (srchterm.indexOf(",") == -1) {
10057: checkok = 0;
1.1075.2.98 raeburn 10058: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10059: }
10060: if (srchterm.indexOf(",") == srchterm.length -1) {
10061: checkok = 0;
1.1075.2.98 raeburn 10062: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10063: }
10064: }
10065: if (checkok == 0) {
1.1075.2.98 raeburn 10066: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10067: return;
10068: }
10069: if (checkok == 1) {
1.570 raeburn 10070: callingForm.submit();
1.556 raeburn 10071: }
10072: }
10073:
10074: $newuserscript
10075:
1.824 bisitz 10076: // ]]>
1.556 raeburn 10077: </script>
1.558 albertel 10078:
10079: $new_user_create
10080:
1.555 raeburn 10081: END_BLOCK
1.558 albertel 10082:
1.876 raeburn 10083: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 10084: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10085: $domform.
10086: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 10087: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10088: $srchbysel.
10089: $srchtypesel.
10090: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10091: $srchinsel.
10092: &Apache::lonhtmlcommon::row_closure(1).
10093: &Apache::lonhtmlcommon::end_pick_box().
10094: '<br />';
1.1075.2.114 raeburn 10095: return ($output,1);
1.555 raeburn 10096: }
10097:
1.612 raeburn 10098: sub user_rule_check {
1.615 raeburn 10099: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 10100: my ($response,%inst_response);
1.612 raeburn 10101: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 10102: if (keys(%{$usershash}) > 1) {
10103: my (%by_username,%by_id,%userdoms);
10104: my $checkid;
1.612 raeburn 10105: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 10106: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10107: $checkid = 1;
10108: }
10109: }
10110: foreach my $user (keys(%{$usershash})) {
10111: my ($uname,$udom) = split(/:/,$user);
10112: if ($checkid) {
10113: if (ref($usershash->{$user}) eq 'HASH') {
10114: if ($usershash->{$user}->{'id'} ne '') {
10115: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
10116: $userdoms{$udom} = 1;
10117: if (ref($inst_results) eq 'HASH') {
10118: $inst_results->{$uname.':'.$udom} = {};
10119: }
10120: }
10121: }
10122: } else {
10123: $by_username{$udom}{$uname} = 1;
10124: $userdoms{$udom} = 1;
10125: if (ref($inst_results) eq 'HASH') {
10126: $inst_results->{$uname.':'.$udom} = {};
10127: }
10128: }
10129: }
10130: foreach my $udom (keys(%userdoms)) {
10131: if (!$got_rules->{$udom}) {
10132: my %domconfig = &Apache::lonnet::get_dom('configuration',
10133: ['usercreation'],$udom);
10134: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10135: foreach my $item ('username','id') {
10136: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10137: $$curr_rules{$udom}{$item} =
10138: $domconfig{'usercreation'}{$item.'_rule'};
10139: }
10140: }
10141: }
10142: $got_rules->{$udom} = 1;
10143: }
10144: }
10145: if ($checkid) {
10146: foreach my $udom (keys(%by_id)) {
10147: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10148: if ($outcome eq 'ok') {
10149: foreach my $id (keys(%{$by_id{$udom}})) {
10150: my $uname = $by_id{$udom}{$id};
10151: $inst_response{$uname.':'.$udom} = $outcome;
10152: }
10153: if (ref($results) eq 'HASH') {
10154: foreach my $uname (keys(%{$results})) {
10155: if (exists($inst_response{$uname.':'.$udom})) {
10156: $inst_response{$uname.':'.$udom} = $outcome;
10157: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10158: }
10159: }
10160: }
10161: }
1.612 raeburn 10162: }
1.615 raeburn 10163: } else {
1.1075.2.99 raeburn 10164: foreach my $udom (keys(%by_username)) {
10165: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10166: if ($outcome eq 'ok') {
10167: foreach my $uname (keys(%{$by_username{$udom}})) {
10168: $inst_response{$uname.':'.$udom} = $outcome;
10169: }
10170: if (ref($results) eq 'HASH') {
10171: foreach my $uname (keys(%{$results})) {
10172: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10173: }
10174: }
10175: }
10176: }
1.612 raeburn 10177: }
1.1075.2.99 raeburn 10178: } elsif (keys(%{$usershash}) == 1) {
10179: my $user = (keys(%{$usershash}))[0];
10180: my ($uname,$udom) = split(/:/,$user);
10181: if (($udom ne '') && ($uname ne '')) {
10182: if (ref($usershash->{$user}) eq 'HASH') {
10183: if (ref($checks) eq 'HASH') {
10184: if (defined($checks->{'username'})) {
10185: ($inst_response{$user},%{$inst_results->{$user}}) =
10186: &Apache::lonnet::get_instuser($udom,$uname);
10187: } elsif (defined($checks->{'id'})) {
10188: if ($usershash->{$user}->{'id'} ne '') {
10189: ($inst_response{$user},%{$inst_results->{$user}}) =
10190: &Apache::lonnet::get_instuser($udom,undef,
10191: $usershash->{$user}->{'id'});
10192: } else {
10193: ($inst_response{$user},%{$inst_results->{$user}}) =
10194: &Apache::lonnet::get_instuser($udom,$uname);
10195: }
10196: }
10197: } else {
10198: ($inst_response{$user},%{$inst_results->{$user}}) =
10199: &Apache::lonnet::get_instuser($udom,$uname);
10200: return;
10201: }
10202: if (!$got_rules->{$udom}) {
10203: my %domconfig = &Apache::lonnet::get_dom('configuration',
10204: ['usercreation'],$udom);
10205: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10206: foreach my $item ('username','id') {
10207: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10208: $$curr_rules{$udom}{$item} =
10209: $domconfig{'usercreation'}{$item.'_rule'};
10210: }
10211: }
1.585 raeburn 10212: }
1.1075.2.99 raeburn 10213: $got_rules->{$udom} = 1;
1.585 raeburn 10214: }
10215: }
1.1075.2.99 raeburn 10216: } else {
10217: return;
10218: }
10219: } else {
10220: return;
10221: }
10222: foreach my $user (keys(%{$usershash})) {
10223: my ($uname,$udom) = split(/:/,$user);
10224: next if (($udom eq '') || ($uname eq ''));
10225: my $id;
10226: if (ref($inst_results) eq 'HASH') {
10227: if (ref($inst_results->{$user}) eq 'HASH') {
10228: $id = $inst_results->{$user}->{'id'};
10229: }
10230: }
10231: if ($id eq '') {
10232: if (ref($usershash->{$user})) {
10233: $id = $usershash->{$user}->{'id'};
10234: }
1.585 raeburn 10235: }
1.612 raeburn 10236: foreach my $item (keys(%{$checks})) {
10237: if (ref($$curr_rules{$udom}) eq 'HASH') {
10238: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10239: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 10240: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10241: $$curr_rules{$udom}{$item});
1.612 raeburn 10242: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10243: if ($rule_check{$rule}) {
10244: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 10245: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10246: if (ref($inst_results) eq 'HASH') {
10247: if (ref($inst_results->{$user}) eq 'HASH') {
10248: if (keys(%{$inst_results->{$user}}) == 0) {
10249: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 10250: } elsif ($item eq 'id') {
10251: if ($inst_results->{$user}->{'id'} eq '') {
10252: $$alerts{$item}{$udom}{$uname} = 1;
10253: }
1.615 raeburn 10254: }
1.612 raeburn 10255: }
10256: }
1.615 raeburn 10257: }
10258: last;
1.585 raeburn 10259: }
10260: }
10261: }
10262: }
10263: }
10264: }
10265: }
10266: }
1.612 raeburn 10267: return;
10268: }
10269:
10270: sub user_rule_formats {
10271: my ($domain,$domdesc,$curr_rules,$check) = @_;
10272: my %text = (
10273: 'username' => 'Usernames',
10274: 'id' => 'IDs',
10275: );
10276: my $output;
10277: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10278: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10279: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 10280: $output = '<br />'.
10281: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10282: '<span class="LC_cusr_emph">','</span>',$domdesc).
10283: ' <ul>';
1.612 raeburn 10284: foreach my $rule (@{$ruleorder}) {
10285: if (ref($curr_rules) eq 'ARRAY') {
10286: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10287: if (ref($rules->{$rule}) eq 'HASH') {
10288: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10289: $rules->{$rule}{'desc'}.'</li>';
10290: }
10291: }
10292: }
10293: }
10294: $output .= '</ul>';
10295: }
10296: }
10297: return $output;
10298: }
10299:
10300: sub instrule_disallow_msg {
1.615 raeburn 10301: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10302: my $response;
10303: my %text = (
10304: item => 'username',
10305: items => 'usernames',
10306: match => 'matches',
10307: do => 'does',
10308: action => 'a username',
10309: one => 'one',
10310: );
10311: if ($count > 1) {
10312: $text{'item'} = 'usernames';
10313: $text{'match'} ='match';
10314: $text{'do'} = 'do';
10315: $text{'action'} = 'usernames',
10316: $text{'one'} = 'ones';
10317: }
10318: if ($checkitem eq 'id') {
10319: $text{'items'} = 'IDs';
10320: $text{'item'} = 'ID';
10321: $text{'action'} = 'an ID';
1.615 raeburn 10322: if ($count > 1) {
10323: $text{'item'} = 'IDs';
10324: $text{'action'} = 'IDs';
10325: }
1.612 raeburn 10326: }
1.674 bisitz 10327: $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 10328: if ($mode eq 'upload') {
10329: if ($checkitem eq 'username') {
10330: $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'}.");
10331: } elsif ($checkitem eq 'id') {
1.674 bisitz 10332: $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 10333: }
1.669 raeburn 10334: } elsif ($mode eq 'selfcreate') {
10335: if ($checkitem eq 'id') {
10336: $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.");
10337: }
1.615 raeburn 10338: } else {
10339: if ($checkitem eq 'username') {
10340: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10341: } elsif ($checkitem eq 'id') {
10342: $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.");
10343: }
1.612 raeburn 10344: }
10345: return $response;
1.585 raeburn 10346: }
10347:
1.624 raeburn 10348: sub personal_data_fieldtitles {
10349: my %fieldtitles = &Apache::lonlocal::texthash (
10350: id => 'Student/Employee ID',
10351: permanentemail => 'E-mail address',
10352: lastname => 'Last Name',
10353: firstname => 'First Name',
10354: middlename => 'Middle Name',
10355: generation => 'Generation',
10356: gen => 'Generation',
1.765 raeburn 10357: inststatus => 'Affiliation',
1.624 raeburn 10358: );
10359: return %fieldtitles;
10360: }
10361:
1.642 raeburn 10362: sub sorted_inst_types {
10363: my ($dom) = @_;
1.1075.2.70 raeburn 10364: my ($usertypes,$order);
10365: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10366: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10367: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10368: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10369: } else {
10370: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10371: }
1.642 raeburn 10372: my $othertitle = &mt('All users');
10373: if ($env{'request.course.id'}) {
1.668 raeburn 10374: $othertitle = &mt('Any users');
1.642 raeburn 10375: }
10376: my @types;
10377: if (ref($order) eq 'ARRAY') {
10378: @types = @{$order};
10379: }
10380: if (@types == 0) {
10381: if (ref($usertypes) eq 'HASH') {
10382: @types = sort(keys(%{$usertypes}));
10383: }
10384: }
10385: if (keys(%{$usertypes}) > 0) {
10386: $othertitle = &mt('Other users');
10387: }
10388: return ($othertitle,$usertypes,\@types);
10389: }
10390:
1.645 raeburn 10391: sub get_institutional_codes {
10392: my ($settings,$allcourses,$LC_code) = @_;
10393: # Get complete list of course sections to update
10394: my @currsections = ();
10395: my @currxlists = ();
10396: my $coursecode = $$settings{'internal.coursecode'};
10397:
10398: if ($$settings{'internal.sectionnums'} ne '') {
10399: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10400: }
10401:
10402: if ($$settings{'internal.crosslistings'} ne '') {
10403: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10404: }
10405:
10406: if (@currxlists > 0) {
10407: foreach (@currxlists) {
10408: if (m/^([^:]+):(\w*)$/) {
10409: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 10410: push(@{$allcourses},$1);
1.645 raeburn 10411: $$LC_code{$1} = $2;
10412: }
10413: }
10414: }
10415: }
10416:
10417: if (@currsections > 0) {
10418: foreach (@currsections) {
10419: if (m/^(\w+):(\w*)$/) {
10420: my $sec = $coursecode.$1;
10421: my $lc_sec = $2;
10422: unless (grep/^$sec$/,@{$allcourses}) {
1.1075.2.119 raeburn 10423: push(@{$allcourses},$sec);
1.645 raeburn 10424: $$LC_code{$sec} = $lc_sec;
10425: }
10426: }
10427: }
10428: }
10429: return;
10430: }
10431:
1.971 raeburn 10432: sub get_standard_codeitems {
10433: return ('Year','Semester','Department','Number','Section');
10434: }
10435:
1.112 bowersj2 10436: =pod
10437:
1.780 raeburn 10438: =head1 Slot Helpers
10439:
10440: =over 4
10441:
10442: =item * sorted_slots()
10443:
1.1040 raeburn 10444: Sorts an array of slot names in order of an optional sort key,
10445: default sort is by slot start time (earliest first).
1.780 raeburn 10446:
10447: Inputs:
10448:
10449: =over 4
10450:
10451: slotsarr - Reference to array of unsorted slot names.
10452:
10453: slots - Reference to hash of hash, where outer hash keys are slot names.
10454:
1.1040 raeburn 10455: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10456:
1.549 albertel 10457: =back
10458:
1.780 raeburn 10459: Returns:
10460:
10461: =over 4
10462:
1.1040 raeburn 10463: sorted - An array of slot names sorted by a specified sort key
10464: (default sort key is start time of the slot).
1.780 raeburn 10465:
10466: =back
10467:
10468: =cut
10469:
10470:
10471: sub sorted_slots {
1.1040 raeburn 10472: my ($slotsarr,$slots,$sortkey) = @_;
10473: if ($sortkey eq '') {
10474: $sortkey = 'starttime';
10475: }
1.780 raeburn 10476: my @sorted;
10477: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10478: @sorted =
10479: sort {
10480: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10481: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10482: }
10483: if (ref($slots->{$a})) { return -1;}
10484: if (ref($slots->{$b})) { return 1;}
10485: return 0;
10486: } @{$slotsarr};
10487: }
10488: return @sorted;
10489: }
10490:
1.1040 raeburn 10491: =pod
10492:
10493: =item * get_future_slots()
10494:
10495: Inputs:
10496:
10497: =over 4
10498:
10499: cnum - course number
10500:
10501: cdom - course domain
10502:
10503: now - current UNIX time
10504:
10505: symb - optional symb
10506:
10507: =back
10508:
10509: Returns:
10510:
10511: =over 4
10512:
10513: sorted_reservable - ref to array of student_schedulable slots currently
10514: reservable, ordered by end date of reservation period.
10515:
10516: reservable_now - ref to hash of student_schedulable slots currently
10517: reservable.
10518:
10519: Keys in inner hash are:
10520: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 10521: (b) endreserve: end date of reservation period.
10522: (c) uniqueperiod: start,end dates when slot is to be uniquely
10523: selected.
1.1040 raeburn 10524:
10525: sorted_future - ref to array of student_schedulable slots reservable in
10526: the future, ordered by start date of reservation period.
10527:
10528: future_reservable - ref to hash of student_schedulable slots reservable
10529: in the future.
10530:
10531: Keys in inner hash are:
10532: (a) symb: either blank or symb to which slot use is restricted.
10533: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 10534: (c) uniqueperiod: start,end dates when slot is to be uniquely
10535: selected.
1.1040 raeburn 10536:
10537: =back
10538:
10539: =cut
10540:
10541: sub get_future_slots {
10542: my ($cnum,$cdom,$now,$symb) = @_;
10543: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10544: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10545: foreach my $slot (keys(%slots)) {
10546: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10547: if ($symb) {
10548: next if (($slots{$slot}->{'symb'} ne '') &&
10549: ($slots{$slot}->{'symb'} ne $symb));
10550: }
10551: if (($slots{$slot}->{'starttime'} > $now) &&
10552: ($slots{$slot}->{'endtime'} > $now)) {
10553: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10554: my $userallowed = 0;
10555: if ($slots{$slot}->{'allowedsections'}) {
10556: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10557: if (!defined($env{'request.role.sec'})
10558: && grep(/^No section assigned$/,@allowed_sec)) {
10559: $userallowed=1;
10560: } else {
10561: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10562: $userallowed=1;
10563: }
10564: }
10565: unless ($userallowed) {
10566: if (defined($env{'request.course.groups'})) {
10567: my @groups = split(/:/,$env{'request.course.groups'});
10568: foreach my $group (@groups) {
10569: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10570: $userallowed=1;
10571: last;
10572: }
10573: }
10574: }
10575: }
10576: }
10577: if ($slots{$slot}->{'allowedusers'}) {
10578: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10579: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10580: if (grep(/^\Q$user\E$/,@allowed_users)) {
10581: $userallowed = 1;
10582: }
10583: }
10584: next unless($userallowed);
10585: }
10586: my $startreserve = $slots{$slot}->{'startreserve'};
10587: my $endreserve = $slots{$slot}->{'endreserve'};
10588: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 10589: my $uniqueperiod;
10590: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10591: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10592: }
1.1040 raeburn 10593: if (($startreserve < $now) &&
10594: (!$endreserve || $endreserve > $now)) {
10595: my $lastres = $endreserve;
10596: if (!$lastres) {
10597: $lastres = $slots{$slot}->{'starttime'};
10598: }
10599: $reservable_now{$slot} = {
10600: symb => $symb,
1.1075.2.104 raeburn 10601: endreserve => $lastres,
10602: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10603: };
10604: } elsif (($startreserve > $now) &&
10605: (!$endreserve || $endreserve > $startreserve)) {
10606: $future_reservable{$slot} = {
10607: symb => $symb,
1.1075.2.104 raeburn 10608: startreserve => $startreserve,
10609: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10610: };
10611: }
10612: }
10613: }
10614: my @unsorted_reservable = keys(%reservable_now);
10615: if (@unsorted_reservable > 0) {
10616: @sorted_reservable =
10617: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10618: }
10619: my @unsorted_future = keys(%future_reservable);
10620: if (@unsorted_future > 0) {
10621: @sorted_future =
10622: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10623: }
10624: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10625: }
1.780 raeburn 10626:
10627: =pod
10628:
1.1057 foxr 10629: =back
10630:
1.549 albertel 10631: =head1 HTTP Helpers
10632:
10633: =over 4
10634:
1.648 raeburn 10635: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10636:
1.258 albertel 10637: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10638: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10639: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10640:
10641: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10642: $possible_names is an ref to an array of form element names. As an example:
10643: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10644: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10645:
10646: =cut
1.1 albertel 10647:
1.6 albertel 10648: sub get_unprocessed_cgi {
1.25 albertel 10649: my ($query,$possible_names)= @_;
1.26 matthew 10650: # $Apache::lonxml::debug=1;
1.356 albertel 10651: foreach my $pair (split(/&/,$query)) {
10652: my ($name, $value) = split(/=/,$pair);
1.369 www 10653: $name = &unescape($name);
1.25 albertel 10654: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10655: $value =~ tr/+/ /;
10656: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10657: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10658: }
1.16 harris41 10659: }
1.6 albertel 10660: }
10661:
1.112 bowersj2 10662: =pod
10663:
1.648 raeburn 10664: =item * &cacheheader()
1.112 bowersj2 10665:
10666: returns cache-controlling header code
10667:
10668: =cut
10669:
1.7 albertel 10670: sub cacheheader {
1.258 albertel 10671: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10672: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10673: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10674: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10675: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10676: return $output;
1.7 albertel 10677: }
10678:
1.112 bowersj2 10679: =pod
10680:
1.648 raeburn 10681: =item * &no_cache($r)
1.112 bowersj2 10682:
10683: specifies header code to not have cache
10684:
10685: =cut
10686:
1.9 albertel 10687: sub no_cache {
1.216 albertel 10688: my ($r) = @_;
10689: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10690: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10691: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10692: $r->no_cache(1);
10693: $r->header_out("Expires" => $date);
10694: $r->header_out("Pragma" => "no-cache");
1.123 www 10695: }
10696:
10697: sub content_type {
1.181 albertel 10698: my ($r,$type,$charset) = @_;
1.299 foxr 10699: if ($r) {
10700: # Note that printout.pl calls this with undef for $r.
10701: &no_cache($r);
10702: }
1.258 albertel 10703: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10704: unless ($charset) {
10705: $charset=&Apache::lonlocal::current_encoding;
10706: }
10707: if ($charset) { $type.='; charset='.$charset; }
10708: if ($r) {
10709: $r->content_type($type);
10710: } else {
10711: print("Content-type: $type\n\n");
10712: }
1.9 albertel 10713: }
1.25 albertel 10714:
1.112 bowersj2 10715: =pod
10716:
1.648 raeburn 10717: =item * &add_to_env($name,$value)
1.112 bowersj2 10718:
1.258 albertel 10719: adds $name to the %env hash with value
1.112 bowersj2 10720: $value, if $name already exists, the entry is converted to an array
10721: reference and $value is added to the array.
10722:
10723: =cut
10724:
1.25 albertel 10725: sub add_to_env {
10726: my ($name,$value)=@_;
1.258 albertel 10727: if (defined($env{$name})) {
10728: if (ref($env{$name})) {
1.25 albertel 10729: #already have multiple values
1.258 albertel 10730: push(@{ $env{$name} },$value);
1.25 albertel 10731: } else {
10732: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10733: my $first=$env{$name};
10734: undef($env{$name});
10735: push(@{ $env{$name} },$first,$value);
1.25 albertel 10736: }
10737: } else {
1.258 albertel 10738: $env{$name}=$value;
1.25 albertel 10739: }
1.31 albertel 10740: }
1.149 albertel 10741:
10742: =pod
10743:
1.648 raeburn 10744: =item * &get_env_multiple($name)
1.149 albertel 10745:
1.258 albertel 10746: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10747: values may be defined and end up as an array ref.
10748:
10749: returns an array of values
10750:
10751: =cut
10752:
10753: sub get_env_multiple {
10754: my ($name) = @_;
10755: my @values;
1.258 albertel 10756: if (defined($env{$name})) {
1.149 albertel 10757: # exists is it an array
1.258 albertel 10758: if (ref($env{$name})) {
10759: @values=@{ $env{$name} };
1.149 albertel 10760: } else {
1.258 albertel 10761: $values[0]=$env{$name};
1.149 albertel 10762: }
10763: }
10764: return(@values);
10765: }
10766:
1.660 raeburn 10767: sub ask_for_embedded_content {
10768: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10769: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 10770: %currsubfile,%unused,$rem);
1.1071 raeburn 10771: my $counter = 0;
10772: my $numnew = 0;
1.987 raeburn 10773: my $numremref = 0;
10774: my $numinvalid = 0;
10775: my $numpathchg = 0;
10776: my $numexisting = 0;
1.1071 raeburn 10777: my $numunused = 0;
10778: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 10779: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10780: my $heading = &mt('Upload embedded files');
10781: my $buttontext = &mt('Upload');
10782:
1.1075.2.11 raeburn 10783: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 10784: if ($actionurl eq '/adm/dependencies') {
10785: $navmap = Apache::lonnavmaps::navmap->new();
10786: }
10787: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10788: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 10789: }
1.1075.2.35 raeburn 10790: if (($actionurl eq '/adm/portfolio') ||
10791: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10792: my $current_path='/';
10793: if ($env{'form.currentpath'}) {
10794: $current_path = $env{'form.currentpath'};
10795: }
10796: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 10797: $udom = $cdom;
10798: $uname = $cnum;
1.984 raeburn 10799: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10800: } else {
10801: $udom = $env{'user.domain'};
10802: $uname = $env{'user.name'};
10803: $url = '/userfiles/portfolio';
10804: }
1.987 raeburn 10805: $toplevel = $url.'/';
1.984 raeburn 10806: $url .= $current_path;
10807: $getpropath = 1;
1.987 raeburn 10808: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10809: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10810: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10811: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10812: $toplevel = $url;
1.984 raeburn 10813: if ($rest ne '') {
1.987 raeburn 10814: $url .= $rest;
10815: }
10816: } elsif ($actionurl eq '/adm/coursedocs') {
10817: if (ref($args) eq 'HASH') {
1.1071 raeburn 10818: $url = $args->{'docs_url'};
10819: $toplevel = $url;
1.1075.2.11 raeburn 10820: if ($args->{'context'} eq 'paste') {
10821: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10822: ($path) =
10823: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10824: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10825: $fileloc =~ s{^/}{};
10826: }
1.1071 raeburn 10827: }
10828: } elsif ($actionurl eq '/adm/dependencies') {
10829: if ($env{'request.course.id'} ne '') {
10830: if (ref($args) eq 'HASH') {
10831: $url = $args->{'docs_url'};
10832: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 10833: $toplevel = $url;
10834: unless ($toplevel =~ m{^/}) {
10835: $toplevel = "/$url";
10836: }
1.1075.2.11 raeburn 10837: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 10838: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10839: $path = $1;
10840: } else {
10841: ($path) =
10842: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10843: }
1.1075.2.79 raeburn 10844: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10845: $fileloc = $toplevel;
10846: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10847: my ($udom,$uname,$fname) =
10848: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10849: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10850: } else {
10851: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10852: }
1.1071 raeburn 10853: $fileloc =~ s{^/}{};
10854: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10855: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10856: }
1.987 raeburn 10857: }
1.1075.2.35 raeburn 10858: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10859: $udom = $cdom;
10860: $uname = $cnum;
10861: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10862: $toplevel = $url;
10863: $path = $url;
10864: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10865: $fileloc =~ s{^/}{};
10866: }
10867: foreach my $file (keys(%{$allfiles})) {
10868: my $embed_file;
10869: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10870: $embed_file = $1;
10871: } else {
10872: $embed_file = $file;
10873: }
1.1075.2.55 raeburn 10874: my ($absolutepath,$cleaned_file);
10875: if ($embed_file =~ m{^\w+://}) {
10876: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 10877: $newfiles{$cleaned_file} = 1;
10878: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10879: } else {
1.1075.2.55 raeburn 10880: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10881: if ($embed_file =~ m{^/}) {
10882: $absolutepath = $embed_file;
10883: }
1.1075.2.47 raeburn 10884: if ($cleaned_file =~ m{/}) {
10885: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10886: $path = &check_for_traversal($path,$url,$toplevel);
10887: my $item = $fname;
10888: if ($path ne '') {
10889: $item = $path.'/'.$fname;
10890: $subdependencies{$path}{$fname} = 1;
10891: } else {
10892: $dependencies{$item} = 1;
10893: }
10894: if ($absolutepath) {
10895: $mapping{$item} = $absolutepath;
10896: } else {
10897: $mapping{$item} = $embed_file;
10898: }
10899: } else {
10900: $dependencies{$embed_file} = 1;
10901: if ($absolutepath) {
1.1075.2.47 raeburn 10902: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10903: } else {
1.1075.2.47 raeburn 10904: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10905: }
10906: }
1.984 raeburn 10907: }
10908: }
1.1071 raeburn 10909: my $dirptr = 16384;
1.984 raeburn 10910: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10911: $currsubfile{$path} = {};
1.1075.2.35 raeburn 10912: if (($actionurl eq '/adm/portfolio') ||
10913: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10914: my ($sublistref,$listerror) =
10915: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10916: if (ref($sublistref) eq 'ARRAY') {
10917: foreach my $line (@{$sublistref}) {
10918: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10919: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10920: }
1.984 raeburn 10921: }
1.987 raeburn 10922: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10923: if (opendir(my $dir,$url.'/'.$path)) {
10924: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10925: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10926: }
1.1075.2.11 raeburn 10927: } elsif (($actionurl eq '/adm/dependencies') ||
10928: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10929: ($args->{'context'} eq 'paste')) ||
10930: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10931: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 10932: my $dir;
10933: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10934: $dir = $fileloc;
10935: } else {
10936: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10937: }
1.1071 raeburn 10938: if ($dir ne '') {
10939: my ($sublistref,$listerror) =
10940: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10941: if (ref($sublistref) eq 'ARRAY') {
10942: foreach my $line (@{$sublistref}) {
10943: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10944: undef,$mtime)=split(/\&/,$line,12);
10945: unless (($testdir&$dirptr) ||
10946: ($file_name =~ /^\.\.?$/)) {
10947: $currsubfile{$path}{$file_name} = [$size,$mtime];
10948: }
10949: }
10950: }
10951: }
1.984 raeburn 10952: }
10953: }
10954: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10955: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10956: my $item = $path.'/'.$file;
10957: unless ($mapping{$item} eq $item) {
10958: $pathchanges{$item} = 1;
10959: }
10960: $existing{$item} = 1;
10961: $numexisting ++;
10962: } else {
10963: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10964: }
10965: }
1.1071 raeburn 10966: if ($actionurl eq '/adm/dependencies') {
10967: foreach my $path (keys(%currsubfile)) {
10968: if (ref($currsubfile{$path}) eq 'HASH') {
10969: foreach my $file (keys(%{$currsubfile{$path}})) {
10970: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 10971: next if (($rem ne '') &&
10972: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10973: (ref($navmap) &&
10974: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10975: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10976: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10977: $unused{$path.'/'.$file} = 1;
10978: }
10979: }
10980: }
10981: }
10982: }
1.984 raeburn 10983: }
1.987 raeburn 10984: my %currfile;
1.1075.2.35 raeburn 10985: if (($actionurl eq '/adm/portfolio') ||
10986: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10987: my ($dirlistref,$listerror) =
10988: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10989: if (ref($dirlistref) eq 'ARRAY') {
10990: foreach my $line (@{$dirlistref}) {
10991: my ($file_name,$rest) = split(/\&/,$line,2);
10992: $currfile{$file_name} = 1;
10993: }
1.984 raeburn 10994: }
1.987 raeburn 10995: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10996: if (opendir(my $dir,$url)) {
1.987 raeburn 10997: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10998: map {$currfile{$_} = 1;} @dir_list;
10999: }
1.1075.2.11 raeburn 11000: } elsif (($actionurl eq '/adm/dependencies') ||
11001: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 11002: ($args->{'context'} eq 'paste')) ||
11003: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11004: if ($env{'request.course.id'} ne '') {
11005: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11006: if ($dir ne '') {
11007: my ($dirlistref,$listerror) =
11008: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11009: if (ref($dirlistref) eq 'ARRAY') {
11010: foreach my $line (@{$dirlistref}) {
11011: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11012: $size,undef,$mtime)=split(/\&/,$line,12);
11013: unless (($testdir&$dirptr) ||
11014: ($file_name =~ /^\.\.?$/)) {
11015: $currfile{$file_name} = [$size,$mtime];
11016: }
11017: }
11018: }
11019: }
11020: }
1.984 raeburn 11021: }
11022: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11023: if (exists($currfile{$file})) {
1.987 raeburn 11024: unless ($mapping{$file} eq $file) {
11025: $pathchanges{$file} = 1;
11026: }
11027: $existing{$file} = 1;
11028: $numexisting ++;
11029: } else {
1.984 raeburn 11030: $newfiles{$file} = 1;
11031: }
11032: }
1.1071 raeburn 11033: foreach my $file (keys(%currfile)) {
11034: unless (($file eq $filename) ||
11035: ($file eq $filename.'.bak') ||
11036: ($dependencies{$file})) {
1.1075.2.11 raeburn 11037: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 11038: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11039: next if (($rem ne '') &&
11040: (($env{"httpref.$rem".$file} ne '') ||
11041: (ref($navmap) &&
11042: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11043: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11044: ($navmap->getResourceByUrl($rem.$1)))))));
11045: }
1.1075.2.11 raeburn 11046: }
1.1071 raeburn 11047: $unused{$file} = 1;
11048: }
11049: }
1.1075.2.11 raeburn 11050: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11051: ($args->{'context'} eq 'paste')) {
11052: $counter = scalar(keys(%existing));
11053: $numpathchg = scalar(keys(%pathchanges));
11054: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 11055: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11056: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11057: $counter = scalar(keys(%existing));
11058: $numpathchg = scalar(keys(%pathchanges));
11059: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 11060: }
1.984 raeburn 11061: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11062: if ($actionurl eq '/adm/dependencies') {
11063: next if ($embed_file =~ m{^\w+://});
11064: }
1.660 raeburn 11065: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11066: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11067: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11068: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 11069: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11070: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11071: }
1.1075.2.35 raeburn 11072: $upload_output .= '</td>';
1.1071 raeburn 11073: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 11074: $upload_output.='<td align="right">'.
11075: '<span class="LC_info LC_fontsize_medium">'.
11076: &mt("URL points to web address").'</span>';
1.987 raeburn 11077: $numremref++;
1.660 raeburn 11078: } elsif ($args->{'error_on_invalid_names'}
11079: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 11080: $upload_output.='<td align="right"><span class="LC_warning">'.
11081: &mt('Invalid characters').'</span>';
1.987 raeburn 11082: $numinvalid++;
1.660 raeburn 11083: } else {
1.1075.2.35 raeburn 11084: $upload_output .= '<td>'.
11085: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11086: $embed_file,\%mapping,
1.1071 raeburn 11087: $allfiles,$codebase,'upload');
11088: $counter ++;
11089: $numnew ++;
1.987 raeburn 11090: }
11091: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11092: }
11093: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11094: if ($actionurl eq '/adm/dependencies') {
11095: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11096: $modify_output .= &start_data_table_row().
11097: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11098: '<img src="'.&icon($embed_file).'" border="0" />'.
11099: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11100: '<td>'.$size.'</td>'.
11101: '<td>'.$mtime.'</td>'.
11102: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11103: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11104: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11105: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11106: &embedded_file_element('upload_embedded',$counter,
11107: $embed_file,\%mapping,
11108: $allfiles,$codebase,'modify').
11109: '</div></td>'.
11110: &end_data_table_row()."\n";
11111: $counter ++;
11112: } else {
11113: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11114: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11115: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11116: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11117: &Apache::loncommon::end_data_table_row()."\n";
11118: }
11119: }
11120: my $delidx = $counter;
11121: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11122: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11123: $delete_output .= &start_data_table_row().
11124: '<td><img src="'.&icon($oldfile).'" />'.
11125: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11126: '<td>'.$size.'</td>'.
11127: '<td>'.$mtime.'</td>'.
11128: '<td><label><input type="checkbox" name="del_upload_dep" '.
11129: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11130: &embedded_file_element('upload_embedded',$delidx,
11131: $oldfile,\%mapping,$allfiles,
11132: $codebase,'delete').'</td>'.
11133: &end_data_table_row()."\n";
11134: $numunused ++;
11135: $delidx ++;
1.987 raeburn 11136: }
11137: if ($upload_output) {
11138: $upload_output = &start_data_table().
11139: $upload_output.
11140: &end_data_table()."\n";
11141: }
1.1071 raeburn 11142: if ($modify_output) {
11143: $modify_output = &start_data_table().
11144: &start_data_table_header_row().
11145: '<th>'.&mt('File').'</th>'.
11146: '<th>'.&mt('Size (KB)').'</th>'.
11147: '<th>'.&mt('Modified').'</th>'.
11148: '<th>'.&mt('Upload replacement?').'</th>'.
11149: &end_data_table_header_row().
11150: $modify_output.
11151: &end_data_table()."\n";
11152: }
11153: if ($delete_output) {
11154: $delete_output = &start_data_table().
11155: &start_data_table_header_row().
11156: '<th>'.&mt('File').'</th>'.
11157: '<th>'.&mt('Size (KB)').'</th>'.
11158: '<th>'.&mt('Modified').'</th>'.
11159: '<th>'.&mt('Delete?').'</th>'.
11160: &end_data_table_header_row().
11161: $delete_output.
11162: &end_data_table()."\n";
11163: }
1.987 raeburn 11164: my $applies = 0;
11165: if ($numremref) {
11166: $applies ++;
11167: }
11168: if ($numinvalid) {
11169: $applies ++;
11170: }
11171: if ($numexisting) {
11172: $applies ++;
11173: }
1.1071 raeburn 11174: if ($counter || $numunused) {
1.987 raeburn 11175: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11176: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11177: $state.'<h3>'.$heading.'</h3>';
11178: if ($actionurl eq '/adm/dependencies') {
11179: if ($numnew) {
11180: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11181: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11182: $upload_output.'<br />'."\n";
11183: }
11184: if ($numexisting) {
11185: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11186: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11187: $modify_output.'<br />'."\n";
11188: $buttontext = &mt('Save changes');
11189: }
11190: if ($numunused) {
11191: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11192: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11193: $delete_output.'<br />'."\n";
11194: $buttontext = &mt('Save changes');
11195: }
11196: } else {
11197: $output .= $upload_output.'<br />'."\n";
11198: }
11199: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11200: $counter.'" />'."\n";
11201: if ($actionurl eq '/adm/dependencies') {
11202: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11203: $numnew.'" />'."\n";
11204: } elsif ($actionurl eq '') {
1.987 raeburn 11205: $output .= '<input type="hidden" name="phase" value="three" />';
11206: }
11207: } elsif ($applies) {
11208: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11209: if ($applies > 1) {
11210: $output .=
1.1075.2.35 raeburn 11211: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11212: if ($numremref) {
11213: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11214: }
11215: if ($numinvalid) {
11216: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11217: }
11218: if ($numexisting) {
11219: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11220: }
11221: $output .= '</ul><br />';
11222: } elsif ($numremref) {
11223: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11224: } elsif ($numinvalid) {
11225: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11226: } elsif ($numexisting) {
11227: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11228: }
11229: $output .= $upload_output.'<br />';
11230: }
11231: my ($pathchange_output,$chgcount);
1.1071 raeburn 11232: $chgcount = $counter;
1.987 raeburn 11233: if (keys(%pathchanges) > 0) {
11234: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11235: if ($counter) {
1.987 raeburn 11236: $output .= &embedded_file_element('pathchange',$chgcount,
11237: $embed_file,\%mapping,
1.1071 raeburn 11238: $allfiles,$codebase,'change');
1.987 raeburn 11239: } else {
11240: $pathchange_output .=
11241: &start_data_table_row().
11242: '<td><input type ="checkbox" name="namechange" value="'.
11243: $chgcount.'" checked="checked" /></td>'.
11244: '<td>'.$mapping{$embed_file}.'</td>'.
11245: '<td>'.$embed_file.
11246: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11247: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11248: '</td>'.&end_data_table_row();
1.660 raeburn 11249: }
1.987 raeburn 11250: $numpathchg ++;
11251: $chgcount ++;
1.660 raeburn 11252: }
11253: }
1.1075.2.35 raeburn 11254: if (($counter) || ($numunused)) {
1.987 raeburn 11255: if ($numpathchg) {
11256: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11257: $numpathchg.'" />'."\n";
11258: }
11259: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11260: ($actionurl eq '/adm/imsimport')) {
11261: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11262: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11263: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11264: } elsif ($actionurl eq '/adm/dependencies') {
11265: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11266: }
1.1075.2.35 raeburn 11267: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11268: } elsif ($numpathchg) {
11269: my %pathchange = ();
11270: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11271: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11272: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 11273: }
1.987 raeburn 11274: }
1.1071 raeburn 11275: return ($output,$counter,$numpathchg);
1.987 raeburn 11276: }
11277:
1.1075.2.47 raeburn 11278: =pod
11279:
11280: =item * clean_path($name)
11281:
11282: Performs clean-up of directories, subdirectories and filename in an
11283: embedded object, referenced in an HTML file which is being uploaded
11284: to a course or portfolio, where
11285: "Upload embedded images/multimedia files if HTML file" checkbox was
11286: checked.
11287:
11288: Clean-up is similar to replacements in lonnet::clean_filename()
11289: except each / between sub-directory and next level is preserved.
11290:
11291: =cut
11292:
11293: sub clean_path {
11294: my ($embed_file) = @_;
11295: $embed_file =~s{^/+}{};
11296: my @contents;
11297: if ($embed_file =~ m{/}) {
11298: @contents = split(/\//,$embed_file);
11299: } else {
11300: @contents = ($embed_file);
11301: }
11302: my $lastidx = scalar(@contents)-1;
11303: for (my $i=0; $i<=$lastidx; $i++) {
11304: $contents[$i]=~s{\\}{/}g;
11305: $contents[$i]=~s/\s+/\_/g;
11306: $contents[$i]=~s{[^/\w\.\-]}{}g;
11307: if ($i == $lastidx) {
11308: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11309: }
11310: }
11311: if ($lastidx > 0) {
11312: return join('/',@contents);
11313: } else {
11314: return $contents[0];
11315: }
11316: }
11317:
1.987 raeburn 11318: sub embedded_file_element {
1.1071 raeburn 11319: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11320: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11321: (ref($codebase) eq 'HASH'));
11322: my $output;
1.1071 raeburn 11323: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11324: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11325: }
11326: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11327: &escape($embed_file).'" />';
11328: unless (($context eq 'upload_embedded') &&
11329: ($mapping->{$embed_file} eq $embed_file)) {
11330: $output .='
11331: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11332: }
11333: my $attrib;
11334: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11335: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11336: }
11337: $output .=
11338: "\n\t\t".
11339: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11340: $attrib.'" />';
11341: if (exists($codebase->{$mapping->{$embed_file}})) {
11342: $output .=
11343: "\n\t\t".
11344: '<input name="codebase_'.$num.'" type="hidden" value="'.
11345: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11346: }
1.987 raeburn 11347: return $output;
1.660 raeburn 11348: }
11349:
1.1071 raeburn 11350: sub get_dependency_details {
11351: my ($currfile,$currsubfile,$embed_file) = @_;
11352: my ($size,$mtime,$showsize,$showmtime);
11353: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11354: if ($embed_file =~ m{/}) {
11355: my ($path,$fname) = split(/\//,$embed_file);
11356: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11357: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11358: }
11359: } else {
11360: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11361: ($size,$mtime) = @{$currfile->{$embed_file}};
11362: }
11363: }
11364: $showsize = $size/1024.0;
11365: $showsize = sprintf("%.1f",$showsize);
11366: if ($mtime > 0) {
11367: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11368: }
11369: }
11370: return ($showsize,$showmtime);
11371: }
11372:
11373: sub ask_embedded_js {
11374: return <<"END";
11375: <script type="text/javascript"">
11376: // <![CDATA[
11377: function toggleBrowse(counter) {
11378: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11379: var fileid = document.getElementById('embedded_item_'+counter);
11380: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11381: if (chkboxid.checked == true) {
11382: uploaddivid.style.display='block';
11383: } else {
11384: uploaddivid.style.display='none';
11385: fileid.value = '';
11386: }
11387: }
11388: // ]]>
11389: </script>
11390:
11391: END
11392: }
11393:
1.661 raeburn 11394: sub upload_embedded {
11395: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11396: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11397: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11398: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11399: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11400: my $orig_uploaded_filename =
11401: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11402: foreach my $type ('orig','ref','attrib','codebase') {
11403: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11404: $env{'form.embedded_'.$type.'_'.$i} =
11405: &unescape($env{'form.embedded_'.$type.'_'.$i});
11406: }
11407: }
1.661 raeburn 11408: my ($path,$fname) =
11409: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11410: # no path, whole string is fname
11411: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11412: $fname = &Apache::lonnet::clean_filename($fname);
11413: # See if there is anything left
11414: next if ($fname eq '');
11415:
11416: # Check if file already exists as a file or directory.
11417: my ($state,$msg);
11418: if ($context eq 'portfolio') {
11419: my $port_path = $dirpath;
11420: if ($group ne '') {
11421: $port_path = "groups/$group/$port_path";
11422: }
1.987 raeburn 11423: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11424: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11425: $dir_root,$port_path,$disk_quota,
11426: $current_disk_usage,$uname,$udom);
11427: if ($state eq 'will_exceed_quota'
1.984 raeburn 11428: || $state eq 'file_locked') {
1.661 raeburn 11429: $output .= $msg;
11430: next;
11431: }
11432: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11433: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11434: if ($state eq 'exists') {
11435: $output .= $msg;
11436: next;
11437: }
11438: }
11439: # Check if extension is valid
11440: if (($fname =~ /\.(\w+)$/) &&
11441: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 11442: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11443: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11444: next;
11445: } elsif (($fname =~ /\.(\w+)$/) &&
11446: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11447: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11448: next;
11449: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 11450: $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 11451: next;
11452: }
11453: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 11454: my $subdir = $path;
11455: $subdir =~ s{/+$}{};
1.661 raeburn 11456: if ($context eq 'portfolio') {
1.984 raeburn 11457: my $result;
11458: if ($state eq 'existingfile') {
11459: $result=
11460: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 11461: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11462: } else {
1.984 raeburn 11463: $result=
11464: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11465: $dirpath.
1.1075.2.35 raeburn 11466: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11467: if ($result !~ m|^/uploaded/|) {
11468: $output .= '<span class="LC_error">'
11469: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11470: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11471: .'</span><br />';
11472: next;
11473: } else {
1.987 raeburn 11474: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11475: $path.$fname.'</span>').'<br />';
1.984 raeburn 11476: }
1.661 raeburn 11477: }
1.1075.2.35 raeburn 11478: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
11479: my $extendedsubdir = $dirpath.'/'.$subdir;
11480: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11481: my $result =
1.1075.2.35 raeburn 11482: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11483: if ($result !~ m|^/uploaded/|) {
11484: $output .= '<span class="LC_error">'
11485: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11486: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11487: .'</span><br />';
11488: next;
11489: } else {
11490: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11491: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 11492: if ($context eq 'syllabus') {
11493: &Apache::lonnet::make_public_indefinitely($result);
11494: }
1.987 raeburn 11495: }
1.661 raeburn 11496: } else {
11497: # Save the file
11498: my $target = $env{'form.embedded_item_'.$i};
11499: my $fullpath = $dir_root.$dirpath.'/'.$path;
11500: my $dest = $fullpath.$fname;
11501: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11502: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11503: my $count;
11504: my $filepath = $dir_root;
1.1027 raeburn 11505: foreach my $subdir (@parts) {
11506: $filepath .= "/$subdir";
11507: if (!-e $filepath) {
1.661 raeburn 11508: mkdir($filepath,0770);
11509: }
11510: }
11511: my $fh;
11512: if (!open($fh,'>'.$dest)) {
11513: &Apache::lonnet::logthis('Failed to create '.$dest);
11514: $output .= '<span class="LC_error">'.
1.1071 raeburn 11515: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11516: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11517: '</span><br />';
11518: } else {
11519: if (!print $fh $env{'form.embedded_item_'.$i}) {
11520: &Apache::lonnet::logthis('Failed to write to '.$dest);
11521: $output .= '<span class="LC_error">'.
1.1071 raeburn 11522: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11523: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11524: '</span><br />';
11525: } else {
1.987 raeburn 11526: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11527: $url.'</span>').'<br />';
11528: unless ($context eq 'testbank') {
11529: $footer .= &mt('View embedded file: [_1]',
11530: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11531: }
11532: }
11533: close($fh);
11534: }
11535: }
11536: if ($env{'form.embedded_ref_'.$i}) {
11537: $pathchange{$i} = 1;
11538: }
11539: }
11540: if ($output) {
11541: $output = '<p>'.$output.'</p>';
11542: }
11543: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11544: $returnflag = 'ok';
1.1071 raeburn 11545: my $numpathchgs = scalar(keys(%pathchange));
11546: if ($numpathchgs > 0) {
1.987 raeburn 11547: if ($context eq 'portfolio') {
11548: $output .= '<p>'.&mt('or').'</p>';
11549: } elsif ($context eq 'testbank') {
1.1071 raeburn 11550: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11551: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11552: $returnflag = 'modify_orightml';
11553: }
11554: }
1.1071 raeburn 11555: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11556: }
11557:
11558: sub modify_html_form {
11559: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11560: my $end = 0;
11561: my $modifyform;
11562: if ($context eq 'upload_embedded') {
11563: return unless (ref($pathchange) eq 'HASH');
11564: if ($env{'form.number_embedded_items'}) {
11565: $end += $env{'form.number_embedded_items'};
11566: }
11567: if ($env{'form.number_pathchange_items'}) {
11568: $end += $env{'form.number_pathchange_items'};
11569: }
11570: if ($end) {
11571: for (my $i=0; $i<$end; $i++) {
11572: if ($i < $env{'form.number_embedded_items'}) {
11573: next unless($pathchange->{$i});
11574: }
11575: $modifyform .=
11576: &start_data_table_row().
11577: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11578: 'checked="checked" /></td>'.
11579: '<td>'.$env{'form.embedded_ref_'.$i}.
11580: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11581: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11582: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11583: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11584: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11585: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11586: '<td>'.$env{'form.embedded_orig_'.$i}.
11587: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11588: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11589: &end_data_table_row();
1.1071 raeburn 11590: }
1.987 raeburn 11591: }
11592: } else {
11593: $modifyform = $pathchgtable;
11594: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11595: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11596: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11597: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11598: }
11599: }
11600: if ($modifyform) {
1.1071 raeburn 11601: if ($actionurl eq '/adm/dependencies') {
11602: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11603: }
1.987 raeburn 11604: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11605: '<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".
11606: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11607: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11608: '</ol></p>'."\n".'<p>'.
11609: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11610: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11611: &start_data_table()."\n".
11612: &start_data_table_header_row().
11613: '<th>'.&mt('Change?').'</th>'.
11614: '<th>'.&mt('Current reference').'</th>'.
11615: '<th>'.&mt('Required reference').'</th>'.
11616: &end_data_table_header_row()."\n".
11617: $modifyform.
11618: &end_data_table().'<br />'."\n".$hiddenstate.
11619: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11620: '</form>'."\n";
11621: }
11622: return;
11623: }
11624:
11625: sub modify_html_refs {
1.1075.2.35 raeburn 11626: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11627: my $container;
11628: if ($context eq 'portfolio') {
11629: $container = $env{'form.container'};
11630: } elsif ($context eq 'coursedoc') {
11631: $container = $env{'form.primaryurl'};
1.1071 raeburn 11632: } elsif ($context eq 'manage_dependencies') {
11633: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11634: $container = "/$container";
1.1075.2.35 raeburn 11635: } elsif ($context eq 'syllabus') {
11636: $container = $url;
1.987 raeburn 11637: } else {
1.1027 raeburn 11638: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11639: }
11640: my (%allfiles,%codebase,$output,$content);
11641: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 11642: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11643: if (wantarray) {
11644: return ('',0,0);
11645: } else {
11646: return;
11647: }
11648: }
11649: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11650: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11651: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11652: if (wantarray) {
11653: return ('',0,0);
11654: } else {
11655: return;
11656: }
11657: }
1.987 raeburn 11658: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11659: if ($content eq '-1') {
11660: if (wantarray) {
11661: return ('',0,0);
11662: } else {
11663: return;
11664: }
11665: }
1.987 raeburn 11666: } else {
1.1071 raeburn 11667: unless ($container =~ /^\Q$dir_root\E/) {
11668: if (wantarray) {
11669: return ('',0,0);
11670: } else {
11671: return;
11672: }
11673: }
1.1075.2.128 raeburn 11674: if (open(my $fh,'<',$container)) {
1.987 raeburn 11675: $content = join('', <$fh>);
11676: close($fh);
11677: } else {
1.1071 raeburn 11678: if (wantarray) {
11679: return ('',0,0);
11680: } else {
11681: return;
11682: }
1.987 raeburn 11683: }
11684: }
11685: my ($count,$codebasecount) = (0,0);
11686: my $mm = new File::MMagic;
11687: my $mime_type = $mm->checktype_contents($content);
11688: if ($mime_type eq 'text/html') {
11689: my $parse_result =
11690: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11691: \%codebase,\$content);
11692: if ($parse_result eq 'ok') {
11693: foreach my $i (@changes) {
11694: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11695: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11696: if ($allfiles{$ref}) {
11697: my $newname = $orig;
11698: my ($attrib_regexp,$codebase);
1.1006 raeburn 11699: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11700: if ($attrib_regexp =~ /:/) {
11701: $attrib_regexp =~ s/\:/|/g;
11702: }
11703: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11704: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11705: $count += $numchg;
1.1075.2.35 raeburn 11706: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11707: delete($allfiles{$ref});
1.987 raeburn 11708: }
11709: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11710: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11711: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11712: $codebasecount ++;
11713: }
11714: }
11715: }
1.1075.2.35 raeburn 11716: my $skiprewrites;
1.987 raeburn 11717: if ($count || $codebasecount) {
11718: my $saveresult;
1.1071 raeburn 11719: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11720: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11721: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11722: if ($url eq $container) {
11723: my ($fname) = ($container =~ m{/([^/]+)$});
11724: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11725: $count,'<span class="LC_filename">'.
1.1071 raeburn 11726: $fname.'</span>').'</p>';
1.987 raeburn 11727: } else {
11728: $output = '<p class="LC_error">'.
11729: &mt('Error: update failed for: [_1].',
11730: '<span class="LC_filename">'.
11731: $container.'</span>').'</p>';
11732: }
1.1075.2.35 raeburn 11733: if ($context eq 'syllabus') {
11734: unless ($saveresult eq 'ok') {
11735: $skiprewrites = 1;
11736: }
11737: }
1.987 raeburn 11738: } else {
1.1075.2.128 raeburn 11739: if (open(my $fh,'>',$container)) {
1.987 raeburn 11740: print $fh $content;
11741: close($fh);
11742: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11743: $count,'<span class="LC_filename">'.
11744: $container.'</span>').'</p>';
1.661 raeburn 11745: } else {
1.987 raeburn 11746: $output = '<p class="LC_error">'.
11747: &mt('Error: could not update [_1].',
11748: '<span class="LC_filename">'.
11749: $container.'</span>').'</p>';
1.661 raeburn 11750: }
11751: }
11752: }
1.1075.2.35 raeburn 11753: if (($context eq 'syllabus') && (!$skiprewrites)) {
11754: my ($actionurl,$state);
11755: $actionurl = "/public/$udom/$uname/syllabus";
11756: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11757: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11758: \%codebase,
11759: {'context' => 'rewrites',
11760: 'ignore_remote_references' => 1,});
11761: if (ref($mapping) eq 'HASH') {
11762: my $rewrites = 0;
11763: foreach my $key (keys(%{$mapping})) {
11764: next if ($key =~ m{^https?://});
11765: my $ref = $mapping->{$key};
11766: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11767: my $attrib;
11768: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11769: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11770: }
11771: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11772: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11773: $rewrites += $numchg;
11774: }
11775: }
11776: if ($rewrites) {
11777: my $saveresult;
11778: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11779: if ($url eq $container) {
11780: my ($fname) = ($container =~ m{/([^/]+)$});
11781: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11782: $count,'<span class="LC_filename">'.
11783: $fname.'</span>').'</p>';
11784: } else {
11785: $output .= '<p class="LC_error">'.
11786: &mt('Error: could not update links in [_1].',
11787: '<span class="LC_filename">'.
11788: $container.'</span>').'</p>';
11789:
11790: }
11791: }
11792: }
11793: }
1.987 raeburn 11794: } else {
11795: &logthis('Failed to parse '.$container.
11796: ' to modify references: '.$parse_result);
1.661 raeburn 11797: }
11798: }
1.1071 raeburn 11799: if (wantarray) {
11800: return ($output,$count,$codebasecount);
11801: } else {
11802: return $output;
11803: }
1.661 raeburn 11804: }
11805:
11806: sub check_for_existing {
11807: my ($path,$fname,$element) = @_;
11808: my ($state,$msg);
11809: if (-d $path.'/'.$fname) {
11810: $state = 'exists';
11811: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11812: } elsif (-e $path.'/'.$fname) {
11813: $state = 'exists';
11814: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11815: }
11816: if ($state eq 'exists') {
11817: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11818: }
11819: return ($state,$msg);
11820: }
11821:
11822: sub check_for_upload {
11823: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11824: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11825: my $filesize = length($env{'form.'.$element});
11826: if (!$filesize) {
11827: my $msg = '<span class="LC_error">'.
11828: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11829: '<span class="LC_filename">'.$fname.'</span>',
11830: $filesize).'<br />'.
1.1007 raeburn 11831: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11832: '</span>';
11833: return ('zero_bytes',$msg);
11834: }
11835: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11836: my $getpropath = 1;
1.1021 raeburn 11837: my ($dirlistref,$listerror) =
11838: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11839: my $found_file = 0;
11840: my $locked_file = 0;
1.991 raeburn 11841: my @lockers;
11842: my $navmap;
11843: if ($env{'request.course.id'}) {
11844: $navmap = Apache::lonnavmaps::navmap->new();
11845: }
1.1021 raeburn 11846: if (ref($dirlistref) eq 'ARRAY') {
11847: foreach my $line (@{$dirlistref}) {
11848: my ($file_name,$rest)=split(/\&/,$line,2);
11849: if ($file_name eq $fname){
11850: $file_name = $path.$file_name;
11851: if ($group ne '') {
11852: $file_name = $group.$file_name;
11853: }
11854: $found_file = 1;
11855: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11856: foreach my $lock (@lockers) {
11857: if (ref($lock) eq 'ARRAY') {
11858: my ($symb,$crsid) = @{$lock};
11859: if ($crsid eq $env{'request.course.id'}) {
11860: if (ref($navmap)) {
11861: my $res = $navmap->getBySymb($symb);
11862: foreach my $part (@{$res->parts()}) {
11863: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11864: unless (($slot_status == $res->RESERVED) ||
11865: ($slot_status == $res->RESERVED_LOCATION)) {
11866: $locked_file = 1;
11867: }
1.991 raeburn 11868: }
1.1021 raeburn 11869: } else {
11870: $locked_file = 1;
1.991 raeburn 11871: }
11872: } else {
11873: $locked_file = 1;
11874: }
11875: }
1.1021 raeburn 11876: }
11877: } else {
11878: my @info = split(/\&/,$rest);
11879: my $currsize = $info[6]/1000;
11880: if ($currsize < $filesize) {
11881: my $extra = $filesize - $currsize;
11882: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 11883: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11884: &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 11885: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11886: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11887: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11888: return ('will_exceed_quota',$msg);
11889: }
1.984 raeburn 11890: }
11891: }
1.661 raeburn 11892: }
11893: }
11894: }
11895: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 11896: my $msg = '<p class="LC_warning">'.
11897: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
11898: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11899: return ('will_exceed_quota',$msg);
11900: } elsif ($found_file) {
11901: if ($locked_file) {
1.1075.2.69 raeburn 11902: my $msg = '<p class="LC_warning">';
1.661 raeburn 11903: $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 11904: $msg .= '</p>';
1.661 raeburn 11905: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11906: return ('file_locked',$msg);
11907: } else {
1.1075.2.69 raeburn 11908: my $msg = '<p class="LC_error">';
1.984 raeburn 11909: $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 11910: $msg .= '</p>';
1.984 raeburn 11911: return ('existingfile',$msg);
1.661 raeburn 11912: }
11913: }
11914: }
11915:
1.987 raeburn 11916: sub check_for_traversal {
11917: my ($path,$url,$toplevel) = @_;
11918: my @parts=split(/\//,$path);
11919: my $cleanpath;
11920: my $fullpath = $url;
11921: for (my $i=0;$i<@parts;$i++) {
11922: next if ($parts[$i] eq '.');
11923: if ($parts[$i] eq '..') {
11924: $fullpath =~ s{([^/]+/)$}{};
11925: } else {
11926: $fullpath .= $parts[$i].'/';
11927: }
11928: }
11929: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11930: $cleanpath = $1;
11931: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11932: my $curr_toprel = $1;
11933: my @parts = split(/\//,$curr_toprel);
11934: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11935: my @urlparts = split(/\//,$url_toprel);
11936: my $doubledots;
11937: my $startdiff = -1;
11938: for (my $i=0; $i<@urlparts; $i++) {
11939: if ($startdiff == -1) {
11940: unless ($urlparts[$i] eq $parts[$i]) {
11941: $startdiff = $i;
11942: $doubledots .= '../';
11943: }
11944: } else {
11945: $doubledots .= '../';
11946: }
11947: }
11948: if ($startdiff > -1) {
11949: $cleanpath = $doubledots;
11950: for (my $i=$startdiff; $i<@parts; $i++) {
11951: $cleanpath .= $parts[$i].'/';
11952: }
11953: }
11954: }
11955: $cleanpath =~ s{(/)$}{};
11956: return $cleanpath;
11957: }
1.31 albertel 11958:
1.1053 raeburn 11959: sub is_archive_file {
11960: my ($mimetype) = @_;
11961: if (($mimetype eq 'application/octet-stream') ||
11962: ($mimetype eq 'application/x-stuffit') ||
11963: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11964: return 1;
11965: }
11966: return;
11967: }
11968:
11969: sub decompress_form {
1.1065 raeburn 11970: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11971: my %lt = &Apache::lonlocal::texthash (
11972: this => 'This file is an archive file.',
1.1067 raeburn 11973: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11974: itsc => 'Its contents are as follows:',
1.1053 raeburn 11975: youm => 'You may wish to extract its contents.',
11976: extr => 'Extract contents',
1.1067 raeburn 11977: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11978: proa => 'Process automatically?',
1.1053 raeburn 11979: yes => 'Yes',
11980: no => 'No',
1.1067 raeburn 11981: fold => 'Title for folder containing movie',
11982: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11983: );
1.1065 raeburn 11984: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11985: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11986: my $info = &list_archive_contents($fileloc,\@paths);
11987: if (@paths) {
11988: foreach my $path (@paths) {
11989: $path =~ s{^/}{};
1.1067 raeburn 11990: if ($path =~ m{^([^/]+)/$}) {
11991: $topdir = $1;
11992: }
1.1065 raeburn 11993: if ($path =~ m{^([^/]+)/}) {
11994: $toplevel{$1} = $path;
11995: } else {
11996: $toplevel{$path} = $path;
11997: }
11998: }
11999: }
1.1067 raeburn 12000: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 12001: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12002: "$topdir/media/",
12003: "$topdir/media/$topdir.mp4",
12004: "$topdir/media/FirstFrame.png",
12005: "$topdir/media/player.swf",
12006: "$topdir/media/swfobject.js",
12007: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 12008: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 12009: "$topdir/$topdir.mp4",
12010: "$topdir/$topdir\_config.xml",
12011: "$topdir/$topdir\_controller.swf",
12012: "$topdir/$topdir\_embed.css",
12013: "$topdir/$topdir\_First_Frame.png",
12014: "$topdir/$topdir\_player.html",
12015: "$topdir/$topdir\_Thumbnails.png",
12016: "$topdir/playerProductInstall.swf",
12017: "$topdir/scripts/",
12018: "$topdir/scripts/config_xml.js",
12019: "$topdir/scripts/handlebars.js",
12020: "$topdir/scripts/jquery-1.7.1.min.js",
12021: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12022: "$topdir/scripts/modernizr.js",
12023: "$topdir/scripts/player-min.js",
12024: "$topdir/scripts/swfobject.js",
12025: "$topdir/skins/",
12026: "$topdir/skins/configuration_express.xml",
12027: "$topdir/skins/express_show/",
12028: "$topdir/skins/express_show/player-min.css",
12029: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 12030: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12031: "$topdir/$topdir.mp4",
12032: "$topdir/$topdir\_config.xml",
12033: "$topdir/$topdir\_controller.swf",
12034: "$topdir/$topdir\_embed.css",
12035: "$topdir/$topdir\_First_Frame.png",
12036: "$topdir/$topdir\_player.html",
12037: "$topdir/$topdir\_Thumbnails.png",
12038: "$topdir/playerProductInstall.swf",
12039: "$topdir/scripts/",
12040: "$topdir/scripts/config_xml.js",
12041: "$topdir/scripts/techsmith-smart-player.min.js",
12042: "$topdir/skins/",
12043: "$topdir/skins/configuration_express.xml",
12044: "$topdir/skins/express_show/",
12045: "$topdir/skins/express_show/spritesheet.min.css",
12046: "$topdir/skins/express_show/spritesheet.png",
12047: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 12048: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12049: if (@diffs == 0) {
1.1075.2.59 raeburn 12050: $is_camtasia = 6;
12051: } else {
1.1075.2.81 raeburn 12052: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 12053: if (@diffs == 0) {
12054: $is_camtasia = 8;
1.1075.2.81 raeburn 12055: } else {
12056: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12057: if (@diffs == 0) {
12058: $is_camtasia = 8;
12059: }
1.1075.2.59 raeburn 12060: }
1.1067 raeburn 12061: }
12062: }
12063: my $output;
12064: if ($is_camtasia) {
12065: $output = <<"ENDCAM";
12066: <script type="text/javascript" language="Javascript">
12067: // <![CDATA[
12068:
12069: function camtasiaToggle() {
12070: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12071: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 12072: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12073: document.getElementById('camtasia_titles').style.display='block';
12074: } else {
12075: document.getElementById('camtasia_titles').style.display='none';
12076: }
12077: }
12078: }
12079: return;
12080: }
12081:
12082: // ]]>
12083: </script>
12084: <p>$lt{'camt'}</p>
12085: ENDCAM
1.1065 raeburn 12086: } else {
1.1067 raeburn 12087: $output = '<p>'.$lt{'this'};
12088: if ($info eq '') {
12089: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12090: } else {
12091: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12092: '<div><pre>'.$info.'</pre></div>';
12093: }
1.1065 raeburn 12094: }
1.1067 raeburn 12095: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12096: my $duplicates;
12097: my $num = 0;
12098: if (ref($dirlist) eq 'ARRAY') {
12099: foreach my $item (@{$dirlist}) {
12100: if (ref($item) eq 'ARRAY') {
12101: if (exists($toplevel{$item->[0]})) {
12102: $duplicates .=
12103: &start_data_table_row().
12104: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12105: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12106: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12107: 'value="1" />'.&mt('Yes').'</label>'.
12108: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12109: '<td>'.$item->[0].'</td>';
12110: if ($item->[2]) {
12111: $duplicates .= '<td>'.&mt('Directory').'</td>';
12112: } else {
12113: $duplicates .= '<td>'.&mt('File').'</td>';
12114: }
12115: $duplicates .= '<td>'.$item->[3].'</td>'.
12116: '<td>'.
12117: &Apache::lonlocal::locallocaltime($item->[4]).
12118: '</td>'.
12119: &end_data_table_row();
12120: $num ++;
12121: }
12122: }
12123: }
12124: }
12125: my $itemcount;
12126: if (@paths > 0) {
12127: $itemcount = scalar(@paths);
12128: } else {
12129: $itemcount = 1;
12130: }
1.1067 raeburn 12131: if ($is_camtasia) {
12132: $output .= $lt{'auto'}.'<br />'.
12133: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 12134: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12135: $lt{'yes'}.'</label> <label>'.
12136: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12137: $lt{'no'}.'</label></span><br />'.
12138: '<div id="camtasia_titles" style="display:block">'.
12139: &Apache::lonhtmlcommon::start_pick_box().
12140: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12141: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12142: &Apache::lonhtmlcommon::row_closure().
12143: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12144: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12145: &Apache::lonhtmlcommon::row_closure(1).
12146: &Apache::lonhtmlcommon::end_pick_box().
12147: '</div>';
12148: }
1.1065 raeburn 12149: $output .=
12150: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12151: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12152: "\n";
1.1065 raeburn 12153: if ($duplicates ne '') {
12154: $output .= '<p><span class="LC_warning">'.
12155: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12156: &start_data_table().
12157: &start_data_table_header_row().
12158: '<th>'.&mt('Overwrite?').'</th>'.
12159: '<th>'.&mt('Name').'</th>'.
12160: '<th>'.&mt('Type').'</th>'.
12161: '<th>'.&mt('Size').'</th>'.
12162: '<th>'.&mt('Last modified').'</th>'.
12163: &end_data_table_header_row().
12164: $duplicates.
12165: &end_data_table().
12166: '</p>';
12167: }
1.1067 raeburn 12168: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12169: if (ref($hiddenelements) eq 'HASH') {
12170: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12171: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12172: }
12173: }
12174: $output .= <<"END";
1.1067 raeburn 12175: <br />
1.1053 raeburn 12176: <input type="submit" name="decompress" value="$lt{'extr'}" />
12177: </form>
12178: $noextract
12179: END
12180: return $output;
12181: }
12182:
1.1065 raeburn 12183: sub decompression_utility {
12184: my ($program) = @_;
12185: my @utilities = ('tar','gunzip','bunzip2','unzip');
12186: my $location;
12187: if (grep(/^\Q$program\E$/,@utilities)) {
12188: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12189: '/usr/sbin/') {
12190: if (-x $dir.$program) {
12191: $location = $dir.$program;
12192: last;
12193: }
12194: }
12195: }
12196: return $location;
12197: }
12198:
12199: sub list_archive_contents {
12200: my ($file,$pathsref) = @_;
12201: my (@cmd,$output);
12202: my $needsregexp;
12203: if ($file =~ /\.zip$/) {
12204: @cmd = (&decompression_utility('unzip'),"-l");
12205: $needsregexp = 1;
12206: } elsif (($file =~ m/\.tar\.gz$/) ||
12207: ($file =~ /\.tgz$/)) {
12208: @cmd = (&decompression_utility('tar'),"-ztf");
12209: } elsif ($file =~ /\.tar\.bz2$/) {
12210: @cmd = (&decompression_utility('tar'),"-jtf");
12211: } elsif ($file =~ m|\.tar$|) {
12212: @cmd = (&decompression_utility('tar'),"-tf");
12213: }
12214: if (@cmd) {
12215: undef($!);
12216: undef($@);
12217: if (open(my $fh,"-|", @cmd, $file)) {
12218: while (my $line = <$fh>) {
12219: $output .= $line;
12220: chomp($line);
12221: my $item;
12222: if ($needsregexp) {
12223: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12224: } else {
12225: $item = $line;
12226: }
12227: if ($item ne '') {
12228: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12229: push(@{$pathsref},$item);
12230: }
12231: }
12232: }
12233: close($fh);
12234: }
12235: }
12236: return $output;
12237: }
12238:
1.1053 raeburn 12239: sub decompress_uploaded_file {
12240: my ($file,$dir) = @_;
12241: &Apache::lonnet::appenv({'cgi.file' => $file});
12242: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12243: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12244: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12245: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12246: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12247: my $decompressed = $env{'cgi.decompressed'};
12248: &Apache::lonnet::delenv('cgi.file');
12249: &Apache::lonnet::delenv('cgi.dir');
12250: &Apache::lonnet::delenv('cgi.decompressed');
12251: return ($decompressed,$result);
12252: }
12253:
1.1055 raeburn 12254: sub process_decompression {
12255: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 12256: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12257: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12258: &mt('Unexpected file path.').'</p>'."\n";
12259: }
12260: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12261: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12262: &mt('Unexpected course context.').'</p>'."\n";
12263: }
12264: unless ($file eq &Apache::lonnet::clean_filename($file)) {
12265: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12266: &mt('Filename contained unexpected characters.').'</p>'."\n";
12267: }
1.1055 raeburn 12268: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 12269: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 12270: $error = &mt('Filename not a supported archive file type.').
12271: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12272: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12273: } else {
12274: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12275: if ($docuhome eq 'no_host') {
12276: $error = &mt('Could not determine home server for course.');
12277: } else {
12278: my @ids=&Apache::lonnet::current_machine_ids();
12279: my $currdir = "$dir_root/$destination";
12280: if (grep(/^\Q$docuhome\E$/,@ids)) {
12281: $dir = &LONCAPA::propath($docudom,$docuname).
12282: "$dir_root/$destination";
12283: } else {
12284: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12285: "$dir_root/$docudom/$docuname/$destination";
12286: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12287: $error = &mt('Archive file not found.');
12288: }
12289: }
1.1065 raeburn 12290: my (@to_overwrite,@to_skip);
12291: if ($env{'form.archive_overwrite_total'} > 0) {
12292: my $total = $env{'form.archive_overwrite_total'};
12293: for (my $i=0; $i<$total; $i++) {
12294: if ($env{'form.archive_overwrite_'.$i} == 1) {
12295: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12296: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12297: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12298: }
12299: }
12300: }
12301: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 12302: my $numoverwrite = scalar(@to_overwrite);
12303: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12304: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12305: } elsif ($dir eq '') {
1.1055 raeburn 12306: $error = &mt('Directory containing archive file unavailable.');
12307: } elsif (!$error) {
1.1065 raeburn 12308: my ($decompressed,$display);
1.1075.2.128 raeburn 12309: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12310: my $tempdir = time.'_'.$$.int(rand(10000));
12311: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 12312: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12313: ($decompressed,$display) =
12314: &decompress_uploaded_file($file,"$dir/$tempdir");
12315: foreach my $item (@to_skip) {
12316: if (($item ne '') && ($item !~ /\.\./)) {
12317: if (-f "$dir/$tempdir/$item") {
12318: unlink("$dir/$tempdir/$item");
12319: } elsif (-d "$dir/$tempdir/$item") {
12320: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
12321: }
12322: }
12323: }
12324: foreach my $item (@to_overwrite) {
12325: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12326: if (($item ne '') && ($item !~ /\.\./)) {
12327: if (-f "$dir/$item") {
12328: unlink("$dir/$item");
12329: } elsif (-d "$dir/$item") {
12330: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
12331: }
12332: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12333: }
1.1065 raeburn 12334: }
12335: }
1.1075.2.128 raeburn 12336: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
12337: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
12338: }
1.1065 raeburn 12339: }
12340: } else {
12341: ($decompressed,$display) =
12342: &decompress_uploaded_file($file,$dir);
12343: }
1.1055 raeburn 12344: if ($decompressed eq 'ok') {
1.1065 raeburn 12345: $output = '<p class="LC_info">'.
12346: &mt('Files extracted successfully from archive.').
12347: '</p>'."\n";
1.1055 raeburn 12348: my ($warning,$result,@contents);
12349: my ($newdirlistref,$newlisterror) =
12350: &Apache::lonnet::dirlist($currdir,$docudom,
12351: $docuname,1);
12352: my (%is_dir,%changes,@newitems);
12353: my $dirptr = 16384;
1.1065 raeburn 12354: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12355: foreach my $dir_line (@{$newdirlistref}) {
12356: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 12357: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12358: push(@newitems,$item);
12359: if ($dirptr&$testdir) {
12360: $is_dir{$item} = 1;
12361: }
12362: $changes{$item} = 1;
12363: }
12364: }
12365: }
12366: if (keys(%changes) > 0) {
12367: foreach my $item (sort(@newitems)) {
12368: if ($changes{$item}) {
12369: push(@contents,$item);
12370: }
12371: }
12372: }
12373: if (@contents > 0) {
1.1067 raeburn 12374: my $wantform;
12375: unless ($env{'form.autoextract_camtasia'}) {
12376: $wantform = 1;
12377: }
1.1056 raeburn 12378: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12379: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12380: $currdir,\%is_dir,
12381: \%children,\%parent,
1.1056 raeburn 12382: \@contents,\%dirorder,
12383: \%titles,$wantform);
1.1055 raeburn 12384: if ($datatable ne '') {
12385: $output .= &archive_options_form('decompressed',$datatable,
12386: $count,$hiddenelem);
1.1065 raeburn 12387: my $startcount = 6;
1.1055 raeburn 12388: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12389: \%titles,\%children);
1.1055 raeburn 12390: }
1.1067 raeburn 12391: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 12392: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12393: my %displayed;
12394: my $total = 1;
12395: $env{'form.archive_directory'} = [];
12396: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12397: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12398: $path =~ s{/$}{};
12399: my $item;
12400: if ($path ne '') {
12401: $item = "$path/$titles{$i}";
12402: } else {
12403: $item = $titles{$i};
12404: }
12405: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12406: if ($item eq $contents[0]) {
12407: push(@{$env{'form.archive_directory'}},$i);
12408: $env{'form.archive_'.$i} = 'display';
12409: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12410: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 12411: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12412: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12413: $env{'form.archive_'.$i} = 'display';
12414: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12415: $displayed{'web'} = $i;
12416: } else {
1.1075.2.59 raeburn 12417: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12418: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12419: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12420: push(@{$env{'form.archive_directory'}},$i);
12421: }
12422: $env{'form.archive_'.$i} = 'dependency';
12423: }
12424: $total ++;
12425: }
12426: for (my $i=1; $i<$total; $i++) {
12427: next if ($i == $displayed{'web'});
12428: next if ($i == $displayed{'folder'});
12429: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12430: }
12431: $env{'form.phase'} = 'decompress_cleanup';
12432: $env{'form.archivedelete'} = 1;
12433: $env{'form.archive_count'} = $total-1;
12434: $output .=
12435: &process_extracted_files('coursedocs',$docudom,
12436: $docuname,$destination,
12437: $dir_root,$hiddenelem);
12438: }
1.1055 raeburn 12439: } else {
12440: $warning = &mt('No new items extracted from archive file.');
12441: }
12442: } else {
12443: $output = $display;
12444: $error = &mt('An error occurred during extraction from the archive file.');
12445: }
12446: }
12447: }
12448: }
12449: if ($error) {
12450: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12451: $error.'</p>'."\n";
12452: }
12453: if ($warning) {
12454: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12455: }
12456: return $output;
12457: }
12458:
12459: sub get_extracted {
1.1056 raeburn 12460: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12461: $titles,$wantform) = @_;
1.1055 raeburn 12462: my $count = 0;
12463: my $depth = 0;
12464: my $datatable;
1.1056 raeburn 12465: my @hierarchy;
1.1055 raeburn 12466: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12467: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12468: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12469: foreach my $item (@{$contents}) {
12470: $count ++;
1.1056 raeburn 12471: @{$dirorder->{$count}} = @hierarchy;
12472: $titles->{$count} = $item;
1.1055 raeburn 12473: &archive_hierarchy($depth,$count,$parent,$children);
12474: if ($wantform) {
12475: $datatable .= &archive_row($is_dir->{$item},$item,
12476: $currdir,$depth,$count);
12477: }
12478: if ($is_dir->{$item}) {
12479: $depth ++;
1.1056 raeburn 12480: push(@hierarchy,$count);
12481: $parent->{$depth} = $count;
1.1055 raeburn 12482: $datatable .=
12483: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12484: \$depth,\$count,\@hierarchy,$dirorder,
12485: $children,$parent,$titles,$wantform);
1.1055 raeburn 12486: $depth --;
1.1056 raeburn 12487: pop(@hierarchy);
1.1055 raeburn 12488: }
12489: }
12490: return ($count,$datatable);
12491: }
12492:
12493: sub recurse_extracted_archive {
1.1056 raeburn 12494: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12495: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12496: my $result='';
1.1056 raeburn 12497: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12498: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12499: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12500: return $result;
12501: }
12502: my $dirptr = 16384;
12503: my ($newdirlistref,$newlisterror) =
12504: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12505: if (ref($newdirlistref) eq 'ARRAY') {
12506: foreach my $dir_line (@{$newdirlistref}) {
12507: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12508: unless ($item =~ /^\.+$/) {
12509: $$count ++;
1.1056 raeburn 12510: @{$dirorder->{$$count}} = @{$hierarchy};
12511: $titles->{$$count} = $item;
1.1055 raeburn 12512: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12513:
1.1055 raeburn 12514: my $is_dir;
12515: if ($dirptr&$testdir) {
12516: $is_dir = 1;
12517: }
12518: if ($wantform) {
12519: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12520: }
12521: if ($is_dir) {
12522: $$depth ++;
1.1056 raeburn 12523: push(@{$hierarchy},$$count);
12524: $parent->{$$depth} = $$count;
1.1055 raeburn 12525: $result .=
12526: &recurse_extracted_archive("$currdir/$item",$docudom,
12527: $docuname,$depth,$count,
1.1056 raeburn 12528: $hierarchy,$dirorder,$children,
12529: $parent,$titles,$wantform);
1.1055 raeburn 12530: $$depth --;
1.1056 raeburn 12531: pop(@{$hierarchy});
1.1055 raeburn 12532: }
12533: }
12534: }
12535: }
12536: return $result;
12537: }
12538:
12539: sub archive_hierarchy {
12540: my ($depth,$count,$parent,$children) =@_;
12541: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12542: if (exists($parent->{$depth})) {
12543: $children->{$parent->{$depth}} .= $count.':';
12544: }
12545: }
12546: return;
12547: }
12548:
12549: sub archive_row {
12550: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12551: my ($name) = ($item =~ m{([^/]+)$});
12552: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12553: 'display' => 'Add as file',
1.1055 raeburn 12554: 'dependency' => 'Include as dependency',
12555: 'discard' => 'Discard',
12556: );
12557: if ($is_dir) {
1.1059 raeburn 12558: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12559: }
1.1056 raeburn 12560: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12561: my $offset = 0;
1.1055 raeburn 12562: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12563: $offset ++;
1.1065 raeburn 12564: if ($action ne 'display') {
12565: $offset ++;
12566: }
1.1055 raeburn 12567: $output .= '<td><span class="LC_nobreak">'.
12568: '<label><input type="radio" name="archive_'.$count.
12569: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12570: my $text = $choices{$action};
12571: if ($is_dir) {
12572: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12573: if ($action eq 'display') {
1.1059 raeburn 12574: $text = &mt('Add as folder');
1.1055 raeburn 12575: }
1.1056 raeburn 12576: } else {
12577: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12578:
12579: }
12580: $output .= ' /> '.$choices{$action}.'</label></span>';
12581: if ($action eq 'dependency') {
12582: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12583: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12584: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12585: '<option value=""></option>'."\n".
12586: '</select>'."\n".
12587: '</div>';
1.1059 raeburn 12588: } elsif ($action eq 'display') {
12589: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12590: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12591: '</div>';
1.1055 raeburn 12592: }
1.1056 raeburn 12593: $output .= '</td>';
1.1055 raeburn 12594: }
12595: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12596: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12597: for (my $i=0; $i<$depth; $i++) {
12598: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12599: }
12600: if ($is_dir) {
12601: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12602: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12603: } else {
12604: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12605: }
12606: $output .= ' '.$name.'</td>'."\n".
12607: &end_data_table_row();
12608: return $output;
12609: }
12610:
12611: sub archive_options_form {
1.1065 raeburn 12612: my ($form,$display,$count,$hiddenelem) = @_;
12613: my %lt = &Apache::lonlocal::texthash(
12614: perm => 'Permanently remove archive file?',
12615: hows => 'How should each extracted item be incorporated in the course?',
12616: cont => 'Content actions for all',
12617: addf => 'Add as folder/file',
12618: incd => 'Include as dependency for a displayed file',
12619: disc => 'Discard',
12620: no => 'No',
12621: yes => 'Yes',
12622: save => 'Save',
12623: );
12624: my $output = <<"END";
12625: <form name="$form" method="post" action="">
12626: <p><span class="LC_nobreak">$lt{'perm'}
12627: <label>
12628: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12629: </label>
12630:
12631: <label>
12632: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12633: </span>
12634: </p>
12635: <input type="hidden" name="phase" value="decompress_cleanup" />
12636: <br />$lt{'hows'}
12637: <div class="LC_columnSection">
12638: <fieldset>
12639: <legend>$lt{'cont'}</legend>
12640: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12641: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12642: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12643: </fieldset>
12644: </div>
12645: END
12646: return $output.
1.1055 raeburn 12647: &start_data_table()."\n".
1.1065 raeburn 12648: $display."\n".
1.1055 raeburn 12649: &end_data_table()."\n".
12650: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12651: $hiddenelem.
1.1065 raeburn 12652: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12653: '</form>';
12654: }
12655:
12656: sub archive_javascript {
1.1056 raeburn 12657: my ($startcount,$numitems,$titles,$children) = @_;
12658: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12659: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12660: my $scripttag = <<START;
12661: <script type="text/javascript">
12662: // <![CDATA[
12663:
12664: function checkAll(form,prefix) {
12665: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12666: for (var i=0; i < form.elements.length; i++) {
12667: var id = form.elements[i].id;
12668: if ((id != '') && (id != undefined)) {
12669: if (idstr.test(id)) {
12670: if (form.elements[i].type == 'radio') {
12671: form.elements[i].checked = true;
1.1056 raeburn 12672: var nostart = i-$startcount;
1.1059 raeburn 12673: var offset = nostart%7;
12674: var count = (nostart-offset)/7;
1.1056 raeburn 12675: dependencyCheck(form,count,offset);
1.1055 raeburn 12676: }
12677: }
12678: }
12679: }
12680: }
12681:
12682: function propagateCheck(form,count) {
12683: if (count > 0) {
1.1059 raeburn 12684: var startelement = $startcount + ((count-1) * 7);
12685: for (var j=1; j<6; j++) {
12686: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12687: var item = startelement + j;
12688: if (form.elements[item].type == 'radio') {
12689: if (form.elements[item].checked) {
12690: containerCheck(form,count,j);
12691: break;
12692: }
1.1055 raeburn 12693: }
12694: }
12695: }
12696: }
12697: }
12698:
12699: numitems = $numitems
1.1056 raeburn 12700: var titles = new Array(numitems);
12701: var parents = new Array(numitems);
1.1055 raeburn 12702: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12703: parents[i] = new Array;
1.1055 raeburn 12704: }
1.1059 raeburn 12705: var maintitle = '$maintitle';
1.1055 raeburn 12706:
12707: START
12708:
1.1056 raeburn 12709: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12710: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12711: for (my $i=0; $i<@contents; $i ++) {
12712: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12713: }
12714: }
12715:
1.1056 raeburn 12716: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12717: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12718: }
12719:
1.1055 raeburn 12720: $scripttag .= <<END;
12721:
12722: function containerCheck(form,count,offset) {
12723: if (count > 0) {
1.1056 raeburn 12724: dependencyCheck(form,count,offset);
1.1059 raeburn 12725: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12726: form.elements[item].checked = true;
12727: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12728: if (parents[count].length > 0) {
12729: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12730: containerCheck(form,parents[count][j],offset);
12731: }
12732: }
12733: }
12734: }
12735: }
12736:
12737: function dependencyCheck(form,count,offset) {
12738: if (count > 0) {
1.1059 raeburn 12739: var chosen = (offset+$startcount)+7*(count-1);
12740: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12741: var currtype = form.elements[depitem].type;
12742: if (form.elements[chosen].value == 'dependency') {
12743: document.getElementById('arc_depon_'+count).style.display='block';
12744: form.elements[depitem].options.length = 0;
12745: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 12746: for (var i=1; i<=numitems; i++) {
12747: if (i == count) {
12748: continue;
12749: }
1.1059 raeburn 12750: var startelement = $startcount + (i-1) * 7;
12751: for (var j=1; j<6; j++) {
12752: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12753: var item = startelement + j;
12754: if (form.elements[item].type == 'radio') {
12755: if (form.elements[item].checked) {
12756: if (form.elements[item].value == 'display') {
12757: var n = form.elements[depitem].options.length;
12758: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12759: }
12760: }
12761: }
12762: }
12763: }
12764: }
12765: } else {
12766: document.getElementById('arc_depon_'+count).style.display='none';
12767: form.elements[depitem].options.length = 0;
12768: form.elements[depitem].options[0] = new Option('Select','',true,true);
12769: }
1.1059 raeburn 12770: titleCheck(form,count,offset);
1.1056 raeburn 12771: }
12772: }
12773:
12774: function propagateSelect(form,count,offset) {
12775: if (count > 0) {
1.1065 raeburn 12776: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12777: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12778: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12779: if (parents[count].length > 0) {
12780: for (var j=0; j<parents[count].length; j++) {
12781: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12782: }
12783: }
12784: }
12785: }
12786: }
1.1056 raeburn 12787:
12788: function containerSelect(form,count,offset,picked) {
12789: if (count > 0) {
1.1065 raeburn 12790: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12791: if (form.elements[item].type == 'radio') {
12792: if (form.elements[item].value == 'dependency') {
12793: if (form.elements[item+1].type == 'select-one') {
12794: for (var i=0; i<form.elements[item+1].options.length; i++) {
12795: if (form.elements[item+1].options[i].value == picked) {
12796: form.elements[item+1].selectedIndex = i;
12797: break;
12798: }
12799: }
12800: }
12801: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12802: if (parents[count].length > 0) {
12803: for (var j=0; j<parents[count].length; j++) {
12804: containerSelect(form,parents[count][j],offset,picked);
12805: }
12806: }
12807: }
12808: }
12809: }
12810: }
12811: }
12812:
1.1059 raeburn 12813: function titleCheck(form,count,offset) {
12814: if (count > 0) {
12815: var chosen = (offset+$startcount)+7*(count-1);
12816: var depitem = $startcount + ((count-1) * 7) + 2;
12817: var currtype = form.elements[depitem].type;
12818: if (form.elements[chosen].value == 'display') {
12819: document.getElementById('arc_title_'+count).style.display='block';
12820: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12821: document.getElementById('archive_title_'+count).value=maintitle;
12822: }
12823: } else {
12824: document.getElementById('arc_title_'+count).style.display='none';
12825: if (currtype == 'text') {
12826: document.getElementById('archive_title_'+count).value='';
12827: }
12828: }
12829: }
12830: return;
12831: }
12832:
1.1055 raeburn 12833: // ]]>
12834: </script>
12835: END
12836: return $scripttag;
12837: }
12838:
12839: sub process_extracted_files {
1.1067 raeburn 12840: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12841: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 12842: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 12843: my @ids=&Apache::lonnet::current_machine_ids();
12844: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12845: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12846: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12847: if (grep(/^\Q$docuhome\E$/,@ids)) {
12848: $prefix = &LONCAPA::propath($docudom,$docuname);
12849: $pathtocheck = "$dir_root/$destination";
12850: $dir = $dir_root;
12851: $ishome = 1;
12852: } else {
12853: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12854: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 12855: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 12856: }
12857: my $currdir = "$dir_root/$destination";
12858: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12859: if ($env{'form.folderpath'}) {
12860: my @items = split('&',$env{'form.folderpath'});
12861: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 12862: if ($env{'form.folderpath'} =~ /\:1$/) {
12863: $containers{'0'}='page';
12864: } else {
12865: $containers{'0'}='sequence';
12866: }
1.1055 raeburn 12867: }
12868: my @archdirs = &get_env_multiple('form.archive_directory');
12869: if ($numitems) {
12870: for (my $i=1; $i<=$numitems; $i++) {
12871: my $path = $env{'form.archive_content_'.$i};
12872: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12873: my $item = $1;
12874: $toplevelitems{$item} = $i;
12875: if (grep(/^\Q$i\E$/,@archdirs)) {
12876: $is_dir{$item} = 1;
12877: }
12878: }
12879: }
12880: }
1.1067 raeburn 12881: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12882: if (keys(%toplevelitems) > 0) {
12883: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12884: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12885: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12886: }
1.1066 raeburn 12887: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12888: if ($numitems) {
12889: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 12890: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12891: my $path = $env{'form.archive_content_'.$i};
12892: if ($path =~ /^\Q$pathtocheck\E/) {
12893: if ($env{'form.archive_'.$i} eq 'discard') {
12894: if ($prefix ne '' && $path ne '') {
12895: if (-e $prefix.$path) {
1.1066 raeburn 12896: if ((@archdirs > 0) &&
12897: (grep(/^\Q$i\E$/,@archdirs))) {
12898: $todeletedir{$prefix.$path} = 1;
12899: } else {
12900: $todelete{$prefix.$path} = 1;
12901: }
1.1055 raeburn 12902: }
12903: }
12904: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12905: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12906: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12907: $docstitle = $env{'form.archive_title_'.$i};
12908: if ($docstitle eq '') {
12909: $docstitle = $title;
12910: }
1.1055 raeburn 12911: $outer = 0;
1.1056 raeburn 12912: if (ref($dirorder{$i}) eq 'ARRAY') {
12913: if (@{$dirorder{$i}} > 0) {
12914: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12915: if ($env{'form.archive_'.$item} eq 'display') {
12916: $outer = $item;
12917: last;
12918: }
12919: }
12920: }
12921: }
12922: my ($errtext,$fatal) =
12923: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12924: '/'.$folders{$outer}.'.'.
12925: $containers{$outer});
12926: next if ($fatal);
12927: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12928: if ($context eq 'coursedocs') {
1.1056 raeburn 12929: $mapinner{$i} = time;
1.1055 raeburn 12930: $folders{$i} = 'default_'.$mapinner{$i};
12931: $containers{$i} = 'sequence';
12932: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12933: $folders{$i}.'.'.$containers{$i};
12934: my $newidx = &LONCAPA::map::getresidx();
12935: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12936: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12937: push(@LONCAPA::map::order,$newidx);
12938: my ($outtext,$errtext) =
12939: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12940: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12941: '.'.$containers{$outer},1,1);
1.1056 raeburn 12942: $newseqid{$i} = $newidx;
1.1067 raeburn 12943: unless ($errtext) {
1.1075.2.128 raeburn 12944: $result .= '<li>'.&mt('Folder: [_1] added to course',
12945: &HTML::Entities::encode($docstitle,'<>&"'))..
12946: '</li>'."\n";
1.1067 raeburn 12947: }
1.1055 raeburn 12948: }
12949: } else {
12950: if ($context eq 'coursedocs') {
12951: my $newidx=&LONCAPA::map::getresidx();
12952: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12953: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12954: $title;
1.1075.2.128 raeburn 12955: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
12956: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
12957: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 12958: }
1.1075.2.128 raeburn 12959: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12960: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
12961: }
12962: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12963: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
12964: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
12965: unless ($ishome) {
12966: my $fetch = "$newdest{$i}/$title";
12967: $fetch =~ s/^\Q$prefix$dir\E//;
12968: $prompttofetch{$fetch} = 1;
12969: }
12970: }
12971: }
12972: $LONCAPA::map::resources[$newidx]=
12973: $docstitle.':'.$url.':false:normal:res';
12974: push(@LONCAPA::map::order, $newidx);
12975: my ($outtext,$errtext)=
12976: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12977: $docuname.'/'.$folders{$outer}.
12978: '.'.$containers{$outer},1,1);
12979: unless ($errtext) {
12980: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
12981: $result .= '<li>'.&mt('File: [_1] added to course',
12982: &HTML::Entities::encode($docstitle,'<>&"')).
12983: '</li>'."\n";
12984: }
1.1067 raeburn 12985: }
1.1075.2.128 raeburn 12986: } else {
12987: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
12988: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 12989: }
1.1055 raeburn 12990: }
12991: }
1.1075.2.11 raeburn 12992: }
12993: } else {
1.1075.2.128 raeburn 12994: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
12995: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 12996: }
12997: }
12998: for (my $i=1; $i<=$numitems; $i++) {
12999: next unless ($env{'form.archive_'.$i} eq 'dependency');
13000: my $path = $env{'form.archive_content_'.$i};
13001: if ($path =~ /^\Q$pathtocheck\E/) {
13002: my ($title) = ($path =~ m{/([^/]+)$});
13003: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13004: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13005: if (ref($dirorder{$i}) eq 'ARRAY') {
13006: my ($itemidx,$fullpath,$relpath);
13007: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13008: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13009: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 13010: if ($dirorder{$i}->[$j] eq $container) {
13011: $itemidx = $j;
1.1056 raeburn 13012: }
13013: }
1.1075.2.11 raeburn 13014: }
13015: if ($itemidx eq '') {
13016: $itemidx = 0;
13017: }
13018: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13019: if ($mapinner{$referrer{$i}}) {
13020: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13021: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13022: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13023: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13024: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13025: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13026: if (!-e $fullpath) {
13027: mkdir($fullpath,0755);
1.1056 raeburn 13028: }
13029: }
1.1075.2.11 raeburn 13030: } else {
13031: last;
1.1056 raeburn 13032: }
1.1075.2.11 raeburn 13033: }
13034: }
13035: } elsif ($newdest{$referrer{$i}}) {
13036: $fullpath = $newdest{$referrer{$i}};
13037: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13038: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13039: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13040: last;
13041: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13042: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13043: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13044: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13045: if (!-e $fullpath) {
13046: mkdir($fullpath,0755);
1.1056 raeburn 13047: }
13048: }
1.1075.2.11 raeburn 13049: } else {
13050: last;
1.1056 raeburn 13051: }
1.1075.2.11 raeburn 13052: }
13053: }
13054: if ($fullpath ne '') {
13055: if (-e "$prefix$path") {
1.1075.2.128 raeburn 13056: unless (rename("$prefix$path","$fullpath/$title")) {
13057: $warning .= &mt('Failed to rename dependency').'<br />';
13058: }
1.1075.2.11 raeburn 13059: }
13060: if (-e "$fullpath/$title") {
13061: my $showpath;
13062: if ($relpath ne '') {
13063: $showpath = "$relpath/$title";
13064: } else {
13065: $showpath = "/$title";
1.1056 raeburn 13066: }
1.1075.2.128 raeburn 13067: $result .= '<li>'.&mt('[_1] included as a dependency',
13068: &HTML::Entities::encode($showpath,'<>&"')).
13069: '</li>'."\n";
13070: unless ($ishome) {
13071: my $fetch = "$fullpath/$title";
13072: $fetch =~ s/^\Q$prefix$dir\E//;
13073: $prompttofetch{$fetch} = 1;
13074: }
1.1055 raeburn 13075: }
13076: }
13077: }
1.1075.2.11 raeburn 13078: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13079: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 13080: &HTML::Entities::encode($path,'<>&"'),
13081: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13082: '<br />';
1.1055 raeburn 13083: }
13084: } else {
1.1075.2.128 raeburn 13085: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13086: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13087: }
13088: }
13089: if (keys(%todelete)) {
13090: foreach my $key (keys(%todelete)) {
13091: unlink($key);
1.1066 raeburn 13092: }
13093: }
13094: if (keys(%todeletedir)) {
13095: foreach my $key (keys(%todeletedir)) {
13096: rmdir($key);
13097: }
13098: }
13099: foreach my $dir (sort(keys(%is_dir))) {
13100: if (($pathtocheck ne '') && ($dir ne '')) {
13101: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13102: }
13103: }
1.1067 raeburn 13104: if ($result ne '') {
13105: $output .= '<ul>'."\n".
13106: $result."\n".
13107: '</ul>';
13108: }
13109: unless ($ishome) {
13110: my $replicationfail;
13111: foreach my $item (keys(%prompttofetch)) {
13112: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13113: unless ($fetchresult eq 'ok') {
13114: $replicationfail .= '<li>'.$item.'</li>'."\n";
13115: }
13116: }
13117: if ($replicationfail) {
13118: $output .= '<p class="LC_error">'.
13119: &mt('Course home server failed to retrieve:').'<ul>'.
13120: $replicationfail.
13121: '</ul></p>';
13122: }
13123: }
1.1055 raeburn 13124: } else {
13125: $warning = &mt('No items found in archive.');
13126: }
13127: if ($error) {
13128: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13129: $error.'</p>'."\n";
13130: }
13131: if ($warning) {
13132: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13133: }
13134: return $output;
13135: }
13136:
1.1066 raeburn 13137: sub cleanup_empty_dirs {
13138: my ($path) = @_;
13139: if (($path ne '') && (-d $path)) {
13140: if (opendir(my $dirh,$path)) {
13141: my @dircontents = grep(!/^\./,readdir($dirh));
13142: my $numitems = 0;
13143: foreach my $item (@dircontents) {
13144: if (-d "$path/$item") {
1.1075.2.28 raeburn 13145: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13146: if (-e "$path/$item") {
13147: $numitems ++;
13148: }
13149: } else {
13150: $numitems ++;
13151: }
13152: }
13153: if ($numitems == 0) {
13154: rmdir($path);
13155: }
13156: closedir($dirh);
13157: }
13158: }
13159: return;
13160: }
13161:
1.41 ng 13162: =pod
1.45 matthew 13163:
1.1075.2.56 raeburn 13164: =item * &get_folder_hierarchy()
1.1068 raeburn 13165:
13166: Provides hierarchy of names of folders/sub-folders containing the current
13167: item,
13168:
13169: Inputs: 3
13170: - $navmap - navmaps object
13171:
13172: - $map - url for map (either the trigger itself, or map containing
13173: the resource, which is the trigger).
13174:
13175: - $showitem - 1 => show title for map itself; 0 => do not show.
13176:
13177: Outputs: 1 @pathitems - array of folder/subfolder names.
13178:
13179: =cut
13180:
13181: sub get_folder_hierarchy {
13182: my ($navmap,$map,$showitem) = @_;
13183: my @pathitems;
13184: if (ref($navmap)) {
13185: my $mapres = $navmap->getResourceByUrl($map);
13186: if (ref($mapres)) {
13187: my $pcslist = $mapres->map_hierarchy();
13188: if ($pcslist ne '') {
13189: my @pcs = split(/,/,$pcslist);
13190: foreach my $pc (@pcs) {
13191: if ($pc == 1) {
1.1075.2.38 raeburn 13192: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13193: } else {
13194: my $res = $navmap->getByMapPc($pc);
13195: if (ref($res)) {
13196: my $title = $res->compTitle();
13197: $title =~ s/\W+/_/g;
13198: if ($title ne '') {
13199: push(@pathitems,$title);
13200: }
13201: }
13202: }
13203: }
13204: }
1.1071 raeburn 13205: if ($showitem) {
13206: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 13207: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13208: } else {
13209: my $maptitle = $mapres->compTitle();
13210: $maptitle =~ s/\W+/_/g;
13211: if ($maptitle ne '') {
13212: push(@pathitems,$maptitle);
13213: }
1.1068 raeburn 13214: }
13215: }
13216: }
13217: }
13218: return @pathitems;
13219: }
13220:
13221: =pod
13222:
1.1015 raeburn 13223: =item * &get_turnedin_filepath()
13224:
13225: Determines path in a user's portfolio file for storage of files uploaded
13226: to a specific essayresponse or dropbox item.
13227:
13228: Inputs: 3 required + 1 optional.
13229: $symb is symb for resource, $uname and $udom are for current user (required).
13230: $caller is optional (can be "submission", if routine is called when storing
13231: an upoaded file when "Submit Answer" button was pressed).
13232:
13233: Returns array containing $path and $multiresp.
13234: $path is path in portfolio. $multiresp is 1 if this resource contains more
13235: than one file upload item. Callers of routine should append partid as a
13236: subdirectory to $path in cases where $multiresp is 1.
13237:
13238: Called by: homework/essayresponse.pm and homework/structuretags.pm
13239:
13240: =cut
13241:
13242: sub get_turnedin_filepath {
13243: my ($symb,$uname,$udom,$caller) = @_;
13244: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13245: my $turnindir;
13246: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13247: $turnindir = $userhash{'turnindir'};
13248: my ($path,$multiresp);
13249: if ($turnindir eq '') {
13250: if ($caller eq 'submission') {
13251: $turnindir = &mt('turned in');
13252: $turnindir =~ s/\W+/_/g;
13253: my %newhash = (
13254: 'turnindir' => $turnindir,
13255: );
13256: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13257: }
13258: }
13259: if ($turnindir ne '') {
13260: $path = '/'.$turnindir.'/';
13261: my ($multipart,$turnin,@pathitems);
13262: my $navmap = Apache::lonnavmaps::navmap->new();
13263: if (defined($navmap)) {
13264: my $mapres = $navmap->getResourceByUrl($map);
13265: if (ref($mapres)) {
13266: my $pcslist = $mapres->map_hierarchy();
13267: if ($pcslist ne '') {
13268: foreach my $pc (split(/,/,$pcslist)) {
13269: my $res = $navmap->getByMapPc($pc);
13270: if (ref($res)) {
13271: my $title = $res->compTitle();
13272: $title =~ s/\W+/_/g;
13273: if ($title ne '') {
1.1075.2.48 raeburn 13274: if (($pc > 1) && (length($title) > 12)) {
13275: $title = substr($title,0,12);
13276: }
1.1015 raeburn 13277: push(@pathitems,$title);
13278: }
13279: }
13280: }
13281: }
13282: my $maptitle = $mapres->compTitle();
13283: $maptitle =~ s/\W+/_/g;
13284: if ($maptitle ne '') {
1.1075.2.48 raeburn 13285: if (length($maptitle) > 12) {
13286: $maptitle = substr($maptitle,0,12);
13287: }
1.1015 raeburn 13288: push(@pathitems,$maptitle);
13289: }
13290: unless ($env{'request.state'} eq 'construct') {
13291: my $res = $navmap->getBySymb($symb);
13292: if (ref($res)) {
13293: my $partlist = $res->parts();
13294: my $totaluploads = 0;
13295: if (ref($partlist) eq 'ARRAY') {
13296: foreach my $part (@{$partlist}) {
13297: my @types = $res->responseType($part);
13298: my @ids = $res->responseIds($part);
13299: for (my $i=0; $i < scalar(@ids); $i++) {
13300: if ($types[$i] eq 'essay') {
13301: my $partid = $part.'_'.$ids[$i];
13302: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13303: $totaluploads ++;
13304: }
13305: }
13306: }
13307: }
13308: if ($totaluploads > 1) {
13309: $multiresp = 1;
13310: }
13311: }
13312: }
13313: }
13314: } else {
13315: return;
13316: }
13317: } else {
13318: return;
13319: }
13320: my $restitle=&Apache::lonnet::gettitle($symb);
13321: $restitle =~ s/\W+/_/g;
13322: if ($restitle eq '') {
13323: $restitle = ($resurl =~ m{/[^/]+$});
13324: if ($restitle eq '') {
13325: $restitle = time;
13326: }
13327: }
1.1075.2.48 raeburn 13328: if (length($restitle) > 12) {
13329: $restitle = substr($restitle,0,12);
13330: }
1.1015 raeburn 13331: push(@pathitems,$restitle);
13332: $path .= join('/',@pathitems);
13333: }
13334: return ($path,$multiresp);
13335: }
13336:
13337: =pod
13338:
1.464 albertel 13339: =back
1.41 ng 13340:
1.112 bowersj2 13341: =head1 CSV Upload/Handling functions
1.38 albertel 13342:
1.41 ng 13343: =over 4
13344:
1.648 raeburn 13345: =item * &upfile_store($r)
1.41 ng 13346:
13347: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13348: needs $env{'form.upfile'}
1.41 ng 13349: returns $datatoken to be put into hidden field
13350:
13351: =cut
1.31 albertel 13352:
13353: sub upfile_store {
13354: my $r=shift;
1.258 albertel 13355: $env{'form.upfile'}=~s/\r/\n/gs;
13356: $env{'form.upfile'}=~s/\f/\n/gs;
13357: $env{'form.upfile'}=~s/\n+/\n/gs;
13358: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13359:
1.1075.2.128 raeburn 13360: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13361: '_enroll_'.$env{'request.course.id'}.'_'.
13362: time.'_'.$$);
13363: return if ($datatoken eq '');
13364:
1.31 albertel 13365: {
1.158 raeburn 13366: my $datafile = $r->dir_config('lonDaemons').
13367: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 13368: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13369: print $fh $env{'form.upfile'};
1.158 raeburn 13370: close($fh);
13371: }
1.31 albertel 13372: }
13373: return $datatoken;
13374: }
13375:
1.56 matthew 13376: =pod
13377:
1.1075.2.128 raeburn 13378: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13379:
13380: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 13381: $datatoken is the name to assign to the temporary file.
1.258 albertel 13382: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13383:
13384: =cut
1.31 albertel 13385:
13386: sub load_tmp_file {
1.1075.2.128 raeburn 13387: my ($r,$datatoken) = @_;
13388: return if ($datatoken eq '');
1.31 albertel 13389: my @studentdata=();
13390: {
1.158 raeburn 13391: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 13392: '/tmp/'.$datatoken.'.tmp';
13393: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 13394: @studentdata=<$fh>;
13395: close($fh);
13396: }
1.31 albertel 13397: }
1.258 albertel 13398: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13399: }
13400:
1.1075.2.128 raeburn 13401: sub valid_datatoken {
13402: my ($datatoken) = @_;
1.1075.2.131 raeburn 13403: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 13404: return $datatoken;
13405: }
13406: return;
13407: }
13408:
1.56 matthew 13409: =pod
13410:
1.648 raeburn 13411: =item * &upfile_record_sep()
1.41 ng 13412:
13413: Separate uploaded file into records
13414: returns array of records,
1.258 albertel 13415: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13416:
13417: =cut
1.31 albertel 13418:
13419: sub upfile_record_sep {
1.258 albertel 13420: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13421: } else {
1.248 albertel 13422: my @records;
1.258 albertel 13423: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13424: if ($line=~/^\s*$/) { next; }
13425: push(@records,$line);
13426: }
13427: return @records;
1.31 albertel 13428: }
13429: }
13430:
1.56 matthew 13431: =pod
13432:
1.648 raeburn 13433: =item * &record_sep($record)
1.41 ng 13434:
1.258 albertel 13435: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13436:
13437: =cut
13438:
1.263 www 13439: sub takeleft {
13440: my $index=shift;
13441: return substr('0000'.$index,-4,4);
13442: }
13443:
1.31 albertel 13444: sub record_sep {
13445: my $record=shift;
13446: my %components=();
1.258 albertel 13447: if ($env{'form.upfiletype'} eq 'xml') {
13448: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13449: my $i=0;
1.356 albertel 13450: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13451: $field=~s/^(\"|\')//;
13452: $field=~s/(\"|\')$//;
1.263 www 13453: $components{&takeleft($i)}=$field;
1.31 albertel 13454: $i++;
13455: }
1.258 albertel 13456: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13457: my $i=0;
1.356 albertel 13458: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13459: $field=~s/^(\"|\')//;
13460: $field=~s/(\"|\')$//;
1.263 www 13461: $components{&takeleft($i)}=$field;
1.31 albertel 13462: $i++;
13463: }
13464: } else {
1.561 www 13465: my $separator=',';
1.480 banghart 13466: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13467: $separator=';';
1.480 banghart 13468: }
1.31 albertel 13469: my $i=0;
1.561 www 13470: # the character we are looking for to indicate the end of a quote or a record
13471: my $looking_for=$separator;
13472: # do not add the characters to the fields
13473: my $ignore=0;
13474: # we just encountered a separator (or the beginning of the record)
13475: my $just_found_separator=1;
13476: # store the field we are working on here
13477: my $field='';
13478: # work our way through all characters in record
13479: foreach my $character ($record=~/(.)/g) {
13480: if ($character eq $looking_for) {
13481: if ($character ne $separator) {
13482: # Found the end of a quote, again looking for separator
13483: $looking_for=$separator;
13484: $ignore=1;
13485: } else {
13486: # Found a separator, store away what we got
13487: $components{&takeleft($i)}=$field;
13488: $i++;
13489: $just_found_separator=1;
13490: $ignore=0;
13491: $field='';
13492: }
13493: next;
13494: }
13495: # single or double quotation marks after a separator indicate beginning of a quote
13496: # we are now looking for the end of the quote and need to ignore separators
13497: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13498: $looking_for=$character;
13499: next;
13500: }
13501: # ignore would be true after we reached the end of a quote
13502: if ($ignore) { next; }
13503: if (($just_found_separator) && ($character=~/\s/)) { next; }
13504: $field.=$character;
13505: $just_found_separator=0;
1.31 albertel 13506: }
1.561 www 13507: # catch the very last entry, since we never encountered the separator
13508: $components{&takeleft($i)}=$field;
1.31 albertel 13509: }
13510: return %components;
13511: }
13512:
1.144 matthew 13513: ######################################################
13514: ######################################################
13515:
1.56 matthew 13516: =pod
13517:
1.648 raeburn 13518: =item * &upfile_select_html()
1.41 ng 13519:
1.144 matthew 13520: Return HTML code to select a file from the users machine and specify
13521: the file type.
1.41 ng 13522:
13523: =cut
13524:
1.144 matthew 13525: ######################################################
13526: ######################################################
1.31 albertel 13527: sub upfile_select_html {
1.144 matthew 13528: my %Types = (
13529: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13530: semisv => &mt('Semicolon separated values'),
1.144 matthew 13531: space => &mt('Space separated'),
13532: tab => &mt('Tabulator separated'),
13533: # xml => &mt('HTML/XML'),
13534: );
13535: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13536: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13537: foreach my $type (sort(keys(%Types))) {
13538: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13539: }
13540: $Str .= "</select>\n";
13541: return $Str;
1.31 albertel 13542: }
13543:
1.301 albertel 13544: sub get_samples {
13545: my ($records,$toget) = @_;
13546: my @samples=({});
13547: my $got=0;
13548: foreach my $rec (@$records) {
13549: my %temp = &record_sep($rec);
13550: if (! grep(/\S/, values(%temp))) { next; }
13551: if (%temp) {
13552: $samples[$got]=\%temp;
13553: $got++;
13554: if ($got == $toget) { last; }
13555: }
13556: }
13557: return \@samples;
13558: }
13559:
1.144 matthew 13560: ######################################################
13561: ######################################################
13562:
1.56 matthew 13563: =pod
13564:
1.648 raeburn 13565: =item * &csv_print_samples($r,$records)
1.41 ng 13566:
13567: Prints a table of sample values from each column uploaded $r is an
13568: Apache Request ref, $records is an arrayref from
13569: &Apache::loncommon::upfile_record_sep
13570:
13571: =cut
13572:
1.144 matthew 13573: ######################################################
13574: ######################################################
1.31 albertel 13575: sub csv_print_samples {
13576: my ($r,$records) = @_;
1.662 bisitz 13577: my $samples = &get_samples($records,5);
1.301 albertel 13578:
1.594 raeburn 13579: $r->print(&mt('Samples').'<br />'.&start_data_table().
13580: &start_data_table_header_row());
1.356 albertel 13581: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13582: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13583: $r->print(&end_data_table_header_row());
1.301 albertel 13584: foreach my $hash (@$samples) {
1.594 raeburn 13585: $r->print(&start_data_table_row());
1.356 albertel 13586: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13587: $r->print('<td>');
1.356 albertel 13588: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13589: $r->print('</td>');
13590: }
1.594 raeburn 13591: $r->print(&end_data_table_row());
1.31 albertel 13592: }
1.594 raeburn 13593: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13594: }
13595:
1.144 matthew 13596: ######################################################
13597: ######################################################
13598:
1.56 matthew 13599: =pod
13600:
1.648 raeburn 13601: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13602:
13603: Prints a table to create associations between values and table columns.
1.144 matthew 13604:
1.41 ng 13605: $r is an Apache Request ref,
13606: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13607: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13608:
13609: =cut
13610:
1.144 matthew 13611: ######################################################
13612: ######################################################
1.31 albertel 13613: sub csv_print_select_table {
13614: my ($r,$records,$d) = @_;
1.301 albertel 13615: my $i=0;
13616: my $samples = &get_samples($records,1);
1.144 matthew 13617: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13618: &start_data_table().&start_data_table_header_row().
1.144 matthew 13619: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13620: '<th>'.&mt('Column').'</th>'.
13621: &end_data_table_header_row()."\n");
1.356 albertel 13622: foreach my $array_ref (@$d) {
13623: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13624: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13625:
1.875 bisitz 13626: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13627: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13628: $r->print('<option value="none"></option>');
1.356 albertel 13629: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13630: $r->print('<option value="'.$sample.'"'.
13631: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13632: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13633: }
1.594 raeburn 13634: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13635: $i++;
13636: }
1.594 raeburn 13637: $r->print(&end_data_table());
1.31 albertel 13638: $i--;
13639: return $i;
13640: }
1.56 matthew 13641:
1.144 matthew 13642: ######################################################
13643: ######################################################
13644:
1.56 matthew 13645: =pod
1.31 albertel 13646:
1.648 raeburn 13647: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13648:
13649: Prints a table of sample values from the upload and can make associate samples to internal names.
13650:
13651: $r is an Apache Request ref,
13652: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13653: $d is an array of 2 element arrays (internal name, displayed name)
13654:
13655: =cut
13656:
1.144 matthew 13657: ######################################################
13658: ######################################################
1.31 albertel 13659: sub csv_samples_select_table {
13660: my ($r,$records,$d) = @_;
13661: my $i=0;
1.144 matthew 13662: #
1.662 bisitz 13663: my $max_samples = 5;
13664: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13665: $r->print(&start_data_table().
13666: &start_data_table_header_row().'<th>'.
13667: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13668: &end_data_table_header_row());
1.301 albertel 13669:
13670: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13671: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13672: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13673: foreach my $option (@$d) {
13674: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13675: $r->print('<option value="'.$value.'"'.
1.253 albertel 13676: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13677: $display.'</option>');
1.31 albertel 13678: }
13679: $r->print('</select></td><td>');
1.662 bisitz 13680: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13681: if (defined($samples->[$line]{$key})) {
13682: $r->print($samples->[$line]{$key}."<br />\n");
13683: }
13684: }
1.594 raeburn 13685: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13686: $i++;
13687: }
1.594 raeburn 13688: $r->print(&end_data_table());
1.31 albertel 13689: $i--;
13690: return($i);
1.115 matthew 13691: }
13692:
1.144 matthew 13693: ######################################################
13694: ######################################################
13695:
1.115 matthew 13696: =pod
13697:
1.648 raeburn 13698: =item * &clean_excel_name($name)
1.115 matthew 13699:
13700: Returns a replacement for $name which does not contain any illegal characters.
13701:
13702: =cut
13703:
1.144 matthew 13704: ######################################################
13705: ######################################################
1.115 matthew 13706: sub clean_excel_name {
13707: my ($name) = @_;
13708: $name =~ s/[:\*\?\/\\]//g;
13709: if (length($name) > 31) {
13710: $name = substr($name,0,31);
13711: }
13712: return $name;
1.25 albertel 13713: }
1.84 albertel 13714:
1.85 albertel 13715: =pod
13716:
1.648 raeburn 13717: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13718:
13719: Returns either 1 or undef
13720:
13721: 1 if the part is to be hidden, undef if it is to be shown
13722:
13723: Arguments are:
13724:
13725: $id the id of the part to be checked
13726: $symb, optional the symb of the resource to check
13727: $udom, optional the domain of the user to check for
13728: $uname, optional the username of the user to check for
13729:
13730: =cut
1.84 albertel 13731:
13732: sub check_if_partid_hidden {
13733: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13734: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13735: $symb,$udom,$uname);
1.141 albertel 13736: my $truth=1;
13737: #if the string starts with !, then the list is the list to show not hide
13738: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13739: my @hiddenlist=split(/,/,$hiddenparts);
13740: foreach my $checkid (@hiddenlist) {
1.141 albertel 13741: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13742: }
1.141 albertel 13743: return !$truth;
1.84 albertel 13744: }
1.127 matthew 13745:
1.138 matthew 13746:
13747: ############################################################
13748: ############################################################
13749:
13750: =pod
13751:
1.157 matthew 13752: =back
13753:
1.138 matthew 13754: =head1 cgi-bin script and graphing routines
13755:
1.157 matthew 13756: =over 4
13757:
1.648 raeburn 13758: =item * &get_cgi_id()
1.138 matthew 13759:
13760: Inputs: none
13761:
13762: Returns an id which can be used to pass environment variables
13763: to various cgi-bin scripts. These environment variables will
13764: be removed from the users environment after a given time by
13765: the routine &Apache::lonnet::transfer_profile_to_env.
13766:
13767: =cut
13768:
13769: ############################################################
13770: ############################################################
1.152 albertel 13771: my $uniq=0;
1.136 matthew 13772: sub get_cgi_id {
1.154 albertel 13773: $uniq=($uniq+1)%100000;
1.280 albertel 13774: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13775: }
13776:
1.127 matthew 13777: ############################################################
13778: ############################################################
13779:
13780: =pod
13781:
1.648 raeburn 13782: =item * &DrawBarGraph()
1.127 matthew 13783:
1.138 matthew 13784: Facilitates the plotting of data in a (stacked) bar graph.
13785: Puts plot definition data into the users environment in order for
13786: graph.png to plot it. Returns an <img> tag for the plot.
13787: The bars on the plot are labeled '1','2',...,'n'.
13788:
13789: Inputs:
13790:
13791: =over 4
13792:
13793: =item $Title: string, the title of the plot
13794:
13795: =item $xlabel: string, text describing the X-axis of the plot
13796:
13797: =item $ylabel: string, text describing the Y-axis of the plot
13798:
13799: =item $Max: scalar, the maximum Y value to use in the plot
13800: If $Max is < any data point, the graph will not be rendered.
13801:
1.140 matthew 13802: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13803: they are plotted. If undefined, default values will be used.
13804:
1.178 matthew 13805: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13806:
1.138 matthew 13807: =item @Values: An array of array references. Each array reference holds data
13808: to be plotted in a stacked bar chart.
13809:
1.239 matthew 13810: =item If the final element of @Values is a hash reference the key/value
13811: pairs will be added to the graph definition.
13812:
1.138 matthew 13813: =back
13814:
13815: Returns:
13816:
13817: An <img> tag which references graph.png and the appropriate identifying
13818: information for the plot.
13819:
1.127 matthew 13820: =cut
13821:
13822: ############################################################
13823: ############################################################
1.134 matthew 13824: sub DrawBarGraph {
1.178 matthew 13825: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13826: #
13827: if (! defined($colors)) {
13828: $colors = ['#33ff00',
13829: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13830: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13831: ];
13832: }
1.228 matthew 13833: my $extra_settings = {};
13834: if (ref($Values[-1]) eq 'HASH') {
13835: $extra_settings = pop(@Values);
13836: }
1.127 matthew 13837: #
1.136 matthew 13838: my $identifier = &get_cgi_id();
13839: my $id = 'cgi.'.$identifier;
1.129 matthew 13840: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13841: return '';
13842: }
1.225 matthew 13843: #
13844: my @Labels;
13845: if (defined($labels)) {
13846: @Labels = @$labels;
13847: } else {
13848: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 13849: push(@Labels,$i+1);
1.225 matthew 13850: }
13851: }
13852: #
1.129 matthew 13853: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13854: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13855: my %ValuesHash;
13856: my $NumSets=1;
13857: foreach my $array (@Values) {
13858: next if (! ref($array));
1.136 matthew 13859: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13860: join(',',@$array);
1.129 matthew 13861: }
1.127 matthew 13862: #
1.136 matthew 13863: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13864: if ($NumBars < 3) {
13865: $width = 120+$NumBars*32;
1.220 matthew 13866: $xskip = 1;
1.225 matthew 13867: $bar_width = 30;
13868: } elsif ($NumBars < 5) {
13869: $width = 120+$NumBars*20;
13870: $xskip = 1;
13871: $bar_width = 20;
1.220 matthew 13872: } elsif ($NumBars < 10) {
1.136 matthew 13873: $width = 120+$NumBars*15;
13874: $xskip = 1;
13875: $bar_width = 15;
13876: } elsif ($NumBars <= 25) {
13877: $width = 120+$NumBars*11;
13878: $xskip = 5;
13879: $bar_width = 8;
13880: } elsif ($NumBars <= 50) {
13881: $width = 120+$NumBars*8;
13882: $xskip = 5;
13883: $bar_width = 4;
13884: } else {
13885: $width = 120+$NumBars*8;
13886: $xskip = 5;
13887: $bar_width = 4;
13888: }
13889: #
1.137 matthew 13890: $Max = 1 if ($Max < 1);
13891: if ( int($Max) < $Max ) {
13892: $Max++;
13893: $Max = int($Max);
13894: }
1.127 matthew 13895: $Title = '' if (! defined($Title));
13896: $xlabel = '' if (! defined($xlabel));
13897: $ylabel = '' if (! defined($ylabel));
1.369 www 13898: $ValuesHash{$id.'.title'} = &escape($Title);
13899: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13900: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13901: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13902: $ValuesHash{$id.'.NumBars'} = $NumBars;
13903: $ValuesHash{$id.'.NumSets'} = $NumSets;
13904: $ValuesHash{$id.'.PlotType'} = 'bar';
13905: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13906: $ValuesHash{$id.'.height'} = $height;
13907: $ValuesHash{$id.'.width'} = $width;
13908: $ValuesHash{$id.'.xskip'} = $xskip;
13909: $ValuesHash{$id.'.bar_width'} = $bar_width;
13910: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13911: #
1.228 matthew 13912: # Deal with other parameters
13913: while (my ($key,$value) = each(%$extra_settings)) {
13914: $ValuesHash{$id.'.'.$key} = $value;
13915: }
13916: #
1.646 raeburn 13917: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13918: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13919: }
13920:
13921: ############################################################
13922: ############################################################
13923:
13924: =pod
13925:
1.648 raeburn 13926: =item * &DrawXYGraph()
1.137 matthew 13927:
1.138 matthew 13928: Facilitates the plotting of data in an XY graph.
13929: Puts plot definition data into the users environment in order for
13930: graph.png to plot it. Returns an <img> tag for the plot.
13931:
13932: Inputs:
13933:
13934: =over 4
13935:
13936: =item $Title: string, the title of the plot
13937:
13938: =item $xlabel: string, text describing the X-axis of the plot
13939:
13940: =item $ylabel: string, text describing the Y-axis of the plot
13941:
13942: =item $Max: scalar, the maximum Y value to use in the plot
13943: If $Max is < any data point, the graph will not be rendered.
13944:
13945: =item $colors: Array ref containing the hex color codes for the data to be
13946: plotted in. If undefined, default values will be used.
13947:
13948: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13949:
13950: =item $Ydata: Array ref containing Array refs.
1.185 www 13951: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13952:
13953: =item %Values: hash indicating or overriding any default values which are
13954: passed to graph.png.
13955: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13956:
13957: =back
13958:
13959: Returns:
13960:
13961: An <img> tag which references graph.png and the appropriate identifying
13962: information for the plot.
13963:
1.137 matthew 13964: =cut
13965:
13966: ############################################################
13967: ############################################################
13968: sub DrawXYGraph {
13969: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13970: #
13971: # Create the identifier for the graph
13972: my $identifier = &get_cgi_id();
13973: my $id = 'cgi.'.$identifier;
13974: #
13975: $Title = '' if (! defined($Title));
13976: $xlabel = '' if (! defined($xlabel));
13977: $ylabel = '' if (! defined($ylabel));
13978: my %ValuesHash =
13979: (
1.369 www 13980: $id.'.title' => &escape($Title),
13981: $id.'.xlabel' => &escape($xlabel),
13982: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13983: $id.'.y_max_value'=> $Max,
13984: $id.'.labels' => join(',',@$Xlabels),
13985: $id.'.PlotType' => 'XY',
13986: );
13987: #
13988: if (defined($colors) && ref($colors) eq 'ARRAY') {
13989: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13990: }
13991: #
13992: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13993: return '';
13994: }
13995: my $NumSets=1;
1.138 matthew 13996: foreach my $array (@{$Ydata}){
1.137 matthew 13997: next if (! ref($array));
13998: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13999: }
1.138 matthew 14000: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14001: #
14002: # Deal with other parameters
14003: while (my ($key,$value) = each(%Values)) {
14004: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14005: }
14006: #
1.646 raeburn 14007: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14008: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14009: }
14010:
14011: ############################################################
14012: ############################################################
14013:
14014: =pod
14015:
1.648 raeburn 14016: =item * &DrawXYYGraph()
1.138 matthew 14017:
14018: Facilitates the plotting of data in an XY graph with two Y axes.
14019: Puts plot definition data into the users environment in order for
14020: graph.png to plot it. Returns an <img> tag for the plot.
14021:
14022: Inputs:
14023:
14024: =over 4
14025:
14026: =item $Title: string, the title of the plot
14027:
14028: =item $xlabel: string, text describing the X-axis of the plot
14029:
14030: =item $ylabel: string, text describing the Y-axis of the plot
14031:
14032: =item $colors: Array ref containing the hex color codes for the data to be
14033: plotted in. If undefined, default values will be used.
14034:
14035: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14036:
14037: =item $Ydata1: The first data set
14038:
14039: =item $Min1: The minimum value of the left Y-axis
14040:
14041: =item $Max1: The maximum value of the left Y-axis
14042:
14043: =item $Ydata2: The second data set
14044:
14045: =item $Min2: The minimum value of the right Y-axis
14046:
14047: =item $Max2: The maximum value of the left Y-axis
14048:
14049: =item %Values: hash indicating or overriding any default values which are
14050: passed to graph.png.
14051: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14052:
14053: =back
14054:
14055: Returns:
14056:
14057: An <img> tag which references graph.png and the appropriate identifying
14058: information for the plot.
1.136 matthew 14059:
14060: =cut
14061:
14062: ############################################################
14063: ############################################################
1.137 matthew 14064: sub DrawXYYGraph {
14065: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14066: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14067: #
14068: # Create the identifier for the graph
14069: my $identifier = &get_cgi_id();
14070: my $id = 'cgi.'.$identifier;
14071: #
14072: $Title = '' if (! defined($Title));
14073: $xlabel = '' if (! defined($xlabel));
14074: $ylabel = '' if (! defined($ylabel));
14075: my %ValuesHash =
14076: (
1.369 www 14077: $id.'.title' => &escape($Title),
14078: $id.'.xlabel' => &escape($xlabel),
14079: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14080: $id.'.labels' => join(',',@$Xlabels),
14081: $id.'.PlotType' => 'XY',
14082: $id.'.NumSets' => 2,
1.137 matthew 14083: $id.'.two_axes' => 1,
14084: $id.'.y1_max_value' => $Max1,
14085: $id.'.y1_min_value' => $Min1,
14086: $id.'.y2_max_value' => $Max2,
14087: $id.'.y2_min_value' => $Min2,
1.136 matthew 14088: );
14089: #
1.137 matthew 14090: if (defined($colors) && ref($colors) eq 'ARRAY') {
14091: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14092: }
14093: #
14094: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14095: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14096: return '';
14097: }
14098: my $NumSets=1;
1.137 matthew 14099: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14100: next if (! ref($array));
14101: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14102: }
14103: #
14104: # Deal with other parameters
14105: while (my ($key,$value) = each(%Values)) {
14106: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14107: }
14108: #
1.646 raeburn 14109: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14110: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14111: }
14112:
14113: ############################################################
14114: ############################################################
14115:
14116: =pod
14117:
1.157 matthew 14118: =back
14119:
1.139 matthew 14120: =head1 Statistics helper routines?
14121:
14122: Bad place for them but what the hell.
14123:
1.157 matthew 14124: =over 4
14125:
1.648 raeburn 14126: =item * &chartlink()
1.139 matthew 14127:
14128: Returns a link to the chart for a specific student.
14129:
14130: Inputs:
14131:
14132: =over 4
14133:
14134: =item $linktext: The text of the link
14135:
14136: =item $sname: The students username
14137:
14138: =item $sdomain: The students domain
14139:
14140: =back
14141:
1.157 matthew 14142: =back
14143:
1.139 matthew 14144: =cut
14145:
14146: ############################################################
14147: ############################################################
14148: sub chartlink {
14149: my ($linktext, $sname, $sdomain) = @_;
14150: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14151: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14152: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14153: '">'.$linktext.'</a>';
1.153 matthew 14154: }
14155:
14156: #######################################################
14157: #######################################################
14158:
14159: =pod
14160:
14161: =head1 Course Environment Routines
1.157 matthew 14162:
14163: =over 4
1.153 matthew 14164:
1.648 raeburn 14165: =item * &restore_course_settings()
1.153 matthew 14166:
1.648 raeburn 14167: =item * &store_course_settings()
1.153 matthew 14168:
14169: Restores/Store indicated form parameters from the course environment.
14170: Will not overwrite existing values of the form parameters.
14171:
14172: Inputs:
14173: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14174:
14175: a hash ref describing the data to be stored. For example:
14176:
14177: %Save_Parameters = ('Status' => 'scalar',
14178: 'chartoutputmode' => 'scalar',
14179: 'chartoutputdata' => 'scalar',
14180: 'Section' => 'array',
1.373 raeburn 14181: 'Group' => 'array',
1.153 matthew 14182: 'StudentData' => 'array',
14183: 'Maps' => 'array');
14184:
14185: Returns: both routines return nothing
14186:
1.631 raeburn 14187: =back
14188:
1.153 matthew 14189: =cut
14190:
14191: #######################################################
14192: #######################################################
14193: sub store_course_settings {
1.496 albertel 14194: return &store_settings($env{'request.course.id'},@_);
14195: }
14196:
14197: sub store_settings {
1.153 matthew 14198: # save to the environment
14199: # appenv the same items, just to be safe
1.300 albertel 14200: my $udom = $env{'user.domain'};
14201: my $uname = $env{'user.name'};
1.496 albertel 14202: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14203: my %SaveHash;
14204: my %AppHash;
14205: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14206: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14207: my $envname = 'environment.'.$basename;
1.258 albertel 14208: if (exists($env{'form.'.$setting})) {
1.153 matthew 14209: # Save this value away
14210: if ($type eq 'scalar' &&
1.258 albertel 14211: (! exists($env{$envname}) ||
14212: $env{$envname} ne $env{'form.'.$setting})) {
14213: $SaveHash{$basename} = $env{'form.'.$setting};
14214: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14215: } elsif ($type eq 'array') {
14216: my $stored_form;
1.258 albertel 14217: if (ref($env{'form.'.$setting})) {
1.153 matthew 14218: $stored_form = join(',',
14219: map {
1.369 www 14220: &escape($_);
1.258 albertel 14221: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14222: } else {
14223: $stored_form =
1.369 www 14224: &escape($env{'form.'.$setting});
1.153 matthew 14225: }
14226: # Determine if the array contents are the same.
1.258 albertel 14227: if ($stored_form ne $env{$envname}) {
1.153 matthew 14228: $SaveHash{$basename} = $stored_form;
14229: $AppHash{$envname} = $stored_form;
14230: }
14231: }
14232: }
14233: }
14234: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14235: $udom,$uname);
1.153 matthew 14236: if ($put_result !~ /^(ok|delayed)/) {
14237: &Apache::lonnet::logthis('unable to save form parameters, '.
14238: 'got error:'.$put_result);
14239: }
14240: # Make sure these settings stick around in this session, too
1.646 raeburn 14241: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14242: return;
14243: }
14244:
14245: sub restore_course_settings {
1.499 albertel 14246: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14247: }
14248:
14249: sub restore_settings {
14250: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14251: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14252: next if (exists($env{'form.'.$setting}));
1.496 albertel 14253: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14254: '.'.$setting;
1.258 albertel 14255: if (exists($env{$envname})) {
1.153 matthew 14256: if ($type eq 'scalar') {
1.258 albertel 14257: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14258: } elsif ($type eq 'array') {
1.258 albertel 14259: $env{'form.'.$setting} = [
1.153 matthew 14260: map {
1.369 www 14261: &unescape($_);
1.258 albertel 14262: } split(',',$env{$envname})
1.153 matthew 14263: ];
14264: }
14265: }
14266: }
1.127 matthew 14267: }
14268:
1.618 raeburn 14269: #######################################################
14270: #######################################################
14271:
14272: =pod
14273:
14274: =head1 Domain E-mail Routines
14275:
14276: =over 4
14277:
1.648 raeburn 14278: =item * &build_recipient_list()
1.618 raeburn 14279:
1.1075.2.44 raeburn 14280: Build recipient lists for following types of e-mail:
1.766 raeburn 14281: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 14282: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14283: module change checking, student/employee ID conflict checks, as
14284: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14285: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14286:
14287: Inputs:
1.1075.2.44 raeburn 14288: defmail (scalar - email address of default recipient),
14289: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14290: requestsmail, updatesmail, or idconflictsmail).
14291:
1.619 raeburn 14292: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 14293:
14294: origmail (scalar - email address of recipient from loncapa.conf,
14295: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14296:
1.1075.2.139 raeburn 14297: $requname username of requester (if mailing type is helpdeskmail)
14298:
14299: $requdom domain of requester (if mailing type is helpdeskmail)
14300:
14301: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14302:
1.655 raeburn 14303: Returns: comma separated list of addresses to which to send e-mail.
14304:
14305: =back
1.618 raeburn 14306:
14307: =cut
14308:
14309: ############################################################
14310: ############################################################
14311: sub build_recipient_list {
1.1075.2.139 raeburn 14312: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14313: my @recipients;
1.1075.2.122 raeburn 14314: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14315: my %domconfig =
1.1075.2.122 raeburn 14316: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14317: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14318: if (exists($domconfig{'contacts'}{$mailing})) {
14319: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14320: my @contacts = ('adminemail','supportemail');
14321: foreach my $item (@contacts) {
14322: if ($domconfig{'contacts'}{$mailing}{$item}) {
14323: my $addr = $domconfig{'contacts'}{$item};
14324: if (!grep(/^\Q$addr\E$/,@recipients)) {
14325: push(@recipients,$addr);
14326: }
1.619 raeburn 14327: }
1.1075.2.122 raeburn 14328: }
14329: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14330: if ($mailing eq 'helpdeskmail') {
14331: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14332: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14333: my @ok_bccs;
14334: foreach my $bcc (@bccs) {
14335: $bcc =~ s/^\s+//g;
14336: $bcc =~ s/\s+$//g;
14337: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14338: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14339: push(@ok_bccs,$bcc);
14340: }
14341: }
14342: }
14343: if (@ok_bccs > 0) {
14344: $allbcc = join(', ',@ok_bccs);
14345: }
14346: }
14347: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14348: }
14349: }
1.766 raeburn 14350: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14351: $lastresort = $origmail;
1.618 raeburn 14352: }
1.1075.2.139 raeburn 14353: if ($mailing eq 'helpdeskmail') {
14354: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14355: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14356: my ($inststatus,$inststatus_checked);
14357: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14358: ($env{'user.domain'} ne 'public')) {
14359: $inststatus_checked = 1;
14360: $inststatus = $env{'environment.inststatus'};
14361: }
14362: unless ($inststatus_checked) {
14363: if (($requname ne '') && ($requdom ne '')) {
14364: if (($requname =~ /^$match_username$/) &&
14365: ($requdom =~ /^$match_domain$/) &&
14366: (&Apache::lonnet::domain($requdom))) {
14367: my $requhome = &Apache::lonnet::homeserver($requname,
14368: $requdom);
14369: unless ($requhome eq 'no_host') {
14370: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14371: $inststatus = $userenv{'inststatus'};
14372: $inststatus_checked = 1;
14373: }
14374: }
14375: }
14376: }
14377: unless ($inststatus_checked) {
14378: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
14379: my %srch = (srchby => 'email',
14380: srchdomain => $defdom,
14381: srchterm => $reqemail,
14382: srchtype => 'exact');
14383: my %srch_results = &Apache::lonnet::usersearch(\%srch);
14384: foreach my $uname (keys(%srch_results)) {
14385: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14386: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14387: $inststatus_checked = 1;
14388: last;
14389: }
14390: }
14391: unless ($inststatus_checked) {
14392: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
14393: if ($dirsrchres eq 'ok') {
14394: foreach my $uname (keys(%srch_results)) {
14395: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14396: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14397: $inststatus_checked = 1;
14398: last;
14399: }
14400: }
14401: }
14402: }
14403: }
14404: }
14405: if ($inststatus ne '') {
14406: foreach my $status (split(/\:/,$inststatus)) {
14407: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
14408: my @contacts = ('adminemail','supportemail');
14409: foreach my $item (@contacts) {
14410: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
14411: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
14412: if (!grep(/^\Q$addr\E$/,@recipients)) {
14413: push(@recipients,$addr);
14414: }
14415: }
14416: }
14417: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
14418: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
14419: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
14420: my @ok_bccs;
14421: foreach my $bcc (@bccs) {
14422: $bcc =~ s/^\s+//g;
14423: $bcc =~ s/\s+$//g;
14424: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14425: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14426: push(@ok_bccs,$bcc);
14427: }
14428: }
14429: }
14430: if (@ok_bccs > 0) {
14431: $allbcc = join(', ',@ok_bccs);
14432: }
14433: }
14434: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
14435: last;
14436: }
14437: }
14438: }
14439: }
14440: }
1.619 raeburn 14441: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14442: $lastresort = $origmail;
14443: }
1.1075.2.128 raeburn 14444: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 14445: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14446: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14447: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14448: my %what = (
14449: perlvar => 1,
14450: );
14451: my $primary = &Apache::lonnet::domain($defdom,'primary');
14452: if ($primary) {
14453: my $gotaddr;
14454: my ($result,$returnhash) =
14455: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14456: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14457: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14458: $lastresort = $returnhash->{'lonSupportEMail'};
14459: $gotaddr = 1;
14460: }
14461: }
14462: unless ($gotaddr) {
14463: my $uintdom = &Apache::lonnet::internet_dom($primary);
14464: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14465: unless ($uintdom eq $intdom) {
14466: my %domconfig =
14467: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14468: if (ref($domconfig{'contacts'}) eq 'HASH') {
14469: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14470: my @contacts = ('adminemail','supportemail');
14471: foreach my $item (@contacts) {
14472: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14473: my $addr = $domconfig{'contacts'}{$item};
14474: if (!grep(/^\Q$addr\E$/,@recipients)) {
14475: push(@recipients,$addr);
14476: }
14477: }
14478: }
14479: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14480: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14481: }
14482: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14483: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14484: my @ok_bccs;
14485: foreach my $bcc (@bccs) {
14486: $bcc =~ s/^\s+//g;
14487: $bcc =~ s/\s+$//g;
14488: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14489: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14490: push(@ok_bccs,$bcc);
14491: }
14492: }
14493: }
14494: if (@ok_bccs > 0) {
14495: $allbcc = join(', ',@ok_bccs);
14496: }
14497: }
14498: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14499: }
14500: }
14501: }
14502: }
14503: }
14504: }
1.618 raeburn 14505: }
1.688 raeburn 14506: if (defined($defmail)) {
14507: if ($defmail ne '') {
14508: push(@recipients,$defmail);
14509: }
1.618 raeburn 14510: }
14511: if ($otheremails) {
1.619 raeburn 14512: my @others;
14513: if ($otheremails =~ /,/) {
14514: @others = split(/,/,$otheremails);
1.618 raeburn 14515: } else {
1.619 raeburn 14516: push(@others,$otheremails);
14517: }
14518: foreach my $addr (@others) {
14519: if (!grep(/^\Q$addr\E$/,@recipients)) {
14520: push(@recipients,$addr);
14521: }
1.618 raeburn 14522: }
14523: }
1.1075.2.128 raeburn 14524: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 14525: if ((!@recipients) && ($lastresort ne '')) {
14526: push(@recipients,$lastresort);
14527: }
14528: } elsif ($lastresort ne '') {
14529: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14530: push(@recipients,$lastresort);
14531: }
14532: }
14533: my $recipientlist = join(',',@recipients);
14534: if (wantarray) {
14535: return ($recipientlist,$allbcc,$addtext);
14536: } else {
14537: return $recipientlist;
14538: }
1.618 raeburn 14539: }
14540:
1.127 matthew 14541: ############################################################
14542: ############################################################
1.154 albertel 14543:
1.655 raeburn 14544: =pod
14545:
14546: =head1 Course Catalog Routines
14547:
14548: =over 4
14549:
14550: =item * &gather_categories()
14551:
14552: Converts category definitions - keys of categories hash stored in
14553: coursecategories in configuration.db on the primary library server in a
14554: domain - to an array. Also generates javascript and idx hash used to
14555: generate Domain Coordinator interface for editing Course Categories.
14556:
14557: Inputs:
1.663 raeburn 14558:
1.655 raeburn 14559: categories (reference to hash of category definitions).
1.663 raeburn 14560:
1.655 raeburn 14561: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14562: categories and subcategories).
1.663 raeburn 14563:
1.655 raeburn 14564: idx (reference to hash of counters used in Domain Coordinator interface for
14565: editing Course Categories).
1.663 raeburn 14566:
1.655 raeburn 14567: jsarray (reference to array of categories used to create Javascript arrays for
14568: Domain Coordinator interface for editing Course Categories).
14569:
14570: Returns: nothing
14571:
14572: Side effects: populates cats, idx and jsarray.
14573:
14574: =cut
14575:
14576: sub gather_categories {
14577: my ($categories,$cats,$idx,$jsarray) = @_;
14578: my %counters;
14579: my $num = 0;
14580: foreach my $item (keys(%{$categories})) {
14581: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14582: if ($container eq '' && $depth == 0) {
14583: $cats->[$depth][$categories->{$item}] = $cat;
14584: } else {
14585: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14586: }
14587: my ($escitem,$tail) = split(/:/,$item,2);
14588: if ($counters{$tail} eq '') {
14589: $counters{$tail} = $num;
14590: $num ++;
14591: }
14592: if (ref($idx) eq 'HASH') {
14593: $idx->{$item} = $counters{$tail};
14594: }
14595: if (ref($jsarray) eq 'ARRAY') {
14596: push(@{$jsarray->[$counters{$tail}]},$item);
14597: }
14598: }
14599: return;
14600: }
14601:
14602: =pod
14603:
14604: =item * &extract_categories()
14605:
14606: Used to generate breadcrumb trails for course categories.
14607:
14608: Inputs:
1.663 raeburn 14609:
1.655 raeburn 14610: categories (reference to hash of category definitions).
1.663 raeburn 14611:
1.655 raeburn 14612: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14613: categories and subcategories).
1.663 raeburn 14614:
1.655 raeburn 14615: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14616:
1.655 raeburn 14617: allitems (reference to hash - key is category key
14618: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14619:
1.655 raeburn 14620: idx (reference to hash of counters used in Domain Coordinator interface for
14621: editing Course Categories).
1.663 raeburn 14622:
1.655 raeburn 14623: jsarray (reference to array of categories used to create Javascript arrays for
14624: Domain Coordinator interface for editing Course Categories).
14625:
1.665 raeburn 14626: subcats (reference to hash of arrays containing all subcategories within each
14627: category, -recursive)
14628:
1.1075.2.132 raeburn 14629: maxd (reference to hash used to hold max depth for all top-level categories).
14630:
1.655 raeburn 14631: Returns: nothing
14632:
14633: Side effects: populates trails and allitems hash references.
14634:
14635: =cut
14636:
14637: sub extract_categories {
1.1075.2.132 raeburn 14638: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 14639: if (ref($categories) eq 'HASH') {
14640: &gather_categories($categories,$cats,$idx,$jsarray);
14641: if (ref($cats->[0]) eq 'ARRAY') {
14642: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14643: my $name = $cats->[0][$i];
14644: my $item = &escape($name).'::0';
14645: my $trailstr;
14646: if ($name eq 'instcode') {
14647: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14648: } elsif ($name eq 'communities') {
14649: $trailstr = &mt('Communities');
1.655 raeburn 14650: } else {
14651: $trailstr = $name;
14652: }
14653: if ($allitems->{$item} eq '') {
14654: push(@{$trails},$trailstr);
14655: $allitems->{$item} = scalar(@{$trails})-1;
14656: }
14657: my @parents = ($name);
14658: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14659: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14660: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14661: if (ref($subcats) eq 'HASH') {
14662: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14663: }
1.1075.2.132 raeburn 14664: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 14665: }
14666: } else {
14667: if (ref($subcats) eq 'HASH') {
14668: $subcats->{$item} = [];
1.655 raeburn 14669: }
1.1075.2.132 raeburn 14670: if (ref($maxd) eq 'HASH') {
14671: $maxd->{$name} = 1;
14672: }
1.655 raeburn 14673: }
14674: }
14675: }
14676: }
14677: return;
14678: }
14679:
14680: =pod
14681:
1.1075.2.56 raeburn 14682: =item * &recurse_categories()
1.655 raeburn 14683:
14684: Recursively used to generate breadcrumb trails for course categories.
14685:
14686: Inputs:
1.663 raeburn 14687:
1.655 raeburn 14688: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14689: categories and subcategories).
1.663 raeburn 14690:
1.655 raeburn 14691: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14692:
14693: category (current course category, for which breadcrumb trail is being generated).
14694:
14695: trails (reference to array of breadcrumb trails for each category).
14696:
1.655 raeburn 14697: allitems (reference to hash - key is category key
14698: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14699:
1.655 raeburn 14700: parents (array containing containers directories for current category,
14701: back to top level).
14702:
14703: Returns: nothing
14704:
14705: Side effects: populates trails and allitems hash references
14706:
14707: =cut
14708:
14709: sub recurse_categories {
1.1075.2.132 raeburn 14710: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 14711: my $shallower = $depth - 1;
14712: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14713: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14714: my $name = $cats->[$depth]{$category}[$k];
14715: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14716: my $trailstr = join(' -> ',(@{$parents},$category));
14717: if ($allitems->{$item} eq '') {
14718: push(@{$trails},$trailstr);
14719: $allitems->{$item} = scalar(@{$trails})-1;
14720: }
14721: my $deeper = $depth+1;
14722: push(@{$parents},$category);
1.665 raeburn 14723: if (ref($subcats) eq 'HASH') {
14724: my $subcat = &escape($name).':'.$category.':'.$depth;
14725: for (my $j=@{$parents}; $j>=0; $j--) {
14726: my $higher;
14727: if ($j > 0) {
14728: $higher = &escape($parents->[$j]).':'.
14729: &escape($parents->[$j-1]).':'.$j;
14730: } else {
14731: $higher = &escape($parents->[$j]).'::'.$j;
14732: }
14733: push(@{$subcats->{$higher}},$subcat);
14734: }
14735: }
14736: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 14737: $subcats,$maxd);
1.655 raeburn 14738: pop(@{$parents});
14739: }
14740: } else {
14741: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 14742: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 14743: if ($allitems->{$item} eq '') {
14744: push(@{$trails},$trailstr);
14745: $allitems->{$item} = scalar(@{$trails})-1;
14746: }
1.1075.2.132 raeburn 14747: if (ref($maxd) eq 'HASH') {
14748: if ($depth > $maxd->{$parents->[0]}) {
14749: $maxd->{$parents->[0]} = $depth;
14750: }
14751: }
1.655 raeburn 14752: }
14753: return;
14754: }
14755:
1.663 raeburn 14756: =pod
14757:
1.1075.2.56 raeburn 14758: =item * &assign_categories_table()
1.663 raeburn 14759:
14760: Create a datatable for display of hierarchical categories in a domain,
14761: with checkboxes to allow a course to be categorized.
14762:
14763: Inputs:
14764:
14765: cathash - reference to hash of categories defined for the domain (from
14766: configuration.db)
14767:
14768: currcat - scalar with an & separated list of categories assigned to a course.
14769:
1.919 raeburn 14770: type - scalar contains course type (Course or Community).
14771:
1.1075.2.117 raeburn 14772: disabled - scalar (optional) contains disabled="disabled" if input elements are
14773: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14774:
1.663 raeburn 14775: Returns: $output (markup to be displayed)
14776:
14777: =cut
14778:
14779: sub assign_categories_table {
1.1075.2.117 raeburn 14780: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 14781: my $output;
14782: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 14783: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
14784: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 14785: $maxdepth = scalar(@cats);
14786: if (@cats > 0) {
14787: my $itemcount = 0;
14788: if (ref($cats[0]) eq 'ARRAY') {
14789: my @currcategories;
14790: if ($currcat ne '') {
14791: @currcategories = split('&',$currcat);
14792: }
1.919 raeburn 14793: my $table;
1.663 raeburn 14794: for (my $i=0; $i<@{$cats[0]}; $i++) {
14795: my $parent = $cats[0][$i];
1.919 raeburn 14796: next if ($parent eq 'instcode');
14797: if ($type eq 'Community') {
14798: next unless ($parent eq 'communities');
14799: } else {
14800: next if ($parent eq 'communities');
14801: }
1.663 raeburn 14802: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14803: my $item = &escape($parent).'::0';
14804: my $checked = '';
14805: if (@currcategories > 0) {
14806: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14807: $checked = ' checked="checked"';
1.663 raeburn 14808: }
14809: }
1.919 raeburn 14810: my $parent_title = $parent;
14811: if ($parent eq 'communities') {
14812: $parent_title = &mt('Communities');
14813: }
14814: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14815: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14816: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 14817: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14818: my $depth = 1;
14819: push(@path,$parent);
1.1075.2.117 raeburn 14820: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 14821: pop(@path);
1.919 raeburn 14822: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14823: $itemcount ++;
14824: }
1.919 raeburn 14825: if ($itemcount) {
14826: $output = &Apache::loncommon::start_data_table().
14827: $table.
14828: &Apache::loncommon::end_data_table();
14829: }
1.663 raeburn 14830: }
14831: }
14832: }
14833: return $output;
14834: }
14835:
14836: =pod
14837:
1.1075.2.56 raeburn 14838: =item * &assign_category_rows()
1.663 raeburn 14839:
14840: Create a datatable row for display of nested categories in a domain,
14841: with checkboxes to allow a course to be categorized,called recursively.
14842:
14843: Inputs:
14844:
14845: itemcount - track row number for alternating colors
14846:
14847: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14848: categories and subcategories.
14849:
14850: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14851:
14852: parent - parent of current category item
14853:
14854: path - Array containing all categories back up through the hierarchy from the
14855: current category to the top level.
14856:
14857: currcategories - reference to array of current categories assigned to the course
14858:
1.1075.2.117 raeburn 14859: disabled - scalar (optional) contains disabled="disabled" if input elements are
14860: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14861:
1.663 raeburn 14862: Returns: $output (markup to be displayed).
14863:
14864: =cut
14865:
14866: sub assign_category_rows {
1.1075.2.117 raeburn 14867: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 14868: my ($text,$name,$item,$chgstr);
14869: if (ref($cats) eq 'ARRAY') {
14870: my $maxdepth = scalar(@{$cats});
14871: if (ref($cats->[$depth]) eq 'HASH') {
14872: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14873: my $numchildren = @{$cats->[$depth]{$parent}};
14874: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 14875: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14876: for (my $j=0; $j<$numchildren; $j++) {
14877: $name = $cats->[$depth]{$parent}[$j];
14878: $item = &escape($name).':'.&escape($parent).':'.$depth;
14879: my $deeper = $depth+1;
14880: my $checked = '';
14881: if (ref($currcategories) eq 'ARRAY') {
14882: if (@{$currcategories} > 0) {
14883: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14884: $checked = ' checked="checked"';
1.663 raeburn 14885: }
14886: }
14887: }
1.664 raeburn 14888: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14889: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14890: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 14891: '<input type="hidden" name="catname" value="'.$name.'" />'.
14892: '</td><td>';
1.663 raeburn 14893: if (ref($path) eq 'ARRAY') {
14894: push(@{$path},$name);
1.1075.2.117 raeburn 14895: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 14896: pop(@{$path});
14897: }
14898: $text .= '</td></tr>';
14899: }
14900: $text .= '</table></td>';
14901: }
14902: }
14903: }
14904: return $text;
14905: }
14906:
1.1075.2.69 raeburn 14907: =pod
14908:
14909: =back
14910:
14911: =cut
14912:
1.655 raeburn 14913: ############################################################
14914: ############################################################
14915:
14916:
1.443 albertel 14917: sub commit_customrole {
1.664 raeburn 14918: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14919: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14920: ($start?', '.&mt('starting').' '.localtime($start):'').
14921: ($end?', ending '.localtime($end):'').': <b>'.
14922: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14923: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14924: '</b><br />';
14925: return $output;
14926: }
14927:
14928: sub commit_standardrole {
1.1075.2.31 raeburn 14929: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14930: my ($output,$logmsg,$linefeed);
14931: if ($context eq 'auto') {
14932: $linefeed = "\n";
14933: } else {
14934: $linefeed = "<br />\n";
14935: }
1.443 albertel 14936: if ($three eq 'st') {
1.541 raeburn 14937: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 14938: $one,$two,$sec,$context,$credits);
1.541 raeburn 14939: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14940: ($result eq 'unknown_course') || ($result eq 'refused')) {
14941: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14942: } else {
1.541 raeburn 14943: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14944: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14945: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14946: if ($context eq 'auto') {
14947: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14948: } else {
14949: $output .= '<b>'.$result.'</b>'.$linefeed.
14950: &mt('Add to classlist').': <b>ok</b>';
14951: }
14952: $output .= $linefeed;
1.443 albertel 14953: }
14954: } else {
14955: $output = &mt('Assigning').' '.$three.' in '.$url.
14956: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14957: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 14958: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 14959: if ($context eq 'auto') {
14960: $output .= $result.$linefeed;
14961: } else {
14962: $output .= '<b>'.$result.'</b>'.$linefeed;
14963: }
1.443 albertel 14964: }
14965: return $output;
14966: }
14967:
14968: sub commit_studentrole {
1.1075.2.31 raeburn 14969: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
14970: $credits) = @_;
1.626 raeburn 14971: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 14972: if ($context eq 'auto') {
14973: $linefeed = "\n";
14974: } else {
14975: $linefeed = '<br />'."\n";
14976: }
1.443 albertel 14977: if (defined($one) && defined($two)) {
14978: my $cid=$one.'_'.$two;
14979: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
14980: my $secchange = 0;
14981: my $expire_role_result;
14982: my $modify_section_result;
1.628 raeburn 14983: if ($oldsec ne '-1') {
14984: if ($oldsec ne $sec) {
1.443 albertel 14985: $secchange = 1;
1.628 raeburn 14986: my $now = time;
1.443 albertel 14987: my $uurl='/'.$cid;
14988: $uurl=~s/\_/\//g;
14989: if ($oldsec) {
14990: $uurl.='/'.$oldsec;
14991: }
1.626 raeburn 14992: $oldsecurl = $uurl;
1.628 raeburn 14993: $expire_role_result =
1.652 raeburn 14994: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 14995: if ($env{'request.course.sec'} ne '') {
14996: if ($expire_role_result eq 'refused') {
14997: my @roles = ('st');
14998: my @statuses = ('previous');
14999: my @roledoms = ($one);
15000: my $withsec = 1;
15001: my %roleshash =
15002: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15003: \@statuses,\@roles,\@roledoms,$withsec);
15004: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15005: my ($oldstart,$oldend) =
15006: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15007: if ($oldend > 0 && $oldend <= $now) {
15008: $expire_role_result = 'ok';
15009: }
15010: }
15011: }
15012: }
1.443 albertel 15013: $result = $expire_role_result;
15014: }
15015: }
15016: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 15017: $modify_section_result =
15018: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15019: undef,undef,undef,$sec,
15020: $end,$start,'','',$cid,
15021: '',$context,$credits);
1.443 albertel 15022: if ($modify_section_result =~ /^ok/) {
15023: if ($secchange == 1) {
1.628 raeburn 15024: if ($sec eq '') {
15025: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15026: } else {
15027: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15028: }
1.443 albertel 15029: } elsif ($oldsec eq '-1') {
1.628 raeburn 15030: if ($sec eq '') {
15031: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15032: } else {
15033: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15034: }
1.443 albertel 15035: } else {
1.628 raeburn 15036: if ($sec eq '') {
15037: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15038: } else {
15039: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15040: }
1.443 albertel 15041: }
15042: } else {
1.628 raeburn 15043: if ($secchange) {
15044: $$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;
15045: } else {
15046: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15047: }
1.443 albertel 15048: }
15049: $result = $modify_section_result;
15050: } elsif ($secchange == 1) {
1.628 raeburn 15051: if ($oldsec eq '') {
1.1075.2.20 raeburn 15052: $$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 15053: } else {
15054: $$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;
15055: }
1.626 raeburn 15056: if ($expire_role_result eq 'refused') {
15057: my $newsecurl = '/'.$cid;
15058: $newsecurl =~ s/\_/\//g;
15059: if ($sec ne '') {
15060: $newsecurl.='/'.$sec;
15061: }
15062: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15063: if ($sec eq '') {
15064: $$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;
15065: } else {
15066: $$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;
15067: }
15068: }
15069: }
1.443 albertel 15070: }
15071: } else {
1.626 raeburn 15072: $$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 15073: $result = "error: incomplete course id\n";
15074: }
15075: return $result;
15076: }
15077:
1.1075.2.25 raeburn 15078: sub show_role_extent {
15079: my ($scope,$context,$role) = @_;
15080: $scope =~ s{^/}{};
15081: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15082: push(@courseroles,'co');
15083: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15084: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15085: $scope =~ s{/}{_};
15086: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15087: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15088: my ($audom,$auname) = split(/\//,$scope);
15089: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15090: &Apache::loncommon::plainname($auname,$audom).'</span>');
15091: } else {
15092: $scope =~ s{/$}{};
15093: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15094: &Apache::lonnet::domain($scope,'description').'</span>');
15095: }
15096: }
15097:
1.443 albertel 15098: ############################################################
15099: ############################################################
15100:
1.566 albertel 15101: sub check_clone {
1.578 raeburn 15102: my ($args,$linefeed) = @_;
1.566 albertel 15103: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15104: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15105: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1075.2.141. .5(raebu 15106:20): my $clonetitle;
15107:20): my @clonemsg;
1.566 albertel 15108: my $can_clone = 0;
1.944 raeburn 15109: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15110: if ($lctype ne 'community') {
15111: $lctype = 'course';
15112: }
1.566 albertel 15113: if ($clonehome eq 'no_host') {
1.944 raeburn 15114: if ($args->{'crstype'} eq 'Community') {
1.1075.2.141. .5(raebu 15115:20): push(@clonemsg,({
15116:20): mt => 'No new community created.',
15117:20): args => [],
15118:20): },
15119:20): {
15120:20): mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
15121:20): args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
15122:20): }));
1.908 raeburn 15123: } else {
1.1075.2.141. .5(raebu 15124:20): push(@clonemsg,({
15125:20): mt => 'No new course created.',
15126:20): args => [],
15127:20): },
15128:20): {
15129:20): mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
15130:20): args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
15131:20): }));
15132:20): }
1.566 albertel 15133: } else {
15134: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1075.2.141. .5(raebu 15135:20): $clonetitle = $clonedesc{'description'};
1.944 raeburn 15136: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15137: if ($clonedesc{'type'} ne 'Community') {
1.1075.2.141. .5(raebu 15138:20): push(@clonemsg,({
15139:20): mt => 'No new community created.',
15140:20): args => [],
15141:20): },
15142:20): {
15143:20): mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
15144:20): args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
15145:20): }));
15146:20): return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 15147: }
15148: }
1.1075.2.119 raeburn 15149: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15150: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15151: $can_clone = 1;
15152: } else {
1.1075.2.95 raeburn 15153: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15154: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 15155: if ($clonehash{'cloners'} eq '') {
15156: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15157: if ($domdefs{'canclone'}) {
15158: unless ($domdefs{'canclone'} eq 'none') {
15159: if ($domdefs{'canclone'} eq 'domain') {
15160: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15161: $can_clone = 1;
15162: }
15163: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15164: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15165: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15166: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15167: $can_clone = 1;
15168: }
15169: }
15170: }
1.908 raeburn 15171: }
1.1075.2.95 raeburn 15172: } else {
15173: my @cloners = split(/,/,$clonehash{'cloners'});
15174: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15175: $can_clone = 1;
1.1075.2.95 raeburn 15176: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15177: $can_clone = 1;
1.1075.2.96 raeburn 15178: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15179: $can_clone = 1;
1.1075.2.95 raeburn 15180: }
15181: unless ($can_clone) {
1.1075.2.96 raeburn 15182: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15183: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 15184: my (%gotdomdefaults,%gotcodedefaults);
15185: foreach my $cloner (@cloners) {
15186: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15187: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15188: my (%codedefaults,@code_order);
15189: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15190: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15191: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15192: }
15193: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15194: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15195: }
15196: } else {
15197: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15198: \%codedefaults,
15199: \@code_order);
15200: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15201: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15202: }
15203: if (@code_order > 0) {
15204: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15205: $cloner,$clonehash{'internal.coursecode'},
15206: $args->{'crscode'})) {
15207: $can_clone = 1;
15208: last;
15209: }
15210: }
15211: }
15212: }
15213: }
1.1075.2.96 raeburn 15214: }
15215: }
15216: unless ($can_clone) {
15217: my $ccrole = 'cc';
15218: if ($args->{'crstype'} eq 'Community') {
15219: $ccrole = 'co';
15220: }
15221: my %roleshash =
15222: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15223: $args->{'ccdomain'},
15224: 'userroles',['active'],[$ccrole],
15225: [$args->{'clonedomain'}]);
15226: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15227: $can_clone = 1;
15228: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15229: $args->{'ccuname'},$args->{'ccdomain'})) {
15230: $can_clone = 1;
1.1075.2.95 raeburn 15231: }
15232: }
15233: unless ($can_clone) {
15234: if ($args->{'crstype'} eq 'Community') {
1.1075.2.141. .5(raebu 15235:20): push(@clonemsg,({
15236:20): mt => 'No new community created.',
15237:20): args => [],
15238:20): },
15239:20): {
15240:20): 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]).',
15241:20): args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
15242:20): }));
1.1075.2.95 raeburn 15243: } else {
1.1075.2.141. .5(raebu 15244:20): push(@clonemsg,({
15245:20): mt => 'No new course created.',
15246:20): args => [],
15247:20): },
15248:20): {
15249:20): 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]).',
15250:20): args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
15251:20): }));
15252:20): }
1.566 albertel 15253: }
1.578 raeburn 15254: }
1.566 albertel 15255: }
1.1075.2.141. .5(raebu 15256:20): return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 15257: }
15258:
1.444 albertel 15259: sub construct_course {
1.1075.2.119 raeburn 15260: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1075.2.141. .5(raebu 15261:20): $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
15262:20): my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 15263: my $linefeed = '<br />'."\n";
15264: if ($context eq 'auto') {
15265: $linefeed = "\n";
15266: }
1.566 albertel 15267:
15268: #
15269: # Are we cloning?
15270: #
1.1075.2.141. .5(raebu 15271:20): my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 15272: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1075.2.141. .5(raebu 15273:20): ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 15274: if (!$can_clone) {
1.1075.2.141. .5(raebu 15275:20): return (0,$outcome,$clonemsgref);
1.566 albertel 15276: }
15277: }
15278:
1.444 albertel 15279: #
15280: # Open course
15281: #
15282: my $crstype = lc($args->{'crstype'});
15283: my %cenv=();
15284: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15285: $args->{'cdescr'},
15286: $args->{'curl'},
15287: $args->{'course_home'},
15288: $args->{'nonstandard'},
15289: $args->{'crscode'},
15290: $args->{'ccuname'}.':'.
15291: $args->{'ccdomain'},
1.882 raeburn 15292: $args->{'crstype'},
1.1075.2.141. .5(raebu 15293:20): $cnum,$context,$category,
15294:20): $callercontext);
1.444 albertel 15295:
15296: # Note: The testing routines depend on this being output; see
15297: # Utils::Course. This needs to at least be output as a comment
15298: # if anyone ever decides to not show this, and Utils::Course::new
15299: # will need to be suitably modified.
1.1075.2.141. .5(raebu 15300:20): if (($callercontext eq 'auto') && ($user_lh ne '')) {
15301:20): $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
15302:20): } else {
15303:20): $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
15304:20): }
1.943 raeburn 15305: if ($$courseid =~ /^error:/) {
1.1075.2.141. .5(raebu 15306:20): return (0,$outcome,$clonemsgref);
1.943 raeburn 15307: }
15308:
1.444 albertel 15309: #
15310: # Check if created correctly
15311: #
1.479 albertel 15312: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15313: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15314: if ($crsuhome eq 'no_host') {
1.1075.2.141. .5(raebu 15315:20): if (($callercontext eq 'auto') && ($user_lh ne '')) {
15316:20): $outcome .= &mt_user($user_lh,
15317:20): 'Course creation failed, unrecognized course home server.');
15318:20): } else {
15319:20): $outcome .= &mt('Course creation failed, unrecognized course home server.');
15320:20): }
15321:20): $outcome .= $linefeed;
15322:20): return (0,$outcome,$clonemsgref);
1.943 raeburn 15323: }
1.541 raeburn 15324: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15325:
1.444 albertel 15326: #
1.566 albertel 15327: # Do the cloning
15328: #
1.1075.2.141. .5(raebu 15329:20): my @clonemsg;
1.566 albertel 15330: if ($can_clone && $cloneid) {
1.1075.2.141. .5(raebu 15331:20): push(@clonemsg,
15332:20): {
15333:20): mt => 'Created [_1] by cloning from [_2]',
15334:20): args => [$crstype,$clonetitle],
15335:20): });
1.566 albertel 15336: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15337: # Copy all files
1.1075.2.141. .5(raebu 15338:20): my @info =
15339:20): &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
15340:20): $args->{'dateshift'},$args->{'crscode'},
15341:20): $args->{'ccuname'}.':'.$args->{'ccdomain'},
15342:20): $args->{'tinyurls'});
15343:20): if (@info) {
15344:20): push(@clonemsg,@info);
15345:20): }
1.444 albertel 15346: # Restore URL
1.566 albertel 15347: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15348: # Restore title
1.566 albertel 15349: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15350: # Restore creation date, creator and creation context.
15351: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15352: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15353: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15354: # Mark as cloned
1.566 albertel 15355: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15356: # Need to clone grading mode
15357: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15358: $cenv{'grading'}=$newenv{'grading'};
15359: # Do not clone these environment entries
15360: &Apache::lonnet::del('environment',
15361: ['default_enrollment_start_date',
15362: 'default_enrollment_end_date',
15363: 'question.email',
15364: 'policy.email',
15365: 'comment.email',
15366: 'pch.users.denied',
1.725 raeburn 15367: 'plc.users.denied',
15368: 'hidefromcat',
1.1075.2.36 raeburn 15369: 'checkforpriv',
1.1075.2.59 raeburn 15370: 'categories',
15371: 'internal.uniquecode'],
1.638 www 15372: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 15373: if ($args->{'textbook'}) {
15374: $cenv{'internal.textbook'} = $args->{'textbook'};
15375: }
1.444 albertel 15376: }
1.566 albertel 15377:
1.444 albertel 15378: #
15379: # Set environment (will override cloned, if existing)
15380: #
15381: my @sections = ();
15382: my @xlists = ();
15383: if ($args->{'crstype'}) {
15384: $cenv{'type'}=$args->{'crstype'};
15385: }
15386: if ($args->{'crsid'}) {
15387: $cenv{'courseid'}=$args->{'crsid'};
15388: }
15389: if ($args->{'crscode'}) {
15390: $cenv{'internal.coursecode'}=$args->{'crscode'};
15391: }
15392: if ($args->{'crsquota'} ne '') {
15393: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15394: } else {
15395: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15396: }
15397: if ($args->{'ccuname'}) {
15398: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15399: ':'.$args->{'ccdomain'};
15400: } else {
15401: $cenv{'internal.courseowner'} = $args->{'curruser'};
15402: }
1.1075.2.31 raeburn 15403: if ($args->{'defaultcredits'}) {
15404: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15405: }
1.444 albertel 15406: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15407: if ($args->{'crssections'}) {
15408: $cenv{'internal.sectionnums'} = '';
15409: if ($args->{'crssections'} =~ m/,/) {
15410: @sections = split/,/,$args->{'crssections'};
15411: } else {
15412: $sections[0] = $args->{'crssections'};
15413: }
15414: if (@sections > 0) {
15415: foreach my $item (@sections) {
15416: my ($sec,$gp) = split/:/,$item;
15417: my $class = $args->{'crscode'}.$sec;
15418: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15419: $cenv{'internal.sectionnums'} .= $item.',';
15420: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15421: push(@badclasses,$class);
1.444 albertel 15422: }
15423: }
15424: $cenv{'internal.sectionnums'} =~ s/,$//;
15425: }
15426: }
15427: # do not hide course coordinator from staff listing,
15428: # even if privileged
15429: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 15430: # add course coordinator's domain to domains to check for privileged users
15431: # if different to course domain
15432: if ($$crsudom ne $args->{'ccdomain'}) {
15433: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15434: }
1.444 albertel 15435: # add crosslistings
15436: if ($args->{'crsxlist'}) {
15437: $cenv{'internal.crosslistings'}='';
15438: if ($args->{'crsxlist'} =~ m/,/) {
15439: @xlists = split/,/,$args->{'crsxlist'};
15440: } else {
15441: $xlists[0] = $args->{'crsxlist'};
15442: }
15443: if (@xlists > 0) {
15444: foreach my $item (@xlists) {
15445: my ($xl,$gp) = split/:/,$item;
15446: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15447: $cenv{'internal.crosslistings'} .= $item.',';
15448: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15449: push(@badclasses,$xl);
1.444 albertel 15450: }
15451: }
15452: $cenv{'internal.crosslistings'} =~ s/,$//;
15453: }
15454: }
15455: if ($args->{'autoadds'}) {
15456: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15457: }
15458: if ($args->{'autodrops'}) {
15459: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15460: }
15461: # check for notification of enrollment changes
15462: my @notified = ();
15463: if ($args->{'notify_owner'}) {
15464: if ($args->{'ccuname'} ne '') {
15465: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15466: }
15467: }
15468: if ($args->{'notify_dc'}) {
15469: if ($uname ne '') {
1.630 raeburn 15470: push(@notified,$uname.':'.$udom);
1.444 albertel 15471: }
15472: }
15473: if (@notified > 0) {
15474: my $notifylist;
15475: if (@notified > 1) {
15476: $notifylist = join(',',@notified);
15477: } else {
15478: $notifylist = $notified[0];
15479: }
15480: $cenv{'internal.notifylist'} = $notifylist;
15481: }
15482: if (@badclasses > 0) {
15483: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 15484: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15485: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15486: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15487: );
1.1075.2.119 raeburn 15488: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15489: &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 15490: if ($context eq 'auto') {
15491: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 15492: } else {
1.566 albertel 15493: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 15494: }
15495: foreach my $item (@badclasses) {
1.541 raeburn 15496: if ($context eq 'auto') {
1.1075.2.119 raeburn 15497: $outcome .= " - $item\n";
1.541 raeburn 15498: } else {
1.1075.2.119 raeburn 15499: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15500: }
1.1075.2.119 raeburn 15501: }
15502: if ($context eq 'auto') {
15503: $outcome .= $linefeed;
15504: } else {
15505: $outcome .= "</ul><br /><br /></div>\n";
15506: }
1.444 albertel 15507: }
15508: if ($args->{'no_end_date'}) {
15509: $args->{'endaccess'} = 0;
15510: }
15511: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15512: $cenv{'internal.autoend'}=$args->{'enrollend'};
15513: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15514: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15515: if ($args->{'showphotos'}) {
15516: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15517: }
15518: $cenv{'internal.authtype'} = $args->{'authtype'};
15519: $cenv{'internal.autharg'} = $args->{'autharg'};
15520: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15521: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15522: 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');
15523: if ($context eq 'auto') {
15524: $outcome .= $krb_msg;
15525: } else {
1.566 albertel 15526: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15527: }
15528: $outcome .= $linefeed;
1.444 albertel 15529: }
15530: }
15531: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15532: if ($args->{'setpolicy'}) {
15533: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15534: }
15535: if ($args->{'setcontent'}) {
15536: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15537: }
1.1075.2.110 raeburn 15538: if ($args->{'setcomment'}) {
15539: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15540: }
1.444 albertel 15541: }
15542: if ($args->{'reshome'}) {
15543: $cenv{'reshome'}=$args->{'reshome'}.'/';
15544: $cenv{'reshome'}=~s/\/+$/\//;
15545: }
15546: #
15547: # course has keyed access
15548: #
15549: if ($args->{'setkeys'}) {
15550: $cenv{'keyaccess'}='yes';
15551: }
15552: # if specified, key authority is not course, but user
15553: # only active if keyaccess is yes
15554: if ($args->{'keyauth'}) {
1.487 albertel 15555: my ($user,$domain) = split(':',$args->{'keyauth'});
15556: $user = &LONCAPA::clean_username($user);
15557: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15558: if ($user ne '' && $domain ne '') {
1.487 albertel 15559: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15560: }
15561: }
15562:
1.1075.2.59 raeburn 15563: #
15564: # generate and store uniquecode (available to course requester), if course should have one.
15565: #
15566: if ($args->{'uniquecode'}) {
15567: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15568: if ($code) {
15569: $cenv{'internal.uniquecode'} = $code;
15570: my %crsinfo =
15571: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15572: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15573: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15574: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15575: }
15576: if (ref($coderef)) {
15577: $$coderef = $code;
15578: }
15579: }
15580: }
15581:
1.444 albertel 15582: if ($args->{'disresdis'}) {
15583: $cenv{'pch.roles.denied'}='st';
15584: }
15585: if ($args->{'disablechat'}) {
15586: $cenv{'plc.roles.denied'}='st';
15587: }
15588:
15589: # Record we've not yet viewed the Course Initialization Helper for this
15590: # course
15591: $cenv{'course.helper.not.run'} = 1;
15592: #
15593: # Use new Randomseed
15594: #
15595: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15596: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15597: #
15598: # The encryption code and receipt prefix for this course
15599: #
15600: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15601: $cenv{'internal.encpref'}=100+int(9*rand(99));
15602: #
15603: # By default, use standard grading
15604: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15605:
1.541 raeburn 15606: $outcome .= $linefeed.&mt('Setting environment').': '.
15607: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15608: #
15609: # Open all assignments
15610: #
15611: if ($args->{'openall'}) {
1.1075.2.141. .4(raebu 15612:20): my $opendate = time;
15613:20): if ($args->{'openallfrom'} =~ /^\d+$/) {
15614:20): $opendate = $args->{'openallfrom'};
15615:20): }
1.444 albertel 15616: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1075.2.141. .4(raebu 15617:20): my %storecontent = ($storeunder => $opendate,
1.444 albertel 15618: $storeunder.'.type' => 'date_start');
1.1075.2.141. .4(raebu 15619:20): $outcome .= &mt('All assignments open starting [_1]',
15620:20): &Apache::lonlocal::locallocaltime($opendate)).': '.
15621:20): &Apache::lonnet::cput
15622:20): ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15623: }
15624: #
15625: # Set first page
15626: #
15627: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15628: || ($cloneid)) {
1.445 albertel 15629: use LONCAPA::map;
1.444 albertel 15630: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15631:
15632: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15633: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15634:
1.444 albertel 15635: $outcome .= ($fatal?$errtext:'read ok').' - ';
15636: my $title; my $url;
15637: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15638: $title=&mt('Syllabus');
1.444 albertel 15639: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15640: } else {
1.963 raeburn 15641: $title=&mt('Table of Contents');
1.444 albertel 15642: $url='/adm/navmaps';
15643: }
1.445 albertel 15644:
15645: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15646: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15647:
15648: if ($errtext) { $fatal=2; }
1.541 raeburn 15649: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15650: }
1.566 albertel 15651:
1.1075.2.141. .5(raebu 15652:20): return (1,$outcome,\@clonemsg);
1.444 albertel 15653: }
15654:
1.1075.2.59 raeburn 15655: sub make_unique_code {
15656: my ($cdom,$cnum) = @_;
15657: # get lock on uniquecodes db
15658: my $lockhash = {
15659: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15660: ':'.$env{'user.domain'},
15661: };
15662: my $tries = 0;
15663: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15664: my ($code,$error);
15665:
15666: while (($gotlock ne 'ok') && ($tries<3)) {
15667: $tries ++;
15668: sleep 1;
15669: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15670: }
15671: if ($gotlock eq 'ok') {
15672: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15673: my $gotcode;
15674: my $attempts = 0;
15675: while ((!$gotcode) && ($attempts < 100)) {
15676: $code = &generate_code();
15677: if (!exists($currcodes{$code})) {
15678: $gotcode = 1;
15679: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15680: $error = 'nostore';
15681: }
15682: }
15683: $attempts ++;
15684: }
15685: my @del_lock = ($cnum."\0".'uniquecodes');
15686: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15687: } else {
15688: $error = 'nolock';
15689: }
15690: return ($code,$error);
15691: }
15692:
15693: sub generate_code {
15694: my $code;
15695: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15696: for (my $i=0; $i<6; $i++) {
15697: my $lettnum = int (rand 2);
15698: my $item = '';
15699: if ($lettnum) {
15700: $item = $letts[int( rand(18) )];
15701: } else {
15702: $item = 1+int( rand(8) );
15703: }
15704: $code .= $item;
15705: }
15706: return $code;
15707: }
15708:
1.444 albertel 15709: ############################################################
15710: ############################################################
15711:
1.953 droeschl 15712: #SD
15713: # only Community and Course, or anything else?
1.378 raeburn 15714: sub course_type {
15715: my ($cid) = @_;
15716: if (!defined($cid)) {
15717: $cid = $env{'request.course.id'};
15718: }
1.404 albertel 15719: if (defined($env{'course.'.$cid.'.type'})) {
15720: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15721: } else {
15722: return 'Course';
1.377 raeburn 15723: }
15724: }
1.156 albertel 15725:
1.406 raeburn 15726: sub group_term {
15727: my $crstype = &course_type();
15728: my %names = (
15729: 'Course' => 'group',
1.865 raeburn 15730: 'Community' => 'group',
1.406 raeburn 15731: );
15732: return $names{$crstype};
15733: }
15734:
1.902 raeburn 15735: sub course_types {
1.1075.2.59 raeburn 15736: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15737: my %typename = (
15738: official => 'Official course',
15739: unofficial => 'Unofficial course',
15740: community => 'Community',
1.1075.2.59 raeburn 15741: textbook => 'Textbook course',
1.902 raeburn 15742: );
15743: return (\@types,\%typename);
15744: }
15745:
1.156 albertel 15746: sub icon {
15747: my ($file)=@_;
1.505 albertel 15748: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15749: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15750: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15751: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15752: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15753: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15754: $curfext.".gif") {
15755: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15756: $curfext.".gif";
15757: }
15758: }
1.249 albertel 15759: return &lonhttpdurl($iconname);
1.154 albertel 15760: }
1.84 albertel 15761:
1.575 albertel 15762: sub lonhttpdurl {
1.692 www 15763: #
15764: # Had been used for "small fry" static images on separate port 8080.
15765: # Modify here if lightweight http functionality desired again.
15766: # Currently eliminated due to increasing firewall issues.
15767: #
1.575 albertel 15768: my ($url)=@_;
1.692 www 15769: return $url;
1.215 albertel 15770: }
15771:
1.213 albertel 15772: sub connection_aborted {
15773: my ($r)=@_;
15774: $r->print(" ");$r->rflush();
15775: my $c = $r->connection;
15776: return $c->aborted();
15777: }
15778:
1.221 foxr 15779: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15780: # strings as 'strings'.
15781: sub escape_single {
1.221 foxr 15782: my ($input) = @_;
1.223 albertel 15783: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15784: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15785: return $input;
15786: }
1.223 albertel 15787:
1.222 foxr 15788: # Same as escape_single, but escape's "'s This
15789: # can be used for "strings"
15790: sub escape_double {
15791: my ($input) = @_;
15792: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15793: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15794: return $input;
15795: }
1.223 albertel 15796:
1.222 foxr 15797: # Escapes the last element of a full URL.
15798: sub escape_url {
15799: my ($url) = @_;
1.238 raeburn 15800: my @urlslices = split(/\//, $url,-1);
1.369 www 15801: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 15802: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15803: }
1.462 albertel 15804:
1.820 raeburn 15805: sub compare_arrays {
15806: my ($arrayref1,$arrayref2) = @_;
15807: my (@difference,%count);
15808: @difference = ();
15809: %count = ();
15810: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15811: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15812: foreach my $element (keys(%count)) {
15813: if ($count{$element} == 1) {
15814: push(@difference,$element);
15815: }
15816: }
15817: }
15818: return @difference;
15819: }
15820:
1.817 bisitz 15821: # -------------------------------------------------------- Initialize user login
1.462 albertel 15822: sub init_user_environment {
1.463 albertel 15823: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15824: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15825:
15826: my $public=($username eq 'public' && $domain eq 'public');
15827:
15828: # See if old ID present, if so, remove
15829:
1.1062 raeburn 15830: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15831: my $now=time;
15832:
15833: if ($public) {
15834: my $max_public=100;
15835: my $oldest;
15836: my $oldest_time=0;
15837: for(my $next=1;$next<=$max_public;$next++) {
15838: if (-e $lonids."/publicuser_$next.id") {
15839: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
15840: if ($mtime<$oldest_time || !$oldest_time) {
15841: $oldest_time=$mtime;
15842: $oldest=$next;
15843: }
15844: } else {
15845: $cookie="publicuser_$next";
15846: last;
15847: }
15848: }
15849: if (!$cookie) { $cookie="publicuser_$oldest"; }
15850: } else {
1.463 albertel 15851: # if this isn't a robot, kill any existing non-robot sessions
15852: if (!$args->{'robot'}) {
15853: opendir(DIR,$lonids);
15854: while ($filename=readdir(DIR)) {
15855: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136 raeburn 15856: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
15857: &GDBM_READER(),0640)) {
15858: my $linkedfile;
15859: if (exists($oldenv{'user.linkedenv'})) {
15860: $linkedfile = $oldenv{'user.linkedenv'};
15861: }
15862: untie(%oldenv);
15863: if (unlink("$lonids/$filename")) {
15864: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
15865: if (-l "$lonids/$linkedfile.id") {
15866: unlink("$lonids/$linkedfile.id");
15867: }
15868: }
15869: }
15870: } else {
15871: unlink($lonids.'/'.$filename);
15872: }
1.463 albertel 15873: }
1.462 albertel 15874: }
1.463 albertel 15875: closedir(DIR);
1.1075.2.84 raeburn 15876: # If there is a undeleted lockfile for the user's paste buffer remove it.
15877: my $namespace = 'nohist_courseeditor';
15878: my $lockingkey = 'paste'."\0".'locked_num';
15879: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
15880: $domain,$username);
15881: if (exists($lockhash{$lockingkey})) {
15882: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
15883: unless ($delresult eq 'ok') {
15884: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
15885: }
15886: }
1.462 albertel 15887: }
15888: # Give them a new cookie
1.463 albertel 15889: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 15890: : $now.$$.int(rand(10000)));
1.463 albertel 15891: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 15892:
15893: # Initialize roles
15894:
1.1062 raeburn 15895: ($userroles,$firstaccenv,$timerintenv) =
15896: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 15897: }
15898: # ------------------------------------ Check browser type and MathML capability
15899:
1.1075.2.77 raeburn 15900: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15901: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15902:
15903: # ------------------------------------------------------------- Get environment
15904:
15905: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15906: my ($tmp) = keys(%userenv);
15907: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
15908: } else {
15909: undef(%userenv);
15910: }
15911: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15912: $form->{'interface'}=$userenv{'interface'};
15913: }
15914: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15915:
15916: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15917: foreach my $option ('interface','localpath','localres') {
15918: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15919: }
15920: # --------------------------------------------------------- Write first profile
15921:
15922: {
15923: my %initial_env =
15924: ("user.name" => $username,
15925: "user.domain" => $domain,
15926: "user.home" => $authhost,
15927: "browser.type" => $clientbrowser,
15928: "browser.version" => $clientversion,
15929: "browser.mathml" => $clientmathml,
15930: "browser.unicode" => $clientunicode,
15931: "browser.os" => $clientos,
1.1075.2.42 raeburn 15932: "browser.mobile" => $clientmobile,
15933: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 15934: "browser.osversion" => $clientosversion,
1.462 albertel 15935: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
15936: "request.course.fn" => '',
15937: "request.course.uri" => '',
15938: "request.course.sec" => '',
15939: "request.role" => 'cm',
15940: "request.role.adv" => $env{'user.adv'},
15941: "request.host" => $ENV{'REMOTE_ADDR'},);
15942:
15943: if ($form->{'localpath'}) {
15944: $initial_env{"browser.localpath"} = $form->{'localpath'};
15945: $initial_env{"browser.localres"} = $form->{'localres'};
15946: }
15947:
15948: if ($form->{'interface'}) {
15949: $form->{'interface'}=~s/\W//gs;
15950: $initial_env{"browser.interface"} = $form->{'interface'};
15951: $env{'browser.interface'}=$form->{'interface'};
15952: }
15953:
1.1075.2.54 raeburn 15954: if ($form->{'iptoken'}) {
15955: my $lonhost = $r->dir_config('lonHostID');
15956: $initial_env{"user.noloadbalance"} = $lonhost;
15957: $env{'user.noloadbalance'} = $lonhost;
15958: }
15959:
1.1075.2.120 raeburn 15960: if ($form->{'noloadbalance'}) {
15961: my @hosts = &Apache::lonnet::current_machine_ids();
15962: my $hosthere = $form->{'noloadbalance'};
15963: if (grep(/^\Q$hosthere\E$/,@hosts)) {
15964: $initial_env{"user.noloadbalance"} = $hosthere;
15965: $env{'user.noloadbalance'} = $hosthere;
15966: }
15967: }
15968:
1.1016 raeburn 15969: unless ($domain eq 'public') {
1.1075.2.125 raeburn 15970: my %is_adv = ( is_adv => $env{'user.adv'} );
15971: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 15972:
1.1075.2.125 raeburn 15973: foreach my $tool ('aboutme','blog','webdav','portfolio') {
15974: $userenv{'availabletools.'.$tool} =
15975: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
15976: undef,\%userenv,\%domdef,\%is_adv);
15977: }
1.724 raeburn 15978:
1.1075.2.125 raeburn 15979: foreach my $crstype ('official','unofficial','community','textbook') {
15980: $userenv{'canrequest.'.$crstype} =
15981: &Apache::lonnet::usertools_access($username,$domain,$crstype,
15982: 'reload','requestcourses',
15983: \%userenv,\%domdef,\%is_adv);
15984: }
1.765 raeburn 15985:
1.1075.2.125 raeburn 15986: $userenv{'canrequest.author'} =
15987: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15988: 'reload','requestauthor',
15989: \%userenv,\%domdef,\%is_adv);
15990: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15991: $domain,$username);
15992: my $reqstatus = $reqauthor{'author_status'};
15993: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15994: if (ref($reqauthor{'author'}) eq 'HASH') {
15995: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15996: $reqauthor{'author'}{'timestamp'};
15997: }
1.1075.2.14 raeburn 15998: }
15999: }
16000:
1.462 albertel 16001: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16002:
1.462 albertel 16003: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16004: &GDBM_WRCREAT(),0640)) {
16005: &_add_to_env(\%disk_env,\%initial_env);
16006: &_add_to_env(\%disk_env,\%userenv,'environment.');
16007: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16008: if (ref($firstaccenv) eq 'HASH') {
16009: &_add_to_env(\%disk_env,$firstaccenv);
16010: }
16011: if (ref($timerintenv) eq 'HASH') {
16012: &_add_to_env(\%disk_env,$timerintenv);
16013: }
1.463 albertel 16014: if (ref($args->{'extra_env'})) {
16015: &_add_to_env(\%disk_env,$args->{'extra_env'});
16016: }
1.462 albertel 16017: untie(%disk_env);
16018: } else {
1.705 tempelho 16019: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16020: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16021: return 'error: '.$!;
16022: }
16023: }
16024: $env{'request.role'}='cm';
16025: $env{'request.role.adv'}=$env{'user.adv'};
16026: $env{'browser.type'}=$clientbrowser;
16027:
16028: return $cookie;
16029:
16030: }
16031:
16032: sub _add_to_env {
16033: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16034: if (ref($env_data) eq 'HASH') {
16035: while (my ($key,$value) = each(%$env_data)) {
16036: $idf->{$prefix.$key} = $value;
16037: $env{$prefix.$key} = $value;
16038: }
1.462 albertel 16039: }
16040: }
16041:
1.685 tempelho 16042: # --- Get the symbolic name of a problem and the url
16043: sub get_symb {
16044: my ($request,$silent) = @_;
1.726 raeburn 16045: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16046: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16047: if ($symb eq '') {
16048: if (!$silent) {
1.1071 raeburn 16049: if (ref($request)) {
16050: $request->print("Unable to handle ambiguous references:$url:.");
16051: }
1.685 tempelho 16052: return ();
16053: }
16054: }
16055: &Apache::lonenc::check_decrypt(\$symb);
16056: return ($symb);
16057: }
16058:
16059: # --------------------------------------------------------------Get annotation
16060:
16061: sub get_annotation {
16062: my ($symb,$enc) = @_;
16063:
16064: my $key = $symb;
16065: if (!$enc) {
16066: $key =
16067: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16068: }
16069: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16070: return $annotation{$key};
16071: }
16072:
16073: sub clean_symb {
1.731 raeburn 16074: my ($symb,$delete_enc) = @_;
1.685 tempelho 16075:
16076: &Apache::lonenc::check_decrypt(\$symb);
16077: my $enc = $env{'request.enc'};
1.731 raeburn 16078: if ($delete_enc) {
1.730 raeburn 16079: delete($env{'request.enc'});
16080: }
1.685 tempelho 16081:
16082: return ($symb,$enc);
16083: }
1.462 albertel 16084:
1.1075.2.69 raeburn 16085: ############################################################
16086: ############################################################
16087:
16088: =pod
16089:
16090: =head1 Routines for building display used to search for courses
16091:
16092:
16093: =over 4
16094:
16095: =item * &build_filters()
16096:
16097: Create markup for a table used to set filters to use when selecting
16098: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16099: and quotacheck.pl
16100:
16101:
16102: Inputs:
16103:
16104: filterlist - anonymous array of fields to include as potential filters
16105:
16106: crstype - course type
16107:
16108: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16109: to pop-open a course selector (will contain "extra element").
16110:
16111: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16112:
16113: filter - anonymous hash of criteria and their values
16114:
16115: action - form action
16116:
16117: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16118:
16119: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
16120:
16121: cloneruname - username of owner of new course who wants to clone
16122:
16123: clonerudom - domain of owner of new course who wants to clone
16124:
16125: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16126:
16127: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16128:
16129: codedom - domain
16130:
16131: formname - value of form element named "form".
16132:
16133: fixeddom - domain, if fixed.
16134:
16135: prevphase - value to assign to form element named "phase" when going back to the previous screen
16136:
16137: cnameelement - name of form element in form on opener page which will receive title of selected course
16138:
16139: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16140:
16141: cdomelement - name of form element in form on opener page which will receive domain of selected course
16142:
16143: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16144:
16145: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16146:
16147: clonewarning - warning message about missing information for intended course owner when DC creates a course
16148:
16149:
16150: Returns: $output - HTML for display of search criteria, and hidden form elements.
16151:
16152:
16153: Side Effects: None
16154:
16155: =cut
16156:
16157: # ---------------------------------------------- search for courses based on last activity etc.
16158:
16159: sub build_filters {
16160: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16161: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16162: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16163: $cnameelement,$cnumelement,$cdomelement,$setroles,
16164: $clonetext,$clonewarning) = @_;
16165: my ($list,$jscript);
16166: my $onchange = 'javascript:updateFilters(this)';
16167: my ($domainselectform,$sincefilterform,$createdfilterform,
16168: $ownerdomselectform,$persondomselectform,$instcodeform,
16169: $typeselectform,$instcodetitle);
16170: if ($formname eq '') {
16171: $formname = $caller;
16172: }
16173: foreach my $item (@{$filterlist}) {
16174: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16175: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16176: if ($item eq 'domainfilter') {
16177: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16178: } elsif ($item eq 'coursefilter') {
16179: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16180: } elsif ($item eq 'ownerfilter') {
16181: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16182: } elsif ($item eq 'ownerdomfilter') {
16183: $filter->{'ownerdomfilter'} =
16184: &LONCAPA::clean_domain($filter->{$item});
16185: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16186: 'ownerdomfilter',1);
16187: } elsif ($item eq 'personfilter') {
16188: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16189: } elsif ($item eq 'persondomfilter') {
16190: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16191: 'persondomfilter',1);
16192: } else {
16193: $filter->{$item} =~ s/\W//g;
16194: }
16195: if (!$filter->{$item}) {
16196: $filter->{$item} = '';
16197: }
16198: }
16199: if ($item eq 'domainfilter') {
16200: my $allow_blank = 1;
16201: if ($formname eq 'portform') {
16202: $allow_blank=0;
16203: } elsif ($formname eq 'studentform') {
16204: $allow_blank=0;
16205: }
16206: if ($fixeddom) {
16207: $domainselectform = '<input type="hidden" name="domainfilter"'.
16208: ' value="'.$codedom.'" />'.
16209: &Apache::lonnet::domain($codedom,'description');
16210: } else {
16211: $domainselectform = &select_dom_form($filter->{$item},
16212: 'domainfilter',
16213: $allow_blank,'',$onchange);
16214: }
16215: } else {
16216: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16217: }
16218: }
16219:
16220: # last course activity filter and selection
16221: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16222:
16223: # course created filter and selection
16224: if (exists($filter->{'createdfilter'})) {
16225: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16226: }
16227:
16228: my %lt = &Apache::lonlocal::texthash(
16229: 'cac' => "$crstype Activity",
16230: 'ccr' => "$crstype Created",
16231: 'cde' => "$crstype Title",
16232: 'cdo' => "$crstype Domain",
16233: 'ins' => 'Institutional Code',
16234: 'inc' => 'Institutional Categorization',
16235: 'cow' => "$crstype Owner/Co-owner",
16236: 'cop' => "$crstype Personnel Includes",
16237: 'cog' => 'Type',
16238: );
16239:
16240: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16241: my $typeval = 'Course';
16242: if ($crstype eq 'Community') {
16243: $typeval = 'Community';
16244: }
16245: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16246: } else {
16247: $typeselectform = '<select name="type" size="1"';
16248: if ($onchange) {
16249: $typeselectform .= ' onchange="'.$onchange.'"';
16250: }
16251: $typeselectform .= '>'."\n";
16252: foreach my $posstype ('Course','Community') {
16253: $typeselectform.='<option value="'.$posstype.'"'.
16254: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
16255: }
16256: $typeselectform.="</select>";
16257: }
16258:
16259: my ($cloneableonlyform,$cloneabletitle);
16260: if (exists($filter->{'cloneableonly'})) {
16261: my $cloneableon = '';
16262: my $cloneableoff = ' checked="checked"';
16263: if ($filter->{'cloneableonly'}) {
16264: $cloneableon = $cloneableoff;
16265: $cloneableoff = '';
16266: }
16267: $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>';
16268: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 16269: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 16270: } else {
16271: $cloneabletitle = &mt('Cloneable by you');
16272: }
16273: }
16274: my $officialjs;
16275: if ($crstype eq 'Course') {
16276: if (exists($filter->{'instcodefilter'})) {
16277: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16278: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16279: if ($codedom) {
16280: $officialjs = 1;
16281: ($instcodeform,$jscript,$$numtitlesref) =
16282: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16283: $officialjs,$codetitlesref);
16284: if ($jscript) {
16285: $jscript = '<script type="text/javascript">'."\n".
16286: '// <![CDATA['."\n".
16287: $jscript."\n".
16288: '// ]]>'."\n".
16289: '</script>'."\n";
16290: }
16291: }
16292: if ($instcodeform eq '') {
16293: $instcodeform =
16294: '<input type="text" name="instcodefilter" size="10" value="'.
16295: $list->{'instcodefilter'}.'" />';
16296: $instcodetitle = $lt{'ins'};
16297: } else {
16298: $instcodetitle = $lt{'inc'};
16299: }
16300: if ($fixeddom) {
16301: $instcodetitle .= '<br />('.$codedom.')';
16302: }
16303: }
16304: }
16305: my $output = qq|
16306: <form method="post" name="filterpicker" action="$action">
16307: <input type="hidden" name="form" value="$formname" />
16308: |;
16309: if ($formname eq 'modifycourse') {
16310: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16311: '<input type="hidden" name="prevphase" value="'.
16312: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 16313: } elsif ($formname eq 'quotacheck') {
16314: $output .= qq|
16315: <input type="hidden" name="sortby" value="" />
16316: <input type="hidden" name="sortorder" value="" />
16317: |;
16318: } else {
1.1075.2.69 raeburn 16319: my $name_input;
16320: if ($cnameelement ne '') {
16321: $name_input = '<input type="hidden" name="cnameelement" value="'.
16322: $cnameelement.'" />';
16323: }
16324: $output .= qq|
16325: <input type="hidden" name="cnumelement" value="$cnumelement" />
16326: <input type="hidden" name="cdomelement" value="$cdomelement" />
16327: $name_input
16328: $roleelement
16329: $multelement
16330: $typeelement
16331: |;
16332: if ($formname eq 'portform') {
16333: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16334: }
16335: }
16336: if ($fixeddom) {
16337: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16338: }
16339: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16340: if ($sincefilterform) {
16341: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16342: .$sincefilterform
16343: .&Apache::lonhtmlcommon::row_closure();
16344: }
16345: if ($createdfilterform) {
16346: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16347: .$createdfilterform
16348: .&Apache::lonhtmlcommon::row_closure();
16349: }
16350: if ($domainselectform) {
16351: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16352: .$domainselectform
16353: .&Apache::lonhtmlcommon::row_closure();
16354: }
16355: if ($typeselectform) {
16356: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16357: $output .= $typeselectform;
16358: } else {
16359: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16360: .$typeselectform
16361: .&Apache::lonhtmlcommon::row_closure();
16362: }
16363: }
16364: if ($instcodeform) {
16365: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16366: .$instcodeform
16367: .&Apache::lonhtmlcommon::row_closure();
16368: }
16369: if (exists($filter->{'ownerfilter'})) {
16370: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16371: '<table><tr><td>'.&mt('Username').'<br />'.
16372: '<input type="text" name="ownerfilter" size="20" value="'.
16373: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16374: $ownerdomselectform.'</td></tr></table>'.
16375: &Apache::lonhtmlcommon::row_closure();
16376: }
16377: if (exists($filter->{'personfilter'})) {
16378: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16379: '<table><tr><td>'.&mt('Username').'<br />'.
16380: '<input type="text" name="personfilter" size="20" value="'.
16381: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16382: $persondomselectform.'</td></tr></table>'.
16383: &Apache::lonhtmlcommon::row_closure();
16384: }
16385: if (exists($filter->{'coursefilter'})) {
16386: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16387: .'<input type="text" name="coursefilter" size="25" value="'
16388: .$list->{'coursefilter'}.'" />'
16389: .&Apache::lonhtmlcommon::row_closure();
16390: }
16391: if ($cloneableonlyform) {
16392: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16393: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16394: }
16395: if (exists($filter->{'descriptfilter'})) {
16396: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16397: .'<input type="text" name="descriptfilter" size="40" value="'
16398: .$list->{'descriptfilter'}.'" />'
16399: .&Apache::lonhtmlcommon::row_closure(1);
16400: }
16401: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16402: '<input type="hidden" name="updater" value="" />'."\n".
16403: '<input type="submit" name="gosearch" value="'.
16404: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16405: return $jscript.$clonewarning.$output;
16406: }
16407:
16408: =pod
16409:
16410: =item * &timebased_select_form()
16411:
16412: Create markup for a dropdown list used to select a time-based
16413: filter e.g., Course Activity, Course Created, when searching for courses
16414: or communities
16415:
16416: Inputs:
16417:
16418: item - name of form element (sincefilter or createdfilter)
16419:
16420: filter - anonymous hash of criteria and their values
16421:
16422: Returns: HTML for a select box contained a blank, then six time selections,
16423: with value set in incoming form variables currently selected.
16424:
16425: Side Effects: None
16426:
16427: =cut
16428:
16429: sub timebased_select_form {
16430: my ($item,$filter) = @_;
16431: if (ref($filter) eq 'HASH') {
16432: $filter->{$item} =~ s/[^\d-]//g;
16433: if (!$filter->{$item}) { $filter->{$item}=-1; }
16434: return &select_form(
16435: $filter->{$item},
16436: $item,
16437: { '-1' => '',
16438: '86400' => &mt('today'),
16439: '604800' => &mt('last week'),
16440: '2592000' => &mt('last month'),
16441: '7776000' => &mt('last three months'),
16442: '15552000' => &mt('last six months'),
16443: '31104000' => &mt('last year'),
16444: 'select_form_order' =>
16445: ['-1','86400','604800','2592000','7776000',
16446: '15552000','31104000']});
16447: }
16448: }
16449:
16450: =pod
16451:
16452: =item * &js_changer()
16453:
16454: Create script tag containing Javascript used to submit course search form
16455: when course type or domain is changed, and also to hide 'Searching ...' on
16456: page load completion for page showing search result.
16457:
16458: Inputs: None
16459:
16460: Returns: markup containing updateFilters() and hideSearching() javascript functions.
16461:
16462: Side Effects: None
16463:
16464: =cut
16465:
16466: sub js_changer {
16467: return <<ENDJS;
16468: <script type="text/javascript">
16469: // <![CDATA[
16470: function updateFilters(caller) {
16471: if (typeof(caller) != "undefined") {
16472: document.filterpicker.updater.value = caller.name;
16473: }
16474: document.filterpicker.submit();
16475: }
16476:
16477: function hideSearching() {
16478: if (document.getElementById('searching')) {
16479: document.getElementById('searching').style.display = 'none';
16480: }
16481: return;
16482: }
16483:
16484: // ]]>
16485: </script>
16486:
16487: ENDJS
16488: }
16489:
16490: =pod
16491:
16492: =item * &search_courses()
16493:
16494: Process selected filters form course search form and pass to lonnet::courseiddump
16495: to retrieve a hash for which keys are courseIDs which match the selected filters.
16496:
16497: Inputs:
16498:
16499: dom - domain being searched
16500:
16501: type - course type ('Course' or 'Community' or '.' if any).
16502:
16503: filter - anonymous hash of criteria and their values
16504:
16505: numtitles - for institutional codes - number of categories
16506:
16507: cloneruname - optional username of new course owner
16508:
16509: clonerudom - optional domain of new course owner
16510:
1.1075.2.95 raeburn 16511: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 16512: (used when DC is using course creation form)
16513:
16514: codetitles - reference to array of titles of components in institutional codes (official courses).
16515:
1.1075.2.95 raeburn 16516: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16517: (and so can clone automatically)
16518:
16519: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16520:
16521: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16522: courses to clone
1.1075.2.69 raeburn 16523:
16524: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16525:
16526:
16527: Side Effects: None
16528:
16529: =cut
16530:
16531:
16532: sub search_courses {
1.1075.2.95 raeburn 16533: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16534: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 16535: my (%courses,%showcourses,$cloner);
16536: if (($filter->{'ownerfilter'} ne '') ||
16537: ($filter->{'ownerdomfilter'} ne '')) {
16538: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16539: $filter->{'ownerdomfilter'};
16540: }
16541: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16542: if (!$filter->{$item}) {
16543: $filter->{$item}='.';
16544: }
16545: }
16546: my $now = time;
16547: my $timefilter =
16548: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16549: my ($createdbefore,$createdafter);
16550: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16551: $createdbefore = $now;
16552: $createdafter = $now-$filter->{'createdfilter'};
16553: }
16554: my ($instcodefilter,$regexpok);
16555: if ($numtitles) {
16556: if ($env{'form.official'} eq 'on') {
16557: $instcodefilter =
16558: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16559: $regexpok = 1;
16560: } elsif ($env{'form.official'} eq 'off') {
16561: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16562: unless ($instcodefilter eq '') {
16563: $regexpok = -1;
16564: }
16565: }
16566: } else {
16567: $instcodefilter = $filter->{'instcodefilter'};
16568: }
16569: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16570: if ($type eq '') { $type = '.'; }
16571:
16572: if (($clonerudom ne '') && ($cloneruname ne '')) {
16573: $cloner = $cloneruname.':'.$clonerudom;
16574: }
16575: %courses = &Apache::lonnet::courseiddump($dom,
16576: $filter->{'descriptfilter'},
16577: $timefilter,
16578: $instcodefilter,
16579: $filter->{'combownerfilter'},
16580: $filter->{'coursefilter'},
16581: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 16582: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 16583: $filter->{'cloneableonly'},
16584: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 16585: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 16586: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16587: my $ccrole;
16588: if ($type eq 'Community') {
16589: $ccrole = 'co';
16590: } else {
16591: $ccrole = 'cc';
16592: }
16593: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16594: $filter->{'persondomfilter'},
16595: 'userroles',undef,
16596: [$ccrole,'in','ad','ep','ta','cr'],
16597: $dom);
16598: foreach my $role (keys(%rolehash)) {
16599: my ($cnum,$cdom,$courserole) = split(':',$role);
16600: my $cid = $cdom.'_'.$cnum;
16601: if (exists($courses{$cid})) {
16602: if (ref($courses{$cid}) eq 'HASH') {
16603: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16604: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 16605: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 16606: }
16607: } else {
16608: $courses{$cid}{roles} = [$courserole];
16609: }
16610: $showcourses{$cid} = $courses{$cid};
16611: }
16612: }
16613: }
16614: %courses = %showcourses;
16615: }
16616: return %courses;
16617: }
16618:
16619: =pod
16620:
16621: =back
16622:
1.1075.2.88 raeburn 16623: =head1 Routines for version requirements for current course.
16624:
16625: =over 4
16626:
16627: =item * &check_release_required()
16628:
16629: Compares required LON-CAPA version with version on server, and
16630: if required version is newer looks for a server with the required version.
16631:
16632: Looks first at servers in user's owen domain; if none suitable, looks at
16633: servers in course's domain are permitted to host sessions for user's domain.
16634:
16635: Inputs:
16636:
16637: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16638:
16639: $courseid - Course ID of current course
16640:
16641: $rolecode - User's current role in course (for switchserver query string).
16642:
16643: $required - LON-CAPA version needed by course (format: Major.Minor).
16644:
16645:
16646: Returns:
16647:
16648: $switchserver - query string tp append to /adm/switchserver call (if
16649: current server's LON-CAPA version is too old.
16650:
16651: $warning - Message is displayed if no suitable server could be found.
16652:
16653: =cut
16654:
16655: sub check_release_required {
16656: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16657: my ($switchserver,$warning);
16658: if ($required ne '') {
16659: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16660: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16661: if ($reqdmajor ne '' && $reqdminor ne '') {
16662: my $otherserver;
16663: if (($major eq '' && $minor eq '') ||
16664: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16665: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16666: my $switchlcrev =
16667: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16668: $userdomserver);
16669: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16670: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16671: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16672: my $cdom = $env{'course.'.$courseid.'.domain'};
16673: if ($cdom ne $env{'user.domain'}) {
16674: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16675: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16676: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16677: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16678: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16679: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16680: my $canhost =
16681: &Apache::lonnet::can_host_session($env{'user.domain'},
16682: $coursedomserver,
16683: $remoterev,
16684: $udomdefaults{'remotesessions'},
16685: $defdomdefaults{'hostedsessions'});
16686:
16687: if ($canhost) {
16688: $otherserver = $coursedomserver;
16689: } else {
16690: $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.");
16691: }
16692: } else {
16693: $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).");
16694: }
16695: } else {
16696: $otherserver = $userdomserver;
16697: }
16698: }
16699: if ($otherserver ne '') {
16700: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16701: }
16702: }
16703: }
16704: return ($switchserver,$warning);
16705: }
16706:
16707: =pod
16708:
16709: =item * &check_release_result()
16710:
16711: Inputs:
16712:
16713: $switchwarning - Warning message if no suitable server found to host session.
16714:
16715: $switchserver - query string to append to /adm/switchserver containing lonHostID
16716: and current role.
16717:
16718: Returns: HTML to display with information about requirement to switch server.
16719: Either displaying warning with link to Roles/Courses screen or
16720: display link to switchserver.
16721:
1.1075.2.69 raeburn 16722: =cut
16723:
1.1075.2.88 raeburn 16724: sub check_release_result {
16725: my ($switchwarning,$switchserver) = @_;
16726: my $output = &start_page('Selected course unavailable on this server').
16727: '<p class="LC_warning">';
16728: if ($switchwarning) {
16729: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16730: if (&show_course()) {
16731: $output .= &mt('Display courses');
16732: } else {
16733: $output .= &mt('Display roles');
16734: }
16735: $output .= '</a>';
16736: } elsif ($switchserver) {
16737: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16738: '<br />'.
16739: '<a href="/adm/switchserver?'.$switchserver.'">'.
16740: &mt('Switch Server').
16741: '</a>';
16742: }
16743: $output .= '</p>'.&end_page();
16744: return $output;
16745: }
16746:
16747: =pod
16748:
16749: =item * &needs_coursereinit()
16750:
16751: Determine if course contents stored for user's session needs to be
16752: refreshed, because content has changed since "Big Hash" last tied.
16753:
16754: Check for change is made if time last checked is more than 10 minutes ago
16755: (by default).
16756:
16757: Inputs:
16758:
16759: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16760:
16761: $interval (optional) - Time which may elapse (in s) between last check for content
16762: change in current course. (default: 600 s).
16763:
16764: Returns: an array; first element is:
16765:
16766: =over 4
16767:
16768: 'switch' - if content updates mean user's session
16769: needs to be switched to a server running a newer LON-CAPA version
16770:
16771: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16772: on current server hosting user's session
16773:
16774: '' - if no action required.
16775:
16776: =back
16777:
16778: If first item element is 'switch':
16779:
16780: second item is $switchwarning - Warning message if no suitable server found to host session.
16781:
16782: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16783: and current role.
16784:
16785: otherwise: no other elements returned.
16786:
16787: =back
16788:
16789: =cut
16790:
16791: sub needs_coursereinit {
16792: my ($loncaparev,$interval) = @_;
16793: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16794: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16795: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16796: my $now = time;
16797: if ($interval eq '') {
16798: $interval = 600;
16799: }
16800: if (($now-$env{'request.course.timechecked'})>$interval) {
16801: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1075.2.141. .6(raebu 16802:20): my $blocked = &blocking_status('reinit',$cnum,$cdom,undef,1);
16803:20): if ($blocked) {
16804:20): return ();
16805:20): }
16806:20): my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
1.1075.2.88 raeburn 16807: if ($lastchange > $env{'request.course.tied'}) {
16808: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16809: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16810: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16811: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16812: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16813: $curr_reqd_hash{'internal.releaserequired'}});
16814: my ($switchserver,$switchwarning) =
16815: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16816: $curr_reqd_hash{'internal.releaserequired'});
16817: if ($switchwarning ne '' || $switchserver ne '') {
16818: return ('switch',$switchwarning,$switchserver);
16819: }
16820: }
16821: }
16822: return ('update');
16823: }
16824: }
16825: return ();
16826: }
1.1075.2.69 raeburn 16827:
1.1075.2.11 raeburn 16828: sub update_content_constraints {
16829: my ($cdom,$cnum,$chome,$cid) = @_;
16830: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16831: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16832: my %checkresponsetypes;
16833: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
16834: my ($item,$name,$value) = split(/:/,$key);
16835: if ($item eq 'resourcetag') {
16836: if ($name eq 'responsetype') {
16837: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
16838: }
16839: }
16840: }
16841: my $navmap = Apache::lonnavmaps::navmap->new();
16842: if (defined($navmap)) {
16843: my %allresponses;
16844: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
16845: my %responses = $res->responseTypes();
16846: foreach my $key (keys(%responses)) {
16847: next unless(exists($checkresponsetypes{$key}));
16848: $allresponses{$key} += $responses{$key};
16849: }
16850: }
16851: foreach my $key (keys(%allresponses)) {
16852: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
16853: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
16854: ($reqdmajor,$reqdminor) = ($major,$minor);
16855: }
16856: }
16857: undef($navmap);
16858: }
16859: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
16860: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
16861: }
16862: return;
16863: }
16864:
1.1075.2.27 raeburn 16865: sub allmaps_incourse {
16866: my ($cdom,$cnum,$chome,$cid) = @_;
16867: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
16868: $cid = $env{'request.course.id'};
16869: $cdom = $env{'course.'.$cid.'.domain'};
16870: $cnum = $env{'course.'.$cid.'.num'};
16871: $chome = $env{'course.'.$cid.'.home'};
16872: }
16873: my %allmaps = ();
16874: my $lastchange =
16875: &Apache::lonnet::get_coursechange($cdom,$cnum);
16876: if ($lastchange > $env{'request.course.tied'}) {
16877: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
16878: unless ($ferr) {
16879: &update_content_constraints($cdom,$cnum,$chome,$cid);
16880: }
16881: }
16882: my $navmap = Apache::lonnavmaps::navmap->new();
16883: if (defined($navmap)) {
16884: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
16885: $allmaps{$res->src()} = 1;
16886: }
16887: }
16888: return \%allmaps;
16889: }
16890:
1.1075.2.11 raeburn 16891: sub parse_supplemental_title {
16892: my ($title) = @_;
16893:
16894: my ($foldertitle,$renametitle);
16895: if ($title =~ /&&&/) {
16896: $title = &HTML::Entites::decode($title);
16897: }
16898: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
16899: $renametitle=$4;
16900: my ($time,$uname,$udom) = ($1,$2,$3);
16901: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
16902: my $name = &plainname($uname,$udom);
16903: $name = &HTML::Entities::encode($name,'"<>&\'');
16904: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
16905: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
16906: $name.': <br />'.$foldertitle;
16907: }
16908: if (wantarray) {
16909: return ($title,$foldertitle,$renametitle);
16910: }
16911: return $title;
16912: }
16913:
1.1075.2.43 raeburn 16914: sub recurse_supplemental {
16915: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
16916: if ($suppmap) {
16917: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16918: if ($fatal) {
16919: $errors ++;
16920: } else {
16921: if ($#LONCAPA::map::resources > 0) {
16922: foreach my $res (@LONCAPA::map::resources) {
16923: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16924: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 16925: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16926: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 16927: } else {
16928: $numfiles ++;
16929: }
16930: }
16931: }
16932: }
16933: }
16934: }
16935: return ($numfiles,$errors);
16936: }
16937:
1.1075.2.18 raeburn 16938: sub symb_to_docspath {
1.1075.2.119 raeburn 16939: my ($symb,$navmapref) = @_;
16940: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 16941: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
16942: if ($resurl=~/\.(sequence|page)$/) {
16943: $mapurl=$resurl;
16944: } elsif ($resurl eq 'adm/navmaps') {
16945: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
16946: }
16947: my $mapresobj;
1.1075.2.119 raeburn 16948: unless (ref($$navmapref)) {
16949: $$navmapref = Apache::lonnavmaps::navmap->new();
16950: }
16951: if (ref($$navmapref)) {
16952: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 16953: }
16954: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
16955: my $type=$2;
16956: my $path;
16957: if (ref($mapresobj)) {
16958: my $pcslist = $mapresobj->map_hierarchy();
16959: if ($pcslist ne '') {
16960: foreach my $pc (split(/,/,$pcslist)) {
16961: next if ($pc <= 1);
1.1075.2.119 raeburn 16962: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 16963: if (ref($res)) {
16964: my $thisurl = $res->src();
16965: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
16966: my $thistitle = $res->title();
16967: $path .= '&'.
16968: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 16969: &escape($thistitle).
1.1075.2.18 raeburn 16970: ':'.$res->randompick().
16971: ':'.$res->randomout().
16972: ':'.$res->encrypted().
16973: ':'.$res->randomorder().
16974: ':'.$res->is_page();
16975: }
16976: }
16977: }
16978: $path =~ s/^\&//;
16979: my $maptitle = $mapresobj->title();
16980: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16981: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16982: }
16983: $path .= (($path ne '')? '&' : '').
16984: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16985: &escape($maptitle).
1.1075.2.18 raeburn 16986: ':'.$mapresobj->randompick().
16987: ':'.$mapresobj->randomout().
16988: ':'.$mapresobj->encrypted().
16989: ':'.$mapresobj->randomorder().
16990: ':'.$mapresobj->is_page();
16991: } else {
16992: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16993: my $ispage = (($type eq 'page')? 1 : '');
16994: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16995: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16996: }
16997: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16998: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 16999: }
17000: unless ($mapurl eq 'default') {
17001: $path = 'default&'.
1.1075.2.46 raeburn 17002: &escape('Main Content').
1.1075.2.18 raeburn 17003: ':::::&'.$path;
17004: }
17005: return $path;
17006: }
17007:
1.1075.2.14 raeburn 17008: sub captcha_display {
1.1075.2.137 raeburn 17009: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 17010: my ($output,$error);
1.1075.2.107 raeburn 17011: my ($captcha,$pubkey,$privkey,$version) =
1.1075.2.137 raeburn 17012: &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 17013: if ($captcha eq 'original') {
17014: $output = &create_captcha();
17015: unless ($output) {
17016: $error = 'captcha';
17017: }
17018: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 17019: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 17020: unless ($output) {
17021: $error = 'recaptcha';
17022: }
17023: }
1.1075.2.107 raeburn 17024: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 17025: }
17026:
17027: sub captcha_response {
1.1075.2.137 raeburn 17028: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 17029: my ($captcha_chk,$captcha_error);
1.1075.2.137 raeburn 17030: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 17031: if ($captcha eq 'original') {
17032: ($captcha_chk,$captcha_error) = &check_captcha();
17033: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 17034: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 17035: } else {
17036: $captcha_chk = 1;
17037: }
17038: return ($captcha_chk,$captcha_error);
17039: }
17040:
17041: sub get_captcha_config {
1.1075.2.137 raeburn 17042: my ($context,$lonhost,$dom_in_effect) = @_;
1.1075.2.107 raeburn 17043: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 17044: my $hostname = &Apache::lonnet::hostname($lonhost);
17045: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17046: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17047: if ($context eq 'usercreation') {
17048: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17049: if (ref($domconfig{$context}) eq 'HASH') {
17050: $hashtocheck = $domconfig{$context}{'cancreate'};
17051: if (ref($hashtocheck) eq 'HASH') {
17052: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17053: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17054: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17055: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17056: }
17057: if ($privkey && $pubkey) {
17058: $captcha = 'recaptcha';
1.1075.2.107 raeburn 17059: $version = $hashtocheck->{'recaptchaversion'};
17060: if ($version ne '2') {
17061: $version = 1;
17062: }
1.1075.2.14 raeburn 17063: } else {
17064: $captcha = 'original';
17065: }
17066: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17067: $captcha = 'original';
17068: }
17069: }
17070: } else {
17071: $captcha = 'captcha';
17072: }
17073: } elsif ($context eq 'login') {
17074: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17075: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17076: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17077: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
17078: if ($privkey && $pubkey) {
17079: $captcha = 'recaptcha';
1.1075.2.107 raeburn 17080: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17081: if ($version ne '2') {
17082: $version = 1;
17083: }
1.1075.2.14 raeburn 17084: } else {
17085: $captcha = 'original';
17086: }
17087: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17088: $captcha = 'original';
17089: }
1.1075.2.137 raeburn 17090: } elsif ($context eq 'passwords') {
17091: if ($dom_in_effect) {
17092: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
17093: if ($passwdconf{'captcha'} eq 'recaptcha') {
17094: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
17095: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
17096: $privkey = $passwdconf{'recaptchakeys'}{'private'};
17097: }
17098: if ($privkey && $pubkey) {
17099: $captcha = 'recaptcha';
17100: $version = $passwdconf{'recaptchaversion'};
17101: if ($version ne '2') {
17102: $version = 1;
17103: }
17104: } else {
17105: $captcha = 'original';
17106: }
17107: } elsif ($passwdconf{'captcha'} ne 'notused') {
17108: $captcha = 'original';
17109: }
17110: }
1.1075.2.14 raeburn 17111: }
1.1075.2.107 raeburn 17112: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 17113: }
17114:
17115: sub create_captcha {
17116: my %captcha_params = &captcha_settings();
17117: my ($output,$maxtries,$tries) = ('',10,0);
17118: while ($tries < $maxtries) {
17119: $tries ++;
17120: my $captcha = Authen::Captcha->new (
17121: output_folder => $captcha_params{'output_dir'},
17122: data_folder => $captcha_params{'db_dir'},
17123: );
17124: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17125:
17126: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17127: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17128: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 17129: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17130: '<br />'.
17131: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 17132: last;
17133: }
17134: }
17135: return $output;
17136: }
17137:
17138: sub captcha_settings {
17139: my %captcha_params = (
17140: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17141: www_output_dir => "/captchaspool",
17142: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17143: numchars => '5',
17144: );
17145: return %captcha_params;
17146: }
17147:
17148: sub check_captcha {
17149: my ($captcha_chk,$captcha_error);
17150: my $code = $env{'form.code'};
17151: my $md5sum = $env{'form.crypt'};
17152: my %captcha_params = &captcha_settings();
17153: my $captcha = Authen::Captcha->new(
17154: output_folder => $captcha_params{'output_dir'},
17155: data_folder => $captcha_params{'db_dir'},
17156: );
1.1075.2.26 raeburn 17157: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 17158: my %captcha_hash = (
17159: 0 => 'Code not checked (file error)',
17160: -1 => 'Failed: code expired',
17161: -2 => 'Failed: invalid code (not in database)',
17162: -3 => 'Failed: invalid code (code does not match crypt)',
17163: );
17164: if ($captcha_chk != 1) {
17165: $captcha_error = $captcha_hash{$captcha_chk}
17166: }
17167: return ($captcha_chk,$captcha_error);
17168: }
17169:
17170: sub create_recaptcha {
1.1075.2.107 raeburn 17171: my ($pubkey,$version) = @_;
17172: if ($version >= 2) {
17173: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17174: } else {
17175: my $use_ssl;
17176: if ($ENV{'SERVER_PORT'} == 443) {
17177: $use_ssl = 1;
17178: }
17179: my $captcha = Captcha::reCAPTCHA->new;
17180: return $captcha->get_options_setter({theme => 'white'})."\n".
17181: $captcha->get_html($pubkey,undef,$use_ssl).
17182: &mt('If the text is hard to read, [_1] will replace them.',
17183: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17184: '<br /><br />';
17185: }
1.1075.2.14 raeburn 17186: }
17187:
17188: sub check_recaptcha {
1.1075.2.107 raeburn 17189: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 17190: my $captcha_chk;
1.1075.2.107 raeburn 17191: if ($version >= 2) {
17192: my $ua = LWP::UserAgent->new;
17193: $ua->timeout(10);
17194: my %info = (
17195: secret => $privkey,
17196: response => $env{'form.g-recaptcha-response'},
17197: remoteip => $ENV{'REMOTE_ADDR'},
17198: );
17199: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
17200: if ($response->is_success) {
17201: my $data = JSON::DWIW->from_json($response->decoded_content);
17202: if (ref($data) eq 'HASH') {
17203: if ($data->{'success'}) {
17204: $captcha_chk = 1;
17205: }
17206: }
17207: }
17208: } else {
17209: my $captcha = Captcha::reCAPTCHA->new;
17210: my $captcha_result =
17211: $captcha->check_answer(
17212: $privkey,
17213: $ENV{'REMOTE_ADDR'},
17214: $env{'form.recaptcha_challenge_field'},
17215: $env{'form.recaptcha_response_field'},
17216: );
17217: if ($captcha_result->{is_valid}) {
17218: $captcha_chk = 1;
17219: }
1.1075.2.14 raeburn 17220: }
17221: return $captcha_chk;
17222: }
17223:
1.1075.2.64 raeburn 17224: sub emailusername_info {
1.1075.2.103 raeburn 17225: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 17226: my %titles = &Apache::lonlocal::texthash (
17227: lastname => 'Last Name',
17228: firstname => 'First Name',
17229: institution => 'School/college/university',
17230: location => "School's city, state/province, country",
17231: web => "School's web address",
17232: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 17233: id => 'Student/Employee ID',
1.1075.2.64 raeburn 17234: );
17235: return (\@fields,\%titles);
17236: }
17237:
1.1075.2.56 raeburn 17238: sub cleanup_html {
17239: my ($incoming) = @_;
17240: my $outgoing;
17241: if ($incoming ne '') {
17242: $outgoing = $incoming;
17243: $outgoing =~ s/;/;/g;
17244: $outgoing =~ s/\#/#/g;
17245: $outgoing =~ s/\&/&/g;
17246: $outgoing =~ s/</</g;
17247: $outgoing =~ s/>/>/g;
17248: $outgoing =~ s/\(/(/g;
17249: $outgoing =~ s/\)/)/g;
17250: $outgoing =~ s/"/"/g;
17251: $outgoing =~ s/'/'/g;
17252: $outgoing =~ s/\$/$/g;
17253: $outgoing =~ s{/}{/}g;
17254: $outgoing =~ s/=/=/g;
17255: $outgoing =~ s/\\/\/g
17256: }
17257: return $outgoing;
17258: }
17259:
1.1075.2.74 raeburn 17260: # Checks for critical messages and returns a redirect url if one exists.
17261: # $interval indicates how often to check for messages.
1.1075.2.141. .6(raebu 17262:20): # $context is the calling context -- roles, grades, contents, menu or flip.
1.1075.2.74 raeburn 17263: sub critical_redirect {
1.1075.2.141. .6(raebu 17264:20): my ($interval,$context) = @_;
1.1075.2.74 raeburn 17265: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1075.2.141. .6(raebu 17266:20): if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
17267:20): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17268:20): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17269:20): my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
17270:20): if ($blocked) {
17271:20): my $checkrole = "cm./$cdom/$cnum";
17272:20): if ($env{'request.course.sec'} ne '') {
17273:20): $checkrole .= "/$env{'request.course.sec'}";
17274:20): }
17275:20): unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
17276:20): ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
17277:20): return;
17278:20): }
17279:20): }
17280:20): }
1.1075.2.74 raeburn 17281: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17282: $env{'user.name'});
17283: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
17284: my $redirecturl;
17285: if ($what[0]) {
17286: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17287: $redirecturl='/adm/email?critical=display';
17288: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17289: return (1, $url);
17290: }
17291: }
17292: }
17293: return ();
17294: }
17295:
1.1075.2.64 raeburn 17296: # Use:
17297: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17298: #
17299: ##################################################
17300: # password associated functions #
17301: ##################################################
17302: sub des_keys {
17303: # Make a new key for DES encryption.
17304: # Each key has two parts which are returned separately.
17305: # Please note: Each key must be passed through the &hex function
17306: # before it is output to the web browser. The hex versions cannot
17307: # be used to decrypt.
17308: my @hexstr=('0','1','2','3','4','5','6','7',
17309: '8','9','a','b','c','d','e','f');
17310: my $lkey='';
17311: for (0..7) {
17312: $lkey.=$hexstr[rand(15)];
17313: }
17314: my $ukey='';
17315: for (0..7) {
17316: $ukey.=$hexstr[rand(15)];
17317: }
17318: return ($lkey,$ukey);
17319: }
17320:
17321: sub des_decrypt {
17322: my ($key,$cyphertext) = @_;
17323: my $keybin=pack("H16",$key);
17324: my $cypher;
17325: if ($Crypt::DES::VERSION>=2.03) {
17326: $cypher=new Crypt::DES $keybin;
17327: } else {
17328: $cypher=new DES $keybin;
17329: }
1.1075.2.106 raeburn 17330: my $plaintext='';
17331: my $cypherlength = length($cyphertext);
17332: my $numchunks = int($cypherlength/32);
17333: for (my $j=0; $j<$numchunks; $j++) {
17334: my $start = $j*32;
17335: my $cypherblock = substr($cyphertext,$start,32);
17336: my $chunk =
17337: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17338: $chunk .=
17339: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17340: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17341: $plaintext .= $chunk;
17342: }
1.1075.2.64 raeburn 17343: return $plaintext;
17344: }
17345:
1.1075.2.141. .5(raebu 17346:20): sub get_requested_shorturls {
.1(raebu 17347:20): my ($cdom,$cnum,$navmap) = @_;
17348:20): return unless (ref($navmap));
.5(raebu 17349:20): my ($numnew,$errors);
.1(raebu 17350:20): my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
17351:20): if (@toshorten) {
17352:20): my (%maps,%resources,%titles);
17353:20): &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
17354:20): 'shorturls',$cdom,$cnum);
17355:20): if (keys(%resources)) {
.5(raebu 17356:20): my %tocreate;
.1(raebu 17357:20): foreach my $item (sort {$a <=> $b} (@toshorten)) {
17358:20): my $symb = $resources{$item};
17359:20): if ($symb) {
17360:20): $tocreate{$cnum.'&'.$symb} = 1;
17361:20): }
17362:20): }
.5(raebu 17363:20): if (keys(%tocreate)) {
17364:20): ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
17365:20): \%tocreate);
17366:20): }
.1(raebu 17367:20): }
.5(raebu 17368:20): }
17369:20): return ($numnew,$errors);
17370:20): }
17371:20):
17372:20): sub make_short_symbs {
17373:20): my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
17374:20): my ($numnew,@errors);
17375:20): if (ref($tocreateref) eq 'HASH') {
17376:20): my %tocreate = %{$tocreateref};
.1(raebu 17377:20): if (keys(%tocreate)) {
17378:20): my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
17379:20): my $su = Short::URL->new(no_vowels => 1);
17380:20): my $init = '';
17381:20): my (%newunique,%addcourse,%courseonly,%failed);
17382:20): # get lock on tiny db
17383:20): my $now = time;
.5(raebu 17384:20): if ($lockuser eq '') {
17385:20): $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
17386:20): }
.1(raebu 17387:20): my $lockhash = {
.5(raebu 17388:20): "lock\0$now" => $lockuser,
.1(raebu 17389:20): };
17390:20): my $tries = 0;
17391:20): my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
17392:20): my ($code,$error);
17393:20): while (($gotlock ne 'ok') && ($tries<3)) {
17394:20): $tries ++;
17395:20): sleep 1;
17396:20): $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
17397:20): }
17398:20): if ($gotlock eq 'ok') {
17399:20): $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
17400:20): \%addcourse,\%courseonly,\%failed);
17401:20): if (keys(%failed)) {
17402:20): my $numfailed = scalar(keys(%failed));
17403:20): push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
17404:20): }
17405:20): if (keys(%newunique)) {
17406:20): my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
17407:20): if ($putres eq 'ok') {
17408:20): $numnew = scalar(keys(%newunique));
17409:20): my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
17410:20): unless ($newputres eq 'ok') {
17411:20): push(@errors,&mt('error: could not store course look-up of short URLs'));
17412:20): }
17413:20): } else {
17414:20): push(@errors,&mt('error: could not store unique six character URLs'));
17415:20): }
17416:20): }
17417:20): }
17418:20): }
17419:20): }
17420:20): return ($numnew,\@errors);
17421:20): }
17422:20):
17423:20): sub shorten_symbs {
17424:20): my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
17425:20): return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
17426:20): (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
17427:20): (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
17428:20): my (%possibles,%collisions);
17429:20): foreach my $key (keys(%{$tocreate})) {
17430:20): my $num = String::CRC32::crc32($key);
17431:20): my $tiny = $su->encode($num,$init);
17432:20): if ($tiny) {
17433:20): $possibles{$tiny} = $key;
17434:20): }
17435:20): }
17436:20): if (!$init) {
17437:20): $init = 1;
17438:20): } else {
17439:20): $init ++;
17440:20): }
17441:20): if (keys(%possibles)) {
17442:20): my @posstiny = keys(%possibles);
17443:20): my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
17444:20): my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
17445:20): if (keys(%currtiny)) {
17446:20): foreach my $key (keys(%currtiny)) {
17447:20): next if ($currtiny{$key} eq '');
17448:20): if ($currtiny{$key} eq $possibles{$key}) {
17449:20): my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
17450:20): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
17451:20): $courseonly->{$tsymb} = $key;
17452:20): }
17453:20): } else {
17454:20): $collisions{$possibles{$key}} = 1;
17455:20): }
17456:20): delete($possibles{$key});
17457:20): }
17458:20): }
17459:20): foreach my $key (keys(%possibles)) {
17460:20): $newunique->{$key} = $possibles{$key};
17461:20): my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
17462:20): unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
17463:20): $addcourse->{$tsymb} = $key;
17464:20): }
17465:20): }
17466:20): }
17467:20): if (keys(%collisions)) {
17468:20): if ($init <5) {
17469:20): if (!$init) {
17470:20): $init = 1;
17471:20): } else {
17472:20): $init ++;
17473:20): }
17474:20): $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
17475:20): $newunique,$addcourse,$courseonly,$failed);
17476:20): } else {
17477:20): foreach my $key (keys(%collisions)) {
17478:20): $failed->{$key} = 1;
17479:20): $failed->{$key} = 1;
17480:20): }
17481:20): }
17482:20): }
17483:20): return $init;
17484:20): }
17485:20):
1.1075.2.135 raeburn 17486: sub is_nonframeable {
17487: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
17488: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
17489: return if (($remprotocol eq '') || ($remhost eq ''));
17490:
17491: $remprotocol = lc($remprotocol);
17492: $remhost = lc($remhost);
17493: my $remport = 80;
17494: if ($remprotocol eq 'https') {
17495: $remport = 443;
17496: }
17497: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
17498: if ($cached) {
17499: unless ($nocache) {
17500: if ($result) {
17501: return 1;
17502: } else {
17503: return 0;
17504: }
17505: }
17506: }
17507: my $uselink;
17508: my $request = new HTTP::Request('HEAD',$url);
1.1075.2.141. .2(raebu 17509:20): my $ua = LWP::UserAgent->new;
17510:20): $ua->timeout(5);
17511:20): my $response=$ua->request($request);
1.1075.2.135 raeburn 17512: if ($response->is_success()) {
17513: my $secpolicy = lc($response->header('content-security-policy'));
17514: my $xframeop = lc($response->header('x-frame-options'));
17515: $secpolicy =~ s/^\s+|\s+$//g;
17516: $xframeop =~ s/^\s+|\s+$//g;
17517: if (($secpolicy ne '') || ($xframeop ne '')) {
17518: my $remotehost = $remprotocol.'://'.$remhost;
17519: my ($origin,$protocol,$port);
17520: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
17521: $port = $ENV{'SERVER_PORT'};
17522: } else {
17523: $port = 80;
17524: }
17525: if ($absolute eq '') {
17526: $protocol = 'http:';
17527: if ($port == 443) {
17528: $protocol = 'https:';
17529: }
17530: $origin = $protocol.'//'.lc($hostname);
17531: } else {
17532: $origin = lc($absolute);
17533: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
17534: }
17535: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
17536: my $framepolicy = $1;
17537: $framepolicy =~ s/^\s+|\s+$//g;
17538: my @policies = split(/\s+/,$framepolicy);
17539: if (@policies) {
17540: if (grep(/^\Q'none'\E$/,@policies)) {
17541: $uselink = 1;
17542: } else {
17543: $uselink = 1;
17544: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
17545: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
17546: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
17547: undef($uselink);
17548: }
17549: if ($uselink) {
17550: if (grep(/^\Q'self'\E$/,@policies)) {
17551: if (($origin ne '') && ($remotehost eq $origin)) {
17552: undef($uselink);
17553: }
17554: }
17555: }
17556: if ($uselink) {
17557: my @possok;
17558: if ($ip ne '') {
17559: push(@possok,$ip);
17560: }
17561: my $hoststr = '';
17562: foreach my $part (reverse(split(/\./,$hostname))) {
17563: if ($hoststr eq '') {
17564: $hoststr = $part;
17565: } else {
17566: $hoststr = "$part.$hoststr";
17567: }
17568: if ($hoststr eq $hostname) {
17569: push(@possok,$hostname);
17570: } else {
17571: push(@possok,"*.$hoststr");
17572: }
17573: }
17574: if (@possok) {
17575: foreach my $poss (@possok) {
17576: last if (!$uselink);
17577: foreach my $policy (@policies) {
17578: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
17579: undef($uselink);
17580: last;
17581: }
17582: }
17583: }
17584: }
17585: }
17586: }
17587: }
17588: } elsif ($xframeop ne '') {
17589: $uselink = 1;
17590: my @policies = split(/\s*,\s*/,$xframeop);
17591: if (@policies) {
17592: unless (grep(/^deny$/,@policies)) {
17593: if ($origin ne '') {
17594: if (grep(/^sameorigin$/,@policies)) {
17595: if ($remotehost eq $origin) {
17596: undef($uselink);
17597: }
17598: }
17599: if ($uselink) {
17600: foreach my $policy (@policies) {
17601: if ($policy =~ /^allow-from\s*(.+)$/) {
17602: my $allowfrom = $1;
17603: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
17604: undef($uselink);
17605: last;
17606: }
17607: }
17608: }
17609: }
17610: }
17611: }
17612: }
17613: }
17614: }
17615: }
17616: if ($nocache) {
17617: if ($cached) {
17618: my $devalidate;
17619: if ($uselink && !$result) {
17620: $devalidate = 1;
17621: } elsif (!$uselink && $result) {
17622: $devalidate = 1;
17623: }
17624: if ($devalidate) {
17625: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
17626: }
17627: }
17628: } else {
17629: if ($uselink) {
17630: $result = 1;
17631: } else {
17632: $result = 0;
17633: }
17634: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
17635: }
17636: return $uselink;
17637: }
17638:
1.112 bowersj2 17639: 1;
17640: __END__;
1.41 ng 17641:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>