Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.147
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.147! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.146 2020/05/22 20:48:01 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.147! raeburn 4847: my ($blocked,$nosymbcache);
! 4848: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
! 4849: $blocked = 1;
! 4850: $nosymbcache = 1;
! 4851: }
! 4852: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$blocked,\%commblocks);
1.1062 raeburn 4853: foreach my $block (@blockers) {
4854: if ($block =~ /^firstaccess____(.+)$/) {
4855: my $item = $1;
4856: my $type = 'map';
4857: my $timersymb = $item;
4858: if ($item eq 'course') {
4859: $type = 'course';
4860: } elsif ($item =~ /___\d+___/) {
4861: $type = 'resource';
4862: } else {
4863: $timersymb = &Apache::lonnet::symbread($item);
4864: }
4865: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4866: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4867: $triggered{$block} = {
4868: start => $start,
4869: end => $end,
4870: type => $type,
4871: };
4872: }
4873: }
4874: } else {
4875: foreach my $block (keys(%commblocks)) {
4876: if ($block =~ m/^(\d+)____(\d+)$/) {
4877: my ($start,$end) = ($1,$2);
4878: if ($start <= time && $end >= time) {
4879: if (ref($commblocks{$block}) eq 'HASH') {
4880: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4881: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4882: unless(grep(/^\Q$block\E$/,@blockers)) {
4883: push(@blockers,$block);
4884: }
4885: }
4886: }
4887: }
4888: }
4889: } elsif ($block =~ /^firstaccess____(.+)$/) {
4890: my $item = $1;
4891: my $timersymb = $item;
4892: my $type = 'map';
4893: if ($item eq 'course') {
4894: $type = 'course';
4895: } elsif ($item =~ /___\d+___/) {
4896: $type = 'resource';
4897: } else {
4898: $timersymb = &Apache::lonnet::symbread($item);
4899: }
4900: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4901: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4902: if ($start && $end) {
4903: if (($start <= time) && ($end >= time)) {
4904: unless (grep(/^\Q$block\E$/,@blockers)) {
4905: push(@blockers,$block);
4906: $triggered{$block} = {
4907: start => $start,
4908: end => $end,
4909: type => $type,
4910: };
4911: }
4912: }
1.490 raeburn 4913: }
1.1062 raeburn 4914: }
4915: }
4916: }
4917: foreach my $blocker (@blockers) {
4918: my ($staff_name,$staff_dom,$title,$blocks) =
4919: &parse_block_record($commblocks{$blocker});
4920: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4921: my ($start,$end,$triggertype);
4922: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4923: ($start,$end) = ($1,$2);
4924: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4925: $start = $triggered{$blocker}{'start'};
4926: $end = $triggered{$blocker}{'end'};
4927: $triggertype = $triggered{$blocker}{'type'};
4928: }
4929: if ($start) {
4930: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4931: if ($triggertype) {
4932: push(@{$$setters{$course}{'triggers'}},$triggertype);
4933: } else {
4934: push(@{$$setters{$course}{'triggers'}},0);
4935: }
4936: if ( ($startblock == 0) || ($startblock > $start) ) {
4937: $startblock = $start;
4938: if ($triggertype) {
4939: $triggerblock = $blocker;
1.474 raeburn 4940: }
4941: }
1.1062 raeburn 4942: if ( ($endblock == 0) || ($endblock < $end) ) {
4943: $endblock = $end;
4944: if ($triggertype) {
4945: $triggerblock = $blocker;
4946: }
4947: }
1.474 raeburn 4948: }
4949: }
1.1062 raeburn 4950: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4951: }
4952:
4953: sub parse_block_record {
4954: my ($record) = @_;
4955: my ($setuname,$setudom,$title,$blocks);
4956: if (ref($record) eq 'HASH') {
4957: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4958: $title = &unescape($record->{'event'});
4959: $blocks = $record->{'blocks'};
4960: } else {
4961: my @data = split(/:/,$record,3);
4962: if (scalar(@data) eq 2) {
4963: $title = $data[1];
4964: ($setuname,$setudom) = split(/@/,$data[0]);
4965: } else {
4966: ($setuname,$setudom,$title) = @data;
4967: }
4968: $blocks = { 'com' => 'on' };
4969: }
4970: return ($setuname,$setudom,$title,$blocks);
4971: }
4972:
1.854 kalberla 4973: sub blocking_status {
1.1075.2.147! raeburn 4974: my ($activity,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 4975: my %setters;
1.890 droeschl 4976:
1.1061 raeburn 4977: # check for active blocking
1.1062 raeburn 4978: my ($startblock,$endblock,$triggerblock) =
1.1075.2.147! raeburn 4979: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 4980: my $blocked = 0;
4981: if ($startblock && $endblock) {
4982: $blocked = 1;
4983: }
1.890 droeschl 4984:
1.1061 raeburn 4985: # caller just wants to know whether a block is active
4986: if (!wantarray) { return $blocked; }
4987:
4988: # build a link to a popup window containing the details
4989: my $querystring = "?activity=$activity";
4990: # $uname and $udom decide whose portfolio the user is trying to look at
1.1075.2.97 raeburn 4991: if (($activity eq 'port') || ($activity eq 'passwd')) {
4992: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
4993: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 4994: } elsif ($activity eq 'docs') {
1.1075.2.147! raeburn 4995: my $showurl = &Apache::lonenc::check_encrypt($url);
! 4996: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
! 4997: if ($symb) {
! 4998: my $showsymb = &Apache::lonenc::check_encrypt($symb);
! 4999: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
! 5000: }
1.1062 raeburn 5001: }
1.1061 raeburn 5002:
5003: my $output .= <<'END_MYBLOCK';
5004: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5005: var options = "width=" + w + ",height=" + h + ",";
5006: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5007: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5008: var newWin = window.open(url, wdwName, options);
5009: newWin.focus();
5010: }
1.890 droeschl 5011: END_MYBLOCK
1.854 kalberla 5012:
1.1061 raeburn 5013: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5014:
1.1061 raeburn 5015: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5016: my $text = &mt('Communication Blocked');
1.1075.2.93 raeburn 5017: my $class = 'LC_comblock';
1.1062 raeburn 5018: if ($activity eq 'docs') {
5019: $text = &mt('Content Access Blocked');
1.1075.2.93 raeburn 5020: $class = '';
1.1063 raeburn 5021: } elsif ($activity eq 'printout') {
5022: $text = &mt('Printing Blocked');
1.1075.2.97 raeburn 5023: } elsif ($activity eq 'passwd') {
5024: $text = &mt('Password Changing Blocked');
1.1062 raeburn 5025: }
1.1061 raeburn 5026: $output .= <<"END_BLOCK";
1.1075.2.93 raeburn 5027: <div class='$class'>
1.869 kalberla 5028: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5029: title='$text'>
5030: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5031: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5032: title='$text'>$text</a>
1.867 kalberla 5033: </div>
5034:
5035: END_BLOCK
1.474 raeburn 5036:
1.1061 raeburn 5037: return ($blocked, $output);
1.854 kalberla 5038: }
1.490 raeburn 5039:
1.60 matthew 5040: ###############################################
5041:
1.682 raeburn 5042: sub check_ip_acc {
1.1075.2.105 raeburn 5043: my ($acc,$clientip)=@_;
1.682 raeburn 5044: &Apache::lonxml::debug("acc is $acc");
5045: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5046: return 1;
5047: }
5048: my $allowed=0;
1.1075.2.144 raeburn 5049: my $ip;
5050: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5051: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5052: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5053: } else {
5054: $ip = $ENV{'REMOTE_ADDR'} || $env{'request.host'} || $clientip;
5055: }
1.682 raeburn 5056:
5057: my $name;
5058: foreach my $pattern (split(',',$acc)) {
5059: $pattern =~ s/^\s*//;
5060: $pattern =~ s/\s*$//;
5061: if ($pattern =~ /\*$/) {
5062: #35.8.*
5063: $pattern=~s/\*//;
5064: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
5065: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5066: #35.8.3.[34-56]
5067: my $low=$2;
5068: my $high=$3;
5069: $pattern=$1;
5070: if ($ip =~ /^\Q$pattern\E/) {
5071: my $last=(split(/\./,$ip))[3];
5072: if ($last <=$high && $last >=$low) { $allowed=1; }
5073: }
5074: } elsif ($pattern =~ /^\*/) {
5075: #*.msu.edu
5076: $pattern=~s/\*//;
5077: if (!defined($name)) {
5078: use Socket;
5079: my $netaddr=inet_aton($ip);
5080: ($name)=gethostbyaddr($netaddr,AF_INET);
5081: }
5082: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
5083: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5084: #127.0.0.1
5085: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
5086: } else {
5087: #some.name.com
5088: if (!defined($name)) {
5089: use Socket;
5090: my $netaddr=inet_aton($ip);
5091: ($name)=gethostbyaddr($netaddr,AF_INET);
5092: }
5093: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
5094: }
5095: if ($allowed) { last; }
5096: }
5097: return $allowed;
5098: }
5099:
5100: ###############################################
5101:
1.60 matthew 5102: =pod
5103:
1.112 bowersj2 5104: =head1 Domain Template Functions
5105:
5106: =over 4
5107:
5108: =item * &determinedomain()
1.60 matthew 5109:
5110: Inputs: $domain (usually will be undef)
5111:
1.63 www 5112: Returns: Determines which domain should be used for designs
1.60 matthew 5113:
5114: =cut
1.54 www 5115:
1.60 matthew 5116: ###############################################
1.63 www 5117: sub determinedomain {
5118: my $domain=shift;
1.531 albertel 5119: if (! $domain) {
1.60 matthew 5120: # Determine domain if we have not been given one
1.893 raeburn 5121: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5122: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5123: if ($env{'request.role.domain'}) {
5124: $domain=$env{'request.role.domain'};
1.60 matthew 5125: }
5126: }
1.63 www 5127: return $domain;
5128: }
5129: ###############################################
1.517 raeburn 5130:
1.518 albertel 5131: sub devalidate_domconfig_cache {
5132: my ($udom)=@_;
5133: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5134: }
5135:
5136: # ---------------------- Get domain configuration for a domain
5137: sub get_domainconf {
5138: my ($udom) = @_;
5139: my $cachetime=1800;
5140: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5141: if (defined($cached)) { return %{$result}; }
5142:
5143: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5144: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5145: my (%designhash,%legacy);
1.518 albertel 5146: if (keys(%domconfig) > 0) {
5147: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5148: if (keys(%{$domconfig{'login'}})) {
5149: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5150: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 5151: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5152: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5153: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5154: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5155: if ($key eq 'loginvia') {
5156: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5157: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5158: $designhash{$udom.'.login.loginvia'} = $server;
5159: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5160: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5161: } else {
5162: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5163: }
1.948 raeburn 5164: }
1.1075.2.87 raeburn 5165: } elsif ($key eq 'headtag') {
5166: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5167: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5168: }
1.946 raeburn 5169: }
1.1075.2.87 raeburn 5170: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5171: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5172: }
1.946 raeburn 5173: }
5174: }
5175: }
5176: } else {
5177: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5178: $designhash{$udom.'.login.'.$key.'_'.$img} =
5179: $domconfig{'login'}{$key}{$img};
5180: }
1.699 raeburn 5181: }
5182: } else {
5183: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5184: }
1.632 raeburn 5185: }
5186: } else {
5187: $legacy{'login'} = 1;
1.518 albertel 5188: }
1.632 raeburn 5189: } else {
5190: $legacy{'login'} = 1;
1.518 albertel 5191: }
5192: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5193: if (keys(%{$domconfig{'rolecolors'}})) {
5194: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5195: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5196: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5197: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5198: }
1.518 albertel 5199: }
5200: }
1.632 raeburn 5201: } else {
5202: $legacy{'rolecolors'} = 1;
1.518 albertel 5203: }
1.632 raeburn 5204: } else {
5205: $legacy{'rolecolors'} = 1;
1.518 albertel 5206: }
1.948 raeburn 5207: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5208: if ($domconfig{'autoenroll'}{'co-owners'}) {
5209: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5210: }
5211: }
1.632 raeburn 5212: if (keys(%legacy) > 0) {
5213: my %legacyhash = &get_legacy_domconf($udom);
5214: foreach my $item (keys(%legacyhash)) {
5215: if ($item =~ /^\Q$udom\E\.login/) {
5216: if ($legacy{'login'}) {
5217: $designhash{$item} = $legacyhash{$item};
5218: }
5219: } else {
5220: if ($legacy{'rolecolors'}) {
5221: $designhash{$item} = $legacyhash{$item};
5222: }
1.518 albertel 5223: }
5224: }
5225: }
1.632 raeburn 5226: } else {
5227: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5228: }
5229: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5230: $cachetime);
5231: return %designhash;
5232: }
5233:
1.632 raeburn 5234: sub get_legacy_domconf {
5235: my ($udom) = @_;
5236: my %legacyhash;
5237: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5238: my $designfile = $designdir.'/'.$udom.'.tab';
5239: if (-e $designfile) {
1.1075.2.128 raeburn 5240: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5241: while (my $line = <$fh>) {
5242: next if ($line =~ /^\#/);
5243: chomp($line);
5244: my ($key,$val)=(split(/\=/,$line));
5245: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5246: }
5247: close($fh);
5248: }
5249: }
1.1026 raeburn 5250: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5251: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5252: }
5253: return %legacyhash;
5254: }
5255:
1.63 www 5256: =pod
5257:
1.112 bowersj2 5258: =item * &domainlogo()
1.63 www 5259:
5260: Inputs: $domain (usually will be undef)
5261:
5262: Returns: A link to a domain logo, if the domain logo exists.
5263: If the domain logo does not exist, a description of the domain.
5264:
5265: =cut
1.112 bowersj2 5266:
1.63 www 5267: ###############################################
5268: sub domainlogo {
1.517 raeburn 5269: my $domain = &determinedomain(shift);
1.518 albertel 5270: my %designhash = &get_domainconf($domain);
1.517 raeburn 5271: # See if there is a logo
5272: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5273: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5274: if ($imgsrc =~ m{^/(adm|res)/}) {
5275: if ($imgsrc =~ m{^/res/}) {
5276: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5277: &Apache::lonnet::repcopy($local_name);
5278: }
5279: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5280: }
5281: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5282: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5283: return &Apache::lonnet::domain($domain,'description');
1.59 www 5284: } else {
1.60 matthew 5285: return '';
1.59 www 5286: }
5287: }
1.63 www 5288: ##############################################
5289:
5290: =pod
5291:
1.112 bowersj2 5292: =item * &designparm()
1.63 www 5293:
5294: Inputs: $which parameter; $domain (usually will be undef)
5295:
5296: Returns: value of designparamter $which
5297:
5298: =cut
1.112 bowersj2 5299:
1.397 albertel 5300:
1.400 albertel 5301: ##############################################
1.397 albertel 5302: sub designparm {
5303: my ($which,$domain)=@_;
5304: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5305: return $env{'environment.color.'.$which};
1.96 www 5306: }
1.63 www 5307: $domain=&determinedomain($domain);
1.1016 raeburn 5308: my %domdesign;
5309: unless ($domain eq 'public') {
5310: %domdesign = &get_domainconf($domain);
5311: }
1.520 raeburn 5312: my $output;
1.517 raeburn 5313: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5314: $output = $domdesign{$domain.'.'.$which};
1.63 www 5315: } else {
1.520 raeburn 5316: $output = $defaultdesign{$which};
5317: }
5318: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5319: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5320: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5321: if ($output =~ m{^/res/}) {
5322: my $local_name = &Apache::lonnet::filelocation('',$output);
5323: &Apache::lonnet::repcopy($local_name);
5324: }
1.520 raeburn 5325: $output = &lonhttpdurl($output);
5326: }
1.63 www 5327: }
1.520 raeburn 5328: return $output;
1.63 www 5329: }
1.59 www 5330:
1.822 bisitz 5331: ##############################################
5332: =pod
5333:
1.832 bisitz 5334: =item * &authorspace()
5335:
1.1028 raeburn 5336: Inputs: $url (usually will be undef).
1.832 bisitz 5337:
1.1075.2.40 raeburn 5338: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5339: directory being viewed (or for which action is being taken).
5340: If $url is provided, and begins /priv/<domain>/<uname>
5341: the path will be that portion of the $context argument.
5342: Otherwise the path will be for the author space of the current
5343: user when the current role is author, or for that of the
5344: co-author/assistant co-author space when the current role
5345: is co-author or assistant co-author.
1.832 bisitz 5346:
5347: =cut
5348:
5349: sub authorspace {
1.1028 raeburn 5350: my ($url) = @_;
5351: if ($url ne '') {
5352: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5353: return $1;
5354: }
5355: }
1.832 bisitz 5356: my $caname = '';
1.1024 www 5357: my $cadom = '';
1.1028 raeburn 5358: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5359: ($cadom,$caname) =
1.832 bisitz 5360: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5361: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5362: $caname = $env{'user.name'};
1.1024 www 5363: $cadom = $env{'user.domain'};
1.832 bisitz 5364: }
1.1028 raeburn 5365: if (($caname ne '') && ($cadom ne '')) {
5366: return "/priv/$cadom/$caname/";
5367: }
5368: return;
1.832 bisitz 5369: }
5370:
5371: ##############################################
5372: =pod
5373:
1.822 bisitz 5374: =item * &head_subbox()
5375:
5376: Inputs: $content (contains HTML code with page functions, etc.)
5377:
5378: Returns: HTML div with $content
5379: To be included in page header
5380:
5381: =cut
5382:
5383: sub head_subbox {
5384: my ($content)=@_;
5385: my $output =
1.993 raeburn 5386: '<div class="LC_head_subbox">'
1.822 bisitz 5387: .$content
5388: .'</div>'
5389: }
5390:
5391: ##############################################
5392: =pod
5393:
5394: =item * &CSTR_pageheader()
5395:
1.1026 raeburn 5396: Input: (optional) filename from which breadcrumb trail is built.
5397: In most cases no input as needed, as $env{'request.filename'}
5398: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5399:
5400: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5401: To be included on Authoring Space pages
1.822 bisitz 5402:
5403: =cut
5404:
5405: sub CSTR_pageheader {
1.1026 raeburn 5406: my ($trailfile) = @_;
5407: if ($trailfile eq '') {
5408: $trailfile = $env{'request.filename'};
5409: }
5410:
5411: # this is for resources; directories have customtitle, and crumbs
5412: # and select recent are created in lonpubdir.pm
5413:
5414: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5415: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5416: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5417: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5418: $formaction =~ s{/+}{/}g;
1.822 bisitz 5419:
5420: my $parentpath = '';
5421: my $lastitem = '';
5422: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5423: $parentpath = $1;
5424: $lastitem = $2;
5425: } else {
5426: $lastitem = $thisdisfn;
5427: }
1.921 bisitz 5428:
5429: my $output =
1.822 bisitz 5430: '<div>'
5431: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5432: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5433: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5434: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5435: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5436:
5437: if ($lastitem) {
5438: $output .=
5439: '<span class="LC_filename">'
5440: .$lastitem
5441: .'</span>';
5442: }
5443: $output .=
5444: '<br />'
1.822 bisitz 5445: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5446: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5447: .'</form>'
5448: .&Apache::lonmenu::constspaceform()
5449: .'</div>';
1.921 bisitz 5450:
5451: return $output;
1.822 bisitz 5452: }
5453:
1.60 matthew 5454: ###############################################
5455: ###############################################
5456:
5457: =pod
5458:
1.112 bowersj2 5459: =back
5460:
1.549 albertel 5461: =head1 HTML Helpers
1.112 bowersj2 5462:
5463: =over 4
5464:
5465: =item * &bodytag()
1.60 matthew 5466:
5467: Returns a uniform header for LON-CAPA web pages.
5468:
5469: Inputs:
5470:
1.112 bowersj2 5471: =over 4
5472:
5473: =item * $title, A title to be displayed on the page.
5474:
5475: =item * $function, the current role (can be undef).
5476:
5477: =item * $addentries, extra parameters for the <body> tag.
5478:
5479: =item * $bodyonly, if defined, only return the <body> tag.
5480:
5481: =item * $domain, if defined, force a given domain.
5482:
5483: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5484: text interface only)
1.60 matthew 5485:
1.814 bisitz 5486: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5487: navigational links
1.317 albertel 5488:
1.338 albertel 5489: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5490:
1.1075.2.12 raeburn 5491: =item * $no_inline_link, if true and in remote mode, don't show the
5492: 'Switch To Inline Menu' link
5493:
1.460 albertel 5494: =item * $args, optional argument valid values are
5495: no_auto_mt_title -> prevents &mt()ing the title arg
1.1075.2.133 raeburn 5496: use_absolute -> for external resource or syllabus, this will
5497: contain https://<hostname> if server uses
5498: https (as per hosts.tab), but request is for http
5499: hostname -> hostname, from $r->hostname().
1.460 albertel 5500:
1.1075.2.15 raeburn 5501: =item * $advtoolsref, optional argument, ref to an array containing
5502: inlineremote items to be added in "Functions" menu below
5503: breadcrumbs.
5504:
1.112 bowersj2 5505: =back
5506:
1.60 matthew 5507: Returns: A uniform header for LON-CAPA web pages.
5508: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5509: If $bodyonly is undef or zero, an html string containing a <body> tag and
5510: other decorations will be returned.
5511:
5512: =cut
5513:
1.54 www 5514: sub bodytag {
1.831 bisitz 5515: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5516: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5517:
1.954 raeburn 5518: my $public;
5519: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5520: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5521: $public = 1;
5522: }
1.460 albertel 5523: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5524: my $httphost = $args->{'use_absolute'};
1.1075.2.133 raeburn 5525: my $hostname = $args->{'hostname'};
1.339 albertel 5526:
1.183 matthew 5527: $function = &get_users_function() if (!$function);
1.339 albertel 5528: my $img = &designparm($function.'.img',$domain);
5529: my $font = &designparm($function.'.font',$domain);
5530: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5531:
1.803 bisitz 5532: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5533: 'bgcolor' => $pgbg,
1.339 albertel 5534: 'text' => $font,
5535: 'alink' => &designparm($function.'.alink',$domain),
5536: 'vlink' => &designparm($function.'.vlink',$domain),
5537: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5538: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5539:
1.63 www 5540: # role and realm
1.1075.2.68 raeburn 5541: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5542: if ($realm) {
5543: $realm = '/'.$realm;
5544: }
1.378 raeburn 5545: if ($role eq 'ca') {
1.479 albertel 5546: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5547: $realm = &plainname($rname,$rdom);
1.378 raeburn 5548: }
1.55 www 5549: # realm
1.258 albertel 5550: if ($env{'request.course.id'}) {
1.378 raeburn 5551: if ($env{'request.role'} !~ /^cr/) {
5552: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1075.2.115 raeburn 5553: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1075.2.121 raeburn 5554: if ($env{'request.role.desc'}) {
5555: $role = $env{'request.role.desc'};
5556: } else {
5557: $role = &mt('Helpdesk[_1]',' '.$2);
5558: }
1.1075.2.115 raeburn 5559: } else {
5560: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5561: }
1.898 raeburn 5562: if ($env{'request.course.sec'}) {
5563: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5564: }
1.359 albertel 5565: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5566: } else {
5567: $role = &Apache::lonnet::plaintext($role);
1.54 www 5568: }
1.433 albertel 5569:
1.359 albertel 5570: if (!$realm) { $realm=' '; }
1.330 albertel 5571:
1.438 albertel 5572: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5573:
1.101 www 5574: # construct main body tag
1.359 albertel 5575: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 5576: &Apache::lontexconvert::init_math_support();
1.252 albertel 5577:
1.1075.2.38 raeburn 5578: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5579:
5580: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5581: return $bodytag;
1.1075.2.38 raeburn 5582: }
1.359 albertel 5583:
1.954 raeburn 5584: if ($public) {
1.433 albertel 5585: undef($role);
5586: }
1.359 albertel 5587:
1.762 bisitz 5588: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5589: #
5590: # Extra info if you are the DC
5591: my $dc_info = '';
5592: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5593: $env{'course.'.$env{'request.course.id'}.
5594: '.domain'}.'/'})) {
5595: my $cid = $env{'request.course.id'};
1.917 raeburn 5596: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5597: $dc_info =~ s/\s+$//;
1.359 albertel 5598: }
5599:
1.1075.2.108 raeburn 5600: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903 droeschl 5601:
1.1075.2.13 raeburn 5602: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5603:
1.1075.2.38 raeburn 5604:
5605:
1.1075.2.21 raeburn 5606: my $funclist;
5607: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5608: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5609: Apache::lonmenu::serverform();
5610: my $forbodytag;
5611: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5612: $forcereg,$args->{'group'},
5613: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5614: $advtoolsref,'','',\$forbodytag);
1.1075.2.21 raeburn 5615: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5616: $funclist = $forbodytag;
5617: }
5618: } else {
1.903 droeschl 5619:
5620: # if ($env{'request.state'} eq 'construct') {
5621: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5622: # }
5623:
1.1075.2.38 raeburn 5624: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5625: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5626:
1.1075.2.38 raeburn 5627: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5628:
1.916 droeschl 5629: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5630: if ($dc_info) {
5631: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5632: }
1.1075.2.38 raeburn 5633: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5634: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5635: return $bodytag;
5636: }
1.894 droeschl 5637:
1.927 raeburn 5638: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5639: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5640: }
1.916 droeschl 5641:
1.1075.2.38 raeburn 5642: $bodytag .= $right;
1.852 droeschl 5643:
1.917 raeburn 5644: if ($dc_info) {
5645: $dc_info = &dc_courseid_toggle($dc_info);
5646: }
5647: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5648:
1.1075.2.61 raeburn 5649: #if directed to not display the secondary menu, don't.
5650: if ($args->{'no_secondary_menu'}) {
5651: return $bodytag;
5652: }
1.903 droeschl 5653: #don't show menus for public users
1.954 raeburn 5654: if (!$public){
1.1075.2.52 raeburn 5655: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5656: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5657: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5658: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5659: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1075.2.133 raeburn 5660: $args->{'bread_crumbs'},'','',$hostname);
1.1075.2.116 raeburn 5661: } elsif ($forcereg) {
1.1075.2.22 raeburn 5662: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.116 raeburn 5663: $args->{'group'},
1.1075.2.133 raeburn 5664: $args->{'hide_buttons',
5665: $hostname});
1.1075.2.15 raeburn 5666: } else {
1.1075.2.21 raeburn 5667: my $forbodytag;
5668: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5669: $forcereg,$args->{'group'},
5670: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5671: $advtoolsref,'',$hostname,
5672: \$forbodytag);
1.1075.2.21 raeburn 5673: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5674: $bodytag .= $forbodytag;
5675: }
1.920 raeburn 5676: }
1.903 droeschl 5677: }else{
5678: # this is to seperate menu from content when there's no secondary
5679: # menu. Especially needed for public accessible ressources.
5680: $bodytag .= '<hr style="clear:both" />';
5681: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5682: }
1.903 droeschl 5683:
1.235 raeburn 5684: return $bodytag;
1.1075.2.12 raeburn 5685: }
5686:
5687: #
5688: # Top frame rendering, Remote is up
5689: #
5690:
5691: my $imgsrc = $img;
5692: if ($img =~ /^\/adm/) {
5693: $imgsrc = &lonhttpdurl($img);
5694: }
5695: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5696:
1.1075.2.60 raeburn 5697: my $help=($no_inline_link?''
5698: :&Apache::loncommon::top_nav_help('Help'));
5699:
1.1075.2.12 raeburn 5700: # Explicit link to get inline menu
5701: my $menu= ($no_inline_link?''
5702: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5703:
5704: if ($dc_info) {
5705: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5706: }
5707:
1.1075.2.38 raeburn 5708: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5709: unless ($public) {
5710: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5711: undef,'LC_menubuttons_link');
5712: }
5713:
1.1075.2.12 raeburn 5714: unless ($env{'form.inhibitmenu'}) {
5715: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5716: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5717: <li>$help</li>
1.1075.2.12 raeburn 5718: <li>$menu</li>
5719: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5720: }
1.1075.2.13 raeburn 5721: if ($env{'request.state'} eq 'construct') {
5722: if (!$public){
5723: if ($env{'request.state'} eq 'construct') {
5724: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5725: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5726: &Apache::lonhtmlcommon::scripttag('','end').
5727: &Apache::lonmenu::innerregister($forcereg,
5728: $args->{'bread_crumbs'});
5729: }
5730: }
5731: }
1.1075.2.21 raeburn 5732: return $bodytag."\n".$funclist;
1.182 matthew 5733: }
5734:
1.917 raeburn 5735: sub dc_courseid_toggle {
5736: my ($dc_info) = @_;
1.980 raeburn 5737: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5738: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5739: &mt('(More ...)').'</a></span>'.
5740: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5741: }
5742:
1.330 albertel 5743: sub make_attr_string {
5744: my ($register,$attr_ref) = @_;
5745:
5746: if ($attr_ref && !ref($attr_ref)) {
5747: die("addentries Must be a hash ref ".
5748: join(':',caller(1))." ".
5749: join(':',caller(0))." ");
5750: }
5751:
5752: if ($register) {
1.339 albertel 5753: my ($on_load,$on_unload);
5754: foreach my $key (keys(%{$attr_ref})) {
5755: if (lc($key) eq 'onload') {
5756: $on_load.=$attr_ref->{$key}.';';
5757: delete($attr_ref->{$key});
5758:
5759: } elsif (lc($key) eq 'onunload') {
5760: $on_unload.=$attr_ref->{$key}.';';
5761: delete($attr_ref->{$key});
5762: }
5763: }
1.1075.2.12 raeburn 5764: if ($env{'environment.remote'} eq 'on') {
5765: $attr_ref->{'onload'} =
5766: &Apache::lonmenu::loadevents(). $on_load;
5767: $attr_ref->{'onunload'}=
5768: &Apache::lonmenu::unloadevents().$on_unload;
5769: } else {
5770: $attr_ref->{'onload'} = $on_load;
5771: $attr_ref->{'onunload'}= $on_unload;
5772: }
1.330 albertel 5773: }
1.339 albertel 5774:
1.330 albertel 5775: my $attr_string;
1.1075.2.56 raeburn 5776: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5777: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5778: }
5779: return $attr_string;
5780: }
5781:
5782:
1.182 matthew 5783: ###############################################
1.251 albertel 5784: ###############################################
5785:
5786: =pod
5787:
5788: =item * &endbodytag()
5789:
5790: Returns a uniform footer for LON-CAPA web pages.
5791:
1.635 raeburn 5792: Inputs: 1 - optional reference to an args hash
5793: If in the hash, key for noredirectlink has a value which evaluates to true,
5794: a 'Continue' link is not displayed if the page contains an
5795: internal redirect in the <head></head> section,
5796: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5797:
5798: =cut
5799:
5800: sub endbodytag {
1.635 raeburn 5801: my ($args) = @_;
1.1075.2.6 raeburn 5802: my $endbodytag;
5803: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5804: $endbodytag='</body>';
5805: }
1.315 albertel 5806: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5807: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5808: $endbodytag=
5809: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5810: &mt('Continue').'</a>'.
5811: $endbodytag;
5812: }
1.315 albertel 5813: }
1.251 albertel 5814: return $endbodytag;
5815: }
5816:
1.352 albertel 5817: =pod
5818:
5819: =item * &standard_css()
5820:
5821: Returns a style sheet
5822:
5823: Inputs: (all optional)
5824: domain -> force to color decorate a page for a specific
5825: domain
5826: function -> force usage of a specific rolish color scheme
5827: bgcolor -> override the default page bgcolor
5828:
5829: =cut
5830:
1.343 albertel 5831: sub standard_css {
1.345 albertel 5832: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5833: $function = &get_users_function() if (!$function);
5834: my $img = &designparm($function.'.img', $domain);
5835: my $tabbg = &designparm($function.'.tabbg', $domain);
5836: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5837: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5838: #second colour for later usage
1.345 albertel 5839: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5840: my $pgbg_or_bgcolor =
5841: $bgcolor ||
1.352 albertel 5842: &designparm($function.'.pgbg', $domain);
1.382 albertel 5843: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5844: my $alink = &designparm($function.'.alink', $domain);
5845: my $vlink = &designparm($function.'.vlink', $domain);
5846: my $link = &designparm($function.'.link', $domain);
5847:
1.602 albertel 5848: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5849: my $mono = 'monospace';
1.850 bisitz 5850: my $data_table_head = $sidebg;
5851: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5852: my $data_table_dark = '#E0E0E0';
1.470 banghart 5853: my $data_table_darker = '#CCCCCC';
1.349 albertel 5854: my $data_table_highlight = '#FFFF00';
1.352 albertel 5855: my $mail_new = '#FFBB77';
5856: my $mail_new_hover = '#DD9955';
5857: my $mail_read = '#BBBB77';
5858: my $mail_read_hover = '#999944';
5859: my $mail_replied = '#AAAA88';
5860: my $mail_replied_hover = '#888855';
5861: my $mail_other = '#99BBBB';
5862: my $mail_other_hover = '#669999';
1.391 albertel 5863: my $table_header = '#DDDDDD';
1.489 raeburn 5864: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5865: my $lg_border_color = '#C8C8C8';
1.952 onken 5866: my $button_hover = '#BF2317';
1.392 albertel 5867:
1.608 albertel 5868: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5869: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5870: : '0 3px 0 4px';
1.448 albertel 5871:
1.523 albertel 5872:
1.343 albertel 5873: return <<END;
1.947 droeschl 5874:
5875: /* needed for iframe to allow 100% height in FF */
5876: body, html {
5877: margin: 0;
5878: padding: 0 0.5%;
5879: height: 99%; /* to avoid scrollbars */
5880: }
5881:
1.795 www 5882: body {
1.911 bisitz 5883: font-family: $sans;
5884: line-height:130%;
5885: font-size:0.83em;
5886: color:$font;
1.795 www 5887: }
5888:
1.959 onken 5889: a:focus,
5890: a:focus img {
1.795 www 5891: color: red;
5892: }
1.698 harmsja 5893:
1.911 bisitz 5894: form, .inline {
5895: display: inline;
1.795 www 5896: }
1.721 harmsja 5897:
1.795 www 5898: .LC_right {
1.911 bisitz 5899: text-align:right;
1.795 www 5900: }
5901:
5902: .LC_middle {
1.911 bisitz 5903: vertical-align:middle;
1.795 www 5904: }
1.721 harmsja 5905:
1.1075.2.38 raeburn 5906: .LC_floatleft {
5907: float: left;
5908: }
5909:
5910: .LC_floatright {
5911: float: right;
5912: }
5913:
1.911 bisitz 5914: .LC_400Box {
5915: width:400px;
5916: }
1.721 harmsja 5917:
1.947 droeschl 5918: .LC_iframecontainer {
5919: width: 98%;
5920: margin: 0;
5921: position: fixed;
5922: top: 8.5em;
5923: bottom: 0;
5924: }
5925:
5926: .LC_iframecontainer iframe{
5927: border: none;
5928: width: 100%;
5929: height: 100%;
5930: }
5931:
1.778 bisitz 5932: .LC_filename {
5933: font-family: $mono;
5934: white-space:pre;
1.921 bisitz 5935: font-size: 120%;
1.778 bisitz 5936: }
5937:
5938: .LC_fileicon {
5939: border: none;
5940: height: 1.3em;
5941: vertical-align: text-bottom;
5942: margin-right: 0.3em;
5943: text-decoration:none;
5944: }
5945:
1.1008 www 5946: .LC_setting {
5947: text-decoration:underline;
5948: }
5949:
1.350 albertel 5950: .LC_error {
5951: color: red;
5952: }
1.795 www 5953:
1.1075.2.15 raeburn 5954: .LC_warning {
5955: color: darkorange;
5956: }
5957:
1.457 albertel 5958: .LC_diff_removed {
1.733 bisitz 5959: color: red;
1.394 albertel 5960: }
1.532 albertel 5961:
5962: .LC_info,
1.457 albertel 5963: .LC_success,
5964: .LC_diff_added {
1.350 albertel 5965: color: green;
5966: }
1.795 www 5967:
1.802 bisitz 5968: div.LC_confirm_box {
5969: background-color: #FAFAFA;
5970: border: 1px solid $lg_border_color;
5971: margin-right: 0;
5972: padding: 5px;
5973: }
5974:
5975: div.LC_confirm_box .LC_error img,
5976: div.LC_confirm_box .LC_success img {
5977: vertical-align: middle;
5978: }
5979:
1.1075.2.108 raeburn 5980: .LC_maxwidth {
5981: max-width: 100%;
5982: height: auto;
5983: }
5984:
5985: .LC_textsize_mobile {
5986: \@media only screen and (max-device-width: 480px) {
5987: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
5988: }
5989: }
5990:
1.440 albertel 5991: .LC_icon {
1.771 droeschl 5992: border: none;
1.790 droeschl 5993: vertical-align: middle;
1.771 droeschl 5994: }
5995:
1.543 albertel 5996: .LC_docs_spacer {
5997: width: 25px;
5998: height: 1px;
1.771 droeschl 5999: border: none;
1.543 albertel 6000: }
1.346 albertel 6001:
1.532 albertel 6002: .LC_internal_info {
1.735 bisitz 6003: color: #999999;
1.532 albertel 6004: }
6005:
1.794 www 6006: .LC_discussion {
1.1050 www 6007: background: $data_table_dark;
1.911 bisitz 6008: border: 1px solid black;
6009: margin: 2px;
1.794 www 6010: }
6011:
6012: .LC_disc_action_left {
1.1050 www 6013: background: $sidebg;
1.911 bisitz 6014: text-align: left;
1.1050 www 6015: padding: 4px;
6016: margin: 2px;
1.794 www 6017: }
6018:
6019: .LC_disc_action_right {
1.1050 www 6020: background: $sidebg;
1.911 bisitz 6021: text-align: right;
1.1050 www 6022: padding: 4px;
6023: margin: 2px;
1.794 www 6024: }
6025:
6026: .LC_disc_new_item {
1.911 bisitz 6027: background: white;
6028: border: 2px solid red;
1.1050 www 6029: margin: 4px;
6030: padding: 4px;
1.794 www 6031: }
6032:
6033: .LC_disc_old_item {
1.911 bisitz 6034: background: white;
1.1050 www 6035: margin: 4px;
6036: padding: 4px;
1.794 www 6037: }
6038:
1.458 albertel 6039: table.LC_pastsubmission {
6040: border: 1px solid black;
6041: margin: 2px;
6042: }
6043:
1.924 bisitz 6044: table#LC_menubuttons {
1.345 albertel 6045: width: 100%;
6046: background: $pgbg;
1.392 albertel 6047: border: 2px;
1.402 albertel 6048: border-collapse: separate;
1.803 bisitz 6049: padding: 0;
1.345 albertel 6050: }
1.392 albertel 6051:
1.801 tempelho 6052: table#LC_title_bar a {
6053: color: $fontmenu;
6054: }
1.836 bisitz 6055:
1.807 droeschl 6056: table#LC_title_bar {
1.819 tempelho 6057: clear: both;
1.836 bisitz 6058: display: none;
1.807 droeschl 6059: }
6060:
1.795 www 6061: table#LC_title_bar,
1.933 droeschl 6062: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6063: table#LC_title_bar.LC_with_remote {
1.359 albertel 6064: width: 100%;
1.392 albertel 6065: border-color: $pgbg;
6066: border-style: solid;
6067: border-width: $border;
1.379 albertel 6068: background: $pgbg;
1.801 tempelho 6069: color: $fontmenu;
1.392 albertel 6070: border-collapse: collapse;
1.803 bisitz 6071: padding: 0;
1.819 tempelho 6072: margin: 0;
1.359 albertel 6073: }
1.795 www 6074:
1.933 droeschl 6075: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6076: margin: 0;
6077: padding: 0;
1.933 droeschl 6078: position: relative;
6079: list-style: none;
1.913 droeschl 6080: }
1.933 droeschl 6081: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6082: display: inline;
6083: }
1.933 droeschl 6084:
6085: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6086: padding: 0;
1.933 droeschl 6087: margin: 0;
6088: float: left;
1.913 droeschl 6089: }
1.933 droeschl 6090: .LC_breadcrumb_tools_tools {
6091: padding: 0;
6092: margin: 0;
1.913 droeschl 6093: float: right;
6094: }
6095:
1.359 albertel 6096: table#LC_title_bar td {
6097: background: $tabbg;
6098: }
1.795 www 6099:
1.911 bisitz 6100: table#LC_menubuttons img {
1.803 bisitz 6101: border: none;
1.346 albertel 6102: }
1.795 www 6103:
1.842 droeschl 6104: .LC_breadcrumbs_component {
1.911 bisitz 6105: float: right;
6106: margin: 0 1em;
1.357 albertel 6107: }
1.842 droeschl 6108: .LC_breadcrumbs_component img {
1.911 bisitz 6109: vertical-align: middle;
1.777 tempelho 6110: }
1.795 www 6111:
1.1075.2.108 raeburn 6112: .LC_breadcrumbs_hoverable {
6113: background: $sidebg;
6114: }
6115:
1.383 albertel 6116: td.LC_table_cell_checkbox {
6117: text-align: center;
6118: }
1.795 www 6119:
6120: .LC_fontsize_small {
1.911 bisitz 6121: font-size: 70%;
1.705 tempelho 6122: }
6123:
1.844 bisitz 6124: #LC_breadcrumbs {
1.911 bisitz 6125: clear:both;
6126: background: $sidebg;
6127: border-bottom: 1px solid $lg_border_color;
6128: line-height: 2.5em;
1.933 droeschl 6129: overflow: hidden;
1.911 bisitz 6130: margin: 0;
6131: padding: 0;
1.995 raeburn 6132: text-align: left;
1.819 tempelho 6133: }
1.862 bisitz 6134:
1.1075.2.16 raeburn 6135: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6136: clear:both;
6137: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6138: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6139: margin: 0 0 10px 0;
1.966 bisitz 6140: padding: 3px;
1.995 raeburn 6141: text-align: left;
1.822 bisitz 6142: }
6143:
1.795 www 6144: .LC_fontsize_medium {
1.911 bisitz 6145: font-size: 85%;
1.705 tempelho 6146: }
6147:
1.795 www 6148: .LC_fontsize_large {
1.911 bisitz 6149: font-size: 120%;
1.705 tempelho 6150: }
6151:
1.346 albertel 6152: .LC_menubuttons_inline_text {
6153: color: $font;
1.698 harmsja 6154: font-size: 90%;
1.701 harmsja 6155: padding-left:3px;
1.346 albertel 6156: }
6157:
1.934 droeschl 6158: .LC_menubuttons_inline_text img{
6159: vertical-align: middle;
6160: }
6161:
1.1051 www 6162: li.LC_menubuttons_inline_text img {
1.951 onken 6163: cursor:pointer;
1.1002 droeschl 6164: text-decoration: none;
1.951 onken 6165: }
6166:
1.526 www 6167: .LC_menubuttons_link {
6168: text-decoration: none;
6169: }
1.795 www 6170:
1.522 albertel 6171: .LC_menubuttons_category {
1.521 www 6172: color: $font;
1.526 www 6173: background: $pgbg;
1.521 www 6174: font-size: larger;
6175: font-weight: bold;
6176: }
6177:
1.346 albertel 6178: td.LC_menubuttons_text {
1.911 bisitz 6179: color: $font;
1.346 albertel 6180: }
1.706 harmsja 6181:
1.346 albertel 6182: .LC_current_location {
6183: background: $tabbg;
6184: }
1.795 www 6185:
1.1075.2.134 raeburn 6186: td.LC_zero_height {
6187: line-height: 0;
6188: cellpadding: 0;
6189: }
6190:
1.938 bisitz 6191: table.LC_data_table {
1.347 albertel 6192: border: 1px solid #000000;
1.402 albertel 6193: border-collapse: separate;
1.426 albertel 6194: border-spacing: 1px;
1.610 albertel 6195: background: $pgbg;
1.347 albertel 6196: }
1.795 www 6197:
1.422 albertel 6198: .LC_data_table_dense {
6199: font-size: small;
6200: }
1.795 www 6201:
1.507 raeburn 6202: table.LC_nested_outer {
6203: border: 1px solid #000000;
1.589 raeburn 6204: border-collapse: collapse;
1.803 bisitz 6205: border-spacing: 0;
1.507 raeburn 6206: width: 100%;
6207: }
1.795 www 6208:
1.879 raeburn 6209: table.LC_innerpickbox,
1.507 raeburn 6210: table.LC_nested {
1.803 bisitz 6211: border: none;
1.589 raeburn 6212: border-collapse: collapse;
1.803 bisitz 6213: border-spacing: 0;
1.507 raeburn 6214: width: 100%;
6215: }
1.795 www 6216:
1.911 bisitz 6217: table.LC_data_table tr th,
6218: table.LC_calendar tr th,
1.879 raeburn 6219: table.LC_prior_tries tr th,
6220: table.LC_innerpickbox tr th {
1.349 albertel 6221: font-weight: bold;
6222: background-color: $data_table_head;
1.801 tempelho 6223: color:$fontmenu;
1.701 harmsja 6224: font-size:90%;
1.347 albertel 6225: }
1.795 www 6226:
1.879 raeburn 6227: table.LC_innerpickbox tr th,
6228: table.LC_innerpickbox tr td {
6229: vertical-align: top;
6230: }
6231:
1.711 raeburn 6232: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6233: background-color: #CCCCCC;
1.711 raeburn 6234: font-weight: bold;
6235: text-align: left;
6236: }
1.795 www 6237:
1.912 bisitz 6238: table.LC_data_table tr.LC_odd_row > td {
6239: background-color: $data_table_light;
6240: padding: 2px;
6241: vertical-align: top;
6242: }
6243:
1.809 bisitz 6244: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6245: background-color: $data_table_light;
1.912 bisitz 6246: vertical-align: top;
6247: }
6248:
6249: table.LC_data_table tr.LC_even_row > td {
6250: background-color: $data_table_dark;
1.425 albertel 6251: padding: 2px;
1.900 bisitz 6252: vertical-align: top;
1.347 albertel 6253: }
1.795 www 6254:
1.809 bisitz 6255: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6256: background-color: $data_table_dark;
1.900 bisitz 6257: vertical-align: top;
1.347 albertel 6258: }
1.795 www 6259:
1.425 albertel 6260: table.LC_data_table tr.LC_data_table_highlight td {
6261: background-color: $data_table_darker;
6262: }
1.795 www 6263:
1.639 raeburn 6264: table.LC_data_table tr td.LC_leftcol_header {
6265: background-color: $data_table_head;
6266: font-weight: bold;
6267: }
1.795 www 6268:
1.451 albertel 6269: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6270: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6271: font-weight: bold;
6272: font-style: italic;
6273: text-align: center;
6274: padding: 8px;
1.347 albertel 6275: }
1.795 www 6276:
1.1075.2.30 raeburn 6277: table.LC_data_table tr.LC_empty_row td,
6278: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6279: background-color: $sidebg;
6280: }
6281:
6282: table.LC_nested tr.LC_empty_row td {
6283: background-color: #FFFFFF;
6284: }
6285:
1.890 droeschl 6286: table.LC_caption {
6287: }
6288:
1.507 raeburn 6289: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6290: padding: 4ex
6291: }
1.795 www 6292:
1.507 raeburn 6293: table.LC_nested_outer tr th {
6294: font-weight: bold;
1.801 tempelho 6295: color:$fontmenu;
1.507 raeburn 6296: background-color: $data_table_head;
1.701 harmsja 6297: font-size: small;
1.507 raeburn 6298: border-bottom: 1px solid #000000;
6299: }
1.795 www 6300:
1.507 raeburn 6301: table.LC_nested_outer tr td.LC_subheader {
6302: background-color: $data_table_head;
6303: font-weight: bold;
6304: font-size: small;
6305: border-bottom: 1px solid #000000;
6306: text-align: right;
1.451 albertel 6307: }
1.795 www 6308:
1.507 raeburn 6309: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6310: background-color: #CCCCCC;
1.451 albertel 6311: font-weight: bold;
6312: font-size: small;
1.507 raeburn 6313: text-align: center;
6314: }
1.795 www 6315:
1.589 raeburn 6316: table.LC_nested tr.LC_info_row td.LC_left_item,
6317: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6318: text-align: left;
1.451 albertel 6319: }
1.795 www 6320:
1.507 raeburn 6321: table.LC_nested td {
1.735 bisitz 6322: background-color: #FFFFFF;
1.451 albertel 6323: font-size: small;
1.507 raeburn 6324: }
1.795 www 6325:
1.507 raeburn 6326: table.LC_nested_outer tr th.LC_right_item,
6327: table.LC_nested tr.LC_info_row td.LC_right_item,
6328: table.LC_nested tr.LC_odd_row td.LC_right_item,
6329: table.LC_nested tr td.LC_right_item {
1.451 albertel 6330: text-align: right;
6331: }
6332:
1.507 raeburn 6333: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6334: background-color: #EEEEEE;
1.451 albertel 6335: }
6336:
1.473 raeburn 6337: table.LC_createuser {
6338: }
6339:
6340: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6341: font-size: small;
1.473 raeburn 6342: }
6343:
6344: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6345: background-color: #CCCCCC;
1.473 raeburn 6346: font-weight: bold;
6347: text-align: center;
6348: }
6349:
1.349 albertel 6350: table.LC_calendar {
6351: border: 1px solid #000000;
6352: border-collapse: collapse;
1.917 raeburn 6353: width: 98%;
1.349 albertel 6354: }
1.795 www 6355:
1.349 albertel 6356: table.LC_calendar_pickdate {
6357: font-size: xx-small;
6358: }
1.795 www 6359:
1.349 albertel 6360: table.LC_calendar tr td {
6361: border: 1px solid #000000;
6362: vertical-align: top;
1.917 raeburn 6363: width: 14%;
1.349 albertel 6364: }
1.795 www 6365:
1.349 albertel 6366: table.LC_calendar tr td.LC_calendar_day_empty {
6367: background-color: $data_table_dark;
6368: }
1.795 www 6369:
1.779 bisitz 6370: table.LC_calendar tr td.LC_calendar_day_current {
6371: background-color: $data_table_highlight;
1.777 tempelho 6372: }
1.795 www 6373:
1.938 bisitz 6374: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6375: background-color: $mail_new;
6376: }
1.795 www 6377:
1.938 bisitz 6378: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6379: background-color: $mail_new_hover;
6380: }
1.795 www 6381:
1.938 bisitz 6382: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6383: background-color: $mail_read;
6384: }
1.795 www 6385:
1.938 bisitz 6386: /*
6387: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6388: background-color: $mail_read_hover;
6389: }
1.938 bisitz 6390: */
1.795 www 6391:
1.938 bisitz 6392: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6393: background-color: $mail_replied;
6394: }
1.795 www 6395:
1.938 bisitz 6396: /*
6397: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6398: background-color: $mail_replied_hover;
6399: }
1.938 bisitz 6400: */
1.795 www 6401:
1.938 bisitz 6402: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6403: background-color: $mail_other;
6404: }
1.795 www 6405:
1.938 bisitz 6406: /*
6407: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6408: background-color: $mail_other_hover;
6409: }
1.938 bisitz 6410: */
1.494 raeburn 6411:
1.777 tempelho 6412: table.LC_data_table tr > td.LC_browser_file,
6413: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6414: background: #AAEE77;
1.389 albertel 6415: }
1.795 www 6416:
1.777 tempelho 6417: table.LC_data_table tr > td.LC_browser_file_locked,
6418: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6419: background: #FFAA99;
1.387 albertel 6420: }
1.795 www 6421:
1.777 tempelho 6422: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6423: background: #888888;
1.779 bisitz 6424: }
1.795 www 6425:
1.777 tempelho 6426: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6427: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6428: background: #F8F866;
1.777 tempelho 6429: }
1.795 www 6430:
1.696 bisitz 6431: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6432: background: #E0E8FF;
1.387 albertel 6433: }
1.696 bisitz 6434:
1.707 bisitz 6435: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6436: /* background: #77FF77; */
1.707 bisitz 6437: }
1.795 www 6438:
1.707 bisitz 6439: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6440: border-right: 8px solid #FFFF77;
1.707 bisitz 6441: }
1.795 www 6442:
1.707 bisitz 6443: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6444: border-right: 8px solid #FFAA77;
1.707 bisitz 6445: }
1.795 www 6446:
1.707 bisitz 6447: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6448: border-right: 8px solid #FF7777;
1.707 bisitz 6449: }
1.795 www 6450:
1.707 bisitz 6451: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6452: border-right: 8px solid #AAFF77;
1.707 bisitz 6453: }
1.795 www 6454:
1.707 bisitz 6455: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6456: border-right: 8px solid #11CC55;
1.707 bisitz 6457: }
6458:
1.388 albertel 6459: span.LC_current_location {
1.701 harmsja 6460: font-size:larger;
1.388 albertel 6461: background: $pgbg;
6462: }
1.387 albertel 6463:
1.1029 www 6464: span.LC_current_nav_location {
6465: font-weight:bold;
6466: background: $sidebg;
6467: }
6468:
1.395 albertel 6469: span.LC_parm_menu_item {
6470: font-size: larger;
6471: }
1.795 www 6472:
1.395 albertel 6473: span.LC_parm_scope_all {
6474: color: red;
6475: }
1.795 www 6476:
1.395 albertel 6477: span.LC_parm_scope_folder {
6478: color: green;
6479: }
1.795 www 6480:
1.395 albertel 6481: span.LC_parm_scope_resource {
6482: color: orange;
6483: }
1.795 www 6484:
1.395 albertel 6485: span.LC_parm_part {
6486: color: blue;
6487: }
1.795 www 6488:
1.911 bisitz 6489: span.LC_parm_folder,
6490: span.LC_parm_symb {
1.395 albertel 6491: font-size: x-small;
6492: font-family: $mono;
6493: color: #AAAAAA;
6494: }
6495:
1.977 bisitz 6496: ul.LC_parm_parmlist li {
6497: display: inline-block;
6498: padding: 0.3em 0.8em;
6499: vertical-align: top;
6500: width: 150px;
6501: border-top:1px solid $lg_border_color;
6502: }
6503:
1.795 www 6504: td.LC_parm_overview_level_menu,
6505: td.LC_parm_overview_map_menu,
6506: td.LC_parm_overview_parm_selectors,
6507: td.LC_parm_overview_restrictions {
1.396 albertel 6508: border: 1px solid black;
6509: border-collapse: collapse;
6510: }
1.795 www 6511:
1.396 albertel 6512: table.LC_parm_overview_restrictions td {
6513: border-width: 1px 4px 1px 4px;
6514: border-style: solid;
6515: border-color: $pgbg;
6516: text-align: center;
6517: }
1.795 www 6518:
1.396 albertel 6519: table.LC_parm_overview_restrictions th {
6520: background: $tabbg;
6521: border-width: 1px 4px 1px 4px;
6522: border-style: solid;
6523: border-color: $pgbg;
6524: }
1.795 www 6525:
1.398 albertel 6526: table#LC_helpmenu {
1.803 bisitz 6527: border: none;
1.398 albertel 6528: height: 55px;
1.803 bisitz 6529: border-spacing: 0;
1.398 albertel 6530: }
6531:
6532: table#LC_helpmenu fieldset legend {
6533: font-size: larger;
6534: }
1.795 www 6535:
1.397 albertel 6536: table#LC_helpmenu_links {
6537: width: 100%;
6538: border: 1px solid black;
6539: background: $pgbg;
1.803 bisitz 6540: padding: 0;
1.397 albertel 6541: border-spacing: 1px;
6542: }
1.795 www 6543:
1.397 albertel 6544: table#LC_helpmenu_links tr td {
6545: padding: 1px;
6546: background: $tabbg;
1.399 albertel 6547: text-align: center;
6548: font-weight: bold;
1.397 albertel 6549: }
1.396 albertel 6550:
1.795 www 6551: table#LC_helpmenu_links a:link,
6552: table#LC_helpmenu_links a:visited,
1.397 albertel 6553: table#LC_helpmenu_links a:active {
6554: text-decoration: none;
6555: color: $font;
6556: }
1.795 www 6557:
1.397 albertel 6558: table#LC_helpmenu_links a:hover {
6559: text-decoration: underline;
6560: color: $vlink;
6561: }
1.396 albertel 6562:
1.417 albertel 6563: .LC_chrt_popup_exists {
6564: border: 1px solid #339933;
6565: margin: -1px;
6566: }
1.795 www 6567:
1.417 albertel 6568: .LC_chrt_popup_up {
6569: border: 1px solid yellow;
6570: margin: -1px;
6571: }
1.795 www 6572:
1.417 albertel 6573: .LC_chrt_popup {
6574: border: 1px solid #8888FF;
6575: background: #CCCCFF;
6576: }
1.795 www 6577:
1.421 albertel 6578: table.LC_pick_box {
6579: border-collapse: separate;
6580: background: white;
6581: border: 1px solid black;
6582: border-spacing: 1px;
6583: }
1.795 www 6584:
1.421 albertel 6585: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6586: background: $sidebg;
1.421 albertel 6587: font-weight: bold;
1.900 bisitz 6588: text-align: left;
1.740 bisitz 6589: vertical-align: top;
1.421 albertel 6590: width: 184px;
6591: padding: 8px;
6592: }
1.795 www 6593:
1.579 raeburn 6594: table.LC_pick_box td.LC_pick_box_value {
6595: text-align: left;
6596: padding: 8px;
6597: }
1.795 www 6598:
1.579 raeburn 6599: table.LC_pick_box td.LC_pick_box_select {
6600: text-align: left;
6601: padding: 8px;
6602: }
1.795 www 6603:
1.424 albertel 6604: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6605: padding: 0;
1.421 albertel 6606: height: 1px;
6607: background: black;
6608: }
1.795 www 6609:
1.421 albertel 6610: table.LC_pick_box td.LC_pick_box_submit {
6611: text-align: right;
6612: }
1.795 www 6613:
1.579 raeburn 6614: table.LC_pick_box td.LC_evenrow_value {
6615: text-align: left;
6616: padding: 8px;
6617: background-color: $data_table_light;
6618: }
1.795 www 6619:
1.579 raeburn 6620: table.LC_pick_box td.LC_oddrow_value {
6621: text-align: left;
6622: padding: 8px;
6623: background-color: $data_table_light;
6624: }
1.795 www 6625:
1.579 raeburn 6626: span.LC_helpform_receipt_cat {
6627: font-weight: bold;
6628: }
1.795 www 6629:
1.424 albertel 6630: table.LC_group_priv_box {
6631: background: white;
6632: border: 1px solid black;
6633: border-spacing: 1px;
6634: }
1.795 www 6635:
1.424 albertel 6636: table.LC_group_priv_box td.LC_pick_box_title {
6637: background: $tabbg;
6638: font-weight: bold;
6639: text-align: right;
6640: width: 184px;
6641: }
1.795 www 6642:
1.424 albertel 6643: table.LC_group_priv_box td.LC_groups_fixed {
6644: background: $data_table_light;
6645: text-align: center;
6646: }
1.795 www 6647:
1.424 albertel 6648: table.LC_group_priv_box td.LC_groups_optional {
6649: background: $data_table_dark;
6650: text-align: center;
6651: }
1.795 www 6652:
1.424 albertel 6653: table.LC_group_priv_box td.LC_groups_functionality {
6654: background: $data_table_darker;
6655: text-align: center;
6656: font-weight: bold;
6657: }
1.795 www 6658:
1.424 albertel 6659: table.LC_group_priv td {
6660: text-align: left;
1.803 bisitz 6661: padding: 0;
1.424 albertel 6662: }
6663:
6664: .LC_navbuttons {
6665: margin: 2ex 0ex 2ex 0ex;
6666: }
1.795 www 6667:
1.423 albertel 6668: .LC_topic_bar {
6669: font-weight: bold;
6670: background: $tabbg;
1.918 wenzelju 6671: margin: 1em 0em 1em 2em;
1.805 bisitz 6672: padding: 3px;
1.918 wenzelju 6673: font-size: 1.2em;
1.423 albertel 6674: }
1.795 www 6675:
1.423 albertel 6676: .LC_topic_bar span {
1.918 wenzelju 6677: left: 0.5em;
6678: position: absolute;
1.423 albertel 6679: vertical-align: middle;
1.918 wenzelju 6680: font-size: 1.2em;
1.423 albertel 6681: }
1.795 www 6682:
1.423 albertel 6683: table.LC_course_group_status {
6684: margin: 20px;
6685: }
1.795 www 6686:
1.423 albertel 6687: table.LC_status_selector td {
6688: vertical-align: top;
6689: text-align: center;
1.424 albertel 6690: padding: 4px;
6691: }
1.795 www 6692:
1.599 albertel 6693: div.LC_feedback_link {
1.616 albertel 6694: clear: both;
1.829 kalberla 6695: background: $sidebg;
1.779 bisitz 6696: width: 100%;
1.829 kalberla 6697: padding-bottom: 10px;
6698: border: 1px $tabbg solid;
1.833 kalberla 6699: height: 22px;
6700: line-height: 22px;
6701: padding-top: 5px;
6702: }
6703:
6704: div.LC_feedback_link img {
6705: height: 22px;
1.867 kalberla 6706: vertical-align:middle;
1.829 kalberla 6707: }
6708:
1.911 bisitz 6709: div.LC_feedback_link a {
1.829 kalberla 6710: text-decoration: none;
1.489 raeburn 6711: }
1.795 www 6712:
1.867 kalberla 6713: div.LC_comblock {
1.911 bisitz 6714: display:inline;
1.867 kalberla 6715: color:$font;
6716: font-size:90%;
6717: }
6718:
6719: div.LC_feedback_link div.LC_comblock {
6720: padding-left:5px;
6721: }
6722:
6723: div.LC_feedback_link div.LC_comblock a {
6724: color:$font;
6725: }
6726:
1.489 raeburn 6727: span.LC_feedback_link {
1.858 bisitz 6728: /* background: $feedback_link_bg; */
1.599 albertel 6729: font-size: larger;
6730: }
1.795 www 6731:
1.599 albertel 6732: span.LC_message_link {
1.858 bisitz 6733: /* background: $feedback_link_bg; */
1.599 albertel 6734: font-size: larger;
6735: position: absolute;
6736: right: 1em;
1.489 raeburn 6737: }
1.421 albertel 6738:
1.515 albertel 6739: table.LC_prior_tries {
1.524 albertel 6740: border: 1px solid #000000;
6741: border-collapse: separate;
6742: border-spacing: 1px;
1.515 albertel 6743: }
1.523 albertel 6744:
1.515 albertel 6745: table.LC_prior_tries td {
1.524 albertel 6746: padding: 2px;
1.515 albertel 6747: }
1.523 albertel 6748:
6749: .LC_answer_correct {
1.795 www 6750: background: lightgreen;
6751: color: darkgreen;
6752: padding: 6px;
1.523 albertel 6753: }
1.795 www 6754:
1.523 albertel 6755: .LC_answer_charged_try {
1.797 www 6756: background: #FFAAAA;
1.795 www 6757: color: darkred;
6758: padding: 6px;
1.523 albertel 6759: }
1.795 www 6760:
1.779 bisitz 6761: .LC_answer_not_charged_try,
1.523 albertel 6762: .LC_answer_no_grade,
6763: .LC_answer_late {
1.795 www 6764: background: lightyellow;
1.523 albertel 6765: color: black;
1.795 www 6766: padding: 6px;
1.523 albertel 6767: }
1.795 www 6768:
1.523 albertel 6769: .LC_answer_previous {
1.795 www 6770: background: lightblue;
6771: color: darkblue;
6772: padding: 6px;
1.523 albertel 6773: }
1.795 www 6774:
1.779 bisitz 6775: .LC_answer_no_message {
1.777 tempelho 6776: background: #FFFFFF;
6777: color: black;
1.795 www 6778: padding: 6px;
1.779 bisitz 6779: }
1.795 www 6780:
1.1075.2.140 raeburn 6781: .LC_answer_unknown,
6782: .LC_answer_warning {
1.779 bisitz 6783: background: orange;
6784: color: black;
1.795 www 6785: padding: 6px;
1.777 tempelho 6786: }
1.795 www 6787:
1.529 albertel 6788: span.LC_prior_numerical,
6789: span.LC_prior_string,
6790: span.LC_prior_custom,
6791: span.LC_prior_reaction,
6792: span.LC_prior_math {
1.925 bisitz 6793: font-family: $mono;
1.523 albertel 6794: white-space: pre;
6795: }
6796:
1.525 albertel 6797: span.LC_prior_string {
1.925 bisitz 6798: font-family: $mono;
1.525 albertel 6799: white-space: pre;
6800: }
6801:
1.523 albertel 6802: table.LC_prior_option {
6803: width: 100%;
6804: border-collapse: collapse;
6805: }
1.795 www 6806:
1.911 bisitz 6807: table.LC_prior_rank,
1.795 www 6808: table.LC_prior_match {
1.528 albertel 6809: border-collapse: collapse;
6810: }
1.795 www 6811:
1.528 albertel 6812: table.LC_prior_option tr td,
6813: table.LC_prior_rank tr td,
6814: table.LC_prior_match tr td {
1.524 albertel 6815: border: 1px solid #000000;
1.515 albertel 6816: }
6817:
1.855 bisitz 6818: .LC_nobreak {
1.544 albertel 6819: white-space: nowrap;
1.519 raeburn 6820: }
6821:
1.576 raeburn 6822: span.LC_cusr_emph {
6823: font-style: italic;
6824: }
6825:
1.633 raeburn 6826: span.LC_cusr_subheading {
6827: font-weight: normal;
6828: font-size: 85%;
6829: }
6830:
1.861 bisitz 6831: div.LC_docs_entry_move {
1.859 bisitz 6832: border: 1px solid #BBBBBB;
1.545 albertel 6833: background: #DDDDDD;
1.861 bisitz 6834: width: 22px;
1.859 bisitz 6835: padding: 1px;
6836: margin: 0;
1.545 albertel 6837: }
6838:
1.861 bisitz 6839: table.LC_data_table tr > td.LC_docs_entry_commands,
6840: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6841: font-size: x-small;
6842: }
1.795 www 6843:
1.861 bisitz 6844: .LC_docs_entry_parameter {
6845: white-space: nowrap;
6846: }
6847:
1.544 albertel 6848: .LC_docs_copy {
1.545 albertel 6849: color: #000099;
1.544 albertel 6850: }
1.795 www 6851:
1.544 albertel 6852: .LC_docs_cut {
1.545 albertel 6853: color: #550044;
1.544 albertel 6854: }
1.795 www 6855:
1.544 albertel 6856: .LC_docs_rename {
1.545 albertel 6857: color: #009900;
1.544 albertel 6858: }
1.795 www 6859:
1.544 albertel 6860: .LC_docs_remove {
1.545 albertel 6861: color: #990000;
6862: }
6863:
1.1075.2.134 raeburn 6864: .LC_domprefs_email,
1.547 albertel 6865: .LC_docs_reinit_warn,
6866: .LC_docs_ext_edit {
6867: font-size: x-small;
6868: }
6869:
1.545 albertel 6870: table.LC_docs_adddocs td,
6871: table.LC_docs_adddocs th {
6872: border: 1px solid #BBBBBB;
6873: padding: 4px;
6874: background: #DDDDDD;
1.543 albertel 6875: }
6876:
1.584 albertel 6877: table.LC_sty_begin {
6878: background: #BBFFBB;
6879: }
1.795 www 6880:
1.584 albertel 6881: table.LC_sty_end {
6882: background: #FFBBBB;
6883: }
6884:
1.589 raeburn 6885: table.LC_double_column {
1.803 bisitz 6886: border-width: 0;
1.589 raeburn 6887: border-collapse: collapse;
6888: width: 100%;
6889: padding: 2px;
6890: }
6891:
6892: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6893: top: 2px;
1.589 raeburn 6894: left: 2px;
6895: width: 47%;
6896: vertical-align: top;
6897: }
6898:
6899: table.LC_double_column tr td.LC_right_col {
6900: top: 2px;
1.779 bisitz 6901: right: 2px;
1.589 raeburn 6902: width: 47%;
6903: vertical-align: top;
6904: }
6905:
1.591 raeburn 6906: div.LC_left_float {
6907: float: left;
6908: padding-right: 5%;
1.597 albertel 6909: padding-bottom: 4px;
1.591 raeburn 6910: }
6911:
6912: div.LC_clear_float_header {
1.597 albertel 6913: padding-bottom: 2px;
1.591 raeburn 6914: }
6915:
6916: div.LC_clear_float_footer {
1.597 albertel 6917: padding-top: 10px;
1.591 raeburn 6918: clear: both;
6919: }
6920:
1.597 albertel 6921: div.LC_grade_show_user {
1.941 bisitz 6922: /* border-left: 5px solid $sidebg; */
6923: border-top: 5px solid #000000;
6924: margin: 50px 0 0 0;
1.936 bisitz 6925: padding: 15px 0 5px 10px;
1.597 albertel 6926: }
1.795 www 6927:
1.936 bisitz 6928: div.LC_grade_show_user_odd_row {
1.941 bisitz 6929: /* border-left: 5px solid #000000; */
6930: }
6931:
6932: div.LC_grade_show_user div.LC_Box {
6933: margin-right: 50px;
1.597 albertel 6934: }
6935:
6936: div.LC_grade_submissions,
6937: div.LC_grade_message_center,
1.936 bisitz 6938: div.LC_grade_info_links {
1.597 albertel 6939: margin: 5px;
6940: width: 99%;
6941: background: #FFFFFF;
6942: }
1.795 www 6943:
1.597 albertel 6944: div.LC_grade_submissions_header,
1.936 bisitz 6945: div.LC_grade_message_center_header {
1.705 tempelho 6946: font-weight: bold;
6947: font-size: large;
1.597 albertel 6948: }
1.795 www 6949:
1.597 albertel 6950: div.LC_grade_submissions_body,
1.936 bisitz 6951: div.LC_grade_message_center_body {
1.597 albertel 6952: border: 1px solid black;
6953: width: 99%;
6954: background: #FFFFFF;
6955: }
1.795 www 6956:
1.613 albertel 6957: table.LC_scantron_action {
6958: width: 100%;
6959: }
1.795 www 6960:
1.613 albertel 6961: table.LC_scantron_action tr th {
1.698 harmsja 6962: font-weight:bold;
6963: font-style:normal;
1.613 albertel 6964: }
1.795 www 6965:
1.779 bisitz 6966: .LC_edit_problem_header,
1.614 albertel 6967: div.LC_edit_problem_footer {
1.705 tempelho 6968: font-weight: normal;
6969: font-size: medium;
1.602 albertel 6970: margin: 2px;
1.1060 bisitz 6971: background-color: $sidebg;
1.600 albertel 6972: }
1.795 www 6973:
1.600 albertel 6974: div.LC_edit_problem_header,
1.602 albertel 6975: div.LC_edit_problem_header div,
1.614 albertel 6976: div.LC_edit_problem_footer,
6977: div.LC_edit_problem_footer div,
1.602 albertel 6978: div.LC_edit_problem_editxml_header,
6979: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 6980: z-index: 100;
1.600 albertel 6981: }
1.795 www 6982:
1.600 albertel 6983: div.LC_edit_problem_header_title {
1.705 tempelho 6984: font-weight: bold;
6985: font-size: larger;
1.602 albertel 6986: background: $tabbg;
6987: padding: 3px;
1.1060 bisitz 6988: margin: 0 0 5px 0;
1.602 albertel 6989: }
1.795 www 6990:
1.602 albertel 6991: table.LC_edit_problem_header_title {
6992: width: 100%;
1.600 albertel 6993: background: $tabbg;
1.602 albertel 6994: }
6995:
1.1075.2.112 raeburn 6996: div.LC_edit_actionbar {
6997: background-color: $sidebg;
6998: margin: 0;
6999: padding: 0;
7000: line-height: 200%;
1.602 albertel 7001: }
1.795 www 7002:
1.1075.2.112 raeburn 7003: div.LC_edit_actionbar div{
7004: padding: 0;
7005: margin: 0;
7006: display: inline-block;
1.600 albertel 7007: }
1.795 www 7008:
1.1075.2.34 raeburn 7009: .LC_edit_opt {
7010: padding-left: 1em;
7011: white-space: nowrap;
7012: }
7013:
1.1075.2.57 raeburn 7014: .LC_edit_problem_latexhelper{
7015: text-align: right;
7016: }
7017:
7018: #LC_edit_problem_colorful div{
7019: margin-left: 40px;
7020: }
7021:
1.1075.2.112 raeburn 7022: #LC_edit_problem_codemirror div{
7023: margin-left: 0px;
7024: }
7025:
1.911 bisitz 7026: img.stift {
1.803 bisitz 7027: border-width: 0;
7028: vertical-align: middle;
1.677 riegler 7029: }
1.680 riegler 7030:
1.923 bisitz 7031: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7032: vertical-align: top;
1.777 tempelho 7033: }
1.795 www 7034:
1.716 raeburn 7035: div.LC_createcourse {
1.911 bisitz 7036: margin: 10px 10px 10px 10px;
1.716 raeburn 7037: }
7038:
1.917 raeburn 7039: .LC_dccid {
1.1075.2.38 raeburn 7040: float: right;
1.917 raeburn 7041: margin: 0.2em 0 0 0;
7042: padding: 0;
7043: font-size: 90%;
7044: display:none;
7045: }
7046:
1.897 wenzelju 7047: ol.LC_primary_menu a:hover,
1.721 harmsja 7048: ol#LC_MenuBreadcrumbs a:hover,
7049: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7050: ul#LC_secondary_menu a:hover,
1.721 harmsja 7051: .LC_FormSectionClearButton input:hover
1.795 www 7052: ul.LC_TabContent li:hover a {
1.952 onken 7053: color:$button_hover;
1.911 bisitz 7054: text-decoration:none;
1.693 droeschl 7055: }
7056:
1.779 bisitz 7057: h1 {
1.911 bisitz 7058: padding: 0;
7059: line-height:130%;
1.693 droeschl 7060: }
1.698 harmsja 7061:
1.911 bisitz 7062: h2,
7063: h3,
7064: h4,
7065: h5,
7066: h6 {
7067: margin: 5px 0 5px 0;
7068: padding: 0;
7069: line-height:130%;
1.693 droeschl 7070: }
1.795 www 7071:
7072: .LC_hcell {
1.911 bisitz 7073: padding:3px 15px 3px 15px;
7074: margin: 0;
7075: background-color:$tabbg;
7076: color:$fontmenu;
7077: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7078: }
1.795 www 7079:
1.840 bisitz 7080: .LC_Box > .LC_hcell {
1.911 bisitz 7081: margin: 0 -10px 10px -10px;
1.835 bisitz 7082: }
7083:
1.721 harmsja 7084: .LC_noBorder {
1.911 bisitz 7085: border: 0;
1.698 harmsja 7086: }
1.693 droeschl 7087:
1.721 harmsja 7088: .LC_FormSectionClearButton input {
1.911 bisitz 7089: background-color:transparent;
7090: border: none;
7091: cursor:pointer;
7092: text-decoration:underline;
1.693 droeschl 7093: }
1.763 bisitz 7094:
7095: .LC_help_open_topic {
1.911 bisitz 7096: color: #FFFFFF;
7097: background-color: #EEEEFF;
7098: margin: 1px;
7099: padding: 4px;
7100: border: 1px solid #000033;
7101: white-space: nowrap;
7102: /* vertical-align: middle; */
1.759 neumanie 7103: }
1.693 droeschl 7104:
1.911 bisitz 7105: dl,
7106: ul,
7107: div,
7108: fieldset {
7109: margin: 10px 10px 10px 0;
7110: /* overflow: hidden; */
1.693 droeschl 7111: }
1.795 www 7112:
1.1075.2.90 raeburn 7113: article.geogebraweb div {
7114: margin: 0;
7115: }
7116:
1.838 bisitz 7117: fieldset > legend {
1.911 bisitz 7118: font-weight: bold;
7119: padding: 0 5px 0 5px;
1.838 bisitz 7120: }
7121:
1.813 bisitz 7122: #LC_nav_bar {
1.911 bisitz 7123: float: left;
1.995 raeburn 7124: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7125: margin: 0 0 2px 0;
1.807 droeschl 7126: }
7127:
1.916 droeschl 7128: #LC_realm {
7129: margin: 0.2em 0 0 0;
7130: padding: 0;
7131: font-weight: bold;
7132: text-align: center;
1.995 raeburn 7133: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7134: }
7135:
1.911 bisitz 7136: #LC_nav_bar em {
7137: font-weight: bold;
7138: font-style: normal;
1.807 droeschl 7139: }
7140:
1.897 wenzelju 7141: ol.LC_primary_menu {
1.934 droeschl 7142: margin: 0;
1.1075.2.2 raeburn 7143: padding: 0;
1.807 droeschl 7144: }
7145:
1.852 droeschl 7146: ol#LC_PathBreadcrumbs {
1.911 bisitz 7147: margin: 0;
1.693 droeschl 7148: }
7149:
1.897 wenzelju 7150: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7151: color: RGB(80, 80, 80);
7152: vertical-align: middle;
7153: text-align: left;
7154: list-style: none;
1.1075.2.112 raeburn 7155: position: relative;
1.1075.2.2 raeburn 7156: float: left;
1.1075.2.112 raeburn 7157: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7158: line-height: 1.5em;
1.1075.2.2 raeburn 7159: }
7160:
1.1075.2.113 raeburn 7161: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7162: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7163: display: block;
7164: margin: 0;
7165: padding: 0 5px 0 10px;
7166: text-decoration: none;
7167: }
7168:
1.1075.2.112 raeburn 7169: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7170: display: inline-block;
7171: width: 95%;
7172: text-align: left;
7173: }
7174:
7175: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7176: display: inline-block;
7177: width: 5%;
7178: float: right;
7179: text-align: right;
7180: font-size: 70%;
7181: }
7182:
7183: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7184: display: none;
1.1075.2.112 raeburn 7185: width: 15em;
1.1075.2.2 raeburn 7186: background-color: $data_table_light;
1.1075.2.112 raeburn 7187: position: absolute;
7188: top: 100%;
7189: }
7190:
7191: ol.LC_primary_menu ul ul {
7192: left: 100%;
7193: top: 0;
1.1075.2.2 raeburn 7194: }
7195:
1.1075.2.112 raeburn 7196: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7197: display: block;
7198: position: absolute;
7199: margin: 0;
7200: padding: 0;
1.1075.2.5 raeburn 7201: z-index: 2;
1.1075.2.2 raeburn 7202: }
7203:
7204: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7205: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7206: font-size: 90%;
1.911 bisitz 7207: vertical-align: top;
1.1075.2.2 raeburn 7208: float: none;
1.1075.2.5 raeburn 7209: border-left: 1px solid black;
7210: border-right: 1px solid black;
1.1075.2.112 raeburn 7211: /* A dark bottom border to visualize different menu options;
7212: overwritten in the create_submenu routine for the last border-bottom of the menu */
7213: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7214: }
7215:
1.1075.2.112 raeburn 7216: ol.LC_primary_menu li li p:hover {
7217: color:$button_hover;
7218: text-decoration:none;
7219: background-color:$data_table_dark;
1.1075.2.2 raeburn 7220: }
7221:
7222: ol.LC_primary_menu li li a:hover {
7223: color:$button_hover;
7224: background-color:$data_table_dark;
1.693 droeschl 7225: }
7226:
1.1075.2.112 raeburn 7227: /* Font-size equal to the size of the predecessors*/
7228: ol.LC_primary_menu li:hover li li {
7229: font-size: 100%;
7230: }
7231:
1.897 wenzelju 7232: ol.LC_primary_menu li img {
1.911 bisitz 7233: vertical-align: bottom;
1.934 droeschl 7234: height: 1.1em;
1.1075.2.3 raeburn 7235: margin: 0.2em 0 0 0;
1.693 droeschl 7236: }
7237:
1.897 wenzelju 7238: ol.LC_primary_menu a {
1.911 bisitz 7239: color: RGB(80, 80, 80);
7240: text-decoration: none;
1.693 droeschl 7241: }
1.795 www 7242:
1.949 droeschl 7243: ol.LC_primary_menu a.LC_new_message {
7244: font-weight:bold;
7245: color: darkred;
7246: }
7247:
1.975 raeburn 7248: ol.LC_docs_parameters {
7249: margin-left: 0;
7250: padding: 0;
7251: list-style: none;
7252: }
7253:
7254: ol.LC_docs_parameters li {
7255: margin: 0;
7256: padding-right: 20px;
7257: display: inline;
7258: }
7259:
1.976 raeburn 7260: ol.LC_docs_parameters li:before {
7261: content: "\\002022 \\0020";
7262: }
7263:
7264: li.LC_docs_parameters_title {
7265: font-weight: bold;
7266: }
7267:
7268: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7269: content: "";
7270: }
7271:
1.897 wenzelju 7272: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7273: clear: right;
1.911 bisitz 7274: color: $fontmenu;
7275: background: $tabbg;
7276: list-style: none;
7277: padding: 0;
7278: margin: 0;
7279: width: 100%;
1.995 raeburn 7280: text-align: left;
1.1075.2.4 raeburn 7281: float: left;
1.808 droeschl 7282: }
7283:
1.897 wenzelju 7284: ul#LC_secondary_menu li {
1.911 bisitz 7285: font-weight: bold;
7286: line-height: 1.8em;
7287: border-right: 1px solid black;
1.1075.2.4 raeburn 7288: float: left;
7289: }
7290:
7291: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7292: background-color: $data_table_light;
7293: }
7294:
7295: ul#LC_secondary_menu li a {
7296: padding: 0 0.8em;
7297: }
7298:
7299: ul#LC_secondary_menu li ul {
7300: display: none;
7301: }
7302:
7303: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7304: display: block;
7305: position: absolute;
7306: margin: 0;
7307: padding: 0;
7308: list-style:none;
7309: float: none;
7310: background-color: $data_table_light;
1.1075.2.5 raeburn 7311: z-index: 2;
1.1075.2.10 raeburn 7312: margin-left: -1px;
1.1075.2.4 raeburn 7313: }
7314:
7315: ul#LC_secondary_menu li ul li {
7316: font-size: 90%;
7317: vertical-align: top;
7318: border-left: 1px solid black;
7319: border-right: 1px solid black;
1.1075.2.33 raeburn 7320: background-color: $data_table_light;
1.1075.2.4 raeburn 7321: list-style:none;
7322: float: none;
7323: }
7324:
7325: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7326: background-color: $data_table_dark;
1.807 droeschl 7327: }
7328:
1.847 tempelho 7329: ul.LC_TabContent {
1.911 bisitz 7330: display:block;
7331: background: $sidebg;
7332: border-bottom: solid 1px $lg_border_color;
7333: list-style:none;
1.1020 raeburn 7334: margin: -1px -10px 0 -10px;
1.911 bisitz 7335: padding: 0;
1.693 droeschl 7336: }
7337:
1.795 www 7338: ul.LC_TabContent li,
7339: ul.LC_TabContentBigger li {
1.911 bisitz 7340: float:left;
1.741 harmsja 7341: }
1.795 www 7342:
1.897 wenzelju 7343: ul#LC_secondary_menu li a {
1.911 bisitz 7344: color: $fontmenu;
7345: text-decoration: none;
1.693 droeschl 7346: }
1.795 www 7347:
1.721 harmsja 7348: ul.LC_TabContent {
1.952 onken 7349: min-height:20px;
1.721 harmsja 7350: }
1.795 www 7351:
7352: ul.LC_TabContent li {
1.911 bisitz 7353: vertical-align:middle;
1.959 onken 7354: padding: 0 16px 0 10px;
1.911 bisitz 7355: background-color:$tabbg;
7356: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7357: border-left: solid 1px $font;
1.721 harmsja 7358: }
1.795 www 7359:
1.847 tempelho 7360: ul.LC_TabContent .right {
1.911 bisitz 7361: float:right;
1.847 tempelho 7362: }
7363:
1.911 bisitz 7364: ul.LC_TabContent li a,
7365: ul.LC_TabContent li {
7366: color:rgb(47,47,47);
7367: text-decoration:none;
7368: font-size:95%;
7369: font-weight:bold;
1.952 onken 7370: min-height:20px;
7371: }
7372:
1.959 onken 7373: ul.LC_TabContent li a:hover,
7374: ul.LC_TabContent li a:focus {
1.952 onken 7375: color: $button_hover;
1.959 onken 7376: background:none;
7377: outline:none;
1.952 onken 7378: }
7379:
7380: ul.LC_TabContent li:hover {
7381: color: $button_hover;
7382: cursor:pointer;
1.721 harmsja 7383: }
1.795 www 7384:
1.911 bisitz 7385: ul.LC_TabContent li.active {
1.952 onken 7386: color: $font;
1.911 bisitz 7387: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7388: border-bottom:solid 1px #FFFFFF;
7389: cursor: default;
1.744 ehlerst 7390: }
1.795 www 7391:
1.959 onken 7392: ul.LC_TabContent li.active a {
7393: color:$font;
7394: background:#FFFFFF;
7395: outline: none;
7396: }
1.1047 raeburn 7397:
7398: ul.LC_TabContent li.goback {
7399: float: left;
7400: border-left: none;
7401: }
7402:
1.870 tempelho 7403: #maincoursedoc {
1.911 bisitz 7404: clear:both;
1.870 tempelho 7405: }
7406:
7407: ul.LC_TabContentBigger {
1.911 bisitz 7408: display:block;
7409: list-style:none;
7410: padding: 0;
1.870 tempelho 7411: }
7412:
1.795 www 7413: ul.LC_TabContentBigger li {
1.911 bisitz 7414: vertical-align:bottom;
7415: height: 30px;
7416: font-size:110%;
7417: font-weight:bold;
7418: color: #737373;
1.841 tempelho 7419: }
7420:
1.957 onken 7421: ul.LC_TabContentBigger li.active {
7422: position: relative;
7423: top: 1px;
7424: }
7425:
1.870 tempelho 7426: ul.LC_TabContentBigger li a {
1.911 bisitz 7427: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7428: height: 30px;
7429: line-height: 30px;
7430: text-align: center;
7431: display: block;
7432: text-decoration: none;
1.958 onken 7433: outline: none;
1.741 harmsja 7434: }
1.795 www 7435:
1.870 tempelho 7436: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7437: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7438: color:$font;
1.744 ehlerst 7439: }
1.795 www 7440:
1.870 tempelho 7441: ul.LC_TabContentBigger li b {
1.911 bisitz 7442: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7443: display: block;
7444: float: left;
7445: padding: 0 30px;
1.957 onken 7446: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7447: }
7448:
1.956 onken 7449: ul.LC_TabContentBigger li:hover b {
7450: color:$button_hover;
7451: }
7452:
1.870 tempelho 7453: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7454: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7455: color:$font;
1.957 onken 7456: border: 0;
1.741 harmsja 7457: }
1.693 droeschl 7458:
1.870 tempelho 7459:
1.862 bisitz 7460: ul.LC_CourseBreadcrumbs {
7461: background: $sidebg;
1.1020 raeburn 7462: height: 2em;
1.862 bisitz 7463: padding-left: 10px;
1.1020 raeburn 7464: margin: 0;
1.862 bisitz 7465: list-style-position: inside;
7466: }
7467:
1.911 bisitz 7468: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7469: ol#LC_PathBreadcrumbs {
1.911 bisitz 7470: padding-left: 10px;
7471: margin: 0;
1.933 droeschl 7472: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7473: }
7474:
1.911 bisitz 7475: ol#LC_MenuBreadcrumbs li,
7476: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7477: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7478: display: inline;
1.933 droeschl 7479: white-space: normal;
1.693 droeschl 7480: }
7481:
1.823 bisitz 7482: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7483: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7484: text-decoration: none;
7485: font-size:90%;
1.693 droeschl 7486: }
1.795 www 7487:
1.969 droeschl 7488: ol#LC_MenuBreadcrumbs h1 {
7489: display: inline;
7490: font-size: 90%;
7491: line-height: 2.5em;
7492: margin: 0;
7493: padding: 0;
7494: }
7495:
1.795 www 7496: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7497: text-decoration:none;
7498: font-size:100%;
7499: font-weight:bold;
1.693 droeschl 7500: }
1.795 www 7501:
1.840 bisitz 7502: .LC_Box {
1.911 bisitz 7503: border: solid 1px $lg_border_color;
7504: padding: 0 10px 10px 10px;
1.746 neumanie 7505: }
1.795 www 7506:
1.1020 raeburn 7507: .LC_DocsBox {
7508: border: solid 1px $lg_border_color;
7509: padding: 0 0 10px 10px;
7510: }
7511:
1.795 www 7512: .LC_AboutMe_Image {
1.911 bisitz 7513: float:left;
7514: margin-right:10px;
1.747 neumanie 7515: }
1.795 www 7516:
7517: .LC_Clear_AboutMe_Image {
1.911 bisitz 7518: clear:left;
1.747 neumanie 7519: }
1.795 www 7520:
1.721 harmsja 7521: dl.LC_ListStyleClean dt {
1.911 bisitz 7522: padding-right: 5px;
7523: display: table-header-group;
1.693 droeschl 7524: }
7525:
1.721 harmsja 7526: dl.LC_ListStyleClean dd {
1.911 bisitz 7527: display: table-row;
1.693 droeschl 7528: }
7529:
1.721 harmsja 7530: .LC_ListStyleClean,
7531: .LC_ListStyleSimple,
7532: .LC_ListStyleNormal,
1.795 www 7533: .LC_ListStyleSpecial {
1.911 bisitz 7534: /* display:block; */
7535: list-style-position: inside;
7536: list-style-type: none;
7537: overflow: hidden;
7538: padding: 0;
1.693 droeschl 7539: }
7540:
1.721 harmsja 7541: .LC_ListStyleSimple li,
7542: .LC_ListStyleSimple dd,
7543: .LC_ListStyleNormal li,
7544: .LC_ListStyleNormal dd,
7545: .LC_ListStyleSpecial li,
1.795 www 7546: .LC_ListStyleSpecial dd {
1.911 bisitz 7547: margin: 0;
7548: padding: 5px 5px 5px 10px;
7549: clear: both;
1.693 droeschl 7550: }
7551:
1.721 harmsja 7552: .LC_ListStyleClean li,
7553: .LC_ListStyleClean dd {
1.911 bisitz 7554: padding-top: 0;
7555: padding-bottom: 0;
1.693 droeschl 7556: }
7557:
1.721 harmsja 7558: .LC_ListStyleSimple dd,
1.795 www 7559: .LC_ListStyleSimple li {
1.911 bisitz 7560: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7561: }
7562:
1.721 harmsja 7563: .LC_ListStyleSpecial li,
7564: .LC_ListStyleSpecial dd {
1.911 bisitz 7565: list-style-type: none;
7566: background-color: RGB(220, 220, 220);
7567: margin-bottom: 4px;
1.693 droeschl 7568: }
7569:
1.721 harmsja 7570: table.LC_SimpleTable {
1.911 bisitz 7571: margin:5px;
7572: border:solid 1px $lg_border_color;
1.795 www 7573: }
1.693 droeschl 7574:
1.721 harmsja 7575: table.LC_SimpleTable tr {
1.911 bisitz 7576: padding: 0;
7577: border:solid 1px $lg_border_color;
1.693 droeschl 7578: }
1.795 www 7579:
7580: table.LC_SimpleTable thead {
1.911 bisitz 7581: background:rgb(220,220,220);
1.693 droeschl 7582: }
7583:
1.721 harmsja 7584: div.LC_columnSection {
1.911 bisitz 7585: display: block;
7586: clear: both;
7587: overflow: hidden;
7588: margin: 0;
1.693 droeschl 7589: }
7590:
1.721 harmsja 7591: div.LC_columnSection>* {
1.911 bisitz 7592: float: left;
7593: margin: 10px 20px 10px 0;
7594: overflow:hidden;
1.693 droeschl 7595: }
1.721 harmsja 7596:
1.795 www 7597: table em {
1.911 bisitz 7598: font-weight: bold;
7599: font-style: normal;
1.748 schulted 7600: }
1.795 www 7601:
1.779 bisitz 7602: table.LC_tableBrowseRes,
1.795 www 7603: table.LC_tableOfContent {
1.911 bisitz 7604: border:none;
7605: border-spacing: 1px;
7606: padding: 3px;
7607: background-color: #FFFFFF;
7608: font-size: 90%;
1.753 droeschl 7609: }
1.789 droeschl 7610:
1.911 bisitz 7611: table.LC_tableOfContent {
7612: border-collapse: collapse;
1.789 droeschl 7613: }
7614:
1.771 droeschl 7615: table.LC_tableBrowseRes a,
1.768 schulted 7616: table.LC_tableOfContent a {
1.911 bisitz 7617: background-color: transparent;
7618: text-decoration: none;
1.753 droeschl 7619: }
7620:
1.795 www 7621: table.LC_tableOfContent img {
1.911 bisitz 7622: border: none;
7623: height: 1.3em;
7624: vertical-align: text-bottom;
7625: margin-right: 0.3em;
1.753 droeschl 7626: }
1.757 schulted 7627:
1.795 www 7628: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7629: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7630: }
7631:
1.795 www 7632: a#LC_content_toolbar_everything {
1.911 bisitz 7633: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7634: }
7635:
1.795 www 7636: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7637: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7638: }
7639:
1.795 www 7640: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7641: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7642: }
7643:
1.795 www 7644: a#LC_content_toolbar_changefolder {
1.911 bisitz 7645: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7646: }
7647:
1.795 www 7648: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7649: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7650: }
7651:
1.1043 raeburn 7652: a#LC_content_toolbar_edittoplevel {
7653: background-image:url(/res/adm/pages/edittoplevel.gif);
7654: }
7655:
1.795 www 7656: ul#LC_toolbar li a:hover {
1.911 bisitz 7657: background-position: bottom center;
1.757 schulted 7658: }
7659:
1.795 www 7660: ul#LC_toolbar {
1.911 bisitz 7661: padding: 0;
7662: margin: 2px;
7663: list-style:none;
7664: position:relative;
7665: background-color:white;
1.1075.2.9 raeburn 7666: overflow: auto;
1.757 schulted 7667: }
7668:
1.795 www 7669: ul#LC_toolbar li {
1.911 bisitz 7670: border:1px solid white;
7671: padding: 0;
7672: margin: 0;
7673: float: left;
7674: display:inline;
7675: vertical-align:middle;
1.1075.2.9 raeburn 7676: white-space: nowrap;
1.911 bisitz 7677: }
1.757 schulted 7678:
1.783 amueller 7679:
1.795 www 7680: a.LC_toolbarItem {
1.911 bisitz 7681: display:block;
7682: padding: 0;
7683: margin: 0;
7684: height: 32px;
7685: width: 32px;
7686: color:white;
7687: border: none;
7688: background-repeat:no-repeat;
7689: background-color:transparent;
1.757 schulted 7690: }
7691:
1.915 droeschl 7692: ul.LC_funclist {
7693: margin: 0;
7694: padding: 0.5em 1em 0.5em 0;
7695: }
7696:
1.933 droeschl 7697: ul.LC_funclist > li:first-child {
7698: font-weight:bold;
7699: margin-left:0.8em;
7700: }
7701:
1.915 droeschl 7702: ul.LC_funclist + ul.LC_funclist {
7703: /*
7704: left border as a seperator if we have more than
7705: one list
7706: */
7707: border-left: 1px solid $sidebg;
7708: /*
7709: this hides the left border behind the border of the
7710: outer box if element is wrapped to the next 'line'
7711: */
7712: margin-left: -1px;
7713: }
7714:
1.843 bisitz 7715: ul.LC_funclist li {
1.915 droeschl 7716: display: inline;
1.782 bisitz 7717: white-space: nowrap;
1.915 droeschl 7718: margin: 0 0 0 25px;
7719: line-height: 150%;
1.782 bisitz 7720: }
7721:
1.974 wenzelju 7722: .LC_hidden {
7723: display: none;
7724: }
7725:
1.1030 www 7726: .LCmodal-overlay {
7727: position:fixed;
7728: top:0;
7729: right:0;
7730: bottom:0;
7731: left:0;
7732: height:100%;
7733: width:100%;
7734: margin:0;
7735: padding:0;
7736: background:#999;
7737: opacity:.75;
7738: filter: alpha(opacity=75);
7739: -moz-opacity: 0.75;
7740: z-index:101;
7741: }
7742:
7743: * html .LCmodal-overlay {
7744: position: absolute;
7745: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7746: }
7747:
7748: .LCmodal-window {
7749: position:fixed;
7750: top:50%;
7751: left:50%;
7752: margin:0;
7753: padding:0;
7754: z-index:102;
7755: }
7756:
7757: * html .LCmodal-window {
7758: position:absolute;
7759: }
7760:
7761: .LCclose-window {
7762: position:absolute;
7763: width:32px;
7764: height:32px;
7765: right:8px;
7766: top:8px;
7767: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7768: text-indent:-99999px;
7769: overflow:hidden;
7770: cursor:pointer;
7771: }
7772:
1.1075.2.141 raeburn 7773: pre.LC_wordwrap {
7774: white-space: pre-wrap;
7775: white-space: -moz-pre-wrap;
7776: white-space: -pre-wrap;
7777: white-space: -o-pre-wrap;
7778: word-wrap: break-word;
7779: }
7780:
1.1075.2.17 raeburn 7781: /*
7782: styles used by TTH when "Default set of options to pass to tth/m
7783: when converting TeX" in course settings has been set
7784:
7785: option passed: -t
7786:
7787: */
7788:
7789: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7790: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7791: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7792: td div.norm {line-height:normal;}
7793:
7794: /*
7795: option passed -y3
7796: */
7797:
7798: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7799: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7800: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7801:
1.1075.2.121 raeburn 7802: #LC_minitab_header {
7803: float:left;
7804: width:100%;
7805: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
7806: font-size:93%;
7807: line-height:normal;
7808: margin: 0.5em 0 0.5em 0;
7809: }
7810: #LC_minitab_header ul {
7811: margin:0;
7812: padding:10px 10px 0;
7813: list-style:none;
7814: }
7815: #LC_minitab_header li {
7816: float:left;
7817: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
7818: margin:0;
7819: padding:0 0 0 9px;
7820: }
7821: #LC_minitab_header a {
7822: display:block;
7823: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
7824: padding:5px 15px 4px 6px;
7825: }
7826: #LC_minitab_header #LC_current_minitab {
7827: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
7828: }
7829: #LC_minitab_header #LC_current_minitab a {
7830: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
7831: padding-bottom:5px;
7832: }
7833:
7834:
1.343 albertel 7835: END
7836: }
7837:
1.306 albertel 7838: =pod
7839:
7840: =item * &headtag()
7841:
7842: Returns a uniform footer for LON-CAPA web pages.
7843:
1.307 albertel 7844: Inputs: $title - optional title for the head
7845: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7846: $args - optional arguments
1.319 albertel 7847: force_register - if is true call registerurl so the remote is
7848: informed
1.415 albertel 7849: redirect -> array ref of
7850: 1- seconds before redirect occurs
7851: 2- url to redirect to
7852: 3- whether the side effect should occur
1.315 albertel 7853: (side effect of setting
7854: $env{'internal.head.redirect'} to the url
7855: redirected too)
1.352 albertel 7856: domain -> force to color decorate a page for a specific
7857: domain
7858: function -> force usage of a specific rolish color scheme
7859: bgcolor -> override the default page bgcolor
1.460 albertel 7860: no_auto_mt_title
7861: -> prevent &mt()ing the title arg
1.464 albertel 7862:
1.306 albertel 7863: =cut
7864:
7865: sub headtag {
1.313 albertel 7866: my ($title,$head_extra,$args) = @_;
1.306 albertel 7867:
1.363 albertel 7868: my $function = $args->{'function'} || &get_users_function();
7869: my $domain = $args->{'domain'} || &determinedomain();
7870: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7871: my $httphost = $args->{'use_absolute'};
1.418 albertel 7872: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7873: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7874: #time(),
1.418 albertel 7875: $env{'environment.color.timestamp'},
1.363 albertel 7876: $function,$domain,$bgcolor);
7877:
1.369 www 7878: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7879:
1.308 albertel 7880: my $result =
7881: '<head>'.
1.1075.2.56 raeburn 7882: &font_settings($args);
1.319 albertel 7883:
1.1075.2.72 raeburn 7884: my $inhibitprint;
7885: if ($args->{'print_suppress'}) {
7886: $inhibitprint = &print_suppression();
7887: }
1.1064 raeburn 7888:
1.461 albertel 7889: if (!$args->{'frameset'}) {
7890: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7891: }
1.1075.2.12 raeburn 7892: if ($args->{'force_register'}) {
7893: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7894: }
1.436 albertel 7895: if (!$args->{'no_nav_bar'}
7896: && !$args->{'only_body'}
7897: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7898: $result .= &help_menu_js($httphost);
1.1032 www 7899: $result.=&modal_window();
1.1038 www 7900: $result.=&togglebox_script();
1.1034 www 7901: $result.=&wishlist_window();
1.1041 www 7902: $result.=&LCprogressbarUpdate_script();
1.1034 www 7903: } else {
7904: if ($args->{'add_modal'}) {
7905: $result.=&modal_window();
7906: }
7907: if ($args->{'add_wishlist'}) {
7908: $result.=&wishlist_window();
7909: }
1.1038 www 7910: if ($args->{'add_togglebox'}) {
7911: $result.=&togglebox_script();
7912: }
1.1041 www 7913: if ($args->{'add_progressbar'}) {
7914: $result.=&LCprogressbarUpdate_script();
7915: }
1.436 albertel 7916: }
1.314 albertel 7917: if (ref($args->{'redirect'})) {
1.414 albertel 7918: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7919: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7920: if (!$inhibit_continue) {
7921: $env{'internal.head.redirect'} = $url;
7922: }
1.313 albertel 7923: $result.=<<ADDMETA
7924: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7925: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7926: ADDMETA
1.1075.2.89 raeburn 7927: } else {
7928: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
7929: my $requrl = $env{'request.uri'};
7930: if ($requrl eq '') {
7931: $requrl = $ENV{'REQUEST_URI'};
7932: $requrl =~ s/\?.+$//;
7933: }
7934: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
7935: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
7936: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
7937: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
7938: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
7939: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1075.2.145 raeburn 7940: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7941: my $offload;
1.1075.2.89 raeburn 7942: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
7943: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1075.2.145 raeburn 7944: $offload = 1;
7945: }
7946: }
7947: unless ($offload) {
7948: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
7949: if ($domdefs{'offloadoth'}{$lonhost}) {
7950: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
7951: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
7952: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
7953: $offload = 1;
7954: $dom_in_use = $env{'user.domain'};
7955: }
1.1075.2.89 raeburn 7956: }
1.1075.2.145 raeburn 7957: }
7958: }
7959: }
7960: if ($offload) {
7961: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
7962: if (($newserver) && ($newserver ne $lonhost)) {
7963: my $numsec = 5;
7964: my $timeout = $numsec * 1000;
7965: my ($newurl,$locknum,%locks,$msg);
7966: if ($env{'request.role.adv'}) {
7967: ($locknum,%locks) = &Apache::lonnet::get_locks();
7968: }
7969: my $disable_submit = 0;
7970: if ($requrl =~ /$LONCAPA::assess_re/) {
7971: $disable_submit = 1;
7972: }
7973: if ($locknum) {
7974: my @lockinfo = sort(values(%locks));
7975: $msg = &mt('Once the following tasks are complete: ')."\n".
7976: join(", ",sort(values(%locks)))."\n";
7977: if (&show_course()) {
7978: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
1.1075.2.89 raeburn 7979: } else {
1.1075.2.145 raeburn 7980: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
7981: }
7982: } else {
7983: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
7984: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
7985: }
7986: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
7987: $newurl = '/adm/switchserver?otherserver='.$newserver;
7988: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
7989: $newurl .= '&role='.$env{'request.role'};
7990: }
7991: if ($env{'request.symb'}) {
7992: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
7993: if ($shownsymb =~ m{^/enc/}) {
7994: my $reqdmajor = 2;
7995: my $reqdminor = 11;
7996: my $reqdsubminor = 3;
7997: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
7998: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
7999: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8000: if (($major eq '' && $minor eq '') ||
8001: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8002: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8003: ($reqdsubminor > $subminor))))) {
8004: undef($shownsymb);
8005: }
1.1075.2.89 raeburn 8006: }
1.1075.2.145 raeburn 8007: if ($shownsymb) {
8008: &js_escape(\$shownsymb);
8009: $newurl .= '&symb='.$shownsymb;
1.1075.2.89 raeburn 8010: }
1.1075.2.145 raeburn 8011: } else {
8012: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8013: &js_escape(\$shownurl);
8014: $newurl .= '&origurl='.$shownurl;
1.1075.2.89 raeburn 8015: }
1.1075.2.145 raeburn 8016: }
8017: &js_escape(\$msg);
8018: $result.=<<OFFLOAD
1.1075.2.89 raeburn 8019: <meta http-equiv="pragma" content="no-cache" />
8020: <script type="text/javascript">
1.1075.2.92 raeburn 8021: // <![CDATA[
1.1075.2.89 raeburn 8022: function LC_Offload_Now() {
8023: var dest = "$newurl";
8024: if (dest != '') {
8025: window.location.href="$newurl";
8026: }
8027: }
1.1075.2.92 raeburn 8028: \$(document).ready(function () {
8029: window.alert('$msg');
8030: if ($disable_submit) {
1.1075.2.89 raeburn 8031: \$(".LC_hwk_submit").prop("disabled", true);
8032: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 8033: }
8034: setTimeout('LC_Offload_Now()', $timeout);
8035: });
8036: // ]]>
1.1075.2.89 raeburn 8037: </script>
8038: OFFLOAD
8039: }
8040: }
8041: }
8042: }
8043: }
1.313 albertel 8044: }
1.306 albertel 8045: if (!defined($title)) {
8046: $title = 'The LearningOnline Network with CAPA';
8047: }
1.460 albertel 8048: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8049: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 8050: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8051: if (!$args->{'frameset'}) {
8052: $result .= ' /';
8053: }
8054: $result .= '>'
1.1064 raeburn 8055: .$inhibitprint
1.414 albertel 8056: .$head_extra;
1.1075.2.108 raeburn 8057: my $clientmobile;
8058: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8059: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8060: } else {
8061: $clientmobile = $env{'browser.mobile'};
8062: }
8063: if ($clientmobile) {
1.1075.2.42 raeburn 8064: $result .= '
8065: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8066: <meta name="apple-mobile-web-app-capable" content="yes" />';
8067: }
1.1075.2.126 raeburn 8068: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8069: return $result.'</head>';
1.306 albertel 8070: }
8071:
8072: =pod
8073:
1.340 albertel 8074: =item * &font_settings()
8075:
8076: Returns neccessary <meta> to set the proper encoding
8077:
1.1075.2.56 raeburn 8078: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8079:
8080: =cut
8081:
8082: sub font_settings {
1.1075.2.56 raeburn 8083: my ($args) = @_;
1.340 albertel 8084: my $headerstring='';
1.1075.2.56 raeburn 8085: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8086: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 8087: $headerstring.=
1.1075.2.61 raeburn 8088: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8089: if (!$args->{'frameset'}) {
8090: $headerstring.= ' /';
8091: }
8092: $headerstring .= '>'."\n";
1.340 albertel 8093: }
8094: return $headerstring;
8095: }
8096:
1.341 albertel 8097: =pod
8098:
1.1064 raeburn 8099: =item * &print_suppression()
8100:
8101: In course context returns css which causes the body to be blank when media="print",
8102: if printout generation is unavailable for the current resource.
8103:
8104: This could be because:
8105:
8106: (a) printstartdate is in the future
8107:
8108: (b) printenddate is in the past
8109:
8110: (c) there is an active exam block with "printout"
8111: functionality blocked
8112:
8113: Users with pav, pfo or evb privileges are exempt.
8114:
8115: Inputs: none
8116:
8117: =cut
8118:
8119:
8120: sub print_suppression {
8121: my $noprint;
8122: if ($env{'request.course.id'}) {
8123: my $scope = $env{'request.course.id'};
8124: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8125: (&Apache::lonnet::allowed('pfo',$scope))) {
8126: return;
8127: }
8128: if ($env{'request.course.sec'} ne '') {
8129: $scope .= "/$env{'request.course.sec'}";
8130: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8131: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8132: return;
1.1064 raeburn 8133: }
8134: }
8135: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8136: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.73 raeburn 8137: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8138: if ($blocked) {
8139: my $checkrole = "cm./$cdom/$cnum";
8140: if ($env{'request.course.sec'} ne '') {
8141: $checkrole .= "/$env{'request.course.sec'}";
8142: }
8143: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8144: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8145: $noprint = 1;
8146: }
8147: }
8148: unless ($noprint) {
8149: my $symb = &Apache::lonnet::symbread();
8150: if ($symb ne '') {
8151: my $navmap = Apache::lonnavmaps::navmap->new();
8152: if (ref($navmap)) {
8153: my $res = $navmap->getBySymb($symb);
8154: if (ref($res)) {
8155: if (!$res->resprintable()) {
8156: $noprint = 1;
8157: }
8158: }
8159: }
8160: }
8161: }
8162: if ($noprint) {
8163: return <<"ENDSTYLE";
8164: <style type="text/css" media="print">
8165: body { display:none }
8166: </style>
8167: ENDSTYLE
8168: }
8169: }
8170: return;
8171: }
8172:
8173: =pod
8174:
1.341 albertel 8175: =item * &xml_begin()
8176:
8177: Returns the needed doctype and <html>
8178:
8179: Inputs: none
8180:
8181: =cut
8182:
8183: sub xml_begin {
1.1075.2.61 raeburn 8184: my ($is_frameset) = @_;
1.341 albertel 8185: my $output='';
8186:
8187: if ($env{'browser.mathml'}) {
8188: $output='<?xml version="1.0"?>'
8189: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8190: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8191:
8192: # .'<!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">] >'
8193: .'<!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">'
8194: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8195: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8196: } elsif ($is_frameset) {
8197: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8198: '<html>'."\n";
1.341 albertel 8199: } else {
1.1075.2.61 raeburn 8200: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8201: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8202: }
8203: return $output;
8204: }
1.340 albertel 8205:
8206: =pod
8207:
1.306 albertel 8208: =item * &start_page()
8209:
8210: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8211:
1.648 raeburn 8212: Inputs:
8213:
8214: =over 4
8215:
8216: $title - optional title for the page
8217:
8218: $head_extra - optional extra HTML to incude inside the <head>
8219:
8220: $args - additional optional args supported are:
8221:
8222: =over 8
8223:
8224: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8225: arg on
1.814 bisitz 8226: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8227: add_entries -> additional attributes to add to the <body>
8228: domain -> force to color decorate a page for a
1.317 albertel 8229: specific domain
1.648 raeburn 8230: function -> force usage of a specific rolish color
1.317 albertel 8231: scheme
1.648 raeburn 8232: redirect -> see &headtag()
8233: bgcolor -> override the default page bg color
8234: js_ready -> return a string ready for being used in
1.317 albertel 8235: a javascript writeln
1.648 raeburn 8236: html_encode -> return a string ready for being used in
1.320 albertel 8237: a html attribute
1.648 raeburn 8238: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8239: $forcereg arg
1.648 raeburn 8240: frameset -> if true will start with a <frameset>
1.330 albertel 8241: rather than <body>
1.648 raeburn 8242: skip_phases -> hash ref of
1.338 albertel 8243: head -> skip the <html><head> generation
8244: body -> skip all <body> generation
1.1075.2.12 raeburn 8245: no_inline_link -> if true and in remote mode, don't show the
8246: 'Switch To Inline Menu' link
1.648 raeburn 8247: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8248: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8249: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 8250: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8251: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8252: group -> includes the current group, if page is for a
8253: specific group
1.1075.2.133 raeburn 8254: use_absolute -> for request for external resource or syllabus, this
8255: will contain https://<hostname> if server uses
8256: https (as per hosts.tab), but request is for http
8257: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8258:
1.648 raeburn 8259: =back
1.460 albertel 8260:
1.648 raeburn 8261: =back
1.562 albertel 8262:
1.306 albertel 8263: =cut
8264:
8265: sub start_page {
1.309 albertel 8266: my ($title,$head_extra,$args) = @_;
1.318 albertel 8267: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8268:
1.315 albertel 8269: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 8270: my ($result,@advtools);
1.964 droeschl 8271:
1.338 albertel 8272: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8273: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8274: }
8275:
8276: if (! exists($args->{'skip_phases'}{'body'}) ) {
8277: if ($args->{'frameset'}) {
8278: my $attr_string = &make_attr_string($args->{'force_register'},
8279: $args->{'add_entries'});
8280: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8281: } else {
8282: $result .=
8283: &bodytag($title,
8284: $args->{'function'}, $args->{'add_entries'},
8285: $args->{'only_body'}, $args->{'domain'},
8286: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 8287: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 8288: $args, \@advtools);
1.831 bisitz 8289: }
1.330 albertel 8290: }
1.338 albertel 8291:
1.315 albertel 8292: if ($args->{'js_ready'}) {
1.713 kaisler 8293: $result = &js_ready($result);
1.315 albertel 8294: }
1.320 albertel 8295: if ($args->{'html_encode'}) {
1.713 kaisler 8296: $result = &html_encode($result);
8297: }
8298:
1.813 bisitz 8299: # Preparation for new and consistent functionlist at top of screen
8300: # if ($args->{'functionlist'}) {
8301: # $result .= &build_functionlist();
8302: #}
8303:
1.964 droeschl 8304: # Don't add anything more if only_body wanted or in const space
8305: return $result if $args->{'only_body'}
8306: || $env{'request.state'} eq 'construct';
1.813 bisitz 8307:
8308: #Breadcrumbs
1.758 kaisler 8309: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8310: &Apache::lonhtmlcommon::clear_breadcrumbs();
8311: #if any br links exists, add them to the breadcrumbs
8312: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8313: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8314: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8315: }
8316: }
1.1075.2.19 raeburn 8317: # if @advtools array contains items add then to the breadcrumbs
8318: if (@advtools > 0) {
8319: &Apache::lonmenu::advtools_crumbs(@advtools);
8320: }
1.1075.2.123 raeburn 8321: my $menulink;
8322: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8323: if (exists($args->{'bread_crumbs_nomenu'})) {
8324: $menulink = 0;
8325: } else {
8326: undef($menulink);
8327: }
1.758 kaisler 8328: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8329: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 8330: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.758 kaisler 8331: }else{
1.1075.2.123 raeburn 8332: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8333: }
1.1075.2.24 raeburn 8334: } elsif (($env{'environment.remote'} eq 'on') &&
8335: ($env{'form.inhibitmenu'} ne 'yes') &&
8336: ($env{'request.noversionuri'} =~ m{^/res/}) &&
8337: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 8338: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 8339: }
1.315 albertel 8340: return $result;
1.306 albertel 8341: }
8342:
8343: sub end_page {
1.315 albertel 8344: my ($args) = @_;
8345: $env{'internal.end_page'}++;
1.330 albertel 8346: my $result;
1.335 albertel 8347: if ($args->{'discussion'}) {
8348: my ($target,$parser);
8349: if (ref($args->{'discussion'})) {
8350: ($target,$parser) =($args->{'discussion'}{'target'},
8351: $args->{'discussion'}{'parser'});
8352: }
8353: $result .= &Apache::lonxml::xmlend($target,$parser);
8354: }
1.330 albertel 8355: if ($args->{'frameset'}) {
8356: $result .= '</frameset>';
8357: } else {
1.635 raeburn 8358: $result .= &endbodytag($args);
1.330 albertel 8359: }
1.1075.2.6 raeburn 8360: unless ($args->{'notbody'}) {
8361: $result .= "\n</html>";
8362: }
1.330 albertel 8363:
1.315 albertel 8364: if ($args->{'js_ready'}) {
1.317 albertel 8365: $result = &js_ready($result);
1.315 albertel 8366: }
1.335 albertel 8367:
1.320 albertel 8368: if ($args->{'html_encode'}) {
8369: $result = &html_encode($result);
8370: }
1.335 albertel 8371:
1.315 albertel 8372: return $result;
8373: }
8374:
1.1034 www 8375: sub wishlist_window {
8376: return(<<'ENDWISHLIST');
1.1046 raeburn 8377: <script type="text/javascript">
1.1034 www 8378: // <![CDATA[
8379: // <!-- BEGIN LON-CAPA Internal
8380: function set_wishlistlink(title, path) {
8381: if (!title) {
8382: title = document.title;
8383: title = title.replace(/^LON-CAPA /,'');
8384: }
1.1075.2.65 raeburn 8385: title = encodeURIComponent(title);
1.1075.2.83 raeburn 8386: title = title.replace("'","\\\'");
1.1034 www 8387: if (!path) {
8388: path = location.pathname;
8389: }
1.1075.2.65 raeburn 8390: path = encodeURIComponent(path);
1.1075.2.83 raeburn 8391: path = path.replace("'","\\\'");
1.1034 www 8392: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8393: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8394: }
8395: // END LON-CAPA Internal -->
8396: // ]]>
8397: </script>
8398: ENDWISHLIST
8399: }
8400:
1.1030 www 8401: sub modal_window {
8402: return(<<'ENDMODAL');
1.1046 raeburn 8403: <script type="text/javascript">
1.1030 www 8404: // <![CDATA[
8405: // <!-- BEGIN LON-CAPA Internal
8406: var modalWindow = {
8407: parent:"body",
8408: windowId:null,
8409: content:null,
8410: width:null,
8411: height:null,
8412: close:function()
8413: {
8414: $(".LCmodal-window").remove();
8415: $(".LCmodal-overlay").remove();
8416: },
8417: open:function()
8418: {
8419: var modal = "";
8420: modal += "<div class=\"LCmodal-overlay\"></div>";
8421: 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;\">";
8422: modal += this.content;
8423: modal += "</div>";
8424:
8425: $(this.parent).append(modal);
8426:
8427: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8428: $(".LCclose-window").click(function(){modalWindow.close();});
8429: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8430: }
8431: };
1.1075.2.42 raeburn 8432: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8433: {
1.1075.2.119 raeburn 8434: source = source.replace(/'/g,"'");
1.1030 www 8435: modalWindow.windowId = "myModal";
8436: modalWindow.width = width;
8437: modalWindow.height = height;
1.1075.2.80 raeburn 8438: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8439: modalWindow.open();
1.1075.2.87 raeburn 8440: };
1.1030 www 8441: // END LON-CAPA Internal -->
8442: // ]]>
8443: </script>
8444: ENDMODAL
8445: }
8446:
8447: sub modal_link {
1.1075.2.42 raeburn 8448: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8449: unless ($width) { $width=480; }
8450: unless ($height) { $height=400; }
1.1031 www 8451: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 8452: unless ($transparency) { $transparency='true'; }
8453:
1.1074 raeburn 8454: my $target_attr;
8455: if (defined($target)) {
8456: $target_attr = 'target="'.$target.'"';
8457: }
8458: return <<"ENDLINK";
1.1075.2.143 raeburn 8459: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 8460: ENDLINK
1.1030 www 8461: }
8462:
1.1032 www 8463: sub modal_adhoc_script {
8464: my ($funcname,$width,$height,$content)=@_;
8465: return (<<ENDADHOC);
1.1046 raeburn 8466: <script type="text/javascript">
1.1032 www 8467: // <![CDATA[
8468: var $funcname = function()
8469: {
8470: modalWindow.windowId = "myModal";
8471: modalWindow.width = $width;
8472: modalWindow.height = $height;
8473: modalWindow.content = '$content';
8474: modalWindow.open();
8475: };
8476: // ]]>
8477: </script>
8478: ENDADHOC
8479: }
8480:
1.1041 www 8481: sub modal_adhoc_inner {
8482: my ($funcname,$width,$height,$content)=@_;
8483: my $innerwidth=$width-20;
8484: $content=&js_ready(
1.1042 www 8485: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 8486: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8487: $content.
1.1041 www 8488: &end_scrollbox().
1.1075.2.42 raeburn 8489: &end_page()
1.1041 www 8490: );
8491: return &modal_adhoc_script($funcname,$width,$height,$content);
8492: }
8493:
8494: sub modal_adhoc_window {
8495: my ($funcname,$width,$height,$content,$linktext)=@_;
8496: return &modal_adhoc_inner($funcname,$width,$height,$content).
8497: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8498: }
8499:
8500: sub modal_adhoc_launch {
8501: my ($funcname,$width,$height,$content)=@_;
8502: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8503: <script type="text/javascript">
8504: // <![CDATA[
8505: $funcname();
8506: // ]]>
8507: </script>
8508: ENDLAUNCH
8509: }
8510:
8511: sub modal_adhoc_close {
8512: return (<<ENDCLOSE);
8513: <script type="text/javascript">
8514: // <![CDATA[
8515: modalWindow.close();
8516: // ]]>
8517: </script>
8518: ENDCLOSE
8519: }
8520:
1.1038 www 8521: sub togglebox_script {
8522: return(<<ENDTOGGLE);
8523: <script type="text/javascript">
8524: // <![CDATA[
8525: function LCtoggleDisplay(id,hidetext,showtext) {
8526: link = document.getElementById(id + "link").childNodes[0];
8527: with (document.getElementById(id).style) {
8528: if (display == "none" ) {
8529: display = "inline";
8530: link.nodeValue = hidetext;
8531: } else {
8532: display = "none";
8533: link.nodeValue = showtext;
8534: }
8535: }
8536: }
8537: // ]]>
8538: </script>
8539: ENDTOGGLE
8540: }
8541:
1.1039 www 8542: sub start_togglebox {
8543: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8544: unless ($heading) { $heading=''; } else { $heading.=' '; }
8545: unless ($showtext) { $showtext=&mt('show'); }
8546: unless ($hidetext) { $hidetext=&mt('hide'); }
8547: unless ($headerbg) { $headerbg='#FFFFFF'; }
8548: return &start_data_table().
8549: &start_data_table_header_row().
8550: '<td bgcolor="'.$headerbg.'">'.$heading.
8551: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8552: $showtext.'\')">'.$showtext.'</a>]</td>'.
8553: &end_data_table_header_row().
8554: '<tr id="'.$id.'" style="display:none""><td>';
8555: }
8556:
8557: sub end_togglebox {
8558: return '</td></tr>'.&end_data_table();
8559: }
8560:
1.1041 www 8561: sub LCprogressbar_script {
1.1075.2.130 raeburn 8562: my ($id,$number_to_do)=@_;
8563: if ($number_to_do) {
8564: return(<<ENDPROGRESS);
1.1041 www 8565: <script type="text/javascript">
8566: // <![CDATA[
1.1045 www 8567: \$('#progressbar$id').progressbar({
1.1041 www 8568: value: 0,
8569: change: function(event, ui) {
8570: var newVal = \$(this).progressbar('option', 'value');
8571: \$('.pblabel', this).text(LCprogressTxt);
8572: }
8573: });
8574: // ]]>
8575: </script>
8576: ENDPROGRESS
1.1075.2.130 raeburn 8577: } else {
8578: return(<<ENDPROGRESS);
8579: <script type="text/javascript">
8580: // <![CDATA[
8581: \$('#progressbar$id').progressbar({
8582: value: false,
8583: create: function(event, ui) {
8584: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
8585: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
8586: }
8587: });
8588: // ]]>
8589: </script>
8590: ENDPROGRESS
8591: }
1.1041 www 8592: }
8593:
8594: sub LCprogressbarUpdate_script {
8595: return(<<ENDPROGRESSUPDATE);
8596: <style type="text/css">
8597: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 8598: .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 8599: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8600: </style>
8601: <script type="text/javascript">
8602: // <![CDATA[
1.1045 www 8603: var LCprogressTxt='---';
8604:
1.1075.2.130 raeburn 8605: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 8606: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 8607: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
8608: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
8609: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
8610: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
8611: } else {
8612: \$('#progressbar'+id).progressbar('value',percent);
8613: }
1.1041 www 8614: }
8615: // ]]>
8616: </script>
8617: ENDPROGRESSUPDATE
8618: }
8619:
1.1042 www 8620: my $LClastpercent;
1.1045 www 8621: my $LCidcnt;
8622: my $LCcurrentid;
1.1042 www 8623:
1.1041 www 8624: sub LCprogressbar {
1.1075.2.130 raeburn 8625: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 8626: $LClastpercent=0;
1.1045 www 8627: $LCidcnt++;
8628: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 8629: my ($starting,$content);
8630: if ($number_to_do) {
8631: $starting=&mt('Starting');
8632: $content=(<<ENDPROGBAR);
8633: $preamble
1.1045 www 8634: <div id="progressbar$LCcurrentid">
1.1041 www 8635: <span class="pblabel">$starting</span>
8636: </div>
8637: ENDPROGBAR
1.1075.2.130 raeburn 8638: } else {
8639: $starting=&mt('Loading...');
8640: $LClastpercent='false';
8641: $content=(<<ENDPROGBAR);
8642: $preamble
8643: <div id="progressbar$LCcurrentid">
8644: <div class="progress-label">$starting</div>
8645: </div>
8646: ENDPROGBAR
8647: }
8648: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 8649: }
8650:
8651: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 8652: my ($r,$val,$text,$number_to_do)=@_;
8653: if ($number_to_do) {
8654: unless ($val) {
8655: if ($LClastpercent) {
8656: $val=$LClastpercent;
8657: } else {
8658: $val=0;
8659: }
8660: }
8661: if ($val<0) { $val=0; }
8662: if ($val>100) { $val=0; }
8663: $LClastpercent=$val;
8664: unless ($text) { $text=$val.'%'; }
8665: } else {
8666: $val = 'false';
1.1042 www 8667: }
1.1041 www 8668: $text=&js_ready($text);
1.1044 www 8669: &r_print($r,<<ENDUPDATE);
1.1041 www 8670: <script type="text/javascript">
8671: // <![CDATA[
1.1075.2.130 raeburn 8672: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 8673: // ]]>
8674: </script>
8675: ENDUPDATE
1.1035 www 8676: }
8677:
1.1042 www 8678: sub LCprogressbarClose {
8679: my ($r)=@_;
8680: $LClastpercent=0;
1.1044 www 8681: &r_print($r,<<ENDCLOSE);
1.1042 www 8682: <script type="text/javascript">
8683: // <![CDATA[
1.1045 www 8684: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8685: // ]]>
8686: </script>
8687: ENDCLOSE
1.1044 www 8688: }
8689:
8690: sub r_print {
8691: my ($r,$to_print)=@_;
8692: if ($r) {
8693: $r->print($to_print);
8694: $r->rflush();
8695: } else {
8696: print($to_print);
8697: }
1.1042 www 8698: }
8699:
1.320 albertel 8700: sub html_encode {
8701: my ($result) = @_;
8702:
1.322 albertel 8703: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8704:
8705: return $result;
8706: }
1.1044 www 8707:
1.317 albertel 8708: sub js_ready {
8709: my ($result) = @_;
8710:
1.323 albertel 8711: $result =~ s/[\n\r]/ /xmsg;
8712: $result =~ s/\\/\\\\/xmsg;
8713: $result =~ s/'/\\'/xmsg;
1.372 albertel 8714: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8715:
8716: return $result;
8717: }
8718:
1.315 albertel 8719: sub validate_page {
8720: if ( exists($env{'internal.start_page'})
1.316 albertel 8721: && $env{'internal.start_page'} > 1) {
8722: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8723: $env{'internal.start_page'}.' '.
1.316 albertel 8724: $ENV{'request.filename'});
1.315 albertel 8725: }
8726: if ( exists($env{'internal.end_page'})
1.316 albertel 8727: && $env{'internal.end_page'} > 1) {
8728: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8729: $env{'internal.end_page'}.' '.
1.316 albertel 8730: $env{'request.filename'});
1.315 albertel 8731: }
8732: if ( exists($env{'internal.start_page'})
8733: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8734: &Apache::lonnet::logthis('start_page called without end_page '.
8735: $env{'request.filename'});
1.315 albertel 8736: }
8737: if ( ! exists($env{'internal.start_page'})
8738: && exists($env{'internal.end_page'})) {
1.316 albertel 8739: &Apache::lonnet::logthis('end_page called without start_page'.
8740: $env{'request.filename'});
1.315 albertel 8741: }
1.306 albertel 8742: }
1.315 albertel 8743:
1.996 www 8744:
8745: sub start_scrollbox {
1.1075.2.56 raeburn 8746: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8747: unless ($outerwidth) { $outerwidth='520px'; }
8748: unless ($width) { $width='500px'; }
8749: unless ($height) { $height='200px'; }
1.1075 raeburn 8750: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8751: if ($id ne '') {
1.1075.2.42 raeburn 8752: $table_id = ' id="table_'.$id.'"';
8753: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8754: }
1.1075 raeburn 8755: if ($bgcolor ne '') {
8756: $tdcol = "background-color: $bgcolor;";
8757: }
1.1075.2.42 raeburn 8758: my $nicescroll_js;
8759: if ($env{'browser.mobile'}) {
8760: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8761: }
1.1075 raeburn 8762: return <<"END";
1.1075.2.42 raeburn 8763: $nicescroll_js
8764:
8765: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8766: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8767: END
1.996 www 8768: }
8769:
8770: sub end_scrollbox {
1.1036 www 8771: return '</div></td></tr></table>';
1.996 www 8772: }
8773:
1.1075.2.42 raeburn 8774: sub nicescroll_javascript {
8775: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8776: my %options;
8777: if (ref($cursor) eq 'HASH') {
8778: %options = %{$cursor};
8779: }
8780: unless ($options{'railalign'} =~ /^left|right$/) {
8781: $options{'railalign'} = 'left';
8782: }
8783: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8784: my $function = &get_users_function();
8785: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8786: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8787: $options{'cursorcolor'} = '#00F';
8788: }
8789: }
8790: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8791: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8792: $options{'cursoropacity'}='1.0';
8793: }
8794: } else {
8795: $options{'cursoropacity'}='1.0';
8796: }
8797: if ($options{'cursorfixedheight'} eq 'none') {
8798: delete($options{'cursorfixedheight'});
8799: } else {
8800: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8801: }
8802: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8803: delete($options{'railoffset'});
8804: }
8805: my @niceoptions;
8806: while (my($key,$value) = each(%options)) {
8807: if ($value =~ /^\{.+\}$/) {
8808: push(@niceoptions,$key.':'.$value);
8809: } else {
8810: push(@niceoptions,$key.':"'.$value.'"');
8811: }
8812: }
8813: my $nicescroll_js = '
8814: $(document).ready(
8815: function() {
8816: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8817: }
8818: );
8819: ';
8820: if ($framecheck) {
8821: $nicescroll_js .= '
8822: function expand_div(caller) {
8823: if (top === self) {
8824: document.getElementById("'.$id.'").style.width = "auto";
8825: document.getElementById("'.$id.'").style.height = "auto";
8826: } else {
8827: try {
8828: if (parent.frames) {
8829: if (parent.frames.length > 1) {
8830: var framesrc = parent.frames[1].location.href;
8831: var currsrc = framesrc.replace(/\#.*$/,"");
8832: if ((caller == "search") || (currsrc == "'.$location.'")) {
8833: document.getElementById("'.$id.'").style.width = "auto";
8834: document.getElementById("'.$id.'").style.height = "auto";
8835: }
8836: }
8837: }
8838: } catch (e) {
8839: return;
8840: }
8841: }
8842: return;
8843: }
8844: ';
8845: }
8846: if ($needjsready) {
8847: $nicescroll_js = '
8848: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8849: } else {
8850: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8851: }
8852: return $nicescroll_js;
8853: }
8854:
1.318 albertel 8855: sub simple_error_page {
1.1075.2.49 raeburn 8856: my ($r,$title,$msg,$args) = @_;
8857: if (ref($args) eq 'HASH') {
8858: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8859: } else {
8860: $msg = &mt($msg);
8861: }
8862:
1.318 albertel 8863: my $page =
8864: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8865: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8866: &Apache::loncommon::end_page();
8867: if (ref($r)) {
8868: $r->print($page);
1.327 albertel 8869: return;
1.318 albertel 8870: }
8871: return $page;
8872: }
1.347 albertel 8873:
8874: {
1.610 albertel 8875: my @row_count;
1.961 onken 8876:
8877: sub start_data_table_count {
8878: unshift(@row_count, 0);
8879: return;
8880: }
8881:
8882: sub end_data_table_count {
8883: shift(@row_count);
8884: return;
8885: }
8886:
1.347 albertel 8887: sub start_data_table {
1.1018 raeburn 8888: my ($add_class,$id) = @_;
1.422 albertel 8889: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8890: my $table_id;
8891: if (defined($id)) {
8892: $table_id = ' id="'.$id.'"';
8893: }
1.961 onken 8894: &start_data_table_count();
1.1018 raeburn 8895: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8896: }
8897:
8898: sub end_data_table {
1.961 onken 8899: &end_data_table_count();
1.389 albertel 8900: return '</table>'."\n";;
1.347 albertel 8901: }
8902:
8903: sub start_data_table_row {
1.974 wenzelju 8904: my ($add_class, $id) = @_;
1.610 albertel 8905: $row_count[0]++;
8906: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8907: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8908: $id = (' id="'.$id.'"') unless ($id eq '');
8909: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8910: }
1.471 banghart 8911:
8912: sub continue_data_table_row {
1.974 wenzelju 8913: my ($add_class, $id) = @_;
1.610 albertel 8914: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8915: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8916: $id = (' id="'.$id.'"') unless ($id eq '');
8917: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8918: }
1.347 albertel 8919:
8920: sub end_data_table_row {
1.389 albertel 8921: return '</tr>'."\n";;
1.347 albertel 8922: }
1.367 www 8923:
1.421 albertel 8924: sub start_data_table_empty_row {
1.707 bisitz 8925: # $row_count[0]++;
1.421 albertel 8926: return '<tr class="LC_empty_row" >'."\n";;
8927: }
8928:
8929: sub end_data_table_empty_row {
8930: return '</tr>'."\n";;
8931: }
8932:
1.367 www 8933: sub start_data_table_header_row {
1.389 albertel 8934: return '<tr class="LC_header_row">'."\n";;
1.367 www 8935: }
8936:
8937: sub end_data_table_header_row {
1.389 albertel 8938: return '</tr>'."\n";;
1.367 www 8939: }
1.890 droeschl 8940:
8941: sub data_table_caption {
8942: my $caption = shift;
8943: return "<caption class=\"LC_caption\">$caption</caption>";
8944: }
1.347 albertel 8945: }
8946:
1.548 albertel 8947: =pod
8948:
8949: =item * &inhibit_menu_check($arg)
8950:
8951: Checks for a inhibitmenu state and generates output to preserve it
8952:
8953: Inputs: $arg - can be any of
8954: - undef - in which case the return value is a string
8955: to add into arguments list of a uri
8956: - 'input' - in which case the return value is a HTML
8957: <form> <input> field of type hidden to
8958: preserve the value
8959: - a url - in which case the return value is the url with
8960: the neccesary cgi args added to preserve the
8961: inhibitmenu state
8962: - a ref to a url - no return value, but the string is
8963: updated to include the neccessary cgi
8964: args to preserve the inhibitmenu state
8965:
8966: =cut
8967:
8968: sub inhibit_menu_check {
8969: my ($arg) = @_;
8970: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8971: if ($arg eq 'input') {
8972: if ($env{'form.inhibitmenu'}) {
8973: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8974: } else {
8975: return
8976: }
8977: }
8978: if ($env{'form.inhibitmenu'}) {
8979: if (ref($arg)) {
8980: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8981: } elsif ($arg eq '') {
8982: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8983: } else {
8984: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8985: }
8986: }
8987: if (!ref($arg)) {
8988: return $arg;
8989: }
8990: }
8991:
1.251 albertel 8992: ###############################################
1.182 matthew 8993:
8994: =pod
8995:
1.549 albertel 8996: =back
8997:
8998: =head1 User Information Routines
8999:
9000: =over 4
9001:
1.405 albertel 9002: =item * &get_users_function()
1.182 matthew 9003:
9004: Used by &bodytag to determine the current users primary role.
9005: Returns either 'student','coordinator','admin', or 'author'.
9006:
9007: =cut
9008:
9009: ###############################################
9010: sub get_users_function {
1.815 tempelho 9011: my $function = 'norole';
1.818 tempelho 9012: if ($env{'request.role'}=~/^(st)/) {
9013: $function='student';
9014: }
1.907 raeburn 9015: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9016: $function='coordinator';
9017: }
1.258 albertel 9018: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9019: $function='admin';
9020: }
1.826 bisitz 9021: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9022: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9023: $function='author';
9024: }
9025: return $function;
1.54 www 9026: }
1.99 www 9027:
9028: ###############################################
9029:
1.233 raeburn 9030: =pod
9031:
1.821 raeburn 9032: =item * &show_course()
9033:
9034: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9035: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9036:
9037: Inputs:
9038: None
9039:
9040: Outputs:
9041: Scalar: 1 if 'Course' to be used, 0 otherwise.
9042:
9043: =cut
9044:
9045: ###############################################
9046: sub show_course {
9047: my $course = !$env{'user.adv'};
9048: if (!$env{'user.adv'}) {
9049: foreach my $env (keys(%env)) {
9050: next if ($env !~ m/^user\.priv\./);
9051: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9052: $course = 0;
9053: last;
9054: }
9055: }
9056: }
9057: return $course;
9058: }
9059:
9060: ###############################################
9061:
9062: =pod
9063:
1.542 raeburn 9064: =item * &check_user_status()
1.274 raeburn 9065:
9066: Determines current status of supplied role for a
9067: specific user. Roles can be active, previous or future.
9068:
9069: Inputs:
9070: user's domain, user's username, course's domain,
1.375 raeburn 9071: course's number, optional section ID.
1.274 raeburn 9072:
9073: Outputs:
9074: role status: active, previous or future.
9075:
9076: =cut
9077:
9078: sub check_user_status {
1.412 raeburn 9079: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9080: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 9081: my @uroles = keys(%userinfo);
1.274 raeburn 9082: my $srchstr;
9083: my $active_chk = 'none';
1.412 raeburn 9084: my $now = time;
1.274 raeburn 9085: if (@uroles > 0) {
1.908 raeburn 9086: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9087: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9088: } else {
1.412 raeburn 9089: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9090: }
9091: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9092: my $role_end = 0;
9093: my $role_start = 0;
9094: $active_chk = 'active';
1.412 raeburn 9095: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9096: $role_end = $1;
9097: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9098: $role_start = $1;
1.274 raeburn 9099: }
9100: }
9101: if ($role_start > 0) {
1.412 raeburn 9102: if ($now < $role_start) {
1.274 raeburn 9103: $active_chk = 'future';
9104: }
9105: }
9106: if ($role_end > 0) {
1.412 raeburn 9107: if ($now > $role_end) {
1.274 raeburn 9108: $active_chk = 'previous';
9109: }
9110: }
9111: }
9112: }
9113: return $active_chk;
9114: }
9115:
9116: ###############################################
9117:
9118: =pod
9119:
1.405 albertel 9120: =item * &get_sections()
1.233 raeburn 9121:
9122: Determines all the sections for a course including
9123: sections with students and sections containing other roles.
1.419 raeburn 9124: Incoming parameters:
9125:
9126: 1. domain
9127: 2. course number
9128: 3. reference to array containing roles for which sections should
9129: be gathered (optional).
9130: 4. reference to array containing status types for which sections
9131: should be gathered (optional).
9132:
9133: If the third argument is undefined, sections are gathered for any role.
9134: If the fourth argument is undefined, sections are gathered for any status.
9135: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9136:
1.374 raeburn 9137: Returns section hash (keys are section IDs, values are
9138: number of users in each section), subject to the
1.419 raeburn 9139: optional roles filter, optional status filter
1.233 raeburn 9140:
9141: =cut
9142:
9143: ###############################################
9144: sub get_sections {
1.419 raeburn 9145: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9146: if (!defined($cdom) || !defined($cnum)) {
9147: my $cid = $env{'request.course.id'};
9148:
9149: return if (!defined($cid));
9150:
9151: $cdom = $env{'course.'.$cid.'.domain'};
9152: $cnum = $env{'course.'.$cid.'.num'};
9153: }
9154:
9155: my %sectioncount;
1.419 raeburn 9156: my $now = time;
1.240 albertel 9157:
1.1075.2.33 raeburn 9158: my $check_students = 1;
9159: my $only_students = 0;
9160: if (ref($possible_roles) eq 'ARRAY') {
9161: if (grep(/^st$/,@{$possible_roles})) {
9162: if (@{$possible_roles} == 1) {
9163: $only_students = 1;
9164: }
9165: } else {
9166: $check_students = 0;
9167: }
9168: }
9169:
9170: if ($check_students) {
1.276 albertel 9171: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9172: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9173: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9174: my $start_index = &Apache::loncoursedata::CL_START();
9175: my $end_index = &Apache::loncoursedata::CL_END();
9176: my $status;
1.366 albertel 9177: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9178: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9179: $data->[$status_index],
9180: $data->[$start_index],
9181: $data->[$end_index]);
9182: if ($stu_status eq 'Active') {
9183: $status = 'active';
9184: } elsif ($end < $now) {
9185: $status = 'previous';
9186: } elsif ($start > $now) {
9187: $status = 'future';
9188: }
9189: if ($section ne '-1' && $section !~ /^\s*$/) {
9190: if ((!defined($possible_status)) || (($status ne '') &&
9191: (grep/^\Q$status\E$/,@{$possible_status}))) {
9192: $sectioncount{$section}++;
9193: }
1.240 albertel 9194: }
9195: }
9196: }
1.1075.2.33 raeburn 9197: if ($only_students) {
9198: return %sectioncount;
9199: }
1.240 albertel 9200: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9201: foreach my $user (sort(keys(%courseroles))) {
9202: if ($user !~ /^(\w{2})/) { next; }
9203: my ($role) = ($user =~ /^(\w{2})/);
9204: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9205: my ($section,$status);
1.240 albertel 9206: if ($role eq 'cr' &&
9207: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9208: $section=$1;
9209: }
9210: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9211: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9212: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9213: if ($end == -1 && $start == -1) {
9214: next; #deleted role
9215: }
9216: if (!defined($possible_status)) {
9217: $sectioncount{$section}++;
9218: } else {
9219: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9220: $status = 'active';
9221: } elsif ($end < $now) {
9222: $status = 'future';
9223: } elsif ($start > $now) {
9224: $status = 'previous';
9225: }
9226: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9227: $sectioncount{$section}++;
9228: }
9229: }
1.233 raeburn 9230: }
1.366 albertel 9231: return %sectioncount;
1.233 raeburn 9232: }
9233:
1.274 raeburn 9234: ###############################################
1.294 raeburn 9235:
9236: =pod
1.405 albertel 9237:
9238: =item * &get_course_users()
9239:
1.275 raeburn 9240: Retrieves usernames:domains for users in the specified course
9241: with specific role(s), and access status.
9242:
9243: Incoming parameters:
1.277 albertel 9244: 1. course domain
9245: 2. course number
9246: 3. access status: users must have - either active,
1.275 raeburn 9247: previous, future, or all.
1.277 albertel 9248: 4. reference to array of permissible roles
1.288 raeburn 9249: 5. reference to array of section restrictions (optional)
9250: 6. reference to results object (hash of hashes).
9251: 7. reference to optional userdata hash
1.609 raeburn 9252: 8. reference to optional statushash
1.630 raeburn 9253: 9. flag if privileged users (except those set to unhide in
9254: course settings) should be excluded
1.609 raeburn 9255: Keys of top level results hash are roles.
1.275 raeburn 9256: Keys of inner hashes are username:domain, with
9257: values set to access type.
1.288 raeburn 9258: Optional userdata hash returns an array with arguments in the
9259: same order as loncoursedata::get_classlist() for student data.
9260:
1.609 raeburn 9261: Optional statushash returns
9262:
1.288 raeburn 9263: Entries for end, start, section and status are blank because
9264: of the possibility of multiple values for non-student roles.
9265:
1.275 raeburn 9266: =cut
1.405 albertel 9267:
1.275 raeburn 9268: ###############################################
1.405 albertel 9269:
1.275 raeburn 9270: sub get_course_users {
1.630 raeburn 9271: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9272: my %idx = ();
1.419 raeburn 9273: my %seclists;
1.288 raeburn 9274:
9275: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9276: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9277: $idx{end} = &Apache::loncoursedata::CL_END();
9278: $idx{start} = &Apache::loncoursedata::CL_START();
9279: $idx{id} = &Apache::loncoursedata::CL_ID();
9280: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9281: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9282: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9283:
1.290 albertel 9284: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9285: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9286: my $now = time;
1.277 albertel 9287: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9288: my $match = 0;
1.412 raeburn 9289: my $secmatch = 0;
1.419 raeburn 9290: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9291: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9292: if ($section eq '') {
9293: $section = 'none';
9294: }
1.291 albertel 9295: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9296: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9297: $secmatch = 1;
9298: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9299: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9300: $secmatch = 1;
9301: }
9302: } else {
1.419 raeburn 9303: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9304: $secmatch = 1;
9305: }
1.290 albertel 9306: }
1.412 raeburn 9307: if (!$secmatch) {
9308: next;
9309: }
1.419 raeburn 9310: }
1.275 raeburn 9311: if (defined($$types{'active'})) {
1.288 raeburn 9312: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9313: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9314: $match = 1;
1.275 raeburn 9315: }
9316: }
9317: if (defined($$types{'previous'})) {
1.609 raeburn 9318: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9319: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9320: $match = 1;
1.275 raeburn 9321: }
9322: }
9323: if (defined($$types{'future'})) {
1.609 raeburn 9324: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9325: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9326: $match = 1;
1.275 raeburn 9327: }
9328: }
1.609 raeburn 9329: if ($match) {
9330: push(@{$seclists{$student}},$section);
9331: if (ref($userdata) eq 'HASH') {
9332: $$userdata{$student} = $$classlist{$student};
9333: }
9334: if (ref($statushash) eq 'HASH') {
9335: $statushash->{$student}{'st'}{$section} = $status;
9336: }
1.288 raeburn 9337: }
1.275 raeburn 9338: }
9339: }
1.412 raeburn 9340: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9341: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9342: my $now = time;
1.609 raeburn 9343: my %displaystatus = ( previous => 'Expired',
9344: active => 'Active',
9345: future => 'Future',
9346: );
1.1075.2.36 raeburn 9347: my (%nothide,@possdoms);
1.630 raeburn 9348: if ($hidepriv) {
9349: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9350: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9351: if ($user !~ /:/) {
9352: $nothide{join(':',split(/[\@]/,$user))}=1;
9353: } else {
9354: $nothide{$user} = 1;
9355: }
9356: }
1.1075.2.36 raeburn 9357: my @possdoms = ($cdom);
9358: if ($coursehash{'checkforpriv'}) {
9359: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9360: }
1.630 raeburn 9361: }
1.439 raeburn 9362: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9363: my $match = 0;
1.412 raeburn 9364: my $secmatch = 0;
1.439 raeburn 9365: my $status;
1.412 raeburn 9366: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9367: $user =~ s/:$//;
1.439 raeburn 9368: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9369: if ($end == -1 || $start == -1) {
9370: next;
9371: }
9372: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9373: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9374: my ($uname,$udom) = split(/:/,$user);
9375: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9376: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9377: $secmatch = 1;
9378: } elsif ($usec eq '') {
1.420 albertel 9379: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9380: $secmatch = 1;
9381: }
9382: } else {
9383: if (grep(/^\Q$usec\E$/,@{$sections})) {
9384: $secmatch = 1;
9385: }
9386: }
9387: if (!$secmatch) {
9388: next;
9389: }
1.288 raeburn 9390: }
1.419 raeburn 9391: if ($usec eq '') {
9392: $usec = 'none';
9393: }
1.275 raeburn 9394: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9395: if ($hidepriv) {
1.1075.2.36 raeburn 9396: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9397: (!$nothide{$uname.':'.$udom})) {
9398: next;
9399: }
9400: }
1.503 raeburn 9401: if ($end > 0 && $end < $now) {
1.439 raeburn 9402: $status = 'previous';
9403: } elsif ($start > $now) {
9404: $status = 'future';
9405: } else {
9406: $status = 'active';
9407: }
1.277 albertel 9408: foreach my $type (keys(%{$types})) {
1.275 raeburn 9409: if ($status eq $type) {
1.420 albertel 9410: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9411: push(@{$$users{$role}{$user}},$type);
9412: }
1.288 raeburn 9413: $match = 1;
9414: }
9415: }
1.419 raeburn 9416: if (($match) && (ref($userdata) eq 'HASH')) {
9417: if (!exists($$userdata{$uname.':'.$udom})) {
9418: &get_user_info($udom,$uname,\%idx,$userdata);
9419: }
1.420 albertel 9420: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9421: push(@{$seclists{$uname.':'.$udom}},$usec);
9422: }
1.609 raeburn 9423: if (ref($statushash) eq 'HASH') {
9424: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9425: }
1.275 raeburn 9426: }
9427: }
9428: }
9429: }
1.290 albertel 9430: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9431: if ((defined($cdom)) && (defined($cnum))) {
9432: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9433: if ( defined($csettings{'internal.courseowner'}) ) {
9434: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9435: next if ($owner eq '');
9436: my ($ownername,$ownerdom);
9437: if ($owner =~ /^([^:]+):([^:]+)$/) {
9438: $ownername = $1;
9439: $ownerdom = $2;
9440: } else {
9441: $ownername = $owner;
9442: $ownerdom = $cdom;
9443: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9444: }
9445: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9446: if (defined($userdata) &&
1.609 raeburn 9447: !exists($$userdata{$owner})) {
9448: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9449: if (!grep(/^none$/,@{$seclists{$owner}})) {
9450: push(@{$seclists{$owner}},'none');
9451: }
9452: if (ref($statushash) eq 'HASH') {
9453: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9454: }
1.290 albertel 9455: }
1.279 raeburn 9456: }
9457: }
9458: }
1.419 raeburn 9459: foreach my $user (keys(%seclists)) {
9460: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9461: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9462: }
1.275 raeburn 9463: }
9464: return;
9465: }
9466:
1.288 raeburn 9467: sub get_user_info {
9468: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9469: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9470: &plainname($uname,$udom,'lastname');
1.291 albertel 9471: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9472: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9473: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9474: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9475: return;
9476: }
1.275 raeburn 9477:
1.472 raeburn 9478: ###############################################
9479:
9480: =pod
9481:
9482: =item * &get_user_quota()
9483:
1.1075.2.41 raeburn 9484: Retrieves quota assigned for storage of user files.
9485: Default is to report quota for portfolio files.
1.472 raeburn 9486:
9487: Incoming parameters:
9488: 1. user's username
9489: 2. user's domain
1.1075.2.41 raeburn 9490: 3. quota name - portfolio, author, or course
9491: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 9492: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 9493: course
1.472 raeburn 9494:
9495: Returns:
1.1075.2.58 raeburn 9496: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9497: 2. (Optional) Type of setting: custom or default
9498: (individually assigned or default for user's
9499: institutional status).
9500: 3. (Optional) - User's institutional status (e.g., faculty, staff
9501: or student - types as defined in localenroll::inst_usertypes
9502: for user's domain, which determines default quota for user.
9503: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9504:
9505: If a value has been stored in the user's environment,
1.536 raeburn 9506: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 9507: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9508:
9509: =cut
9510:
9511: ###############################################
9512:
9513:
9514: sub get_user_quota {
1.1075.2.42 raeburn 9515: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9516: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9517: if (!defined($udom)) {
9518: $udom = $env{'user.domain'};
9519: }
9520: if (!defined($uname)) {
9521: $uname = $env{'user.name'};
9522: }
9523: if (($udom eq '' || $uname eq '') ||
9524: ($udom eq 'public') && ($uname eq 'public')) {
9525: $quota = 0;
1.536 raeburn 9526: $quotatype = 'default';
9527: $defquota = 0;
1.472 raeburn 9528: } else {
1.536 raeburn 9529: my $inststatus;
1.1075.2.41 raeburn 9530: if ($quotaname eq 'course') {
9531: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9532: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9533: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9534: } else {
9535: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9536: $quota = $cenv{'internal.uploadquota'};
9537: }
1.536 raeburn 9538: } else {
1.1075.2.41 raeburn 9539: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9540: if ($quotaname eq 'author') {
9541: $quota = $env{'environment.authorquota'};
9542: } else {
9543: $quota = $env{'environment.portfolioquota'};
9544: }
9545: $inststatus = $env{'environment.inststatus'};
9546: } else {
9547: my %userenv =
9548: &Apache::lonnet::get('environment',['portfolioquota',
9549: 'authorquota','inststatus'],$udom,$uname);
9550: my ($tmp) = keys(%userenv);
9551: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9552: if ($quotaname eq 'author') {
9553: $quota = $userenv{'authorquota'};
9554: } else {
9555: $quota = $userenv{'portfolioquota'};
9556: }
9557: $inststatus = $userenv{'inststatus'};
9558: } else {
9559: undef(%userenv);
9560: }
9561: }
9562: }
9563: if ($quota eq '' || wantarray) {
9564: if ($quotaname eq 'course') {
9565: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 9566: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9567: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 9568: $defquota = $domdefs{$crstype.'quota'};
9569: }
9570: if ($defquota eq '') {
9571: $defquota = 500;
9572: }
1.1075.2.41 raeburn 9573: } else {
9574: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9575: }
9576: if ($quota eq '') {
9577: $quota = $defquota;
9578: $quotatype = 'default';
9579: } else {
9580: $quotatype = 'custom';
9581: }
1.472 raeburn 9582: }
9583: }
1.536 raeburn 9584: if (wantarray) {
9585: return ($quota,$quotatype,$settingstatus,$defquota);
9586: } else {
9587: return $quota;
9588: }
1.472 raeburn 9589: }
9590:
9591: ###############################################
9592:
9593: =pod
9594:
9595: =item * &default_quota()
9596:
1.536 raeburn 9597: Retrieves default quota assigned for storage of user portfolio files,
9598: given an (optional) user's institutional status.
1.472 raeburn 9599:
9600: Incoming parameters:
1.1075.2.42 raeburn 9601:
1.472 raeburn 9602: 1. domain
1.536 raeburn 9603: 2. (Optional) institutional status(es). This is a : separated list of
9604: status types (e.g., faculty, staff, student etc.)
9605: which apply to the user for whom the default is being retrieved.
9606: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9607: default quota will be returned.
9608: 3. quota name - portfolio, author, or course
9609: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9610:
9611: Returns:
1.1075.2.42 raeburn 9612:
1.1075.2.58 raeburn 9613: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9614: 2. (Optional) institutional type which determined the value of the
9615: default quota.
1.472 raeburn 9616:
9617: If a value has been stored in the domain's configuration db,
9618: it will return that, otherwise it returns 20 (for backwards
9619: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9620: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9621:
1.536 raeburn 9622: If the user's status includes multiple types (e.g., staff and student),
9623: the largest default quota which applies to the user determines the
9624: default quota returned.
9625:
1.472 raeburn 9626: =cut
9627:
9628: ###############################################
9629:
9630:
9631: sub default_quota {
1.1075.2.41 raeburn 9632: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9633: my ($defquota,$settingstatus);
9634: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9635: ['quotas'],$udom);
1.1075.2.41 raeburn 9636: my $key = 'defaultquota';
9637: if ($quotaname eq 'author') {
9638: $key = 'authorquota';
9639: }
1.622 raeburn 9640: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9641: if ($inststatus ne '') {
1.765 raeburn 9642: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9643: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9644: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9645: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9646: if ($defquota eq '') {
1.1075.2.41 raeburn 9647: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9648: $settingstatus = $item;
1.1075.2.41 raeburn 9649: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9650: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9651: $settingstatus = $item;
9652: }
9653: }
1.1075.2.41 raeburn 9654: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9655: if ($quotahash{'quotas'}{$item} ne '') {
9656: if ($defquota eq '') {
9657: $defquota = $quotahash{'quotas'}{$item};
9658: $settingstatus = $item;
9659: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9660: $defquota = $quotahash{'quotas'}{$item};
9661: $settingstatus = $item;
9662: }
1.536 raeburn 9663: }
9664: }
9665: }
9666: }
9667: if ($defquota eq '') {
1.1075.2.41 raeburn 9668: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9669: $defquota = $quotahash{'quotas'}{$key}{'default'};
9670: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9671: $defquota = $quotahash{'quotas'}{'default'};
9672: }
1.536 raeburn 9673: $settingstatus = 'default';
1.1075.2.42 raeburn 9674: if ($defquota eq '') {
9675: if ($quotaname eq 'author') {
9676: $defquota = 500;
9677: }
9678: }
1.536 raeburn 9679: }
9680: } else {
9681: $settingstatus = 'default';
1.1075.2.41 raeburn 9682: if ($quotaname eq 'author') {
9683: $defquota = 500;
9684: } else {
9685: $defquota = 20;
9686: }
1.536 raeburn 9687: }
9688: if (wantarray) {
9689: return ($defquota,$settingstatus);
1.472 raeburn 9690: } else {
1.536 raeburn 9691: return $defquota;
1.472 raeburn 9692: }
9693: }
9694:
1.1075.2.41 raeburn 9695: ###############################################
9696:
9697: =pod
9698:
1.1075.2.42 raeburn 9699: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9700:
9701: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9702: of existing file within authoring space will cause quota for the authoring
9703: space to be exceeded.
9704:
9705: Same, if upload of a file directly to a course/community via Course Editor
9706: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9707:
1.1075.2.61 raeburn 9708: Inputs: 7
1.1075.2.42 raeburn 9709: 1. username or coursenum
1.1075.2.41 raeburn 9710: 2. domain
1.1075.2.42 raeburn 9711: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9712: 4. filename of file for which action is being requested
9713: 5. filesize (kB) of file
9714: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9715: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9716:
9717: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9718: otherwise return null.
9719:
1.1075.2.42 raeburn 9720: =back
9721:
1.1075.2.41 raeburn 9722: =cut
9723:
1.1075.2.42 raeburn 9724: sub excess_filesize_warning {
1.1075.2.59 raeburn 9725: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9726: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9727: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9728: if ($context eq 'author') {
9729: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9730: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9731: } else {
9732: foreach my $subdir ('docs','supplemental') {
9733: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9734: }
9735: }
1.1075.2.41 raeburn 9736: $disk_quota = int($disk_quota * 1000);
9737: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9738: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9739: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9740: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9741: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9742: $disk_quota,$current_disk_usage).
9743: '</p>';
9744: }
9745: return;
9746: }
9747:
9748: ###############################################
9749:
9750:
1.384 raeburn 9751: sub get_secgrprole_info {
9752: my ($cdom,$cnum,$needroles,$type) = @_;
9753: my %sections_count = &get_sections($cdom,$cnum);
9754: my @sections = (sort {$a <=> $b} keys(%sections_count));
9755: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9756: my @groups = sort(keys(%curr_groups));
9757: my $allroles = [];
9758: my $rolehash;
9759: my $accesshash = {
9760: active => 'Currently has access',
9761: future => 'Will have future access',
9762: previous => 'Previously had access',
9763: };
9764: if ($needroles) {
9765: $rolehash = {'all' => 'all'};
1.385 albertel 9766: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9767: if (&Apache::lonnet::error(%user_roles)) {
9768: undef(%user_roles);
9769: }
9770: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9771: my ($role)=split(/\:/,$item,2);
9772: if ($role eq 'cr') { next; }
9773: if ($role =~ /^cr/) {
9774: $$rolehash{$role} = (split('/',$role))[3];
9775: } else {
9776: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9777: }
9778: }
9779: foreach my $key (sort(keys(%{$rolehash}))) {
9780: push(@{$allroles},$key);
9781: }
9782: push (@{$allroles},'st');
9783: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9784: }
9785: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9786: }
9787:
1.555 raeburn 9788: sub user_picker {
1.1075.2.127 raeburn 9789: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 9790: my $currdom = $dom;
1.1075.2.114 raeburn 9791: my @alldoms = &Apache::lonnet::all_domains();
9792: if (@alldoms == 1) {
9793: my %domsrch = &Apache::lonnet::get_dom('configuration',
9794: ['directorysrch'],$alldoms[0]);
9795: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
9796: my $showdom = $domdesc;
9797: if ($showdom eq '') {
9798: $showdom = $dom;
9799: }
9800: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
9801: if ((!$domsrch{'directorysrch'}{'available'}) &&
9802: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
9803: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
9804: }
9805: }
9806: }
1.555 raeburn 9807: my %curr_selected = (
9808: srchin => 'dom',
1.580 raeburn 9809: srchby => 'lastname',
1.555 raeburn 9810: );
9811: my $srchterm;
1.625 raeburn 9812: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9813: if ($srch->{'srchby'} ne '') {
9814: $curr_selected{'srchby'} = $srch->{'srchby'};
9815: }
9816: if ($srch->{'srchin'} ne '') {
9817: $curr_selected{'srchin'} = $srch->{'srchin'};
9818: }
9819: if ($srch->{'srchtype'} ne '') {
9820: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9821: }
9822: if ($srch->{'srchdomain'} ne '') {
9823: $currdom = $srch->{'srchdomain'};
9824: }
9825: $srchterm = $srch->{'srchterm'};
9826: }
1.1075.2.98 raeburn 9827: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 9828: 'usr' => 'Search criteria',
1.563 raeburn 9829: 'doma' => 'Domain/institution to search',
1.558 albertel 9830: 'uname' => 'username',
9831: 'lastname' => 'last name',
1.555 raeburn 9832: 'lastfirst' => 'last name, first name',
1.558 albertel 9833: 'crs' => 'in this course',
1.576 raeburn 9834: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9835: 'alc' => 'all LON-CAPA',
1.573 raeburn 9836: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9837: 'exact' => 'is',
9838: 'contains' => 'contains',
1.569 raeburn 9839: 'begins' => 'begins with',
1.1075.2.98 raeburn 9840: );
9841: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 9842: 'youm' => "You must include some text to search for.",
9843: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9844: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9845: 'yomc' => "You must choose a domain when using an institutional directory search.",
9846: 'ymcd' => "You must choose a domain when using a domain search.",
9847: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9848: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9849: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9850: );
1.1075.2.98 raeburn 9851: &html_escape(\%html_lt);
9852: &js_escape(\%js_lt);
1.1075.2.115 raeburn 9853: my $domform;
1.1075.2.126 raeburn 9854: my $allow_blank = 1;
1.1075.2.115 raeburn 9855: if ($fixeddom) {
1.1075.2.126 raeburn 9856: $allow_blank = 0;
9857: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 9858: } else {
1.1075.2.126 raeburn 9859: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 9860: }
1.563 raeburn 9861: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9862:
9863: my @srchins = ('crs','dom','alc','instd');
9864:
9865: foreach my $option (@srchins) {
9866: # FIXME 'alc' option unavailable until
9867: # loncreateuser::print_user_query_page()
9868: # has been completed.
9869: next if ($option eq 'alc');
1.880 raeburn 9870: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9871: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 9872: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 9873: if ($curr_selected{'srchin'} eq $option) {
9874: $srchinsel .= '
1.1075.2.98 raeburn 9875: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 9876: } else {
9877: $srchinsel .= '
1.1075.2.98 raeburn 9878: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 9879: }
1.555 raeburn 9880: }
1.563 raeburn 9881: $srchinsel .= "\n </select>\n";
1.555 raeburn 9882:
9883: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9884: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9885: if ($curr_selected{'srchby'} eq $option) {
9886: $srchbysel .= '
1.1075.2.98 raeburn 9887: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9888: } else {
9889: $srchbysel .= '
1.1075.2.98 raeburn 9890: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9891: }
9892: }
9893: $srchbysel .= "\n </select>\n";
9894:
9895: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9896: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9897: if ($curr_selected{'srchtype'} eq $option) {
9898: $srchtypesel .= '
1.1075.2.98 raeburn 9899: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9900: } else {
9901: $srchtypesel .= '
1.1075.2.98 raeburn 9902: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9903: }
9904: }
9905: $srchtypesel .= "\n </select>\n";
9906:
1.558 albertel 9907: my ($newuserscript,$new_user_create);
1.994 raeburn 9908: my $context_dom = $env{'request.role.domain'};
9909: if ($context eq 'requestcrs') {
9910: if ($env{'form.coursedom'} ne '') {
9911: $context_dom = $env{'form.coursedom'};
9912: }
9913: }
1.556 raeburn 9914: if ($forcenewuser) {
1.576 raeburn 9915: if (ref($srch) eq 'HASH') {
1.994 raeburn 9916: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9917: if ($cancreate) {
9918: $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>';
9919: } else {
1.799 bisitz 9920: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9921: my %usertypetext = (
9922: official => 'institutional',
9923: unofficial => 'non-institutional',
9924: );
1.799 bisitz 9925: $new_user_create = '<p class="LC_warning">'
9926: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9927: .' '
9928: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9929: ,'<a href="'.$helplink.'">','</a>')
9930: .'</p><br />';
1.627 raeburn 9931: }
1.576 raeburn 9932: }
9933: }
9934:
1.556 raeburn 9935: $newuserscript = <<"ENDSCRIPT";
9936:
1.570 raeburn 9937: function setSearch(createnew,callingForm) {
1.556 raeburn 9938: if (createnew == 1) {
1.570 raeburn 9939: for (var i=0; i<callingForm.srchby.length; i++) {
9940: if (callingForm.srchby.options[i].value == 'uname') {
9941: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9942: }
9943: }
1.570 raeburn 9944: for (var i=0; i<callingForm.srchin.length; i++) {
9945: if ( callingForm.srchin.options[i].value == 'dom') {
9946: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9947: }
9948: }
1.570 raeburn 9949: for (var i=0; i<callingForm.srchtype.length; i++) {
9950: if (callingForm.srchtype.options[i].value == 'exact') {
9951: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9952: }
9953: }
1.570 raeburn 9954: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9955: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9956: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9957: }
9958: }
9959: }
9960: }
9961: ENDSCRIPT
1.558 albertel 9962:
1.556 raeburn 9963: }
9964:
1.555 raeburn 9965: my $output = <<"END_BLOCK";
1.556 raeburn 9966: <script type="text/javascript">
1.824 bisitz 9967: // <![CDATA[
1.570 raeburn 9968: function validateEntry(callingForm) {
1.558 albertel 9969:
1.556 raeburn 9970: var checkok = 1;
1.558 albertel 9971: var srchin;
1.570 raeburn 9972: for (var i=0; i<callingForm.srchin.length; i++) {
9973: if ( callingForm.srchin[i].checked ) {
9974: srchin = callingForm.srchin[i].value;
1.558 albertel 9975: }
9976: }
9977:
1.570 raeburn 9978: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9979: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9980: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9981: var srchterm = callingForm.srchterm.value;
9982: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9983: var msg = "";
9984:
9985: if (srchterm == "") {
9986: checkok = 0;
1.1075.2.98 raeburn 9987: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 9988: }
9989:
1.569 raeburn 9990: if (srchtype== 'begins') {
9991: if (srchterm.length < 2) {
9992: checkok = 0;
1.1075.2.98 raeburn 9993: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 9994: }
9995: }
9996:
1.556 raeburn 9997: if (srchtype== 'contains') {
9998: if (srchterm.length < 3) {
9999: checkok = 0;
1.1075.2.98 raeburn 10000: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10001: }
10002: }
10003: if (srchin == 'instd') {
10004: if (srchdomain == '') {
10005: checkok = 0;
1.1075.2.98 raeburn 10006: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10007: }
10008: }
10009: if (srchin == 'dom') {
10010: if (srchdomain == '') {
10011: checkok = 0;
1.1075.2.98 raeburn 10012: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10013: }
10014: }
10015: if (srchby == 'lastfirst') {
10016: if (srchterm.indexOf(",") == -1) {
10017: checkok = 0;
1.1075.2.98 raeburn 10018: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10019: }
10020: if (srchterm.indexOf(",") == srchterm.length -1) {
10021: checkok = 0;
1.1075.2.98 raeburn 10022: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10023: }
10024: }
10025: if (checkok == 0) {
1.1075.2.98 raeburn 10026: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10027: return;
10028: }
10029: if (checkok == 1) {
1.570 raeburn 10030: callingForm.submit();
1.556 raeburn 10031: }
10032: }
10033:
10034: $newuserscript
10035:
1.824 bisitz 10036: // ]]>
1.556 raeburn 10037: </script>
1.558 albertel 10038:
10039: $new_user_create
10040:
1.555 raeburn 10041: END_BLOCK
1.558 albertel 10042:
1.876 raeburn 10043: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 10044: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10045: $domform.
10046: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 10047: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10048: $srchbysel.
10049: $srchtypesel.
10050: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10051: $srchinsel.
10052: &Apache::lonhtmlcommon::row_closure(1).
10053: &Apache::lonhtmlcommon::end_pick_box().
10054: '<br />';
1.1075.2.114 raeburn 10055: return ($output,1);
1.555 raeburn 10056: }
10057:
1.612 raeburn 10058: sub user_rule_check {
1.615 raeburn 10059: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 10060: my ($response,%inst_response);
1.612 raeburn 10061: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 10062: if (keys(%{$usershash}) > 1) {
10063: my (%by_username,%by_id,%userdoms);
10064: my $checkid;
1.612 raeburn 10065: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 10066: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10067: $checkid = 1;
10068: }
10069: }
10070: foreach my $user (keys(%{$usershash})) {
10071: my ($uname,$udom) = split(/:/,$user);
10072: if ($checkid) {
10073: if (ref($usershash->{$user}) eq 'HASH') {
10074: if ($usershash->{$user}->{'id'} ne '') {
10075: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
10076: $userdoms{$udom} = 1;
10077: if (ref($inst_results) eq 'HASH') {
10078: $inst_results->{$uname.':'.$udom} = {};
10079: }
10080: }
10081: }
10082: } else {
10083: $by_username{$udom}{$uname} = 1;
10084: $userdoms{$udom} = 1;
10085: if (ref($inst_results) eq 'HASH') {
10086: $inst_results->{$uname.':'.$udom} = {};
10087: }
10088: }
10089: }
10090: foreach my $udom (keys(%userdoms)) {
10091: if (!$got_rules->{$udom}) {
10092: my %domconfig = &Apache::lonnet::get_dom('configuration',
10093: ['usercreation'],$udom);
10094: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10095: foreach my $item ('username','id') {
10096: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10097: $$curr_rules{$udom}{$item} =
10098: $domconfig{'usercreation'}{$item.'_rule'};
10099: }
10100: }
10101: }
10102: $got_rules->{$udom} = 1;
10103: }
10104: }
10105: if ($checkid) {
10106: foreach my $udom (keys(%by_id)) {
10107: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10108: if ($outcome eq 'ok') {
10109: foreach my $id (keys(%{$by_id{$udom}})) {
10110: my $uname = $by_id{$udom}{$id};
10111: $inst_response{$uname.':'.$udom} = $outcome;
10112: }
10113: if (ref($results) eq 'HASH') {
10114: foreach my $uname (keys(%{$results})) {
10115: if (exists($inst_response{$uname.':'.$udom})) {
10116: $inst_response{$uname.':'.$udom} = $outcome;
10117: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10118: }
10119: }
10120: }
10121: }
1.612 raeburn 10122: }
1.615 raeburn 10123: } else {
1.1075.2.99 raeburn 10124: foreach my $udom (keys(%by_username)) {
10125: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10126: if ($outcome eq 'ok') {
10127: foreach my $uname (keys(%{$by_username{$udom}})) {
10128: $inst_response{$uname.':'.$udom} = $outcome;
10129: }
10130: if (ref($results) eq 'HASH') {
10131: foreach my $uname (keys(%{$results})) {
10132: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10133: }
10134: }
10135: }
10136: }
1.612 raeburn 10137: }
1.1075.2.99 raeburn 10138: } elsif (keys(%{$usershash}) == 1) {
10139: my $user = (keys(%{$usershash}))[0];
10140: my ($uname,$udom) = split(/:/,$user);
10141: if (($udom ne '') && ($uname ne '')) {
10142: if (ref($usershash->{$user}) eq 'HASH') {
10143: if (ref($checks) eq 'HASH') {
10144: if (defined($checks->{'username'})) {
10145: ($inst_response{$user},%{$inst_results->{$user}}) =
10146: &Apache::lonnet::get_instuser($udom,$uname);
10147: } elsif (defined($checks->{'id'})) {
10148: if ($usershash->{$user}->{'id'} ne '') {
10149: ($inst_response{$user},%{$inst_results->{$user}}) =
10150: &Apache::lonnet::get_instuser($udom,undef,
10151: $usershash->{$user}->{'id'});
10152: } else {
10153: ($inst_response{$user},%{$inst_results->{$user}}) =
10154: &Apache::lonnet::get_instuser($udom,$uname);
10155: }
10156: }
10157: } else {
10158: ($inst_response{$user},%{$inst_results->{$user}}) =
10159: &Apache::lonnet::get_instuser($udom,$uname);
10160: return;
10161: }
10162: if (!$got_rules->{$udom}) {
10163: my %domconfig = &Apache::lonnet::get_dom('configuration',
10164: ['usercreation'],$udom);
10165: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10166: foreach my $item ('username','id') {
10167: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10168: $$curr_rules{$udom}{$item} =
10169: $domconfig{'usercreation'}{$item.'_rule'};
10170: }
10171: }
1.585 raeburn 10172: }
1.1075.2.99 raeburn 10173: $got_rules->{$udom} = 1;
1.585 raeburn 10174: }
10175: }
1.1075.2.99 raeburn 10176: } else {
10177: return;
10178: }
10179: } else {
10180: return;
10181: }
10182: foreach my $user (keys(%{$usershash})) {
10183: my ($uname,$udom) = split(/:/,$user);
10184: next if (($udom eq '') || ($uname eq ''));
10185: my $id;
10186: if (ref($inst_results) eq 'HASH') {
10187: if (ref($inst_results->{$user}) eq 'HASH') {
10188: $id = $inst_results->{$user}->{'id'};
10189: }
10190: }
10191: if ($id eq '') {
10192: if (ref($usershash->{$user})) {
10193: $id = $usershash->{$user}->{'id'};
10194: }
1.585 raeburn 10195: }
1.612 raeburn 10196: foreach my $item (keys(%{$checks})) {
10197: if (ref($$curr_rules{$udom}) eq 'HASH') {
10198: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10199: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 10200: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10201: $$curr_rules{$udom}{$item});
1.612 raeburn 10202: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10203: if ($rule_check{$rule}) {
10204: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 10205: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10206: if (ref($inst_results) eq 'HASH') {
10207: if (ref($inst_results->{$user}) eq 'HASH') {
10208: if (keys(%{$inst_results->{$user}}) == 0) {
10209: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 10210: } elsif ($item eq 'id') {
10211: if ($inst_results->{$user}->{'id'} eq '') {
10212: $$alerts{$item}{$udom}{$uname} = 1;
10213: }
1.615 raeburn 10214: }
1.612 raeburn 10215: }
10216: }
1.615 raeburn 10217: }
10218: last;
1.585 raeburn 10219: }
10220: }
10221: }
10222: }
10223: }
10224: }
10225: }
10226: }
1.612 raeburn 10227: return;
10228: }
10229:
10230: sub user_rule_formats {
10231: my ($domain,$domdesc,$curr_rules,$check) = @_;
10232: my %text = (
10233: 'username' => 'Usernames',
10234: 'id' => 'IDs',
10235: );
10236: my $output;
10237: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10238: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10239: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 10240: $output = '<br />'.
10241: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10242: '<span class="LC_cusr_emph">','</span>',$domdesc).
10243: ' <ul>';
1.612 raeburn 10244: foreach my $rule (@{$ruleorder}) {
10245: if (ref($curr_rules) eq 'ARRAY') {
10246: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10247: if (ref($rules->{$rule}) eq 'HASH') {
10248: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10249: $rules->{$rule}{'desc'}.'</li>';
10250: }
10251: }
10252: }
10253: }
10254: $output .= '</ul>';
10255: }
10256: }
10257: return $output;
10258: }
10259:
10260: sub instrule_disallow_msg {
1.615 raeburn 10261: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10262: my $response;
10263: my %text = (
10264: item => 'username',
10265: items => 'usernames',
10266: match => 'matches',
10267: do => 'does',
10268: action => 'a username',
10269: one => 'one',
10270: );
10271: if ($count > 1) {
10272: $text{'item'} = 'usernames';
10273: $text{'match'} ='match';
10274: $text{'do'} = 'do';
10275: $text{'action'} = 'usernames',
10276: $text{'one'} = 'ones';
10277: }
10278: if ($checkitem eq 'id') {
10279: $text{'items'} = 'IDs';
10280: $text{'item'} = 'ID';
10281: $text{'action'} = 'an ID';
1.615 raeburn 10282: if ($count > 1) {
10283: $text{'item'} = 'IDs';
10284: $text{'action'} = 'IDs';
10285: }
1.612 raeburn 10286: }
1.674 bisitz 10287: $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 10288: if ($mode eq 'upload') {
10289: if ($checkitem eq 'username') {
10290: $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'}.");
10291: } elsif ($checkitem eq 'id') {
1.674 bisitz 10292: $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 10293: }
1.669 raeburn 10294: } elsif ($mode eq 'selfcreate') {
10295: if ($checkitem eq 'id') {
10296: $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.");
10297: }
1.615 raeburn 10298: } else {
10299: if ($checkitem eq 'username') {
10300: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10301: } elsif ($checkitem eq 'id') {
10302: $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.");
10303: }
1.612 raeburn 10304: }
10305: return $response;
1.585 raeburn 10306: }
10307:
1.624 raeburn 10308: sub personal_data_fieldtitles {
10309: my %fieldtitles = &Apache::lonlocal::texthash (
10310: id => 'Student/Employee ID',
10311: permanentemail => 'E-mail address',
10312: lastname => 'Last Name',
10313: firstname => 'First Name',
10314: middlename => 'Middle Name',
10315: generation => 'Generation',
10316: gen => 'Generation',
1.765 raeburn 10317: inststatus => 'Affiliation',
1.624 raeburn 10318: );
10319: return %fieldtitles;
10320: }
10321:
1.642 raeburn 10322: sub sorted_inst_types {
10323: my ($dom) = @_;
1.1075.2.70 raeburn 10324: my ($usertypes,$order);
10325: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10326: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10327: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10328: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10329: } else {
10330: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10331: }
1.642 raeburn 10332: my $othertitle = &mt('All users');
10333: if ($env{'request.course.id'}) {
1.668 raeburn 10334: $othertitle = &mt('Any users');
1.642 raeburn 10335: }
10336: my @types;
10337: if (ref($order) eq 'ARRAY') {
10338: @types = @{$order};
10339: }
10340: if (@types == 0) {
10341: if (ref($usertypes) eq 'HASH') {
10342: @types = sort(keys(%{$usertypes}));
10343: }
10344: }
10345: if (keys(%{$usertypes}) > 0) {
10346: $othertitle = &mt('Other users');
10347: }
10348: return ($othertitle,$usertypes,\@types);
10349: }
10350:
1.645 raeburn 10351: sub get_institutional_codes {
10352: my ($settings,$allcourses,$LC_code) = @_;
10353: # Get complete list of course sections to update
10354: my @currsections = ();
10355: my @currxlists = ();
10356: my $coursecode = $$settings{'internal.coursecode'};
10357:
10358: if ($$settings{'internal.sectionnums'} ne '') {
10359: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10360: }
10361:
10362: if ($$settings{'internal.crosslistings'} ne '') {
10363: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10364: }
10365:
10366: if (@currxlists > 0) {
10367: foreach (@currxlists) {
10368: if (m/^([^:]+):(\w*)$/) {
10369: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 10370: push(@{$allcourses},$1);
1.645 raeburn 10371: $$LC_code{$1} = $2;
10372: }
10373: }
10374: }
10375: }
10376:
10377: if (@currsections > 0) {
10378: foreach (@currsections) {
10379: if (m/^(\w+):(\w*)$/) {
10380: my $sec = $coursecode.$1;
10381: my $lc_sec = $2;
10382: unless (grep/^$sec$/,@{$allcourses}) {
1.1075.2.119 raeburn 10383: push(@{$allcourses},$sec);
1.645 raeburn 10384: $$LC_code{$sec} = $lc_sec;
10385: }
10386: }
10387: }
10388: }
10389: return;
10390: }
10391:
1.971 raeburn 10392: sub get_standard_codeitems {
10393: return ('Year','Semester','Department','Number','Section');
10394: }
10395:
1.112 bowersj2 10396: =pod
10397:
1.780 raeburn 10398: =head1 Slot Helpers
10399:
10400: =over 4
10401:
10402: =item * sorted_slots()
10403:
1.1040 raeburn 10404: Sorts an array of slot names in order of an optional sort key,
10405: default sort is by slot start time (earliest first).
1.780 raeburn 10406:
10407: Inputs:
10408:
10409: =over 4
10410:
10411: slotsarr - Reference to array of unsorted slot names.
10412:
10413: slots - Reference to hash of hash, where outer hash keys are slot names.
10414:
1.1040 raeburn 10415: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10416:
1.549 albertel 10417: =back
10418:
1.780 raeburn 10419: Returns:
10420:
10421: =over 4
10422:
1.1040 raeburn 10423: sorted - An array of slot names sorted by a specified sort key
10424: (default sort key is start time of the slot).
1.780 raeburn 10425:
10426: =back
10427:
10428: =cut
10429:
10430:
10431: sub sorted_slots {
1.1040 raeburn 10432: my ($slotsarr,$slots,$sortkey) = @_;
10433: if ($sortkey eq '') {
10434: $sortkey = 'starttime';
10435: }
1.780 raeburn 10436: my @sorted;
10437: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10438: @sorted =
10439: sort {
10440: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10441: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10442: }
10443: if (ref($slots->{$a})) { return -1;}
10444: if (ref($slots->{$b})) { return 1;}
10445: return 0;
10446: } @{$slotsarr};
10447: }
10448: return @sorted;
10449: }
10450:
1.1040 raeburn 10451: =pod
10452:
10453: =item * get_future_slots()
10454:
10455: Inputs:
10456:
10457: =over 4
10458:
10459: cnum - course number
10460:
10461: cdom - course domain
10462:
10463: now - current UNIX time
10464:
10465: symb - optional symb
10466:
10467: =back
10468:
10469: Returns:
10470:
10471: =over 4
10472:
10473: sorted_reservable - ref to array of student_schedulable slots currently
10474: reservable, ordered by end date of reservation period.
10475:
10476: reservable_now - ref to hash of student_schedulable slots currently
10477: reservable.
10478:
10479: Keys in inner hash are:
10480: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 10481: (b) endreserve: end date of reservation period.
10482: (c) uniqueperiod: start,end dates when slot is to be uniquely
10483: selected.
1.1040 raeburn 10484:
10485: sorted_future - ref to array of student_schedulable slots reservable in
10486: the future, ordered by start date of reservation period.
10487:
10488: future_reservable - ref to hash of student_schedulable slots reservable
10489: in the future.
10490:
10491: Keys in inner hash are:
10492: (a) symb: either blank or symb to which slot use is restricted.
10493: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 10494: (c) uniqueperiod: start,end dates when slot is to be uniquely
10495: selected.
1.1040 raeburn 10496:
10497: =back
10498:
10499: =cut
10500:
10501: sub get_future_slots {
10502: my ($cnum,$cdom,$now,$symb) = @_;
10503: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10504: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10505: foreach my $slot (keys(%slots)) {
10506: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10507: if ($symb) {
10508: next if (($slots{$slot}->{'symb'} ne '') &&
10509: ($slots{$slot}->{'symb'} ne $symb));
10510: }
10511: if (($slots{$slot}->{'starttime'} > $now) &&
10512: ($slots{$slot}->{'endtime'} > $now)) {
10513: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10514: my $userallowed = 0;
10515: if ($slots{$slot}->{'allowedsections'}) {
10516: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10517: if (!defined($env{'request.role.sec'})
10518: && grep(/^No section assigned$/,@allowed_sec)) {
10519: $userallowed=1;
10520: } else {
10521: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10522: $userallowed=1;
10523: }
10524: }
10525: unless ($userallowed) {
10526: if (defined($env{'request.course.groups'})) {
10527: my @groups = split(/:/,$env{'request.course.groups'});
10528: foreach my $group (@groups) {
10529: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10530: $userallowed=1;
10531: last;
10532: }
10533: }
10534: }
10535: }
10536: }
10537: if ($slots{$slot}->{'allowedusers'}) {
10538: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10539: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10540: if (grep(/^\Q$user\E$/,@allowed_users)) {
10541: $userallowed = 1;
10542: }
10543: }
10544: next unless($userallowed);
10545: }
10546: my $startreserve = $slots{$slot}->{'startreserve'};
10547: my $endreserve = $slots{$slot}->{'endreserve'};
10548: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 10549: my $uniqueperiod;
10550: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10551: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10552: }
1.1040 raeburn 10553: if (($startreserve < $now) &&
10554: (!$endreserve || $endreserve > $now)) {
10555: my $lastres = $endreserve;
10556: if (!$lastres) {
10557: $lastres = $slots{$slot}->{'starttime'};
10558: }
10559: $reservable_now{$slot} = {
10560: symb => $symb,
1.1075.2.104 raeburn 10561: endreserve => $lastres,
10562: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10563: };
10564: } elsif (($startreserve > $now) &&
10565: (!$endreserve || $endreserve > $startreserve)) {
10566: $future_reservable{$slot} = {
10567: symb => $symb,
1.1075.2.104 raeburn 10568: startreserve => $startreserve,
10569: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10570: };
10571: }
10572: }
10573: }
10574: my @unsorted_reservable = keys(%reservable_now);
10575: if (@unsorted_reservable > 0) {
10576: @sorted_reservable =
10577: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10578: }
10579: my @unsorted_future = keys(%future_reservable);
10580: if (@unsorted_future > 0) {
10581: @sorted_future =
10582: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10583: }
10584: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10585: }
1.780 raeburn 10586:
10587: =pod
10588:
1.1057 foxr 10589: =back
10590:
1.549 albertel 10591: =head1 HTTP Helpers
10592:
10593: =over 4
10594:
1.648 raeburn 10595: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10596:
1.258 albertel 10597: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10598: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10599: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10600:
10601: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10602: $possible_names is an ref to an array of form element names. As an example:
10603: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10604: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10605:
10606: =cut
1.1 albertel 10607:
1.6 albertel 10608: sub get_unprocessed_cgi {
1.25 albertel 10609: my ($query,$possible_names)= @_;
1.26 matthew 10610: # $Apache::lonxml::debug=1;
1.356 albertel 10611: foreach my $pair (split(/&/,$query)) {
10612: my ($name, $value) = split(/=/,$pair);
1.369 www 10613: $name = &unescape($name);
1.25 albertel 10614: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10615: $value =~ tr/+/ /;
10616: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10617: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10618: }
1.16 harris41 10619: }
1.6 albertel 10620: }
10621:
1.112 bowersj2 10622: =pod
10623:
1.648 raeburn 10624: =item * &cacheheader()
1.112 bowersj2 10625:
10626: returns cache-controlling header code
10627:
10628: =cut
10629:
1.7 albertel 10630: sub cacheheader {
1.258 albertel 10631: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10632: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10633: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10634: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10635: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10636: return $output;
1.7 albertel 10637: }
10638:
1.112 bowersj2 10639: =pod
10640:
1.648 raeburn 10641: =item * &no_cache($r)
1.112 bowersj2 10642:
10643: specifies header code to not have cache
10644:
10645: =cut
10646:
1.9 albertel 10647: sub no_cache {
1.216 albertel 10648: my ($r) = @_;
10649: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10650: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10651: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10652: $r->no_cache(1);
10653: $r->header_out("Expires" => $date);
10654: $r->header_out("Pragma" => "no-cache");
1.123 www 10655: }
10656:
10657: sub content_type {
1.181 albertel 10658: my ($r,$type,$charset) = @_;
1.299 foxr 10659: if ($r) {
10660: # Note that printout.pl calls this with undef for $r.
10661: &no_cache($r);
10662: }
1.258 albertel 10663: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10664: unless ($charset) {
10665: $charset=&Apache::lonlocal::current_encoding;
10666: }
10667: if ($charset) { $type.='; charset='.$charset; }
10668: if ($r) {
10669: $r->content_type($type);
10670: } else {
10671: print("Content-type: $type\n\n");
10672: }
1.9 albertel 10673: }
1.25 albertel 10674:
1.112 bowersj2 10675: =pod
10676:
1.648 raeburn 10677: =item * &add_to_env($name,$value)
1.112 bowersj2 10678:
1.258 albertel 10679: adds $name to the %env hash with value
1.112 bowersj2 10680: $value, if $name already exists, the entry is converted to an array
10681: reference and $value is added to the array.
10682:
10683: =cut
10684:
1.25 albertel 10685: sub add_to_env {
10686: my ($name,$value)=@_;
1.258 albertel 10687: if (defined($env{$name})) {
10688: if (ref($env{$name})) {
1.25 albertel 10689: #already have multiple values
1.258 albertel 10690: push(@{ $env{$name} },$value);
1.25 albertel 10691: } else {
10692: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10693: my $first=$env{$name};
10694: undef($env{$name});
10695: push(@{ $env{$name} },$first,$value);
1.25 albertel 10696: }
10697: } else {
1.258 albertel 10698: $env{$name}=$value;
1.25 albertel 10699: }
1.31 albertel 10700: }
1.149 albertel 10701:
10702: =pod
10703:
1.648 raeburn 10704: =item * &get_env_multiple($name)
1.149 albertel 10705:
1.258 albertel 10706: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10707: values may be defined and end up as an array ref.
10708:
10709: returns an array of values
10710:
10711: =cut
10712:
10713: sub get_env_multiple {
10714: my ($name) = @_;
10715: my @values;
1.258 albertel 10716: if (defined($env{$name})) {
1.149 albertel 10717: # exists is it an array
1.258 albertel 10718: if (ref($env{$name})) {
10719: @values=@{ $env{$name} };
1.149 albertel 10720: } else {
1.258 albertel 10721: $values[0]=$env{$name};
1.149 albertel 10722: }
10723: }
10724: return(@values);
10725: }
10726:
1.660 raeburn 10727: sub ask_for_embedded_content {
10728: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10729: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 10730: %currsubfile,%unused,$rem);
1.1071 raeburn 10731: my $counter = 0;
10732: my $numnew = 0;
1.987 raeburn 10733: my $numremref = 0;
10734: my $numinvalid = 0;
10735: my $numpathchg = 0;
10736: my $numexisting = 0;
1.1071 raeburn 10737: my $numunused = 0;
10738: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 10739: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10740: my $heading = &mt('Upload embedded files');
10741: my $buttontext = &mt('Upload');
10742:
1.1075.2.11 raeburn 10743: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 10744: if ($actionurl eq '/adm/dependencies') {
10745: $navmap = Apache::lonnavmaps::navmap->new();
10746: }
10747: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10748: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 10749: }
1.1075.2.35 raeburn 10750: if (($actionurl eq '/adm/portfolio') ||
10751: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10752: my $current_path='/';
10753: if ($env{'form.currentpath'}) {
10754: $current_path = $env{'form.currentpath'};
10755: }
10756: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 10757: $udom = $cdom;
10758: $uname = $cnum;
1.984 raeburn 10759: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10760: } else {
10761: $udom = $env{'user.domain'};
10762: $uname = $env{'user.name'};
10763: $url = '/userfiles/portfolio';
10764: }
1.987 raeburn 10765: $toplevel = $url.'/';
1.984 raeburn 10766: $url .= $current_path;
10767: $getpropath = 1;
1.987 raeburn 10768: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10769: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10770: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10771: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10772: $toplevel = $url;
1.984 raeburn 10773: if ($rest ne '') {
1.987 raeburn 10774: $url .= $rest;
10775: }
10776: } elsif ($actionurl eq '/adm/coursedocs') {
10777: if (ref($args) eq 'HASH') {
1.1071 raeburn 10778: $url = $args->{'docs_url'};
10779: $toplevel = $url;
1.1075.2.11 raeburn 10780: if ($args->{'context'} eq 'paste') {
10781: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10782: ($path) =
10783: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10784: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10785: $fileloc =~ s{^/}{};
10786: }
1.1071 raeburn 10787: }
10788: } elsif ($actionurl eq '/adm/dependencies') {
10789: if ($env{'request.course.id'} ne '') {
10790: if (ref($args) eq 'HASH') {
10791: $url = $args->{'docs_url'};
10792: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 10793: $toplevel = $url;
10794: unless ($toplevel =~ m{^/}) {
10795: $toplevel = "/$url";
10796: }
1.1075.2.11 raeburn 10797: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 10798: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10799: $path = $1;
10800: } else {
10801: ($path) =
10802: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10803: }
1.1075.2.79 raeburn 10804: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10805: $fileloc = $toplevel;
10806: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10807: my ($udom,$uname,$fname) =
10808: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10809: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10810: } else {
10811: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10812: }
1.1071 raeburn 10813: $fileloc =~ s{^/}{};
10814: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10815: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10816: }
1.987 raeburn 10817: }
1.1075.2.35 raeburn 10818: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10819: $udom = $cdom;
10820: $uname = $cnum;
10821: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10822: $toplevel = $url;
10823: $path = $url;
10824: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10825: $fileloc =~ s{^/}{};
10826: }
10827: foreach my $file (keys(%{$allfiles})) {
10828: my $embed_file;
10829: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10830: $embed_file = $1;
10831: } else {
10832: $embed_file = $file;
10833: }
1.1075.2.55 raeburn 10834: my ($absolutepath,$cleaned_file);
10835: if ($embed_file =~ m{^\w+://}) {
10836: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 10837: $newfiles{$cleaned_file} = 1;
10838: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10839: } else {
1.1075.2.55 raeburn 10840: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10841: if ($embed_file =~ m{^/}) {
10842: $absolutepath = $embed_file;
10843: }
1.1075.2.47 raeburn 10844: if ($cleaned_file =~ m{/}) {
10845: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10846: $path = &check_for_traversal($path,$url,$toplevel);
10847: my $item = $fname;
10848: if ($path ne '') {
10849: $item = $path.'/'.$fname;
10850: $subdependencies{$path}{$fname} = 1;
10851: } else {
10852: $dependencies{$item} = 1;
10853: }
10854: if ($absolutepath) {
10855: $mapping{$item} = $absolutepath;
10856: } else {
10857: $mapping{$item} = $embed_file;
10858: }
10859: } else {
10860: $dependencies{$embed_file} = 1;
10861: if ($absolutepath) {
1.1075.2.47 raeburn 10862: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10863: } else {
1.1075.2.47 raeburn 10864: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10865: }
10866: }
1.984 raeburn 10867: }
10868: }
1.1071 raeburn 10869: my $dirptr = 16384;
1.984 raeburn 10870: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10871: $currsubfile{$path} = {};
1.1075.2.35 raeburn 10872: if (($actionurl eq '/adm/portfolio') ||
10873: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10874: my ($sublistref,$listerror) =
10875: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10876: if (ref($sublistref) eq 'ARRAY') {
10877: foreach my $line (@{$sublistref}) {
10878: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10879: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10880: }
1.984 raeburn 10881: }
1.987 raeburn 10882: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10883: if (opendir(my $dir,$url.'/'.$path)) {
10884: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10885: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10886: }
1.1075.2.11 raeburn 10887: } elsif (($actionurl eq '/adm/dependencies') ||
10888: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10889: ($args->{'context'} eq 'paste')) ||
10890: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10891: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 10892: my $dir;
10893: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10894: $dir = $fileloc;
10895: } else {
10896: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10897: }
1.1071 raeburn 10898: if ($dir ne '') {
10899: my ($sublistref,$listerror) =
10900: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10901: if (ref($sublistref) eq 'ARRAY') {
10902: foreach my $line (@{$sublistref}) {
10903: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10904: undef,$mtime)=split(/\&/,$line,12);
10905: unless (($testdir&$dirptr) ||
10906: ($file_name =~ /^\.\.?$/)) {
10907: $currsubfile{$path}{$file_name} = [$size,$mtime];
10908: }
10909: }
10910: }
10911: }
1.984 raeburn 10912: }
10913: }
10914: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10915: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10916: my $item = $path.'/'.$file;
10917: unless ($mapping{$item} eq $item) {
10918: $pathchanges{$item} = 1;
10919: }
10920: $existing{$item} = 1;
10921: $numexisting ++;
10922: } else {
10923: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10924: }
10925: }
1.1071 raeburn 10926: if ($actionurl eq '/adm/dependencies') {
10927: foreach my $path (keys(%currsubfile)) {
10928: if (ref($currsubfile{$path}) eq 'HASH') {
10929: foreach my $file (keys(%{$currsubfile{$path}})) {
10930: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 10931: next if (($rem ne '') &&
10932: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10933: (ref($navmap) &&
10934: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10935: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10936: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10937: $unused{$path.'/'.$file} = 1;
10938: }
10939: }
10940: }
10941: }
10942: }
1.984 raeburn 10943: }
1.987 raeburn 10944: my %currfile;
1.1075.2.35 raeburn 10945: if (($actionurl eq '/adm/portfolio') ||
10946: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10947: my ($dirlistref,$listerror) =
10948: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10949: if (ref($dirlistref) eq 'ARRAY') {
10950: foreach my $line (@{$dirlistref}) {
10951: my ($file_name,$rest) = split(/\&/,$line,2);
10952: $currfile{$file_name} = 1;
10953: }
1.984 raeburn 10954: }
1.987 raeburn 10955: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10956: if (opendir(my $dir,$url)) {
1.987 raeburn 10957: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10958: map {$currfile{$_} = 1;} @dir_list;
10959: }
1.1075.2.11 raeburn 10960: } elsif (($actionurl eq '/adm/dependencies') ||
10961: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10962: ($args->{'context'} eq 'paste')) ||
10963: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10964: if ($env{'request.course.id'} ne '') {
10965: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10966: if ($dir ne '') {
10967: my ($dirlistref,$listerror) =
10968: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10969: if (ref($dirlistref) eq 'ARRAY') {
10970: foreach my $line (@{$dirlistref}) {
10971: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10972: $size,undef,$mtime)=split(/\&/,$line,12);
10973: unless (($testdir&$dirptr) ||
10974: ($file_name =~ /^\.\.?$/)) {
10975: $currfile{$file_name} = [$size,$mtime];
10976: }
10977: }
10978: }
10979: }
10980: }
1.984 raeburn 10981: }
10982: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10983: if (exists($currfile{$file})) {
1.987 raeburn 10984: unless ($mapping{$file} eq $file) {
10985: $pathchanges{$file} = 1;
10986: }
10987: $existing{$file} = 1;
10988: $numexisting ++;
10989: } else {
1.984 raeburn 10990: $newfiles{$file} = 1;
10991: }
10992: }
1.1071 raeburn 10993: foreach my $file (keys(%currfile)) {
10994: unless (($file eq $filename) ||
10995: ($file eq $filename.'.bak') ||
10996: ($dependencies{$file})) {
1.1075.2.11 raeburn 10997: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10998: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10999: next if (($rem ne '') &&
11000: (($env{"httpref.$rem".$file} ne '') ||
11001: (ref($navmap) &&
11002: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11003: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11004: ($navmap->getResourceByUrl($rem.$1)))))));
11005: }
1.1075.2.11 raeburn 11006: }
1.1071 raeburn 11007: $unused{$file} = 1;
11008: }
11009: }
1.1075.2.11 raeburn 11010: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11011: ($args->{'context'} eq 'paste')) {
11012: $counter = scalar(keys(%existing));
11013: $numpathchg = scalar(keys(%pathchanges));
11014: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 11015: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11016: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11017: $counter = scalar(keys(%existing));
11018: $numpathchg = scalar(keys(%pathchanges));
11019: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 11020: }
1.984 raeburn 11021: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11022: if ($actionurl eq '/adm/dependencies') {
11023: next if ($embed_file =~ m{^\w+://});
11024: }
1.660 raeburn 11025: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11026: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11027: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11028: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 11029: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11030: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11031: }
1.1075.2.35 raeburn 11032: $upload_output .= '</td>';
1.1071 raeburn 11033: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 11034: $upload_output.='<td align="right">'.
11035: '<span class="LC_info LC_fontsize_medium">'.
11036: &mt("URL points to web address").'</span>';
1.987 raeburn 11037: $numremref++;
1.660 raeburn 11038: } elsif ($args->{'error_on_invalid_names'}
11039: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 11040: $upload_output.='<td align="right"><span class="LC_warning">'.
11041: &mt('Invalid characters').'</span>';
1.987 raeburn 11042: $numinvalid++;
1.660 raeburn 11043: } else {
1.1075.2.35 raeburn 11044: $upload_output .= '<td>'.
11045: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11046: $embed_file,\%mapping,
1.1071 raeburn 11047: $allfiles,$codebase,'upload');
11048: $counter ++;
11049: $numnew ++;
1.987 raeburn 11050: }
11051: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11052: }
11053: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11054: if ($actionurl eq '/adm/dependencies') {
11055: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11056: $modify_output .= &start_data_table_row().
11057: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11058: '<img src="'.&icon($embed_file).'" border="0" />'.
11059: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11060: '<td>'.$size.'</td>'.
11061: '<td>'.$mtime.'</td>'.
11062: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11063: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11064: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11065: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11066: &embedded_file_element('upload_embedded',$counter,
11067: $embed_file,\%mapping,
11068: $allfiles,$codebase,'modify').
11069: '</div></td>'.
11070: &end_data_table_row()."\n";
11071: $counter ++;
11072: } else {
11073: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11074: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11075: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11076: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11077: &Apache::loncommon::end_data_table_row()."\n";
11078: }
11079: }
11080: my $delidx = $counter;
11081: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11082: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11083: $delete_output .= &start_data_table_row().
11084: '<td><img src="'.&icon($oldfile).'" />'.
11085: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11086: '<td>'.$size.'</td>'.
11087: '<td>'.$mtime.'</td>'.
11088: '<td><label><input type="checkbox" name="del_upload_dep" '.
11089: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11090: &embedded_file_element('upload_embedded',$delidx,
11091: $oldfile,\%mapping,$allfiles,
11092: $codebase,'delete').'</td>'.
11093: &end_data_table_row()."\n";
11094: $numunused ++;
11095: $delidx ++;
1.987 raeburn 11096: }
11097: if ($upload_output) {
11098: $upload_output = &start_data_table().
11099: $upload_output.
11100: &end_data_table()."\n";
11101: }
1.1071 raeburn 11102: if ($modify_output) {
11103: $modify_output = &start_data_table().
11104: &start_data_table_header_row().
11105: '<th>'.&mt('File').'</th>'.
11106: '<th>'.&mt('Size (KB)').'</th>'.
11107: '<th>'.&mt('Modified').'</th>'.
11108: '<th>'.&mt('Upload replacement?').'</th>'.
11109: &end_data_table_header_row().
11110: $modify_output.
11111: &end_data_table()."\n";
11112: }
11113: if ($delete_output) {
11114: $delete_output = &start_data_table().
11115: &start_data_table_header_row().
11116: '<th>'.&mt('File').'</th>'.
11117: '<th>'.&mt('Size (KB)').'</th>'.
11118: '<th>'.&mt('Modified').'</th>'.
11119: '<th>'.&mt('Delete?').'</th>'.
11120: &end_data_table_header_row().
11121: $delete_output.
11122: &end_data_table()."\n";
11123: }
1.987 raeburn 11124: my $applies = 0;
11125: if ($numremref) {
11126: $applies ++;
11127: }
11128: if ($numinvalid) {
11129: $applies ++;
11130: }
11131: if ($numexisting) {
11132: $applies ++;
11133: }
1.1071 raeburn 11134: if ($counter || $numunused) {
1.987 raeburn 11135: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11136: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11137: $state.'<h3>'.$heading.'</h3>';
11138: if ($actionurl eq '/adm/dependencies') {
11139: if ($numnew) {
11140: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11141: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11142: $upload_output.'<br />'."\n";
11143: }
11144: if ($numexisting) {
11145: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11146: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11147: $modify_output.'<br />'."\n";
11148: $buttontext = &mt('Save changes');
11149: }
11150: if ($numunused) {
11151: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11152: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11153: $delete_output.'<br />'."\n";
11154: $buttontext = &mt('Save changes');
11155: }
11156: } else {
11157: $output .= $upload_output.'<br />'."\n";
11158: }
11159: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11160: $counter.'" />'."\n";
11161: if ($actionurl eq '/adm/dependencies') {
11162: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11163: $numnew.'" />'."\n";
11164: } elsif ($actionurl eq '') {
1.987 raeburn 11165: $output .= '<input type="hidden" name="phase" value="three" />';
11166: }
11167: } elsif ($applies) {
11168: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11169: if ($applies > 1) {
11170: $output .=
1.1075.2.35 raeburn 11171: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11172: if ($numremref) {
11173: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11174: }
11175: if ($numinvalid) {
11176: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11177: }
11178: if ($numexisting) {
11179: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11180: }
11181: $output .= '</ul><br />';
11182: } elsif ($numremref) {
11183: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11184: } elsif ($numinvalid) {
11185: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11186: } elsif ($numexisting) {
11187: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11188: }
11189: $output .= $upload_output.'<br />';
11190: }
11191: my ($pathchange_output,$chgcount);
1.1071 raeburn 11192: $chgcount = $counter;
1.987 raeburn 11193: if (keys(%pathchanges) > 0) {
11194: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11195: if ($counter) {
1.987 raeburn 11196: $output .= &embedded_file_element('pathchange',$chgcount,
11197: $embed_file,\%mapping,
1.1071 raeburn 11198: $allfiles,$codebase,'change');
1.987 raeburn 11199: } else {
11200: $pathchange_output .=
11201: &start_data_table_row().
11202: '<td><input type ="checkbox" name="namechange" value="'.
11203: $chgcount.'" checked="checked" /></td>'.
11204: '<td>'.$mapping{$embed_file}.'</td>'.
11205: '<td>'.$embed_file.
11206: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11207: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11208: '</td>'.&end_data_table_row();
1.660 raeburn 11209: }
1.987 raeburn 11210: $numpathchg ++;
11211: $chgcount ++;
1.660 raeburn 11212: }
11213: }
1.1075.2.35 raeburn 11214: if (($counter) || ($numunused)) {
1.987 raeburn 11215: if ($numpathchg) {
11216: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11217: $numpathchg.'" />'."\n";
11218: }
11219: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11220: ($actionurl eq '/adm/imsimport')) {
11221: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11222: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11223: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11224: } elsif ($actionurl eq '/adm/dependencies') {
11225: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11226: }
1.1075.2.35 raeburn 11227: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11228: } elsif ($numpathchg) {
11229: my %pathchange = ();
11230: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11231: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11232: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 11233: }
1.987 raeburn 11234: }
1.1071 raeburn 11235: return ($output,$counter,$numpathchg);
1.987 raeburn 11236: }
11237:
1.1075.2.47 raeburn 11238: =pod
11239:
11240: =item * clean_path($name)
11241:
11242: Performs clean-up of directories, subdirectories and filename in an
11243: embedded object, referenced in an HTML file which is being uploaded
11244: to a course or portfolio, where
11245: "Upload embedded images/multimedia files if HTML file" checkbox was
11246: checked.
11247:
11248: Clean-up is similar to replacements in lonnet::clean_filename()
11249: except each / between sub-directory and next level is preserved.
11250:
11251: =cut
11252:
11253: sub clean_path {
11254: my ($embed_file) = @_;
11255: $embed_file =~s{^/+}{};
11256: my @contents;
11257: if ($embed_file =~ m{/}) {
11258: @contents = split(/\//,$embed_file);
11259: } else {
11260: @contents = ($embed_file);
11261: }
11262: my $lastidx = scalar(@contents)-1;
11263: for (my $i=0; $i<=$lastidx; $i++) {
11264: $contents[$i]=~s{\\}{/}g;
11265: $contents[$i]=~s/\s+/\_/g;
11266: $contents[$i]=~s{[^/\w\.\-]}{}g;
11267: if ($i == $lastidx) {
11268: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11269: }
11270: }
11271: if ($lastidx > 0) {
11272: return join('/',@contents);
11273: } else {
11274: return $contents[0];
11275: }
11276: }
11277:
1.987 raeburn 11278: sub embedded_file_element {
1.1071 raeburn 11279: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11280: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11281: (ref($codebase) eq 'HASH'));
11282: my $output;
1.1071 raeburn 11283: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11284: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11285: }
11286: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11287: &escape($embed_file).'" />';
11288: unless (($context eq 'upload_embedded') &&
11289: ($mapping->{$embed_file} eq $embed_file)) {
11290: $output .='
11291: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11292: }
11293: my $attrib;
11294: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11295: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11296: }
11297: $output .=
11298: "\n\t\t".
11299: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11300: $attrib.'" />';
11301: if (exists($codebase->{$mapping->{$embed_file}})) {
11302: $output .=
11303: "\n\t\t".
11304: '<input name="codebase_'.$num.'" type="hidden" value="'.
11305: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11306: }
1.987 raeburn 11307: return $output;
1.660 raeburn 11308: }
11309:
1.1071 raeburn 11310: sub get_dependency_details {
11311: my ($currfile,$currsubfile,$embed_file) = @_;
11312: my ($size,$mtime,$showsize,$showmtime);
11313: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11314: if ($embed_file =~ m{/}) {
11315: my ($path,$fname) = split(/\//,$embed_file);
11316: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11317: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11318: }
11319: } else {
11320: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11321: ($size,$mtime) = @{$currfile->{$embed_file}};
11322: }
11323: }
11324: $showsize = $size/1024.0;
11325: $showsize = sprintf("%.1f",$showsize);
11326: if ($mtime > 0) {
11327: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11328: }
11329: }
11330: return ($showsize,$showmtime);
11331: }
11332:
11333: sub ask_embedded_js {
11334: return <<"END";
11335: <script type="text/javascript"">
11336: // <![CDATA[
11337: function toggleBrowse(counter) {
11338: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11339: var fileid = document.getElementById('embedded_item_'+counter);
11340: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11341: if (chkboxid.checked == true) {
11342: uploaddivid.style.display='block';
11343: } else {
11344: uploaddivid.style.display='none';
11345: fileid.value = '';
11346: }
11347: }
11348: // ]]>
11349: </script>
11350:
11351: END
11352: }
11353:
1.661 raeburn 11354: sub upload_embedded {
11355: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11356: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11357: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11358: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11359: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11360: my $orig_uploaded_filename =
11361: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11362: foreach my $type ('orig','ref','attrib','codebase') {
11363: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11364: $env{'form.embedded_'.$type.'_'.$i} =
11365: &unescape($env{'form.embedded_'.$type.'_'.$i});
11366: }
11367: }
1.661 raeburn 11368: my ($path,$fname) =
11369: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11370: # no path, whole string is fname
11371: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11372: $fname = &Apache::lonnet::clean_filename($fname);
11373: # See if there is anything left
11374: next if ($fname eq '');
11375:
11376: # Check if file already exists as a file or directory.
11377: my ($state,$msg);
11378: if ($context eq 'portfolio') {
11379: my $port_path = $dirpath;
11380: if ($group ne '') {
11381: $port_path = "groups/$group/$port_path";
11382: }
1.987 raeburn 11383: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11384: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11385: $dir_root,$port_path,$disk_quota,
11386: $current_disk_usage,$uname,$udom);
11387: if ($state eq 'will_exceed_quota'
1.984 raeburn 11388: || $state eq 'file_locked') {
1.661 raeburn 11389: $output .= $msg;
11390: next;
11391: }
11392: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11393: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11394: if ($state eq 'exists') {
11395: $output .= $msg;
11396: next;
11397: }
11398: }
11399: # Check if extension is valid
11400: if (($fname =~ /\.(\w+)$/) &&
11401: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 11402: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11403: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11404: next;
11405: } elsif (($fname =~ /\.(\w+)$/) &&
11406: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11407: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11408: next;
11409: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 11410: $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 11411: next;
11412: }
11413: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 11414: my $subdir = $path;
11415: $subdir =~ s{/+$}{};
1.661 raeburn 11416: if ($context eq 'portfolio') {
1.984 raeburn 11417: my $result;
11418: if ($state eq 'existingfile') {
11419: $result=
11420: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 11421: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11422: } else {
1.984 raeburn 11423: $result=
11424: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11425: $dirpath.
1.1075.2.35 raeburn 11426: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11427: if ($result !~ m|^/uploaded/|) {
11428: $output .= '<span class="LC_error">'
11429: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11430: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11431: .'</span><br />';
11432: next;
11433: } else {
1.987 raeburn 11434: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11435: $path.$fname.'</span>').'<br />';
1.984 raeburn 11436: }
1.661 raeburn 11437: }
1.1075.2.35 raeburn 11438: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
11439: my $extendedsubdir = $dirpath.'/'.$subdir;
11440: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11441: my $result =
1.1075.2.35 raeburn 11442: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11443: if ($result !~ m|^/uploaded/|) {
11444: $output .= '<span class="LC_error">'
11445: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11446: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11447: .'</span><br />';
11448: next;
11449: } else {
11450: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11451: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 11452: if ($context eq 'syllabus') {
11453: &Apache::lonnet::make_public_indefinitely($result);
11454: }
1.987 raeburn 11455: }
1.661 raeburn 11456: } else {
11457: # Save the file
11458: my $target = $env{'form.embedded_item_'.$i};
11459: my $fullpath = $dir_root.$dirpath.'/'.$path;
11460: my $dest = $fullpath.$fname;
11461: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11462: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11463: my $count;
11464: my $filepath = $dir_root;
1.1027 raeburn 11465: foreach my $subdir (@parts) {
11466: $filepath .= "/$subdir";
11467: if (!-e $filepath) {
1.661 raeburn 11468: mkdir($filepath,0770);
11469: }
11470: }
11471: my $fh;
11472: if (!open($fh,'>'.$dest)) {
11473: &Apache::lonnet::logthis('Failed to create '.$dest);
11474: $output .= '<span class="LC_error">'.
1.1071 raeburn 11475: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11476: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11477: '</span><br />';
11478: } else {
11479: if (!print $fh $env{'form.embedded_item_'.$i}) {
11480: &Apache::lonnet::logthis('Failed to write to '.$dest);
11481: $output .= '<span class="LC_error">'.
1.1071 raeburn 11482: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11483: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11484: '</span><br />';
11485: } else {
1.987 raeburn 11486: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11487: $url.'</span>').'<br />';
11488: unless ($context eq 'testbank') {
11489: $footer .= &mt('View embedded file: [_1]',
11490: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11491: }
11492: }
11493: close($fh);
11494: }
11495: }
11496: if ($env{'form.embedded_ref_'.$i}) {
11497: $pathchange{$i} = 1;
11498: }
11499: }
11500: if ($output) {
11501: $output = '<p>'.$output.'</p>';
11502: }
11503: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11504: $returnflag = 'ok';
1.1071 raeburn 11505: my $numpathchgs = scalar(keys(%pathchange));
11506: if ($numpathchgs > 0) {
1.987 raeburn 11507: if ($context eq 'portfolio') {
11508: $output .= '<p>'.&mt('or').'</p>';
11509: } elsif ($context eq 'testbank') {
1.1071 raeburn 11510: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11511: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11512: $returnflag = 'modify_orightml';
11513: }
11514: }
1.1071 raeburn 11515: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11516: }
11517:
11518: sub modify_html_form {
11519: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11520: my $end = 0;
11521: my $modifyform;
11522: if ($context eq 'upload_embedded') {
11523: return unless (ref($pathchange) eq 'HASH');
11524: if ($env{'form.number_embedded_items'}) {
11525: $end += $env{'form.number_embedded_items'};
11526: }
11527: if ($env{'form.number_pathchange_items'}) {
11528: $end += $env{'form.number_pathchange_items'};
11529: }
11530: if ($end) {
11531: for (my $i=0; $i<$end; $i++) {
11532: if ($i < $env{'form.number_embedded_items'}) {
11533: next unless($pathchange->{$i});
11534: }
11535: $modifyform .=
11536: &start_data_table_row().
11537: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11538: 'checked="checked" /></td>'.
11539: '<td>'.$env{'form.embedded_ref_'.$i}.
11540: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11541: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11542: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11543: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11544: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11545: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11546: '<td>'.$env{'form.embedded_orig_'.$i}.
11547: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11548: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11549: &end_data_table_row();
1.1071 raeburn 11550: }
1.987 raeburn 11551: }
11552: } else {
11553: $modifyform = $pathchgtable;
11554: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11555: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11556: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11557: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11558: }
11559: }
11560: if ($modifyform) {
1.1071 raeburn 11561: if ($actionurl eq '/adm/dependencies') {
11562: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11563: }
1.987 raeburn 11564: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11565: '<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".
11566: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11567: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11568: '</ol></p>'."\n".'<p>'.
11569: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11570: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11571: &start_data_table()."\n".
11572: &start_data_table_header_row().
11573: '<th>'.&mt('Change?').'</th>'.
11574: '<th>'.&mt('Current reference').'</th>'.
11575: '<th>'.&mt('Required reference').'</th>'.
11576: &end_data_table_header_row()."\n".
11577: $modifyform.
11578: &end_data_table().'<br />'."\n".$hiddenstate.
11579: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11580: '</form>'."\n";
11581: }
11582: return;
11583: }
11584:
11585: sub modify_html_refs {
1.1075.2.35 raeburn 11586: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11587: my $container;
11588: if ($context eq 'portfolio') {
11589: $container = $env{'form.container'};
11590: } elsif ($context eq 'coursedoc') {
11591: $container = $env{'form.primaryurl'};
1.1071 raeburn 11592: } elsif ($context eq 'manage_dependencies') {
11593: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11594: $container = "/$container";
1.1075.2.35 raeburn 11595: } elsif ($context eq 'syllabus') {
11596: $container = $url;
1.987 raeburn 11597: } else {
1.1027 raeburn 11598: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11599: }
11600: my (%allfiles,%codebase,$output,$content);
11601: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 11602: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11603: if (wantarray) {
11604: return ('',0,0);
11605: } else {
11606: return;
11607: }
11608: }
11609: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11610: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11611: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11612: if (wantarray) {
11613: return ('',0,0);
11614: } else {
11615: return;
11616: }
11617: }
1.987 raeburn 11618: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11619: if ($content eq '-1') {
11620: if (wantarray) {
11621: return ('',0,0);
11622: } else {
11623: return;
11624: }
11625: }
1.987 raeburn 11626: } else {
1.1071 raeburn 11627: unless ($container =~ /^\Q$dir_root\E/) {
11628: if (wantarray) {
11629: return ('',0,0);
11630: } else {
11631: return;
11632: }
11633: }
1.1075.2.128 raeburn 11634: if (open(my $fh,'<',$container)) {
1.987 raeburn 11635: $content = join('', <$fh>);
11636: close($fh);
11637: } else {
1.1071 raeburn 11638: if (wantarray) {
11639: return ('',0,0);
11640: } else {
11641: return;
11642: }
1.987 raeburn 11643: }
11644: }
11645: my ($count,$codebasecount) = (0,0);
11646: my $mm = new File::MMagic;
11647: my $mime_type = $mm->checktype_contents($content);
11648: if ($mime_type eq 'text/html') {
11649: my $parse_result =
11650: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11651: \%codebase,\$content);
11652: if ($parse_result eq 'ok') {
11653: foreach my $i (@changes) {
11654: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11655: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11656: if ($allfiles{$ref}) {
11657: my $newname = $orig;
11658: my ($attrib_regexp,$codebase);
1.1006 raeburn 11659: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11660: if ($attrib_regexp =~ /:/) {
11661: $attrib_regexp =~ s/\:/|/g;
11662: }
11663: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11664: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11665: $count += $numchg;
1.1075.2.35 raeburn 11666: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11667: delete($allfiles{$ref});
1.987 raeburn 11668: }
11669: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11670: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11671: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11672: $codebasecount ++;
11673: }
11674: }
11675: }
1.1075.2.35 raeburn 11676: my $skiprewrites;
1.987 raeburn 11677: if ($count || $codebasecount) {
11678: my $saveresult;
1.1071 raeburn 11679: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11680: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11681: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11682: if ($url eq $container) {
11683: my ($fname) = ($container =~ m{/([^/]+)$});
11684: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11685: $count,'<span class="LC_filename">'.
1.1071 raeburn 11686: $fname.'</span>').'</p>';
1.987 raeburn 11687: } else {
11688: $output = '<p class="LC_error">'.
11689: &mt('Error: update failed for: [_1].',
11690: '<span class="LC_filename">'.
11691: $container.'</span>').'</p>';
11692: }
1.1075.2.35 raeburn 11693: if ($context eq 'syllabus') {
11694: unless ($saveresult eq 'ok') {
11695: $skiprewrites = 1;
11696: }
11697: }
1.987 raeburn 11698: } else {
1.1075.2.128 raeburn 11699: if (open(my $fh,'>',$container)) {
1.987 raeburn 11700: print $fh $content;
11701: close($fh);
11702: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11703: $count,'<span class="LC_filename">'.
11704: $container.'</span>').'</p>';
1.661 raeburn 11705: } else {
1.987 raeburn 11706: $output = '<p class="LC_error">'.
11707: &mt('Error: could not update [_1].',
11708: '<span class="LC_filename">'.
11709: $container.'</span>').'</p>';
1.661 raeburn 11710: }
11711: }
11712: }
1.1075.2.35 raeburn 11713: if (($context eq 'syllabus') && (!$skiprewrites)) {
11714: my ($actionurl,$state);
11715: $actionurl = "/public/$udom/$uname/syllabus";
11716: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11717: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11718: \%codebase,
11719: {'context' => 'rewrites',
11720: 'ignore_remote_references' => 1,});
11721: if (ref($mapping) eq 'HASH') {
11722: my $rewrites = 0;
11723: foreach my $key (keys(%{$mapping})) {
11724: next if ($key =~ m{^https?://});
11725: my $ref = $mapping->{$key};
11726: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11727: my $attrib;
11728: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11729: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11730: }
11731: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11732: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11733: $rewrites += $numchg;
11734: }
11735: }
11736: if ($rewrites) {
11737: my $saveresult;
11738: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11739: if ($url eq $container) {
11740: my ($fname) = ($container =~ m{/([^/]+)$});
11741: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11742: $count,'<span class="LC_filename">'.
11743: $fname.'</span>').'</p>';
11744: } else {
11745: $output .= '<p class="LC_error">'.
11746: &mt('Error: could not update links in [_1].',
11747: '<span class="LC_filename">'.
11748: $container.'</span>').'</p>';
11749:
11750: }
11751: }
11752: }
11753: }
1.987 raeburn 11754: } else {
11755: &logthis('Failed to parse '.$container.
11756: ' to modify references: '.$parse_result);
1.661 raeburn 11757: }
11758: }
1.1071 raeburn 11759: if (wantarray) {
11760: return ($output,$count,$codebasecount);
11761: } else {
11762: return $output;
11763: }
1.661 raeburn 11764: }
11765:
11766: sub check_for_existing {
11767: my ($path,$fname,$element) = @_;
11768: my ($state,$msg);
11769: if (-d $path.'/'.$fname) {
11770: $state = 'exists';
11771: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11772: } elsif (-e $path.'/'.$fname) {
11773: $state = 'exists';
11774: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11775: }
11776: if ($state eq 'exists') {
11777: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11778: }
11779: return ($state,$msg);
11780: }
11781:
11782: sub check_for_upload {
11783: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11784: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11785: my $filesize = length($env{'form.'.$element});
11786: if (!$filesize) {
11787: my $msg = '<span class="LC_error">'.
11788: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11789: '<span class="LC_filename">'.$fname.'</span>',
11790: $filesize).'<br />'.
1.1007 raeburn 11791: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11792: '</span>';
11793: return ('zero_bytes',$msg);
11794: }
11795: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11796: my $getpropath = 1;
1.1021 raeburn 11797: my ($dirlistref,$listerror) =
11798: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11799: my $found_file = 0;
11800: my $locked_file = 0;
1.991 raeburn 11801: my @lockers;
11802: my $navmap;
11803: if ($env{'request.course.id'}) {
11804: $navmap = Apache::lonnavmaps::navmap->new();
11805: }
1.1021 raeburn 11806: if (ref($dirlistref) eq 'ARRAY') {
11807: foreach my $line (@{$dirlistref}) {
11808: my ($file_name,$rest)=split(/\&/,$line,2);
11809: if ($file_name eq $fname){
11810: $file_name = $path.$file_name;
11811: if ($group ne '') {
11812: $file_name = $group.$file_name;
11813: }
11814: $found_file = 1;
11815: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11816: foreach my $lock (@lockers) {
11817: if (ref($lock) eq 'ARRAY') {
11818: my ($symb,$crsid) = @{$lock};
11819: if ($crsid eq $env{'request.course.id'}) {
11820: if (ref($navmap)) {
11821: my $res = $navmap->getBySymb($symb);
11822: foreach my $part (@{$res->parts()}) {
11823: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11824: unless (($slot_status == $res->RESERVED) ||
11825: ($slot_status == $res->RESERVED_LOCATION)) {
11826: $locked_file = 1;
11827: }
1.991 raeburn 11828: }
1.1021 raeburn 11829: } else {
11830: $locked_file = 1;
1.991 raeburn 11831: }
11832: } else {
11833: $locked_file = 1;
11834: }
11835: }
1.1021 raeburn 11836: }
11837: } else {
11838: my @info = split(/\&/,$rest);
11839: my $currsize = $info[6]/1000;
11840: if ($currsize < $filesize) {
11841: my $extra = $filesize - $currsize;
11842: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 11843: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11844: &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 11845: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11846: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11847: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11848: return ('will_exceed_quota',$msg);
11849: }
1.984 raeburn 11850: }
11851: }
1.661 raeburn 11852: }
11853: }
11854: }
11855: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 11856: my $msg = '<p class="LC_warning">'.
11857: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
11858: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11859: return ('will_exceed_quota',$msg);
11860: } elsif ($found_file) {
11861: if ($locked_file) {
1.1075.2.69 raeburn 11862: my $msg = '<p class="LC_warning">';
1.661 raeburn 11863: $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 11864: $msg .= '</p>';
1.661 raeburn 11865: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11866: return ('file_locked',$msg);
11867: } else {
1.1075.2.69 raeburn 11868: my $msg = '<p class="LC_error">';
1.984 raeburn 11869: $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 11870: $msg .= '</p>';
1.984 raeburn 11871: return ('existingfile',$msg);
1.661 raeburn 11872: }
11873: }
11874: }
11875:
1.987 raeburn 11876: sub check_for_traversal {
11877: my ($path,$url,$toplevel) = @_;
11878: my @parts=split(/\//,$path);
11879: my $cleanpath;
11880: my $fullpath = $url;
11881: for (my $i=0;$i<@parts;$i++) {
11882: next if ($parts[$i] eq '.');
11883: if ($parts[$i] eq '..') {
11884: $fullpath =~ s{([^/]+/)$}{};
11885: } else {
11886: $fullpath .= $parts[$i].'/';
11887: }
11888: }
11889: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11890: $cleanpath = $1;
11891: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11892: my $curr_toprel = $1;
11893: my @parts = split(/\//,$curr_toprel);
11894: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11895: my @urlparts = split(/\//,$url_toprel);
11896: my $doubledots;
11897: my $startdiff = -1;
11898: for (my $i=0; $i<@urlparts; $i++) {
11899: if ($startdiff == -1) {
11900: unless ($urlparts[$i] eq $parts[$i]) {
11901: $startdiff = $i;
11902: $doubledots .= '../';
11903: }
11904: } else {
11905: $doubledots .= '../';
11906: }
11907: }
11908: if ($startdiff > -1) {
11909: $cleanpath = $doubledots;
11910: for (my $i=$startdiff; $i<@parts; $i++) {
11911: $cleanpath .= $parts[$i].'/';
11912: }
11913: }
11914: }
11915: $cleanpath =~ s{(/)$}{};
11916: return $cleanpath;
11917: }
1.31 albertel 11918:
1.1053 raeburn 11919: sub is_archive_file {
11920: my ($mimetype) = @_;
11921: if (($mimetype eq 'application/octet-stream') ||
11922: ($mimetype eq 'application/x-stuffit') ||
11923: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11924: return 1;
11925: }
11926: return;
11927: }
11928:
11929: sub decompress_form {
1.1065 raeburn 11930: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11931: my %lt = &Apache::lonlocal::texthash (
11932: this => 'This file is an archive file.',
1.1067 raeburn 11933: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11934: itsc => 'Its contents are as follows:',
1.1053 raeburn 11935: youm => 'You may wish to extract its contents.',
11936: extr => 'Extract contents',
1.1067 raeburn 11937: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11938: proa => 'Process automatically?',
1.1053 raeburn 11939: yes => 'Yes',
11940: no => 'No',
1.1067 raeburn 11941: fold => 'Title for folder containing movie',
11942: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11943: );
1.1065 raeburn 11944: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11945: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11946: my $info = &list_archive_contents($fileloc,\@paths);
11947: if (@paths) {
11948: foreach my $path (@paths) {
11949: $path =~ s{^/}{};
1.1067 raeburn 11950: if ($path =~ m{^([^/]+)/$}) {
11951: $topdir = $1;
11952: }
1.1065 raeburn 11953: if ($path =~ m{^([^/]+)/}) {
11954: $toplevel{$1} = $path;
11955: } else {
11956: $toplevel{$path} = $path;
11957: }
11958: }
11959: }
1.1067 raeburn 11960: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 11961: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11962: "$topdir/media/",
11963: "$topdir/media/$topdir.mp4",
11964: "$topdir/media/FirstFrame.png",
11965: "$topdir/media/player.swf",
11966: "$topdir/media/swfobject.js",
11967: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 11968: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 11969: "$topdir/$topdir.mp4",
11970: "$topdir/$topdir\_config.xml",
11971: "$topdir/$topdir\_controller.swf",
11972: "$topdir/$topdir\_embed.css",
11973: "$topdir/$topdir\_First_Frame.png",
11974: "$topdir/$topdir\_player.html",
11975: "$topdir/$topdir\_Thumbnails.png",
11976: "$topdir/playerProductInstall.swf",
11977: "$topdir/scripts/",
11978: "$topdir/scripts/config_xml.js",
11979: "$topdir/scripts/handlebars.js",
11980: "$topdir/scripts/jquery-1.7.1.min.js",
11981: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11982: "$topdir/scripts/modernizr.js",
11983: "$topdir/scripts/player-min.js",
11984: "$topdir/scripts/swfobject.js",
11985: "$topdir/skins/",
11986: "$topdir/skins/configuration_express.xml",
11987: "$topdir/skins/express_show/",
11988: "$topdir/skins/express_show/player-min.css",
11989: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 11990: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
11991: "$topdir/$topdir.mp4",
11992: "$topdir/$topdir\_config.xml",
11993: "$topdir/$topdir\_controller.swf",
11994: "$topdir/$topdir\_embed.css",
11995: "$topdir/$topdir\_First_Frame.png",
11996: "$topdir/$topdir\_player.html",
11997: "$topdir/$topdir\_Thumbnails.png",
11998: "$topdir/playerProductInstall.swf",
11999: "$topdir/scripts/",
12000: "$topdir/scripts/config_xml.js",
12001: "$topdir/scripts/techsmith-smart-player.min.js",
12002: "$topdir/skins/",
12003: "$topdir/skins/configuration_express.xml",
12004: "$topdir/skins/express_show/",
12005: "$topdir/skins/express_show/spritesheet.min.css",
12006: "$topdir/skins/express_show/spritesheet.png",
12007: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 12008: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12009: if (@diffs == 0) {
1.1075.2.59 raeburn 12010: $is_camtasia = 6;
12011: } else {
1.1075.2.81 raeburn 12012: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 12013: if (@diffs == 0) {
12014: $is_camtasia = 8;
1.1075.2.81 raeburn 12015: } else {
12016: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12017: if (@diffs == 0) {
12018: $is_camtasia = 8;
12019: }
1.1075.2.59 raeburn 12020: }
1.1067 raeburn 12021: }
12022: }
12023: my $output;
12024: if ($is_camtasia) {
12025: $output = <<"ENDCAM";
12026: <script type="text/javascript" language="Javascript">
12027: // <![CDATA[
12028:
12029: function camtasiaToggle() {
12030: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12031: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 12032: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12033: document.getElementById('camtasia_titles').style.display='block';
12034: } else {
12035: document.getElementById('camtasia_titles').style.display='none';
12036: }
12037: }
12038: }
12039: return;
12040: }
12041:
12042: // ]]>
12043: </script>
12044: <p>$lt{'camt'}</p>
12045: ENDCAM
1.1065 raeburn 12046: } else {
1.1067 raeburn 12047: $output = '<p>'.$lt{'this'};
12048: if ($info eq '') {
12049: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12050: } else {
12051: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12052: '<div><pre>'.$info.'</pre></div>';
12053: }
1.1065 raeburn 12054: }
1.1067 raeburn 12055: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12056: my $duplicates;
12057: my $num = 0;
12058: if (ref($dirlist) eq 'ARRAY') {
12059: foreach my $item (@{$dirlist}) {
12060: if (ref($item) eq 'ARRAY') {
12061: if (exists($toplevel{$item->[0]})) {
12062: $duplicates .=
12063: &start_data_table_row().
12064: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12065: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12066: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12067: 'value="1" />'.&mt('Yes').'</label>'.
12068: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12069: '<td>'.$item->[0].'</td>';
12070: if ($item->[2]) {
12071: $duplicates .= '<td>'.&mt('Directory').'</td>';
12072: } else {
12073: $duplicates .= '<td>'.&mt('File').'</td>';
12074: }
12075: $duplicates .= '<td>'.$item->[3].'</td>'.
12076: '<td>'.
12077: &Apache::lonlocal::locallocaltime($item->[4]).
12078: '</td>'.
12079: &end_data_table_row();
12080: $num ++;
12081: }
12082: }
12083: }
12084: }
12085: my $itemcount;
12086: if (@paths > 0) {
12087: $itemcount = scalar(@paths);
12088: } else {
12089: $itemcount = 1;
12090: }
1.1067 raeburn 12091: if ($is_camtasia) {
12092: $output .= $lt{'auto'}.'<br />'.
12093: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 12094: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12095: $lt{'yes'}.'</label> <label>'.
12096: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12097: $lt{'no'}.'</label></span><br />'.
12098: '<div id="camtasia_titles" style="display:block">'.
12099: &Apache::lonhtmlcommon::start_pick_box().
12100: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12101: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12102: &Apache::lonhtmlcommon::row_closure().
12103: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12104: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12105: &Apache::lonhtmlcommon::row_closure(1).
12106: &Apache::lonhtmlcommon::end_pick_box().
12107: '</div>';
12108: }
1.1065 raeburn 12109: $output .=
12110: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12111: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12112: "\n";
1.1065 raeburn 12113: if ($duplicates ne '') {
12114: $output .= '<p><span class="LC_warning">'.
12115: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12116: &start_data_table().
12117: &start_data_table_header_row().
12118: '<th>'.&mt('Overwrite?').'</th>'.
12119: '<th>'.&mt('Name').'</th>'.
12120: '<th>'.&mt('Type').'</th>'.
12121: '<th>'.&mt('Size').'</th>'.
12122: '<th>'.&mt('Last modified').'</th>'.
12123: &end_data_table_header_row().
12124: $duplicates.
12125: &end_data_table().
12126: '</p>';
12127: }
1.1067 raeburn 12128: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12129: if (ref($hiddenelements) eq 'HASH') {
12130: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12131: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12132: }
12133: }
12134: $output .= <<"END";
1.1067 raeburn 12135: <br />
1.1053 raeburn 12136: <input type="submit" name="decompress" value="$lt{'extr'}" />
12137: </form>
12138: $noextract
12139: END
12140: return $output;
12141: }
12142:
1.1065 raeburn 12143: sub decompression_utility {
12144: my ($program) = @_;
12145: my @utilities = ('tar','gunzip','bunzip2','unzip');
12146: my $location;
12147: if (grep(/^\Q$program\E$/,@utilities)) {
12148: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12149: '/usr/sbin/') {
12150: if (-x $dir.$program) {
12151: $location = $dir.$program;
12152: last;
12153: }
12154: }
12155: }
12156: return $location;
12157: }
12158:
12159: sub list_archive_contents {
12160: my ($file,$pathsref) = @_;
12161: my (@cmd,$output);
12162: my $needsregexp;
12163: if ($file =~ /\.zip$/) {
12164: @cmd = (&decompression_utility('unzip'),"-l");
12165: $needsregexp = 1;
12166: } elsif (($file =~ m/\.tar\.gz$/) ||
12167: ($file =~ /\.tgz$/)) {
12168: @cmd = (&decompression_utility('tar'),"-ztf");
12169: } elsif ($file =~ /\.tar\.bz2$/) {
12170: @cmd = (&decompression_utility('tar'),"-jtf");
12171: } elsif ($file =~ m|\.tar$|) {
12172: @cmd = (&decompression_utility('tar'),"-tf");
12173: }
12174: if (@cmd) {
12175: undef($!);
12176: undef($@);
12177: if (open(my $fh,"-|", @cmd, $file)) {
12178: while (my $line = <$fh>) {
12179: $output .= $line;
12180: chomp($line);
12181: my $item;
12182: if ($needsregexp) {
12183: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12184: } else {
12185: $item = $line;
12186: }
12187: if ($item ne '') {
12188: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12189: push(@{$pathsref},$item);
12190: }
12191: }
12192: }
12193: close($fh);
12194: }
12195: }
12196: return $output;
12197: }
12198:
1.1053 raeburn 12199: sub decompress_uploaded_file {
12200: my ($file,$dir) = @_;
12201: &Apache::lonnet::appenv({'cgi.file' => $file});
12202: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12203: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12204: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12205: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12206: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12207: my $decompressed = $env{'cgi.decompressed'};
12208: &Apache::lonnet::delenv('cgi.file');
12209: &Apache::lonnet::delenv('cgi.dir');
12210: &Apache::lonnet::delenv('cgi.decompressed');
12211: return ($decompressed,$result);
12212: }
12213:
1.1055 raeburn 12214: sub process_decompression {
12215: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 12216: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12217: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12218: &mt('Unexpected file path.').'</p>'."\n";
12219: }
12220: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12221: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12222: &mt('Unexpected course context.').'</p>'."\n";
12223: }
12224: unless ($file eq &Apache::lonnet::clean_filename($file)) {
12225: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12226: &mt('Filename contained unexpected characters.').'</p>'."\n";
12227: }
1.1055 raeburn 12228: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 12229: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 12230: $error = &mt('Filename not a supported archive file type.').
12231: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12232: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12233: } else {
12234: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12235: if ($docuhome eq 'no_host') {
12236: $error = &mt('Could not determine home server for course.');
12237: } else {
12238: my @ids=&Apache::lonnet::current_machine_ids();
12239: my $currdir = "$dir_root/$destination";
12240: if (grep(/^\Q$docuhome\E$/,@ids)) {
12241: $dir = &LONCAPA::propath($docudom,$docuname).
12242: "$dir_root/$destination";
12243: } else {
12244: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12245: "$dir_root/$docudom/$docuname/$destination";
12246: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12247: $error = &mt('Archive file not found.');
12248: }
12249: }
1.1065 raeburn 12250: my (@to_overwrite,@to_skip);
12251: if ($env{'form.archive_overwrite_total'} > 0) {
12252: my $total = $env{'form.archive_overwrite_total'};
12253: for (my $i=0; $i<$total; $i++) {
12254: if ($env{'form.archive_overwrite_'.$i} == 1) {
12255: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12256: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12257: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12258: }
12259: }
12260: }
12261: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 12262: my $numoverwrite = scalar(@to_overwrite);
12263: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12264: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12265: } elsif ($dir eq '') {
1.1055 raeburn 12266: $error = &mt('Directory containing archive file unavailable.');
12267: } elsif (!$error) {
1.1065 raeburn 12268: my ($decompressed,$display);
1.1075.2.128 raeburn 12269: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12270: my $tempdir = time.'_'.$$.int(rand(10000));
12271: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 12272: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12273: ($decompressed,$display) =
12274: &decompress_uploaded_file($file,"$dir/$tempdir");
12275: foreach my $item (@to_skip) {
12276: if (($item ne '') && ($item !~ /\.\./)) {
12277: if (-f "$dir/$tempdir/$item") {
12278: unlink("$dir/$tempdir/$item");
12279: } elsif (-d "$dir/$tempdir/$item") {
12280: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
12281: }
12282: }
12283: }
12284: foreach my $item (@to_overwrite) {
12285: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12286: if (($item ne '') && ($item !~ /\.\./)) {
12287: if (-f "$dir/$item") {
12288: unlink("$dir/$item");
12289: } elsif (-d "$dir/$item") {
12290: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
12291: }
12292: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12293: }
1.1065 raeburn 12294: }
12295: }
1.1075.2.128 raeburn 12296: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
12297: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
12298: }
1.1065 raeburn 12299: }
12300: } else {
12301: ($decompressed,$display) =
12302: &decompress_uploaded_file($file,$dir);
12303: }
1.1055 raeburn 12304: if ($decompressed eq 'ok') {
1.1065 raeburn 12305: $output = '<p class="LC_info">'.
12306: &mt('Files extracted successfully from archive.').
12307: '</p>'."\n";
1.1055 raeburn 12308: my ($warning,$result,@contents);
12309: my ($newdirlistref,$newlisterror) =
12310: &Apache::lonnet::dirlist($currdir,$docudom,
12311: $docuname,1);
12312: my (%is_dir,%changes,@newitems);
12313: my $dirptr = 16384;
1.1065 raeburn 12314: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12315: foreach my $dir_line (@{$newdirlistref}) {
12316: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 12317: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12318: push(@newitems,$item);
12319: if ($dirptr&$testdir) {
12320: $is_dir{$item} = 1;
12321: }
12322: $changes{$item} = 1;
12323: }
12324: }
12325: }
12326: if (keys(%changes) > 0) {
12327: foreach my $item (sort(@newitems)) {
12328: if ($changes{$item}) {
12329: push(@contents,$item);
12330: }
12331: }
12332: }
12333: if (@contents > 0) {
1.1067 raeburn 12334: my $wantform;
12335: unless ($env{'form.autoextract_camtasia'}) {
12336: $wantform = 1;
12337: }
1.1056 raeburn 12338: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12339: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12340: $currdir,\%is_dir,
12341: \%children,\%parent,
1.1056 raeburn 12342: \@contents,\%dirorder,
12343: \%titles,$wantform);
1.1055 raeburn 12344: if ($datatable ne '') {
12345: $output .= &archive_options_form('decompressed',$datatable,
12346: $count,$hiddenelem);
1.1065 raeburn 12347: my $startcount = 6;
1.1055 raeburn 12348: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12349: \%titles,\%children);
1.1055 raeburn 12350: }
1.1067 raeburn 12351: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 12352: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12353: my %displayed;
12354: my $total = 1;
12355: $env{'form.archive_directory'} = [];
12356: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12357: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12358: $path =~ s{/$}{};
12359: my $item;
12360: if ($path ne '') {
12361: $item = "$path/$titles{$i}";
12362: } else {
12363: $item = $titles{$i};
12364: }
12365: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12366: if ($item eq $contents[0]) {
12367: push(@{$env{'form.archive_directory'}},$i);
12368: $env{'form.archive_'.$i} = 'display';
12369: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12370: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 12371: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12372: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12373: $env{'form.archive_'.$i} = 'display';
12374: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12375: $displayed{'web'} = $i;
12376: } else {
1.1075.2.59 raeburn 12377: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12378: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12379: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12380: push(@{$env{'form.archive_directory'}},$i);
12381: }
12382: $env{'form.archive_'.$i} = 'dependency';
12383: }
12384: $total ++;
12385: }
12386: for (my $i=1; $i<$total; $i++) {
12387: next if ($i == $displayed{'web'});
12388: next if ($i == $displayed{'folder'});
12389: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12390: }
12391: $env{'form.phase'} = 'decompress_cleanup';
12392: $env{'form.archivedelete'} = 1;
12393: $env{'form.archive_count'} = $total-1;
12394: $output .=
12395: &process_extracted_files('coursedocs',$docudom,
12396: $docuname,$destination,
12397: $dir_root,$hiddenelem);
12398: }
1.1055 raeburn 12399: } else {
12400: $warning = &mt('No new items extracted from archive file.');
12401: }
12402: } else {
12403: $output = $display;
12404: $error = &mt('An error occurred during extraction from the archive file.');
12405: }
12406: }
12407: }
12408: }
12409: if ($error) {
12410: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12411: $error.'</p>'."\n";
12412: }
12413: if ($warning) {
12414: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12415: }
12416: return $output;
12417: }
12418:
12419: sub get_extracted {
1.1056 raeburn 12420: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12421: $titles,$wantform) = @_;
1.1055 raeburn 12422: my $count = 0;
12423: my $depth = 0;
12424: my $datatable;
1.1056 raeburn 12425: my @hierarchy;
1.1055 raeburn 12426: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12427: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12428: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12429: foreach my $item (@{$contents}) {
12430: $count ++;
1.1056 raeburn 12431: @{$dirorder->{$count}} = @hierarchy;
12432: $titles->{$count} = $item;
1.1055 raeburn 12433: &archive_hierarchy($depth,$count,$parent,$children);
12434: if ($wantform) {
12435: $datatable .= &archive_row($is_dir->{$item},$item,
12436: $currdir,$depth,$count);
12437: }
12438: if ($is_dir->{$item}) {
12439: $depth ++;
1.1056 raeburn 12440: push(@hierarchy,$count);
12441: $parent->{$depth} = $count;
1.1055 raeburn 12442: $datatable .=
12443: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12444: \$depth,\$count,\@hierarchy,$dirorder,
12445: $children,$parent,$titles,$wantform);
1.1055 raeburn 12446: $depth --;
1.1056 raeburn 12447: pop(@hierarchy);
1.1055 raeburn 12448: }
12449: }
12450: return ($count,$datatable);
12451: }
12452:
12453: sub recurse_extracted_archive {
1.1056 raeburn 12454: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12455: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12456: my $result='';
1.1056 raeburn 12457: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12458: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12459: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12460: return $result;
12461: }
12462: my $dirptr = 16384;
12463: my ($newdirlistref,$newlisterror) =
12464: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12465: if (ref($newdirlistref) eq 'ARRAY') {
12466: foreach my $dir_line (@{$newdirlistref}) {
12467: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12468: unless ($item =~ /^\.+$/) {
12469: $$count ++;
1.1056 raeburn 12470: @{$dirorder->{$$count}} = @{$hierarchy};
12471: $titles->{$$count} = $item;
1.1055 raeburn 12472: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12473:
1.1055 raeburn 12474: my $is_dir;
12475: if ($dirptr&$testdir) {
12476: $is_dir = 1;
12477: }
12478: if ($wantform) {
12479: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12480: }
12481: if ($is_dir) {
12482: $$depth ++;
1.1056 raeburn 12483: push(@{$hierarchy},$$count);
12484: $parent->{$$depth} = $$count;
1.1055 raeburn 12485: $result .=
12486: &recurse_extracted_archive("$currdir/$item",$docudom,
12487: $docuname,$depth,$count,
1.1056 raeburn 12488: $hierarchy,$dirorder,$children,
12489: $parent,$titles,$wantform);
1.1055 raeburn 12490: $$depth --;
1.1056 raeburn 12491: pop(@{$hierarchy});
1.1055 raeburn 12492: }
12493: }
12494: }
12495: }
12496: return $result;
12497: }
12498:
12499: sub archive_hierarchy {
12500: my ($depth,$count,$parent,$children) =@_;
12501: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12502: if (exists($parent->{$depth})) {
12503: $children->{$parent->{$depth}} .= $count.':';
12504: }
12505: }
12506: return;
12507: }
12508:
12509: sub archive_row {
12510: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12511: my ($name) = ($item =~ m{([^/]+)$});
12512: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12513: 'display' => 'Add as file',
1.1055 raeburn 12514: 'dependency' => 'Include as dependency',
12515: 'discard' => 'Discard',
12516: );
12517: if ($is_dir) {
1.1059 raeburn 12518: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12519: }
1.1056 raeburn 12520: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12521: my $offset = 0;
1.1055 raeburn 12522: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12523: $offset ++;
1.1065 raeburn 12524: if ($action ne 'display') {
12525: $offset ++;
12526: }
1.1055 raeburn 12527: $output .= '<td><span class="LC_nobreak">'.
12528: '<label><input type="radio" name="archive_'.$count.
12529: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12530: my $text = $choices{$action};
12531: if ($is_dir) {
12532: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12533: if ($action eq 'display') {
1.1059 raeburn 12534: $text = &mt('Add as folder');
1.1055 raeburn 12535: }
1.1056 raeburn 12536: } else {
12537: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12538:
12539: }
12540: $output .= ' /> '.$choices{$action}.'</label></span>';
12541: if ($action eq 'dependency') {
12542: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12543: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12544: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12545: '<option value=""></option>'."\n".
12546: '</select>'."\n".
12547: '</div>';
1.1059 raeburn 12548: } elsif ($action eq 'display') {
12549: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12550: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12551: '</div>';
1.1055 raeburn 12552: }
1.1056 raeburn 12553: $output .= '</td>';
1.1055 raeburn 12554: }
12555: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12556: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12557: for (my $i=0; $i<$depth; $i++) {
12558: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12559: }
12560: if ($is_dir) {
12561: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12562: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12563: } else {
12564: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12565: }
12566: $output .= ' '.$name.'</td>'."\n".
12567: &end_data_table_row();
12568: return $output;
12569: }
12570:
12571: sub archive_options_form {
1.1065 raeburn 12572: my ($form,$display,$count,$hiddenelem) = @_;
12573: my %lt = &Apache::lonlocal::texthash(
12574: perm => 'Permanently remove archive file?',
12575: hows => 'How should each extracted item be incorporated in the course?',
12576: cont => 'Content actions for all',
12577: addf => 'Add as folder/file',
12578: incd => 'Include as dependency for a displayed file',
12579: disc => 'Discard',
12580: no => 'No',
12581: yes => 'Yes',
12582: save => 'Save',
12583: );
12584: my $output = <<"END";
12585: <form name="$form" method="post" action="">
12586: <p><span class="LC_nobreak">$lt{'perm'}
12587: <label>
12588: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12589: </label>
12590:
12591: <label>
12592: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12593: </span>
12594: </p>
12595: <input type="hidden" name="phase" value="decompress_cleanup" />
12596: <br />$lt{'hows'}
12597: <div class="LC_columnSection">
12598: <fieldset>
12599: <legend>$lt{'cont'}</legend>
12600: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12601: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12602: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12603: </fieldset>
12604: </div>
12605: END
12606: return $output.
1.1055 raeburn 12607: &start_data_table()."\n".
1.1065 raeburn 12608: $display."\n".
1.1055 raeburn 12609: &end_data_table()."\n".
12610: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12611: $hiddenelem.
1.1065 raeburn 12612: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12613: '</form>';
12614: }
12615:
12616: sub archive_javascript {
1.1056 raeburn 12617: my ($startcount,$numitems,$titles,$children) = @_;
12618: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12619: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12620: my $scripttag = <<START;
12621: <script type="text/javascript">
12622: // <![CDATA[
12623:
12624: function checkAll(form,prefix) {
12625: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12626: for (var i=0; i < form.elements.length; i++) {
12627: var id = form.elements[i].id;
12628: if ((id != '') && (id != undefined)) {
12629: if (idstr.test(id)) {
12630: if (form.elements[i].type == 'radio') {
12631: form.elements[i].checked = true;
1.1056 raeburn 12632: var nostart = i-$startcount;
1.1059 raeburn 12633: var offset = nostart%7;
12634: var count = (nostart-offset)/7;
1.1056 raeburn 12635: dependencyCheck(form,count,offset);
1.1055 raeburn 12636: }
12637: }
12638: }
12639: }
12640: }
12641:
12642: function propagateCheck(form,count) {
12643: if (count > 0) {
1.1059 raeburn 12644: var startelement = $startcount + ((count-1) * 7);
12645: for (var j=1; j<6; j++) {
12646: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12647: var item = startelement + j;
12648: if (form.elements[item].type == 'radio') {
12649: if (form.elements[item].checked) {
12650: containerCheck(form,count,j);
12651: break;
12652: }
1.1055 raeburn 12653: }
12654: }
12655: }
12656: }
12657: }
12658:
12659: numitems = $numitems
1.1056 raeburn 12660: var titles = new Array(numitems);
12661: var parents = new Array(numitems);
1.1055 raeburn 12662: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12663: parents[i] = new Array;
1.1055 raeburn 12664: }
1.1059 raeburn 12665: var maintitle = '$maintitle';
1.1055 raeburn 12666:
12667: START
12668:
1.1056 raeburn 12669: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12670: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12671: for (my $i=0; $i<@contents; $i ++) {
12672: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12673: }
12674: }
12675:
1.1056 raeburn 12676: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12677: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12678: }
12679:
1.1055 raeburn 12680: $scripttag .= <<END;
12681:
12682: function containerCheck(form,count,offset) {
12683: if (count > 0) {
1.1056 raeburn 12684: dependencyCheck(form,count,offset);
1.1059 raeburn 12685: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12686: form.elements[item].checked = true;
12687: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12688: if (parents[count].length > 0) {
12689: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12690: containerCheck(form,parents[count][j],offset);
12691: }
12692: }
12693: }
12694: }
12695: }
12696:
12697: function dependencyCheck(form,count,offset) {
12698: if (count > 0) {
1.1059 raeburn 12699: var chosen = (offset+$startcount)+7*(count-1);
12700: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12701: var currtype = form.elements[depitem].type;
12702: if (form.elements[chosen].value == 'dependency') {
12703: document.getElementById('arc_depon_'+count).style.display='block';
12704: form.elements[depitem].options.length = 0;
12705: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 12706: for (var i=1; i<=numitems; i++) {
12707: if (i == count) {
12708: continue;
12709: }
1.1059 raeburn 12710: var startelement = $startcount + (i-1) * 7;
12711: for (var j=1; j<6; j++) {
12712: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12713: var item = startelement + j;
12714: if (form.elements[item].type == 'radio') {
12715: if (form.elements[item].checked) {
12716: if (form.elements[item].value == 'display') {
12717: var n = form.elements[depitem].options.length;
12718: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12719: }
12720: }
12721: }
12722: }
12723: }
12724: }
12725: } else {
12726: document.getElementById('arc_depon_'+count).style.display='none';
12727: form.elements[depitem].options.length = 0;
12728: form.elements[depitem].options[0] = new Option('Select','',true,true);
12729: }
1.1059 raeburn 12730: titleCheck(form,count,offset);
1.1056 raeburn 12731: }
12732: }
12733:
12734: function propagateSelect(form,count,offset) {
12735: if (count > 0) {
1.1065 raeburn 12736: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12737: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12738: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12739: if (parents[count].length > 0) {
12740: for (var j=0; j<parents[count].length; j++) {
12741: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12742: }
12743: }
12744: }
12745: }
12746: }
1.1056 raeburn 12747:
12748: function containerSelect(form,count,offset,picked) {
12749: if (count > 0) {
1.1065 raeburn 12750: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12751: if (form.elements[item].type == 'radio') {
12752: if (form.elements[item].value == 'dependency') {
12753: if (form.elements[item+1].type == 'select-one') {
12754: for (var i=0; i<form.elements[item+1].options.length; i++) {
12755: if (form.elements[item+1].options[i].value == picked) {
12756: form.elements[item+1].selectedIndex = i;
12757: break;
12758: }
12759: }
12760: }
12761: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12762: if (parents[count].length > 0) {
12763: for (var j=0; j<parents[count].length; j++) {
12764: containerSelect(form,parents[count][j],offset,picked);
12765: }
12766: }
12767: }
12768: }
12769: }
12770: }
12771: }
12772:
1.1059 raeburn 12773: function titleCheck(form,count,offset) {
12774: if (count > 0) {
12775: var chosen = (offset+$startcount)+7*(count-1);
12776: var depitem = $startcount + ((count-1) * 7) + 2;
12777: var currtype = form.elements[depitem].type;
12778: if (form.elements[chosen].value == 'display') {
12779: document.getElementById('arc_title_'+count).style.display='block';
12780: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12781: document.getElementById('archive_title_'+count).value=maintitle;
12782: }
12783: } else {
12784: document.getElementById('arc_title_'+count).style.display='none';
12785: if (currtype == 'text') {
12786: document.getElementById('archive_title_'+count).value='';
12787: }
12788: }
12789: }
12790: return;
12791: }
12792:
1.1055 raeburn 12793: // ]]>
12794: </script>
12795: END
12796: return $scripttag;
12797: }
12798:
12799: sub process_extracted_files {
1.1067 raeburn 12800: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12801: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 12802: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 12803: my @ids=&Apache::lonnet::current_machine_ids();
12804: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12805: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12806: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12807: if (grep(/^\Q$docuhome\E$/,@ids)) {
12808: $prefix = &LONCAPA::propath($docudom,$docuname);
12809: $pathtocheck = "$dir_root/$destination";
12810: $dir = $dir_root;
12811: $ishome = 1;
12812: } else {
12813: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12814: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 12815: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 12816: }
12817: my $currdir = "$dir_root/$destination";
12818: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12819: if ($env{'form.folderpath'}) {
12820: my @items = split('&',$env{'form.folderpath'});
12821: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 12822: if ($env{'form.folderpath'} =~ /\:1$/) {
12823: $containers{'0'}='page';
12824: } else {
12825: $containers{'0'}='sequence';
12826: }
1.1055 raeburn 12827: }
12828: my @archdirs = &get_env_multiple('form.archive_directory');
12829: if ($numitems) {
12830: for (my $i=1; $i<=$numitems; $i++) {
12831: my $path = $env{'form.archive_content_'.$i};
12832: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12833: my $item = $1;
12834: $toplevelitems{$item} = $i;
12835: if (grep(/^\Q$i\E$/,@archdirs)) {
12836: $is_dir{$item} = 1;
12837: }
12838: }
12839: }
12840: }
1.1067 raeburn 12841: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12842: if (keys(%toplevelitems) > 0) {
12843: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12844: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12845: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12846: }
1.1066 raeburn 12847: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12848: if ($numitems) {
12849: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 12850: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12851: my $path = $env{'form.archive_content_'.$i};
12852: if ($path =~ /^\Q$pathtocheck\E/) {
12853: if ($env{'form.archive_'.$i} eq 'discard') {
12854: if ($prefix ne '' && $path ne '') {
12855: if (-e $prefix.$path) {
1.1066 raeburn 12856: if ((@archdirs > 0) &&
12857: (grep(/^\Q$i\E$/,@archdirs))) {
12858: $todeletedir{$prefix.$path} = 1;
12859: } else {
12860: $todelete{$prefix.$path} = 1;
12861: }
1.1055 raeburn 12862: }
12863: }
12864: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12865: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12866: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12867: $docstitle = $env{'form.archive_title_'.$i};
12868: if ($docstitle eq '') {
12869: $docstitle = $title;
12870: }
1.1055 raeburn 12871: $outer = 0;
1.1056 raeburn 12872: if (ref($dirorder{$i}) eq 'ARRAY') {
12873: if (@{$dirorder{$i}} > 0) {
12874: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12875: if ($env{'form.archive_'.$item} eq 'display') {
12876: $outer = $item;
12877: last;
12878: }
12879: }
12880: }
12881: }
12882: my ($errtext,$fatal) =
12883: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12884: '/'.$folders{$outer}.'.'.
12885: $containers{$outer});
12886: next if ($fatal);
12887: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12888: if ($context eq 'coursedocs') {
1.1056 raeburn 12889: $mapinner{$i} = time;
1.1055 raeburn 12890: $folders{$i} = 'default_'.$mapinner{$i};
12891: $containers{$i} = 'sequence';
12892: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12893: $folders{$i}.'.'.$containers{$i};
12894: my $newidx = &LONCAPA::map::getresidx();
12895: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12896: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12897: push(@LONCAPA::map::order,$newidx);
12898: my ($outtext,$errtext) =
12899: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12900: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12901: '.'.$containers{$outer},1,1);
1.1056 raeburn 12902: $newseqid{$i} = $newidx;
1.1067 raeburn 12903: unless ($errtext) {
1.1075.2.128 raeburn 12904: $result .= '<li>'.&mt('Folder: [_1] added to course',
12905: &HTML::Entities::encode($docstitle,'<>&"'))..
12906: '</li>'."\n";
1.1067 raeburn 12907: }
1.1055 raeburn 12908: }
12909: } else {
12910: if ($context eq 'coursedocs') {
12911: my $newidx=&LONCAPA::map::getresidx();
12912: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12913: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12914: $title;
1.1075.2.128 raeburn 12915: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
12916: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
12917: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 12918: }
1.1075.2.128 raeburn 12919: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12920: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
12921: }
12922: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12923: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
12924: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
12925: unless ($ishome) {
12926: my $fetch = "$newdest{$i}/$title";
12927: $fetch =~ s/^\Q$prefix$dir\E//;
12928: $prompttofetch{$fetch} = 1;
12929: }
12930: }
12931: }
12932: $LONCAPA::map::resources[$newidx]=
12933: $docstitle.':'.$url.':false:normal:res';
12934: push(@LONCAPA::map::order, $newidx);
12935: my ($outtext,$errtext)=
12936: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12937: $docuname.'/'.$folders{$outer}.
12938: '.'.$containers{$outer},1,1);
12939: unless ($errtext) {
12940: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
12941: $result .= '<li>'.&mt('File: [_1] added to course',
12942: &HTML::Entities::encode($docstitle,'<>&"')).
12943: '</li>'."\n";
12944: }
1.1067 raeburn 12945: }
1.1075.2.128 raeburn 12946: } else {
12947: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
12948: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 12949: }
1.1055 raeburn 12950: }
12951: }
1.1075.2.11 raeburn 12952: }
12953: } else {
1.1075.2.128 raeburn 12954: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
12955: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 12956: }
12957: }
12958: for (my $i=1; $i<=$numitems; $i++) {
12959: next unless ($env{'form.archive_'.$i} eq 'dependency');
12960: my $path = $env{'form.archive_content_'.$i};
12961: if ($path =~ /^\Q$pathtocheck\E/) {
12962: my ($title) = ($path =~ m{/([^/]+)$});
12963: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12964: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12965: if (ref($dirorder{$i}) eq 'ARRAY') {
12966: my ($itemidx,$fullpath,$relpath);
12967: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12968: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12969: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 12970: if ($dirorder{$i}->[$j] eq $container) {
12971: $itemidx = $j;
1.1056 raeburn 12972: }
12973: }
1.1075.2.11 raeburn 12974: }
12975: if ($itemidx eq '') {
12976: $itemidx = 0;
12977: }
12978: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12979: if ($mapinner{$referrer{$i}}) {
12980: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12981: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12982: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12983: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12984: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12985: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12986: if (!-e $fullpath) {
12987: mkdir($fullpath,0755);
1.1056 raeburn 12988: }
12989: }
1.1075.2.11 raeburn 12990: } else {
12991: last;
1.1056 raeburn 12992: }
1.1075.2.11 raeburn 12993: }
12994: }
12995: } elsif ($newdest{$referrer{$i}}) {
12996: $fullpath = $newdest{$referrer{$i}};
12997: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12998: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12999: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13000: last;
13001: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13002: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13003: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13004: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13005: if (!-e $fullpath) {
13006: mkdir($fullpath,0755);
1.1056 raeburn 13007: }
13008: }
1.1075.2.11 raeburn 13009: } else {
13010: last;
1.1056 raeburn 13011: }
1.1075.2.11 raeburn 13012: }
13013: }
13014: if ($fullpath ne '') {
13015: if (-e "$prefix$path") {
1.1075.2.128 raeburn 13016: unless (rename("$prefix$path","$fullpath/$title")) {
13017: $warning .= &mt('Failed to rename dependency').'<br />';
13018: }
1.1075.2.11 raeburn 13019: }
13020: if (-e "$fullpath/$title") {
13021: my $showpath;
13022: if ($relpath ne '') {
13023: $showpath = "$relpath/$title";
13024: } else {
13025: $showpath = "/$title";
1.1056 raeburn 13026: }
1.1075.2.128 raeburn 13027: $result .= '<li>'.&mt('[_1] included as a dependency',
13028: &HTML::Entities::encode($showpath,'<>&"')).
13029: '</li>'."\n";
13030: unless ($ishome) {
13031: my $fetch = "$fullpath/$title";
13032: $fetch =~ s/^\Q$prefix$dir\E//;
13033: $prompttofetch{$fetch} = 1;
13034: }
1.1055 raeburn 13035: }
13036: }
13037: }
1.1075.2.11 raeburn 13038: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13039: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 13040: &HTML::Entities::encode($path,'<>&"'),
13041: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13042: '<br />';
1.1055 raeburn 13043: }
13044: } else {
1.1075.2.128 raeburn 13045: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13046: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13047: }
13048: }
13049: if (keys(%todelete)) {
13050: foreach my $key (keys(%todelete)) {
13051: unlink($key);
1.1066 raeburn 13052: }
13053: }
13054: if (keys(%todeletedir)) {
13055: foreach my $key (keys(%todeletedir)) {
13056: rmdir($key);
13057: }
13058: }
13059: foreach my $dir (sort(keys(%is_dir))) {
13060: if (($pathtocheck ne '') && ($dir ne '')) {
13061: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13062: }
13063: }
1.1067 raeburn 13064: if ($result ne '') {
13065: $output .= '<ul>'."\n".
13066: $result."\n".
13067: '</ul>';
13068: }
13069: unless ($ishome) {
13070: my $replicationfail;
13071: foreach my $item (keys(%prompttofetch)) {
13072: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13073: unless ($fetchresult eq 'ok') {
13074: $replicationfail .= '<li>'.$item.'</li>'."\n";
13075: }
13076: }
13077: if ($replicationfail) {
13078: $output .= '<p class="LC_error">'.
13079: &mt('Course home server failed to retrieve:').'<ul>'.
13080: $replicationfail.
13081: '</ul></p>';
13082: }
13083: }
1.1055 raeburn 13084: } else {
13085: $warning = &mt('No items found in archive.');
13086: }
13087: if ($error) {
13088: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13089: $error.'</p>'."\n";
13090: }
13091: if ($warning) {
13092: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13093: }
13094: return $output;
13095: }
13096:
1.1066 raeburn 13097: sub cleanup_empty_dirs {
13098: my ($path) = @_;
13099: if (($path ne '') && (-d $path)) {
13100: if (opendir(my $dirh,$path)) {
13101: my @dircontents = grep(!/^\./,readdir($dirh));
13102: my $numitems = 0;
13103: foreach my $item (@dircontents) {
13104: if (-d "$path/$item") {
1.1075.2.28 raeburn 13105: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13106: if (-e "$path/$item") {
13107: $numitems ++;
13108: }
13109: } else {
13110: $numitems ++;
13111: }
13112: }
13113: if ($numitems == 0) {
13114: rmdir($path);
13115: }
13116: closedir($dirh);
13117: }
13118: }
13119: return;
13120: }
13121:
1.41 ng 13122: =pod
1.45 matthew 13123:
1.1075.2.56 raeburn 13124: =item * &get_folder_hierarchy()
1.1068 raeburn 13125:
13126: Provides hierarchy of names of folders/sub-folders containing the current
13127: item,
13128:
13129: Inputs: 3
13130: - $navmap - navmaps object
13131:
13132: - $map - url for map (either the trigger itself, or map containing
13133: the resource, which is the trigger).
13134:
13135: - $showitem - 1 => show title for map itself; 0 => do not show.
13136:
13137: Outputs: 1 @pathitems - array of folder/subfolder names.
13138:
13139: =cut
13140:
13141: sub get_folder_hierarchy {
13142: my ($navmap,$map,$showitem) = @_;
13143: my @pathitems;
13144: if (ref($navmap)) {
13145: my $mapres = $navmap->getResourceByUrl($map);
13146: if (ref($mapres)) {
13147: my $pcslist = $mapres->map_hierarchy();
13148: if ($pcslist ne '') {
13149: my @pcs = split(/,/,$pcslist);
13150: foreach my $pc (@pcs) {
13151: if ($pc == 1) {
1.1075.2.38 raeburn 13152: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13153: } else {
13154: my $res = $navmap->getByMapPc($pc);
13155: if (ref($res)) {
13156: my $title = $res->compTitle();
13157: $title =~ s/\W+/_/g;
13158: if ($title ne '') {
13159: push(@pathitems,$title);
13160: }
13161: }
13162: }
13163: }
13164: }
1.1071 raeburn 13165: if ($showitem) {
13166: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 13167: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13168: } else {
13169: my $maptitle = $mapres->compTitle();
13170: $maptitle =~ s/\W+/_/g;
13171: if ($maptitle ne '') {
13172: push(@pathitems,$maptitle);
13173: }
1.1068 raeburn 13174: }
13175: }
13176: }
13177: }
13178: return @pathitems;
13179: }
13180:
13181: =pod
13182:
1.1015 raeburn 13183: =item * &get_turnedin_filepath()
13184:
13185: Determines path in a user's portfolio file for storage of files uploaded
13186: to a specific essayresponse or dropbox item.
13187:
13188: Inputs: 3 required + 1 optional.
13189: $symb is symb for resource, $uname and $udom are for current user (required).
13190: $caller is optional (can be "submission", if routine is called when storing
13191: an upoaded file when "Submit Answer" button was pressed).
13192:
13193: Returns array containing $path and $multiresp.
13194: $path is path in portfolio. $multiresp is 1 if this resource contains more
13195: than one file upload item. Callers of routine should append partid as a
13196: subdirectory to $path in cases where $multiresp is 1.
13197:
13198: Called by: homework/essayresponse.pm and homework/structuretags.pm
13199:
13200: =cut
13201:
13202: sub get_turnedin_filepath {
13203: my ($symb,$uname,$udom,$caller) = @_;
13204: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13205: my $turnindir;
13206: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13207: $turnindir = $userhash{'turnindir'};
13208: my ($path,$multiresp);
13209: if ($turnindir eq '') {
13210: if ($caller eq 'submission') {
13211: $turnindir = &mt('turned in');
13212: $turnindir =~ s/\W+/_/g;
13213: my %newhash = (
13214: 'turnindir' => $turnindir,
13215: );
13216: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13217: }
13218: }
13219: if ($turnindir ne '') {
13220: $path = '/'.$turnindir.'/';
13221: my ($multipart,$turnin,@pathitems);
13222: my $navmap = Apache::lonnavmaps::navmap->new();
13223: if (defined($navmap)) {
13224: my $mapres = $navmap->getResourceByUrl($map);
13225: if (ref($mapres)) {
13226: my $pcslist = $mapres->map_hierarchy();
13227: if ($pcslist ne '') {
13228: foreach my $pc (split(/,/,$pcslist)) {
13229: my $res = $navmap->getByMapPc($pc);
13230: if (ref($res)) {
13231: my $title = $res->compTitle();
13232: $title =~ s/\W+/_/g;
13233: if ($title ne '') {
1.1075.2.48 raeburn 13234: if (($pc > 1) && (length($title) > 12)) {
13235: $title = substr($title,0,12);
13236: }
1.1015 raeburn 13237: push(@pathitems,$title);
13238: }
13239: }
13240: }
13241: }
13242: my $maptitle = $mapres->compTitle();
13243: $maptitle =~ s/\W+/_/g;
13244: if ($maptitle ne '') {
1.1075.2.48 raeburn 13245: if (length($maptitle) > 12) {
13246: $maptitle = substr($maptitle,0,12);
13247: }
1.1015 raeburn 13248: push(@pathitems,$maptitle);
13249: }
13250: unless ($env{'request.state'} eq 'construct') {
13251: my $res = $navmap->getBySymb($symb);
13252: if (ref($res)) {
13253: my $partlist = $res->parts();
13254: my $totaluploads = 0;
13255: if (ref($partlist) eq 'ARRAY') {
13256: foreach my $part (@{$partlist}) {
13257: my @types = $res->responseType($part);
13258: my @ids = $res->responseIds($part);
13259: for (my $i=0; $i < scalar(@ids); $i++) {
13260: if ($types[$i] eq 'essay') {
13261: my $partid = $part.'_'.$ids[$i];
13262: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13263: $totaluploads ++;
13264: }
13265: }
13266: }
13267: }
13268: if ($totaluploads > 1) {
13269: $multiresp = 1;
13270: }
13271: }
13272: }
13273: }
13274: } else {
13275: return;
13276: }
13277: } else {
13278: return;
13279: }
13280: my $restitle=&Apache::lonnet::gettitle($symb);
13281: $restitle =~ s/\W+/_/g;
13282: if ($restitle eq '') {
13283: $restitle = ($resurl =~ m{/[^/]+$});
13284: if ($restitle eq '') {
13285: $restitle = time;
13286: }
13287: }
1.1075.2.48 raeburn 13288: if (length($restitle) > 12) {
13289: $restitle = substr($restitle,0,12);
13290: }
1.1015 raeburn 13291: push(@pathitems,$restitle);
13292: $path .= join('/',@pathitems);
13293: }
13294: return ($path,$multiresp);
13295: }
13296:
13297: =pod
13298:
1.464 albertel 13299: =back
1.41 ng 13300:
1.112 bowersj2 13301: =head1 CSV Upload/Handling functions
1.38 albertel 13302:
1.41 ng 13303: =over 4
13304:
1.648 raeburn 13305: =item * &upfile_store($r)
1.41 ng 13306:
13307: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13308: needs $env{'form.upfile'}
1.41 ng 13309: returns $datatoken to be put into hidden field
13310:
13311: =cut
1.31 albertel 13312:
13313: sub upfile_store {
13314: my $r=shift;
1.258 albertel 13315: $env{'form.upfile'}=~s/\r/\n/gs;
13316: $env{'form.upfile'}=~s/\f/\n/gs;
13317: $env{'form.upfile'}=~s/\n+/\n/gs;
13318: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13319:
1.1075.2.128 raeburn 13320: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13321: '_enroll_'.$env{'request.course.id'}.'_'.
13322: time.'_'.$$);
13323: return if ($datatoken eq '');
13324:
1.31 albertel 13325: {
1.158 raeburn 13326: my $datafile = $r->dir_config('lonDaemons').
13327: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 13328: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13329: print $fh $env{'form.upfile'};
1.158 raeburn 13330: close($fh);
13331: }
1.31 albertel 13332: }
13333: return $datatoken;
13334: }
13335:
1.56 matthew 13336: =pod
13337:
1.1075.2.128 raeburn 13338: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13339:
13340: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 13341: $datatoken is the name to assign to the temporary file.
1.258 albertel 13342: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13343:
13344: =cut
1.31 albertel 13345:
13346: sub load_tmp_file {
1.1075.2.128 raeburn 13347: my ($r,$datatoken) = @_;
13348: return if ($datatoken eq '');
1.31 albertel 13349: my @studentdata=();
13350: {
1.158 raeburn 13351: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 13352: '/tmp/'.$datatoken.'.tmp';
13353: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 13354: @studentdata=<$fh>;
13355: close($fh);
13356: }
1.31 albertel 13357: }
1.258 albertel 13358: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13359: }
13360:
1.1075.2.128 raeburn 13361: sub valid_datatoken {
13362: my ($datatoken) = @_;
1.1075.2.131 raeburn 13363: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 13364: return $datatoken;
13365: }
13366: return;
13367: }
13368:
1.56 matthew 13369: =pod
13370:
1.648 raeburn 13371: =item * &upfile_record_sep()
1.41 ng 13372:
13373: Separate uploaded file into records
13374: returns array of records,
1.258 albertel 13375: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13376:
13377: =cut
1.31 albertel 13378:
13379: sub upfile_record_sep {
1.258 albertel 13380: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13381: } else {
1.248 albertel 13382: my @records;
1.258 albertel 13383: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13384: if ($line=~/^\s*$/) { next; }
13385: push(@records,$line);
13386: }
13387: return @records;
1.31 albertel 13388: }
13389: }
13390:
1.56 matthew 13391: =pod
13392:
1.648 raeburn 13393: =item * &record_sep($record)
1.41 ng 13394:
1.258 albertel 13395: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13396:
13397: =cut
13398:
1.263 www 13399: sub takeleft {
13400: my $index=shift;
13401: return substr('0000'.$index,-4,4);
13402: }
13403:
1.31 albertel 13404: sub record_sep {
13405: my $record=shift;
13406: my %components=();
1.258 albertel 13407: if ($env{'form.upfiletype'} eq 'xml') {
13408: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13409: my $i=0;
1.356 albertel 13410: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13411: $field=~s/^(\"|\')//;
13412: $field=~s/(\"|\')$//;
1.263 www 13413: $components{&takeleft($i)}=$field;
1.31 albertel 13414: $i++;
13415: }
1.258 albertel 13416: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13417: my $i=0;
1.356 albertel 13418: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13419: $field=~s/^(\"|\')//;
13420: $field=~s/(\"|\')$//;
1.263 www 13421: $components{&takeleft($i)}=$field;
1.31 albertel 13422: $i++;
13423: }
13424: } else {
1.561 www 13425: my $separator=',';
1.480 banghart 13426: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13427: $separator=';';
1.480 banghart 13428: }
1.31 albertel 13429: my $i=0;
1.561 www 13430: # the character we are looking for to indicate the end of a quote or a record
13431: my $looking_for=$separator;
13432: # do not add the characters to the fields
13433: my $ignore=0;
13434: # we just encountered a separator (or the beginning of the record)
13435: my $just_found_separator=1;
13436: # store the field we are working on here
13437: my $field='';
13438: # work our way through all characters in record
13439: foreach my $character ($record=~/(.)/g) {
13440: if ($character eq $looking_for) {
13441: if ($character ne $separator) {
13442: # Found the end of a quote, again looking for separator
13443: $looking_for=$separator;
13444: $ignore=1;
13445: } else {
13446: # Found a separator, store away what we got
13447: $components{&takeleft($i)}=$field;
13448: $i++;
13449: $just_found_separator=1;
13450: $ignore=0;
13451: $field='';
13452: }
13453: next;
13454: }
13455: # single or double quotation marks after a separator indicate beginning of a quote
13456: # we are now looking for the end of the quote and need to ignore separators
13457: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13458: $looking_for=$character;
13459: next;
13460: }
13461: # ignore would be true after we reached the end of a quote
13462: if ($ignore) { next; }
13463: if (($just_found_separator) && ($character=~/\s/)) { next; }
13464: $field.=$character;
13465: $just_found_separator=0;
1.31 albertel 13466: }
1.561 www 13467: # catch the very last entry, since we never encountered the separator
13468: $components{&takeleft($i)}=$field;
1.31 albertel 13469: }
13470: return %components;
13471: }
13472:
1.144 matthew 13473: ######################################################
13474: ######################################################
13475:
1.56 matthew 13476: =pod
13477:
1.648 raeburn 13478: =item * &upfile_select_html()
1.41 ng 13479:
1.144 matthew 13480: Return HTML code to select a file from the users machine and specify
13481: the file type.
1.41 ng 13482:
13483: =cut
13484:
1.144 matthew 13485: ######################################################
13486: ######################################################
1.31 albertel 13487: sub upfile_select_html {
1.144 matthew 13488: my %Types = (
13489: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13490: semisv => &mt('Semicolon separated values'),
1.144 matthew 13491: space => &mt('Space separated'),
13492: tab => &mt('Tabulator separated'),
13493: # xml => &mt('HTML/XML'),
13494: );
13495: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13496: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13497: foreach my $type (sort(keys(%Types))) {
13498: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13499: }
13500: $Str .= "</select>\n";
13501: return $Str;
1.31 albertel 13502: }
13503:
1.301 albertel 13504: sub get_samples {
13505: my ($records,$toget) = @_;
13506: my @samples=({});
13507: my $got=0;
13508: foreach my $rec (@$records) {
13509: my %temp = &record_sep($rec);
13510: if (! grep(/\S/, values(%temp))) { next; }
13511: if (%temp) {
13512: $samples[$got]=\%temp;
13513: $got++;
13514: if ($got == $toget) { last; }
13515: }
13516: }
13517: return \@samples;
13518: }
13519:
1.144 matthew 13520: ######################################################
13521: ######################################################
13522:
1.56 matthew 13523: =pod
13524:
1.648 raeburn 13525: =item * &csv_print_samples($r,$records)
1.41 ng 13526:
13527: Prints a table of sample values from each column uploaded $r is an
13528: Apache Request ref, $records is an arrayref from
13529: &Apache::loncommon::upfile_record_sep
13530:
13531: =cut
13532:
1.144 matthew 13533: ######################################################
13534: ######################################################
1.31 albertel 13535: sub csv_print_samples {
13536: my ($r,$records) = @_;
1.662 bisitz 13537: my $samples = &get_samples($records,5);
1.301 albertel 13538:
1.594 raeburn 13539: $r->print(&mt('Samples').'<br />'.&start_data_table().
13540: &start_data_table_header_row());
1.356 albertel 13541: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13542: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13543: $r->print(&end_data_table_header_row());
1.301 albertel 13544: foreach my $hash (@$samples) {
1.594 raeburn 13545: $r->print(&start_data_table_row());
1.356 albertel 13546: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13547: $r->print('<td>');
1.356 albertel 13548: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13549: $r->print('</td>');
13550: }
1.594 raeburn 13551: $r->print(&end_data_table_row());
1.31 albertel 13552: }
1.594 raeburn 13553: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13554: }
13555:
1.144 matthew 13556: ######################################################
13557: ######################################################
13558:
1.56 matthew 13559: =pod
13560:
1.648 raeburn 13561: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13562:
13563: Prints a table to create associations between values and table columns.
1.144 matthew 13564:
1.41 ng 13565: $r is an Apache Request ref,
13566: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13567: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13568:
13569: =cut
13570:
1.144 matthew 13571: ######################################################
13572: ######################################################
1.31 albertel 13573: sub csv_print_select_table {
13574: my ($r,$records,$d) = @_;
1.301 albertel 13575: my $i=0;
13576: my $samples = &get_samples($records,1);
1.144 matthew 13577: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13578: &start_data_table().&start_data_table_header_row().
1.144 matthew 13579: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13580: '<th>'.&mt('Column').'</th>'.
13581: &end_data_table_header_row()."\n");
1.356 albertel 13582: foreach my $array_ref (@$d) {
13583: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13584: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13585:
1.875 bisitz 13586: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13587: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13588: $r->print('<option value="none"></option>');
1.356 albertel 13589: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13590: $r->print('<option value="'.$sample.'"'.
13591: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13592: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13593: }
1.594 raeburn 13594: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13595: $i++;
13596: }
1.594 raeburn 13597: $r->print(&end_data_table());
1.31 albertel 13598: $i--;
13599: return $i;
13600: }
1.56 matthew 13601:
1.144 matthew 13602: ######################################################
13603: ######################################################
13604:
1.56 matthew 13605: =pod
1.31 albertel 13606:
1.648 raeburn 13607: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13608:
13609: Prints a table of sample values from the upload and can make associate samples to internal names.
13610:
13611: $r is an Apache Request ref,
13612: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13613: $d is an array of 2 element arrays (internal name, displayed name)
13614:
13615: =cut
13616:
1.144 matthew 13617: ######################################################
13618: ######################################################
1.31 albertel 13619: sub csv_samples_select_table {
13620: my ($r,$records,$d) = @_;
13621: my $i=0;
1.144 matthew 13622: #
1.662 bisitz 13623: my $max_samples = 5;
13624: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13625: $r->print(&start_data_table().
13626: &start_data_table_header_row().'<th>'.
13627: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13628: &end_data_table_header_row());
1.301 albertel 13629:
13630: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13631: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13632: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13633: foreach my $option (@$d) {
13634: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13635: $r->print('<option value="'.$value.'"'.
1.253 albertel 13636: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13637: $display.'</option>');
1.31 albertel 13638: }
13639: $r->print('</select></td><td>');
1.662 bisitz 13640: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13641: if (defined($samples->[$line]{$key})) {
13642: $r->print($samples->[$line]{$key}."<br />\n");
13643: }
13644: }
1.594 raeburn 13645: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13646: $i++;
13647: }
1.594 raeburn 13648: $r->print(&end_data_table());
1.31 albertel 13649: $i--;
13650: return($i);
1.115 matthew 13651: }
13652:
1.144 matthew 13653: ######################################################
13654: ######################################################
13655:
1.115 matthew 13656: =pod
13657:
1.648 raeburn 13658: =item * &clean_excel_name($name)
1.115 matthew 13659:
13660: Returns a replacement for $name which does not contain any illegal characters.
13661:
13662: =cut
13663:
1.144 matthew 13664: ######################################################
13665: ######################################################
1.115 matthew 13666: sub clean_excel_name {
13667: my ($name) = @_;
13668: $name =~ s/[:\*\?\/\\]//g;
13669: if (length($name) > 31) {
13670: $name = substr($name,0,31);
13671: }
13672: return $name;
1.25 albertel 13673: }
1.84 albertel 13674:
1.85 albertel 13675: =pod
13676:
1.648 raeburn 13677: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13678:
13679: Returns either 1 or undef
13680:
13681: 1 if the part is to be hidden, undef if it is to be shown
13682:
13683: Arguments are:
13684:
13685: $id the id of the part to be checked
13686: $symb, optional the symb of the resource to check
13687: $udom, optional the domain of the user to check for
13688: $uname, optional the username of the user to check for
13689:
13690: =cut
1.84 albertel 13691:
13692: sub check_if_partid_hidden {
13693: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13694: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13695: $symb,$udom,$uname);
1.141 albertel 13696: my $truth=1;
13697: #if the string starts with !, then the list is the list to show not hide
13698: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13699: my @hiddenlist=split(/,/,$hiddenparts);
13700: foreach my $checkid (@hiddenlist) {
1.141 albertel 13701: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13702: }
1.141 albertel 13703: return !$truth;
1.84 albertel 13704: }
1.127 matthew 13705:
1.138 matthew 13706:
13707: ############################################################
13708: ############################################################
13709:
13710: =pod
13711:
1.157 matthew 13712: =back
13713:
1.138 matthew 13714: =head1 cgi-bin script and graphing routines
13715:
1.157 matthew 13716: =over 4
13717:
1.648 raeburn 13718: =item * &get_cgi_id()
1.138 matthew 13719:
13720: Inputs: none
13721:
13722: Returns an id which can be used to pass environment variables
13723: to various cgi-bin scripts. These environment variables will
13724: be removed from the users environment after a given time by
13725: the routine &Apache::lonnet::transfer_profile_to_env.
13726:
13727: =cut
13728:
13729: ############################################################
13730: ############################################################
1.152 albertel 13731: my $uniq=0;
1.136 matthew 13732: sub get_cgi_id {
1.154 albertel 13733: $uniq=($uniq+1)%100000;
1.280 albertel 13734: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13735: }
13736:
1.127 matthew 13737: ############################################################
13738: ############################################################
13739:
13740: =pod
13741:
1.648 raeburn 13742: =item * &DrawBarGraph()
1.127 matthew 13743:
1.138 matthew 13744: Facilitates the plotting of data in a (stacked) bar graph.
13745: Puts plot definition data into the users environment in order for
13746: graph.png to plot it. Returns an <img> tag for the plot.
13747: The bars on the plot are labeled '1','2',...,'n'.
13748:
13749: Inputs:
13750:
13751: =over 4
13752:
13753: =item $Title: string, the title of the plot
13754:
13755: =item $xlabel: string, text describing the X-axis of the plot
13756:
13757: =item $ylabel: string, text describing the Y-axis of the plot
13758:
13759: =item $Max: scalar, the maximum Y value to use in the plot
13760: If $Max is < any data point, the graph will not be rendered.
13761:
1.140 matthew 13762: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13763: they are plotted. If undefined, default values will be used.
13764:
1.178 matthew 13765: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13766:
1.138 matthew 13767: =item @Values: An array of array references. Each array reference holds data
13768: to be plotted in a stacked bar chart.
13769:
1.239 matthew 13770: =item If the final element of @Values is a hash reference the key/value
13771: pairs will be added to the graph definition.
13772:
1.138 matthew 13773: =back
13774:
13775: Returns:
13776:
13777: An <img> tag which references graph.png and the appropriate identifying
13778: information for the plot.
13779:
1.127 matthew 13780: =cut
13781:
13782: ############################################################
13783: ############################################################
1.134 matthew 13784: sub DrawBarGraph {
1.178 matthew 13785: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13786: #
13787: if (! defined($colors)) {
13788: $colors = ['#33ff00',
13789: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13790: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13791: ];
13792: }
1.228 matthew 13793: my $extra_settings = {};
13794: if (ref($Values[-1]) eq 'HASH') {
13795: $extra_settings = pop(@Values);
13796: }
1.127 matthew 13797: #
1.136 matthew 13798: my $identifier = &get_cgi_id();
13799: my $id = 'cgi.'.$identifier;
1.129 matthew 13800: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13801: return '';
13802: }
1.225 matthew 13803: #
13804: my @Labels;
13805: if (defined($labels)) {
13806: @Labels = @$labels;
13807: } else {
13808: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 13809: push(@Labels,$i+1);
1.225 matthew 13810: }
13811: }
13812: #
1.129 matthew 13813: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13814: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13815: my %ValuesHash;
13816: my $NumSets=1;
13817: foreach my $array (@Values) {
13818: next if (! ref($array));
1.136 matthew 13819: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13820: join(',',@$array);
1.129 matthew 13821: }
1.127 matthew 13822: #
1.136 matthew 13823: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13824: if ($NumBars < 3) {
13825: $width = 120+$NumBars*32;
1.220 matthew 13826: $xskip = 1;
1.225 matthew 13827: $bar_width = 30;
13828: } elsif ($NumBars < 5) {
13829: $width = 120+$NumBars*20;
13830: $xskip = 1;
13831: $bar_width = 20;
1.220 matthew 13832: } elsif ($NumBars < 10) {
1.136 matthew 13833: $width = 120+$NumBars*15;
13834: $xskip = 1;
13835: $bar_width = 15;
13836: } elsif ($NumBars <= 25) {
13837: $width = 120+$NumBars*11;
13838: $xskip = 5;
13839: $bar_width = 8;
13840: } elsif ($NumBars <= 50) {
13841: $width = 120+$NumBars*8;
13842: $xskip = 5;
13843: $bar_width = 4;
13844: } else {
13845: $width = 120+$NumBars*8;
13846: $xskip = 5;
13847: $bar_width = 4;
13848: }
13849: #
1.137 matthew 13850: $Max = 1 if ($Max < 1);
13851: if ( int($Max) < $Max ) {
13852: $Max++;
13853: $Max = int($Max);
13854: }
1.127 matthew 13855: $Title = '' if (! defined($Title));
13856: $xlabel = '' if (! defined($xlabel));
13857: $ylabel = '' if (! defined($ylabel));
1.369 www 13858: $ValuesHash{$id.'.title'} = &escape($Title);
13859: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13860: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13861: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13862: $ValuesHash{$id.'.NumBars'} = $NumBars;
13863: $ValuesHash{$id.'.NumSets'} = $NumSets;
13864: $ValuesHash{$id.'.PlotType'} = 'bar';
13865: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13866: $ValuesHash{$id.'.height'} = $height;
13867: $ValuesHash{$id.'.width'} = $width;
13868: $ValuesHash{$id.'.xskip'} = $xskip;
13869: $ValuesHash{$id.'.bar_width'} = $bar_width;
13870: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13871: #
1.228 matthew 13872: # Deal with other parameters
13873: while (my ($key,$value) = each(%$extra_settings)) {
13874: $ValuesHash{$id.'.'.$key} = $value;
13875: }
13876: #
1.646 raeburn 13877: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13878: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13879: }
13880:
13881: ############################################################
13882: ############################################################
13883:
13884: =pod
13885:
1.648 raeburn 13886: =item * &DrawXYGraph()
1.137 matthew 13887:
1.138 matthew 13888: Facilitates the plotting of data in an XY graph.
13889: Puts plot definition data into the users environment in order for
13890: graph.png to plot it. Returns an <img> tag for the plot.
13891:
13892: Inputs:
13893:
13894: =over 4
13895:
13896: =item $Title: string, the title of the plot
13897:
13898: =item $xlabel: string, text describing the X-axis of the plot
13899:
13900: =item $ylabel: string, text describing the Y-axis of the plot
13901:
13902: =item $Max: scalar, the maximum Y value to use in the plot
13903: If $Max is < any data point, the graph will not be rendered.
13904:
13905: =item $colors: Array ref containing the hex color codes for the data to be
13906: plotted in. If undefined, default values will be used.
13907:
13908: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13909:
13910: =item $Ydata: Array ref containing Array refs.
1.185 www 13911: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13912:
13913: =item %Values: hash indicating or overriding any default values which are
13914: passed to graph.png.
13915: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13916:
13917: =back
13918:
13919: Returns:
13920:
13921: An <img> tag which references graph.png and the appropriate identifying
13922: information for the plot.
13923:
1.137 matthew 13924: =cut
13925:
13926: ############################################################
13927: ############################################################
13928: sub DrawXYGraph {
13929: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13930: #
13931: # Create the identifier for the graph
13932: my $identifier = &get_cgi_id();
13933: my $id = 'cgi.'.$identifier;
13934: #
13935: $Title = '' if (! defined($Title));
13936: $xlabel = '' if (! defined($xlabel));
13937: $ylabel = '' if (! defined($ylabel));
13938: my %ValuesHash =
13939: (
1.369 www 13940: $id.'.title' => &escape($Title),
13941: $id.'.xlabel' => &escape($xlabel),
13942: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13943: $id.'.y_max_value'=> $Max,
13944: $id.'.labels' => join(',',@$Xlabels),
13945: $id.'.PlotType' => 'XY',
13946: );
13947: #
13948: if (defined($colors) && ref($colors) eq 'ARRAY') {
13949: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13950: }
13951: #
13952: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13953: return '';
13954: }
13955: my $NumSets=1;
1.138 matthew 13956: foreach my $array (@{$Ydata}){
1.137 matthew 13957: next if (! ref($array));
13958: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13959: }
1.138 matthew 13960: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 13961: #
13962: # Deal with other parameters
13963: while (my ($key,$value) = each(%Values)) {
13964: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 13965: }
13966: #
1.646 raeburn 13967: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 13968: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13969: }
13970:
13971: ############################################################
13972: ############################################################
13973:
13974: =pod
13975:
1.648 raeburn 13976: =item * &DrawXYYGraph()
1.138 matthew 13977:
13978: Facilitates the plotting of data in an XY graph with two Y axes.
13979: Puts plot definition data into the users environment in order for
13980: graph.png to plot it. Returns an <img> tag for the plot.
13981:
13982: Inputs:
13983:
13984: =over 4
13985:
13986: =item $Title: string, the title of the plot
13987:
13988: =item $xlabel: string, text describing the X-axis of the plot
13989:
13990: =item $ylabel: string, text describing the Y-axis of the plot
13991:
13992: =item $colors: Array ref containing the hex color codes for the data to be
13993: plotted in. If undefined, default values will be used.
13994:
13995: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13996:
13997: =item $Ydata1: The first data set
13998:
13999: =item $Min1: The minimum value of the left Y-axis
14000:
14001: =item $Max1: The maximum value of the left Y-axis
14002:
14003: =item $Ydata2: The second data set
14004:
14005: =item $Min2: The minimum value of the right Y-axis
14006:
14007: =item $Max2: The maximum value of the left Y-axis
14008:
14009: =item %Values: hash indicating or overriding any default values which are
14010: passed to graph.png.
14011: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14012:
14013: =back
14014:
14015: Returns:
14016:
14017: An <img> tag which references graph.png and the appropriate identifying
14018: information for the plot.
1.136 matthew 14019:
14020: =cut
14021:
14022: ############################################################
14023: ############################################################
1.137 matthew 14024: sub DrawXYYGraph {
14025: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14026: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14027: #
14028: # Create the identifier for the graph
14029: my $identifier = &get_cgi_id();
14030: my $id = 'cgi.'.$identifier;
14031: #
14032: $Title = '' if (! defined($Title));
14033: $xlabel = '' if (! defined($xlabel));
14034: $ylabel = '' if (! defined($ylabel));
14035: my %ValuesHash =
14036: (
1.369 www 14037: $id.'.title' => &escape($Title),
14038: $id.'.xlabel' => &escape($xlabel),
14039: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14040: $id.'.labels' => join(',',@$Xlabels),
14041: $id.'.PlotType' => 'XY',
14042: $id.'.NumSets' => 2,
1.137 matthew 14043: $id.'.two_axes' => 1,
14044: $id.'.y1_max_value' => $Max1,
14045: $id.'.y1_min_value' => $Min1,
14046: $id.'.y2_max_value' => $Max2,
14047: $id.'.y2_min_value' => $Min2,
1.136 matthew 14048: );
14049: #
1.137 matthew 14050: if (defined($colors) && ref($colors) eq 'ARRAY') {
14051: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14052: }
14053: #
14054: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14055: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14056: return '';
14057: }
14058: my $NumSets=1;
1.137 matthew 14059: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14060: next if (! ref($array));
14061: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14062: }
14063: #
14064: # Deal with other parameters
14065: while (my ($key,$value) = each(%Values)) {
14066: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14067: }
14068: #
1.646 raeburn 14069: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14070: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14071: }
14072:
14073: ############################################################
14074: ############################################################
14075:
14076: =pod
14077:
1.157 matthew 14078: =back
14079:
1.139 matthew 14080: =head1 Statistics helper routines?
14081:
14082: Bad place for them but what the hell.
14083:
1.157 matthew 14084: =over 4
14085:
1.648 raeburn 14086: =item * &chartlink()
1.139 matthew 14087:
14088: Returns a link to the chart for a specific student.
14089:
14090: Inputs:
14091:
14092: =over 4
14093:
14094: =item $linktext: The text of the link
14095:
14096: =item $sname: The students username
14097:
14098: =item $sdomain: The students domain
14099:
14100: =back
14101:
1.157 matthew 14102: =back
14103:
1.139 matthew 14104: =cut
14105:
14106: ############################################################
14107: ############################################################
14108: sub chartlink {
14109: my ($linktext, $sname, $sdomain) = @_;
14110: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14111: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14112: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14113: '">'.$linktext.'</a>';
1.153 matthew 14114: }
14115:
14116: #######################################################
14117: #######################################################
14118:
14119: =pod
14120:
14121: =head1 Course Environment Routines
1.157 matthew 14122:
14123: =over 4
1.153 matthew 14124:
1.648 raeburn 14125: =item * &restore_course_settings()
1.153 matthew 14126:
1.648 raeburn 14127: =item * &store_course_settings()
1.153 matthew 14128:
14129: Restores/Store indicated form parameters from the course environment.
14130: Will not overwrite existing values of the form parameters.
14131:
14132: Inputs:
14133: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14134:
14135: a hash ref describing the data to be stored. For example:
14136:
14137: %Save_Parameters = ('Status' => 'scalar',
14138: 'chartoutputmode' => 'scalar',
14139: 'chartoutputdata' => 'scalar',
14140: 'Section' => 'array',
1.373 raeburn 14141: 'Group' => 'array',
1.153 matthew 14142: 'StudentData' => 'array',
14143: 'Maps' => 'array');
14144:
14145: Returns: both routines return nothing
14146:
1.631 raeburn 14147: =back
14148:
1.153 matthew 14149: =cut
14150:
14151: #######################################################
14152: #######################################################
14153: sub store_course_settings {
1.496 albertel 14154: return &store_settings($env{'request.course.id'},@_);
14155: }
14156:
14157: sub store_settings {
1.153 matthew 14158: # save to the environment
14159: # appenv the same items, just to be safe
1.300 albertel 14160: my $udom = $env{'user.domain'};
14161: my $uname = $env{'user.name'};
1.496 albertel 14162: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14163: my %SaveHash;
14164: my %AppHash;
14165: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14166: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14167: my $envname = 'environment.'.$basename;
1.258 albertel 14168: if (exists($env{'form.'.$setting})) {
1.153 matthew 14169: # Save this value away
14170: if ($type eq 'scalar' &&
1.258 albertel 14171: (! exists($env{$envname}) ||
14172: $env{$envname} ne $env{'form.'.$setting})) {
14173: $SaveHash{$basename} = $env{'form.'.$setting};
14174: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14175: } elsif ($type eq 'array') {
14176: my $stored_form;
1.258 albertel 14177: if (ref($env{'form.'.$setting})) {
1.153 matthew 14178: $stored_form = join(',',
14179: map {
1.369 www 14180: &escape($_);
1.258 albertel 14181: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14182: } else {
14183: $stored_form =
1.369 www 14184: &escape($env{'form.'.$setting});
1.153 matthew 14185: }
14186: # Determine if the array contents are the same.
1.258 albertel 14187: if ($stored_form ne $env{$envname}) {
1.153 matthew 14188: $SaveHash{$basename} = $stored_form;
14189: $AppHash{$envname} = $stored_form;
14190: }
14191: }
14192: }
14193: }
14194: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14195: $udom,$uname);
1.153 matthew 14196: if ($put_result !~ /^(ok|delayed)/) {
14197: &Apache::lonnet::logthis('unable to save form parameters, '.
14198: 'got error:'.$put_result);
14199: }
14200: # Make sure these settings stick around in this session, too
1.646 raeburn 14201: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14202: return;
14203: }
14204:
14205: sub restore_course_settings {
1.499 albertel 14206: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14207: }
14208:
14209: sub restore_settings {
14210: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14211: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14212: next if (exists($env{'form.'.$setting}));
1.496 albertel 14213: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14214: '.'.$setting;
1.258 albertel 14215: if (exists($env{$envname})) {
1.153 matthew 14216: if ($type eq 'scalar') {
1.258 albertel 14217: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14218: } elsif ($type eq 'array') {
1.258 albertel 14219: $env{'form.'.$setting} = [
1.153 matthew 14220: map {
1.369 www 14221: &unescape($_);
1.258 albertel 14222: } split(',',$env{$envname})
1.153 matthew 14223: ];
14224: }
14225: }
14226: }
1.127 matthew 14227: }
14228:
1.618 raeburn 14229: #######################################################
14230: #######################################################
14231:
14232: =pod
14233:
14234: =head1 Domain E-mail Routines
14235:
14236: =over 4
14237:
1.648 raeburn 14238: =item * &build_recipient_list()
1.618 raeburn 14239:
1.1075.2.44 raeburn 14240: Build recipient lists for following types of e-mail:
1.766 raeburn 14241: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 14242: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14243: module change checking, student/employee ID conflict checks, as
14244: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14245: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14246:
14247: Inputs:
1.1075.2.44 raeburn 14248: defmail (scalar - email address of default recipient),
14249: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14250: requestsmail, updatesmail, or idconflictsmail).
14251:
1.619 raeburn 14252: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 14253:
14254: origmail (scalar - email address of recipient from loncapa.conf,
14255: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14256:
1.1075.2.139 raeburn 14257: $requname username of requester (if mailing type is helpdeskmail)
14258:
14259: $requdom domain of requester (if mailing type is helpdeskmail)
14260:
14261: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14262:
1.655 raeburn 14263: Returns: comma separated list of addresses to which to send e-mail.
14264:
14265: =back
1.618 raeburn 14266:
14267: =cut
14268:
14269: ############################################################
14270: ############################################################
14271: sub build_recipient_list {
1.1075.2.139 raeburn 14272: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14273: my @recipients;
1.1075.2.122 raeburn 14274: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14275: my %domconfig =
1.1075.2.122 raeburn 14276: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14277: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14278: if (exists($domconfig{'contacts'}{$mailing})) {
14279: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14280: my @contacts = ('adminemail','supportemail');
14281: foreach my $item (@contacts) {
14282: if ($domconfig{'contacts'}{$mailing}{$item}) {
14283: my $addr = $domconfig{'contacts'}{$item};
14284: if (!grep(/^\Q$addr\E$/,@recipients)) {
14285: push(@recipients,$addr);
14286: }
1.619 raeburn 14287: }
1.1075.2.122 raeburn 14288: }
14289: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14290: if ($mailing eq 'helpdeskmail') {
14291: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14292: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14293: my @ok_bccs;
14294: foreach my $bcc (@bccs) {
14295: $bcc =~ s/^\s+//g;
14296: $bcc =~ s/\s+$//g;
14297: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14298: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14299: push(@ok_bccs,$bcc);
14300: }
14301: }
14302: }
14303: if (@ok_bccs > 0) {
14304: $allbcc = join(', ',@ok_bccs);
14305: }
14306: }
14307: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14308: }
14309: }
1.766 raeburn 14310: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14311: $lastresort = $origmail;
1.618 raeburn 14312: }
1.1075.2.139 raeburn 14313: if ($mailing eq 'helpdeskmail') {
14314: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14315: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14316: my ($inststatus,$inststatus_checked);
14317: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14318: ($env{'user.domain'} ne 'public')) {
14319: $inststatus_checked = 1;
14320: $inststatus = $env{'environment.inststatus'};
14321: }
14322: unless ($inststatus_checked) {
14323: if (($requname ne '') && ($requdom ne '')) {
14324: if (($requname =~ /^$match_username$/) &&
14325: ($requdom =~ /^$match_domain$/) &&
14326: (&Apache::lonnet::domain($requdom))) {
14327: my $requhome = &Apache::lonnet::homeserver($requname,
14328: $requdom);
14329: unless ($requhome eq 'no_host') {
14330: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14331: $inststatus = $userenv{'inststatus'};
14332: $inststatus_checked = 1;
14333: }
14334: }
14335: }
14336: }
14337: unless ($inststatus_checked) {
14338: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
14339: my %srch = (srchby => 'email',
14340: srchdomain => $defdom,
14341: srchterm => $reqemail,
14342: srchtype => 'exact');
14343: my %srch_results = &Apache::lonnet::usersearch(\%srch);
14344: foreach my $uname (keys(%srch_results)) {
14345: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14346: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14347: $inststatus_checked = 1;
14348: last;
14349: }
14350: }
14351: unless ($inststatus_checked) {
14352: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
14353: if ($dirsrchres eq 'ok') {
14354: foreach my $uname (keys(%srch_results)) {
14355: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14356: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14357: $inststatus_checked = 1;
14358: last;
14359: }
14360: }
14361: }
14362: }
14363: }
14364: }
14365: if ($inststatus ne '') {
14366: foreach my $status (split(/\:/,$inststatus)) {
14367: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
14368: my @contacts = ('adminemail','supportemail');
14369: foreach my $item (@contacts) {
14370: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
14371: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
14372: if (!grep(/^\Q$addr\E$/,@recipients)) {
14373: push(@recipients,$addr);
14374: }
14375: }
14376: }
14377: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
14378: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
14379: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
14380: my @ok_bccs;
14381: foreach my $bcc (@bccs) {
14382: $bcc =~ s/^\s+//g;
14383: $bcc =~ s/\s+$//g;
14384: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14385: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14386: push(@ok_bccs,$bcc);
14387: }
14388: }
14389: }
14390: if (@ok_bccs > 0) {
14391: $allbcc = join(', ',@ok_bccs);
14392: }
14393: }
14394: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
14395: last;
14396: }
14397: }
14398: }
14399: }
14400: }
1.619 raeburn 14401: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14402: $lastresort = $origmail;
14403: }
1.1075.2.128 raeburn 14404: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 14405: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14406: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14407: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14408: my %what = (
14409: perlvar => 1,
14410: );
14411: my $primary = &Apache::lonnet::domain($defdom,'primary');
14412: if ($primary) {
14413: my $gotaddr;
14414: my ($result,$returnhash) =
14415: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14416: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14417: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14418: $lastresort = $returnhash->{'lonSupportEMail'};
14419: $gotaddr = 1;
14420: }
14421: }
14422: unless ($gotaddr) {
14423: my $uintdom = &Apache::lonnet::internet_dom($primary);
14424: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14425: unless ($uintdom eq $intdom) {
14426: my %domconfig =
14427: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14428: if (ref($domconfig{'contacts'}) eq 'HASH') {
14429: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14430: my @contacts = ('adminemail','supportemail');
14431: foreach my $item (@contacts) {
14432: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14433: my $addr = $domconfig{'contacts'}{$item};
14434: if (!grep(/^\Q$addr\E$/,@recipients)) {
14435: push(@recipients,$addr);
14436: }
14437: }
14438: }
14439: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14440: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14441: }
14442: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14443: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14444: my @ok_bccs;
14445: foreach my $bcc (@bccs) {
14446: $bcc =~ s/^\s+//g;
14447: $bcc =~ s/\s+$//g;
14448: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14449: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14450: push(@ok_bccs,$bcc);
14451: }
14452: }
14453: }
14454: if (@ok_bccs > 0) {
14455: $allbcc = join(', ',@ok_bccs);
14456: }
14457: }
14458: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14459: }
14460: }
14461: }
14462: }
14463: }
14464: }
1.618 raeburn 14465: }
1.688 raeburn 14466: if (defined($defmail)) {
14467: if ($defmail ne '') {
14468: push(@recipients,$defmail);
14469: }
1.618 raeburn 14470: }
14471: if ($otheremails) {
1.619 raeburn 14472: my @others;
14473: if ($otheremails =~ /,/) {
14474: @others = split(/,/,$otheremails);
1.618 raeburn 14475: } else {
1.619 raeburn 14476: push(@others,$otheremails);
14477: }
14478: foreach my $addr (@others) {
14479: if (!grep(/^\Q$addr\E$/,@recipients)) {
14480: push(@recipients,$addr);
14481: }
1.618 raeburn 14482: }
14483: }
1.1075.2.128 raeburn 14484: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 14485: if ((!@recipients) && ($lastresort ne '')) {
14486: push(@recipients,$lastresort);
14487: }
14488: } elsif ($lastresort ne '') {
14489: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14490: push(@recipients,$lastresort);
14491: }
14492: }
14493: my $recipientlist = join(',',@recipients);
14494: if (wantarray) {
14495: return ($recipientlist,$allbcc,$addtext);
14496: } else {
14497: return $recipientlist;
14498: }
1.618 raeburn 14499: }
14500:
1.127 matthew 14501: ############################################################
14502: ############################################################
1.154 albertel 14503:
1.655 raeburn 14504: =pod
14505:
14506: =head1 Course Catalog Routines
14507:
14508: =over 4
14509:
14510: =item * &gather_categories()
14511:
14512: Converts category definitions - keys of categories hash stored in
14513: coursecategories in configuration.db on the primary library server in a
14514: domain - to an array. Also generates javascript and idx hash used to
14515: generate Domain Coordinator interface for editing Course Categories.
14516:
14517: Inputs:
1.663 raeburn 14518:
1.655 raeburn 14519: categories (reference to hash of category definitions).
1.663 raeburn 14520:
1.655 raeburn 14521: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14522: categories and subcategories).
1.663 raeburn 14523:
1.655 raeburn 14524: idx (reference to hash of counters used in Domain Coordinator interface for
14525: editing Course Categories).
1.663 raeburn 14526:
1.655 raeburn 14527: jsarray (reference to array of categories used to create Javascript arrays for
14528: Domain Coordinator interface for editing Course Categories).
14529:
14530: Returns: nothing
14531:
14532: Side effects: populates cats, idx and jsarray.
14533:
14534: =cut
14535:
14536: sub gather_categories {
14537: my ($categories,$cats,$idx,$jsarray) = @_;
14538: my %counters;
14539: my $num = 0;
14540: foreach my $item (keys(%{$categories})) {
14541: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14542: if ($container eq '' && $depth == 0) {
14543: $cats->[$depth][$categories->{$item}] = $cat;
14544: } else {
14545: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14546: }
14547: my ($escitem,$tail) = split(/:/,$item,2);
14548: if ($counters{$tail} eq '') {
14549: $counters{$tail} = $num;
14550: $num ++;
14551: }
14552: if (ref($idx) eq 'HASH') {
14553: $idx->{$item} = $counters{$tail};
14554: }
14555: if (ref($jsarray) eq 'ARRAY') {
14556: push(@{$jsarray->[$counters{$tail}]},$item);
14557: }
14558: }
14559: return;
14560: }
14561:
14562: =pod
14563:
14564: =item * &extract_categories()
14565:
14566: Used to generate breadcrumb trails for course categories.
14567:
14568: Inputs:
1.663 raeburn 14569:
1.655 raeburn 14570: categories (reference to hash of category definitions).
1.663 raeburn 14571:
1.655 raeburn 14572: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14573: categories and subcategories).
1.663 raeburn 14574:
1.655 raeburn 14575: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14576:
1.655 raeburn 14577: allitems (reference to hash - key is category key
14578: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14579:
1.655 raeburn 14580: idx (reference to hash of counters used in Domain Coordinator interface for
14581: editing Course Categories).
1.663 raeburn 14582:
1.655 raeburn 14583: jsarray (reference to array of categories used to create Javascript arrays for
14584: Domain Coordinator interface for editing Course Categories).
14585:
1.665 raeburn 14586: subcats (reference to hash of arrays containing all subcategories within each
14587: category, -recursive)
14588:
1.1075.2.132 raeburn 14589: maxd (reference to hash used to hold max depth for all top-level categories).
14590:
1.655 raeburn 14591: Returns: nothing
14592:
14593: Side effects: populates trails and allitems hash references.
14594:
14595: =cut
14596:
14597: sub extract_categories {
1.1075.2.132 raeburn 14598: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 14599: if (ref($categories) eq 'HASH') {
14600: &gather_categories($categories,$cats,$idx,$jsarray);
14601: if (ref($cats->[0]) eq 'ARRAY') {
14602: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14603: my $name = $cats->[0][$i];
14604: my $item = &escape($name).'::0';
14605: my $trailstr;
14606: if ($name eq 'instcode') {
14607: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14608: } elsif ($name eq 'communities') {
14609: $trailstr = &mt('Communities');
1.655 raeburn 14610: } else {
14611: $trailstr = $name;
14612: }
14613: if ($allitems->{$item} eq '') {
14614: push(@{$trails},$trailstr);
14615: $allitems->{$item} = scalar(@{$trails})-1;
14616: }
14617: my @parents = ($name);
14618: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14619: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14620: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14621: if (ref($subcats) eq 'HASH') {
14622: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14623: }
1.1075.2.132 raeburn 14624: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 14625: }
14626: } else {
14627: if (ref($subcats) eq 'HASH') {
14628: $subcats->{$item} = [];
1.655 raeburn 14629: }
1.1075.2.132 raeburn 14630: if (ref($maxd) eq 'HASH') {
14631: $maxd->{$name} = 1;
14632: }
1.655 raeburn 14633: }
14634: }
14635: }
14636: }
14637: return;
14638: }
14639:
14640: =pod
14641:
1.1075.2.56 raeburn 14642: =item * &recurse_categories()
1.655 raeburn 14643:
14644: Recursively used to generate breadcrumb trails for course categories.
14645:
14646: Inputs:
1.663 raeburn 14647:
1.655 raeburn 14648: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14649: categories and subcategories).
1.663 raeburn 14650:
1.655 raeburn 14651: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14652:
14653: category (current course category, for which breadcrumb trail is being generated).
14654:
14655: trails (reference to array of breadcrumb trails for each category).
14656:
1.655 raeburn 14657: allitems (reference to hash - key is category key
14658: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14659:
1.655 raeburn 14660: parents (array containing containers directories for current category,
14661: back to top level).
14662:
14663: Returns: nothing
14664:
14665: Side effects: populates trails and allitems hash references
14666:
14667: =cut
14668:
14669: sub recurse_categories {
1.1075.2.132 raeburn 14670: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 14671: my $shallower = $depth - 1;
14672: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14673: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14674: my $name = $cats->[$depth]{$category}[$k];
14675: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14676: my $trailstr = join(' -> ',(@{$parents},$category));
14677: if ($allitems->{$item} eq '') {
14678: push(@{$trails},$trailstr);
14679: $allitems->{$item} = scalar(@{$trails})-1;
14680: }
14681: my $deeper = $depth+1;
14682: push(@{$parents},$category);
1.665 raeburn 14683: if (ref($subcats) eq 'HASH') {
14684: my $subcat = &escape($name).':'.$category.':'.$depth;
14685: for (my $j=@{$parents}; $j>=0; $j--) {
14686: my $higher;
14687: if ($j > 0) {
14688: $higher = &escape($parents->[$j]).':'.
14689: &escape($parents->[$j-1]).':'.$j;
14690: } else {
14691: $higher = &escape($parents->[$j]).'::'.$j;
14692: }
14693: push(@{$subcats->{$higher}},$subcat);
14694: }
14695: }
14696: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 14697: $subcats,$maxd);
1.655 raeburn 14698: pop(@{$parents});
14699: }
14700: } else {
14701: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 14702: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 14703: if ($allitems->{$item} eq '') {
14704: push(@{$trails},$trailstr);
14705: $allitems->{$item} = scalar(@{$trails})-1;
14706: }
1.1075.2.132 raeburn 14707: if (ref($maxd) eq 'HASH') {
14708: if ($depth > $maxd->{$parents->[0]}) {
14709: $maxd->{$parents->[0]} = $depth;
14710: }
14711: }
1.655 raeburn 14712: }
14713: return;
14714: }
14715:
1.663 raeburn 14716: =pod
14717:
1.1075.2.56 raeburn 14718: =item * &assign_categories_table()
1.663 raeburn 14719:
14720: Create a datatable for display of hierarchical categories in a domain,
14721: with checkboxes to allow a course to be categorized.
14722:
14723: Inputs:
14724:
14725: cathash - reference to hash of categories defined for the domain (from
14726: configuration.db)
14727:
14728: currcat - scalar with an & separated list of categories assigned to a course.
14729:
1.919 raeburn 14730: type - scalar contains course type (Course or Community).
14731:
1.1075.2.117 raeburn 14732: disabled - scalar (optional) contains disabled="disabled" if input elements are
14733: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14734:
1.663 raeburn 14735: Returns: $output (markup to be displayed)
14736:
14737: =cut
14738:
14739: sub assign_categories_table {
1.1075.2.117 raeburn 14740: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 14741: my $output;
14742: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 14743: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
14744: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 14745: $maxdepth = scalar(@cats);
14746: if (@cats > 0) {
14747: my $itemcount = 0;
14748: if (ref($cats[0]) eq 'ARRAY') {
14749: my @currcategories;
14750: if ($currcat ne '') {
14751: @currcategories = split('&',$currcat);
14752: }
1.919 raeburn 14753: my $table;
1.663 raeburn 14754: for (my $i=0; $i<@{$cats[0]}; $i++) {
14755: my $parent = $cats[0][$i];
1.919 raeburn 14756: next if ($parent eq 'instcode');
14757: if ($type eq 'Community') {
14758: next unless ($parent eq 'communities');
14759: } else {
14760: next if ($parent eq 'communities');
14761: }
1.663 raeburn 14762: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14763: my $item = &escape($parent).'::0';
14764: my $checked = '';
14765: if (@currcategories > 0) {
14766: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14767: $checked = ' checked="checked"';
1.663 raeburn 14768: }
14769: }
1.919 raeburn 14770: my $parent_title = $parent;
14771: if ($parent eq 'communities') {
14772: $parent_title = &mt('Communities');
14773: }
14774: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14775: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14776: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 14777: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14778: my $depth = 1;
14779: push(@path,$parent);
1.1075.2.117 raeburn 14780: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 14781: pop(@path);
1.919 raeburn 14782: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14783: $itemcount ++;
14784: }
1.919 raeburn 14785: if ($itemcount) {
14786: $output = &Apache::loncommon::start_data_table().
14787: $table.
14788: &Apache::loncommon::end_data_table();
14789: }
1.663 raeburn 14790: }
14791: }
14792: }
14793: return $output;
14794: }
14795:
14796: =pod
14797:
1.1075.2.56 raeburn 14798: =item * &assign_category_rows()
1.663 raeburn 14799:
14800: Create a datatable row for display of nested categories in a domain,
14801: with checkboxes to allow a course to be categorized,called recursively.
14802:
14803: Inputs:
14804:
14805: itemcount - track row number for alternating colors
14806:
14807: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14808: categories and subcategories.
14809:
14810: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14811:
14812: parent - parent of current category item
14813:
14814: path - Array containing all categories back up through the hierarchy from the
14815: current category to the top level.
14816:
14817: currcategories - reference to array of current categories assigned to the course
14818:
1.1075.2.117 raeburn 14819: disabled - scalar (optional) contains disabled="disabled" if input elements are
14820: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14821:
1.663 raeburn 14822: Returns: $output (markup to be displayed).
14823:
14824: =cut
14825:
14826: sub assign_category_rows {
1.1075.2.117 raeburn 14827: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 14828: my ($text,$name,$item,$chgstr);
14829: if (ref($cats) eq 'ARRAY') {
14830: my $maxdepth = scalar(@{$cats});
14831: if (ref($cats->[$depth]) eq 'HASH') {
14832: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14833: my $numchildren = @{$cats->[$depth]{$parent}};
14834: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 14835: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14836: for (my $j=0; $j<$numchildren; $j++) {
14837: $name = $cats->[$depth]{$parent}[$j];
14838: $item = &escape($name).':'.&escape($parent).':'.$depth;
14839: my $deeper = $depth+1;
14840: my $checked = '';
14841: if (ref($currcategories) eq 'ARRAY') {
14842: if (@{$currcategories} > 0) {
14843: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14844: $checked = ' checked="checked"';
1.663 raeburn 14845: }
14846: }
14847: }
1.664 raeburn 14848: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14849: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14850: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 14851: '<input type="hidden" name="catname" value="'.$name.'" />'.
14852: '</td><td>';
1.663 raeburn 14853: if (ref($path) eq 'ARRAY') {
14854: push(@{$path},$name);
1.1075.2.117 raeburn 14855: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 14856: pop(@{$path});
14857: }
14858: $text .= '</td></tr>';
14859: }
14860: $text .= '</table></td>';
14861: }
14862: }
14863: }
14864: return $text;
14865: }
14866:
1.1075.2.69 raeburn 14867: =pod
14868:
14869: =back
14870:
14871: =cut
14872:
1.655 raeburn 14873: ############################################################
14874: ############################################################
14875:
14876:
1.443 albertel 14877: sub commit_customrole {
1.664 raeburn 14878: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14879: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14880: ($start?', '.&mt('starting').' '.localtime($start):'').
14881: ($end?', ending '.localtime($end):'').': <b>'.
14882: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14883: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14884: '</b><br />';
14885: return $output;
14886: }
14887:
14888: sub commit_standardrole {
1.1075.2.31 raeburn 14889: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14890: my ($output,$logmsg,$linefeed);
14891: if ($context eq 'auto') {
14892: $linefeed = "\n";
14893: } else {
14894: $linefeed = "<br />\n";
14895: }
1.443 albertel 14896: if ($three eq 'st') {
1.541 raeburn 14897: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 14898: $one,$two,$sec,$context,$credits);
1.541 raeburn 14899: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14900: ($result eq 'unknown_course') || ($result eq 'refused')) {
14901: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14902: } else {
1.541 raeburn 14903: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14904: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14905: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14906: if ($context eq 'auto') {
14907: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14908: } else {
14909: $output .= '<b>'.$result.'</b>'.$linefeed.
14910: &mt('Add to classlist').': <b>ok</b>';
14911: }
14912: $output .= $linefeed;
1.443 albertel 14913: }
14914: } else {
14915: $output = &mt('Assigning').' '.$three.' in '.$url.
14916: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14917: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 14918: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 14919: if ($context eq 'auto') {
14920: $output .= $result.$linefeed;
14921: } else {
14922: $output .= '<b>'.$result.'</b>'.$linefeed;
14923: }
1.443 albertel 14924: }
14925: return $output;
14926: }
14927:
14928: sub commit_studentrole {
1.1075.2.31 raeburn 14929: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
14930: $credits) = @_;
1.626 raeburn 14931: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 14932: if ($context eq 'auto') {
14933: $linefeed = "\n";
14934: } else {
14935: $linefeed = '<br />'."\n";
14936: }
1.443 albertel 14937: if (defined($one) && defined($two)) {
14938: my $cid=$one.'_'.$two;
14939: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
14940: my $secchange = 0;
14941: my $expire_role_result;
14942: my $modify_section_result;
1.628 raeburn 14943: if ($oldsec ne '-1') {
14944: if ($oldsec ne $sec) {
1.443 albertel 14945: $secchange = 1;
1.628 raeburn 14946: my $now = time;
1.443 albertel 14947: my $uurl='/'.$cid;
14948: $uurl=~s/\_/\//g;
14949: if ($oldsec) {
14950: $uurl.='/'.$oldsec;
14951: }
1.626 raeburn 14952: $oldsecurl = $uurl;
1.628 raeburn 14953: $expire_role_result =
1.652 raeburn 14954: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 14955: if ($env{'request.course.sec'} ne '') {
14956: if ($expire_role_result eq 'refused') {
14957: my @roles = ('st');
14958: my @statuses = ('previous');
14959: my @roledoms = ($one);
14960: my $withsec = 1;
14961: my %roleshash =
14962: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
14963: \@statuses,\@roles,\@roledoms,$withsec);
14964: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
14965: my ($oldstart,$oldend) =
14966: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
14967: if ($oldend > 0 && $oldend <= $now) {
14968: $expire_role_result = 'ok';
14969: }
14970: }
14971: }
14972: }
1.443 albertel 14973: $result = $expire_role_result;
14974: }
14975: }
14976: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 14977: $modify_section_result =
14978: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
14979: undef,undef,undef,$sec,
14980: $end,$start,'','',$cid,
14981: '',$context,$credits);
1.443 albertel 14982: if ($modify_section_result =~ /^ok/) {
14983: if ($secchange == 1) {
1.628 raeburn 14984: if ($sec eq '') {
14985: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
14986: } else {
14987: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
14988: }
1.443 albertel 14989: } elsif ($oldsec eq '-1') {
1.628 raeburn 14990: if ($sec eq '') {
14991: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
14992: } else {
14993: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14994: }
1.443 albertel 14995: } else {
1.628 raeburn 14996: if ($sec eq '') {
14997: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
14998: } else {
14999: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15000: }
1.443 albertel 15001: }
15002: } else {
1.628 raeburn 15003: if ($secchange) {
15004: $$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;
15005: } else {
15006: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15007: }
1.443 albertel 15008: }
15009: $result = $modify_section_result;
15010: } elsif ($secchange == 1) {
1.628 raeburn 15011: if ($oldsec eq '') {
1.1075.2.20 raeburn 15012: $$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 15013: } else {
15014: $$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;
15015: }
1.626 raeburn 15016: if ($expire_role_result eq 'refused') {
15017: my $newsecurl = '/'.$cid;
15018: $newsecurl =~ s/\_/\//g;
15019: if ($sec ne '') {
15020: $newsecurl.='/'.$sec;
15021: }
15022: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15023: if ($sec eq '') {
15024: $$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;
15025: } else {
15026: $$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;
15027: }
15028: }
15029: }
1.443 albertel 15030: }
15031: } else {
1.626 raeburn 15032: $$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 15033: $result = "error: incomplete course id\n";
15034: }
15035: return $result;
15036: }
15037:
1.1075.2.25 raeburn 15038: sub show_role_extent {
15039: my ($scope,$context,$role) = @_;
15040: $scope =~ s{^/}{};
15041: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15042: push(@courseroles,'co');
15043: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15044: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15045: $scope =~ s{/}{_};
15046: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15047: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15048: my ($audom,$auname) = split(/\//,$scope);
15049: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15050: &Apache::loncommon::plainname($auname,$audom).'</span>');
15051: } else {
15052: $scope =~ s{/$}{};
15053: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15054: &Apache::lonnet::domain($scope,'description').'</span>');
15055: }
15056: }
15057:
1.443 albertel 15058: ############################################################
15059: ############################################################
15060:
1.566 albertel 15061: sub check_clone {
1.578 raeburn 15062: my ($args,$linefeed) = @_;
1.566 albertel 15063: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15064: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15065: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15066: my $clonemsg;
15067: my $can_clone = 0;
1.944 raeburn 15068: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15069: if ($lctype ne 'community') {
15070: $lctype = 'course';
15071: }
1.566 albertel 15072: if ($clonehome eq 'no_host') {
1.944 raeburn 15073: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15074: $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'});
15075: } else {
15076: $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'});
15077: }
1.566 albertel 15078: } else {
15079: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15080: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15081: if ($clonedesc{'type'} ne 'Community') {
15082: $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'});
15083: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15084: }
15085: }
1.1075.2.119 raeburn 15086: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15087: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15088: $can_clone = 1;
15089: } else {
1.1075.2.95 raeburn 15090: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15091: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 15092: if ($clonehash{'cloners'} eq '') {
15093: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15094: if ($domdefs{'canclone'}) {
15095: unless ($domdefs{'canclone'} eq 'none') {
15096: if ($domdefs{'canclone'} eq 'domain') {
15097: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15098: $can_clone = 1;
15099: }
15100: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15101: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15102: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15103: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15104: $can_clone = 1;
15105: }
15106: }
15107: }
1.908 raeburn 15108: }
1.1075.2.95 raeburn 15109: } else {
15110: my @cloners = split(/,/,$clonehash{'cloners'});
15111: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15112: $can_clone = 1;
1.1075.2.95 raeburn 15113: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15114: $can_clone = 1;
1.1075.2.96 raeburn 15115: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15116: $can_clone = 1;
1.1075.2.95 raeburn 15117: }
15118: unless ($can_clone) {
1.1075.2.96 raeburn 15119: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15120: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 15121: my (%gotdomdefaults,%gotcodedefaults);
15122: foreach my $cloner (@cloners) {
15123: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15124: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15125: my (%codedefaults,@code_order);
15126: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15127: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15128: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15129: }
15130: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15131: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15132: }
15133: } else {
15134: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15135: \%codedefaults,
15136: \@code_order);
15137: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15138: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15139: }
15140: if (@code_order > 0) {
15141: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15142: $cloner,$clonehash{'internal.coursecode'},
15143: $args->{'crscode'})) {
15144: $can_clone = 1;
15145: last;
15146: }
15147: }
15148: }
15149: }
15150: }
1.1075.2.96 raeburn 15151: }
15152: }
15153: unless ($can_clone) {
15154: my $ccrole = 'cc';
15155: if ($args->{'crstype'} eq 'Community') {
15156: $ccrole = 'co';
15157: }
15158: my %roleshash =
15159: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15160: $args->{'ccdomain'},
15161: 'userroles',['active'],[$ccrole],
15162: [$args->{'clonedomain'}]);
15163: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15164: $can_clone = 1;
15165: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15166: $args->{'ccuname'},$args->{'ccdomain'})) {
15167: $can_clone = 1;
1.1075.2.95 raeburn 15168: }
15169: }
15170: unless ($can_clone) {
15171: if ($args->{'crstype'} eq 'Community') {
15172: $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'});
15173: } else {
15174: $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 15175: }
1.566 albertel 15176: }
1.578 raeburn 15177: }
1.566 albertel 15178: }
15179: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15180: }
15181:
1.444 albertel 15182: sub construct_course {
1.1075.2.119 raeburn 15183: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15184: $cnum,$category,$coderef) = @_;
1.444 albertel 15185: my $outcome;
1.541 raeburn 15186: my $linefeed = '<br />'."\n";
15187: if ($context eq 'auto') {
15188: $linefeed = "\n";
15189: }
1.566 albertel 15190:
15191: #
15192: # Are we cloning?
15193: #
15194: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15195: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15196: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15197: if ($context ne 'auto') {
1.578 raeburn 15198: if ($clonemsg ne '') {
15199: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15200: }
1.566 albertel 15201: }
15202: $outcome .= $clonemsg.$linefeed;
15203:
15204: if (!$can_clone) {
15205: return (0,$outcome);
15206: }
15207: }
15208:
1.444 albertel 15209: #
15210: # Open course
15211: #
15212: my $crstype = lc($args->{'crstype'});
15213: my %cenv=();
15214: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15215: $args->{'cdescr'},
15216: $args->{'curl'},
15217: $args->{'course_home'},
15218: $args->{'nonstandard'},
15219: $args->{'crscode'},
15220: $args->{'ccuname'}.':'.
15221: $args->{'ccdomain'},
1.882 raeburn 15222: $args->{'crstype'},
1.885 raeburn 15223: $cnum,$context,$category);
1.444 albertel 15224:
15225: # Note: The testing routines depend on this being output; see
15226: # Utils::Course. This needs to at least be output as a comment
15227: # if anyone ever decides to not show this, and Utils::Course::new
15228: # will need to be suitably modified.
1.541 raeburn 15229: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 15230: if ($$courseid =~ /^error:/) {
15231: return (0,$outcome);
15232: }
15233:
1.444 albertel 15234: #
15235: # Check if created correctly
15236: #
1.479 albertel 15237: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15238: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15239: if ($crsuhome eq 'no_host') {
15240: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15241: return (0,$outcome);
15242: }
1.541 raeburn 15243: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15244:
1.444 albertel 15245: #
1.566 albertel 15246: # Do the cloning
15247: #
15248: if ($can_clone && $cloneid) {
15249: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
15250: if ($context ne 'auto') {
15251: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15252: }
15253: $outcome .= $clonemsg.$linefeed;
15254: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15255: # Copy all files
1.637 www 15256: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15257: # Restore URL
1.566 albertel 15258: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15259: # Restore title
1.566 albertel 15260: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15261: # Restore creation date, creator and creation context.
15262: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15263: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15264: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15265: # Mark as cloned
1.566 albertel 15266: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15267: # Need to clone grading mode
15268: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15269: $cenv{'grading'}=$newenv{'grading'};
15270: # Do not clone these environment entries
15271: &Apache::lonnet::del('environment',
15272: ['default_enrollment_start_date',
15273: 'default_enrollment_end_date',
15274: 'question.email',
15275: 'policy.email',
15276: 'comment.email',
15277: 'pch.users.denied',
1.725 raeburn 15278: 'plc.users.denied',
15279: 'hidefromcat',
1.1075.2.36 raeburn 15280: 'checkforpriv',
1.1075.2.59 raeburn 15281: 'categories',
15282: 'internal.uniquecode'],
1.638 www 15283: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 15284: if ($args->{'textbook'}) {
15285: $cenv{'internal.textbook'} = $args->{'textbook'};
15286: }
1.444 albertel 15287: }
1.566 albertel 15288:
1.444 albertel 15289: #
15290: # Set environment (will override cloned, if existing)
15291: #
15292: my @sections = ();
15293: my @xlists = ();
15294: if ($args->{'crstype'}) {
15295: $cenv{'type'}=$args->{'crstype'};
15296: }
15297: if ($args->{'crsid'}) {
15298: $cenv{'courseid'}=$args->{'crsid'};
15299: }
15300: if ($args->{'crscode'}) {
15301: $cenv{'internal.coursecode'}=$args->{'crscode'};
15302: }
15303: if ($args->{'crsquota'} ne '') {
15304: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15305: } else {
15306: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15307: }
15308: if ($args->{'ccuname'}) {
15309: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15310: ':'.$args->{'ccdomain'};
15311: } else {
15312: $cenv{'internal.courseowner'} = $args->{'curruser'};
15313: }
1.1075.2.31 raeburn 15314: if ($args->{'defaultcredits'}) {
15315: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15316: }
1.444 albertel 15317: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15318: if ($args->{'crssections'}) {
15319: $cenv{'internal.sectionnums'} = '';
15320: if ($args->{'crssections'} =~ m/,/) {
15321: @sections = split/,/,$args->{'crssections'};
15322: } else {
15323: $sections[0] = $args->{'crssections'};
15324: }
15325: if (@sections > 0) {
15326: foreach my $item (@sections) {
15327: my ($sec,$gp) = split/:/,$item;
15328: my $class = $args->{'crscode'}.$sec;
15329: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15330: $cenv{'internal.sectionnums'} .= $item.',';
15331: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15332: push(@badclasses,$class);
1.444 albertel 15333: }
15334: }
15335: $cenv{'internal.sectionnums'} =~ s/,$//;
15336: }
15337: }
15338: # do not hide course coordinator from staff listing,
15339: # even if privileged
15340: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 15341: # add course coordinator's domain to domains to check for privileged users
15342: # if different to course domain
15343: if ($$crsudom ne $args->{'ccdomain'}) {
15344: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15345: }
1.444 albertel 15346: # add crosslistings
15347: if ($args->{'crsxlist'}) {
15348: $cenv{'internal.crosslistings'}='';
15349: if ($args->{'crsxlist'} =~ m/,/) {
15350: @xlists = split/,/,$args->{'crsxlist'};
15351: } else {
15352: $xlists[0] = $args->{'crsxlist'};
15353: }
15354: if (@xlists > 0) {
15355: foreach my $item (@xlists) {
15356: my ($xl,$gp) = split/:/,$item;
15357: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15358: $cenv{'internal.crosslistings'} .= $item.',';
15359: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15360: push(@badclasses,$xl);
1.444 albertel 15361: }
15362: }
15363: $cenv{'internal.crosslistings'} =~ s/,$//;
15364: }
15365: }
15366: if ($args->{'autoadds'}) {
15367: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15368: }
15369: if ($args->{'autodrops'}) {
15370: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15371: }
15372: # check for notification of enrollment changes
15373: my @notified = ();
15374: if ($args->{'notify_owner'}) {
15375: if ($args->{'ccuname'} ne '') {
15376: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15377: }
15378: }
15379: if ($args->{'notify_dc'}) {
15380: if ($uname ne '') {
1.630 raeburn 15381: push(@notified,$uname.':'.$udom);
1.444 albertel 15382: }
15383: }
15384: if (@notified > 0) {
15385: my $notifylist;
15386: if (@notified > 1) {
15387: $notifylist = join(',',@notified);
15388: } else {
15389: $notifylist = $notified[0];
15390: }
15391: $cenv{'internal.notifylist'} = $notifylist;
15392: }
15393: if (@badclasses > 0) {
15394: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 15395: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15396: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15397: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15398: );
1.1075.2.119 raeburn 15399: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15400: &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 15401: if ($context eq 'auto') {
15402: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 15403: } else {
1.566 albertel 15404: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 15405: }
15406: foreach my $item (@badclasses) {
1.541 raeburn 15407: if ($context eq 'auto') {
1.1075.2.119 raeburn 15408: $outcome .= " - $item\n";
1.541 raeburn 15409: } else {
1.1075.2.119 raeburn 15410: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15411: }
1.1075.2.119 raeburn 15412: }
15413: if ($context eq 'auto') {
15414: $outcome .= $linefeed;
15415: } else {
15416: $outcome .= "</ul><br /><br /></div>\n";
15417: }
1.444 albertel 15418: }
15419: if ($args->{'no_end_date'}) {
15420: $args->{'endaccess'} = 0;
15421: }
15422: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15423: $cenv{'internal.autoend'}=$args->{'enrollend'};
15424: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15425: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15426: if ($args->{'showphotos'}) {
15427: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15428: }
15429: $cenv{'internal.authtype'} = $args->{'authtype'};
15430: $cenv{'internal.autharg'} = $args->{'autharg'};
15431: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15432: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15433: 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');
15434: if ($context eq 'auto') {
15435: $outcome .= $krb_msg;
15436: } else {
1.566 albertel 15437: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15438: }
15439: $outcome .= $linefeed;
1.444 albertel 15440: }
15441: }
15442: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15443: if ($args->{'setpolicy'}) {
15444: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15445: }
15446: if ($args->{'setcontent'}) {
15447: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15448: }
1.1075.2.110 raeburn 15449: if ($args->{'setcomment'}) {
15450: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15451: }
1.444 albertel 15452: }
15453: if ($args->{'reshome'}) {
15454: $cenv{'reshome'}=$args->{'reshome'}.'/';
15455: $cenv{'reshome'}=~s/\/+$/\//;
15456: }
15457: #
15458: # course has keyed access
15459: #
15460: if ($args->{'setkeys'}) {
15461: $cenv{'keyaccess'}='yes';
15462: }
15463: # if specified, key authority is not course, but user
15464: # only active if keyaccess is yes
15465: if ($args->{'keyauth'}) {
1.487 albertel 15466: my ($user,$domain) = split(':',$args->{'keyauth'});
15467: $user = &LONCAPA::clean_username($user);
15468: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15469: if ($user ne '' && $domain ne '') {
1.487 albertel 15470: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15471: }
15472: }
15473:
1.1075.2.59 raeburn 15474: #
15475: # generate and store uniquecode (available to course requester), if course should have one.
15476: #
15477: if ($args->{'uniquecode'}) {
15478: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15479: if ($code) {
15480: $cenv{'internal.uniquecode'} = $code;
15481: my %crsinfo =
15482: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15483: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15484: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15485: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15486: }
15487: if (ref($coderef)) {
15488: $$coderef = $code;
15489: }
15490: }
15491: }
15492:
1.444 albertel 15493: if ($args->{'disresdis'}) {
15494: $cenv{'pch.roles.denied'}='st';
15495: }
15496: if ($args->{'disablechat'}) {
15497: $cenv{'plc.roles.denied'}='st';
15498: }
15499:
15500: # Record we've not yet viewed the Course Initialization Helper for this
15501: # course
15502: $cenv{'course.helper.not.run'} = 1;
15503: #
15504: # Use new Randomseed
15505: #
15506: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15507: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15508: #
15509: # The encryption code and receipt prefix for this course
15510: #
15511: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15512: $cenv{'internal.encpref'}=100+int(9*rand(99));
15513: #
15514: # By default, use standard grading
15515: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15516:
1.541 raeburn 15517: $outcome .= $linefeed.&mt('Setting environment').': '.
15518: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15519: #
15520: # Open all assignments
15521: #
15522: if ($args->{'openall'}) {
1.1075.2.146 raeburn 15523: my $opendate = time;
15524: if ($args->{'openallfrom'} =~ /^\d+$/) {
15525: $opendate = $args->{'openallfrom'};
15526: }
1.444 albertel 15527: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1075.2.146 raeburn 15528: my %storecontent = ($storeunder => $opendate,
1.444 albertel 15529: $storeunder.'.type' => 'date_start');
1.1075.2.146 raeburn 15530: $outcome .= &mt('All assignments open starting [_1]',
15531: &Apache::lonlocal::locallocaltime($opendate)).': '.
15532: &Apache::lonnet::cput
15533: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15534: }
15535: #
15536: # Set first page
15537: #
15538: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15539: || ($cloneid)) {
1.445 albertel 15540: use LONCAPA::map;
1.444 albertel 15541: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15542:
15543: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15544: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15545:
1.444 albertel 15546: $outcome .= ($fatal?$errtext:'read ok').' - ';
15547: my $title; my $url;
15548: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15549: $title=&mt('Syllabus');
1.444 albertel 15550: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15551: } else {
1.963 raeburn 15552: $title=&mt('Table of Contents');
1.444 albertel 15553: $url='/adm/navmaps';
15554: }
1.445 albertel 15555:
15556: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15557: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15558:
15559: if ($errtext) { $fatal=2; }
1.541 raeburn 15560: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15561: }
1.566 albertel 15562:
15563: return (1,$outcome);
1.444 albertel 15564: }
15565:
1.1075.2.59 raeburn 15566: sub make_unique_code {
15567: my ($cdom,$cnum) = @_;
15568: # get lock on uniquecodes db
15569: my $lockhash = {
15570: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15571: ':'.$env{'user.domain'},
15572: };
15573: my $tries = 0;
15574: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15575: my ($code,$error);
15576:
15577: while (($gotlock ne 'ok') && ($tries<3)) {
15578: $tries ++;
15579: sleep 1;
15580: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15581: }
15582: if ($gotlock eq 'ok') {
15583: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15584: my $gotcode;
15585: my $attempts = 0;
15586: while ((!$gotcode) && ($attempts < 100)) {
15587: $code = &generate_code();
15588: if (!exists($currcodes{$code})) {
15589: $gotcode = 1;
15590: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15591: $error = 'nostore';
15592: }
15593: }
15594: $attempts ++;
15595: }
15596: my @del_lock = ($cnum."\0".'uniquecodes');
15597: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15598: } else {
15599: $error = 'nolock';
15600: }
15601: return ($code,$error);
15602: }
15603:
15604: sub generate_code {
15605: my $code;
15606: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15607: for (my $i=0; $i<6; $i++) {
15608: my $lettnum = int (rand 2);
15609: my $item = '';
15610: if ($lettnum) {
15611: $item = $letts[int( rand(18) )];
15612: } else {
15613: $item = 1+int( rand(8) );
15614: }
15615: $code .= $item;
15616: }
15617: return $code;
15618: }
15619:
1.444 albertel 15620: ############################################################
15621: ############################################################
15622:
1.953 droeschl 15623: #SD
15624: # only Community and Course, or anything else?
1.378 raeburn 15625: sub course_type {
15626: my ($cid) = @_;
15627: if (!defined($cid)) {
15628: $cid = $env{'request.course.id'};
15629: }
1.404 albertel 15630: if (defined($env{'course.'.$cid.'.type'})) {
15631: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15632: } else {
15633: return 'Course';
1.377 raeburn 15634: }
15635: }
1.156 albertel 15636:
1.406 raeburn 15637: sub group_term {
15638: my $crstype = &course_type();
15639: my %names = (
15640: 'Course' => 'group',
1.865 raeburn 15641: 'Community' => 'group',
1.406 raeburn 15642: );
15643: return $names{$crstype};
15644: }
15645:
1.902 raeburn 15646: sub course_types {
1.1075.2.59 raeburn 15647: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15648: my %typename = (
15649: official => 'Official course',
15650: unofficial => 'Unofficial course',
15651: community => 'Community',
1.1075.2.59 raeburn 15652: textbook => 'Textbook course',
1.902 raeburn 15653: );
15654: return (\@types,\%typename);
15655: }
15656:
1.156 albertel 15657: sub icon {
15658: my ($file)=@_;
1.505 albertel 15659: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15660: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15661: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15662: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15663: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15664: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15665: $curfext.".gif") {
15666: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15667: $curfext.".gif";
15668: }
15669: }
1.249 albertel 15670: return &lonhttpdurl($iconname);
1.154 albertel 15671: }
1.84 albertel 15672:
1.575 albertel 15673: sub lonhttpdurl {
1.692 www 15674: #
15675: # Had been used for "small fry" static images on separate port 8080.
15676: # Modify here if lightweight http functionality desired again.
15677: # Currently eliminated due to increasing firewall issues.
15678: #
1.575 albertel 15679: my ($url)=@_;
1.692 www 15680: return $url;
1.215 albertel 15681: }
15682:
1.213 albertel 15683: sub connection_aborted {
15684: my ($r)=@_;
15685: $r->print(" ");$r->rflush();
15686: my $c = $r->connection;
15687: return $c->aborted();
15688: }
15689:
1.221 foxr 15690: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15691: # strings as 'strings'.
15692: sub escape_single {
1.221 foxr 15693: my ($input) = @_;
1.223 albertel 15694: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15695: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15696: return $input;
15697: }
1.223 albertel 15698:
1.222 foxr 15699: # Same as escape_single, but escape's "'s This
15700: # can be used for "strings"
15701: sub escape_double {
15702: my ($input) = @_;
15703: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15704: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15705: return $input;
15706: }
1.223 albertel 15707:
1.222 foxr 15708: # Escapes the last element of a full URL.
15709: sub escape_url {
15710: my ($url) = @_;
1.238 raeburn 15711: my @urlslices = split(/\//, $url,-1);
1.369 www 15712: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 15713: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15714: }
1.462 albertel 15715:
1.820 raeburn 15716: sub compare_arrays {
15717: my ($arrayref1,$arrayref2) = @_;
15718: my (@difference,%count);
15719: @difference = ();
15720: %count = ();
15721: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15722: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15723: foreach my $element (keys(%count)) {
15724: if ($count{$element} == 1) {
15725: push(@difference,$element);
15726: }
15727: }
15728: }
15729: return @difference;
15730: }
15731:
1.817 bisitz 15732: # -------------------------------------------------------- Initialize user login
1.462 albertel 15733: sub init_user_environment {
1.463 albertel 15734: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15735: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15736:
15737: my $public=($username eq 'public' && $domain eq 'public');
15738:
15739: # See if old ID present, if so, remove
15740:
1.1062 raeburn 15741: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15742: my $now=time;
15743:
15744: if ($public) {
15745: my $max_public=100;
15746: my $oldest;
15747: my $oldest_time=0;
15748: for(my $next=1;$next<=$max_public;$next++) {
15749: if (-e $lonids."/publicuser_$next.id") {
15750: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
15751: if ($mtime<$oldest_time || !$oldest_time) {
15752: $oldest_time=$mtime;
15753: $oldest=$next;
15754: }
15755: } else {
15756: $cookie="publicuser_$next";
15757: last;
15758: }
15759: }
15760: if (!$cookie) { $cookie="publicuser_$oldest"; }
15761: } else {
1.463 albertel 15762: # if this isn't a robot, kill any existing non-robot sessions
15763: if (!$args->{'robot'}) {
15764: opendir(DIR,$lonids);
15765: while ($filename=readdir(DIR)) {
15766: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136 raeburn 15767: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
15768: &GDBM_READER(),0640)) {
15769: my $linkedfile;
15770: if (exists($oldenv{'user.linkedenv'})) {
15771: $linkedfile = $oldenv{'user.linkedenv'};
15772: }
15773: untie(%oldenv);
15774: if (unlink("$lonids/$filename")) {
15775: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
15776: if (-l "$lonids/$linkedfile.id") {
15777: unlink("$lonids/$linkedfile.id");
15778: }
15779: }
15780: }
15781: } else {
15782: unlink($lonids.'/'.$filename);
15783: }
1.463 albertel 15784: }
1.462 albertel 15785: }
1.463 albertel 15786: closedir(DIR);
1.1075.2.84 raeburn 15787: # If there is a undeleted lockfile for the user's paste buffer remove it.
15788: my $namespace = 'nohist_courseeditor';
15789: my $lockingkey = 'paste'."\0".'locked_num';
15790: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
15791: $domain,$username);
15792: if (exists($lockhash{$lockingkey})) {
15793: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
15794: unless ($delresult eq 'ok') {
15795: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
15796: }
15797: }
1.462 albertel 15798: }
15799: # Give them a new cookie
1.463 albertel 15800: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 15801: : $now.$$.int(rand(10000)));
1.463 albertel 15802: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 15803:
15804: # Initialize roles
15805:
1.1062 raeburn 15806: ($userroles,$firstaccenv,$timerintenv) =
15807: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 15808: }
15809: # ------------------------------------ Check browser type and MathML capability
15810:
1.1075.2.77 raeburn 15811: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15812: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15813:
15814: # ------------------------------------------------------------- Get environment
15815:
15816: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15817: my ($tmp) = keys(%userenv);
15818: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
15819: } else {
15820: undef(%userenv);
15821: }
15822: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15823: $form->{'interface'}=$userenv{'interface'};
15824: }
15825: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15826:
15827: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15828: foreach my $option ('interface','localpath','localres') {
15829: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15830: }
15831: # --------------------------------------------------------- Write first profile
15832:
15833: {
15834: my %initial_env =
15835: ("user.name" => $username,
15836: "user.domain" => $domain,
15837: "user.home" => $authhost,
15838: "browser.type" => $clientbrowser,
15839: "browser.version" => $clientversion,
15840: "browser.mathml" => $clientmathml,
15841: "browser.unicode" => $clientunicode,
15842: "browser.os" => $clientos,
1.1075.2.42 raeburn 15843: "browser.mobile" => $clientmobile,
15844: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 15845: "browser.osversion" => $clientosversion,
1.462 albertel 15846: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
15847: "request.course.fn" => '',
15848: "request.course.uri" => '',
15849: "request.course.sec" => '',
15850: "request.role" => 'cm',
15851: "request.role.adv" => $env{'user.adv'},
15852: "request.host" => $ENV{'REMOTE_ADDR'},);
15853:
15854: if ($form->{'localpath'}) {
15855: $initial_env{"browser.localpath"} = $form->{'localpath'};
15856: $initial_env{"browser.localres"} = $form->{'localres'};
15857: }
15858:
15859: if ($form->{'interface'}) {
15860: $form->{'interface'}=~s/\W//gs;
15861: $initial_env{"browser.interface"} = $form->{'interface'};
15862: $env{'browser.interface'}=$form->{'interface'};
15863: }
15864:
1.1075.2.54 raeburn 15865: if ($form->{'iptoken'}) {
15866: my $lonhost = $r->dir_config('lonHostID');
15867: $initial_env{"user.noloadbalance"} = $lonhost;
15868: $env{'user.noloadbalance'} = $lonhost;
15869: }
15870:
1.1075.2.120 raeburn 15871: if ($form->{'noloadbalance'}) {
15872: my @hosts = &Apache::lonnet::current_machine_ids();
15873: my $hosthere = $form->{'noloadbalance'};
15874: if (grep(/^\Q$hosthere\E$/,@hosts)) {
15875: $initial_env{"user.noloadbalance"} = $hosthere;
15876: $env{'user.noloadbalance'} = $hosthere;
15877: }
15878: }
15879:
1.1016 raeburn 15880: unless ($domain eq 'public') {
1.1075.2.125 raeburn 15881: my %is_adv = ( is_adv => $env{'user.adv'} );
15882: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 15883:
1.1075.2.125 raeburn 15884: foreach my $tool ('aboutme','blog','webdav','portfolio') {
15885: $userenv{'availabletools.'.$tool} =
15886: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
15887: undef,\%userenv,\%domdef,\%is_adv);
15888: }
1.724 raeburn 15889:
1.1075.2.125 raeburn 15890: foreach my $crstype ('official','unofficial','community','textbook') {
15891: $userenv{'canrequest.'.$crstype} =
15892: &Apache::lonnet::usertools_access($username,$domain,$crstype,
15893: 'reload','requestcourses',
15894: \%userenv,\%domdef,\%is_adv);
15895: }
1.765 raeburn 15896:
1.1075.2.125 raeburn 15897: $userenv{'canrequest.author'} =
15898: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15899: 'reload','requestauthor',
15900: \%userenv,\%domdef,\%is_adv);
15901: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15902: $domain,$username);
15903: my $reqstatus = $reqauthor{'author_status'};
15904: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15905: if (ref($reqauthor{'author'}) eq 'HASH') {
15906: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15907: $reqauthor{'author'}{'timestamp'};
15908: }
1.1075.2.14 raeburn 15909: }
15910: }
15911:
1.462 albertel 15912: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 15913:
1.462 albertel 15914: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
15915: &GDBM_WRCREAT(),0640)) {
15916: &_add_to_env(\%disk_env,\%initial_env);
15917: &_add_to_env(\%disk_env,\%userenv,'environment.');
15918: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 15919: if (ref($firstaccenv) eq 'HASH') {
15920: &_add_to_env(\%disk_env,$firstaccenv);
15921: }
15922: if (ref($timerintenv) eq 'HASH') {
15923: &_add_to_env(\%disk_env,$timerintenv);
15924: }
1.463 albertel 15925: if (ref($args->{'extra_env'})) {
15926: &_add_to_env(\%disk_env,$args->{'extra_env'});
15927: }
1.462 albertel 15928: untie(%disk_env);
15929: } else {
1.705 tempelho 15930: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
15931: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 15932: return 'error: '.$!;
15933: }
15934: }
15935: $env{'request.role'}='cm';
15936: $env{'request.role.adv'}=$env{'user.adv'};
15937: $env{'browser.type'}=$clientbrowser;
15938:
15939: return $cookie;
15940:
15941: }
15942:
15943: sub _add_to_env {
15944: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 15945: if (ref($env_data) eq 'HASH') {
15946: while (my ($key,$value) = each(%$env_data)) {
15947: $idf->{$prefix.$key} = $value;
15948: $env{$prefix.$key} = $value;
15949: }
1.462 albertel 15950: }
15951: }
15952:
1.685 tempelho 15953: # --- Get the symbolic name of a problem and the url
15954: sub get_symb {
15955: my ($request,$silent) = @_;
1.726 raeburn 15956: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 15957: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
15958: if ($symb eq '') {
15959: if (!$silent) {
1.1071 raeburn 15960: if (ref($request)) {
15961: $request->print("Unable to handle ambiguous references:$url:.");
15962: }
1.685 tempelho 15963: return ();
15964: }
15965: }
15966: &Apache::lonenc::check_decrypt(\$symb);
15967: return ($symb);
15968: }
15969:
15970: # --------------------------------------------------------------Get annotation
15971:
15972: sub get_annotation {
15973: my ($symb,$enc) = @_;
15974:
15975: my $key = $symb;
15976: if (!$enc) {
15977: $key =
15978: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
15979: }
15980: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
15981: return $annotation{$key};
15982: }
15983:
15984: sub clean_symb {
1.731 raeburn 15985: my ($symb,$delete_enc) = @_;
1.685 tempelho 15986:
15987: &Apache::lonenc::check_decrypt(\$symb);
15988: my $enc = $env{'request.enc'};
1.731 raeburn 15989: if ($delete_enc) {
1.730 raeburn 15990: delete($env{'request.enc'});
15991: }
1.685 tempelho 15992:
15993: return ($symb,$enc);
15994: }
1.462 albertel 15995:
1.1075.2.69 raeburn 15996: ############################################################
15997: ############################################################
15998:
15999: =pod
16000:
16001: =head1 Routines for building display used to search for courses
16002:
16003:
16004: =over 4
16005:
16006: =item * &build_filters()
16007:
16008: Create markup for a table used to set filters to use when selecting
16009: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16010: and quotacheck.pl
16011:
16012:
16013: Inputs:
16014:
16015: filterlist - anonymous array of fields to include as potential filters
16016:
16017: crstype - course type
16018:
16019: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16020: to pop-open a course selector (will contain "extra element").
16021:
16022: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16023:
16024: filter - anonymous hash of criteria and their values
16025:
16026: action - form action
16027:
16028: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16029:
16030: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
16031:
16032: cloneruname - username of owner of new course who wants to clone
16033:
16034: clonerudom - domain of owner of new course who wants to clone
16035:
16036: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16037:
16038: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16039:
16040: codedom - domain
16041:
16042: formname - value of form element named "form".
16043:
16044: fixeddom - domain, if fixed.
16045:
16046: prevphase - value to assign to form element named "phase" when going back to the previous screen
16047:
16048: cnameelement - name of form element in form on opener page which will receive title of selected course
16049:
16050: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16051:
16052: cdomelement - name of form element in form on opener page which will receive domain of selected course
16053:
16054: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16055:
16056: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16057:
16058: clonewarning - warning message about missing information for intended course owner when DC creates a course
16059:
16060:
16061: Returns: $output - HTML for display of search criteria, and hidden form elements.
16062:
16063:
16064: Side Effects: None
16065:
16066: =cut
16067:
16068: # ---------------------------------------------- search for courses based on last activity etc.
16069:
16070: sub build_filters {
16071: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16072: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16073: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16074: $cnameelement,$cnumelement,$cdomelement,$setroles,
16075: $clonetext,$clonewarning) = @_;
16076: my ($list,$jscript);
16077: my $onchange = 'javascript:updateFilters(this)';
16078: my ($domainselectform,$sincefilterform,$createdfilterform,
16079: $ownerdomselectform,$persondomselectform,$instcodeform,
16080: $typeselectform,$instcodetitle);
16081: if ($formname eq '') {
16082: $formname = $caller;
16083: }
16084: foreach my $item (@{$filterlist}) {
16085: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16086: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16087: if ($item eq 'domainfilter') {
16088: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16089: } elsif ($item eq 'coursefilter') {
16090: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16091: } elsif ($item eq 'ownerfilter') {
16092: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16093: } elsif ($item eq 'ownerdomfilter') {
16094: $filter->{'ownerdomfilter'} =
16095: &LONCAPA::clean_domain($filter->{$item});
16096: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16097: 'ownerdomfilter',1);
16098: } elsif ($item eq 'personfilter') {
16099: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16100: } elsif ($item eq 'persondomfilter') {
16101: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16102: 'persondomfilter',1);
16103: } else {
16104: $filter->{$item} =~ s/\W//g;
16105: }
16106: if (!$filter->{$item}) {
16107: $filter->{$item} = '';
16108: }
16109: }
16110: if ($item eq 'domainfilter') {
16111: my $allow_blank = 1;
16112: if ($formname eq 'portform') {
16113: $allow_blank=0;
16114: } elsif ($formname eq 'studentform') {
16115: $allow_blank=0;
16116: }
16117: if ($fixeddom) {
16118: $domainselectform = '<input type="hidden" name="domainfilter"'.
16119: ' value="'.$codedom.'" />'.
16120: &Apache::lonnet::domain($codedom,'description');
16121: } else {
16122: $domainselectform = &select_dom_form($filter->{$item},
16123: 'domainfilter',
16124: $allow_blank,'',$onchange);
16125: }
16126: } else {
16127: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16128: }
16129: }
16130:
16131: # last course activity filter and selection
16132: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16133:
16134: # course created filter and selection
16135: if (exists($filter->{'createdfilter'})) {
16136: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16137: }
16138:
16139: my %lt = &Apache::lonlocal::texthash(
16140: 'cac' => "$crstype Activity",
16141: 'ccr' => "$crstype Created",
16142: 'cde' => "$crstype Title",
16143: 'cdo' => "$crstype Domain",
16144: 'ins' => 'Institutional Code',
16145: 'inc' => 'Institutional Categorization',
16146: 'cow' => "$crstype Owner/Co-owner",
16147: 'cop' => "$crstype Personnel Includes",
16148: 'cog' => 'Type',
16149: );
16150:
16151: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16152: my $typeval = 'Course';
16153: if ($crstype eq 'Community') {
16154: $typeval = 'Community';
16155: }
16156: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16157: } else {
16158: $typeselectform = '<select name="type" size="1"';
16159: if ($onchange) {
16160: $typeselectform .= ' onchange="'.$onchange.'"';
16161: }
16162: $typeselectform .= '>'."\n";
16163: foreach my $posstype ('Course','Community') {
16164: $typeselectform.='<option value="'.$posstype.'"'.
16165: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
16166: }
16167: $typeselectform.="</select>";
16168: }
16169:
16170: my ($cloneableonlyform,$cloneabletitle);
16171: if (exists($filter->{'cloneableonly'})) {
16172: my $cloneableon = '';
16173: my $cloneableoff = ' checked="checked"';
16174: if ($filter->{'cloneableonly'}) {
16175: $cloneableon = $cloneableoff;
16176: $cloneableoff = '';
16177: }
16178: $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>';
16179: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 16180: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 16181: } else {
16182: $cloneabletitle = &mt('Cloneable by you');
16183: }
16184: }
16185: my $officialjs;
16186: if ($crstype eq 'Course') {
16187: if (exists($filter->{'instcodefilter'})) {
16188: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16189: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16190: if ($codedom) {
16191: $officialjs = 1;
16192: ($instcodeform,$jscript,$$numtitlesref) =
16193: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16194: $officialjs,$codetitlesref);
16195: if ($jscript) {
16196: $jscript = '<script type="text/javascript">'."\n".
16197: '// <![CDATA['."\n".
16198: $jscript."\n".
16199: '// ]]>'."\n".
16200: '</script>'."\n";
16201: }
16202: }
16203: if ($instcodeform eq '') {
16204: $instcodeform =
16205: '<input type="text" name="instcodefilter" size="10" value="'.
16206: $list->{'instcodefilter'}.'" />';
16207: $instcodetitle = $lt{'ins'};
16208: } else {
16209: $instcodetitle = $lt{'inc'};
16210: }
16211: if ($fixeddom) {
16212: $instcodetitle .= '<br />('.$codedom.')';
16213: }
16214: }
16215: }
16216: my $output = qq|
16217: <form method="post" name="filterpicker" action="$action">
16218: <input type="hidden" name="form" value="$formname" />
16219: |;
16220: if ($formname eq 'modifycourse') {
16221: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16222: '<input type="hidden" name="prevphase" value="'.
16223: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 16224: } elsif ($formname eq 'quotacheck') {
16225: $output .= qq|
16226: <input type="hidden" name="sortby" value="" />
16227: <input type="hidden" name="sortorder" value="" />
16228: |;
16229: } else {
1.1075.2.69 raeburn 16230: my $name_input;
16231: if ($cnameelement ne '') {
16232: $name_input = '<input type="hidden" name="cnameelement" value="'.
16233: $cnameelement.'" />';
16234: }
16235: $output .= qq|
16236: <input type="hidden" name="cnumelement" value="$cnumelement" />
16237: <input type="hidden" name="cdomelement" value="$cdomelement" />
16238: $name_input
16239: $roleelement
16240: $multelement
16241: $typeelement
16242: |;
16243: if ($formname eq 'portform') {
16244: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16245: }
16246: }
16247: if ($fixeddom) {
16248: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16249: }
16250: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16251: if ($sincefilterform) {
16252: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16253: .$sincefilterform
16254: .&Apache::lonhtmlcommon::row_closure();
16255: }
16256: if ($createdfilterform) {
16257: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16258: .$createdfilterform
16259: .&Apache::lonhtmlcommon::row_closure();
16260: }
16261: if ($domainselectform) {
16262: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16263: .$domainselectform
16264: .&Apache::lonhtmlcommon::row_closure();
16265: }
16266: if ($typeselectform) {
16267: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16268: $output .= $typeselectform;
16269: } else {
16270: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16271: .$typeselectform
16272: .&Apache::lonhtmlcommon::row_closure();
16273: }
16274: }
16275: if ($instcodeform) {
16276: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16277: .$instcodeform
16278: .&Apache::lonhtmlcommon::row_closure();
16279: }
16280: if (exists($filter->{'ownerfilter'})) {
16281: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16282: '<table><tr><td>'.&mt('Username').'<br />'.
16283: '<input type="text" name="ownerfilter" size="20" value="'.
16284: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16285: $ownerdomselectform.'</td></tr></table>'.
16286: &Apache::lonhtmlcommon::row_closure();
16287: }
16288: if (exists($filter->{'personfilter'})) {
16289: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16290: '<table><tr><td>'.&mt('Username').'<br />'.
16291: '<input type="text" name="personfilter" size="20" value="'.
16292: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16293: $persondomselectform.'</td></tr></table>'.
16294: &Apache::lonhtmlcommon::row_closure();
16295: }
16296: if (exists($filter->{'coursefilter'})) {
16297: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16298: .'<input type="text" name="coursefilter" size="25" value="'
16299: .$list->{'coursefilter'}.'" />'
16300: .&Apache::lonhtmlcommon::row_closure();
16301: }
16302: if ($cloneableonlyform) {
16303: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16304: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16305: }
16306: if (exists($filter->{'descriptfilter'})) {
16307: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16308: .'<input type="text" name="descriptfilter" size="40" value="'
16309: .$list->{'descriptfilter'}.'" />'
16310: .&Apache::lonhtmlcommon::row_closure(1);
16311: }
16312: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16313: '<input type="hidden" name="updater" value="" />'."\n".
16314: '<input type="submit" name="gosearch" value="'.
16315: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16316: return $jscript.$clonewarning.$output;
16317: }
16318:
16319: =pod
16320:
16321: =item * &timebased_select_form()
16322:
16323: Create markup for a dropdown list used to select a time-based
16324: filter e.g., Course Activity, Course Created, when searching for courses
16325: or communities
16326:
16327: Inputs:
16328:
16329: item - name of form element (sincefilter or createdfilter)
16330:
16331: filter - anonymous hash of criteria and their values
16332:
16333: Returns: HTML for a select box contained a blank, then six time selections,
16334: with value set in incoming form variables currently selected.
16335:
16336: Side Effects: None
16337:
16338: =cut
16339:
16340: sub timebased_select_form {
16341: my ($item,$filter) = @_;
16342: if (ref($filter) eq 'HASH') {
16343: $filter->{$item} =~ s/[^\d-]//g;
16344: if (!$filter->{$item}) { $filter->{$item}=-1; }
16345: return &select_form(
16346: $filter->{$item},
16347: $item,
16348: { '-1' => '',
16349: '86400' => &mt('today'),
16350: '604800' => &mt('last week'),
16351: '2592000' => &mt('last month'),
16352: '7776000' => &mt('last three months'),
16353: '15552000' => &mt('last six months'),
16354: '31104000' => &mt('last year'),
16355: 'select_form_order' =>
16356: ['-1','86400','604800','2592000','7776000',
16357: '15552000','31104000']});
16358: }
16359: }
16360:
16361: =pod
16362:
16363: =item * &js_changer()
16364:
16365: Create script tag containing Javascript used to submit course search form
16366: when course type or domain is changed, and also to hide 'Searching ...' on
16367: page load completion for page showing search result.
16368:
16369: Inputs: None
16370:
16371: Returns: markup containing updateFilters() and hideSearching() javascript functions.
16372:
16373: Side Effects: None
16374:
16375: =cut
16376:
16377: sub js_changer {
16378: return <<ENDJS;
16379: <script type="text/javascript">
16380: // <![CDATA[
16381: function updateFilters(caller) {
16382: if (typeof(caller) != "undefined") {
16383: document.filterpicker.updater.value = caller.name;
16384: }
16385: document.filterpicker.submit();
16386: }
16387:
16388: function hideSearching() {
16389: if (document.getElementById('searching')) {
16390: document.getElementById('searching').style.display = 'none';
16391: }
16392: return;
16393: }
16394:
16395: // ]]>
16396: </script>
16397:
16398: ENDJS
16399: }
16400:
16401: =pod
16402:
16403: =item * &search_courses()
16404:
16405: Process selected filters form course search form and pass to lonnet::courseiddump
16406: to retrieve a hash for which keys are courseIDs which match the selected filters.
16407:
16408: Inputs:
16409:
16410: dom - domain being searched
16411:
16412: type - course type ('Course' or 'Community' or '.' if any).
16413:
16414: filter - anonymous hash of criteria and their values
16415:
16416: numtitles - for institutional codes - number of categories
16417:
16418: cloneruname - optional username of new course owner
16419:
16420: clonerudom - optional domain of new course owner
16421:
1.1075.2.95 raeburn 16422: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 16423: (used when DC is using course creation form)
16424:
16425: codetitles - reference to array of titles of components in institutional codes (official courses).
16426:
1.1075.2.95 raeburn 16427: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16428: (and so can clone automatically)
16429:
16430: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16431:
16432: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16433: courses to clone
1.1075.2.69 raeburn 16434:
16435: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16436:
16437:
16438: Side Effects: None
16439:
16440: =cut
16441:
16442:
16443: sub search_courses {
1.1075.2.95 raeburn 16444: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16445: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 16446: my (%courses,%showcourses,$cloner);
16447: if (($filter->{'ownerfilter'} ne '') ||
16448: ($filter->{'ownerdomfilter'} ne '')) {
16449: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16450: $filter->{'ownerdomfilter'};
16451: }
16452: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16453: if (!$filter->{$item}) {
16454: $filter->{$item}='.';
16455: }
16456: }
16457: my $now = time;
16458: my $timefilter =
16459: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16460: my ($createdbefore,$createdafter);
16461: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16462: $createdbefore = $now;
16463: $createdafter = $now-$filter->{'createdfilter'};
16464: }
16465: my ($instcodefilter,$regexpok);
16466: if ($numtitles) {
16467: if ($env{'form.official'} eq 'on') {
16468: $instcodefilter =
16469: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16470: $regexpok = 1;
16471: } elsif ($env{'form.official'} eq 'off') {
16472: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16473: unless ($instcodefilter eq '') {
16474: $regexpok = -1;
16475: }
16476: }
16477: } else {
16478: $instcodefilter = $filter->{'instcodefilter'};
16479: }
16480: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16481: if ($type eq '') { $type = '.'; }
16482:
16483: if (($clonerudom ne '') && ($cloneruname ne '')) {
16484: $cloner = $cloneruname.':'.$clonerudom;
16485: }
16486: %courses = &Apache::lonnet::courseiddump($dom,
16487: $filter->{'descriptfilter'},
16488: $timefilter,
16489: $instcodefilter,
16490: $filter->{'combownerfilter'},
16491: $filter->{'coursefilter'},
16492: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 16493: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 16494: $filter->{'cloneableonly'},
16495: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 16496: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 16497: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16498: my $ccrole;
16499: if ($type eq 'Community') {
16500: $ccrole = 'co';
16501: } else {
16502: $ccrole = 'cc';
16503: }
16504: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16505: $filter->{'persondomfilter'},
16506: 'userroles',undef,
16507: [$ccrole,'in','ad','ep','ta','cr'],
16508: $dom);
16509: foreach my $role (keys(%rolehash)) {
16510: my ($cnum,$cdom,$courserole) = split(':',$role);
16511: my $cid = $cdom.'_'.$cnum;
16512: if (exists($courses{$cid})) {
16513: if (ref($courses{$cid}) eq 'HASH') {
16514: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16515: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 16516: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 16517: }
16518: } else {
16519: $courses{$cid}{roles} = [$courserole];
16520: }
16521: $showcourses{$cid} = $courses{$cid};
16522: }
16523: }
16524: }
16525: %courses = %showcourses;
16526: }
16527: return %courses;
16528: }
16529:
16530: =pod
16531:
16532: =back
16533:
1.1075.2.88 raeburn 16534: =head1 Routines for version requirements for current course.
16535:
16536: =over 4
16537:
16538: =item * &check_release_required()
16539:
16540: Compares required LON-CAPA version with version on server, and
16541: if required version is newer looks for a server with the required version.
16542:
16543: Looks first at servers in user's owen domain; if none suitable, looks at
16544: servers in course's domain are permitted to host sessions for user's domain.
16545:
16546: Inputs:
16547:
16548: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16549:
16550: $courseid - Course ID of current course
16551:
16552: $rolecode - User's current role in course (for switchserver query string).
16553:
16554: $required - LON-CAPA version needed by course (format: Major.Minor).
16555:
16556:
16557: Returns:
16558:
16559: $switchserver - query string tp append to /adm/switchserver call (if
16560: current server's LON-CAPA version is too old.
16561:
16562: $warning - Message is displayed if no suitable server could be found.
16563:
16564: =cut
16565:
16566: sub check_release_required {
16567: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16568: my ($switchserver,$warning);
16569: if ($required ne '') {
16570: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16571: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16572: if ($reqdmajor ne '' && $reqdminor ne '') {
16573: my $otherserver;
16574: if (($major eq '' && $minor eq '') ||
16575: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16576: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16577: my $switchlcrev =
16578: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16579: $userdomserver);
16580: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16581: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16582: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16583: my $cdom = $env{'course.'.$courseid.'.domain'};
16584: if ($cdom ne $env{'user.domain'}) {
16585: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16586: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16587: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16588: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16589: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16590: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16591: my $canhost =
16592: &Apache::lonnet::can_host_session($env{'user.domain'},
16593: $coursedomserver,
16594: $remoterev,
16595: $udomdefaults{'remotesessions'},
16596: $defdomdefaults{'hostedsessions'});
16597:
16598: if ($canhost) {
16599: $otherserver = $coursedomserver;
16600: } else {
16601: $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.");
16602: }
16603: } else {
16604: $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).");
16605: }
16606: } else {
16607: $otherserver = $userdomserver;
16608: }
16609: }
16610: if ($otherserver ne '') {
16611: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16612: }
16613: }
16614: }
16615: return ($switchserver,$warning);
16616: }
16617:
16618: =pod
16619:
16620: =item * &check_release_result()
16621:
16622: Inputs:
16623:
16624: $switchwarning - Warning message if no suitable server found to host session.
16625:
16626: $switchserver - query string to append to /adm/switchserver containing lonHostID
16627: and current role.
16628:
16629: Returns: HTML to display with information about requirement to switch server.
16630: Either displaying warning with link to Roles/Courses screen or
16631: display link to switchserver.
16632:
1.1075.2.69 raeburn 16633: =cut
16634:
1.1075.2.88 raeburn 16635: sub check_release_result {
16636: my ($switchwarning,$switchserver) = @_;
16637: my $output = &start_page('Selected course unavailable on this server').
16638: '<p class="LC_warning">';
16639: if ($switchwarning) {
16640: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16641: if (&show_course()) {
16642: $output .= &mt('Display courses');
16643: } else {
16644: $output .= &mt('Display roles');
16645: }
16646: $output .= '</a>';
16647: } elsif ($switchserver) {
16648: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16649: '<br />'.
16650: '<a href="/adm/switchserver?'.$switchserver.'">'.
16651: &mt('Switch Server').
16652: '</a>';
16653: }
16654: $output .= '</p>'.&end_page();
16655: return $output;
16656: }
16657:
16658: =pod
16659:
16660: =item * &needs_coursereinit()
16661:
16662: Determine if course contents stored for user's session needs to be
16663: refreshed, because content has changed since "Big Hash" last tied.
16664:
16665: Check for change is made if time last checked is more than 10 minutes ago
16666: (by default).
16667:
16668: Inputs:
16669:
16670: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16671:
16672: $interval (optional) - Time which may elapse (in s) between last check for content
16673: change in current course. (default: 600 s).
16674:
16675: Returns: an array; first element is:
16676:
16677: =over 4
16678:
16679: 'switch' - if content updates mean user's session
16680: needs to be switched to a server running a newer LON-CAPA version
16681:
16682: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16683: on current server hosting user's session
16684:
16685: '' - if no action required.
16686:
16687: =back
16688:
16689: If first item element is 'switch':
16690:
16691: second item is $switchwarning - Warning message if no suitable server found to host session.
16692:
16693: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16694: and current role.
16695:
16696: otherwise: no other elements returned.
16697:
16698: =back
16699:
16700: =cut
16701:
16702: sub needs_coursereinit {
16703: my ($loncaparev,$interval) = @_;
16704: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16705: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16706: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16707: my $now = time;
16708: if ($interval eq '') {
16709: $interval = 600;
16710: }
16711: if (($now-$env{'request.course.timechecked'})>$interval) {
16712: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16713: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16714: if ($lastchange > $env{'request.course.tied'}) {
16715: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16716: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16717: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16718: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16719: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16720: $curr_reqd_hash{'internal.releaserequired'}});
16721: my ($switchserver,$switchwarning) =
16722: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16723: $curr_reqd_hash{'internal.releaserequired'});
16724: if ($switchwarning ne '' || $switchserver ne '') {
16725: return ('switch',$switchwarning,$switchserver);
16726: }
16727: }
16728: }
16729: return ('update');
16730: }
16731: }
16732: return ();
16733: }
1.1075.2.69 raeburn 16734:
1.1075.2.11 raeburn 16735: sub update_content_constraints {
16736: my ($cdom,$cnum,$chome,$cid) = @_;
16737: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16738: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16739: my %checkresponsetypes;
16740: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
16741: my ($item,$name,$value) = split(/:/,$key);
16742: if ($item eq 'resourcetag') {
16743: if ($name eq 'responsetype') {
16744: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
16745: }
16746: }
16747: }
16748: my $navmap = Apache::lonnavmaps::navmap->new();
16749: if (defined($navmap)) {
16750: my %allresponses;
16751: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
16752: my %responses = $res->responseTypes();
16753: foreach my $key (keys(%responses)) {
16754: next unless(exists($checkresponsetypes{$key}));
16755: $allresponses{$key} += $responses{$key};
16756: }
16757: }
16758: foreach my $key (keys(%allresponses)) {
16759: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
16760: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
16761: ($reqdmajor,$reqdminor) = ($major,$minor);
16762: }
16763: }
16764: undef($navmap);
16765: }
16766: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
16767: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
16768: }
16769: return;
16770: }
16771:
1.1075.2.27 raeburn 16772: sub allmaps_incourse {
16773: my ($cdom,$cnum,$chome,$cid) = @_;
16774: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
16775: $cid = $env{'request.course.id'};
16776: $cdom = $env{'course.'.$cid.'.domain'};
16777: $cnum = $env{'course.'.$cid.'.num'};
16778: $chome = $env{'course.'.$cid.'.home'};
16779: }
16780: my %allmaps = ();
16781: my $lastchange =
16782: &Apache::lonnet::get_coursechange($cdom,$cnum);
16783: if ($lastchange > $env{'request.course.tied'}) {
16784: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
16785: unless ($ferr) {
16786: &update_content_constraints($cdom,$cnum,$chome,$cid);
16787: }
16788: }
16789: my $navmap = Apache::lonnavmaps::navmap->new();
16790: if (defined($navmap)) {
16791: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
16792: $allmaps{$res->src()} = 1;
16793: }
16794: }
16795: return \%allmaps;
16796: }
16797:
1.1075.2.11 raeburn 16798: sub parse_supplemental_title {
16799: my ($title) = @_;
16800:
16801: my ($foldertitle,$renametitle);
16802: if ($title =~ /&&&/) {
16803: $title = &HTML::Entites::decode($title);
16804: }
16805: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
16806: $renametitle=$4;
16807: my ($time,$uname,$udom) = ($1,$2,$3);
16808: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
16809: my $name = &plainname($uname,$udom);
16810: $name = &HTML::Entities::encode($name,'"<>&\'');
16811: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
16812: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
16813: $name.': <br />'.$foldertitle;
16814: }
16815: if (wantarray) {
16816: return ($title,$foldertitle,$renametitle);
16817: }
16818: return $title;
16819: }
16820:
1.1075.2.43 raeburn 16821: sub recurse_supplemental {
16822: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
16823: if ($suppmap) {
16824: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16825: if ($fatal) {
16826: $errors ++;
16827: } else {
16828: if ($#LONCAPA::map::resources > 0) {
16829: foreach my $res (@LONCAPA::map::resources) {
16830: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16831: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 16832: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16833: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 16834: } else {
16835: $numfiles ++;
16836: }
16837: }
16838: }
16839: }
16840: }
16841: }
16842: return ($numfiles,$errors);
16843: }
16844:
1.1075.2.18 raeburn 16845: sub symb_to_docspath {
1.1075.2.119 raeburn 16846: my ($symb,$navmapref) = @_;
16847: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 16848: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
16849: if ($resurl=~/\.(sequence|page)$/) {
16850: $mapurl=$resurl;
16851: } elsif ($resurl eq 'adm/navmaps') {
16852: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
16853: }
16854: my $mapresobj;
1.1075.2.119 raeburn 16855: unless (ref($$navmapref)) {
16856: $$navmapref = Apache::lonnavmaps::navmap->new();
16857: }
16858: if (ref($$navmapref)) {
16859: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 16860: }
16861: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
16862: my $type=$2;
16863: my $path;
16864: if (ref($mapresobj)) {
16865: my $pcslist = $mapresobj->map_hierarchy();
16866: if ($pcslist ne '') {
16867: foreach my $pc (split(/,/,$pcslist)) {
16868: next if ($pc <= 1);
1.1075.2.119 raeburn 16869: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 16870: if (ref($res)) {
16871: my $thisurl = $res->src();
16872: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
16873: my $thistitle = $res->title();
16874: $path .= '&'.
16875: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 16876: &escape($thistitle).
1.1075.2.18 raeburn 16877: ':'.$res->randompick().
16878: ':'.$res->randomout().
16879: ':'.$res->encrypted().
16880: ':'.$res->randomorder().
16881: ':'.$res->is_page();
16882: }
16883: }
16884: }
16885: $path =~ s/^\&//;
16886: my $maptitle = $mapresobj->title();
16887: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16888: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16889: }
16890: $path .= (($path ne '')? '&' : '').
16891: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16892: &escape($maptitle).
1.1075.2.18 raeburn 16893: ':'.$mapresobj->randompick().
16894: ':'.$mapresobj->randomout().
16895: ':'.$mapresobj->encrypted().
16896: ':'.$mapresobj->randomorder().
16897: ':'.$mapresobj->is_page();
16898: } else {
16899: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16900: my $ispage = (($type eq 'page')? 1 : '');
16901: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16902: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16903: }
16904: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16905: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 16906: }
16907: unless ($mapurl eq 'default') {
16908: $path = 'default&'.
1.1075.2.46 raeburn 16909: &escape('Main Content').
1.1075.2.18 raeburn 16910: ':::::&'.$path;
16911: }
16912: return $path;
16913: }
16914:
1.1075.2.14 raeburn 16915: sub captcha_display {
1.1075.2.137 raeburn 16916: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 16917: my ($output,$error);
1.1075.2.107 raeburn 16918: my ($captcha,$pubkey,$privkey,$version) =
1.1075.2.137 raeburn 16919: &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 16920: if ($captcha eq 'original') {
16921: $output = &create_captcha();
16922: unless ($output) {
16923: $error = 'captcha';
16924: }
16925: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16926: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 16927: unless ($output) {
16928: $error = 'recaptcha';
16929: }
16930: }
1.1075.2.107 raeburn 16931: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 16932: }
16933:
16934: sub captcha_response {
1.1075.2.137 raeburn 16935: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 16936: my ($captcha_chk,$captcha_error);
1.1075.2.137 raeburn 16937: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 16938: if ($captcha eq 'original') {
16939: ($captcha_chk,$captcha_error) = &check_captcha();
16940: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16941: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 16942: } else {
16943: $captcha_chk = 1;
16944: }
16945: return ($captcha_chk,$captcha_error);
16946: }
16947:
16948: sub get_captcha_config {
1.1075.2.137 raeburn 16949: my ($context,$lonhost,$dom_in_effect) = @_;
1.1075.2.107 raeburn 16950: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 16951: my $hostname = &Apache::lonnet::hostname($lonhost);
16952: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
16953: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16954: if ($context eq 'usercreation') {
16955: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
16956: if (ref($domconfig{$context}) eq 'HASH') {
16957: $hashtocheck = $domconfig{$context}{'cancreate'};
16958: if (ref($hashtocheck) eq 'HASH') {
16959: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
16960: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
16961: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
16962: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
16963: }
16964: if ($privkey && $pubkey) {
16965: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16966: $version = $hashtocheck->{'recaptchaversion'};
16967: if ($version ne '2') {
16968: $version = 1;
16969: }
1.1075.2.14 raeburn 16970: } else {
16971: $captcha = 'original';
16972: }
16973: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
16974: $captcha = 'original';
16975: }
16976: }
16977: } else {
16978: $captcha = 'captcha';
16979: }
16980: } elsif ($context eq 'login') {
16981: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
16982: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
16983: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
16984: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
16985: if ($privkey && $pubkey) {
16986: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16987: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
16988: if ($version ne '2') {
16989: $version = 1;
16990: }
1.1075.2.14 raeburn 16991: } else {
16992: $captcha = 'original';
16993: }
16994: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
16995: $captcha = 'original';
16996: }
1.1075.2.137 raeburn 16997: } elsif ($context eq 'passwords') {
16998: if ($dom_in_effect) {
16999: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
17000: if ($passwdconf{'captcha'} eq 'recaptcha') {
17001: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
17002: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
17003: $privkey = $passwdconf{'recaptchakeys'}{'private'};
17004: }
17005: if ($privkey && $pubkey) {
17006: $captcha = 'recaptcha';
17007: $version = $passwdconf{'recaptchaversion'};
17008: if ($version ne '2') {
17009: $version = 1;
17010: }
17011: } else {
17012: $captcha = 'original';
17013: }
17014: } elsif ($passwdconf{'captcha'} ne 'notused') {
17015: $captcha = 'original';
17016: }
17017: }
1.1075.2.14 raeburn 17018: }
1.1075.2.107 raeburn 17019: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 17020: }
17021:
17022: sub create_captcha {
17023: my %captcha_params = &captcha_settings();
17024: my ($output,$maxtries,$tries) = ('',10,0);
17025: while ($tries < $maxtries) {
17026: $tries ++;
17027: my $captcha = Authen::Captcha->new (
17028: output_folder => $captcha_params{'output_dir'},
17029: data_folder => $captcha_params{'db_dir'},
17030: );
17031: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17032:
17033: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17034: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17035: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 17036: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17037: '<br />'.
17038: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 17039: last;
17040: }
17041: }
17042: return $output;
17043: }
17044:
17045: sub captcha_settings {
17046: my %captcha_params = (
17047: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17048: www_output_dir => "/captchaspool",
17049: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17050: numchars => '5',
17051: );
17052: return %captcha_params;
17053: }
17054:
17055: sub check_captcha {
17056: my ($captcha_chk,$captcha_error);
17057: my $code = $env{'form.code'};
17058: my $md5sum = $env{'form.crypt'};
17059: my %captcha_params = &captcha_settings();
17060: my $captcha = Authen::Captcha->new(
17061: output_folder => $captcha_params{'output_dir'},
17062: data_folder => $captcha_params{'db_dir'},
17063: );
1.1075.2.26 raeburn 17064: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 17065: my %captcha_hash = (
17066: 0 => 'Code not checked (file error)',
17067: -1 => 'Failed: code expired',
17068: -2 => 'Failed: invalid code (not in database)',
17069: -3 => 'Failed: invalid code (code does not match crypt)',
17070: );
17071: if ($captcha_chk != 1) {
17072: $captcha_error = $captcha_hash{$captcha_chk}
17073: }
17074: return ($captcha_chk,$captcha_error);
17075: }
17076:
17077: sub create_recaptcha {
1.1075.2.107 raeburn 17078: my ($pubkey,$version) = @_;
17079: if ($version >= 2) {
17080: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17081: } else {
17082: my $use_ssl;
17083: if ($ENV{'SERVER_PORT'} == 443) {
17084: $use_ssl = 1;
17085: }
17086: my $captcha = Captcha::reCAPTCHA->new;
17087: return $captcha->get_options_setter({theme => 'white'})."\n".
17088: $captcha->get_html($pubkey,undef,$use_ssl).
17089: &mt('If the text is hard to read, [_1] will replace them.',
17090: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17091: '<br /><br />';
17092: }
1.1075.2.14 raeburn 17093: }
17094:
17095: sub check_recaptcha {
1.1075.2.107 raeburn 17096: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 17097: my $captcha_chk;
1.1075.2.107 raeburn 17098: if ($version >= 2) {
17099: my $ua = LWP::UserAgent->new;
17100: $ua->timeout(10);
17101: my %info = (
17102: secret => $privkey,
17103: response => $env{'form.g-recaptcha-response'},
17104: remoteip => $ENV{'REMOTE_ADDR'},
17105: );
17106: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
17107: if ($response->is_success) {
17108: my $data = JSON::DWIW->from_json($response->decoded_content);
17109: if (ref($data) eq 'HASH') {
17110: if ($data->{'success'}) {
17111: $captcha_chk = 1;
17112: }
17113: }
17114: }
17115: } else {
17116: my $captcha = Captcha::reCAPTCHA->new;
17117: my $captcha_result =
17118: $captcha->check_answer(
17119: $privkey,
17120: $ENV{'REMOTE_ADDR'},
17121: $env{'form.recaptcha_challenge_field'},
17122: $env{'form.recaptcha_response_field'},
17123: );
17124: if ($captcha_result->{is_valid}) {
17125: $captcha_chk = 1;
17126: }
1.1075.2.14 raeburn 17127: }
17128: return $captcha_chk;
17129: }
17130:
1.1075.2.64 raeburn 17131: sub emailusername_info {
1.1075.2.103 raeburn 17132: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 17133: my %titles = &Apache::lonlocal::texthash (
17134: lastname => 'Last Name',
17135: firstname => 'First Name',
17136: institution => 'School/college/university',
17137: location => "School's city, state/province, country",
17138: web => "School's web address",
17139: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 17140: id => 'Student/Employee ID',
1.1075.2.64 raeburn 17141: );
17142: return (\@fields,\%titles);
17143: }
17144:
1.1075.2.56 raeburn 17145: sub cleanup_html {
17146: my ($incoming) = @_;
17147: my $outgoing;
17148: if ($incoming ne '') {
17149: $outgoing = $incoming;
17150: $outgoing =~ s/;/;/g;
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: }
17164: return $outgoing;
17165: }
17166:
1.1075.2.74 raeburn 17167: # Checks for critical messages and returns a redirect url if one exists.
17168: # $interval indicates how often to check for messages.
17169: sub critical_redirect {
17170: my ($interval) = @_;
17171: if ((time-$env{'user.criticalcheck.time'})>$interval) {
17172: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17173: $env{'user.name'});
17174: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
17175: my $redirecturl;
17176: if ($what[0]) {
17177: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17178: $redirecturl='/adm/email?critical=display';
17179: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17180: return (1, $url);
17181: }
17182: }
17183: }
17184: return ();
17185: }
17186:
1.1075.2.64 raeburn 17187: # Use:
17188: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17189: #
17190: ##################################################
17191: # password associated functions #
17192: ##################################################
17193: sub des_keys {
17194: # Make a new key for DES encryption.
17195: # Each key has two parts which are returned separately.
17196: # Please note: Each key must be passed through the &hex function
17197: # before it is output to the web browser. The hex versions cannot
17198: # be used to decrypt.
17199: my @hexstr=('0','1','2','3','4','5','6','7',
17200: '8','9','a','b','c','d','e','f');
17201: my $lkey='';
17202: for (0..7) {
17203: $lkey.=$hexstr[rand(15)];
17204: }
17205: my $ukey='';
17206: for (0..7) {
17207: $ukey.=$hexstr[rand(15)];
17208: }
17209: return ($lkey,$ukey);
17210: }
17211:
17212: sub des_decrypt {
17213: my ($key,$cyphertext) = @_;
17214: my $keybin=pack("H16",$key);
17215: my $cypher;
17216: if ($Crypt::DES::VERSION>=2.03) {
17217: $cypher=new Crypt::DES $keybin;
17218: } else {
17219: $cypher=new DES $keybin;
17220: }
1.1075.2.106 raeburn 17221: my $plaintext='';
17222: my $cypherlength = length($cyphertext);
17223: my $numchunks = int($cypherlength/32);
17224: for (my $j=0; $j<$numchunks; $j++) {
17225: my $start = $j*32;
17226: my $cypherblock = substr($cyphertext,$start,32);
17227: my $chunk =
17228: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17229: $chunk .=
17230: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17231: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17232: $plaintext .= $chunk;
17233: }
1.1075.2.64 raeburn 17234: return $plaintext;
17235: }
17236:
1.1075.2.135 raeburn 17237: sub is_nonframeable {
17238: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
17239: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
17240: return if (($remprotocol eq '') || ($remhost eq ''));
17241:
17242: $remprotocol = lc($remprotocol);
17243: $remhost = lc($remhost);
17244: my $remport = 80;
17245: if ($remprotocol eq 'https') {
17246: $remport = 443;
17247: }
17248: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
17249: if ($cached) {
17250: unless ($nocache) {
17251: if ($result) {
17252: return 1;
17253: } else {
17254: return 0;
17255: }
17256: }
17257: }
17258: my $uselink;
17259: my $request = new HTTP::Request('HEAD',$url);
1.1075.2.142 raeburn 17260: my $ua = LWP::UserAgent->new;
17261: $ua->timeout(5);
17262: my $response=$ua->request($request);
1.1075.2.135 raeburn 17263: if ($response->is_success()) {
17264: my $secpolicy = lc($response->header('content-security-policy'));
17265: my $xframeop = lc($response->header('x-frame-options'));
17266: $secpolicy =~ s/^\s+|\s+$//g;
17267: $xframeop =~ s/^\s+|\s+$//g;
17268: if (($secpolicy ne '') || ($xframeop ne '')) {
17269: my $remotehost = $remprotocol.'://'.$remhost;
17270: my ($origin,$protocol,$port);
17271: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
17272: $port = $ENV{'SERVER_PORT'};
17273: } else {
17274: $port = 80;
17275: }
17276: if ($absolute eq '') {
17277: $protocol = 'http:';
17278: if ($port == 443) {
17279: $protocol = 'https:';
17280: }
17281: $origin = $protocol.'//'.lc($hostname);
17282: } else {
17283: $origin = lc($absolute);
17284: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
17285: }
17286: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
17287: my $framepolicy = $1;
17288: $framepolicy =~ s/^\s+|\s+$//g;
17289: my @policies = split(/\s+/,$framepolicy);
17290: if (@policies) {
17291: if (grep(/^\Q'none'\E$/,@policies)) {
17292: $uselink = 1;
17293: } else {
17294: $uselink = 1;
17295: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
17296: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
17297: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
17298: undef($uselink);
17299: }
17300: if ($uselink) {
17301: if (grep(/^\Q'self'\E$/,@policies)) {
17302: if (($origin ne '') && ($remotehost eq $origin)) {
17303: undef($uselink);
17304: }
17305: }
17306: }
17307: if ($uselink) {
17308: my @possok;
17309: if ($ip ne '') {
17310: push(@possok,$ip);
17311: }
17312: my $hoststr = '';
17313: foreach my $part (reverse(split(/\./,$hostname))) {
17314: if ($hoststr eq '') {
17315: $hoststr = $part;
17316: } else {
17317: $hoststr = "$part.$hoststr";
17318: }
17319: if ($hoststr eq $hostname) {
17320: push(@possok,$hostname);
17321: } else {
17322: push(@possok,"*.$hoststr");
17323: }
17324: }
17325: if (@possok) {
17326: foreach my $poss (@possok) {
17327: last if (!$uselink);
17328: foreach my $policy (@policies) {
17329: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
17330: undef($uselink);
17331: last;
17332: }
17333: }
17334: }
17335: }
17336: }
17337: }
17338: }
17339: } elsif ($xframeop ne '') {
17340: $uselink = 1;
17341: my @policies = split(/\s*,\s*/,$xframeop);
17342: if (@policies) {
17343: unless (grep(/^deny$/,@policies)) {
17344: if ($origin ne '') {
17345: if (grep(/^sameorigin$/,@policies)) {
17346: if ($remotehost eq $origin) {
17347: undef($uselink);
17348: }
17349: }
17350: if ($uselink) {
17351: foreach my $policy (@policies) {
17352: if ($policy =~ /^allow-from\s*(.+)$/) {
17353: my $allowfrom = $1;
17354: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
17355: undef($uselink);
17356: last;
17357: }
17358: }
17359: }
17360: }
17361: }
17362: }
17363: }
17364: }
17365: }
17366: }
17367: if ($nocache) {
17368: if ($cached) {
17369: my $devalidate;
17370: if ($uselink && !$result) {
17371: $devalidate = 1;
17372: } elsif (!$uselink && $result) {
17373: $devalidate = 1;
17374: }
17375: if ($devalidate) {
17376: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
17377: }
17378: }
17379: } else {
17380: if ($uselink) {
17381: $result = 1;
17382: } else {
17383: $result = 0;
17384: }
17385: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
17386: }
17387: return $uselink;
17388: }
17389:
1.112 bowersj2 17390: 1;
17391: __END__;
1.41 ng 17392:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>