Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.148
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.148! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.147 2020/09/28 00:38:30 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.117 www 86:
1.517 raeburn 87: # ---------------------------------------------- Designs
88: use vars qw(%defaultdesign);
89:
1.22 www 90: my $readit;
91:
1.517 raeburn 92:
1.157 matthew 93: ##
94: ## Global Variables
95: ##
1.46 matthew 96:
1.643 foxr 97:
98: # ----------------------------------------------- SSI with retries:
99: #
100:
101: =pod
102:
1.648 raeburn 103: =head1 Server Side include with retries:
1.643 foxr 104:
105: =over 4
106:
1.648 raeburn 107: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 108:
109: Performs an ssi with some number of retries. Retries continue either
110: until the result is ok or until the retry count supplied by the
111: caller is exhausted.
112:
113: Inputs:
1.648 raeburn 114:
115: =over 4
116:
1.643 foxr 117: resource - Identifies the resource to insert.
1.648 raeburn 118:
1.643 foxr 119: retries - Count of the number of retries allowed.
1.648 raeburn 120:
1.643 foxr 121: form - Hash that identifies the rendering options.
122:
1.648 raeburn 123: =back
124:
125: Returns:
126:
127: =over 4
128:
1.643 foxr 129: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 130:
1.643 foxr 131: response - The response from the last attempt (which may or may not have been successful.
132:
1.648 raeburn 133: =back
134:
135: =back
136:
1.643 foxr 137: =cut
138:
139: sub ssi_with_retries {
140: my ($resource, $retries, %form) = @_;
141:
142:
143: my $ok = 0; # True if we got a good response.
144: my $content;
145: my $response;
146:
147: # Try to get the ssi done. within the retries count:
148:
149: do {
150: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
151: $ok = $response->is_success;
1.650 www 152: if (!$ok) {
153: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
154: }
1.643 foxr 155: $retries--;
156: } while (!$ok && ($retries > 0));
157:
158: if (!$ok) {
159: $content = ''; # On error return an empty content.
160: }
161: return ($content, $response);
162:
163: }
164:
165:
166:
1.20 www 167: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 168: my %language;
1.124 www 169: my %supported_language;
1.1048 foxr 170: my %latex_language; # For choosing hyphenation in <transl..>
171: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 172: my %cprtag;
1.192 taceyjo1 173: my %scprtag;
1.351 www 174: my %fe; my %fd; my %fm;
1.41 ng 175: my %category_extensions;
1.12 harris41 176:
1.46 matthew 177: # ---------------------------------------------- Thesaurus variables
1.144 matthew 178: #
179: # %Keywords:
180: # A hash used by &keyword to determine if a word is considered a keyword.
181: # $thesaurus_db_file
182: # Scalar containing the full path to the thesaurus database.
1.46 matthew 183:
184: my %Keywords;
185: my $thesaurus_db_file;
186:
1.144 matthew 187: #
188: # Initialize values from language.tab, copyright.tab, filetypes.tab,
189: # thesaurus.tab, and filecategories.tab.
190: #
1.18 www 191: BEGIN {
1.46 matthew 192: # Variable initialization
193: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
194: #
1.22 www 195: unless ($readit) {
1.12 harris41 196: # ------------------------------------------------------------------- languages
197: {
1.158 raeburn 198: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
199: '/language.tab';
1.1075.2.128 raeburn 200: if ( open(my $fh,'<',$langtabfile) ) {
1.356 albertel 201: while (my $line = <$fh>) {
202: next if ($line=~/^\#/);
203: chomp($line);
1.1048 foxr 204: my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 205: $language{$key}=$val.' - '.$enc;
206: if ($sup) {
207: $supported_language{$key}=$sup;
208: }
1.1048 foxr 209: if ($latex) {
210: $latex_language_bykey{$key} = $latex;
211: $latex_language{$two} = $latex;
212: }
1.158 raeburn 213: }
214: close($fh);
215: }
1.12 harris41 216: }
217: # ------------------------------------------------------------------ copyrights
218: {
1.158 raeburn 219: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
220: '/copyright.tab';
1.1075.2.128 raeburn 221: if ( open (my $fh,'<',$copyrightfile) ) {
1.356 albertel 222: while (my $line = <$fh>) {
223: next if ($line=~/^\#/);
224: chomp($line);
225: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 226: $cprtag{$key}=$val;
227: }
228: close($fh);
229: }
1.12 harris41 230: }
1.351 www 231: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 232: {
233: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
234: '/source_copyright.tab';
1.1075.2.128 raeburn 235: if ( open (my $fh,'<',$sourcecopyrightfile) ) {
1.356 albertel 236: while (my $line = <$fh>) {
237: next if ($line =~ /^\#/);
238: chomp($line);
239: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 240: $scprtag{$key}=$val;
241: }
242: close($fh);
243: }
244: }
1.63 www 245:
1.517 raeburn 246: # -------------------------------------------------------------- default domain designs
1.63 www 247: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 248: my $designfile = $designdir.'/default.tab';
1.1075.2.128 raeburn 249: if ( open (my $fh,'<',$designfile) ) {
1.517 raeburn 250: while (my $line = <$fh>) {
251: next if ($line =~ /^\#/);
252: chomp($line);
253: my ($key,$val)=(split(/\=/,$line));
254: if ($val) { $defaultdesign{$key}=$val; }
255: }
256: close($fh);
1.63 www 257: }
258:
1.15 harris41 259: # ------------------------------------------------------------- file categories
260: {
1.158 raeburn 261: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
262: '/filecategories.tab';
1.1075.2.128 raeburn 263: if ( open (my $fh,'<',$categoryfile) ) {
1.356 albertel 264: while (my $line = <$fh>) {
265: next if ($line =~ /^\#/);
266: chomp($line);
267: my ($extension,$category)=(split(/\s+/,$line,2));
1.1075.2.119 raeburn 268: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 269: }
270: close($fh);
271: }
272:
1.15 harris41 273: }
1.12 harris41 274: # ------------------------------------------------------------------ file types
275: {
1.158 raeburn 276: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
277: '/filetypes.tab';
1.1075.2.128 raeburn 278: if ( open (my $fh,'<',$typesfile) ) {
1.356 albertel 279: while (my $line = <$fh>) {
280: next if ($line =~ /^\#/);
281: chomp($line);
282: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 283: if ($descr ne '') {
284: $fe{$ending}=lc($emb);
285: $fd{$ending}=$descr;
1.351 www 286: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 287: }
288: }
289: close($fh);
290: }
1.12 harris41 291: }
1.22 www 292: &Apache::lonnet::logthis(
1.705 tempelho 293: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 294: $readit=1;
1.46 matthew 295: } # end of unless($readit)
1.32 matthew 296:
297: }
1.112 bowersj2 298:
1.42 matthew 299: ###############################################################
300: ## HTML and Javascript Helper Functions ##
301: ###############################################################
302:
303: =pod
304:
1.112 bowersj2 305: =head1 HTML and Javascript Functions
1.42 matthew 306:
1.112 bowersj2 307: =over 4
308:
1.648 raeburn 309: =item * &browser_and_searcher_javascript()
1.112 bowersj2 310:
311: X<browsing, javascript>X<searching, javascript>Returns a string
312: containing javascript with two functions, C<openbrowser> and
313: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
314: tags.
1.42 matthew 315:
1.648 raeburn 316: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 317:
318: inputs: formname, elementname, only, omit
319:
320: formname and elementname indicate the name of the html form and name of
321: the element that the results of the browsing selection are to be placed in.
322:
323: Specifying 'only' will restrict the browser to displaying only files
1.185 www 324: with the given extension. Can be a comma separated list.
1.42 matthew 325:
326: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 327: with the given extension. Can be a comma separated list.
1.42 matthew 328:
1.648 raeburn 329: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 330:
331: Inputs: formname, elementname
332:
333: formname and elementname specify the name of the html form and the name
334: of the element the selection from the search results will be placed in.
1.542 raeburn 335:
1.42 matthew 336: =cut
337:
338: sub browser_and_searcher_javascript {
1.199 albertel 339: my ($mode)=@_;
340: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 341: my $resurl=&escape_single(&lastresurl());
1.42 matthew 342: return <<END;
1.219 albertel 343: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 344: var editbrowser = null;
1.135 albertel 345: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 346: var url = '$resurl/?';
1.42 matthew 347: if (editbrowser == null) {
348: url += 'launch=1&';
349: }
350: url += 'catalogmode=interactive&';
1.199 albertel 351: url += 'mode=$mode&';
1.611 albertel 352: url += 'inhibitmenu=yes&';
1.42 matthew 353: url += 'form=' + formname + '&';
354: if (only != null) {
355: url += 'only=' + only + '&';
1.217 albertel 356: } else {
357: url += 'only=&';
358: }
1.42 matthew 359: if (omit != null) {
360: url += 'omit=' + omit + '&';
1.217 albertel 361: } else {
362: url += 'omit=&';
363: }
1.135 albertel 364: if (titleelement != null) {
365: url += 'titleelement=' + titleelement + '&';
1.217 albertel 366: } else {
367: url += 'titleelement=&';
368: }
1.42 matthew 369: url += 'element=' + elementname + '';
370: var title = 'Browser';
1.435 albertel 371: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 372: options += ',width=700,height=600';
373: editbrowser = open(url,title,options,'1');
374: editbrowser.focus();
375: }
376: var editsearcher;
1.135 albertel 377: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 378: var url = '/adm/searchcat?';
379: if (editsearcher == null) {
380: url += 'launch=1&';
381: }
382: url += 'catalogmode=interactive&';
1.199 albertel 383: url += 'mode=$mode&';
1.42 matthew 384: url += 'form=' + formname + '&';
1.135 albertel 385: if (titleelement != null) {
386: url += 'titleelement=' + titleelement + '&';
1.217 albertel 387: } else {
388: url += 'titleelement=&';
389: }
1.42 matthew 390: url += 'element=' + elementname + '';
391: var title = 'Search';
1.435 albertel 392: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 393: options += ',width=700,height=600';
394: editsearcher = open(url,title,options,'1');
395: editsearcher.focus();
396: }
1.219 albertel 397: // END LON-CAPA Internal -->
1.42 matthew 398: END
1.170 www 399: }
400:
401: sub lastresurl {
1.258 albertel 402: if ($env{'environment.lastresurl'}) {
403: return $env{'environment.lastresurl'}
1.170 www 404: } else {
405: return '/res';
406: }
407: }
408:
409: sub storeresurl {
410: my $resurl=&Apache::lonnet::clutter(shift);
411: unless ($resurl=~/^\/res/) { return 0; }
412: $resurl=~s/\/$//;
413: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 414: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 415: return 1;
1.42 matthew 416: }
417:
1.74 www 418: sub studentbrowser_javascript {
1.111 www 419: unless (
1.258 albertel 420: (($env{'request.course.id'}) &&
1.302 albertel 421: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
422: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
423: '/'.$env{'request.course.sec'})
424: ))
1.258 albertel 425: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 426: ) { return ''; }
1.74 www 427: return (<<'ENDSTDBRW');
1.776 bisitz 428: <script type="text/javascript" language="Javascript">
1.824 bisitz 429: // <![CDATA[
1.74 www 430: var stdeditbrowser;
1.1075.2.143 raeburn 431: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadv) {
1.74 www 432: var url = '/adm/pickstudent?';
433: var filter;
1.558 albertel 434: if (!ignorefilter) {
435: eval('filter=document.'+formname+'.'+uname+'.value;');
436: }
1.74 www 437: if (filter != null) {
438: if (filter != '') {
439: url += 'filter='+filter+'&';
440: }
441: }
442: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 443: '&udomelement='+udom+
444: '&clicker='+clicker;
1.111 www 445: if (roleflag) { url+="&roles=1"; }
1.1075.2.143 raeburn 446: if (courseadv == 'condition') {
447: if (document.getElementById('courseadv')) {
448: courseadv = document.getElementById('courseadv').value;
449: }
450: }
451: if ((courseadv == 'only') || (courseadv == 'none')) { url+="&courseadv="+courseadv; }
1.102 www 452: var title = 'Student_Browser';
1.74 www 453: var options = 'scrollbars=1,resizable=1,menubar=0';
454: options += ',width=700,height=600';
455: stdeditbrowser = open(url,title,options,'1');
456: stdeditbrowser.focus();
457: }
1.824 bisitz 458: // ]]>
1.74 www 459: </script>
460: ENDSTDBRW
461: }
1.42 matthew 462:
1.1003 www 463: sub resourcebrowser_javascript {
464: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 465: return (<<'ENDRESBRW');
1.1003 www 466: <script type="text/javascript" language="Javascript">
467: // <![CDATA[
468: var reseditbrowser;
1.1004 www 469: function openresbrowser(formname,reslink) {
1.1005 www 470: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 471: var title = 'Resource_Browser';
472: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 473: options += ',width=700,height=500';
1.1004 www 474: reseditbrowser = open(url,title,options,'1');
475: reseditbrowser.focus();
1.1003 www 476: }
477: // ]]>
478: </script>
1.1004 www 479: ENDRESBRW
1.1003 www 480: }
481:
1.74 www 482: sub selectstudent_link {
1.1075.2.143 raeburn 483: my ($form,$unameele,$udomele,$courseadv,$clickerid)=@_;
1.999 www 484: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
485: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
486: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 487: if ($env{'request.course.id'}) {
1.302 albertel 488: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
489: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
490: '/'.$env{'request.course.sec'})) {
1.111 www 491: return '';
492: }
1.999 www 493: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.1075.2.143 raeburn 494: if ($courseadv eq 'only') {
495: $callargs .= ",'',1,'$courseadv'";
496: } elsif ($courseadv eq 'none') {
497: $callargs .= ",'','','$courseadv'";
498: } elsif ($courseadv eq 'condition') {
499: $callargs .= ",'','','$courseadv'";
1.793 raeburn 500: }
501: return '<span class="LC_nobreak">'.
502: '<a href="javascript:openstdbrowser('.$callargs.');">'.
503: &mt('Select User').'</a></span>';
1.74 www 504: }
1.258 albertel 505: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 506: $callargs .= ",'',1";
1.793 raeburn 507: return '<span class="LC_nobreak">'.
508: '<a href="javascript:openstdbrowser('.$callargs.');">'.
509: &mt('Select User').'</a></span>';
1.111 www 510: }
511: return '';
1.91 www 512: }
513:
1.1004 www 514: sub selectresource_link {
515: my ($form,$reslink,$arg)=@_;
516:
517: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
518: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
519: unless ($env{'request.course.id'}) { return $arg; }
520: return '<span class="LC_nobreak">'.
521: '<a href="javascript:openresbrowser('.$callargs.');">'.
522: $arg.'</a></span>';
523: }
524:
525:
526:
1.653 raeburn 527: sub authorbrowser_javascript {
528: return <<"ENDAUTHORBRW";
1.776 bisitz 529: <script type="text/javascript" language="JavaScript">
1.824 bisitz 530: // <![CDATA[
1.653 raeburn 531: var stdeditbrowser;
532:
533: function openauthorbrowser(formname,udom) {
534: var url = '/adm/pickauthor?';
535: url += 'form='+formname+'&roledom='+udom;
536: var title = 'Author_Browser';
537: var options = 'scrollbars=1,resizable=1,menubar=0';
538: options += ',width=700,height=600';
539: stdeditbrowser = open(url,title,options,'1');
540: stdeditbrowser.focus();
541: }
542:
1.824 bisitz 543: // ]]>
1.653 raeburn 544: </script>
545: ENDAUTHORBRW
546: }
547:
1.91 www 548: sub coursebrowser_javascript {
1.1075.2.31 raeburn 549: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1075.2.95 raeburn 550: $credits_element,$instcode) = @_;
1.932 raeburn 551: my $wintitle = 'Course_Browser';
1.931 raeburn 552: if ($crstype eq 'Community') {
1.932 raeburn 553: $wintitle = 'Community_Browser';
1.909 raeburn 554: }
1.876 raeburn 555: my $id_functions = &javascript_index_functions();
556: my $output = '
1.776 bisitz 557: <script type="text/javascript" language="JavaScript">
1.824 bisitz 558: // <![CDATA[
1.468 raeburn 559: var stdeditbrowser;'."\n";
1.876 raeburn 560:
561: $output .= <<"ENDSTDBRW";
1.909 raeburn 562: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 563: var url = '/adm/pickcourse?';
1.895 raeburn 564: var formid = getFormIdByName(formname);
1.876 raeburn 565: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 566: if (domainfilter != null) {
567: if (domainfilter != '') {
568: url += 'domainfilter='+domainfilter+'&';
569: }
570: }
1.91 www 571: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 572: '&cdomelement='+udom+
573: '&cnameelement='+desc;
1.468 raeburn 574: if (extra_element !=null && extra_element != '') {
1.594 raeburn 575: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 576: url += '&roleelement='+extra_element;
577: if (domainfilter == null || domainfilter == '') {
578: url += '&domainfilter='+extra_element;
579: }
1.234 raeburn 580: }
1.468 raeburn 581: else {
582: if (formname == 'portform') {
583: url += '&setroles='+extra_element;
1.800 raeburn 584: } else {
585: if (formname == 'rules') {
586: url += '&fixeddom='+extra_element;
587: }
1.468 raeburn 588: }
589: }
1.230 raeburn 590: }
1.909 raeburn 591: if (type != null && type != '') {
592: url += '&type='+type;
593: }
594: if (type_elem != null && type_elem != '') {
595: url += '&typeelement='+type_elem;
596: }
1.872 raeburn 597: if (formname == 'ccrs') {
598: var ownername = document.forms[formid].ccuname.value;
599: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1075.2.101 raeburn 600: url += '&cloner='+ownername+':'+ownerdom;
601: if (type == 'Course') {
602: url += '&crscode='+document.forms[formid].crscode.value;
603: }
1.1075.2.95 raeburn 604: }
605: if (formname == 'requestcrs') {
606: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 607: }
1.293 raeburn 608: if (multflag !=null && multflag != '') {
609: url += '&multiple='+multflag;
610: }
1.909 raeburn 611: var title = '$wintitle';
1.91 www 612: var options = 'scrollbars=1,resizable=1,menubar=0';
613: options += ',width=700,height=600';
614: stdeditbrowser = open(url,title,options,'1');
615: stdeditbrowser.focus();
616: }
1.876 raeburn 617: $id_functions
618: ENDSTDBRW
1.1075.2.31 raeburn 619: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
620: $output .= &setsec_javascript($sec_element,$formname,$role_element,
621: $credits_element);
1.876 raeburn 622: }
623: $output .= '
624: // ]]>
625: </script>';
626: return $output;
627: }
628:
629: sub javascript_index_functions {
630: return <<"ENDJS";
631:
632: function getFormIdByName(formname) {
633: for (var i=0;i<document.forms.length;i++) {
634: if (document.forms[i].name == formname) {
635: return i;
636: }
637: }
638: return -1;
639: }
640:
641: function getIndexByName(formid,item) {
642: for (var i=0;i<document.forms[formid].elements.length;i++) {
643: if (document.forms[formid].elements[i].name == item) {
644: return i;
645: }
646: }
647: return -1;
648: }
1.468 raeburn 649:
1.876 raeburn 650: function getDomainFromSelectbox(formname,udom) {
651: var userdom;
652: var formid = getFormIdByName(formname);
653: if (formid > -1) {
654: var domid = getIndexByName(formid,udom);
655: if (domid > -1) {
656: if (document.forms[formid].elements[domid].type == 'select-one') {
657: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
658: }
659: if (document.forms[formid].elements[domid].type == 'hidden') {
660: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 661: }
662: }
663: }
1.876 raeburn 664: return userdom;
665: }
666:
667: ENDJS
1.468 raeburn 668:
1.876 raeburn 669: }
670:
1.1017 raeburn 671: sub javascript_array_indexof {
1.1018 raeburn 672: return <<ENDJS;
1.1017 raeburn 673: <script type="text/javascript" language="JavaScript">
674: // <![CDATA[
675:
676: if (!Array.prototype.indexOf) {
677: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
678: "use strict";
679: if (this === void 0 || this === null) {
680: throw new TypeError();
681: }
682: var t = Object(this);
683: var len = t.length >>> 0;
684: if (len === 0) {
685: return -1;
686: }
687: var n = 0;
688: if (arguments.length > 0) {
689: n = Number(arguments[1]);
690: if (n !== n) { // shortcut for verifying if it's NaN
691: n = 0;
692: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
693: n = (n > 0 || -1) * Math.floor(Math.abs(n));
694: }
695: }
696: if (n >= len) {
697: return -1;
698: }
699: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
700: for (; k < len; k++) {
701: if (k in t && t[k] === searchElement) {
702: return k;
703: }
704: }
705: return -1;
706: }
707: }
708:
709: // ]]>
710: </script>
711:
712: ENDJS
713:
714: }
715:
1.876 raeburn 716: sub userbrowser_javascript {
717: my $id_functions = &javascript_index_functions();
718: return <<"ENDUSERBRW";
719:
1.888 raeburn 720: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 721: var url = '/adm/pickuser?';
722: var userdom = getDomainFromSelectbox(formname,udom);
723: if (userdom != null) {
724: if (userdom != '') {
725: url += 'srchdom='+userdom+'&';
726: }
727: }
728: url += 'form=' + formname + '&unameelement='+uname+
729: '&udomelement='+udom+
730: '&ulastelement='+ulast+
731: '&ufirstelement='+ufirst+
732: '&uemailelement='+uemail+
1.881 raeburn 733: '&hideudomelement='+hideudom+
734: '&coursedom='+crsdom;
1.888 raeburn 735: if ((caller != null) && (caller != undefined)) {
736: url += '&caller='+caller;
737: }
1.876 raeburn 738: var title = 'User_Browser';
739: var options = 'scrollbars=1,resizable=1,menubar=0';
740: options += ',width=700,height=600';
741: var stdeditbrowser = open(url,title,options,'1');
742: stdeditbrowser.focus();
743: }
744:
1.888 raeburn 745: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 746: var formid = getFormIdByName(formname);
747: if (formid > -1) {
1.888 raeburn 748: var unameid = getIndexByName(formid,uname);
1.876 raeburn 749: var domid = getIndexByName(formid,udom);
750: var hidedomid = getIndexByName(formid,origdom);
751: if (hidedomid > -1) {
752: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 753: var unameval = document.forms[formid].elements[unameid].value;
754: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
755: if (domid > -1) {
756: var slct = document.forms[formid].elements[domid];
757: if (slct.type == 'select-one') {
758: var i;
759: for (i=0;i<slct.length;i++) {
760: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
761: }
762: }
763: if (slct.type == 'hidden') {
764: slct.value = fixeddom;
1.876 raeburn 765: }
766: }
1.468 raeburn 767: }
768: }
769: }
1.876 raeburn 770: return;
771: }
772:
773: $id_functions
774: ENDUSERBRW
1.468 raeburn 775: }
776:
777: sub setsec_javascript {
1.1075.2.31 raeburn 778: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 779: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
780: $communityrolestr);
781: if ($role_element ne '') {
782: my @allroles = ('st','ta','ep','in','ad');
783: foreach my $crstype ('Course','Community') {
784: if ($crstype eq 'Community') {
785: foreach my $role (@allroles) {
786: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
787: }
788: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
789: } else {
790: foreach my $role (@allroles) {
791: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
792: }
793: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
794: }
795: }
796: $rolestr = '"'.join('","',@allroles).'"';
797: $courserolestr = '"'.join('","',@courserolenames).'"';
798: $communityrolestr = '"'.join('","',@communityrolenames).'"';
799: }
1.468 raeburn 800: my $setsections = qq|
801: function setSect(sectionlist) {
1.629 raeburn 802: var sectionsArray = new Array();
803: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
804: sectionsArray = sectionlist.split(",");
805: }
1.468 raeburn 806: var numSections = sectionsArray.length;
807: document.$formname.$sec_element.length = 0;
808: if (numSections == 0) {
809: document.$formname.$sec_element.multiple=false;
810: document.$formname.$sec_element.size=1;
811: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
812: } else {
813: if (numSections == 1) {
814: document.$formname.$sec_element.multiple=false;
815: document.$formname.$sec_element.size=1;
816: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
817: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
818: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
819: } else {
820: for (var i=0; i<numSections; i++) {
821: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
822: }
823: document.$formname.$sec_element.multiple=true
824: if (numSections < 3) {
825: document.$formname.$sec_element.size=numSections;
826: } else {
827: document.$formname.$sec_element.size=3;
828: }
829: document.$formname.$sec_element.options[0].selected = false
830: }
831: }
1.91 www 832: }
1.905 raeburn 833:
834: function setRole(crstype) {
1.468 raeburn 835: |;
1.905 raeburn 836: if ($role_element eq '') {
837: $setsections .= ' return;
838: }
839: ';
840: } else {
841: $setsections .= qq|
842: var elementLength = document.$formname.$role_element.length;
843: var allroles = Array($rolestr);
844: var courserolenames = Array($courserolestr);
845: var communityrolenames = Array($communityrolestr);
846: if (elementLength != undefined) {
847: if (document.$formname.$role_element.options[5].value == 'cc') {
848: if (crstype == 'Course') {
849: return;
850: } else {
851: allroles[5] = 'co';
852: for (var i=0; i<6; i++) {
853: document.$formname.$role_element.options[i].value = allroles[i];
854: document.$formname.$role_element.options[i].text = communityrolenames[i];
855: }
856: }
857: } else {
858: if (crstype == 'Community') {
859: return;
860: } else {
861: allroles[5] = 'cc';
862: for (var i=0; i<6; i++) {
863: document.$formname.$role_element.options[i].value = allroles[i];
864: document.$formname.$role_element.options[i].text = courserolenames[i];
865: }
866: }
867: }
868: }
869: return;
870: }
871: |;
872: }
1.1075.2.31 raeburn 873: if ($credits_element) {
874: $setsections .= qq|
875: function setCredits(defaultcredits) {
876: document.$formname.$credits_element.value = defaultcredits;
877: return;
878: }
879: |;
880: }
1.468 raeburn 881: return $setsections;
882: }
883:
1.91 www 884: sub selectcourse_link {
1.909 raeburn 885: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
886: $typeelement) = @_;
887: my $type = $selecttype;
1.871 raeburn 888: my $linktext = &mt('Select Course');
889: if ($selecttype eq 'Community') {
1.909 raeburn 890: $linktext = &mt('Select Community');
1.906 raeburn 891: } elsif ($selecttype eq 'Course/Community') {
892: $linktext = &mt('Select Course/Community');
1.909 raeburn 893: $type = '';
1.1019 raeburn 894: } elsif ($selecttype eq 'Select') {
895: $linktext = &mt('Select');
896: $type = '';
1.871 raeburn 897: }
1.787 bisitz 898: return '<span class="LC_nobreak">'
899: ."<a href='"
900: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
901: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 902: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 903: ."'>".$linktext.'</a>'
1.787 bisitz 904: .'</span>';
1.74 www 905: }
1.42 matthew 906:
1.653 raeburn 907: sub selectauthor_link {
908: my ($form,$udom)=@_;
909: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
910: &mt('Select Author').'</a>';
911: }
912:
1.876 raeburn 913: sub selectuser_link {
1.881 raeburn 914: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 915: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 916: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 917: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 918: ');">'.$linktext.'</a>';
1.876 raeburn 919: }
920:
1.273 raeburn 921: sub check_uncheck_jscript {
922: my $jscript = <<"ENDSCRT";
923: function checkAll(field) {
924: if (field.length > 0) {
925: for (i = 0; i < field.length; i++) {
1.1075.2.14 raeburn 926: if (!field[i].disabled) {
927: field[i].checked = true;
928: }
1.273 raeburn 929: }
930: } else {
1.1075.2.14 raeburn 931: if (!field.disabled) {
932: field.checked = true;
933: }
1.273 raeburn 934: }
935: }
936:
937: function uncheckAll(field) {
938: if (field.length > 0) {
939: for (i = 0; i < field.length; i++) {
940: field[i].checked = false ;
1.543 albertel 941: }
942: } else {
1.273 raeburn 943: field.checked = false ;
944: }
945: }
946: ENDSCRT
947: return $jscript;
948: }
949:
1.656 www 950: sub select_timezone {
1.1075.2.115 raeburn 951: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
952: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 953: if ($includeempty) {
954: $output .= '<option value=""';
955: if (($selected eq '') || ($selected eq 'local')) {
956: $output .= ' selected="selected" ';
957: }
958: $output .= '> </option>';
959: }
1.657 raeburn 960: my @timezones = DateTime::TimeZone->all_names;
961: foreach my $tzone (@timezones) {
962: $output.= '<option value="'.$tzone.'"';
963: if ($tzone eq $selected) {
964: $output.=' selected="selected"';
965: }
966: $output.=">$tzone</option>\n";
1.656 www 967: }
968: $output.="</select>";
969: return $output;
970: }
1.273 raeburn 971:
1.687 raeburn 972: sub select_datelocale {
1.1075.2.115 raeburn 973: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
974: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 975: if ($includeempty) {
976: $output .= '<option value=""';
977: if ($selected eq '') {
978: $output .= ' selected="selected" ';
979: }
980: $output .= '> </option>';
981: }
1.1075.2.102 raeburn 982: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 983: my (@possibles,%locale_names);
1.1075.2.102 raeburn 984: my @locales = DateTime::Locale->ids();
985: foreach my $id (@locales) {
986: if ($id ne '') {
987: my ($en_terr,$native_terr);
988: my $loc = DateTime::Locale->load($id);
989: if (ref($loc)) {
990: $en_terr = $loc->name();
991: $native_terr = $loc->native_name();
1.687 raeburn 992: if (grep(/^en$/,@languages) || !@languages) {
993: if ($en_terr ne '') {
994: $locale_names{$id} = '('.$en_terr.')';
995: } elsif ($native_terr ne '') {
996: $locale_names{$id} = $native_terr;
997: }
998: } else {
999: if ($native_terr ne '') {
1000: $locale_names{$id} = $native_terr.' ';
1001: } elsif ($en_terr ne '') {
1002: $locale_names{$id} = '('.$en_terr.')';
1003: }
1004: }
1.1075.2.94 raeburn 1005: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1075.2.102 raeburn 1006: push(@possibles,$id);
1.687 raeburn 1007: }
1008: }
1009: }
1010: foreach my $item (sort(@possibles)) {
1011: $output.= '<option value="'.$item.'"';
1012: if ($item eq $selected) {
1013: $output.=' selected="selected"';
1014: }
1015: $output.=">$item";
1016: if ($locale_names{$item} ne '') {
1.1075.2.94 raeburn 1017: $output.=' '.$locale_names{$item};
1.687 raeburn 1018: }
1019: $output.="</option>\n";
1020: }
1021: $output.="</select>";
1022: return $output;
1023: }
1024:
1.792 raeburn 1025: sub select_language {
1.1075.2.115 raeburn 1026: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1027: my %langchoices;
1028: if ($includeempty) {
1.1075.2.32 raeburn 1029: %langchoices = ('' => 'No language preference');
1.792 raeburn 1030: }
1031: foreach my $id (&languageids()) {
1032: my $code = &supportedlanguagecode($id);
1033: if ($code) {
1034: $langchoices{$code} = &plainlanguagedescription($id);
1035: }
1036: }
1.1075.2.32 raeburn 1037: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1075.2.115 raeburn 1038: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1039: }
1040:
1.42 matthew 1041: =pod
1.36 matthew 1042:
1.648 raeburn 1043: =item * &linked_select_forms(...)
1.36 matthew 1044:
1045: linked_select_forms returns a string containing a <script></script> block
1046: and html for two <select> menus. The select menus will be linked in that
1047: changing the value of the first menu will result in new values being placed
1048: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1049: order unless a defined order is provided.
1.36 matthew 1050:
1051: linked_select_forms takes the following ordered inputs:
1052:
1053: =over 4
1054:
1.112 bowersj2 1055: =item * $formname, the name of the <form> tag
1.36 matthew 1056:
1.112 bowersj2 1057: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1058:
1.112 bowersj2 1059: =item * $firstdefault, the default value for the first menu
1.36 matthew 1060:
1.112 bowersj2 1061: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1062:
1.112 bowersj2 1063: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1064:
1.112 bowersj2 1065: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1066:
1.609 raeburn 1067: =item * $menuorder, the order of values in the first menu
1068:
1.1075.2.31 raeburn 1069: =item * $onchangefirst, additional javascript call to execute for an onchange
1070: event for the first <select> tag
1071:
1072: =item * $onchangesecond, additional javascript call to execute for an onchange
1073: event for the second <select> tag
1074:
1.41 ng 1075: =back
1076:
1.36 matthew 1077: Below is an example of such a hash. Only the 'text', 'default', and
1078: 'select2' keys must appear as stated. keys(%menu) are the possible
1079: values for the first select menu. The text that coincides with the
1.41 ng 1080: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1081: and text for the second menu are given in the hash pointed to by
1082: $menu{$choice1}->{'select2'}.
1083:
1.112 bowersj2 1084: my %menu = ( A1 => { text =>"Choice A1" ,
1085: default => "B3",
1086: select2 => {
1087: B1 => "Choice B1",
1088: B2 => "Choice B2",
1089: B3 => "Choice B3",
1090: B4 => "Choice B4"
1.609 raeburn 1091: },
1092: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1093: },
1094: A2 => { text =>"Choice A2" ,
1095: default => "C2",
1096: select2 => {
1097: C1 => "Choice C1",
1098: C2 => "Choice C2",
1099: C3 => "Choice C3"
1.609 raeburn 1100: },
1101: order => ['C2','C1','C3'],
1.112 bowersj2 1102: },
1103: A3 => { text =>"Choice A3" ,
1104: default => "D6",
1105: select2 => {
1106: D1 => "Choice D1",
1107: D2 => "Choice D2",
1108: D3 => "Choice D3",
1109: D4 => "Choice D4",
1110: D5 => "Choice D5",
1111: D6 => "Choice D6",
1112: D7 => "Choice D7"
1.609 raeburn 1113: },
1114: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1115: }
1116: );
1.36 matthew 1117:
1118: =cut
1119:
1120: sub linked_select_forms {
1121: my ($formname,
1122: $middletext,
1123: $firstdefault,
1124: $firstselectname,
1125: $secondselectname,
1.609 raeburn 1126: $hashref,
1127: $menuorder,
1.1075.2.31 raeburn 1128: $onchangefirst,
1129: $onchangesecond
1.36 matthew 1130: ) = @_;
1131: my $second = "document.$formname.$secondselectname";
1132: my $first = "document.$formname.$firstselectname";
1133: # output the javascript to do the changing
1134: my $result = '';
1.776 bisitz 1135: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1136: $result.="// <![CDATA[\n";
1.36 matthew 1137: $result.="var select2data = new Object();\n";
1138: $" = '","';
1139: my $debug = '';
1140: foreach my $s1 (sort(keys(%$hashref))) {
1141: $result.="select2data.d_$s1 = new Object();\n";
1142: $result.="select2data.d_$s1.def = new String('".
1143: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1144: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1145: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1146: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1147: @s2values = @{$hashref->{$s1}->{'order'}};
1148: }
1.36 matthew 1149: $result.="\"@s2values\");\n";
1150: $result.="select2data.d_$s1.texts = new Array(";
1151: my @s2texts;
1152: foreach my $value (@s2values) {
1.1075.2.119 raeburn 1153: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1154: }
1155: $result.="\"@s2texts\");\n";
1156: }
1157: $"=' ';
1158: $result.= <<"END";
1159:
1160: function select1_changed() {
1161: // Determine new choice
1162: var newvalue = "d_" + $first.value;
1163: // update select2
1164: var values = select2data[newvalue].values;
1165: var texts = select2data[newvalue].texts;
1166: var select2def = select2data[newvalue].def;
1167: var i;
1168: // out with the old
1169: for (i = 0; i < $second.options.length; i++) {
1170: $second.options[i] = null;
1171: }
1172: // in with the nuclear
1173: for (i=0;i<values.length; i++) {
1174: $second.options[i] = new Option(values[i]);
1.143 matthew 1175: $second.options[i].value = values[i];
1.36 matthew 1176: $second.options[i].text = texts[i];
1177: if (values[i] == select2def) {
1178: $second.options[i].selected = true;
1179: }
1180: }
1181: }
1.824 bisitz 1182: // ]]>
1.36 matthew 1183: </script>
1184: END
1185: # output the initial values for the selection lists
1.1075.2.31 raeburn 1186: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1187: my @order = sort(keys(%{$hashref}));
1188: if (ref($menuorder) eq 'ARRAY') {
1189: @order = @{$menuorder};
1190: }
1191: foreach my $value (@order) {
1.36 matthew 1192: $result.=" <option value=\"$value\" ";
1.253 albertel 1193: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1194: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1195: }
1196: $result .= "</select>\n";
1197: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1198: $result .= $middletext;
1.1075.2.31 raeburn 1199: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1200: if ($onchangesecond) {
1201: $result .= ' onchange="'.$onchangesecond.'"';
1202: }
1203: $result .= ">\n";
1.36 matthew 1204: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1205:
1206: my @secondorder = sort(keys(%select2));
1207: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1208: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1209: }
1210: foreach my $value (@secondorder) {
1.36 matthew 1211: $result.=" <option value=\"$value\" ";
1.253 albertel 1212: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1213: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1214: }
1215: $result .= "</select>\n";
1216: # return $debug;
1217: return $result;
1218: } # end of sub linked_select_forms {
1219:
1.45 matthew 1220: =pod
1.44 bowersj2 1221:
1.973 raeburn 1222: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1223:
1.112 bowersj2 1224: Returns a string corresponding to an HTML link to the given help
1225: $topic, where $topic corresponds to the name of a .tex file in
1226: /home/httpd/html/adm/help/tex, with underscores replaced by
1227: spaces.
1228:
1229: $text will optionally be linked to the same topic, allowing you to
1230: link text in addition to the graphic. If you do not want to link
1231: text, but wish to specify one of the later parameters, pass an
1232: empty string.
1233:
1234: $stayOnPage is a value that will be interpreted as a boolean. If true,
1235: the link will not open a new window. If false, the link will open
1236: a new window using Javascript. (Default is false.)
1237:
1238: $width and $height are optional numerical parameters that will
1239: override the width and height of the popped up window, which may
1.973 raeburn 1240: be useful for certain help topics with big pictures included.
1241:
1242: $imgid is the id of the img tag used for the help icon. This may be
1243: used in a javascript call to switch the image src. See
1244: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1245:
1246: =cut
1247:
1248: sub help_open_topic {
1.973 raeburn 1249: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1250: $text = "" if (not defined $text);
1.44 bowersj2 1251: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1252: $width = 500 if (not defined $width);
1.44 bowersj2 1253: $height = 400 if (not defined $height);
1254: my $filename = $topic;
1255: $filename =~ s/ /_/g;
1256:
1.48 bowersj2 1257: my $template = "";
1258: my $link;
1.572 banghart 1259:
1.159 www 1260: $topic=~s/\W/\_/g;
1.44 bowersj2 1261:
1.572 banghart 1262: if (!$stayOnPage) {
1.1075.2.50 raeburn 1263: if ($env{'browser.mobile'}) {
1264: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1265: } else {
1266: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1267: }
1.1037 www 1268: } elsif ($stayOnPage eq 'popup') {
1269: $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 1270: } else {
1.48 bowersj2 1271: $link = "/adm/help/${filename}.hlp";
1272: }
1273:
1274: # Add the text
1.755 neumanie 1275: if ($text ne "") {
1.763 bisitz 1276: $template.='<span class="LC_help_open_topic">'
1277: .'<a target="_top" href="'.$link.'">'
1278: .$text.'</a>';
1.48 bowersj2 1279: }
1280:
1.763 bisitz 1281: # (Always) Add the graphic
1.179 matthew 1282: my $title = &mt('Online Help');
1.667 raeburn 1283: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1284: if ($imgid ne '') {
1285: $imgid = ' id="'.$imgid.'"';
1286: }
1.763 bisitz 1287: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1288: .'<img src="'.$helpicon.'" border="0"'
1289: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1290: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1291: .' /></a>';
1292: if ($text ne "") {
1293: $template.='</span>';
1294: }
1.44 bowersj2 1295: return $template;
1296:
1.106 bowersj2 1297: }
1298:
1299: # This is a quicky function for Latex cheatsheet editing, since it
1300: # appears in at least four places
1301: sub helpLatexCheatsheet {
1.1037 www 1302: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1303: my $out;
1.106 bowersj2 1304: my $addOther = '';
1.732 raeburn 1305: if ($topic) {
1.1037 www 1306: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1307: }
1308: $out = '<span>' # Start cheatsheet
1309: .$addOther
1310: .'<span>'
1.1037 www 1311: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1312: .'</span> <span>'
1.1037 www 1313: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1314: .'</span>';
1.732 raeburn 1315: unless ($not_author) {
1.763 bisitz 1316: $out .= ' <span>'
1.1037 www 1317: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1318: .'</span> <span>'
1.1075.2.78 raeburn 1319: .&help_open_topic('Authoring_Multilingual_Problems',&mt('Languages'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1320: .'</span>';
1.732 raeburn 1321: }
1.763 bisitz 1322: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1323: return $out;
1.172 www 1324: }
1325:
1.430 albertel 1326: sub general_help {
1327: my $helptopic='Student_Intro';
1328: if ($env{'request.role'}=~/^(ca|au)/) {
1329: $helptopic='Authoring_Intro';
1.907 raeburn 1330: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1331: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1332: } elsif ($env{'request.role'}=~/^dc/) {
1333: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1334: }
1335: return $helptopic;
1336: }
1337:
1338: sub update_help_link {
1339: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1340: my $origurl = $ENV{'REQUEST_URI'};
1341: $origurl=~s|^/~|/priv/|;
1342: my $timestamp = time;
1343: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1344: $$datum = &escape($$datum);
1345: }
1346:
1347: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1348: my $output .= <<"ENDOUTPUT";
1349: <script type="text/javascript">
1.824 bisitz 1350: // <![CDATA[
1.430 albertel 1351: banner_link = '$banner_link';
1.824 bisitz 1352: // ]]>
1.430 albertel 1353: </script>
1354: ENDOUTPUT
1355: return $output;
1356: }
1357:
1358: # now just updates the help link and generates a blue icon
1.193 raeburn 1359: sub help_open_menu {
1.430 albertel 1360: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1361: = @_;
1.949 droeschl 1362: $stayOnPage = 1;
1.430 albertel 1363: my $output;
1364: if ($component_help) {
1365: if (!$text) {
1366: $output=&help_open_topic($component_help,undef,$stayOnPage,
1367: $width,$height);
1368: } else {
1369: my $help_text;
1370: $help_text=&unescape($topic);
1371: $output='<table><tr><td>'.
1372: &help_open_topic($component_help,$help_text,$stayOnPage,
1373: $width,$height).'</td></tr></table>';
1374: }
1375: }
1376: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1377: return $output.$banner_link;
1378: }
1379:
1380: sub top_nav_help {
1381: my ($text) = @_;
1.436 albertel 1382: $text = &mt($text);
1.1075.2.60 raeburn 1383: my $stay_on_page;
1384: unless ($env{'environment.remote'} eq 'on') {
1385: $stay_on_page = 1;
1386: }
1.1075.2.61 raeburn 1387: my ($link,$banner_link);
1388: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1389: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1390: : "javascript:helpMenu('open')";
1391: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1392: }
1.201 raeburn 1393: my $title = &mt('Get help');
1.1075.2.61 raeburn 1394: if ($link) {
1395: return <<"END";
1.436 albertel 1396: $banner_link
1.1075.2.56 raeburn 1397: <a href="$link" title="$title">$text</a>
1.436 albertel 1398: END
1.1075.2.61 raeburn 1399: } else {
1400: return ' '.$text.' ';
1401: }
1.436 albertel 1402: }
1403:
1404: sub help_menu_js {
1.1075.2.52 raeburn 1405: my ($httphost) = @_;
1.949 droeschl 1406: my $stayOnPage = 1;
1.436 albertel 1407: my $width = 620;
1408: my $height = 600;
1.430 albertel 1409: my $helptopic=&general_help();
1.1075.2.52 raeburn 1410: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1411: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1412: my $start_page =
1413: &Apache::loncommon::start_page('Help Menu', undef,
1414: {'frameset' => 1,
1415: 'js_ready' => 1,
1.1075.2.136 raeburn 1416: 'use_absolute' => $httphost,
1.331 albertel 1417: 'add_entries' => {
1418: 'border' => '0',
1.579 raeburn 1419: 'rows' => "110,*",},});
1.331 albertel 1420: my $end_page =
1421: &Apache::loncommon::end_page({'frameset' => 1,
1422: 'js_ready' => 1,});
1423:
1.436 albertel 1424: my $template .= <<"ENDTEMPLATE";
1425: <script type="text/javascript">
1.877 bisitz 1426: // <![CDATA[
1.253 albertel 1427: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1428: var banner_link = '';
1.243 raeburn 1429: function helpMenu(target) {
1430: var caller = this;
1431: if (target == 'open') {
1432: var newWindow = null;
1433: try {
1.262 albertel 1434: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1435: }
1436: catch(error) {
1437: writeHelp(caller);
1438: return;
1439: }
1440: if (newWindow) {
1441: caller = newWindow;
1442: }
1.193 raeburn 1443: }
1.243 raeburn 1444: writeHelp(caller);
1445: return;
1446: }
1447: function writeHelp(caller) {
1.1075.2.61 raeburn 1448: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1449: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1450: caller.document.close();
1451: caller.focus();
1.193 raeburn 1452: }
1.877 bisitz 1453: // END LON-CAPA Internal -->
1.253 albertel 1454: // ]]>
1.436 albertel 1455: </script>
1.193 raeburn 1456: ENDTEMPLATE
1457: return $template;
1458: }
1459:
1.172 www 1460: sub help_open_bug {
1461: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1462: unless ($env{'user.adv'}) { return ''; }
1.172 www 1463: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1464: $text = "" if (not defined $text);
1465: $stayOnPage=1;
1.184 albertel 1466: $width = 600 if (not defined $width);
1467: $height = 600 if (not defined $height);
1.172 www 1468:
1469: $topic=~s/\W+/\+/g;
1470: my $link='';
1471: my $template='';
1.379 albertel 1472: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1473: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1474: if (!$stayOnPage)
1475: {
1476: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1477: }
1478: else
1479: {
1480: $link = $url;
1481: }
1482: # Add the text
1483: if ($text ne "")
1484: {
1485: $template .=
1486: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1487: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1488: }
1489:
1490: # Add the graphic
1.179 matthew 1491: my $title = &mt('Report a Bug');
1.215 albertel 1492: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1493: $template .= <<"ENDTEMPLATE";
1.436 albertel 1494: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1495: ENDTEMPLATE
1496: if ($text ne '') { $template.='</td></tr></table>' };
1497: return $template;
1498:
1499: }
1500:
1501: sub help_open_faq {
1502: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1503: unless ($env{'user.adv'}) { return ''; }
1.172 www 1504: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1505: $text = "" if (not defined $text);
1506: $stayOnPage=1;
1507: $width = 350 if (not defined $width);
1508: $height = 400 if (not defined $height);
1509:
1510: $topic=~s/\W+/\+/g;
1511: my $link='';
1512: my $template='';
1513: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1514: if (!$stayOnPage)
1515: {
1516: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1517: }
1518: else
1519: {
1520: $link = $url;
1521: }
1522:
1523: # Add the text
1524: if ($text ne "")
1525: {
1526: $template .=
1.173 www 1527: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1528: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1529: }
1530:
1531: # Add the graphic
1.179 matthew 1532: my $title = &mt('View the FAQ');
1.215 albertel 1533: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1534: $template .= <<"ENDTEMPLATE";
1.436 albertel 1535: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1536: ENDTEMPLATE
1537: if ($text ne '') { $template.='</td></tr></table>' };
1538: return $template;
1539:
1.44 bowersj2 1540: }
1.37 matthew 1541:
1.180 matthew 1542: ###############################################################
1543: ###############################################################
1544:
1.45 matthew 1545: =pod
1546:
1.648 raeburn 1547: =item * &change_content_javascript():
1.256 matthew 1548:
1549: This and the next function allow you to create small sections of an
1550: otherwise static HTML page that you can update on the fly with
1551: Javascript, even in Netscape 4.
1552:
1553: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1554: must be written to the HTML page once. It will prove the Javascript
1555: function "change(name, content)". Calling the change function with the
1556: name of the section
1557: you want to update, matching the name passed to C<changable_area>, and
1558: the new content you want to put in there, will put the content into
1559: that area.
1560:
1561: B<Note>: Netscape 4 only reserves enough space for the changable area
1562: to contain room for the original contents. You need to "make space"
1563: for whatever changes you wish to make, and be B<sure> to check your
1564: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1565: it's adequate for updating a one-line status display, but little more.
1566: This script will set the space to 100% width, so you only need to
1567: worry about height in Netscape 4.
1568:
1569: Modern browsers are much less limiting, and if you can commit to the
1570: user not using Netscape 4, this feature may be used freely with
1571: pretty much any HTML.
1572:
1573: =cut
1574:
1575: sub change_content_javascript {
1576: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1577: if ($env{'browser.type'} eq 'netscape' &&
1578: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1579: return (<<NETSCAPE4);
1580: function change(name, content) {
1581: doc = document.layers[name+"___escape"].layers[0].document;
1582: doc.open();
1583: doc.write(content);
1584: doc.close();
1585: }
1586: NETSCAPE4
1587: } else {
1588: # Otherwise, we need to use semi-standards-compliant code
1589: # (technically, "innerHTML" isn't standard but the equivalent
1590: # is really scary, and every useful browser supports it
1591: return (<<DOMBASED);
1592: function change(name, content) {
1593: element = document.getElementById(name);
1594: element.innerHTML = content;
1595: }
1596: DOMBASED
1597: }
1598: }
1599:
1600: =pod
1601:
1.648 raeburn 1602: =item * &changable_area($name,$origContent):
1.256 matthew 1603:
1604: This provides a "changable area" that can be modified on the fly via
1605: the Javascript code provided in C<change_content_javascript>. $name is
1606: the name you will use to reference the area later; do not repeat the
1607: same name on a given HTML page more then once. $origContent is what
1608: the area will originally contain, which can be left blank.
1609:
1610: =cut
1611:
1612: sub changable_area {
1613: my ($name, $origContent) = @_;
1614:
1.258 albertel 1615: if ($env{'browser.type'} eq 'netscape' &&
1616: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1617: # If this is netscape 4, we need to use the Layer tag
1618: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1619: } else {
1620: return "<span id='$name'>$origContent</span>";
1621: }
1622: }
1623:
1624: =pod
1625:
1.648 raeburn 1626: =item * &viewport_geometry_js
1.590 raeburn 1627:
1628: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1629:
1630: =cut
1631:
1632:
1633: sub viewport_geometry_js {
1634: return <<"GEOMETRY";
1635: var Geometry = {};
1636: function init_geometry() {
1637: if (Geometry.init) { return };
1638: Geometry.init=1;
1639: if (window.innerHeight) {
1640: Geometry.getViewportHeight = function() { return window.innerHeight; };
1641: Geometry.getViewportWidth = function() { return window.innerWidth; };
1642: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1643: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1644: }
1645: else if (document.documentElement && document.documentElement.clientHeight) {
1646: Geometry.getViewportHeight =
1647: function() { return document.documentElement.clientHeight; };
1648: Geometry.getViewportWidth =
1649: function() { return document.documentElement.clientWidth; };
1650:
1651: Geometry.getHorizontalScroll =
1652: function() { return document.documentElement.scrollLeft; };
1653: Geometry.getVerticalScroll =
1654: function() { return document.documentElement.scrollTop; };
1655: }
1656: else if (document.body.clientHeight) {
1657: Geometry.getViewportHeight =
1658: function() { return document.body.clientHeight; };
1659: Geometry.getViewportWidth =
1660: function() { return document.body.clientWidth; };
1661: Geometry.getHorizontalScroll =
1662: function() { return document.body.scrollLeft; };
1663: Geometry.getVerticalScroll =
1664: function() { return document.body.scrollTop; };
1665: }
1666: }
1667:
1668: GEOMETRY
1669: }
1670:
1671: =pod
1672:
1.648 raeburn 1673: =item * &viewport_size_js()
1.590 raeburn 1674:
1675: 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.
1676:
1677: =cut
1678:
1679: sub viewport_size_js {
1680: my $geometry = &viewport_geometry_js();
1681: return <<"DIMS";
1682:
1683: $geometry
1684:
1685: function getViewportDims(width,height) {
1686: init_geometry();
1687: width.value = Geometry.getViewportWidth();
1688: height.value = Geometry.getViewportHeight();
1689: return;
1690: }
1691:
1692: DIMS
1693: }
1694:
1695: =pod
1696:
1.648 raeburn 1697: =item * &resize_textarea_js()
1.565 albertel 1698:
1699: emits the needed javascript to resize a textarea to be as big as possible
1700:
1701: creates a function resize_textrea that takes two IDs first should be
1702: the id of the element to resize, second should be the id of a div that
1703: surrounds everything that comes after the textarea, this routine needs
1704: to be attached to the <body> for the onload and onresize events.
1705:
1.648 raeburn 1706: =back
1.565 albertel 1707:
1708: =cut
1709:
1710: sub resize_textarea_js {
1.590 raeburn 1711: my $geometry = &viewport_geometry_js();
1.565 albertel 1712: return <<"RESIZE";
1713: <script type="text/javascript">
1.824 bisitz 1714: // <![CDATA[
1.590 raeburn 1715: $geometry
1.565 albertel 1716:
1.588 albertel 1717: function getX(element) {
1718: var x = 0;
1719: while (element) {
1720: x += element.offsetLeft;
1721: element = element.offsetParent;
1722: }
1723: return x;
1724: }
1725: function getY(element) {
1726: var y = 0;
1727: while (element) {
1728: y += element.offsetTop;
1729: element = element.offsetParent;
1730: }
1731: return y;
1732: }
1733:
1734:
1.565 albertel 1735: function resize_textarea(textarea_id,bottom_id) {
1736: init_geometry();
1737: var textarea = document.getElementById(textarea_id);
1738: //alert(textarea);
1739:
1.588 albertel 1740: var textarea_top = getY(textarea);
1.565 albertel 1741: var textarea_height = textarea.offsetHeight;
1742: var bottom = document.getElementById(bottom_id);
1.588 albertel 1743: var bottom_top = getY(bottom);
1.565 albertel 1744: var bottom_height = bottom.offsetHeight;
1745: var window_height = Geometry.getViewportHeight();
1.588 albertel 1746: var fudge = 23;
1.565 albertel 1747: var new_height = window_height-fudge-textarea_top-bottom_height;
1748: if (new_height < 300) {
1749: new_height = 300;
1750: }
1751: textarea.style.height=new_height+'px';
1752: }
1.824 bisitz 1753: // ]]>
1.565 albertel 1754: </script>
1755: RESIZE
1756:
1757: }
1758:
1.1075.2.112 raeburn 1759: sub colorfuleditor_js {
1760: return <<"COLORFULEDIT"
1761: <script type="text/javascript">
1762: // <![CDATA[>
1763: function fold_box(curDepth, lastresource){
1764:
1765: // we need a list because there can be several blocks you need to fold in one tag
1766: var block = document.getElementsByName('foldblock_'+curDepth);
1767: // but there is only one folding button per tag
1768: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1769:
1770: if(block.item(0).style.display == 'none'){
1771:
1772: foldbutton.value = '@{[&mt("Hide")]}';
1773: for (i = 0; i < block.length; i++){
1774: block.item(i).style.display = '';
1775: }
1776: }else{
1777:
1778: foldbutton.value = '@{[&mt("Show")]}';
1779: for (i = 0; i < block.length; i++){
1780: // block.item(i).style.visibility = 'collapse';
1781: block.item(i).style.display = 'none';
1782: }
1783: };
1784: saveState(lastresource);
1785: }
1786:
1787: function saveState (lastresource) {
1788:
1789: var tag_list = getTagList();
1790: if(tag_list != null){
1791: var timestamp = new Date().getTime();
1792: var key = lastresource;
1793:
1794: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1795: // starting with timestamp
1796: var value = timestamp+';';
1797:
1798: // building the list of key-value pairs
1799: for(var i = 0; i < tag_list.length; i++){
1800: value += tag_list[i]+',';
1801: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1802: }
1803:
1804: // only iterate whole storage if nothing to override
1805: if(localStorage.getItem(key) == null){
1806:
1807: // prevent storage from growing large
1808: if(localStorage.length > 50){
1809: var regex_getTimestamp = /^(?:\d)+;/;
1810: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1811: var oldest_key;
1812:
1813: for(var i = 1; i < localStorage.length; i++){
1814: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1815: oldest_key = localStorage.key(i);
1816: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1817: }
1818: }
1819: localStorage.removeItem(oldest_key);
1820: }
1821: }
1822: localStorage.setItem(key,value);
1823: }
1824: }
1825:
1826: // restore folding status of blocks (on page load)
1827: function restoreState (lastresource) {
1828: if(localStorage.getItem(lastresource) != null){
1829: var key = lastresource;
1830: var value = localStorage.getItem(key);
1831: var regex_delTimestamp = /^\d+;/;
1832:
1833: value.replace(regex_delTimestamp, '');
1834:
1835: var valueArr = value.split(';');
1836: var pairs;
1837: var elements;
1838: for (var i = 0; i < valueArr.length; i++){
1839: pairs = valueArr[i].split(',');
1840: elements = document.getElementsByName(pairs[0]);
1841:
1842: for (var j = 0; j < elements.length; j++){
1843: elements[j].style.display = pairs[1];
1844: if (pairs[1] == "none"){
1845: var regex_id = /([_\\d]+)\$/;
1846: regex_id.exec(pairs[0]);
1847: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
1848: }
1849: }
1850: }
1851: }
1852: }
1853:
1854: function getTagList () {
1855:
1856: var stringToSearch = document.lonhomework.innerHTML;
1857:
1858: var ret = new Array();
1859: var regex_findBlock = /(foldblock_.*?)"/g;
1860: var tag_list = stringToSearch.match(regex_findBlock);
1861:
1862: if(tag_list != null){
1863: for(var i = 0; i < tag_list.length; i++){
1864: ret.push(tag_list[i].replace(/"/, ''));
1865: }
1866: }
1867: return ret;
1868: }
1869:
1870: function saveScrollPosition (resource) {
1871: var tag_list = getTagList();
1872:
1873: // we dont always want to jump to the first block
1874: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
1875: if(\$(window).scrollTop() > 170){
1876: if(tag_list != null){
1877: var result;
1878: for(var i = 0; i < tag_list.length; i++){
1879: if(isElementInViewport(tag_list[i])){
1880: result += tag_list[i]+';';
1881: }
1882: }
1883: sessionStorage.setItem('anchor_'+resource, result);
1884: }
1885: } else {
1886: // we dont need to save zero, just delete the item to leave everything tidy
1887: sessionStorage.removeItem('anchor_'+resource);
1888: }
1889: }
1890:
1891: function restoreScrollPosition(resource){
1892:
1893: var elem = sessionStorage.getItem('anchor_'+resource);
1894: if(elem != null){
1895: var tag_list = elem.split(';');
1896: var elem_list;
1897:
1898: for(var i = 0; i < tag_list.length; i++){
1899: elem_list = document.getElementsByName(tag_list[i]);
1900:
1901: if(elem_list.length > 0){
1902: elem = elem_list[0];
1903: break;
1904: }
1905: }
1906: elem.scrollIntoView();
1907: }
1908: }
1909:
1910: function isElementInViewport(el) {
1911:
1912: // change to last element instead of first
1913: var elem = document.getElementsByName(el);
1914: var rect = elem[0].getBoundingClientRect();
1915:
1916: return (
1917: rect.top >= 0 &&
1918: rect.left >= 0 &&
1919: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1920: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1921: );
1922: }
1923:
1924: function autosize(depth){
1925: var cmInst = window['cm'+depth];
1926: var fitsizeButton = document.getElementById('fitsize'+depth);
1927:
1928: // is fixed size, switching to dynamic
1929: if (sessionStorage.getItem("autosized_"+depth) == null) {
1930: cmInst.setSize("","auto");
1931: fitsizeButton.value = "@{[&mt('Fixed size')]}";
1932: sessionStorage.setItem("autosized_"+depth, "yes");
1933:
1934: // is dynamic size, switching to fixed
1935: } else {
1936: cmInst.setSize("","300px");
1937: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
1938: sessionStorage.removeItem("autosized_"+depth);
1939: }
1940: }
1941:
1942:
1943:
1944: // ]]>
1945: </script>
1946: COLORFULEDIT
1947: }
1948:
1949: sub xmleditor_js {
1950: return <<XMLEDIT
1951: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
1952: <script type="text/javascript">
1953: // <![CDATA[>
1954:
1955: function saveScrollPosition (resource) {
1956:
1957: var scrollPos = \$(window).scrollTop();
1958: sessionStorage.setItem(resource,scrollPos);
1959: }
1960:
1961: function restoreScrollPosition(resource){
1962:
1963: var scrollPos = sessionStorage.getItem(resource);
1964: \$(window).scrollTop(scrollPos);
1965: }
1966:
1967: // unless internet explorer
1968: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
1969:
1970: \$(document).ready(function() {
1971: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
1972: });
1973: }
1974:
1975: // inserts text at cursor position into codemirror (xml editor only)
1976: function insertText(text){
1977: cm.focus();
1978: var curPos = cm.getCursor();
1979: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
1980: }
1981: // ]]>
1982: </script>
1983: XMLEDIT
1984: }
1985:
1986: sub insert_folding_button {
1987: my $curDepth = $Apache::lonxml::curdepth;
1988: my $lastresource = $env{'request.ambiguous'};
1989:
1990: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
1991: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
1992: }
1993:
1994:
1.565 albertel 1995: =pod
1996:
1.256 matthew 1997: =head1 Excel and CSV file utility routines
1998:
1999: =cut
2000:
2001: ###############################################################
2002: ###############################################################
2003:
2004: =pod
2005:
1.1075.2.56 raeburn 2006: =over 4
2007:
1.648 raeburn 2008: =item * &csv_translate($text)
1.37 matthew 2009:
1.185 www 2010: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2011: format.
2012:
2013: =cut
2014:
1.180 matthew 2015: ###############################################################
2016: ###############################################################
1.37 matthew 2017: sub csv_translate {
2018: my $text = shift;
2019: $text =~ s/\"/\"\"/g;
1.209 albertel 2020: $text =~ s/\n/ /g;
1.37 matthew 2021: return $text;
2022: }
1.180 matthew 2023:
2024: ###############################################################
2025: ###############################################################
2026:
2027: =pod
2028:
1.648 raeburn 2029: =item * &define_excel_formats()
1.180 matthew 2030:
2031: Define some commonly used Excel cell formats.
2032:
2033: Currently supported formats:
2034:
2035: =over 4
2036:
2037: =item header
2038:
2039: =item bold
2040:
2041: =item h1
2042:
2043: =item h2
2044:
2045: =item h3
2046:
1.256 matthew 2047: =item h4
2048:
2049: =item i
2050:
1.180 matthew 2051: =item date
2052:
2053: =back
2054:
2055: Inputs: $workbook
2056:
2057: Returns: $format, a hash reference.
2058:
1.1057 foxr 2059:
1.180 matthew 2060: =cut
2061:
2062: ###############################################################
2063: ###############################################################
2064: sub define_excel_formats {
2065: my ($workbook) = @_;
2066: my $format;
2067: $format->{'header'} = $workbook->add_format(bold => 1,
2068: bottom => 1,
2069: align => 'center');
2070: $format->{'bold'} = $workbook->add_format(bold=>1);
2071: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2072: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2073: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2074: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2075: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2076: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2077: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2078: return $format;
2079: }
2080:
2081: ###############################################################
2082: ###############################################################
1.113 bowersj2 2083:
2084: =pod
2085:
1.648 raeburn 2086: =item * &create_workbook()
1.255 matthew 2087:
2088: Create an Excel worksheet. If it fails, output message on the
2089: request object and return undefs.
2090:
2091: Inputs: Apache request object
2092:
2093: Returns (undef) on failure,
2094: Excel worksheet object, scalar with filename, and formats
2095: from &Apache::loncommon::define_excel_formats on success
2096:
2097: =cut
2098:
2099: ###############################################################
2100: ###############################################################
2101: sub create_workbook {
2102: my ($r) = @_;
2103: #
2104: # Create the excel spreadsheet
2105: my $filename = '/prtspool/'.
1.258 albertel 2106: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2107: time.'_'.rand(1000000000).'.xls';
2108: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2109: if (! defined($workbook)) {
2110: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2111: $r->print(
2112: '<p class="LC_error">'
2113: .&mt('Problems occurred in creating the new Excel file.')
2114: .' '.&mt('This error has been logged.')
2115: .' '.&mt('Please alert your LON-CAPA administrator.')
2116: .'</p>'
2117: );
1.255 matthew 2118: return (undef);
2119: }
2120: #
1.1014 foxr 2121: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2122: #
2123: my $format = &Apache::loncommon::define_excel_formats($workbook);
2124: return ($workbook,$filename,$format);
2125: }
2126:
2127: ###############################################################
2128: ###############################################################
2129:
2130: =pod
2131:
1.648 raeburn 2132: =item * &create_text_file()
1.113 bowersj2 2133:
1.542 raeburn 2134: Create a file to write to and eventually make available to the user.
1.256 matthew 2135: If file creation fails, outputs an error message on the request object and
2136: return undefs.
1.113 bowersj2 2137:
1.256 matthew 2138: Inputs: Apache request object, and file suffix
1.113 bowersj2 2139:
1.256 matthew 2140: Returns (undef) on failure,
2141: Filehandle and filename on success.
1.113 bowersj2 2142:
2143: =cut
2144:
1.256 matthew 2145: ###############################################################
2146: ###############################################################
2147: sub create_text_file {
2148: my ($r,$suffix) = @_;
2149: if (! defined($suffix)) { $suffix = 'txt'; };
2150: my $fh;
2151: my $filename = '/prtspool/'.
1.258 albertel 2152: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2153: time.'_'.rand(1000000000).'.'.$suffix;
2154: $fh = Apache::File->new('>/home/httpd'.$filename);
2155: if (! defined($fh)) {
2156: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2157: $r->print(
2158: '<p class="LC_error">'
2159: .&mt('Problems occurred in creating the output file.')
2160: .' '.&mt('This error has been logged.')
2161: .' '.&mt('Please alert your LON-CAPA administrator.')
2162: .'</p>'
2163: );
1.113 bowersj2 2164: }
1.256 matthew 2165: return ($fh,$filename)
1.113 bowersj2 2166: }
2167:
2168:
1.256 matthew 2169: =pod
1.113 bowersj2 2170:
2171: =back
2172:
2173: =cut
1.37 matthew 2174:
2175: ###############################################################
1.33 matthew 2176: ## Home server <option> list generating code ##
2177: ###############################################################
1.35 matthew 2178:
1.169 www 2179: # ------------------------------------------
2180:
2181: sub domain_select {
2182: my ($name,$value,$multiple)=@_;
2183: my %domains=map {
1.514 albertel 2184: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2185: } &Apache::lonnet::all_domains();
1.169 www 2186: if ($multiple) {
2187: $domains{''}=&mt('Any domain');
1.550 albertel 2188: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2189: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2190: } else {
1.550 albertel 2191: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2192: return &select_form($name,$value,\%domains);
1.169 www 2193: }
2194: }
2195:
1.282 albertel 2196: #-------------------------------------------
2197:
2198: =pod
2199:
1.519 raeburn 2200: =head1 Routines for form select boxes
2201:
2202: =over 4
2203:
1.648 raeburn 2204: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2205:
2206: Returns a string containing a <select> element int multiple mode
2207:
2208:
2209: Args:
2210: $name - name of the <select> element
1.506 raeburn 2211: $value - scalar or array ref of values that should already be selected
1.282 albertel 2212: $size - number of rows long the select element is
1.283 albertel 2213: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2214: (shown text should already have been &mt())
1.506 raeburn 2215: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2216:
1.282 albertel 2217: =cut
2218:
2219: #-------------------------------------------
1.169 www 2220: sub multiple_select_form {
1.284 albertel 2221: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2222: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2223: my $output='';
1.191 matthew 2224: if (! defined($size)) {
2225: $size = 4;
1.283 albertel 2226: if (scalar(keys(%$hash))<4) {
2227: $size = scalar(keys(%$hash));
1.191 matthew 2228: }
2229: }
1.734 bisitz 2230: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2231: my @order;
1.506 raeburn 2232: if (ref($order) eq 'ARRAY') {
2233: @order = @{$order};
2234: } else {
2235: @order = sort(keys(%$hash));
1.501 banghart 2236: }
2237: if (exists($$hash{'select_form_order'})) {
2238: @order = @{$$hash{'select_form_order'}};
2239: }
2240:
1.284 albertel 2241: foreach my $key (@order) {
1.356 albertel 2242: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2243: $output.='selected="selected" ' if ($selected{$key});
2244: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2245: }
2246: $output.="</select>\n";
2247: return $output;
2248: }
2249:
1.88 www 2250: #-------------------------------------------
2251:
2252: =pod
2253:
1.1075.2.115 raeburn 2254: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2255:
2256: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2257: allow a user to select options from a ref to a hash containing:
2258: option_name => displayed text. An optional $onchange can include
1.1075.2.115 raeburn 2259: a javascript onchange item, e.g., onchange="this.form.submit();".
2260: An optional arg -- $readonly -- if true will cause the select form
2261: to be disabled, e.g., for the case where an instructor has a section-
2262: specific role, and is viewing/modifying parameters.
1.970 raeburn 2263:
1.88 www 2264: See lonrights.pm for an example invocation and use.
2265:
2266: =cut
2267:
2268: #-------------------------------------------
2269: sub select_form {
1.1075.2.115 raeburn 2270: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2271: return unless (ref($hashref) eq 'HASH');
2272: if ($onchange) {
2273: $onchange = ' onchange="'.$onchange.'"';
2274: }
1.1075.2.129 raeburn 2275: my $disabled;
2276: if ($readonly) {
2277: $disabled = ' disabled="disabled"';
2278: }
2279: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2280: my @keys;
1.970 raeburn 2281: if (exists($hashref->{'select_form_order'})) {
2282: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2283: } else {
1.970 raeburn 2284: @keys=sort(keys(%{$hashref}));
1.128 albertel 2285: }
1.356 albertel 2286: foreach my $key (@keys) {
2287: $selectform.=
2288: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2289: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2290: ">".$hashref->{$key}."</option>\n";
1.88 www 2291: }
2292: $selectform.="</select>";
2293: return $selectform;
2294: }
2295:
1.475 www 2296: # For display filters
2297:
2298: sub display_filter {
1.1074 raeburn 2299: my ($context) = @_;
1.475 www 2300: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2301: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2302: my $phraseinput = 'hidden';
2303: my $includeinput = 'hidden';
2304: my ($checked,$includetypestext);
2305: if ($env{'form.displayfilter'} eq 'containing') {
2306: $phraseinput = 'text';
2307: if ($context eq 'parmslog') {
2308: $includeinput = 'checkbox';
2309: if ($env{'form.includetypes'}) {
2310: $checked = ' checked="checked"';
2311: }
2312: $includetypestext = &mt('Include parameter types');
2313: }
2314: } else {
2315: $includetypestext = ' ';
2316: }
2317: my ($additional,$secondid,$thirdid);
2318: if ($context eq 'parmslog') {
2319: $additional =
2320: '<label><input type="'.$includeinput.'" name="includetypes"'.
2321: $checked.' name="includetypes" value="1" id="includetypes" />'.
2322: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2323: '</label>';
2324: $secondid = 'includetypes';
2325: $thirdid = 'includetypestext';
2326: }
2327: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2328: '$secondid','$thirdid')";
2329: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2330: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2331: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2332: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2333: &mt('Filter: [_1]',
1.477 www 2334: &select_form($env{'form.displayfilter'},
2335: 'displayfilter',
1.970 raeburn 2336: {'currentfolder' => 'Current folder/page',
1.477 www 2337: 'containing' => 'Containing phrase',
1.1074 raeburn 2338: 'none' => 'None'},$onchange)).' '.
2339: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2340: &HTML::Entities::encode($env{'form.containingphrase'}).
2341: '" />'.$additional;
2342: }
2343:
2344: sub display_filter_js {
2345: my $includetext = &mt('Include parameter types');
2346: return <<"ENDJS";
2347:
2348: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2349: var firstType = 'hidden';
2350: if (setter.options[setter.selectedIndex].value == 'containing') {
2351: firstType = 'text';
2352: }
2353: firstObject = document.getElementById(firstid);
2354: if (typeof(firstObject) == 'object') {
2355: if (firstObject.type != firstType) {
2356: changeInputType(firstObject,firstType);
2357: }
2358: }
2359: if (context == 'parmslog') {
2360: var secondType = 'hidden';
2361: if (firstType == 'text') {
2362: secondType = 'checkbox';
2363: }
2364: secondObject = document.getElementById(secondid);
2365: if (typeof(secondObject) == 'object') {
2366: if (secondObject.type != secondType) {
2367: changeInputType(secondObject,secondType);
2368: }
2369: }
2370: var textItem = document.getElementById(thirdid);
2371: var currtext = textItem.innerHTML;
2372: var newtext;
2373: if (firstType == 'text') {
2374: newtext = '$includetext';
2375: } else {
2376: newtext = ' ';
2377: }
2378: if (currtext != newtext) {
2379: textItem.innerHTML = newtext;
2380: }
2381: }
2382: return;
2383: }
2384:
2385: function changeInputType(oldObject,newType) {
2386: var newObject = document.createElement('input');
2387: newObject.type = newType;
2388: if (oldObject.size) {
2389: newObject.size = oldObject.size;
2390: }
2391: if (oldObject.value) {
2392: newObject.value = oldObject.value;
2393: }
2394: if (oldObject.name) {
2395: newObject.name = oldObject.name;
2396: }
2397: if (oldObject.id) {
2398: newObject.id = oldObject.id;
2399: }
2400: oldObject.parentNode.replaceChild(newObject,oldObject);
2401: return;
2402: }
2403:
2404: ENDJS
1.475 www 2405: }
2406:
1.167 www 2407: sub gradeleveldescription {
2408: my $gradelevel=shift;
2409: my %gradelevels=(0 => 'Not specified',
2410: 1 => 'Grade 1',
2411: 2 => 'Grade 2',
2412: 3 => 'Grade 3',
2413: 4 => 'Grade 4',
2414: 5 => 'Grade 5',
2415: 6 => 'Grade 6',
2416: 7 => 'Grade 7',
2417: 8 => 'Grade 8',
2418: 9 => 'Grade 9',
2419: 10 => 'Grade 10',
2420: 11 => 'Grade 11',
2421: 12 => 'Grade 12',
2422: 13 => 'Grade 13',
2423: 14 => '100 Level',
2424: 15 => '200 Level',
2425: 16 => '300 Level',
2426: 17 => '400 Level',
2427: 18 => 'Graduate Level');
2428: return &mt($gradelevels{$gradelevel});
2429: }
2430:
1.163 www 2431: sub select_level_form {
2432: my ($deflevel,$name)=@_;
2433: unless ($deflevel) { $deflevel=0; }
1.167 www 2434: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2435: for (my $i=0; $i<=18; $i++) {
2436: $selectform.="<option value=\"$i\" ".
1.253 albertel 2437: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2438: ">".&gradeleveldescription($i)."</option>\n";
2439: }
2440: $selectform.="</select>";
2441: return $selectform;
1.163 www 2442: }
1.167 www 2443:
1.35 matthew 2444: #-------------------------------------------
2445:
1.45 matthew 2446: =pod
2447:
1.1075.2.115 raeburn 2448: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2449:
2450: Returns a string containing a <select name='$name' size='1'> form to
2451: allow a user to select the domain to preform an operation in.
2452: See loncreateuser.pm for an example invocation and use.
2453:
1.90 www 2454: If the $includeempty flag is set, it also includes an empty choice ("no domain
2455: selected");
2456:
1.743 raeburn 2457: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2458:
1.910 raeburn 2459: 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.
2460:
1.1075.2.36 raeburn 2461: The optional $incdoms is a reference to an array of domains which will be the only available options.
2462:
1.1075.2.115 raeburn 2463: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
2464:
2465: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
1.563 raeburn 2466:
1.35 matthew 2467: =cut
2468:
2469: #-------------------------------------------
1.34 matthew 2470: sub select_dom_form {
1.1075.2.115 raeburn 2471: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2472: if ($onchange) {
1.874 raeburn 2473: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2474: }
1.1075.2.115 raeburn 2475: if ($disabled) {
2476: $disabled = ' disabled="disabled"';
2477: }
1.1075.2.36 raeburn 2478: my (@domains,%exclude);
1.910 raeburn 2479: if (ref($incdoms) eq 'ARRAY') {
2480: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2481: } else {
2482: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2483: }
1.90 www 2484: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2485: if (ref($excdoms) eq 'ARRAY') {
2486: map { $exclude{$_} = 1; } @{$excdoms};
2487: }
1.1075.2.115 raeburn 2488: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2489: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2490: next if ($exclude{$dom});
1.356 albertel 2491: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2492: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2493: if ($showdomdesc) {
2494: if ($dom ne '') {
2495: my $domdesc = &Apache::lonnet::domain($dom,'description');
2496: if ($domdesc ne '') {
2497: $selectdomain .= ' ('.$domdesc.')';
2498: }
2499: }
2500: }
2501: $selectdomain .= "</option>\n";
1.34 matthew 2502: }
2503: $selectdomain.="</select>";
2504: return $selectdomain;
2505: }
2506:
1.35 matthew 2507: #-------------------------------------------
2508:
1.45 matthew 2509: =pod
2510:
1.648 raeburn 2511: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2512:
1.586 raeburn 2513: input: 4 arguments (two required, two optional) -
2514: $domain - domain of new user
2515: $name - name of form element
2516: $default - Value of 'default' causes a default item to be first
2517: option, and selected by default.
2518: $hide - Value of 'hide' causes hiding of the name of the server,
2519: if 1 server found, or default, if 0 found.
1.594 raeburn 2520: output: returns 2 items:
1.586 raeburn 2521: (a) form element which contains either:
2522: (i) <select name="$name">
2523: <option value="$hostid1">$hostid $servers{$hostid}</option>
2524: <option value="$hostid2">$hostid $servers{$hostid}</option>
2525: </select>
2526: form item if there are multiple library servers in $domain, or
2527: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2528: if there is only one library server in $domain.
2529:
2530: (b) number of library servers found.
2531:
2532: See loncreateuser.pm for example of use.
1.35 matthew 2533:
2534: =cut
2535:
2536: #-------------------------------------------
1.586 raeburn 2537: sub home_server_form_item {
2538: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2539: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2540: my $result;
2541: my $numlib = keys(%servers);
2542: if ($numlib > 1) {
2543: $result .= '<select name="'.$name.'" />'."\n";
2544: if ($default) {
1.804 bisitz 2545: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2546: '</option>'."\n";
2547: }
2548: foreach my $hostid (sort(keys(%servers))) {
2549: $result.= '<option value="'.$hostid.'">'.
2550: $hostid.' '.$servers{$hostid}."</option>\n";
2551: }
2552: $result .= '</select>'."\n";
2553: } elsif ($numlib == 1) {
2554: my $hostid;
2555: foreach my $item (keys(%servers)) {
2556: $hostid = $item;
2557: }
2558: $result .= '<input type="hidden" name="'.$name.'" value="'.
2559: $hostid.'" />';
2560: if (!$hide) {
2561: $result .= $hostid.' '.$servers{$hostid};
2562: }
2563: $result .= "\n";
2564: } elsif ($default) {
2565: $result .= '<input type="hidden" name="'.$name.
2566: '" value="default" />';
2567: if (!$hide) {
2568: $result .= &mt('default');
2569: }
2570: $result .= "\n";
1.33 matthew 2571: }
1.586 raeburn 2572: return ($result,$numlib);
1.33 matthew 2573: }
1.112 bowersj2 2574:
2575: =pod
2576:
1.534 albertel 2577: =back
2578:
1.112 bowersj2 2579: =cut
1.87 matthew 2580:
2581: ###############################################################
1.112 bowersj2 2582: ## Decoding User Agent ##
1.87 matthew 2583: ###############################################################
2584:
2585: =pod
2586:
1.112 bowersj2 2587: =head1 Decoding the User Agent
2588:
2589: =over 4
2590:
2591: =item * &decode_user_agent()
1.87 matthew 2592:
2593: Inputs: $r
2594:
2595: Outputs:
2596:
2597: =over 4
2598:
1.112 bowersj2 2599: =item * $httpbrowser
1.87 matthew 2600:
1.112 bowersj2 2601: =item * $clientbrowser
1.87 matthew 2602:
1.112 bowersj2 2603: =item * $clientversion
1.87 matthew 2604:
1.112 bowersj2 2605: =item * $clientmathml
1.87 matthew 2606:
1.112 bowersj2 2607: =item * $clientunicode
1.87 matthew 2608:
1.112 bowersj2 2609: =item * $clientos
1.87 matthew 2610:
1.1075.2.42 raeburn 2611: =item * $clientmobile
2612:
2613: =item * $clientinfo
2614:
1.1075.2.77 raeburn 2615: =item * $clientosversion
2616:
1.87 matthew 2617: =back
2618:
1.157 matthew 2619: =back
2620:
1.87 matthew 2621: =cut
2622:
2623: ###############################################################
2624: ###############################################################
2625: sub decode_user_agent {
1.247 albertel 2626: my ($r)=@_;
1.87 matthew 2627: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2628: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2629: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2630: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2631: my $clientbrowser='unknown';
2632: my $clientversion='0';
2633: my $clientmathml='';
2634: my $clientunicode='0';
1.1075.2.42 raeburn 2635: my $clientmobile=0;
1.1075.2.77 raeburn 2636: my $clientosversion='';
1.87 matthew 2637: for (my $i=0;$i<=$#browsertype;$i++) {
1.1075.2.76 raeburn 2638: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2639: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2640: $clientbrowser=$bname;
2641: $httpbrowser=~/$vreg/i;
2642: $clientversion=$1;
2643: $clientmathml=($clientversion>=$minv);
2644: $clientunicode=($clientversion>=$univ);
2645: }
2646: }
2647: my $clientos='unknown';
1.1075.2.42 raeburn 2648: my $clientinfo;
1.87 matthew 2649: if (($httpbrowser=~/linux/i) ||
2650: ($httpbrowser=~/unix/i) ||
2651: ($httpbrowser=~/ux/i) ||
2652: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2653: if (($httpbrowser=~/vax/i) ||
2654: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2655: if ($httpbrowser=~/next/i) { $clientos='next'; }
2656: if (($httpbrowser=~/mac/i) ||
2657: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1075.2.77 raeburn 2658: if ($httpbrowser=~/win/i) {
2659: $clientos='win';
2660: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2661: $clientosversion = $1;
2662: }
2663: }
1.87 matthew 2664: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2665: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2666: $clientmobile=lc($1);
2667: }
2668: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2669: $clientinfo = 'firefox-'.$1;
2670: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2671: $clientinfo = 'chromeframe-'.$1;
2672: }
1.87 matthew 2673: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.77 raeburn 2674: $clientunicode,$clientos,$clientmobile,$clientinfo,
2675: $clientosversion);
1.87 matthew 2676: }
2677:
1.32 matthew 2678: ###############################################################
2679: ## Authentication changing form generation subroutines ##
2680: ###############################################################
2681: ##
2682: ## All of the authform_xxxxxxx subroutines take their inputs in a
2683: ## hash, and have reasonable default values.
2684: ##
2685: ## formname = the name given in the <form> tag.
1.35 matthew 2686: #-------------------------------------------
2687:
1.45 matthew 2688: =pod
2689:
1.112 bowersj2 2690: =head1 Authentication Routines
2691:
2692: =over 4
2693:
1.648 raeburn 2694: =item * &authform_xxxxxx()
1.35 matthew 2695:
2696: The authform_xxxxxx subroutines provide javascript and html forms which
2697: handle some of the conveniences required for authentication forms.
2698: This is not an optimal method, but it works.
2699:
2700: =over 4
2701:
1.112 bowersj2 2702: =item * authform_header
1.35 matthew 2703:
1.112 bowersj2 2704: =item * authform_authorwarning
1.35 matthew 2705:
1.112 bowersj2 2706: =item * authform_nochange
1.35 matthew 2707:
1.112 bowersj2 2708: =item * authform_kerberos
1.35 matthew 2709:
1.112 bowersj2 2710: =item * authform_internal
1.35 matthew 2711:
1.112 bowersj2 2712: =item * authform_filesystem
1.35 matthew 2713:
2714: =back
2715:
1.648 raeburn 2716: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2717:
1.35 matthew 2718: =cut
2719:
2720: #-------------------------------------------
1.32 matthew 2721: sub authform_header{
2722: my %in = (
2723: formname => 'cu',
1.80 albertel 2724: kerb_def_dom => '',
1.32 matthew 2725: @_,
2726: );
2727: $in{'formname'} = 'document.' . $in{'formname'};
2728: my $result='';
1.80 albertel 2729:
2730: #---------------------------------------------- Code for upper case translation
2731: my $Javascript_toUpperCase;
2732: unless ($in{kerb_def_dom}) {
2733: $Javascript_toUpperCase =<<"END";
2734: switch (choice) {
2735: case 'krb': currentform.elements[choicearg].value =
2736: currentform.elements[choicearg].value.toUpperCase();
2737: break;
2738: default:
2739: }
2740: END
2741: } else {
2742: $Javascript_toUpperCase = "";
2743: }
2744:
1.165 raeburn 2745: my $radioval = "'nochange'";
1.591 raeburn 2746: if (defined($in{'curr_authtype'})) {
2747: if ($in{'curr_authtype'} ne '') {
2748: $radioval = "'".$in{'curr_authtype'}."arg'";
2749: }
1.174 matthew 2750: }
1.165 raeburn 2751: my $argfield = 'null';
1.591 raeburn 2752: if (defined($in{'mode'})) {
1.165 raeburn 2753: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2754: if (defined($in{'curr_autharg'})) {
2755: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2756: $argfield = "'$in{'curr_autharg'}'";
2757: }
2758: }
2759: }
2760: }
2761:
1.32 matthew 2762: $result.=<<"END";
2763: var current = new Object();
1.165 raeburn 2764: current.radiovalue = $radioval;
2765: current.argfield = $argfield;
1.32 matthew 2766:
2767: function changed_radio(choice,currentform) {
2768: var choicearg = choice + 'arg';
2769: // If a radio button in changed, we need to change the argfield
2770: if (current.radiovalue != choice) {
2771: current.radiovalue = choice;
2772: if (current.argfield != null) {
2773: currentform.elements[current.argfield].value = '';
2774: }
2775: if (choice == 'nochange') {
2776: current.argfield = null;
2777: } else {
2778: current.argfield = choicearg;
2779: switch(choice) {
2780: case 'krb':
2781: currentform.elements[current.argfield].value =
2782: "$in{'kerb_def_dom'}";
2783: break;
2784: default:
2785: break;
2786: }
2787: }
2788: }
2789: return;
2790: }
1.22 www 2791:
1.32 matthew 2792: function changed_text(choice,currentform) {
2793: var choicearg = choice + 'arg';
2794: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2795: $Javascript_toUpperCase
1.32 matthew 2796: // clear old field
2797: if ((current.argfield != choicearg) && (current.argfield != null)) {
2798: currentform.elements[current.argfield].value = '';
2799: }
2800: current.argfield = choicearg;
2801: }
2802: set_auth_radio_buttons(choice,currentform);
2803: return;
1.20 www 2804: }
1.32 matthew 2805:
2806: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2807: var numauthchoices = currentform.login.length;
2808: if (typeof numauthchoices == "undefined") {
2809: return;
2810: }
1.32 matthew 2811: var i=0;
1.986 raeburn 2812: while (i < numauthchoices) {
1.32 matthew 2813: if (currentform.login[i].value == newvalue) { break; }
2814: i++;
2815: }
1.986 raeburn 2816: if (i == numauthchoices) {
1.32 matthew 2817: return;
2818: }
2819: current.radiovalue = newvalue;
2820: currentform.login[i].checked = true;
2821: return;
2822: }
2823: END
2824: return $result;
2825: }
2826:
1.1075.2.20 raeburn 2827: sub authform_authorwarning {
1.32 matthew 2828: my $result='';
1.144 matthew 2829: $result='<i>'.
2830: &mt('As a general rule, only authors or co-authors should be '.
2831: 'filesystem authenticated '.
2832: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2833: return $result;
2834: }
2835:
1.1075.2.20 raeburn 2836: sub authform_nochange {
1.32 matthew 2837: my %in = (
2838: formname => 'document.cu',
2839: kerb_def_dom => 'MSU.EDU',
2840: @_,
2841: );
1.1075.2.20 raeburn 2842: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2843: my $result;
1.1075.2.20 raeburn 2844: if (!$authnum) {
2845: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2846: } else {
2847: $result = '<label>'.&mt('[_1] Do not change login data',
2848: '<input type="radio" name="login" value="nochange" '.
2849: 'checked="checked" onclick="'.
1.281 albertel 2850: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2851: '</label>';
1.586 raeburn 2852: }
1.32 matthew 2853: return $result;
2854: }
2855:
1.591 raeburn 2856: sub authform_kerberos {
1.32 matthew 2857: my %in = (
2858: formname => 'document.cu',
2859: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2860: kerb_def_auth => 'krb4',
1.32 matthew 2861: @_,
2862: );
1.586 raeburn 2863: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1075.2.117 raeburn 2864: $autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2865: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2866: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2867: $check5 = ' checked="checked"';
1.80 albertel 2868: } else {
1.772 bisitz 2869: $check4 = ' checked="checked"';
1.80 albertel 2870: }
1.1075.2.117 raeburn 2871: if ($in{'readonly'}) {
2872: $disabled = ' disabled="disabled"';
2873: }
1.165 raeburn 2874: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2875: if (defined($in{'curr_authtype'})) {
2876: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2877: $krbcheck = ' checked="checked"';
1.623 raeburn 2878: if (defined($in{'mode'})) {
2879: if ($in{'mode'} eq 'modifyuser') {
2880: $krbcheck = '';
2881: }
2882: }
1.591 raeburn 2883: if (defined($in{'curr_kerb_ver'})) {
2884: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2885: $check5 = ' checked="checked"';
1.591 raeburn 2886: $check4 = '';
2887: } else {
1.772 bisitz 2888: $check4 = ' checked="checked"';
1.591 raeburn 2889: $check5 = '';
2890: }
1.586 raeburn 2891: }
1.591 raeburn 2892: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2893: $krbarg = $in{'curr_autharg'};
2894: }
1.586 raeburn 2895: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2896: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2897: $result =
2898: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2899: $in{'curr_autharg'},$krbver);
2900: } else {
2901: $result =
2902: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2903: }
2904: return $result;
2905: }
2906: }
2907: } else {
2908: if ($authnum == 1) {
1.784 bisitz 2909: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2910: }
2911: }
1.586 raeburn 2912: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2913: return;
1.587 raeburn 2914: } elsif ($authtype eq '') {
1.591 raeburn 2915: if (defined($in{'mode'})) {
1.587 raeburn 2916: if ($in{'mode'} eq 'modifycourse') {
2917: if ($authnum == 1) {
1.1075.2.117 raeburn 2918: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 2919: }
2920: }
2921: }
1.586 raeburn 2922: }
2923: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2924: if ($authtype eq '') {
2925: $authtype = '<input type="radio" name="login" value="krb" '.
2926: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1075.2.117 raeburn 2927: $krbcheck.$disabled.' />';
1.586 raeburn 2928: }
2929: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2930: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2931: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2932: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2933: $in{'curr_authtype'} eq 'krb4')) {
2934: $result .= &mt
1.144 matthew 2935: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2936: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2937: '<label>'.$authtype,
1.281 albertel 2938: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2939: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2940: 'onchange="'.$jscall.'"'.$disabled.' />',
2941: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
2942: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 2943: '</label>');
1.586 raeburn 2944: } elsif ($can_assign{'krb4'}) {
2945: $result .= &mt
2946: ('[_1] Kerberos authenticated with domain [_2] '.
2947: '[_3] Version 4 [_4]',
2948: '<label>'.$authtype,
2949: '</label><input type="text" size="10" name="krbarg" '.
2950: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2951: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2952: '<label><input type="hidden" name="krbver" value="4" />',
2953: '</label>');
2954: } elsif ($can_assign{'krb5'}) {
2955: $result .= &mt
2956: ('[_1] Kerberos authenticated with domain [_2] '.
2957: '[_3] Version 5 [_4]',
2958: '<label>'.$authtype,
2959: '</label><input type="text" size="10" name="krbarg" '.
2960: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2961: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2962: '<label><input type="hidden" name="krbver" value="5" />',
2963: '</label>');
2964: }
1.32 matthew 2965: return $result;
2966: }
2967:
1.1075.2.20 raeburn 2968: sub authform_internal {
1.586 raeburn 2969: my %in = (
1.32 matthew 2970: formname => 'document.cu',
2971: kerb_def_dom => 'MSU.EDU',
2972: @_,
2973: );
1.1075.2.117 raeburn 2974: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2975: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 2976: if ($in{'readonly'}) {
2977: $disabled = ' disabled="disabled"';
2978: }
1.591 raeburn 2979: if (defined($in{'curr_authtype'})) {
2980: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2981: if ($can_assign{'int'}) {
1.772 bisitz 2982: $intcheck = 'checked="checked" ';
1.623 raeburn 2983: if (defined($in{'mode'})) {
2984: if ($in{'mode'} eq 'modifyuser') {
2985: $intcheck = '';
2986: }
2987: }
1.591 raeburn 2988: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2989: $intarg = $in{'curr_autharg'};
2990: }
2991: } else {
2992: $result = &mt('Currently internally authenticated.');
2993: return $result;
1.165 raeburn 2994: }
2995: }
1.586 raeburn 2996: } else {
2997: if ($authnum == 1) {
1.784 bisitz 2998: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2999: }
3000: }
3001: if (!$can_assign{'int'}) {
3002: return;
1.587 raeburn 3003: } elsif ($authtype eq '') {
1.591 raeburn 3004: if (defined($in{'mode'})) {
1.587 raeburn 3005: if ($in{'mode'} eq 'modifycourse') {
3006: if ($authnum == 1) {
1.1075.2.117 raeburn 3007: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3008: }
3009: }
3010: }
1.165 raeburn 3011: }
1.586 raeburn 3012: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3013: if ($authtype eq '') {
3014: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1075.2.117 raeburn 3015: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3016: }
1.605 bisitz 3017: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1075.2.117 raeburn 3018: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3019: $result = &mt
1.144 matthew 3020: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3021: '<label>'.$authtype,'</label>'.$autharg);
1.1075.2.118 raeburn 3022: $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 3023: return $result;
3024: }
3025:
1.1075.2.20 raeburn 3026: sub authform_local {
1.32 matthew 3027: my %in = (
3028: formname => 'document.cu',
3029: kerb_def_dom => 'MSU.EDU',
3030: @_,
3031: );
1.1075.2.117 raeburn 3032: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3033: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3034: if ($in{'readonly'}) {
3035: $disabled = ' disabled="disabled"';
3036: }
1.591 raeburn 3037: if (defined($in{'curr_authtype'})) {
3038: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3039: if ($can_assign{'loc'}) {
1.772 bisitz 3040: $loccheck = 'checked="checked" ';
1.623 raeburn 3041: if (defined($in{'mode'})) {
3042: if ($in{'mode'} eq 'modifyuser') {
3043: $loccheck = '';
3044: }
3045: }
1.591 raeburn 3046: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3047: $locarg = $in{'curr_autharg'};
3048: }
3049: } else {
3050: $result = &mt('Currently using local (institutional) authentication.');
3051: return $result;
1.165 raeburn 3052: }
3053: }
1.586 raeburn 3054: } else {
3055: if ($authnum == 1) {
1.784 bisitz 3056: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3057: }
3058: }
3059: if (!$can_assign{'loc'}) {
3060: return;
1.587 raeburn 3061: } elsif ($authtype eq '') {
1.591 raeburn 3062: if (defined($in{'mode'})) {
1.587 raeburn 3063: if ($in{'mode'} eq 'modifycourse') {
3064: if ($authnum == 1) {
1.1075.2.117 raeburn 3065: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3066: }
3067: }
3068: }
1.165 raeburn 3069: }
1.586 raeburn 3070: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3071: if ($authtype eq '') {
3072: $authtype = '<input type="radio" name="login" value="loc" '.
3073: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3074: $jscall.'"'.$disabled.' />';
1.586 raeburn 3075: }
3076: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1075.2.117 raeburn 3077: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3078: $result = &mt('[_1] Local Authentication with argument [_2]',
3079: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3080: return $result;
3081: }
3082:
1.1075.2.20 raeburn 3083: sub authform_filesystem {
1.32 matthew 3084: my %in = (
3085: formname => 'document.cu',
3086: kerb_def_dom => 'MSU.EDU',
3087: @_,
3088: );
1.1075.2.117 raeburn 3089: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3090: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3091: if ($in{'readonly'}) {
3092: $disabled = ' disabled="disabled"';
3093: }
1.591 raeburn 3094: if (defined($in{'curr_authtype'})) {
3095: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3096: if ($can_assign{'fsys'}) {
1.772 bisitz 3097: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3098: if (defined($in{'mode'})) {
3099: if ($in{'mode'} eq 'modifyuser') {
3100: $fsyscheck = '';
3101: }
3102: }
1.586 raeburn 3103: } else {
3104: $result = &mt('Currently Filesystem Authenticated.');
3105: return $result;
3106: }
3107: }
3108: } else {
3109: if ($authnum == 1) {
1.784 bisitz 3110: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3111: }
3112: }
3113: if (!$can_assign{'fsys'}) {
3114: return;
1.587 raeburn 3115: } elsif ($authtype eq '') {
1.591 raeburn 3116: if (defined($in{'mode'})) {
1.587 raeburn 3117: if ($in{'mode'} eq 'modifycourse') {
3118: if ($authnum == 1) {
1.1075.2.117 raeburn 3119: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3120: }
3121: }
3122: }
1.586 raeburn 3123: }
3124: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3125: if ($authtype eq '') {
3126: $authtype = '<input type="radio" name="login" value="fsys" '.
3127: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3128: $jscall.'"'.$disabled.' />';
1.586 raeburn 3129: }
3130: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
1.1075.2.117 raeburn 3131: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3132: $result = &mt
1.144 matthew 3133: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 3134: '<label><input type="radio" name="login" value="fsys" '.
1.1075.2.117 raeburn 3135: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />',
1.605 bisitz 3136: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.1075.2.117 raeburn 3137: 'onchange="'.$jscall.'"'.$disabled.' />');
1.32 matthew 3138: return $result;
3139: }
3140:
1.586 raeburn 3141: sub get_assignable_auth {
3142: my ($dom) = @_;
3143: if ($dom eq '') {
3144: $dom = $env{'request.role.domain'};
3145: }
3146: my %can_assign = (
3147: krb4 => 1,
3148: krb5 => 1,
3149: int => 1,
3150: loc => 1,
3151: );
3152: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3153: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3154: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3155: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3156: my $context;
3157: if ($env{'request.role'} =~ /^au/) {
3158: $context = 'author';
1.1075.2.117 raeburn 3159: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3160: $context = 'domain';
3161: } elsif ($env{'request.course.id'}) {
3162: $context = 'course';
3163: }
3164: if ($context) {
3165: if (ref($authhash->{$context}) eq 'HASH') {
3166: %can_assign = %{$authhash->{$context}};
3167: }
3168: }
3169: }
3170: }
3171: my $authnum = 0;
3172: foreach my $key (keys(%can_assign)) {
3173: if ($can_assign{$key}) {
3174: $authnum ++;
3175: }
3176: }
3177: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3178: $authnum --;
3179: }
3180: return ($authnum,%can_assign);
3181: }
3182:
1.1075.2.137 raeburn 3183: sub check_passwd_rules {
3184: my ($domain,$plainpass) = @_;
3185: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3186: my ($min,$max,@chars,@brokerule,$warning);
1.1075.2.138 raeburn 3187: $min = $Apache::lonnet::passwdmin;
1.1075.2.137 raeburn 3188: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3189: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1075.2.138 raeburn 3190: if ($passwdconf{'min'} > $min) {
3191: $min = $passwdconf{'min'};
3192: }
1.1075.2.137 raeburn 3193: }
3194: if ($passwdconf{'max'} =~ /^\d+$/) {
3195: $max = $passwdconf{'max'};
3196: }
3197: @chars = @{$passwdconf{'chars'}};
3198: }
3199: if (($min) && (length($plainpass) < $min)) {
3200: push(@brokerule,'min');
3201: }
3202: if (($max) && (length($plainpass) > $max)) {
3203: push(@brokerule,'max');
3204: }
3205: if (@chars) {
3206: my %rules;
3207: map { $rules{$_} = 1; } @chars;
3208: if ($rules{'uc'}) {
3209: unless ($plainpass =~ /[A-Z]/) {
3210: push(@brokerule,'uc');
3211: }
3212: }
3213: if ($rules{'lc'}) {
3214: unless ($plainpass =~ /[a-z]/) {
3215: push(@brokerule,'lc');
3216: }
3217: }
3218: if ($rules{'num'}) {
3219: unless ($plainpass =~ /\d/) {
3220: push(@brokerule,'num');
3221: }
3222: }
3223: if ($rules{'spec'}) {
3224: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3225: push(@brokerule,'spec');
3226: }
3227: }
3228: }
3229: if (@brokerule) {
3230: my %rulenames = &Apache::lonlocal::texthash(
3231: uc => 'At least one upper case letter',
3232: lc => 'At least one lower case letter',
3233: num => 'At least one number',
3234: spec => 'At least one non-alphanumeric',
3235: );
3236: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3237: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3238: $rulenames{'num'} .= ': 0123456789';
3239: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3240: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3241: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3242: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1075.2.143 raeburn 3243: foreach my $rule ('min','max','uc','lc','num','spec') {
1.1075.2.137 raeburn 3244: if (grep(/^$rule$/,@brokerule)) {
3245: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3246: }
3247: }
3248: $warning .= '</ul>';
3249: }
3250: if (wantarray) {
3251: return @brokerule;
3252: }
3253: return $warning;
3254: }
3255:
1.80 albertel 3256: ###############################################################
3257: ## Get Kerberos Defaults for Domain ##
3258: ###############################################################
3259: ##
3260: ## Returns default kerberos version and an associated argument
3261: ## as listed in file domain.tab. If not listed, provides
3262: ## appropriate default domain and kerberos version.
3263: ##
3264: #-------------------------------------------
3265:
3266: =pod
3267:
1.648 raeburn 3268: =item * &get_kerberos_defaults()
1.80 albertel 3269:
3270: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3271: version and domain. If not found, it defaults to version 4 and the
3272: domain of the server.
1.80 albertel 3273:
1.648 raeburn 3274: =over 4
3275:
1.80 albertel 3276: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3277:
1.648 raeburn 3278: =back
3279:
3280: =back
3281:
1.80 albertel 3282: =cut
3283:
3284: #-------------------------------------------
3285: sub get_kerberos_defaults {
3286: my $domain=shift;
1.641 raeburn 3287: my ($krbdef,$krbdefdom);
3288: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3289: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3290: $krbdef = $domdefaults{'auth_def'};
3291: $krbdefdom = $domdefaults{'auth_arg_def'};
3292: } else {
1.80 albertel 3293: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3294: my $krbdefdom=$1;
3295: $krbdefdom=~tr/a-z/A-Z/;
3296: $krbdef = "krb4";
3297: }
3298: return ($krbdef,$krbdefdom);
3299: }
1.112 bowersj2 3300:
1.32 matthew 3301:
1.46 matthew 3302: ###############################################################
3303: ## Thesaurus Functions ##
3304: ###############################################################
1.20 www 3305:
1.46 matthew 3306: =pod
1.20 www 3307:
1.112 bowersj2 3308: =head1 Thesaurus Functions
3309:
3310: =over 4
3311:
1.648 raeburn 3312: =item * &initialize_keywords()
1.46 matthew 3313:
3314: Initializes the package variable %Keywords if it is empty. Uses the
3315: package variable $thesaurus_db_file.
3316:
3317: =cut
3318:
3319: ###################################################
3320:
3321: sub initialize_keywords {
3322: return 1 if (scalar keys(%Keywords));
3323: # If we are here, %Keywords is empty, so fill it up
3324: # Make sure the file we need exists...
3325: if (! -e $thesaurus_db_file) {
3326: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3327: " failed because it does not exist");
3328: return 0;
3329: }
3330: # Set up the hash as a database
3331: my %thesaurus_db;
3332: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3333: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3334: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3335: $thesaurus_db_file);
3336: return 0;
3337: }
3338: # Get the average number of appearances of a word.
3339: my $avecount = $thesaurus_db{'average.count'};
3340: # Put keywords (those that appear > average) into %Keywords
3341: while (my ($word,$data)=each (%thesaurus_db)) {
3342: my ($count,undef) = split /:/,$data;
3343: $Keywords{$word}++ if ($count > $avecount);
3344: }
3345: untie %thesaurus_db;
3346: # Remove special values from %Keywords.
1.356 albertel 3347: foreach my $value ('total.count','average.count') {
3348: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3349: }
1.46 matthew 3350: return 1;
3351: }
3352:
3353: ###################################################
3354:
3355: =pod
3356:
1.648 raeburn 3357: =item * &keyword($word)
1.46 matthew 3358:
3359: Returns true if $word is a keyword. A keyword is a word that appears more
3360: than the average number of times in the thesaurus database. Calls
3361: &initialize_keywords
3362:
3363: =cut
3364:
3365: ###################################################
1.20 www 3366:
3367: sub keyword {
1.46 matthew 3368: return if (!&initialize_keywords());
3369: my $word=lc(shift());
3370: $word=~s/\W//g;
3371: return exists($Keywords{$word});
1.20 www 3372: }
1.46 matthew 3373:
3374: ###############################################################
3375:
3376: =pod
1.20 www 3377:
1.648 raeburn 3378: =item * &get_related_words()
1.46 matthew 3379:
1.160 matthew 3380: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3381: an array of words. If the keyword is not in the thesaurus, an empty array
3382: will be returned. The order of the words returned is determined by the
3383: database which holds them.
3384:
3385: Uses global $thesaurus_db_file.
3386:
1.1057 foxr 3387:
1.46 matthew 3388: =cut
3389:
3390: ###############################################################
3391: sub get_related_words {
3392: my $keyword = shift;
3393: my %thesaurus_db;
3394: if (! -e $thesaurus_db_file) {
3395: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3396: "failed because the file does not exist");
3397: return ();
3398: }
3399: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3400: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3401: return ();
3402: }
3403: my @Words=();
1.429 www 3404: my $count=0;
1.46 matthew 3405: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3406: # The first element is the number of times
3407: # the word appears. We do not need it now.
1.429 www 3408: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3409: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3410: my $threshold=$mostfrequentcount/10;
3411: foreach my $possibleword (@RelatedWords) {
3412: my ($word,$wordcount)=split(/\,/,$possibleword);
3413: if ($wordcount>$threshold) {
3414: push(@Words,$word);
3415: $count++;
3416: if ($count>10) { last; }
3417: }
1.20 www 3418: }
3419: }
1.46 matthew 3420: untie %thesaurus_db;
3421: return @Words;
1.14 harris41 3422: }
1.46 matthew 3423:
1.112 bowersj2 3424: =pod
3425:
3426: =back
3427:
3428: =cut
1.61 www 3429:
3430: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3431: =pod
3432:
1.112 bowersj2 3433: =head1 User Name Functions
3434:
3435: =over 4
3436:
1.648 raeburn 3437: =item * &plainname($uname,$udom,$first)
1.81 albertel 3438:
1.112 bowersj2 3439: Takes a users logon name and returns it as a string in
1.226 albertel 3440: "first middle last generation" form
3441: if $first is set to 'lastname' then it returns it as
3442: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3443:
3444: =cut
1.61 www 3445:
1.295 www 3446:
1.81 albertel 3447: ###############################################################
1.61 www 3448: sub plainname {
1.226 albertel 3449: my ($uname,$udom,$first)=@_;
1.537 albertel 3450: return if (!defined($uname) || !defined($udom));
1.295 www 3451: my %names=&getnames($uname,$udom);
1.226 albertel 3452: my $name=&Apache::lonnet::format_name($names{'firstname'},
3453: $names{'middlename'},
3454: $names{'lastname'},
3455: $names{'generation'},$first);
3456: $name=~s/^\s+//;
1.62 www 3457: $name=~s/\s+$//;
3458: $name=~s/\s+/ /g;
1.353 albertel 3459: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3460: return $name;
1.61 www 3461: }
1.66 www 3462:
3463: # -------------------------------------------------------------------- Nickname
1.81 albertel 3464: =pod
3465:
1.648 raeburn 3466: =item * &nickname($uname,$udom)
1.81 albertel 3467:
3468: Gets a users name and returns it as a string as
3469:
3470: ""nickname""
1.66 www 3471:
1.81 albertel 3472: if the user has a nickname or
3473:
3474: "first middle last generation"
3475:
3476: if the user does not
3477:
3478: =cut
1.66 www 3479:
3480: sub nickname {
3481: my ($uname,$udom)=@_;
1.537 albertel 3482: return if (!defined($uname) || !defined($udom));
1.295 www 3483: my %names=&getnames($uname,$udom);
1.68 albertel 3484: my $name=$names{'nickname'};
1.66 www 3485: if ($name) {
3486: $name='"'.$name.'"';
3487: } else {
3488: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3489: $names{'lastname'}.' '.$names{'generation'};
3490: $name=~s/\s+$//;
3491: $name=~s/\s+/ /g;
3492: }
3493: return $name;
3494: }
3495:
1.295 www 3496: sub getnames {
3497: my ($uname,$udom)=@_;
1.537 albertel 3498: return if (!defined($uname) || !defined($udom));
1.433 albertel 3499: if ($udom eq 'public' && $uname eq 'public') {
3500: return ('lastname' => &mt('Public'));
3501: }
1.295 www 3502: my $id=$uname.':'.$udom;
3503: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3504: if ($cached) {
3505: return %{$names};
3506: } else {
3507: my %loadnames=&Apache::lonnet::get('environment',
3508: ['firstname','middlename','lastname','generation','nickname'],
3509: $udom,$uname);
3510: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3511: return %loadnames;
3512: }
3513: }
1.61 www 3514:
1.542 raeburn 3515: # -------------------------------------------------------------------- getemails
1.648 raeburn 3516:
1.542 raeburn 3517: =pod
3518:
1.648 raeburn 3519: =item * &getemails($uname,$udom)
1.542 raeburn 3520:
3521: Gets a user's email information and returns it as a hash with keys:
3522: notification, critnotification, permanentemail
3523:
3524: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3525: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3526:
1.648 raeburn 3527:
1.542 raeburn 3528: =cut
3529:
1.648 raeburn 3530:
1.466 albertel 3531: sub getemails {
3532: my ($uname,$udom)=@_;
3533: if ($udom eq 'public' && $uname eq 'public') {
3534: return;
3535: }
1.467 www 3536: if (!$udom) { $udom=$env{'user.domain'}; }
3537: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3538: my $id=$uname.':'.$udom;
3539: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3540: if ($cached) {
3541: return %{$names};
3542: } else {
3543: my %loadnames=&Apache::lonnet::get('environment',
3544: ['notification','critnotification',
3545: 'permanentemail'],
3546: $udom,$uname);
3547: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3548: return %loadnames;
3549: }
3550: }
3551:
1.551 albertel 3552: sub flush_email_cache {
3553: my ($uname,$udom)=@_;
3554: if (!$udom) { $udom =$env{'user.domain'}; }
3555: if (!$uname) { $uname=$env{'user.name'}; }
3556: return if ($udom eq 'public' && $uname eq 'public');
3557: my $id=$uname.':'.$udom;
3558: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3559: }
3560:
1.728 raeburn 3561: # -------------------------------------------------------------------- getlangs
3562:
3563: =pod
3564:
3565: =item * &getlangs($uname,$udom)
3566:
3567: Gets a user's language preference and returns it as a hash with key:
3568: language.
3569:
3570: =cut
3571:
3572:
3573: sub getlangs {
3574: my ($uname,$udom) = @_;
3575: if (!$udom) { $udom =$env{'user.domain'}; }
3576: if (!$uname) { $uname=$env{'user.name'}; }
3577: my $id=$uname.':'.$udom;
3578: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3579: if ($cached) {
3580: return %{$langs};
3581: } else {
3582: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3583: $udom,$uname);
3584: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3585: return %loadlangs;
3586: }
3587: }
3588:
3589: sub flush_langs_cache {
3590: my ($uname,$udom)=@_;
3591: if (!$udom) { $udom =$env{'user.domain'}; }
3592: if (!$uname) { $uname=$env{'user.name'}; }
3593: return if ($udom eq 'public' && $uname eq 'public');
3594: my $id=$uname.':'.$udom;
3595: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3596: }
3597:
1.61 www 3598: # ------------------------------------------------------------------ Screenname
1.81 albertel 3599:
3600: =pod
3601:
1.648 raeburn 3602: =item * &screenname($uname,$udom)
1.81 albertel 3603:
3604: Gets a users screenname and returns it as a string
3605:
3606: =cut
1.61 www 3607:
3608: sub screenname {
3609: my ($uname,$udom)=@_;
1.258 albertel 3610: if ($uname eq $env{'user.name'} &&
3611: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3612: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3613: return $names{'screenname'};
1.62 www 3614: }
3615:
1.212 albertel 3616:
1.802 bisitz 3617: # ------------------------------------------------------------- Confirm Wrapper
3618: =pod
3619:
1.1075.2.42 raeburn 3620: =item * &confirmwrapper($message)
1.802 bisitz 3621:
3622: Wrap messages about completion of operation in box
3623:
3624: =cut
3625:
3626: sub confirmwrapper {
3627: my ($message)=@_;
3628: if ($message) {
3629: return "\n".'<div class="LC_confirm_box">'."\n"
3630: .$message."\n"
3631: .'</div>'."\n";
3632: } else {
3633: return $message;
3634: }
3635: }
3636:
1.62 www 3637: # ------------------------------------------------------------- Message Wrapper
3638:
3639: sub messagewrapper {
1.369 www 3640: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3641: return
1.441 albertel 3642: '<a href="/adm/email?compose=individual&'.
3643: 'recname='.$username.'&recdom='.$domain.
3644: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3645: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3646: }
1.802 bisitz 3647:
1.74 www 3648: # --------------------------------------------------------------- Notes Wrapper
3649:
3650: sub noteswrapper {
3651: my ($link,$un,$do)=@_;
3652: return
1.896 amueller 3653: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3654: }
1.802 bisitz 3655:
1.62 www 3656: # ------------------------------------------------------------- Aboutme Wrapper
3657:
3658: sub aboutmewrapper {
1.1070 raeburn 3659: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3660: if (!defined($username) && !defined($domain)) {
3661: return;
3662: }
1.1075.2.15 raeburn 3663: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3664: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3665: }
3666:
3667: # ------------------------------------------------------------ Syllabus Wrapper
3668:
3669: sub syllabuswrapper {
1.707 bisitz 3670: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3671: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3672: }
1.14 harris41 3673:
1.802 bisitz 3674: # -----------------------------------------------------------------------------
3675:
1.208 matthew 3676: sub track_student_link {
1.887 raeburn 3677: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3678: my $link ="/adm/trackstudent?";
1.208 matthew 3679: my $title = 'View recent activity';
3680: if (defined($sname) && $sname !~ /^\s*$/ &&
3681: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3682: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3683: $title .= ' of this student';
1.268 albertel 3684: }
1.208 matthew 3685: if (defined($target) && $target !~ /^\s*$/) {
3686: $target = qq{target="$target"};
3687: } else {
3688: $target = '';
3689: }
1.268 albertel 3690: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3691: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3692: $title = &mt($title);
3693: $linktext = &mt($linktext);
1.448 albertel 3694: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3695: &help_open_topic('View_recent_activity');
1.208 matthew 3696: }
3697:
1.781 raeburn 3698: sub slot_reservations_link {
3699: my ($linktext,$sname,$sdom,$target) = @_;
3700: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3701: my $title = 'View slot reservation history';
3702: if (defined($sname) && $sname !~ /^\s*$/ &&
3703: defined($sdom) && $sdom !~ /^\s*$/) {
3704: $link .= "&uname=$sname&udom=$sdom";
3705: $title .= ' of this student';
3706: }
3707: if (defined($target) && $target !~ /^\s*$/) {
3708: $target = qq{target="$target"};
3709: } else {
3710: $target = '';
3711: }
3712: $title = &mt($title);
3713: $linktext = &mt($linktext);
3714: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3715: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3716:
3717: }
3718:
1.508 www 3719: # ===================================================== Display a student photo
3720:
3721:
1.509 albertel 3722: sub student_image_tag {
1.508 www 3723: my ($domain,$user)=@_;
3724: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3725: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3726: return '<img src="'.$imgsrc.'" align="right" />';
3727: } else {
3728: return '';
3729: }
3730: }
3731:
1.112 bowersj2 3732: =pod
3733:
3734: =back
3735:
3736: =head1 Access .tab File Data
3737:
3738: =over 4
3739:
1.648 raeburn 3740: =item * &languageids()
1.112 bowersj2 3741:
3742: returns list of all language ids
3743:
3744: =cut
3745:
1.14 harris41 3746: sub languageids {
1.16 harris41 3747: return sort(keys(%language));
1.14 harris41 3748: }
3749:
1.112 bowersj2 3750: =pod
3751:
1.648 raeburn 3752: =item * &languagedescription()
1.112 bowersj2 3753:
3754: returns description of a specified language id
3755:
3756: =cut
3757:
1.14 harris41 3758: sub languagedescription {
1.125 www 3759: my $code=shift;
3760: return ($supported_language{$code}?'* ':'').
3761: $language{$code}.
1.126 www 3762: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3763: }
3764:
1.1048 foxr 3765: =pod
3766:
3767: =item * &plainlanguagedescription
3768:
3769: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3770: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3771:
3772: =cut
3773:
1.145 www 3774: sub plainlanguagedescription {
3775: my $code=shift;
3776: return $language{$code};
3777: }
3778:
1.1048 foxr 3779: =pod
3780:
3781: =item * &supportedlanguagecode
3782:
3783: Returns the supported language code (e.g. sptutf maps to pt) given a language
3784: code.
3785:
3786: =cut
3787:
1.145 www 3788: sub supportedlanguagecode {
3789: my $code=shift;
3790: return $supported_language{$code};
1.97 www 3791: }
3792:
1.112 bowersj2 3793: =pod
3794:
1.1048 foxr 3795: =item * &latexlanguage()
3796:
3797: Given a language key code returns the correspondnig language to use
3798: to select the correct hyphenation on LaTeX printouts. This is undef if there
3799: is no supported hyphenation for the language code.
3800:
3801: =cut
3802:
3803: sub latexlanguage {
3804: my $code = shift;
3805: return $latex_language{$code};
3806: }
3807:
3808: =pod
3809:
3810: =item * &latexhyphenation()
3811:
3812: Same as above but what's supplied is the language as it might be stored
3813: in the metadata.
3814:
3815: =cut
3816:
3817: sub latexhyphenation {
3818: my $key = shift;
3819: return $latex_language_bykey{$key};
3820: }
3821:
3822: =pod
3823:
1.648 raeburn 3824: =item * ©rightids()
1.112 bowersj2 3825:
3826: returns list of all copyrights
3827:
3828: =cut
3829:
3830: sub copyrightids {
3831: return sort(keys(%cprtag));
3832: }
3833:
3834: =pod
3835:
1.648 raeburn 3836: =item * ©rightdescription()
1.112 bowersj2 3837:
3838: returns description of a specified copyright id
3839:
3840: =cut
3841:
3842: sub copyrightdescription {
1.166 www 3843: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3844: }
1.197 matthew 3845:
3846: =pod
3847:
1.648 raeburn 3848: =item * &source_copyrightids()
1.192 taceyjo1 3849:
3850: returns list of all source copyrights
3851:
3852: =cut
3853:
3854: sub source_copyrightids {
3855: return sort(keys(%scprtag));
3856: }
3857:
3858: =pod
3859:
1.648 raeburn 3860: =item * &source_copyrightdescription()
1.192 taceyjo1 3861:
3862: returns description of a specified source copyright id
3863:
3864: =cut
3865:
3866: sub source_copyrightdescription {
3867: return &mt($scprtag{shift(@_)});
3868: }
1.112 bowersj2 3869:
3870: =pod
3871:
1.648 raeburn 3872: =item * &filecategories()
1.112 bowersj2 3873:
3874: returns list of all file categories
3875:
3876: =cut
3877:
3878: sub filecategories {
3879: return sort(keys(%category_extensions));
3880: }
3881:
3882: =pod
3883:
1.648 raeburn 3884: =item * &filecategorytypes()
1.112 bowersj2 3885:
3886: returns list of file types belonging to a given file
3887: category
3888:
3889: =cut
3890:
3891: sub filecategorytypes {
1.356 albertel 3892: my ($cat) = @_;
3893: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3894: }
3895:
3896: =pod
3897:
1.648 raeburn 3898: =item * &fileembstyle()
1.112 bowersj2 3899:
3900: returns embedding style for a specified file type
3901:
3902: =cut
3903:
3904: sub fileembstyle {
3905: return $fe{lc(shift(@_))};
1.169 www 3906: }
3907:
1.351 www 3908: sub filemimetype {
3909: return $fm{lc(shift(@_))};
3910: }
3911:
1.169 www 3912:
3913: sub filecategoryselect {
3914: my ($name,$value)=@_;
1.189 matthew 3915: return &select_form($value,$name,
1.970 raeburn 3916: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3917: }
3918:
3919: =pod
3920:
1.648 raeburn 3921: =item * &filedescription()
1.112 bowersj2 3922:
3923: returns description for a specified file type
3924:
3925: =cut
3926:
3927: sub filedescription {
1.188 matthew 3928: my $file_description = $fd{lc(shift())};
3929: $file_description =~ s:([\[\]]):~$1:g;
3930: return &mt($file_description);
1.112 bowersj2 3931: }
3932:
3933: =pod
3934:
1.648 raeburn 3935: =item * &filedescriptionex()
1.112 bowersj2 3936:
3937: returns description for a specified file type with
3938: extra formatting
3939:
3940: =cut
3941:
3942: sub filedescriptionex {
3943: my $ex=shift;
1.188 matthew 3944: my $file_description = $fd{lc($ex)};
3945: $file_description =~ s:([\[\]]):~$1:g;
3946: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3947: }
3948:
3949: # End of .tab access
3950: =pod
3951:
3952: =back
3953:
3954: =cut
3955:
3956: # ------------------------------------------------------------------ File Types
3957: sub fileextensions {
3958: return sort(keys(%fe));
3959: }
3960:
1.97 www 3961: # ----------------------------------------------------------- Display Languages
3962: # returns a hash with all desired display languages
3963: #
3964:
3965: sub display_languages {
3966: my %languages=();
1.695 raeburn 3967: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3968: $languages{$lang}=1;
1.97 www 3969: }
3970: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3971: if ($env{'form.displaylanguage'}) {
1.356 albertel 3972: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3973: $languages{$lang}=1;
1.97 www 3974: }
3975: }
3976: return %languages;
1.14 harris41 3977: }
3978:
1.582 albertel 3979: sub languages {
3980: my ($possible_langs) = @_;
1.695 raeburn 3981: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3982: if (!ref($possible_langs)) {
3983: if( wantarray ) {
3984: return @preferred_langs;
3985: } else {
3986: return $preferred_langs[0];
3987: }
3988: }
3989: my %possibilities = map { $_ => 1 } (@$possible_langs);
3990: my @preferred_possibilities;
3991: foreach my $preferred_lang (@preferred_langs) {
3992: if (exists($possibilities{$preferred_lang})) {
3993: push(@preferred_possibilities, $preferred_lang);
3994: }
3995: }
3996: if( wantarray ) {
3997: return @preferred_possibilities;
3998: }
3999: return $preferred_possibilities[0];
4000: }
4001:
1.742 raeburn 4002: sub user_lang {
4003: my ($touname,$toudom,$fromcid) = @_;
4004: my @userlangs;
4005: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4006: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4007: $env{'course.'.$fromcid.'.languages'}));
4008: } else {
4009: my %langhash = &getlangs($touname,$toudom);
4010: if ($langhash{'languages'} ne '') {
4011: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4012: } else {
4013: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4014: if ($domdefs{'lang_def'} ne '') {
4015: @userlangs = ($domdefs{'lang_def'});
4016: }
4017: }
4018: }
4019: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4020: my $user_lh = Apache::localize->get_handle(@languages);
4021: return $user_lh;
4022: }
4023:
4024:
1.112 bowersj2 4025: ###############################################################
4026: ## Student Answer Attempts ##
4027: ###############################################################
4028:
4029: =pod
4030:
4031: =head1 Alternate Problem Views
4032:
4033: =over 4
4034:
1.648 raeburn 4035: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1075.2.86 raeburn 4036: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4037:
4038: Return string with previous attempt on problem. Arguments:
4039:
4040: =over 4
4041:
4042: =item * $symb: Problem, including path
4043:
4044: =item * $username: username of the desired student
4045:
4046: =item * $domain: domain of the desired student
1.14 harris41 4047:
1.112 bowersj2 4048: =item * $course: Course ID
1.14 harris41 4049:
1.112 bowersj2 4050: =item * $getattempt: Leave blank for all attempts, otherwise put
4051: something
1.14 harris41 4052:
1.112 bowersj2 4053: =item * $regexp: if string matches this regexp, the string will be
4054: sent to $gradesub
1.14 harris41 4055:
1.112 bowersj2 4056: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4057:
1.1075.2.86 raeburn 4058: =item * $usec: section of the desired student
4059:
4060: =item * $identifier: counter for student (multiple students one problem) or
4061: problem (one student; whole sequence).
4062:
1.112 bowersj2 4063: =back
1.14 harris41 4064:
1.112 bowersj2 4065: The output string is a table containing all desired attempts, if any.
1.16 harris41 4066:
1.112 bowersj2 4067: =cut
1.1 albertel 4068:
4069: sub get_previous_attempt {
1.1075.2.86 raeburn 4070: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4071: my $prevattempts='';
1.43 ng 4072: no strict 'refs';
1.1 albertel 4073: if ($symb) {
1.3 albertel 4074: my (%returnhash)=
4075: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4076: if ($returnhash{'version'}) {
4077: my %lasthash=();
4078: my $version;
4079: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.91 raeburn 4080: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4081: if ($key =~ /\.rawrndseed$/) {
4082: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4083: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4084: } else {
4085: $lasthash{$key}=$returnhash{$version.':'.$key};
4086: }
1.19 harris41 4087: }
1.1 albertel 4088: }
1.596 albertel 4089: $prevattempts=&start_data_table().&start_data_table_header_row();
4090: $prevattempts.='<th>'.&mt('History').'</th>';
1.1075.2.86 raeburn 4091: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4092: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4093: foreach my $key (sort(keys(%lasthash))) {
4094: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4095: if ($#parts > 0) {
1.31 albertel 4096: my $data=$parts[-1];
1.989 raeburn 4097: next if ($data eq 'foilorder');
1.31 albertel 4098: pop(@parts);
1.1010 www 4099: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4100: if ($data eq 'type') {
4101: unless ($showsurv) {
4102: my $id = join(',',@parts);
4103: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4104: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4105: $lasthidden{$ign.'.'.$id} = 1;
4106: }
1.945 raeburn 4107: }
1.1075.2.86 raeburn 4108: if ($identifier ne '') {
4109: my $id = join(',',@parts);
4110: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4111: $domain,$username,$usec,undef,$course) =~ /^no/) {
4112: $hidestatus{$ign.'.'.$id} = 1;
4113: }
4114: }
4115: } elsif ($data eq 'regrader') {
4116: if (($identifier ne '') && (@parts)) {
4117: my $id = join(',',@parts);
4118: $regraded{$ign.'.'.$id} = 1;
4119: }
1.1010 www 4120: }
1.31 albertel 4121: } else {
1.41 ng 4122: if ($#parts == 0) {
4123: $prevattempts.='<th>'.$parts[0].'</th>';
4124: } else {
4125: $prevattempts.='<th>'.$ign.'</th>';
4126: }
1.31 albertel 4127: }
1.16 harris41 4128: }
1.596 albertel 4129: $prevattempts.=&end_data_table_header_row();
1.40 ng 4130: if ($getattempt eq '') {
1.1075.2.86 raeburn 4131: my (%solved,%resets,%probstatus);
4132: if (($identifier ne '') && (keys(%regraded) > 0)) {
4133: for ($version=1;$version<=$returnhash{'version'};$version++) {
4134: foreach my $id (keys(%regraded)) {
4135: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4136: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4137: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4138: push(@{$resets{$id}},$version);
4139: }
4140: }
4141: }
4142: }
1.40 ng 4143: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.86 raeburn 4144: my (@hidden,@unsolved);
1.945 raeburn 4145: if (%typeparts) {
4146: foreach my $id (keys(%typeparts)) {
1.1075.2.86 raeburn 4147: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4148: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4149: push(@hidden,$id);
1.1075.2.86 raeburn 4150: } elsif ($identifier ne '') {
4151: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4152: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4153: ($hidestatus{$id})) {
4154: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
4155: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4156: push(@{$solved{$id}},$version);
4157: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4158: (ref($solved{$id}) eq 'ARRAY')) {
4159: my $skip;
4160: if (ref($resets{$id}) eq 'ARRAY') {
4161: foreach my $reset (@{$resets{$id}}) {
4162: if ($reset > $solved{$id}[-1]) {
4163: $skip=1;
4164: last;
4165: }
4166: }
4167: }
4168: unless ($skip) {
4169: my ($ign,$partslist) = split(/\./,$id,2);
4170: push(@unsolved,$partslist);
4171: }
4172: }
4173: }
1.945 raeburn 4174: }
4175: }
4176: }
4177: $prevattempts.=&start_data_table_row().
1.1075.2.86 raeburn 4178: '<td>'.&mt('Transaction [_1]',$version);
4179: if (@unsolved) {
4180: $prevattempts .= '<span class="LC_nobreak"><label>'.
4181: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4182: &mt('Hide').'</label></span>';
4183: }
4184: $prevattempts .= '</td>';
1.945 raeburn 4185: if (@hidden) {
4186: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4187: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4188: my $hide;
4189: foreach my $id (@hidden) {
4190: if ($key =~ /^\Q$id\E/) {
4191: $hide = 1;
4192: last;
4193: }
4194: }
4195: if ($hide) {
4196: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4197: if (($data eq 'award') || ($data eq 'awarddetail')) {
4198: my $value = &format_previous_attempt_value($key,
4199: $returnhash{$version.':'.$key});
4200: $prevattempts.='<td>'.$value.' </td>';
4201: } else {
4202: $prevattempts.='<td> </td>';
4203: }
4204: } else {
4205: if ($key =~ /\./) {
1.1075.2.91 raeburn 4206: my $value = $returnhash{$version.':'.$key};
4207: if ($key =~ /\.rndseed$/) {
4208: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4209: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4210: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4211: }
4212: }
4213: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4214: ' </td>';
1.945 raeburn 4215: } else {
4216: $prevattempts.='<td> </td>';
4217: }
4218: }
4219: }
4220: } else {
4221: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4222: next if ($key =~ /\.foilorder$/);
1.1075.2.91 raeburn 4223: my $value = $returnhash{$version.':'.$key};
4224: if ($key =~ /\.rndseed$/) {
4225: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4226: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4227: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4228: }
4229: }
4230: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4231: ' </td>';
1.945 raeburn 4232: }
4233: }
4234: $prevattempts.=&end_data_table_row();
1.40 ng 4235: }
1.1 albertel 4236: }
1.945 raeburn 4237: my @currhidden = keys(%lasthidden);
1.596 albertel 4238: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4239: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4240: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4241: if (%typeparts) {
4242: my $hidden;
4243: foreach my $id (@currhidden) {
4244: if ($key =~ /^\Q$id\E/) {
4245: $hidden = 1;
4246: last;
4247: }
4248: }
4249: if ($hidden) {
4250: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4251: if (($data eq 'award') || ($data eq 'awarddetail')) {
4252: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4253: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4254: $value = &$gradesub($value);
4255: }
4256: $prevattempts.='<td>'.$value.' </td>';
4257: } else {
4258: $prevattempts.='<td> </td>';
4259: }
4260: } else {
4261: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4262: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4263: $value = &$gradesub($value);
4264: }
4265: $prevattempts.='<td>'.$value.' </td>';
4266: }
4267: } else {
4268: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4269: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4270: $value = &$gradesub($value);
4271: }
4272: $prevattempts.='<td>'.$value.' </td>';
4273: }
1.16 harris41 4274: }
1.596 albertel 4275: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4276: } else {
1.596 albertel 4277: $prevattempts=
4278: &start_data_table().&start_data_table_row().
4279: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4280: &end_data_table_row().&end_data_table();
1.1 albertel 4281: }
4282: } else {
1.596 albertel 4283: $prevattempts=
4284: &start_data_table().&start_data_table_row().
4285: '<td>'.&mt('No data.').'</td>'.
4286: &end_data_table_row().&end_data_table();
1.1 albertel 4287: }
1.10 albertel 4288: }
4289:
1.581 albertel 4290: sub format_previous_attempt_value {
4291: my ($key,$value) = @_;
1.1011 www 4292: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 4293: $value = &Apache::lonlocal::locallocaltime($value);
4294: } elsif (ref($value) eq 'ARRAY') {
4295: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 4296: } elsif ($key =~ /answerstring$/) {
4297: my %answers = &Apache::lonnet::str2hash($value);
4298: my @anskeys = sort(keys(%answers));
4299: if (@anskeys == 1) {
4300: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4301: if ($answer =~ m{\0}) {
4302: $answer =~ s{\0}{,}g;
1.988 raeburn 4303: }
4304: my $tag_internal_answer_name = 'INTERNAL';
4305: if ($anskeys[0] eq $tag_internal_answer_name) {
4306: $value = $answer;
4307: } else {
4308: $value = $anskeys[0].'='.$answer;
4309: }
4310: } else {
4311: foreach my $ans (@anskeys) {
4312: my $answer = $answers{$ans};
1.1001 raeburn 4313: if ($answer =~ m{\0}) {
4314: $answer =~ s{\0}{,}g;
1.988 raeburn 4315: }
4316: $value .= $ans.'='.$answer.'<br />';;
4317: }
4318: }
1.581 albertel 4319: } else {
4320: $value = &unescape($value);
4321: }
4322: return $value;
4323: }
4324:
4325:
1.107 albertel 4326: sub relative_to_absolute {
4327: my ($url,$output)=@_;
4328: my $parser=HTML::TokeParser->new(\$output);
4329: my $token;
4330: my $thisdir=$url;
4331: my @rlinks=();
4332: while ($token=$parser->get_token) {
4333: if ($token->[0] eq 'S') {
4334: if ($token->[1] eq 'a') {
4335: if ($token->[2]->{'href'}) {
4336: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4337: }
4338: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4339: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4340: } elsif ($token->[1] eq 'base') {
4341: $thisdir=$token->[2]->{'href'};
4342: }
4343: }
4344: }
4345: $thisdir=~s-/[^/]*$--;
1.356 albertel 4346: foreach my $link (@rlinks) {
1.726 raeburn 4347: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4348: ($link=~/^\//) ||
4349: ($link=~/^javascript:/i) ||
4350: ($link=~/^mailto:/i) ||
4351: ($link=~/^\#/)) {
4352: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4353: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4354: }
4355: }
4356: # -------------------------------------------------- Deal with Applet codebases
4357: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4358: return $output;
4359: }
4360:
1.112 bowersj2 4361: =pod
4362:
1.648 raeburn 4363: =item * &get_student_view()
1.112 bowersj2 4364:
4365: show a snapshot of what student was looking at
4366:
4367: =cut
4368:
1.10 albertel 4369: sub get_student_view {
1.186 albertel 4370: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4371: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4372: my (%form);
1.10 albertel 4373: my @elements=('symb','courseid','domain','username');
4374: foreach my $element (@elements) {
1.186 albertel 4375: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4376: }
1.186 albertel 4377: if (defined($moreenv)) {
4378: %form=(%form,%{$moreenv});
4379: }
1.236 albertel 4380: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4381: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4382: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4383: $userview=~s/\<body[^\>]*\>//gi;
4384: $userview=~s/\<\/body\>//gi;
4385: $userview=~s/\<html\>//gi;
4386: $userview=~s/\<\/html\>//gi;
4387: $userview=~s/\<head\>//gi;
4388: $userview=~s/\<\/head\>//gi;
4389: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4390: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4391: if (wantarray) {
4392: return ($userview,$response);
4393: } else {
4394: return $userview;
4395: }
4396: }
4397:
4398: sub get_student_view_with_retries {
4399: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4400:
4401: my $ok = 0; # True if we got a good response.
4402: my $content;
4403: my $response;
4404:
4405: # Try to get the student_view done. within the retries count:
4406:
4407: do {
4408: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4409: $ok = $response->is_success;
4410: if (!$ok) {
4411: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4412: }
4413: $retries--;
4414: } while (!$ok && ($retries > 0));
4415:
4416: if (!$ok) {
4417: $content = ''; # On error return an empty content.
4418: }
1.651 www 4419: if (wantarray) {
4420: return ($content, $response);
4421: } else {
4422: return $content;
4423: }
1.11 albertel 4424: }
4425:
1.112 bowersj2 4426: =pod
4427:
1.648 raeburn 4428: =item * &get_student_answers()
1.112 bowersj2 4429:
4430: show a snapshot of how student was answering problem
4431:
4432: =cut
4433:
1.11 albertel 4434: sub get_student_answers {
1.100 sakharuk 4435: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4436: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4437: my (%moreenv);
1.11 albertel 4438: my @elements=('symb','courseid','domain','username');
4439: foreach my $element (@elements) {
1.186 albertel 4440: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4441: }
1.186 albertel 4442: $moreenv{'grade_target'}='answer';
4443: %moreenv=(%form,%moreenv);
1.497 raeburn 4444: $feedurl = &Apache::lonnet::clutter($feedurl);
4445: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4446: return $userview;
1.1 albertel 4447: }
1.116 albertel 4448:
4449: =pod
4450:
4451: =item * &submlink()
4452:
1.242 albertel 4453: Inputs: $text $uname $udom $symb $target
1.116 albertel 4454:
4455: Returns: A link to grades.pm such as to see the SUBM view of a student
4456:
4457: =cut
4458:
4459: ###############################################
4460: sub submlink {
1.242 albertel 4461: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4462: if (!($uname && $udom)) {
4463: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4464: &Apache::lonnet::whichuser($symb);
1.116 albertel 4465: if (!$symb) { $symb=$cursymb; }
4466: }
1.254 matthew 4467: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4468: $symb=&escape($symb);
1.960 bisitz 4469: if ($target) { $target=" target=\"$target\""; }
4470: return
4471: '<a href="/adm/grades?command=submission'.
4472: '&symb='.$symb.
4473: '&student='.$uname.
4474: '&userdom='.$udom.'"'.
4475: $target.'>'.$text.'</a>';
1.242 albertel 4476: }
4477: ##############################################
4478:
4479: =pod
4480:
4481: =item * &pgrdlink()
4482:
4483: Inputs: $text $uname $udom $symb $target
4484:
4485: Returns: A link to grades.pm such as to see the PGRD view of a student
4486:
4487: =cut
4488:
4489: ###############################################
4490: sub pgrdlink {
4491: my $link=&submlink(@_);
4492: $link=~s/(&command=submission)/$1&showgrading=yes/;
4493: return $link;
4494: }
4495: ##############################################
4496:
4497: =pod
4498:
4499: =item * &pprmlink()
4500:
4501: Inputs: $text $uname $udom $symb $target
4502:
4503: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4504: student and a specific resource
1.242 albertel 4505:
4506: =cut
4507:
4508: ###############################################
4509: sub pprmlink {
4510: my ($text,$uname,$udom,$symb,$target)=@_;
4511: if (!($uname && $udom)) {
4512: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4513: &Apache::lonnet::whichuser($symb);
1.242 albertel 4514: if (!$symb) { $symb=$cursymb; }
4515: }
1.254 matthew 4516: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4517: $symb=&escape($symb);
1.242 albertel 4518: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4519: return '<a href="/adm/parmset?command=set&'.
4520: 'symb='.$symb.'&uname='.$uname.
4521: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4522: }
4523: ##############################################
1.37 matthew 4524:
1.112 bowersj2 4525: =pod
4526:
4527: =back
4528:
4529: =cut
4530:
1.37 matthew 4531: ###############################################
1.51 www 4532:
4533:
4534: sub timehash {
1.687 raeburn 4535: my ($thistime) = @_;
4536: my $timezone = &Apache::lonlocal::gettimezone();
4537: my $dt = DateTime->from_epoch(epoch => $thistime)
4538: ->set_time_zone($timezone);
4539: my $wday = $dt->day_of_week();
4540: if ($wday == 7) { $wday = 0; }
4541: return ( 'second' => $dt->second(),
4542: 'minute' => $dt->minute(),
4543: 'hour' => $dt->hour(),
4544: 'day' => $dt->day_of_month(),
4545: 'month' => $dt->month(),
4546: 'year' => $dt->year(),
4547: 'weekday' => $wday,
4548: 'dayyear' => $dt->day_of_year(),
4549: 'dlsav' => $dt->is_dst() );
1.51 www 4550: }
4551:
1.370 www 4552: sub utc_string {
4553: my ($date)=@_;
1.371 www 4554: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4555: }
4556:
1.51 www 4557: sub maketime {
4558: my %th=@_;
1.687 raeburn 4559: my ($epoch_time,$timezone,$dt);
4560: $timezone = &Apache::lonlocal::gettimezone();
4561: eval {
4562: $dt = DateTime->new( year => $th{'year'},
4563: month => $th{'month'},
4564: day => $th{'day'},
4565: hour => $th{'hour'},
4566: minute => $th{'minute'},
4567: second => $th{'second'},
4568: time_zone => $timezone,
4569: );
4570: };
4571: if (!$@) {
4572: $epoch_time = $dt->epoch;
4573: if ($epoch_time) {
4574: return $epoch_time;
4575: }
4576: }
1.51 www 4577: return POSIX::mktime(
4578: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4579: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4580: }
4581:
4582: #########################################
1.51 www 4583:
4584: sub findallcourses {
1.482 raeburn 4585: my ($roles,$uname,$udom) = @_;
1.355 albertel 4586: my %roles;
4587: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4588: my %courses;
1.51 www 4589: my $now=time;
1.482 raeburn 4590: if (!defined($uname)) {
4591: $uname = $env{'user.name'};
4592: }
4593: if (!defined($udom)) {
4594: $udom = $env{'user.domain'};
4595: }
4596: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4597: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4598: if (!%roles) {
4599: %roles = (
4600: cc => 1,
1.907 raeburn 4601: co => 1,
1.482 raeburn 4602: in => 1,
4603: ep => 1,
4604: ta => 1,
4605: cr => 1,
4606: st => 1,
4607: );
4608: }
4609: foreach my $entry (keys(%roleshash)) {
4610: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4611: if ($trole =~ /^cr/) {
4612: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4613: } else {
4614: next if (!exists($roles{$trole}));
4615: }
4616: if ($tend) {
4617: next if ($tend < $now);
4618: }
4619: if ($tstart) {
4620: next if ($tstart > $now);
4621: }
1.1058 raeburn 4622: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4623: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4624: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4625: if ($secpart eq '') {
4626: ($cnum,$role) = split(/_/,$cnumpart);
4627: $sec = 'none';
1.1058 raeburn 4628: $value .= $cnum.'/';
1.482 raeburn 4629: } else {
4630: $cnum = $cnumpart;
4631: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4632: $value .= $cnum.'/'.$sec;
4633: }
4634: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4635: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4636: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4637: }
4638: } else {
4639: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4640: }
1.482 raeburn 4641: }
4642: } else {
4643: foreach my $key (keys(%env)) {
1.483 albertel 4644: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4645: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4646: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4647: next if ($role eq 'ca' || $role eq 'aa');
4648: next if (%roles && !exists($roles{$role}));
4649: my ($starttime,$endtime)=split(/\./,$env{$key});
4650: my $active=1;
4651: if ($starttime) {
4652: if ($now<$starttime) { $active=0; }
4653: }
4654: if ($endtime) {
4655: if ($now>$endtime) { $active=0; }
4656: }
4657: if ($active) {
1.1058 raeburn 4658: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4659: if ($sec eq '') {
4660: $sec = 'none';
1.1058 raeburn 4661: } else {
4662: $value .= $sec;
4663: }
4664: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4665: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4666: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4667: }
4668: } else {
4669: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4670: }
1.474 raeburn 4671: }
4672: }
1.51 www 4673: }
4674: }
1.474 raeburn 4675: return %courses;
1.51 www 4676: }
1.37 matthew 4677:
1.54 www 4678: ###############################################
1.474 raeburn 4679:
4680: sub blockcheck {
1.1075.2.147 raeburn 4681: my ($setters,$activity,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.490 raeburn 4682:
1.1075.2.73 raeburn 4683: if (defined($udom) && defined($uname)) {
4684: # If uname and udom are for a course, check for blocks in the course.
4685: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4686: my ($startblock,$endblock,$triggerblock) =
1.1075.2.147 raeburn 4687: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1075.2.73 raeburn 4688: return ($startblock,$endblock,$triggerblock);
4689: }
4690: } else {
1.490 raeburn 4691: $udom = $env{'user.domain'};
4692: $uname = $env{'user.name'};
4693: }
4694:
1.502 raeburn 4695: my $startblock = 0;
4696: my $endblock = 0;
1.1062 raeburn 4697: my $triggerblock = '';
1.482 raeburn 4698: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4699:
1.490 raeburn 4700: # If uname is for a user, and activity is course-specific, i.e.,
4701: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4702:
1.490 raeburn 4703: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.73 raeburn 4704: $activity eq 'groups' || $activity eq 'printout') &&
4705: ($env{'request.course.id'})) {
1.490 raeburn 4706: foreach my $key (keys(%live_courses)) {
4707: if ($key ne $env{'request.course.id'}) {
4708: delete($live_courses{$key});
4709: }
4710: }
4711: }
4712:
4713: my $otheruser = 0;
4714: my %own_courses;
4715: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4716: # Resource belongs to user other than current user.
4717: $otheruser = 1;
4718: # Gather courses for current user
4719: %own_courses =
4720: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4721: }
4722:
4723: # Gather active course roles - course coordinator, instructor,
4724: # exam proctor, ta, student, or custom role.
1.474 raeburn 4725:
4726: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4727: my ($cdom,$cnum);
4728: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4729: $cdom = $env{'course.'.$course.'.domain'};
4730: $cnum = $env{'course.'.$course.'.num'};
4731: } else {
1.490 raeburn 4732: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4733: }
4734: my $no_ownblock = 0;
4735: my $no_userblock = 0;
1.533 raeburn 4736: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4737: # Check if current user has 'evb' priv for this
4738: if (defined($own_courses{$course})) {
4739: foreach my $sec (keys(%{$own_courses{$course}})) {
4740: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4741: if ($sec ne 'none') {
4742: $checkrole .= '/'.$sec;
4743: }
4744: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4745: $no_ownblock = 1;
4746: last;
4747: }
4748: }
4749: }
4750: # if they have 'evb' priv and are currently not playing student
4751: next if (($no_ownblock) &&
4752: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4753: }
1.474 raeburn 4754: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4755: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4756: if ($sec ne 'none') {
1.482 raeburn 4757: $checkrole .= '/'.$sec;
1.474 raeburn 4758: }
1.490 raeburn 4759: if ($otheruser) {
4760: # Resource belongs to user other than current user.
4761: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4762: my (%allroles,%userroles);
4763: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4764: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4765: my ($trole,$tdom,$tnum,$tsec);
4766: if ($entry =~ /^cr/) {
4767: ($trole,$tdom,$tnum,$tsec) =
4768: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4769: } else {
4770: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4771: }
4772: my ($spec,$area,$trest);
4773: $area = '/'.$tdom.'/'.$tnum;
4774: $trest = $tnum;
4775: if ($tsec ne '') {
4776: $area .= '/'.$tsec;
4777: $trest .= '/'.$tsec;
4778: }
4779: $spec = $trole.'.'.$area;
4780: if ($trole =~ /^cr/) {
4781: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4782: $tdom,$spec,$trest,$area);
4783: } else {
4784: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4785: $tdom,$spec,$trest,$area);
4786: }
4787: }
1.1075.2.124 raeburn 4788: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 4789: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4790: if ($1) {
4791: $no_userblock = 1;
4792: last;
4793: }
1.486 raeburn 4794: }
4795: }
1.490 raeburn 4796: } else {
4797: # Resource belongs to current user
4798: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4799: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4800: $no_ownblock = 1;
4801: last;
4802: }
1.474 raeburn 4803: }
4804: }
4805: # if they have the evb priv and are currently not playing student
1.482 raeburn 4806: next if (($no_ownblock) &&
1.491 albertel 4807: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4808: next if ($no_userblock);
1.474 raeburn 4809:
1.1075.2.128 raeburn 4810: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 4811: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4812:
1.1062 raeburn 4813: my ($start,$end,$trigger) =
1.1075.2.147 raeburn 4814: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 4815: if (($start != 0) &&
4816: (($startblock == 0) || ($startblock > $start))) {
4817: $startblock = $start;
1.1062 raeburn 4818: if ($trigger ne '') {
4819: $triggerblock = $trigger;
4820: }
1.502 raeburn 4821: }
4822: if (($end != 0) &&
4823: (($endblock == 0) || ($endblock < $end))) {
4824: $endblock = $end;
1.1062 raeburn 4825: if ($trigger ne '') {
4826: $triggerblock = $trigger;
4827: }
1.502 raeburn 4828: }
1.490 raeburn 4829: }
1.1062 raeburn 4830: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4831: }
4832:
4833: sub get_blocks {
1.1075.2.147 raeburn 4834: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 4835: my $startblock = 0;
4836: my $endblock = 0;
1.1062 raeburn 4837: my $triggerblock = '';
1.490 raeburn 4838: my $course = $cdom.'_'.$cnum;
4839: $setters->{$course} = {};
4840: $setters->{$course}{'staff'} = [];
4841: $setters->{$course}{'times'} = [];
1.1062 raeburn 4842: $setters->{$course}{'triggers'} = [];
4843: my (@blockers,%triggered);
4844: my $now = time;
4845: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4846: if ($activity eq 'docs') {
1.1075.2.148! raeburn 4847: my ($blocked,$nosymbcache,$noenccheck);
1.1075.2.147 raeburn 4848: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
4849: $blocked = 1;
4850: $nosymbcache = 1;
1.1075.2.148! raeburn 4851: $noenccheck = 1;
1.1075.2.147 raeburn 4852: }
1.1075.2.148! raeburn 4853: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 4854: foreach my $block (@blockers) {
4855: if ($block =~ /^firstaccess____(.+)$/) {
4856: my $item = $1;
4857: my $type = 'map';
4858: my $timersymb = $item;
4859: if ($item eq 'course') {
4860: $type = 'course';
4861: } elsif ($item =~ /___\d+___/) {
4862: $type = 'resource';
4863: } else {
4864: $timersymb = &Apache::lonnet::symbread($item);
4865: }
4866: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4867: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4868: $triggered{$block} = {
4869: start => $start,
4870: end => $end,
4871: type => $type,
4872: };
4873: }
4874: }
4875: } else {
4876: foreach my $block (keys(%commblocks)) {
4877: if ($block =~ m/^(\d+)____(\d+)$/) {
4878: my ($start,$end) = ($1,$2);
4879: if ($start <= time && $end >= time) {
4880: if (ref($commblocks{$block}) eq 'HASH') {
4881: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4882: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4883: unless(grep(/^\Q$block\E$/,@blockers)) {
4884: push(@blockers,$block);
4885: }
4886: }
4887: }
4888: }
4889: }
4890: } elsif ($block =~ /^firstaccess____(.+)$/) {
4891: my $item = $1;
4892: my $timersymb = $item;
4893: my $type = 'map';
4894: if ($item eq 'course') {
4895: $type = 'course';
4896: } elsif ($item =~ /___\d+___/) {
4897: $type = 'resource';
4898: } else {
4899: $timersymb = &Apache::lonnet::symbread($item);
4900: }
4901: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4902: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4903: if ($start && $end) {
4904: if (($start <= time) && ($end >= time)) {
4905: unless (grep(/^\Q$block\E$/,@blockers)) {
4906: push(@blockers,$block);
4907: $triggered{$block} = {
4908: start => $start,
4909: end => $end,
4910: type => $type,
4911: };
4912: }
4913: }
1.490 raeburn 4914: }
1.1062 raeburn 4915: }
4916: }
4917: }
4918: foreach my $blocker (@blockers) {
4919: my ($staff_name,$staff_dom,$title,$blocks) =
4920: &parse_block_record($commblocks{$blocker});
4921: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4922: my ($start,$end,$triggertype);
4923: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4924: ($start,$end) = ($1,$2);
4925: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4926: $start = $triggered{$blocker}{'start'};
4927: $end = $triggered{$blocker}{'end'};
4928: $triggertype = $triggered{$blocker}{'type'};
4929: }
4930: if ($start) {
4931: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4932: if ($triggertype) {
4933: push(@{$$setters{$course}{'triggers'}},$triggertype);
4934: } else {
4935: push(@{$$setters{$course}{'triggers'}},0);
4936: }
4937: if ( ($startblock == 0) || ($startblock > $start) ) {
4938: $startblock = $start;
4939: if ($triggertype) {
4940: $triggerblock = $blocker;
1.474 raeburn 4941: }
4942: }
1.1062 raeburn 4943: if ( ($endblock == 0) || ($endblock < $end) ) {
4944: $endblock = $end;
4945: if ($triggertype) {
4946: $triggerblock = $blocker;
4947: }
4948: }
1.474 raeburn 4949: }
4950: }
1.1062 raeburn 4951: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4952: }
4953:
4954: sub parse_block_record {
4955: my ($record) = @_;
4956: my ($setuname,$setudom,$title,$blocks);
4957: if (ref($record) eq 'HASH') {
4958: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4959: $title = &unescape($record->{'event'});
4960: $blocks = $record->{'blocks'};
4961: } else {
4962: my @data = split(/:/,$record,3);
4963: if (scalar(@data) eq 2) {
4964: $title = $data[1];
4965: ($setuname,$setudom) = split(/@/,$data[0]);
4966: } else {
4967: ($setuname,$setudom,$title) = @data;
4968: }
4969: $blocks = { 'com' => 'on' };
4970: }
4971: return ($setuname,$setudom,$title,$blocks);
4972: }
4973:
1.854 kalberla 4974: sub blocking_status {
1.1075.2.147 raeburn 4975: my ($activity,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 4976: my %setters;
1.890 droeschl 4977:
1.1061 raeburn 4978: # check for active blocking
1.1062 raeburn 4979: my ($startblock,$endblock,$triggerblock) =
1.1075.2.147 raeburn 4980: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 4981: my $blocked = 0;
4982: if ($startblock && $endblock) {
4983: $blocked = 1;
4984: }
1.890 droeschl 4985:
1.1061 raeburn 4986: # caller just wants to know whether a block is active
4987: if (!wantarray) { return $blocked; }
4988:
4989: # build a link to a popup window containing the details
4990: my $querystring = "?activity=$activity";
4991: # $uname and $udom decide whose portfolio the user is trying to look at
1.1075.2.97 raeburn 4992: if (($activity eq 'port') || ($activity eq 'passwd')) {
4993: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
4994: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 4995: } elsif ($activity eq 'docs') {
1.1075.2.147 raeburn 4996: my $showurl = &Apache::lonenc::check_encrypt($url);
4997: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
4998: if ($symb) {
4999: my $showsymb = &Apache::lonenc::check_encrypt($symb);
5000: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
5001: }
1.1062 raeburn 5002: }
1.1061 raeburn 5003:
5004: my $output .= <<'END_MYBLOCK';
5005: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5006: var options = "width=" + w + ",height=" + h + ",";
5007: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5008: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5009: var newWin = window.open(url, wdwName, options);
5010: newWin.focus();
5011: }
1.890 droeschl 5012: END_MYBLOCK
1.854 kalberla 5013:
1.1061 raeburn 5014: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5015:
1.1061 raeburn 5016: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5017: my $text = &mt('Communication Blocked');
1.1075.2.93 raeburn 5018: my $class = 'LC_comblock';
1.1062 raeburn 5019: if ($activity eq 'docs') {
5020: $text = &mt('Content Access Blocked');
1.1075.2.93 raeburn 5021: $class = '';
1.1063 raeburn 5022: } elsif ($activity eq 'printout') {
5023: $text = &mt('Printing Blocked');
1.1075.2.97 raeburn 5024: } elsif ($activity eq 'passwd') {
5025: $text = &mt('Password Changing Blocked');
1.1062 raeburn 5026: }
1.1061 raeburn 5027: $output .= <<"END_BLOCK";
1.1075.2.93 raeburn 5028: <div class='$class'>
1.869 kalberla 5029: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5030: title='$text'>
5031: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5032: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5033: title='$text'>$text</a>
1.867 kalberla 5034: </div>
5035:
5036: END_BLOCK
1.474 raeburn 5037:
1.1061 raeburn 5038: return ($blocked, $output);
1.854 kalberla 5039: }
1.490 raeburn 5040:
1.60 matthew 5041: ###############################################
5042:
1.682 raeburn 5043: sub check_ip_acc {
1.1075.2.105 raeburn 5044: my ($acc,$clientip)=@_;
1.682 raeburn 5045: &Apache::lonxml::debug("acc is $acc");
5046: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5047: return 1;
5048: }
5049: my $allowed=0;
1.1075.2.144 raeburn 5050: my $ip;
5051: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5052: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5053: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5054: } else {
5055: $ip = $ENV{'REMOTE_ADDR'} || $env{'request.host'} || $clientip;
5056: }
1.682 raeburn 5057:
5058: my $name;
5059: foreach my $pattern (split(',',$acc)) {
5060: $pattern =~ s/^\s*//;
5061: $pattern =~ s/\s*$//;
5062: if ($pattern =~ /\*$/) {
5063: #35.8.*
5064: $pattern=~s/\*//;
5065: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
5066: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5067: #35.8.3.[34-56]
5068: my $low=$2;
5069: my $high=$3;
5070: $pattern=$1;
5071: if ($ip =~ /^\Q$pattern\E/) {
5072: my $last=(split(/\./,$ip))[3];
5073: if ($last <=$high && $last >=$low) { $allowed=1; }
5074: }
5075: } elsif ($pattern =~ /^\*/) {
5076: #*.msu.edu
5077: $pattern=~s/\*//;
5078: if (!defined($name)) {
5079: use Socket;
5080: my $netaddr=inet_aton($ip);
5081: ($name)=gethostbyaddr($netaddr,AF_INET);
5082: }
5083: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
5084: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5085: #127.0.0.1
5086: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
5087: } else {
5088: #some.name.com
5089: if (!defined($name)) {
5090: use Socket;
5091: my $netaddr=inet_aton($ip);
5092: ($name)=gethostbyaddr($netaddr,AF_INET);
5093: }
5094: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
5095: }
5096: if ($allowed) { last; }
5097: }
5098: return $allowed;
5099: }
5100:
5101: ###############################################
5102:
1.60 matthew 5103: =pod
5104:
1.112 bowersj2 5105: =head1 Domain Template Functions
5106:
5107: =over 4
5108:
5109: =item * &determinedomain()
1.60 matthew 5110:
5111: Inputs: $domain (usually will be undef)
5112:
1.63 www 5113: Returns: Determines which domain should be used for designs
1.60 matthew 5114:
5115: =cut
1.54 www 5116:
1.60 matthew 5117: ###############################################
1.63 www 5118: sub determinedomain {
5119: my $domain=shift;
1.531 albertel 5120: if (! $domain) {
1.60 matthew 5121: # Determine domain if we have not been given one
1.893 raeburn 5122: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5123: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5124: if ($env{'request.role.domain'}) {
5125: $domain=$env{'request.role.domain'};
1.60 matthew 5126: }
5127: }
1.63 www 5128: return $domain;
5129: }
5130: ###############################################
1.517 raeburn 5131:
1.518 albertel 5132: sub devalidate_domconfig_cache {
5133: my ($udom)=@_;
5134: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5135: }
5136:
5137: # ---------------------- Get domain configuration for a domain
5138: sub get_domainconf {
5139: my ($udom) = @_;
5140: my $cachetime=1800;
5141: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5142: if (defined($cached)) { return %{$result}; }
5143:
5144: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5145: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5146: my (%designhash,%legacy);
1.518 albertel 5147: if (keys(%domconfig) > 0) {
5148: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5149: if (keys(%{$domconfig{'login'}})) {
5150: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5151: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 5152: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5153: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5154: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5155: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5156: if ($key eq 'loginvia') {
5157: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5158: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5159: $designhash{$udom.'.login.loginvia'} = $server;
5160: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5161: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5162: } else {
5163: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5164: }
1.948 raeburn 5165: }
1.1075.2.87 raeburn 5166: } elsif ($key eq 'headtag') {
5167: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5168: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5169: }
1.946 raeburn 5170: }
1.1075.2.87 raeburn 5171: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5172: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5173: }
1.946 raeburn 5174: }
5175: }
5176: }
5177: } else {
5178: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5179: $designhash{$udom.'.login.'.$key.'_'.$img} =
5180: $domconfig{'login'}{$key}{$img};
5181: }
1.699 raeburn 5182: }
5183: } else {
5184: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5185: }
1.632 raeburn 5186: }
5187: } else {
5188: $legacy{'login'} = 1;
1.518 albertel 5189: }
1.632 raeburn 5190: } else {
5191: $legacy{'login'} = 1;
1.518 albertel 5192: }
5193: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5194: if (keys(%{$domconfig{'rolecolors'}})) {
5195: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5196: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5197: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5198: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5199: }
1.518 albertel 5200: }
5201: }
1.632 raeburn 5202: } else {
5203: $legacy{'rolecolors'} = 1;
1.518 albertel 5204: }
1.632 raeburn 5205: } else {
5206: $legacy{'rolecolors'} = 1;
1.518 albertel 5207: }
1.948 raeburn 5208: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5209: if ($domconfig{'autoenroll'}{'co-owners'}) {
5210: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5211: }
5212: }
1.632 raeburn 5213: if (keys(%legacy) > 0) {
5214: my %legacyhash = &get_legacy_domconf($udom);
5215: foreach my $item (keys(%legacyhash)) {
5216: if ($item =~ /^\Q$udom\E\.login/) {
5217: if ($legacy{'login'}) {
5218: $designhash{$item} = $legacyhash{$item};
5219: }
5220: } else {
5221: if ($legacy{'rolecolors'}) {
5222: $designhash{$item} = $legacyhash{$item};
5223: }
1.518 albertel 5224: }
5225: }
5226: }
1.632 raeburn 5227: } else {
5228: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5229: }
5230: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5231: $cachetime);
5232: return %designhash;
5233: }
5234:
1.632 raeburn 5235: sub get_legacy_domconf {
5236: my ($udom) = @_;
5237: my %legacyhash;
5238: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5239: my $designfile = $designdir.'/'.$udom.'.tab';
5240: if (-e $designfile) {
1.1075.2.128 raeburn 5241: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5242: while (my $line = <$fh>) {
5243: next if ($line =~ /^\#/);
5244: chomp($line);
5245: my ($key,$val)=(split(/\=/,$line));
5246: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5247: }
5248: close($fh);
5249: }
5250: }
1.1026 raeburn 5251: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5252: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5253: }
5254: return %legacyhash;
5255: }
5256:
1.63 www 5257: =pod
5258:
1.112 bowersj2 5259: =item * &domainlogo()
1.63 www 5260:
5261: Inputs: $domain (usually will be undef)
5262:
5263: Returns: A link to a domain logo, if the domain logo exists.
5264: If the domain logo does not exist, a description of the domain.
5265:
5266: =cut
1.112 bowersj2 5267:
1.63 www 5268: ###############################################
5269: sub domainlogo {
1.517 raeburn 5270: my $domain = &determinedomain(shift);
1.518 albertel 5271: my %designhash = &get_domainconf($domain);
1.517 raeburn 5272: # See if there is a logo
5273: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5274: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5275: if ($imgsrc =~ m{^/(adm|res)/}) {
5276: if ($imgsrc =~ m{^/res/}) {
5277: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5278: &Apache::lonnet::repcopy($local_name);
5279: }
5280: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5281: }
5282: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5283: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5284: return &Apache::lonnet::domain($domain,'description');
1.59 www 5285: } else {
1.60 matthew 5286: return '';
1.59 www 5287: }
5288: }
1.63 www 5289: ##############################################
5290:
5291: =pod
5292:
1.112 bowersj2 5293: =item * &designparm()
1.63 www 5294:
5295: Inputs: $which parameter; $domain (usually will be undef)
5296:
5297: Returns: value of designparamter $which
5298:
5299: =cut
1.112 bowersj2 5300:
1.397 albertel 5301:
1.400 albertel 5302: ##############################################
1.397 albertel 5303: sub designparm {
5304: my ($which,$domain)=@_;
5305: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5306: return $env{'environment.color.'.$which};
1.96 www 5307: }
1.63 www 5308: $domain=&determinedomain($domain);
1.1016 raeburn 5309: my %domdesign;
5310: unless ($domain eq 'public') {
5311: %domdesign = &get_domainconf($domain);
5312: }
1.520 raeburn 5313: my $output;
1.517 raeburn 5314: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5315: $output = $domdesign{$domain.'.'.$which};
1.63 www 5316: } else {
1.520 raeburn 5317: $output = $defaultdesign{$which};
5318: }
5319: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5320: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5321: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5322: if ($output =~ m{^/res/}) {
5323: my $local_name = &Apache::lonnet::filelocation('',$output);
5324: &Apache::lonnet::repcopy($local_name);
5325: }
1.520 raeburn 5326: $output = &lonhttpdurl($output);
5327: }
1.63 www 5328: }
1.520 raeburn 5329: return $output;
1.63 www 5330: }
1.59 www 5331:
1.822 bisitz 5332: ##############################################
5333: =pod
5334:
1.832 bisitz 5335: =item * &authorspace()
5336:
1.1028 raeburn 5337: Inputs: $url (usually will be undef).
1.832 bisitz 5338:
1.1075.2.40 raeburn 5339: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5340: directory being viewed (or for which action is being taken).
5341: If $url is provided, and begins /priv/<domain>/<uname>
5342: the path will be that portion of the $context argument.
5343: Otherwise the path will be for the author space of the current
5344: user when the current role is author, or for that of the
5345: co-author/assistant co-author space when the current role
5346: is co-author or assistant co-author.
1.832 bisitz 5347:
5348: =cut
5349:
5350: sub authorspace {
1.1028 raeburn 5351: my ($url) = @_;
5352: if ($url ne '') {
5353: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5354: return $1;
5355: }
5356: }
1.832 bisitz 5357: my $caname = '';
1.1024 www 5358: my $cadom = '';
1.1028 raeburn 5359: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5360: ($cadom,$caname) =
1.832 bisitz 5361: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5362: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5363: $caname = $env{'user.name'};
1.1024 www 5364: $cadom = $env{'user.domain'};
1.832 bisitz 5365: }
1.1028 raeburn 5366: if (($caname ne '') && ($cadom ne '')) {
5367: return "/priv/$cadom/$caname/";
5368: }
5369: return;
1.832 bisitz 5370: }
5371:
5372: ##############################################
5373: =pod
5374:
1.822 bisitz 5375: =item * &head_subbox()
5376:
5377: Inputs: $content (contains HTML code with page functions, etc.)
5378:
5379: Returns: HTML div with $content
5380: To be included in page header
5381:
5382: =cut
5383:
5384: sub head_subbox {
5385: my ($content)=@_;
5386: my $output =
1.993 raeburn 5387: '<div class="LC_head_subbox">'
1.822 bisitz 5388: .$content
5389: .'</div>'
5390: }
5391:
5392: ##############################################
5393: =pod
5394:
5395: =item * &CSTR_pageheader()
5396:
1.1026 raeburn 5397: Input: (optional) filename from which breadcrumb trail is built.
5398: In most cases no input as needed, as $env{'request.filename'}
5399: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5400:
5401: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5402: To be included on Authoring Space pages
1.822 bisitz 5403:
5404: =cut
5405:
5406: sub CSTR_pageheader {
1.1026 raeburn 5407: my ($trailfile) = @_;
5408: if ($trailfile eq '') {
5409: $trailfile = $env{'request.filename'};
5410: }
5411:
5412: # this is for resources; directories have customtitle, and crumbs
5413: # and select recent are created in lonpubdir.pm
5414:
5415: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5416: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5417: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5418: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5419: $formaction =~ s{/+}{/}g;
1.822 bisitz 5420:
5421: my $parentpath = '';
5422: my $lastitem = '';
5423: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5424: $parentpath = $1;
5425: $lastitem = $2;
5426: } else {
5427: $lastitem = $thisdisfn;
5428: }
1.921 bisitz 5429:
5430: my $output =
1.822 bisitz 5431: '<div>'
5432: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5433: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5434: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5435: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5436: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5437:
5438: if ($lastitem) {
5439: $output .=
5440: '<span class="LC_filename">'
5441: .$lastitem
5442: .'</span>';
5443: }
5444: $output .=
5445: '<br />'
1.822 bisitz 5446: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5447: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5448: .'</form>'
5449: .&Apache::lonmenu::constspaceform()
5450: .'</div>';
1.921 bisitz 5451:
5452: return $output;
1.822 bisitz 5453: }
5454:
1.60 matthew 5455: ###############################################
5456: ###############################################
5457:
5458: =pod
5459:
1.112 bowersj2 5460: =back
5461:
1.549 albertel 5462: =head1 HTML Helpers
1.112 bowersj2 5463:
5464: =over 4
5465:
5466: =item * &bodytag()
1.60 matthew 5467:
5468: Returns a uniform header for LON-CAPA web pages.
5469:
5470: Inputs:
5471:
1.112 bowersj2 5472: =over 4
5473:
5474: =item * $title, A title to be displayed on the page.
5475:
5476: =item * $function, the current role (can be undef).
5477:
5478: =item * $addentries, extra parameters for the <body> tag.
5479:
5480: =item * $bodyonly, if defined, only return the <body> tag.
5481:
5482: =item * $domain, if defined, force a given domain.
5483:
5484: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5485: text interface only)
1.60 matthew 5486:
1.814 bisitz 5487: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5488: navigational links
1.317 albertel 5489:
1.338 albertel 5490: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5491:
1.1075.2.12 raeburn 5492: =item * $no_inline_link, if true and in remote mode, don't show the
5493: 'Switch To Inline Menu' link
5494:
1.460 albertel 5495: =item * $args, optional argument valid values are
5496: no_auto_mt_title -> prevents &mt()ing the title arg
1.1075.2.133 raeburn 5497: use_absolute -> for external resource or syllabus, this will
5498: contain https://<hostname> if server uses
5499: https (as per hosts.tab), but request is for http
5500: hostname -> hostname, from $r->hostname().
1.460 albertel 5501:
1.1075.2.15 raeburn 5502: =item * $advtoolsref, optional argument, ref to an array containing
5503: inlineremote items to be added in "Functions" menu below
5504: breadcrumbs.
5505:
1.112 bowersj2 5506: =back
5507:
1.60 matthew 5508: Returns: A uniform header for LON-CAPA web pages.
5509: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5510: If $bodyonly is undef or zero, an html string containing a <body> tag and
5511: other decorations will be returned.
5512:
5513: =cut
5514:
1.54 www 5515: sub bodytag {
1.831 bisitz 5516: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5517: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5518:
1.954 raeburn 5519: my $public;
5520: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5521: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5522: $public = 1;
5523: }
1.460 albertel 5524: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5525: my $httphost = $args->{'use_absolute'};
1.1075.2.133 raeburn 5526: my $hostname = $args->{'hostname'};
1.339 albertel 5527:
1.183 matthew 5528: $function = &get_users_function() if (!$function);
1.339 albertel 5529: my $img = &designparm($function.'.img',$domain);
5530: my $font = &designparm($function.'.font',$domain);
5531: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5532:
1.803 bisitz 5533: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5534: 'bgcolor' => $pgbg,
1.339 albertel 5535: 'text' => $font,
5536: 'alink' => &designparm($function.'.alink',$domain),
5537: 'vlink' => &designparm($function.'.vlink',$domain),
5538: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5539: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5540:
1.63 www 5541: # role and realm
1.1075.2.68 raeburn 5542: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5543: if ($realm) {
5544: $realm = '/'.$realm;
5545: }
1.378 raeburn 5546: if ($role eq 'ca') {
1.479 albertel 5547: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5548: $realm = &plainname($rname,$rdom);
1.378 raeburn 5549: }
1.55 www 5550: # realm
1.258 albertel 5551: if ($env{'request.course.id'}) {
1.378 raeburn 5552: if ($env{'request.role'} !~ /^cr/) {
5553: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1075.2.115 raeburn 5554: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1075.2.121 raeburn 5555: if ($env{'request.role.desc'}) {
5556: $role = $env{'request.role.desc'};
5557: } else {
5558: $role = &mt('Helpdesk[_1]',' '.$2);
5559: }
1.1075.2.115 raeburn 5560: } else {
5561: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5562: }
1.898 raeburn 5563: if ($env{'request.course.sec'}) {
5564: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5565: }
1.359 albertel 5566: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5567: } else {
5568: $role = &Apache::lonnet::plaintext($role);
1.54 www 5569: }
1.433 albertel 5570:
1.359 albertel 5571: if (!$realm) { $realm=' '; }
1.330 albertel 5572:
1.438 albertel 5573: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5574:
1.101 www 5575: # construct main body tag
1.359 albertel 5576: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 5577: &Apache::lontexconvert::init_math_support();
1.252 albertel 5578:
1.1075.2.38 raeburn 5579: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5580:
5581: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5582: return $bodytag;
1.1075.2.38 raeburn 5583: }
1.359 albertel 5584:
1.954 raeburn 5585: if ($public) {
1.433 albertel 5586: undef($role);
5587: }
1.359 albertel 5588:
1.762 bisitz 5589: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5590: #
5591: # Extra info if you are the DC
5592: my $dc_info = '';
5593: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5594: $env{'course.'.$env{'request.course.id'}.
5595: '.domain'}.'/'})) {
5596: my $cid = $env{'request.course.id'};
1.917 raeburn 5597: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5598: $dc_info =~ s/\s+$//;
1.359 albertel 5599: }
5600:
1.1075.2.108 raeburn 5601: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903 droeschl 5602:
1.1075.2.13 raeburn 5603: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5604:
1.1075.2.38 raeburn 5605:
5606:
1.1075.2.21 raeburn 5607: my $funclist;
5608: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5609: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5610: Apache::lonmenu::serverform();
5611: my $forbodytag;
5612: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5613: $forcereg,$args->{'group'},
5614: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5615: $advtoolsref,'','',\$forbodytag);
1.1075.2.21 raeburn 5616: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5617: $funclist = $forbodytag;
5618: }
5619: } else {
1.903 droeschl 5620:
5621: # if ($env{'request.state'} eq 'construct') {
5622: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5623: # }
5624:
1.1075.2.38 raeburn 5625: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5626: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5627:
1.1075.2.38 raeburn 5628: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5629:
1.916 droeschl 5630: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5631: if ($dc_info) {
5632: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5633: }
1.1075.2.38 raeburn 5634: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5635: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5636: return $bodytag;
5637: }
1.894 droeschl 5638:
1.927 raeburn 5639: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5640: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5641: }
1.916 droeschl 5642:
1.1075.2.38 raeburn 5643: $bodytag .= $right;
1.852 droeschl 5644:
1.917 raeburn 5645: if ($dc_info) {
5646: $dc_info = &dc_courseid_toggle($dc_info);
5647: }
5648: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5649:
1.1075.2.61 raeburn 5650: #if directed to not display the secondary menu, don't.
5651: if ($args->{'no_secondary_menu'}) {
5652: return $bodytag;
5653: }
1.903 droeschl 5654: #don't show menus for public users
1.954 raeburn 5655: if (!$public){
1.1075.2.52 raeburn 5656: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5657: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5658: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5659: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5660: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1075.2.133 raeburn 5661: $args->{'bread_crumbs'},'','',$hostname);
1.1075.2.116 raeburn 5662: } elsif ($forcereg) {
1.1075.2.22 raeburn 5663: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.116 raeburn 5664: $args->{'group'},
1.1075.2.133 raeburn 5665: $args->{'hide_buttons',
5666: $hostname});
1.1075.2.15 raeburn 5667: } else {
1.1075.2.21 raeburn 5668: my $forbodytag;
5669: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5670: $forcereg,$args->{'group'},
5671: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5672: $advtoolsref,'',$hostname,
5673: \$forbodytag);
1.1075.2.21 raeburn 5674: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5675: $bodytag .= $forbodytag;
5676: }
1.920 raeburn 5677: }
1.903 droeschl 5678: }else{
5679: # this is to seperate menu from content when there's no secondary
5680: # menu. Especially needed for public accessible ressources.
5681: $bodytag .= '<hr style="clear:both" />';
5682: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5683: }
1.903 droeschl 5684:
1.235 raeburn 5685: return $bodytag;
1.1075.2.12 raeburn 5686: }
5687:
5688: #
5689: # Top frame rendering, Remote is up
5690: #
5691:
5692: my $imgsrc = $img;
5693: if ($img =~ /^\/adm/) {
5694: $imgsrc = &lonhttpdurl($img);
5695: }
5696: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5697:
1.1075.2.60 raeburn 5698: my $help=($no_inline_link?''
5699: :&Apache::loncommon::top_nav_help('Help'));
5700:
1.1075.2.12 raeburn 5701: # Explicit link to get inline menu
5702: my $menu= ($no_inline_link?''
5703: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5704:
5705: if ($dc_info) {
5706: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5707: }
5708:
1.1075.2.38 raeburn 5709: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5710: unless ($public) {
5711: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5712: undef,'LC_menubuttons_link');
5713: }
5714:
1.1075.2.12 raeburn 5715: unless ($env{'form.inhibitmenu'}) {
5716: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5717: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5718: <li>$help</li>
1.1075.2.12 raeburn 5719: <li>$menu</li>
5720: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5721: }
1.1075.2.13 raeburn 5722: if ($env{'request.state'} eq 'construct') {
5723: if (!$public){
5724: if ($env{'request.state'} eq 'construct') {
5725: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5726: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5727: &Apache::lonhtmlcommon::scripttag('','end').
5728: &Apache::lonmenu::innerregister($forcereg,
5729: $args->{'bread_crumbs'});
5730: }
5731: }
5732: }
1.1075.2.21 raeburn 5733: return $bodytag."\n".$funclist;
1.182 matthew 5734: }
5735:
1.917 raeburn 5736: sub dc_courseid_toggle {
5737: my ($dc_info) = @_;
1.980 raeburn 5738: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5739: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5740: &mt('(More ...)').'</a></span>'.
5741: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5742: }
5743:
1.330 albertel 5744: sub make_attr_string {
5745: my ($register,$attr_ref) = @_;
5746:
5747: if ($attr_ref && !ref($attr_ref)) {
5748: die("addentries Must be a hash ref ".
5749: join(':',caller(1))." ".
5750: join(':',caller(0))." ");
5751: }
5752:
5753: if ($register) {
1.339 albertel 5754: my ($on_load,$on_unload);
5755: foreach my $key (keys(%{$attr_ref})) {
5756: if (lc($key) eq 'onload') {
5757: $on_load.=$attr_ref->{$key}.';';
5758: delete($attr_ref->{$key});
5759:
5760: } elsif (lc($key) eq 'onunload') {
5761: $on_unload.=$attr_ref->{$key}.';';
5762: delete($attr_ref->{$key});
5763: }
5764: }
1.1075.2.12 raeburn 5765: if ($env{'environment.remote'} eq 'on') {
5766: $attr_ref->{'onload'} =
5767: &Apache::lonmenu::loadevents(). $on_load;
5768: $attr_ref->{'onunload'}=
5769: &Apache::lonmenu::unloadevents().$on_unload;
5770: } else {
5771: $attr_ref->{'onload'} = $on_load;
5772: $attr_ref->{'onunload'}= $on_unload;
5773: }
1.330 albertel 5774: }
1.339 albertel 5775:
1.330 albertel 5776: my $attr_string;
1.1075.2.56 raeburn 5777: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5778: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5779: }
5780: return $attr_string;
5781: }
5782:
5783:
1.182 matthew 5784: ###############################################
1.251 albertel 5785: ###############################################
5786:
5787: =pod
5788:
5789: =item * &endbodytag()
5790:
5791: Returns a uniform footer for LON-CAPA web pages.
5792:
1.635 raeburn 5793: Inputs: 1 - optional reference to an args hash
5794: If in the hash, key for noredirectlink has a value which evaluates to true,
5795: a 'Continue' link is not displayed if the page contains an
5796: internal redirect in the <head></head> section,
5797: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5798:
5799: =cut
5800:
5801: sub endbodytag {
1.635 raeburn 5802: my ($args) = @_;
1.1075.2.6 raeburn 5803: my $endbodytag;
5804: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5805: $endbodytag='</body>';
5806: }
1.315 albertel 5807: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5808: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5809: $endbodytag=
5810: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5811: &mt('Continue').'</a>'.
5812: $endbodytag;
5813: }
1.315 albertel 5814: }
1.251 albertel 5815: return $endbodytag;
5816: }
5817:
1.352 albertel 5818: =pod
5819:
5820: =item * &standard_css()
5821:
5822: Returns a style sheet
5823:
5824: Inputs: (all optional)
5825: domain -> force to color decorate a page for a specific
5826: domain
5827: function -> force usage of a specific rolish color scheme
5828: bgcolor -> override the default page bgcolor
5829:
5830: =cut
5831:
1.343 albertel 5832: sub standard_css {
1.345 albertel 5833: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5834: $function = &get_users_function() if (!$function);
5835: my $img = &designparm($function.'.img', $domain);
5836: my $tabbg = &designparm($function.'.tabbg', $domain);
5837: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5838: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5839: #second colour for later usage
1.345 albertel 5840: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5841: my $pgbg_or_bgcolor =
5842: $bgcolor ||
1.352 albertel 5843: &designparm($function.'.pgbg', $domain);
1.382 albertel 5844: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5845: my $alink = &designparm($function.'.alink', $domain);
5846: my $vlink = &designparm($function.'.vlink', $domain);
5847: my $link = &designparm($function.'.link', $domain);
5848:
1.602 albertel 5849: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5850: my $mono = 'monospace';
1.850 bisitz 5851: my $data_table_head = $sidebg;
5852: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5853: my $data_table_dark = '#E0E0E0';
1.470 banghart 5854: my $data_table_darker = '#CCCCCC';
1.349 albertel 5855: my $data_table_highlight = '#FFFF00';
1.352 albertel 5856: my $mail_new = '#FFBB77';
5857: my $mail_new_hover = '#DD9955';
5858: my $mail_read = '#BBBB77';
5859: my $mail_read_hover = '#999944';
5860: my $mail_replied = '#AAAA88';
5861: my $mail_replied_hover = '#888855';
5862: my $mail_other = '#99BBBB';
5863: my $mail_other_hover = '#669999';
1.391 albertel 5864: my $table_header = '#DDDDDD';
1.489 raeburn 5865: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5866: my $lg_border_color = '#C8C8C8';
1.952 onken 5867: my $button_hover = '#BF2317';
1.392 albertel 5868:
1.608 albertel 5869: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5870: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5871: : '0 3px 0 4px';
1.448 albertel 5872:
1.523 albertel 5873:
1.343 albertel 5874: return <<END;
1.947 droeschl 5875:
5876: /* needed for iframe to allow 100% height in FF */
5877: body, html {
5878: margin: 0;
5879: padding: 0 0.5%;
5880: height: 99%; /* to avoid scrollbars */
5881: }
5882:
1.795 www 5883: body {
1.911 bisitz 5884: font-family: $sans;
5885: line-height:130%;
5886: font-size:0.83em;
5887: color:$font;
1.795 www 5888: }
5889:
1.959 onken 5890: a:focus,
5891: a:focus img {
1.795 www 5892: color: red;
5893: }
1.698 harmsja 5894:
1.911 bisitz 5895: form, .inline {
5896: display: inline;
1.795 www 5897: }
1.721 harmsja 5898:
1.795 www 5899: .LC_right {
1.911 bisitz 5900: text-align:right;
1.795 www 5901: }
5902:
5903: .LC_middle {
1.911 bisitz 5904: vertical-align:middle;
1.795 www 5905: }
1.721 harmsja 5906:
1.1075.2.38 raeburn 5907: .LC_floatleft {
5908: float: left;
5909: }
5910:
5911: .LC_floatright {
5912: float: right;
5913: }
5914:
1.911 bisitz 5915: .LC_400Box {
5916: width:400px;
5917: }
1.721 harmsja 5918:
1.947 droeschl 5919: .LC_iframecontainer {
5920: width: 98%;
5921: margin: 0;
5922: position: fixed;
5923: top: 8.5em;
5924: bottom: 0;
5925: }
5926:
5927: .LC_iframecontainer iframe{
5928: border: none;
5929: width: 100%;
5930: height: 100%;
5931: }
5932:
1.778 bisitz 5933: .LC_filename {
5934: font-family: $mono;
5935: white-space:pre;
1.921 bisitz 5936: font-size: 120%;
1.778 bisitz 5937: }
5938:
5939: .LC_fileicon {
5940: border: none;
5941: height: 1.3em;
5942: vertical-align: text-bottom;
5943: margin-right: 0.3em;
5944: text-decoration:none;
5945: }
5946:
1.1008 www 5947: .LC_setting {
5948: text-decoration:underline;
5949: }
5950:
1.350 albertel 5951: .LC_error {
5952: color: red;
5953: }
1.795 www 5954:
1.1075.2.15 raeburn 5955: .LC_warning {
5956: color: darkorange;
5957: }
5958:
1.457 albertel 5959: .LC_diff_removed {
1.733 bisitz 5960: color: red;
1.394 albertel 5961: }
1.532 albertel 5962:
5963: .LC_info,
1.457 albertel 5964: .LC_success,
5965: .LC_diff_added {
1.350 albertel 5966: color: green;
5967: }
1.795 www 5968:
1.802 bisitz 5969: div.LC_confirm_box {
5970: background-color: #FAFAFA;
5971: border: 1px solid $lg_border_color;
5972: margin-right: 0;
5973: padding: 5px;
5974: }
5975:
5976: div.LC_confirm_box .LC_error img,
5977: div.LC_confirm_box .LC_success img {
5978: vertical-align: middle;
5979: }
5980:
1.1075.2.108 raeburn 5981: .LC_maxwidth {
5982: max-width: 100%;
5983: height: auto;
5984: }
5985:
5986: .LC_textsize_mobile {
5987: \@media only screen and (max-device-width: 480px) {
5988: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
5989: }
5990: }
5991:
1.440 albertel 5992: .LC_icon {
1.771 droeschl 5993: border: none;
1.790 droeschl 5994: vertical-align: middle;
1.771 droeschl 5995: }
5996:
1.543 albertel 5997: .LC_docs_spacer {
5998: width: 25px;
5999: height: 1px;
1.771 droeschl 6000: border: none;
1.543 albertel 6001: }
1.346 albertel 6002:
1.532 albertel 6003: .LC_internal_info {
1.735 bisitz 6004: color: #999999;
1.532 albertel 6005: }
6006:
1.794 www 6007: .LC_discussion {
1.1050 www 6008: background: $data_table_dark;
1.911 bisitz 6009: border: 1px solid black;
6010: margin: 2px;
1.794 www 6011: }
6012:
6013: .LC_disc_action_left {
1.1050 www 6014: background: $sidebg;
1.911 bisitz 6015: text-align: left;
1.1050 www 6016: padding: 4px;
6017: margin: 2px;
1.794 www 6018: }
6019:
6020: .LC_disc_action_right {
1.1050 www 6021: background: $sidebg;
1.911 bisitz 6022: text-align: right;
1.1050 www 6023: padding: 4px;
6024: margin: 2px;
1.794 www 6025: }
6026:
6027: .LC_disc_new_item {
1.911 bisitz 6028: background: white;
6029: border: 2px solid red;
1.1050 www 6030: margin: 4px;
6031: padding: 4px;
1.794 www 6032: }
6033:
6034: .LC_disc_old_item {
1.911 bisitz 6035: background: white;
1.1050 www 6036: margin: 4px;
6037: padding: 4px;
1.794 www 6038: }
6039:
1.458 albertel 6040: table.LC_pastsubmission {
6041: border: 1px solid black;
6042: margin: 2px;
6043: }
6044:
1.924 bisitz 6045: table#LC_menubuttons {
1.345 albertel 6046: width: 100%;
6047: background: $pgbg;
1.392 albertel 6048: border: 2px;
1.402 albertel 6049: border-collapse: separate;
1.803 bisitz 6050: padding: 0;
1.345 albertel 6051: }
1.392 albertel 6052:
1.801 tempelho 6053: table#LC_title_bar a {
6054: color: $fontmenu;
6055: }
1.836 bisitz 6056:
1.807 droeschl 6057: table#LC_title_bar {
1.819 tempelho 6058: clear: both;
1.836 bisitz 6059: display: none;
1.807 droeschl 6060: }
6061:
1.795 www 6062: table#LC_title_bar,
1.933 droeschl 6063: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6064: table#LC_title_bar.LC_with_remote {
1.359 albertel 6065: width: 100%;
1.392 albertel 6066: border-color: $pgbg;
6067: border-style: solid;
6068: border-width: $border;
1.379 albertel 6069: background: $pgbg;
1.801 tempelho 6070: color: $fontmenu;
1.392 albertel 6071: border-collapse: collapse;
1.803 bisitz 6072: padding: 0;
1.819 tempelho 6073: margin: 0;
1.359 albertel 6074: }
1.795 www 6075:
1.933 droeschl 6076: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6077: margin: 0;
6078: padding: 0;
1.933 droeschl 6079: position: relative;
6080: list-style: none;
1.913 droeschl 6081: }
1.933 droeschl 6082: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6083: display: inline;
6084: }
1.933 droeschl 6085:
6086: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6087: padding: 0;
1.933 droeschl 6088: margin: 0;
6089: float: left;
1.913 droeschl 6090: }
1.933 droeschl 6091: .LC_breadcrumb_tools_tools {
6092: padding: 0;
6093: margin: 0;
1.913 droeschl 6094: float: right;
6095: }
6096:
1.359 albertel 6097: table#LC_title_bar td {
6098: background: $tabbg;
6099: }
1.795 www 6100:
1.911 bisitz 6101: table#LC_menubuttons img {
1.803 bisitz 6102: border: none;
1.346 albertel 6103: }
1.795 www 6104:
1.842 droeschl 6105: .LC_breadcrumbs_component {
1.911 bisitz 6106: float: right;
6107: margin: 0 1em;
1.357 albertel 6108: }
1.842 droeschl 6109: .LC_breadcrumbs_component img {
1.911 bisitz 6110: vertical-align: middle;
1.777 tempelho 6111: }
1.795 www 6112:
1.1075.2.108 raeburn 6113: .LC_breadcrumbs_hoverable {
6114: background: $sidebg;
6115: }
6116:
1.383 albertel 6117: td.LC_table_cell_checkbox {
6118: text-align: center;
6119: }
1.795 www 6120:
6121: .LC_fontsize_small {
1.911 bisitz 6122: font-size: 70%;
1.705 tempelho 6123: }
6124:
1.844 bisitz 6125: #LC_breadcrumbs {
1.911 bisitz 6126: clear:both;
6127: background: $sidebg;
6128: border-bottom: 1px solid $lg_border_color;
6129: line-height: 2.5em;
1.933 droeschl 6130: overflow: hidden;
1.911 bisitz 6131: margin: 0;
6132: padding: 0;
1.995 raeburn 6133: text-align: left;
1.819 tempelho 6134: }
1.862 bisitz 6135:
1.1075.2.16 raeburn 6136: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6137: clear:both;
6138: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6139: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6140: margin: 0 0 10px 0;
1.966 bisitz 6141: padding: 3px;
1.995 raeburn 6142: text-align: left;
1.822 bisitz 6143: }
6144:
1.795 www 6145: .LC_fontsize_medium {
1.911 bisitz 6146: font-size: 85%;
1.705 tempelho 6147: }
6148:
1.795 www 6149: .LC_fontsize_large {
1.911 bisitz 6150: font-size: 120%;
1.705 tempelho 6151: }
6152:
1.346 albertel 6153: .LC_menubuttons_inline_text {
6154: color: $font;
1.698 harmsja 6155: font-size: 90%;
1.701 harmsja 6156: padding-left:3px;
1.346 albertel 6157: }
6158:
1.934 droeschl 6159: .LC_menubuttons_inline_text img{
6160: vertical-align: middle;
6161: }
6162:
1.1051 www 6163: li.LC_menubuttons_inline_text img {
1.951 onken 6164: cursor:pointer;
1.1002 droeschl 6165: text-decoration: none;
1.951 onken 6166: }
6167:
1.526 www 6168: .LC_menubuttons_link {
6169: text-decoration: none;
6170: }
1.795 www 6171:
1.522 albertel 6172: .LC_menubuttons_category {
1.521 www 6173: color: $font;
1.526 www 6174: background: $pgbg;
1.521 www 6175: font-size: larger;
6176: font-weight: bold;
6177: }
6178:
1.346 albertel 6179: td.LC_menubuttons_text {
1.911 bisitz 6180: color: $font;
1.346 albertel 6181: }
1.706 harmsja 6182:
1.346 albertel 6183: .LC_current_location {
6184: background: $tabbg;
6185: }
1.795 www 6186:
1.1075.2.134 raeburn 6187: td.LC_zero_height {
6188: line-height: 0;
6189: cellpadding: 0;
6190: }
6191:
1.938 bisitz 6192: table.LC_data_table {
1.347 albertel 6193: border: 1px solid #000000;
1.402 albertel 6194: border-collapse: separate;
1.426 albertel 6195: border-spacing: 1px;
1.610 albertel 6196: background: $pgbg;
1.347 albertel 6197: }
1.795 www 6198:
1.422 albertel 6199: .LC_data_table_dense {
6200: font-size: small;
6201: }
1.795 www 6202:
1.507 raeburn 6203: table.LC_nested_outer {
6204: border: 1px solid #000000;
1.589 raeburn 6205: border-collapse: collapse;
1.803 bisitz 6206: border-spacing: 0;
1.507 raeburn 6207: width: 100%;
6208: }
1.795 www 6209:
1.879 raeburn 6210: table.LC_innerpickbox,
1.507 raeburn 6211: table.LC_nested {
1.803 bisitz 6212: border: none;
1.589 raeburn 6213: border-collapse: collapse;
1.803 bisitz 6214: border-spacing: 0;
1.507 raeburn 6215: width: 100%;
6216: }
1.795 www 6217:
1.911 bisitz 6218: table.LC_data_table tr th,
6219: table.LC_calendar tr th,
1.879 raeburn 6220: table.LC_prior_tries tr th,
6221: table.LC_innerpickbox tr th {
1.349 albertel 6222: font-weight: bold;
6223: background-color: $data_table_head;
1.801 tempelho 6224: color:$fontmenu;
1.701 harmsja 6225: font-size:90%;
1.347 albertel 6226: }
1.795 www 6227:
1.879 raeburn 6228: table.LC_innerpickbox tr th,
6229: table.LC_innerpickbox tr td {
6230: vertical-align: top;
6231: }
6232:
1.711 raeburn 6233: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6234: background-color: #CCCCCC;
1.711 raeburn 6235: font-weight: bold;
6236: text-align: left;
6237: }
1.795 www 6238:
1.912 bisitz 6239: table.LC_data_table tr.LC_odd_row > td {
6240: background-color: $data_table_light;
6241: padding: 2px;
6242: vertical-align: top;
6243: }
6244:
1.809 bisitz 6245: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6246: background-color: $data_table_light;
1.912 bisitz 6247: vertical-align: top;
6248: }
6249:
6250: table.LC_data_table tr.LC_even_row > td {
6251: background-color: $data_table_dark;
1.425 albertel 6252: padding: 2px;
1.900 bisitz 6253: vertical-align: top;
1.347 albertel 6254: }
1.795 www 6255:
1.809 bisitz 6256: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6257: background-color: $data_table_dark;
1.900 bisitz 6258: vertical-align: top;
1.347 albertel 6259: }
1.795 www 6260:
1.425 albertel 6261: table.LC_data_table tr.LC_data_table_highlight td {
6262: background-color: $data_table_darker;
6263: }
1.795 www 6264:
1.639 raeburn 6265: table.LC_data_table tr td.LC_leftcol_header {
6266: background-color: $data_table_head;
6267: font-weight: bold;
6268: }
1.795 www 6269:
1.451 albertel 6270: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6271: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6272: font-weight: bold;
6273: font-style: italic;
6274: text-align: center;
6275: padding: 8px;
1.347 albertel 6276: }
1.795 www 6277:
1.1075.2.30 raeburn 6278: table.LC_data_table tr.LC_empty_row td,
6279: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6280: background-color: $sidebg;
6281: }
6282:
6283: table.LC_nested tr.LC_empty_row td {
6284: background-color: #FFFFFF;
6285: }
6286:
1.890 droeschl 6287: table.LC_caption {
6288: }
6289:
1.507 raeburn 6290: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6291: padding: 4ex
6292: }
1.795 www 6293:
1.507 raeburn 6294: table.LC_nested_outer tr th {
6295: font-weight: bold;
1.801 tempelho 6296: color:$fontmenu;
1.507 raeburn 6297: background-color: $data_table_head;
1.701 harmsja 6298: font-size: small;
1.507 raeburn 6299: border-bottom: 1px solid #000000;
6300: }
1.795 www 6301:
1.507 raeburn 6302: table.LC_nested_outer tr td.LC_subheader {
6303: background-color: $data_table_head;
6304: font-weight: bold;
6305: font-size: small;
6306: border-bottom: 1px solid #000000;
6307: text-align: right;
1.451 albertel 6308: }
1.795 www 6309:
1.507 raeburn 6310: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6311: background-color: #CCCCCC;
1.451 albertel 6312: font-weight: bold;
6313: font-size: small;
1.507 raeburn 6314: text-align: center;
6315: }
1.795 www 6316:
1.589 raeburn 6317: table.LC_nested tr.LC_info_row td.LC_left_item,
6318: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6319: text-align: left;
1.451 albertel 6320: }
1.795 www 6321:
1.507 raeburn 6322: table.LC_nested td {
1.735 bisitz 6323: background-color: #FFFFFF;
1.451 albertel 6324: font-size: small;
1.507 raeburn 6325: }
1.795 www 6326:
1.507 raeburn 6327: table.LC_nested_outer tr th.LC_right_item,
6328: table.LC_nested tr.LC_info_row td.LC_right_item,
6329: table.LC_nested tr.LC_odd_row td.LC_right_item,
6330: table.LC_nested tr td.LC_right_item {
1.451 albertel 6331: text-align: right;
6332: }
6333:
1.507 raeburn 6334: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6335: background-color: #EEEEEE;
1.451 albertel 6336: }
6337:
1.473 raeburn 6338: table.LC_createuser {
6339: }
6340:
6341: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6342: font-size: small;
1.473 raeburn 6343: }
6344:
6345: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6346: background-color: #CCCCCC;
1.473 raeburn 6347: font-weight: bold;
6348: text-align: center;
6349: }
6350:
1.349 albertel 6351: table.LC_calendar {
6352: border: 1px solid #000000;
6353: border-collapse: collapse;
1.917 raeburn 6354: width: 98%;
1.349 albertel 6355: }
1.795 www 6356:
1.349 albertel 6357: table.LC_calendar_pickdate {
6358: font-size: xx-small;
6359: }
1.795 www 6360:
1.349 albertel 6361: table.LC_calendar tr td {
6362: border: 1px solid #000000;
6363: vertical-align: top;
1.917 raeburn 6364: width: 14%;
1.349 albertel 6365: }
1.795 www 6366:
1.349 albertel 6367: table.LC_calendar tr td.LC_calendar_day_empty {
6368: background-color: $data_table_dark;
6369: }
1.795 www 6370:
1.779 bisitz 6371: table.LC_calendar tr td.LC_calendar_day_current {
6372: background-color: $data_table_highlight;
1.777 tempelho 6373: }
1.795 www 6374:
1.938 bisitz 6375: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6376: background-color: $mail_new;
6377: }
1.795 www 6378:
1.938 bisitz 6379: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6380: background-color: $mail_new_hover;
6381: }
1.795 www 6382:
1.938 bisitz 6383: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6384: background-color: $mail_read;
6385: }
1.795 www 6386:
1.938 bisitz 6387: /*
6388: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6389: background-color: $mail_read_hover;
6390: }
1.938 bisitz 6391: */
1.795 www 6392:
1.938 bisitz 6393: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6394: background-color: $mail_replied;
6395: }
1.795 www 6396:
1.938 bisitz 6397: /*
6398: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6399: background-color: $mail_replied_hover;
6400: }
1.938 bisitz 6401: */
1.795 www 6402:
1.938 bisitz 6403: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6404: background-color: $mail_other;
6405: }
1.795 www 6406:
1.938 bisitz 6407: /*
6408: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6409: background-color: $mail_other_hover;
6410: }
1.938 bisitz 6411: */
1.494 raeburn 6412:
1.777 tempelho 6413: table.LC_data_table tr > td.LC_browser_file,
6414: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6415: background: #AAEE77;
1.389 albertel 6416: }
1.795 www 6417:
1.777 tempelho 6418: table.LC_data_table tr > td.LC_browser_file_locked,
6419: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6420: background: #FFAA99;
1.387 albertel 6421: }
1.795 www 6422:
1.777 tempelho 6423: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6424: background: #888888;
1.779 bisitz 6425: }
1.795 www 6426:
1.777 tempelho 6427: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6428: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6429: background: #F8F866;
1.777 tempelho 6430: }
1.795 www 6431:
1.696 bisitz 6432: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6433: background: #E0E8FF;
1.387 albertel 6434: }
1.696 bisitz 6435:
1.707 bisitz 6436: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6437: /* background: #77FF77; */
1.707 bisitz 6438: }
1.795 www 6439:
1.707 bisitz 6440: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6441: border-right: 8px solid #FFFF77;
1.707 bisitz 6442: }
1.795 www 6443:
1.707 bisitz 6444: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6445: border-right: 8px solid #FFAA77;
1.707 bisitz 6446: }
1.795 www 6447:
1.707 bisitz 6448: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6449: border-right: 8px solid #FF7777;
1.707 bisitz 6450: }
1.795 www 6451:
1.707 bisitz 6452: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6453: border-right: 8px solid #AAFF77;
1.707 bisitz 6454: }
1.795 www 6455:
1.707 bisitz 6456: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6457: border-right: 8px solid #11CC55;
1.707 bisitz 6458: }
6459:
1.388 albertel 6460: span.LC_current_location {
1.701 harmsja 6461: font-size:larger;
1.388 albertel 6462: background: $pgbg;
6463: }
1.387 albertel 6464:
1.1029 www 6465: span.LC_current_nav_location {
6466: font-weight:bold;
6467: background: $sidebg;
6468: }
6469:
1.395 albertel 6470: span.LC_parm_menu_item {
6471: font-size: larger;
6472: }
1.795 www 6473:
1.395 albertel 6474: span.LC_parm_scope_all {
6475: color: red;
6476: }
1.795 www 6477:
1.395 albertel 6478: span.LC_parm_scope_folder {
6479: color: green;
6480: }
1.795 www 6481:
1.395 albertel 6482: span.LC_parm_scope_resource {
6483: color: orange;
6484: }
1.795 www 6485:
1.395 albertel 6486: span.LC_parm_part {
6487: color: blue;
6488: }
1.795 www 6489:
1.911 bisitz 6490: span.LC_parm_folder,
6491: span.LC_parm_symb {
1.395 albertel 6492: font-size: x-small;
6493: font-family: $mono;
6494: color: #AAAAAA;
6495: }
6496:
1.977 bisitz 6497: ul.LC_parm_parmlist li {
6498: display: inline-block;
6499: padding: 0.3em 0.8em;
6500: vertical-align: top;
6501: width: 150px;
6502: border-top:1px solid $lg_border_color;
6503: }
6504:
1.795 www 6505: td.LC_parm_overview_level_menu,
6506: td.LC_parm_overview_map_menu,
6507: td.LC_parm_overview_parm_selectors,
6508: td.LC_parm_overview_restrictions {
1.396 albertel 6509: border: 1px solid black;
6510: border-collapse: collapse;
6511: }
1.795 www 6512:
1.396 albertel 6513: table.LC_parm_overview_restrictions td {
6514: border-width: 1px 4px 1px 4px;
6515: border-style: solid;
6516: border-color: $pgbg;
6517: text-align: center;
6518: }
1.795 www 6519:
1.396 albertel 6520: table.LC_parm_overview_restrictions th {
6521: background: $tabbg;
6522: border-width: 1px 4px 1px 4px;
6523: border-style: solid;
6524: border-color: $pgbg;
6525: }
1.795 www 6526:
1.398 albertel 6527: table#LC_helpmenu {
1.803 bisitz 6528: border: none;
1.398 albertel 6529: height: 55px;
1.803 bisitz 6530: border-spacing: 0;
1.398 albertel 6531: }
6532:
6533: table#LC_helpmenu fieldset legend {
6534: font-size: larger;
6535: }
1.795 www 6536:
1.397 albertel 6537: table#LC_helpmenu_links {
6538: width: 100%;
6539: border: 1px solid black;
6540: background: $pgbg;
1.803 bisitz 6541: padding: 0;
1.397 albertel 6542: border-spacing: 1px;
6543: }
1.795 www 6544:
1.397 albertel 6545: table#LC_helpmenu_links tr td {
6546: padding: 1px;
6547: background: $tabbg;
1.399 albertel 6548: text-align: center;
6549: font-weight: bold;
1.397 albertel 6550: }
1.396 albertel 6551:
1.795 www 6552: table#LC_helpmenu_links a:link,
6553: table#LC_helpmenu_links a:visited,
1.397 albertel 6554: table#LC_helpmenu_links a:active {
6555: text-decoration: none;
6556: color: $font;
6557: }
1.795 www 6558:
1.397 albertel 6559: table#LC_helpmenu_links a:hover {
6560: text-decoration: underline;
6561: color: $vlink;
6562: }
1.396 albertel 6563:
1.417 albertel 6564: .LC_chrt_popup_exists {
6565: border: 1px solid #339933;
6566: margin: -1px;
6567: }
1.795 www 6568:
1.417 albertel 6569: .LC_chrt_popup_up {
6570: border: 1px solid yellow;
6571: margin: -1px;
6572: }
1.795 www 6573:
1.417 albertel 6574: .LC_chrt_popup {
6575: border: 1px solid #8888FF;
6576: background: #CCCCFF;
6577: }
1.795 www 6578:
1.421 albertel 6579: table.LC_pick_box {
6580: border-collapse: separate;
6581: background: white;
6582: border: 1px solid black;
6583: border-spacing: 1px;
6584: }
1.795 www 6585:
1.421 albertel 6586: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6587: background: $sidebg;
1.421 albertel 6588: font-weight: bold;
1.900 bisitz 6589: text-align: left;
1.740 bisitz 6590: vertical-align: top;
1.421 albertel 6591: width: 184px;
6592: padding: 8px;
6593: }
1.795 www 6594:
1.579 raeburn 6595: table.LC_pick_box td.LC_pick_box_value {
6596: text-align: left;
6597: padding: 8px;
6598: }
1.795 www 6599:
1.579 raeburn 6600: table.LC_pick_box td.LC_pick_box_select {
6601: text-align: left;
6602: padding: 8px;
6603: }
1.795 www 6604:
1.424 albertel 6605: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6606: padding: 0;
1.421 albertel 6607: height: 1px;
6608: background: black;
6609: }
1.795 www 6610:
1.421 albertel 6611: table.LC_pick_box td.LC_pick_box_submit {
6612: text-align: right;
6613: }
1.795 www 6614:
1.579 raeburn 6615: table.LC_pick_box td.LC_evenrow_value {
6616: text-align: left;
6617: padding: 8px;
6618: background-color: $data_table_light;
6619: }
1.795 www 6620:
1.579 raeburn 6621: table.LC_pick_box td.LC_oddrow_value {
6622: text-align: left;
6623: padding: 8px;
6624: background-color: $data_table_light;
6625: }
1.795 www 6626:
1.579 raeburn 6627: span.LC_helpform_receipt_cat {
6628: font-weight: bold;
6629: }
1.795 www 6630:
1.424 albertel 6631: table.LC_group_priv_box {
6632: background: white;
6633: border: 1px solid black;
6634: border-spacing: 1px;
6635: }
1.795 www 6636:
1.424 albertel 6637: table.LC_group_priv_box td.LC_pick_box_title {
6638: background: $tabbg;
6639: font-weight: bold;
6640: text-align: right;
6641: width: 184px;
6642: }
1.795 www 6643:
1.424 albertel 6644: table.LC_group_priv_box td.LC_groups_fixed {
6645: background: $data_table_light;
6646: text-align: center;
6647: }
1.795 www 6648:
1.424 albertel 6649: table.LC_group_priv_box td.LC_groups_optional {
6650: background: $data_table_dark;
6651: text-align: center;
6652: }
1.795 www 6653:
1.424 albertel 6654: table.LC_group_priv_box td.LC_groups_functionality {
6655: background: $data_table_darker;
6656: text-align: center;
6657: font-weight: bold;
6658: }
1.795 www 6659:
1.424 albertel 6660: table.LC_group_priv td {
6661: text-align: left;
1.803 bisitz 6662: padding: 0;
1.424 albertel 6663: }
6664:
6665: .LC_navbuttons {
6666: margin: 2ex 0ex 2ex 0ex;
6667: }
1.795 www 6668:
1.423 albertel 6669: .LC_topic_bar {
6670: font-weight: bold;
6671: background: $tabbg;
1.918 wenzelju 6672: margin: 1em 0em 1em 2em;
1.805 bisitz 6673: padding: 3px;
1.918 wenzelju 6674: font-size: 1.2em;
1.423 albertel 6675: }
1.795 www 6676:
1.423 albertel 6677: .LC_topic_bar span {
1.918 wenzelju 6678: left: 0.5em;
6679: position: absolute;
1.423 albertel 6680: vertical-align: middle;
1.918 wenzelju 6681: font-size: 1.2em;
1.423 albertel 6682: }
1.795 www 6683:
1.423 albertel 6684: table.LC_course_group_status {
6685: margin: 20px;
6686: }
1.795 www 6687:
1.423 albertel 6688: table.LC_status_selector td {
6689: vertical-align: top;
6690: text-align: center;
1.424 albertel 6691: padding: 4px;
6692: }
1.795 www 6693:
1.599 albertel 6694: div.LC_feedback_link {
1.616 albertel 6695: clear: both;
1.829 kalberla 6696: background: $sidebg;
1.779 bisitz 6697: width: 100%;
1.829 kalberla 6698: padding-bottom: 10px;
6699: border: 1px $tabbg solid;
1.833 kalberla 6700: height: 22px;
6701: line-height: 22px;
6702: padding-top: 5px;
6703: }
6704:
6705: div.LC_feedback_link img {
6706: height: 22px;
1.867 kalberla 6707: vertical-align:middle;
1.829 kalberla 6708: }
6709:
1.911 bisitz 6710: div.LC_feedback_link a {
1.829 kalberla 6711: text-decoration: none;
1.489 raeburn 6712: }
1.795 www 6713:
1.867 kalberla 6714: div.LC_comblock {
1.911 bisitz 6715: display:inline;
1.867 kalberla 6716: color:$font;
6717: font-size:90%;
6718: }
6719:
6720: div.LC_feedback_link div.LC_comblock {
6721: padding-left:5px;
6722: }
6723:
6724: div.LC_feedback_link div.LC_comblock a {
6725: color:$font;
6726: }
6727:
1.489 raeburn 6728: span.LC_feedback_link {
1.858 bisitz 6729: /* background: $feedback_link_bg; */
1.599 albertel 6730: font-size: larger;
6731: }
1.795 www 6732:
1.599 albertel 6733: span.LC_message_link {
1.858 bisitz 6734: /* background: $feedback_link_bg; */
1.599 albertel 6735: font-size: larger;
6736: position: absolute;
6737: right: 1em;
1.489 raeburn 6738: }
1.421 albertel 6739:
1.515 albertel 6740: table.LC_prior_tries {
1.524 albertel 6741: border: 1px solid #000000;
6742: border-collapse: separate;
6743: border-spacing: 1px;
1.515 albertel 6744: }
1.523 albertel 6745:
1.515 albertel 6746: table.LC_prior_tries td {
1.524 albertel 6747: padding: 2px;
1.515 albertel 6748: }
1.523 albertel 6749:
6750: .LC_answer_correct {
1.795 www 6751: background: lightgreen;
6752: color: darkgreen;
6753: padding: 6px;
1.523 albertel 6754: }
1.795 www 6755:
1.523 albertel 6756: .LC_answer_charged_try {
1.797 www 6757: background: #FFAAAA;
1.795 www 6758: color: darkred;
6759: padding: 6px;
1.523 albertel 6760: }
1.795 www 6761:
1.779 bisitz 6762: .LC_answer_not_charged_try,
1.523 albertel 6763: .LC_answer_no_grade,
6764: .LC_answer_late {
1.795 www 6765: background: lightyellow;
1.523 albertel 6766: color: black;
1.795 www 6767: padding: 6px;
1.523 albertel 6768: }
1.795 www 6769:
1.523 albertel 6770: .LC_answer_previous {
1.795 www 6771: background: lightblue;
6772: color: darkblue;
6773: padding: 6px;
1.523 albertel 6774: }
1.795 www 6775:
1.779 bisitz 6776: .LC_answer_no_message {
1.777 tempelho 6777: background: #FFFFFF;
6778: color: black;
1.795 www 6779: padding: 6px;
1.779 bisitz 6780: }
1.795 www 6781:
1.1075.2.140 raeburn 6782: .LC_answer_unknown,
6783: .LC_answer_warning {
1.779 bisitz 6784: background: orange;
6785: color: black;
1.795 www 6786: padding: 6px;
1.777 tempelho 6787: }
1.795 www 6788:
1.529 albertel 6789: span.LC_prior_numerical,
6790: span.LC_prior_string,
6791: span.LC_prior_custom,
6792: span.LC_prior_reaction,
6793: span.LC_prior_math {
1.925 bisitz 6794: font-family: $mono;
1.523 albertel 6795: white-space: pre;
6796: }
6797:
1.525 albertel 6798: span.LC_prior_string {
1.925 bisitz 6799: font-family: $mono;
1.525 albertel 6800: white-space: pre;
6801: }
6802:
1.523 albertel 6803: table.LC_prior_option {
6804: width: 100%;
6805: border-collapse: collapse;
6806: }
1.795 www 6807:
1.911 bisitz 6808: table.LC_prior_rank,
1.795 www 6809: table.LC_prior_match {
1.528 albertel 6810: border-collapse: collapse;
6811: }
1.795 www 6812:
1.528 albertel 6813: table.LC_prior_option tr td,
6814: table.LC_prior_rank tr td,
6815: table.LC_prior_match tr td {
1.524 albertel 6816: border: 1px solid #000000;
1.515 albertel 6817: }
6818:
1.855 bisitz 6819: .LC_nobreak {
1.544 albertel 6820: white-space: nowrap;
1.519 raeburn 6821: }
6822:
1.576 raeburn 6823: span.LC_cusr_emph {
6824: font-style: italic;
6825: }
6826:
1.633 raeburn 6827: span.LC_cusr_subheading {
6828: font-weight: normal;
6829: font-size: 85%;
6830: }
6831:
1.861 bisitz 6832: div.LC_docs_entry_move {
1.859 bisitz 6833: border: 1px solid #BBBBBB;
1.545 albertel 6834: background: #DDDDDD;
1.861 bisitz 6835: width: 22px;
1.859 bisitz 6836: padding: 1px;
6837: margin: 0;
1.545 albertel 6838: }
6839:
1.861 bisitz 6840: table.LC_data_table tr > td.LC_docs_entry_commands,
6841: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6842: font-size: x-small;
6843: }
1.795 www 6844:
1.861 bisitz 6845: .LC_docs_entry_parameter {
6846: white-space: nowrap;
6847: }
6848:
1.544 albertel 6849: .LC_docs_copy {
1.545 albertel 6850: color: #000099;
1.544 albertel 6851: }
1.795 www 6852:
1.544 albertel 6853: .LC_docs_cut {
1.545 albertel 6854: color: #550044;
1.544 albertel 6855: }
1.795 www 6856:
1.544 albertel 6857: .LC_docs_rename {
1.545 albertel 6858: color: #009900;
1.544 albertel 6859: }
1.795 www 6860:
1.544 albertel 6861: .LC_docs_remove {
1.545 albertel 6862: color: #990000;
6863: }
6864:
1.1075.2.134 raeburn 6865: .LC_domprefs_email,
1.547 albertel 6866: .LC_docs_reinit_warn,
6867: .LC_docs_ext_edit {
6868: font-size: x-small;
6869: }
6870:
1.545 albertel 6871: table.LC_docs_adddocs td,
6872: table.LC_docs_adddocs th {
6873: border: 1px solid #BBBBBB;
6874: padding: 4px;
6875: background: #DDDDDD;
1.543 albertel 6876: }
6877:
1.584 albertel 6878: table.LC_sty_begin {
6879: background: #BBFFBB;
6880: }
1.795 www 6881:
1.584 albertel 6882: table.LC_sty_end {
6883: background: #FFBBBB;
6884: }
6885:
1.589 raeburn 6886: table.LC_double_column {
1.803 bisitz 6887: border-width: 0;
1.589 raeburn 6888: border-collapse: collapse;
6889: width: 100%;
6890: padding: 2px;
6891: }
6892:
6893: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6894: top: 2px;
1.589 raeburn 6895: left: 2px;
6896: width: 47%;
6897: vertical-align: top;
6898: }
6899:
6900: table.LC_double_column tr td.LC_right_col {
6901: top: 2px;
1.779 bisitz 6902: right: 2px;
1.589 raeburn 6903: width: 47%;
6904: vertical-align: top;
6905: }
6906:
1.591 raeburn 6907: div.LC_left_float {
6908: float: left;
6909: padding-right: 5%;
1.597 albertel 6910: padding-bottom: 4px;
1.591 raeburn 6911: }
6912:
6913: div.LC_clear_float_header {
1.597 albertel 6914: padding-bottom: 2px;
1.591 raeburn 6915: }
6916:
6917: div.LC_clear_float_footer {
1.597 albertel 6918: padding-top: 10px;
1.591 raeburn 6919: clear: both;
6920: }
6921:
1.597 albertel 6922: div.LC_grade_show_user {
1.941 bisitz 6923: /* border-left: 5px solid $sidebg; */
6924: border-top: 5px solid #000000;
6925: margin: 50px 0 0 0;
1.936 bisitz 6926: padding: 15px 0 5px 10px;
1.597 albertel 6927: }
1.795 www 6928:
1.936 bisitz 6929: div.LC_grade_show_user_odd_row {
1.941 bisitz 6930: /* border-left: 5px solid #000000; */
6931: }
6932:
6933: div.LC_grade_show_user div.LC_Box {
6934: margin-right: 50px;
1.597 albertel 6935: }
6936:
6937: div.LC_grade_submissions,
6938: div.LC_grade_message_center,
1.936 bisitz 6939: div.LC_grade_info_links {
1.597 albertel 6940: margin: 5px;
6941: width: 99%;
6942: background: #FFFFFF;
6943: }
1.795 www 6944:
1.597 albertel 6945: div.LC_grade_submissions_header,
1.936 bisitz 6946: div.LC_grade_message_center_header {
1.705 tempelho 6947: font-weight: bold;
6948: font-size: large;
1.597 albertel 6949: }
1.795 www 6950:
1.597 albertel 6951: div.LC_grade_submissions_body,
1.936 bisitz 6952: div.LC_grade_message_center_body {
1.597 albertel 6953: border: 1px solid black;
6954: width: 99%;
6955: background: #FFFFFF;
6956: }
1.795 www 6957:
1.613 albertel 6958: table.LC_scantron_action {
6959: width: 100%;
6960: }
1.795 www 6961:
1.613 albertel 6962: table.LC_scantron_action tr th {
1.698 harmsja 6963: font-weight:bold;
6964: font-style:normal;
1.613 albertel 6965: }
1.795 www 6966:
1.779 bisitz 6967: .LC_edit_problem_header,
1.614 albertel 6968: div.LC_edit_problem_footer {
1.705 tempelho 6969: font-weight: normal;
6970: font-size: medium;
1.602 albertel 6971: margin: 2px;
1.1060 bisitz 6972: background-color: $sidebg;
1.600 albertel 6973: }
1.795 www 6974:
1.600 albertel 6975: div.LC_edit_problem_header,
1.602 albertel 6976: div.LC_edit_problem_header div,
1.614 albertel 6977: div.LC_edit_problem_footer,
6978: div.LC_edit_problem_footer div,
1.602 albertel 6979: div.LC_edit_problem_editxml_header,
6980: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 6981: z-index: 100;
1.600 albertel 6982: }
1.795 www 6983:
1.600 albertel 6984: div.LC_edit_problem_header_title {
1.705 tempelho 6985: font-weight: bold;
6986: font-size: larger;
1.602 albertel 6987: background: $tabbg;
6988: padding: 3px;
1.1060 bisitz 6989: margin: 0 0 5px 0;
1.602 albertel 6990: }
1.795 www 6991:
1.602 albertel 6992: table.LC_edit_problem_header_title {
6993: width: 100%;
1.600 albertel 6994: background: $tabbg;
1.602 albertel 6995: }
6996:
1.1075.2.112 raeburn 6997: div.LC_edit_actionbar {
6998: background-color: $sidebg;
6999: margin: 0;
7000: padding: 0;
7001: line-height: 200%;
1.602 albertel 7002: }
1.795 www 7003:
1.1075.2.112 raeburn 7004: div.LC_edit_actionbar div{
7005: padding: 0;
7006: margin: 0;
7007: display: inline-block;
1.600 albertel 7008: }
1.795 www 7009:
1.1075.2.34 raeburn 7010: .LC_edit_opt {
7011: padding-left: 1em;
7012: white-space: nowrap;
7013: }
7014:
1.1075.2.57 raeburn 7015: .LC_edit_problem_latexhelper{
7016: text-align: right;
7017: }
7018:
7019: #LC_edit_problem_colorful div{
7020: margin-left: 40px;
7021: }
7022:
1.1075.2.112 raeburn 7023: #LC_edit_problem_codemirror div{
7024: margin-left: 0px;
7025: }
7026:
1.911 bisitz 7027: img.stift {
1.803 bisitz 7028: border-width: 0;
7029: vertical-align: middle;
1.677 riegler 7030: }
1.680 riegler 7031:
1.923 bisitz 7032: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7033: vertical-align: top;
1.777 tempelho 7034: }
1.795 www 7035:
1.716 raeburn 7036: div.LC_createcourse {
1.911 bisitz 7037: margin: 10px 10px 10px 10px;
1.716 raeburn 7038: }
7039:
1.917 raeburn 7040: .LC_dccid {
1.1075.2.38 raeburn 7041: float: right;
1.917 raeburn 7042: margin: 0.2em 0 0 0;
7043: padding: 0;
7044: font-size: 90%;
7045: display:none;
7046: }
7047:
1.897 wenzelju 7048: ol.LC_primary_menu a:hover,
1.721 harmsja 7049: ol#LC_MenuBreadcrumbs a:hover,
7050: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7051: ul#LC_secondary_menu a:hover,
1.721 harmsja 7052: .LC_FormSectionClearButton input:hover
1.795 www 7053: ul.LC_TabContent li:hover a {
1.952 onken 7054: color:$button_hover;
1.911 bisitz 7055: text-decoration:none;
1.693 droeschl 7056: }
7057:
1.779 bisitz 7058: h1 {
1.911 bisitz 7059: padding: 0;
7060: line-height:130%;
1.693 droeschl 7061: }
1.698 harmsja 7062:
1.911 bisitz 7063: h2,
7064: h3,
7065: h4,
7066: h5,
7067: h6 {
7068: margin: 5px 0 5px 0;
7069: padding: 0;
7070: line-height:130%;
1.693 droeschl 7071: }
1.795 www 7072:
7073: .LC_hcell {
1.911 bisitz 7074: padding:3px 15px 3px 15px;
7075: margin: 0;
7076: background-color:$tabbg;
7077: color:$fontmenu;
7078: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7079: }
1.795 www 7080:
1.840 bisitz 7081: .LC_Box > .LC_hcell {
1.911 bisitz 7082: margin: 0 -10px 10px -10px;
1.835 bisitz 7083: }
7084:
1.721 harmsja 7085: .LC_noBorder {
1.911 bisitz 7086: border: 0;
1.698 harmsja 7087: }
1.693 droeschl 7088:
1.721 harmsja 7089: .LC_FormSectionClearButton input {
1.911 bisitz 7090: background-color:transparent;
7091: border: none;
7092: cursor:pointer;
7093: text-decoration:underline;
1.693 droeschl 7094: }
1.763 bisitz 7095:
7096: .LC_help_open_topic {
1.911 bisitz 7097: color: #FFFFFF;
7098: background-color: #EEEEFF;
7099: margin: 1px;
7100: padding: 4px;
7101: border: 1px solid #000033;
7102: white-space: nowrap;
7103: /* vertical-align: middle; */
1.759 neumanie 7104: }
1.693 droeschl 7105:
1.911 bisitz 7106: dl,
7107: ul,
7108: div,
7109: fieldset {
7110: margin: 10px 10px 10px 0;
7111: /* overflow: hidden; */
1.693 droeschl 7112: }
1.795 www 7113:
1.1075.2.90 raeburn 7114: article.geogebraweb div {
7115: margin: 0;
7116: }
7117:
1.838 bisitz 7118: fieldset > legend {
1.911 bisitz 7119: font-weight: bold;
7120: padding: 0 5px 0 5px;
1.838 bisitz 7121: }
7122:
1.813 bisitz 7123: #LC_nav_bar {
1.911 bisitz 7124: float: left;
1.995 raeburn 7125: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7126: margin: 0 0 2px 0;
1.807 droeschl 7127: }
7128:
1.916 droeschl 7129: #LC_realm {
7130: margin: 0.2em 0 0 0;
7131: padding: 0;
7132: font-weight: bold;
7133: text-align: center;
1.995 raeburn 7134: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7135: }
7136:
1.911 bisitz 7137: #LC_nav_bar em {
7138: font-weight: bold;
7139: font-style: normal;
1.807 droeschl 7140: }
7141:
1.897 wenzelju 7142: ol.LC_primary_menu {
1.934 droeschl 7143: margin: 0;
1.1075.2.2 raeburn 7144: padding: 0;
1.807 droeschl 7145: }
7146:
1.852 droeschl 7147: ol#LC_PathBreadcrumbs {
1.911 bisitz 7148: margin: 0;
1.693 droeschl 7149: }
7150:
1.897 wenzelju 7151: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7152: color: RGB(80, 80, 80);
7153: vertical-align: middle;
7154: text-align: left;
7155: list-style: none;
1.1075.2.112 raeburn 7156: position: relative;
1.1075.2.2 raeburn 7157: float: left;
1.1075.2.112 raeburn 7158: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7159: line-height: 1.5em;
1.1075.2.2 raeburn 7160: }
7161:
1.1075.2.113 raeburn 7162: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7163: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7164: display: block;
7165: margin: 0;
7166: padding: 0 5px 0 10px;
7167: text-decoration: none;
7168: }
7169:
1.1075.2.112 raeburn 7170: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7171: display: inline-block;
7172: width: 95%;
7173: text-align: left;
7174: }
7175:
7176: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7177: display: inline-block;
7178: width: 5%;
7179: float: right;
7180: text-align: right;
7181: font-size: 70%;
7182: }
7183:
7184: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7185: display: none;
1.1075.2.112 raeburn 7186: width: 15em;
1.1075.2.2 raeburn 7187: background-color: $data_table_light;
1.1075.2.112 raeburn 7188: position: absolute;
7189: top: 100%;
7190: }
7191:
7192: ol.LC_primary_menu ul ul {
7193: left: 100%;
7194: top: 0;
1.1075.2.2 raeburn 7195: }
7196:
1.1075.2.112 raeburn 7197: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7198: display: block;
7199: position: absolute;
7200: margin: 0;
7201: padding: 0;
1.1075.2.5 raeburn 7202: z-index: 2;
1.1075.2.2 raeburn 7203: }
7204:
7205: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7206: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7207: font-size: 90%;
1.911 bisitz 7208: vertical-align: top;
1.1075.2.2 raeburn 7209: float: none;
1.1075.2.5 raeburn 7210: border-left: 1px solid black;
7211: border-right: 1px solid black;
1.1075.2.112 raeburn 7212: /* A dark bottom border to visualize different menu options;
7213: overwritten in the create_submenu routine for the last border-bottom of the menu */
7214: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7215: }
7216:
1.1075.2.112 raeburn 7217: ol.LC_primary_menu li li p:hover {
7218: color:$button_hover;
7219: text-decoration:none;
7220: background-color:$data_table_dark;
1.1075.2.2 raeburn 7221: }
7222:
7223: ol.LC_primary_menu li li a:hover {
7224: color:$button_hover;
7225: background-color:$data_table_dark;
1.693 droeschl 7226: }
7227:
1.1075.2.112 raeburn 7228: /* Font-size equal to the size of the predecessors*/
7229: ol.LC_primary_menu li:hover li li {
7230: font-size: 100%;
7231: }
7232:
1.897 wenzelju 7233: ol.LC_primary_menu li img {
1.911 bisitz 7234: vertical-align: bottom;
1.934 droeschl 7235: height: 1.1em;
1.1075.2.3 raeburn 7236: margin: 0.2em 0 0 0;
1.693 droeschl 7237: }
7238:
1.897 wenzelju 7239: ol.LC_primary_menu a {
1.911 bisitz 7240: color: RGB(80, 80, 80);
7241: text-decoration: none;
1.693 droeschl 7242: }
1.795 www 7243:
1.949 droeschl 7244: ol.LC_primary_menu a.LC_new_message {
7245: font-weight:bold;
7246: color: darkred;
7247: }
7248:
1.975 raeburn 7249: ol.LC_docs_parameters {
7250: margin-left: 0;
7251: padding: 0;
7252: list-style: none;
7253: }
7254:
7255: ol.LC_docs_parameters li {
7256: margin: 0;
7257: padding-right: 20px;
7258: display: inline;
7259: }
7260:
1.976 raeburn 7261: ol.LC_docs_parameters li:before {
7262: content: "\\002022 \\0020";
7263: }
7264:
7265: li.LC_docs_parameters_title {
7266: font-weight: bold;
7267: }
7268:
7269: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7270: content: "";
7271: }
7272:
1.897 wenzelju 7273: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7274: clear: right;
1.911 bisitz 7275: color: $fontmenu;
7276: background: $tabbg;
7277: list-style: none;
7278: padding: 0;
7279: margin: 0;
7280: width: 100%;
1.995 raeburn 7281: text-align: left;
1.1075.2.4 raeburn 7282: float: left;
1.808 droeschl 7283: }
7284:
1.897 wenzelju 7285: ul#LC_secondary_menu li {
1.911 bisitz 7286: font-weight: bold;
7287: line-height: 1.8em;
7288: border-right: 1px solid black;
1.1075.2.4 raeburn 7289: float: left;
7290: }
7291:
7292: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7293: background-color: $data_table_light;
7294: }
7295:
7296: ul#LC_secondary_menu li a {
7297: padding: 0 0.8em;
7298: }
7299:
7300: ul#LC_secondary_menu li ul {
7301: display: none;
7302: }
7303:
7304: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7305: display: block;
7306: position: absolute;
7307: margin: 0;
7308: padding: 0;
7309: list-style:none;
7310: float: none;
7311: background-color: $data_table_light;
1.1075.2.5 raeburn 7312: z-index: 2;
1.1075.2.10 raeburn 7313: margin-left: -1px;
1.1075.2.4 raeburn 7314: }
7315:
7316: ul#LC_secondary_menu li ul li {
7317: font-size: 90%;
7318: vertical-align: top;
7319: border-left: 1px solid black;
7320: border-right: 1px solid black;
1.1075.2.33 raeburn 7321: background-color: $data_table_light;
1.1075.2.4 raeburn 7322: list-style:none;
7323: float: none;
7324: }
7325:
7326: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7327: background-color: $data_table_dark;
1.807 droeschl 7328: }
7329:
1.847 tempelho 7330: ul.LC_TabContent {
1.911 bisitz 7331: display:block;
7332: background: $sidebg;
7333: border-bottom: solid 1px $lg_border_color;
7334: list-style:none;
1.1020 raeburn 7335: margin: -1px -10px 0 -10px;
1.911 bisitz 7336: padding: 0;
1.693 droeschl 7337: }
7338:
1.795 www 7339: ul.LC_TabContent li,
7340: ul.LC_TabContentBigger li {
1.911 bisitz 7341: float:left;
1.741 harmsja 7342: }
1.795 www 7343:
1.897 wenzelju 7344: ul#LC_secondary_menu li a {
1.911 bisitz 7345: color: $fontmenu;
7346: text-decoration: none;
1.693 droeschl 7347: }
1.795 www 7348:
1.721 harmsja 7349: ul.LC_TabContent {
1.952 onken 7350: min-height:20px;
1.721 harmsja 7351: }
1.795 www 7352:
7353: ul.LC_TabContent li {
1.911 bisitz 7354: vertical-align:middle;
1.959 onken 7355: padding: 0 16px 0 10px;
1.911 bisitz 7356: background-color:$tabbg;
7357: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7358: border-left: solid 1px $font;
1.721 harmsja 7359: }
1.795 www 7360:
1.847 tempelho 7361: ul.LC_TabContent .right {
1.911 bisitz 7362: float:right;
1.847 tempelho 7363: }
7364:
1.911 bisitz 7365: ul.LC_TabContent li a,
7366: ul.LC_TabContent li {
7367: color:rgb(47,47,47);
7368: text-decoration:none;
7369: font-size:95%;
7370: font-weight:bold;
1.952 onken 7371: min-height:20px;
7372: }
7373:
1.959 onken 7374: ul.LC_TabContent li a:hover,
7375: ul.LC_TabContent li a:focus {
1.952 onken 7376: color: $button_hover;
1.959 onken 7377: background:none;
7378: outline:none;
1.952 onken 7379: }
7380:
7381: ul.LC_TabContent li:hover {
7382: color: $button_hover;
7383: cursor:pointer;
1.721 harmsja 7384: }
1.795 www 7385:
1.911 bisitz 7386: ul.LC_TabContent li.active {
1.952 onken 7387: color: $font;
1.911 bisitz 7388: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7389: border-bottom:solid 1px #FFFFFF;
7390: cursor: default;
1.744 ehlerst 7391: }
1.795 www 7392:
1.959 onken 7393: ul.LC_TabContent li.active a {
7394: color:$font;
7395: background:#FFFFFF;
7396: outline: none;
7397: }
1.1047 raeburn 7398:
7399: ul.LC_TabContent li.goback {
7400: float: left;
7401: border-left: none;
7402: }
7403:
1.870 tempelho 7404: #maincoursedoc {
1.911 bisitz 7405: clear:both;
1.870 tempelho 7406: }
7407:
7408: ul.LC_TabContentBigger {
1.911 bisitz 7409: display:block;
7410: list-style:none;
7411: padding: 0;
1.870 tempelho 7412: }
7413:
1.795 www 7414: ul.LC_TabContentBigger li {
1.911 bisitz 7415: vertical-align:bottom;
7416: height: 30px;
7417: font-size:110%;
7418: font-weight:bold;
7419: color: #737373;
1.841 tempelho 7420: }
7421:
1.957 onken 7422: ul.LC_TabContentBigger li.active {
7423: position: relative;
7424: top: 1px;
7425: }
7426:
1.870 tempelho 7427: ul.LC_TabContentBigger li a {
1.911 bisitz 7428: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7429: height: 30px;
7430: line-height: 30px;
7431: text-align: center;
7432: display: block;
7433: text-decoration: none;
1.958 onken 7434: outline: none;
1.741 harmsja 7435: }
1.795 www 7436:
1.870 tempelho 7437: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7438: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7439: color:$font;
1.744 ehlerst 7440: }
1.795 www 7441:
1.870 tempelho 7442: ul.LC_TabContentBigger li b {
1.911 bisitz 7443: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7444: display: block;
7445: float: left;
7446: padding: 0 30px;
1.957 onken 7447: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7448: }
7449:
1.956 onken 7450: ul.LC_TabContentBigger li:hover b {
7451: color:$button_hover;
7452: }
7453:
1.870 tempelho 7454: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7455: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7456: color:$font;
1.957 onken 7457: border: 0;
1.741 harmsja 7458: }
1.693 droeschl 7459:
1.870 tempelho 7460:
1.862 bisitz 7461: ul.LC_CourseBreadcrumbs {
7462: background: $sidebg;
1.1020 raeburn 7463: height: 2em;
1.862 bisitz 7464: padding-left: 10px;
1.1020 raeburn 7465: margin: 0;
1.862 bisitz 7466: list-style-position: inside;
7467: }
7468:
1.911 bisitz 7469: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7470: ol#LC_PathBreadcrumbs {
1.911 bisitz 7471: padding-left: 10px;
7472: margin: 0;
1.933 droeschl 7473: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7474: }
7475:
1.911 bisitz 7476: ol#LC_MenuBreadcrumbs li,
7477: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7478: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7479: display: inline;
1.933 droeschl 7480: white-space: normal;
1.693 droeschl 7481: }
7482:
1.823 bisitz 7483: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7484: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7485: text-decoration: none;
7486: font-size:90%;
1.693 droeschl 7487: }
1.795 www 7488:
1.969 droeschl 7489: ol#LC_MenuBreadcrumbs h1 {
7490: display: inline;
7491: font-size: 90%;
7492: line-height: 2.5em;
7493: margin: 0;
7494: padding: 0;
7495: }
7496:
1.795 www 7497: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7498: text-decoration:none;
7499: font-size:100%;
7500: font-weight:bold;
1.693 droeschl 7501: }
1.795 www 7502:
1.840 bisitz 7503: .LC_Box {
1.911 bisitz 7504: border: solid 1px $lg_border_color;
7505: padding: 0 10px 10px 10px;
1.746 neumanie 7506: }
1.795 www 7507:
1.1020 raeburn 7508: .LC_DocsBox {
7509: border: solid 1px $lg_border_color;
7510: padding: 0 0 10px 10px;
7511: }
7512:
1.795 www 7513: .LC_AboutMe_Image {
1.911 bisitz 7514: float:left;
7515: margin-right:10px;
1.747 neumanie 7516: }
1.795 www 7517:
7518: .LC_Clear_AboutMe_Image {
1.911 bisitz 7519: clear:left;
1.747 neumanie 7520: }
1.795 www 7521:
1.721 harmsja 7522: dl.LC_ListStyleClean dt {
1.911 bisitz 7523: padding-right: 5px;
7524: display: table-header-group;
1.693 droeschl 7525: }
7526:
1.721 harmsja 7527: dl.LC_ListStyleClean dd {
1.911 bisitz 7528: display: table-row;
1.693 droeschl 7529: }
7530:
1.721 harmsja 7531: .LC_ListStyleClean,
7532: .LC_ListStyleSimple,
7533: .LC_ListStyleNormal,
1.795 www 7534: .LC_ListStyleSpecial {
1.911 bisitz 7535: /* display:block; */
7536: list-style-position: inside;
7537: list-style-type: none;
7538: overflow: hidden;
7539: padding: 0;
1.693 droeschl 7540: }
7541:
1.721 harmsja 7542: .LC_ListStyleSimple li,
7543: .LC_ListStyleSimple dd,
7544: .LC_ListStyleNormal li,
7545: .LC_ListStyleNormal dd,
7546: .LC_ListStyleSpecial li,
1.795 www 7547: .LC_ListStyleSpecial dd {
1.911 bisitz 7548: margin: 0;
7549: padding: 5px 5px 5px 10px;
7550: clear: both;
1.693 droeschl 7551: }
7552:
1.721 harmsja 7553: .LC_ListStyleClean li,
7554: .LC_ListStyleClean dd {
1.911 bisitz 7555: padding-top: 0;
7556: padding-bottom: 0;
1.693 droeschl 7557: }
7558:
1.721 harmsja 7559: .LC_ListStyleSimple dd,
1.795 www 7560: .LC_ListStyleSimple li {
1.911 bisitz 7561: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7562: }
7563:
1.721 harmsja 7564: .LC_ListStyleSpecial li,
7565: .LC_ListStyleSpecial dd {
1.911 bisitz 7566: list-style-type: none;
7567: background-color: RGB(220, 220, 220);
7568: margin-bottom: 4px;
1.693 droeschl 7569: }
7570:
1.721 harmsja 7571: table.LC_SimpleTable {
1.911 bisitz 7572: margin:5px;
7573: border:solid 1px $lg_border_color;
1.795 www 7574: }
1.693 droeschl 7575:
1.721 harmsja 7576: table.LC_SimpleTable tr {
1.911 bisitz 7577: padding: 0;
7578: border:solid 1px $lg_border_color;
1.693 droeschl 7579: }
1.795 www 7580:
7581: table.LC_SimpleTable thead {
1.911 bisitz 7582: background:rgb(220,220,220);
1.693 droeschl 7583: }
7584:
1.721 harmsja 7585: div.LC_columnSection {
1.911 bisitz 7586: display: block;
7587: clear: both;
7588: overflow: hidden;
7589: margin: 0;
1.693 droeschl 7590: }
7591:
1.721 harmsja 7592: div.LC_columnSection>* {
1.911 bisitz 7593: float: left;
7594: margin: 10px 20px 10px 0;
7595: overflow:hidden;
1.693 droeschl 7596: }
1.721 harmsja 7597:
1.795 www 7598: table em {
1.911 bisitz 7599: font-weight: bold;
7600: font-style: normal;
1.748 schulted 7601: }
1.795 www 7602:
1.779 bisitz 7603: table.LC_tableBrowseRes,
1.795 www 7604: table.LC_tableOfContent {
1.911 bisitz 7605: border:none;
7606: border-spacing: 1px;
7607: padding: 3px;
7608: background-color: #FFFFFF;
7609: font-size: 90%;
1.753 droeschl 7610: }
1.789 droeschl 7611:
1.911 bisitz 7612: table.LC_tableOfContent {
7613: border-collapse: collapse;
1.789 droeschl 7614: }
7615:
1.771 droeschl 7616: table.LC_tableBrowseRes a,
1.768 schulted 7617: table.LC_tableOfContent a {
1.911 bisitz 7618: background-color: transparent;
7619: text-decoration: none;
1.753 droeschl 7620: }
7621:
1.795 www 7622: table.LC_tableOfContent img {
1.911 bisitz 7623: border: none;
7624: height: 1.3em;
7625: vertical-align: text-bottom;
7626: margin-right: 0.3em;
1.753 droeschl 7627: }
1.757 schulted 7628:
1.795 www 7629: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7630: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7631: }
7632:
1.795 www 7633: a#LC_content_toolbar_everything {
1.911 bisitz 7634: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7635: }
7636:
1.795 www 7637: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7638: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7639: }
7640:
1.795 www 7641: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7642: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7643: }
7644:
1.795 www 7645: a#LC_content_toolbar_changefolder {
1.911 bisitz 7646: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7647: }
7648:
1.795 www 7649: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7650: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7651: }
7652:
1.1043 raeburn 7653: a#LC_content_toolbar_edittoplevel {
7654: background-image:url(/res/adm/pages/edittoplevel.gif);
7655: }
7656:
1.795 www 7657: ul#LC_toolbar li a:hover {
1.911 bisitz 7658: background-position: bottom center;
1.757 schulted 7659: }
7660:
1.795 www 7661: ul#LC_toolbar {
1.911 bisitz 7662: padding: 0;
7663: margin: 2px;
7664: list-style:none;
7665: position:relative;
7666: background-color:white;
1.1075.2.9 raeburn 7667: overflow: auto;
1.757 schulted 7668: }
7669:
1.795 www 7670: ul#LC_toolbar li {
1.911 bisitz 7671: border:1px solid white;
7672: padding: 0;
7673: margin: 0;
7674: float: left;
7675: display:inline;
7676: vertical-align:middle;
1.1075.2.9 raeburn 7677: white-space: nowrap;
1.911 bisitz 7678: }
1.757 schulted 7679:
1.783 amueller 7680:
1.795 www 7681: a.LC_toolbarItem {
1.911 bisitz 7682: display:block;
7683: padding: 0;
7684: margin: 0;
7685: height: 32px;
7686: width: 32px;
7687: color:white;
7688: border: none;
7689: background-repeat:no-repeat;
7690: background-color:transparent;
1.757 schulted 7691: }
7692:
1.915 droeschl 7693: ul.LC_funclist {
7694: margin: 0;
7695: padding: 0.5em 1em 0.5em 0;
7696: }
7697:
1.933 droeschl 7698: ul.LC_funclist > li:first-child {
7699: font-weight:bold;
7700: margin-left:0.8em;
7701: }
7702:
1.915 droeschl 7703: ul.LC_funclist + ul.LC_funclist {
7704: /*
7705: left border as a seperator if we have more than
7706: one list
7707: */
7708: border-left: 1px solid $sidebg;
7709: /*
7710: this hides the left border behind the border of the
7711: outer box if element is wrapped to the next 'line'
7712: */
7713: margin-left: -1px;
7714: }
7715:
1.843 bisitz 7716: ul.LC_funclist li {
1.915 droeschl 7717: display: inline;
1.782 bisitz 7718: white-space: nowrap;
1.915 droeschl 7719: margin: 0 0 0 25px;
7720: line-height: 150%;
1.782 bisitz 7721: }
7722:
1.974 wenzelju 7723: .LC_hidden {
7724: display: none;
7725: }
7726:
1.1030 www 7727: .LCmodal-overlay {
7728: position:fixed;
7729: top:0;
7730: right:0;
7731: bottom:0;
7732: left:0;
7733: height:100%;
7734: width:100%;
7735: margin:0;
7736: padding:0;
7737: background:#999;
7738: opacity:.75;
7739: filter: alpha(opacity=75);
7740: -moz-opacity: 0.75;
7741: z-index:101;
7742: }
7743:
7744: * html .LCmodal-overlay {
7745: position: absolute;
7746: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7747: }
7748:
7749: .LCmodal-window {
7750: position:fixed;
7751: top:50%;
7752: left:50%;
7753: margin:0;
7754: padding:0;
7755: z-index:102;
7756: }
7757:
7758: * html .LCmodal-window {
7759: position:absolute;
7760: }
7761:
7762: .LCclose-window {
7763: position:absolute;
7764: width:32px;
7765: height:32px;
7766: right:8px;
7767: top:8px;
7768: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7769: text-indent:-99999px;
7770: overflow:hidden;
7771: cursor:pointer;
7772: }
7773:
1.1075.2.141 raeburn 7774: pre.LC_wordwrap {
7775: white-space: pre-wrap;
7776: white-space: -moz-pre-wrap;
7777: white-space: -pre-wrap;
7778: white-space: -o-pre-wrap;
7779: word-wrap: break-word;
7780: }
7781:
1.1075.2.17 raeburn 7782: /*
7783: styles used by TTH when "Default set of options to pass to tth/m
7784: when converting TeX" in course settings has been set
7785:
7786: option passed: -t
7787:
7788: */
7789:
7790: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7791: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7792: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7793: td div.norm {line-height:normal;}
7794:
7795: /*
7796: option passed -y3
7797: */
7798:
7799: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7800: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7801: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7802:
1.1075.2.121 raeburn 7803: #LC_minitab_header {
7804: float:left;
7805: width:100%;
7806: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
7807: font-size:93%;
7808: line-height:normal;
7809: margin: 0.5em 0 0.5em 0;
7810: }
7811: #LC_minitab_header ul {
7812: margin:0;
7813: padding:10px 10px 0;
7814: list-style:none;
7815: }
7816: #LC_minitab_header li {
7817: float:left;
7818: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
7819: margin:0;
7820: padding:0 0 0 9px;
7821: }
7822: #LC_minitab_header a {
7823: display:block;
7824: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
7825: padding:5px 15px 4px 6px;
7826: }
7827: #LC_minitab_header #LC_current_minitab {
7828: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
7829: }
7830: #LC_minitab_header #LC_current_minitab a {
7831: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
7832: padding-bottom:5px;
7833: }
7834:
7835:
1.343 albertel 7836: END
7837: }
7838:
1.306 albertel 7839: =pod
7840:
7841: =item * &headtag()
7842:
7843: Returns a uniform footer for LON-CAPA web pages.
7844:
1.307 albertel 7845: Inputs: $title - optional title for the head
7846: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7847: $args - optional arguments
1.319 albertel 7848: force_register - if is true call registerurl so the remote is
7849: informed
1.415 albertel 7850: redirect -> array ref of
7851: 1- seconds before redirect occurs
7852: 2- url to redirect to
7853: 3- whether the side effect should occur
1.315 albertel 7854: (side effect of setting
7855: $env{'internal.head.redirect'} to the url
7856: redirected too)
1.352 albertel 7857: domain -> force to color decorate a page for a specific
7858: domain
7859: function -> force usage of a specific rolish color scheme
7860: bgcolor -> override the default page bgcolor
1.460 albertel 7861: no_auto_mt_title
7862: -> prevent &mt()ing the title arg
1.464 albertel 7863:
1.306 albertel 7864: =cut
7865:
7866: sub headtag {
1.313 albertel 7867: my ($title,$head_extra,$args) = @_;
1.306 albertel 7868:
1.363 albertel 7869: my $function = $args->{'function'} || &get_users_function();
7870: my $domain = $args->{'domain'} || &determinedomain();
7871: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7872: my $httphost = $args->{'use_absolute'};
1.418 albertel 7873: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7874: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7875: #time(),
1.418 albertel 7876: $env{'environment.color.timestamp'},
1.363 albertel 7877: $function,$domain,$bgcolor);
7878:
1.369 www 7879: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7880:
1.308 albertel 7881: my $result =
7882: '<head>'.
1.1075.2.56 raeburn 7883: &font_settings($args);
1.319 albertel 7884:
1.1075.2.72 raeburn 7885: my $inhibitprint;
7886: if ($args->{'print_suppress'}) {
7887: $inhibitprint = &print_suppression();
7888: }
1.1064 raeburn 7889:
1.461 albertel 7890: if (!$args->{'frameset'}) {
7891: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7892: }
1.1075.2.12 raeburn 7893: if ($args->{'force_register'}) {
7894: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7895: }
1.436 albertel 7896: if (!$args->{'no_nav_bar'}
7897: && !$args->{'only_body'}
7898: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7899: $result .= &help_menu_js($httphost);
1.1032 www 7900: $result.=&modal_window();
1.1038 www 7901: $result.=&togglebox_script();
1.1034 www 7902: $result.=&wishlist_window();
1.1041 www 7903: $result.=&LCprogressbarUpdate_script();
1.1034 www 7904: } else {
7905: if ($args->{'add_modal'}) {
7906: $result.=&modal_window();
7907: }
7908: if ($args->{'add_wishlist'}) {
7909: $result.=&wishlist_window();
7910: }
1.1038 www 7911: if ($args->{'add_togglebox'}) {
7912: $result.=&togglebox_script();
7913: }
1.1041 www 7914: if ($args->{'add_progressbar'}) {
7915: $result.=&LCprogressbarUpdate_script();
7916: }
1.436 albertel 7917: }
1.314 albertel 7918: if (ref($args->{'redirect'})) {
1.414 albertel 7919: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7920: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7921: if (!$inhibit_continue) {
7922: $env{'internal.head.redirect'} = $url;
7923: }
1.313 albertel 7924: $result.=<<ADDMETA
7925: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7926: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7927: ADDMETA
1.1075.2.89 raeburn 7928: } else {
7929: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
7930: my $requrl = $env{'request.uri'};
7931: if ($requrl eq '') {
7932: $requrl = $ENV{'REQUEST_URI'};
7933: $requrl =~ s/\?.+$//;
7934: }
7935: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
7936: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
7937: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
7938: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
7939: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
7940: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1075.2.145 raeburn 7941: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7942: my $offload;
1.1075.2.89 raeburn 7943: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
7944: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1075.2.145 raeburn 7945: $offload = 1;
7946: }
7947: }
7948: unless ($offload) {
7949: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
7950: if ($domdefs{'offloadoth'}{$lonhost}) {
7951: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
7952: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
7953: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
7954: $offload = 1;
7955: $dom_in_use = $env{'user.domain'};
7956: }
1.1075.2.89 raeburn 7957: }
1.1075.2.145 raeburn 7958: }
7959: }
7960: }
7961: if ($offload) {
7962: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
7963: if (($newserver) && ($newserver ne $lonhost)) {
7964: my $numsec = 5;
7965: my $timeout = $numsec * 1000;
7966: my ($newurl,$locknum,%locks,$msg);
7967: if ($env{'request.role.adv'}) {
7968: ($locknum,%locks) = &Apache::lonnet::get_locks();
7969: }
7970: my $disable_submit = 0;
7971: if ($requrl =~ /$LONCAPA::assess_re/) {
7972: $disable_submit = 1;
7973: }
7974: if ($locknum) {
7975: my @lockinfo = sort(values(%locks));
7976: $msg = &mt('Once the following tasks are complete: ')."\n".
7977: join(", ",sort(values(%locks)))."\n";
7978: if (&show_course()) {
7979: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
1.1075.2.89 raeburn 7980: } else {
1.1075.2.145 raeburn 7981: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
7982: }
7983: } else {
7984: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
7985: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
7986: }
7987: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
7988: $newurl = '/adm/switchserver?otherserver='.$newserver;
7989: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
7990: $newurl .= '&role='.$env{'request.role'};
7991: }
7992: if ($env{'request.symb'}) {
7993: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
7994: if ($shownsymb =~ m{^/enc/}) {
7995: my $reqdmajor = 2;
7996: my $reqdminor = 11;
7997: my $reqdsubminor = 3;
7998: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
7999: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8000: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8001: if (($major eq '' && $minor eq '') ||
8002: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8003: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8004: ($reqdsubminor > $subminor))))) {
8005: undef($shownsymb);
8006: }
1.1075.2.89 raeburn 8007: }
1.1075.2.145 raeburn 8008: if ($shownsymb) {
8009: &js_escape(\$shownsymb);
8010: $newurl .= '&symb='.$shownsymb;
1.1075.2.89 raeburn 8011: }
1.1075.2.145 raeburn 8012: } else {
8013: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8014: &js_escape(\$shownurl);
8015: $newurl .= '&origurl='.$shownurl;
1.1075.2.89 raeburn 8016: }
1.1075.2.145 raeburn 8017: }
8018: &js_escape(\$msg);
8019: $result.=<<OFFLOAD
1.1075.2.89 raeburn 8020: <meta http-equiv="pragma" content="no-cache" />
8021: <script type="text/javascript">
1.1075.2.92 raeburn 8022: // <![CDATA[
1.1075.2.89 raeburn 8023: function LC_Offload_Now() {
8024: var dest = "$newurl";
8025: if (dest != '') {
8026: window.location.href="$newurl";
8027: }
8028: }
1.1075.2.92 raeburn 8029: \$(document).ready(function () {
8030: window.alert('$msg');
8031: if ($disable_submit) {
1.1075.2.89 raeburn 8032: \$(".LC_hwk_submit").prop("disabled", true);
8033: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 8034: }
8035: setTimeout('LC_Offload_Now()', $timeout);
8036: });
8037: // ]]>
1.1075.2.89 raeburn 8038: </script>
8039: OFFLOAD
8040: }
8041: }
8042: }
8043: }
8044: }
1.313 albertel 8045: }
1.306 albertel 8046: if (!defined($title)) {
8047: $title = 'The LearningOnline Network with CAPA';
8048: }
1.460 albertel 8049: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8050: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 8051: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8052: if (!$args->{'frameset'}) {
8053: $result .= ' /';
8054: }
8055: $result .= '>'
1.1064 raeburn 8056: .$inhibitprint
1.414 albertel 8057: .$head_extra;
1.1075.2.108 raeburn 8058: my $clientmobile;
8059: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8060: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8061: } else {
8062: $clientmobile = $env{'browser.mobile'};
8063: }
8064: if ($clientmobile) {
1.1075.2.42 raeburn 8065: $result .= '
8066: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8067: <meta name="apple-mobile-web-app-capable" content="yes" />';
8068: }
1.1075.2.126 raeburn 8069: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8070: return $result.'</head>';
1.306 albertel 8071: }
8072:
8073: =pod
8074:
1.340 albertel 8075: =item * &font_settings()
8076:
8077: Returns neccessary <meta> to set the proper encoding
8078:
1.1075.2.56 raeburn 8079: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8080:
8081: =cut
8082:
8083: sub font_settings {
1.1075.2.56 raeburn 8084: my ($args) = @_;
1.340 albertel 8085: my $headerstring='';
1.1075.2.56 raeburn 8086: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8087: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 8088: $headerstring.=
1.1075.2.61 raeburn 8089: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8090: if (!$args->{'frameset'}) {
8091: $headerstring.= ' /';
8092: }
8093: $headerstring .= '>'."\n";
1.340 albertel 8094: }
8095: return $headerstring;
8096: }
8097:
1.341 albertel 8098: =pod
8099:
1.1064 raeburn 8100: =item * &print_suppression()
8101:
8102: In course context returns css which causes the body to be blank when media="print",
8103: if printout generation is unavailable for the current resource.
8104:
8105: This could be because:
8106:
8107: (a) printstartdate is in the future
8108:
8109: (b) printenddate is in the past
8110:
8111: (c) there is an active exam block with "printout"
8112: functionality blocked
8113:
8114: Users with pav, pfo or evb privileges are exempt.
8115:
8116: Inputs: none
8117:
8118: =cut
8119:
8120:
8121: sub print_suppression {
8122: my $noprint;
8123: if ($env{'request.course.id'}) {
8124: my $scope = $env{'request.course.id'};
8125: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8126: (&Apache::lonnet::allowed('pfo',$scope))) {
8127: return;
8128: }
8129: if ($env{'request.course.sec'} ne '') {
8130: $scope .= "/$env{'request.course.sec'}";
8131: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8132: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8133: return;
1.1064 raeburn 8134: }
8135: }
8136: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8137: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.73 raeburn 8138: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8139: if ($blocked) {
8140: my $checkrole = "cm./$cdom/$cnum";
8141: if ($env{'request.course.sec'} ne '') {
8142: $checkrole .= "/$env{'request.course.sec'}";
8143: }
8144: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8145: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8146: $noprint = 1;
8147: }
8148: }
8149: unless ($noprint) {
8150: my $symb = &Apache::lonnet::symbread();
8151: if ($symb ne '') {
8152: my $navmap = Apache::lonnavmaps::navmap->new();
8153: if (ref($navmap)) {
8154: my $res = $navmap->getBySymb($symb);
8155: if (ref($res)) {
8156: if (!$res->resprintable()) {
8157: $noprint = 1;
8158: }
8159: }
8160: }
8161: }
8162: }
8163: if ($noprint) {
8164: return <<"ENDSTYLE";
8165: <style type="text/css" media="print">
8166: body { display:none }
8167: </style>
8168: ENDSTYLE
8169: }
8170: }
8171: return;
8172: }
8173:
8174: =pod
8175:
1.341 albertel 8176: =item * &xml_begin()
8177:
8178: Returns the needed doctype and <html>
8179:
8180: Inputs: none
8181:
8182: =cut
8183:
8184: sub xml_begin {
1.1075.2.61 raeburn 8185: my ($is_frameset) = @_;
1.341 albertel 8186: my $output='';
8187:
8188: if ($env{'browser.mathml'}) {
8189: $output='<?xml version="1.0"?>'
8190: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8191: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8192:
8193: # .'<!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">] >'
8194: .'<!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">'
8195: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8196: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8197: } elsif ($is_frameset) {
8198: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8199: '<html>'."\n";
1.341 albertel 8200: } else {
1.1075.2.61 raeburn 8201: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8202: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8203: }
8204: return $output;
8205: }
1.340 albertel 8206:
8207: =pod
8208:
1.306 albertel 8209: =item * &start_page()
8210:
8211: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8212:
1.648 raeburn 8213: Inputs:
8214:
8215: =over 4
8216:
8217: $title - optional title for the page
8218:
8219: $head_extra - optional extra HTML to incude inside the <head>
8220:
8221: $args - additional optional args supported are:
8222:
8223: =over 8
8224:
8225: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8226: arg on
1.814 bisitz 8227: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8228: add_entries -> additional attributes to add to the <body>
8229: domain -> force to color decorate a page for a
1.317 albertel 8230: specific domain
1.648 raeburn 8231: function -> force usage of a specific rolish color
1.317 albertel 8232: scheme
1.648 raeburn 8233: redirect -> see &headtag()
8234: bgcolor -> override the default page bg color
8235: js_ready -> return a string ready for being used in
1.317 albertel 8236: a javascript writeln
1.648 raeburn 8237: html_encode -> return a string ready for being used in
1.320 albertel 8238: a html attribute
1.648 raeburn 8239: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8240: $forcereg arg
1.648 raeburn 8241: frameset -> if true will start with a <frameset>
1.330 albertel 8242: rather than <body>
1.648 raeburn 8243: skip_phases -> hash ref of
1.338 albertel 8244: head -> skip the <html><head> generation
8245: body -> skip all <body> generation
1.1075.2.12 raeburn 8246: no_inline_link -> if true and in remote mode, don't show the
8247: 'Switch To Inline Menu' link
1.648 raeburn 8248: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8249: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8250: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 8251: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8252: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8253: group -> includes the current group, if page is for a
8254: specific group
1.1075.2.133 raeburn 8255: use_absolute -> for request for external resource or syllabus, this
8256: will contain https://<hostname> if server uses
8257: https (as per hosts.tab), but request is for http
8258: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8259:
1.648 raeburn 8260: =back
1.460 albertel 8261:
1.648 raeburn 8262: =back
1.562 albertel 8263:
1.306 albertel 8264: =cut
8265:
8266: sub start_page {
1.309 albertel 8267: my ($title,$head_extra,$args) = @_;
1.318 albertel 8268: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8269:
1.315 albertel 8270: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 8271: my ($result,@advtools);
1.964 droeschl 8272:
1.338 albertel 8273: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8274: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8275: }
8276:
8277: if (! exists($args->{'skip_phases'}{'body'}) ) {
8278: if ($args->{'frameset'}) {
8279: my $attr_string = &make_attr_string($args->{'force_register'},
8280: $args->{'add_entries'});
8281: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8282: } else {
8283: $result .=
8284: &bodytag($title,
8285: $args->{'function'}, $args->{'add_entries'},
8286: $args->{'only_body'}, $args->{'domain'},
8287: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 8288: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 8289: $args, \@advtools);
1.831 bisitz 8290: }
1.330 albertel 8291: }
1.338 albertel 8292:
1.315 albertel 8293: if ($args->{'js_ready'}) {
1.713 kaisler 8294: $result = &js_ready($result);
1.315 albertel 8295: }
1.320 albertel 8296: if ($args->{'html_encode'}) {
1.713 kaisler 8297: $result = &html_encode($result);
8298: }
8299:
1.813 bisitz 8300: # Preparation for new and consistent functionlist at top of screen
8301: # if ($args->{'functionlist'}) {
8302: # $result .= &build_functionlist();
8303: #}
8304:
1.964 droeschl 8305: # Don't add anything more if only_body wanted or in const space
8306: return $result if $args->{'only_body'}
8307: || $env{'request.state'} eq 'construct';
1.813 bisitz 8308:
8309: #Breadcrumbs
1.758 kaisler 8310: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8311: &Apache::lonhtmlcommon::clear_breadcrumbs();
8312: #if any br links exists, add them to the breadcrumbs
8313: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8314: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8315: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8316: }
8317: }
1.1075.2.19 raeburn 8318: # if @advtools array contains items add then to the breadcrumbs
8319: if (@advtools > 0) {
8320: &Apache::lonmenu::advtools_crumbs(@advtools);
8321: }
1.1075.2.123 raeburn 8322: my $menulink;
8323: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8324: if (exists($args->{'bread_crumbs_nomenu'})) {
8325: $menulink = 0;
8326: } else {
8327: undef($menulink);
8328: }
1.758 kaisler 8329: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8330: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 8331: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.758 kaisler 8332: }else{
1.1075.2.123 raeburn 8333: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8334: }
1.1075.2.24 raeburn 8335: } elsif (($env{'environment.remote'} eq 'on') &&
8336: ($env{'form.inhibitmenu'} ne 'yes') &&
8337: ($env{'request.noversionuri'} =~ m{^/res/}) &&
8338: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 8339: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 8340: }
1.315 albertel 8341: return $result;
1.306 albertel 8342: }
8343:
8344: sub end_page {
1.315 albertel 8345: my ($args) = @_;
8346: $env{'internal.end_page'}++;
1.330 albertel 8347: my $result;
1.335 albertel 8348: if ($args->{'discussion'}) {
8349: my ($target,$parser);
8350: if (ref($args->{'discussion'})) {
8351: ($target,$parser) =($args->{'discussion'}{'target'},
8352: $args->{'discussion'}{'parser'});
8353: }
8354: $result .= &Apache::lonxml::xmlend($target,$parser);
8355: }
1.330 albertel 8356: if ($args->{'frameset'}) {
8357: $result .= '</frameset>';
8358: } else {
1.635 raeburn 8359: $result .= &endbodytag($args);
1.330 albertel 8360: }
1.1075.2.6 raeburn 8361: unless ($args->{'notbody'}) {
8362: $result .= "\n</html>";
8363: }
1.330 albertel 8364:
1.315 albertel 8365: if ($args->{'js_ready'}) {
1.317 albertel 8366: $result = &js_ready($result);
1.315 albertel 8367: }
1.335 albertel 8368:
1.320 albertel 8369: if ($args->{'html_encode'}) {
8370: $result = &html_encode($result);
8371: }
1.335 albertel 8372:
1.315 albertel 8373: return $result;
8374: }
8375:
1.1034 www 8376: sub wishlist_window {
8377: return(<<'ENDWISHLIST');
1.1046 raeburn 8378: <script type="text/javascript">
1.1034 www 8379: // <![CDATA[
8380: // <!-- BEGIN LON-CAPA Internal
8381: function set_wishlistlink(title, path) {
8382: if (!title) {
8383: title = document.title;
8384: title = title.replace(/^LON-CAPA /,'');
8385: }
1.1075.2.65 raeburn 8386: title = encodeURIComponent(title);
1.1075.2.83 raeburn 8387: title = title.replace("'","\\\'");
1.1034 www 8388: if (!path) {
8389: path = location.pathname;
8390: }
1.1075.2.65 raeburn 8391: path = encodeURIComponent(path);
1.1075.2.83 raeburn 8392: path = path.replace("'","\\\'");
1.1034 www 8393: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8394: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8395: }
8396: // END LON-CAPA Internal -->
8397: // ]]>
8398: </script>
8399: ENDWISHLIST
8400: }
8401:
1.1030 www 8402: sub modal_window {
8403: return(<<'ENDMODAL');
1.1046 raeburn 8404: <script type="text/javascript">
1.1030 www 8405: // <![CDATA[
8406: // <!-- BEGIN LON-CAPA Internal
8407: var modalWindow = {
8408: parent:"body",
8409: windowId:null,
8410: content:null,
8411: width:null,
8412: height:null,
8413: close:function()
8414: {
8415: $(".LCmodal-window").remove();
8416: $(".LCmodal-overlay").remove();
8417: },
8418: open:function()
8419: {
8420: var modal = "";
8421: modal += "<div class=\"LCmodal-overlay\"></div>";
8422: 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;\">";
8423: modal += this.content;
8424: modal += "</div>";
8425:
8426: $(this.parent).append(modal);
8427:
8428: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8429: $(".LCclose-window").click(function(){modalWindow.close();});
8430: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8431: }
8432: };
1.1075.2.42 raeburn 8433: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8434: {
1.1075.2.119 raeburn 8435: source = source.replace(/'/g,"'");
1.1030 www 8436: modalWindow.windowId = "myModal";
8437: modalWindow.width = width;
8438: modalWindow.height = height;
1.1075.2.80 raeburn 8439: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8440: modalWindow.open();
1.1075.2.87 raeburn 8441: };
1.1030 www 8442: // END LON-CAPA Internal -->
8443: // ]]>
8444: </script>
8445: ENDMODAL
8446: }
8447:
8448: sub modal_link {
1.1075.2.42 raeburn 8449: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8450: unless ($width) { $width=480; }
8451: unless ($height) { $height=400; }
1.1031 www 8452: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 8453: unless ($transparency) { $transparency='true'; }
8454:
1.1074 raeburn 8455: my $target_attr;
8456: if (defined($target)) {
8457: $target_attr = 'target="'.$target.'"';
8458: }
8459: return <<"ENDLINK";
1.1075.2.143 raeburn 8460: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 8461: ENDLINK
1.1030 www 8462: }
8463:
1.1032 www 8464: sub modal_adhoc_script {
8465: my ($funcname,$width,$height,$content)=@_;
8466: return (<<ENDADHOC);
1.1046 raeburn 8467: <script type="text/javascript">
1.1032 www 8468: // <![CDATA[
8469: var $funcname = function()
8470: {
8471: modalWindow.windowId = "myModal";
8472: modalWindow.width = $width;
8473: modalWindow.height = $height;
8474: modalWindow.content = '$content';
8475: modalWindow.open();
8476: };
8477: // ]]>
8478: </script>
8479: ENDADHOC
8480: }
8481:
1.1041 www 8482: sub modal_adhoc_inner {
8483: my ($funcname,$width,$height,$content)=@_;
8484: my $innerwidth=$width-20;
8485: $content=&js_ready(
1.1042 www 8486: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 8487: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8488: $content.
1.1041 www 8489: &end_scrollbox().
1.1075.2.42 raeburn 8490: &end_page()
1.1041 www 8491: );
8492: return &modal_adhoc_script($funcname,$width,$height,$content);
8493: }
8494:
8495: sub modal_adhoc_window {
8496: my ($funcname,$width,$height,$content,$linktext)=@_;
8497: return &modal_adhoc_inner($funcname,$width,$height,$content).
8498: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8499: }
8500:
8501: sub modal_adhoc_launch {
8502: my ($funcname,$width,$height,$content)=@_;
8503: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8504: <script type="text/javascript">
8505: // <![CDATA[
8506: $funcname();
8507: // ]]>
8508: </script>
8509: ENDLAUNCH
8510: }
8511:
8512: sub modal_adhoc_close {
8513: return (<<ENDCLOSE);
8514: <script type="text/javascript">
8515: // <![CDATA[
8516: modalWindow.close();
8517: // ]]>
8518: </script>
8519: ENDCLOSE
8520: }
8521:
1.1038 www 8522: sub togglebox_script {
8523: return(<<ENDTOGGLE);
8524: <script type="text/javascript">
8525: // <![CDATA[
8526: function LCtoggleDisplay(id,hidetext,showtext) {
8527: link = document.getElementById(id + "link").childNodes[0];
8528: with (document.getElementById(id).style) {
8529: if (display == "none" ) {
8530: display = "inline";
8531: link.nodeValue = hidetext;
8532: } else {
8533: display = "none";
8534: link.nodeValue = showtext;
8535: }
8536: }
8537: }
8538: // ]]>
8539: </script>
8540: ENDTOGGLE
8541: }
8542:
1.1039 www 8543: sub start_togglebox {
8544: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8545: unless ($heading) { $heading=''; } else { $heading.=' '; }
8546: unless ($showtext) { $showtext=&mt('show'); }
8547: unless ($hidetext) { $hidetext=&mt('hide'); }
8548: unless ($headerbg) { $headerbg='#FFFFFF'; }
8549: return &start_data_table().
8550: &start_data_table_header_row().
8551: '<td bgcolor="'.$headerbg.'">'.$heading.
8552: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8553: $showtext.'\')">'.$showtext.'</a>]</td>'.
8554: &end_data_table_header_row().
8555: '<tr id="'.$id.'" style="display:none""><td>';
8556: }
8557:
8558: sub end_togglebox {
8559: return '</td></tr>'.&end_data_table();
8560: }
8561:
1.1041 www 8562: sub LCprogressbar_script {
1.1075.2.130 raeburn 8563: my ($id,$number_to_do)=@_;
8564: if ($number_to_do) {
8565: return(<<ENDPROGRESS);
1.1041 www 8566: <script type="text/javascript">
8567: // <![CDATA[
1.1045 www 8568: \$('#progressbar$id').progressbar({
1.1041 www 8569: value: 0,
8570: change: function(event, ui) {
8571: var newVal = \$(this).progressbar('option', 'value');
8572: \$('.pblabel', this).text(LCprogressTxt);
8573: }
8574: });
8575: // ]]>
8576: </script>
8577: ENDPROGRESS
1.1075.2.130 raeburn 8578: } else {
8579: return(<<ENDPROGRESS);
8580: <script type="text/javascript">
8581: // <![CDATA[
8582: \$('#progressbar$id').progressbar({
8583: value: false,
8584: create: function(event, ui) {
8585: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
8586: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
8587: }
8588: });
8589: // ]]>
8590: </script>
8591: ENDPROGRESS
8592: }
1.1041 www 8593: }
8594:
8595: sub LCprogressbarUpdate_script {
8596: return(<<ENDPROGRESSUPDATE);
8597: <style type="text/css">
8598: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 8599: .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 8600: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8601: </style>
8602: <script type="text/javascript">
8603: // <![CDATA[
1.1045 www 8604: var LCprogressTxt='---';
8605:
1.1075.2.130 raeburn 8606: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 8607: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 8608: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
8609: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
8610: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
8611: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
8612: } else {
8613: \$('#progressbar'+id).progressbar('value',percent);
8614: }
1.1041 www 8615: }
8616: // ]]>
8617: </script>
8618: ENDPROGRESSUPDATE
8619: }
8620:
1.1042 www 8621: my $LClastpercent;
1.1045 www 8622: my $LCidcnt;
8623: my $LCcurrentid;
1.1042 www 8624:
1.1041 www 8625: sub LCprogressbar {
1.1075.2.130 raeburn 8626: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 8627: $LClastpercent=0;
1.1045 www 8628: $LCidcnt++;
8629: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 8630: my ($starting,$content);
8631: if ($number_to_do) {
8632: $starting=&mt('Starting');
8633: $content=(<<ENDPROGBAR);
8634: $preamble
1.1045 www 8635: <div id="progressbar$LCcurrentid">
1.1041 www 8636: <span class="pblabel">$starting</span>
8637: </div>
8638: ENDPROGBAR
1.1075.2.130 raeburn 8639: } else {
8640: $starting=&mt('Loading...');
8641: $LClastpercent='false';
8642: $content=(<<ENDPROGBAR);
8643: $preamble
8644: <div id="progressbar$LCcurrentid">
8645: <div class="progress-label">$starting</div>
8646: </div>
8647: ENDPROGBAR
8648: }
8649: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 8650: }
8651:
8652: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 8653: my ($r,$val,$text,$number_to_do)=@_;
8654: if ($number_to_do) {
8655: unless ($val) {
8656: if ($LClastpercent) {
8657: $val=$LClastpercent;
8658: } else {
8659: $val=0;
8660: }
8661: }
8662: if ($val<0) { $val=0; }
8663: if ($val>100) { $val=0; }
8664: $LClastpercent=$val;
8665: unless ($text) { $text=$val.'%'; }
8666: } else {
8667: $val = 'false';
1.1042 www 8668: }
1.1041 www 8669: $text=&js_ready($text);
1.1044 www 8670: &r_print($r,<<ENDUPDATE);
1.1041 www 8671: <script type="text/javascript">
8672: // <![CDATA[
1.1075.2.130 raeburn 8673: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 8674: // ]]>
8675: </script>
8676: ENDUPDATE
1.1035 www 8677: }
8678:
1.1042 www 8679: sub LCprogressbarClose {
8680: my ($r)=@_;
8681: $LClastpercent=0;
1.1044 www 8682: &r_print($r,<<ENDCLOSE);
1.1042 www 8683: <script type="text/javascript">
8684: // <![CDATA[
1.1045 www 8685: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8686: // ]]>
8687: </script>
8688: ENDCLOSE
1.1044 www 8689: }
8690:
8691: sub r_print {
8692: my ($r,$to_print)=@_;
8693: if ($r) {
8694: $r->print($to_print);
8695: $r->rflush();
8696: } else {
8697: print($to_print);
8698: }
1.1042 www 8699: }
8700:
1.320 albertel 8701: sub html_encode {
8702: my ($result) = @_;
8703:
1.322 albertel 8704: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8705:
8706: return $result;
8707: }
1.1044 www 8708:
1.317 albertel 8709: sub js_ready {
8710: my ($result) = @_;
8711:
1.323 albertel 8712: $result =~ s/[\n\r]/ /xmsg;
8713: $result =~ s/\\/\\\\/xmsg;
8714: $result =~ s/'/\\'/xmsg;
1.372 albertel 8715: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8716:
8717: return $result;
8718: }
8719:
1.315 albertel 8720: sub validate_page {
8721: if ( exists($env{'internal.start_page'})
1.316 albertel 8722: && $env{'internal.start_page'} > 1) {
8723: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8724: $env{'internal.start_page'}.' '.
1.316 albertel 8725: $ENV{'request.filename'});
1.315 albertel 8726: }
8727: if ( exists($env{'internal.end_page'})
1.316 albertel 8728: && $env{'internal.end_page'} > 1) {
8729: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8730: $env{'internal.end_page'}.' '.
1.316 albertel 8731: $env{'request.filename'});
1.315 albertel 8732: }
8733: if ( exists($env{'internal.start_page'})
8734: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8735: &Apache::lonnet::logthis('start_page called without end_page '.
8736: $env{'request.filename'});
1.315 albertel 8737: }
8738: if ( ! exists($env{'internal.start_page'})
8739: && exists($env{'internal.end_page'})) {
1.316 albertel 8740: &Apache::lonnet::logthis('end_page called without start_page'.
8741: $env{'request.filename'});
1.315 albertel 8742: }
1.306 albertel 8743: }
1.315 albertel 8744:
1.996 www 8745:
8746: sub start_scrollbox {
1.1075.2.56 raeburn 8747: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8748: unless ($outerwidth) { $outerwidth='520px'; }
8749: unless ($width) { $width='500px'; }
8750: unless ($height) { $height='200px'; }
1.1075 raeburn 8751: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8752: if ($id ne '') {
1.1075.2.42 raeburn 8753: $table_id = ' id="table_'.$id.'"';
8754: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8755: }
1.1075 raeburn 8756: if ($bgcolor ne '') {
8757: $tdcol = "background-color: $bgcolor;";
8758: }
1.1075.2.42 raeburn 8759: my $nicescroll_js;
8760: if ($env{'browser.mobile'}) {
8761: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8762: }
1.1075 raeburn 8763: return <<"END";
1.1075.2.42 raeburn 8764: $nicescroll_js
8765:
8766: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8767: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8768: END
1.996 www 8769: }
8770:
8771: sub end_scrollbox {
1.1036 www 8772: return '</div></td></tr></table>';
1.996 www 8773: }
8774:
1.1075.2.42 raeburn 8775: sub nicescroll_javascript {
8776: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8777: my %options;
8778: if (ref($cursor) eq 'HASH') {
8779: %options = %{$cursor};
8780: }
8781: unless ($options{'railalign'} =~ /^left|right$/) {
8782: $options{'railalign'} = 'left';
8783: }
8784: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8785: my $function = &get_users_function();
8786: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8787: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8788: $options{'cursorcolor'} = '#00F';
8789: }
8790: }
8791: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8792: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8793: $options{'cursoropacity'}='1.0';
8794: }
8795: } else {
8796: $options{'cursoropacity'}='1.0';
8797: }
8798: if ($options{'cursorfixedheight'} eq 'none') {
8799: delete($options{'cursorfixedheight'});
8800: } else {
8801: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8802: }
8803: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8804: delete($options{'railoffset'});
8805: }
8806: my @niceoptions;
8807: while (my($key,$value) = each(%options)) {
8808: if ($value =~ /^\{.+\}$/) {
8809: push(@niceoptions,$key.':'.$value);
8810: } else {
8811: push(@niceoptions,$key.':"'.$value.'"');
8812: }
8813: }
8814: my $nicescroll_js = '
8815: $(document).ready(
8816: function() {
8817: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8818: }
8819: );
8820: ';
8821: if ($framecheck) {
8822: $nicescroll_js .= '
8823: function expand_div(caller) {
8824: if (top === self) {
8825: document.getElementById("'.$id.'").style.width = "auto";
8826: document.getElementById("'.$id.'").style.height = "auto";
8827: } else {
8828: try {
8829: if (parent.frames) {
8830: if (parent.frames.length > 1) {
8831: var framesrc = parent.frames[1].location.href;
8832: var currsrc = framesrc.replace(/\#.*$/,"");
8833: if ((caller == "search") || (currsrc == "'.$location.'")) {
8834: document.getElementById("'.$id.'").style.width = "auto";
8835: document.getElementById("'.$id.'").style.height = "auto";
8836: }
8837: }
8838: }
8839: } catch (e) {
8840: return;
8841: }
8842: }
8843: return;
8844: }
8845: ';
8846: }
8847: if ($needjsready) {
8848: $nicescroll_js = '
8849: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8850: } else {
8851: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8852: }
8853: return $nicescroll_js;
8854: }
8855:
1.318 albertel 8856: sub simple_error_page {
1.1075.2.49 raeburn 8857: my ($r,$title,$msg,$args) = @_;
8858: if (ref($args) eq 'HASH') {
8859: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8860: } else {
8861: $msg = &mt($msg);
8862: }
8863:
1.318 albertel 8864: my $page =
8865: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8866: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8867: &Apache::loncommon::end_page();
8868: if (ref($r)) {
8869: $r->print($page);
1.327 albertel 8870: return;
1.318 albertel 8871: }
8872: return $page;
8873: }
1.347 albertel 8874:
8875: {
1.610 albertel 8876: my @row_count;
1.961 onken 8877:
8878: sub start_data_table_count {
8879: unshift(@row_count, 0);
8880: return;
8881: }
8882:
8883: sub end_data_table_count {
8884: shift(@row_count);
8885: return;
8886: }
8887:
1.347 albertel 8888: sub start_data_table {
1.1018 raeburn 8889: my ($add_class,$id) = @_;
1.422 albertel 8890: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8891: my $table_id;
8892: if (defined($id)) {
8893: $table_id = ' id="'.$id.'"';
8894: }
1.961 onken 8895: &start_data_table_count();
1.1018 raeburn 8896: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8897: }
8898:
8899: sub end_data_table {
1.961 onken 8900: &end_data_table_count();
1.389 albertel 8901: return '</table>'."\n";;
1.347 albertel 8902: }
8903:
8904: sub start_data_table_row {
1.974 wenzelju 8905: my ($add_class, $id) = @_;
1.610 albertel 8906: $row_count[0]++;
8907: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8908: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8909: $id = (' id="'.$id.'"') unless ($id eq '');
8910: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8911: }
1.471 banghart 8912:
8913: sub continue_data_table_row {
1.974 wenzelju 8914: my ($add_class, $id) = @_;
1.610 albertel 8915: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8916: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8917: $id = (' id="'.$id.'"') unless ($id eq '');
8918: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8919: }
1.347 albertel 8920:
8921: sub end_data_table_row {
1.389 albertel 8922: return '</tr>'."\n";;
1.347 albertel 8923: }
1.367 www 8924:
1.421 albertel 8925: sub start_data_table_empty_row {
1.707 bisitz 8926: # $row_count[0]++;
1.421 albertel 8927: return '<tr class="LC_empty_row" >'."\n";;
8928: }
8929:
8930: sub end_data_table_empty_row {
8931: return '</tr>'."\n";;
8932: }
8933:
1.367 www 8934: sub start_data_table_header_row {
1.389 albertel 8935: return '<tr class="LC_header_row">'."\n";;
1.367 www 8936: }
8937:
8938: sub end_data_table_header_row {
1.389 albertel 8939: return '</tr>'."\n";;
1.367 www 8940: }
1.890 droeschl 8941:
8942: sub data_table_caption {
8943: my $caption = shift;
8944: return "<caption class=\"LC_caption\">$caption</caption>";
8945: }
1.347 albertel 8946: }
8947:
1.548 albertel 8948: =pod
8949:
8950: =item * &inhibit_menu_check($arg)
8951:
8952: Checks for a inhibitmenu state and generates output to preserve it
8953:
8954: Inputs: $arg - can be any of
8955: - undef - in which case the return value is a string
8956: to add into arguments list of a uri
8957: - 'input' - in which case the return value is a HTML
8958: <form> <input> field of type hidden to
8959: preserve the value
8960: - a url - in which case the return value is the url with
8961: the neccesary cgi args added to preserve the
8962: inhibitmenu state
8963: - a ref to a url - no return value, but the string is
8964: updated to include the neccessary cgi
8965: args to preserve the inhibitmenu state
8966:
8967: =cut
8968:
8969: sub inhibit_menu_check {
8970: my ($arg) = @_;
8971: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8972: if ($arg eq 'input') {
8973: if ($env{'form.inhibitmenu'}) {
8974: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8975: } else {
8976: return
8977: }
8978: }
8979: if ($env{'form.inhibitmenu'}) {
8980: if (ref($arg)) {
8981: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8982: } elsif ($arg eq '') {
8983: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8984: } else {
8985: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8986: }
8987: }
8988: if (!ref($arg)) {
8989: return $arg;
8990: }
8991: }
8992:
1.251 albertel 8993: ###############################################
1.182 matthew 8994:
8995: =pod
8996:
1.549 albertel 8997: =back
8998:
8999: =head1 User Information Routines
9000:
9001: =over 4
9002:
1.405 albertel 9003: =item * &get_users_function()
1.182 matthew 9004:
9005: Used by &bodytag to determine the current users primary role.
9006: Returns either 'student','coordinator','admin', or 'author'.
9007:
9008: =cut
9009:
9010: ###############################################
9011: sub get_users_function {
1.815 tempelho 9012: my $function = 'norole';
1.818 tempelho 9013: if ($env{'request.role'}=~/^(st)/) {
9014: $function='student';
9015: }
1.907 raeburn 9016: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9017: $function='coordinator';
9018: }
1.258 albertel 9019: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9020: $function='admin';
9021: }
1.826 bisitz 9022: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9023: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9024: $function='author';
9025: }
9026: return $function;
1.54 www 9027: }
1.99 www 9028:
9029: ###############################################
9030:
1.233 raeburn 9031: =pod
9032:
1.821 raeburn 9033: =item * &show_course()
9034:
9035: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9036: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9037:
9038: Inputs:
9039: None
9040:
9041: Outputs:
9042: Scalar: 1 if 'Course' to be used, 0 otherwise.
9043:
9044: =cut
9045:
9046: ###############################################
9047: sub show_course {
9048: my $course = !$env{'user.adv'};
9049: if (!$env{'user.adv'}) {
9050: foreach my $env (keys(%env)) {
9051: next if ($env !~ m/^user\.priv\./);
9052: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9053: $course = 0;
9054: last;
9055: }
9056: }
9057: }
9058: return $course;
9059: }
9060:
9061: ###############################################
9062:
9063: =pod
9064:
1.542 raeburn 9065: =item * &check_user_status()
1.274 raeburn 9066:
9067: Determines current status of supplied role for a
9068: specific user. Roles can be active, previous or future.
9069:
9070: Inputs:
9071: user's domain, user's username, course's domain,
1.375 raeburn 9072: course's number, optional section ID.
1.274 raeburn 9073:
9074: Outputs:
9075: role status: active, previous or future.
9076:
9077: =cut
9078:
9079: sub check_user_status {
1.412 raeburn 9080: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9081: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 9082: my @uroles = keys(%userinfo);
1.274 raeburn 9083: my $srchstr;
9084: my $active_chk = 'none';
1.412 raeburn 9085: my $now = time;
1.274 raeburn 9086: if (@uroles > 0) {
1.908 raeburn 9087: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9088: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9089: } else {
1.412 raeburn 9090: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9091: }
9092: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9093: my $role_end = 0;
9094: my $role_start = 0;
9095: $active_chk = 'active';
1.412 raeburn 9096: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9097: $role_end = $1;
9098: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9099: $role_start = $1;
1.274 raeburn 9100: }
9101: }
9102: if ($role_start > 0) {
1.412 raeburn 9103: if ($now < $role_start) {
1.274 raeburn 9104: $active_chk = 'future';
9105: }
9106: }
9107: if ($role_end > 0) {
1.412 raeburn 9108: if ($now > $role_end) {
1.274 raeburn 9109: $active_chk = 'previous';
9110: }
9111: }
9112: }
9113: }
9114: return $active_chk;
9115: }
9116:
9117: ###############################################
9118:
9119: =pod
9120:
1.405 albertel 9121: =item * &get_sections()
1.233 raeburn 9122:
9123: Determines all the sections for a course including
9124: sections with students and sections containing other roles.
1.419 raeburn 9125: Incoming parameters:
9126:
9127: 1. domain
9128: 2. course number
9129: 3. reference to array containing roles for which sections should
9130: be gathered (optional).
9131: 4. reference to array containing status types for which sections
9132: should be gathered (optional).
9133:
9134: If the third argument is undefined, sections are gathered for any role.
9135: If the fourth argument is undefined, sections are gathered for any status.
9136: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9137:
1.374 raeburn 9138: Returns section hash (keys are section IDs, values are
9139: number of users in each section), subject to the
1.419 raeburn 9140: optional roles filter, optional status filter
1.233 raeburn 9141:
9142: =cut
9143:
9144: ###############################################
9145: sub get_sections {
1.419 raeburn 9146: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9147: if (!defined($cdom) || !defined($cnum)) {
9148: my $cid = $env{'request.course.id'};
9149:
9150: return if (!defined($cid));
9151:
9152: $cdom = $env{'course.'.$cid.'.domain'};
9153: $cnum = $env{'course.'.$cid.'.num'};
9154: }
9155:
9156: my %sectioncount;
1.419 raeburn 9157: my $now = time;
1.240 albertel 9158:
1.1075.2.33 raeburn 9159: my $check_students = 1;
9160: my $only_students = 0;
9161: if (ref($possible_roles) eq 'ARRAY') {
9162: if (grep(/^st$/,@{$possible_roles})) {
9163: if (@{$possible_roles} == 1) {
9164: $only_students = 1;
9165: }
9166: } else {
9167: $check_students = 0;
9168: }
9169: }
9170:
9171: if ($check_students) {
1.276 albertel 9172: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9173: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9174: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9175: my $start_index = &Apache::loncoursedata::CL_START();
9176: my $end_index = &Apache::loncoursedata::CL_END();
9177: my $status;
1.366 albertel 9178: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9179: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9180: $data->[$status_index],
9181: $data->[$start_index],
9182: $data->[$end_index]);
9183: if ($stu_status eq 'Active') {
9184: $status = 'active';
9185: } elsif ($end < $now) {
9186: $status = 'previous';
9187: } elsif ($start > $now) {
9188: $status = 'future';
9189: }
9190: if ($section ne '-1' && $section !~ /^\s*$/) {
9191: if ((!defined($possible_status)) || (($status ne '') &&
9192: (grep/^\Q$status\E$/,@{$possible_status}))) {
9193: $sectioncount{$section}++;
9194: }
1.240 albertel 9195: }
9196: }
9197: }
1.1075.2.33 raeburn 9198: if ($only_students) {
9199: return %sectioncount;
9200: }
1.240 albertel 9201: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9202: foreach my $user (sort(keys(%courseroles))) {
9203: if ($user !~ /^(\w{2})/) { next; }
9204: my ($role) = ($user =~ /^(\w{2})/);
9205: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9206: my ($section,$status);
1.240 albertel 9207: if ($role eq 'cr' &&
9208: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9209: $section=$1;
9210: }
9211: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9212: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9213: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9214: if ($end == -1 && $start == -1) {
9215: next; #deleted role
9216: }
9217: if (!defined($possible_status)) {
9218: $sectioncount{$section}++;
9219: } else {
9220: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9221: $status = 'active';
9222: } elsif ($end < $now) {
9223: $status = 'future';
9224: } elsif ($start > $now) {
9225: $status = 'previous';
9226: }
9227: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9228: $sectioncount{$section}++;
9229: }
9230: }
1.233 raeburn 9231: }
1.366 albertel 9232: return %sectioncount;
1.233 raeburn 9233: }
9234:
1.274 raeburn 9235: ###############################################
1.294 raeburn 9236:
9237: =pod
1.405 albertel 9238:
9239: =item * &get_course_users()
9240:
1.275 raeburn 9241: Retrieves usernames:domains for users in the specified course
9242: with specific role(s), and access status.
9243:
9244: Incoming parameters:
1.277 albertel 9245: 1. course domain
9246: 2. course number
9247: 3. access status: users must have - either active,
1.275 raeburn 9248: previous, future, or all.
1.277 albertel 9249: 4. reference to array of permissible roles
1.288 raeburn 9250: 5. reference to array of section restrictions (optional)
9251: 6. reference to results object (hash of hashes).
9252: 7. reference to optional userdata hash
1.609 raeburn 9253: 8. reference to optional statushash
1.630 raeburn 9254: 9. flag if privileged users (except those set to unhide in
9255: course settings) should be excluded
1.609 raeburn 9256: Keys of top level results hash are roles.
1.275 raeburn 9257: Keys of inner hashes are username:domain, with
9258: values set to access type.
1.288 raeburn 9259: Optional userdata hash returns an array with arguments in the
9260: same order as loncoursedata::get_classlist() for student data.
9261:
1.609 raeburn 9262: Optional statushash returns
9263:
1.288 raeburn 9264: Entries for end, start, section and status are blank because
9265: of the possibility of multiple values for non-student roles.
9266:
1.275 raeburn 9267: =cut
1.405 albertel 9268:
1.275 raeburn 9269: ###############################################
1.405 albertel 9270:
1.275 raeburn 9271: sub get_course_users {
1.630 raeburn 9272: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9273: my %idx = ();
1.419 raeburn 9274: my %seclists;
1.288 raeburn 9275:
9276: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9277: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9278: $idx{end} = &Apache::loncoursedata::CL_END();
9279: $idx{start} = &Apache::loncoursedata::CL_START();
9280: $idx{id} = &Apache::loncoursedata::CL_ID();
9281: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9282: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9283: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9284:
1.290 albertel 9285: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9286: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9287: my $now = time;
1.277 albertel 9288: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9289: my $match = 0;
1.412 raeburn 9290: my $secmatch = 0;
1.419 raeburn 9291: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9292: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9293: if ($section eq '') {
9294: $section = 'none';
9295: }
1.291 albertel 9296: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9297: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9298: $secmatch = 1;
9299: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9300: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9301: $secmatch = 1;
9302: }
9303: } else {
1.419 raeburn 9304: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9305: $secmatch = 1;
9306: }
1.290 albertel 9307: }
1.412 raeburn 9308: if (!$secmatch) {
9309: next;
9310: }
1.419 raeburn 9311: }
1.275 raeburn 9312: if (defined($$types{'active'})) {
1.288 raeburn 9313: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9314: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9315: $match = 1;
1.275 raeburn 9316: }
9317: }
9318: if (defined($$types{'previous'})) {
1.609 raeburn 9319: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9320: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9321: $match = 1;
1.275 raeburn 9322: }
9323: }
9324: if (defined($$types{'future'})) {
1.609 raeburn 9325: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9326: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9327: $match = 1;
1.275 raeburn 9328: }
9329: }
1.609 raeburn 9330: if ($match) {
9331: push(@{$seclists{$student}},$section);
9332: if (ref($userdata) eq 'HASH') {
9333: $$userdata{$student} = $$classlist{$student};
9334: }
9335: if (ref($statushash) eq 'HASH') {
9336: $statushash->{$student}{'st'}{$section} = $status;
9337: }
1.288 raeburn 9338: }
1.275 raeburn 9339: }
9340: }
1.412 raeburn 9341: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9342: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9343: my $now = time;
1.609 raeburn 9344: my %displaystatus = ( previous => 'Expired',
9345: active => 'Active',
9346: future => 'Future',
9347: );
1.1075.2.36 raeburn 9348: my (%nothide,@possdoms);
1.630 raeburn 9349: if ($hidepriv) {
9350: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9351: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9352: if ($user !~ /:/) {
9353: $nothide{join(':',split(/[\@]/,$user))}=1;
9354: } else {
9355: $nothide{$user} = 1;
9356: }
9357: }
1.1075.2.36 raeburn 9358: my @possdoms = ($cdom);
9359: if ($coursehash{'checkforpriv'}) {
9360: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9361: }
1.630 raeburn 9362: }
1.439 raeburn 9363: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9364: my $match = 0;
1.412 raeburn 9365: my $secmatch = 0;
1.439 raeburn 9366: my $status;
1.412 raeburn 9367: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9368: $user =~ s/:$//;
1.439 raeburn 9369: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9370: if ($end == -1 || $start == -1) {
9371: next;
9372: }
9373: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9374: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9375: my ($uname,$udom) = split(/:/,$user);
9376: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9377: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9378: $secmatch = 1;
9379: } elsif ($usec eq '') {
1.420 albertel 9380: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9381: $secmatch = 1;
9382: }
9383: } else {
9384: if (grep(/^\Q$usec\E$/,@{$sections})) {
9385: $secmatch = 1;
9386: }
9387: }
9388: if (!$secmatch) {
9389: next;
9390: }
1.288 raeburn 9391: }
1.419 raeburn 9392: if ($usec eq '') {
9393: $usec = 'none';
9394: }
1.275 raeburn 9395: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9396: if ($hidepriv) {
1.1075.2.36 raeburn 9397: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9398: (!$nothide{$uname.':'.$udom})) {
9399: next;
9400: }
9401: }
1.503 raeburn 9402: if ($end > 0 && $end < $now) {
1.439 raeburn 9403: $status = 'previous';
9404: } elsif ($start > $now) {
9405: $status = 'future';
9406: } else {
9407: $status = 'active';
9408: }
1.277 albertel 9409: foreach my $type (keys(%{$types})) {
1.275 raeburn 9410: if ($status eq $type) {
1.420 albertel 9411: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9412: push(@{$$users{$role}{$user}},$type);
9413: }
1.288 raeburn 9414: $match = 1;
9415: }
9416: }
1.419 raeburn 9417: if (($match) && (ref($userdata) eq 'HASH')) {
9418: if (!exists($$userdata{$uname.':'.$udom})) {
9419: &get_user_info($udom,$uname,\%idx,$userdata);
9420: }
1.420 albertel 9421: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9422: push(@{$seclists{$uname.':'.$udom}},$usec);
9423: }
1.609 raeburn 9424: if (ref($statushash) eq 'HASH') {
9425: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9426: }
1.275 raeburn 9427: }
9428: }
9429: }
9430: }
1.290 albertel 9431: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9432: if ((defined($cdom)) && (defined($cnum))) {
9433: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9434: if ( defined($csettings{'internal.courseowner'}) ) {
9435: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9436: next if ($owner eq '');
9437: my ($ownername,$ownerdom);
9438: if ($owner =~ /^([^:]+):([^:]+)$/) {
9439: $ownername = $1;
9440: $ownerdom = $2;
9441: } else {
9442: $ownername = $owner;
9443: $ownerdom = $cdom;
9444: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9445: }
9446: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9447: if (defined($userdata) &&
1.609 raeburn 9448: !exists($$userdata{$owner})) {
9449: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9450: if (!grep(/^none$/,@{$seclists{$owner}})) {
9451: push(@{$seclists{$owner}},'none');
9452: }
9453: if (ref($statushash) eq 'HASH') {
9454: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9455: }
1.290 albertel 9456: }
1.279 raeburn 9457: }
9458: }
9459: }
1.419 raeburn 9460: foreach my $user (keys(%seclists)) {
9461: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9462: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9463: }
1.275 raeburn 9464: }
9465: return;
9466: }
9467:
1.288 raeburn 9468: sub get_user_info {
9469: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9470: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9471: &plainname($uname,$udom,'lastname');
1.291 albertel 9472: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9473: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9474: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9475: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9476: return;
9477: }
1.275 raeburn 9478:
1.472 raeburn 9479: ###############################################
9480:
9481: =pod
9482:
9483: =item * &get_user_quota()
9484:
1.1075.2.41 raeburn 9485: Retrieves quota assigned for storage of user files.
9486: Default is to report quota for portfolio files.
1.472 raeburn 9487:
9488: Incoming parameters:
9489: 1. user's username
9490: 2. user's domain
1.1075.2.41 raeburn 9491: 3. quota name - portfolio, author, or course
9492: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 9493: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 9494: course
1.472 raeburn 9495:
9496: Returns:
1.1075.2.58 raeburn 9497: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9498: 2. (Optional) Type of setting: custom or default
9499: (individually assigned or default for user's
9500: institutional status).
9501: 3. (Optional) - User's institutional status (e.g., faculty, staff
9502: or student - types as defined in localenroll::inst_usertypes
9503: for user's domain, which determines default quota for user.
9504: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9505:
9506: If a value has been stored in the user's environment,
1.536 raeburn 9507: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 9508: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9509:
9510: =cut
9511:
9512: ###############################################
9513:
9514:
9515: sub get_user_quota {
1.1075.2.42 raeburn 9516: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9517: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9518: if (!defined($udom)) {
9519: $udom = $env{'user.domain'};
9520: }
9521: if (!defined($uname)) {
9522: $uname = $env{'user.name'};
9523: }
9524: if (($udom eq '' || $uname eq '') ||
9525: ($udom eq 'public') && ($uname eq 'public')) {
9526: $quota = 0;
1.536 raeburn 9527: $quotatype = 'default';
9528: $defquota = 0;
1.472 raeburn 9529: } else {
1.536 raeburn 9530: my $inststatus;
1.1075.2.41 raeburn 9531: if ($quotaname eq 'course') {
9532: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9533: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9534: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9535: } else {
9536: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9537: $quota = $cenv{'internal.uploadquota'};
9538: }
1.536 raeburn 9539: } else {
1.1075.2.41 raeburn 9540: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9541: if ($quotaname eq 'author') {
9542: $quota = $env{'environment.authorquota'};
9543: } else {
9544: $quota = $env{'environment.portfolioquota'};
9545: }
9546: $inststatus = $env{'environment.inststatus'};
9547: } else {
9548: my %userenv =
9549: &Apache::lonnet::get('environment',['portfolioquota',
9550: 'authorquota','inststatus'],$udom,$uname);
9551: my ($tmp) = keys(%userenv);
9552: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9553: if ($quotaname eq 'author') {
9554: $quota = $userenv{'authorquota'};
9555: } else {
9556: $quota = $userenv{'portfolioquota'};
9557: }
9558: $inststatus = $userenv{'inststatus'};
9559: } else {
9560: undef(%userenv);
9561: }
9562: }
9563: }
9564: if ($quota eq '' || wantarray) {
9565: if ($quotaname eq 'course') {
9566: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 9567: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9568: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 9569: $defquota = $domdefs{$crstype.'quota'};
9570: }
9571: if ($defquota eq '') {
9572: $defquota = 500;
9573: }
1.1075.2.41 raeburn 9574: } else {
9575: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9576: }
9577: if ($quota eq '') {
9578: $quota = $defquota;
9579: $quotatype = 'default';
9580: } else {
9581: $quotatype = 'custom';
9582: }
1.472 raeburn 9583: }
9584: }
1.536 raeburn 9585: if (wantarray) {
9586: return ($quota,$quotatype,$settingstatus,$defquota);
9587: } else {
9588: return $quota;
9589: }
1.472 raeburn 9590: }
9591:
9592: ###############################################
9593:
9594: =pod
9595:
9596: =item * &default_quota()
9597:
1.536 raeburn 9598: Retrieves default quota assigned for storage of user portfolio files,
9599: given an (optional) user's institutional status.
1.472 raeburn 9600:
9601: Incoming parameters:
1.1075.2.42 raeburn 9602:
1.472 raeburn 9603: 1. domain
1.536 raeburn 9604: 2. (Optional) institutional status(es). This is a : separated list of
9605: status types (e.g., faculty, staff, student etc.)
9606: which apply to the user for whom the default is being retrieved.
9607: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9608: default quota will be returned.
9609: 3. quota name - portfolio, author, or course
9610: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9611:
9612: Returns:
1.1075.2.42 raeburn 9613:
1.1075.2.58 raeburn 9614: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9615: 2. (Optional) institutional type which determined the value of the
9616: default quota.
1.472 raeburn 9617:
9618: If a value has been stored in the domain's configuration db,
9619: it will return that, otherwise it returns 20 (for backwards
9620: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9621: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9622:
1.536 raeburn 9623: If the user's status includes multiple types (e.g., staff and student),
9624: the largest default quota which applies to the user determines the
9625: default quota returned.
9626:
1.472 raeburn 9627: =cut
9628:
9629: ###############################################
9630:
9631:
9632: sub default_quota {
1.1075.2.41 raeburn 9633: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9634: my ($defquota,$settingstatus);
9635: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9636: ['quotas'],$udom);
1.1075.2.41 raeburn 9637: my $key = 'defaultquota';
9638: if ($quotaname eq 'author') {
9639: $key = 'authorquota';
9640: }
1.622 raeburn 9641: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9642: if ($inststatus ne '') {
1.765 raeburn 9643: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9644: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9645: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9646: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9647: if ($defquota eq '') {
1.1075.2.41 raeburn 9648: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9649: $settingstatus = $item;
1.1075.2.41 raeburn 9650: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9651: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9652: $settingstatus = $item;
9653: }
9654: }
1.1075.2.41 raeburn 9655: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9656: if ($quotahash{'quotas'}{$item} ne '') {
9657: if ($defquota eq '') {
9658: $defquota = $quotahash{'quotas'}{$item};
9659: $settingstatus = $item;
9660: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9661: $defquota = $quotahash{'quotas'}{$item};
9662: $settingstatus = $item;
9663: }
1.536 raeburn 9664: }
9665: }
9666: }
9667: }
9668: if ($defquota eq '') {
1.1075.2.41 raeburn 9669: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9670: $defquota = $quotahash{'quotas'}{$key}{'default'};
9671: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9672: $defquota = $quotahash{'quotas'}{'default'};
9673: }
1.536 raeburn 9674: $settingstatus = 'default';
1.1075.2.42 raeburn 9675: if ($defquota eq '') {
9676: if ($quotaname eq 'author') {
9677: $defquota = 500;
9678: }
9679: }
1.536 raeburn 9680: }
9681: } else {
9682: $settingstatus = 'default';
1.1075.2.41 raeburn 9683: if ($quotaname eq 'author') {
9684: $defquota = 500;
9685: } else {
9686: $defquota = 20;
9687: }
1.536 raeburn 9688: }
9689: if (wantarray) {
9690: return ($defquota,$settingstatus);
1.472 raeburn 9691: } else {
1.536 raeburn 9692: return $defquota;
1.472 raeburn 9693: }
9694: }
9695:
1.1075.2.41 raeburn 9696: ###############################################
9697:
9698: =pod
9699:
1.1075.2.42 raeburn 9700: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9701:
9702: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9703: of existing file within authoring space will cause quota for the authoring
9704: space to be exceeded.
9705:
9706: Same, if upload of a file directly to a course/community via Course Editor
9707: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9708:
1.1075.2.61 raeburn 9709: Inputs: 7
1.1075.2.42 raeburn 9710: 1. username or coursenum
1.1075.2.41 raeburn 9711: 2. domain
1.1075.2.42 raeburn 9712: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9713: 4. filename of file for which action is being requested
9714: 5. filesize (kB) of file
9715: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9716: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9717:
9718: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9719: otherwise return null.
9720:
1.1075.2.42 raeburn 9721: =back
9722:
1.1075.2.41 raeburn 9723: =cut
9724:
1.1075.2.42 raeburn 9725: sub excess_filesize_warning {
1.1075.2.59 raeburn 9726: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9727: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9728: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9729: if ($context eq 'author') {
9730: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9731: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9732: } else {
9733: foreach my $subdir ('docs','supplemental') {
9734: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9735: }
9736: }
1.1075.2.41 raeburn 9737: $disk_quota = int($disk_quota * 1000);
9738: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9739: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9740: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9741: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9742: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9743: $disk_quota,$current_disk_usage).
9744: '</p>';
9745: }
9746: return;
9747: }
9748:
9749: ###############################################
9750:
9751:
1.384 raeburn 9752: sub get_secgrprole_info {
9753: my ($cdom,$cnum,$needroles,$type) = @_;
9754: my %sections_count = &get_sections($cdom,$cnum);
9755: my @sections = (sort {$a <=> $b} keys(%sections_count));
9756: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9757: my @groups = sort(keys(%curr_groups));
9758: my $allroles = [];
9759: my $rolehash;
9760: my $accesshash = {
9761: active => 'Currently has access',
9762: future => 'Will have future access',
9763: previous => 'Previously had access',
9764: };
9765: if ($needroles) {
9766: $rolehash = {'all' => 'all'};
1.385 albertel 9767: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9768: if (&Apache::lonnet::error(%user_roles)) {
9769: undef(%user_roles);
9770: }
9771: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9772: my ($role)=split(/\:/,$item,2);
9773: if ($role eq 'cr') { next; }
9774: if ($role =~ /^cr/) {
9775: $$rolehash{$role} = (split('/',$role))[3];
9776: } else {
9777: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9778: }
9779: }
9780: foreach my $key (sort(keys(%{$rolehash}))) {
9781: push(@{$allroles},$key);
9782: }
9783: push (@{$allroles},'st');
9784: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9785: }
9786: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9787: }
9788:
1.555 raeburn 9789: sub user_picker {
1.1075.2.127 raeburn 9790: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 9791: my $currdom = $dom;
1.1075.2.114 raeburn 9792: my @alldoms = &Apache::lonnet::all_domains();
9793: if (@alldoms == 1) {
9794: my %domsrch = &Apache::lonnet::get_dom('configuration',
9795: ['directorysrch'],$alldoms[0]);
9796: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
9797: my $showdom = $domdesc;
9798: if ($showdom eq '') {
9799: $showdom = $dom;
9800: }
9801: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
9802: if ((!$domsrch{'directorysrch'}{'available'}) &&
9803: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
9804: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
9805: }
9806: }
9807: }
1.555 raeburn 9808: my %curr_selected = (
9809: srchin => 'dom',
1.580 raeburn 9810: srchby => 'lastname',
1.555 raeburn 9811: );
9812: my $srchterm;
1.625 raeburn 9813: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9814: if ($srch->{'srchby'} ne '') {
9815: $curr_selected{'srchby'} = $srch->{'srchby'};
9816: }
9817: if ($srch->{'srchin'} ne '') {
9818: $curr_selected{'srchin'} = $srch->{'srchin'};
9819: }
9820: if ($srch->{'srchtype'} ne '') {
9821: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9822: }
9823: if ($srch->{'srchdomain'} ne '') {
9824: $currdom = $srch->{'srchdomain'};
9825: }
9826: $srchterm = $srch->{'srchterm'};
9827: }
1.1075.2.98 raeburn 9828: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 9829: 'usr' => 'Search criteria',
1.563 raeburn 9830: 'doma' => 'Domain/institution to search',
1.558 albertel 9831: 'uname' => 'username',
9832: 'lastname' => 'last name',
1.555 raeburn 9833: 'lastfirst' => 'last name, first name',
1.558 albertel 9834: 'crs' => 'in this course',
1.576 raeburn 9835: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9836: 'alc' => 'all LON-CAPA',
1.573 raeburn 9837: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9838: 'exact' => 'is',
9839: 'contains' => 'contains',
1.569 raeburn 9840: 'begins' => 'begins with',
1.1075.2.98 raeburn 9841: );
9842: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 9843: 'youm' => "You must include some text to search for.",
9844: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9845: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9846: 'yomc' => "You must choose a domain when using an institutional directory search.",
9847: 'ymcd' => "You must choose a domain when using a domain search.",
9848: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9849: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9850: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9851: );
1.1075.2.98 raeburn 9852: &html_escape(\%html_lt);
9853: &js_escape(\%js_lt);
1.1075.2.115 raeburn 9854: my $domform;
1.1075.2.126 raeburn 9855: my $allow_blank = 1;
1.1075.2.115 raeburn 9856: if ($fixeddom) {
1.1075.2.126 raeburn 9857: $allow_blank = 0;
9858: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 9859: } else {
1.1075.2.126 raeburn 9860: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 9861: }
1.563 raeburn 9862: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9863:
9864: my @srchins = ('crs','dom','alc','instd');
9865:
9866: foreach my $option (@srchins) {
9867: # FIXME 'alc' option unavailable until
9868: # loncreateuser::print_user_query_page()
9869: # has been completed.
9870: next if ($option eq 'alc');
1.880 raeburn 9871: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9872: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 9873: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 9874: if ($curr_selected{'srchin'} eq $option) {
9875: $srchinsel .= '
1.1075.2.98 raeburn 9876: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 9877: } else {
9878: $srchinsel .= '
1.1075.2.98 raeburn 9879: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 9880: }
1.555 raeburn 9881: }
1.563 raeburn 9882: $srchinsel .= "\n </select>\n";
1.555 raeburn 9883:
9884: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9885: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9886: if ($curr_selected{'srchby'} eq $option) {
9887: $srchbysel .= '
1.1075.2.98 raeburn 9888: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9889: } else {
9890: $srchbysel .= '
1.1075.2.98 raeburn 9891: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9892: }
9893: }
9894: $srchbysel .= "\n </select>\n";
9895:
9896: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9897: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9898: if ($curr_selected{'srchtype'} eq $option) {
9899: $srchtypesel .= '
1.1075.2.98 raeburn 9900: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9901: } else {
9902: $srchtypesel .= '
1.1075.2.98 raeburn 9903: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9904: }
9905: }
9906: $srchtypesel .= "\n </select>\n";
9907:
1.558 albertel 9908: my ($newuserscript,$new_user_create);
1.994 raeburn 9909: my $context_dom = $env{'request.role.domain'};
9910: if ($context eq 'requestcrs') {
9911: if ($env{'form.coursedom'} ne '') {
9912: $context_dom = $env{'form.coursedom'};
9913: }
9914: }
1.556 raeburn 9915: if ($forcenewuser) {
1.576 raeburn 9916: if (ref($srch) eq 'HASH') {
1.994 raeburn 9917: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9918: if ($cancreate) {
9919: $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>';
9920: } else {
1.799 bisitz 9921: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9922: my %usertypetext = (
9923: official => 'institutional',
9924: unofficial => 'non-institutional',
9925: );
1.799 bisitz 9926: $new_user_create = '<p class="LC_warning">'
9927: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9928: .' '
9929: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9930: ,'<a href="'.$helplink.'">','</a>')
9931: .'</p><br />';
1.627 raeburn 9932: }
1.576 raeburn 9933: }
9934: }
9935:
1.556 raeburn 9936: $newuserscript = <<"ENDSCRIPT";
9937:
1.570 raeburn 9938: function setSearch(createnew,callingForm) {
1.556 raeburn 9939: if (createnew == 1) {
1.570 raeburn 9940: for (var i=0; i<callingForm.srchby.length; i++) {
9941: if (callingForm.srchby.options[i].value == 'uname') {
9942: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9943: }
9944: }
1.570 raeburn 9945: for (var i=0; i<callingForm.srchin.length; i++) {
9946: if ( callingForm.srchin.options[i].value == 'dom') {
9947: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9948: }
9949: }
1.570 raeburn 9950: for (var i=0; i<callingForm.srchtype.length; i++) {
9951: if (callingForm.srchtype.options[i].value == 'exact') {
9952: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9953: }
9954: }
1.570 raeburn 9955: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9956: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9957: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9958: }
9959: }
9960: }
9961: }
9962: ENDSCRIPT
1.558 albertel 9963:
1.556 raeburn 9964: }
9965:
1.555 raeburn 9966: my $output = <<"END_BLOCK";
1.556 raeburn 9967: <script type="text/javascript">
1.824 bisitz 9968: // <![CDATA[
1.570 raeburn 9969: function validateEntry(callingForm) {
1.558 albertel 9970:
1.556 raeburn 9971: var checkok = 1;
1.558 albertel 9972: var srchin;
1.570 raeburn 9973: for (var i=0; i<callingForm.srchin.length; i++) {
9974: if ( callingForm.srchin[i].checked ) {
9975: srchin = callingForm.srchin[i].value;
1.558 albertel 9976: }
9977: }
9978:
1.570 raeburn 9979: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9980: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9981: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9982: var srchterm = callingForm.srchterm.value;
9983: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9984: var msg = "";
9985:
9986: if (srchterm == "") {
9987: checkok = 0;
1.1075.2.98 raeburn 9988: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 9989: }
9990:
1.569 raeburn 9991: if (srchtype== 'begins') {
9992: if (srchterm.length < 2) {
9993: checkok = 0;
1.1075.2.98 raeburn 9994: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 9995: }
9996: }
9997:
1.556 raeburn 9998: if (srchtype== 'contains') {
9999: if (srchterm.length < 3) {
10000: checkok = 0;
1.1075.2.98 raeburn 10001: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10002: }
10003: }
10004: if (srchin == 'instd') {
10005: if (srchdomain == '') {
10006: checkok = 0;
1.1075.2.98 raeburn 10007: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10008: }
10009: }
10010: if (srchin == 'dom') {
10011: if (srchdomain == '') {
10012: checkok = 0;
1.1075.2.98 raeburn 10013: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10014: }
10015: }
10016: if (srchby == 'lastfirst') {
10017: if (srchterm.indexOf(",") == -1) {
10018: checkok = 0;
1.1075.2.98 raeburn 10019: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10020: }
10021: if (srchterm.indexOf(",") == srchterm.length -1) {
10022: checkok = 0;
1.1075.2.98 raeburn 10023: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10024: }
10025: }
10026: if (checkok == 0) {
1.1075.2.98 raeburn 10027: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10028: return;
10029: }
10030: if (checkok == 1) {
1.570 raeburn 10031: callingForm.submit();
1.556 raeburn 10032: }
10033: }
10034:
10035: $newuserscript
10036:
1.824 bisitz 10037: // ]]>
1.556 raeburn 10038: </script>
1.558 albertel 10039:
10040: $new_user_create
10041:
1.555 raeburn 10042: END_BLOCK
1.558 albertel 10043:
1.876 raeburn 10044: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 10045: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10046: $domform.
10047: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 10048: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10049: $srchbysel.
10050: $srchtypesel.
10051: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10052: $srchinsel.
10053: &Apache::lonhtmlcommon::row_closure(1).
10054: &Apache::lonhtmlcommon::end_pick_box().
10055: '<br />';
1.1075.2.114 raeburn 10056: return ($output,1);
1.555 raeburn 10057: }
10058:
1.612 raeburn 10059: sub user_rule_check {
1.615 raeburn 10060: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 10061: my ($response,%inst_response);
1.612 raeburn 10062: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 10063: if (keys(%{$usershash}) > 1) {
10064: my (%by_username,%by_id,%userdoms);
10065: my $checkid;
1.612 raeburn 10066: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 10067: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10068: $checkid = 1;
10069: }
10070: }
10071: foreach my $user (keys(%{$usershash})) {
10072: my ($uname,$udom) = split(/:/,$user);
10073: if ($checkid) {
10074: if (ref($usershash->{$user}) eq 'HASH') {
10075: if ($usershash->{$user}->{'id'} ne '') {
10076: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
10077: $userdoms{$udom} = 1;
10078: if (ref($inst_results) eq 'HASH') {
10079: $inst_results->{$uname.':'.$udom} = {};
10080: }
10081: }
10082: }
10083: } else {
10084: $by_username{$udom}{$uname} = 1;
10085: $userdoms{$udom} = 1;
10086: if (ref($inst_results) eq 'HASH') {
10087: $inst_results->{$uname.':'.$udom} = {};
10088: }
10089: }
10090: }
10091: foreach my $udom (keys(%userdoms)) {
10092: if (!$got_rules->{$udom}) {
10093: my %domconfig = &Apache::lonnet::get_dom('configuration',
10094: ['usercreation'],$udom);
10095: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10096: foreach my $item ('username','id') {
10097: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10098: $$curr_rules{$udom}{$item} =
10099: $domconfig{'usercreation'}{$item.'_rule'};
10100: }
10101: }
10102: }
10103: $got_rules->{$udom} = 1;
10104: }
10105: }
10106: if ($checkid) {
10107: foreach my $udom (keys(%by_id)) {
10108: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10109: if ($outcome eq 'ok') {
10110: foreach my $id (keys(%{$by_id{$udom}})) {
10111: my $uname = $by_id{$udom}{$id};
10112: $inst_response{$uname.':'.$udom} = $outcome;
10113: }
10114: if (ref($results) eq 'HASH') {
10115: foreach my $uname (keys(%{$results})) {
10116: if (exists($inst_response{$uname.':'.$udom})) {
10117: $inst_response{$uname.':'.$udom} = $outcome;
10118: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10119: }
10120: }
10121: }
10122: }
1.612 raeburn 10123: }
1.615 raeburn 10124: } else {
1.1075.2.99 raeburn 10125: foreach my $udom (keys(%by_username)) {
10126: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10127: if ($outcome eq 'ok') {
10128: foreach my $uname (keys(%{$by_username{$udom}})) {
10129: $inst_response{$uname.':'.$udom} = $outcome;
10130: }
10131: if (ref($results) eq 'HASH') {
10132: foreach my $uname (keys(%{$results})) {
10133: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10134: }
10135: }
10136: }
10137: }
1.612 raeburn 10138: }
1.1075.2.99 raeburn 10139: } elsif (keys(%{$usershash}) == 1) {
10140: my $user = (keys(%{$usershash}))[0];
10141: my ($uname,$udom) = split(/:/,$user);
10142: if (($udom ne '') && ($uname ne '')) {
10143: if (ref($usershash->{$user}) eq 'HASH') {
10144: if (ref($checks) eq 'HASH') {
10145: if (defined($checks->{'username'})) {
10146: ($inst_response{$user},%{$inst_results->{$user}}) =
10147: &Apache::lonnet::get_instuser($udom,$uname);
10148: } elsif (defined($checks->{'id'})) {
10149: if ($usershash->{$user}->{'id'} ne '') {
10150: ($inst_response{$user},%{$inst_results->{$user}}) =
10151: &Apache::lonnet::get_instuser($udom,undef,
10152: $usershash->{$user}->{'id'});
10153: } else {
10154: ($inst_response{$user},%{$inst_results->{$user}}) =
10155: &Apache::lonnet::get_instuser($udom,$uname);
10156: }
10157: }
10158: } else {
10159: ($inst_response{$user},%{$inst_results->{$user}}) =
10160: &Apache::lonnet::get_instuser($udom,$uname);
10161: return;
10162: }
10163: if (!$got_rules->{$udom}) {
10164: my %domconfig = &Apache::lonnet::get_dom('configuration',
10165: ['usercreation'],$udom);
10166: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10167: foreach my $item ('username','id') {
10168: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10169: $$curr_rules{$udom}{$item} =
10170: $domconfig{'usercreation'}{$item.'_rule'};
10171: }
10172: }
1.585 raeburn 10173: }
1.1075.2.99 raeburn 10174: $got_rules->{$udom} = 1;
1.585 raeburn 10175: }
10176: }
1.1075.2.99 raeburn 10177: } else {
10178: return;
10179: }
10180: } else {
10181: return;
10182: }
10183: foreach my $user (keys(%{$usershash})) {
10184: my ($uname,$udom) = split(/:/,$user);
10185: next if (($udom eq '') || ($uname eq ''));
10186: my $id;
10187: if (ref($inst_results) eq 'HASH') {
10188: if (ref($inst_results->{$user}) eq 'HASH') {
10189: $id = $inst_results->{$user}->{'id'};
10190: }
10191: }
10192: if ($id eq '') {
10193: if (ref($usershash->{$user})) {
10194: $id = $usershash->{$user}->{'id'};
10195: }
1.585 raeburn 10196: }
1.612 raeburn 10197: foreach my $item (keys(%{$checks})) {
10198: if (ref($$curr_rules{$udom}) eq 'HASH') {
10199: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10200: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 10201: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10202: $$curr_rules{$udom}{$item});
1.612 raeburn 10203: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10204: if ($rule_check{$rule}) {
10205: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 10206: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10207: if (ref($inst_results) eq 'HASH') {
10208: if (ref($inst_results->{$user}) eq 'HASH') {
10209: if (keys(%{$inst_results->{$user}}) == 0) {
10210: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 10211: } elsif ($item eq 'id') {
10212: if ($inst_results->{$user}->{'id'} eq '') {
10213: $$alerts{$item}{$udom}{$uname} = 1;
10214: }
1.615 raeburn 10215: }
1.612 raeburn 10216: }
10217: }
1.615 raeburn 10218: }
10219: last;
1.585 raeburn 10220: }
10221: }
10222: }
10223: }
10224: }
10225: }
10226: }
10227: }
1.612 raeburn 10228: return;
10229: }
10230:
10231: sub user_rule_formats {
10232: my ($domain,$domdesc,$curr_rules,$check) = @_;
10233: my %text = (
10234: 'username' => 'Usernames',
10235: 'id' => 'IDs',
10236: );
10237: my $output;
10238: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10239: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10240: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 10241: $output = '<br />'.
10242: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10243: '<span class="LC_cusr_emph">','</span>',$domdesc).
10244: ' <ul>';
1.612 raeburn 10245: foreach my $rule (@{$ruleorder}) {
10246: if (ref($curr_rules) eq 'ARRAY') {
10247: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10248: if (ref($rules->{$rule}) eq 'HASH') {
10249: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10250: $rules->{$rule}{'desc'}.'</li>';
10251: }
10252: }
10253: }
10254: }
10255: $output .= '</ul>';
10256: }
10257: }
10258: return $output;
10259: }
10260:
10261: sub instrule_disallow_msg {
1.615 raeburn 10262: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10263: my $response;
10264: my %text = (
10265: item => 'username',
10266: items => 'usernames',
10267: match => 'matches',
10268: do => 'does',
10269: action => 'a username',
10270: one => 'one',
10271: );
10272: if ($count > 1) {
10273: $text{'item'} = 'usernames';
10274: $text{'match'} ='match';
10275: $text{'do'} = 'do';
10276: $text{'action'} = 'usernames',
10277: $text{'one'} = 'ones';
10278: }
10279: if ($checkitem eq 'id') {
10280: $text{'items'} = 'IDs';
10281: $text{'item'} = 'ID';
10282: $text{'action'} = 'an ID';
1.615 raeburn 10283: if ($count > 1) {
10284: $text{'item'} = 'IDs';
10285: $text{'action'} = 'IDs';
10286: }
1.612 raeburn 10287: }
1.674 bisitz 10288: $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 10289: if ($mode eq 'upload') {
10290: if ($checkitem eq 'username') {
10291: $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'}.");
10292: } elsif ($checkitem eq 'id') {
1.674 bisitz 10293: $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 10294: }
1.669 raeburn 10295: } elsif ($mode eq 'selfcreate') {
10296: if ($checkitem eq 'id') {
10297: $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.");
10298: }
1.615 raeburn 10299: } else {
10300: if ($checkitem eq 'username') {
10301: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10302: } elsif ($checkitem eq 'id') {
10303: $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.");
10304: }
1.612 raeburn 10305: }
10306: return $response;
1.585 raeburn 10307: }
10308:
1.624 raeburn 10309: sub personal_data_fieldtitles {
10310: my %fieldtitles = &Apache::lonlocal::texthash (
10311: id => 'Student/Employee ID',
10312: permanentemail => 'E-mail address',
10313: lastname => 'Last Name',
10314: firstname => 'First Name',
10315: middlename => 'Middle Name',
10316: generation => 'Generation',
10317: gen => 'Generation',
1.765 raeburn 10318: inststatus => 'Affiliation',
1.624 raeburn 10319: );
10320: return %fieldtitles;
10321: }
10322:
1.642 raeburn 10323: sub sorted_inst_types {
10324: my ($dom) = @_;
1.1075.2.70 raeburn 10325: my ($usertypes,$order);
10326: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10327: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10328: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10329: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10330: } else {
10331: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10332: }
1.642 raeburn 10333: my $othertitle = &mt('All users');
10334: if ($env{'request.course.id'}) {
1.668 raeburn 10335: $othertitle = &mt('Any users');
1.642 raeburn 10336: }
10337: my @types;
10338: if (ref($order) eq 'ARRAY') {
10339: @types = @{$order};
10340: }
10341: if (@types == 0) {
10342: if (ref($usertypes) eq 'HASH') {
10343: @types = sort(keys(%{$usertypes}));
10344: }
10345: }
10346: if (keys(%{$usertypes}) > 0) {
10347: $othertitle = &mt('Other users');
10348: }
10349: return ($othertitle,$usertypes,\@types);
10350: }
10351:
1.645 raeburn 10352: sub get_institutional_codes {
10353: my ($settings,$allcourses,$LC_code) = @_;
10354: # Get complete list of course sections to update
10355: my @currsections = ();
10356: my @currxlists = ();
10357: my $coursecode = $$settings{'internal.coursecode'};
10358:
10359: if ($$settings{'internal.sectionnums'} ne '') {
10360: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10361: }
10362:
10363: if ($$settings{'internal.crosslistings'} ne '') {
10364: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10365: }
10366:
10367: if (@currxlists > 0) {
10368: foreach (@currxlists) {
10369: if (m/^([^:]+):(\w*)$/) {
10370: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 10371: push(@{$allcourses},$1);
1.645 raeburn 10372: $$LC_code{$1} = $2;
10373: }
10374: }
10375: }
10376: }
10377:
10378: if (@currsections > 0) {
10379: foreach (@currsections) {
10380: if (m/^(\w+):(\w*)$/) {
10381: my $sec = $coursecode.$1;
10382: my $lc_sec = $2;
10383: unless (grep/^$sec$/,@{$allcourses}) {
1.1075.2.119 raeburn 10384: push(@{$allcourses},$sec);
1.645 raeburn 10385: $$LC_code{$sec} = $lc_sec;
10386: }
10387: }
10388: }
10389: }
10390: return;
10391: }
10392:
1.971 raeburn 10393: sub get_standard_codeitems {
10394: return ('Year','Semester','Department','Number','Section');
10395: }
10396:
1.112 bowersj2 10397: =pod
10398:
1.780 raeburn 10399: =head1 Slot Helpers
10400:
10401: =over 4
10402:
10403: =item * sorted_slots()
10404:
1.1040 raeburn 10405: Sorts an array of slot names in order of an optional sort key,
10406: default sort is by slot start time (earliest first).
1.780 raeburn 10407:
10408: Inputs:
10409:
10410: =over 4
10411:
10412: slotsarr - Reference to array of unsorted slot names.
10413:
10414: slots - Reference to hash of hash, where outer hash keys are slot names.
10415:
1.1040 raeburn 10416: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10417:
1.549 albertel 10418: =back
10419:
1.780 raeburn 10420: Returns:
10421:
10422: =over 4
10423:
1.1040 raeburn 10424: sorted - An array of slot names sorted by a specified sort key
10425: (default sort key is start time of the slot).
1.780 raeburn 10426:
10427: =back
10428:
10429: =cut
10430:
10431:
10432: sub sorted_slots {
1.1040 raeburn 10433: my ($slotsarr,$slots,$sortkey) = @_;
10434: if ($sortkey eq '') {
10435: $sortkey = 'starttime';
10436: }
1.780 raeburn 10437: my @sorted;
10438: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10439: @sorted =
10440: sort {
10441: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10442: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10443: }
10444: if (ref($slots->{$a})) { return -1;}
10445: if (ref($slots->{$b})) { return 1;}
10446: return 0;
10447: } @{$slotsarr};
10448: }
10449: return @sorted;
10450: }
10451:
1.1040 raeburn 10452: =pod
10453:
10454: =item * get_future_slots()
10455:
10456: Inputs:
10457:
10458: =over 4
10459:
10460: cnum - course number
10461:
10462: cdom - course domain
10463:
10464: now - current UNIX time
10465:
10466: symb - optional symb
10467:
10468: =back
10469:
10470: Returns:
10471:
10472: =over 4
10473:
10474: sorted_reservable - ref to array of student_schedulable slots currently
10475: reservable, ordered by end date of reservation period.
10476:
10477: reservable_now - ref to hash of student_schedulable slots currently
10478: reservable.
10479:
10480: Keys in inner hash are:
10481: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 10482: (b) endreserve: end date of reservation period.
10483: (c) uniqueperiod: start,end dates when slot is to be uniquely
10484: selected.
1.1040 raeburn 10485:
10486: sorted_future - ref to array of student_schedulable slots reservable in
10487: the future, ordered by start date of reservation period.
10488:
10489: future_reservable - ref to hash of student_schedulable slots reservable
10490: in the future.
10491:
10492: Keys in inner hash are:
10493: (a) symb: either blank or symb to which slot use is restricted.
10494: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 10495: (c) uniqueperiod: start,end dates when slot is to be uniquely
10496: selected.
1.1040 raeburn 10497:
10498: =back
10499:
10500: =cut
10501:
10502: sub get_future_slots {
10503: my ($cnum,$cdom,$now,$symb) = @_;
10504: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10505: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10506: foreach my $slot (keys(%slots)) {
10507: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10508: if ($symb) {
10509: next if (($slots{$slot}->{'symb'} ne '') &&
10510: ($slots{$slot}->{'symb'} ne $symb));
10511: }
10512: if (($slots{$slot}->{'starttime'} > $now) &&
10513: ($slots{$slot}->{'endtime'} > $now)) {
10514: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10515: my $userallowed = 0;
10516: if ($slots{$slot}->{'allowedsections'}) {
10517: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10518: if (!defined($env{'request.role.sec'})
10519: && grep(/^No section assigned$/,@allowed_sec)) {
10520: $userallowed=1;
10521: } else {
10522: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10523: $userallowed=1;
10524: }
10525: }
10526: unless ($userallowed) {
10527: if (defined($env{'request.course.groups'})) {
10528: my @groups = split(/:/,$env{'request.course.groups'});
10529: foreach my $group (@groups) {
10530: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10531: $userallowed=1;
10532: last;
10533: }
10534: }
10535: }
10536: }
10537: }
10538: if ($slots{$slot}->{'allowedusers'}) {
10539: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10540: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10541: if (grep(/^\Q$user\E$/,@allowed_users)) {
10542: $userallowed = 1;
10543: }
10544: }
10545: next unless($userallowed);
10546: }
10547: my $startreserve = $slots{$slot}->{'startreserve'};
10548: my $endreserve = $slots{$slot}->{'endreserve'};
10549: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 10550: my $uniqueperiod;
10551: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10552: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10553: }
1.1040 raeburn 10554: if (($startreserve < $now) &&
10555: (!$endreserve || $endreserve > $now)) {
10556: my $lastres = $endreserve;
10557: if (!$lastres) {
10558: $lastres = $slots{$slot}->{'starttime'};
10559: }
10560: $reservable_now{$slot} = {
10561: symb => $symb,
1.1075.2.104 raeburn 10562: endreserve => $lastres,
10563: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10564: };
10565: } elsif (($startreserve > $now) &&
10566: (!$endreserve || $endreserve > $startreserve)) {
10567: $future_reservable{$slot} = {
10568: symb => $symb,
1.1075.2.104 raeburn 10569: startreserve => $startreserve,
10570: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10571: };
10572: }
10573: }
10574: }
10575: my @unsorted_reservable = keys(%reservable_now);
10576: if (@unsorted_reservable > 0) {
10577: @sorted_reservable =
10578: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10579: }
10580: my @unsorted_future = keys(%future_reservable);
10581: if (@unsorted_future > 0) {
10582: @sorted_future =
10583: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10584: }
10585: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10586: }
1.780 raeburn 10587:
10588: =pod
10589:
1.1057 foxr 10590: =back
10591:
1.549 albertel 10592: =head1 HTTP Helpers
10593:
10594: =over 4
10595:
1.648 raeburn 10596: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10597:
1.258 albertel 10598: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10599: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10600: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10601:
10602: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10603: $possible_names is an ref to an array of form element names. As an example:
10604: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10605: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10606:
10607: =cut
1.1 albertel 10608:
1.6 albertel 10609: sub get_unprocessed_cgi {
1.25 albertel 10610: my ($query,$possible_names)= @_;
1.26 matthew 10611: # $Apache::lonxml::debug=1;
1.356 albertel 10612: foreach my $pair (split(/&/,$query)) {
10613: my ($name, $value) = split(/=/,$pair);
1.369 www 10614: $name = &unescape($name);
1.25 albertel 10615: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10616: $value =~ tr/+/ /;
10617: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10618: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10619: }
1.16 harris41 10620: }
1.6 albertel 10621: }
10622:
1.112 bowersj2 10623: =pod
10624:
1.648 raeburn 10625: =item * &cacheheader()
1.112 bowersj2 10626:
10627: returns cache-controlling header code
10628:
10629: =cut
10630:
1.7 albertel 10631: sub cacheheader {
1.258 albertel 10632: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10633: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10634: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10635: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10636: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10637: return $output;
1.7 albertel 10638: }
10639:
1.112 bowersj2 10640: =pod
10641:
1.648 raeburn 10642: =item * &no_cache($r)
1.112 bowersj2 10643:
10644: specifies header code to not have cache
10645:
10646: =cut
10647:
1.9 albertel 10648: sub no_cache {
1.216 albertel 10649: my ($r) = @_;
10650: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10651: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10652: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10653: $r->no_cache(1);
10654: $r->header_out("Expires" => $date);
10655: $r->header_out("Pragma" => "no-cache");
1.123 www 10656: }
10657:
10658: sub content_type {
1.181 albertel 10659: my ($r,$type,$charset) = @_;
1.299 foxr 10660: if ($r) {
10661: # Note that printout.pl calls this with undef for $r.
10662: &no_cache($r);
10663: }
1.258 albertel 10664: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10665: unless ($charset) {
10666: $charset=&Apache::lonlocal::current_encoding;
10667: }
10668: if ($charset) { $type.='; charset='.$charset; }
10669: if ($r) {
10670: $r->content_type($type);
10671: } else {
10672: print("Content-type: $type\n\n");
10673: }
1.9 albertel 10674: }
1.25 albertel 10675:
1.112 bowersj2 10676: =pod
10677:
1.648 raeburn 10678: =item * &add_to_env($name,$value)
1.112 bowersj2 10679:
1.258 albertel 10680: adds $name to the %env hash with value
1.112 bowersj2 10681: $value, if $name already exists, the entry is converted to an array
10682: reference and $value is added to the array.
10683:
10684: =cut
10685:
1.25 albertel 10686: sub add_to_env {
10687: my ($name,$value)=@_;
1.258 albertel 10688: if (defined($env{$name})) {
10689: if (ref($env{$name})) {
1.25 albertel 10690: #already have multiple values
1.258 albertel 10691: push(@{ $env{$name} },$value);
1.25 albertel 10692: } else {
10693: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10694: my $first=$env{$name};
10695: undef($env{$name});
10696: push(@{ $env{$name} },$first,$value);
1.25 albertel 10697: }
10698: } else {
1.258 albertel 10699: $env{$name}=$value;
1.25 albertel 10700: }
1.31 albertel 10701: }
1.149 albertel 10702:
10703: =pod
10704:
1.648 raeburn 10705: =item * &get_env_multiple($name)
1.149 albertel 10706:
1.258 albertel 10707: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10708: values may be defined and end up as an array ref.
10709:
10710: returns an array of values
10711:
10712: =cut
10713:
10714: sub get_env_multiple {
10715: my ($name) = @_;
10716: my @values;
1.258 albertel 10717: if (defined($env{$name})) {
1.149 albertel 10718: # exists is it an array
1.258 albertel 10719: if (ref($env{$name})) {
10720: @values=@{ $env{$name} };
1.149 albertel 10721: } else {
1.258 albertel 10722: $values[0]=$env{$name};
1.149 albertel 10723: }
10724: }
10725: return(@values);
10726: }
10727:
1.660 raeburn 10728: sub ask_for_embedded_content {
10729: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10730: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 10731: %currsubfile,%unused,$rem);
1.1071 raeburn 10732: my $counter = 0;
10733: my $numnew = 0;
1.987 raeburn 10734: my $numremref = 0;
10735: my $numinvalid = 0;
10736: my $numpathchg = 0;
10737: my $numexisting = 0;
1.1071 raeburn 10738: my $numunused = 0;
10739: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 10740: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10741: my $heading = &mt('Upload embedded files');
10742: my $buttontext = &mt('Upload');
10743:
1.1075.2.11 raeburn 10744: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 10745: if ($actionurl eq '/adm/dependencies') {
10746: $navmap = Apache::lonnavmaps::navmap->new();
10747: }
10748: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10749: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 10750: }
1.1075.2.35 raeburn 10751: if (($actionurl eq '/adm/portfolio') ||
10752: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10753: my $current_path='/';
10754: if ($env{'form.currentpath'}) {
10755: $current_path = $env{'form.currentpath'};
10756: }
10757: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 10758: $udom = $cdom;
10759: $uname = $cnum;
1.984 raeburn 10760: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10761: } else {
10762: $udom = $env{'user.domain'};
10763: $uname = $env{'user.name'};
10764: $url = '/userfiles/portfolio';
10765: }
1.987 raeburn 10766: $toplevel = $url.'/';
1.984 raeburn 10767: $url .= $current_path;
10768: $getpropath = 1;
1.987 raeburn 10769: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10770: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10771: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10772: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10773: $toplevel = $url;
1.984 raeburn 10774: if ($rest ne '') {
1.987 raeburn 10775: $url .= $rest;
10776: }
10777: } elsif ($actionurl eq '/adm/coursedocs') {
10778: if (ref($args) eq 'HASH') {
1.1071 raeburn 10779: $url = $args->{'docs_url'};
10780: $toplevel = $url;
1.1075.2.11 raeburn 10781: if ($args->{'context'} eq 'paste') {
10782: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10783: ($path) =
10784: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10785: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10786: $fileloc =~ s{^/}{};
10787: }
1.1071 raeburn 10788: }
10789: } elsif ($actionurl eq '/adm/dependencies') {
10790: if ($env{'request.course.id'} ne '') {
10791: if (ref($args) eq 'HASH') {
10792: $url = $args->{'docs_url'};
10793: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 10794: $toplevel = $url;
10795: unless ($toplevel =~ m{^/}) {
10796: $toplevel = "/$url";
10797: }
1.1075.2.11 raeburn 10798: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 10799: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10800: $path = $1;
10801: } else {
10802: ($path) =
10803: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10804: }
1.1075.2.79 raeburn 10805: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10806: $fileloc = $toplevel;
10807: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10808: my ($udom,$uname,$fname) =
10809: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10810: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10811: } else {
10812: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10813: }
1.1071 raeburn 10814: $fileloc =~ s{^/}{};
10815: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10816: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10817: }
1.987 raeburn 10818: }
1.1075.2.35 raeburn 10819: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10820: $udom = $cdom;
10821: $uname = $cnum;
10822: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10823: $toplevel = $url;
10824: $path = $url;
10825: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10826: $fileloc =~ s{^/}{};
10827: }
10828: foreach my $file (keys(%{$allfiles})) {
10829: my $embed_file;
10830: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10831: $embed_file = $1;
10832: } else {
10833: $embed_file = $file;
10834: }
1.1075.2.55 raeburn 10835: my ($absolutepath,$cleaned_file);
10836: if ($embed_file =~ m{^\w+://}) {
10837: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 10838: $newfiles{$cleaned_file} = 1;
10839: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10840: } else {
1.1075.2.55 raeburn 10841: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10842: if ($embed_file =~ m{^/}) {
10843: $absolutepath = $embed_file;
10844: }
1.1075.2.47 raeburn 10845: if ($cleaned_file =~ m{/}) {
10846: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10847: $path = &check_for_traversal($path,$url,$toplevel);
10848: my $item = $fname;
10849: if ($path ne '') {
10850: $item = $path.'/'.$fname;
10851: $subdependencies{$path}{$fname} = 1;
10852: } else {
10853: $dependencies{$item} = 1;
10854: }
10855: if ($absolutepath) {
10856: $mapping{$item} = $absolutepath;
10857: } else {
10858: $mapping{$item} = $embed_file;
10859: }
10860: } else {
10861: $dependencies{$embed_file} = 1;
10862: if ($absolutepath) {
1.1075.2.47 raeburn 10863: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10864: } else {
1.1075.2.47 raeburn 10865: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10866: }
10867: }
1.984 raeburn 10868: }
10869: }
1.1071 raeburn 10870: my $dirptr = 16384;
1.984 raeburn 10871: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10872: $currsubfile{$path} = {};
1.1075.2.35 raeburn 10873: if (($actionurl eq '/adm/portfolio') ||
10874: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10875: my ($sublistref,$listerror) =
10876: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10877: if (ref($sublistref) eq 'ARRAY') {
10878: foreach my $line (@{$sublistref}) {
10879: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10880: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10881: }
1.984 raeburn 10882: }
1.987 raeburn 10883: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10884: if (opendir(my $dir,$url.'/'.$path)) {
10885: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10886: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10887: }
1.1075.2.11 raeburn 10888: } elsif (($actionurl eq '/adm/dependencies') ||
10889: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10890: ($args->{'context'} eq 'paste')) ||
10891: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10892: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 10893: my $dir;
10894: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10895: $dir = $fileloc;
10896: } else {
10897: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10898: }
1.1071 raeburn 10899: if ($dir ne '') {
10900: my ($sublistref,$listerror) =
10901: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10902: if (ref($sublistref) eq 'ARRAY') {
10903: foreach my $line (@{$sublistref}) {
10904: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10905: undef,$mtime)=split(/\&/,$line,12);
10906: unless (($testdir&$dirptr) ||
10907: ($file_name =~ /^\.\.?$/)) {
10908: $currsubfile{$path}{$file_name} = [$size,$mtime];
10909: }
10910: }
10911: }
10912: }
1.984 raeburn 10913: }
10914: }
10915: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10916: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10917: my $item = $path.'/'.$file;
10918: unless ($mapping{$item} eq $item) {
10919: $pathchanges{$item} = 1;
10920: }
10921: $existing{$item} = 1;
10922: $numexisting ++;
10923: } else {
10924: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10925: }
10926: }
1.1071 raeburn 10927: if ($actionurl eq '/adm/dependencies') {
10928: foreach my $path (keys(%currsubfile)) {
10929: if (ref($currsubfile{$path}) eq 'HASH') {
10930: foreach my $file (keys(%{$currsubfile{$path}})) {
10931: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 10932: next if (($rem ne '') &&
10933: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10934: (ref($navmap) &&
10935: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10936: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10937: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10938: $unused{$path.'/'.$file} = 1;
10939: }
10940: }
10941: }
10942: }
10943: }
1.984 raeburn 10944: }
1.987 raeburn 10945: my %currfile;
1.1075.2.35 raeburn 10946: if (($actionurl eq '/adm/portfolio') ||
10947: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10948: my ($dirlistref,$listerror) =
10949: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10950: if (ref($dirlistref) eq 'ARRAY') {
10951: foreach my $line (@{$dirlistref}) {
10952: my ($file_name,$rest) = split(/\&/,$line,2);
10953: $currfile{$file_name} = 1;
10954: }
1.984 raeburn 10955: }
1.987 raeburn 10956: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10957: if (opendir(my $dir,$url)) {
1.987 raeburn 10958: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10959: map {$currfile{$_} = 1;} @dir_list;
10960: }
1.1075.2.11 raeburn 10961: } elsif (($actionurl eq '/adm/dependencies') ||
10962: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10963: ($args->{'context'} eq 'paste')) ||
10964: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10965: if ($env{'request.course.id'} ne '') {
10966: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10967: if ($dir ne '') {
10968: my ($dirlistref,$listerror) =
10969: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10970: if (ref($dirlistref) eq 'ARRAY') {
10971: foreach my $line (@{$dirlistref}) {
10972: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10973: $size,undef,$mtime)=split(/\&/,$line,12);
10974: unless (($testdir&$dirptr) ||
10975: ($file_name =~ /^\.\.?$/)) {
10976: $currfile{$file_name} = [$size,$mtime];
10977: }
10978: }
10979: }
10980: }
10981: }
1.984 raeburn 10982: }
10983: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10984: if (exists($currfile{$file})) {
1.987 raeburn 10985: unless ($mapping{$file} eq $file) {
10986: $pathchanges{$file} = 1;
10987: }
10988: $existing{$file} = 1;
10989: $numexisting ++;
10990: } else {
1.984 raeburn 10991: $newfiles{$file} = 1;
10992: }
10993: }
1.1071 raeburn 10994: foreach my $file (keys(%currfile)) {
10995: unless (($file eq $filename) ||
10996: ($file eq $filename.'.bak') ||
10997: ($dependencies{$file})) {
1.1075.2.11 raeburn 10998: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10999: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11000: next if (($rem ne '') &&
11001: (($env{"httpref.$rem".$file} ne '') ||
11002: (ref($navmap) &&
11003: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11004: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11005: ($navmap->getResourceByUrl($rem.$1)))))));
11006: }
1.1075.2.11 raeburn 11007: }
1.1071 raeburn 11008: $unused{$file} = 1;
11009: }
11010: }
1.1075.2.11 raeburn 11011: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11012: ($args->{'context'} eq 'paste')) {
11013: $counter = scalar(keys(%existing));
11014: $numpathchg = scalar(keys(%pathchanges));
11015: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 11016: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11017: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11018: $counter = scalar(keys(%existing));
11019: $numpathchg = scalar(keys(%pathchanges));
11020: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 11021: }
1.984 raeburn 11022: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11023: if ($actionurl eq '/adm/dependencies') {
11024: next if ($embed_file =~ m{^\w+://});
11025: }
1.660 raeburn 11026: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11027: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11028: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11029: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 11030: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11031: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11032: }
1.1075.2.35 raeburn 11033: $upload_output .= '</td>';
1.1071 raeburn 11034: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 11035: $upload_output.='<td align="right">'.
11036: '<span class="LC_info LC_fontsize_medium">'.
11037: &mt("URL points to web address").'</span>';
1.987 raeburn 11038: $numremref++;
1.660 raeburn 11039: } elsif ($args->{'error_on_invalid_names'}
11040: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 11041: $upload_output.='<td align="right"><span class="LC_warning">'.
11042: &mt('Invalid characters').'</span>';
1.987 raeburn 11043: $numinvalid++;
1.660 raeburn 11044: } else {
1.1075.2.35 raeburn 11045: $upload_output .= '<td>'.
11046: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11047: $embed_file,\%mapping,
1.1071 raeburn 11048: $allfiles,$codebase,'upload');
11049: $counter ++;
11050: $numnew ++;
1.987 raeburn 11051: }
11052: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11053: }
11054: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11055: if ($actionurl eq '/adm/dependencies') {
11056: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11057: $modify_output .= &start_data_table_row().
11058: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11059: '<img src="'.&icon($embed_file).'" border="0" />'.
11060: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11061: '<td>'.$size.'</td>'.
11062: '<td>'.$mtime.'</td>'.
11063: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11064: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11065: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11066: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11067: &embedded_file_element('upload_embedded',$counter,
11068: $embed_file,\%mapping,
11069: $allfiles,$codebase,'modify').
11070: '</div></td>'.
11071: &end_data_table_row()."\n";
11072: $counter ++;
11073: } else {
11074: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11075: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11076: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11077: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11078: &Apache::loncommon::end_data_table_row()."\n";
11079: }
11080: }
11081: my $delidx = $counter;
11082: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11083: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11084: $delete_output .= &start_data_table_row().
11085: '<td><img src="'.&icon($oldfile).'" />'.
11086: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11087: '<td>'.$size.'</td>'.
11088: '<td>'.$mtime.'</td>'.
11089: '<td><label><input type="checkbox" name="del_upload_dep" '.
11090: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11091: &embedded_file_element('upload_embedded',$delidx,
11092: $oldfile,\%mapping,$allfiles,
11093: $codebase,'delete').'</td>'.
11094: &end_data_table_row()."\n";
11095: $numunused ++;
11096: $delidx ++;
1.987 raeburn 11097: }
11098: if ($upload_output) {
11099: $upload_output = &start_data_table().
11100: $upload_output.
11101: &end_data_table()."\n";
11102: }
1.1071 raeburn 11103: if ($modify_output) {
11104: $modify_output = &start_data_table().
11105: &start_data_table_header_row().
11106: '<th>'.&mt('File').'</th>'.
11107: '<th>'.&mt('Size (KB)').'</th>'.
11108: '<th>'.&mt('Modified').'</th>'.
11109: '<th>'.&mt('Upload replacement?').'</th>'.
11110: &end_data_table_header_row().
11111: $modify_output.
11112: &end_data_table()."\n";
11113: }
11114: if ($delete_output) {
11115: $delete_output = &start_data_table().
11116: &start_data_table_header_row().
11117: '<th>'.&mt('File').'</th>'.
11118: '<th>'.&mt('Size (KB)').'</th>'.
11119: '<th>'.&mt('Modified').'</th>'.
11120: '<th>'.&mt('Delete?').'</th>'.
11121: &end_data_table_header_row().
11122: $delete_output.
11123: &end_data_table()."\n";
11124: }
1.987 raeburn 11125: my $applies = 0;
11126: if ($numremref) {
11127: $applies ++;
11128: }
11129: if ($numinvalid) {
11130: $applies ++;
11131: }
11132: if ($numexisting) {
11133: $applies ++;
11134: }
1.1071 raeburn 11135: if ($counter || $numunused) {
1.987 raeburn 11136: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11137: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11138: $state.'<h3>'.$heading.'</h3>';
11139: if ($actionurl eq '/adm/dependencies') {
11140: if ($numnew) {
11141: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11142: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11143: $upload_output.'<br />'."\n";
11144: }
11145: if ($numexisting) {
11146: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11147: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11148: $modify_output.'<br />'."\n";
11149: $buttontext = &mt('Save changes');
11150: }
11151: if ($numunused) {
11152: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11153: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11154: $delete_output.'<br />'."\n";
11155: $buttontext = &mt('Save changes');
11156: }
11157: } else {
11158: $output .= $upload_output.'<br />'."\n";
11159: }
11160: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11161: $counter.'" />'."\n";
11162: if ($actionurl eq '/adm/dependencies') {
11163: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11164: $numnew.'" />'."\n";
11165: } elsif ($actionurl eq '') {
1.987 raeburn 11166: $output .= '<input type="hidden" name="phase" value="three" />';
11167: }
11168: } elsif ($applies) {
11169: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11170: if ($applies > 1) {
11171: $output .=
1.1075.2.35 raeburn 11172: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11173: if ($numremref) {
11174: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11175: }
11176: if ($numinvalid) {
11177: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11178: }
11179: if ($numexisting) {
11180: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11181: }
11182: $output .= '</ul><br />';
11183: } elsif ($numremref) {
11184: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11185: } elsif ($numinvalid) {
11186: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11187: } elsif ($numexisting) {
11188: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11189: }
11190: $output .= $upload_output.'<br />';
11191: }
11192: my ($pathchange_output,$chgcount);
1.1071 raeburn 11193: $chgcount = $counter;
1.987 raeburn 11194: if (keys(%pathchanges) > 0) {
11195: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11196: if ($counter) {
1.987 raeburn 11197: $output .= &embedded_file_element('pathchange',$chgcount,
11198: $embed_file,\%mapping,
1.1071 raeburn 11199: $allfiles,$codebase,'change');
1.987 raeburn 11200: } else {
11201: $pathchange_output .=
11202: &start_data_table_row().
11203: '<td><input type ="checkbox" name="namechange" value="'.
11204: $chgcount.'" checked="checked" /></td>'.
11205: '<td>'.$mapping{$embed_file}.'</td>'.
11206: '<td>'.$embed_file.
11207: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11208: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11209: '</td>'.&end_data_table_row();
1.660 raeburn 11210: }
1.987 raeburn 11211: $numpathchg ++;
11212: $chgcount ++;
1.660 raeburn 11213: }
11214: }
1.1075.2.35 raeburn 11215: if (($counter) || ($numunused)) {
1.987 raeburn 11216: if ($numpathchg) {
11217: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11218: $numpathchg.'" />'."\n";
11219: }
11220: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11221: ($actionurl eq '/adm/imsimport')) {
11222: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11223: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11224: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11225: } elsif ($actionurl eq '/adm/dependencies') {
11226: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11227: }
1.1075.2.35 raeburn 11228: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11229: } elsif ($numpathchg) {
11230: my %pathchange = ();
11231: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11232: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11233: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 11234: }
1.987 raeburn 11235: }
1.1071 raeburn 11236: return ($output,$counter,$numpathchg);
1.987 raeburn 11237: }
11238:
1.1075.2.47 raeburn 11239: =pod
11240:
11241: =item * clean_path($name)
11242:
11243: Performs clean-up of directories, subdirectories and filename in an
11244: embedded object, referenced in an HTML file which is being uploaded
11245: to a course or portfolio, where
11246: "Upload embedded images/multimedia files if HTML file" checkbox was
11247: checked.
11248:
11249: Clean-up is similar to replacements in lonnet::clean_filename()
11250: except each / between sub-directory and next level is preserved.
11251:
11252: =cut
11253:
11254: sub clean_path {
11255: my ($embed_file) = @_;
11256: $embed_file =~s{^/+}{};
11257: my @contents;
11258: if ($embed_file =~ m{/}) {
11259: @contents = split(/\//,$embed_file);
11260: } else {
11261: @contents = ($embed_file);
11262: }
11263: my $lastidx = scalar(@contents)-1;
11264: for (my $i=0; $i<=$lastidx; $i++) {
11265: $contents[$i]=~s{\\}{/}g;
11266: $contents[$i]=~s/\s+/\_/g;
11267: $contents[$i]=~s{[^/\w\.\-]}{}g;
11268: if ($i == $lastidx) {
11269: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11270: }
11271: }
11272: if ($lastidx > 0) {
11273: return join('/',@contents);
11274: } else {
11275: return $contents[0];
11276: }
11277: }
11278:
1.987 raeburn 11279: sub embedded_file_element {
1.1071 raeburn 11280: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11281: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11282: (ref($codebase) eq 'HASH'));
11283: my $output;
1.1071 raeburn 11284: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11285: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11286: }
11287: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11288: &escape($embed_file).'" />';
11289: unless (($context eq 'upload_embedded') &&
11290: ($mapping->{$embed_file} eq $embed_file)) {
11291: $output .='
11292: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11293: }
11294: my $attrib;
11295: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11296: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11297: }
11298: $output .=
11299: "\n\t\t".
11300: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11301: $attrib.'" />';
11302: if (exists($codebase->{$mapping->{$embed_file}})) {
11303: $output .=
11304: "\n\t\t".
11305: '<input name="codebase_'.$num.'" type="hidden" value="'.
11306: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11307: }
1.987 raeburn 11308: return $output;
1.660 raeburn 11309: }
11310:
1.1071 raeburn 11311: sub get_dependency_details {
11312: my ($currfile,$currsubfile,$embed_file) = @_;
11313: my ($size,$mtime,$showsize,$showmtime);
11314: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11315: if ($embed_file =~ m{/}) {
11316: my ($path,$fname) = split(/\//,$embed_file);
11317: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11318: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11319: }
11320: } else {
11321: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11322: ($size,$mtime) = @{$currfile->{$embed_file}};
11323: }
11324: }
11325: $showsize = $size/1024.0;
11326: $showsize = sprintf("%.1f",$showsize);
11327: if ($mtime > 0) {
11328: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11329: }
11330: }
11331: return ($showsize,$showmtime);
11332: }
11333:
11334: sub ask_embedded_js {
11335: return <<"END";
11336: <script type="text/javascript"">
11337: // <![CDATA[
11338: function toggleBrowse(counter) {
11339: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11340: var fileid = document.getElementById('embedded_item_'+counter);
11341: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11342: if (chkboxid.checked == true) {
11343: uploaddivid.style.display='block';
11344: } else {
11345: uploaddivid.style.display='none';
11346: fileid.value = '';
11347: }
11348: }
11349: // ]]>
11350: </script>
11351:
11352: END
11353: }
11354:
1.661 raeburn 11355: sub upload_embedded {
11356: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11357: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11358: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11359: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11360: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11361: my $orig_uploaded_filename =
11362: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11363: foreach my $type ('orig','ref','attrib','codebase') {
11364: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11365: $env{'form.embedded_'.$type.'_'.$i} =
11366: &unescape($env{'form.embedded_'.$type.'_'.$i});
11367: }
11368: }
1.661 raeburn 11369: my ($path,$fname) =
11370: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11371: # no path, whole string is fname
11372: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11373: $fname = &Apache::lonnet::clean_filename($fname);
11374: # See if there is anything left
11375: next if ($fname eq '');
11376:
11377: # Check if file already exists as a file or directory.
11378: my ($state,$msg);
11379: if ($context eq 'portfolio') {
11380: my $port_path = $dirpath;
11381: if ($group ne '') {
11382: $port_path = "groups/$group/$port_path";
11383: }
1.987 raeburn 11384: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11385: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11386: $dir_root,$port_path,$disk_quota,
11387: $current_disk_usage,$uname,$udom);
11388: if ($state eq 'will_exceed_quota'
1.984 raeburn 11389: || $state eq 'file_locked') {
1.661 raeburn 11390: $output .= $msg;
11391: next;
11392: }
11393: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11394: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11395: if ($state eq 'exists') {
11396: $output .= $msg;
11397: next;
11398: }
11399: }
11400: # Check if extension is valid
11401: if (($fname =~ /\.(\w+)$/) &&
11402: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 11403: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11404: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11405: next;
11406: } elsif (($fname =~ /\.(\w+)$/) &&
11407: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11408: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11409: next;
11410: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 11411: $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 11412: next;
11413: }
11414: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 11415: my $subdir = $path;
11416: $subdir =~ s{/+$}{};
1.661 raeburn 11417: if ($context eq 'portfolio') {
1.984 raeburn 11418: my $result;
11419: if ($state eq 'existingfile') {
11420: $result=
11421: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 11422: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11423: } else {
1.984 raeburn 11424: $result=
11425: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11426: $dirpath.
1.1075.2.35 raeburn 11427: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11428: if ($result !~ m|^/uploaded/|) {
11429: $output .= '<span class="LC_error">'
11430: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11431: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11432: .'</span><br />';
11433: next;
11434: } else {
1.987 raeburn 11435: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11436: $path.$fname.'</span>').'<br />';
1.984 raeburn 11437: }
1.661 raeburn 11438: }
1.1075.2.35 raeburn 11439: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
11440: my $extendedsubdir = $dirpath.'/'.$subdir;
11441: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11442: my $result =
1.1075.2.35 raeburn 11443: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11444: if ($result !~ m|^/uploaded/|) {
11445: $output .= '<span class="LC_error">'
11446: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11447: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11448: .'</span><br />';
11449: next;
11450: } else {
11451: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11452: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 11453: if ($context eq 'syllabus') {
11454: &Apache::lonnet::make_public_indefinitely($result);
11455: }
1.987 raeburn 11456: }
1.661 raeburn 11457: } else {
11458: # Save the file
11459: my $target = $env{'form.embedded_item_'.$i};
11460: my $fullpath = $dir_root.$dirpath.'/'.$path;
11461: my $dest = $fullpath.$fname;
11462: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11463: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11464: my $count;
11465: my $filepath = $dir_root;
1.1027 raeburn 11466: foreach my $subdir (@parts) {
11467: $filepath .= "/$subdir";
11468: if (!-e $filepath) {
1.661 raeburn 11469: mkdir($filepath,0770);
11470: }
11471: }
11472: my $fh;
11473: if (!open($fh,'>'.$dest)) {
11474: &Apache::lonnet::logthis('Failed to create '.$dest);
11475: $output .= '<span class="LC_error">'.
1.1071 raeburn 11476: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11477: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11478: '</span><br />';
11479: } else {
11480: if (!print $fh $env{'form.embedded_item_'.$i}) {
11481: &Apache::lonnet::logthis('Failed to write to '.$dest);
11482: $output .= '<span class="LC_error">'.
1.1071 raeburn 11483: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11484: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11485: '</span><br />';
11486: } else {
1.987 raeburn 11487: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11488: $url.'</span>').'<br />';
11489: unless ($context eq 'testbank') {
11490: $footer .= &mt('View embedded file: [_1]',
11491: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11492: }
11493: }
11494: close($fh);
11495: }
11496: }
11497: if ($env{'form.embedded_ref_'.$i}) {
11498: $pathchange{$i} = 1;
11499: }
11500: }
11501: if ($output) {
11502: $output = '<p>'.$output.'</p>';
11503: }
11504: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11505: $returnflag = 'ok';
1.1071 raeburn 11506: my $numpathchgs = scalar(keys(%pathchange));
11507: if ($numpathchgs > 0) {
1.987 raeburn 11508: if ($context eq 'portfolio') {
11509: $output .= '<p>'.&mt('or').'</p>';
11510: } elsif ($context eq 'testbank') {
1.1071 raeburn 11511: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11512: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11513: $returnflag = 'modify_orightml';
11514: }
11515: }
1.1071 raeburn 11516: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11517: }
11518:
11519: sub modify_html_form {
11520: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11521: my $end = 0;
11522: my $modifyform;
11523: if ($context eq 'upload_embedded') {
11524: return unless (ref($pathchange) eq 'HASH');
11525: if ($env{'form.number_embedded_items'}) {
11526: $end += $env{'form.number_embedded_items'};
11527: }
11528: if ($env{'form.number_pathchange_items'}) {
11529: $end += $env{'form.number_pathchange_items'};
11530: }
11531: if ($end) {
11532: for (my $i=0; $i<$end; $i++) {
11533: if ($i < $env{'form.number_embedded_items'}) {
11534: next unless($pathchange->{$i});
11535: }
11536: $modifyform .=
11537: &start_data_table_row().
11538: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11539: 'checked="checked" /></td>'.
11540: '<td>'.$env{'form.embedded_ref_'.$i}.
11541: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11542: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11543: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11544: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11545: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11546: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11547: '<td>'.$env{'form.embedded_orig_'.$i}.
11548: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11549: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11550: &end_data_table_row();
1.1071 raeburn 11551: }
1.987 raeburn 11552: }
11553: } else {
11554: $modifyform = $pathchgtable;
11555: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11556: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11557: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11558: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11559: }
11560: }
11561: if ($modifyform) {
1.1071 raeburn 11562: if ($actionurl eq '/adm/dependencies') {
11563: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11564: }
1.987 raeburn 11565: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11566: '<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".
11567: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11568: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11569: '</ol></p>'."\n".'<p>'.
11570: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11571: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11572: &start_data_table()."\n".
11573: &start_data_table_header_row().
11574: '<th>'.&mt('Change?').'</th>'.
11575: '<th>'.&mt('Current reference').'</th>'.
11576: '<th>'.&mt('Required reference').'</th>'.
11577: &end_data_table_header_row()."\n".
11578: $modifyform.
11579: &end_data_table().'<br />'."\n".$hiddenstate.
11580: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11581: '</form>'."\n";
11582: }
11583: return;
11584: }
11585:
11586: sub modify_html_refs {
1.1075.2.35 raeburn 11587: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11588: my $container;
11589: if ($context eq 'portfolio') {
11590: $container = $env{'form.container'};
11591: } elsif ($context eq 'coursedoc') {
11592: $container = $env{'form.primaryurl'};
1.1071 raeburn 11593: } elsif ($context eq 'manage_dependencies') {
11594: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11595: $container = "/$container";
1.1075.2.35 raeburn 11596: } elsif ($context eq 'syllabus') {
11597: $container = $url;
1.987 raeburn 11598: } else {
1.1027 raeburn 11599: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11600: }
11601: my (%allfiles,%codebase,$output,$content);
11602: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 11603: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11604: if (wantarray) {
11605: return ('',0,0);
11606: } else {
11607: return;
11608: }
11609: }
11610: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11611: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11612: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11613: if (wantarray) {
11614: return ('',0,0);
11615: } else {
11616: return;
11617: }
11618: }
1.987 raeburn 11619: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11620: if ($content eq '-1') {
11621: if (wantarray) {
11622: return ('',0,0);
11623: } else {
11624: return;
11625: }
11626: }
1.987 raeburn 11627: } else {
1.1071 raeburn 11628: unless ($container =~ /^\Q$dir_root\E/) {
11629: if (wantarray) {
11630: return ('',0,0);
11631: } else {
11632: return;
11633: }
11634: }
1.1075.2.128 raeburn 11635: if (open(my $fh,'<',$container)) {
1.987 raeburn 11636: $content = join('', <$fh>);
11637: close($fh);
11638: } else {
1.1071 raeburn 11639: if (wantarray) {
11640: return ('',0,0);
11641: } else {
11642: return;
11643: }
1.987 raeburn 11644: }
11645: }
11646: my ($count,$codebasecount) = (0,0);
11647: my $mm = new File::MMagic;
11648: my $mime_type = $mm->checktype_contents($content);
11649: if ($mime_type eq 'text/html') {
11650: my $parse_result =
11651: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11652: \%codebase,\$content);
11653: if ($parse_result eq 'ok') {
11654: foreach my $i (@changes) {
11655: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11656: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11657: if ($allfiles{$ref}) {
11658: my $newname = $orig;
11659: my ($attrib_regexp,$codebase);
1.1006 raeburn 11660: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11661: if ($attrib_regexp =~ /:/) {
11662: $attrib_regexp =~ s/\:/|/g;
11663: }
11664: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11665: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11666: $count += $numchg;
1.1075.2.35 raeburn 11667: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11668: delete($allfiles{$ref});
1.987 raeburn 11669: }
11670: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11671: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11672: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11673: $codebasecount ++;
11674: }
11675: }
11676: }
1.1075.2.35 raeburn 11677: my $skiprewrites;
1.987 raeburn 11678: if ($count || $codebasecount) {
11679: my $saveresult;
1.1071 raeburn 11680: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11681: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11682: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11683: if ($url eq $container) {
11684: my ($fname) = ($container =~ m{/([^/]+)$});
11685: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11686: $count,'<span class="LC_filename">'.
1.1071 raeburn 11687: $fname.'</span>').'</p>';
1.987 raeburn 11688: } else {
11689: $output = '<p class="LC_error">'.
11690: &mt('Error: update failed for: [_1].',
11691: '<span class="LC_filename">'.
11692: $container.'</span>').'</p>';
11693: }
1.1075.2.35 raeburn 11694: if ($context eq 'syllabus') {
11695: unless ($saveresult eq 'ok') {
11696: $skiprewrites = 1;
11697: }
11698: }
1.987 raeburn 11699: } else {
1.1075.2.128 raeburn 11700: if (open(my $fh,'>',$container)) {
1.987 raeburn 11701: print $fh $content;
11702: close($fh);
11703: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11704: $count,'<span class="LC_filename">'.
11705: $container.'</span>').'</p>';
1.661 raeburn 11706: } else {
1.987 raeburn 11707: $output = '<p class="LC_error">'.
11708: &mt('Error: could not update [_1].',
11709: '<span class="LC_filename">'.
11710: $container.'</span>').'</p>';
1.661 raeburn 11711: }
11712: }
11713: }
1.1075.2.35 raeburn 11714: if (($context eq 'syllabus') && (!$skiprewrites)) {
11715: my ($actionurl,$state);
11716: $actionurl = "/public/$udom/$uname/syllabus";
11717: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11718: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11719: \%codebase,
11720: {'context' => 'rewrites',
11721: 'ignore_remote_references' => 1,});
11722: if (ref($mapping) eq 'HASH') {
11723: my $rewrites = 0;
11724: foreach my $key (keys(%{$mapping})) {
11725: next if ($key =~ m{^https?://});
11726: my $ref = $mapping->{$key};
11727: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11728: my $attrib;
11729: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11730: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11731: }
11732: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11733: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11734: $rewrites += $numchg;
11735: }
11736: }
11737: if ($rewrites) {
11738: my $saveresult;
11739: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11740: if ($url eq $container) {
11741: my ($fname) = ($container =~ m{/([^/]+)$});
11742: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11743: $count,'<span class="LC_filename">'.
11744: $fname.'</span>').'</p>';
11745: } else {
11746: $output .= '<p class="LC_error">'.
11747: &mt('Error: could not update links in [_1].',
11748: '<span class="LC_filename">'.
11749: $container.'</span>').'</p>';
11750:
11751: }
11752: }
11753: }
11754: }
1.987 raeburn 11755: } else {
11756: &logthis('Failed to parse '.$container.
11757: ' to modify references: '.$parse_result);
1.661 raeburn 11758: }
11759: }
1.1071 raeburn 11760: if (wantarray) {
11761: return ($output,$count,$codebasecount);
11762: } else {
11763: return $output;
11764: }
1.661 raeburn 11765: }
11766:
11767: sub check_for_existing {
11768: my ($path,$fname,$element) = @_;
11769: my ($state,$msg);
11770: if (-d $path.'/'.$fname) {
11771: $state = 'exists';
11772: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11773: } elsif (-e $path.'/'.$fname) {
11774: $state = 'exists';
11775: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11776: }
11777: if ($state eq 'exists') {
11778: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11779: }
11780: return ($state,$msg);
11781: }
11782:
11783: sub check_for_upload {
11784: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11785: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11786: my $filesize = length($env{'form.'.$element});
11787: if (!$filesize) {
11788: my $msg = '<span class="LC_error">'.
11789: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11790: '<span class="LC_filename">'.$fname.'</span>',
11791: $filesize).'<br />'.
1.1007 raeburn 11792: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11793: '</span>';
11794: return ('zero_bytes',$msg);
11795: }
11796: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11797: my $getpropath = 1;
1.1021 raeburn 11798: my ($dirlistref,$listerror) =
11799: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11800: my $found_file = 0;
11801: my $locked_file = 0;
1.991 raeburn 11802: my @lockers;
11803: my $navmap;
11804: if ($env{'request.course.id'}) {
11805: $navmap = Apache::lonnavmaps::navmap->new();
11806: }
1.1021 raeburn 11807: if (ref($dirlistref) eq 'ARRAY') {
11808: foreach my $line (@{$dirlistref}) {
11809: my ($file_name,$rest)=split(/\&/,$line,2);
11810: if ($file_name eq $fname){
11811: $file_name = $path.$file_name;
11812: if ($group ne '') {
11813: $file_name = $group.$file_name;
11814: }
11815: $found_file = 1;
11816: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11817: foreach my $lock (@lockers) {
11818: if (ref($lock) eq 'ARRAY') {
11819: my ($symb,$crsid) = @{$lock};
11820: if ($crsid eq $env{'request.course.id'}) {
11821: if (ref($navmap)) {
11822: my $res = $navmap->getBySymb($symb);
11823: foreach my $part (@{$res->parts()}) {
11824: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11825: unless (($slot_status == $res->RESERVED) ||
11826: ($slot_status == $res->RESERVED_LOCATION)) {
11827: $locked_file = 1;
11828: }
1.991 raeburn 11829: }
1.1021 raeburn 11830: } else {
11831: $locked_file = 1;
1.991 raeburn 11832: }
11833: } else {
11834: $locked_file = 1;
11835: }
11836: }
1.1021 raeburn 11837: }
11838: } else {
11839: my @info = split(/\&/,$rest);
11840: my $currsize = $info[6]/1000;
11841: if ($currsize < $filesize) {
11842: my $extra = $filesize - $currsize;
11843: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 11844: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11845: &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 11846: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11847: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11848: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11849: return ('will_exceed_quota',$msg);
11850: }
1.984 raeburn 11851: }
11852: }
1.661 raeburn 11853: }
11854: }
11855: }
11856: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 11857: my $msg = '<p class="LC_warning">'.
11858: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
11859: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11860: return ('will_exceed_quota',$msg);
11861: } elsif ($found_file) {
11862: if ($locked_file) {
1.1075.2.69 raeburn 11863: my $msg = '<p class="LC_warning">';
1.661 raeburn 11864: $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 11865: $msg .= '</p>';
1.661 raeburn 11866: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11867: return ('file_locked',$msg);
11868: } else {
1.1075.2.69 raeburn 11869: my $msg = '<p class="LC_error">';
1.984 raeburn 11870: $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 11871: $msg .= '</p>';
1.984 raeburn 11872: return ('existingfile',$msg);
1.661 raeburn 11873: }
11874: }
11875: }
11876:
1.987 raeburn 11877: sub check_for_traversal {
11878: my ($path,$url,$toplevel) = @_;
11879: my @parts=split(/\//,$path);
11880: my $cleanpath;
11881: my $fullpath = $url;
11882: for (my $i=0;$i<@parts;$i++) {
11883: next if ($parts[$i] eq '.');
11884: if ($parts[$i] eq '..') {
11885: $fullpath =~ s{([^/]+/)$}{};
11886: } else {
11887: $fullpath .= $parts[$i].'/';
11888: }
11889: }
11890: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11891: $cleanpath = $1;
11892: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11893: my $curr_toprel = $1;
11894: my @parts = split(/\//,$curr_toprel);
11895: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11896: my @urlparts = split(/\//,$url_toprel);
11897: my $doubledots;
11898: my $startdiff = -1;
11899: for (my $i=0; $i<@urlparts; $i++) {
11900: if ($startdiff == -1) {
11901: unless ($urlparts[$i] eq $parts[$i]) {
11902: $startdiff = $i;
11903: $doubledots .= '../';
11904: }
11905: } else {
11906: $doubledots .= '../';
11907: }
11908: }
11909: if ($startdiff > -1) {
11910: $cleanpath = $doubledots;
11911: for (my $i=$startdiff; $i<@parts; $i++) {
11912: $cleanpath .= $parts[$i].'/';
11913: }
11914: }
11915: }
11916: $cleanpath =~ s{(/)$}{};
11917: return $cleanpath;
11918: }
1.31 albertel 11919:
1.1053 raeburn 11920: sub is_archive_file {
11921: my ($mimetype) = @_;
11922: if (($mimetype eq 'application/octet-stream') ||
11923: ($mimetype eq 'application/x-stuffit') ||
11924: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11925: return 1;
11926: }
11927: return;
11928: }
11929:
11930: sub decompress_form {
1.1065 raeburn 11931: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11932: my %lt = &Apache::lonlocal::texthash (
11933: this => 'This file is an archive file.',
1.1067 raeburn 11934: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11935: itsc => 'Its contents are as follows:',
1.1053 raeburn 11936: youm => 'You may wish to extract its contents.',
11937: extr => 'Extract contents',
1.1067 raeburn 11938: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11939: proa => 'Process automatically?',
1.1053 raeburn 11940: yes => 'Yes',
11941: no => 'No',
1.1067 raeburn 11942: fold => 'Title for folder containing movie',
11943: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11944: );
1.1065 raeburn 11945: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11946: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11947: my $info = &list_archive_contents($fileloc,\@paths);
11948: if (@paths) {
11949: foreach my $path (@paths) {
11950: $path =~ s{^/}{};
1.1067 raeburn 11951: if ($path =~ m{^([^/]+)/$}) {
11952: $topdir = $1;
11953: }
1.1065 raeburn 11954: if ($path =~ m{^([^/]+)/}) {
11955: $toplevel{$1} = $path;
11956: } else {
11957: $toplevel{$path} = $path;
11958: }
11959: }
11960: }
1.1067 raeburn 11961: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 11962: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11963: "$topdir/media/",
11964: "$topdir/media/$topdir.mp4",
11965: "$topdir/media/FirstFrame.png",
11966: "$topdir/media/player.swf",
11967: "$topdir/media/swfobject.js",
11968: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 11969: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 11970: "$topdir/$topdir.mp4",
11971: "$topdir/$topdir\_config.xml",
11972: "$topdir/$topdir\_controller.swf",
11973: "$topdir/$topdir\_embed.css",
11974: "$topdir/$topdir\_First_Frame.png",
11975: "$topdir/$topdir\_player.html",
11976: "$topdir/$topdir\_Thumbnails.png",
11977: "$topdir/playerProductInstall.swf",
11978: "$topdir/scripts/",
11979: "$topdir/scripts/config_xml.js",
11980: "$topdir/scripts/handlebars.js",
11981: "$topdir/scripts/jquery-1.7.1.min.js",
11982: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11983: "$topdir/scripts/modernizr.js",
11984: "$topdir/scripts/player-min.js",
11985: "$topdir/scripts/swfobject.js",
11986: "$topdir/skins/",
11987: "$topdir/skins/configuration_express.xml",
11988: "$topdir/skins/express_show/",
11989: "$topdir/skins/express_show/player-min.css",
11990: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 11991: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
11992: "$topdir/$topdir.mp4",
11993: "$topdir/$topdir\_config.xml",
11994: "$topdir/$topdir\_controller.swf",
11995: "$topdir/$topdir\_embed.css",
11996: "$topdir/$topdir\_First_Frame.png",
11997: "$topdir/$topdir\_player.html",
11998: "$topdir/$topdir\_Thumbnails.png",
11999: "$topdir/playerProductInstall.swf",
12000: "$topdir/scripts/",
12001: "$topdir/scripts/config_xml.js",
12002: "$topdir/scripts/techsmith-smart-player.min.js",
12003: "$topdir/skins/",
12004: "$topdir/skins/configuration_express.xml",
12005: "$topdir/skins/express_show/",
12006: "$topdir/skins/express_show/spritesheet.min.css",
12007: "$topdir/skins/express_show/spritesheet.png",
12008: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 12009: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12010: if (@diffs == 0) {
1.1075.2.59 raeburn 12011: $is_camtasia = 6;
12012: } else {
1.1075.2.81 raeburn 12013: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 12014: if (@diffs == 0) {
12015: $is_camtasia = 8;
1.1075.2.81 raeburn 12016: } else {
12017: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12018: if (@diffs == 0) {
12019: $is_camtasia = 8;
12020: }
1.1075.2.59 raeburn 12021: }
1.1067 raeburn 12022: }
12023: }
12024: my $output;
12025: if ($is_camtasia) {
12026: $output = <<"ENDCAM";
12027: <script type="text/javascript" language="Javascript">
12028: // <![CDATA[
12029:
12030: function camtasiaToggle() {
12031: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12032: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 12033: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12034: document.getElementById('camtasia_titles').style.display='block';
12035: } else {
12036: document.getElementById('camtasia_titles').style.display='none';
12037: }
12038: }
12039: }
12040: return;
12041: }
12042:
12043: // ]]>
12044: </script>
12045: <p>$lt{'camt'}</p>
12046: ENDCAM
1.1065 raeburn 12047: } else {
1.1067 raeburn 12048: $output = '<p>'.$lt{'this'};
12049: if ($info eq '') {
12050: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12051: } else {
12052: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12053: '<div><pre>'.$info.'</pre></div>';
12054: }
1.1065 raeburn 12055: }
1.1067 raeburn 12056: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12057: my $duplicates;
12058: my $num = 0;
12059: if (ref($dirlist) eq 'ARRAY') {
12060: foreach my $item (@{$dirlist}) {
12061: if (ref($item) eq 'ARRAY') {
12062: if (exists($toplevel{$item->[0]})) {
12063: $duplicates .=
12064: &start_data_table_row().
12065: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12066: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12067: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12068: 'value="1" />'.&mt('Yes').'</label>'.
12069: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12070: '<td>'.$item->[0].'</td>';
12071: if ($item->[2]) {
12072: $duplicates .= '<td>'.&mt('Directory').'</td>';
12073: } else {
12074: $duplicates .= '<td>'.&mt('File').'</td>';
12075: }
12076: $duplicates .= '<td>'.$item->[3].'</td>'.
12077: '<td>'.
12078: &Apache::lonlocal::locallocaltime($item->[4]).
12079: '</td>'.
12080: &end_data_table_row();
12081: $num ++;
12082: }
12083: }
12084: }
12085: }
12086: my $itemcount;
12087: if (@paths > 0) {
12088: $itemcount = scalar(@paths);
12089: } else {
12090: $itemcount = 1;
12091: }
1.1067 raeburn 12092: if ($is_camtasia) {
12093: $output .= $lt{'auto'}.'<br />'.
12094: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 12095: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12096: $lt{'yes'}.'</label> <label>'.
12097: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12098: $lt{'no'}.'</label></span><br />'.
12099: '<div id="camtasia_titles" style="display:block">'.
12100: &Apache::lonhtmlcommon::start_pick_box().
12101: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12102: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12103: &Apache::lonhtmlcommon::row_closure().
12104: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12105: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12106: &Apache::lonhtmlcommon::row_closure(1).
12107: &Apache::lonhtmlcommon::end_pick_box().
12108: '</div>';
12109: }
1.1065 raeburn 12110: $output .=
12111: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12112: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12113: "\n";
1.1065 raeburn 12114: if ($duplicates ne '') {
12115: $output .= '<p><span class="LC_warning">'.
12116: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12117: &start_data_table().
12118: &start_data_table_header_row().
12119: '<th>'.&mt('Overwrite?').'</th>'.
12120: '<th>'.&mt('Name').'</th>'.
12121: '<th>'.&mt('Type').'</th>'.
12122: '<th>'.&mt('Size').'</th>'.
12123: '<th>'.&mt('Last modified').'</th>'.
12124: &end_data_table_header_row().
12125: $duplicates.
12126: &end_data_table().
12127: '</p>';
12128: }
1.1067 raeburn 12129: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12130: if (ref($hiddenelements) eq 'HASH') {
12131: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12132: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12133: }
12134: }
12135: $output .= <<"END";
1.1067 raeburn 12136: <br />
1.1053 raeburn 12137: <input type="submit" name="decompress" value="$lt{'extr'}" />
12138: </form>
12139: $noextract
12140: END
12141: return $output;
12142: }
12143:
1.1065 raeburn 12144: sub decompression_utility {
12145: my ($program) = @_;
12146: my @utilities = ('tar','gunzip','bunzip2','unzip');
12147: my $location;
12148: if (grep(/^\Q$program\E$/,@utilities)) {
12149: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12150: '/usr/sbin/') {
12151: if (-x $dir.$program) {
12152: $location = $dir.$program;
12153: last;
12154: }
12155: }
12156: }
12157: return $location;
12158: }
12159:
12160: sub list_archive_contents {
12161: my ($file,$pathsref) = @_;
12162: my (@cmd,$output);
12163: my $needsregexp;
12164: if ($file =~ /\.zip$/) {
12165: @cmd = (&decompression_utility('unzip'),"-l");
12166: $needsregexp = 1;
12167: } elsif (($file =~ m/\.tar\.gz$/) ||
12168: ($file =~ /\.tgz$/)) {
12169: @cmd = (&decompression_utility('tar'),"-ztf");
12170: } elsif ($file =~ /\.tar\.bz2$/) {
12171: @cmd = (&decompression_utility('tar'),"-jtf");
12172: } elsif ($file =~ m|\.tar$|) {
12173: @cmd = (&decompression_utility('tar'),"-tf");
12174: }
12175: if (@cmd) {
12176: undef($!);
12177: undef($@);
12178: if (open(my $fh,"-|", @cmd, $file)) {
12179: while (my $line = <$fh>) {
12180: $output .= $line;
12181: chomp($line);
12182: my $item;
12183: if ($needsregexp) {
12184: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12185: } else {
12186: $item = $line;
12187: }
12188: if ($item ne '') {
12189: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12190: push(@{$pathsref},$item);
12191: }
12192: }
12193: }
12194: close($fh);
12195: }
12196: }
12197: return $output;
12198: }
12199:
1.1053 raeburn 12200: sub decompress_uploaded_file {
12201: my ($file,$dir) = @_;
12202: &Apache::lonnet::appenv({'cgi.file' => $file});
12203: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12204: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12205: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12206: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12207: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12208: my $decompressed = $env{'cgi.decompressed'};
12209: &Apache::lonnet::delenv('cgi.file');
12210: &Apache::lonnet::delenv('cgi.dir');
12211: &Apache::lonnet::delenv('cgi.decompressed');
12212: return ($decompressed,$result);
12213: }
12214:
1.1055 raeburn 12215: sub process_decompression {
12216: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 12217: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12218: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12219: &mt('Unexpected file path.').'</p>'."\n";
12220: }
12221: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12222: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12223: &mt('Unexpected course context.').'</p>'."\n";
12224: }
12225: unless ($file eq &Apache::lonnet::clean_filename($file)) {
12226: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12227: &mt('Filename contained unexpected characters.').'</p>'."\n";
12228: }
1.1055 raeburn 12229: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 12230: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 12231: $error = &mt('Filename not a supported archive file type.').
12232: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12233: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12234: } else {
12235: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12236: if ($docuhome eq 'no_host') {
12237: $error = &mt('Could not determine home server for course.');
12238: } else {
12239: my @ids=&Apache::lonnet::current_machine_ids();
12240: my $currdir = "$dir_root/$destination";
12241: if (grep(/^\Q$docuhome\E$/,@ids)) {
12242: $dir = &LONCAPA::propath($docudom,$docuname).
12243: "$dir_root/$destination";
12244: } else {
12245: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12246: "$dir_root/$docudom/$docuname/$destination";
12247: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12248: $error = &mt('Archive file not found.');
12249: }
12250: }
1.1065 raeburn 12251: my (@to_overwrite,@to_skip);
12252: if ($env{'form.archive_overwrite_total'} > 0) {
12253: my $total = $env{'form.archive_overwrite_total'};
12254: for (my $i=0; $i<$total; $i++) {
12255: if ($env{'form.archive_overwrite_'.$i} == 1) {
12256: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12257: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12258: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12259: }
12260: }
12261: }
12262: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 12263: my $numoverwrite = scalar(@to_overwrite);
12264: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12265: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12266: } elsif ($dir eq '') {
1.1055 raeburn 12267: $error = &mt('Directory containing archive file unavailable.');
12268: } elsif (!$error) {
1.1065 raeburn 12269: my ($decompressed,$display);
1.1075.2.128 raeburn 12270: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12271: my $tempdir = time.'_'.$$.int(rand(10000));
12272: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 12273: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12274: ($decompressed,$display) =
12275: &decompress_uploaded_file($file,"$dir/$tempdir");
12276: foreach my $item (@to_skip) {
12277: if (($item ne '') && ($item !~ /\.\./)) {
12278: if (-f "$dir/$tempdir/$item") {
12279: unlink("$dir/$tempdir/$item");
12280: } elsif (-d "$dir/$tempdir/$item") {
12281: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
12282: }
12283: }
12284: }
12285: foreach my $item (@to_overwrite) {
12286: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12287: if (($item ne '') && ($item !~ /\.\./)) {
12288: if (-f "$dir/$item") {
12289: unlink("$dir/$item");
12290: } elsif (-d "$dir/$item") {
12291: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
12292: }
12293: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12294: }
1.1065 raeburn 12295: }
12296: }
1.1075.2.128 raeburn 12297: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
12298: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
12299: }
1.1065 raeburn 12300: }
12301: } else {
12302: ($decompressed,$display) =
12303: &decompress_uploaded_file($file,$dir);
12304: }
1.1055 raeburn 12305: if ($decompressed eq 'ok') {
1.1065 raeburn 12306: $output = '<p class="LC_info">'.
12307: &mt('Files extracted successfully from archive.').
12308: '</p>'."\n";
1.1055 raeburn 12309: my ($warning,$result,@contents);
12310: my ($newdirlistref,$newlisterror) =
12311: &Apache::lonnet::dirlist($currdir,$docudom,
12312: $docuname,1);
12313: my (%is_dir,%changes,@newitems);
12314: my $dirptr = 16384;
1.1065 raeburn 12315: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12316: foreach my $dir_line (@{$newdirlistref}) {
12317: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 12318: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12319: push(@newitems,$item);
12320: if ($dirptr&$testdir) {
12321: $is_dir{$item} = 1;
12322: }
12323: $changes{$item} = 1;
12324: }
12325: }
12326: }
12327: if (keys(%changes) > 0) {
12328: foreach my $item (sort(@newitems)) {
12329: if ($changes{$item}) {
12330: push(@contents,$item);
12331: }
12332: }
12333: }
12334: if (@contents > 0) {
1.1067 raeburn 12335: my $wantform;
12336: unless ($env{'form.autoextract_camtasia'}) {
12337: $wantform = 1;
12338: }
1.1056 raeburn 12339: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12340: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12341: $currdir,\%is_dir,
12342: \%children,\%parent,
1.1056 raeburn 12343: \@contents,\%dirorder,
12344: \%titles,$wantform);
1.1055 raeburn 12345: if ($datatable ne '') {
12346: $output .= &archive_options_form('decompressed',$datatable,
12347: $count,$hiddenelem);
1.1065 raeburn 12348: my $startcount = 6;
1.1055 raeburn 12349: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12350: \%titles,\%children);
1.1055 raeburn 12351: }
1.1067 raeburn 12352: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 12353: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12354: my %displayed;
12355: my $total = 1;
12356: $env{'form.archive_directory'} = [];
12357: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12358: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12359: $path =~ s{/$}{};
12360: my $item;
12361: if ($path ne '') {
12362: $item = "$path/$titles{$i}";
12363: } else {
12364: $item = $titles{$i};
12365: }
12366: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12367: if ($item eq $contents[0]) {
12368: push(@{$env{'form.archive_directory'}},$i);
12369: $env{'form.archive_'.$i} = 'display';
12370: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12371: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 12372: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12373: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12374: $env{'form.archive_'.$i} = 'display';
12375: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12376: $displayed{'web'} = $i;
12377: } else {
1.1075.2.59 raeburn 12378: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12379: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12380: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12381: push(@{$env{'form.archive_directory'}},$i);
12382: }
12383: $env{'form.archive_'.$i} = 'dependency';
12384: }
12385: $total ++;
12386: }
12387: for (my $i=1; $i<$total; $i++) {
12388: next if ($i == $displayed{'web'});
12389: next if ($i == $displayed{'folder'});
12390: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12391: }
12392: $env{'form.phase'} = 'decompress_cleanup';
12393: $env{'form.archivedelete'} = 1;
12394: $env{'form.archive_count'} = $total-1;
12395: $output .=
12396: &process_extracted_files('coursedocs',$docudom,
12397: $docuname,$destination,
12398: $dir_root,$hiddenelem);
12399: }
1.1055 raeburn 12400: } else {
12401: $warning = &mt('No new items extracted from archive file.');
12402: }
12403: } else {
12404: $output = $display;
12405: $error = &mt('An error occurred during extraction from the archive file.');
12406: }
12407: }
12408: }
12409: }
12410: if ($error) {
12411: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12412: $error.'</p>'."\n";
12413: }
12414: if ($warning) {
12415: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12416: }
12417: return $output;
12418: }
12419:
12420: sub get_extracted {
1.1056 raeburn 12421: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12422: $titles,$wantform) = @_;
1.1055 raeburn 12423: my $count = 0;
12424: my $depth = 0;
12425: my $datatable;
1.1056 raeburn 12426: my @hierarchy;
1.1055 raeburn 12427: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12428: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12429: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12430: foreach my $item (@{$contents}) {
12431: $count ++;
1.1056 raeburn 12432: @{$dirorder->{$count}} = @hierarchy;
12433: $titles->{$count} = $item;
1.1055 raeburn 12434: &archive_hierarchy($depth,$count,$parent,$children);
12435: if ($wantform) {
12436: $datatable .= &archive_row($is_dir->{$item},$item,
12437: $currdir,$depth,$count);
12438: }
12439: if ($is_dir->{$item}) {
12440: $depth ++;
1.1056 raeburn 12441: push(@hierarchy,$count);
12442: $parent->{$depth} = $count;
1.1055 raeburn 12443: $datatable .=
12444: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12445: \$depth,\$count,\@hierarchy,$dirorder,
12446: $children,$parent,$titles,$wantform);
1.1055 raeburn 12447: $depth --;
1.1056 raeburn 12448: pop(@hierarchy);
1.1055 raeburn 12449: }
12450: }
12451: return ($count,$datatable);
12452: }
12453:
12454: sub recurse_extracted_archive {
1.1056 raeburn 12455: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12456: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12457: my $result='';
1.1056 raeburn 12458: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12459: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12460: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12461: return $result;
12462: }
12463: my $dirptr = 16384;
12464: my ($newdirlistref,$newlisterror) =
12465: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12466: if (ref($newdirlistref) eq 'ARRAY') {
12467: foreach my $dir_line (@{$newdirlistref}) {
12468: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12469: unless ($item =~ /^\.+$/) {
12470: $$count ++;
1.1056 raeburn 12471: @{$dirorder->{$$count}} = @{$hierarchy};
12472: $titles->{$$count} = $item;
1.1055 raeburn 12473: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12474:
1.1055 raeburn 12475: my $is_dir;
12476: if ($dirptr&$testdir) {
12477: $is_dir = 1;
12478: }
12479: if ($wantform) {
12480: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12481: }
12482: if ($is_dir) {
12483: $$depth ++;
1.1056 raeburn 12484: push(@{$hierarchy},$$count);
12485: $parent->{$$depth} = $$count;
1.1055 raeburn 12486: $result .=
12487: &recurse_extracted_archive("$currdir/$item",$docudom,
12488: $docuname,$depth,$count,
1.1056 raeburn 12489: $hierarchy,$dirorder,$children,
12490: $parent,$titles,$wantform);
1.1055 raeburn 12491: $$depth --;
1.1056 raeburn 12492: pop(@{$hierarchy});
1.1055 raeburn 12493: }
12494: }
12495: }
12496: }
12497: return $result;
12498: }
12499:
12500: sub archive_hierarchy {
12501: my ($depth,$count,$parent,$children) =@_;
12502: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12503: if (exists($parent->{$depth})) {
12504: $children->{$parent->{$depth}} .= $count.':';
12505: }
12506: }
12507: return;
12508: }
12509:
12510: sub archive_row {
12511: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12512: my ($name) = ($item =~ m{([^/]+)$});
12513: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12514: 'display' => 'Add as file',
1.1055 raeburn 12515: 'dependency' => 'Include as dependency',
12516: 'discard' => 'Discard',
12517: );
12518: if ($is_dir) {
1.1059 raeburn 12519: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12520: }
1.1056 raeburn 12521: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12522: my $offset = 0;
1.1055 raeburn 12523: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12524: $offset ++;
1.1065 raeburn 12525: if ($action ne 'display') {
12526: $offset ++;
12527: }
1.1055 raeburn 12528: $output .= '<td><span class="LC_nobreak">'.
12529: '<label><input type="radio" name="archive_'.$count.
12530: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12531: my $text = $choices{$action};
12532: if ($is_dir) {
12533: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12534: if ($action eq 'display') {
1.1059 raeburn 12535: $text = &mt('Add as folder');
1.1055 raeburn 12536: }
1.1056 raeburn 12537: } else {
12538: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12539:
12540: }
12541: $output .= ' /> '.$choices{$action}.'</label></span>';
12542: if ($action eq 'dependency') {
12543: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12544: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12545: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12546: '<option value=""></option>'."\n".
12547: '</select>'."\n".
12548: '</div>';
1.1059 raeburn 12549: } elsif ($action eq 'display') {
12550: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12551: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12552: '</div>';
1.1055 raeburn 12553: }
1.1056 raeburn 12554: $output .= '</td>';
1.1055 raeburn 12555: }
12556: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12557: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12558: for (my $i=0; $i<$depth; $i++) {
12559: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12560: }
12561: if ($is_dir) {
12562: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12563: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12564: } else {
12565: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12566: }
12567: $output .= ' '.$name.'</td>'."\n".
12568: &end_data_table_row();
12569: return $output;
12570: }
12571:
12572: sub archive_options_form {
1.1065 raeburn 12573: my ($form,$display,$count,$hiddenelem) = @_;
12574: my %lt = &Apache::lonlocal::texthash(
12575: perm => 'Permanently remove archive file?',
12576: hows => 'How should each extracted item be incorporated in the course?',
12577: cont => 'Content actions for all',
12578: addf => 'Add as folder/file',
12579: incd => 'Include as dependency for a displayed file',
12580: disc => 'Discard',
12581: no => 'No',
12582: yes => 'Yes',
12583: save => 'Save',
12584: );
12585: my $output = <<"END";
12586: <form name="$form" method="post" action="">
12587: <p><span class="LC_nobreak">$lt{'perm'}
12588: <label>
12589: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12590: </label>
12591:
12592: <label>
12593: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12594: </span>
12595: </p>
12596: <input type="hidden" name="phase" value="decompress_cleanup" />
12597: <br />$lt{'hows'}
12598: <div class="LC_columnSection">
12599: <fieldset>
12600: <legend>$lt{'cont'}</legend>
12601: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12602: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12603: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12604: </fieldset>
12605: </div>
12606: END
12607: return $output.
1.1055 raeburn 12608: &start_data_table()."\n".
1.1065 raeburn 12609: $display."\n".
1.1055 raeburn 12610: &end_data_table()."\n".
12611: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12612: $hiddenelem.
1.1065 raeburn 12613: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12614: '</form>';
12615: }
12616:
12617: sub archive_javascript {
1.1056 raeburn 12618: my ($startcount,$numitems,$titles,$children) = @_;
12619: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12620: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12621: my $scripttag = <<START;
12622: <script type="text/javascript">
12623: // <![CDATA[
12624:
12625: function checkAll(form,prefix) {
12626: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12627: for (var i=0; i < form.elements.length; i++) {
12628: var id = form.elements[i].id;
12629: if ((id != '') && (id != undefined)) {
12630: if (idstr.test(id)) {
12631: if (form.elements[i].type == 'radio') {
12632: form.elements[i].checked = true;
1.1056 raeburn 12633: var nostart = i-$startcount;
1.1059 raeburn 12634: var offset = nostart%7;
12635: var count = (nostart-offset)/7;
1.1056 raeburn 12636: dependencyCheck(form,count,offset);
1.1055 raeburn 12637: }
12638: }
12639: }
12640: }
12641: }
12642:
12643: function propagateCheck(form,count) {
12644: if (count > 0) {
1.1059 raeburn 12645: var startelement = $startcount + ((count-1) * 7);
12646: for (var j=1; j<6; j++) {
12647: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12648: var item = startelement + j;
12649: if (form.elements[item].type == 'radio') {
12650: if (form.elements[item].checked) {
12651: containerCheck(form,count,j);
12652: break;
12653: }
1.1055 raeburn 12654: }
12655: }
12656: }
12657: }
12658: }
12659:
12660: numitems = $numitems
1.1056 raeburn 12661: var titles = new Array(numitems);
12662: var parents = new Array(numitems);
1.1055 raeburn 12663: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12664: parents[i] = new Array;
1.1055 raeburn 12665: }
1.1059 raeburn 12666: var maintitle = '$maintitle';
1.1055 raeburn 12667:
12668: START
12669:
1.1056 raeburn 12670: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12671: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12672: for (my $i=0; $i<@contents; $i ++) {
12673: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12674: }
12675: }
12676:
1.1056 raeburn 12677: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12678: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12679: }
12680:
1.1055 raeburn 12681: $scripttag .= <<END;
12682:
12683: function containerCheck(form,count,offset) {
12684: if (count > 0) {
1.1056 raeburn 12685: dependencyCheck(form,count,offset);
1.1059 raeburn 12686: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12687: form.elements[item].checked = true;
12688: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12689: if (parents[count].length > 0) {
12690: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12691: containerCheck(form,parents[count][j],offset);
12692: }
12693: }
12694: }
12695: }
12696: }
12697:
12698: function dependencyCheck(form,count,offset) {
12699: if (count > 0) {
1.1059 raeburn 12700: var chosen = (offset+$startcount)+7*(count-1);
12701: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12702: var currtype = form.elements[depitem].type;
12703: if (form.elements[chosen].value == 'dependency') {
12704: document.getElementById('arc_depon_'+count).style.display='block';
12705: form.elements[depitem].options.length = 0;
12706: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 12707: for (var i=1; i<=numitems; i++) {
12708: if (i == count) {
12709: continue;
12710: }
1.1059 raeburn 12711: var startelement = $startcount + (i-1) * 7;
12712: for (var j=1; j<6; j++) {
12713: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12714: var item = startelement + j;
12715: if (form.elements[item].type == 'radio') {
12716: if (form.elements[item].checked) {
12717: if (form.elements[item].value == 'display') {
12718: var n = form.elements[depitem].options.length;
12719: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12720: }
12721: }
12722: }
12723: }
12724: }
12725: }
12726: } else {
12727: document.getElementById('arc_depon_'+count).style.display='none';
12728: form.elements[depitem].options.length = 0;
12729: form.elements[depitem].options[0] = new Option('Select','',true,true);
12730: }
1.1059 raeburn 12731: titleCheck(form,count,offset);
1.1056 raeburn 12732: }
12733: }
12734:
12735: function propagateSelect(form,count,offset) {
12736: if (count > 0) {
1.1065 raeburn 12737: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12738: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12739: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12740: if (parents[count].length > 0) {
12741: for (var j=0; j<parents[count].length; j++) {
12742: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12743: }
12744: }
12745: }
12746: }
12747: }
1.1056 raeburn 12748:
12749: function containerSelect(form,count,offset,picked) {
12750: if (count > 0) {
1.1065 raeburn 12751: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12752: if (form.elements[item].type == 'radio') {
12753: if (form.elements[item].value == 'dependency') {
12754: if (form.elements[item+1].type == 'select-one') {
12755: for (var i=0; i<form.elements[item+1].options.length; i++) {
12756: if (form.elements[item+1].options[i].value == picked) {
12757: form.elements[item+1].selectedIndex = i;
12758: break;
12759: }
12760: }
12761: }
12762: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12763: if (parents[count].length > 0) {
12764: for (var j=0; j<parents[count].length; j++) {
12765: containerSelect(form,parents[count][j],offset,picked);
12766: }
12767: }
12768: }
12769: }
12770: }
12771: }
12772: }
12773:
1.1059 raeburn 12774: function titleCheck(form,count,offset) {
12775: if (count > 0) {
12776: var chosen = (offset+$startcount)+7*(count-1);
12777: var depitem = $startcount + ((count-1) * 7) + 2;
12778: var currtype = form.elements[depitem].type;
12779: if (form.elements[chosen].value == 'display') {
12780: document.getElementById('arc_title_'+count).style.display='block';
12781: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12782: document.getElementById('archive_title_'+count).value=maintitle;
12783: }
12784: } else {
12785: document.getElementById('arc_title_'+count).style.display='none';
12786: if (currtype == 'text') {
12787: document.getElementById('archive_title_'+count).value='';
12788: }
12789: }
12790: }
12791: return;
12792: }
12793:
1.1055 raeburn 12794: // ]]>
12795: </script>
12796: END
12797: return $scripttag;
12798: }
12799:
12800: sub process_extracted_files {
1.1067 raeburn 12801: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12802: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 12803: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 12804: my @ids=&Apache::lonnet::current_machine_ids();
12805: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12806: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12807: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12808: if (grep(/^\Q$docuhome\E$/,@ids)) {
12809: $prefix = &LONCAPA::propath($docudom,$docuname);
12810: $pathtocheck = "$dir_root/$destination";
12811: $dir = $dir_root;
12812: $ishome = 1;
12813: } else {
12814: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12815: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 12816: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 12817: }
12818: my $currdir = "$dir_root/$destination";
12819: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12820: if ($env{'form.folderpath'}) {
12821: my @items = split('&',$env{'form.folderpath'});
12822: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 12823: if ($env{'form.folderpath'} =~ /\:1$/) {
12824: $containers{'0'}='page';
12825: } else {
12826: $containers{'0'}='sequence';
12827: }
1.1055 raeburn 12828: }
12829: my @archdirs = &get_env_multiple('form.archive_directory');
12830: if ($numitems) {
12831: for (my $i=1; $i<=$numitems; $i++) {
12832: my $path = $env{'form.archive_content_'.$i};
12833: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12834: my $item = $1;
12835: $toplevelitems{$item} = $i;
12836: if (grep(/^\Q$i\E$/,@archdirs)) {
12837: $is_dir{$item} = 1;
12838: }
12839: }
12840: }
12841: }
1.1067 raeburn 12842: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12843: if (keys(%toplevelitems) > 0) {
12844: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12845: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12846: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12847: }
1.1066 raeburn 12848: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12849: if ($numitems) {
12850: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 12851: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12852: my $path = $env{'form.archive_content_'.$i};
12853: if ($path =~ /^\Q$pathtocheck\E/) {
12854: if ($env{'form.archive_'.$i} eq 'discard') {
12855: if ($prefix ne '' && $path ne '') {
12856: if (-e $prefix.$path) {
1.1066 raeburn 12857: if ((@archdirs > 0) &&
12858: (grep(/^\Q$i\E$/,@archdirs))) {
12859: $todeletedir{$prefix.$path} = 1;
12860: } else {
12861: $todelete{$prefix.$path} = 1;
12862: }
1.1055 raeburn 12863: }
12864: }
12865: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12866: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12867: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12868: $docstitle = $env{'form.archive_title_'.$i};
12869: if ($docstitle eq '') {
12870: $docstitle = $title;
12871: }
1.1055 raeburn 12872: $outer = 0;
1.1056 raeburn 12873: if (ref($dirorder{$i}) eq 'ARRAY') {
12874: if (@{$dirorder{$i}} > 0) {
12875: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12876: if ($env{'form.archive_'.$item} eq 'display') {
12877: $outer = $item;
12878: last;
12879: }
12880: }
12881: }
12882: }
12883: my ($errtext,$fatal) =
12884: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12885: '/'.$folders{$outer}.'.'.
12886: $containers{$outer});
12887: next if ($fatal);
12888: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12889: if ($context eq 'coursedocs') {
1.1056 raeburn 12890: $mapinner{$i} = time;
1.1055 raeburn 12891: $folders{$i} = 'default_'.$mapinner{$i};
12892: $containers{$i} = 'sequence';
12893: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12894: $folders{$i}.'.'.$containers{$i};
12895: my $newidx = &LONCAPA::map::getresidx();
12896: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12897: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12898: push(@LONCAPA::map::order,$newidx);
12899: my ($outtext,$errtext) =
12900: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12901: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12902: '.'.$containers{$outer},1,1);
1.1056 raeburn 12903: $newseqid{$i} = $newidx;
1.1067 raeburn 12904: unless ($errtext) {
1.1075.2.128 raeburn 12905: $result .= '<li>'.&mt('Folder: [_1] added to course',
12906: &HTML::Entities::encode($docstitle,'<>&"'))..
12907: '</li>'."\n";
1.1067 raeburn 12908: }
1.1055 raeburn 12909: }
12910: } else {
12911: if ($context eq 'coursedocs') {
12912: my $newidx=&LONCAPA::map::getresidx();
12913: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12914: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12915: $title;
1.1075.2.128 raeburn 12916: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
12917: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
12918: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 12919: }
1.1075.2.128 raeburn 12920: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12921: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
12922: }
12923: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12924: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
12925: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
12926: unless ($ishome) {
12927: my $fetch = "$newdest{$i}/$title";
12928: $fetch =~ s/^\Q$prefix$dir\E//;
12929: $prompttofetch{$fetch} = 1;
12930: }
12931: }
12932: }
12933: $LONCAPA::map::resources[$newidx]=
12934: $docstitle.':'.$url.':false:normal:res';
12935: push(@LONCAPA::map::order, $newidx);
12936: my ($outtext,$errtext)=
12937: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12938: $docuname.'/'.$folders{$outer}.
12939: '.'.$containers{$outer},1,1);
12940: unless ($errtext) {
12941: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
12942: $result .= '<li>'.&mt('File: [_1] added to course',
12943: &HTML::Entities::encode($docstitle,'<>&"')).
12944: '</li>'."\n";
12945: }
1.1067 raeburn 12946: }
1.1075.2.128 raeburn 12947: } else {
12948: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
12949: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 12950: }
1.1055 raeburn 12951: }
12952: }
1.1075.2.11 raeburn 12953: }
12954: } else {
1.1075.2.128 raeburn 12955: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
12956: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 12957: }
12958: }
12959: for (my $i=1; $i<=$numitems; $i++) {
12960: next unless ($env{'form.archive_'.$i} eq 'dependency');
12961: my $path = $env{'form.archive_content_'.$i};
12962: if ($path =~ /^\Q$pathtocheck\E/) {
12963: my ($title) = ($path =~ m{/([^/]+)$});
12964: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12965: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12966: if (ref($dirorder{$i}) eq 'ARRAY') {
12967: my ($itemidx,$fullpath,$relpath);
12968: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12969: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12970: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 12971: if ($dirorder{$i}->[$j] eq $container) {
12972: $itemidx = $j;
1.1056 raeburn 12973: }
12974: }
1.1075.2.11 raeburn 12975: }
12976: if ($itemidx eq '') {
12977: $itemidx = 0;
12978: }
12979: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12980: if ($mapinner{$referrer{$i}}) {
12981: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12982: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12983: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12984: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12985: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12986: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12987: if (!-e $fullpath) {
12988: mkdir($fullpath,0755);
1.1056 raeburn 12989: }
12990: }
1.1075.2.11 raeburn 12991: } else {
12992: last;
1.1056 raeburn 12993: }
1.1075.2.11 raeburn 12994: }
12995: }
12996: } elsif ($newdest{$referrer{$i}}) {
12997: $fullpath = $newdest{$referrer{$i}};
12998: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12999: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13000: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13001: last;
13002: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13003: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13004: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13005: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13006: if (!-e $fullpath) {
13007: mkdir($fullpath,0755);
1.1056 raeburn 13008: }
13009: }
1.1075.2.11 raeburn 13010: } else {
13011: last;
1.1056 raeburn 13012: }
1.1075.2.11 raeburn 13013: }
13014: }
13015: if ($fullpath ne '') {
13016: if (-e "$prefix$path") {
1.1075.2.128 raeburn 13017: unless (rename("$prefix$path","$fullpath/$title")) {
13018: $warning .= &mt('Failed to rename dependency').'<br />';
13019: }
1.1075.2.11 raeburn 13020: }
13021: if (-e "$fullpath/$title") {
13022: my $showpath;
13023: if ($relpath ne '') {
13024: $showpath = "$relpath/$title";
13025: } else {
13026: $showpath = "/$title";
1.1056 raeburn 13027: }
1.1075.2.128 raeburn 13028: $result .= '<li>'.&mt('[_1] included as a dependency',
13029: &HTML::Entities::encode($showpath,'<>&"')).
13030: '</li>'."\n";
13031: unless ($ishome) {
13032: my $fetch = "$fullpath/$title";
13033: $fetch =~ s/^\Q$prefix$dir\E//;
13034: $prompttofetch{$fetch} = 1;
13035: }
1.1055 raeburn 13036: }
13037: }
13038: }
1.1075.2.11 raeburn 13039: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13040: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 13041: &HTML::Entities::encode($path,'<>&"'),
13042: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13043: '<br />';
1.1055 raeburn 13044: }
13045: } else {
1.1075.2.128 raeburn 13046: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13047: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13048: }
13049: }
13050: if (keys(%todelete)) {
13051: foreach my $key (keys(%todelete)) {
13052: unlink($key);
1.1066 raeburn 13053: }
13054: }
13055: if (keys(%todeletedir)) {
13056: foreach my $key (keys(%todeletedir)) {
13057: rmdir($key);
13058: }
13059: }
13060: foreach my $dir (sort(keys(%is_dir))) {
13061: if (($pathtocheck ne '') && ($dir ne '')) {
13062: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13063: }
13064: }
1.1067 raeburn 13065: if ($result ne '') {
13066: $output .= '<ul>'."\n".
13067: $result."\n".
13068: '</ul>';
13069: }
13070: unless ($ishome) {
13071: my $replicationfail;
13072: foreach my $item (keys(%prompttofetch)) {
13073: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13074: unless ($fetchresult eq 'ok') {
13075: $replicationfail .= '<li>'.$item.'</li>'."\n";
13076: }
13077: }
13078: if ($replicationfail) {
13079: $output .= '<p class="LC_error">'.
13080: &mt('Course home server failed to retrieve:').'<ul>'.
13081: $replicationfail.
13082: '</ul></p>';
13083: }
13084: }
1.1055 raeburn 13085: } else {
13086: $warning = &mt('No items found in archive.');
13087: }
13088: if ($error) {
13089: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13090: $error.'</p>'."\n";
13091: }
13092: if ($warning) {
13093: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13094: }
13095: return $output;
13096: }
13097:
1.1066 raeburn 13098: sub cleanup_empty_dirs {
13099: my ($path) = @_;
13100: if (($path ne '') && (-d $path)) {
13101: if (opendir(my $dirh,$path)) {
13102: my @dircontents = grep(!/^\./,readdir($dirh));
13103: my $numitems = 0;
13104: foreach my $item (@dircontents) {
13105: if (-d "$path/$item") {
1.1075.2.28 raeburn 13106: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13107: if (-e "$path/$item") {
13108: $numitems ++;
13109: }
13110: } else {
13111: $numitems ++;
13112: }
13113: }
13114: if ($numitems == 0) {
13115: rmdir($path);
13116: }
13117: closedir($dirh);
13118: }
13119: }
13120: return;
13121: }
13122:
1.41 ng 13123: =pod
1.45 matthew 13124:
1.1075.2.56 raeburn 13125: =item * &get_folder_hierarchy()
1.1068 raeburn 13126:
13127: Provides hierarchy of names of folders/sub-folders containing the current
13128: item,
13129:
13130: Inputs: 3
13131: - $navmap - navmaps object
13132:
13133: - $map - url for map (either the trigger itself, or map containing
13134: the resource, which is the trigger).
13135:
13136: - $showitem - 1 => show title for map itself; 0 => do not show.
13137:
13138: Outputs: 1 @pathitems - array of folder/subfolder names.
13139:
13140: =cut
13141:
13142: sub get_folder_hierarchy {
13143: my ($navmap,$map,$showitem) = @_;
13144: my @pathitems;
13145: if (ref($navmap)) {
13146: my $mapres = $navmap->getResourceByUrl($map);
13147: if (ref($mapres)) {
13148: my $pcslist = $mapres->map_hierarchy();
13149: if ($pcslist ne '') {
13150: my @pcs = split(/,/,$pcslist);
13151: foreach my $pc (@pcs) {
13152: if ($pc == 1) {
1.1075.2.38 raeburn 13153: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13154: } else {
13155: my $res = $navmap->getByMapPc($pc);
13156: if (ref($res)) {
13157: my $title = $res->compTitle();
13158: $title =~ s/\W+/_/g;
13159: if ($title ne '') {
13160: push(@pathitems,$title);
13161: }
13162: }
13163: }
13164: }
13165: }
1.1071 raeburn 13166: if ($showitem) {
13167: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 13168: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13169: } else {
13170: my $maptitle = $mapres->compTitle();
13171: $maptitle =~ s/\W+/_/g;
13172: if ($maptitle ne '') {
13173: push(@pathitems,$maptitle);
13174: }
1.1068 raeburn 13175: }
13176: }
13177: }
13178: }
13179: return @pathitems;
13180: }
13181:
13182: =pod
13183:
1.1015 raeburn 13184: =item * &get_turnedin_filepath()
13185:
13186: Determines path in a user's portfolio file for storage of files uploaded
13187: to a specific essayresponse or dropbox item.
13188:
13189: Inputs: 3 required + 1 optional.
13190: $symb is symb for resource, $uname and $udom are for current user (required).
13191: $caller is optional (can be "submission", if routine is called when storing
13192: an upoaded file when "Submit Answer" button was pressed).
13193:
13194: Returns array containing $path and $multiresp.
13195: $path is path in portfolio. $multiresp is 1 if this resource contains more
13196: than one file upload item. Callers of routine should append partid as a
13197: subdirectory to $path in cases where $multiresp is 1.
13198:
13199: Called by: homework/essayresponse.pm and homework/structuretags.pm
13200:
13201: =cut
13202:
13203: sub get_turnedin_filepath {
13204: my ($symb,$uname,$udom,$caller) = @_;
13205: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13206: my $turnindir;
13207: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13208: $turnindir = $userhash{'turnindir'};
13209: my ($path,$multiresp);
13210: if ($turnindir eq '') {
13211: if ($caller eq 'submission') {
13212: $turnindir = &mt('turned in');
13213: $turnindir =~ s/\W+/_/g;
13214: my %newhash = (
13215: 'turnindir' => $turnindir,
13216: );
13217: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13218: }
13219: }
13220: if ($turnindir ne '') {
13221: $path = '/'.$turnindir.'/';
13222: my ($multipart,$turnin,@pathitems);
13223: my $navmap = Apache::lonnavmaps::navmap->new();
13224: if (defined($navmap)) {
13225: my $mapres = $navmap->getResourceByUrl($map);
13226: if (ref($mapres)) {
13227: my $pcslist = $mapres->map_hierarchy();
13228: if ($pcslist ne '') {
13229: foreach my $pc (split(/,/,$pcslist)) {
13230: my $res = $navmap->getByMapPc($pc);
13231: if (ref($res)) {
13232: my $title = $res->compTitle();
13233: $title =~ s/\W+/_/g;
13234: if ($title ne '') {
1.1075.2.48 raeburn 13235: if (($pc > 1) && (length($title) > 12)) {
13236: $title = substr($title,0,12);
13237: }
1.1015 raeburn 13238: push(@pathitems,$title);
13239: }
13240: }
13241: }
13242: }
13243: my $maptitle = $mapres->compTitle();
13244: $maptitle =~ s/\W+/_/g;
13245: if ($maptitle ne '') {
1.1075.2.48 raeburn 13246: if (length($maptitle) > 12) {
13247: $maptitle = substr($maptitle,0,12);
13248: }
1.1015 raeburn 13249: push(@pathitems,$maptitle);
13250: }
13251: unless ($env{'request.state'} eq 'construct') {
13252: my $res = $navmap->getBySymb($symb);
13253: if (ref($res)) {
13254: my $partlist = $res->parts();
13255: my $totaluploads = 0;
13256: if (ref($partlist) eq 'ARRAY') {
13257: foreach my $part (@{$partlist}) {
13258: my @types = $res->responseType($part);
13259: my @ids = $res->responseIds($part);
13260: for (my $i=0; $i < scalar(@ids); $i++) {
13261: if ($types[$i] eq 'essay') {
13262: my $partid = $part.'_'.$ids[$i];
13263: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13264: $totaluploads ++;
13265: }
13266: }
13267: }
13268: }
13269: if ($totaluploads > 1) {
13270: $multiresp = 1;
13271: }
13272: }
13273: }
13274: }
13275: } else {
13276: return;
13277: }
13278: } else {
13279: return;
13280: }
13281: my $restitle=&Apache::lonnet::gettitle($symb);
13282: $restitle =~ s/\W+/_/g;
13283: if ($restitle eq '') {
13284: $restitle = ($resurl =~ m{/[^/]+$});
13285: if ($restitle eq '') {
13286: $restitle = time;
13287: }
13288: }
1.1075.2.48 raeburn 13289: if (length($restitle) > 12) {
13290: $restitle = substr($restitle,0,12);
13291: }
1.1015 raeburn 13292: push(@pathitems,$restitle);
13293: $path .= join('/',@pathitems);
13294: }
13295: return ($path,$multiresp);
13296: }
13297:
13298: =pod
13299:
1.464 albertel 13300: =back
1.41 ng 13301:
1.112 bowersj2 13302: =head1 CSV Upload/Handling functions
1.38 albertel 13303:
1.41 ng 13304: =over 4
13305:
1.648 raeburn 13306: =item * &upfile_store($r)
1.41 ng 13307:
13308: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13309: needs $env{'form.upfile'}
1.41 ng 13310: returns $datatoken to be put into hidden field
13311:
13312: =cut
1.31 albertel 13313:
13314: sub upfile_store {
13315: my $r=shift;
1.258 albertel 13316: $env{'form.upfile'}=~s/\r/\n/gs;
13317: $env{'form.upfile'}=~s/\f/\n/gs;
13318: $env{'form.upfile'}=~s/\n+/\n/gs;
13319: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13320:
1.1075.2.128 raeburn 13321: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13322: '_enroll_'.$env{'request.course.id'}.'_'.
13323: time.'_'.$$);
13324: return if ($datatoken eq '');
13325:
1.31 albertel 13326: {
1.158 raeburn 13327: my $datafile = $r->dir_config('lonDaemons').
13328: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 13329: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13330: print $fh $env{'form.upfile'};
1.158 raeburn 13331: close($fh);
13332: }
1.31 albertel 13333: }
13334: return $datatoken;
13335: }
13336:
1.56 matthew 13337: =pod
13338:
1.1075.2.128 raeburn 13339: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13340:
13341: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 13342: $datatoken is the name to assign to the temporary file.
1.258 albertel 13343: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13344:
13345: =cut
1.31 albertel 13346:
13347: sub load_tmp_file {
1.1075.2.128 raeburn 13348: my ($r,$datatoken) = @_;
13349: return if ($datatoken eq '');
1.31 albertel 13350: my @studentdata=();
13351: {
1.158 raeburn 13352: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 13353: '/tmp/'.$datatoken.'.tmp';
13354: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 13355: @studentdata=<$fh>;
13356: close($fh);
13357: }
1.31 albertel 13358: }
1.258 albertel 13359: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13360: }
13361:
1.1075.2.128 raeburn 13362: sub valid_datatoken {
13363: my ($datatoken) = @_;
1.1075.2.131 raeburn 13364: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 13365: return $datatoken;
13366: }
13367: return;
13368: }
13369:
1.56 matthew 13370: =pod
13371:
1.648 raeburn 13372: =item * &upfile_record_sep()
1.41 ng 13373:
13374: Separate uploaded file into records
13375: returns array of records,
1.258 albertel 13376: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13377:
13378: =cut
1.31 albertel 13379:
13380: sub upfile_record_sep {
1.258 albertel 13381: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13382: } else {
1.248 albertel 13383: my @records;
1.258 albertel 13384: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13385: if ($line=~/^\s*$/) { next; }
13386: push(@records,$line);
13387: }
13388: return @records;
1.31 albertel 13389: }
13390: }
13391:
1.56 matthew 13392: =pod
13393:
1.648 raeburn 13394: =item * &record_sep($record)
1.41 ng 13395:
1.258 albertel 13396: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13397:
13398: =cut
13399:
1.263 www 13400: sub takeleft {
13401: my $index=shift;
13402: return substr('0000'.$index,-4,4);
13403: }
13404:
1.31 albertel 13405: sub record_sep {
13406: my $record=shift;
13407: my %components=();
1.258 albertel 13408: if ($env{'form.upfiletype'} eq 'xml') {
13409: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13410: my $i=0;
1.356 albertel 13411: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13412: $field=~s/^(\"|\')//;
13413: $field=~s/(\"|\')$//;
1.263 www 13414: $components{&takeleft($i)}=$field;
1.31 albertel 13415: $i++;
13416: }
1.258 albertel 13417: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13418: my $i=0;
1.356 albertel 13419: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13420: $field=~s/^(\"|\')//;
13421: $field=~s/(\"|\')$//;
1.263 www 13422: $components{&takeleft($i)}=$field;
1.31 albertel 13423: $i++;
13424: }
13425: } else {
1.561 www 13426: my $separator=',';
1.480 banghart 13427: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13428: $separator=';';
1.480 banghart 13429: }
1.31 albertel 13430: my $i=0;
1.561 www 13431: # the character we are looking for to indicate the end of a quote or a record
13432: my $looking_for=$separator;
13433: # do not add the characters to the fields
13434: my $ignore=0;
13435: # we just encountered a separator (or the beginning of the record)
13436: my $just_found_separator=1;
13437: # store the field we are working on here
13438: my $field='';
13439: # work our way through all characters in record
13440: foreach my $character ($record=~/(.)/g) {
13441: if ($character eq $looking_for) {
13442: if ($character ne $separator) {
13443: # Found the end of a quote, again looking for separator
13444: $looking_for=$separator;
13445: $ignore=1;
13446: } else {
13447: # Found a separator, store away what we got
13448: $components{&takeleft($i)}=$field;
13449: $i++;
13450: $just_found_separator=1;
13451: $ignore=0;
13452: $field='';
13453: }
13454: next;
13455: }
13456: # single or double quotation marks after a separator indicate beginning of a quote
13457: # we are now looking for the end of the quote and need to ignore separators
13458: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13459: $looking_for=$character;
13460: next;
13461: }
13462: # ignore would be true after we reached the end of a quote
13463: if ($ignore) { next; }
13464: if (($just_found_separator) && ($character=~/\s/)) { next; }
13465: $field.=$character;
13466: $just_found_separator=0;
1.31 albertel 13467: }
1.561 www 13468: # catch the very last entry, since we never encountered the separator
13469: $components{&takeleft($i)}=$field;
1.31 albertel 13470: }
13471: return %components;
13472: }
13473:
1.144 matthew 13474: ######################################################
13475: ######################################################
13476:
1.56 matthew 13477: =pod
13478:
1.648 raeburn 13479: =item * &upfile_select_html()
1.41 ng 13480:
1.144 matthew 13481: Return HTML code to select a file from the users machine and specify
13482: the file type.
1.41 ng 13483:
13484: =cut
13485:
1.144 matthew 13486: ######################################################
13487: ######################################################
1.31 albertel 13488: sub upfile_select_html {
1.144 matthew 13489: my %Types = (
13490: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13491: semisv => &mt('Semicolon separated values'),
1.144 matthew 13492: space => &mt('Space separated'),
13493: tab => &mt('Tabulator separated'),
13494: # xml => &mt('HTML/XML'),
13495: );
13496: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13497: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13498: foreach my $type (sort(keys(%Types))) {
13499: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13500: }
13501: $Str .= "</select>\n";
13502: return $Str;
1.31 albertel 13503: }
13504:
1.301 albertel 13505: sub get_samples {
13506: my ($records,$toget) = @_;
13507: my @samples=({});
13508: my $got=0;
13509: foreach my $rec (@$records) {
13510: my %temp = &record_sep($rec);
13511: if (! grep(/\S/, values(%temp))) { next; }
13512: if (%temp) {
13513: $samples[$got]=\%temp;
13514: $got++;
13515: if ($got == $toget) { last; }
13516: }
13517: }
13518: return \@samples;
13519: }
13520:
1.144 matthew 13521: ######################################################
13522: ######################################################
13523:
1.56 matthew 13524: =pod
13525:
1.648 raeburn 13526: =item * &csv_print_samples($r,$records)
1.41 ng 13527:
13528: Prints a table of sample values from each column uploaded $r is an
13529: Apache Request ref, $records is an arrayref from
13530: &Apache::loncommon::upfile_record_sep
13531:
13532: =cut
13533:
1.144 matthew 13534: ######################################################
13535: ######################################################
1.31 albertel 13536: sub csv_print_samples {
13537: my ($r,$records) = @_;
1.662 bisitz 13538: my $samples = &get_samples($records,5);
1.301 albertel 13539:
1.594 raeburn 13540: $r->print(&mt('Samples').'<br />'.&start_data_table().
13541: &start_data_table_header_row());
1.356 albertel 13542: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13543: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13544: $r->print(&end_data_table_header_row());
1.301 albertel 13545: foreach my $hash (@$samples) {
1.594 raeburn 13546: $r->print(&start_data_table_row());
1.356 albertel 13547: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13548: $r->print('<td>');
1.356 albertel 13549: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13550: $r->print('</td>');
13551: }
1.594 raeburn 13552: $r->print(&end_data_table_row());
1.31 albertel 13553: }
1.594 raeburn 13554: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13555: }
13556:
1.144 matthew 13557: ######################################################
13558: ######################################################
13559:
1.56 matthew 13560: =pod
13561:
1.648 raeburn 13562: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13563:
13564: Prints a table to create associations between values and table columns.
1.144 matthew 13565:
1.41 ng 13566: $r is an Apache Request ref,
13567: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13568: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13569:
13570: =cut
13571:
1.144 matthew 13572: ######################################################
13573: ######################################################
1.31 albertel 13574: sub csv_print_select_table {
13575: my ($r,$records,$d) = @_;
1.301 albertel 13576: my $i=0;
13577: my $samples = &get_samples($records,1);
1.144 matthew 13578: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13579: &start_data_table().&start_data_table_header_row().
1.144 matthew 13580: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13581: '<th>'.&mt('Column').'</th>'.
13582: &end_data_table_header_row()."\n");
1.356 albertel 13583: foreach my $array_ref (@$d) {
13584: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13585: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13586:
1.875 bisitz 13587: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13588: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13589: $r->print('<option value="none"></option>');
1.356 albertel 13590: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13591: $r->print('<option value="'.$sample.'"'.
13592: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13593: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13594: }
1.594 raeburn 13595: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13596: $i++;
13597: }
1.594 raeburn 13598: $r->print(&end_data_table());
1.31 albertel 13599: $i--;
13600: return $i;
13601: }
1.56 matthew 13602:
1.144 matthew 13603: ######################################################
13604: ######################################################
13605:
1.56 matthew 13606: =pod
1.31 albertel 13607:
1.648 raeburn 13608: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13609:
13610: Prints a table of sample values from the upload and can make associate samples to internal names.
13611:
13612: $r is an Apache Request ref,
13613: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13614: $d is an array of 2 element arrays (internal name, displayed name)
13615:
13616: =cut
13617:
1.144 matthew 13618: ######################################################
13619: ######################################################
1.31 albertel 13620: sub csv_samples_select_table {
13621: my ($r,$records,$d) = @_;
13622: my $i=0;
1.144 matthew 13623: #
1.662 bisitz 13624: my $max_samples = 5;
13625: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13626: $r->print(&start_data_table().
13627: &start_data_table_header_row().'<th>'.
13628: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13629: &end_data_table_header_row());
1.301 albertel 13630:
13631: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13632: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13633: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13634: foreach my $option (@$d) {
13635: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13636: $r->print('<option value="'.$value.'"'.
1.253 albertel 13637: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13638: $display.'</option>');
1.31 albertel 13639: }
13640: $r->print('</select></td><td>');
1.662 bisitz 13641: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13642: if (defined($samples->[$line]{$key})) {
13643: $r->print($samples->[$line]{$key}."<br />\n");
13644: }
13645: }
1.594 raeburn 13646: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13647: $i++;
13648: }
1.594 raeburn 13649: $r->print(&end_data_table());
1.31 albertel 13650: $i--;
13651: return($i);
1.115 matthew 13652: }
13653:
1.144 matthew 13654: ######################################################
13655: ######################################################
13656:
1.115 matthew 13657: =pod
13658:
1.648 raeburn 13659: =item * &clean_excel_name($name)
1.115 matthew 13660:
13661: Returns a replacement for $name which does not contain any illegal characters.
13662:
13663: =cut
13664:
1.144 matthew 13665: ######################################################
13666: ######################################################
1.115 matthew 13667: sub clean_excel_name {
13668: my ($name) = @_;
13669: $name =~ s/[:\*\?\/\\]//g;
13670: if (length($name) > 31) {
13671: $name = substr($name,0,31);
13672: }
13673: return $name;
1.25 albertel 13674: }
1.84 albertel 13675:
1.85 albertel 13676: =pod
13677:
1.648 raeburn 13678: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13679:
13680: Returns either 1 or undef
13681:
13682: 1 if the part is to be hidden, undef if it is to be shown
13683:
13684: Arguments are:
13685:
13686: $id the id of the part to be checked
13687: $symb, optional the symb of the resource to check
13688: $udom, optional the domain of the user to check for
13689: $uname, optional the username of the user to check for
13690:
13691: =cut
1.84 albertel 13692:
13693: sub check_if_partid_hidden {
13694: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13695: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13696: $symb,$udom,$uname);
1.141 albertel 13697: my $truth=1;
13698: #if the string starts with !, then the list is the list to show not hide
13699: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13700: my @hiddenlist=split(/,/,$hiddenparts);
13701: foreach my $checkid (@hiddenlist) {
1.141 albertel 13702: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13703: }
1.141 albertel 13704: return !$truth;
1.84 albertel 13705: }
1.127 matthew 13706:
1.138 matthew 13707:
13708: ############################################################
13709: ############################################################
13710:
13711: =pod
13712:
1.157 matthew 13713: =back
13714:
1.138 matthew 13715: =head1 cgi-bin script and graphing routines
13716:
1.157 matthew 13717: =over 4
13718:
1.648 raeburn 13719: =item * &get_cgi_id()
1.138 matthew 13720:
13721: Inputs: none
13722:
13723: Returns an id which can be used to pass environment variables
13724: to various cgi-bin scripts. These environment variables will
13725: be removed from the users environment after a given time by
13726: the routine &Apache::lonnet::transfer_profile_to_env.
13727:
13728: =cut
13729:
13730: ############################################################
13731: ############################################################
1.152 albertel 13732: my $uniq=0;
1.136 matthew 13733: sub get_cgi_id {
1.154 albertel 13734: $uniq=($uniq+1)%100000;
1.280 albertel 13735: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13736: }
13737:
1.127 matthew 13738: ############################################################
13739: ############################################################
13740:
13741: =pod
13742:
1.648 raeburn 13743: =item * &DrawBarGraph()
1.127 matthew 13744:
1.138 matthew 13745: Facilitates the plotting of data in a (stacked) bar graph.
13746: Puts plot definition data into the users environment in order for
13747: graph.png to plot it. Returns an <img> tag for the plot.
13748: The bars on the plot are labeled '1','2',...,'n'.
13749:
13750: Inputs:
13751:
13752: =over 4
13753:
13754: =item $Title: string, the title of the plot
13755:
13756: =item $xlabel: string, text describing the X-axis of the plot
13757:
13758: =item $ylabel: string, text describing the Y-axis of the plot
13759:
13760: =item $Max: scalar, the maximum Y value to use in the plot
13761: If $Max is < any data point, the graph will not be rendered.
13762:
1.140 matthew 13763: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13764: they are plotted. If undefined, default values will be used.
13765:
1.178 matthew 13766: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13767:
1.138 matthew 13768: =item @Values: An array of array references. Each array reference holds data
13769: to be plotted in a stacked bar chart.
13770:
1.239 matthew 13771: =item If the final element of @Values is a hash reference the key/value
13772: pairs will be added to the graph definition.
13773:
1.138 matthew 13774: =back
13775:
13776: Returns:
13777:
13778: An <img> tag which references graph.png and the appropriate identifying
13779: information for the plot.
13780:
1.127 matthew 13781: =cut
13782:
13783: ############################################################
13784: ############################################################
1.134 matthew 13785: sub DrawBarGraph {
1.178 matthew 13786: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13787: #
13788: if (! defined($colors)) {
13789: $colors = ['#33ff00',
13790: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13791: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13792: ];
13793: }
1.228 matthew 13794: my $extra_settings = {};
13795: if (ref($Values[-1]) eq 'HASH') {
13796: $extra_settings = pop(@Values);
13797: }
1.127 matthew 13798: #
1.136 matthew 13799: my $identifier = &get_cgi_id();
13800: my $id = 'cgi.'.$identifier;
1.129 matthew 13801: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13802: return '';
13803: }
1.225 matthew 13804: #
13805: my @Labels;
13806: if (defined($labels)) {
13807: @Labels = @$labels;
13808: } else {
13809: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 13810: push(@Labels,$i+1);
1.225 matthew 13811: }
13812: }
13813: #
1.129 matthew 13814: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13815: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13816: my %ValuesHash;
13817: my $NumSets=1;
13818: foreach my $array (@Values) {
13819: next if (! ref($array));
1.136 matthew 13820: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13821: join(',',@$array);
1.129 matthew 13822: }
1.127 matthew 13823: #
1.136 matthew 13824: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13825: if ($NumBars < 3) {
13826: $width = 120+$NumBars*32;
1.220 matthew 13827: $xskip = 1;
1.225 matthew 13828: $bar_width = 30;
13829: } elsif ($NumBars < 5) {
13830: $width = 120+$NumBars*20;
13831: $xskip = 1;
13832: $bar_width = 20;
1.220 matthew 13833: } elsif ($NumBars < 10) {
1.136 matthew 13834: $width = 120+$NumBars*15;
13835: $xskip = 1;
13836: $bar_width = 15;
13837: } elsif ($NumBars <= 25) {
13838: $width = 120+$NumBars*11;
13839: $xskip = 5;
13840: $bar_width = 8;
13841: } elsif ($NumBars <= 50) {
13842: $width = 120+$NumBars*8;
13843: $xskip = 5;
13844: $bar_width = 4;
13845: } else {
13846: $width = 120+$NumBars*8;
13847: $xskip = 5;
13848: $bar_width = 4;
13849: }
13850: #
1.137 matthew 13851: $Max = 1 if ($Max < 1);
13852: if ( int($Max) < $Max ) {
13853: $Max++;
13854: $Max = int($Max);
13855: }
1.127 matthew 13856: $Title = '' if (! defined($Title));
13857: $xlabel = '' if (! defined($xlabel));
13858: $ylabel = '' if (! defined($ylabel));
1.369 www 13859: $ValuesHash{$id.'.title'} = &escape($Title);
13860: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13861: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13862: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13863: $ValuesHash{$id.'.NumBars'} = $NumBars;
13864: $ValuesHash{$id.'.NumSets'} = $NumSets;
13865: $ValuesHash{$id.'.PlotType'} = 'bar';
13866: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13867: $ValuesHash{$id.'.height'} = $height;
13868: $ValuesHash{$id.'.width'} = $width;
13869: $ValuesHash{$id.'.xskip'} = $xskip;
13870: $ValuesHash{$id.'.bar_width'} = $bar_width;
13871: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13872: #
1.228 matthew 13873: # Deal with other parameters
13874: while (my ($key,$value) = each(%$extra_settings)) {
13875: $ValuesHash{$id.'.'.$key} = $value;
13876: }
13877: #
1.646 raeburn 13878: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13879: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13880: }
13881:
13882: ############################################################
13883: ############################################################
13884:
13885: =pod
13886:
1.648 raeburn 13887: =item * &DrawXYGraph()
1.137 matthew 13888:
1.138 matthew 13889: Facilitates the plotting of data in an XY graph.
13890: Puts plot definition data into the users environment in order for
13891: graph.png to plot it. Returns an <img> tag for the plot.
13892:
13893: Inputs:
13894:
13895: =over 4
13896:
13897: =item $Title: string, the title of the plot
13898:
13899: =item $xlabel: string, text describing the X-axis of the plot
13900:
13901: =item $ylabel: string, text describing the Y-axis of the plot
13902:
13903: =item $Max: scalar, the maximum Y value to use in the plot
13904: If $Max is < any data point, the graph will not be rendered.
13905:
13906: =item $colors: Array ref containing the hex color codes for the data to be
13907: plotted in. If undefined, default values will be used.
13908:
13909: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13910:
13911: =item $Ydata: Array ref containing Array refs.
1.185 www 13912: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13913:
13914: =item %Values: hash indicating or overriding any default values which are
13915: passed to graph.png.
13916: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13917:
13918: =back
13919:
13920: Returns:
13921:
13922: An <img> tag which references graph.png and the appropriate identifying
13923: information for the plot.
13924:
1.137 matthew 13925: =cut
13926:
13927: ############################################################
13928: ############################################################
13929: sub DrawXYGraph {
13930: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13931: #
13932: # Create the identifier for the graph
13933: my $identifier = &get_cgi_id();
13934: my $id = 'cgi.'.$identifier;
13935: #
13936: $Title = '' if (! defined($Title));
13937: $xlabel = '' if (! defined($xlabel));
13938: $ylabel = '' if (! defined($ylabel));
13939: my %ValuesHash =
13940: (
1.369 www 13941: $id.'.title' => &escape($Title),
13942: $id.'.xlabel' => &escape($xlabel),
13943: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13944: $id.'.y_max_value'=> $Max,
13945: $id.'.labels' => join(',',@$Xlabels),
13946: $id.'.PlotType' => 'XY',
13947: );
13948: #
13949: if (defined($colors) && ref($colors) eq 'ARRAY') {
13950: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13951: }
13952: #
13953: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13954: return '';
13955: }
13956: my $NumSets=1;
1.138 matthew 13957: foreach my $array (@{$Ydata}){
1.137 matthew 13958: next if (! ref($array));
13959: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13960: }
1.138 matthew 13961: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 13962: #
13963: # Deal with other parameters
13964: while (my ($key,$value) = each(%Values)) {
13965: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 13966: }
13967: #
1.646 raeburn 13968: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 13969: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13970: }
13971:
13972: ############################################################
13973: ############################################################
13974:
13975: =pod
13976:
1.648 raeburn 13977: =item * &DrawXYYGraph()
1.138 matthew 13978:
13979: Facilitates the plotting of data in an XY graph with two Y axes.
13980: Puts plot definition data into the users environment in order for
13981: graph.png to plot it. Returns an <img> tag for the plot.
13982:
13983: Inputs:
13984:
13985: =over 4
13986:
13987: =item $Title: string, the title of the plot
13988:
13989: =item $xlabel: string, text describing the X-axis of the plot
13990:
13991: =item $ylabel: string, text describing the Y-axis of the plot
13992:
13993: =item $colors: Array ref containing the hex color codes for the data to be
13994: plotted in. If undefined, default values will be used.
13995:
13996: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13997:
13998: =item $Ydata1: The first data set
13999:
14000: =item $Min1: The minimum value of the left Y-axis
14001:
14002: =item $Max1: The maximum value of the left Y-axis
14003:
14004: =item $Ydata2: The second data set
14005:
14006: =item $Min2: The minimum value of the right Y-axis
14007:
14008: =item $Max2: The maximum value of the left Y-axis
14009:
14010: =item %Values: hash indicating or overriding any default values which are
14011: passed to graph.png.
14012: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14013:
14014: =back
14015:
14016: Returns:
14017:
14018: An <img> tag which references graph.png and the appropriate identifying
14019: information for the plot.
1.136 matthew 14020:
14021: =cut
14022:
14023: ############################################################
14024: ############################################################
1.137 matthew 14025: sub DrawXYYGraph {
14026: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14027: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14028: #
14029: # Create the identifier for the graph
14030: my $identifier = &get_cgi_id();
14031: my $id = 'cgi.'.$identifier;
14032: #
14033: $Title = '' if (! defined($Title));
14034: $xlabel = '' if (! defined($xlabel));
14035: $ylabel = '' if (! defined($ylabel));
14036: my %ValuesHash =
14037: (
1.369 www 14038: $id.'.title' => &escape($Title),
14039: $id.'.xlabel' => &escape($xlabel),
14040: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14041: $id.'.labels' => join(',',@$Xlabels),
14042: $id.'.PlotType' => 'XY',
14043: $id.'.NumSets' => 2,
1.137 matthew 14044: $id.'.two_axes' => 1,
14045: $id.'.y1_max_value' => $Max1,
14046: $id.'.y1_min_value' => $Min1,
14047: $id.'.y2_max_value' => $Max2,
14048: $id.'.y2_min_value' => $Min2,
1.136 matthew 14049: );
14050: #
1.137 matthew 14051: if (defined($colors) && ref($colors) eq 'ARRAY') {
14052: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14053: }
14054: #
14055: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14056: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14057: return '';
14058: }
14059: my $NumSets=1;
1.137 matthew 14060: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14061: next if (! ref($array));
14062: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14063: }
14064: #
14065: # Deal with other parameters
14066: while (my ($key,$value) = each(%Values)) {
14067: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14068: }
14069: #
1.646 raeburn 14070: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14071: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14072: }
14073:
14074: ############################################################
14075: ############################################################
14076:
14077: =pod
14078:
1.157 matthew 14079: =back
14080:
1.139 matthew 14081: =head1 Statistics helper routines?
14082:
14083: Bad place for them but what the hell.
14084:
1.157 matthew 14085: =over 4
14086:
1.648 raeburn 14087: =item * &chartlink()
1.139 matthew 14088:
14089: Returns a link to the chart for a specific student.
14090:
14091: Inputs:
14092:
14093: =over 4
14094:
14095: =item $linktext: The text of the link
14096:
14097: =item $sname: The students username
14098:
14099: =item $sdomain: The students domain
14100:
14101: =back
14102:
1.157 matthew 14103: =back
14104:
1.139 matthew 14105: =cut
14106:
14107: ############################################################
14108: ############################################################
14109: sub chartlink {
14110: my ($linktext, $sname, $sdomain) = @_;
14111: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14112: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14113: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14114: '">'.$linktext.'</a>';
1.153 matthew 14115: }
14116:
14117: #######################################################
14118: #######################################################
14119:
14120: =pod
14121:
14122: =head1 Course Environment Routines
1.157 matthew 14123:
14124: =over 4
1.153 matthew 14125:
1.648 raeburn 14126: =item * &restore_course_settings()
1.153 matthew 14127:
1.648 raeburn 14128: =item * &store_course_settings()
1.153 matthew 14129:
14130: Restores/Store indicated form parameters from the course environment.
14131: Will not overwrite existing values of the form parameters.
14132:
14133: Inputs:
14134: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14135:
14136: a hash ref describing the data to be stored. For example:
14137:
14138: %Save_Parameters = ('Status' => 'scalar',
14139: 'chartoutputmode' => 'scalar',
14140: 'chartoutputdata' => 'scalar',
14141: 'Section' => 'array',
1.373 raeburn 14142: 'Group' => 'array',
1.153 matthew 14143: 'StudentData' => 'array',
14144: 'Maps' => 'array');
14145:
14146: Returns: both routines return nothing
14147:
1.631 raeburn 14148: =back
14149:
1.153 matthew 14150: =cut
14151:
14152: #######################################################
14153: #######################################################
14154: sub store_course_settings {
1.496 albertel 14155: return &store_settings($env{'request.course.id'},@_);
14156: }
14157:
14158: sub store_settings {
1.153 matthew 14159: # save to the environment
14160: # appenv the same items, just to be safe
1.300 albertel 14161: my $udom = $env{'user.domain'};
14162: my $uname = $env{'user.name'};
1.496 albertel 14163: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14164: my %SaveHash;
14165: my %AppHash;
14166: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14167: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14168: my $envname = 'environment.'.$basename;
1.258 albertel 14169: if (exists($env{'form.'.$setting})) {
1.153 matthew 14170: # Save this value away
14171: if ($type eq 'scalar' &&
1.258 albertel 14172: (! exists($env{$envname}) ||
14173: $env{$envname} ne $env{'form.'.$setting})) {
14174: $SaveHash{$basename} = $env{'form.'.$setting};
14175: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14176: } elsif ($type eq 'array') {
14177: my $stored_form;
1.258 albertel 14178: if (ref($env{'form.'.$setting})) {
1.153 matthew 14179: $stored_form = join(',',
14180: map {
1.369 www 14181: &escape($_);
1.258 albertel 14182: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14183: } else {
14184: $stored_form =
1.369 www 14185: &escape($env{'form.'.$setting});
1.153 matthew 14186: }
14187: # Determine if the array contents are the same.
1.258 albertel 14188: if ($stored_form ne $env{$envname}) {
1.153 matthew 14189: $SaveHash{$basename} = $stored_form;
14190: $AppHash{$envname} = $stored_form;
14191: }
14192: }
14193: }
14194: }
14195: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14196: $udom,$uname);
1.153 matthew 14197: if ($put_result !~ /^(ok|delayed)/) {
14198: &Apache::lonnet::logthis('unable to save form parameters, '.
14199: 'got error:'.$put_result);
14200: }
14201: # Make sure these settings stick around in this session, too
1.646 raeburn 14202: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14203: return;
14204: }
14205:
14206: sub restore_course_settings {
1.499 albertel 14207: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14208: }
14209:
14210: sub restore_settings {
14211: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14212: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14213: next if (exists($env{'form.'.$setting}));
1.496 albertel 14214: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14215: '.'.$setting;
1.258 albertel 14216: if (exists($env{$envname})) {
1.153 matthew 14217: if ($type eq 'scalar') {
1.258 albertel 14218: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14219: } elsif ($type eq 'array') {
1.258 albertel 14220: $env{'form.'.$setting} = [
1.153 matthew 14221: map {
1.369 www 14222: &unescape($_);
1.258 albertel 14223: } split(',',$env{$envname})
1.153 matthew 14224: ];
14225: }
14226: }
14227: }
1.127 matthew 14228: }
14229:
1.618 raeburn 14230: #######################################################
14231: #######################################################
14232:
14233: =pod
14234:
14235: =head1 Domain E-mail Routines
14236:
14237: =over 4
14238:
1.648 raeburn 14239: =item * &build_recipient_list()
1.618 raeburn 14240:
1.1075.2.44 raeburn 14241: Build recipient lists for following types of e-mail:
1.766 raeburn 14242: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 14243: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14244: module change checking, student/employee ID conflict checks, as
14245: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14246: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14247:
14248: Inputs:
1.1075.2.44 raeburn 14249: defmail (scalar - email address of default recipient),
14250: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14251: requestsmail, updatesmail, or idconflictsmail).
14252:
1.619 raeburn 14253: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 14254:
14255: origmail (scalar - email address of recipient from loncapa.conf,
14256: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14257:
1.1075.2.139 raeburn 14258: $requname username of requester (if mailing type is helpdeskmail)
14259:
14260: $requdom domain of requester (if mailing type is helpdeskmail)
14261:
14262: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14263:
1.655 raeburn 14264: Returns: comma separated list of addresses to which to send e-mail.
14265:
14266: =back
1.618 raeburn 14267:
14268: =cut
14269:
14270: ############################################################
14271: ############################################################
14272: sub build_recipient_list {
1.1075.2.139 raeburn 14273: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14274: my @recipients;
1.1075.2.122 raeburn 14275: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14276: my %domconfig =
1.1075.2.122 raeburn 14277: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14278: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14279: if (exists($domconfig{'contacts'}{$mailing})) {
14280: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14281: my @contacts = ('adminemail','supportemail');
14282: foreach my $item (@contacts) {
14283: if ($domconfig{'contacts'}{$mailing}{$item}) {
14284: my $addr = $domconfig{'contacts'}{$item};
14285: if (!grep(/^\Q$addr\E$/,@recipients)) {
14286: push(@recipients,$addr);
14287: }
1.619 raeburn 14288: }
1.1075.2.122 raeburn 14289: }
14290: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14291: if ($mailing eq 'helpdeskmail') {
14292: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14293: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14294: my @ok_bccs;
14295: foreach my $bcc (@bccs) {
14296: $bcc =~ s/^\s+//g;
14297: $bcc =~ s/\s+$//g;
14298: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14299: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14300: push(@ok_bccs,$bcc);
14301: }
14302: }
14303: }
14304: if (@ok_bccs > 0) {
14305: $allbcc = join(', ',@ok_bccs);
14306: }
14307: }
14308: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14309: }
14310: }
1.766 raeburn 14311: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14312: $lastresort = $origmail;
1.618 raeburn 14313: }
1.1075.2.139 raeburn 14314: if ($mailing eq 'helpdeskmail') {
14315: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14316: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14317: my ($inststatus,$inststatus_checked);
14318: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14319: ($env{'user.domain'} ne 'public')) {
14320: $inststatus_checked = 1;
14321: $inststatus = $env{'environment.inststatus'};
14322: }
14323: unless ($inststatus_checked) {
14324: if (($requname ne '') && ($requdom ne '')) {
14325: if (($requname =~ /^$match_username$/) &&
14326: ($requdom =~ /^$match_domain$/) &&
14327: (&Apache::lonnet::domain($requdom))) {
14328: my $requhome = &Apache::lonnet::homeserver($requname,
14329: $requdom);
14330: unless ($requhome eq 'no_host') {
14331: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14332: $inststatus = $userenv{'inststatus'};
14333: $inststatus_checked = 1;
14334: }
14335: }
14336: }
14337: }
14338: unless ($inststatus_checked) {
14339: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
14340: my %srch = (srchby => 'email',
14341: srchdomain => $defdom,
14342: srchterm => $reqemail,
14343: srchtype => 'exact');
14344: my %srch_results = &Apache::lonnet::usersearch(\%srch);
14345: foreach my $uname (keys(%srch_results)) {
14346: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14347: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14348: $inststatus_checked = 1;
14349: last;
14350: }
14351: }
14352: unless ($inststatus_checked) {
14353: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
14354: if ($dirsrchres eq 'ok') {
14355: foreach my $uname (keys(%srch_results)) {
14356: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14357: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14358: $inststatus_checked = 1;
14359: last;
14360: }
14361: }
14362: }
14363: }
14364: }
14365: }
14366: if ($inststatus ne '') {
14367: foreach my $status (split(/\:/,$inststatus)) {
14368: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
14369: my @contacts = ('adminemail','supportemail');
14370: foreach my $item (@contacts) {
14371: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
14372: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
14373: if (!grep(/^\Q$addr\E$/,@recipients)) {
14374: push(@recipients,$addr);
14375: }
14376: }
14377: }
14378: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
14379: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
14380: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
14381: my @ok_bccs;
14382: foreach my $bcc (@bccs) {
14383: $bcc =~ s/^\s+//g;
14384: $bcc =~ s/\s+$//g;
14385: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14386: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14387: push(@ok_bccs,$bcc);
14388: }
14389: }
14390: }
14391: if (@ok_bccs > 0) {
14392: $allbcc = join(', ',@ok_bccs);
14393: }
14394: }
14395: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
14396: last;
14397: }
14398: }
14399: }
14400: }
14401: }
1.619 raeburn 14402: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14403: $lastresort = $origmail;
14404: }
1.1075.2.128 raeburn 14405: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 14406: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14407: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14408: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14409: my %what = (
14410: perlvar => 1,
14411: );
14412: my $primary = &Apache::lonnet::domain($defdom,'primary');
14413: if ($primary) {
14414: my $gotaddr;
14415: my ($result,$returnhash) =
14416: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14417: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14418: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14419: $lastresort = $returnhash->{'lonSupportEMail'};
14420: $gotaddr = 1;
14421: }
14422: }
14423: unless ($gotaddr) {
14424: my $uintdom = &Apache::lonnet::internet_dom($primary);
14425: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14426: unless ($uintdom eq $intdom) {
14427: my %domconfig =
14428: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14429: if (ref($domconfig{'contacts'}) eq 'HASH') {
14430: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14431: my @contacts = ('adminemail','supportemail');
14432: foreach my $item (@contacts) {
14433: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14434: my $addr = $domconfig{'contacts'}{$item};
14435: if (!grep(/^\Q$addr\E$/,@recipients)) {
14436: push(@recipients,$addr);
14437: }
14438: }
14439: }
14440: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14441: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14442: }
14443: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14444: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14445: my @ok_bccs;
14446: foreach my $bcc (@bccs) {
14447: $bcc =~ s/^\s+//g;
14448: $bcc =~ s/\s+$//g;
14449: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14450: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14451: push(@ok_bccs,$bcc);
14452: }
14453: }
14454: }
14455: if (@ok_bccs > 0) {
14456: $allbcc = join(', ',@ok_bccs);
14457: }
14458: }
14459: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14460: }
14461: }
14462: }
14463: }
14464: }
14465: }
1.618 raeburn 14466: }
1.688 raeburn 14467: if (defined($defmail)) {
14468: if ($defmail ne '') {
14469: push(@recipients,$defmail);
14470: }
1.618 raeburn 14471: }
14472: if ($otheremails) {
1.619 raeburn 14473: my @others;
14474: if ($otheremails =~ /,/) {
14475: @others = split(/,/,$otheremails);
1.618 raeburn 14476: } else {
1.619 raeburn 14477: push(@others,$otheremails);
14478: }
14479: foreach my $addr (@others) {
14480: if (!grep(/^\Q$addr\E$/,@recipients)) {
14481: push(@recipients,$addr);
14482: }
1.618 raeburn 14483: }
14484: }
1.1075.2.128 raeburn 14485: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 14486: if ((!@recipients) && ($lastresort ne '')) {
14487: push(@recipients,$lastresort);
14488: }
14489: } elsif ($lastresort ne '') {
14490: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14491: push(@recipients,$lastresort);
14492: }
14493: }
14494: my $recipientlist = join(',',@recipients);
14495: if (wantarray) {
14496: return ($recipientlist,$allbcc,$addtext);
14497: } else {
14498: return $recipientlist;
14499: }
1.618 raeburn 14500: }
14501:
1.127 matthew 14502: ############################################################
14503: ############################################################
1.154 albertel 14504:
1.655 raeburn 14505: =pod
14506:
14507: =head1 Course Catalog Routines
14508:
14509: =over 4
14510:
14511: =item * &gather_categories()
14512:
14513: Converts category definitions - keys of categories hash stored in
14514: coursecategories in configuration.db on the primary library server in a
14515: domain - to an array. Also generates javascript and idx hash used to
14516: generate Domain Coordinator interface for editing Course Categories.
14517:
14518: Inputs:
1.663 raeburn 14519:
1.655 raeburn 14520: categories (reference to hash of category definitions).
1.663 raeburn 14521:
1.655 raeburn 14522: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14523: categories and subcategories).
1.663 raeburn 14524:
1.655 raeburn 14525: idx (reference to hash of counters used in Domain Coordinator interface for
14526: editing Course Categories).
1.663 raeburn 14527:
1.655 raeburn 14528: jsarray (reference to array of categories used to create Javascript arrays for
14529: Domain Coordinator interface for editing Course Categories).
14530:
14531: Returns: nothing
14532:
14533: Side effects: populates cats, idx and jsarray.
14534:
14535: =cut
14536:
14537: sub gather_categories {
14538: my ($categories,$cats,$idx,$jsarray) = @_;
14539: my %counters;
14540: my $num = 0;
14541: foreach my $item (keys(%{$categories})) {
14542: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14543: if ($container eq '' && $depth == 0) {
14544: $cats->[$depth][$categories->{$item}] = $cat;
14545: } else {
14546: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14547: }
14548: my ($escitem,$tail) = split(/:/,$item,2);
14549: if ($counters{$tail} eq '') {
14550: $counters{$tail} = $num;
14551: $num ++;
14552: }
14553: if (ref($idx) eq 'HASH') {
14554: $idx->{$item} = $counters{$tail};
14555: }
14556: if (ref($jsarray) eq 'ARRAY') {
14557: push(@{$jsarray->[$counters{$tail}]},$item);
14558: }
14559: }
14560: return;
14561: }
14562:
14563: =pod
14564:
14565: =item * &extract_categories()
14566:
14567: Used to generate breadcrumb trails for course categories.
14568:
14569: Inputs:
1.663 raeburn 14570:
1.655 raeburn 14571: categories (reference to hash of category definitions).
1.663 raeburn 14572:
1.655 raeburn 14573: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14574: categories and subcategories).
1.663 raeburn 14575:
1.655 raeburn 14576: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14577:
1.655 raeburn 14578: allitems (reference to hash - key is category key
14579: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14580:
1.655 raeburn 14581: idx (reference to hash of counters used in Domain Coordinator interface for
14582: editing Course Categories).
1.663 raeburn 14583:
1.655 raeburn 14584: jsarray (reference to array of categories used to create Javascript arrays for
14585: Domain Coordinator interface for editing Course Categories).
14586:
1.665 raeburn 14587: subcats (reference to hash of arrays containing all subcategories within each
14588: category, -recursive)
14589:
1.1075.2.132 raeburn 14590: maxd (reference to hash used to hold max depth for all top-level categories).
14591:
1.655 raeburn 14592: Returns: nothing
14593:
14594: Side effects: populates trails and allitems hash references.
14595:
14596: =cut
14597:
14598: sub extract_categories {
1.1075.2.132 raeburn 14599: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 14600: if (ref($categories) eq 'HASH') {
14601: &gather_categories($categories,$cats,$idx,$jsarray);
14602: if (ref($cats->[0]) eq 'ARRAY') {
14603: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14604: my $name = $cats->[0][$i];
14605: my $item = &escape($name).'::0';
14606: my $trailstr;
14607: if ($name eq 'instcode') {
14608: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14609: } elsif ($name eq 'communities') {
14610: $trailstr = &mt('Communities');
1.655 raeburn 14611: } else {
14612: $trailstr = $name;
14613: }
14614: if ($allitems->{$item} eq '') {
14615: push(@{$trails},$trailstr);
14616: $allitems->{$item} = scalar(@{$trails})-1;
14617: }
14618: my @parents = ($name);
14619: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14620: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14621: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14622: if (ref($subcats) eq 'HASH') {
14623: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14624: }
1.1075.2.132 raeburn 14625: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 14626: }
14627: } else {
14628: if (ref($subcats) eq 'HASH') {
14629: $subcats->{$item} = [];
1.655 raeburn 14630: }
1.1075.2.132 raeburn 14631: if (ref($maxd) eq 'HASH') {
14632: $maxd->{$name} = 1;
14633: }
1.655 raeburn 14634: }
14635: }
14636: }
14637: }
14638: return;
14639: }
14640:
14641: =pod
14642:
1.1075.2.56 raeburn 14643: =item * &recurse_categories()
1.655 raeburn 14644:
14645: Recursively used to generate breadcrumb trails for course categories.
14646:
14647: Inputs:
1.663 raeburn 14648:
1.655 raeburn 14649: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14650: categories and subcategories).
1.663 raeburn 14651:
1.655 raeburn 14652: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14653:
14654: category (current course category, for which breadcrumb trail is being generated).
14655:
14656: trails (reference to array of breadcrumb trails for each category).
14657:
1.655 raeburn 14658: allitems (reference to hash - key is category key
14659: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14660:
1.655 raeburn 14661: parents (array containing containers directories for current category,
14662: back to top level).
14663:
14664: Returns: nothing
14665:
14666: Side effects: populates trails and allitems hash references
14667:
14668: =cut
14669:
14670: sub recurse_categories {
1.1075.2.132 raeburn 14671: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 14672: my $shallower = $depth - 1;
14673: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14674: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14675: my $name = $cats->[$depth]{$category}[$k];
14676: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14677: my $trailstr = join(' -> ',(@{$parents},$category));
14678: if ($allitems->{$item} eq '') {
14679: push(@{$trails},$trailstr);
14680: $allitems->{$item} = scalar(@{$trails})-1;
14681: }
14682: my $deeper = $depth+1;
14683: push(@{$parents},$category);
1.665 raeburn 14684: if (ref($subcats) eq 'HASH') {
14685: my $subcat = &escape($name).':'.$category.':'.$depth;
14686: for (my $j=@{$parents}; $j>=0; $j--) {
14687: my $higher;
14688: if ($j > 0) {
14689: $higher = &escape($parents->[$j]).':'.
14690: &escape($parents->[$j-1]).':'.$j;
14691: } else {
14692: $higher = &escape($parents->[$j]).'::'.$j;
14693: }
14694: push(@{$subcats->{$higher}},$subcat);
14695: }
14696: }
14697: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 14698: $subcats,$maxd);
1.655 raeburn 14699: pop(@{$parents});
14700: }
14701: } else {
14702: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 14703: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 14704: if ($allitems->{$item} eq '') {
14705: push(@{$trails},$trailstr);
14706: $allitems->{$item} = scalar(@{$trails})-1;
14707: }
1.1075.2.132 raeburn 14708: if (ref($maxd) eq 'HASH') {
14709: if ($depth > $maxd->{$parents->[0]}) {
14710: $maxd->{$parents->[0]} = $depth;
14711: }
14712: }
1.655 raeburn 14713: }
14714: return;
14715: }
14716:
1.663 raeburn 14717: =pod
14718:
1.1075.2.56 raeburn 14719: =item * &assign_categories_table()
1.663 raeburn 14720:
14721: Create a datatable for display of hierarchical categories in a domain,
14722: with checkboxes to allow a course to be categorized.
14723:
14724: Inputs:
14725:
14726: cathash - reference to hash of categories defined for the domain (from
14727: configuration.db)
14728:
14729: currcat - scalar with an & separated list of categories assigned to a course.
14730:
1.919 raeburn 14731: type - scalar contains course type (Course or Community).
14732:
1.1075.2.117 raeburn 14733: disabled - scalar (optional) contains disabled="disabled" if input elements are
14734: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14735:
1.663 raeburn 14736: Returns: $output (markup to be displayed)
14737:
14738: =cut
14739:
14740: sub assign_categories_table {
1.1075.2.117 raeburn 14741: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 14742: my $output;
14743: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 14744: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
14745: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 14746: $maxdepth = scalar(@cats);
14747: if (@cats > 0) {
14748: my $itemcount = 0;
14749: if (ref($cats[0]) eq 'ARRAY') {
14750: my @currcategories;
14751: if ($currcat ne '') {
14752: @currcategories = split('&',$currcat);
14753: }
1.919 raeburn 14754: my $table;
1.663 raeburn 14755: for (my $i=0; $i<@{$cats[0]}; $i++) {
14756: my $parent = $cats[0][$i];
1.919 raeburn 14757: next if ($parent eq 'instcode');
14758: if ($type eq 'Community') {
14759: next unless ($parent eq 'communities');
14760: } else {
14761: next if ($parent eq 'communities');
14762: }
1.663 raeburn 14763: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14764: my $item = &escape($parent).'::0';
14765: my $checked = '';
14766: if (@currcategories > 0) {
14767: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14768: $checked = ' checked="checked"';
1.663 raeburn 14769: }
14770: }
1.919 raeburn 14771: my $parent_title = $parent;
14772: if ($parent eq 'communities') {
14773: $parent_title = &mt('Communities');
14774: }
14775: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14776: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14777: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 14778: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14779: my $depth = 1;
14780: push(@path,$parent);
1.1075.2.117 raeburn 14781: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 14782: pop(@path);
1.919 raeburn 14783: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14784: $itemcount ++;
14785: }
1.919 raeburn 14786: if ($itemcount) {
14787: $output = &Apache::loncommon::start_data_table().
14788: $table.
14789: &Apache::loncommon::end_data_table();
14790: }
1.663 raeburn 14791: }
14792: }
14793: }
14794: return $output;
14795: }
14796:
14797: =pod
14798:
1.1075.2.56 raeburn 14799: =item * &assign_category_rows()
1.663 raeburn 14800:
14801: Create a datatable row for display of nested categories in a domain,
14802: with checkboxes to allow a course to be categorized,called recursively.
14803:
14804: Inputs:
14805:
14806: itemcount - track row number for alternating colors
14807:
14808: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14809: categories and subcategories.
14810:
14811: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14812:
14813: parent - parent of current category item
14814:
14815: path - Array containing all categories back up through the hierarchy from the
14816: current category to the top level.
14817:
14818: currcategories - reference to array of current categories assigned to the course
14819:
1.1075.2.117 raeburn 14820: disabled - scalar (optional) contains disabled="disabled" if input elements are
14821: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14822:
1.663 raeburn 14823: Returns: $output (markup to be displayed).
14824:
14825: =cut
14826:
14827: sub assign_category_rows {
1.1075.2.117 raeburn 14828: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 14829: my ($text,$name,$item,$chgstr);
14830: if (ref($cats) eq 'ARRAY') {
14831: my $maxdepth = scalar(@{$cats});
14832: if (ref($cats->[$depth]) eq 'HASH') {
14833: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14834: my $numchildren = @{$cats->[$depth]{$parent}};
14835: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 14836: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14837: for (my $j=0; $j<$numchildren; $j++) {
14838: $name = $cats->[$depth]{$parent}[$j];
14839: $item = &escape($name).':'.&escape($parent).':'.$depth;
14840: my $deeper = $depth+1;
14841: my $checked = '';
14842: if (ref($currcategories) eq 'ARRAY') {
14843: if (@{$currcategories} > 0) {
14844: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14845: $checked = ' checked="checked"';
1.663 raeburn 14846: }
14847: }
14848: }
1.664 raeburn 14849: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14850: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14851: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 14852: '<input type="hidden" name="catname" value="'.$name.'" />'.
14853: '</td><td>';
1.663 raeburn 14854: if (ref($path) eq 'ARRAY') {
14855: push(@{$path},$name);
1.1075.2.117 raeburn 14856: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 14857: pop(@{$path});
14858: }
14859: $text .= '</td></tr>';
14860: }
14861: $text .= '</table></td>';
14862: }
14863: }
14864: }
14865: return $text;
14866: }
14867:
1.1075.2.69 raeburn 14868: =pod
14869:
14870: =back
14871:
14872: =cut
14873:
1.655 raeburn 14874: ############################################################
14875: ############################################################
14876:
14877:
1.443 albertel 14878: sub commit_customrole {
1.664 raeburn 14879: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14880: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14881: ($start?', '.&mt('starting').' '.localtime($start):'').
14882: ($end?', ending '.localtime($end):'').': <b>'.
14883: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14884: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14885: '</b><br />';
14886: return $output;
14887: }
14888:
14889: sub commit_standardrole {
1.1075.2.31 raeburn 14890: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14891: my ($output,$logmsg,$linefeed);
14892: if ($context eq 'auto') {
14893: $linefeed = "\n";
14894: } else {
14895: $linefeed = "<br />\n";
14896: }
1.443 albertel 14897: if ($three eq 'st') {
1.541 raeburn 14898: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 14899: $one,$two,$sec,$context,$credits);
1.541 raeburn 14900: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14901: ($result eq 'unknown_course') || ($result eq 'refused')) {
14902: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14903: } else {
1.541 raeburn 14904: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14905: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14906: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14907: if ($context eq 'auto') {
14908: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14909: } else {
14910: $output .= '<b>'.$result.'</b>'.$linefeed.
14911: &mt('Add to classlist').': <b>ok</b>';
14912: }
14913: $output .= $linefeed;
1.443 albertel 14914: }
14915: } else {
14916: $output = &mt('Assigning').' '.$three.' in '.$url.
14917: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14918: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 14919: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 14920: if ($context eq 'auto') {
14921: $output .= $result.$linefeed;
14922: } else {
14923: $output .= '<b>'.$result.'</b>'.$linefeed;
14924: }
1.443 albertel 14925: }
14926: return $output;
14927: }
14928:
14929: sub commit_studentrole {
1.1075.2.31 raeburn 14930: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
14931: $credits) = @_;
1.626 raeburn 14932: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 14933: if ($context eq 'auto') {
14934: $linefeed = "\n";
14935: } else {
14936: $linefeed = '<br />'."\n";
14937: }
1.443 albertel 14938: if (defined($one) && defined($two)) {
14939: my $cid=$one.'_'.$two;
14940: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
14941: my $secchange = 0;
14942: my $expire_role_result;
14943: my $modify_section_result;
1.628 raeburn 14944: if ($oldsec ne '-1') {
14945: if ($oldsec ne $sec) {
1.443 albertel 14946: $secchange = 1;
1.628 raeburn 14947: my $now = time;
1.443 albertel 14948: my $uurl='/'.$cid;
14949: $uurl=~s/\_/\//g;
14950: if ($oldsec) {
14951: $uurl.='/'.$oldsec;
14952: }
1.626 raeburn 14953: $oldsecurl = $uurl;
1.628 raeburn 14954: $expire_role_result =
1.652 raeburn 14955: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 14956: if ($env{'request.course.sec'} ne '') {
14957: if ($expire_role_result eq 'refused') {
14958: my @roles = ('st');
14959: my @statuses = ('previous');
14960: my @roledoms = ($one);
14961: my $withsec = 1;
14962: my %roleshash =
14963: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
14964: \@statuses,\@roles,\@roledoms,$withsec);
14965: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
14966: my ($oldstart,$oldend) =
14967: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
14968: if ($oldend > 0 && $oldend <= $now) {
14969: $expire_role_result = 'ok';
14970: }
14971: }
14972: }
14973: }
1.443 albertel 14974: $result = $expire_role_result;
14975: }
14976: }
14977: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 14978: $modify_section_result =
14979: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
14980: undef,undef,undef,$sec,
14981: $end,$start,'','',$cid,
14982: '',$context,$credits);
1.443 albertel 14983: if ($modify_section_result =~ /^ok/) {
14984: if ($secchange == 1) {
1.628 raeburn 14985: if ($sec eq '') {
14986: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
14987: } else {
14988: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
14989: }
1.443 albertel 14990: } elsif ($oldsec eq '-1') {
1.628 raeburn 14991: if ($sec eq '') {
14992: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
14993: } else {
14994: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14995: }
1.443 albertel 14996: } else {
1.628 raeburn 14997: if ($sec eq '') {
14998: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
14999: } else {
15000: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15001: }
1.443 albertel 15002: }
15003: } else {
1.628 raeburn 15004: if ($secchange) {
15005: $$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;
15006: } else {
15007: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15008: }
1.443 albertel 15009: }
15010: $result = $modify_section_result;
15011: } elsif ($secchange == 1) {
1.628 raeburn 15012: if ($oldsec eq '') {
1.1075.2.20 raeburn 15013: $$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 15014: } else {
15015: $$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;
15016: }
1.626 raeburn 15017: if ($expire_role_result eq 'refused') {
15018: my $newsecurl = '/'.$cid;
15019: $newsecurl =~ s/\_/\//g;
15020: if ($sec ne '') {
15021: $newsecurl.='/'.$sec;
15022: }
15023: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15024: if ($sec eq '') {
15025: $$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;
15026: } else {
15027: $$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;
15028: }
15029: }
15030: }
1.443 albertel 15031: }
15032: } else {
1.626 raeburn 15033: $$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 15034: $result = "error: incomplete course id\n";
15035: }
15036: return $result;
15037: }
15038:
1.1075.2.25 raeburn 15039: sub show_role_extent {
15040: my ($scope,$context,$role) = @_;
15041: $scope =~ s{^/}{};
15042: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15043: push(@courseroles,'co');
15044: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15045: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15046: $scope =~ s{/}{_};
15047: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15048: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15049: my ($audom,$auname) = split(/\//,$scope);
15050: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15051: &Apache::loncommon::plainname($auname,$audom).'</span>');
15052: } else {
15053: $scope =~ s{/$}{};
15054: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15055: &Apache::lonnet::domain($scope,'description').'</span>');
15056: }
15057: }
15058:
1.443 albertel 15059: ############################################################
15060: ############################################################
15061:
1.566 albertel 15062: sub check_clone {
1.578 raeburn 15063: my ($args,$linefeed) = @_;
1.566 albertel 15064: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15065: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15066: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15067: my $clonemsg;
15068: my $can_clone = 0;
1.944 raeburn 15069: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15070: if ($lctype ne 'community') {
15071: $lctype = 'course';
15072: }
1.566 albertel 15073: if ($clonehome eq 'no_host') {
1.944 raeburn 15074: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15075: $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
15076: } else {
15077: $clonemsg = &mt('No new course created.').$linefeed.&mt('A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
15078: }
1.566 albertel 15079: } else {
15080: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15081: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15082: if ($clonedesc{'type'} ne 'Community') {
15083: $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
15084: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15085: }
15086: }
1.1075.2.119 raeburn 15087: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15088: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15089: $can_clone = 1;
15090: } else {
1.1075.2.95 raeburn 15091: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15092: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 15093: if ($clonehash{'cloners'} eq '') {
15094: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15095: if ($domdefs{'canclone'}) {
15096: unless ($domdefs{'canclone'} eq 'none') {
15097: if ($domdefs{'canclone'} eq 'domain') {
15098: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15099: $can_clone = 1;
15100: }
15101: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15102: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15103: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15104: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15105: $can_clone = 1;
15106: }
15107: }
15108: }
1.908 raeburn 15109: }
1.1075.2.95 raeburn 15110: } else {
15111: my @cloners = split(/,/,$clonehash{'cloners'});
15112: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15113: $can_clone = 1;
1.1075.2.95 raeburn 15114: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15115: $can_clone = 1;
1.1075.2.96 raeburn 15116: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15117: $can_clone = 1;
1.1075.2.95 raeburn 15118: }
15119: unless ($can_clone) {
1.1075.2.96 raeburn 15120: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15121: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 15122: my (%gotdomdefaults,%gotcodedefaults);
15123: foreach my $cloner (@cloners) {
15124: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15125: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15126: my (%codedefaults,@code_order);
15127: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15128: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15129: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15130: }
15131: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15132: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15133: }
15134: } else {
15135: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15136: \%codedefaults,
15137: \@code_order);
15138: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15139: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15140: }
15141: if (@code_order > 0) {
15142: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15143: $cloner,$clonehash{'internal.coursecode'},
15144: $args->{'crscode'})) {
15145: $can_clone = 1;
15146: last;
15147: }
15148: }
15149: }
15150: }
15151: }
1.1075.2.96 raeburn 15152: }
15153: }
15154: unless ($can_clone) {
15155: my $ccrole = 'cc';
15156: if ($args->{'crstype'} eq 'Community') {
15157: $ccrole = 'co';
15158: }
15159: my %roleshash =
15160: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15161: $args->{'ccdomain'},
15162: 'userroles',['active'],[$ccrole],
15163: [$args->{'clonedomain'}]);
15164: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15165: $can_clone = 1;
15166: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15167: $args->{'ccuname'},$args->{'ccdomain'})) {
15168: $can_clone = 1;
1.1075.2.95 raeburn 15169: }
15170: }
15171: unless ($can_clone) {
15172: if ($args->{'crstype'} eq 'Community') {
15173: $clonemsg = &mt('No new community created.').$linefeed.&mt('The new community could not be cloned from the existing community because the new community owner ([_1]) does not have cloning rights in the existing community ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
15174: } else {
15175: $clonemsg = &mt('No new course created.').$linefeed.&mt('The new course could not be cloned from the existing course because the new course owner ([_1]) does not have cloning rights in the existing course ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
1.578 raeburn 15176: }
1.566 albertel 15177: }
1.578 raeburn 15178: }
1.566 albertel 15179: }
15180: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15181: }
15182:
1.444 albertel 15183: sub construct_course {
1.1075.2.119 raeburn 15184: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15185: $cnum,$category,$coderef) = @_;
1.444 albertel 15186: my $outcome;
1.541 raeburn 15187: my $linefeed = '<br />'."\n";
15188: if ($context eq 'auto') {
15189: $linefeed = "\n";
15190: }
1.566 albertel 15191:
15192: #
15193: # Are we cloning?
15194: #
15195: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15196: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15197: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15198: if ($context ne 'auto') {
1.578 raeburn 15199: if ($clonemsg ne '') {
15200: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15201: }
1.566 albertel 15202: }
15203: $outcome .= $clonemsg.$linefeed;
15204:
15205: if (!$can_clone) {
15206: return (0,$outcome);
15207: }
15208: }
15209:
1.444 albertel 15210: #
15211: # Open course
15212: #
15213: my $crstype = lc($args->{'crstype'});
15214: my %cenv=();
15215: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15216: $args->{'cdescr'},
15217: $args->{'curl'},
15218: $args->{'course_home'},
15219: $args->{'nonstandard'},
15220: $args->{'crscode'},
15221: $args->{'ccuname'}.':'.
15222: $args->{'ccdomain'},
1.882 raeburn 15223: $args->{'crstype'},
1.885 raeburn 15224: $cnum,$context,$category);
1.444 albertel 15225:
15226: # Note: The testing routines depend on this being output; see
15227: # Utils::Course. This needs to at least be output as a comment
15228: # if anyone ever decides to not show this, and Utils::Course::new
15229: # will need to be suitably modified.
1.541 raeburn 15230: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 15231: if ($$courseid =~ /^error:/) {
15232: return (0,$outcome);
15233: }
15234:
1.444 albertel 15235: #
15236: # Check if created correctly
15237: #
1.479 albertel 15238: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15239: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15240: if ($crsuhome eq 'no_host') {
15241: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15242: return (0,$outcome);
15243: }
1.541 raeburn 15244: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15245:
1.444 albertel 15246: #
1.566 albertel 15247: # Do the cloning
15248: #
15249: if ($can_clone && $cloneid) {
15250: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
15251: if ($context ne 'auto') {
15252: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15253: }
15254: $outcome .= $clonemsg.$linefeed;
15255: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15256: # Copy all files
1.637 www 15257: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15258: # Restore URL
1.566 albertel 15259: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15260: # Restore title
1.566 albertel 15261: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15262: # Restore creation date, creator and creation context.
15263: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15264: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15265: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15266: # Mark as cloned
1.566 albertel 15267: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15268: # Need to clone grading mode
15269: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15270: $cenv{'grading'}=$newenv{'grading'};
15271: # Do not clone these environment entries
15272: &Apache::lonnet::del('environment',
15273: ['default_enrollment_start_date',
15274: 'default_enrollment_end_date',
15275: 'question.email',
15276: 'policy.email',
15277: 'comment.email',
15278: 'pch.users.denied',
1.725 raeburn 15279: 'plc.users.denied',
15280: 'hidefromcat',
1.1075.2.36 raeburn 15281: 'checkforpriv',
1.1075.2.59 raeburn 15282: 'categories',
15283: 'internal.uniquecode'],
1.638 www 15284: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 15285: if ($args->{'textbook'}) {
15286: $cenv{'internal.textbook'} = $args->{'textbook'};
15287: }
1.444 albertel 15288: }
1.566 albertel 15289:
1.444 albertel 15290: #
15291: # Set environment (will override cloned, if existing)
15292: #
15293: my @sections = ();
15294: my @xlists = ();
15295: if ($args->{'crstype'}) {
15296: $cenv{'type'}=$args->{'crstype'};
15297: }
15298: if ($args->{'crsid'}) {
15299: $cenv{'courseid'}=$args->{'crsid'};
15300: }
15301: if ($args->{'crscode'}) {
15302: $cenv{'internal.coursecode'}=$args->{'crscode'};
15303: }
15304: if ($args->{'crsquota'} ne '') {
15305: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15306: } else {
15307: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15308: }
15309: if ($args->{'ccuname'}) {
15310: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15311: ':'.$args->{'ccdomain'};
15312: } else {
15313: $cenv{'internal.courseowner'} = $args->{'curruser'};
15314: }
1.1075.2.31 raeburn 15315: if ($args->{'defaultcredits'}) {
15316: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15317: }
1.444 albertel 15318: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15319: if ($args->{'crssections'}) {
15320: $cenv{'internal.sectionnums'} = '';
15321: if ($args->{'crssections'} =~ m/,/) {
15322: @sections = split/,/,$args->{'crssections'};
15323: } else {
15324: $sections[0] = $args->{'crssections'};
15325: }
15326: if (@sections > 0) {
15327: foreach my $item (@sections) {
15328: my ($sec,$gp) = split/:/,$item;
15329: my $class = $args->{'crscode'}.$sec;
15330: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15331: $cenv{'internal.sectionnums'} .= $item.',';
15332: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15333: push(@badclasses,$class);
1.444 albertel 15334: }
15335: }
15336: $cenv{'internal.sectionnums'} =~ s/,$//;
15337: }
15338: }
15339: # do not hide course coordinator from staff listing,
15340: # even if privileged
15341: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 15342: # add course coordinator's domain to domains to check for privileged users
15343: # if different to course domain
15344: if ($$crsudom ne $args->{'ccdomain'}) {
15345: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15346: }
1.444 albertel 15347: # add crosslistings
15348: if ($args->{'crsxlist'}) {
15349: $cenv{'internal.crosslistings'}='';
15350: if ($args->{'crsxlist'} =~ m/,/) {
15351: @xlists = split/,/,$args->{'crsxlist'};
15352: } else {
15353: $xlists[0] = $args->{'crsxlist'};
15354: }
15355: if (@xlists > 0) {
15356: foreach my $item (@xlists) {
15357: my ($xl,$gp) = split/:/,$item;
15358: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15359: $cenv{'internal.crosslistings'} .= $item.',';
15360: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15361: push(@badclasses,$xl);
1.444 albertel 15362: }
15363: }
15364: $cenv{'internal.crosslistings'} =~ s/,$//;
15365: }
15366: }
15367: if ($args->{'autoadds'}) {
15368: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15369: }
15370: if ($args->{'autodrops'}) {
15371: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15372: }
15373: # check for notification of enrollment changes
15374: my @notified = ();
15375: if ($args->{'notify_owner'}) {
15376: if ($args->{'ccuname'} ne '') {
15377: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15378: }
15379: }
15380: if ($args->{'notify_dc'}) {
15381: if ($uname ne '') {
1.630 raeburn 15382: push(@notified,$uname.':'.$udom);
1.444 albertel 15383: }
15384: }
15385: if (@notified > 0) {
15386: my $notifylist;
15387: if (@notified > 1) {
15388: $notifylist = join(',',@notified);
15389: } else {
15390: $notifylist = $notified[0];
15391: }
15392: $cenv{'internal.notifylist'} = $notifylist;
15393: }
15394: if (@badclasses > 0) {
15395: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 15396: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15397: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15398: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15399: );
1.1075.2.119 raeburn 15400: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15401: &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 15402: if ($context eq 'auto') {
15403: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 15404: } else {
1.566 albertel 15405: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 15406: }
15407: foreach my $item (@badclasses) {
1.541 raeburn 15408: if ($context eq 'auto') {
1.1075.2.119 raeburn 15409: $outcome .= " - $item\n";
1.541 raeburn 15410: } else {
1.1075.2.119 raeburn 15411: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15412: }
1.1075.2.119 raeburn 15413: }
15414: if ($context eq 'auto') {
15415: $outcome .= $linefeed;
15416: } else {
15417: $outcome .= "</ul><br /><br /></div>\n";
15418: }
1.444 albertel 15419: }
15420: if ($args->{'no_end_date'}) {
15421: $args->{'endaccess'} = 0;
15422: }
15423: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15424: $cenv{'internal.autoend'}=$args->{'enrollend'};
15425: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15426: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15427: if ($args->{'showphotos'}) {
15428: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15429: }
15430: $cenv{'internal.authtype'} = $args->{'authtype'};
15431: $cenv{'internal.autharg'} = $args->{'autharg'};
15432: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15433: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15434: 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');
15435: if ($context eq 'auto') {
15436: $outcome .= $krb_msg;
15437: } else {
1.566 albertel 15438: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15439: }
15440: $outcome .= $linefeed;
1.444 albertel 15441: }
15442: }
15443: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15444: if ($args->{'setpolicy'}) {
15445: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15446: }
15447: if ($args->{'setcontent'}) {
15448: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15449: }
1.1075.2.110 raeburn 15450: if ($args->{'setcomment'}) {
15451: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15452: }
1.444 albertel 15453: }
15454: if ($args->{'reshome'}) {
15455: $cenv{'reshome'}=$args->{'reshome'}.'/';
15456: $cenv{'reshome'}=~s/\/+$/\//;
15457: }
15458: #
15459: # course has keyed access
15460: #
15461: if ($args->{'setkeys'}) {
15462: $cenv{'keyaccess'}='yes';
15463: }
15464: # if specified, key authority is not course, but user
15465: # only active if keyaccess is yes
15466: if ($args->{'keyauth'}) {
1.487 albertel 15467: my ($user,$domain) = split(':',$args->{'keyauth'});
15468: $user = &LONCAPA::clean_username($user);
15469: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15470: if ($user ne '' && $domain ne '') {
1.487 albertel 15471: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15472: }
15473: }
15474:
1.1075.2.59 raeburn 15475: #
15476: # generate and store uniquecode (available to course requester), if course should have one.
15477: #
15478: if ($args->{'uniquecode'}) {
15479: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15480: if ($code) {
15481: $cenv{'internal.uniquecode'} = $code;
15482: my %crsinfo =
15483: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15484: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15485: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15486: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15487: }
15488: if (ref($coderef)) {
15489: $$coderef = $code;
15490: }
15491: }
15492: }
15493:
1.444 albertel 15494: if ($args->{'disresdis'}) {
15495: $cenv{'pch.roles.denied'}='st';
15496: }
15497: if ($args->{'disablechat'}) {
15498: $cenv{'plc.roles.denied'}='st';
15499: }
15500:
15501: # Record we've not yet viewed the Course Initialization Helper for this
15502: # course
15503: $cenv{'course.helper.not.run'} = 1;
15504: #
15505: # Use new Randomseed
15506: #
15507: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15508: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15509: #
15510: # The encryption code and receipt prefix for this course
15511: #
15512: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15513: $cenv{'internal.encpref'}=100+int(9*rand(99));
15514: #
15515: # By default, use standard grading
15516: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15517:
1.541 raeburn 15518: $outcome .= $linefeed.&mt('Setting environment').': '.
15519: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15520: #
15521: # Open all assignments
15522: #
15523: if ($args->{'openall'}) {
1.1075.2.146 raeburn 15524: my $opendate = time;
15525: if ($args->{'openallfrom'} =~ /^\d+$/) {
15526: $opendate = $args->{'openallfrom'};
15527: }
1.444 albertel 15528: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1075.2.146 raeburn 15529: my %storecontent = ($storeunder => $opendate,
1.444 albertel 15530: $storeunder.'.type' => 'date_start');
1.1075.2.146 raeburn 15531: $outcome .= &mt('All assignments open starting [_1]',
15532: &Apache::lonlocal::locallocaltime($opendate)).': '.
15533: &Apache::lonnet::cput
15534: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15535: }
15536: #
15537: # Set first page
15538: #
15539: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15540: || ($cloneid)) {
1.445 albertel 15541: use LONCAPA::map;
1.444 albertel 15542: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15543:
15544: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15545: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15546:
1.444 albertel 15547: $outcome .= ($fatal?$errtext:'read ok').' - ';
15548: my $title; my $url;
15549: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15550: $title=&mt('Syllabus');
1.444 albertel 15551: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15552: } else {
1.963 raeburn 15553: $title=&mt('Table of Contents');
1.444 albertel 15554: $url='/adm/navmaps';
15555: }
1.445 albertel 15556:
15557: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15558: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15559:
15560: if ($errtext) { $fatal=2; }
1.541 raeburn 15561: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15562: }
1.566 albertel 15563:
15564: return (1,$outcome);
1.444 albertel 15565: }
15566:
1.1075.2.59 raeburn 15567: sub make_unique_code {
15568: my ($cdom,$cnum) = @_;
15569: # get lock on uniquecodes db
15570: my $lockhash = {
15571: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15572: ':'.$env{'user.domain'},
15573: };
15574: my $tries = 0;
15575: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15576: my ($code,$error);
15577:
15578: while (($gotlock ne 'ok') && ($tries<3)) {
15579: $tries ++;
15580: sleep 1;
15581: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15582: }
15583: if ($gotlock eq 'ok') {
15584: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15585: my $gotcode;
15586: my $attempts = 0;
15587: while ((!$gotcode) && ($attempts < 100)) {
15588: $code = &generate_code();
15589: if (!exists($currcodes{$code})) {
15590: $gotcode = 1;
15591: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15592: $error = 'nostore';
15593: }
15594: }
15595: $attempts ++;
15596: }
15597: my @del_lock = ($cnum."\0".'uniquecodes');
15598: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15599: } else {
15600: $error = 'nolock';
15601: }
15602: return ($code,$error);
15603: }
15604:
15605: sub generate_code {
15606: my $code;
15607: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15608: for (my $i=0; $i<6; $i++) {
15609: my $lettnum = int (rand 2);
15610: my $item = '';
15611: if ($lettnum) {
15612: $item = $letts[int( rand(18) )];
15613: } else {
15614: $item = 1+int( rand(8) );
15615: }
15616: $code .= $item;
15617: }
15618: return $code;
15619: }
15620:
1.444 albertel 15621: ############################################################
15622: ############################################################
15623:
1.953 droeschl 15624: #SD
15625: # only Community and Course, or anything else?
1.378 raeburn 15626: sub course_type {
15627: my ($cid) = @_;
15628: if (!defined($cid)) {
15629: $cid = $env{'request.course.id'};
15630: }
1.404 albertel 15631: if (defined($env{'course.'.$cid.'.type'})) {
15632: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15633: } else {
15634: return 'Course';
1.377 raeburn 15635: }
15636: }
1.156 albertel 15637:
1.406 raeburn 15638: sub group_term {
15639: my $crstype = &course_type();
15640: my %names = (
15641: 'Course' => 'group',
1.865 raeburn 15642: 'Community' => 'group',
1.406 raeburn 15643: );
15644: return $names{$crstype};
15645: }
15646:
1.902 raeburn 15647: sub course_types {
1.1075.2.59 raeburn 15648: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15649: my %typename = (
15650: official => 'Official course',
15651: unofficial => 'Unofficial course',
15652: community => 'Community',
1.1075.2.59 raeburn 15653: textbook => 'Textbook course',
1.902 raeburn 15654: );
15655: return (\@types,\%typename);
15656: }
15657:
1.156 albertel 15658: sub icon {
15659: my ($file)=@_;
1.505 albertel 15660: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15661: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15662: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15663: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15664: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15665: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15666: $curfext.".gif") {
15667: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15668: $curfext.".gif";
15669: }
15670: }
1.249 albertel 15671: return &lonhttpdurl($iconname);
1.154 albertel 15672: }
1.84 albertel 15673:
1.575 albertel 15674: sub lonhttpdurl {
1.692 www 15675: #
15676: # Had been used for "small fry" static images on separate port 8080.
15677: # Modify here if lightweight http functionality desired again.
15678: # Currently eliminated due to increasing firewall issues.
15679: #
1.575 albertel 15680: my ($url)=@_;
1.692 www 15681: return $url;
1.215 albertel 15682: }
15683:
1.213 albertel 15684: sub connection_aborted {
15685: my ($r)=@_;
15686: $r->print(" ");$r->rflush();
15687: my $c = $r->connection;
15688: return $c->aborted();
15689: }
15690:
1.221 foxr 15691: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15692: # strings as 'strings'.
15693: sub escape_single {
1.221 foxr 15694: my ($input) = @_;
1.223 albertel 15695: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15696: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15697: return $input;
15698: }
1.223 albertel 15699:
1.222 foxr 15700: # Same as escape_single, but escape's "'s This
15701: # can be used for "strings"
15702: sub escape_double {
15703: my ($input) = @_;
15704: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15705: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15706: return $input;
15707: }
1.223 albertel 15708:
1.222 foxr 15709: # Escapes the last element of a full URL.
15710: sub escape_url {
15711: my ($url) = @_;
1.238 raeburn 15712: my @urlslices = split(/\//, $url,-1);
1.369 www 15713: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 15714: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15715: }
1.462 albertel 15716:
1.820 raeburn 15717: sub compare_arrays {
15718: my ($arrayref1,$arrayref2) = @_;
15719: my (@difference,%count);
15720: @difference = ();
15721: %count = ();
15722: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15723: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15724: foreach my $element (keys(%count)) {
15725: if ($count{$element} == 1) {
15726: push(@difference,$element);
15727: }
15728: }
15729: }
15730: return @difference;
15731: }
15732:
1.817 bisitz 15733: # -------------------------------------------------------- Initialize user login
1.462 albertel 15734: sub init_user_environment {
1.463 albertel 15735: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15736: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15737:
15738: my $public=($username eq 'public' && $domain eq 'public');
15739:
15740: # See if old ID present, if so, remove
15741:
1.1062 raeburn 15742: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15743: my $now=time;
15744:
15745: if ($public) {
15746: my $max_public=100;
15747: my $oldest;
15748: my $oldest_time=0;
15749: for(my $next=1;$next<=$max_public;$next++) {
15750: if (-e $lonids."/publicuser_$next.id") {
15751: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
15752: if ($mtime<$oldest_time || !$oldest_time) {
15753: $oldest_time=$mtime;
15754: $oldest=$next;
15755: }
15756: } else {
15757: $cookie="publicuser_$next";
15758: last;
15759: }
15760: }
15761: if (!$cookie) { $cookie="publicuser_$oldest"; }
15762: } else {
1.463 albertel 15763: # if this isn't a robot, kill any existing non-robot sessions
15764: if (!$args->{'robot'}) {
15765: opendir(DIR,$lonids);
15766: while ($filename=readdir(DIR)) {
15767: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136 raeburn 15768: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
15769: &GDBM_READER(),0640)) {
15770: my $linkedfile;
15771: if (exists($oldenv{'user.linkedenv'})) {
15772: $linkedfile = $oldenv{'user.linkedenv'};
15773: }
15774: untie(%oldenv);
15775: if (unlink("$lonids/$filename")) {
15776: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
15777: if (-l "$lonids/$linkedfile.id") {
15778: unlink("$lonids/$linkedfile.id");
15779: }
15780: }
15781: }
15782: } else {
15783: unlink($lonids.'/'.$filename);
15784: }
1.463 albertel 15785: }
1.462 albertel 15786: }
1.463 albertel 15787: closedir(DIR);
1.1075.2.84 raeburn 15788: # If there is a undeleted lockfile for the user's paste buffer remove it.
15789: my $namespace = 'nohist_courseeditor';
15790: my $lockingkey = 'paste'."\0".'locked_num';
15791: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
15792: $domain,$username);
15793: if (exists($lockhash{$lockingkey})) {
15794: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
15795: unless ($delresult eq 'ok') {
15796: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
15797: }
15798: }
1.462 albertel 15799: }
15800: # Give them a new cookie
1.463 albertel 15801: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 15802: : $now.$$.int(rand(10000)));
1.463 albertel 15803: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 15804:
15805: # Initialize roles
15806:
1.1062 raeburn 15807: ($userroles,$firstaccenv,$timerintenv) =
15808: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 15809: }
15810: # ------------------------------------ Check browser type and MathML capability
15811:
1.1075.2.77 raeburn 15812: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15813: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15814:
15815: # ------------------------------------------------------------- Get environment
15816:
15817: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15818: my ($tmp) = keys(%userenv);
15819: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
15820: } else {
15821: undef(%userenv);
15822: }
15823: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15824: $form->{'interface'}=$userenv{'interface'};
15825: }
15826: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15827:
15828: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15829: foreach my $option ('interface','localpath','localres') {
15830: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15831: }
15832: # --------------------------------------------------------- Write first profile
15833:
15834: {
15835: my %initial_env =
15836: ("user.name" => $username,
15837: "user.domain" => $domain,
15838: "user.home" => $authhost,
15839: "browser.type" => $clientbrowser,
15840: "browser.version" => $clientversion,
15841: "browser.mathml" => $clientmathml,
15842: "browser.unicode" => $clientunicode,
15843: "browser.os" => $clientos,
1.1075.2.42 raeburn 15844: "browser.mobile" => $clientmobile,
15845: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 15846: "browser.osversion" => $clientosversion,
1.462 albertel 15847: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
15848: "request.course.fn" => '',
15849: "request.course.uri" => '',
15850: "request.course.sec" => '',
15851: "request.role" => 'cm',
15852: "request.role.adv" => $env{'user.adv'},
15853: "request.host" => $ENV{'REMOTE_ADDR'},);
15854:
15855: if ($form->{'localpath'}) {
15856: $initial_env{"browser.localpath"} = $form->{'localpath'};
15857: $initial_env{"browser.localres"} = $form->{'localres'};
15858: }
15859:
15860: if ($form->{'interface'}) {
15861: $form->{'interface'}=~s/\W//gs;
15862: $initial_env{"browser.interface"} = $form->{'interface'};
15863: $env{'browser.interface'}=$form->{'interface'};
15864: }
15865:
1.1075.2.54 raeburn 15866: if ($form->{'iptoken'}) {
15867: my $lonhost = $r->dir_config('lonHostID');
15868: $initial_env{"user.noloadbalance"} = $lonhost;
15869: $env{'user.noloadbalance'} = $lonhost;
15870: }
15871:
1.1075.2.120 raeburn 15872: if ($form->{'noloadbalance'}) {
15873: my @hosts = &Apache::lonnet::current_machine_ids();
15874: my $hosthere = $form->{'noloadbalance'};
15875: if (grep(/^\Q$hosthere\E$/,@hosts)) {
15876: $initial_env{"user.noloadbalance"} = $hosthere;
15877: $env{'user.noloadbalance'} = $hosthere;
15878: }
15879: }
15880:
1.1016 raeburn 15881: unless ($domain eq 'public') {
1.1075.2.125 raeburn 15882: my %is_adv = ( is_adv => $env{'user.adv'} );
15883: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 15884:
1.1075.2.125 raeburn 15885: foreach my $tool ('aboutme','blog','webdav','portfolio') {
15886: $userenv{'availabletools.'.$tool} =
15887: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
15888: undef,\%userenv,\%domdef,\%is_adv);
15889: }
1.724 raeburn 15890:
1.1075.2.125 raeburn 15891: foreach my $crstype ('official','unofficial','community','textbook') {
15892: $userenv{'canrequest.'.$crstype} =
15893: &Apache::lonnet::usertools_access($username,$domain,$crstype,
15894: 'reload','requestcourses',
15895: \%userenv,\%domdef,\%is_adv);
15896: }
1.765 raeburn 15897:
1.1075.2.125 raeburn 15898: $userenv{'canrequest.author'} =
15899: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15900: 'reload','requestauthor',
15901: \%userenv,\%domdef,\%is_adv);
15902: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15903: $domain,$username);
15904: my $reqstatus = $reqauthor{'author_status'};
15905: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15906: if (ref($reqauthor{'author'}) eq 'HASH') {
15907: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15908: $reqauthor{'author'}{'timestamp'};
15909: }
1.1075.2.14 raeburn 15910: }
15911: }
15912:
1.462 albertel 15913: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 15914:
1.462 albertel 15915: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
15916: &GDBM_WRCREAT(),0640)) {
15917: &_add_to_env(\%disk_env,\%initial_env);
15918: &_add_to_env(\%disk_env,\%userenv,'environment.');
15919: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 15920: if (ref($firstaccenv) eq 'HASH') {
15921: &_add_to_env(\%disk_env,$firstaccenv);
15922: }
15923: if (ref($timerintenv) eq 'HASH') {
15924: &_add_to_env(\%disk_env,$timerintenv);
15925: }
1.463 albertel 15926: if (ref($args->{'extra_env'})) {
15927: &_add_to_env(\%disk_env,$args->{'extra_env'});
15928: }
1.462 albertel 15929: untie(%disk_env);
15930: } else {
1.705 tempelho 15931: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
15932: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 15933: return 'error: '.$!;
15934: }
15935: }
15936: $env{'request.role'}='cm';
15937: $env{'request.role.adv'}=$env{'user.adv'};
15938: $env{'browser.type'}=$clientbrowser;
15939:
15940: return $cookie;
15941:
15942: }
15943:
15944: sub _add_to_env {
15945: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 15946: if (ref($env_data) eq 'HASH') {
15947: while (my ($key,$value) = each(%$env_data)) {
15948: $idf->{$prefix.$key} = $value;
15949: $env{$prefix.$key} = $value;
15950: }
1.462 albertel 15951: }
15952: }
15953:
1.685 tempelho 15954: # --- Get the symbolic name of a problem and the url
15955: sub get_symb {
15956: my ($request,$silent) = @_;
1.726 raeburn 15957: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 15958: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
15959: if ($symb eq '') {
15960: if (!$silent) {
1.1071 raeburn 15961: if (ref($request)) {
15962: $request->print("Unable to handle ambiguous references:$url:.");
15963: }
1.685 tempelho 15964: return ();
15965: }
15966: }
15967: &Apache::lonenc::check_decrypt(\$symb);
15968: return ($symb);
15969: }
15970:
15971: # --------------------------------------------------------------Get annotation
15972:
15973: sub get_annotation {
15974: my ($symb,$enc) = @_;
15975:
15976: my $key = $symb;
15977: if (!$enc) {
15978: $key =
15979: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
15980: }
15981: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
15982: return $annotation{$key};
15983: }
15984:
15985: sub clean_symb {
1.731 raeburn 15986: my ($symb,$delete_enc) = @_;
1.685 tempelho 15987:
15988: &Apache::lonenc::check_decrypt(\$symb);
15989: my $enc = $env{'request.enc'};
1.731 raeburn 15990: if ($delete_enc) {
1.730 raeburn 15991: delete($env{'request.enc'});
15992: }
1.685 tempelho 15993:
15994: return ($symb,$enc);
15995: }
1.462 albertel 15996:
1.1075.2.69 raeburn 15997: ############################################################
15998: ############################################################
15999:
16000: =pod
16001:
16002: =head1 Routines for building display used to search for courses
16003:
16004:
16005: =over 4
16006:
16007: =item * &build_filters()
16008:
16009: Create markup for a table used to set filters to use when selecting
16010: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16011: and quotacheck.pl
16012:
16013:
16014: Inputs:
16015:
16016: filterlist - anonymous array of fields to include as potential filters
16017:
16018: crstype - course type
16019:
16020: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16021: to pop-open a course selector (will contain "extra element").
16022:
16023: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16024:
16025: filter - anonymous hash of criteria and their values
16026:
16027: action - form action
16028:
16029: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16030:
16031: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
16032:
16033: cloneruname - username of owner of new course who wants to clone
16034:
16035: clonerudom - domain of owner of new course who wants to clone
16036:
16037: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16038:
16039: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16040:
16041: codedom - domain
16042:
16043: formname - value of form element named "form".
16044:
16045: fixeddom - domain, if fixed.
16046:
16047: prevphase - value to assign to form element named "phase" when going back to the previous screen
16048:
16049: cnameelement - name of form element in form on opener page which will receive title of selected course
16050:
16051: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16052:
16053: cdomelement - name of form element in form on opener page which will receive domain of selected course
16054:
16055: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16056:
16057: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16058:
16059: clonewarning - warning message about missing information for intended course owner when DC creates a course
16060:
16061:
16062: Returns: $output - HTML for display of search criteria, and hidden form elements.
16063:
16064:
16065: Side Effects: None
16066:
16067: =cut
16068:
16069: # ---------------------------------------------- search for courses based on last activity etc.
16070:
16071: sub build_filters {
16072: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16073: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16074: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16075: $cnameelement,$cnumelement,$cdomelement,$setroles,
16076: $clonetext,$clonewarning) = @_;
16077: my ($list,$jscript);
16078: my $onchange = 'javascript:updateFilters(this)';
16079: my ($domainselectform,$sincefilterform,$createdfilterform,
16080: $ownerdomselectform,$persondomselectform,$instcodeform,
16081: $typeselectform,$instcodetitle);
16082: if ($formname eq '') {
16083: $formname = $caller;
16084: }
16085: foreach my $item (@{$filterlist}) {
16086: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16087: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16088: if ($item eq 'domainfilter') {
16089: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16090: } elsif ($item eq 'coursefilter') {
16091: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16092: } elsif ($item eq 'ownerfilter') {
16093: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16094: } elsif ($item eq 'ownerdomfilter') {
16095: $filter->{'ownerdomfilter'} =
16096: &LONCAPA::clean_domain($filter->{$item});
16097: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16098: 'ownerdomfilter',1);
16099: } elsif ($item eq 'personfilter') {
16100: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16101: } elsif ($item eq 'persondomfilter') {
16102: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16103: 'persondomfilter',1);
16104: } else {
16105: $filter->{$item} =~ s/\W//g;
16106: }
16107: if (!$filter->{$item}) {
16108: $filter->{$item} = '';
16109: }
16110: }
16111: if ($item eq 'domainfilter') {
16112: my $allow_blank = 1;
16113: if ($formname eq 'portform') {
16114: $allow_blank=0;
16115: } elsif ($formname eq 'studentform') {
16116: $allow_blank=0;
16117: }
16118: if ($fixeddom) {
16119: $domainselectform = '<input type="hidden" name="domainfilter"'.
16120: ' value="'.$codedom.'" />'.
16121: &Apache::lonnet::domain($codedom,'description');
16122: } else {
16123: $domainselectform = &select_dom_form($filter->{$item},
16124: 'domainfilter',
16125: $allow_blank,'',$onchange);
16126: }
16127: } else {
16128: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16129: }
16130: }
16131:
16132: # last course activity filter and selection
16133: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16134:
16135: # course created filter and selection
16136: if (exists($filter->{'createdfilter'})) {
16137: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16138: }
16139:
16140: my %lt = &Apache::lonlocal::texthash(
16141: 'cac' => "$crstype Activity",
16142: 'ccr' => "$crstype Created",
16143: 'cde' => "$crstype Title",
16144: 'cdo' => "$crstype Domain",
16145: 'ins' => 'Institutional Code',
16146: 'inc' => 'Institutional Categorization',
16147: 'cow' => "$crstype Owner/Co-owner",
16148: 'cop' => "$crstype Personnel Includes",
16149: 'cog' => 'Type',
16150: );
16151:
16152: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16153: my $typeval = 'Course';
16154: if ($crstype eq 'Community') {
16155: $typeval = 'Community';
16156: }
16157: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16158: } else {
16159: $typeselectform = '<select name="type" size="1"';
16160: if ($onchange) {
16161: $typeselectform .= ' onchange="'.$onchange.'"';
16162: }
16163: $typeselectform .= '>'."\n";
16164: foreach my $posstype ('Course','Community') {
16165: $typeselectform.='<option value="'.$posstype.'"'.
16166: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
16167: }
16168: $typeselectform.="</select>";
16169: }
16170:
16171: my ($cloneableonlyform,$cloneabletitle);
16172: if (exists($filter->{'cloneableonly'})) {
16173: my $cloneableon = '';
16174: my $cloneableoff = ' checked="checked"';
16175: if ($filter->{'cloneableonly'}) {
16176: $cloneableon = $cloneableoff;
16177: $cloneableoff = '';
16178: }
16179: $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>';
16180: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 16181: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 16182: } else {
16183: $cloneabletitle = &mt('Cloneable by you');
16184: }
16185: }
16186: my $officialjs;
16187: if ($crstype eq 'Course') {
16188: if (exists($filter->{'instcodefilter'})) {
16189: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16190: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16191: if ($codedom) {
16192: $officialjs = 1;
16193: ($instcodeform,$jscript,$$numtitlesref) =
16194: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16195: $officialjs,$codetitlesref);
16196: if ($jscript) {
16197: $jscript = '<script type="text/javascript">'."\n".
16198: '// <![CDATA['."\n".
16199: $jscript."\n".
16200: '// ]]>'."\n".
16201: '</script>'."\n";
16202: }
16203: }
16204: if ($instcodeform eq '') {
16205: $instcodeform =
16206: '<input type="text" name="instcodefilter" size="10" value="'.
16207: $list->{'instcodefilter'}.'" />';
16208: $instcodetitle = $lt{'ins'};
16209: } else {
16210: $instcodetitle = $lt{'inc'};
16211: }
16212: if ($fixeddom) {
16213: $instcodetitle .= '<br />('.$codedom.')';
16214: }
16215: }
16216: }
16217: my $output = qq|
16218: <form method="post" name="filterpicker" action="$action">
16219: <input type="hidden" name="form" value="$formname" />
16220: |;
16221: if ($formname eq 'modifycourse') {
16222: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16223: '<input type="hidden" name="prevphase" value="'.
16224: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 16225: } elsif ($formname eq 'quotacheck') {
16226: $output .= qq|
16227: <input type="hidden" name="sortby" value="" />
16228: <input type="hidden" name="sortorder" value="" />
16229: |;
16230: } else {
1.1075.2.69 raeburn 16231: my $name_input;
16232: if ($cnameelement ne '') {
16233: $name_input = '<input type="hidden" name="cnameelement" value="'.
16234: $cnameelement.'" />';
16235: }
16236: $output .= qq|
16237: <input type="hidden" name="cnumelement" value="$cnumelement" />
16238: <input type="hidden" name="cdomelement" value="$cdomelement" />
16239: $name_input
16240: $roleelement
16241: $multelement
16242: $typeelement
16243: |;
16244: if ($formname eq 'portform') {
16245: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16246: }
16247: }
16248: if ($fixeddom) {
16249: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16250: }
16251: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16252: if ($sincefilterform) {
16253: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16254: .$sincefilterform
16255: .&Apache::lonhtmlcommon::row_closure();
16256: }
16257: if ($createdfilterform) {
16258: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16259: .$createdfilterform
16260: .&Apache::lonhtmlcommon::row_closure();
16261: }
16262: if ($domainselectform) {
16263: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16264: .$domainselectform
16265: .&Apache::lonhtmlcommon::row_closure();
16266: }
16267: if ($typeselectform) {
16268: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16269: $output .= $typeselectform;
16270: } else {
16271: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16272: .$typeselectform
16273: .&Apache::lonhtmlcommon::row_closure();
16274: }
16275: }
16276: if ($instcodeform) {
16277: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16278: .$instcodeform
16279: .&Apache::lonhtmlcommon::row_closure();
16280: }
16281: if (exists($filter->{'ownerfilter'})) {
16282: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16283: '<table><tr><td>'.&mt('Username').'<br />'.
16284: '<input type="text" name="ownerfilter" size="20" value="'.
16285: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16286: $ownerdomselectform.'</td></tr></table>'.
16287: &Apache::lonhtmlcommon::row_closure();
16288: }
16289: if (exists($filter->{'personfilter'})) {
16290: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16291: '<table><tr><td>'.&mt('Username').'<br />'.
16292: '<input type="text" name="personfilter" size="20" value="'.
16293: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16294: $persondomselectform.'</td></tr></table>'.
16295: &Apache::lonhtmlcommon::row_closure();
16296: }
16297: if (exists($filter->{'coursefilter'})) {
16298: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16299: .'<input type="text" name="coursefilter" size="25" value="'
16300: .$list->{'coursefilter'}.'" />'
16301: .&Apache::lonhtmlcommon::row_closure();
16302: }
16303: if ($cloneableonlyform) {
16304: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16305: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16306: }
16307: if (exists($filter->{'descriptfilter'})) {
16308: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16309: .'<input type="text" name="descriptfilter" size="40" value="'
16310: .$list->{'descriptfilter'}.'" />'
16311: .&Apache::lonhtmlcommon::row_closure(1);
16312: }
16313: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16314: '<input type="hidden" name="updater" value="" />'."\n".
16315: '<input type="submit" name="gosearch" value="'.
16316: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16317: return $jscript.$clonewarning.$output;
16318: }
16319:
16320: =pod
16321:
16322: =item * &timebased_select_form()
16323:
16324: Create markup for a dropdown list used to select a time-based
16325: filter e.g., Course Activity, Course Created, when searching for courses
16326: or communities
16327:
16328: Inputs:
16329:
16330: item - name of form element (sincefilter or createdfilter)
16331:
16332: filter - anonymous hash of criteria and their values
16333:
16334: Returns: HTML for a select box contained a blank, then six time selections,
16335: with value set in incoming form variables currently selected.
16336:
16337: Side Effects: None
16338:
16339: =cut
16340:
16341: sub timebased_select_form {
16342: my ($item,$filter) = @_;
16343: if (ref($filter) eq 'HASH') {
16344: $filter->{$item} =~ s/[^\d-]//g;
16345: if (!$filter->{$item}) { $filter->{$item}=-1; }
16346: return &select_form(
16347: $filter->{$item},
16348: $item,
16349: { '-1' => '',
16350: '86400' => &mt('today'),
16351: '604800' => &mt('last week'),
16352: '2592000' => &mt('last month'),
16353: '7776000' => &mt('last three months'),
16354: '15552000' => &mt('last six months'),
16355: '31104000' => &mt('last year'),
16356: 'select_form_order' =>
16357: ['-1','86400','604800','2592000','7776000',
16358: '15552000','31104000']});
16359: }
16360: }
16361:
16362: =pod
16363:
16364: =item * &js_changer()
16365:
16366: Create script tag containing Javascript used to submit course search form
16367: when course type or domain is changed, and also to hide 'Searching ...' on
16368: page load completion for page showing search result.
16369:
16370: Inputs: None
16371:
16372: Returns: markup containing updateFilters() and hideSearching() javascript functions.
16373:
16374: Side Effects: None
16375:
16376: =cut
16377:
16378: sub js_changer {
16379: return <<ENDJS;
16380: <script type="text/javascript">
16381: // <![CDATA[
16382: function updateFilters(caller) {
16383: if (typeof(caller) != "undefined") {
16384: document.filterpicker.updater.value = caller.name;
16385: }
16386: document.filterpicker.submit();
16387: }
16388:
16389: function hideSearching() {
16390: if (document.getElementById('searching')) {
16391: document.getElementById('searching').style.display = 'none';
16392: }
16393: return;
16394: }
16395:
16396: // ]]>
16397: </script>
16398:
16399: ENDJS
16400: }
16401:
16402: =pod
16403:
16404: =item * &search_courses()
16405:
16406: Process selected filters form course search form and pass to lonnet::courseiddump
16407: to retrieve a hash for which keys are courseIDs which match the selected filters.
16408:
16409: Inputs:
16410:
16411: dom - domain being searched
16412:
16413: type - course type ('Course' or 'Community' or '.' if any).
16414:
16415: filter - anonymous hash of criteria and their values
16416:
16417: numtitles - for institutional codes - number of categories
16418:
16419: cloneruname - optional username of new course owner
16420:
16421: clonerudom - optional domain of new course owner
16422:
1.1075.2.95 raeburn 16423: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 16424: (used when DC is using course creation form)
16425:
16426: codetitles - reference to array of titles of components in institutional codes (official courses).
16427:
1.1075.2.95 raeburn 16428: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16429: (and so can clone automatically)
16430:
16431: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16432:
16433: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16434: courses to clone
1.1075.2.69 raeburn 16435:
16436: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16437:
16438:
16439: Side Effects: None
16440:
16441: =cut
16442:
16443:
16444: sub search_courses {
1.1075.2.95 raeburn 16445: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16446: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 16447: my (%courses,%showcourses,$cloner);
16448: if (($filter->{'ownerfilter'} ne '') ||
16449: ($filter->{'ownerdomfilter'} ne '')) {
16450: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16451: $filter->{'ownerdomfilter'};
16452: }
16453: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16454: if (!$filter->{$item}) {
16455: $filter->{$item}='.';
16456: }
16457: }
16458: my $now = time;
16459: my $timefilter =
16460: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16461: my ($createdbefore,$createdafter);
16462: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16463: $createdbefore = $now;
16464: $createdafter = $now-$filter->{'createdfilter'};
16465: }
16466: my ($instcodefilter,$regexpok);
16467: if ($numtitles) {
16468: if ($env{'form.official'} eq 'on') {
16469: $instcodefilter =
16470: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16471: $regexpok = 1;
16472: } elsif ($env{'form.official'} eq 'off') {
16473: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16474: unless ($instcodefilter eq '') {
16475: $regexpok = -1;
16476: }
16477: }
16478: } else {
16479: $instcodefilter = $filter->{'instcodefilter'};
16480: }
16481: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16482: if ($type eq '') { $type = '.'; }
16483:
16484: if (($clonerudom ne '') && ($cloneruname ne '')) {
16485: $cloner = $cloneruname.':'.$clonerudom;
16486: }
16487: %courses = &Apache::lonnet::courseiddump($dom,
16488: $filter->{'descriptfilter'},
16489: $timefilter,
16490: $instcodefilter,
16491: $filter->{'combownerfilter'},
16492: $filter->{'coursefilter'},
16493: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 16494: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 16495: $filter->{'cloneableonly'},
16496: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 16497: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 16498: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16499: my $ccrole;
16500: if ($type eq 'Community') {
16501: $ccrole = 'co';
16502: } else {
16503: $ccrole = 'cc';
16504: }
16505: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16506: $filter->{'persondomfilter'},
16507: 'userroles',undef,
16508: [$ccrole,'in','ad','ep','ta','cr'],
16509: $dom);
16510: foreach my $role (keys(%rolehash)) {
16511: my ($cnum,$cdom,$courserole) = split(':',$role);
16512: my $cid = $cdom.'_'.$cnum;
16513: if (exists($courses{$cid})) {
16514: if (ref($courses{$cid}) eq 'HASH') {
16515: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16516: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 16517: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 16518: }
16519: } else {
16520: $courses{$cid}{roles} = [$courserole];
16521: }
16522: $showcourses{$cid} = $courses{$cid};
16523: }
16524: }
16525: }
16526: %courses = %showcourses;
16527: }
16528: return %courses;
16529: }
16530:
16531: =pod
16532:
16533: =back
16534:
1.1075.2.88 raeburn 16535: =head1 Routines for version requirements for current course.
16536:
16537: =over 4
16538:
16539: =item * &check_release_required()
16540:
16541: Compares required LON-CAPA version with version on server, and
16542: if required version is newer looks for a server with the required version.
16543:
16544: Looks first at servers in user's owen domain; if none suitable, looks at
16545: servers in course's domain are permitted to host sessions for user's domain.
16546:
16547: Inputs:
16548:
16549: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16550:
16551: $courseid - Course ID of current course
16552:
16553: $rolecode - User's current role in course (for switchserver query string).
16554:
16555: $required - LON-CAPA version needed by course (format: Major.Minor).
16556:
16557:
16558: Returns:
16559:
16560: $switchserver - query string tp append to /adm/switchserver call (if
16561: current server's LON-CAPA version is too old.
16562:
16563: $warning - Message is displayed if no suitable server could be found.
16564:
16565: =cut
16566:
16567: sub check_release_required {
16568: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16569: my ($switchserver,$warning);
16570: if ($required ne '') {
16571: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16572: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16573: if ($reqdmajor ne '' && $reqdminor ne '') {
16574: my $otherserver;
16575: if (($major eq '' && $minor eq '') ||
16576: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16577: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16578: my $switchlcrev =
16579: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16580: $userdomserver);
16581: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16582: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16583: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16584: my $cdom = $env{'course.'.$courseid.'.domain'};
16585: if ($cdom ne $env{'user.domain'}) {
16586: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16587: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16588: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16589: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16590: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16591: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16592: my $canhost =
16593: &Apache::lonnet::can_host_session($env{'user.domain'},
16594: $coursedomserver,
16595: $remoterev,
16596: $udomdefaults{'remotesessions'},
16597: $defdomdefaults{'hostedsessions'});
16598:
16599: if ($canhost) {
16600: $otherserver = $coursedomserver;
16601: } else {
16602: $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.");
16603: }
16604: } else {
16605: $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).");
16606: }
16607: } else {
16608: $otherserver = $userdomserver;
16609: }
16610: }
16611: if ($otherserver ne '') {
16612: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16613: }
16614: }
16615: }
16616: return ($switchserver,$warning);
16617: }
16618:
16619: =pod
16620:
16621: =item * &check_release_result()
16622:
16623: Inputs:
16624:
16625: $switchwarning - Warning message if no suitable server found to host session.
16626:
16627: $switchserver - query string to append to /adm/switchserver containing lonHostID
16628: and current role.
16629:
16630: Returns: HTML to display with information about requirement to switch server.
16631: Either displaying warning with link to Roles/Courses screen or
16632: display link to switchserver.
16633:
1.1075.2.69 raeburn 16634: =cut
16635:
1.1075.2.88 raeburn 16636: sub check_release_result {
16637: my ($switchwarning,$switchserver) = @_;
16638: my $output = &start_page('Selected course unavailable on this server').
16639: '<p class="LC_warning">';
16640: if ($switchwarning) {
16641: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16642: if (&show_course()) {
16643: $output .= &mt('Display courses');
16644: } else {
16645: $output .= &mt('Display roles');
16646: }
16647: $output .= '</a>';
16648: } elsif ($switchserver) {
16649: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16650: '<br />'.
16651: '<a href="/adm/switchserver?'.$switchserver.'">'.
16652: &mt('Switch Server').
16653: '</a>';
16654: }
16655: $output .= '</p>'.&end_page();
16656: return $output;
16657: }
16658:
16659: =pod
16660:
16661: =item * &needs_coursereinit()
16662:
16663: Determine if course contents stored for user's session needs to be
16664: refreshed, because content has changed since "Big Hash" last tied.
16665:
16666: Check for change is made if time last checked is more than 10 minutes ago
16667: (by default).
16668:
16669: Inputs:
16670:
16671: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16672:
16673: $interval (optional) - Time which may elapse (in s) between last check for content
16674: change in current course. (default: 600 s).
16675:
16676: Returns: an array; first element is:
16677:
16678: =over 4
16679:
16680: 'switch' - if content updates mean user's session
16681: needs to be switched to a server running a newer LON-CAPA version
16682:
16683: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16684: on current server hosting user's session
16685:
16686: '' - if no action required.
16687:
16688: =back
16689:
16690: If first item element is 'switch':
16691:
16692: second item is $switchwarning - Warning message if no suitable server found to host session.
16693:
16694: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16695: and current role.
16696:
16697: otherwise: no other elements returned.
16698:
16699: =back
16700:
16701: =cut
16702:
16703: sub needs_coursereinit {
16704: my ($loncaparev,$interval) = @_;
16705: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16706: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16707: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16708: my $now = time;
16709: if ($interval eq '') {
16710: $interval = 600;
16711: }
16712: if (($now-$env{'request.course.timechecked'})>$interval) {
16713: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16714: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16715: if ($lastchange > $env{'request.course.tied'}) {
16716: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16717: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16718: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16719: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16720: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16721: $curr_reqd_hash{'internal.releaserequired'}});
16722: my ($switchserver,$switchwarning) =
16723: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16724: $curr_reqd_hash{'internal.releaserequired'});
16725: if ($switchwarning ne '' || $switchserver ne '') {
16726: return ('switch',$switchwarning,$switchserver);
16727: }
16728: }
16729: }
16730: return ('update');
16731: }
16732: }
16733: return ();
16734: }
1.1075.2.69 raeburn 16735:
1.1075.2.11 raeburn 16736: sub update_content_constraints {
16737: my ($cdom,$cnum,$chome,$cid) = @_;
16738: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16739: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16740: my %checkresponsetypes;
16741: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
16742: my ($item,$name,$value) = split(/:/,$key);
16743: if ($item eq 'resourcetag') {
16744: if ($name eq 'responsetype') {
16745: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
16746: }
16747: }
16748: }
16749: my $navmap = Apache::lonnavmaps::navmap->new();
16750: if (defined($navmap)) {
16751: my %allresponses;
16752: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
16753: my %responses = $res->responseTypes();
16754: foreach my $key (keys(%responses)) {
16755: next unless(exists($checkresponsetypes{$key}));
16756: $allresponses{$key} += $responses{$key};
16757: }
16758: }
16759: foreach my $key (keys(%allresponses)) {
16760: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
16761: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
16762: ($reqdmajor,$reqdminor) = ($major,$minor);
16763: }
16764: }
16765: undef($navmap);
16766: }
16767: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
16768: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
16769: }
16770: return;
16771: }
16772:
1.1075.2.27 raeburn 16773: sub allmaps_incourse {
16774: my ($cdom,$cnum,$chome,$cid) = @_;
16775: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
16776: $cid = $env{'request.course.id'};
16777: $cdom = $env{'course.'.$cid.'.domain'};
16778: $cnum = $env{'course.'.$cid.'.num'};
16779: $chome = $env{'course.'.$cid.'.home'};
16780: }
16781: my %allmaps = ();
16782: my $lastchange =
16783: &Apache::lonnet::get_coursechange($cdom,$cnum);
16784: if ($lastchange > $env{'request.course.tied'}) {
16785: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
16786: unless ($ferr) {
16787: &update_content_constraints($cdom,$cnum,$chome,$cid);
16788: }
16789: }
16790: my $navmap = Apache::lonnavmaps::navmap->new();
16791: if (defined($navmap)) {
16792: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
16793: $allmaps{$res->src()} = 1;
16794: }
16795: }
16796: return \%allmaps;
16797: }
16798:
1.1075.2.11 raeburn 16799: sub parse_supplemental_title {
16800: my ($title) = @_;
16801:
16802: my ($foldertitle,$renametitle);
16803: if ($title =~ /&&&/) {
16804: $title = &HTML::Entites::decode($title);
16805: }
16806: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
16807: $renametitle=$4;
16808: my ($time,$uname,$udom) = ($1,$2,$3);
16809: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
16810: my $name = &plainname($uname,$udom);
16811: $name = &HTML::Entities::encode($name,'"<>&\'');
16812: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
16813: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
16814: $name.': <br />'.$foldertitle;
16815: }
16816: if (wantarray) {
16817: return ($title,$foldertitle,$renametitle);
16818: }
16819: return $title;
16820: }
16821:
1.1075.2.43 raeburn 16822: sub recurse_supplemental {
16823: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
16824: if ($suppmap) {
16825: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16826: if ($fatal) {
16827: $errors ++;
16828: } else {
16829: if ($#LONCAPA::map::resources > 0) {
16830: foreach my $res (@LONCAPA::map::resources) {
16831: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16832: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 16833: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16834: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 16835: } else {
16836: $numfiles ++;
16837: }
16838: }
16839: }
16840: }
16841: }
16842: }
16843: return ($numfiles,$errors);
16844: }
16845:
1.1075.2.18 raeburn 16846: sub symb_to_docspath {
1.1075.2.119 raeburn 16847: my ($symb,$navmapref) = @_;
16848: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 16849: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
16850: if ($resurl=~/\.(sequence|page)$/) {
16851: $mapurl=$resurl;
16852: } elsif ($resurl eq 'adm/navmaps') {
16853: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
16854: }
16855: my $mapresobj;
1.1075.2.119 raeburn 16856: unless (ref($$navmapref)) {
16857: $$navmapref = Apache::lonnavmaps::navmap->new();
16858: }
16859: if (ref($$navmapref)) {
16860: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 16861: }
16862: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
16863: my $type=$2;
16864: my $path;
16865: if (ref($mapresobj)) {
16866: my $pcslist = $mapresobj->map_hierarchy();
16867: if ($pcslist ne '') {
16868: foreach my $pc (split(/,/,$pcslist)) {
16869: next if ($pc <= 1);
1.1075.2.119 raeburn 16870: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 16871: if (ref($res)) {
16872: my $thisurl = $res->src();
16873: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
16874: my $thistitle = $res->title();
16875: $path .= '&'.
16876: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 16877: &escape($thistitle).
1.1075.2.18 raeburn 16878: ':'.$res->randompick().
16879: ':'.$res->randomout().
16880: ':'.$res->encrypted().
16881: ':'.$res->randomorder().
16882: ':'.$res->is_page();
16883: }
16884: }
16885: }
16886: $path =~ s/^\&//;
16887: my $maptitle = $mapresobj->title();
16888: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16889: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16890: }
16891: $path .= (($path ne '')? '&' : '').
16892: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16893: &escape($maptitle).
1.1075.2.18 raeburn 16894: ':'.$mapresobj->randompick().
16895: ':'.$mapresobj->randomout().
16896: ':'.$mapresobj->encrypted().
16897: ':'.$mapresobj->randomorder().
16898: ':'.$mapresobj->is_page();
16899: } else {
16900: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16901: my $ispage = (($type eq 'page')? 1 : '');
16902: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16903: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16904: }
16905: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16906: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 16907: }
16908: unless ($mapurl eq 'default') {
16909: $path = 'default&'.
1.1075.2.46 raeburn 16910: &escape('Main Content').
1.1075.2.18 raeburn 16911: ':::::&'.$path;
16912: }
16913: return $path;
16914: }
16915:
1.1075.2.14 raeburn 16916: sub captcha_display {
1.1075.2.137 raeburn 16917: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 16918: my ($output,$error);
1.1075.2.107 raeburn 16919: my ($captcha,$pubkey,$privkey,$version) =
1.1075.2.137 raeburn 16920: &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 16921: if ($captcha eq 'original') {
16922: $output = &create_captcha();
16923: unless ($output) {
16924: $error = 'captcha';
16925: }
16926: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16927: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 16928: unless ($output) {
16929: $error = 'recaptcha';
16930: }
16931: }
1.1075.2.107 raeburn 16932: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 16933: }
16934:
16935: sub captcha_response {
1.1075.2.137 raeburn 16936: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 16937: my ($captcha_chk,$captcha_error);
1.1075.2.137 raeburn 16938: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 16939: if ($captcha eq 'original') {
16940: ($captcha_chk,$captcha_error) = &check_captcha();
16941: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16942: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 16943: } else {
16944: $captcha_chk = 1;
16945: }
16946: return ($captcha_chk,$captcha_error);
16947: }
16948:
16949: sub get_captcha_config {
1.1075.2.137 raeburn 16950: my ($context,$lonhost,$dom_in_effect) = @_;
1.1075.2.107 raeburn 16951: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 16952: my $hostname = &Apache::lonnet::hostname($lonhost);
16953: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
16954: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16955: if ($context eq 'usercreation') {
16956: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
16957: if (ref($domconfig{$context}) eq 'HASH') {
16958: $hashtocheck = $domconfig{$context}{'cancreate'};
16959: if (ref($hashtocheck) eq 'HASH') {
16960: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
16961: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
16962: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
16963: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
16964: }
16965: if ($privkey && $pubkey) {
16966: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16967: $version = $hashtocheck->{'recaptchaversion'};
16968: if ($version ne '2') {
16969: $version = 1;
16970: }
1.1075.2.14 raeburn 16971: } else {
16972: $captcha = 'original';
16973: }
16974: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
16975: $captcha = 'original';
16976: }
16977: }
16978: } else {
16979: $captcha = 'captcha';
16980: }
16981: } elsif ($context eq 'login') {
16982: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
16983: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
16984: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
16985: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
16986: if ($privkey && $pubkey) {
16987: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16988: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
16989: if ($version ne '2') {
16990: $version = 1;
16991: }
1.1075.2.14 raeburn 16992: } else {
16993: $captcha = 'original';
16994: }
16995: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
16996: $captcha = 'original';
16997: }
1.1075.2.137 raeburn 16998: } elsif ($context eq 'passwords') {
16999: if ($dom_in_effect) {
17000: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
17001: if ($passwdconf{'captcha'} eq 'recaptcha') {
17002: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
17003: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
17004: $privkey = $passwdconf{'recaptchakeys'}{'private'};
17005: }
17006: if ($privkey && $pubkey) {
17007: $captcha = 'recaptcha';
17008: $version = $passwdconf{'recaptchaversion'};
17009: if ($version ne '2') {
17010: $version = 1;
17011: }
17012: } else {
17013: $captcha = 'original';
17014: }
17015: } elsif ($passwdconf{'captcha'} ne 'notused') {
17016: $captcha = 'original';
17017: }
17018: }
1.1075.2.14 raeburn 17019: }
1.1075.2.107 raeburn 17020: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 17021: }
17022:
17023: sub create_captcha {
17024: my %captcha_params = &captcha_settings();
17025: my ($output,$maxtries,$tries) = ('',10,0);
17026: while ($tries < $maxtries) {
17027: $tries ++;
17028: my $captcha = Authen::Captcha->new (
17029: output_folder => $captcha_params{'output_dir'},
17030: data_folder => $captcha_params{'db_dir'},
17031: );
17032: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17033:
17034: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17035: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17036: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 17037: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17038: '<br />'.
17039: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 17040: last;
17041: }
17042: }
17043: return $output;
17044: }
17045:
17046: sub captcha_settings {
17047: my %captcha_params = (
17048: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17049: www_output_dir => "/captchaspool",
17050: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17051: numchars => '5',
17052: );
17053: return %captcha_params;
17054: }
17055:
17056: sub check_captcha {
17057: my ($captcha_chk,$captcha_error);
17058: my $code = $env{'form.code'};
17059: my $md5sum = $env{'form.crypt'};
17060: my %captcha_params = &captcha_settings();
17061: my $captcha = Authen::Captcha->new(
17062: output_folder => $captcha_params{'output_dir'},
17063: data_folder => $captcha_params{'db_dir'},
17064: );
1.1075.2.26 raeburn 17065: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 17066: my %captcha_hash = (
17067: 0 => 'Code not checked (file error)',
17068: -1 => 'Failed: code expired',
17069: -2 => 'Failed: invalid code (not in database)',
17070: -3 => 'Failed: invalid code (code does not match crypt)',
17071: );
17072: if ($captcha_chk != 1) {
17073: $captcha_error = $captcha_hash{$captcha_chk}
17074: }
17075: return ($captcha_chk,$captcha_error);
17076: }
17077:
17078: sub create_recaptcha {
1.1075.2.107 raeburn 17079: my ($pubkey,$version) = @_;
17080: if ($version >= 2) {
17081: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17082: } else {
17083: my $use_ssl;
17084: if ($ENV{'SERVER_PORT'} == 443) {
17085: $use_ssl = 1;
17086: }
17087: my $captcha = Captcha::reCAPTCHA->new;
17088: return $captcha->get_options_setter({theme => 'white'})."\n".
17089: $captcha->get_html($pubkey,undef,$use_ssl).
17090: &mt('If the text is hard to read, [_1] will replace them.',
17091: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17092: '<br /><br />';
17093: }
1.1075.2.14 raeburn 17094: }
17095:
17096: sub check_recaptcha {
1.1075.2.107 raeburn 17097: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 17098: my $captcha_chk;
1.1075.2.107 raeburn 17099: if ($version >= 2) {
17100: my $ua = LWP::UserAgent->new;
17101: $ua->timeout(10);
17102: my %info = (
17103: secret => $privkey,
17104: response => $env{'form.g-recaptcha-response'},
17105: remoteip => $ENV{'REMOTE_ADDR'},
17106: );
17107: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
17108: if ($response->is_success) {
17109: my $data = JSON::DWIW->from_json($response->decoded_content);
17110: if (ref($data) eq 'HASH') {
17111: if ($data->{'success'}) {
17112: $captcha_chk = 1;
17113: }
17114: }
17115: }
17116: } else {
17117: my $captcha = Captcha::reCAPTCHA->new;
17118: my $captcha_result =
17119: $captcha->check_answer(
17120: $privkey,
17121: $ENV{'REMOTE_ADDR'},
17122: $env{'form.recaptcha_challenge_field'},
17123: $env{'form.recaptcha_response_field'},
17124: );
17125: if ($captcha_result->{is_valid}) {
17126: $captcha_chk = 1;
17127: }
1.1075.2.14 raeburn 17128: }
17129: return $captcha_chk;
17130: }
17131:
1.1075.2.64 raeburn 17132: sub emailusername_info {
1.1075.2.103 raeburn 17133: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 17134: my %titles = &Apache::lonlocal::texthash (
17135: lastname => 'Last Name',
17136: firstname => 'First Name',
17137: institution => 'School/college/university',
17138: location => "School's city, state/province, country",
17139: web => "School's web address",
17140: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 17141: id => 'Student/Employee ID',
1.1075.2.64 raeburn 17142: );
17143: return (\@fields,\%titles);
17144: }
17145:
1.1075.2.56 raeburn 17146: sub cleanup_html {
17147: my ($incoming) = @_;
17148: my $outgoing;
17149: if ($incoming ne '') {
17150: $outgoing = $incoming;
17151: $outgoing =~ s/;/;/g;
17152: $outgoing =~ s/\#/#/g;
17153: $outgoing =~ s/\&/&/g;
17154: $outgoing =~ s/</</g;
17155: $outgoing =~ s/>/>/g;
17156: $outgoing =~ s/\(/(/g;
17157: $outgoing =~ s/\)/)/g;
17158: $outgoing =~ s/"/"/g;
17159: $outgoing =~ s/'/'/g;
17160: $outgoing =~ s/\$/$/g;
17161: $outgoing =~ s{/}{/}g;
17162: $outgoing =~ s/=/=/g;
17163: $outgoing =~ s/\\/\/g
17164: }
17165: return $outgoing;
17166: }
17167:
1.1075.2.74 raeburn 17168: # Checks for critical messages and returns a redirect url if one exists.
17169: # $interval indicates how often to check for messages.
17170: sub critical_redirect {
17171: my ($interval) = @_;
17172: if ((time-$env{'user.criticalcheck.time'})>$interval) {
17173: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17174: $env{'user.name'});
17175: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
17176: my $redirecturl;
17177: if ($what[0]) {
17178: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17179: $redirecturl='/adm/email?critical=display';
17180: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17181: return (1, $url);
17182: }
17183: }
17184: }
17185: return ();
17186: }
17187:
1.1075.2.64 raeburn 17188: # Use:
17189: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17190: #
17191: ##################################################
17192: # password associated functions #
17193: ##################################################
17194: sub des_keys {
17195: # Make a new key for DES encryption.
17196: # Each key has two parts which are returned separately.
17197: # Please note: Each key must be passed through the &hex function
17198: # before it is output to the web browser. The hex versions cannot
17199: # be used to decrypt.
17200: my @hexstr=('0','1','2','3','4','5','6','7',
17201: '8','9','a','b','c','d','e','f');
17202: my $lkey='';
17203: for (0..7) {
17204: $lkey.=$hexstr[rand(15)];
17205: }
17206: my $ukey='';
17207: for (0..7) {
17208: $ukey.=$hexstr[rand(15)];
17209: }
17210: return ($lkey,$ukey);
17211: }
17212:
17213: sub des_decrypt {
17214: my ($key,$cyphertext) = @_;
17215: my $keybin=pack("H16",$key);
17216: my $cypher;
17217: if ($Crypt::DES::VERSION>=2.03) {
17218: $cypher=new Crypt::DES $keybin;
17219: } else {
17220: $cypher=new DES $keybin;
17221: }
1.1075.2.106 raeburn 17222: my $plaintext='';
17223: my $cypherlength = length($cyphertext);
17224: my $numchunks = int($cypherlength/32);
17225: for (my $j=0; $j<$numchunks; $j++) {
17226: my $start = $j*32;
17227: my $cypherblock = substr($cyphertext,$start,32);
17228: my $chunk =
17229: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17230: $chunk .=
17231: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17232: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17233: $plaintext .= $chunk;
17234: }
1.1075.2.64 raeburn 17235: return $plaintext;
17236: }
17237:
1.1075.2.135 raeburn 17238: sub is_nonframeable {
17239: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
17240: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
17241: return if (($remprotocol eq '') || ($remhost eq ''));
17242:
17243: $remprotocol = lc($remprotocol);
17244: $remhost = lc($remhost);
17245: my $remport = 80;
17246: if ($remprotocol eq 'https') {
17247: $remport = 443;
17248: }
17249: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
17250: if ($cached) {
17251: unless ($nocache) {
17252: if ($result) {
17253: return 1;
17254: } else {
17255: return 0;
17256: }
17257: }
17258: }
17259: my $uselink;
17260: my $request = new HTTP::Request('HEAD',$url);
1.1075.2.142 raeburn 17261: my $ua = LWP::UserAgent->new;
17262: $ua->timeout(5);
17263: my $response=$ua->request($request);
1.1075.2.135 raeburn 17264: if ($response->is_success()) {
17265: my $secpolicy = lc($response->header('content-security-policy'));
17266: my $xframeop = lc($response->header('x-frame-options'));
17267: $secpolicy =~ s/^\s+|\s+$//g;
17268: $xframeop =~ s/^\s+|\s+$//g;
17269: if (($secpolicy ne '') || ($xframeop ne '')) {
17270: my $remotehost = $remprotocol.'://'.$remhost;
17271: my ($origin,$protocol,$port);
17272: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
17273: $port = $ENV{'SERVER_PORT'};
17274: } else {
17275: $port = 80;
17276: }
17277: if ($absolute eq '') {
17278: $protocol = 'http:';
17279: if ($port == 443) {
17280: $protocol = 'https:';
17281: }
17282: $origin = $protocol.'//'.lc($hostname);
17283: } else {
17284: $origin = lc($absolute);
17285: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
17286: }
17287: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
17288: my $framepolicy = $1;
17289: $framepolicy =~ s/^\s+|\s+$//g;
17290: my @policies = split(/\s+/,$framepolicy);
17291: if (@policies) {
17292: if (grep(/^\Q'none'\E$/,@policies)) {
17293: $uselink = 1;
17294: } else {
17295: $uselink = 1;
17296: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
17297: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
17298: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
17299: undef($uselink);
17300: }
17301: if ($uselink) {
17302: if (grep(/^\Q'self'\E$/,@policies)) {
17303: if (($origin ne '') && ($remotehost eq $origin)) {
17304: undef($uselink);
17305: }
17306: }
17307: }
17308: if ($uselink) {
17309: my @possok;
17310: if ($ip ne '') {
17311: push(@possok,$ip);
17312: }
17313: my $hoststr = '';
17314: foreach my $part (reverse(split(/\./,$hostname))) {
17315: if ($hoststr eq '') {
17316: $hoststr = $part;
17317: } else {
17318: $hoststr = "$part.$hoststr";
17319: }
17320: if ($hoststr eq $hostname) {
17321: push(@possok,$hostname);
17322: } else {
17323: push(@possok,"*.$hoststr");
17324: }
17325: }
17326: if (@possok) {
17327: foreach my $poss (@possok) {
17328: last if (!$uselink);
17329: foreach my $policy (@policies) {
17330: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
17331: undef($uselink);
17332: last;
17333: }
17334: }
17335: }
17336: }
17337: }
17338: }
17339: }
17340: } elsif ($xframeop ne '') {
17341: $uselink = 1;
17342: my @policies = split(/\s*,\s*/,$xframeop);
17343: if (@policies) {
17344: unless (grep(/^deny$/,@policies)) {
17345: if ($origin ne '') {
17346: if (grep(/^sameorigin$/,@policies)) {
17347: if ($remotehost eq $origin) {
17348: undef($uselink);
17349: }
17350: }
17351: if ($uselink) {
17352: foreach my $policy (@policies) {
17353: if ($policy =~ /^allow-from\s*(.+)$/) {
17354: my $allowfrom = $1;
17355: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
17356: undef($uselink);
17357: last;
17358: }
17359: }
17360: }
17361: }
17362: }
17363: }
17364: }
17365: }
17366: }
17367: }
17368: if ($nocache) {
17369: if ($cached) {
17370: my $devalidate;
17371: if ($uselink && !$result) {
17372: $devalidate = 1;
17373: } elsif (!$uselink && $result) {
17374: $devalidate = 1;
17375: }
17376: if ($devalidate) {
17377: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
17378: }
17379: }
17380: } else {
17381: if ($uselink) {
17382: $result = 1;
17383: } else {
17384: $result = 0;
17385: }
17386: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
17387: }
17388: return $uselink;
17389: }
17390:
1.112 bowersj2 17391: 1;
17392: __END__;
1.41 ng 17393:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>