Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.140
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.140! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.139 2019/08/28 02:38:42 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.999 www 431: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
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.793 raeburn 446: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 447: var title = 'Student_Browser';
1.74 www 448: var options = 'scrollbars=1,resizable=1,menubar=0';
449: options += ',width=700,height=600';
450: stdeditbrowser = open(url,title,options,'1');
451: stdeditbrowser.focus();
452: }
1.824 bisitz 453: // ]]>
1.74 www 454: </script>
455: ENDSTDBRW
456: }
1.42 matthew 457:
1.1003 www 458: sub resourcebrowser_javascript {
459: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 460: return (<<'ENDRESBRW');
1.1003 www 461: <script type="text/javascript" language="Javascript">
462: // <![CDATA[
463: var reseditbrowser;
1.1004 www 464: function openresbrowser(formname,reslink) {
1.1005 www 465: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 466: var title = 'Resource_Browser';
467: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 468: options += ',width=700,height=500';
1.1004 www 469: reseditbrowser = open(url,title,options,'1');
470: reseditbrowser.focus();
1.1003 www 471: }
472: // ]]>
473: </script>
1.1004 www 474: ENDRESBRW
1.1003 www 475: }
476:
1.74 www 477: sub selectstudent_link {
1.999 www 478: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
479: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
480: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
481: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 482: if ($env{'request.course.id'}) {
1.302 albertel 483: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
484: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
485: '/'.$env{'request.course.sec'})) {
1.111 www 486: return '';
487: }
1.999 www 488: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 489: if ($courseadvonly) {
490: $callargs .= ",'',1,1";
491: }
492: return '<span class="LC_nobreak">'.
493: '<a href="javascript:openstdbrowser('.$callargs.');">'.
494: &mt('Select User').'</a></span>';
1.74 www 495: }
1.258 albertel 496: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 497: $callargs .= ",'',1";
1.793 raeburn 498: return '<span class="LC_nobreak">'.
499: '<a href="javascript:openstdbrowser('.$callargs.');">'.
500: &mt('Select User').'</a></span>';
1.111 www 501: }
502: return '';
1.91 www 503: }
504:
1.1004 www 505: sub selectresource_link {
506: my ($form,$reslink,$arg)=@_;
507:
508: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
509: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
510: unless ($env{'request.course.id'}) { return $arg; }
511: return '<span class="LC_nobreak">'.
512: '<a href="javascript:openresbrowser('.$callargs.');">'.
513: $arg.'</a></span>';
514: }
515:
516:
517:
1.653 raeburn 518: sub authorbrowser_javascript {
519: return <<"ENDAUTHORBRW";
1.776 bisitz 520: <script type="text/javascript" language="JavaScript">
1.824 bisitz 521: // <![CDATA[
1.653 raeburn 522: var stdeditbrowser;
523:
524: function openauthorbrowser(formname,udom) {
525: var url = '/adm/pickauthor?';
526: url += 'form='+formname+'&roledom='+udom;
527: var title = 'Author_Browser';
528: var options = 'scrollbars=1,resizable=1,menubar=0';
529: options += ',width=700,height=600';
530: stdeditbrowser = open(url,title,options,'1');
531: stdeditbrowser.focus();
532: }
533:
1.824 bisitz 534: // ]]>
1.653 raeburn 535: </script>
536: ENDAUTHORBRW
537: }
538:
1.91 www 539: sub coursebrowser_javascript {
1.1075.2.31 raeburn 540: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1075.2.95 raeburn 541: $credits_element,$instcode) = @_;
1.932 raeburn 542: my $wintitle = 'Course_Browser';
1.931 raeburn 543: if ($crstype eq 'Community') {
1.932 raeburn 544: $wintitle = 'Community_Browser';
1.909 raeburn 545: }
1.876 raeburn 546: my $id_functions = &javascript_index_functions();
547: my $output = '
1.776 bisitz 548: <script type="text/javascript" language="JavaScript">
1.824 bisitz 549: // <![CDATA[
1.468 raeburn 550: var stdeditbrowser;'."\n";
1.876 raeburn 551:
552: $output .= <<"ENDSTDBRW";
1.909 raeburn 553: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 554: var url = '/adm/pickcourse?';
1.895 raeburn 555: var formid = getFormIdByName(formname);
1.876 raeburn 556: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 557: if (domainfilter != null) {
558: if (domainfilter != '') {
559: url += 'domainfilter='+domainfilter+'&';
560: }
561: }
1.91 www 562: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 563: '&cdomelement='+udom+
564: '&cnameelement='+desc;
1.468 raeburn 565: if (extra_element !=null && extra_element != '') {
1.594 raeburn 566: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 567: url += '&roleelement='+extra_element;
568: if (domainfilter == null || domainfilter == '') {
569: url += '&domainfilter='+extra_element;
570: }
1.234 raeburn 571: }
1.468 raeburn 572: else {
573: if (formname == 'portform') {
574: url += '&setroles='+extra_element;
1.800 raeburn 575: } else {
576: if (formname == 'rules') {
577: url += '&fixeddom='+extra_element;
578: }
1.468 raeburn 579: }
580: }
1.230 raeburn 581: }
1.909 raeburn 582: if (type != null && type != '') {
583: url += '&type='+type;
584: }
585: if (type_elem != null && type_elem != '') {
586: url += '&typeelement='+type_elem;
587: }
1.872 raeburn 588: if (formname == 'ccrs') {
589: var ownername = document.forms[formid].ccuname.value;
590: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1075.2.101 raeburn 591: url += '&cloner='+ownername+':'+ownerdom;
592: if (type == 'Course') {
593: url += '&crscode='+document.forms[formid].crscode.value;
594: }
1.1075.2.95 raeburn 595: }
596: if (formname == 'requestcrs') {
597: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 598: }
1.293 raeburn 599: if (multflag !=null && multflag != '') {
600: url += '&multiple='+multflag;
601: }
1.909 raeburn 602: var title = '$wintitle';
1.91 www 603: var options = 'scrollbars=1,resizable=1,menubar=0';
604: options += ',width=700,height=600';
605: stdeditbrowser = open(url,title,options,'1');
606: stdeditbrowser.focus();
607: }
1.876 raeburn 608: $id_functions
609: ENDSTDBRW
1.1075.2.31 raeburn 610: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
611: $output .= &setsec_javascript($sec_element,$formname,$role_element,
612: $credits_element);
1.876 raeburn 613: }
614: $output .= '
615: // ]]>
616: </script>';
617: return $output;
618: }
619:
620: sub javascript_index_functions {
621: return <<"ENDJS";
622:
623: function getFormIdByName(formname) {
624: for (var i=0;i<document.forms.length;i++) {
625: if (document.forms[i].name == formname) {
626: return i;
627: }
628: }
629: return -1;
630: }
631:
632: function getIndexByName(formid,item) {
633: for (var i=0;i<document.forms[formid].elements.length;i++) {
634: if (document.forms[formid].elements[i].name == item) {
635: return i;
636: }
637: }
638: return -1;
639: }
1.468 raeburn 640:
1.876 raeburn 641: function getDomainFromSelectbox(formname,udom) {
642: var userdom;
643: var formid = getFormIdByName(formname);
644: if (formid > -1) {
645: var domid = getIndexByName(formid,udom);
646: if (domid > -1) {
647: if (document.forms[formid].elements[domid].type == 'select-one') {
648: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
649: }
650: if (document.forms[formid].elements[domid].type == 'hidden') {
651: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 652: }
653: }
654: }
1.876 raeburn 655: return userdom;
656: }
657:
658: ENDJS
1.468 raeburn 659:
1.876 raeburn 660: }
661:
1.1017 raeburn 662: sub javascript_array_indexof {
1.1018 raeburn 663: return <<ENDJS;
1.1017 raeburn 664: <script type="text/javascript" language="JavaScript">
665: // <![CDATA[
666:
667: if (!Array.prototype.indexOf) {
668: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
669: "use strict";
670: if (this === void 0 || this === null) {
671: throw new TypeError();
672: }
673: var t = Object(this);
674: var len = t.length >>> 0;
675: if (len === 0) {
676: return -1;
677: }
678: var n = 0;
679: if (arguments.length > 0) {
680: n = Number(arguments[1]);
681: if (n !== n) { // shortcut for verifying if it's NaN
682: n = 0;
683: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
684: n = (n > 0 || -1) * Math.floor(Math.abs(n));
685: }
686: }
687: if (n >= len) {
688: return -1;
689: }
690: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
691: for (; k < len; k++) {
692: if (k in t && t[k] === searchElement) {
693: return k;
694: }
695: }
696: return -1;
697: }
698: }
699:
700: // ]]>
701: </script>
702:
703: ENDJS
704:
705: }
706:
1.876 raeburn 707: sub userbrowser_javascript {
708: my $id_functions = &javascript_index_functions();
709: return <<"ENDUSERBRW";
710:
1.888 raeburn 711: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 712: var url = '/adm/pickuser?';
713: var userdom = getDomainFromSelectbox(formname,udom);
714: if (userdom != null) {
715: if (userdom != '') {
716: url += 'srchdom='+userdom+'&';
717: }
718: }
719: url += 'form=' + formname + '&unameelement='+uname+
720: '&udomelement='+udom+
721: '&ulastelement='+ulast+
722: '&ufirstelement='+ufirst+
723: '&uemailelement='+uemail+
1.881 raeburn 724: '&hideudomelement='+hideudom+
725: '&coursedom='+crsdom;
1.888 raeburn 726: if ((caller != null) && (caller != undefined)) {
727: url += '&caller='+caller;
728: }
1.876 raeburn 729: var title = 'User_Browser';
730: var options = 'scrollbars=1,resizable=1,menubar=0';
731: options += ',width=700,height=600';
732: var stdeditbrowser = open(url,title,options,'1');
733: stdeditbrowser.focus();
734: }
735:
1.888 raeburn 736: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 737: var formid = getFormIdByName(formname);
738: if (formid > -1) {
1.888 raeburn 739: var unameid = getIndexByName(formid,uname);
1.876 raeburn 740: var domid = getIndexByName(formid,udom);
741: var hidedomid = getIndexByName(formid,origdom);
742: if (hidedomid > -1) {
743: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 744: var unameval = document.forms[formid].elements[unameid].value;
745: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
746: if (domid > -1) {
747: var slct = document.forms[formid].elements[domid];
748: if (slct.type == 'select-one') {
749: var i;
750: for (i=0;i<slct.length;i++) {
751: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
752: }
753: }
754: if (slct.type == 'hidden') {
755: slct.value = fixeddom;
1.876 raeburn 756: }
757: }
1.468 raeburn 758: }
759: }
760: }
1.876 raeburn 761: return;
762: }
763:
764: $id_functions
765: ENDUSERBRW
1.468 raeburn 766: }
767:
768: sub setsec_javascript {
1.1075.2.31 raeburn 769: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 770: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
771: $communityrolestr);
772: if ($role_element ne '') {
773: my @allroles = ('st','ta','ep','in','ad');
774: foreach my $crstype ('Course','Community') {
775: if ($crstype eq 'Community') {
776: foreach my $role (@allroles) {
777: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
778: }
779: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
780: } else {
781: foreach my $role (@allroles) {
782: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
783: }
784: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
785: }
786: }
787: $rolestr = '"'.join('","',@allroles).'"';
788: $courserolestr = '"'.join('","',@courserolenames).'"';
789: $communityrolestr = '"'.join('","',@communityrolenames).'"';
790: }
1.468 raeburn 791: my $setsections = qq|
792: function setSect(sectionlist) {
1.629 raeburn 793: var sectionsArray = new Array();
794: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
795: sectionsArray = sectionlist.split(",");
796: }
1.468 raeburn 797: var numSections = sectionsArray.length;
798: document.$formname.$sec_element.length = 0;
799: if (numSections == 0) {
800: document.$formname.$sec_element.multiple=false;
801: document.$formname.$sec_element.size=1;
802: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
803: } else {
804: if (numSections == 1) {
805: document.$formname.$sec_element.multiple=false;
806: document.$formname.$sec_element.size=1;
807: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
808: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
809: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
810: } else {
811: for (var i=0; i<numSections; i++) {
812: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
813: }
814: document.$formname.$sec_element.multiple=true
815: if (numSections < 3) {
816: document.$formname.$sec_element.size=numSections;
817: } else {
818: document.$formname.$sec_element.size=3;
819: }
820: document.$formname.$sec_element.options[0].selected = false
821: }
822: }
1.91 www 823: }
1.905 raeburn 824:
825: function setRole(crstype) {
1.468 raeburn 826: |;
1.905 raeburn 827: if ($role_element eq '') {
828: $setsections .= ' return;
829: }
830: ';
831: } else {
832: $setsections .= qq|
833: var elementLength = document.$formname.$role_element.length;
834: var allroles = Array($rolestr);
835: var courserolenames = Array($courserolestr);
836: var communityrolenames = Array($communityrolestr);
837: if (elementLength != undefined) {
838: if (document.$formname.$role_element.options[5].value == 'cc') {
839: if (crstype == 'Course') {
840: return;
841: } else {
842: allroles[5] = 'co';
843: for (var i=0; i<6; i++) {
844: document.$formname.$role_element.options[i].value = allroles[i];
845: document.$formname.$role_element.options[i].text = communityrolenames[i];
846: }
847: }
848: } else {
849: if (crstype == 'Community') {
850: return;
851: } else {
852: allroles[5] = 'cc';
853: for (var i=0; i<6; i++) {
854: document.$formname.$role_element.options[i].value = allroles[i];
855: document.$formname.$role_element.options[i].text = courserolenames[i];
856: }
857: }
858: }
859: }
860: return;
861: }
862: |;
863: }
1.1075.2.31 raeburn 864: if ($credits_element) {
865: $setsections .= qq|
866: function setCredits(defaultcredits) {
867: document.$formname.$credits_element.value = defaultcredits;
868: return;
869: }
870: |;
871: }
1.468 raeburn 872: return $setsections;
873: }
874:
1.91 www 875: sub selectcourse_link {
1.909 raeburn 876: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
877: $typeelement) = @_;
878: my $type = $selecttype;
1.871 raeburn 879: my $linktext = &mt('Select Course');
880: if ($selecttype eq 'Community') {
1.909 raeburn 881: $linktext = &mt('Select Community');
1.906 raeburn 882: } elsif ($selecttype eq 'Course/Community') {
883: $linktext = &mt('Select Course/Community');
1.909 raeburn 884: $type = '';
1.1019 raeburn 885: } elsif ($selecttype eq 'Select') {
886: $linktext = &mt('Select');
887: $type = '';
1.871 raeburn 888: }
1.787 bisitz 889: return '<span class="LC_nobreak">'
890: ."<a href='"
891: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
892: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 893: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 894: ."'>".$linktext.'</a>'
1.787 bisitz 895: .'</span>';
1.74 www 896: }
1.42 matthew 897:
1.653 raeburn 898: sub selectauthor_link {
899: my ($form,$udom)=@_;
900: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
901: &mt('Select Author').'</a>';
902: }
903:
1.876 raeburn 904: sub selectuser_link {
1.881 raeburn 905: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 906: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 907: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 908: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 909: ');">'.$linktext.'</a>';
1.876 raeburn 910: }
911:
1.273 raeburn 912: sub check_uncheck_jscript {
913: my $jscript = <<"ENDSCRT";
914: function checkAll(field) {
915: if (field.length > 0) {
916: for (i = 0; i < field.length; i++) {
1.1075.2.14 raeburn 917: if (!field[i].disabled) {
918: field[i].checked = true;
919: }
1.273 raeburn 920: }
921: } else {
1.1075.2.14 raeburn 922: if (!field.disabled) {
923: field.checked = true;
924: }
1.273 raeburn 925: }
926: }
927:
928: function uncheckAll(field) {
929: if (field.length > 0) {
930: for (i = 0; i < field.length; i++) {
931: field[i].checked = false ;
1.543 albertel 932: }
933: } else {
1.273 raeburn 934: field.checked = false ;
935: }
936: }
937: ENDSCRT
938: return $jscript;
939: }
940:
1.656 www 941: sub select_timezone {
1.1075.2.115 raeburn 942: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
943: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 944: if ($includeempty) {
945: $output .= '<option value=""';
946: if (($selected eq '') || ($selected eq 'local')) {
947: $output .= ' selected="selected" ';
948: }
949: $output .= '> </option>';
950: }
1.657 raeburn 951: my @timezones = DateTime::TimeZone->all_names;
952: foreach my $tzone (@timezones) {
953: $output.= '<option value="'.$tzone.'"';
954: if ($tzone eq $selected) {
955: $output.=' selected="selected"';
956: }
957: $output.=">$tzone</option>\n";
1.656 www 958: }
959: $output.="</select>";
960: return $output;
961: }
1.273 raeburn 962:
1.687 raeburn 963: sub select_datelocale {
1.1075.2.115 raeburn 964: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
965: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 966: if ($includeempty) {
967: $output .= '<option value=""';
968: if ($selected eq '') {
969: $output .= ' selected="selected" ';
970: }
971: $output .= '> </option>';
972: }
1.1075.2.102 raeburn 973: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 974: my (@possibles,%locale_names);
1.1075.2.102 raeburn 975: my @locales = DateTime::Locale->ids();
976: foreach my $id (@locales) {
977: if ($id ne '') {
978: my ($en_terr,$native_terr);
979: my $loc = DateTime::Locale->load($id);
980: if (ref($loc)) {
981: $en_terr = $loc->name();
982: $native_terr = $loc->native_name();
1.687 raeburn 983: if (grep(/^en$/,@languages) || !@languages) {
984: if ($en_terr ne '') {
985: $locale_names{$id} = '('.$en_terr.')';
986: } elsif ($native_terr ne '') {
987: $locale_names{$id} = $native_terr;
988: }
989: } else {
990: if ($native_terr ne '') {
991: $locale_names{$id} = $native_terr.' ';
992: } elsif ($en_terr ne '') {
993: $locale_names{$id} = '('.$en_terr.')';
994: }
995: }
1.1075.2.94 raeburn 996: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1075.2.102 raeburn 997: push(@possibles,$id);
1.687 raeburn 998: }
999: }
1000: }
1001: foreach my $item (sort(@possibles)) {
1002: $output.= '<option value="'.$item.'"';
1003: if ($item eq $selected) {
1004: $output.=' selected="selected"';
1005: }
1006: $output.=">$item";
1007: if ($locale_names{$item} ne '') {
1.1075.2.94 raeburn 1008: $output.=' '.$locale_names{$item};
1.687 raeburn 1009: }
1010: $output.="</option>\n";
1011: }
1012: $output.="</select>";
1013: return $output;
1014: }
1015:
1.792 raeburn 1016: sub select_language {
1.1075.2.115 raeburn 1017: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1018: my %langchoices;
1019: if ($includeempty) {
1.1075.2.32 raeburn 1020: %langchoices = ('' => 'No language preference');
1.792 raeburn 1021: }
1022: foreach my $id (&languageids()) {
1023: my $code = &supportedlanguagecode($id);
1024: if ($code) {
1025: $langchoices{$code} = &plainlanguagedescription($id);
1026: }
1027: }
1.1075.2.32 raeburn 1028: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1075.2.115 raeburn 1029: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1030: }
1031:
1.42 matthew 1032: =pod
1.36 matthew 1033:
1.648 raeburn 1034: =item * &linked_select_forms(...)
1.36 matthew 1035:
1036: linked_select_forms returns a string containing a <script></script> block
1037: and html for two <select> menus. The select menus will be linked in that
1038: changing the value of the first menu will result in new values being placed
1039: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1040: order unless a defined order is provided.
1.36 matthew 1041:
1042: linked_select_forms takes the following ordered inputs:
1043:
1044: =over 4
1045:
1.112 bowersj2 1046: =item * $formname, the name of the <form> tag
1.36 matthew 1047:
1.112 bowersj2 1048: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1049:
1.112 bowersj2 1050: =item * $firstdefault, the default value for the first menu
1.36 matthew 1051:
1.112 bowersj2 1052: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1053:
1.112 bowersj2 1054: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1055:
1.112 bowersj2 1056: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1057:
1.609 raeburn 1058: =item * $menuorder, the order of values in the first menu
1059:
1.1075.2.31 raeburn 1060: =item * $onchangefirst, additional javascript call to execute for an onchange
1061: event for the first <select> tag
1062:
1063: =item * $onchangesecond, additional javascript call to execute for an onchange
1064: event for the second <select> tag
1065:
1.41 ng 1066: =back
1067:
1.36 matthew 1068: Below is an example of such a hash. Only the 'text', 'default', and
1069: 'select2' keys must appear as stated. keys(%menu) are the possible
1070: values for the first select menu. The text that coincides with the
1.41 ng 1071: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1072: and text for the second menu are given in the hash pointed to by
1073: $menu{$choice1}->{'select2'}.
1074:
1.112 bowersj2 1075: my %menu = ( A1 => { text =>"Choice A1" ,
1076: default => "B3",
1077: select2 => {
1078: B1 => "Choice B1",
1079: B2 => "Choice B2",
1080: B3 => "Choice B3",
1081: B4 => "Choice B4"
1.609 raeburn 1082: },
1083: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1084: },
1085: A2 => { text =>"Choice A2" ,
1086: default => "C2",
1087: select2 => {
1088: C1 => "Choice C1",
1089: C2 => "Choice C2",
1090: C3 => "Choice C3"
1.609 raeburn 1091: },
1092: order => ['C2','C1','C3'],
1.112 bowersj2 1093: },
1094: A3 => { text =>"Choice A3" ,
1095: default => "D6",
1096: select2 => {
1097: D1 => "Choice D1",
1098: D2 => "Choice D2",
1099: D3 => "Choice D3",
1100: D4 => "Choice D4",
1101: D5 => "Choice D5",
1102: D6 => "Choice D6",
1103: D7 => "Choice D7"
1.609 raeburn 1104: },
1105: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1106: }
1107: );
1.36 matthew 1108:
1109: =cut
1110:
1111: sub linked_select_forms {
1112: my ($formname,
1113: $middletext,
1114: $firstdefault,
1115: $firstselectname,
1116: $secondselectname,
1.609 raeburn 1117: $hashref,
1118: $menuorder,
1.1075.2.31 raeburn 1119: $onchangefirst,
1120: $onchangesecond
1.36 matthew 1121: ) = @_;
1122: my $second = "document.$formname.$secondselectname";
1123: my $first = "document.$formname.$firstselectname";
1124: # output the javascript to do the changing
1125: my $result = '';
1.776 bisitz 1126: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1127: $result.="// <![CDATA[\n";
1.36 matthew 1128: $result.="var select2data = new Object();\n";
1129: $" = '","';
1130: my $debug = '';
1131: foreach my $s1 (sort(keys(%$hashref))) {
1132: $result.="select2data.d_$s1 = new Object();\n";
1133: $result.="select2data.d_$s1.def = new String('".
1134: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1135: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1136: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1137: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1138: @s2values = @{$hashref->{$s1}->{'order'}};
1139: }
1.36 matthew 1140: $result.="\"@s2values\");\n";
1141: $result.="select2data.d_$s1.texts = new Array(";
1142: my @s2texts;
1143: foreach my $value (@s2values) {
1.1075.2.119 raeburn 1144: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1145: }
1146: $result.="\"@s2texts\");\n";
1147: }
1148: $"=' ';
1149: $result.= <<"END";
1150:
1151: function select1_changed() {
1152: // Determine new choice
1153: var newvalue = "d_" + $first.value;
1154: // update select2
1155: var values = select2data[newvalue].values;
1156: var texts = select2data[newvalue].texts;
1157: var select2def = select2data[newvalue].def;
1158: var i;
1159: // out with the old
1160: for (i = 0; i < $second.options.length; i++) {
1161: $second.options[i] = null;
1162: }
1163: // in with the nuclear
1164: for (i=0;i<values.length; i++) {
1165: $second.options[i] = new Option(values[i]);
1.143 matthew 1166: $second.options[i].value = values[i];
1.36 matthew 1167: $second.options[i].text = texts[i];
1168: if (values[i] == select2def) {
1169: $second.options[i].selected = true;
1170: }
1171: }
1172: }
1.824 bisitz 1173: // ]]>
1.36 matthew 1174: </script>
1175: END
1176: # output the initial values for the selection lists
1.1075.2.31 raeburn 1177: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1178: my @order = sort(keys(%{$hashref}));
1179: if (ref($menuorder) eq 'ARRAY') {
1180: @order = @{$menuorder};
1181: }
1182: foreach my $value (@order) {
1.36 matthew 1183: $result.=" <option value=\"$value\" ";
1.253 albertel 1184: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1185: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1186: }
1187: $result .= "</select>\n";
1188: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1189: $result .= $middletext;
1.1075.2.31 raeburn 1190: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1191: if ($onchangesecond) {
1192: $result .= ' onchange="'.$onchangesecond.'"';
1193: }
1194: $result .= ">\n";
1.36 matthew 1195: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1196:
1197: my @secondorder = sort(keys(%select2));
1198: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1199: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1200: }
1201: foreach my $value (@secondorder) {
1.36 matthew 1202: $result.=" <option value=\"$value\" ";
1.253 albertel 1203: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1204: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1205: }
1206: $result .= "</select>\n";
1207: # return $debug;
1208: return $result;
1209: } # end of sub linked_select_forms {
1210:
1.45 matthew 1211: =pod
1.44 bowersj2 1212:
1.973 raeburn 1213: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1214:
1.112 bowersj2 1215: Returns a string corresponding to an HTML link to the given help
1216: $topic, where $topic corresponds to the name of a .tex file in
1217: /home/httpd/html/adm/help/tex, with underscores replaced by
1218: spaces.
1219:
1220: $text will optionally be linked to the same topic, allowing you to
1221: link text in addition to the graphic. If you do not want to link
1222: text, but wish to specify one of the later parameters, pass an
1223: empty string.
1224:
1225: $stayOnPage is a value that will be interpreted as a boolean. If true,
1226: the link will not open a new window. If false, the link will open
1227: a new window using Javascript. (Default is false.)
1228:
1229: $width and $height are optional numerical parameters that will
1230: override the width and height of the popped up window, which may
1.973 raeburn 1231: be useful for certain help topics with big pictures included.
1232:
1233: $imgid is the id of the img tag used for the help icon. This may be
1234: used in a javascript call to switch the image src. See
1235: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1236:
1237: =cut
1238:
1239: sub help_open_topic {
1.973 raeburn 1240: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1241: $text = "" if (not defined $text);
1.44 bowersj2 1242: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1243: $width = 500 if (not defined $width);
1.44 bowersj2 1244: $height = 400 if (not defined $height);
1245: my $filename = $topic;
1246: $filename =~ s/ /_/g;
1247:
1.48 bowersj2 1248: my $template = "";
1249: my $link;
1.572 banghart 1250:
1.159 www 1251: $topic=~s/\W/\_/g;
1.44 bowersj2 1252:
1.572 banghart 1253: if (!$stayOnPage) {
1.1075.2.50 raeburn 1254: if ($env{'browser.mobile'}) {
1255: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1256: } else {
1257: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1258: }
1.1037 www 1259: } elsif ($stayOnPage eq 'popup') {
1260: $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 1261: } else {
1.48 bowersj2 1262: $link = "/adm/help/${filename}.hlp";
1263: }
1264:
1265: # Add the text
1.755 neumanie 1266: if ($text ne "") {
1.763 bisitz 1267: $template.='<span class="LC_help_open_topic">'
1268: .'<a target="_top" href="'.$link.'">'
1269: .$text.'</a>';
1.48 bowersj2 1270: }
1271:
1.763 bisitz 1272: # (Always) Add the graphic
1.179 matthew 1273: my $title = &mt('Online Help');
1.667 raeburn 1274: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1275: if ($imgid ne '') {
1276: $imgid = ' id="'.$imgid.'"';
1277: }
1.763 bisitz 1278: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1279: .'<img src="'.$helpicon.'" border="0"'
1280: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1281: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1282: .' /></a>';
1283: if ($text ne "") {
1284: $template.='</span>';
1285: }
1.44 bowersj2 1286: return $template;
1287:
1.106 bowersj2 1288: }
1289:
1290: # This is a quicky function for Latex cheatsheet editing, since it
1291: # appears in at least four places
1292: sub helpLatexCheatsheet {
1.1037 www 1293: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1294: my $out;
1.106 bowersj2 1295: my $addOther = '';
1.732 raeburn 1296: if ($topic) {
1.1037 www 1297: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1298: }
1299: $out = '<span>' # Start cheatsheet
1300: .$addOther
1301: .'<span>'
1.1037 www 1302: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1303: .'</span> <span>'
1.1037 www 1304: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1305: .'</span>';
1.732 raeburn 1306: unless ($not_author) {
1.763 bisitz 1307: $out .= ' <span>'
1.1037 www 1308: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1309: .'</span> <span>'
1.1075.2.78 raeburn 1310: .&help_open_topic('Authoring_Multilingual_Problems',&mt('Languages'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1311: .'</span>';
1.732 raeburn 1312: }
1.763 bisitz 1313: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1314: return $out;
1.172 www 1315: }
1316:
1.430 albertel 1317: sub general_help {
1318: my $helptopic='Student_Intro';
1319: if ($env{'request.role'}=~/^(ca|au)/) {
1320: $helptopic='Authoring_Intro';
1.907 raeburn 1321: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1322: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1323: } elsif ($env{'request.role'}=~/^dc/) {
1324: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1325: }
1326: return $helptopic;
1327: }
1328:
1329: sub update_help_link {
1330: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1331: my $origurl = $ENV{'REQUEST_URI'};
1332: $origurl=~s|^/~|/priv/|;
1333: my $timestamp = time;
1334: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1335: $$datum = &escape($$datum);
1336: }
1337:
1338: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1339: my $output .= <<"ENDOUTPUT";
1340: <script type="text/javascript">
1.824 bisitz 1341: // <![CDATA[
1.430 albertel 1342: banner_link = '$banner_link';
1.824 bisitz 1343: // ]]>
1.430 albertel 1344: </script>
1345: ENDOUTPUT
1346: return $output;
1347: }
1348:
1349: # now just updates the help link and generates a blue icon
1.193 raeburn 1350: sub help_open_menu {
1.430 albertel 1351: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1352: = @_;
1.949 droeschl 1353: $stayOnPage = 1;
1.430 albertel 1354: my $output;
1355: if ($component_help) {
1356: if (!$text) {
1357: $output=&help_open_topic($component_help,undef,$stayOnPage,
1358: $width,$height);
1359: } else {
1360: my $help_text;
1361: $help_text=&unescape($topic);
1362: $output='<table><tr><td>'.
1363: &help_open_topic($component_help,$help_text,$stayOnPage,
1364: $width,$height).'</td></tr></table>';
1365: }
1366: }
1367: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1368: return $output.$banner_link;
1369: }
1370:
1371: sub top_nav_help {
1372: my ($text) = @_;
1.436 albertel 1373: $text = &mt($text);
1.1075.2.60 raeburn 1374: my $stay_on_page;
1375: unless ($env{'environment.remote'} eq 'on') {
1376: $stay_on_page = 1;
1377: }
1.1075.2.61 raeburn 1378: my ($link,$banner_link);
1379: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1380: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1381: : "javascript:helpMenu('open')";
1382: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1383: }
1.201 raeburn 1384: my $title = &mt('Get help');
1.1075.2.61 raeburn 1385: if ($link) {
1386: return <<"END";
1.436 albertel 1387: $banner_link
1.1075.2.56 raeburn 1388: <a href="$link" title="$title">$text</a>
1.436 albertel 1389: END
1.1075.2.61 raeburn 1390: } else {
1391: return ' '.$text.' ';
1392: }
1.436 albertel 1393: }
1394:
1395: sub help_menu_js {
1.1075.2.52 raeburn 1396: my ($httphost) = @_;
1.949 droeschl 1397: my $stayOnPage = 1;
1.436 albertel 1398: my $width = 620;
1399: my $height = 600;
1.430 albertel 1400: my $helptopic=&general_help();
1.1075.2.52 raeburn 1401: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1402: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1403: my $start_page =
1404: &Apache::loncommon::start_page('Help Menu', undef,
1405: {'frameset' => 1,
1406: 'js_ready' => 1,
1.1075.2.136 raeburn 1407: 'use_absolute' => $httphost,
1.331 albertel 1408: 'add_entries' => {
1409: 'border' => '0',
1.579 raeburn 1410: 'rows' => "110,*",},});
1.331 albertel 1411: my $end_page =
1412: &Apache::loncommon::end_page({'frameset' => 1,
1413: 'js_ready' => 1,});
1414:
1.436 albertel 1415: my $template .= <<"ENDTEMPLATE";
1416: <script type="text/javascript">
1.877 bisitz 1417: // <![CDATA[
1.253 albertel 1418: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1419: var banner_link = '';
1.243 raeburn 1420: function helpMenu(target) {
1421: var caller = this;
1422: if (target == 'open') {
1423: var newWindow = null;
1424: try {
1.262 albertel 1425: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1426: }
1427: catch(error) {
1428: writeHelp(caller);
1429: return;
1430: }
1431: if (newWindow) {
1432: caller = newWindow;
1433: }
1.193 raeburn 1434: }
1.243 raeburn 1435: writeHelp(caller);
1436: return;
1437: }
1438: function writeHelp(caller) {
1.1075.2.61 raeburn 1439: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1440: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1441: caller.document.close();
1442: caller.focus();
1.193 raeburn 1443: }
1.877 bisitz 1444: // END LON-CAPA Internal -->
1.253 albertel 1445: // ]]>
1.436 albertel 1446: </script>
1.193 raeburn 1447: ENDTEMPLATE
1448: return $template;
1449: }
1450:
1.172 www 1451: sub help_open_bug {
1452: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1453: unless ($env{'user.adv'}) { return ''; }
1.172 www 1454: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1455: $text = "" if (not defined $text);
1456: $stayOnPage=1;
1.184 albertel 1457: $width = 600 if (not defined $width);
1458: $height = 600 if (not defined $height);
1.172 www 1459:
1460: $topic=~s/\W+/\+/g;
1461: my $link='';
1462: my $template='';
1.379 albertel 1463: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1464: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1465: if (!$stayOnPage)
1466: {
1467: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1468: }
1469: else
1470: {
1471: $link = $url;
1472: }
1473: # Add the text
1474: if ($text ne "")
1475: {
1476: $template .=
1477: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1478: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1479: }
1480:
1481: # Add the graphic
1.179 matthew 1482: my $title = &mt('Report a Bug');
1.215 albertel 1483: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1484: $template .= <<"ENDTEMPLATE";
1.436 albertel 1485: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1486: ENDTEMPLATE
1487: if ($text ne '') { $template.='</td></tr></table>' };
1488: return $template;
1489:
1490: }
1491:
1492: sub help_open_faq {
1493: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1494: unless ($env{'user.adv'}) { return ''; }
1.172 www 1495: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1496: $text = "" if (not defined $text);
1497: $stayOnPage=1;
1498: $width = 350 if (not defined $width);
1499: $height = 400 if (not defined $height);
1500:
1501: $topic=~s/\W+/\+/g;
1502: my $link='';
1503: my $template='';
1504: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1505: if (!$stayOnPage)
1506: {
1507: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1508: }
1509: else
1510: {
1511: $link = $url;
1512: }
1513:
1514: # Add the text
1515: if ($text ne "")
1516: {
1517: $template .=
1.173 www 1518: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1519: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1520: }
1521:
1522: # Add the graphic
1.179 matthew 1523: my $title = &mt('View the FAQ');
1.215 albertel 1524: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1525: $template .= <<"ENDTEMPLATE";
1.436 albertel 1526: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1527: ENDTEMPLATE
1528: if ($text ne '') { $template.='</td></tr></table>' };
1529: return $template;
1530:
1.44 bowersj2 1531: }
1.37 matthew 1532:
1.180 matthew 1533: ###############################################################
1534: ###############################################################
1535:
1.45 matthew 1536: =pod
1537:
1.648 raeburn 1538: =item * &change_content_javascript():
1.256 matthew 1539:
1540: This and the next function allow you to create small sections of an
1541: otherwise static HTML page that you can update on the fly with
1542: Javascript, even in Netscape 4.
1543:
1544: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1545: must be written to the HTML page once. It will prove the Javascript
1546: function "change(name, content)". Calling the change function with the
1547: name of the section
1548: you want to update, matching the name passed to C<changable_area>, and
1549: the new content you want to put in there, will put the content into
1550: that area.
1551:
1552: B<Note>: Netscape 4 only reserves enough space for the changable area
1553: to contain room for the original contents. You need to "make space"
1554: for whatever changes you wish to make, and be B<sure> to check your
1555: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1556: it's adequate for updating a one-line status display, but little more.
1557: This script will set the space to 100% width, so you only need to
1558: worry about height in Netscape 4.
1559:
1560: Modern browsers are much less limiting, and if you can commit to the
1561: user not using Netscape 4, this feature may be used freely with
1562: pretty much any HTML.
1563:
1564: =cut
1565:
1566: sub change_content_javascript {
1567: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1568: if ($env{'browser.type'} eq 'netscape' &&
1569: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1570: return (<<NETSCAPE4);
1571: function change(name, content) {
1572: doc = document.layers[name+"___escape"].layers[0].document;
1573: doc.open();
1574: doc.write(content);
1575: doc.close();
1576: }
1577: NETSCAPE4
1578: } else {
1579: # Otherwise, we need to use semi-standards-compliant code
1580: # (technically, "innerHTML" isn't standard but the equivalent
1581: # is really scary, and every useful browser supports it
1582: return (<<DOMBASED);
1583: function change(name, content) {
1584: element = document.getElementById(name);
1585: element.innerHTML = content;
1586: }
1587: DOMBASED
1588: }
1589: }
1590:
1591: =pod
1592:
1.648 raeburn 1593: =item * &changable_area($name,$origContent):
1.256 matthew 1594:
1595: This provides a "changable area" that can be modified on the fly via
1596: the Javascript code provided in C<change_content_javascript>. $name is
1597: the name you will use to reference the area later; do not repeat the
1598: same name on a given HTML page more then once. $origContent is what
1599: the area will originally contain, which can be left blank.
1600:
1601: =cut
1602:
1603: sub changable_area {
1604: my ($name, $origContent) = @_;
1605:
1.258 albertel 1606: if ($env{'browser.type'} eq 'netscape' &&
1607: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1608: # If this is netscape 4, we need to use the Layer tag
1609: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1610: } else {
1611: return "<span id='$name'>$origContent</span>";
1612: }
1613: }
1614:
1615: =pod
1616:
1.648 raeburn 1617: =item * &viewport_geometry_js
1.590 raeburn 1618:
1619: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1620:
1621: =cut
1622:
1623:
1624: sub viewport_geometry_js {
1625: return <<"GEOMETRY";
1626: var Geometry = {};
1627: function init_geometry() {
1628: if (Geometry.init) { return };
1629: Geometry.init=1;
1630: if (window.innerHeight) {
1631: Geometry.getViewportHeight = function() { return window.innerHeight; };
1632: Geometry.getViewportWidth = function() { return window.innerWidth; };
1633: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1634: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1635: }
1636: else if (document.documentElement && document.documentElement.clientHeight) {
1637: Geometry.getViewportHeight =
1638: function() { return document.documentElement.clientHeight; };
1639: Geometry.getViewportWidth =
1640: function() { return document.documentElement.clientWidth; };
1641:
1642: Geometry.getHorizontalScroll =
1643: function() { return document.documentElement.scrollLeft; };
1644: Geometry.getVerticalScroll =
1645: function() { return document.documentElement.scrollTop; };
1646: }
1647: else if (document.body.clientHeight) {
1648: Geometry.getViewportHeight =
1649: function() { return document.body.clientHeight; };
1650: Geometry.getViewportWidth =
1651: function() { return document.body.clientWidth; };
1652: Geometry.getHorizontalScroll =
1653: function() { return document.body.scrollLeft; };
1654: Geometry.getVerticalScroll =
1655: function() { return document.body.scrollTop; };
1656: }
1657: }
1658:
1659: GEOMETRY
1660: }
1661:
1662: =pod
1663:
1.648 raeburn 1664: =item * &viewport_size_js()
1.590 raeburn 1665:
1666: 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.
1667:
1668: =cut
1669:
1670: sub viewport_size_js {
1671: my $geometry = &viewport_geometry_js();
1672: return <<"DIMS";
1673:
1674: $geometry
1675:
1676: function getViewportDims(width,height) {
1677: init_geometry();
1678: width.value = Geometry.getViewportWidth();
1679: height.value = Geometry.getViewportHeight();
1680: return;
1681: }
1682:
1683: DIMS
1684: }
1685:
1686: =pod
1687:
1.648 raeburn 1688: =item * &resize_textarea_js()
1.565 albertel 1689:
1690: emits the needed javascript to resize a textarea to be as big as possible
1691:
1692: creates a function resize_textrea that takes two IDs first should be
1693: the id of the element to resize, second should be the id of a div that
1694: surrounds everything that comes after the textarea, this routine needs
1695: to be attached to the <body> for the onload and onresize events.
1696:
1.648 raeburn 1697: =back
1.565 albertel 1698:
1699: =cut
1700:
1701: sub resize_textarea_js {
1.590 raeburn 1702: my $geometry = &viewport_geometry_js();
1.565 albertel 1703: return <<"RESIZE";
1704: <script type="text/javascript">
1.824 bisitz 1705: // <![CDATA[
1.590 raeburn 1706: $geometry
1.565 albertel 1707:
1.588 albertel 1708: function getX(element) {
1709: var x = 0;
1710: while (element) {
1711: x += element.offsetLeft;
1712: element = element.offsetParent;
1713: }
1714: return x;
1715: }
1716: function getY(element) {
1717: var y = 0;
1718: while (element) {
1719: y += element.offsetTop;
1720: element = element.offsetParent;
1721: }
1722: return y;
1723: }
1724:
1725:
1.565 albertel 1726: function resize_textarea(textarea_id,bottom_id) {
1727: init_geometry();
1728: var textarea = document.getElementById(textarea_id);
1729: //alert(textarea);
1730:
1.588 albertel 1731: var textarea_top = getY(textarea);
1.565 albertel 1732: var textarea_height = textarea.offsetHeight;
1733: var bottom = document.getElementById(bottom_id);
1.588 albertel 1734: var bottom_top = getY(bottom);
1.565 albertel 1735: var bottom_height = bottom.offsetHeight;
1736: var window_height = Geometry.getViewportHeight();
1.588 albertel 1737: var fudge = 23;
1.565 albertel 1738: var new_height = window_height-fudge-textarea_top-bottom_height;
1739: if (new_height < 300) {
1740: new_height = 300;
1741: }
1742: textarea.style.height=new_height+'px';
1743: }
1.824 bisitz 1744: // ]]>
1.565 albertel 1745: </script>
1746: RESIZE
1747:
1748: }
1749:
1.1075.2.112 raeburn 1750: sub colorfuleditor_js {
1751: return <<"COLORFULEDIT"
1752: <script type="text/javascript">
1753: // <![CDATA[>
1754: function fold_box(curDepth, lastresource){
1755:
1756: // we need a list because there can be several blocks you need to fold in one tag
1757: var block = document.getElementsByName('foldblock_'+curDepth);
1758: // but there is only one folding button per tag
1759: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1760:
1761: if(block.item(0).style.display == 'none'){
1762:
1763: foldbutton.value = '@{[&mt("Hide")]}';
1764: for (i = 0; i < block.length; i++){
1765: block.item(i).style.display = '';
1766: }
1767: }else{
1768:
1769: foldbutton.value = '@{[&mt("Show")]}';
1770: for (i = 0; i < block.length; i++){
1771: // block.item(i).style.visibility = 'collapse';
1772: block.item(i).style.display = 'none';
1773: }
1774: };
1775: saveState(lastresource);
1776: }
1777:
1778: function saveState (lastresource) {
1779:
1780: var tag_list = getTagList();
1781: if(tag_list != null){
1782: var timestamp = new Date().getTime();
1783: var key = lastresource;
1784:
1785: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1786: // starting with timestamp
1787: var value = timestamp+';';
1788:
1789: // building the list of key-value pairs
1790: for(var i = 0; i < tag_list.length; i++){
1791: value += tag_list[i]+',';
1792: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1793: }
1794:
1795: // only iterate whole storage if nothing to override
1796: if(localStorage.getItem(key) == null){
1797:
1798: // prevent storage from growing large
1799: if(localStorage.length > 50){
1800: var regex_getTimestamp = /^(?:\d)+;/;
1801: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1802: var oldest_key;
1803:
1804: for(var i = 1; i < localStorage.length; i++){
1805: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1806: oldest_key = localStorage.key(i);
1807: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1808: }
1809: }
1810: localStorage.removeItem(oldest_key);
1811: }
1812: }
1813: localStorage.setItem(key,value);
1814: }
1815: }
1816:
1817: // restore folding status of blocks (on page load)
1818: function restoreState (lastresource) {
1819: if(localStorage.getItem(lastresource) != null){
1820: var key = lastresource;
1821: var value = localStorage.getItem(key);
1822: var regex_delTimestamp = /^\d+;/;
1823:
1824: value.replace(regex_delTimestamp, '');
1825:
1826: var valueArr = value.split(';');
1827: var pairs;
1828: var elements;
1829: for (var i = 0; i < valueArr.length; i++){
1830: pairs = valueArr[i].split(',');
1831: elements = document.getElementsByName(pairs[0]);
1832:
1833: for (var j = 0; j < elements.length; j++){
1834: elements[j].style.display = pairs[1];
1835: if (pairs[1] == "none"){
1836: var regex_id = /([_\\d]+)\$/;
1837: regex_id.exec(pairs[0]);
1838: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
1839: }
1840: }
1841: }
1842: }
1843: }
1844:
1845: function getTagList () {
1846:
1847: var stringToSearch = document.lonhomework.innerHTML;
1848:
1849: var ret = new Array();
1850: var regex_findBlock = /(foldblock_.*?)"/g;
1851: var tag_list = stringToSearch.match(regex_findBlock);
1852:
1853: if(tag_list != null){
1854: for(var i = 0; i < tag_list.length; i++){
1855: ret.push(tag_list[i].replace(/"/, ''));
1856: }
1857: }
1858: return ret;
1859: }
1860:
1861: function saveScrollPosition (resource) {
1862: var tag_list = getTagList();
1863:
1864: // we dont always want to jump to the first block
1865: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
1866: if(\$(window).scrollTop() > 170){
1867: if(tag_list != null){
1868: var result;
1869: for(var i = 0; i < tag_list.length; i++){
1870: if(isElementInViewport(tag_list[i])){
1871: result += tag_list[i]+';';
1872: }
1873: }
1874: sessionStorage.setItem('anchor_'+resource, result);
1875: }
1876: } else {
1877: // we dont need to save zero, just delete the item to leave everything tidy
1878: sessionStorage.removeItem('anchor_'+resource);
1879: }
1880: }
1881:
1882: function restoreScrollPosition(resource){
1883:
1884: var elem = sessionStorage.getItem('anchor_'+resource);
1885: if(elem != null){
1886: var tag_list = elem.split(';');
1887: var elem_list;
1888:
1889: for(var i = 0; i < tag_list.length; i++){
1890: elem_list = document.getElementsByName(tag_list[i]);
1891:
1892: if(elem_list.length > 0){
1893: elem = elem_list[0];
1894: break;
1895: }
1896: }
1897: elem.scrollIntoView();
1898: }
1899: }
1900:
1901: function isElementInViewport(el) {
1902:
1903: // change to last element instead of first
1904: var elem = document.getElementsByName(el);
1905: var rect = elem[0].getBoundingClientRect();
1906:
1907: return (
1908: rect.top >= 0 &&
1909: rect.left >= 0 &&
1910: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1911: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1912: );
1913: }
1914:
1915: function autosize(depth){
1916: var cmInst = window['cm'+depth];
1917: var fitsizeButton = document.getElementById('fitsize'+depth);
1918:
1919: // is fixed size, switching to dynamic
1920: if (sessionStorage.getItem("autosized_"+depth) == null) {
1921: cmInst.setSize("","auto");
1922: fitsizeButton.value = "@{[&mt('Fixed size')]}";
1923: sessionStorage.setItem("autosized_"+depth, "yes");
1924:
1925: // is dynamic size, switching to fixed
1926: } else {
1927: cmInst.setSize("","300px");
1928: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
1929: sessionStorage.removeItem("autosized_"+depth);
1930: }
1931: }
1932:
1933:
1934:
1935: // ]]>
1936: </script>
1937: COLORFULEDIT
1938: }
1939:
1940: sub xmleditor_js {
1941: return <<XMLEDIT
1942: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
1943: <script type="text/javascript">
1944: // <![CDATA[>
1945:
1946: function saveScrollPosition (resource) {
1947:
1948: var scrollPos = \$(window).scrollTop();
1949: sessionStorage.setItem(resource,scrollPos);
1950: }
1951:
1952: function restoreScrollPosition(resource){
1953:
1954: var scrollPos = sessionStorage.getItem(resource);
1955: \$(window).scrollTop(scrollPos);
1956: }
1957:
1958: // unless internet explorer
1959: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
1960:
1961: \$(document).ready(function() {
1962: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
1963: });
1964: }
1965:
1966: // inserts text at cursor position into codemirror (xml editor only)
1967: function insertText(text){
1968: cm.focus();
1969: var curPos = cm.getCursor();
1970: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
1971: }
1972: // ]]>
1973: </script>
1974: XMLEDIT
1975: }
1976:
1977: sub insert_folding_button {
1978: my $curDepth = $Apache::lonxml::curdepth;
1979: my $lastresource = $env{'request.ambiguous'};
1980:
1981: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
1982: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
1983: }
1984:
1985:
1.565 albertel 1986: =pod
1987:
1.256 matthew 1988: =head1 Excel and CSV file utility routines
1989:
1990: =cut
1991:
1992: ###############################################################
1993: ###############################################################
1994:
1995: =pod
1996:
1.1075.2.56 raeburn 1997: =over 4
1998:
1.648 raeburn 1999: =item * &csv_translate($text)
1.37 matthew 2000:
1.185 www 2001: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2002: format.
2003:
2004: =cut
2005:
1.180 matthew 2006: ###############################################################
2007: ###############################################################
1.37 matthew 2008: sub csv_translate {
2009: my $text = shift;
2010: $text =~ s/\"/\"\"/g;
1.209 albertel 2011: $text =~ s/\n/ /g;
1.37 matthew 2012: return $text;
2013: }
1.180 matthew 2014:
2015: ###############################################################
2016: ###############################################################
2017:
2018: =pod
2019:
1.648 raeburn 2020: =item * &define_excel_formats()
1.180 matthew 2021:
2022: Define some commonly used Excel cell formats.
2023:
2024: Currently supported formats:
2025:
2026: =over 4
2027:
2028: =item header
2029:
2030: =item bold
2031:
2032: =item h1
2033:
2034: =item h2
2035:
2036: =item h3
2037:
1.256 matthew 2038: =item h4
2039:
2040: =item i
2041:
1.180 matthew 2042: =item date
2043:
2044: =back
2045:
2046: Inputs: $workbook
2047:
2048: Returns: $format, a hash reference.
2049:
1.1057 foxr 2050:
1.180 matthew 2051: =cut
2052:
2053: ###############################################################
2054: ###############################################################
2055: sub define_excel_formats {
2056: my ($workbook) = @_;
2057: my $format;
2058: $format->{'header'} = $workbook->add_format(bold => 1,
2059: bottom => 1,
2060: align => 'center');
2061: $format->{'bold'} = $workbook->add_format(bold=>1);
2062: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2063: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2064: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2065: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2066: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2067: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2068: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2069: return $format;
2070: }
2071:
2072: ###############################################################
2073: ###############################################################
1.113 bowersj2 2074:
2075: =pod
2076:
1.648 raeburn 2077: =item * &create_workbook()
1.255 matthew 2078:
2079: Create an Excel worksheet. If it fails, output message on the
2080: request object and return undefs.
2081:
2082: Inputs: Apache request object
2083:
2084: Returns (undef) on failure,
2085: Excel worksheet object, scalar with filename, and formats
2086: from &Apache::loncommon::define_excel_formats on success
2087:
2088: =cut
2089:
2090: ###############################################################
2091: ###############################################################
2092: sub create_workbook {
2093: my ($r) = @_;
2094: #
2095: # Create the excel spreadsheet
2096: my $filename = '/prtspool/'.
1.258 albertel 2097: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2098: time.'_'.rand(1000000000).'.xls';
2099: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2100: if (! defined($workbook)) {
2101: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2102: $r->print(
2103: '<p class="LC_error">'
2104: .&mt('Problems occurred in creating the new Excel file.')
2105: .' '.&mt('This error has been logged.')
2106: .' '.&mt('Please alert your LON-CAPA administrator.')
2107: .'</p>'
2108: );
1.255 matthew 2109: return (undef);
2110: }
2111: #
1.1014 foxr 2112: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2113: #
2114: my $format = &Apache::loncommon::define_excel_formats($workbook);
2115: return ($workbook,$filename,$format);
2116: }
2117:
2118: ###############################################################
2119: ###############################################################
2120:
2121: =pod
2122:
1.648 raeburn 2123: =item * &create_text_file()
1.113 bowersj2 2124:
1.542 raeburn 2125: Create a file to write to and eventually make available to the user.
1.256 matthew 2126: If file creation fails, outputs an error message on the request object and
2127: return undefs.
1.113 bowersj2 2128:
1.256 matthew 2129: Inputs: Apache request object, and file suffix
1.113 bowersj2 2130:
1.256 matthew 2131: Returns (undef) on failure,
2132: Filehandle and filename on success.
1.113 bowersj2 2133:
2134: =cut
2135:
1.256 matthew 2136: ###############################################################
2137: ###############################################################
2138: sub create_text_file {
2139: my ($r,$suffix) = @_;
2140: if (! defined($suffix)) { $suffix = 'txt'; };
2141: my $fh;
2142: my $filename = '/prtspool/'.
1.258 albertel 2143: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2144: time.'_'.rand(1000000000).'.'.$suffix;
2145: $fh = Apache::File->new('>/home/httpd'.$filename);
2146: if (! defined($fh)) {
2147: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2148: $r->print(
2149: '<p class="LC_error">'
2150: .&mt('Problems occurred in creating the output file.')
2151: .' '.&mt('This error has been logged.')
2152: .' '.&mt('Please alert your LON-CAPA administrator.')
2153: .'</p>'
2154: );
1.113 bowersj2 2155: }
1.256 matthew 2156: return ($fh,$filename)
1.113 bowersj2 2157: }
2158:
2159:
1.256 matthew 2160: =pod
1.113 bowersj2 2161:
2162: =back
2163:
2164: =cut
1.37 matthew 2165:
2166: ###############################################################
1.33 matthew 2167: ## Home server <option> list generating code ##
2168: ###############################################################
1.35 matthew 2169:
1.169 www 2170: # ------------------------------------------
2171:
2172: sub domain_select {
2173: my ($name,$value,$multiple)=@_;
2174: my %domains=map {
1.514 albertel 2175: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2176: } &Apache::lonnet::all_domains();
1.169 www 2177: if ($multiple) {
2178: $domains{''}=&mt('Any domain');
1.550 albertel 2179: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2180: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2181: } else {
1.550 albertel 2182: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2183: return &select_form($name,$value,\%domains);
1.169 www 2184: }
2185: }
2186:
1.282 albertel 2187: #-------------------------------------------
2188:
2189: =pod
2190:
1.519 raeburn 2191: =head1 Routines for form select boxes
2192:
2193: =over 4
2194:
1.648 raeburn 2195: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2196:
2197: Returns a string containing a <select> element int multiple mode
2198:
2199:
2200: Args:
2201: $name - name of the <select> element
1.506 raeburn 2202: $value - scalar or array ref of values that should already be selected
1.282 albertel 2203: $size - number of rows long the select element is
1.283 albertel 2204: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2205: (shown text should already have been &mt())
1.506 raeburn 2206: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2207:
1.282 albertel 2208: =cut
2209:
2210: #-------------------------------------------
1.169 www 2211: sub multiple_select_form {
1.284 albertel 2212: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2213: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2214: my $output='';
1.191 matthew 2215: if (! defined($size)) {
2216: $size = 4;
1.283 albertel 2217: if (scalar(keys(%$hash))<4) {
2218: $size = scalar(keys(%$hash));
1.191 matthew 2219: }
2220: }
1.734 bisitz 2221: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2222: my @order;
1.506 raeburn 2223: if (ref($order) eq 'ARRAY') {
2224: @order = @{$order};
2225: } else {
2226: @order = sort(keys(%$hash));
1.501 banghart 2227: }
2228: if (exists($$hash{'select_form_order'})) {
2229: @order = @{$$hash{'select_form_order'}};
2230: }
2231:
1.284 albertel 2232: foreach my $key (@order) {
1.356 albertel 2233: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2234: $output.='selected="selected" ' if ($selected{$key});
2235: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2236: }
2237: $output.="</select>\n";
2238: return $output;
2239: }
2240:
1.88 www 2241: #-------------------------------------------
2242:
2243: =pod
2244:
1.1075.2.115 raeburn 2245: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2246:
2247: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2248: allow a user to select options from a ref to a hash containing:
2249: option_name => displayed text. An optional $onchange can include
1.1075.2.115 raeburn 2250: a javascript onchange item, e.g., onchange="this.form.submit();".
2251: An optional arg -- $readonly -- if true will cause the select form
2252: to be disabled, e.g., for the case where an instructor has a section-
2253: specific role, and is viewing/modifying parameters.
1.970 raeburn 2254:
1.88 www 2255: See lonrights.pm for an example invocation and use.
2256:
2257: =cut
2258:
2259: #-------------------------------------------
2260: sub select_form {
1.1075.2.115 raeburn 2261: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2262: return unless (ref($hashref) eq 'HASH');
2263: if ($onchange) {
2264: $onchange = ' onchange="'.$onchange.'"';
2265: }
1.1075.2.129 raeburn 2266: my $disabled;
2267: if ($readonly) {
2268: $disabled = ' disabled="disabled"';
2269: }
2270: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2271: my @keys;
1.970 raeburn 2272: if (exists($hashref->{'select_form_order'})) {
2273: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2274: } else {
1.970 raeburn 2275: @keys=sort(keys(%{$hashref}));
1.128 albertel 2276: }
1.356 albertel 2277: foreach my $key (@keys) {
2278: $selectform.=
2279: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2280: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2281: ">".$hashref->{$key}."</option>\n";
1.88 www 2282: }
2283: $selectform.="</select>";
2284: return $selectform;
2285: }
2286:
1.475 www 2287: # For display filters
2288:
2289: sub display_filter {
1.1074 raeburn 2290: my ($context) = @_;
1.475 www 2291: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2292: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2293: my $phraseinput = 'hidden';
2294: my $includeinput = 'hidden';
2295: my ($checked,$includetypestext);
2296: if ($env{'form.displayfilter'} eq 'containing') {
2297: $phraseinput = 'text';
2298: if ($context eq 'parmslog') {
2299: $includeinput = 'checkbox';
2300: if ($env{'form.includetypes'}) {
2301: $checked = ' checked="checked"';
2302: }
2303: $includetypestext = &mt('Include parameter types');
2304: }
2305: } else {
2306: $includetypestext = ' ';
2307: }
2308: my ($additional,$secondid,$thirdid);
2309: if ($context eq 'parmslog') {
2310: $additional =
2311: '<label><input type="'.$includeinput.'" name="includetypes"'.
2312: $checked.' name="includetypes" value="1" id="includetypes" />'.
2313: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2314: '</label>';
2315: $secondid = 'includetypes';
2316: $thirdid = 'includetypestext';
2317: }
2318: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2319: '$secondid','$thirdid')";
2320: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2321: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2322: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2323: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2324: &mt('Filter: [_1]',
1.477 www 2325: &select_form($env{'form.displayfilter'},
2326: 'displayfilter',
1.970 raeburn 2327: {'currentfolder' => 'Current folder/page',
1.477 www 2328: 'containing' => 'Containing phrase',
1.1074 raeburn 2329: 'none' => 'None'},$onchange)).' '.
2330: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2331: &HTML::Entities::encode($env{'form.containingphrase'}).
2332: '" />'.$additional;
2333: }
2334:
2335: sub display_filter_js {
2336: my $includetext = &mt('Include parameter types');
2337: return <<"ENDJS";
2338:
2339: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2340: var firstType = 'hidden';
2341: if (setter.options[setter.selectedIndex].value == 'containing') {
2342: firstType = 'text';
2343: }
2344: firstObject = document.getElementById(firstid);
2345: if (typeof(firstObject) == 'object') {
2346: if (firstObject.type != firstType) {
2347: changeInputType(firstObject,firstType);
2348: }
2349: }
2350: if (context == 'parmslog') {
2351: var secondType = 'hidden';
2352: if (firstType == 'text') {
2353: secondType = 'checkbox';
2354: }
2355: secondObject = document.getElementById(secondid);
2356: if (typeof(secondObject) == 'object') {
2357: if (secondObject.type != secondType) {
2358: changeInputType(secondObject,secondType);
2359: }
2360: }
2361: var textItem = document.getElementById(thirdid);
2362: var currtext = textItem.innerHTML;
2363: var newtext;
2364: if (firstType == 'text') {
2365: newtext = '$includetext';
2366: } else {
2367: newtext = ' ';
2368: }
2369: if (currtext != newtext) {
2370: textItem.innerHTML = newtext;
2371: }
2372: }
2373: return;
2374: }
2375:
2376: function changeInputType(oldObject,newType) {
2377: var newObject = document.createElement('input');
2378: newObject.type = newType;
2379: if (oldObject.size) {
2380: newObject.size = oldObject.size;
2381: }
2382: if (oldObject.value) {
2383: newObject.value = oldObject.value;
2384: }
2385: if (oldObject.name) {
2386: newObject.name = oldObject.name;
2387: }
2388: if (oldObject.id) {
2389: newObject.id = oldObject.id;
2390: }
2391: oldObject.parentNode.replaceChild(newObject,oldObject);
2392: return;
2393: }
2394:
2395: ENDJS
1.475 www 2396: }
2397:
1.167 www 2398: sub gradeleveldescription {
2399: my $gradelevel=shift;
2400: my %gradelevels=(0 => 'Not specified',
2401: 1 => 'Grade 1',
2402: 2 => 'Grade 2',
2403: 3 => 'Grade 3',
2404: 4 => 'Grade 4',
2405: 5 => 'Grade 5',
2406: 6 => 'Grade 6',
2407: 7 => 'Grade 7',
2408: 8 => 'Grade 8',
2409: 9 => 'Grade 9',
2410: 10 => 'Grade 10',
2411: 11 => 'Grade 11',
2412: 12 => 'Grade 12',
2413: 13 => 'Grade 13',
2414: 14 => '100 Level',
2415: 15 => '200 Level',
2416: 16 => '300 Level',
2417: 17 => '400 Level',
2418: 18 => 'Graduate Level');
2419: return &mt($gradelevels{$gradelevel});
2420: }
2421:
1.163 www 2422: sub select_level_form {
2423: my ($deflevel,$name)=@_;
2424: unless ($deflevel) { $deflevel=0; }
1.167 www 2425: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2426: for (my $i=0; $i<=18; $i++) {
2427: $selectform.="<option value=\"$i\" ".
1.253 albertel 2428: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2429: ">".&gradeleveldescription($i)."</option>\n";
2430: }
2431: $selectform.="</select>";
2432: return $selectform;
1.163 www 2433: }
1.167 www 2434:
1.35 matthew 2435: #-------------------------------------------
2436:
1.45 matthew 2437: =pod
2438:
1.1075.2.115 raeburn 2439: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2440:
2441: Returns a string containing a <select name='$name' size='1'> form to
2442: allow a user to select the domain to preform an operation in.
2443: See loncreateuser.pm for an example invocation and use.
2444:
1.90 www 2445: If the $includeempty flag is set, it also includes an empty choice ("no domain
2446: selected");
2447:
1.743 raeburn 2448: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2449:
1.910 raeburn 2450: 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.
2451:
1.1075.2.36 raeburn 2452: The optional $incdoms is a reference to an array of domains which will be the only available options.
2453:
1.1075.2.115 raeburn 2454: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
2455:
2456: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
1.563 raeburn 2457:
1.35 matthew 2458: =cut
2459:
2460: #-------------------------------------------
1.34 matthew 2461: sub select_dom_form {
1.1075.2.115 raeburn 2462: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2463: if ($onchange) {
1.874 raeburn 2464: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2465: }
1.1075.2.115 raeburn 2466: if ($disabled) {
2467: $disabled = ' disabled="disabled"';
2468: }
1.1075.2.36 raeburn 2469: my (@domains,%exclude);
1.910 raeburn 2470: if (ref($incdoms) eq 'ARRAY') {
2471: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2472: } else {
2473: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2474: }
1.90 www 2475: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2476: if (ref($excdoms) eq 'ARRAY') {
2477: map { $exclude{$_} = 1; } @{$excdoms};
2478: }
1.1075.2.115 raeburn 2479: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2480: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2481: next if ($exclude{$dom});
1.356 albertel 2482: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2483: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2484: if ($showdomdesc) {
2485: if ($dom ne '') {
2486: my $domdesc = &Apache::lonnet::domain($dom,'description');
2487: if ($domdesc ne '') {
2488: $selectdomain .= ' ('.$domdesc.')';
2489: }
2490: }
2491: }
2492: $selectdomain .= "</option>\n";
1.34 matthew 2493: }
2494: $selectdomain.="</select>";
2495: return $selectdomain;
2496: }
2497:
1.35 matthew 2498: #-------------------------------------------
2499:
1.45 matthew 2500: =pod
2501:
1.648 raeburn 2502: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2503:
1.586 raeburn 2504: input: 4 arguments (two required, two optional) -
2505: $domain - domain of new user
2506: $name - name of form element
2507: $default - Value of 'default' causes a default item to be first
2508: option, and selected by default.
2509: $hide - Value of 'hide' causes hiding of the name of the server,
2510: if 1 server found, or default, if 0 found.
1.594 raeburn 2511: output: returns 2 items:
1.586 raeburn 2512: (a) form element which contains either:
2513: (i) <select name="$name">
2514: <option value="$hostid1">$hostid $servers{$hostid}</option>
2515: <option value="$hostid2">$hostid $servers{$hostid}</option>
2516: </select>
2517: form item if there are multiple library servers in $domain, or
2518: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2519: if there is only one library server in $domain.
2520:
2521: (b) number of library servers found.
2522:
2523: See loncreateuser.pm for example of use.
1.35 matthew 2524:
2525: =cut
2526:
2527: #-------------------------------------------
1.586 raeburn 2528: sub home_server_form_item {
2529: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2530: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2531: my $result;
2532: my $numlib = keys(%servers);
2533: if ($numlib > 1) {
2534: $result .= '<select name="'.$name.'" />'."\n";
2535: if ($default) {
1.804 bisitz 2536: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2537: '</option>'."\n";
2538: }
2539: foreach my $hostid (sort(keys(%servers))) {
2540: $result.= '<option value="'.$hostid.'">'.
2541: $hostid.' '.$servers{$hostid}."</option>\n";
2542: }
2543: $result .= '</select>'."\n";
2544: } elsif ($numlib == 1) {
2545: my $hostid;
2546: foreach my $item (keys(%servers)) {
2547: $hostid = $item;
2548: }
2549: $result .= '<input type="hidden" name="'.$name.'" value="'.
2550: $hostid.'" />';
2551: if (!$hide) {
2552: $result .= $hostid.' '.$servers{$hostid};
2553: }
2554: $result .= "\n";
2555: } elsif ($default) {
2556: $result .= '<input type="hidden" name="'.$name.
2557: '" value="default" />';
2558: if (!$hide) {
2559: $result .= &mt('default');
2560: }
2561: $result .= "\n";
1.33 matthew 2562: }
1.586 raeburn 2563: return ($result,$numlib);
1.33 matthew 2564: }
1.112 bowersj2 2565:
2566: =pod
2567:
1.534 albertel 2568: =back
2569:
1.112 bowersj2 2570: =cut
1.87 matthew 2571:
2572: ###############################################################
1.112 bowersj2 2573: ## Decoding User Agent ##
1.87 matthew 2574: ###############################################################
2575:
2576: =pod
2577:
1.112 bowersj2 2578: =head1 Decoding the User Agent
2579:
2580: =over 4
2581:
2582: =item * &decode_user_agent()
1.87 matthew 2583:
2584: Inputs: $r
2585:
2586: Outputs:
2587:
2588: =over 4
2589:
1.112 bowersj2 2590: =item * $httpbrowser
1.87 matthew 2591:
1.112 bowersj2 2592: =item * $clientbrowser
1.87 matthew 2593:
1.112 bowersj2 2594: =item * $clientversion
1.87 matthew 2595:
1.112 bowersj2 2596: =item * $clientmathml
1.87 matthew 2597:
1.112 bowersj2 2598: =item * $clientunicode
1.87 matthew 2599:
1.112 bowersj2 2600: =item * $clientos
1.87 matthew 2601:
1.1075.2.42 raeburn 2602: =item * $clientmobile
2603:
2604: =item * $clientinfo
2605:
1.1075.2.77 raeburn 2606: =item * $clientosversion
2607:
1.87 matthew 2608: =back
2609:
1.157 matthew 2610: =back
2611:
1.87 matthew 2612: =cut
2613:
2614: ###############################################################
2615: ###############################################################
2616: sub decode_user_agent {
1.247 albertel 2617: my ($r)=@_;
1.87 matthew 2618: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2619: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2620: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2621: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2622: my $clientbrowser='unknown';
2623: my $clientversion='0';
2624: my $clientmathml='';
2625: my $clientunicode='0';
1.1075.2.42 raeburn 2626: my $clientmobile=0;
1.1075.2.77 raeburn 2627: my $clientosversion='';
1.87 matthew 2628: for (my $i=0;$i<=$#browsertype;$i++) {
1.1075.2.76 raeburn 2629: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2630: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2631: $clientbrowser=$bname;
2632: $httpbrowser=~/$vreg/i;
2633: $clientversion=$1;
2634: $clientmathml=($clientversion>=$minv);
2635: $clientunicode=($clientversion>=$univ);
2636: }
2637: }
2638: my $clientos='unknown';
1.1075.2.42 raeburn 2639: my $clientinfo;
1.87 matthew 2640: if (($httpbrowser=~/linux/i) ||
2641: ($httpbrowser=~/unix/i) ||
2642: ($httpbrowser=~/ux/i) ||
2643: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2644: if (($httpbrowser=~/vax/i) ||
2645: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2646: if ($httpbrowser=~/next/i) { $clientos='next'; }
2647: if (($httpbrowser=~/mac/i) ||
2648: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1075.2.77 raeburn 2649: if ($httpbrowser=~/win/i) {
2650: $clientos='win';
2651: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2652: $clientosversion = $1;
2653: }
2654: }
1.87 matthew 2655: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2656: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2657: $clientmobile=lc($1);
2658: }
2659: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2660: $clientinfo = 'firefox-'.$1;
2661: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2662: $clientinfo = 'chromeframe-'.$1;
2663: }
1.87 matthew 2664: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.77 raeburn 2665: $clientunicode,$clientos,$clientmobile,$clientinfo,
2666: $clientosversion);
1.87 matthew 2667: }
2668:
1.32 matthew 2669: ###############################################################
2670: ## Authentication changing form generation subroutines ##
2671: ###############################################################
2672: ##
2673: ## All of the authform_xxxxxxx subroutines take their inputs in a
2674: ## hash, and have reasonable default values.
2675: ##
2676: ## formname = the name given in the <form> tag.
1.35 matthew 2677: #-------------------------------------------
2678:
1.45 matthew 2679: =pod
2680:
1.112 bowersj2 2681: =head1 Authentication Routines
2682:
2683: =over 4
2684:
1.648 raeburn 2685: =item * &authform_xxxxxx()
1.35 matthew 2686:
2687: The authform_xxxxxx subroutines provide javascript and html forms which
2688: handle some of the conveniences required for authentication forms.
2689: This is not an optimal method, but it works.
2690:
2691: =over 4
2692:
1.112 bowersj2 2693: =item * authform_header
1.35 matthew 2694:
1.112 bowersj2 2695: =item * authform_authorwarning
1.35 matthew 2696:
1.112 bowersj2 2697: =item * authform_nochange
1.35 matthew 2698:
1.112 bowersj2 2699: =item * authform_kerberos
1.35 matthew 2700:
1.112 bowersj2 2701: =item * authform_internal
1.35 matthew 2702:
1.112 bowersj2 2703: =item * authform_filesystem
1.35 matthew 2704:
2705: =back
2706:
1.648 raeburn 2707: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2708:
1.35 matthew 2709: =cut
2710:
2711: #-------------------------------------------
1.32 matthew 2712: sub authform_header{
2713: my %in = (
2714: formname => 'cu',
1.80 albertel 2715: kerb_def_dom => '',
1.32 matthew 2716: @_,
2717: );
2718: $in{'formname'} = 'document.' . $in{'formname'};
2719: my $result='';
1.80 albertel 2720:
2721: #---------------------------------------------- Code for upper case translation
2722: my $Javascript_toUpperCase;
2723: unless ($in{kerb_def_dom}) {
2724: $Javascript_toUpperCase =<<"END";
2725: switch (choice) {
2726: case 'krb': currentform.elements[choicearg].value =
2727: currentform.elements[choicearg].value.toUpperCase();
2728: break;
2729: default:
2730: }
2731: END
2732: } else {
2733: $Javascript_toUpperCase = "";
2734: }
2735:
1.165 raeburn 2736: my $radioval = "'nochange'";
1.591 raeburn 2737: if (defined($in{'curr_authtype'})) {
2738: if ($in{'curr_authtype'} ne '') {
2739: $radioval = "'".$in{'curr_authtype'}."arg'";
2740: }
1.174 matthew 2741: }
1.165 raeburn 2742: my $argfield = 'null';
1.591 raeburn 2743: if (defined($in{'mode'})) {
1.165 raeburn 2744: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2745: if (defined($in{'curr_autharg'})) {
2746: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2747: $argfield = "'$in{'curr_autharg'}'";
2748: }
2749: }
2750: }
2751: }
2752:
1.32 matthew 2753: $result.=<<"END";
2754: var current = new Object();
1.165 raeburn 2755: current.radiovalue = $radioval;
2756: current.argfield = $argfield;
1.32 matthew 2757:
2758: function changed_radio(choice,currentform) {
2759: var choicearg = choice + 'arg';
2760: // If a radio button in changed, we need to change the argfield
2761: if (current.radiovalue != choice) {
2762: current.radiovalue = choice;
2763: if (current.argfield != null) {
2764: currentform.elements[current.argfield].value = '';
2765: }
2766: if (choice == 'nochange') {
2767: current.argfield = null;
2768: } else {
2769: current.argfield = choicearg;
2770: switch(choice) {
2771: case 'krb':
2772: currentform.elements[current.argfield].value =
2773: "$in{'kerb_def_dom'}";
2774: break;
2775: default:
2776: break;
2777: }
2778: }
2779: }
2780: return;
2781: }
1.22 www 2782:
1.32 matthew 2783: function changed_text(choice,currentform) {
2784: var choicearg = choice + 'arg';
2785: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2786: $Javascript_toUpperCase
1.32 matthew 2787: // clear old field
2788: if ((current.argfield != choicearg) && (current.argfield != null)) {
2789: currentform.elements[current.argfield].value = '';
2790: }
2791: current.argfield = choicearg;
2792: }
2793: set_auth_radio_buttons(choice,currentform);
2794: return;
1.20 www 2795: }
1.32 matthew 2796:
2797: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2798: var numauthchoices = currentform.login.length;
2799: if (typeof numauthchoices == "undefined") {
2800: return;
2801: }
1.32 matthew 2802: var i=0;
1.986 raeburn 2803: while (i < numauthchoices) {
1.32 matthew 2804: if (currentform.login[i].value == newvalue) { break; }
2805: i++;
2806: }
1.986 raeburn 2807: if (i == numauthchoices) {
1.32 matthew 2808: return;
2809: }
2810: current.radiovalue = newvalue;
2811: currentform.login[i].checked = true;
2812: return;
2813: }
2814: END
2815: return $result;
2816: }
2817:
1.1075.2.20 raeburn 2818: sub authform_authorwarning {
1.32 matthew 2819: my $result='';
1.144 matthew 2820: $result='<i>'.
2821: &mt('As a general rule, only authors or co-authors should be '.
2822: 'filesystem authenticated '.
2823: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2824: return $result;
2825: }
2826:
1.1075.2.20 raeburn 2827: sub authform_nochange {
1.32 matthew 2828: my %in = (
2829: formname => 'document.cu',
2830: kerb_def_dom => 'MSU.EDU',
2831: @_,
2832: );
1.1075.2.20 raeburn 2833: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2834: my $result;
1.1075.2.20 raeburn 2835: if (!$authnum) {
2836: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2837: } else {
2838: $result = '<label>'.&mt('[_1] Do not change login data',
2839: '<input type="radio" name="login" value="nochange" '.
2840: 'checked="checked" onclick="'.
1.281 albertel 2841: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2842: '</label>';
1.586 raeburn 2843: }
1.32 matthew 2844: return $result;
2845: }
2846:
1.591 raeburn 2847: sub authform_kerberos {
1.32 matthew 2848: my %in = (
2849: formname => 'document.cu',
2850: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2851: kerb_def_auth => 'krb4',
1.32 matthew 2852: @_,
2853: );
1.586 raeburn 2854: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1075.2.117 raeburn 2855: $autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2856: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2857: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2858: $check5 = ' checked="checked"';
1.80 albertel 2859: } else {
1.772 bisitz 2860: $check4 = ' checked="checked"';
1.80 albertel 2861: }
1.1075.2.117 raeburn 2862: if ($in{'readonly'}) {
2863: $disabled = ' disabled="disabled"';
2864: }
1.165 raeburn 2865: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2866: if (defined($in{'curr_authtype'})) {
2867: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2868: $krbcheck = ' checked="checked"';
1.623 raeburn 2869: if (defined($in{'mode'})) {
2870: if ($in{'mode'} eq 'modifyuser') {
2871: $krbcheck = '';
2872: }
2873: }
1.591 raeburn 2874: if (defined($in{'curr_kerb_ver'})) {
2875: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2876: $check5 = ' checked="checked"';
1.591 raeburn 2877: $check4 = '';
2878: } else {
1.772 bisitz 2879: $check4 = ' checked="checked"';
1.591 raeburn 2880: $check5 = '';
2881: }
1.586 raeburn 2882: }
1.591 raeburn 2883: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2884: $krbarg = $in{'curr_autharg'};
2885: }
1.586 raeburn 2886: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2887: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2888: $result =
2889: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2890: $in{'curr_autharg'},$krbver);
2891: } else {
2892: $result =
2893: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2894: }
2895: return $result;
2896: }
2897: }
2898: } else {
2899: if ($authnum == 1) {
1.784 bisitz 2900: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2901: }
2902: }
1.586 raeburn 2903: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2904: return;
1.587 raeburn 2905: } elsif ($authtype eq '') {
1.591 raeburn 2906: if (defined($in{'mode'})) {
1.587 raeburn 2907: if ($in{'mode'} eq 'modifycourse') {
2908: if ($authnum == 1) {
1.1075.2.117 raeburn 2909: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 2910: }
2911: }
2912: }
1.586 raeburn 2913: }
2914: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2915: if ($authtype eq '') {
2916: $authtype = '<input type="radio" name="login" value="krb" '.
2917: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1075.2.117 raeburn 2918: $krbcheck.$disabled.' />';
1.586 raeburn 2919: }
2920: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2921: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2922: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2923: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2924: $in{'curr_authtype'} eq 'krb4')) {
2925: $result .= &mt
1.144 matthew 2926: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2927: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2928: '<label>'.$authtype,
1.281 albertel 2929: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2930: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2931: 'onchange="'.$jscall.'"'.$disabled.' />',
2932: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
2933: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 2934: '</label>');
1.586 raeburn 2935: } elsif ($can_assign{'krb4'}) {
2936: $result .= &mt
2937: ('[_1] Kerberos authenticated with domain [_2] '.
2938: '[_3] Version 4 [_4]',
2939: '<label>'.$authtype,
2940: '</label><input type="text" size="10" name="krbarg" '.
2941: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2942: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2943: '<label><input type="hidden" name="krbver" value="4" />',
2944: '</label>');
2945: } elsif ($can_assign{'krb5'}) {
2946: $result .= &mt
2947: ('[_1] Kerberos authenticated with domain [_2] '.
2948: '[_3] Version 5 [_4]',
2949: '<label>'.$authtype,
2950: '</label><input type="text" size="10" name="krbarg" '.
2951: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2952: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2953: '<label><input type="hidden" name="krbver" value="5" />',
2954: '</label>');
2955: }
1.32 matthew 2956: return $result;
2957: }
2958:
1.1075.2.20 raeburn 2959: sub authform_internal {
1.586 raeburn 2960: my %in = (
1.32 matthew 2961: formname => 'document.cu',
2962: kerb_def_dom => 'MSU.EDU',
2963: @_,
2964: );
1.1075.2.117 raeburn 2965: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2966: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 2967: if ($in{'readonly'}) {
2968: $disabled = ' disabled="disabled"';
2969: }
1.591 raeburn 2970: if (defined($in{'curr_authtype'})) {
2971: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2972: if ($can_assign{'int'}) {
1.772 bisitz 2973: $intcheck = 'checked="checked" ';
1.623 raeburn 2974: if (defined($in{'mode'})) {
2975: if ($in{'mode'} eq 'modifyuser') {
2976: $intcheck = '';
2977: }
2978: }
1.591 raeburn 2979: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2980: $intarg = $in{'curr_autharg'};
2981: }
2982: } else {
2983: $result = &mt('Currently internally authenticated.');
2984: return $result;
1.165 raeburn 2985: }
2986: }
1.586 raeburn 2987: } else {
2988: if ($authnum == 1) {
1.784 bisitz 2989: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2990: }
2991: }
2992: if (!$can_assign{'int'}) {
2993: return;
1.587 raeburn 2994: } elsif ($authtype eq '') {
1.591 raeburn 2995: if (defined($in{'mode'})) {
1.587 raeburn 2996: if ($in{'mode'} eq 'modifycourse') {
2997: if ($authnum == 1) {
1.1075.2.117 raeburn 2998: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 2999: }
3000: }
3001: }
1.165 raeburn 3002: }
1.586 raeburn 3003: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3004: if ($authtype eq '') {
3005: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1075.2.117 raeburn 3006: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3007: }
1.605 bisitz 3008: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1075.2.117 raeburn 3009: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3010: $result = &mt
1.144 matthew 3011: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3012: '<label>'.$authtype,'</label>'.$autharg);
1.1075.2.118 raeburn 3013: $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 3014: return $result;
3015: }
3016:
1.1075.2.20 raeburn 3017: sub authform_local {
1.32 matthew 3018: my %in = (
3019: formname => 'document.cu',
3020: kerb_def_dom => 'MSU.EDU',
3021: @_,
3022: );
1.1075.2.117 raeburn 3023: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3024: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3025: if ($in{'readonly'}) {
3026: $disabled = ' disabled="disabled"';
3027: }
1.591 raeburn 3028: if (defined($in{'curr_authtype'})) {
3029: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3030: if ($can_assign{'loc'}) {
1.772 bisitz 3031: $loccheck = 'checked="checked" ';
1.623 raeburn 3032: if (defined($in{'mode'})) {
3033: if ($in{'mode'} eq 'modifyuser') {
3034: $loccheck = '';
3035: }
3036: }
1.591 raeburn 3037: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3038: $locarg = $in{'curr_autharg'};
3039: }
3040: } else {
3041: $result = &mt('Currently using local (institutional) authentication.');
3042: return $result;
1.165 raeburn 3043: }
3044: }
1.586 raeburn 3045: } else {
3046: if ($authnum == 1) {
1.784 bisitz 3047: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3048: }
3049: }
3050: if (!$can_assign{'loc'}) {
3051: return;
1.587 raeburn 3052: } elsif ($authtype eq '') {
1.591 raeburn 3053: if (defined($in{'mode'})) {
1.587 raeburn 3054: if ($in{'mode'} eq 'modifycourse') {
3055: if ($authnum == 1) {
1.1075.2.117 raeburn 3056: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3057: }
3058: }
3059: }
1.165 raeburn 3060: }
1.586 raeburn 3061: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3062: if ($authtype eq '') {
3063: $authtype = '<input type="radio" name="login" value="loc" '.
3064: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3065: $jscall.'"'.$disabled.' />';
1.586 raeburn 3066: }
3067: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1075.2.117 raeburn 3068: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3069: $result = &mt('[_1] Local Authentication with argument [_2]',
3070: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3071: return $result;
3072: }
3073:
1.1075.2.20 raeburn 3074: sub authform_filesystem {
1.32 matthew 3075: my %in = (
3076: formname => 'document.cu',
3077: kerb_def_dom => 'MSU.EDU',
3078: @_,
3079: );
1.1075.2.117 raeburn 3080: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3081: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3082: if ($in{'readonly'}) {
3083: $disabled = ' disabled="disabled"';
3084: }
1.591 raeburn 3085: if (defined($in{'curr_authtype'})) {
3086: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3087: if ($can_assign{'fsys'}) {
1.772 bisitz 3088: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3089: if (defined($in{'mode'})) {
3090: if ($in{'mode'} eq 'modifyuser') {
3091: $fsyscheck = '';
3092: }
3093: }
1.586 raeburn 3094: } else {
3095: $result = &mt('Currently Filesystem Authenticated.');
3096: return $result;
3097: }
3098: }
3099: } else {
3100: if ($authnum == 1) {
1.784 bisitz 3101: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3102: }
3103: }
3104: if (!$can_assign{'fsys'}) {
3105: return;
1.587 raeburn 3106: } elsif ($authtype eq '') {
1.591 raeburn 3107: if (defined($in{'mode'})) {
1.587 raeburn 3108: if ($in{'mode'} eq 'modifycourse') {
3109: if ($authnum == 1) {
1.1075.2.117 raeburn 3110: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3111: }
3112: }
3113: }
1.586 raeburn 3114: }
3115: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3116: if ($authtype eq '') {
3117: $authtype = '<input type="radio" name="login" value="fsys" '.
3118: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3119: $jscall.'"'.$disabled.' />';
1.586 raeburn 3120: }
3121: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
1.1075.2.117 raeburn 3122: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3123: $result = &mt
1.144 matthew 3124: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 3125: '<label><input type="radio" name="login" value="fsys" '.
1.1075.2.117 raeburn 3126: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />',
1.605 bisitz 3127: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.1075.2.117 raeburn 3128: 'onchange="'.$jscall.'"'.$disabled.' />');
1.32 matthew 3129: return $result;
3130: }
3131:
1.586 raeburn 3132: sub get_assignable_auth {
3133: my ($dom) = @_;
3134: if ($dom eq '') {
3135: $dom = $env{'request.role.domain'};
3136: }
3137: my %can_assign = (
3138: krb4 => 1,
3139: krb5 => 1,
3140: int => 1,
3141: loc => 1,
3142: );
3143: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3144: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3145: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3146: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3147: my $context;
3148: if ($env{'request.role'} =~ /^au/) {
3149: $context = 'author';
1.1075.2.117 raeburn 3150: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3151: $context = 'domain';
3152: } elsif ($env{'request.course.id'}) {
3153: $context = 'course';
3154: }
3155: if ($context) {
3156: if (ref($authhash->{$context}) eq 'HASH') {
3157: %can_assign = %{$authhash->{$context}};
3158: }
3159: }
3160: }
3161: }
3162: my $authnum = 0;
3163: foreach my $key (keys(%can_assign)) {
3164: if ($can_assign{$key}) {
3165: $authnum ++;
3166: }
3167: }
3168: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3169: $authnum --;
3170: }
3171: return ($authnum,%can_assign);
3172: }
3173:
1.1075.2.137 raeburn 3174: sub check_passwd_rules {
3175: my ($domain,$plainpass) = @_;
3176: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3177: my ($min,$max,@chars,@brokerule,$warning);
1.1075.2.138 raeburn 3178: $min = $Apache::lonnet::passwdmin;
1.1075.2.137 raeburn 3179: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3180: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1075.2.138 raeburn 3181: if ($passwdconf{'min'} > $min) {
3182: $min = $passwdconf{'min'};
3183: }
1.1075.2.137 raeburn 3184: }
3185: if ($passwdconf{'max'} =~ /^\d+$/) {
3186: $max = $passwdconf{'max'};
3187: }
3188: @chars = @{$passwdconf{'chars'}};
3189: }
3190: if (($min) && (length($plainpass) < $min)) {
3191: push(@brokerule,'min');
3192: }
3193: if (($max) && (length($plainpass) > $max)) {
3194: push(@brokerule,'max');
3195: }
3196: if (@chars) {
3197: my %rules;
3198: map { $rules{$_} = 1; } @chars;
3199: if ($rules{'uc'}) {
3200: unless ($plainpass =~ /[A-Z]/) {
3201: push(@brokerule,'uc');
3202: }
3203: }
3204: if ($rules{'lc'}) {
3205: unless ($plainpass =~ /[a-z]/) {
3206: push(@brokerule,'lc');
3207: }
3208: }
3209: if ($rules{'num'}) {
3210: unless ($plainpass =~ /\d/) {
3211: push(@brokerule,'num');
3212: }
3213: }
3214: if ($rules{'spec'}) {
3215: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3216: push(@brokerule,'spec');
3217: }
3218: }
3219: }
3220: if (@brokerule) {
3221: my %rulenames = &Apache::lonlocal::texthash(
3222: uc => 'At least one upper case letter',
3223: lc => 'At least one lower case letter',
3224: num => 'At least one number',
3225: spec => 'At least one non-alphanumeric',
3226: );
3227: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3228: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3229: $rulenames{'num'} .= ': 0123456789';
3230: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3231: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3232: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3233: $warning = &mt('Password did not satisfy the following:').'<ul>';
3234: foreach my $rule ('min','max','uc','ls','num','spec') {
3235: if (grep(/^$rule$/,@brokerule)) {
3236: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3237: }
3238: }
3239: $warning .= '</ul>';
3240: }
3241: if (wantarray) {
3242: return @brokerule;
3243: }
3244: return $warning;
3245: }
3246:
1.80 albertel 3247: ###############################################################
3248: ## Get Kerberos Defaults for Domain ##
3249: ###############################################################
3250: ##
3251: ## Returns default kerberos version and an associated argument
3252: ## as listed in file domain.tab. If not listed, provides
3253: ## appropriate default domain and kerberos version.
3254: ##
3255: #-------------------------------------------
3256:
3257: =pod
3258:
1.648 raeburn 3259: =item * &get_kerberos_defaults()
1.80 albertel 3260:
3261: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3262: version and domain. If not found, it defaults to version 4 and the
3263: domain of the server.
1.80 albertel 3264:
1.648 raeburn 3265: =over 4
3266:
1.80 albertel 3267: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3268:
1.648 raeburn 3269: =back
3270:
3271: =back
3272:
1.80 albertel 3273: =cut
3274:
3275: #-------------------------------------------
3276: sub get_kerberos_defaults {
3277: my $domain=shift;
1.641 raeburn 3278: my ($krbdef,$krbdefdom);
3279: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3280: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3281: $krbdef = $domdefaults{'auth_def'};
3282: $krbdefdom = $domdefaults{'auth_arg_def'};
3283: } else {
1.80 albertel 3284: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3285: my $krbdefdom=$1;
3286: $krbdefdom=~tr/a-z/A-Z/;
3287: $krbdef = "krb4";
3288: }
3289: return ($krbdef,$krbdefdom);
3290: }
1.112 bowersj2 3291:
1.32 matthew 3292:
1.46 matthew 3293: ###############################################################
3294: ## Thesaurus Functions ##
3295: ###############################################################
1.20 www 3296:
1.46 matthew 3297: =pod
1.20 www 3298:
1.112 bowersj2 3299: =head1 Thesaurus Functions
3300:
3301: =over 4
3302:
1.648 raeburn 3303: =item * &initialize_keywords()
1.46 matthew 3304:
3305: Initializes the package variable %Keywords if it is empty. Uses the
3306: package variable $thesaurus_db_file.
3307:
3308: =cut
3309:
3310: ###################################################
3311:
3312: sub initialize_keywords {
3313: return 1 if (scalar keys(%Keywords));
3314: # If we are here, %Keywords is empty, so fill it up
3315: # Make sure the file we need exists...
3316: if (! -e $thesaurus_db_file) {
3317: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3318: " failed because it does not exist");
3319: return 0;
3320: }
3321: # Set up the hash as a database
3322: my %thesaurus_db;
3323: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3324: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3325: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3326: $thesaurus_db_file);
3327: return 0;
3328: }
3329: # Get the average number of appearances of a word.
3330: my $avecount = $thesaurus_db{'average.count'};
3331: # Put keywords (those that appear > average) into %Keywords
3332: while (my ($word,$data)=each (%thesaurus_db)) {
3333: my ($count,undef) = split /:/,$data;
3334: $Keywords{$word}++ if ($count > $avecount);
3335: }
3336: untie %thesaurus_db;
3337: # Remove special values from %Keywords.
1.356 albertel 3338: foreach my $value ('total.count','average.count') {
3339: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3340: }
1.46 matthew 3341: return 1;
3342: }
3343:
3344: ###################################################
3345:
3346: =pod
3347:
1.648 raeburn 3348: =item * &keyword($word)
1.46 matthew 3349:
3350: Returns true if $word is a keyword. A keyword is a word that appears more
3351: than the average number of times in the thesaurus database. Calls
3352: &initialize_keywords
3353:
3354: =cut
3355:
3356: ###################################################
1.20 www 3357:
3358: sub keyword {
1.46 matthew 3359: return if (!&initialize_keywords());
3360: my $word=lc(shift());
3361: $word=~s/\W//g;
3362: return exists($Keywords{$word});
1.20 www 3363: }
1.46 matthew 3364:
3365: ###############################################################
3366:
3367: =pod
1.20 www 3368:
1.648 raeburn 3369: =item * &get_related_words()
1.46 matthew 3370:
1.160 matthew 3371: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3372: an array of words. If the keyword is not in the thesaurus, an empty array
3373: will be returned. The order of the words returned is determined by the
3374: database which holds them.
3375:
3376: Uses global $thesaurus_db_file.
3377:
1.1057 foxr 3378:
1.46 matthew 3379: =cut
3380:
3381: ###############################################################
3382: sub get_related_words {
3383: my $keyword = shift;
3384: my %thesaurus_db;
3385: if (! -e $thesaurus_db_file) {
3386: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3387: "failed because the file does not exist");
3388: return ();
3389: }
3390: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3391: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3392: return ();
3393: }
3394: my @Words=();
1.429 www 3395: my $count=0;
1.46 matthew 3396: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3397: # The first element is the number of times
3398: # the word appears. We do not need it now.
1.429 www 3399: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3400: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3401: my $threshold=$mostfrequentcount/10;
3402: foreach my $possibleword (@RelatedWords) {
3403: my ($word,$wordcount)=split(/\,/,$possibleword);
3404: if ($wordcount>$threshold) {
3405: push(@Words,$word);
3406: $count++;
3407: if ($count>10) { last; }
3408: }
1.20 www 3409: }
3410: }
1.46 matthew 3411: untie %thesaurus_db;
3412: return @Words;
1.14 harris41 3413: }
1.46 matthew 3414:
1.112 bowersj2 3415: =pod
3416:
3417: =back
3418:
3419: =cut
1.61 www 3420:
3421: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3422: =pod
3423:
1.112 bowersj2 3424: =head1 User Name Functions
3425:
3426: =over 4
3427:
1.648 raeburn 3428: =item * &plainname($uname,$udom,$first)
1.81 albertel 3429:
1.112 bowersj2 3430: Takes a users logon name and returns it as a string in
1.226 albertel 3431: "first middle last generation" form
3432: if $first is set to 'lastname' then it returns it as
3433: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3434:
3435: =cut
1.61 www 3436:
1.295 www 3437:
1.81 albertel 3438: ###############################################################
1.61 www 3439: sub plainname {
1.226 albertel 3440: my ($uname,$udom,$first)=@_;
1.537 albertel 3441: return if (!defined($uname) || !defined($udom));
1.295 www 3442: my %names=&getnames($uname,$udom);
1.226 albertel 3443: my $name=&Apache::lonnet::format_name($names{'firstname'},
3444: $names{'middlename'},
3445: $names{'lastname'},
3446: $names{'generation'},$first);
3447: $name=~s/^\s+//;
1.62 www 3448: $name=~s/\s+$//;
3449: $name=~s/\s+/ /g;
1.353 albertel 3450: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3451: return $name;
1.61 www 3452: }
1.66 www 3453:
3454: # -------------------------------------------------------------------- Nickname
1.81 albertel 3455: =pod
3456:
1.648 raeburn 3457: =item * &nickname($uname,$udom)
1.81 albertel 3458:
3459: Gets a users name and returns it as a string as
3460:
3461: ""nickname""
1.66 www 3462:
1.81 albertel 3463: if the user has a nickname or
3464:
3465: "first middle last generation"
3466:
3467: if the user does not
3468:
3469: =cut
1.66 www 3470:
3471: sub nickname {
3472: my ($uname,$udom)=@_;
1.537 albertel 3473: return if (!defined($uname) || !defined($udom));
1.295 www 3474: my %names=&getnames($uname,$udom);
1.68 albertel 3475: my $name=$names{'nickname'};
1.66 www 3476: if ($name) {
3477: $name='"'.$name.'"';
3478: } else {
3479: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3480: $names{'lastname'}.' '.$names{'generation'};
3481: $name=~s/\s+$//;
3482: $name=~s/\s+/ /g;
3483: }
3484: return $name;
3485: }
3486:
1.295 www 3487: sub getnames {
3488: my ($uname,$udom)=@_;
1.537 albertel 3489: return if (!defined($uname) || !defined($udom));
1.433 albertel 3490: if ($udom eq 'public' && $uname eq 'public') {
3491: return ('lastname' => &mt('Public'));
3492: }
1.295 www 3493: my $id=$uname.':'.$udom;
3494: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3495: if ($cached) {
3496: return %{$names};
3497: } else {
3498: my %loadnames=&Apache::lonnet::get('environment',
3499: ['firstname','middlename','lastname','generation','nickname'],
3500: $udom,$uname);
3501: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3502: return %loadnames;
3503: }
3504: }
1.61 www 3505:
1.542 raeburn 3506: # -------------------------------------------------------------------- getemails
1.648 raeburn 3507:
1.542 raeburn 3508: =pod
3509:
1.648 raeburn 3510: =item * &getemails($uname,$udom)
1.542 raeburn 3511:
3512: Gets a user's email information and returns it as a hash with keys:
3513: notification, critnotification, permanentemail
3514:
3515: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3516: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3517:
1.648 raeburn 3518:
1.542 raeburn 3519: =cut
3520:
1.648 raeburn 3521:
1.466 albertel 3522: sub getemails {
3523: my ($uname,$udom)=@_;
3524: if ($udom eq 'public' && $uname eq 'public') {
3525: return;
3526: }
1.467 www 3527: if (!$udom) { $udom=$env{'user.domain'}; }
3528: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3529: my $id=$uname.':'.$udom;
3530: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3531: if ($cached) {
3532: return %{$names};
3533: } else {
3534: my %loadnames=&Apache::lonnet::get('environment',
3535: ['notification','critnotification',
3536: 'permanentemail'],
3537: $udom,$uname);
3538: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3539: return %loadnames;
3540: }
3541: }
3542:
1.551 albertel 3543: sub flush_email_cache {
3544: my ($uname,$udom)=@_;
3545: if (!$udom) { $udom =$env{'user.domain'}; }
3546: if (!$uname) { $uname=$env{'user.name'}; }
3547: return if ($udom eq 'public' && $uname eq 'public');
3548: my $id=$uname.':'.$udom;
3549: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3550: }
3551:
1.728 raeburn 3552: # -------------------------------------------------------------------- getlangs
3553:
3554: =pod
3555:
3556: =item * &getlangs($uname,$udom)
3557:
3558: Gets a user's language preference and returns it as a hash with key:
3559: language.
3560:
3561: =cut
3562:
3563:
3564: sub getlangs {
3565: my ($uname,$udom) = @_;
3566: if (!$udom) { $udom =$env{'user.domain'}; }
3567: if (!$uname) { $uname=$env{'user.name'}; }
3568: my $id=$uname.':'.$udom;
3569: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3570: if ($cached) {
3571: return %{$langs};
3572: } else {
3573: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3574: $udom,$uname);
3575: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3576: return %loadlangs;
3577: }
3578: }
3579:
3580: sub flush_langs_cache {
3581: my ($uname,$udom)=@_;
3582: if (!$udom) { $udom =$env{'user.domain'}; }
3583: if (!$uname) { $uname=$env{'user.name'}; }
3584: return if ($udom eq 'public' && $uname eq 'public');
3585: my $id=$uname.':'.$udom;
3586: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3587: }
3588:
1.61 www 3589: # ------------------------------------------------------------------ Screenname
1.81 albertel 3590:
3591: =pod
3592:
1.648 raeburn 3593: =item * &screenname($uname,$udom)
1.81 albertel 3594:
3595: Gets a users screenname and returns it as a string
3596:
3597: =cut
1.61 www 3598:
3599: sub screenname {
3600: my ($uname,$udom)=@_;
1.258 albertel 3601: if ($uname eq $env{'user.name'} &&
3602: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3603: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3604: return $names{'screenname'};
1.62 www 3605: }
3606:
1.212 albertel 3607:
1.802 bisitz 3608: # ------------------------------------------------------------- Confirm Wrapper
3609: =pod
3610:
1.1075.2.42 raeburn 3611: =item * &confirmwrapper($message)
1.802 bisitz 3612:
3613: Wrap messages about completion of operation in box
3614:
3615: =cut
3616:
3617: sub confirmwrapper {
3618: my ($message)=@_;
3619: if ($message) {
3620: return "\n".'<div class="LC_confirm_box">'."\n"
3621: .$message."\n"
3622: .'</div>'."\n";
3623: } else {
3624: return $message;
3625: }
3626: }
3627:
1.62 www 3628: # ------------------------------------------------------------- Message Wrapper
3629:
3630: sub messagewrapper {
1.369 www 3631: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3632: return
1.441 albertel 3633: '<a href="/adm/email?compose=individual&'.
3634: 'recname='.$username.'&recdom='.$domain.
3635: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3636: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3637: }
1.802 bisitz 3638:
1.74 www 3639: # --------------------------------------------------------------- Notes Wrapper
3640:
3641: sub noteswrapper {
3642: my ($link,$un,$do)=@_;
3643: return
1.896 amueller 3644: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3645: }
1.802 bisitz 3646:
1.62 www 3647: # ------------------------------------------------------------- Aboutme Wrapper
3648:
3649: sub aboutmewrapper {
1.1070 raeburn 3650: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3651: if (!defined($username) && !defined($domain)) {
3652: return;
3653: }
1.1075.2.15 raeburn 3654: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3655: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3656: }
3657:
3658: # ------------------------------------------------------------ Syllabus Wrapper
3659:
3660: sub syllabuswrapper {
1.707 bisitz 3661: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3662: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3663: }
1.14 harris41 3664:
1.802 bisitz 3665: # -----------------------------------------------------------------------------
3666:
1.208 matthew 3667: sub track_student_link {
1.887 raeburn 3668: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3669: my $link ="/adm/trackstudent?";
1.208 matthew 3670: my $title = 'View recent activity';
3671: if (defined($sname) && $sname !~ /^\s*$/ &&
3672: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3673: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3674: $title .= ' of this student';
1.268 albertel 3675: }
1.208 matthew 3676: if (defined($target) && $target !~ /^\s*$/) {
3677: $target = qq{target="$target"};
3678: } else {
3679: $target = '';
3680: }
1.268 albertel 3681: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3682: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3683: $title = &mt($title);
3684: $linktext = &mt($linktext);
1.448 albertel 3685: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3686: &help_open_topic('View_recent_activity');
1.208 matthew 3687: }
3688:
1.781 raeburn 3689: sub slot_reservations_link {
3690: my ($linktext,$sname,$sdom,$target) = @_;
3691: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3692: my $title = 'View slot reservation history';
3693: if (defined($sname) && $sname !~ /^\s*$/ &&
3694: defined($sdom) && $sdom !~ /^\s*$/) {
3695: $link .= "&uname=$sname&udom=$sdom";
3696: $title .= ' of this student';
3697: }
3698: if (defined($target) && $target !~ /^\s*$/) {
3699: $target = qq{target="$target"};
3700: } else {
3701: $target = '';
3702: }
3703: $title = &mt($title);
3704: $linktext = &mt($linktext);
3705: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3706: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3707:
3708: }
3709:
1.508 www 3710: # ===================================================== Display a student photo
3711:
3712:
1.509 albertel 3713: sub student_image_tag {
1.508 www 3714: my ($domain,$user)=@_;
3715: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3716: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3717: return '<img src="'.$imgsrc.'" align="right" />';
3718: } else {
3719: return '';
3720: }
3721: }
3722:
1.112 bowersj2 3723: =pod
3724:
3725: =back
3726:
3727: =head1 Access .tab File Data
3728:
3729: =over 4
3730:
1.648 raeburn 3731: =item * &languageids()
1.112 bowersj2 3732:
3733: returns list of all language ids
3734:
3735: =cut
3736:
1.14 harris41 3737: sub languageids {
1.16 harris41 3738: return sort(keys(%language));
1.14 harris41 3739: }
3740:
1.112 bowersj2 3741: =pod
3742:
1.648 raeburn 3743: =item * &languagedescription()
1.112 bowersj2 3744:
3745: returns description of a specified language id
3746:
3747: =cut
3748:
1.14 harris41 3749: sub languagedescription {
1.125 www 3750: my $code=shift;
3751: return ($supported_language{$code}?'* ':'').
3752: $language{$code}.
1.126 www 3753: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3754: }
3755:
1.1048 foxr 3756: =pod
3757:
3758: =item * &plainlanguagedescription
3759:
3760: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3761: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3762:
3763: =cut
3764:
1.145 www 3765: sub plainlanguagedescription {
3766: my $code=shift;
3767: return $language{$code};
3768: }
3769:
1.1048 foxr 3770: =pod
3771:
3772: =item * &supportedlanguagecode
3773:
3774: Returns the supported language code (e.g. sptutf maps to pt) given a language
3775: code.
3776:
3777: =cut
3778:
1.145 www 3779: sub supportedlanguagecode {
3780: my $code=shift;
3781: return $supported_language{$code};
1.97 www 3782: }
3783:
1.112 bowersj2 3784: =pod
3785:
1.1048 foxr 3786: =item * &latexlanguage()
3787:
3788: Given a language key code returns the correspondnig language to use
3789: to select the correct hyphenation on LaTeX printouts. This is undef if there
3790: is no supported hyphenation for the language code.
3791:
3792: =cut
3793:
3794: sub latexlanguage {
3795: my $code = shift;
3796: return $latex_language{$code};
3797: }
3798:
3799: =pod
3800:
3801: =item * &latexhyphenation()
3802:
3803: Same as above but what's supplied is the language as it might be stored
3804: in the metadata.
3805:
3806: =cut
3807:
3808: sub latexhyphenation {
3809: my $key = shift;
3810: return $latex_language_bykey{$key};
3811: }
3812:
3813: =pod
3814:
1.648 raeburn 3815: =item * ©rightids()
1.112 bowersj2 3816:
3817: returns list of all copyrights
3818:
3819: =cut
3820:
3821: sub copyrightids {
3822: return sort(keys(%cprtag));
3823: }
3824:
3825: =pod
3826:
1.648 raeburn 3827: =item * ©rightdescription()
1.112 bowersj2 3828:
3829: returns description of a specified copyright id
3830:
3831: =cut
3832:
3833: sub copyrightdescription {
1.166 www 3834: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3835: }
1.197 matthew 3836:
3837: =pod
3838:
1.648 raeburn 3839: =item * &source_copyrightids()
1.192 taceyjo1 3840:
3841: returns list of all source copyrights
3842:
3843: =cut
3844:
3845: sub source_copyrightids {
3846: return sort(keys(%scprtag));
3847: }
3848:
3849: =pod
3850:
1.648 raeburn 3851: =item * &source_copyrightdescription()
1.192 taceyjo1 3852:
3853: returns description of a specified source copyright id
3854:
3855: =cut
3856:
3857: sub source_copyrightdescription {
3858: return &mt($scprtag{shift(@_)});
3859: }
1.112 bowersj2 3860:
3861: =pod
3862:
1.648 raeburn 3863: =item * &filecategories()
1.112 bowersj2 3864:
3865: returns list of all file categories
3866:
3867: =cut
3868:
3869: sub filecategories {
3870: return sort(keys(%category_extensions));
3871: }
3872:
3873: =pod
3874:
1.648 raeburn 3875: =item * &filecategorytypes()
1.112 bowersj2 3876:
3877: returns list of file types belonging to a given file
3878: category
3879:
3880: =cut
3881:
3882: sub filecategorytypes {
1.356 albertel 3883: my ($cat) = @_;
3884: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3885: }
3886:
3887: =pod
3888:
1.648 raeburn 3889: =item * &fileembstyle()
1.112 bowersj2 3890:
3891: returns embedding style for a specified file type
3892:
3893: =cut
3894:
3895: sub fileembstyle {
3896: return $fe{lc(shift(@_))};
1.169 www 3897: }
3898:
1.351 www 3899: sub filemimetype {
3900: return $fm{lc(shift(@_))};
3901: }
3902:
1.169 www 3903:
3904: sub filecategoryselect {
3905: my ($name,$value)=@_;
1.189 matthew 3906: return &select_form($value,$name,
1.970 raeburn 3907: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3908: }
3909:
3910: =pod
3911:
1.648 raeburn 3912: =item * &filedescription()
1.112 bowersj2 3913:
3914: returns description for a specified file type
3915:
3916: =cut
3917:
3918: sub filedescription {
1.188 matthew 3919: my $file_description = $fd{lc(shift())};
3920: $file_description =~ s:([\[\]]):~$1:g;
3921: return &mt($file_description);
1.112 bowersj2 3922: }
3923:
3924: =pod
3925:
1.648 raeburn 3926: =item * &filedescriptionex()
1.112 bowersj2 3927:
3928: returns description for a specified file type with
3929: extra formatting
3930:
3931: =cut
3932:
3933: sub filedescriptionex {
3934: my $ex=shift;
1.188 matthew 3935: my $file_description = $fd{lc($ex)};
3936: $file_description =~ s:([\[\]]):~$1:g;
3937: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3938: }
3939:
3940: # End of .tab access
3941: =pod
3942:
3943: =back
3944:
3945: =cut
3946:
3947: # ------------------------------------------------------------------ File Types
3948: sub fileextensions {
3949: return sort(keys(%fe));
3950: }
3951:
1.97 www 3952: # ----------------------------------------------------------- Display Languages
3953: # returns a hash with all desired display languages
3954: #
3955:
3956: sub display_languages {
3957: my %languages=();
1.695 raeburn 3958: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3959: $languages{$lang}=1;
1.97 www 3960: }
3961: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3962: if ($env{'form.displaylanguage'}) {
1.356 albertel 3963: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3964: $languages{$lang}=1;
1.97 www 3965: }
3966: }
3967: return %languages;
1.14 harris41 3968: }
3969:
1.582 albertel 3970: sub languages {
3971: my ($possible_langs) = @_;
1.695 raeburn 3972: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3973: if (!ref($possible_langs)) {
3974: if( wantarray ) {
3975: return @preferred_langs;
3976: } else {
3977: return $preferred_langs[0];
3978: }
3979: }
3980: my %possibilities = map { $_ => 1 } (@$possible_langs);
3981: my @preferred_possibilities;
3982: foreach my $preferred_lang (@preferred_langs) {
3983: if (exists($possibilities{$preferred_lang})) {
3984: push(@preferred_possibilities, $preferred_lang);
3985: }
3986: }
3987: if( wantarray ) {
3988: return @preferred_possibilities;
3989: }
3990: return $preferred_possibilities[0];
3991: }
3992:
1.742 raeburn 3993: sub user_lang {
3994: my ($touname,$toudom,$fromcid) = @_;
3995: my @userlangs;
3996: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3997: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3998: $env{'course.'.$fromcid.'.languages'}));
3999: } else {
4000: my %langhash = &getlangs($touname,$toudom);
4001: if ($langhash{'languages'} ne '') {
4002: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4003: } else {
4004: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4005: if ($domdefs{'lang_def'} ne '') {
4006: @userlangs = ($domdefs{'lang_def'});
4007: }
4008: }
4009: }
4010: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4011: my $user_lh = Apache::localize->get_handle(@languages);
4012: return $user_lh;
4013: }
4014:
4015:
1.112 bowersj2 4016: ###############################################################
4017: ## Student Answer Attempts ##
4018: ###############################################################
4019:
4020: =pod
4021:
4022: =head1 Alternate Problem Views
4023:
4024: =over 4
4025:
1.648 raeburn 4026: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1075.2.86 raeburn 4027: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4028:
4029: Return string with previous attempt on problem. Arguments:
4030:
4031: =over 4
4032:
4033: =item * $symb: Problem, including path
4034:
4035: =item * $username: username of the desired student
4036:
4037: =item * $domain: domain of the desired student
1.14 harris41 4038:
1.112 bowersj2 4039: =item * $course: Course ID
1.14 harris41 4040:
1.112 bowersj2 4041: =item * $getattempt: Leave blank for all attempts, otherwise put
4042: something
1.14 harris41 4043:
1.112 bowersj2 4044: =item * $regexp: if string matches this regexp, the string will be
4045: sent to $gradesub
1.14 harris41 4046:
1.112 bowersj2 4047: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4048:
1.1075.2.86 raeburn 4049: =item * $usec: section of the desired student
4050:
4051: =item * $identifier: counter for student (multiple students one problem) or
4052: problem (one student; whole sequence).
4053:
1.112 bowersj2 4054: =back
1.14 harris41 4055:
1.112 bowersj2 4056: The output string is a table containing all desired attempts, if any.
1.16 harris41 4057:
1.112 bowersj2 4058: =cut
1.1 albertel 4059:
4060: sub get_previous_attempt {
1.1075.2.86 raeburn 4061: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4062: my $prevattempts='';
1.43 ng 4063: no strict 'refs';
1.1 albertel 4064: if ($symb) {
1.3 albertel 4065: my (%returnhash)=
4066: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4067: if ($returnhash{'version'}) {
4068: my %lasthash=();
4069: my $version;
4070: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.91 raeburn 4071: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4072: if ($key =~ /\.rawrndseed$/) {
4073: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4074: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4075: } else {
4076: $lasthash{$key}=$returnhash{$version.':'.$key};
4077: }
1.19 harris41 4078: }
1.1 albertel 4079: }
1.596 albertel 4080: $prevattempts=&start_data_table().&start_data_table_header_row();
4081: $prevattempts.='<th>'.&mt('History').'</th>';
1.1075.2.86 raeburn 4082: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4083: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4084: foreach my $key (sort(keys(%lasthash))) {
4085: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4086: if ($#parts > 0) {
1.31 albertel 4087: my $data=$parts[-1];
1.989 raeburn 4088: next if ($data eq 'foilorder');
1.31 albertel 4089: pop(@parts);
1.1010 www 4090: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4091: if ($data eq 'type') {
4092: unless ($showsurv) {
4093: my $id = join(',',@parts);
4094: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4095: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4096: $lasthidden{$ign.'.'.$id} = 1;
4097: }
1.945 raeburn 4098: }
1.1075.2.86 raeburn 4099: if ($identifier ne '') {
4100: my $id = join(',',@parts);
4101: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4102: $domain,$username,$usec,undef,$course) =~ /^no/) {
4103: $hidestatus{$ign.'.'.$id} = 1;
4104: }
4105: }
4106: } elsif ($data eq 'regrader') {
4107: if (($identifier ne '') && (@parts)) {
4108: my $id = join(',',@parts);
4109: $regraded{$ign.'.'.$id} = 1;
4110: }
1.1010 www 4111: }
1.31 albertel 4112: } else {
1.41 ng 4113: if ($#parts == 0) {
4114: $prevattempts.='<th>'.$parts[0].'</th>';
4115: } else {
4116: $prevattempts.='<th>'.$ign.'</th>';
4117: }
1.31 albertel 4118: }
1.16 harris41 4119: }
1.596 albertel 4120: $prevattempts.=&end_data_table_header_row();
1.40 ng 4121: if ($getattempt eq '') {
1.1075.2.86 raeburn 4122: my (%solved,%resets,%probstatus);
4123: if (($identifier ne '') && (keys(%regraded) > 0)) {
4124: for ($version=1;$version<=$returnhash{'version'};$version++) {
4125: foreach my $id (keys(%regraded)) {
4126: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4127: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4128: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4129: push(@{$resets{$id}},$version);
4130: }
4131: }
4132: }
4133: }
1.40 ng 4134: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.86 raeburn 4135: my (@hidden,@unsolved);
1.945 raeburn 4136: if (%typeparts) {
4137: foreach my $id (keys(%typeparts)) {
1.1075.2.86 raeburn 4138: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4139: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4140: push(@hidden,$id);
1.1075.2.86 raeburn 4141: } elsif ($identifier ne '') {
4142: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4143: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4144: ($hidestatus{$id})) {
4145: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
4146: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4147: push(@{$solved{$id}},$version);
4148: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4149: (ref($solved{$id}) eq 'ARRAY')) {
4150: my $skip;
4151: if (ref($resets{$id}) eq 'ARRAY') {
4152: foreach my $reset (@{$resets{$id}}) {
4153: if ($reset > $solved{$id}[-1]) {
4154: $skip=1;
4155: last;
4156: }
4157: }
4158: }
4159: unless ($skip) {
4160: my ($ign,$partslist) = split(/\./,$id,2);
4161: push(@unsolved,$partslist);
4162: }
4163: }
4164: }
1.945 raeburn 4165: }
4166: }
4167: }
4168: $prevattempts.=&start_data_table_row().
1.1075.2.86 raeburn 4169: '<td>'.&mt('Transaction [_1]',$version);
4170: if (@unsolved) {
4171: $prevattempts .= '<span class="LC_nobreak"><label>'.
4172: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4173: &mt('Hide').'</label></span>';
4174: }
4175: $prevattempts .= '</td>';
1.945 raeburn 4176: if (@hidden) {
4177: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4178: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4179: my $hide;
4180: foreach my $id (@hidden) {
4181: if ($key =~ /^\Q$id\E/) {
4182: $hide = 1;
4183: last;
4184: }
4185: }
4186: if ($hide) {
4187: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4188: if (($data eq 'award') || ($data eq 'awarddetail')) {
4189: my $value = &format_previous_attempt_value($key,
4190: $returnhash{$version.':'.$key});
4191: $prevattempts.='<td>'.$value.' </td>';
4192: } else {
4193: $prevattempts.='<td> </td>';
4194: }
4195: } else {
4196: if ($key =~ /\./) {
1.1075.2.91 raeburn 4197: my $value = $returnhash{$version.':'.$key};
4198: if ($key =~ /\.rndseed$/) {
4199: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4200: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4201: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4202: }
4203: }
4204: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4205: ' </td>';
1.945 raeburn 4206: } else {
4207: $prevattempts.='<td> </td>';
4208: }
4209: }
4210: }
4211: } else {
4212: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4213: next if ($key =~ /\.foilorder$/);
1.1075.2.91 raeburn 4214: my $value = $returnhash{$version.':'.$key};
4215: if ($key =~ /\.rndseed$/) {
4216: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4217: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4218: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4219: }
4220: }
4221: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4222: ' </td>';
1.945 raeburn 4223: }
4224: }
4225: $prevattempts.=&end_data_table_row();
1.40 ng 4226: }
1.1 albertel 4227: }
1.945 raeburn 4228: my @currhidden = keys(%lasthidden);
1.596 albertel 4229: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4230: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4231: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4232: if (%typeparts) {
4233: my $hidden;
4234: foreach my $id (@currhidden) {
4235: if ($key =~ /^\Q$id\E/) {
4236: $hidden = 1;
4237: last;
4238: }
4239: }
4240: if ($hidden) {
4241: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4242: if (($data eq 'award') || ($data eq 'awarddetail')) {
4243: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4244: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4245: $value = &$gradesub($value);
4246: }
4247: $prevattempts.='<td>'.$value.' </td>';
4248: } else {
4249: $prevattempts.='<td> </td>';
4250: }
4251: } else {
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: }
4258: } else {
4259: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4260: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4261: $value = &$gradesub($value);
4262: }
4263: $prevattempts.='<td>'.$value.' </td>';
4264: }
1.16 harris41 4265: }
1.596 albertel 4266: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4267: } else {
1.596 albertel 4268: $prevattempts=
4269: &start_data_table().&start_data_table_row().
4270: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4271: &end_data_table_row().&end_data_table();
1.1 albertel 4272: }
4273: } else {
1.596 albertel 4274: $prevattempts=
4275: &start_data_table().&start_data_table_row().
4276: '<td>'.&mt('No data.').'</td>'.
4277: &end_data_table_row().&end_data_table();
1.1 albertel 4278: }
1.10 albertel 4279: }
4280:
1.581 albertel 4281: sub format_previous_attempt_value {
4282: my ($key,$value) = @_;
1.1011 www 4283: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 4284: $value = &Apache::lonlocal::locallocaltime($value);
4285: } elsif (ref($value) eq 'ARRAY') {
4286: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 4287: } elsif ($key =~ /answerstring$/) {
4288: my %answers = &Apache::lonnet::str2hash($value);
4289: my @anskeys = sort(keys(%answers));
4290: if (@anskeys == 1) {
4291: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4292: if ($answer =~ m{\0}) {
4293: $answer =~ s{\0}{,}g;
1.988 raeburn 4294: }
4295: my $tag_internal_answer_name = 'INTERNAL';
4296: if ($anskeys[0] eq $tag_internal_answer_name) {
4297: $value = $answer;
4298: } else {
4299: $value = $anskeys[0].'='.$answer;
4300: }
4301: } else {
4302: foreach my $ans (@anskeys) {
4303: my $answer = $answers{$ans};
1.1001 raeburn 4304: if ($answer =~ m{\0}) {
4305: $answer =~ s{\0}{,}g;
1.988 raeburn 4306: }
4307: $value .= $ans.'='.$answer.'<br />';;
4308: }
4309: }
1.581 albertel 4310: } else {
4311: $value = &unescape($value);
4312: }
4313: return $value;
4314: }
4315:
4316:
1.107 albertel 4317: sub relative_to_absolute {
4318: my ($url,$output)=@_;
4319: my $parser=HTML::TokeParser->new(\$output);
4320: my $token;
4321: my $thisdir=$url;
4322: my @rlinks=();
4323: while ($token=$parser->get_token) {
4324: if ($token->[0] eq 'S') {
4325: if ($token->[1] eq 'a') {
4326: if ($token->[2]->{'href'}) {
4327: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4328: }
4329: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4330: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4331: } elsif ($token->[1] eq 'base') {
4332: $thisdir=$token->[2]->{'href'};
4333: }
4334: }
4335: }
4336: $thisdir=~s-/[^/]*$--;
1.356 albertel 4337: foreach my $link (@rlinks) {
1.726 raeburn 4338: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4339: ($link=~/^\//) ||
4340: ($link=~/^javascript:/i) ||
4341: ($link=~/^mailto:/i) ||
4342: ($link=~/^\#/)) {
4343: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4344: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4345: }
4346: }
4347: # -------------------------------------------------- Deal with Applet codebases
4348: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4349: return $output;
4350: }
4351:
1.112 bowersj2 4352: =pod
4353:
1.648 raeburn 4354: =item * &get_student_view()
1.112 bowersj2 4355:
4356: show a snapshot of what student was looking at
4357:
4358: =cut
4359:
1.10 albertel 4360: sub get_student_view {
1.186 albertel 4361: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4362: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4363: my (%form);
1.10 albertel 4364: my @elements=('symb','courseid','domain','username');
4365: foreach my $element (@elements) {
1.186 albertel 4366: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4367: }
1.186 albertel 4368: if (defined($moreenv)) {
4369: %form=(%form,%{$moreenv});
4370: }
1.236 albertel 4371: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4372: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4373: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4374: $userview=~s/\<body[^\>]*\>//gi;
4375: $userview=~s/\<\/body\>//gi;
4376: $userview=~s/\<html\>//gi;
4377: $userview=~s/\<\/html\>//gi;
4378: $userview=~s/\<head\>//gi;
4379: $userview=~s/\<\/head\>//gi;
4380: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4381: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4382: if (wantarray) {
4383: return ($userview,$response);
4384: } else {
4385: return $userview;
4386: }
4387: }
4388:
4389: sub get_student_view_with_retries {
4390: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4391:
4392: my $ok = 0; # True if we got a good response.
4393: my $content;
4394: my $response;
4395:
4396: # Try to get the student_view done. within the retries count:
4397:
4398: do {
4399: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4400: $ok = $response->is_success;
4401: if (!$ok) {
4402: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4403: }
4404: $retries--;
4405: } while (!$ok && ($retries > 0));
4406:
4407: if (!$ok) {
4408: $content = ''; # On error return an empty content.
4409: }
1.651 www 4410: if (wantarray) {
4411: return ($content, $response);
4412: } else {
4413: return $content;
4414: }
1.11 albertel 4415: }
4416:
1.112 bowersj2 4417: =pod
4418:
1.648 raeburn 4419: =item * &get_student_answers()
1.112 bowersj2 4420:
4421: show a snapshot of how student was answering problem
4422:
4423: =cut
4424:
1.11 albertel 4425: sub get_student_answers {
1.100 sakharuk 4426: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4427: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4428: my (%moreenv);
1.11 albertel 4429: my @elements=('symb','courseid','domain','username');
4430: foreach my $element (@elements) {
1.186 albertel 4431: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4432: }
1.186 albertel 4433: $moreenv{'grade_target'}='answer';
4434: %moreenv=(%form,%moreenv);
1.497 raeburn 4435: $feedurl = &Apache::lonnet::clutter($feedurl);
4436: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4437: return $userview;
1.1 albertel 4438: }
1.116 albertel 4439:
4440: =pod
4441:
4442: =item * &submlink()
4443:
1.242 albertel 4444: Inputs: $text $uname $udom $symb $target
1.116 albertel 4445:
4446: Returns: A link to grades.pm such as to see the SUBM view of a student
4447:
4448: =cut
4449:
4450: ###############################################
4451: sub submlink {
1.242 albertel 4452: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4453: if (!($uname && $udom)) {
4454: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4455: &Apache::lonnet::whichuser($symb);
1.116 albertel 4456: if (!$symb) { $symb=$cursymb; }
4457: }
1.254 matthew 4458: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4459: $symb=&escape($symb);
1.960 bisitz 4460: if ($target) { $target=" target=\"$target\""; }
4461: return
4462: '<a href="/adm/grades?command=submission'.
4463: '&symb='.$symb.
4464: '&student='.$uname.
4465: '&userdom='.$udom.'"'.
4466: $target.'>'.$text.'</a>';
1.242 albertel 4467: }
4468: ##############################################
4469:
4470: =pod
4471:
4472: =item * &pgrdlink()
4473:
4474: Inputs: $text $uname $udom $symb $target
4475:
4476: Returns: A link to grades.pm such as to see the PGRD view of a student
4477:
4478: =cut
4479:
4480: ###############################################
4481: sub pgrdlink {
4482: my $link=&submlink(@_);
4483: $link=~s/(&command=submission)/$1&showgrading=yes/;
4484: return $link;
4485: }
4486: ##############################################
4487:
4488: =pod
4489:
4490: =item * &pprmlink()
4491:
4492: Inputs: $text $uname $udom $symb $target
4493:
4494: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4495: student and a specific resource
1.242 albertel 4496:
4497: =cut
4498:
4499: ###############################################
4500: sub pprmlink {
4501: my ($text,$uname,$udom,$symb,$target)=@_;
4502: if (!($uname && $udom)) {
4503: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4504: &Apache::lonnet::whichuser($symb);
1.242 albertel 4505: if (!$symb) { $symb=$cursymb; }
4506: }
1.254 matthew 4507: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4508: $symb=&escape($symb);
1.242 albertel 4509: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4510: return '<a href="/adm/parmset?command=set&'.
4511: 'symb='.$symb.'&uname='.$uname.
4512: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4513: }
4514: ##############################################
1.37 matthew 4515:
1.112 bowersj2 4516: =pod
4517:
4518: =back
4519:
4520: =cut
4521:
1.37 matthew 4522: ###############################################
1.51 www 4523:
4524:
4525: sub timehash {
1.687 raeburn 4526: my ($thistime) = @_;
4527: my $timezone = &Apache::lonlocal::gettimezone();
4528: my $dt = DateTime->from_epoch(epoch => $thistime)
4529: ->set_time_zone($timezone);
4530: my $wday = $dt->day_of_week();
4531: if ($wday == 7) { $wday = 0; }
4532: return ( 'second' => $dt->second(),
4533: 'minute' => $dt->minute(),
4534: 'hour' => $dt->hour(),
4535: 'day' => $dt->day_of_month(),
4536: 'month' => $dt->month(),
4537: 'year' => $dt->year(),
4538: 'weekday' => $wday,
4539: 'dayyear' => $dt->day_of_year(),
4540: 'dlsav' => $dt->is_dst() );
1.51 www 4541: }
4542:
1.370 www 4543: sub utc_string {
4544: my ($date)=@_;
1.371 www 4545: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4546: }
4547:
1.51 www 4548: sub maketime {
4549: my %th=@_;
1.687 raeburn 4550: my ($epoch_time,$timezone,$dt);
4551: $timezone = &Apache::lonlocal::gettimezone();
4552: eval {
4553: $dt = DateTime->new( year => $th{'year'},
4554: month => $th{'month'},
4555: day => $th{'day'},
4556: hour => $th{'hour'},
4557: minute => $th{'minute'},
4558: second => $th{'second'},
4559: time_zone => $timezone,
4560: );
4561: };
4562: if (!$@) {
4563: $epoch_time = $dt->epoch;
4564: if ($epoch_time) {
4565: return $epoch_time;
4566: }
4567: }
1.51 www 4568: return POSIX::mktime(
4569: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4570: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4571: }
4572:
4573: #########################################
1.51 www 4574:
4575: sub findallcourses {
1.482 raeburn 4576: my ($roles,$uname,$udom) = @_;
1.355 albertel 4577: my %roles;
4578: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4579: my %courses;
1.51 www 4580: my $now=time;
1.482 raeburn 4581: if (!defined($uname)) {
4582: $uname = $env{'user.name'};
4583: }
4584: if (!defined($udom)) {
4585: $udom = $env{'user.domain'};
4586: }
4587: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4588: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4589: if (!%roles) {
4590: %roles = (
4591: cc => 1,
1.907 raeburn 4592: co => 1,
1.482 raeburn 4593: in => 1,
4594: ep => 1,
4595: ta => 1,
4596: cr => 1,
4597: st => 1,
4598: );
4599: }
4600: foreach my $entry (keys(%roleshash)) {
4601: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4602: if ($trole =~ /^cr/) {
4603: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4604: } else {
4605: next if (!exists($roles{$trole}));
4606: }
4607: if ($tend) {
4608: next if ($tend < $now);
4609: }
4610: if ($tstart) {
4611: next if ($tstart > $now);
4612: }
1.1058 raeburn 4613: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4614: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4615: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4616: if ($secpart eq '') {
4617: ($cnum,$role) = split(/_/,$cnumpart);
4618: $sec = 'none';
1.1058 raeburn 4619: $value .= $cnum.'/';
1.482 raeburn 4620: } else {
4621: $cnum = $cnumpart;
4622: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4623: $value .= $cnum.'/'.$sec;
4624: }
4625: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4626: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4627: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4628: }
4629: } else {
4630: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4631: }
1.482 raeburn 4632: }
4633: } else {
4634: foreach my $key (keys(%env)) {
1.483 albertel 4635: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4636: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4637: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4638: next if ($role eq 'ca' || $role eq 'aa');
4639: next if (%roles && !exists($roles{$role}));
4640: my ($starttime,$endtime)=split(/\./,$env{$key});
4641: my $active=1;
4642: if ($starttime) {
4643: if ($now<$starttime) { $active=0; }
4644: }
4645: if ($endtime) {
4646: if ($now>$endtime) { $active=0; }
4647: }
4648: if ($active) {
1.1058 raeburn 4649: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4650: if ($sec eq '') {
4651: $sec = 'none';
1.1058 raeburn 4652: } else {
4653: $value .= $sec;
4654: }
4655: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4656: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4657: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4658: }
4659: } else {
4660: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4661: }
1.474 raeburn 4662: }
4663: }
1.51 www 4664: }
4665: }
1.474 raeburn 4666: return %courses;
1.51 www 4667: }
1.37 matthew 4668:
1.54 www 4669: ###############################################
1.474 raeburn 4670:
4671: sub blockcheck {
1.1075.2.73 raeburn 4672: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4673:
1.1075.2.73 raeburn 4674: if (defined($udom) && defined($uname)) {
4675: # If uname and udom are for a course, check for blocks in the course.
4676: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4677: my ($startblock,$endblock,$triggerblock) =
4678: &get_blocks($setters,$activity,$udom,$uname,$url);
4679: return ($startblock,$endblock,$triggerblock);
4680: }
4681: } else {
1.490 raeburn 4682: $udom = $env{'user.domain'};
4683: $uname = $env{'user.name'};
4684: }
4685:
1.502 raeburn 4686: my $startblock = 0;
4687: my $endblock = 0;
1.1062 raeburn 4688: my $triggerblock = '';
1.482 raeburn 4689: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4690:
1.490 raeburn 4691: # If uname is for a user, and activity is course-specific, i.e.,
4692: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4693:
1.490 raeburn 4694: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.73 raeburn 4695: $activity eq 'groups' || $activity eq 'printout') &&
4696: ($env{'request.course.id'})) {
1.490 raeburn 4697: foreach my $key (keys(%live_courses)) {
4698: if ($key ne $env{'request.course.id'}) {
4699: delete($live_courses{$key});
4700: }
4701: }
4702: }
4703:
4704: my $otheruser = 0;
4705: my %own_courses;
4706: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4707: # Resource belongs to user other than current user.
4708: $otheruser = 1;
4709: # Gather courses for current user
4710: %own_courses =
4711: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4712: }
4713:
4714: # Gather active course roles - course coordinator, instructor,
4715: # exam proctor, ta, student, or custom role.
1.474 raeburn 4716:
4717: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4718: my ($cdom,$cnum);
4719: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4720: $cdom = $env{'course.'.$course.'.domain'};
4721: $cnum = $env{'course.'.$course.'.num'};
4722: } else {
1.490 raeburn 4723: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4724: }
4725: my $no_ownblock = 0;
4726: my $no_userblock = 0;
1.533 raeburn 4727: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4728: # Check if current user has 'evb' priv for this
4729: if (defined($own_courses{$course})) {
4730: foreach my $sec (keys(%{$own_courses{$course}})) {
4731: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4732: if ($sec ne 'none') {
4733: $checkrole .= '/'.$sec;
4734: }
4735: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4736: $no_ownblock = 1;
4737: last;
4738: }
4739: }
4740: }
4741: # if they have 'evb' priv and are currently not playing student
4742: next if (($no_ownblock) &&
4743: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4744: }
1.474 raeburn 4745: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4746: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4747: if ($sec ne 'none') {
1.482 raeburn 4748: $checkrole .= '/'.$sec;
1.474 raeburn 4749: }
1.490 raeburn 4750: if ($otheruser) {
4751: # Resource belongs to user other than current user.
4752: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4753: my (%allroles,%userroles);
4754: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4755: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4756: my ($trole,$tdom,$tnum,$tsec);
4757: if ($entry =~ /^cr/) {
4758: ($trole,$tdom,$tnum,$tsec) =
4759: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4760: } else {
4761: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4762: }
4763: my ($spec,$area,$trest);
4764: $area = '/'.$tdom.'/'.$tnum;
4765: $trest = $tnum;
4766: if ($tsec ne '') {
4767: $area .= '/'.$tsec;
4768: $trest .= '/'.$tsec;
4769: }
4770: $spec = $trole.'.'.$area;
4771: if ($trole =~ /^cr/) {
4772: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4773: $tdom,$spec,$trest,$area);
4774: } else {
4775: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4776: $tdom,$spec,$trest,$area);
4777: }
4778: }
1.1075.2.124 raeburn 4779: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 4780: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4781: if ($1) {
4782: $no_userblock = 1;
4783: last;
4784: }
1.486 raeburn 4785: }
4786: }
1.490 raeburn 4787: } else {
4788: # Resource belongs to current user
4789: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4790: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4791: $no_ownblock = 1;
4792: last;
4793: }
1.474 raeburn 4794: }
4795: }
4796: # if they have the evb priv and are currently not playing student
1.482 raeburn 4797: next if (($no_ownblock) &&
1.491 albertel 4798: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4799: next if ($no_userblock);
1.474 raeburn 4800:
1.1075.2.128 raeburn 4801: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 4802: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4803:
1.1062 raeburn 4804: my ($start,$end,$trigger) =
4805: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4806: if (($start != 0) &&
4807: (($startblock == 0) || ($startblock > $start))) {
4808: $startblock = $start;
1.1062 raeburn 4809: if ($trigger ne '') {
4810: $triggerblock = $trigger;
4811: }
1.502 raeburn 4812: }
4813: if (($end != 0) &&
4814: (($endblock == 0) || ($endblock < $end))) {
4815: $endblock = $end;
1.1062 raeburn 4816: if ($trigger ne '') {
4817: $triggerblock = $trigger;
4818: }
1.502 raeburn 4819: }
1.490 raeburn 4820: }
1.1062 raeburn 4821: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4822: }
4823:
4824: sub get_blocks {
1.1062 raeburn 4825: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4826: my $startblock = 0;
4827: my $endblock = 0;
1.1062 raeburn 4828: my $triggerblock = '';
1.490 raeburn 4829: my $course = $cdom.'_'.$cnum;
4830: $setters->{$course} = {};
4831: $setters->{$course}{'staff'} = [];
4832: $setters->{$course}{'times'} = [];
1.1062 raeburn 4833: $setters->{$course}{'triggers'} = [];
4834: my (@blockers,%triggered);
4835: my $now = time;
4836: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4837: if ($activity eq 'docs') {
4838: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4839: foreach my $block (@blockers) {
4840: if ($block =~ /^firstaccess____(.+)$/) {
4841: my $item = $1;
4842: my $type = 'map';
4843: my $timersymb = $item;
4844: if ($item eq 'course') {
4845: $type = 'course';
4846: } elsif ($item =~ /___\d+___/) {
4847: $type = 'resource';
4848: } else {
4849: $timersymb = &Apache::lonnet::symbread($item);
4850: }
4851: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4852: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4853: $triggered{$block} = {
4854: start => $start,
4855: end => $end,
4856: type => $type,
4857: };
4858: }
4859: }
4860: } else {
4861: foreach my $block (keys(%commblocks)) {
4862: if ($block =~ m/^(\d+)____(\d+)$/) {
4863: my ($start,$end) = ($1,$2);
4864: if ($start <= time && $end >= time) {
4865: if (ref($commblocks{$block}) eq 'HASH') {
4866: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4867: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4868: unless(grep(/^\Q$block\E$/,@blockers)) {
4869: push(@blockers,$block);
4870: }
4871: }
4872: }
4873: }
4874: }
4875: } elsif ($block =~ /^firstaccess____(.+)$/) {
4876: my $item = $1;
4877: my $timersymb = $item;
4878: my $type = 'map';
4879: if ($item eq 'course') {
4880: $type = 'course';
4881: } elsif ($item =~ /___\d+___/) {
4882: $type = 'resource';
4883: } else {
4884: $timersymb = &Apache::lonnet::symbread($item);
4885: }
4886: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4887: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4888: if ($start && $end) {
4889: if (($start <= time) && ($end >= time)) {
4890: unless (grep(/^\Q$block\E$/,@blockers)) {
4891: push(@blockers,$block);
4892: $triggered{$block} = {
4893: start => $start,
4894: end => $end,
4895: type => $type,
4896: };
4897: }
4898: }
1.490 raeburn 4899: }
1.1062 raeburn 4900: }
4901: }
4902: }
4903: foreach my $blocker (@blockers) {
4904: my ($staff_name,$staff_dom,$title,$blocks) =
4905: &parse_block_record($commblocks{$blocker});
4906: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4907: my ($start,$end,$triggertype);
4908: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4909: ($start,$end) = ($1,$2);
4910: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4911: $start = $triggered{$blocker}{'start'};
4912: $end = $triggered{$blocker}{'end'};
4913: $triggertype = $triggered{$blocker}{'type'};
4914: }
4915: if ($start) {
4916: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4917: if ($triggertype) {
4918: push(@{$$setters{$course}{'triggers'}},$triggertype);
4919: } else {
4920: push(@{$$setters{$course}{'triggers'}},0);
4921: }
4922: if ( ($startblock == 0) || ($startblock > $start) ) {
4923: $startblock = $start;
4924: if ($triggertype) {
4925: $triggerblock = $blocker;
1.474 raeburn 4926: }
4927: }
1.1062 raeburn 4928: if ( ($endblock == 0) || ($endblock < $end) ) {
4929: $endblock = $end;
4930: if ($triggertype) {
4931: $triggerblock = $blocker;
4932: }
4933: }
1.474 raeburn 4934: }
4935: }
1.1062 raeburn 4936: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4937: }
4938:
4939: sub parse_block_record {
4940: my ($record) = @_;
4941: my ($setuname,$setudom,$title,$blocks);
4942: if (ref($record) eq 'HASH') {
4943: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4944: $title = &unescape($record->{'event'});
4945: $blocks = $record->{'blocks'};
4946: } else {
4947: my @data = split(/:/,$record,3);
4948: if (scalar(@data) eq 2) {
4949: $title = $data[1];
4950: ($setuname,$setudom) = split(/@/,$data[0]);
4951: } else {
4952: ($setuname,$setudom,$title) = @data;
4953: }
4954: $blocks = { 'com' => 'on' };
4955: }
4956: return ($setuname,$setudom,$title,$blocks);
4957: }
4958:
1.854 kalberla 4959: sub blocking_status {
1.1075.2.73 raeburn 4960: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 4961: my %setters;
1.890 droeschl 4962:
1.1061 raeburn 4963: # check for active blocking
1.1062 raeburn 4964: my ($startblock,$endblock,$triggerblock) =
1.1075.2.73 raeburn 4965: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 4966: my $blocked = 0;
4967: if ($startblock && $endblock) {
4968: $blocked = 1;
4969: }
1.890 droeschl 4970:
1.1061 raeburn 4971: # caller just wants to know whether a block is active
4972: if (!wantarray) { return $blocked; }
4973:
4974: # build a link to a popup window containing the details
4975: my $querystring = "?activity=$activity";
4976: # $uname and $udom decide whose portfolio the user is trying to look at
1.1075.2.97 raeburn 4977: if (($activity eq 'port') || ($activity eq 'passwd')) {
4978: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
4979: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 4980: } elsif ($activity eq 'docs') {
4981: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4982: }
1.1061 raeburn 4983:
4984: my $output .= <<'END_MYBLOCK';
4985: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4986: var options = "width=" + w + ",height=" + h + ",";
4987: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4988: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4989: var newWin = window.open(url, wdwName, options);
4990: newWin.focus();
4991: }
1.890 droeschl 4992: END_MYBLOCK
1.854 kalberla 4993:
1.1061 raeburn 4994: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4995:
1.1061 raeburn 4996: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4997: my $text = &mt('Communication Blocked');
1.1075.2.93 raeburn 4998: my $class = 'LC_comblock';
1.1062 raeburn 4999: if ($activity eq 'docs') {
5000: $text = &mt('Content Access Blocked');
1.1075.2.93 raeburn 5001: $class = '';
1.1063 raeburn 5002: } elsif ($activity eq 'printout') {
5003: $text = &mt('Printing Blocked');
1.1075.2.97 raeburn 5004: } elsif ($activity eq 'passwd') {
5005: $text = &mt('Password Changing Blocked');
1.1062 raeburn 5006: }
1.1061 raeburn 5007: $output .= <<"END_BLOCK";
1.1075.2.93 raeburn 5008: <div class='$class'>
1.869 kalberla 5009: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5010: title='$text'>
5011: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5012: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5013: title='$text'>$text</a>
1.867 kalberla 5014: </div>
5015:
5016: END_BLOCK
1.474 raeburn 5017:
1.1061 raeburn 5018: return ($blocked, $output);
1.854 kalberla 5019: }
1.490 raeburn 5020:
1.60 matthew 5021: ###############################################
5022:
1.682 raeburn 5023: sub check_ip_acc {
1.1075.2.105 raeburn 5024: my ($acc,$clientip)=@_;
1.682 raeburn 5025: &Apache::lonxml::debug("acc is $acc");
5026: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5027: return 1;
5028: }
5029: my $allowed=0;
1.1075.2.111 raeburn 5030: my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
1.682 raeburn 5031:
5032: my $name;
5033: foreach my $pattern (split(',',$acc)) {
5034: $pattern =~ s/^\s*//;
5035: $pattern =~ s/\s*$//;
5036: if ($pattern =~ /\*$/) {
5037: #35.8.*
5038: $pattern=~s/\*//;
5039: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
5040: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5041: #35.8.3.[34-56]
5042: my $low=$2;
5043: my $high=$3;
5044: $pattern=$1;
5045: if ($ip =~ /^\Q$pattern\E/) {
5046: my $last=(split(/\./,$ip))[3];
5047: if ($last <=$high && $last >=$low) { $allowed=1; }
5048: }
5049: } elsif ($pattern =~ /^\*/) {
5050: #*.msu.edu
5051: $pattern=~s/\*//;
5052: if (!defined($name)) {
5053: use Socket;
5054: my $netaddr=inet_aton($ip);
5055: ($name)=gethostbyaddr($netaddr,AF_INET);
5056: }
5057: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
5058: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5059: #127.0.0.1
5060: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
5061: } else {
5062: #some.name.com
5063: if (!defined($name)) {
5064: use Socket;
5065: my $netaddr=inet_aton($ip);
5066: ($name)=gethostbyaddr($netaddr,AF_INET);
5067: }
5068: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
5069: }
5070: if ($allowed) { last; }
5071: }
5072: return $allowed;
5073: }
5074:
5075: ###############################################
5076:
1.60 matthew 5077: =pod
5078:
1.112 bowersj2 5079: =head1 Domain Template Functions
5080:
5081: =over 4
5082:
5083: =item * &determinedomain()
1.60 matthew 5084:
5085: Inputs: $domain (usually will be undef)
5086:
1.63 www 5087: Returns: Determines which domain should be used for designs
1.60 matthew 5088:
5089: =cut
1.54 www 5090:
1.60 matthew 5091: ###############################################
1.63 www 5092: sub determinedomain {
5093: my $domain=shift;
1.531 albertel 5094: if (! $domain) {
1.60 matthew 5095: # Determine domain if we have not been given one
1.893 raeburn 5096: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5097: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5098: if ($env{'request.role.domain'}) {
5099: $domain=$env{'request.role.domain'};
1.60 matthew 5100: }
5101: }
1.63 www 5102: return $domain;
5103: }
5104: ###############################################
1.517 raeburn 5105:
1.518 albertel 5106: sub devalidate_domconfig_cache {
5107: my ($udom)=@_;
5108: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5109: }
5110:
5111: # ---------------------- Get domain configuration for a domain
5112: sub get_domainconf {
5113: my ($udom) = @_;
5114: my $cachetime=1800;
5115: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5116: if (defined($cached)) { return %{$result}; }
5117:
5118: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5119: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5120: my (%designhash,%legacy);
1.518 albertel 5121: if (keys(%domconfig) > 0) {
5122: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5123: if (keys(%{$domconfig{'login'}})) {
5124: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5125: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 5126: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5127: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5128: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5129: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5130: if ($key eq 'loginvia') {
5131: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5132: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5133: $designhash{$udom.'.login.loginvia'} = $server;
5134: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5135: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5136: } else {
5137: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5138: }
1.948 raeburn 5139: }
1.1075.2.87 raeburn 5140: } elsif ($key eq 'headtag') {
5141: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5142: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5143: }
1.946 raeburn 5144: }
1.1075.2.87 raeburn 5145: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5146: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5147: }
1.946 raeburn 5148: }
5149: }
5150: }
5151: } else {
5152: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5153: $designhash{$udom.'.login.'.$key.'_'.$img} =
5154: $domconfig{'login'}{$key}{$img};
5155: }
1.699 raeburn 5156: }
5157: } else {
5158: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5159: }
1.632 raeburn 5160: }
5161: } else {
5162: $legacy{'login'} = 1;
1.518 albertel 5163: }
1.632 raeburn 5164: } else {
5165: $legacy{'login'} = 1;
1.518 albertel 5166: }
5167: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5168: if (keys(%{$domconfig{'rolecolors'}})) {
5169: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5170: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5171: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5172: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5173: }
1.518 albertel 5174: }
5175: }
1.632 raeburn 5176: } else {
5177: $legacy{'rolecolors'} = 1;
1.518 albertel 5178: }
1.632 raeburn 5179: } else {
5180: $legacy{'rolecolors'} = 1;
1.518 albertel 5181: }
1.948 raeburn 5182: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5183: if ($domconfig{'autoenroll'}{'co-owners'}) {
5184: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5185: }
5186: }
1.632 raeburn 5187: if (keys(%legacy) > 0) {
5188: my %legacyhash = &get_legacy_domconf($udom);
5189: foreach my $item (keys(%legacyhash)) {
5190: if ($item =~ /^\Q$udom\E\.login/) {
5191: if ($legacy{'login'}) {
5192: $designhash{$item} = $legacyhash{$item};
5193: }
5194: } else {
5195: if ($legacy{'rolecolors'}) {
5196: $designhash{$item} = $legacyhash{$item};
5197: }
1.518 albertel 5198: }
5199: }
5200: }
1.632 raeburn 5201: } else {
5202: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5203: }
5204: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5205: $cachetime);
5206: return %designhash;
5207: }
5208:
1.632 raeburn 5209: sub get_legacy_domconf {
5210: my ($udom) = @_;
5211: my %legacyhash;
5212: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5213: my $designfile = $designdir.'/'.$udom.'.tab';
5214: if (-e $designfile) {
1.1075.2.128 raeburn 5215: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5216: while (my $line = <$fh>) {
5217: next if ($line =~ /^\#/);
5218: chomp($line);
5219: my ($key,$val)=(split(/\=/,$line));
5220: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5221: }
5222: close($fh);
5223: }
5224: }
1.1026 raeburn 5225: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5226: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5227: }
5228: return %legacyhash;
5229: }
5230:
1.63 www 5231: =pod
5232:
1.112 bowersj2 5233: =item * &domainlogo()
1.63 www 5234:
5235: Inputs: $domain (usually will be undef)
5236:
5237: Returns: A link to a domain logo, if the domain logo exists.
5238: If the domain logo does not exist, a description of the domain.
5239:
5240: =cut
1.112 bowersj2 5241:
1.63 www 5242: ###############################################
5243: sub domainlogo {
1.517 raeburn 5244: my $domain = &determinedomain(shift);
1.518 albertel 5245: my %designhash = &get_domainconf($domain);
1.517 raeburn 5246: # See if there is a logo
5247: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5248: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5249: if ($imgsrc =~ m{^/(adm|res)/}) {
5250: if ($imgsrc =~ m{^/res/}) {
5251: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5252: &Apache::lonnet::repcopy($local_name);
5253: }
5254: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5255: }
5256: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5257: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5258: return &Apache::lonnet::domain($domain,'description');
1.59 www 5259: } else {
1.60 matthew 5260: return '';
1.59 www 5261: }
5262: }
1.63 www 5263: ##############################################
5264:
5265: =pod
5266:
1.112 bowersj2 5267: =item * &designparm()
1.63 www 5268:
5269: Inputs: $which parameter; $domain (usually will be undef)
5270:
5271: Returns: value of designparamter $which
5272:
5273: =cut
1.112 bowersj2 5274:
1.397 albertel 5275:
1.400 albertel 5276: ##############################################
1.397 albertel 5277: sub designparm {
5278: my ($which,$domain)=@_;
5279: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5280: return $env{'environment.color.'.$which};
1.96 www 5281: }
1.63 www 5282: $domain=&determinedomain($domain);
1.1016 raeburn 5283: my %domdesign;
5284: unless ($domain eq 'public') {
5285: %domdesign = &get_domainconf($domain);
5286: }
1.520 raeburn 5287: my $output;
1.517 raeburn 5288: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5289: $output = $domdesign{$domain.'.'.$which};
1.63 www 5290: } else {
1.520 raeburn 5291: $output = $defaultdesign{$which};
5292: }
5293: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5294: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5295: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5296: if ($output =~ m{^/res/}) {
5297: my $local_name = &Apache::lonnet::filelocation('',$output);
5298: &Apache::lonnet::repcopy($local_name);
5299: }
1.520 raeburn 5300: $output = &lonhttpdurl($output);
5301: }
1.63 www 5302: }
1.520 raeburn 5303: return $output;
1.63 www 5304: }
1.59 www 5305:
1.822 bisitz 5306: ##############################################
5307: =pod
5308:
1.832 bisitz 5309: =item * &authorspace()
5310:
1.1028 raeburn 5311: Inputs: $url (usually will be undef).
1.832 bisitz 5312:
1.1075.2.40 raeburn 5313: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5314: directory being viewed (or for which action is being taken).
5315: If $url is provided, and begins /priv/<domain>/<uname>
5316: the path will be that portion of the $context argument.
5317: Otherwise the path will be for the author space of the current
5318: user when the current role is author, or for that of the
5319: co-author/assistant co-author space when the current role
5320: is co-author or assistant co-author.
1.832 bisitz 5321:
5322: =cut
5323:
5324: sub authorspace {
1.1028 raeburn 5325: my ($url) = @_;
5326: if ($url ne '') {
5327: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5328: return $1;
5329: }
5330: }
1.832 bisitz 5331: my $caname = '';
1.1024 www 5332: my $cadom = '';
1.1028 raeburn 5333: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5334: ($cadom,$caname) =
1.832 bisitz 5335: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5336: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5337: $caname = $env{'user.name'};
1.1024 www 5338: $cadom = $env{'user.domain'};
1.832 bisitz 5339: }
1.1028 raeburn 5340: if (($caname ne '') && ($cadom ne '')) {
5341: return "/priv/$cadom/$caname/";
5342: }
5343: return;
1.832 bisitz 5344: }
5345:
5346: ##############################################
5347: =pod
5348:
1.822 bisitz 5349: =item * &head_subbox()
5350:
5351: Inputs: $content (contains HTML code with page functions, etc.)
5352:
5353: Returns: HTML div with $content
5354: To be included in page header
5355:
5356: =cut
5357:
5358: sub head_subbox {
5359: my ($content)=@_;
5360: my $output =
1.993 raeburn 5361: '<div class="LC_head_subbox">'
1.822 bisitz 5362: .$content
5363: .'</div>'
5364: }
5365:
5366: ##############################################
5367: =pod
5368:
5369: =item * &CSTR_pageheader()
5370:
1.1026 raeburn 5371: Input: (optional) filename from which breadcrumb trail is built.
5372: In most cases no input as needed, as $env{'request.filename'}
5373: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5374:
5375: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5376: To be included on Authoring Space pages
1.822 bisitz 5377:
5378: =cut
5379:
5380: sub CSTR_pageheader {
1.1026 raeburn 5381: my ($trailfile) = @_;
5382: if ($trailfile eq '') {
5383: $trailfile = $env{'request.filename'};
5384: }
5385:
5386: # this is for resources; directories have customtitle, and crumbs
5387: # and select recent are created in lonpubdir.pm
5388:
5389: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5390: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5391: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5392: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5393: $formaction =~ s{/+}{/}g;
1.822 bisitz 5394:
5395: my $parentpath = '';
5396: my $lastitem = '';
5397: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5398: $parentpath = $1;
5399: $lastitem = $2;
5400: } else {
5401: $lastitem = $thisdisfn;
5402: }
1.921 bisitz 5403:
5404: my $output =
1.822 bisitz 5405: '<div>'
5406: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5407: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5408: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5409: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5410: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5411:
5412: if ($lastitem) {
5413: $output .=
5414: '<span class="LC_filename">'
5415: .$lastitem
5416: .'</span>';
5417: }
5418: $output .=
5419: '<br />'
1.822 bisitz 5420: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5421: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5422: .'</form>'
5423: .&Apache::lonmenu::constspaceform()
5424: .'</div>';
1.921 bisitz 5425:
5426: return $output;
1.822 bisitz 5427: }
5428:
1.60 matthew 5429: ###############################################
5430: ###############################################
5431:
5432: =pod
5433:
1.112 bowersj2 5434: =back
5435:
1.549 albertel 5436: =head1 HTML Helpers
1.112 bowersj2 5437:
5438: =over 4
5439:
5440: =item * &bodytag()
1.60 matthew 5441:
5442: Returns a uniform header for LON-CAPA web pages.
5443:
5444: Inputs:
5445:
1.112 bowersj2 5446: =over 4
5447:
5448: =item * $title, A title to be displayed on the page.
5449:
5450: =item * $function, the current role (can be undef).
5451:
5452: =item * $addentries, extra parameters for the <body> tag.
5453:
5454: =item * $bodyonly, if defined, only return the <body> tag.
5455:
5456: =item * $domain, if defined, force a given domain.
5457:
5458: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5459: text interface only)
1.60 matthew 5460:
1.814 bisitz 5461: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5462: navigational links
1.317 albertel 5463:
1.338 albertel 5464: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5465:
1.1075.2.12 raeburn 5466: =item * $no_inline_link, if true and in remote mode, don't show the
5467: 'Switch To Inline Menu' link
5468:
1.460 albertel 5469: =item * $args, optional argument valid values are
5470: no_auto_mt_title -> prevents &mt()ing the title arg
1.1075.2.133 raeburn 5471: use_absolute -> for external resource or syllabus, this will
5472: contain https://<hostname> if server uses
5473: https (as per hosts.tab), but request is for http
5474: hostname -> hostname, from $r->hostname().
1.460 albertel 5475:
1.1075.2.15 raeburn 5476: =item * $advtoolsref, optional argument, ref to an array containing
5477: inlineremote items to be added in "Functions" menu below
5478: breadcrumbs.
5479:
1.112 bowersj2 5480: =back
5481:
1.60 matthew 5482: Returns: A uniform header for LON-CAPA web pages.
5483: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5484: If $bodyonly is undef or zero, an html string containing a <body> tag and
5485: other decorations will be returned.
5486:
5487: =cut
5488:
1.54 www 5489: sub bodytag {
1.831 bisitz 5490: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5491: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5492:
1.954 raeburn 5493: my $public;
5494: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5495: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5496: $public = 1;
5497: }
1.460 albertel 5498: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5499: my $httphost = $args->{'use_absolute'};
1.1075.2.133 raeburn 5500: my $hostname = $args->{'hostname'};
1.339 albertel 5501:
1.183 matthew 5502: $function = &get_users_function() if (!$function);
1.339 albertel 5503: my $img = &designparm($function.'.img',$domain);
5504: my $font = &designparm($function.'.font',$domain);
5505: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5506:
1.803 bisitz 5507: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5508: 'bgcolor' => $pgbg,
1.339 albertel 5509: 'text' => $font,
5510: 'alink' => &designparm($function.'.alink',$domain),
5511: 'vlink' => &designparm($function.'.vlink',$domain),
5512: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5513: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5514:
1.63 www 5515: # role and realm
1.1075.2.68 raeburn 5516: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5517: if ($realm) {
5518: $realm = '/'.$realm;
5519: }
1.378 raeburn 5520: if ($role eq 'ca') {
1.479 albertel 5521: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5522: $realm = &plainname($rname,$rdom);
1.378 raeburn 5523: }
1.55 www 5524: # realm
1.258 albertel 5525: if ($env{'request.course.id'}) {
1.378 raeburn 5526: if ($env{'request.role'} !~ /^cr/) {
5527: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1075.2.115 raeburn 5528: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1075.2.121 raeburn 5529: if ($env{'request.role.desc'}) {
5530: $role = $env{'request.role.desc'};
5531: } else {
5532: $role = &mt('Helpdesk[_1]',' '.$2);
5533: }
1.1075.2.115 raeburn 5534: } else {
5535: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5536: }
1.898 raeburn 5537: if ($env{'request.course.sec'}) {
5538: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5539: }
1.359 albertel 5540: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5541: } else {
5542: $role = &Apache::lonnet::plaintext($role);
1.54 www 5543: }
1.433 albertel 5544:
1.359 albertel 5545: if (!$realm) { $realm=' '; }
1.330 albertel 5546:
1.438 albertel 5547: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5548:
1.101 www 5549: # construct main body tag
1.359 albertel 5550: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 5551: &Apache::lontexconvert::init_math_support();
1.252 albertel 5552:
1.1075.2.38 raeburn 5553: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5554:
5555: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5556: return $bodytag;
1.1075.2.38 raeburn 5557: }
1.359 albertel 5558:
1.954 raeburn 5559: if ($public) {
1.433 albertel 5560: undef($role);
5561: }
1.359 albertel 5562:
1.762 bisitz 5563: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5564: #
5565: # Extra info if you are the DC
5566: my $dc_info = '';
5567: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5568: $env{'course.'.$env{'request.course.id'}.
5569: '.domain'}.'/'})) {
5570: my $cid = $env{'request.course.id'};
1.917 raeburn 5571: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5572: $dc_info =~ s/\s+$//;
1.359 albertel 5573: }
5574:
1.1075.2.108 raeburn 5575: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903 droeschl 5576:
1.1075.2.13 raeburn 5577: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5578:
1.1075.2.38 raeburn 5579:
5580:
1.1075.2.21 raeburn 5581: my $funclist;
5582: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5583: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5584: Apache::lonmenu::serverform();
5585: my $forbodytag;
5586: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5587: $forcereg,$args->{'group'},
5588: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5589: $advtoolsref,'','',\$forbodytag);
1.1075.2.21 raeburn 5590: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5591: $funclist = $forbodytag;
5592: }
5593: } else {
1.903 droeschl 5594:
5595: # if ($env{'request.state'} eq 'construct') {
5596: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5597: # }
5598:
1.1075.2.38 raeburn 5599: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5600: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5601:
1.1075.2.38 raeburn 5602: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5603:
1.916 droeschl 5604: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5605: if ($dc_info) {
5606: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5607: }
1.1075.2.38 raeburn 5608: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5609: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5610: return $bodytag;
5611: }
1.894 droeschl 5612:
1.927 raeburn 5613: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5614: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5615: }
1.916 droeschl 5616:
1.1075.2.38 raeburn 5617: $bodytag .= $right;
1.852 droeschl 5618:
1.917 raeburn 5619: if ($dc_info) {
5620: $dc_info = &dc_courseid_toggle($dc_info);
5621: }
5622: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5623:
1.1075.2.61 raeburn 5624: #if directed to not display the secondary menu, don't.
5625: if ($args->{'no_secondary_menu'}) {
5626: return $bodytag;
5627: }
1.903 droeschl 5628: #don't show menus for public users
1.954 raeburn 5629: if (!$public){
1.1075.2.52 raeburn 5630: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5631: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5632: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5633: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5634: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1075.2.133 raeburn 5635: $args->{'bread_crumbs'},'','',$hostname);
1.1075.2.116 raeburn 5636: } elsif ($forcereg) {
1.1075.2.22 raeburn 5637: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.116 raeburn 5638: $args->{'group'},
1.1075.2.133 raeburn 5639: $args->{'hide_buttons',
5640: $hostname});
1.1075.2.15 raeburn 5641: } else {
1.1075.2.21 raeburn 5642: my $forbodytag;
5643: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5644: $forcereg,$args->{'group'},
5645: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5646: $advtoolsref,'',$hostname,
5647: \$forbodytag);
1.1075.2.21 raeburn 5648: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5649: $bodytag .= $forbodytag;
5650: }
1.920 raeburn 5651: }
1.903 droeschl 5652: }else{
5653: # this is to seperate menu from content when there's no secondary
5654: # menu. Especially needed for public accessible ressources.
5655: $bodytag .= '<hr style="clear:both" />';
5656: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5657: }
1.903 droeschl 5658:
1.235 raeburn 5659: return $bodytag;
1.1075.2.12 raeburn 5660: }
5661:
5662: #
5663: # Top frame rendering, Remote is up
5664: #
5665:
5666: my $imgsrc = $img;
5667: if ($img =~ /^\/adm/) {
5668: $imgsrc = &lonhttpdurl($img);
5669: }
5670: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5671:
1.1075.2.60 raeburn 5672: my $help=($no_inline_link?''
5673: :&Apache::loncommon::top_nav_help('Help'));
5674:
1.1075.2.12 raeburn 5675: # Explicit link to get inline menu
5676: my $menu= ($no_inline_link?''
5677: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5678:
5679: if ($dc_info) {
5680: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5681: }
5682:
1.1075.2.38 raeburn 5683: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5684: unless ($public) {
5685: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5686: undef,'LC_menubuttons_link');
5687: }
5688:
1.1075.2.12 raeburn 5689: unless ($env{'form.inhibitmenu'}) {
5690: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5691: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5692: <li>$help</li>
1.1075.2.12 raeburn 5693: <li>$menu</li>
5694: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5695: }
1.1075.2.13 raeburn 5696: if ($env{'request.state'} eq 'construct') {
5697: if (!$public){
5698: if ($env{'request.state'} eq 'construct') {
5699: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5700: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5701: &Apache::lonhtmlcommon::scripttag('','end').
5702: &Apache::lonmenu::innerregister($forcereg,
5703: $args->{'bread_crumbs'});
5704: }
5705: }
5706: }
1.1075.2.21 raeburn 5707: return $bodytag."\n".$funclist;
1.182 matthew 5708: }
5709:
1.917 raeburn 5710: sub dc_courseid_toggle {
5711: my ($dc_info) = @_;
1.980 raeburn 5712: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5713: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5714: &mt('(More ...)').'</a></span>'.
5715: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5716: }
5717:
1.330 albertel 5718: sub make_attr_string {
5719: my ($register,$attr_ref) = @_;
5720:
5721: if ($attr_ref && !ref($attr_ref)) {
5722: die("addentries Must be a hash ref ".
5723: join(':',caller(1))." ".
5724: join(':',caller(0))." ");
5725: }
5726:
5727: if ($register) {
1.339 albertel 5728: my ($on_load,$on_unload);
5729: foreach my $key (keys(%{$attr_ref})) {
5730: if (lc($key) eq 'onload') {
5731: $on_load.=$attr_ref->{$key}.';';
5732: delete($attr_ref->{$key});
5733:
5734: } elsif (lc($key) eq 'onunload') {
5735: $on_unload.=$attr_ref->{$key}.';';
5736: delete($attr_ref->{$key});
5737: }
5738: }
1.1075.2.12 raeburn 5739: if ($env{'environment.remote'} eq 'on') {
5740: $attr_ref->{'onload'} =
5741: &Apache::lonmenu::loadevents(). $on_load;
5742: $attr_ref->{'onunload'}=
5743: &Apache::lonmenu::unloadevents().$on_unload;
5744: } else {
5745: $attr_ref->{'onload'} = $on_load;
5746: $attr_ref->{'onunload'}= $on_unload;
5747: }
1.330 albertel 5748: }
1.339 albertel 5749:
1.330 albertel 5750: my $attr_string;
1.1075.2.56 raeburn 5751: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5752: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5753: }
5754: return $attr_string;
5755: }
5756:
5757:
1.182 matthew 5758: ###############################################
1.251 albertel 5759: ###############################################
5760:
5761: =pod
5762:
5763: =item * &endbodytag()
5764:
5765: Returns a uniform footer for LON-CAPA web pages.
5766:
1.635 raeburn 5767: Inputs: 1 - optional reference to an args hash
5768: If in the hash, key for noredirectlink has a value which evaluates to true,
5769: a 'Continue' link is not displayed if the page contains an
5770: internal redirect in the <head></head> section,
5771: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5772:
5773: =cut
5774:
5775: sub endbodytag {
1.635 raeburn 5776: my ($args) = @_;
1.1075.2.6 raeburn 5777: my $endbodytag;
5778: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5779: $endbodytag='</body>';
5780: }
1.315 albertel 5781: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5782: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5783: $endbodytag=
5784: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5785: &mt('Continue').'</a>'.
5786: $endbodytag;
5787: }
1.315 albertel 5788: }
1.251 albertel 5789: return $endbodytag;
5790: }
5791:
1.352 albertel 5792: =pod
5793:
5794: =item * &standard_css()
5795:
5796: Returns a style sheet
5797:
5798: Inputs: (all optional)
5799: domain -> force to color decorate a page for a specific
5800: domain
5801: function -> force usage of a specific rolish color scheme
5802: bgcolor -> override the default page bgcolor
5803:
5804: =cut
5805:
1.343 albertel 5806: sub standard_css {
1.345 albertel 5807: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5808: $function = &get_users_function() if (!$function);
5809: my $img = &designparm($function.'.img', $domain);
5810: my $tabbg = &designparm($function.'.tabbg', $domain);
5811: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5812: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5813: #second colour for later usage
1.345 albertel 5814: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5815: my $pgbg_or_bgcolor =
5816: $bgcolor ||
1.352 albertel 5817: &designparm($function.'.pgbg', $domain);
1.382 albertel 5818: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5819: my $alink = &designparm($function.'.alink', $domain);
5820: my $vlink = &designparm($function.'.vlink', $domain);
5821: my $link = &designparm($function.'.link', $domain);
5822:
1.602 albertel 5823: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5824: my $mono = 'monospace';
1.850 bisitz 5825: my $data_table_head = $sidebg;
5826: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5827: my $data_table_dark = '#E0E0E0';
1.470 banghart 5828: my $data_table_darker = '#CCCCCC';
1.349 albertel 5829: my $data_table_highlight = '#FFFF00';
1.352 albertel 5830: my $mail_new = '#FFBB77';
5831: my $mail_new_hover = '#DD9955';
5832: my $mail_read = '#BBBB77';
5833: my $mail_read_hover = '#999944';
5834: my $mail_replied = '#AAAA88';
5835: my $mail_replied_hover = '#888855';
5836: my $mail_other = '#99BBBB';
5837: my $mail_other_hover = '#669999';
1.391 albertel 5838: my $table_header = '#DDDDDD';
1.489 raeburn 5839: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5840: my $lg_border_color = '#C8C8C8';
1.952 onken 5841: my $button_hover = '#BF2317';
1.392 albertel 5842:
1.608 albertel 5843: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5844: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5845: : '0 3px 0 4px';
1.448 albertel 5846:
1.523 albertel 5847:
1.343 albertel 5848: return <<END;
1.947 droeschl 5849:
5850: /* needed for iframe to allow 100% height in FF */
5851: body, html {
5852: margin: 0;
5853: padding: 0 0.5%;
5854: height: 99%; /* to avoid scrollbars */
5855: }
5856:
1.795 www 5857: body {
1.911 bisitz 5858: font-family: $sans;
5859: line-height:130%;
5860: font-size:0.83em;
5861: color:$font;
1.795 www 5862: }
5863:
1.959 onken 5864: a:focus,
5865: a:focus img {
1.795 www 5866: color: red;
5867: }
1.698 harmsja 5868:
1.911 bisitz 5869: form, .inline {
5870: display: inline;
1.795 www 5871: }
1.721 harmsja 5872:
1.795 www 5873: .LC_right {
1.911 bisitz 5874: text-align:right;
1.795 www 5875: }
5876:
5877: .LC_middle {
1.911 bisitz 5878: vertical-align:middle;
1.795 www 5879: }
1.721 harmsja 5880:
1.1075.2.38 raeburn 5881: .LC_floatleft {
5882: float: left;
5883: }
5884:
5885: .LC_floatright {
5886: float: right;
5887: }
5888:
1.911 bisitz 5889: .LC_400Box {
5890: width:400px;
5891: }
1.721 harmsja 5892:
1.947 droeschl 5893: .LC_iframecontainer {
5894: width: 98%;
5895: margin: 0;
5896: position: fixed;
5897: top: 8.5em;
5898: bottom: 0;
5899: }
5900:
5901: .LC_iframecontainer iframe{
5902: border: none;
5903: width: 100%;
5904: height: 100%;
5905: }
5906:
1.778 bisitz 5907: .LC_filename {
5908: font-family: $mono;
5909: white-space:pre;
1.921 bisitz 5910: font-size: 120%;
1.778 bisitz 5911: }
5912:
5913: .LC_fileicon {
5914: border: none;
5915: height: 1.3em;
5916: vertical-align: text-bottom;
5917: margin-right: 0.3em;
5918: text-decoration:none;
5919: }
5920:
1.1008 www 5921: .LC_setting {
5922: text-decoration:underline;
5923: }
5924:
1.350 albertel 5925: .LC_error {
5926: color: red;
5927: }
1.795 www 5928:
1.1075.2.15 raeburn 5929: .LC_warning {
5930: color: darkorange;
5931: }
5932:
1.457 albertel 5933: .LC_diff_removed {
1.733 bisitz 5934: color: red;
1.394 albertel 5935: }
1.532 albertel 5936:
5937: .LC_info,
1.457 albertel 5938: .LC_success,
5939: .LC_diff_added {
1.350 albertel 5940: color: green;
5941: }
1.795 www 5942:
1.802 bisitz 5943: div.LC_confirm_box {
5944: background-color: #FAFAFA;
5945: border: 1px solid $lg_border_color;
5946: margin-right: 0;
5947: padding: 5px;
5948: }
5949:
5950: div.LC_confirm_box .LC_error img,
5951: div.LC_confirm_box .LC_success img {
5952: vertical-align: middle;
5953: }
5954:
1.1075.2.108 raeburn 5955: .LC_maxwidth {
5956: max-width: 100%;
5957: height: auto;
5958: }
5959:
5960: .LC_textsize_mobile {
5961: \@media only screen and (max-device-width: 480px) {
5962: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
5963: }
5964: }
5965:
1.440 albertel 5966: .LC_icon {
1.771 droeschl 5967: border: none;
1.790 droeschl 5968: vertical-align: middle;
1.771 droeschl 5969: }
5970:
1.543 albertel 5971: .LC_docs_spacer {
5972: width: 25px;
5973: height: 1px;
1.771 droeschl 5974: border: none;
1.543 albertel 5975: }
1.346 albertel 5976:
1.532 albertel 5977: .LC_internal_info {
1.735 bisitz 5978: color: #999999;
1.532 albertel 5979: }
5980:
1.794 www 5981: .LC_discussion {
1.1050 www 5982: background: $data_table_dark;
1.911 bisitz 5983: border: 1px solid black;
5984: margin: 2px;
1.794 www 5985: }
5986:
5987: .LC_disc_action_left {
1.1050 www 5988: background: $sidebg;
1.911 bisitz 5989: text-align: left;
1.1050 www 5990: padding: 4px;
5991: margin: 2px;
1.794 www 5992: }
5993:
5994: .LC_disc_action_right {
1.1050 www 5995: background: $sidebg;
1.911 bisitz 5996: text-align: right;
1.1050 www 5997: padding: 4px;
5998: margin: 2px;
1.794 www 5999: }
6000:
6001: .LC_disc_new_item {
1.911 bisitz 6002: background: white;
6003: border: 2px solid red;
1.1050 www 6004: margin: 4px;
6005: padding: 4px;
1.794 www 6006: }
6007:
6008: .LC_disc_old_item {
1.911 bisitz 6009: background: white;
1.1050 www 6010: margin: 4px;
6011: padding: 4px;
1.794 www 6012: }
6013:
1.458 albertel 6014: table.LC_pastsubmission {
6015: border: 1px solid black;
6016: margin: 2px;
6017: }
6018:
1.924 bisitz 6019: table#LC_menubuttons {
1.345 albertel 6020: width: 100%;
6021: background: $pgbg;
1.392 albertel 6022: border: 2px;
1.402 albertel 6023: border-collapse: separate;
1.803 bisitz 6024: padding: 0;
1.345 albertel 6025: }
1.392 albertel 6026:
1.801 tempelho 6027: table#LC_title_bar a {
6028: color: $fontmenu;
6029: }
1.836 bisitz 6030:
1.807 droeschl 6031: table#LC_title_bar {
1.819 tempelho 6032: clear: both;
1.836 bisitz 6033: display: none;
1.807 droeschl 6034: }
6035:
1.795 www 6036: table#LC_title_bar,
1.933 droeschl 6037: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6038: table#LC_title_bar.LC_with_remote {
1.359 albertel 6039: width: 100%;
1.392 albertel 6040: border-color: $pgbg;
6041: border-style: solid;
6042: border-width: $border;
1.379 albertel 6043: background: $pgbg;
1.801 tempelho 6044: color: $fontmenu;
1.392 albertel 6045: border-collapse: collapse;
1.803 bisitz 6046: padding: 0;
1.819 tempelho 6047: margin: 0;
1.359 albertel 6048: }
1.795 www 6049:
1.933 droeschl 6050: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6051: margin: 0;
6052: padding: 0;
1.933 droeschl 6053: position: relative;
6054: list-style: none;
1.913 droeschl 6055: }
1.933 droeschl 6056: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6057: display: inline;
6058: }
1.933 droeschl 6059:
6060: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6061: padding: 0;
1.933 droeschl 6062: margin: 0;
6063: float: left;
1.913 droeschl 6064: }
1.933 droeschl 6065: .LC_breadcrumb_tools_tools {
6066: padding: 0;
6067: margin: 0;
1.913 droeschl 6068: float: right;
6069: }
6070:
1.359 albertel 6071: table#LC_title_bar td {
6072: background: $tabbg;
6073: }
1.795 www 6074:
1.911 bisitz 6075: table#LC_menubuttons img {
1.803 bisitz 6076: border: none;
1.346 albertel 6077: }
1.795 www 6078:
1.842 droeschl 6079: .LC_breadcrumbs_component {
1.911 bisitz 6080: float: right;
6081: margin: 0 1em;
1.357 albertel 6082: }
1.842 droeschl 6083: .LC_breadcrumbs_component img {
1.911 bisitz 6084: vertical-align: middle;
1.777 tempelho 6085: }
1.795 www 6086:
1.1075.2.108 raeburn 6087: .LC_breadcrumbs_hoverable {
6088: background: $sidebg;
6089: }
6090:
1.383 albertel 6091: td.LC_table_cell_checkbox {
6092: text-align: center;
6093: }
1.795 www 6094:
6095: .LC_fontsize_small {
1.911 bisitz 6096: font-size: 70%;
1.705 tempelho 6097: }
6098:
1.844 bisitz 6099: #LC_breadcrumbs {
1.911 bisitz 6100: clear:both;
6101: background: $sidebg;
6102: border-bottom: 1px solid $lg_border_color;
6103: line-height: 2.5em;
1.933 droeschl 6104: overflow: hidden;
1.911 bisitz 6105: margin: 0;
6106: padding: 0;
1.995 raeburn 6107: text-align: left;
1.819 tempelho 6108: }
1.862 bisitz 6109:
1.1075.2.16 raeburn 6110: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6111: clear:both;
6112: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6113: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6114: margin: 0 0 10px 0;
1.966 bisitz 6115: padding: 3px;
1.995 raeburn 6116: text-align: left;
1.822 bisitz 6117: }
6118:
1.795 www 6119: .LC_fontsize_medium {
1.911 bisitz 6120: font-size: 85%;
1.705 tempelho 6121: }
6122:
1.795 www 6123: .LC_fontsize_large {
1.911 bisitz 6124: font-size: 120%;
1.705 tempelho 6125: }
6126:
1.346 albertel 6127: .LC_menubuttons_inline_text {
6128: color: $font;
1.698 harmsja 6129: font-size: 90%;
1.701 harmsja 6130: padding-left:3px;
1.346 albertel 6131: }
6132:
1.934 droeschl 6133: .LC_menubuttons_inline_text img{
6134: vertical-align: middle;
6135: }
6136:
1.1051 www 6137: li.LC_menubuttons_inline_text img {
1.951 onken 6138: cursor:pointer;
1.1002 droeschl 6139: text-decoration: none;
1.951 onken 6140: }
6141:
1.526 www 6142: .LC_menubuttons_link {
6143: text-decoration: none;
6144: }
1.795 www 6145:
1.522 albertel 6146: .LC_menubuttons_category {
1.521 www 6147: color: $font;
1.526 www 6148: background: $pgbg;
1.521 www 6149: font-size: larger;
6150: font-weight: bold;
6151: }
6152:
1.346 albertel 6153: td.LC_menubuttons_text {
1.911 bisitz 6154: color: $font;
1.346 albertel 6155: }
1.706 harmsja 6156:
1.346 albertel 6157: .LC_current_location {
6158: background: $tabbg;
6159: }
1.795 www 6160:
1.1075.2.134 raeburn 6161: td.LC_zero_height {
6162: line-height: 0;
6163: cellpadding: 0;
6164: }
6165:
1.938 bisitz 6166: table.LC_data_table {
1.347 albertel 6167: border: 1px solid #000000;
1.402 albertel 6168: border-collapse: separate;
1.426 albertel 6169: border-spacing: 1px;
1.610 albertel 6170: background: $pgbg;
1.347 albertel 6171: }
1.795 www 6172:
1.422 albertel 6173: .LC_data_table_dense {
6174: font-size: small;
6175: }
1.795 www 6176:
1.507 raeburn 6177: table.LC_nested_outer {
6178: border: 1px solid #000000;
1.589 raeburn 6179: border-collapse: collapse;
1.803 bisitz 6180: border-spacing: 0;
1.507 raeburn 6181: width: 100%;
6182: }
1.795 www 6183:
1.879 raeburn 6184: table.LC_innerpickbox,
1.507 raeburn 6185: table.LC_nested {
1.803 bisitz 6186: border: none;
1.589 raeburn 6187: border-collapse: collapse;
1.803 bisitz 6188: border-spacing: 0;
1.507 raeburn 6189: width: 100%;
6190: }
1.795 www 6191:
1.911 bisitz 6192: table.LC_data_table tr th,
6193: table.LC_calendar tr th,
1.879 raeburn 6194: table.LC_prior_tries tr th,
6195: table.LC_innerpickbox tr th {
1.349 albertel 6196: font-weight: bold;
6197: background-color: $data_table_head;
1.801 tempelho 6198: color:$fontmenu;
1.701 harmsja 6199: font-size:90%;
1.347 albertel 6200: }
1.795 www 6201:
1.879 raeburn 6202: table.LC_innerpickbox tr th,
6203: table.LC_innerpickbox tr td {
6204: vertical-align: top;
6205: }
6206:
1.711 raeburn 6207: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6208: background-color: #CCCCCC;
1.711 raeburn 6209: font-weight: bold;
6210: text-align: left;
6211: }
1.795 www 6212:
1.912 bisitz 6213: table.LC_data_table tr.LC_odd_row > td {
6214: background-color: $data_table_light;
6215: padding: 2px;
6216: vertical-align: top;
6217: }
6218:
1.809 bisitz 6219: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6220: background-color: $data_table_light;
1.912 bisitz 6221: vertical-align: top;
6222: }
6223:
6224: table.LC_data_table tr.LC_even_row > td {
6225: background-color: $data_table_dark;
1.425 albertel 6226: padding: 2px;
1.900 bisitz 6227: vertical-align: top;
1.347 albertel 6228: }
1.795 www 6229:
1.809 bisitz 6230: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6231: background-color: $data_table_dark;
1.900 bisitz 6232: vertical-align: top;
1.347 albertel 6233: }
1.795 www 6234:
1.425 albertel 6235: table.LC_data_table tr.LC_data_table_highlight td {
6236: background-color: $data_table_darker;
6237: }
1.795 www 6238:
1.639 raeburn 6239: table.LC_data_table tr td.LC_leftcol_header {
6240: background-color: $data_table_head;
6241: font-weight: bold;
6242: }
1.795 www 6243:
1.451 albertel 6244: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6245: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6246: font-weight: bold;
6247: font-style: italic;
6248: text-align: center;
6249: padding: 8px;
1.347 albertel 6250: }
1.795 www 6251:
1.1075.2.30 raeburn 6252: table.LC_data_table tr.LC_empty_row td,
6253: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6254: background-color: $sidebg;
6255: }
6256:
6257: table.LC_nested tr.LC_empty_row td {
6258: background-color: #FFFFFF;
6259: }
6260:
1.890 droeschl 6261: table.LC_caption {
6262: }
6263:
1.507 raeburn 6264: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6265: padding: 4ex
6266: }
1.795 www 6267:
1.507 raeburn 6268: table.LC_nested_outer tr th {
6269: font-weight: bold;
1.801 tempelho 6270: color:$fontmenu;
1.507 raeburn 6271: background-color: $data_table_head;
1.701 harmsja 6272: font-size: small;
1.507 raeburn 6273: border-bottom: 1px solid #000000;
6274: }
1.795 www 6275:
1.507 raeburn 6276: table.LC_nested_outer tr td.LC_subheader {
6277: background-color: $data_table_head;
6278: font-weight: bold;
6279: font-size: small;
6280: border-bottom: 1px solid #000000;
6281: text-align: right;
1.451 albertel 6282: }
1.795 www 6283:
1.507 raeburn 6284: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6285: background-color: #CCCCCC;
1.451 albertel 6286: font-weight: bold;
6287: font-size: small;
1.507 raeburn 6288: text-align: center;
6289: }
1.795 www 6290:
1.589 raeburn 6291: table.LC_nested tr.LC_info_row td.LC_left_item,
6292: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6293: text-align: left;
1.451 albertel 6294: }
1.795 www 6295:
1.507 raeburn 6296: table.LC_nested td {
1.735 bisitz 6297: background-color: #FFFFFF;
1.451 albertel 6298: font-size: small;
1.507 raeburn 6299: }
1.795 www 6300:
1.507 raeburn 6301: table.LC_nested_outer tr th.LC_right_item,
6302: table.LC_nested tr.LC_info_row td.LC_right_item,
6303: table.LC_nested tr.LC_odd_row td.LC_right_item,
6304: table.LC_nested tr td.LC_right_item {
1.451 albertel 6305: text-align: right;
6306: }
6307:
1.507 raeburn 6308: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6309: background-color: #EEEEEE;
1.451 albertel 6310: }
6311:
1.473 raeburn 6312: table.LC_createuser {
6313: }
6314:
6315: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6316: font-size: small;
1.473 raeburn 6317: }
6318:
6319: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6320: background-color: #CCCCCC;
1.473 raeburn 6321: font-weight: bold;
6322: text-align: center;
6323: }
6324:
1.349 albertel 6325: table.LC_calendar {
6326: border: 1px solid #000000;
6327: border-collapse: collapse;
1.917 raeburn 6328: width: 98%;
1.349 albertel 6329: }
1.795 www 6330:
1.349 albertel 6331: table.LC_calendar_pickdate {
6332: font-size: xx-small;
6333: }
1.795 www 6334:
1.349 albertel 6335: table.LC_calendar tr td {
6336: border: 1px solid #000000;
6337: vertical-align: top;
1.917 raeburn 6338: width: 14%;
1.349 albertel 6339: }
1.795 www 6340:
1.349 albertel 6341: table.LC_calendar tr td.LC_calendar_day_empty {
6342: background-color: $data_table_dark;
6343: }
1.795 www 6344:
1.779 bisitz 6345: table.LC_calendar tr td.LC_calendar_day_current {
6346: background-color: $data_table_highlight;
1.777 tempelho 6347: }
1.795 www 6348:
1.938 bisitz 6349: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6350: background-color: $mail_new;
6351: }
1.795 www 6352:
1.938 bisitz 6353: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6354: background-color: $mail_new_hover;
6355: }
1.795 www 6356:
1.938 bisitz 6357: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6358: background-color: $mail_read;
6359: }
1.795 www 6360:
1.938 bisitz 6361: /*
6362: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6363: background-color: $mail_read_hover;
6364: }
1.938 bisitz 6365: */
1.795 www 6366:
1.938 bisitz 6367: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6368: background-color: $mail_replied;
6369: }
1.795 www 6370:
1.938 bisitz 6371: /*
6372: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6373: background-color: $mail_replied_hover;
6374: }
1.938 bisitz 6375: */
1.795 www 6376:
1.938 bisitz 6377: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6378: background-color: $mail_other;
6379: }
1.795 www 6380:
1.938 bisitz 6381: /*
6382: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6383: background-color: $mail_other_hover;
6384: }
1.938 bisitz 6385: */
1.494 raeburn 6386:
1.777 tempelho 6387: table.LC_data_table tr > td.LC_browser_file,
6388: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6389: background: #AAEE77;
1.389 albertel 6390: }
1.795 www 6391:
1.777 tempelho 6392: table.LC_data_table tr > td.LC_browser_file_locked,
6393: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6394: background: #FFAA99;
1.387 albertel 6395: }
1.795 www 6396:
1.777 tempelho 6397: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6398: background: #888888;
1.779 bisitz 6399: }
1.795 www 6400:
1.777 tempelho 6401: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6402: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6403: background: #F8F866;
1.777 tempelho 6404: }
1.795 www 6405:
1.696 bisitz 6406: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6407: background: #E0E8FF;
1.387 albertel 6408: }
1.696 bisitz 6409:
1.707 bisitz 6410: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6411: /* background: #77FF77; */
1.707 bisitz 6412: }
1.795 www 6413:
1.707 bisitz 6414: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6415: border-right: 8px solid #FFFF77;
1.707 bisitz 6416: }
1.795 www 6417:
1.707 bisitz 6418: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6419: border-right: 8px solid #FFAA77;
1.707 bisitz 6420: }
1.795 www 6421:
1.707 bisitz 6422: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6423: border-right: 8px solid #FF7777;
1.707 bisitz 6424: }
1.795 www 6425:
1.707 bisitz 6426: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6427: border-right: 8px solid #AAFF77;
1.707 bisitz 6428: }
1.795 www 6429:
1.707 bisitz 6430: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6431: border-right: 8px solid #11CC55;
1.707 bisitz 6432: }
6433:
1.388 albertel 6434: span.LC_current_location {
1.701 harmsja 6435: font-size:larger;
1.388 albertel 6436: background: $pgbg;
6437: }
1.387 albertel 6438:
1.1029 www 6439: span.LC_current_nav_location {
6440: font-weight:bold;
6441: background: $sidebg;
6442: }
6443:
1.395 albertel 6444: span.LC_parm_menu_item {
6445: font-size: larger;
6446: }
1.795 www 6447:
1.395 albertel 6448: span.LC_parm_scope_all {
6449: color: red;
6450: }
1.795 www 6451:
1.395 albertel 6452: span.LC_parm_scope_folder {
6453: color: green;
6454: }
1.795 www 6455:
1.395 albertel 6456: span.LC_parm_scope_resource {
6457: color: orange;
6458: }
1.795 www 6459:
1.395 albertel 6460: span.LC_parm_part {
6461: color: blue;
6462: }
1.795 www 6463:
1.911 bisitz 6464: span.LC_parm_folder,
6465: span.LC_parm_symb {
1.395 albertel 6466: font-size: x-small;
6467: font-family: $mono;
6468: color: #AAAAAA;
6469: }
6470:
1.977 bisitz 6471: ul.LC_parm_parmlist li {
6472: display: inline-block;
6473: padding: 0.3em 0.8em;
6474: vertical-align: top;
6475: width: 150px;
6476: border-top:1px solid $lg_border_color;
6477: }
6478:
1.795 www 6479: td.LC_parm_overview_level_menu,
6480: td.LC_parm_overview_map_menu,
6481: td.LC_parm_overview_parm_selectors,
6482: td.LC_parm_overview_restrictions {
1.396 albertel 6483: border: 1px solid black;
6484: border-collapse: collapse;
6485: }
1.795 www 6486:
1.396 albertel 6487: table.LC_parm_overview_restrictions td {
6488: border-width: 1px 4px 1px 4px;
6489: border-style: solid;
6490: border-color: $pgbg;
6491: text-align: center;
6492: }
1.795 www 6493:
1.396 albertel 6494: table.LC_parm_overview_restrictions th {
6495: background: $tabbg;
6496: border-width: 1px 4px 1px 4px;
6497: border-style: solid;
6498: border-color: $pgbg;
6499: }
1.795 www 6500:
1.398 albertel 6501: table#LC_helpmenu {
1.803 bisitz 6502: border: none;
1.398 albertel 6503: height: 55px;
1.803 bisitz 6504: border-spacing: 0;
1.398 albertel 6505: }
6506:
6507: table#LC_helpmenu fieldset legend {
6508: font-size: larger;
6509: }
1.795 www 6510:
1.397 albertel 6511: table#LC_helpmenu_links {
6512: width: 100%;
6513: border: 1px solid black;
6514: background: $pgbg;
1.803 bisitz 6515: padding: 0;
1.397 albertel 6516: border-spacing: 1px;
6517: }
1.795 www 6518:
1.397 albertel 6519: table#LC_helpmenu_links tr td {
6520: padding: 1px;
6521: background: $tabbg;
1.399 albertel 6522: text-align: center;
6523: font-weight: bold;
1.397 albertel 6524: }
1.396 albertel 6525:
1.795 www 6526: table#LC_helpmenu_links a:link,
6527: table#LC_helpmenu_links a:visited,
1.397 albertel 6528: table#LC_helpmenu_links a:active {
6529: text-decoration: none;
6530: color: $font;
6531: }
1.795 www 6532:
1.397 albertel 6533: table#LC_helpmenu_links a:hover {
6534: text-decoration: underline;
6535: color: $vlink;
6536: }
1.396 albertel 6537:
1.417 albertel 6538: .LC_chrt_popup_exists {
6539: border: 1px solid #339933;
6540: margin: -1px;
6541: }
1.795 www 6542:
1.417 albertel 6543: .LC_chrt_popup_up {
6544: border: 1px solid yellow;
6545: margin: -1px;
6546: }
1.795 www 6547:
1.417 albertel 6548: .LC_chrt_popup {
6549: border: 1px solid #8888FF;
6550: background: #CCCCFF;
6551: }
1.795 www 6552:
1.421 albertel 6553: table.LC_pick_box {
6554: border-collapse: separate;
6555: background: white;
6556: border: 1px solid black;
6557: border-spacing: 1px;
6558: }
1.795 www 6559:
1.421 albertel 6560: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6561: background: $sidebg;
1.421 albertel 6562: font-weight: bold;
1.900 bisitz 6563: text-align: left;
1.740 bisitz 6564: vertical-align: top;
1.421 albertel 6565: width: 184px;
6566: padding: 8px;
6567: }
1.795 www 6568:
1.579 raeburn 6569: table.LC_pick_box td.LC_pick_box_value {
6570: text-align: left;
6571: padding: 8px;
6572: }
1.795 www 6573:
1.579 raeburn 6574: table.LC_pick_box td.LC_pick_box_select {
6575: text-align: left;
6576: padding: 8px;
6577: }
1.795 www 6578:
1.424 albertel 6579: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6580: padding: 0;
1.421 albertel 6581: height: 1px;
6582: background: black;
6583: }
1.795 www 6584:
1.421 albertel 6585: table.LC_pick_box td.LC_pick_box_submit {
6586: text-align: right;
6587: }
1.795 www 6588:
1.579 raeburn 6589: table.LC_pick_box td.LC_evenrow_value {
6590: text-align: left;
6591: padding: 8px;
6592: background-color: $data_table_light;
6593: }
1.795 www 6594:
1.579 raeburn 6595: table.LC_pick_box td.LC_oddrow_value {
6596: text-align: left;
6597: padding: 8px;
6598: background-color: $data_table_light;
6599: }
1.795 www 6600:
1.579 raeburn 6601: span.LC_helpform_receipt_cat {
6602: font-weight: bold;
6603: }
1.795 www 6604:
1.424 albertel 6605: table.LC_group_priv_box {
6606: background: white;
6607: border: 1px solid black;
6608: border-spacing: 1px;
6609: }
1.795 www 6610:
1.424 albertel 6611: table.LC_group_priv_box td.LC_pick_box_title {
6612: background: $tabbg;
6613: font-weight: bold;
6614: text-align: right;
6615: width: 184px;
6616: }
1.795 www 6617:
1.424 albertel 6618: table.LC_group_priv_box td.LC_groups_fixed {
6619: background: $data_table_light;
6620: text-align: center;
6621: }
1.795 www 6622:
1.424 albertel 6623: table.LC_group_priv_box td.LC_groups_optional {
6624: background: $data_table_dark;
6625: text-align: center;
6626: }
1.795 www 6627:
1.424 albertel 6628: table.LC_group_priv_box td.LC_groups_functionality {
6629: background: $data_table_darker;
6630: text-align: center;
6631: font-weight: bold;
6632: }
1.795 www 6633:
1.424 albertel 6634: table.LC_group_priv td {
6635: text-align: left;
1.803 bisitz 6636: padding: 0;
1.424 albertel 6637: }
6638:
6639: .LC_navbuttons {
6640: margin: 2ex 0ex 2ex 0ex;
6641: }
1.795 www 6642:
1.423 albertel 6643: .LC_topic_bar {
6644: font-weight: bold;
6645: background: $tabbg;
1.918 wenzelju 6646: margin: 1em 0em 1em 2em;
1.805 bisitz 6647: padding: 3px;
1.918 wenzelju 6648: font-size: 1.2em;
1.423 albertel 6649: }
1.795 www 6650:
1.423 albertel 6651: .LC_topic_bar span {
1.918 wenzelju 6652: left: 0.5em;
6653: position: absolute;
1.423 albertel 6654: vertical-align: middle;
1.918 wenzelju 6655: font-size: 1.2em;
1.423 albertel 6656: }
1.795 www 6657:
1.423 albertel 6658: table.LC_course_group_status {
6659: margin: 20px;
6660: }
1.795 www 6661:
1.423 albertel 6662: table.LC_status_selector td {
6663: vertical-align: top;
6664: text-align: center;
1.424 albertel 6665: padding: 4px;
6666: }
1.795 www 6667:
1.599 albertel 6668: div.LC_feedback_link {
1.616 albertel 6669: clear: both;
1.829 kalberla 6670: background: $sidebg;
1.779 bisitz 6671: width: 100%;
1.829 kalberla 6672: padding-bottom: 10px;
6673: border: 1px $tabbg solid;
1.833 kalberla 6674: height: 22px;
6675: line-height: 22px;
6676: padding-top: 5px;
6677: }
6678:
6679: div.LC_feedback_link img {
6680: height: 22px;
1.867 kalberla 6681: vertical-align:middle;
1.829 kalberla 6682: }
6683:
1.911 bisitz 6684: div.LC_feedback_link a {
1.829 kalberla 6685: text-decoration: none;
1.489 raeburn 6686: }
1.795 www 6687:
1.867 kalberla 6688: div.LC_comblock {
1.911 bisitz 6689: display:inline;
1.867 kalberla 6690: color:$font;
6691: font-size:90%;
6692: }
6693:
6694: div.LC_feedback_link div.LC_comblock {
6695: padding-left:5px;
6696: }
6697:
6698: div.LC_feedback_link div.LC_comblock a {
6699: color:$font;
6700: }
6701:
1.489 raeburn 6702: span.LC_feedback_link {
1.858 bisitz 6703: /* background: $feedback_link_bg; */
1.599 albertel 6704: font-size: larger;
6705: }
1.795 www 6706:
1.599 albertel 6707: span.LC_message_link {
1.858 bisitz 6708: /* background: $feedback_link_bg; */
1.599 albertel 6709: font-size: larger;
6710: position: absolute;
6711: right: 1em;
1.489 raeburn 6712: }
1.421 albertel 6713:
1.515 albertel 6714: table.LC_prior_tries {
1.524 albertel 6715: border: 1px solid #000000;
6716: border-collapse: separate;
6717: border-spacing: 1px;
1.515 albertel 6718: }
1.523 albertel 6719:
1.515 albertel 6720: table.LC_prior_tries td {
1.524 albertel 6721: padding: 2px;
1.515 albertel 6722: }
1.523 albertel 6723:
6724: .LC_answer_correct {
1.795 www 6725: background: lightgreen;
6726: color: darkgreen;
6727: padding: 6px;
1.523 albertel 6728: }
1.795 www 6729:
1.523 albertel 6730: .LC_answer_charged_try {
1.797 www 6731: background: #FFAAAA;
1.795 www 6732: color: darkred;
6733: padding: 6px;
1.523 albertel 6734: }
1.795 www 6735:
1.779 bisitz 6736: .LC_answer_not_charged_try,
1.523 albertel 6737: .LC_answer_no_grade,
6738: .LC_answer_late {
1.795 www 6739: background: lightyellow;
1.523 albertel 6740: color: black;
1.795 www 6741: padding: 6px;
1.523 albertel 6742: }
1.795 www 6743:
1.523 albertel 6744: .LC_answer_previous {
1.795 www 6745: background: lightblue;
6746: color: darkblue;
6747: padding: 6px;
1.523 albertel 6748: }
1.795 www 6749:
1.779 bisitz 6750: .LC_answer_no_message {
1.777 tempelho 6751: background: #FFFFFF;
6752: color: black;
1.795 www 6753: padding: 6px;
1.779 bisitz 6754: }
1.795 www 6755:
1.1075.2.140! raeburn 6756: .LC_answer_unknown,
! 6757: .LC_answer_warning {
1.779 bisitz 6758: background: orange;
6759: color: black;
1.795 www 6760: padding: 6px;
1.777 tempelho 6761: }
1.795 www 6762:
1.529 albertel 6763: span.LC_prior_numerical,
6764: span.LC_prior_string,
6765: span.LC_prior_custom,
6766: span.LC_prior_reaction,
6767: span.LC_prior_math {
1.925 bisitz 6768: font-family: $mono;
1.523 albertel 6769: white-space: pre;
6770: }
6771:
1.525 albertel 6772: span.LC_prior_string {
1.925 bisitz 6773: font-family: $mono;
1.525 albertel 6774: white-space: pre;
6775: }
6776:
1.523 albertel 6777: table.LC_prior_option {
6778: width: 100%;
6779: border-collapse: collapse;
6780: }
1.795 www 6781:
1.911 bisitz 6782: table.LC_prior_rank,
1.795 www 6783: table.LC_prior_match {
1.528 albertel 6784: border-collapse: collapse;
6785: }
1.795 www 6786:
1.528 albertel 6787: table.LC_prior_option tr td,
6788: table.LC_prior_rank tr td,
6789: table.LC_prior_match tr td {
1.524 albertel 6790: border: 1px solid #000000;
1.515 albertel 6791: }
6792:
1.855 bisitz 6793: .LC_nobreak {
1.544 albertel 6794: white-space: nowrap;
1.519 raeburn 6795: }
6796:
1.576 raeburn 6797: span.LC_cusr_emph {
6798: font-style: italic;
6799: }
6800:
1.633 raeburn 6801: span.LC_cusr_subheading {
6802: font-weight: normal;
6803: font-size: 85%;
6804: }
6805:
1.861 bisitz 6806: div.LC_docs_entry_move {
1.859 bisitz 6807: border: 1px solid #BBBBBB;
1.545 albertel 6808: background: #DDDDDD;
1.861 bisitz 6809: width: 22px;
1.859 bisitz 6810: padding: 1px;
6811: margin: 0;
1.545 albertel 6812: }
6813:
1.861 bisitz 6814: table.LC_data_table tr > td.LC_docs_entry_commands,
6815: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6816: font-size: x-small;
6817: }
1.795 www 6818:
1.861 bisitz 6819: .LC_docs_entry_parameter {
6820: white-space: nowrap;
6821: }
6822:
1.544 albertel 6823: .LC_docs_copy {
1.545 albertel 6824: color: #000099;
1.544 albertel 6825: }
1.795 www 6826:
1.544 albertel 6827: .LC_docs_cut {
1.545 albertel 6828: color: #550044;
1.544 albertel 6829: }
1.795 www 6830:
1.544 albertel 6831: .LC_docs_rename {
1.545 albertel 6832: color: #009900;
1.544 albertel 6833: }
1.795 www 6834:
1.544 albertel 6835: .LC_docs_remove {
1.545 albertel 6836: color: #990000;
6837: }
6838:
1.1075.2.134 raeburn 6839: .LC_domprefs_email,
1.547 albertel 6840: .LC_docs_reinit_warn,
6841: .LC_docs_ext_edit {
6842: font-size: x-small;
6843: }
6844:
1.545 albertel 6845: table.LC_docs_adddocs td,
6846: table.LC_docs_adddocs th {
6847: border: 1px solid #BBBBBB;
6848: padding: 4px;
6849: background: #DDDDDD;
1.543 albertel 6850: }
6851:
1.584 albertel 6852: table.LC_sty_begin {
6853: background: #BBFFBB;
6854: }
1.795 www 6855:
1.584 albertel 6856: table.LC_sty_end {
6857: background: #FFBBBB;
6858: }
6859:
1.589 raeburn 6860: table.LC_double_column {
1.803 bisitz 6861: border-width: 0;
1.589 raeburn 6862: border-collapse: collapse;
6863: width: 100%;
6864: padding: 2px;
6865: }
6866:
6867: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6868: top: 2px;
1.589 raeburn 6869: left: 2px;
6870: width: 47%;
6871: vertical-align: top;
6872: }
6873:
6874: table.LC_double_column tr td.LC_right_col {
6875: top: 2px;
1.779 bisitz 6876: right: 2px;
1.589 raeburn 6877: width: 47%;
6878: vertical-align: top;
6879: }
6880:
1.591 raeburn 6881: div.LC_left_float {
6882: float: left;
6883: padding-right: 5%;
1.597 albertel 6884: padding-bottom: 4px;
1.591 raeburn 6885: }
6886:
6887: div.LC_clear_float_header {
1.597 albertel 6888: padding-bottom: 2px;
1.591 raeburn 6889: }
6890:
6891: div.LC_clear_float_footer {
1.597 albertel 6892: padding-top: 10px;
1.591 raeburn 6893: clear: both;
6894: }
6895:
1.597 albertel 6896: div.LC_grade_show_user {
1.941 bisitz 6897: /* border-left: 5px solid $sidebg; */
6898: border-top: 5px solid #000000;
6899: margin: 50px 0 0 0;
1.936 bisitz 6900: padding: 15px 0 5px 10px;
1.597 albertel 6901: }
1.795 www 6902:
1.936 bisitz 6903: div.LC_grade_show_user_odd_row {
1.941 bisitz 6904: /* border-left: 5px solid #000000; */
6905: }
6906:
6907: div.LC_grade_show_user div.LC_Box {
6908: margin-right: 50px;
1.597 albertel 6909: }
6910:
6911: div.LC_grade_submissions,
6912: div.LC_grade_message_center,
1.936 bisitz 6913: div.LC_grade_info_links {
1.597 albertel 6914: margin: 5px;
6915: width: 99%;
6916: background: #FFFFFF;
6917: }
1.795 www 6918:
1.597 albertel 6919: div.LC_grade_submissions_header,
1.936 bisitz 6920: div.LC_grade_message_center_header {
1.705 tempelho 6921: font-weight: bold;
6922: font-size: large;
1.597 albertel 6923: }
1.795 www 6924:
1.597 albertel 6925: div.LC_grade_submissions_body,
1.936 bisitz 6926: div.LC_grade_message_center_body {
1.597 albertel 6927: border: 1px solid black;
6928: width: 99%;
6929: background: #FFFFFF;
6930: }
1.795 www 6931:
1.613 albertel 6932: table.LC_scantron_action {
6933: width: 100%;
6934: }
1.795 www 6935:
1.613 albertel 6936: table.LC_scantron_action tr th {
1.698 harmsja 6937: font-weight:bold;
6938: font-style:normal;
1.613 albertel 6939: }
1.795 www 6940:
1.779 bisitz 6941: .LC_edit_problem_header,
1.614 albertel 6942: div.LC_edit_problem_footer {
1.705 tempelho 6943: font-weight: normal;
6944: font-size: medium;
1.602 albertel 6945: margin: 2px;
1.1060 bisitz 6946: background-color: $sidebg;
1.600 albertel 6947: }
1.795 www 6948:
1.600 albertel 6949: div.LC_edit_problem_header,
1.602 albertel 6950: div.LC_edit_problem_header div,
1.614 albertel 6951: div.LC_edit_problem_footer,
6952: div.LC_edit_problem_footer div,
1.602 albertel 6953: div.LC_edit_problem_editxml_header,
6954: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 6955: z-index: 100;
1.600 albertel 6956: }
1.795 www 6957:
1.600 albertel 6958: div.LC_edit_problem_header_title {
1.705 tempelho 6959: font-weight: bold;
6960: font-size: larger;
1.602 albertel 6961: background: $tabbg;
6962: padding: 3px;
1.1060 bisitz 6963: margin: 0 0 5px 0;
1.602 albertel 6964: }
1.795 www 6965:
1.602 albertel 6966: table.LC_edit_problem_header_title {
6967: width: 100%;
1.600 albertel 6968: background: $tabbg;
1.602 albertel 6969: }
6970:
1.1075.2.112 raeburn 6971: div.LC_edit_actionbar {
6972: background-color: $sidebg;
6973: margin: 0;
6974: padding: 0;
6975: line-height: 200%;
1.602 albertel 6976: }
1.795 www 6977:
1.1075.2.112 raeburn 6978: div.LC_edit_actionbar div{
6979: padding: 0;
6980: margin: 0;
6981: display: inline-block;
1.600 albertel 6982: }
1.795 www 6983:
1.1075.2.34 raeburn 6984: .LC_edit_opt {
6985: padding-left: 1em;
6986: white-space: nowrap;
6987: }
6988:
1.1075.2.57 raeburn 6989: .LC_edit_problem_latexhelper{
6990: text-align: right;
6991: }
6992:
6993: #LC_edit_problem_colorful div{
6994: margin-left: 40px;
6995: }
6996:
1.1075.2.112 raeburn 6997: #LC_edit_problem_codemirror div{
6998: margin-left: 0px;
6999: }
7000:
1.911 bisitz 7001: img.stift {
1.803 bisitz 7002: border-width: 0;
7003: vertical-align: middle;
1.677 riegler 7004: }
1.680 riegler 7005:
1.923 bisitz 7006: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7007: vertical-align: top;
1.777 tempelho 7008: }
1.795 www 7009:
1.716 raeburn 7010: div.LC_createcourse {
1.911 bisitz 7011: margin: 10px 10px 10px 10px;
1.716 raeburn 7012: }
7013:
1.917 raeburn 7014: .LC_dccid {
1.1075.2.38 raeburn 7015: float: right;
1.917 raeburn 7016: margin: 0.2em 0 0 0;
7017: padding: 0;
7018: font-size: 90%;
7019: display:none;
7020: }
7021:
1.897 wenzelju 7022: ol.LC_primary_menu a:hover,
1.721 harmsja 7023: ol#LC_MenuBreadcrumbs a:hover,
7024: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7025: ul#LC_secondary_menu a:hover,
1.721 harmsja 7026: .LC_FormSectionClearButton input:hover
1.795 www 7027: ul.LC_TabContent li:hover a {
1.952 onken 7028: color:$button_hover;
1.911 bisitz 7029: text-decoration:none;
1.693 droeschl 7030: }
7031:
1.779 bisitz 7032: h1 {
1.911 bisitz 7033: padding: 0;
7034: line-height:130%;
1.693 droeschl 7035: }
1.698 harmsja 7036:
1.911 bisitz 7037: h2,
7038: h3,
7039: h4,
7040: h5,
7041: h6 {
7042: margin: 5px 0 5px 0;
7043: padding: 0;
7044: line-height:130%;
1.693 droeschl 7045: }
1.795 www 7046:
7047: .LC_hcell {
1.911 bisitz 7048: padding:3px 15px 3px 15px;
7049: margin: 0;
7050: background-color:$tabbg;
7051: color:$fontmenu;
7052: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7053: }
1.795 www 7054:
1.840 bisitz 7055: .LC_Box > .LC_hcell {
1.911 bisitz 7056: margin: 0 -10px 10px -10px;
1.835 bisitz 7057: }
7058:
1.721 harmsja 7059: .LC_noBorder {
1.911 bisitz 7060: border: 0;
1.698 harmsja 7061: }
1.693 droeschl 7062:
1.721 harmsja 7063: .LC_FormSectionClearButton input {
1.911 bisitz 7064: background-color:transparent;
7065: border: none;
7066: cursor:pointer;
7067: text-decoration:underline;
1.693 droeschl 7068: }
1.763 bisitz 7069:
7070: .LC_help_open_topic {
1.911 bisitz 7071: color: #FFFFFF;
7072: background-color: #EEEEFF;
7073: margin: 1px;
7074: padding: 4px;
7075: border: 1px solid #000033;
7076: white-space: nowrap;
7077: /* vertical-align: middle; */
1.759 neumanie 7078: }
1.693 droeschl 7079:
1.911 bisitz 7080: dl,
7081: ul,
7082: div,
7083: fieldset {
7084: margin: 10px 10px 10px 0;
7085: /* overflow: hidden; */
1.693 droeschl 7086: }
1.795 www 7087:
1.1075.2.90 raeburn 7088: article.geogebraweb div {
7089: margin: 0;
7090: }
7091:
1.838 bisitz 7092: fieldset > legend {
1.911 bisitz 7093: font-weight: bold;
7094: padding: 0 5px 0 5px;
1.838 bisitz 7095: }
7096:
1.813 bisitz 7097: #LC_nav_bar {
1.911 bisitz 7098: float: left;
1.995 raeburn 7099: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7100: margin: 0 0 2px 0;
1.807 droeschl 7101: }
7102:
1.916 droeschl 7103: #LC_realm {
7104: margin: 0.2em 0 0 0;
7105: padding: 0;
7106: font-weight: bold;
7107: text-align: center;
1.995 raeburn 7108: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7109: }
7110:
1.911 bisitz 7111: #LC_nav_bar em {
7112: font-weight: bold;
7113: font-style: normal;
1.807 droeschl 7114: }
7115:
1.897 wenzelju 7116: ol.LC_primary_menu {
1.934 droeschl 7117: margin: 0;
1.1075.2.2 raeburn 7118: padding: 0;
1.807 droeschl 7119: }
7120:
1.852 droeschl 7121: ol#LC_PathBreadcrumbs {
1.911 bisitz 7122: margin: 0;
1.693 droeschl 7123: }
7124:
1.897 wenzelju 7125: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7126: color: RGB(80, 80, 80);
7127: vertical-align: middle;
7128: text-align: left;
7129: list-style: none;
1.1075.2.112 raeburn 7130: position: relative;
1.1075.2.2 raeburn 7131: float: left;
1.1075.2.112 raeburn 7132: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7133: line-height: 1.5em;
1.1075.2.2 raeburn 7134: }
7135:
1.1075.2.113 raeburn 7136: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7137: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7138: display: block;
7139: margin: 0;
7140: padding: 0 5px 0 10px;
7141: text-decoration: none;
7142: }
7143:
1.1075.2.112 raeburn 7144: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7145: display: inline-block;
7146: width: 95%;
7147: text-align: left;
7148: }
7149:
7150: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7151: display: inline-block;
7152: width: 5%;
7153: float: right;
7154: text-align: right;
7155: font-size: 70%;
7156: }
7157:
7158: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7159: display: none;
1.1075.2.112 raeburn 7160: width: 15em;
1.1075.2.2 raeburn 7161: background-color: $data_table_light;
1.1075.2.112 raeburn 7162: position: absolute;
7163: top: 100%;
7164: }
7165:
7166: ol.LC_primary_menu ul ul {
7167: left: 100%;
7168: top: 0;
1.1075.2.2 raeburn 7169: }
7170:
1.1075.2.112 raeburn 7171: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7172: display: block;
7173: position: absolute;
7174: margin: 0;
7175: padding: 0;
1.1075.2.5 raeburn 7176: z-index: 2;
1.1075.2.2 raeburn 7177: }
7178:
7179: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7180: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7181: font-size: 90%;
1.911 bisitz 7182: vertical-align: top;
1.1075.2.2 raeburn 7183: float: none;
1.1075.2.5 raeburn 7184: border-left: 1px solid black;
7185: border-right: 1px solid black;
1.1075.2.112 raeburn 7186: /* A dark bottom border to visualize different menu options;
7187: overwritten in the create_submenu routine for the last border-bottom of the menu */
7188: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7189: }
7190:
1.1075.2.112 raeburn 7191: ol.LC_primary_menu li li p:hover {
7192: color:$button_hover;
7193: text-decoration:none;
7194: background-color:$data_table_dark;
1.1075.2.2 raeburn 7195: }
7196:
7197: ol.LC_primary_menu li li a:hover {
7198: color:$button_hover;
7199: background-color:$data_table_dark;
1.693 droeschl 7200: }
7201:
1.1075.2.112 raeburn 7202: /* Font-size equal to the size of the predecessors*/
7203: ol.LC_primary_menu li:hover li li {
7204: font-size: 100%;
7205: }
7206:
1.897 wenzelju 7207: ol.LC_primary_menu li img {
1.911 bisitz 7208: vertical-align: bottom;
1.934 droeschl 7209: height: 1.1em;
1.1075.2.3 raeburn 7210: margin: 0.2em 0 0 0;
1.693 droeschl 7211: }
7212:
1.897 wenzelju 7213: ol.LC_primary_menu a {
1.911 bisitz 7214: color: RGB(80, 80, 80);
7215: text-decoration: none;
1.693 droeschl 7216: }
1.795 www 7217:
1.949 droeschl 7218: ol.LC_primary_menu a.LC_new_message {
7219: font-weight:bold;
7220: color: darkred;
7221: }
7222:
1.975 raeburn 7223: ol.LC_docs_parameters {
7224: margin-left: 0;
7225: padding: 0;
7226: list-style: none;
7227: }
7228:
7229: ol.LC_docs_parameters li {
7230: margin: 0;
7231: padding-right: 20px;
7232: display: inline;
7233: }
7234:
1.976 raeburn 7235: ol.LC_docs_parameters li:before {
7236: content: "\\002022 \\0020";
7237: }
7238:
7239: li.LC_docs_parameters_title {
7240: font-weight: bold;
7241: }
7242:
7243: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7244: content: "";
7245: }
7246:
1.897 wenzelju 7247: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7248: clear: right;
1.911 bisitz 7249: color: $fontmenu;
7250: background: $tabbg;
7251: list-style: none;
7252: padding: 0;
7253: margin: 0;
7254: width: 100%;
1.995 raeburn 7255: text-align: left;
1.1075.2.4 raeburn 7256: float: left;
1.808 droeschl 7257: }
7258:
1.897 wenzelju 7259: ul#LC_secondary_menu li {
1.911 bisitz 7260: font-weight: bold;
7261: line-height: 1.8em;
7262: border-right: 1px solid black;
1.1075.2.4 raeburn 7263: float: left;
7264: }
7265:
7266: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7267: background-color: $data_table_light;
7268: }
7269:
7270: ul#LC_secondary_menu li a {
7271: padding: 0 0.8em;
7272: }
7273:
7274: ul#LC_secondary_menu li ul {
7275: display: none;
7276: }
7277:
7278: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7279: display: block;
7280: position: absolute;
7281: margin: 0;
7282: padding: 0;
7283: list-style:none;
7284: float: none;
7285: background-color: $data_table_light;
1.1075.2.5 raeburn 7286: z-index: 2;
1.1075.2.10 raeburn 7287: margin-left: -1px;
1.1075.2.4 raeburn 7288: }
7289:
7290: ul#LC_secondary_menu li ul li {
7291: font-size: 90%;
7292: vertical-align: top;
7293: border-left: 1px solid black;
7294: border-right: 1px solid black;
1.1075.2.33 raeburn 7295: background-color: $data_table_light;
1.1075.2.4 raeburn 7296: list-style:none;
7297: float: none;
7298: }
7299:
7300: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7301: background-color: $data_table_dark;
1.807 droeschl 7302: }
7303:
1.847 tempelho 7304: ul.LC_TabContent {
1.911 bisitz 7305: display:block;
7306: background: $sidebg;
7307: border-bottom: solid 1px $lg_border_color;
7308: list-style:none;
1.1020 raeburn 7309: margin: -1px -10px 0 -10px;
1.911 bisitz 7310: padding: 0;
1.693 droeschl 7311: }
7312:
1.795 www 7313: ul.LC_TabContent li,
7314: ul.LC_TabContentBigger li {
1.911 bisitz 7315: float:left;
1.741 harmsja 7316: }
1.795 www 7317:
1.897 wenzelju 7318: ul#LC_secondary_menu li a {
1.911 bisitz 7319: color: $fontmenu;
7320: text-decoration: none;
1.693 droeschl 7321: }
1.795 www 7322:
1.721 harmsja 7323: ul.LC_TabContent {
1.952 onken 7324: min-height:20px;
1.721 harmsja 7325: }
1.795 www 7326:
7327: ul.LC_TabContent li {
1.911 bisitz 7328: vertical-align:middle;
1.959 onken 7329: padding: 0 16px 0 10px;
1.911 bisitz 7330: background-color:$tabbg;
7331: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7332: border-left: solid 1px $font;
1.721 harmsja 7333: }
1.795 www 7334:
1.847 tempelho 7335: ul.LC_TabContent .right {
1.911 bisitz 7336: float:right;
1.847 tempelho 7337: }
7338:
1.911 bisitz 7339: ul.LC_TabContent li a,
7340: ul.LC_TabContent li {
7341: color:rgb(47,47,47);
7342: text-decoration:none;
7343: font-size:95%;
7344: font-weight:bold;
1.952 onken 7345: min-height:20px;
7346: }
7347:
1.959 onken 7348: ul.LC_TabContent li a:hover,
7349: ul.LC_TabContent li a:focus {
1.952 onken 7350: color: $button_hover;
1.959 onken 7351: background:none;
7352: outline:none;
1.952 onken 7353: }
7354:
7355: ul.LC_TabContent li:hover {
7356: color: $button_hover;
7357: cursor:pointer;
1.721 harmsja 7358: }
1.795 www 7359:
1.911 bisitz 7360: ul.LC_TabContent li.active {
1.952 onken 7361: color: $font;
1.911 bisitz 7362: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7363: border-bottom:solid 1px #FFFFFF;
7364: cursor: default;
1.744 ehlerst 7365: }
1.795 www 7366:
1.959 onken 7367: ul.LC_TabContent li.active a {
7368: color:$font;
7369: background:#FFFFFF;
7370: outline: none;
7371: }
1.1047 raeburn 7372:
7373: ul.LC_TabContent li.goback {
7374: float: left;
7375: border-left: none;
7376: }
7377:
1.870 tempelho 7378: #maincoursedoc {
1.911 bisitz 7379: clear:both;
1.870 tempelho 7380: }
7381:
7382: ul.LC_TabContentBigger {
1.911 bisitz 7383: display:block;
7384: list-style:none;
7385: padding: 0;
1.870 tempelho 7386: }
7387:
1.795 www 7388: ul.LC_TabContentBigger li {
1.911 bisitz 7389: vertical-align:bottom;
7390: height: 30px;
7391: font-size:110%;
7392: font-weight:bold;
7393: color: #737373;
1.841 tempelho 7394: }
7395:
1.957 onken 7396: ul.LC_TabContentBigger li.active {
7397: position: relative;
7398: top: 1px;
7399: }
7400:
1.870 tempelho 7401: ul.LC_TabContentBigger li a {
1.911 bisitz 7402: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7403: height: 30px;
7404: line-height: 30px;
7405: text-align: center;
7406: display: block;
7407: text-decoration: none;
1.958 onken 7408: outline: none;
1.741 harmsja 7409: }
1.795 www 7410:
1.870 tempelho 7411: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7412: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7413: color:$font;
1.744 ehlerst 7414: }
1.795 www 7415:
1.870 tempelho 7416: ul.LC_TabContentBigger li b {
1.911 bisitz 7417: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7418: display: block;
7419: float: left;
7420: padding: 0 30px;
1.957 onken 7421: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7422: }
7423:
1.956 onken 7424: ul.LC_TabContentBigger li:hover b {
7425: color:$button_hover;
7426: }
7427:
1.870 tempelho 7428: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7429: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7430: color:$font;
1.957 onken 7431: border: 0;
1.741 harmsja 7432: }
1.693 droeschl 7433:
1.870 tempelho 7434:
1.862 bisitz 7435: ul.LC_CourseBreadcrumbs {
7436: background: $sidebg;
1.1020 raeburn 7437: height: 2em;
1.862 bisitz 7438: padding-left: 10px;
1.1020 raeburn 7439: margin: 0;
1.862 bisitz 7440: list-style-position: inside;
7441: }
7442:
1.911 bisitz 7443: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7444: ol#LC_PathBreadcrumbs {
1.911 bisitz 7445: padding-left: 10px;
7446: margin: 0;
1.933 droeschl 7447: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7448: }
7449:
1.911 bisitz 7450: ol#LC_MenuBreadcrumbs li,
7451: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7452: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7453: display: inline;
1.933 droeschl 7454: white-space: normal;
1.693 droeschl 7455: }
7456:
1.823 bisitz 7457: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7458: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7459: text-decoration: none;
7460: font-size:90%;
1.693 droeschl 7461: }
1.795 www 7462:
1.969 droeschl 7463: ol#LC_MenuBreadcrumbs h1 {
7464: display: inline;
7465: font-size: 90%;
7466: line-height: 2.5em;
7467: margin: 0;
7468: padding: 0;
7469: }
7470:
1.795 www 7471: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7472: text-decoration:none;
7473: font-size:100%;
7474: font-weight:bold;
1.693 droeschl 7475: }
1.795 www 7476:
1.840 bisitz 7477: .LC_Box {
1.911 bisitz 7478: border: solid 1px $lg_border_color;
7479: padding: 0 10px 10px 10px;
1.746 neumanie 7480: }
1.795 www 7481:
1.1020 raeburn 7482: .LC_DocsBox {
7483: border: solid 1px $lg_border_color;
7484: padding: 0 0 10px 10px;
7485: }
7486:
1.795 www 7487: .LC_AboutMe_Image {
1.911 bisitz 7488: float:left;
7489: margin-right:10px;
1.747 neumanie 7490: }
1.795 www 7491:
7492: .LC_Clear_AboutMe_Image {
1.911 bisitz 7493: clear:left;
1.747 neumanie 7494: }
1.795 www 7495:
1.721 harmsja 7496: dl.LC_ListStyleClean dt {
1.911 bisitz 7497: padding-right: 5px;
7498: display: table-header-group;
1.693 droeschl 7499: }
7500:
1.721 harmsja 7501: dl.LC_ListStyleClean dd {
1.911 bisitz 7502: display: table-row;
1.693 droeschl 7503: }
7504:
1.721 harmsja 7505: .LC_ListStyleClean,
7506: .LC_ListStyleSimple,
7507: .LC_ListStyleNormal,
1.795 www 7508: .LC_ListStyleSpecial {
1.911 bisitz 7509: /* display:block; */
7510: list-style-position: inside;
7511: list-style-type: none;
7512: overflow: hidden;
7513: padding: 0;
1.693 droeschl 7514: }
7515:
1.721 harmsja 7516: .LC_ListStyleSimple li,
7517: .LC_ListStyleSimple dd,
7518: .LC_ListStyleNormal li,
7519: .LC_ListStyleNormal dd,
7520: .LC_ListStyleSpecial li,
1.795 www 7521: .LC_ListStyleSpecial dd {
1.911 bisitz 7522: margin: 0;
7523: padding: 5px 5px 5px 10px;
7524: clear: both;
1.693 droeschl 7525: }
7526:
1.721 harmsja 7527: .LC_ListStyleClean li,
7528: .LC_ListStyleClean dd {
1.911 bisitz 7529: padding-top: 0;
7530: padding-bottom: 0;
1.693 droeschl 7531: }
7532:
1.721 harmsja 7533: .LC_ListStyleSimple dd,
1.795 www 7534: .LC_ListStyleSimple li {
1.911 bisitz 7535: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7536: }
7537:
1.721 harmsja 7538: .LC_ListStyleSpecial li,
7539: .LC_ListStyleSpecial dd {
1.911 bisitz 7540: list-style-type: none;
7541: background-color: RGB(220, 220, 220);
7542: margin-bottom: 4px;
1.693 droeschl 7543: }
7544:
1.721 harmsja 7545: table.LC_SimpleTable {
1.911 bisitz 7546: margin:5px;
7547: border:solid 1px $lg_border_color;
1.795 www 7548: }
1.693 droeschl 7549:
1.721 harmsja 7550: table.LC_SimpleTable tr {
1.911 bisitz 7551: padding: 0;
7552: border:solid 1px $lg_border_color;
1.693 droeschl 7553: }
1.795 www 7554:
7555: table.LC_SimpleTable thead {
1.911 bisitz 7556: background:rgb(220,220,220);
1.693 droeschl 7557: }
7558:
1.721 harmsja 7559: div.LC_columnSection {
1.911 bisitz 7560: display: block;
7561: clear: both;
7562: overflow: hidden;
7563: margin: 0;
1.693 droeschl 7564: }
7565:
1.721 harmsja 7566: div.LC_columnSection>* {
1.911 bisitz 7567: float: left;
7568: margin: 10px 20px 10px 0;
7569: overflow:hidden;
1.693 droeschl 7570: }
1.721 harmsja 7571:
1.795 www 7572: table em {
1.911 bisitz 7573: font-weight: bold;
7574: font-style: normal;
1.748 schulted 7575: }
1.795 www 7576:
1.779 bisitz 7577: table.LC_tableBrowseRes,
1.795 www 7578: table.LC_tableOfContent {
1.911 bisitz 7579: border:none;
7580: border-spacing: 1px;
7581: padding: 3px;
7582: background-color: #FFFFFF;
7583: font-size: 90%;
1.753 droeschl 7584: }
1.789 droeschl 7585:
1.911 bisitz 7586: table.LC_tableOfContent {
7587: border-collapse: collapse;
1.789 droeschl 7588: }
7589:
1.771 droeschl 7590: table.LC_tableBrowseRes a,
1.768 schulted 7591: table.LC_tableOfContent a {
1.911 bisitz 7592: background-color: transparent;
7593: text-decoration: none;
1.753 droeschl 7594: }
7595:
1.795 www 7596: table.LC_tableOfContent img {
1.911 bisitz 7597: border: none;
7598: height: 1.3em;
7599: vertical-align: text-bottom;
7600: margin-right: 0.3em;
1.753 droeschl 7601: }
1.757 schulted 7602:
1.795 www 7603: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7604: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7605: }
7606:
1.795 www 7607: a#LC_content_toolbar_everything {
1.911 bisitz 7608: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7609: }
7610:
1.795 www 7611: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7612: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7613: }
7614:
1.795 www 7615: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7616: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7617: }
7618:
1.795 www 7619: a#LC_content_toolbar_changefolder {
1.911 bisitz 7620: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7621: }
7622:
1.795 www 7623: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7624: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7625: }
7626:
1.1043 raeburn 7627: a#LC_content_toolbar_edittoplevel {
7628: background-image:url(/res/adm/pages/edittoplevel.gif);
7629: }
7630:
1.795 www 7631: ul#LC_toolbar li a:hover {
1.911 bisitz 7632: background-position: bottom center;
1.757 schulted 7633: }
7634:
1.795 www 7635: ul#LC_toolbar {
1.911 bisitz 7636: padding: 0;
7637: margin: 2px;
7638: list-style:none;
7639: position:relative;
7640: background-color:white;
1.1075.2.9 raeburn 7641: overflow: auto;
1.757 schulted 7642: }
7643:
1.795 www 7644: ul#LC_toolbar li {
1.911 bisitz 7645: border:1px solid white;
7646: padding: 0;
7647: margin: 0;
7648: float: left;
7649: display:inline;
7650: vertical-align:middle;
1.1075.2.9 raeburn 7651: white-space: nowrap;
1.911 bisitz 7652: }
1.757 schulted 7653:
1.783 amueller 7654:
1.795 www 7655: a.LC_toolbarItem {
1.911 bisitz 7656: display:block;
7657: padding: 0;
7658: margin: 0;
7659: height: 32px;
7660: width: 32px;
7661: color:white;
7662: border: none;
7663: background-repeat:no-repeat;
7664: background-color:transparent;
1.757 schulted 7665: }
7666:
1.915 droeschl 7667: ul.LC_funclist {
7668: margin: 0;
7669: padding: 0.5em 1em 0.5em 0;
7670: }
7671:
1.933 droeschl 7672: ul.LC_funclist > li:first-child {
7673: font-weight:bold;
7674: margin-left:0.8em;
7675: }
7676:
1.915 droeschl 7677: ul.LC_funclist + ul.LC_funclist {
7678: /*
7679: left border as a seperator if we have more than
7680: one list
7681: */
7682: border-left: 1px solid $sidebg;
7683: /*
7684: this hides the left border behind the border of the
7685: outer box if element is wrapped to the next 'line'
7686: */
7687: margin-left: -1px;
7688: }
7689:
1.843 bisitz 7690: ul.LC_funclist li {
1.915 droeschl 7691: display: inline;
1.782 bisitz 7692: white-space: nowrap;
1.915 droeschl 7693: margin: 0 0 0 25px;
7694: line-height: 150%;
1.782 bisitz 7695: }
7696:
1.974 wenzelju 7697: .LC_hidden {
7698: display: none;
7699: }
7700:
1.1030 www 7701: .LCmodal-overlay {
7702: position:fixed;
7703: top:0;
7704: right:0;
7705: bottom:0;
7706: left:0;
7707: height:100%;
7708: width:100%;
7709: margin:0;
7710: padding:0;
7711: background:#999;
7712: opacity:.75;
7713: filter: alpha(opacity=75);
7714: -moz-opacity: 0.75;
7715: z-index:101;
7716: }
7717:
7718: * html .LCmodal-overlay {
7719: position: absolute;
7720: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7721: }
7722:
7723: .LCmodal-window {
7724: position:fixed;
7725: top:50%;
7726: left:50%;
7727: margin:0;
7728: padding:0;
7729: z-index:102;
7730: }
7731:
7732: * html .LCmodal-window {
7733: position:absolute;
7734: }
7735:
7736: .LCclose-window {
7737: position:absolute;
7738: width:32px;
7739: height:32px;
7740: right:8px;
7741: top:8px;
7742: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7743: text-indent:-99999px;
7744: overflow:hidden;
7745: cursor:pointer;
7746: }
7747:
1.1075.2.17 raeburn 7748: /*
7749: styles used by TTH when "Default set of options to pass to tth/m
7750: when converting TeX" in course settings has been set
7751:
7752: option passed: -t
7753:
7754: */
7755:
7756: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7757: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7758: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7759: td div.norm {line-height:normal;}
7760:
7761: /*
7762: option passed -y3
7763: */
7764:
7765: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7766: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7767: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7768:
1.1075.2.121 raeburn 7769: #LC_minitab_header {
7770: float:left;
7771: width:100%;
7772: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
7773: font-size:93%;
7774: line-height:normal;
7775: margin: 0.5em 0 0.5em 0;
7776: }
7777: #LC_minitab_header ul {
7778: margin:0;
7779: padding:10px 10px 0;
7780: list-style:none;
7781: }
7782: #LC_minitab_header li {
7783: float:left;
7784: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
7785: margin:0;
7786: padding:0 0 0 9px;
7787: }
7788: #LC_minitab_header a {
7789: display:block;
7790: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
7791: padding:5px 15px 4px 6px;
7792: }
7793: #LC_minitab_header #LC_current_minitab {
7794: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
7795: }
7796: #LC_minitab_header #LC_current_minitab a {
7797: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
7798: padding-bottom:5px;
7799: }
7800:
7801:
1.343 albertel 7802: END
7803: }
7804:
1.306 albertel 7805: =pod
7806:
7807: =item * &headtag()
7808:
7809: Returns a uniform footer for LON-CAPA web pages.
7810:
1.307 albertel 7811: Inputs: $title - optional title for the head
7812: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7813: $args - optional arguments
1.319 albertel 7814: force_register - if is true call registerurl so the remote is
7815: informed
1.415 albertel 7816: redirect -> array ref of
7817: 1- seconds before redirect occurs
7818: 2- url to redirect to
7819: 3- whether the side effect should occur
1.315 albertel 7820: (side effect of setting
7821: $env{'internal.head.redirect'} to the url
7822: redirected too)
1.352 albertel 7823: domain -> force to color decorate a page for a specific
7824: domain
7825: function -> force usage of a specific rolish color scheme
7826: bgcolor -> override the default page bgcolor
1.460 albertel 7827: no_auto_mt_title
7828: -> prevent &mt()ing the title arg
1.464 albertel 7829:
1.306 albertel 7830: =cut
7831:
7832: sub headtag {
1.313 albertel 7833: my ($title,$head_extra,$args) = @_;
1.306 albertel 7834:
1.363 albertel 7835: my $function = $args->{'function'} || &get_users_function();
7836: my $domain = $args->{'domain'} || &determinedomain();
7837: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7838: my $httphost = $args->{'use_absolute'};
1.418 albertel 7839: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7840: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7841: #time(),
1.418 albertel 7842: $env{'environment.color.timestamp'},
1.363 albertel 7843: $function,$domain,$bgcolor);
7844:
1.369 www 7845: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7846:
1.308 albertel 7847: my $result =
7848: '<head>'.
1.1075.2.56 raeburn 7849: &font_settings($args);
1.319 albertel 7850:
1.1075.2.72 raeburn 7851: my $inhibitprint;
7852: if ($args->{'print_suppress'}) {
7853: $inhibitprint = &print_suppression();
7854: }
1.1064 raeburn 7855:
1.461 albertel 7856: if (!$args->{'frameset'}) {
7857: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7858: }
1.1075.2.12 raeburn 7859: if ($args->{'force_register'}) {
7860: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7861: }
1.436 albertel 7862: if (!$args->{'no_nav_bar'}
7863: && !$args->{'only_body'}
7864: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7865: $result .= &help_menu_js($httphost);
1.1032 www 7866: $result.=&modal_window();
1.1038 www 7867: $result.=&togglebox_script();
1.1034 www 7868: $result.=&wishlist_window();
1.1041 www 7869: $result.=&LCprogressbarUpdate_script();
1.1034 www 7870: } else {
7871: if ($args->{'add_modal'}) {
7872: $result.=&modal_window();
7873: }
7874: if ($args->{'add_wishlist'}) {
7875: $result.=&wishlist_window();
7876: }
1.1038 www 7877: if ($args->{'add_togglebox'}) {
7878: $result.=&togglebox_script();
7879: }
1.1041 www 7880: if ($args->{'add_progressbar'}) {
7881: $result.=&LCprogressbarUpdate_script();
7882: }
1.436 albertel 7883: }
1.314 albertel 7884: if (ref($args->{'redirect'})) {
1.414 albertel 7885: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7886: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7887: if (!$inhibit_continue) {
7888: $env{'internal.head.redirect'} = $url;
7889: }
1.313 albertel 7890: $result.=<<ADDMETA
7891: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7892: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7893: ADDMETA
1.1075.2.89 raeburn 7894: } else {
7895: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
7896: my $requrl = $env{'request.uri'};
7897: if ($requrl eq '') {
7898: $requrl = $ENV{'REQUEST_URI'};
7899: $requrl =~ s/\?.+$//;
7900: }
7901: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
7902: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
7903: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
7904: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
7905: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
7906: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
7907: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
7908: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7909: if ($domdefs{'offloadnow'}{$lonhost}) {
7910: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
7911: if (($newserver) && ($newserver ne $lonhost)) {
7912: my $numsec = 5;
7913: my $timeout = $numsec * 1000;
7914: my ($newurl,$locknum,%locks,$msg);
7915: if ($env{'request.role.adv'}) {
7916: ($locknum,%locks) = &Apache::lonnet::get_locks();
7917: }
7918: my $disable_submit = 0;
7919: if ($requrl =~ /$LONCAPA::assess_re/) {
7920: $disable_submit = 1;
7921: }
7922: if ($locknum) {
7923: my @lockinfo = sort(values(%locks));
7924: $msg = &mt('Once the following tasks are complete: ')."\\n".
7925: join(", ",sort(values(%locks)))."\\n".
7926: &mt('your session will be transferred to a different server, after you click "Roles".');
7927: } else {
7928: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
7929: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
7930: }
7931: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
7932: $newurl = '/adm/switchserver?otherserver='.$newserver;
7933: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
7934: $newurl .= '&role='.$env{'request.role'};
7935: }
7936: if ($env{'request.symb'}) {
7937: $newurl .= '&symb='.$env{'request.symb'};
7938: } else {
7939: $newurl .= '&origurl='.$requrl;
7940: }
7941: }
1.1075.2.98 raeburn 7942: &js_escape(\$msg);
1.1075.2.89 raeburn 7943: $result.=<<OFFLOAD
7944: <meta http-equiv="pragma" content="no-cache" />
7945: <script type="text/javascript">
1.1075.2.92 raeburn 7946: // <![CDATA[
1.1075.2.89 raeburn 7947: function LC_Offload_Now() {
7948: var dest = "$newurl";
7949: if (dest != '') {
7950: window.location.href="$newurl";
7951: }
7952: }
1.1075.2.92 raeburn 7953: \$(document).ready(function () {
7954: window.alert('$msg');
7955: if ($disable_submit) {
1.1075.2.89 raeburn 7956: \$(".LC_hwk_submit").prop("disabled", true);
7957: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 7958: }
7959: setTimeout('LC_Offload_Now()', $timeout);
7960: });
7961: // ]]>
1.1075.2.89 raeburn 7962: </script>
7963: OFFLOAD
7964: }
7965: }
7966: }
7967: }
7968: }
7969: }
1.313 albertel 7970: }
1.306 albertel 7971: if (!defined($title)) {
7972: $title = 'The LearningOnline Network with CAPA';
7973: }
1.460 albertel 7974: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7975: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 7976: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7977: if (!$args->{'frameset'}) {
7978: $result .= ' /';
7979: }
7980: $result .= '>'
1.1064 raeburn 7981: .$inhibitprint
1.414 albertel 7982: .$head_extra;
1.1075.2.108 raeburn 7983: my $clientmobile;
7984: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
7985: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
7986: } else {
7987: $clientmobile = $env{'browser.mobile'};
7988: }
7989: if ($clientmobile) {
1.1075.2.42 raeburn 7990: $result .= '
7991: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7992: <meta name="apple-mobile-web-app-capable" content="yes" />';
7993: }
1.1075.2.126 raeburn 7994: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 7995: return $result.'</head>';
1.306 albertel 7996: }
7997:
7998: =pod
7999:
1.340 albertel 8000: =item * &font_settings()
8001:
8002: Returns neccessary <meta> to set the proper encoding
8003:
1.1075.2.56 raeburn 8004: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8005:
8006: =cut
8007:
8008: sub font_settings {
1.1075.2.56 raeburn 8009: my ($args) = @_;
1.340 albertel 8010: my $headerstring='';
1.1075.2.56 raeburn 8011: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8012: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 8013: $headerstring.=
1.1075.2.61 raeburn 8014: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8015: if (!$args->{'frameset'}) {
8016: $headerstring.= ' /';
8017: }
8018: $headerstring .= '>'."\n";
1.340 albertel 8019: }
8020: return $headerstring;
8021: }
8022:
1.341 albertel 8023: =pod
8024:
1.1064 raeburn 8025: =item * &print_suppression()
8026:
8027: In course context returns css which causes the body to be blank when media="print",
8028: if printout generation is unavailable for the current resource.
8029:
8030: This could be because:
8031:
8032: (a) printstartdate is in the future
8033:
8034: (b) printenddate is in the past
8035:
8036: (c) there is an active exam block with "printout"
8037: functionality blocked
8038:
8039: Users with pav, pfo or evb privileges are exempt.
8040:
8041: Inputs: none
8042:
8043: =cut
8044:
8045:
8046: sub print_suppression {
8047: my $noprint;
8048: if ($env{'request.course.id'}) {
8049: my $scope = $env{'request.course.id'};
8050: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8051: (&Apache::lonnet::allowed('pfo',$scope))) {
8052: return;
8053: }
8054: if ($env{'request.course.sec'} ne '') {
8055: $scope .= "/$env{'request.course.sec'}";
8056: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8057: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8058: return;
1.1064 raeburn 8059: }
8060: }
8061: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8062: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.73 raeburn 8063: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8064: if ($blocked) {
8065: my $checkrole = "cm./$cdom/$cnum";
8066: if ($env{'request.course.sec'} ne '') {
8067: $checkrole .= "/$env{'request.course.sec'}";
8068: }
8069: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8070: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8071: $noprint = 1;
8072: }
8073: }
8074: unless ($noprint) {
8075: my $symb = &Apache::lonnet::symbread();
8076: if ($symb ne '') {
8077: my $navmap = Apache::lonnavmaps::navmap->new();
8078: if (ref($navmap)) {
8079: my $res = $navmap->getBySymb($symb);
8080: if (ref($res)) {
8081: if (!$res->resprintable()) {
8082: $noprint = 1;
8083: }
8084: }
8085: }
8086: }
8087: }
8088: if ($noprint) {
8089: return <<"ENDSTYLE";
8090: <style type="text/css" media="print">
8091: body { display:none }
8092: </style>
8093: ENDSTYLE
8094: }
8095: }
8096: return;
8097: }
8098:
8099: =pod
8100:
1.341 albertel 8101: =item * &xml_begin()
8102:
8103: Returns the needed doctype and <html>
8104:
8105: Inputs: none
8106:
8107: =cut
8108:
8109: sub xml_begin {
1.1075.2.61 raeburn 8110: my ($is_frameset) = @_;
1.341 albertel 8111: my $output='';
8112:
8113: if ($env{'browser.mathml'}) {
8114: $output='<?xml version="1.0"?>'
8115: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8116: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8117:
8118: # .'<!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">] >'
8119: .'<!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">'
8120: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8121: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8122: } elsif ($is_frameset) {
8123: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8124: '<html>'."\n";
1.341 albertel 8125: } else {
1.1075.2.61 raeburn 8126: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8127: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8128: }
8129: return $output;
8130: }
1.340 albertel 8131:
8132: =pod
8133:
1.306 albertel 8134: =item * &start_page()
8135:
8136: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8137:
1.648 raeburn 8138: Inputs:
8139:
8140: =over 4
8141:
8142: $title - optional title for the page
8143:
8144: $head_extra - optional extra HTML to incude inside the <head>
8145:
8146: $args - additional optional args supported are:
8147:
8148: =over 8
8149:
8150: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8151: arg on
1.814 bisitz 8152: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8153: add_entries -> additional attributes to add to the <body>
8154: domain -> force to color decorate a page for a
1.317 albertel 8155: specific domain
1.648 raeburn 8156: function -> force usage of a specific rolish color
1.317 albertel 8157: scheme
1.648 raeburn 8158: redirect -> see &headtag()
8159: bgcolor -> override the default page bg color
8160: js_ready -> return a string ready for being used in
1.317 albertel 8161: a javascript writeln
1.648 raeburn 8162: html_encode -> return a string ready for being used in
1.320 albertel 8163: a html attribute
1.648 raeburn 8164: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8165: $forcereg arg
1.648 raeburn 8166: frameset -> if true will start with a <frameset>
1.330 albertel 8167: rather than <body>
1.648 raeburn 8168: skip_phases -> hash ref of
1.338 albertel 8169: head -> skip the <html><head> generation
8170: body -> skip all <body> generation
1.1075.2.12 raeburn 8171: no_inline_link -> if true and in remote mode, don't show the
8172: 'Switch To Inline Menu' link
1.648 raeburn 8173: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8174: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8175: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 8176: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8177: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8178: group -> includes the current group, if page is for a
8179: specific group
1.1075.2.133 raeburn 8180: use_absolute -> for request for external resource or syllabus, this
8181: will contain https://<hostname> if server uses
8182: https (as per hosts.tab), but request is for http
8183: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8184:
1.648 raeburn 8185: =back
1.460 albertel 8186:
1.648 raeburn 8187: =back
1.562 albertel 8188:
1.306 albertel 8189: =cut
8190:
8191: sub start_page {
1.309 albertel 8192: my ($title,$head_extra,$args) = @_;
1.318 albertel 8193: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8194:
1.315 albertel 8195: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 8196: my ($result,@advtools);
1.964 droeschl 8197:
1.338 albertel 8198: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8199: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8200: }
8201:
8202: if (! exists($args->{'skip_phases'}{'body'}) ) {
8203: if ($args->{'frameset'}) {
8204: my $attr_string = &make_attr_string($args->{'force_register'},
8205: $args->{'add_entries'});
8206: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8207: } else {
8208: $result .=
8209: &bodytag($title,
8210: $args->{'function'}, $args->{'add_entries'},
8211: $args->{'only_body'}, $args->{'domain'},
8212: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 8213: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 8214: $args, \@advtools);
1.831 bisitz 8215: }
1.330 albertel 8216: }
1.338 albertel 8217:
1.315 albertel 8218: if ($args->{'js_ready'}) {
1.713 kaisler 8219: $result = &js_ready($result);
1.315 albertel 8220: }
1.320 albertel 8221: if ($args->{'html_encode'}) {
1.713 kaisler 8222: $result = &html_encode($result);
8223: }
8224:
1.813 bisitz 8225: # Preparation for new and consistent functionlist at top of screen
8226: # if ($args->{'functionlist'}) {
8227: # $result .= &build_functionlist();
8228: #}
8229:
1.964 droeschl 8230: # Don't add anything more if only_body wanted or in const space
8231: return $result if $args->{'only_body'}
8232: || $env{'request.state'} eq 'construct';
1.813 bisitz 8233:
8234: #Breadcrumbs
1.758 kaisler 8235: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8236: &Apache::lonhtmlcommon::clear_breadcrumbs();
8237: #if any br links exists, add them to the breadcrumbs
8238: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8239: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8240: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8241: }
8242: }
1.1075.2.19 raeburn 8243: # if @advtools array contains items add then to the breadcrumbs
8244: if (@advtools > 0) {
8245: &Apache::lonmenu::advtools_crumbs(@advtools);
8246: }
1.1075.2.123 raeburn 8247: my $menulink;
8248: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8249: if (exists($args->{'bread_crumbs_nomenu'})) {
8250: $menulink = 0;
8251: } else {
8252: undef($menulink);
8253: }
1.758 kaisler 8254: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8255: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 8256: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.758 kaisler 8257: }else{
1.1075.2.123 raeburn 8258: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8259: }
1.1075.2.24 raeburn 8260: } elsif (($env{'environment.remote'} eq 'on') &&
8261: ($env{'form.inhibitmenu'} ne 'yes') &&
8262: ($env{'request.noversionuri'} =~ m{^/res/}) &&
8263: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 8264: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 8265: }
1.315 albertel 8266: return $result;
1.306 albertel 8267: }
8268:
8269: sub end_page {
1.315 albertel 8270: my ($args) = @_;
8271: $env{'internal.end_page'}++;
1.330 albertel 8272: my $result;
1.335 albertel 8273: if ($args->{'discussion'}) {
8274: my ($target,$parser);
8275: if (ref($args->{'discussion'})) {
8276: ($target,$parser) =($args->{'discussion'}{'target'},
8277: $args->{'discussion'}{'parser'});
8278: }
8279: $result .= &Apache::lonxml::xmlend($target,$parser);
8280: }
1.330 albertel 8281: if ($args->{'frameset'}) {
8282: $result .= '</frameset>';
8283: } else {
1.635 raeburn 8284: $result .= &endbodytag($args);
1.330 albertel 8285: }
1.1075.2.6 raeburn 8286: unless ($args->{'notbody'}) {
8287: $result .= "\n</html>";
8288: }
1.330 albertel 8289:
1.315 albertel 8290: if ($args->{'js_ready'}) {
1.317 albertel 8291: $result = &js_ready($result);
1.315 albertel 8292: }
1.335 albertel 8293:
1.320 albertel 8294: if ($args->{'html_encode'}) {
8295: $result = &html_encode($result);
8296: }
1.335 albertel 8297:
1.315 albertel 8298: return $result;
8299: }
8300:
1.1034 www 8301: sub wishlist_window {
8302: return(<<'ENDWISHLIST');
1.1046 raeburn 8303: <script type="text/javascript">
1.1034 www 8304: // <![CDATA[
8305: // <!-- BEGIN LON-CAPA Internal
8306: function set_wishlistlink(title, path) {
8307: if (!title) {
8308: title = document.title;
8309: title = title.replace(/^LON-CAPA /,'');
8310: }
1.1075.2.65 raeburn 8311: title = encodeURIComponent(title);
1.1075.2.83 raeburn 8312: title = title.replace("'","\\\'");
1.1034 www 8313: if (!path) {
8314: path = location.pathname;
8315: }
1.1075.2.65 raeburn 8316: path = encodeURIComponent(path);
1.1075.2.83 raeburn 8317: path = path.replace("'","\\\'");
1.1034 www 8318: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8319: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8320: }
8321: // END LON-CAPA Internal -->
8322: // ]]>
8323: </script>
8324: ENDWISHLIST
8325: }
8326:
1.1030 www 8327: sub modal_window {
8328: return(<<'ENDMODAL');
1.1046 raeburn 8329: <script type="text/javascript">
1.1030 www 8330: // <![CDATA[
8331: // <!-- BEGIN LON-CAPA Internal
8332: var modalWindow = {
8333: parent:"body",
8334: windowId:null,
8335: content:null,
8336: width:null,
8337: height:null,
8338: close:function()
8339: {
8340: $(".LCmodal-window").remove();
8341: $(".LCmodal-overlay").remove();
8342: },
8343: open:function()
8344: {
8345: var modal = "";
8346: modal += "<div class=\"LCmodal-overlay\"></div>";
8347: 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;\">";
8348: modal += this.content;
8349: modal += "</div>";
8350:
8351: $(this.parent).append(modal);
8352:
8353: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8354: $(".LCclose-window").click(function(){modalWindow.close();});
8355: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8356: }
8357: };
1.1075.2.42 raeburn 8358: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8359: {
1.1075.2.119 raeburn 8360: source = source.replace(/'/g,"'");
1.1030 www 8361: modalWindow.windowId = "myModal";
8362: modalWindow.width = width;
8363: modalWindow.height = height;
1.1075.2.80 raeburn 8364: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8365: modalWindow.open();
1.1075.2.87 raeburn 8366: };
1.1030 www 8367: // END LON-CAPA Internal -->
8368: // ]]>
8369: </script>
8370: ENDMODAL
8371: }
8372:
8373: sub modal_link {
1.1075.2.42 raeburn 8374: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8375: unless ($width) { $width=480; }
8376: unless ($height) { $height=400; }
1.1031 www 8377: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 8378: unless ($transparency) { $transparency='true'; }
8379:
1.1074 raeburn 8380: my $target_attr;
8381: if (defined($target)) {
8382: $target_attr = 'target="'.$target.'"';
8383: }
8384: return <<"ENDLINK";
1.1075.2.42 raeburn 8385: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8386: $linktext</a>
8387: ENDLINK
1.1030 www 8388: }
8389:
1.1032 www 8390: sub modal_adhoc_script {
8391: my ($funcname,$width,$height,$content)=@_;
8392: return (<<ENDADHOC);
1.1046 raeburn 8393: <script type="text/javascript">
1.1032 www 8394: // <![CDATA[
8395: var $funcname = function()
8396: {
8397: modalWindow.windowId = "myModal";
8398: modalWindow.width = $width;
8399: modalWindow.height = $height;
8400: modalWindow.content = '$content';
8401: modalWindow.open();
8402: };
8403: // ]]>
8404: </script>
8405: ENDADHOC
8406: }
8407:
1.1041 www 8408: sub modal_adhoc_inner {
8409: my ($funcname,$width,$height,$content)=@_;
8410: my $innerwidth=$width-20;
8411: $content=&js_ready(
1.1042 www 8412: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 8413: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8414: $content.
1.1041 www 8415: &end_scrollbox().
1.1075.2.42 raeburn 8416: &end_page()
1.1041 www 8417: );
8418: return &modal_adhoc_script($funcname,$width,$height,$content);
8419: }
8420:
8421: sub modal_adhoc_window {
8422: my ($funcname,$width,$height,$content,$linktext)=@_;
8423: return &modal_adhoc_inner($funcname,$width,$height,$content).
8424: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8425: }
8426:
8427: sub modal_adhoc_launch {
8428: my ($funcname,$width,$height,$content)=@_;
8429: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8430: <script type="text/javascript">
8431: // <![CDATA[
8432: $funcname();
8433: // ]]>
8434: </script>
8435: ENDLAUNCH
8436: }
8437:
8438: sub modal_adhoc_close {
8439: return (<<ENDCLOSE);
8440: <script type="text/javascript">
8441: // <![CDATA[
8442: modalWindow.close();
8443: // ]]>
8444: </script>
8445: ENDCLOSE
8446: }
8447:
1.1038 www 8448: sub togglebox_script {
8449: return(<<ENDTOGGLE);
8450: <script type="text/javascript">
8451: // <![CDATA[
8452: function LCtoggleDisplay(id,hidetext,showtext) {
8453: link = document.getElementById(id + "link").childNodes[0];
8454: with (document.getElementById(id).style) {
8455: if (display == "none" ) {
8456: display = "inline";
8457: link.nodeValue = hidetext;
8458: } else {
8459: display = "none";
8460: link.nodeValue = showtext;
8461: }
8462: }
8463: }
8464: // ]]>
8465: </script>
8466: ENDTOGGLE
8467: }
8468:
1.1039 www 8469: sub start_togglebox {
8470: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8471: unless ($heading) { $heading=''; } else { $heading.=' '; }
8472: unless ($showtext) { $showtext=&mt('show'); }
8473: unless ($hidetext) { $hidetext=&mt('hide'); }
8474: unless ($headerbg) { $headerbg='#FFFFFF'; }
8475: return &start_data_table().
8476: &start_data_table_header_row().
8477: '<td bgcolor="'.$headerbg.'">'.$heading.
8478: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8479: $showtext.'\')">'.$showtext.'</a>]</td>'.
8480: &end_data_table_header_row().
8481: '<tr id="'.$id.'" style="display:none""><td>';
8482: }
8483:
8484: sub end_togglebox {
8485: return '</td></tr>'.&end_data_table();
8486: }
8487:
1.1041 www 8488: sub LCprogressbar_script {
1.1075.2.130 raeburn 8489: my ($id,$number_to_do)=@_;
8490: if ($number_to_do) {
8491: return(<<ENDPROGRESS);
1.1041 www 8492: <script type="text/javascript">
8493: // <![CDATA[
1.1045 www 8494: \$('#progressbar$id').progressbar({
1.1041 www 8495: value: 0,
8496: change: function(event, ui) {
8497: var newVal = \$(this).progressbar('option', 'value');
8498: \$('.pblabel', this).text(LCprogressTxt);
8499: }
8500: });
8501: // ]]>
8502: </script>
8503: ENDPROGRESS
1.1075.2.130 raeburn 8504: } else {
8505: return(<<ENDPROGRESS);
8506: <script type="text/javascript">
8507: // <![CDATA[
8508: \$('#progressbar$id').progressbar({
8509: value: false,
8510: create: function(event, ui) {
8511: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
8512: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
8513: }
8514: });
8515: // ]]>
8516: </script>
8517: ENDPROGRESS
8518: }
1.1041 www 8519: }
8520:
8521: sub LCprogressbarUpdate_script {
8522: return(<<ENDPROGRESSUPDATE);
8523: <style type="text/css">
8524: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 8525: .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 8526: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8527: </style>
8528: <script type="text/javascript">
8529: // <![CDATA[
1.1045 www 8530: var LCprogressTxt='---';
8531:
1.1075.2.130 raeburn 8532: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 8533: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 8534: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
8535: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
8536: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
8537: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
8538: } else {
8539: \$('#progressbar'+id).progressbar('value',percent);
8540: }
1.1041 www 8541: }
8542: // ]]>
8543: </script>
8544: ENDPROGRESSUPDATE
8545: }
8546:
1.1042 www 8547: my $LClastpercent;
1.1045 www 8548: my $LCidcnt;
8549: my $LCcurrentid;
1.1042 www 8550:
1.1041 www 8551: sub LCprogressbar {
1.1075.2.130 raeburn 8552: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 8553: $LClastpercent=0;
1.1045 www 8554: $LCidcnt++;
8555: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 8556: my ($starting,$content);
8557: if ($number_to_do) {
8558: $starting=&mt('Starting');
8559: $content=(<<ENDPROGBAR);
8560: $preamble
1.1045 www 8561: <div id="progressbar$LCcurrentid">
1.1041 www 8562: <span class="pblabel">$starting</span>
8563: </div>
8564: ENDPROGBAR
1.1075.2.130 raeburn 8565: } else {
8566: $starting=&mt('Loading...');
8567: $LClastpercent='false';
8568: $content=(<<ENDPROGBAR);
8569: $preamble
8570: <div id="progressbar$LCcurrentid">
8571: <div class="progress-label">$starting</div>
8572: </div>
8573: ENDPROGBAR
8574: }
8575: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 8576: }
8577:
8578: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 8579: my ($r,$val,$text,$number_to_do)=@_;
8580: if ($number_to_do) {
8581: unless ($val) {
8582: if ($LClastpercent) {
8583: $val=$LClastpercent;
8584: } else {
8585: $val=0;
8586: }
8587: }
8588: if ($val<0) { $val=0; }
8589: if ($val>100) { $val=0; }
8590: $LClastpercent=$val;
8591: unless ($text) { $text=$val.'%'; }
8592: } else {
8593: $val = 'false';
1.1042 www 8594: }
1.1041 www 8595: $text=&js_ready($text);
1.1044 www 8596: &r_print($r,<<ENDUPDATE);
1.1041 www 8597: <script type="text/javascript">
8598: // <![CDATA[
1.1075.2.130 raeburn 8599: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 8600: // ]]>
8601: </script>
8602: ENDUPDATE
1.1035 www 8603: }
8604:
1.1042 www 8605: sub LCprogressbarClose {
8606: my ($r)=@_;
8607: $LClastpercent=0;
1.1044 www 8608: &r_print($r,<<ENDCLOSE);
1.1042 www 8609: <script type="text/javascript">
8610: // <![CDATA[
1.1045 www 8611: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8612: // ]]>
8613: </script>
8614: ENDCLOSE
1.1044 www 8615: }
8616:
8617: sub r_print {
8618: my ($r,$to_print)=@_;
8619: if ($r) {
8620: $r->print($to_print);
8621: $r->rflush();
8622: } else {
8623: print($to_print);
8624: }
1.1042 www 8625: }
8626:
1.320 albertel 8627: sub html_encode {
8628: my ($result) = @_;
8629:
1.322 albertel 8630: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8631:
8632: return $result;
8633: }
1.1044 www 8634:
1.317 albertel 8635: sub js_ready {
8636: my ($result) = @_;
8637:
1.323 albertel 8638: $result =~ s/[\n\r]/ /xmsg;
8639: $result =~ s/\\/\\\\/xmsg;
8640: $result =~ s/'/\\'/xmsg;
1.372 albertel 8641: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8642:
8643: return $result;
8644: }
8645:
1.315 albertel 8646: sub validate_page {
8647: if ( exists($env{'internal.start_page'})
1.316 albertel 8648: && $env{'internal.start_page'} > 1) {
8649: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8650: $env{'internal.start_page'}.' '.
1.316 albertel 8651: $ENV{'request.filename'});
1.315 albertel 8652: }
8653: if ( exists($env{'internal.end_page'})
1.316 albertel 8654: && $env{'internal.end_page'} > 1) {
8655: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8656: $env{'internal.end_page'}.' '.
1.316 albertel 8657: $env{'request.filename'});
1.315 albertel 8658: }
8659: if ( exists($env{'internal.start_page'})
8660: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8661: &Apache::lonnet::logthis('start_page called without end_page '.
8662: $env{'request.filename'});
1.315 albertel 8663: }
8664: if ( ! exists($env{'internal.start_page'})
8665: && exists($env{'internal.end_page'})) {
1.316 albertel 8666: &Apache::lonnet::logthis('end_page called without start_page'.
8667: $env{'request.filename'});
1.315 albertel 8668: }
1.306 albertel 8669: }
1.315 albertel 8670:
1.996 www 8671:
8672: sub start_scrollbox {
1.1075.2.56 raeburn 8673: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8674: unless ($outerwidth) { $outerwidth='520px'; }
8675: unless ($width) { $width='500px'; }
8676: unless ($height) { $height='200px'; }
1.1075 raeburn 8677: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8678: if ($id ne '') {
1.1075.2.42 raeburn 8679: $table_id = ' id="table_'.$id.'"';
8680: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8681: }
1.1075 raeburn 8682: if ($bgcolor ne '') {
8683: $tdcol = "background-color: $bgcolor;";
8684: }
1.1075.2.42 raeburn 8685: my $nicescroll_js;
8686: if ($env{'browser.mobile'}) {
8687: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8688: }
1.1075 raeburn 8689: return <<"END";
1.1075.2.42 raeburn 8690: $nicescroll_js
8691:
8692: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8693: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8694: END
1.996 www 8695: }
8696:
8697: sub end_scrollbox {
1.1036 www 8698: return '</div></td></tr></table>';
1.996 www 8699: }
8700:
1.1075.2.42 raeburn 8701: sub nicescroll_javascript {
8702: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8703: my %options;
8704: if (ref($cursor) eq 'HASH') {
8705: %options = %{$cursor};
8706: }
8707: unless ($options{'railalign'} =~ /^left|right$/) {
8708: $options{'railalign'} = 'left';
8709: }
8710: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8711: my $function = &get_users_function();
8712: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8713: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8714: $options{'cursorcolor'} = '#00F';
8715: }
8716: }
8717: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8718: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8719: $options{'cursoropacity'}='1.0';
8720: }
8721: } else {
8722: $options{'cursoropacity'}='1.0';
8723: }
8724: if ($options{'cursorfixedheight'} eq 'none') {
8725: delete($options{'cursorfixedheight'});
8726: } else {
8727: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8728: }
8729: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8730: delete($options{'railoffset'});
8731: }
8732: my @niceoptions;
8733: while (my($key,$value) = each(%options)) {
8734: if ($value =~ /^\{.+\}$/) {
8735: push(@niceoptions,$key.':'.$value);
8736: } else {
8737: push(@niceoptions,$key.':"'.$value.'"');
8738: }
8739: }
8740: my $nicescroll_js = '
8741: $(document).ready(
8742: function() {
8743: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8744: }
8745: );
8746: ';
8747: if ($framecheck) {
8748: $nicescroll_js .= '
8749: function expand_div(caller) {
8750: if (top === self) {
8751: document.getElementById("'.$id.'").style.width = "auto";
8752: document.getElementById("'.$id.'").style.height = "auto";
8753: } else {
8754: try {
8755: if (parent.frames) {
8756: if (parent.frames.length > 1) {
8757: var framesrc = parent.frames[1].location.href;
8758: var currsrc = framesrc.replace(/\#.*$/,"");
8759: if ((caller == "search") || (currsrc == "'.$location.'")) {
8760: document.getElementById("'.$id.'").style.width = "auto";
8761: document.getElementById("'.$id.'").style.height = "auto";
8762: }
8763: }
8764: }
8765: } catch (e) {
8766: return;
8767: }
8768: }
8769: return;
8770: }
8771: ';
8772: }
8773: if ($needjsready) {
8774: $nicescroll_js = '
8775: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8776: } else {
8777: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8778: }
8779: return $nicescroll_js;
8780: }
8781:
1.318 albertel 8782: sub simple_error_page {
1.1075.2.49 raeburn 8783: my ($r,$title,$msg,$args) = @_;
8784: if (ref($args) eq 'HASH') {
8785: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8786: } else {
8787: $msg = &mt($msg);
8788: }
8789:
1.318 albertel 8790: my $page =
8791: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8792: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8793: &Apache::loncommon::end_page();
8794: if (ref($r)) {
8795: $r->print($page);
1.327 albertel 8796: return;
1.318 albertel 8797: }
8798: return $page;
8799: }
1.347 albertel 8800:
8801: {
1.610 albertel 8802: my @row_count;
1.961 onken 8803:
8804: sub start_data_table_count {
8805: unshift(@row_count, 0);
8806: return;
8807: }
8808:
8809: sub end_data_table_count {
8810: shift(@row_count);
8811: return;
8812: }
8813:
1.347 albertel 8814: sub start_data_table {
1.1018 raeburn 8815: my ($add_class,$id) = @_;
1.422 albertel 8816: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8817: my $table_id;
8818: if (defined($id)) {
8819: $table_id = ' id="'.$id.'"';
8820: }
1.961 onken 8821: &start_data_table_count();
1.1018 raeburn 8822: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8823: }
8824:
8825: sub end_data_table {
1.961 onken 8826: &end_data_table_count();
1.389 albertel 8827: return '</table>'."\n";;
1.347 albertel 8828: }
8829:
8830: sub start_data_table_row {
1.974 wenzelju 8831: my ($add_class, $id) = @_;
1.610 albertel 8832: $row_count[0]++;
8833: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8834: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8835: $id = (' id="'.$id.'"') unless ($id eq '');
8836: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8837: }
1.471 banghart 8838:
8839: sub continue_data_table_row {
1.974 wenzelju 8840: my ($add_class, $id) = @_;
1.610 albertel 8841: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8842: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8843: $id = (' id="'.$id.'"') unless ($id eq '');
8844: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8845: }
1.347 albertel 8846:
8847: sub end_data_table_row {
1.389 albertel 8848: return '</tr>'."\n";;
1.347 albertel 8849: }
1.367 www 8850:
1.421 albertel 8851: sub start_data_table_empty_row {
1.707 bisitz 8852: # $row_count[0]++;
1.421 albertel 8853: return '<tr class="LC_empty_row" >'."\n";;
8854: }
8855:
8856: sub end_data_table_empty_row {
8857: return '</tr>'."\n";;
8858: }
8859:
1.367 www 8860: sub start_data_table_header_row {
1.389 albertel 8861: return '<tr class="LC_header_row">'."\n";;
1.367 www 8862: }
8863:
8864: sub end_data_table_header_row {
1.389 albertel 8865: return '</tr>'."\n";;
1.367 www 8866: }
1.890 droeschl 8867:
8868: sub data_table_caption {
8869: my $caption = shift;
8870: return "<caption class=\"LC_caption\">$caption</caption>";
8871: }
1.347 albertel 8872: }
8873:
1.548 albertel 8874: =pod
8875:
8876: =item * &inhibit_menu_check($arg)
8877:
8878: Checks for a inhibitmenu state and generates output to preserve it
8879:
8880: Inputs: $arg - can be any of
8881: - undef - in which case the return value is a string
8882: to add into arguments list of a uri
8883: - 'input' - in which case the return value is a HTML
8884: <form> <input> field of type hidden to
8885: preserve the value
8886: - a url - in which case the return value is the url with
8887: the neccesary cgi args added to preserve the
8888: inhibitmenu state
8889: - a ref to a url - no return value, but the string is
8890: updated to include the neccessary cgi
8891: args to preserve the inhibitmenu state
8892:
8893: =cut
8894:
8895: sub inhibit_menu_check {
8896: my ($arg) = @_;
8897: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8898: if ($arg eq 'input') {
8899: if ($env{'form.inhibitmenu'}) {
8900: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8901: } else {
8902: return
8903: }
8904: }
8905: if ($env{'form.inhibitmenu'}) {
8906: if (ref($arg)) {
8907: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8908: } elsif ($arg eq '') {
8909: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8910: } else {
8911: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8912: }
8913: }
8914: if (!ref($arg)) {
8915: return $arg;
8916: }
8917: }
8918:
1.251 albertel 8919: ###############################################
1.182 matthew 8920:
8921: =pod
8922:
1.549 albertel 8923: =back
8924:
8925: =head1 User Information Routines
8926:
8927: =over 4
8928:
1.405 albertel 8929: =item * &get_users_function()
1.182 matthew 8930:
8931: Used by &bodytag to determine the current users primary role.
8932: Returns either 'student','coordinator','admin', or 'author'.
8933:
8934: =cut
8935:
8936: ###############################################
8937: sub get_users_function {
1.815 tempelho 8938: my $function = 'norole';
1.818 tempelho 8939: if ($env{'request.role'}=~/^(st)/) {
8940: $function='student';
8941: }
1.907 raeburn 8942: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8943: $function='coordinator';
8944: }
1.258 albertel 8945: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8946: $function='admin';
8947: }
1.826 bisitz 8948: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8949: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8950: $function='author';
8951: }
8952: return $function;
1.54 www 8953: }
1.99 www 8954:
8955: ###############################################
8956:
1.233 raeburn 8957: =pod
8958:
1.821 raeburn 8959: =item * &show_course()
8960:
8961: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8962: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8963:
8964: Inputs:
8965: None
8966:
8967: Outputs:
8968: Scalar: 1 if 'Course' to be used, 0 otherwise.
8969:
8970: =cut
8971:
8972: ###############################################
8973: sub show_course {
8974: my $course = !$env{'user.adv'};
8975: if (!$env{'user.adv'}) {
8976: foreach my $env (keys(%env)) {
8977: next if ($env !~ m/^user\.priv\./);
8978: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8979: $course = 0;
8980: last;
8981: }
8982: }
8983: }
8984: return $course;
8985: }
8986:
8987: ###############################################
8988:
8989: =pod
8990:
1.542 raeburn 8991: =item * &check_user_status()
1.274 raeburn 8992:
8993: Determines current status of supplied role for a
8994: specific user. Roles can be active, previous or future.
8995:
8996: Inputs:
8997: user's domain, user's username, course's domain,
1.375 raeburn 8998: course's number, optional section ID.
1.274 raeburn 8999:
9000: Outputs:
9001: role status: active, previous or future.
9002:
9003: =cut
9004:
9005: sub check_user_status {
1.412 raeburn 9006: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9007: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 9008: my @uroles = keys(%userinfo);
1.274 raeburn 9009: my $srchstr;
9010: my $active_chk = 'none';
1.412 raeburn 9011: my $now = time;
1.274 raeburn 9012: if (@uroles > 0) {
1.908 raeburn 9013: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9014: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9015: } else {
1.412 raeburn 9016: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9017: }
9018: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9019: my $role_end = 0;
9020: my $role_start = 0;
9021: $active_chk = 'active';
1.412 raeburn 9022: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9023: $role_end = $1;
9024: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9025: $role_start = $1;
1.274 raeburn 9026: }
9027: }
9028: if ($role_start > 0) {
1.412 raeburn 9029: if ($now < $role_start) {
1.274 raeburn 9030: $active_chk = 'future';
9031: }
9032: }
9033: if ($role_end > 0) {
1.412 raeburn 9034: if ($now > $role_end) {
1.274 raeburn 9035: $active_chk = 'previous';
9036: }
9037: }
9038: }
9039: }
9040: return $active_chk;
9041: }
9042:
9043: ###############################################
9044:
9045: =pod
9046:
1.405 albertel 9047: =item * &get_sections()
1.233 raeburn 9048:
9049: Determines all the sections for a course including
9050: sections with students and sections containing other roles.
1.419 raeburn 9051: Incoming parameters:
9052:
9053: 1. domain
9054: 2. course number
9055: 3. reference to array containing roles for which sections should
9056: be gathered (optional).
9057: 4. reference to array containing status types for which sections
9058: should be gathered (optional).
9059:
9060: If the third argument is undefined, sections are gathered for any role.
9061: If the fourth argument is undefined, sections are gathered for any status.
9062: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9063:
1.374 raeburn 9064: Returns section hash (keys are section IDs, values are
9065: number of users in each section), subject to the
1.419 raeburn 9066: optional roles filter, optional status filter
1.233 raeburn 9067:
9068: =cut
9069:
9070: ###############################################
9071: sub get_sections {
1.419 raeburn 9072: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9073: if (!defined($cdom) || !defined($cnum)) {
9074: my $cid = $env{'request.course.id'};
9075:
9076: return if (!defined($cid));
9077:
9078: $cdom = $env{'course.'.$cid.'.domain'};
9079: $cnum = $env{'course.'.$cid.'.num'};
9080: }
9081:
9082: my %sectioncount;
1.419 raeburn 9083: my $now = time;
1.240 albertel 9084:
1.1075.2.33 raeburn 9085: my $check_students = 1;
9086: my $only_students = 0;
9087: if (ref($possible_roles) eq 'ARRAY') {
9088: if (grep(/^st$/,@{$possible_roles})) {
9089: if (@{$possible_roles} == 1) {
9090: $only_students = 1;
9091: }
9092: } else {
9093: $check_students = 0;
9094: }
9095: }
9096:
9097: if ($check_students) {
1.276 albertel 9098: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9099: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9100: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9101: my $start_index = &Apache::loncoursedata::CL_START();
9102: my $end_index = &Apache::loncoursedata::CL_END();
9103: my $status;
1.366 albertel 9104: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9105: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9106: $data->[$status_index],
9107: $data->[$start_index],
9108: $data->[$end_index]);
9109: if ($stu_status eq 'Active') {
9110: $status = 'active';
9111: } elsif ($end < $now) {
9112: $status = 'previous';
9113: } elsif ($start > $now) {
9114: $status = 'future';
9115: }
9116: if ($section ne '-1' && $section !~ /^\s*$/) {
9117: if ((!defined($possible_status)) || (($status ne '') &&
9118: (grep/^\Q$status\E$/,@{$possible_status}))) {
9119: $sectioncount{$section}++;
9120: }
1.240 albertel 9121: }
9122: }
9123: }
1.1075.2.33 raeburn 9124: if ($only_students) {
9125: return %sectioncount;
9126: }
1.240 albertel 9127: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9128: foreach my $user (sort(keys(%courseroles))) {
9129: if ($user !~ /^(\w{2})/) { next; }
9130: my ($role) = ($user =~ /^(\w{2})/);
9131: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9132: my ($section,$status);
1.240 albertel 9133: if ($role eq 'cr' &&
9134: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9135: $section=$1;
9136: }
9137: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9138: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9139: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9140: if ($end == -1 && $start == -1) {
9141: next; #deleted role
9142: }
9143: if (!defined($possible_status)) {
9144: $sectioncount{$section}++;
9145: } else {
9146: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9147: $status = 'active';
9148: } elsif ($end < $now) {
9149: $status = 'future';
9150: } elsif ($start > $now) {
9151: $status = 'previous';
9152: }
9153: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9154: $sectioncount{$section}++;
9155: }
9156: }
1.233 raeburn 9157: }
1.366 albertel 9158: return %sectioncount;
1.233 raeburn 9159: }
9160:
1.274 raeburn 9161: ###############################################
1.294 raeburn 9162:
9163: =pod
1.405 albertel 9164:
9165: =item * &get_course_users()
9166:
1.275 raeburn 9167: Retrieves usernames:domains for users in the specified course
9168: with specific role(s), and access status.
9169:
9170: Incoming parameters:
1.277 albertel 9171: 1. course domain
9172: 2. course number
9173: 3. access status: users must have - either active,
1.275 raeburn 9174: previous, future, or all.
1.277 albertel 9175: 4. reference to array of permissible roles
1.288 raeburn 9176: 5. reference to array of section restrictions (optional)
9177: 6. reference to results object (hash of hashes).
9178: 7. reference to optional userdata hash
1.609 raeburn 9179: 8. reference to optional statushash
1.630 raeburn 9180: 9. flag if privileged users (except those set to unhide in
9181: course settings) should be excluded
1.609 raeburn 9182: Keys of top level results hash are roles.
1.275 raeburn 9183: Keys of inner hashes are username:domain, with
9184: values set to access type.
1.288 raeburn 9185: Optional userdata hash returns an array with arguments in the
9186: same order as loncoursedata::get_classlist() for student data.
9187:
1.609 raeburn 9188: Optional statushash returns
9189:
1.288 raeburn 9190: Entries for end, start, section and status are blank because
9191: of the possibility of multiple values for non-student roles.
9192:
1.275 raeburn 9193: =cut
1.405 albertel 9194:
1.275 raeburn 9195: ###############################################
1.405 albertel 9196:
1.275 raeburn 9197: sub get_course_users {
1.630 raeburn 9198: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9199: my %idx = ();
1.419 raeburn 9200: my %seclists;
1.288 raeburn 9201:
9202: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9203: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9204: $idx{end} = &Apache::loncoursedata::CL_END();
9205: $idx{start} = &Apache::loncoursedata::CL_START();
9206: $idx{id} = &Apache::loncoursedata::CL_ID();
9207: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9208: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9209: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9210:
1.290 albertel 9211: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9212: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9213: my $now = time;
1.277 albertel 9214: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9215: my $match = 0;
1.412 raeburn 9216: my $secmatch = 0;
1.419 raeburn 9217: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9218: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9219: if ($section eq '') {
9220: $section = 'none';
9221: }
1.291 albertel 9222: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9223: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9224: $secmatch = 1;
9225: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9226: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9227: $secmatch = 1;
9228: }
9229: } else {
1.419 raeburn 9230: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9231: $secmatch = 1;
9232: }
1.290 albertel 9233: }
1.412 raeburn 9234: if (!$secmatch) {
9235: next;
9236: }
1.419 raeburn 9237: }
1.275 raeburn 9238: if (defined($$types{'active'})) {
1.288 raeburn 9239: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9240: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9241: $match = 1;
1.275 raeburn 9242: }
9243: }
9244: if (defined($$types{'previous'})) {
1.609 raeburn 9245: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9246: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9247: $match = 1;
1.275 raeburn 9248: }
9249: }
9250: if (defined($$types{'future'})) {
1.609 raeburn 9251: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9252: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9253: $match = 1;
1.275 raeburn 9254: }
9255: }
1.609 raeburn 9256: if ($match) {
9257: push(@{$seclists{$student}},$section);
9258: if (ref($userdata) eq 'HASH') {
9259: $$userdata{$student} = $$classlist{$student};
9260: }
9261: if (ref($statushash) eq 'HASH') {
9262: $statushash->{$student}{'st'}{$section} = $status;
9263: }
1.288 raeburn 9264: }
1.275 raeburn 9265: }
9266: }
1.412 raeburn 9267: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9268: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9269: my $now = time;
1.609 raeburn 9270: my %displaystatus = ( previous => 'Expired',
9271: active => 'Active',
9272: future => 'Future',
9273: );
1.1075.2.36 raeburn 9274: my (%nothide,@possdoms);
1.630 raeburn 9275: if ($hidepriv) {
9276: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9277: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9278: if ($user !~ /:/) {
9279: $nothide{join(':',split(/[\@]/,$user))}=1;
9280: } else {
9281: $nothide{$user} = 1;
9282: }
9283: }
1.1075.2.36 raeburn 9284: my @possdoms = ($cdom);
9285: if ($coursehash{'checkforpriv'}) {
9286: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9287: }
1.630 raeburn 9288: }
1.439 raeburn 9289: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9290: my $match = 0;
1.412 raeburn 9291: my $secmatch = 0;
1.439 raeburn 9292: my $status;
1.412 raeburn 9293: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9294: $user =~ s/:$//;
1.439 raeburn 9295: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9296: if ($end == -1 || $start == -1) {
9297: next;
9298: }
9299: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9300: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9301: my ($uname,$udom) = split(/:/,$user);
9302: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9303: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9304: $secmatch = 1;
9305: } elsif ($usec eq '') {
1.420 albertel 9306: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9307: $secmatch = 1;
9308: }
9309: } else {
9310: if (grep(/^\Q$usec\E$/,@{$sections})) {
9311: $secmatch = 1;
9312: }
9313: }
9314: if (!$secmatch) {
9315: next;
9316: }
1.288 raeburn 9317: }
1.419 raeburn 9318: if ($usec eq '') {
9319: $usec = 'none';
9320: }
1.275 raeburn 9321: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9322: if ($hidepriv) {
1.1075.2.36 raeburn 9323: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9324: (!$nothide{$uname.':'.$udom})) {
9325: next;
9326: }
9327: }
1.503 raeburn 9328: if ($end > 0 && $end < $now) {
1.439 raeburn 9329: $status = 'previous';
9330: } elsif ($start > $now) {
9331: $status = 'future';
9332: } else {
9333: $status = 'active';
9334: }
1.277 albertel 9335: foreach my $type (keys(%{$types})) {
1.275 raeburn 9336: if ($status eq $type) {
1.420 albertel 9337: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9338: push(@{$$users{$role}{$user}},$type);
9339: }
1.288 raeburn 9340: $match = 1;
9341: }
9342: }
1.419 raeburn 9343: if (($match) && (ref($userdata) eq 'HASH')) {
9344: if (!exists($$userdata{$uname.':'.$udom})) {
9345: &get_user_info($udom,$uname,\%idx,$userdata);
9346: }
1.420 albertel 9347: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9348: push(@{$seclists{$uname.':'.$udom}},$usec);
9349: }
1.609 raeburn 9350: if (ref($statushash) eq 'HASH') {
9351: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9352: }
1.275 raeburn 9353: }
9354: }
9355: }
9356: }
1.290 albertel 9357: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9358: if ((defined($cdom)) && (defined($cnum))) {
9359: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9360: if ( defined($csettings{'internal.courseowner'}) ) {
9361: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9362: next if ($owner eq '');
9363: my ($ownername,$ownerdom);
9364: if ($owner =~ /^([^:]+):([^:]+)$/) {
9365: $ownername = $1;
9366: $ownerdom = $2;
9367: } else {
9368: $ownername = $owner;
9369: $ownerdom = $cdom;
9370: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9371: }
9372: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9373: if (defined($userdata) &&
1.609 raeburn 9374: !exists($$userdata{$owner})) {
9375: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9376: if (!grep(/^none$/,@{$seclists{$owner}})) {
9377: push(@{$seclists{$owner}},'none');
9378: }
9379: if (ref($statushash) eq 'HASH') {
9380: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9381: }
1.290 albertel 9382: }
1.279 raeburn 9383: }
9384: }
9385: }
1.419 raeburn 9386: foreach my $user (keys(%seclists)) {
9387: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9388: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9389: }
1.275 raeburn 9390: }
9391: return;
9392: }
9393:
1.288 raeburn 9394: sub get_user_info {
9395: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9396: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9397: &plainname($uname,$udom,'lastname');
1.291 albertel 9398: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9399: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9400: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9401: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9402: return;
9403: }
1.275 raeburn 9404:
1.472 raeburn 9405: ###############################################
9406:
9407: =pod
9408:
9409: =item * &get_user_quota()
9410:
1.1075.2.41 raeburn 9411: Retrieves quota assigned for storage of user files.
9412: Default is to report quota for portfolio files.
1.472 raeburn 9413:
9414: Incoming parameters:
9415: 1. user's username
9416: 2. user's domain
1.1075.2.41 raeburn 9417: 3. quota name - portfolio, author, or course
9418: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 9419: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 9420: course
1.472 raeburn 9421:
9422: Returns:
1.1075.2.58 raeburn 9423: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9424: 2. (Optional) Type of setting: custom or default
9425: (individually assigned or default for user's
9426: institutional status).
9427: 3. (Optional) - User's institutional status (e.g., faculty, staff
9428: or student - types as defined in localenroll::inst_usertypes
9429: for user's domain, which determines default quota for user.
9430: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9431:
9432: If a value has been stored in the user's environment,
1.536 raeburn 9433: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 9434: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9435:
9436: =cut
9437:
9438: ###############################################
9439:
9440:
9441: sub get_user_quota {
1.1075.2.42 raeburn 9442: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9443: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9444: if (!defined($udom)) {
9445: $udom = $env{'user.domain'};
9446: }
9447: if (!defined($uname)) {
9448: $uname = $env{'user.name'};
9449: }
9450: if (($udom eq '' || $uname eq '') ||
9451: ($udom eq 'public') && ($uname eq 'public')) {
9452: $quota = 0;
1.536 raeburn 9453: $quotatype = 'default';
9454: $defquota = 0;
1.472 raeburn 9455: } else {
1.536 raeburn 9456: my $inststatus;
1.1075.2.41 raeburn 9457: if ($quotaname eq 'course') {
9458: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9459: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9460: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9461: } else {
9462: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9463: $quota = $cenv{'internal.uploadquota'};
9464: }
1.536 raeburn 9465: } else {
1.1075.2.41 raeburn 9466: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9467: if ($quotaname eq 'author') {
9468: $quota = $env{'environment.authorquota'};
9469: } else {
9470: $quota = $env{'environment.portfolioquota'};
9471: }
9472: $inststatus = $env{'environment.inststatus'};
9473: } else {
9474: my %userenv =
9475: &Apache::lonnet::get('environment',['portfolioquota',
9476: 'authorquota','inststatus'],$udom,$uname);
9477: my ($tmp) = keys(%userenv);
9478: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9479: if ($quotaname eq 'author') {
9480: $quota = $userenv{'authorquota'};
9481: } else {
9482: $quota = $userenv{'portfolioquota'};
9483: }
9484: $inststatus = $userenv{'inststatus'};
9485: } else {
9486: undef(%userenv);
9487: }
9488: }
9489: }
9490: if ($quota eq '' || wantarray) {
9491: if ($quotaname eq 'course') {
9492: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 9493: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9494: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 9495: $defquota = $domdefs{$crstype.'quota'};
9496: }
9497: if ($defquota eq '') {
9498: $defquota = 500;
9499: }
1.1075.2.41 raeburn 9500: } else {
9501: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9502: }
9503: if ($quota eq '') {
9504: $quota = $defquota;
9505: $quotatype = 'default';
9506: } else {
9507: $quotatype = 'custom';
9508: }
1.472 raeburn 9509: }
9510: }
1.536 raeburn 9511: if (wantarray) {
9512: return ($quota,$quotatype,$settingstatus,$defquota);
9513: } else {
9514: return $quota;
9515: }
1.472 raeburn 9516: }
9517:
9518: ###############################################
9519:
9520: =pod
9521:
9522: =item * &default_quota()
9523:
1.536 raeburn 9524: Retrieves default quota assigned for storage of user portfolio files,
9525: given an (optional) user's institutional status.
1.472 raeburn 9526:
9527: Incoming parameters:
1.1075.2.42 raeburn 9528:
1.472 raeburn 9529: 1. domain
1.536 raeburn 9530: 2. (Optional) institutional status(es). This is a : separated list of
9531: status types (e.g., faculty, staff, student etc.)
9532: which apply to the user for whom the default is being retrieved.
9533: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9534: default quota will be returned.
9535: 3. quota name - portfolio, author, or course
9536: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9537:
9538: Returns:
1.1075.2.42 raeburn 9539:
1.1075.2.58 raeburn 9540: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9541: 2. (Optional) institutional type which determined the value of the
9542: default quota.
1.472 raeburn 9543:
9544: If a value has been stored in the domain's configuration db,
9545: it will return that, otherwise it returns 20 (for backwards
9546: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9547: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9548:
1.536 raeburn 9549: If the user's status includes multiple types (e.g., staff and student),
9550: the largest default quota which applies to the user determines the
9551: default quota returned.
9552:
1.472 raeburn 9553: =cut
9554:
9555: ###############################################
9556:
9557:
9558: sub default_quota {
1.1075.2.41 raeburn 9559: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9560: my ($defquota,$settingstatus);
9561: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9562: ['quotas'],$udom);
1.1075.2.41 raeburn 9563: my $key = 'defaultquota';
9564: if ($quotaname eq 'author') {
9565: $key = 'authorquota';
9566: }
1.622 raeburn 9567: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9568: if ($inststatus ne '') {
1.765 raeburn 9569: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9570: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9571: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9572: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9573: if ($defquota eq '') {
1.1075.2.41 raeburn 9574: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9575: $settingstatus = $item;
1.1075.2.41 raeburn 9576: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9577: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9578: $settingstatus = $item;
9579: }
9580: }
1.1075.2.41 raeburn 9581: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9582: if ($quotahash{'quotas'}{$item} ne '') {
9583: if ($defquota eq '') {
9584: $defquota = $quotahash{'quotas'}{$item};
9585: $settingstatus = $item;
9586: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9587: $defquota = $quotahash{'quotas'}{$item};
9588: $settingstatus = $item;
9589: }
1.536 raeburn 9590: }
9591: }
9592: }
9593: }
9594: if ($defquota eq '') {
1.1075.2.41 raeburn 9595: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9596: $defquota = $quotahash{'quotas'}{$key}{'default'};
9597: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9598: $defquota = $quotahash{'quotas'}{'default'};
9599: }
1.536 raeburn 9600: $settingstatus = 'default';
1.1075.2.42 raeburn 9601: if ($defquota eq '') {
9602: if ($quotaname eq 'author') {
9603: $defquota = 500;
9604: }
9605: }
1.536 raeburn 9606: }
9607: } else {
9608: $settingstatus = 'default';
1.1075.2.41 raeburn 9609: if ($quotaname eq 'author') {
9610: $defquota = 500;
9611: } else {
9612: $defquota = 20;
9613: }
1.536 raeburn 9614: }
9615: if (wantarray) {
9616: return ($defquota,$settingstatus);
1.472 raeburn 9617: } else {
1.536 raeburn 9618: return $defquota;
1.472 raeburn 9619: }
9620: }
9621:
1.1075.2.41 raeburn 9622: ###############################################
9623:
9624: =pod
9625:
1.1075.2.42 raeburn 9626: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9627:
9628: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9629: of existing file within authoring space will cause quota for the authoring
9630: space to be exceeded.
9631:
9632: Same, if upload of a file directly to a course/community via Course Editor
9633: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9634:
1.1075.2.61 raeburn 9635: Inputs: 7
1.1075.2.42 raeburn 9636: 1. username or coursenum
1.1075.2.41 raeburn 9637: 2. domain
1.1075.2.42 raeburn 9638: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9639: 4. filename of file for which action is being requested
9640: 5. filesize (kB) of file
9641: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9642: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9643:
9644: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9645: otherwise return null.
9646:
1.1075.2.42 raeburn 9647: =back
9648:
1.1075.2.41 raeburn 9649: =cut
9650:
1.1075.2.42 raeburn 9651: sub excess_filesize_warning {
1.1075.2.59 raeburn 9652: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9653: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9654: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9655: if ($context eq 'author') {
9656: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9657: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9658: } else {
9659: foreach my $subdir ('docs','supplemental') {
9660: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9661: }
9662: }
1.1075.2.41 raeburn 9663: $disk_quota = int($disk_quota * 1000);
9664: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9665: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9666: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9667: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9668: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9669: $disk_quota,$current_disk_usage).
9670: '</p>';
9671: }
9672: return;
9673: }
9674:
9675: ###############################################
9676:
9677:
1.384 raeburn 9678: sub get_secgrprole_info {
9679: my ($cdom,$cnum,$needroles,$type) = @_;
9680: my %sections_count = &get_sections($cdom,$cnum);
9681: my @sections = (sort {$a <=> $b} keys(%sections_count));
9682: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9683: my @groups = sort(keys(%curr_groups));
9684: my $allroles = [];
9685: my $rolehash;
9686: my $accesshash = {
9687: active => 'Currently has access',
9688: future => 'Will have future access',
9689: previous => 'Previously had access',
9690: };
9691: if ($needroles) {
9692: $rolehash = {'all' => 'all'};
1.385 albertel 9693: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9694: if (&Apache::lonnet::error(%user_roles)) {
9695: undef(%user_roles);
9696: }
9697: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9698: my ($role)=split(/\:/,$item,2);
9699: if ($role eq 'cr') { next; }
9700: if ($role =~ /^cr/) {
9701: $$rolehash{$role} = (split('/',$role))[3];
9702: } else {
9703: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9704: }
9705: }
9706: foreach my $key (sort(keys(%{$rolehash}))) {
9707: push(@{$allroles},$key);
9708: }
9709: push (@{$allroles},'st');
9710: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9711: }
9712: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9713: }
9714:
1.555 raeburn 9715: sub user_picker {
1.1075.2.127 raeburn 9716: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 9717: my $currdom = $dom;
1.1075.2.114 raeburn 9718: my @alldoms = &Apache::lonnet::all_domains();
9719: if (@alldoms == 1) {
9720: my %domsrch = &Apache::lonnet::get_dom('configuration',
9721: ['directorysrch'],$alldoms[0]);
9722: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
9723: my $showdom = $domdesc;
9724: if ($showdom eq '') {
9725: $showdom = $dom;
9726: }
9727: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
9728: if ((!$domsrch{'directorysrch'}{'available'}) &&
9729: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
9730: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
9731: }
9732: }
9733: }
1.555 raeburn 9734: my %curr_selected = (
9735: srchin => 'dom',
1.580 raeburn 9736: srchby => 'lastname',
1.555 raeburn 9737: );
9738: my $srchterm;
1.625 raeburn 9739: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9740: if ($srch->{'srchby'} ne '') {
9741: $curr_selected{'srchby'} = $srch->{'srchby'};
9742: }
9743: if ($srch->{'srchin'} ne '') {
9744: $curr_selected{'srchin'} = $srch->{'srchin'};
9745: }
9746: if ($srch->{'srchtype'} ne '') {
9747: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9748: }
9749: if ($srch->{'srchdomain'} ne '') {
9750: $currdom = $srch->{'srchdomain'};
9751: }
9752: $srchterm = $srch->{'srchterm'};
9753: }
1.1075.2.98 raeburn 9754: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 9755: 'usr' => 'Search criteria',
1.563 raeburn 9756: 'doma' => 'Domain/institution to search',
1.558 albertel 9757: 'uname' => 'username',
9758: 'lastname' => 'last name',
1.555 raeburn 9759: 'lastfirst' => 'last name, first name',
1.558 albertel 9760: 'crs' => 'in this course',
1.576 raeburn 9761: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9762: 'alc' => 'all LON-CAPA',
1.573 raeburn 9763: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9764: 'exact' => 'is',
9765: 'contains' => 'contains',
1.569 raeburn 9766: 'begins' => 'begins with',
1.1075.2.98 raeburn 9767: );
9768: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 9769: 'youm' => "You must include some text to search for.",
9770: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9771: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9772: 'yomc' => "You must choose a domain when using an institutional directory search.",
9773: 'ymcd' => "You must choose a domain when using a domain search.",
9774: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9775: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9776: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9777: );
1.1075.2.98 raeburn 9778: &html_escape(\%html_lt);
9779: &js_escape(\%js_lt);
1.1075.2.115 raeburn 9780: my $domform;
1.1075.2.126 raeburn 9781: my $allow_blank = 1;
1.1075.2.115 raeburn 9782: if ($fixeddom) {
1.1075.2.126 raeburn 9783: $allow_blank = 0;
9784: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 9785: } else {
1.1075.2.126 raeburn 9786: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 9787: }
1.563 raeburn 9788: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9789:
9790: my @srchins = ('crs','dom','alc','instd');
9791:
9792: foreach my $option (@srchins) {
9793: # FIXME 'alc' option unavailable until
9794: # loncreateuser::print_user_query_page()
9795: # has been completed.
9796: next if ($option eq 'alc');
1.880 raeburn 9797: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9798: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 9799: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 9800: if ($curr_selected{'srchin'} eq $option) {
9801: $srchinsel .= '
1.1075.2.98 raeburn 9802: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 9803: } else {
9804: $srchinsel .= '
1.1075.2.98 raeburn 9805: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 9806: }
1.555 raeburn 9807: }
1.563 raeburn 9808: $srchinsel .= "\n </select>\n";
1.555 raeburn 9809:
9810: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9811: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9812: if ($curr_selected{'srchby'} eq $option) {
9813: $srchbysel .= '
1.1075.2.98 raeburn 9814: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9815: } else {
9816: $srchbysel .= '
1.1075.2.98 raeburn 9817: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9818: }
9819: }
9820: $srchbysel .= "\n </select>\n";
9821:
9822: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9823: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9824: if ($curr_selected{'srchtype'} eq $option) {
9825: $srchtypesel .= '
1.1075.2.98 raeburn 9826: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9827: } else {
9828: $srchtypesel .= '
1.1075.2.98 raeburn 9829: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9830: }
9831: }
9832: $srchtypesel .= "\n </select>\n";
9833:
1.558 albertel 9834: my ($newuserscript,$new_user_create);
1.994 raeburn 9835: my $context_dom = $env{'request.role.domain'};
9836: if ($context eq 'requestcrs') {
9837: if ($env{'form.coursedom'} ne '') {
9838: $context_dom = $env{'form.coursedom'};
9839: }
9840: }
1.556 raeburn 9841: if ($forcenewuser) {
1.576 raeburn 9842: if (ref($srch) eq 'HASH') {
1.994 raeburn 9843: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9844: if ($cancreate) {
9845: $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>';
9846: } else {
1.799 bisitz 9847: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9848: my %usertypetext = (
9849: official => 'institutional',
9850: unofficial => 'non-institutional',
9851: );
1.799 bisitz 9852: $new_user_create = '<p class="LC_warning">'
9853: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9854: .' '
9855: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9856: ,'<a href="'.$helplink.'">','</a>')
9857: .'</p><br />';
1.627 raeburn 9858: }
1.576 raeburn 9859: }
9860: }
9861:
1.556 raeburn 9862: $newuserscript = <<"ENDSCRIPT";
9863:
1.570 raeburn 9864: function setSearch(createnew,callingForm) {
1.556 raeburn 9865: if (createnew == 1) {
1.570 raeburn 9866: for (var i=0; i<callingForm.srchby.length; i++) {
9867: if (callingForm.srchby.options[i].value == 'uname') {
9868: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9869: }
9870: }
1.570 raeburn 9871: for (var i=0; i<callingForm.srchin.length; i++) {
9872: if ( callingForm.srchin.options[i].value == 'dom') {
9873: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9874: }
9875: }
1.570 raeburn 9876: for (var i=0; i<callingForm.srchtype.length; i++) {
9877: if (callingForm.srchtype.options[i].value == 'exact') {
9878: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9879: }
9880: }
1.570 raeburn 9881: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9882: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9883: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9884: }
9885: }
9886: }
9887: }
9888: ENDSCRIPT
1.558 albertel 9889:
1.556 raeburn 9890: }
9891:
1.555 raeburn 9892: my $output = <<"END_BLOCK";
1.556 raeburn 9893: <script type="text/javascript">
1.824 bisitz 9894: // <![CDATA[
1.570 raeburn 9895: function validateEntry(callingForm) {
1.558 albertel 9896:
1.556 raeburn 9897: var checkok = 1;
1.558 albertel 9898: var srchin;
1.570 raeburn 9899: for (var i=0; i<callingForm.srchin.length; i++) {
9900: if ( callingForm.srchin[i].checked ) {
9901: srchin = callingForm.srchin[i].value;
1.558 albertel 9902: }
9903: }
9904:
1.570 raeburn 9905: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9906: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9907: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9908: var srchterm = callingForm.srchterm.value;
9909: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9910: var msg = "";
9911:
9912: if (srchterm == "") {
9913: checkok = 0;
1.1075.2.98 raeburn 9914: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 9915: }
9916:
1.569 raeburn 9917: if (srchtype== 'begins') {
9918: if (srchterm.length < 2) {
9919: checkok = 0;
1.1075.2.98 raeburn 9920: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 9921: }
9922: }
9923:
1.556 raeburn 9924: if (srchtype== 'contains') {
9925: if (srchterm.length < 3) {
9926: checkok = 0;
1.1075.2.98 raeburn 9927: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 9928: }
9929: }
9930: if (srchin == 'instd') {
9931: if (srchdomain == '') {
9932: checkok = 0;
1.1075.2.98 raeburn 9933: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 9934: }
9935: }
9936: if (srchin == 'dom') {
9937: if (srchdomain == '') {
9938: checkok = 0;
1.1075.2.98 raeburn 9939: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 9940: }
9941: }
9942: if (srchby == 'lastfirst') {
9943: if (srchterm.indexOf(",") == -1) {
9944: checkok = 0;
1.1075.2.98 raeburn 9945: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 9946: }
9947: if (srchterm.indexOf(",") == srchterm.length -1) {
9948: checkok = 0;
1.1075.2.98 raeburn 9949: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 9950: }
9951: }
9952: if (checkok == 0) {
1.1075.2.98 raeburn 9953: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 9954: return;
9955: }
9956: if (checkok == 1) {
1.570 raeburn 9957: callingForm.submit();
1.556 raeburn 9958: }
9959: }
9960:
9961: $newuserscript
9962:
1.824 bisitz 9963: // ]]>
1.556 raeburn 9964: </script>
1.558 albertel 9965:
9966: $new_user_create
9967:
1.555 raeburn 9968: END_BLOCK
1.558 albertel 9969:
1.876 raeburn 9970: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 9971: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 9972: $domform.
9973: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 9974: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 9975: $srchbysel.
9976: $srchtypesel.
9977: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9978: $srchinsel.
9979: &Apache::lonhtmlcommon::row_closure(1).
9980: &Apache::lonhtmlcommon::end_pick_box().
9981: '<br />';
1.1075.2.114 raeburn 9982: return ($output,1);
1.555 raeburn 9983: }
9984:
1.612 raeburn 9985: sub user_rule_check {
1.615 raeburn 9986: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 9987: my ($response,%inst_response);
1.612 raeburn 9988: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 9989: if (keys(%{$usershash}) > 1) {
9990: my (%by_username,%by_id,%userdoms);
9991: my $checkid;
1.612 raeburn 9992: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 9993: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
9994: $checkid = 1;
9995: }
9996: }
9997: foreach my $user (keys(%{$usershash})) {
9998: my ($uname,$udom) = split(/:/,$user);
9999: if ($checkid) {
10000: if (ref($usershash->{$user}) eq 'HASH') {
10001: if ($usershash->{$user}->{'id'} ne '') {
10002: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
10003: $userdoms{$udom} = 1;
10004: if (ref($inst_results) eq 'HASH') {
10005: $inst_results->{$uname.':'.$udom} = {};
10006: }
10007: }
10008: }
10009: } else {
10010: $by_username{$udom}{$uname} = 1;
10011: $userdoms{$udom} = 1;
10012: if (ref($inst_results) eq 'HASH') {
10013: $inst_results->{$uname.':'.$udom} = {};
10014: }
10015: }
10016: }
10017: foreach my $udom (keys(%userdoms)) {
10018: if (!$got_rules->{$udom}) {
10019: my %domconfig = &Apache::lonnet::get_dom('configuration',
10020: ['usercreation'],$udom);
10021: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10022: foreach my $item ('username','id') {
10023: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10024: $$curr_rules{$udom}{$item} =
10025: $domconfig{'usercreation'}{$item.'_rule'};
10026: }
10027: }
10028: }
10029: $got_rules->{$udom} = 1;
10030: }
10031: }
10032: if ($checkid) {
10033: foreach my $udom (keys(%by_id)) {
10034: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10035: if ($outcome eq 'ok') {
10036: foreach my $id (keys(%{$by_id{$udom}})) {
10037: my $uname = $by_id{$udom}{$id};
10038: $inst_response{$uname.':'.$udom} = $outcome;
10039: }
10040: if (ref($results) eq 'HASH') {
10041: foreach my $uname (keys(%{$results})) {
10042: if (exists($inst_response{$uname.':'.$udom})) {
10043: $inst_response{$uname.':'.$udom} = $outcome;
10044: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10045: }
10046: }
10047: }
10048: }
1.612 raeburn 10049: }
1.615 raeburn 10050: } else {
1.1075.2.99 raeburn 10051: foreach my $udom (keys(%by_username)) {
10052: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10053: if ($outcome eq 'ok') {
10054: foreach my $uname (keys(%{$by_username{$udom}})) {
10055: $inst_response{$uname.':'.$udom} = $outcome;
10056: }
10057: if (ref($results) eq 'HASH') {
10058: foreach my $uname (keys(%{$results})) {
10059: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10060: }
10061: }
10062: }
10063: }
1.612 raeburn 10064: }
1.1075.2.99 raeburn 10065: } elsif (keys(%{$usershash}) == 1) {
10066: my $user = (keys(%{$usershash}))[0];
10067: my ($uname,$udom) = split(/:/,$user);
10068: if (($udom ne '') && ($uname ne '')) {
10069: if (ref($usershash->{$user}) eq 'HASH') {
10070: if (ref($checks) eq 'HASH') {
10071: if (defined($checks->{'username'})) {
10072: ($inst_response{$user},%{$inst_results->{$user}}) =
10073: &Apache::lonnet::get_instuser($udom,$uname);
10074: } elsif (defined($checks->{'id'})) {
10075: if ($usershash->{$user}->{'id'} ne '') {
10076: ($inst_response{$user},%{$inst_results->{$user}}) =
10077: &Apache::lonnet::get_instuser($udom,undef,
10078: $usershash->{$user}->{'id'});
10079: } else {
10080: ($inst_response{$user},%{$inst_results->{$user}}) =
10081: &Apache::lonnet::get_instuser($udom,$uname);
10082: }
10083: }
10084: } else {
10085: ($inst_response{$user},%{$inst_results->{$user}}) =
10086: &Apache::lonnet::get_instuser($udom,$uname);
10087: return;
10088: }
10089: if (!$got_rules->{$udom}) {
10090: my %domconfig = &Apache::lonnet::get_dom('configuration',
10091: ['usercreation'],$udom);
10092: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10093: foreach my $item ('username','id') {
10094: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10095: $$curr_rules{$udom}{$item} =
10096: $domconfig{'usercreation'}{$item.'_rule'};
10097: }
10098: }
1.585 raeburn 10099: }
1.1075.2.99 raeburn 10100: $got_rules->{$udom} = 1;
1.585 raeburn 10101: }
10102: }
1.1075.2.99 raeburn 10103: } else {
10104: return;
10105: }
10106: } else {
10107: return;
10108: }
10109: foreach my $user (keys(%{$usershash})) {
10110: my ($uname,$udom) = split(/:/,$user);
10111: next if (($udom eq '') || ($uname eq ''));
10112: my $id;
10113: if (ref($inst_results) eq 'HASH') {
10114: if (ref($inst_results->{$user}) eq 'HASH') {
10115: $id = $inst_results->{$user}->{'id'};
10116: }
10117: }
10118: if ($id eq '') {
10119: if (ref($usershash->{$user})) {
10120: $id = $usershash->{$user}->{'id'};
10121: }
1.585 raeburn 10122: }
1.612 raeburn 10123: foreach my $item (keys(%{$checks})) {
10124: if (ref($$curr_rules{$udom}) eq 'HASH') {
10125: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10126: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 10127: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10128: $$curr_rules{$udom}{$item});
1.612 raeburn 10129: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10130: if ($rule_check{$rule}) {
10131: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 10132: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10133: if (ref($inst_results) eq 'HASH') {
10134: if (ref($inst_results->{$user}) eq 'HASH') {
10135: if (keys(%{$inst_results->{$user}}) == 0) {
10136: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 10137: } elsif ($item eq 'id') {
10138: if ($inst_results->{$user}->{'id'} eq '') {
10139: $$alerts{$item}{$udom}{$uname} = 1;
10140: }
1.615 raeburn 10141: }
1.612 raeburn 10142: }
10143: }
1.615 raeburn 10144: }
10145: last;
1.585 raeburn 10146: }
10147: }
10148: }
10149: }
10150: }
10151: }
10152: }
10153: }
1.612 raeburn 10154: return;
10155: }
10156:
10157: sub user_rule_formats {
10158: my ($domain,$domdesc,$curr_rules,$check) = @_;
10159: my %text = (
10160: 'username' => 'Usernames',
10161: 'id' => 'IDs',
10162: );
10163: my $output;
10164: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10165: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10166: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 10167: $output = '<br />'.
10168: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10169: '<span class="LC_cusr_emph">','</span>',$domdesc).
10170: ' <ul>';
1.612 raeburn 10171: foreach my $rule (@{$ruleorder}) {
10172: if (ref($curr_rules) eq 'ARRAY') {
10173: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10174: if (ref($rules->{$rule}) eq 'HASH') {
10175: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10176: $rules->{$rule}{'desc'}.'</li>';
10177: }
10178: }
10179: }
10180: }
10181: $output .= '</ul>';
10182: }
10183: }
10184: return $output;
10185: }
10186:
10187: sub instrule_disallow_msg {
1.615 raeburn 10188: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10189: my $response;
10190: my %text = (
10191: item => 'username',
10192: items => 'usernames',
10193: match => 'matches',
10194: do => 'does',
10195: action => 'a username',
10196: one => 'one',
10197: );
10198: if ($count > 1) {
10199: $text{'item'} = 'usernames';
10200: $text{'match'} ='match';
10201: $text{'do'} = 'do';
10202: $text{'action'} = 'usernames',
10203: $text{'one'} = 'ones';
10204: }
10205: if ($checkitem eq 'id') {
10206: $text{'items'} = 'IDs';
10207: $text{'item'} = 'ID';
10208: $text{'action'} = 'an ID';
1.615 raeburn 10209: if ($count > 1) {
10210: $text{'item'} = 'IDs';
10211: $text{'action'} = 'IDs';
10212: }
1.612 raeburn 10213: }
1.674 bisitz 10214: $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 10215: if ($mode eq 'upload') {
10216: if ($checkitem eq 'username') {
10217: $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'}.");
10218: } elsif ($checkitem eq 'id') {
1.674 bisitz 10219: $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 10220: }
1.669 raeburn 10221: } elsif ($mode eq 'selfcreate') {
10222: if ($checkitem eq 'id') {
10223: $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.");
10224: }
1.615 raeburn 10225: } else {
10226: if ($checkitem eq 'username') {
10227: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10228: } elsif ($checkitem eq 'id') {
10229: $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.");
10230: }
1.612 raeburn 10231: }
10232: return $response;
1.585 raeburn 10233: }
10234:
1.624 raeburn 10235: sub personal_data_fieldtitles {
10236: my %fieldtitles = &Apache::lonlocal::texthash (
10237: id => 'Student/Employee ID',
10238: permanentemail => 'E-mail address',
10239: lastname => 'Last Name',
10240: firstname => 'First Name',
10241: middlename => 'Middle Name',
10242: generation => 'Generation',
10243: gen => 'Generation',
1.765 raeburn 10244: inststatus => 'Affiliation',
1.624 raeburn 10245: );
10246: return %fieldtitles;
10247: }
10248:
1.642 raeburn 10249: sub sorted_inst_types {
10250: my ($dom) = @_;
1.1075.2.70 raeburn 10251: my ($usertypes,$order);
10252: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10253: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10254: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10255: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10256: } else {
10257: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10258: }
1.642 raeburn 10259: my $othertitle = &mt('All users');
10260: if ($env{'request.course.id'}) {
1.668 raeburn 10261: $othertitle = &mt('Any users');
1.642 raeburn 10262: }
10263: my @types;
10264: if (ref($order) eq 'ARRAY') {
10265: @types = @{$order};
10266: }
10267: if (@types == 0) {
10268: if (ref($usertypes) eq 'HASH') {
10269: @types = sort(keys(%{$usertypes}));
10270: }
10271: }
10272: if (keys(%{$usertypes}) > 0) {
10273: $othertitle = &mt('Other users');
10274: }
10275: return ($othertitle,$usertypes,\@types);
10276: }
10277:
1.645 raeburn 10278: sub get_institutional_codes {
10279: my ($settings,$allcourses,$LC_code) = @_;
10280: # Get complete list of course sections to update
10281: my @currsections = ();
10282: my @currxlists = ();
10283: my $coursecode = $$settings{'internal.coursecode'};
10284:
10285: if ($$settings{'internal.sectionnums'} ne '') {
10286: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10287: }
10288:
10289: if ($$settings{'internal.crosslistings'} ne '') {
10290: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10291: }
10292:
10293: if (@currxlists > 0) {
10294: foreach (@currxlists) {
10295: if (m/^([^:]+):(\w*)$/) {
10296: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 10297: push(@{$allcourses},$1);
1.645 raeburn 10298: $$LC_code{$1} = $2;
10299: }
10300: }
10301: }
10302: }
10303:
10304: if (@currsections > 0) {
10305: foreach (@currsections) {
10306: if (m/^(\w+):(\w*)$/) {
10307: my $sec = $coursecode.$1;
10308: my $lc_sec = $2;
10309: unless (grep/^$sec$/,@{$allcourses}) {
1.1075.2.119 raeburn 10310: push(@{$allcourses},$sec);
1.645 raeburn 10311: $$LC_code{$sec} = $lc_sec;
10312: }
10313: }
10314: }
10315: }
10316: return;
10317: }
10318:
1.971 raeburn 10319: sub get_standard_codeitems {
10320: return ('Year','Semester','Department','Number','Section');
10321: }
10322:
1.112 bowersj2 10323: =pod
10324:
1.780 raeburn 10325: =head1 Slot Helpers
10326:
10327: =over 4
10328:
10329: =item * sorted_slots()
10330:
1.1040 raeburn 10331: Sorts an array of slot names in order of an optional sort key,
10332: default sort is by slot start time (earliest first).
1.780 raeburn 10333:
10334: Inputs:
10335:
10336: =over 4
10337:
10338: slotsarr - Reference to array of unsorted slot names.
10339:
10340: slots - Reference to hash of hash, where outer hash keys are slot names.
10341:
1.1040 raeburn 10342: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10343:
1.549 albertel 10344: =back
10345:
1.780 raeburn 10346: Returns:
10347:
10348: =over 4
10349:
1.1040 raeburn 10350: sorted - An array of slot names sorted by a specified sort key
10351: (default sort key is start time of the slot).
1.780 raeburn 10352:
10353: =back
10354:
10355: =cut
10356:
10357:
10358: sub sorted_slots {
1.1040 raeburn 10359: my ($slotsarr,$slots,$sortkey) = @_;
10360: if ($sortkey eq '') {
10361: $sortkey = 'starttime';
10362: }
1.780 raeburn 10363: my @sorted;
10364: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10365: @sorted =
10366: sort {
10367: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10368: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10369: }
10370: if (ref($slots->{$a})) { return -1;}
10371: if (ref($slots->{$b})) { return 1;}
10372: return 0;
10373: } @{$slotsarr};
10374: }
10375: return @sorted;
10376: }
10377:
1.1040 raeburn 10378: =pod
10379:
10380: =item * get_future_slots()
10381:
10382: Inputs:
10383:
10384: =over 4
10385:
10386: cnum - course number
10387:
10388: cdom - course domain
10389:
10390: now - current UNIX time
10391:
10392: symb - optional symb
10393:
10394: =back
10395:
10396: Returns:
10397:
10398: =over 4
10399:
10400: sorted_reservable - ref to array of student_schedulable slots currently
10401: reservable, ordered by end date of reservation period.
10402:
10403: reservable_now - ref to hash of student_schedulable slots currently
10404: reservable.
10405:
10406: Keys in inner hash are:
10407: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 10408: (b) endreserve: end date of reservation period.
10409: (c) uniqueperiod: start,end dates when slot is to be uniquely
10410: selected.
1.1040 raeburn 10411:
10412: sorted_future - ref to array of student_schedulable slots reservable in
10413: the future, ordered by start date of reservation period.
10414:
10415: future_reservable - ref to hash of student_schedulable slots reservable
10416: in the future.
10417:
10418: Keys in inner hash are:
10419: (a) symb: either blank or symb to which slot use is restricted.
10420: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 10421: (c) uniqueperiod: start,end dates when slot is to be uniquely
10422: selected.
1.1040 raeburn 10423:
10424: =back
10425:
10426: =cut
10427:
10428: sub get_future_slots {
10429: my ($cnum,$cdom,$now,$symb) = @_;
10430: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10431: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10432: foreach my $slot (keys(%slots)) {
10433: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10434: if ($symb) {
10435: next if (($slots{$slot}->{'symb'} ne '') &&
10436: ($slots{$slot}->{'symb'} ne $symb));
10437: }
10438: if (($slots{$slot}->{'starttime'} > $now) &&
10439: ($slots{$slot}->{'endtime'} > $now)) {
10440: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10441: my $userallowed = 0;
10442: if ($slots{$slot}->{'allowedsections'}) {
10443: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10444: if (!defined($env{'request.role.sec'})
10445: && grep(/^No section assigned$/,@allowed_sec)) {
10446: $userallowed=1;
10447: } else {
10448: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10449: $userallowed=1;
10450: }
10451: }
10452: unless ($userallowed) {
10453: if (defined($env{'request.course.groups'})) {
10454: my @groups = split(/:/,$env{'request.course.groups'});
10455: foreach my $group (@groups) {
10456: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10457: $userallowed=1;
10458: last;
10459: }
10460: }
10461: }
10462: }
10463: }
10464: if ($slots{$slot}->{'allowedusers'}) {
10465: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10466: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10467: if (grep(/^\Q$user\E$/,@allowed_users)) {
10468: $userallowed = 1;
10469: }
10470: }
10471: next unless($userallowed);
10472: }
10473: my $startreserve = $slots{$slot}->{'startreserve'};
10474: my $endreserve = $slots{$slot}->{'endreserve'};
10475: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 10476: my $uniqueperiod;
10477: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10478: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10479: }
1.1040 raeburn 10480: if (($startreserve < $now) &&
10481: (!$endreserve || $endreserve > $now)) {
10482: my $lastres = $endreserve;
10483: if (!$lastres) {
10484: $lastres = $slots{$slot}->{'starttime'};
10485: }
10486: $reservable_now{$slot} = {
10487: symb => $symb,
1.1075.2.104 raeburn 10488: endreserve => $lastres,
10489: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10490: };
10491: } elsif (($startreserve > $now) &&
10492: (!$endreserve || $endreserve > $startreserve)) {
10493: $future_reservable{$slot} = {
10494: symb => $symb,
1.1075.2.104 raeburn 10495: startreserve => $startreserve,
10496: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10497: };
10498: }
10499: }
10500: }
10501: my @unsorted_reservable = keys(%reservable_now);
10502: if (@unsorted_reservable > 0) {
10503: @sorted_reservable =
10504: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10505: }
10506: my @unsorted_future = keys(%future_reservable);
10507: if (@unsorted_future > 0) {
10508: @sorted_future =
10509: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10510: }
10511: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10512: }
1.780 raeburn 10513:
10514: =pod
10515:
1.1057 foxr 10516: =back
10517:
1.549 albertel 10518: =head1 HTTP Helpers
10519:
10520: =over 4
10521:
1.648 raeburn 10522: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10523:
1.258 albertel 10524: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10525: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10526: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10527:
10528: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10529: $possible_names is an ref to an array of form element names. As an example:
10530: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10531: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10532:
10533: =cut
1.1 albertel 10534:
1.6 albertel 10535: sub get_unprocessed_cgi {
1.25 albertel 10536: my ($query,$possible_names)= @_;
1.26 matthew 10537: # $Apache::lonxml::debug=1;
1.356 albertel 10538: foreach my $pair (split(/&/,$query)) {
10539: my ($name, $value) = split(/=/,$pair);
1.369 www 10540: $name = &unescape($name);
1.25 albertel 10541: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10542: $value =~ tr/+/ /;
10543: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10544: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10545: }
1.16 harris41 10546: }
1.6 albertel 10547: }
10548:
1.112 bowersj2 10549: =pod
10550:
1.648 raeburn 10551: =item * &cacheheader()
1.112 bowersj2 10552:
10553: returns cache-controlling header code
10554:
10555: =cut
10556:
1.7 albertel 10557: sub cacheheader {
1.258 albertel 10558: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10559: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10560: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10561: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10562: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10563: return $output;
1.7 albertel 10564: }
10565:
1.112 bowersj2 10566: =pod
10567:
1.648 raeburn 10568: =item * &no_cache($r)
1.112 bowersj2 10569:
10570: specifies header code to not have cache
10571:
10572: =cut
10573:
1.9 albertel 10574: sub no_cache {
1.216 albertel 10575: my ($r) = @_;
10576: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10577: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10578: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10579: $r->no_cache(1);
10580: $r->header_out("Expires" => $date);
10581: $r->header_out("Pragma" => "no-cache");
1.123 www 10582: }
10583:
10584: sub content_type {
1.181 albertel 10585: my ($r,$type,$charset) = @_;
1.299 foxr 10586: if ($r) {
10587: # Note that printout.pl calls this with undef for $r.
10588: &no_cache($r);
10589: }
1.258 albertel 10590: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10591: unless ($charset) {
10592: $charset=&Apache::lonlocal::current_encoding;
10593: }
10594: if ($charset) { $type.='; charset='.$charset; }
10595: if ($r) {
10596: $r->content_type($type);
10597: } else {
10598: print("Content-type: $type\n\n");
10599: }
1.9 albertel 10600: }
1.25 albertel 10601:
1.112 bowersj2 10602: =pod
10603:
1.648 raeburn 10604: =item * &add_to_env($name,$value)
1.112 bowersj2 10605:
1.258 albertel 10606: adds $name to the %env hash with value
1.112 bowersj2 10607: $value, if $name already exists, the entry is converted to an array
10608: reference and $value is added to the array.
10609:
10610: =cut
10611:
1.25 albertel 10612: sub add_to_env {
10613: my ($name,$value)=@_;
1.258 albertel 10614: if (defined($env{$name})) {
10615: if (ref($env{$name})) {
1.25 albertel 10616: #already have multiple values
1.258 albertel 10617: push(@{ $env{$name} },$value);
1.25 albertel 10618: } else {
10619: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10620: my $first=$env{$name};
10621: undef($env{$name});
10622: push(@{ $env{$name} },$first,$value);
1.25 albertel 10623: }
10624: } else {
1.258 albertel 10625: $env{$name}=$value;
1.25 albertel 10626: }
1.31 albertel 10627: }
1.149 albertel 10628:
10629: =pod
10630:
1.648 raeburn 10631: =item * &get_env_multiple($name)
1.149 albertel 10632:
1.258 albertel 10633: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10634: values may be defined and end up as an array ref.
10635:
10636: returns an array of values
10637:
10638: =cut
10639:
10640: sub get_env_multiple {
10641: my ($name) = @_;
10642: my @values;
1.258 albertel 10643: if (defined($env{$name})) {
1.149 albertel 10644: # exists is it an array
1.258 albertel 10645: if (ref($env{$name})) {
10646: @values=@{ $env{$name} };
1.149 albertel 10647: } else {
1.258 albertel 10648: $values[0]=$env{$name};
1.149 albertel 10649: }
10650: }
10651: return(@values);
10652: }
10653:
1.660 raeburn 10654: sub ask_for_embedded_content {
10655: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10656: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 10657: %currsubfile,%unused,$rem);
1.1071 raeburn 10658: my $counter = 0;
10659: my $numnew = 0;
1.987 raeburn 10660: my $numremref = 0;
10661: my $numinvalid = 0;
10662: my $numpathchg = 0;
10663: my $numexisting = 0;
1.1071 raeburn 10664: my $numunused = 0;
10665: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 10666: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10667: my $heading = &mt('Upload embedded files');
10668: my $buttontext = &mt('Upload');
10669:
1.1075.2.11 raeburn 10670: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 10671: if ($actionurl eq '/adm/dependencies') {
10672: $navmap = Apache::lonnavmaps::navmap->new();
10673: }
10674: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10675: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 10676: }
1.1075.2.35 raeburn 10677: if (($actionurl eq '/adm/portfolio') ||
10678: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10679: my $current_path='/';
10680: if ($env{'form.currentpath'}) {
10681: $current_path = $env{'form.currentpath'};
10682: }
10683: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 10684: $udom = $cdom;
10685: $uname = $cnum;
1.984 raeburn 10686: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10687: } else {
10688: $udom = $env{'user.domain'};
10689: $uname = $env{'user.name'};
10690: $url = '/userfiles/portfolio';
10691: }
1.987 raeburn 10692: $toplevel = $url.'/';
1.984 raeburn 10693: $url .= $current_path;
10694: $getpropath = 1;
1.987 raeburn 10695: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10696: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10697: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10698: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10699: $toplevel = $url;
1.984 raeburn 10700: if ($rest ne '') {
1.987 raeburn 10701: $url .= $rest;
10702: }
10703: } elsif ($actionurl eq '/adm/coursedocs') {
10704: if (ref($args) eq 'HASH') {
1.1071 raeburn 10705: $url = $args->{'docs_url'};
10706: $toplevel = $url;
1.1075.2.11 raeburn 10707: if ($args->{'context'} eq 'paste') {
10708: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10709: ($path) =
10710: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10711: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10712: $fileloc =~ s{^/}{};
10713: }
1.1071 raeburn 10714: }
10715: } elsif ($actionurl eq '/adm/dependencies') {
10716: if ($env{'request.course.id'} ne '') {
10717: if (ref($args) eq 'HASH') {
10718: $url = $args->{'docs_url'};
10719: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 10720: $toplevel = $url;
10721: unless ($toplevel =~ m{^/}) {
10722: $toplevel = "/$url";
10723: }
1.1075.2.11 raeburn 10724: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 10725: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10726: $path = $1;
10727: } else {
10728: ($path) =
10729: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10730: }
1.1075.2.79 raeburn 10731: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10732: $fileloc = $toplevel;
10733: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10734: my ($udom,$uname,$fname) =
10735: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10736: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10737: } else {
10738: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10739: }
1.1071 raeburn 10740: $fileloc =~ s{^/}{};
10741: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10742: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10743: }
1.987 raeburn 10744: }
1.1075.2.35 raeburn 10745: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10746: $udom = $cdom;
10747: $uname = $cnum;
10748: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10749: $toplevel = $url;
10750: $path = $url;
10751: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10752: $fileloc =~ s{^/}{};
10753: }
10754: foreach my $file (keys(%{$allfiles})) {
10755: my $embed_file;
10756: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10757: $embed_file = $1;
10758: } else {
10759: $embed_file = $file;
10760: }
1.1075.2.55 raeburn 10761: my ($absolutepath,$cleaned_file);
10762: if ($embed_file =~ m{^\w+://}) {
10763: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 10764: $newfiles{$cleaned_file} = 1;
10765: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10766: } else {
1.1075.2.55 raeburn 10767: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10768: if ($embed_file =~ m{^/}) {
10769: $absolutepath = $embed_file;
10770: }
1.1075.2.47 raeburn 10771: if ($cleaned_file =~ m{/}) {
10772: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10773: $path = &check_for_traversal($path,$url,$toplevel);
10774: my $item = $fname;
10775: if ($path ne '') {
10776: $item = $path.'/'.$fname;
10777: $subdependencies{$path}{$fname} = 1;
10778: } else {
10779: $dependencies{$item} = 1;
10780: }
10781: if ($absolutepath) {
10782: $mapping{$item} = $absolutepath;
10783: } else {
10784: $mapping{$item} = $embed_file;
10785: }
10786: } else {
10787: $dependencies{$embed_file} = 1;
10788: if ($absolutepath) {
1.1075.2.47 raeburn 10789: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10790: } else {
1.1075.2.47 raeburn 10791: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10792: }
10793: }
1.984 raeburn 10794: }
10795: }
1.1071 raeburn 10796: my $dirptr = 16384;
1.984 raeburn 10797: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10798: $currsubfile{$path} = {};
1.1075.2.35 raeburn 10799: if (($actionurl eq '/adm/portfolio') ||
10800: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10801: my ($sublistref,$listerror) =
10802: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10803: if (ref($sublistref) eq 'ARRAY') {
10804: foreach my $line (@{$sublistref}) {
10805: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10806: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10807: }
1.984 raeburn 10808: }
1.987 raeburn 10809: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10810: if (opendir(my $dir,$url.'/'.$path)) {
10811: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10812: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10813: }
1.1075.2.11 raeburn 10814: } elsif (($actionurl eq '/adm/dependencies') ||
10815: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10816: ($args->{'context'} eq 'paste')) ||
10817: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10818: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 10819: my $dir;
10820: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10821: $dir = $fileloc;
10822: } else {
10823: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10824: }
1.1071 raeburn 10825: if ($dir ne '') {
10826: my ($sublistref,$listerror) =
10827: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10828: if (ref($sublistref) eq 'ARRAY') {
10829: foreach my $line (@{$sublistref}) {
10830: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10831: undef,$mtime)=split(/\&/,$line,12);
10832: unless (($testdir&$dirptr) ||
10833: ($file_name =~ /^\.\.?$/)) {
10834: $currsubfile{$path}{$file_name} = [$size,$mtime];
10835: }
10836: }
10837: }
10838: }
1.984 raeburn 10839: }
10840: }
10841: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10842: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10843: my $item = $path.'/'.$file;
10844: unless ($mapping{$item} eq $item) {
10845: $pathchanges{$item} = 1;
10846: }
10847: $existing{$item} = 1;
10848: $numexisting ++;
10849: } else {
10850: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10851: }
10852: }
1.1071 raeburn 10853: if ($actionurl eq '/adm/dependencies') {
10854: foreach my $path (keys(%currsubfile)) {
10855: if (ref($currsubfile{$path}) eq 'HASH') {
10856: foreach my $file (keys(%{$currsubfile{$path}})) {
10857: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 10858: next if (($rem ne '') &&
10859: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10860: (ref($navmap) &&
10861: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10862: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10863: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10864: $unused{$path.'/'.$file} = 1;
10865: }
10866: }
10867: }
10868: }
10869: }
1.984 raeburn 10870: }
1.987 raeburn 10871: my %currfile;
1.1075.2.35 raeburn 10872: if (($actionurl eq '/adm/portfolio') ||
10873: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10874: my ($dirlistref,$listerror) =
10875: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10876: if (ref($dirlistref) eq 'ARRAY') {
10877: foreach my $line (@{$dirlistref}) {
10878: my ($file_name,$rest) = split(/\&/,$line,2);
10879: $currfile{$file_name} = 1;
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)) {
1.987 raeburn 10884: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10885: map {$currfile{$_} = 1;} @dir_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 '') {
10892: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10893: if ($dir ne '') {
10894: my ($dirlistref,$listerror) =
10895: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10896: if (ref($dirlistref) eq 'ARRAY') {
10897: foreach my $line (@{$dirlistref}) {
10898: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10899: $size,undef,$mtime)=split(/\&/,$line,12);
10900: unless (($testdir&$dirptr) ||
10901: ($file_name =~ /^\.\.?$/)) {
10902: $currfile{$file_name} = [$size,$mtime];
10903: }
10904: }
10905: }
10906: }
10907: }
1.984 raeburn 10908: }
10909: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10910: if (exists($currfile{$file})) {
1.987 raeburn 10911: unless ($mapping{$file} eq $file) {
10912: $pathchanges{$file} = 1;
10913: }
10914: $existing{$file} = 1;
10915: $numexisting ++;
10916: } else {
1.984 raeburn 10917: $newfiles{$file} = 1;
10918: }
10919: }
1.1071 raeburn 10920: foreach my $file (keys(%currfile)) {
10921: unless (($file eq $filename) ||
10922: ($file eq $filename.'.bak') ||
10923: ($dependencies{$file})) {
1.1075.2.11 raeburn 10924: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10925: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10926: next if (($rem ne '') &&
10927: (($env{"httpref.$rem".$file} ne '') ||
10928: (ref($navmap) &&
10929: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10930: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10931: ($navmap->getResourceByUrl($rem.$1)))))));
10932: }
1.1075.2.11 raeburn 10933: }
1.1071 raeburn 10934: $unused{$file} = 1;
10935: }
10936: }
1.1075.2.11 raeburn 10937: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10938: ($args->{'context'} eq 'paste')) {
10939: $counter = scalar(keys(%existing));
10940: $numpathchg = scalar(keys(%pathchanges));
10941: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10942: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10943: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10944: $counter = scalar(keys(%existing));
10945: $numpathchg = scalar(keys(%pathchanges));
10946: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10947: }
1.984 raeburn 10948: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10949: if ($actionurl eq '/adm/dependencies') {
10950: next if ($embed_file =~ m{^\w+://});
10951: }
1.660 raeburn 10952: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10953: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10954: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10955: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10956: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10957: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10958: }
1.1075.2.35 raeburn 10959: $upload_output .= '</td>';
1.1071 raeburn 10960: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10961: $upload_output.='<td align="right">'.
10962: '<span class="LC_info LC_fontsize_medium">'.
10963: &mt("URL points to web address").'</span>';
1.987 raeburn 10964: $numremref++;
1.660 raeburn 10965: } elsif ($args->{'error_on_invalid_names'}
10966: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10967: $upload_output.='<td align="right"><span class="LC_warning">'.
10968: &mt('Invalid characters').'</span>';
1.987 raeburn 10969: $numinvalid++;
1.660 raeburn 10970: } else {
1.1075.2.35 raeburn 10971: $upload_output .= '<td>'.
10972: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10973: $embed_file,\%mapping,
1.1071 raeburn 10974: $allfiles,$codebase,'upload');
10975: $counter ++;
10976: $numnew ++;
1.987 raeburn 10977: }
10978: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10979: }
10980: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10981: if ($actionurl eq '/adm/dependencies') {
10982: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10983: $modify_output .= &start_data_table_row().
10984: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10985: '<img src="'.&icon($embed_file).'" border="0" />'.
10986: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10987: '<td>'.$size.'</td>'.
10988: '<td>'.$mtime.'</td>'.
10989: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10990: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10991: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10992: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10993: &embedded_file_element('upload_embedded',$counter,
10994: $embed_file,\%mapping,
10995: $allfiles,$codebase,'modify').
10996: '</div></td>'.
10997: &end_data_table_row()."\n";
10998: $counter ++;
10999: } else {
11000: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11001: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11002: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11003: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11004: &Apache::loncommon::end_data_table_row()."\n";
11005: }
11006: }
11007: my $delidx = $counter;
11008: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11009: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11010: $delete_output .= &start_data_table_row().
11011: '<td><img src="'.&icon($oldfile).'" />'.
11012: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11013: '<td>'.$size.'</td>'.
11014: '<td>'.$mtime.'</td>'.
11015: '<td><label><input type="checkbox" name="del_upload_dep" '.
11016: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11017: &embedded_file_element('upload_embedded',$delidx,
11018: $oldfile,\%mapping,$allfiles,
11019: $codebase,'delete').'</td>'.
11020: &end_data_table_row()."\n";
11021: $numunused ++;
11022: $delidx ++;
1.987 raeburn 11023: }
11024: if ($upload_output) {
11025: $upload_output = &start_data_table().
11026: $upload_output.
11027: &end_data_table()."\n";
11028: }
1.1071 raeburn 11029: if ($modify_output) {
11030: $modify_output = &start_data_table().
11031: &start_data_table_header_row().
11032: '<th>'.&mt('File').'</th>'.
11033: '<th>'.&mt('Size (KB)').'</th>'.
11034: '<th>'.&mt('Modified').'</th>'.
11035: '<th>'.&mt('Upload replacement?').'</th>'.
11036: &end_data_table_header_row().
11037: $modify_output.
11038: &end_data_table()."\n";
11039: }
11040: if ($delete_output) {
11041: $delete_output = &start_data_table().
11042: &start_data_table_header_row().
11043: '<th>'.&mt('File').'</th>'.
11044: '<th>'.&mt('Size (KB)').'</th>'.
11045: '<th>'.&mt('Modified').'</th>'.
11046: '<th>'.&mt('Delete?').'</th>'.
11047: &end_data_table_header_row().
11048: $delete_output.
11049: &end_data_table()."\n";
11050: }
1.987 raeburn 11051: my $applies = 0;
11052: if ($numremref) {
11053: $applies ++;
11054: }
11055: if ($numinvalid) {
11056: $applies ++;
11057: }
11058: if ($numexisting) {
11059: $applies ++;
11060: }
1.1071 raeburn 11061: if ($counter || $numunused) {
1.987 raeburn 11062: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11063: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11064: $state.'<h3>'.$heading.'</h3>';
11065: if ($actionurl eq '/adm/dependencies') {
11066: if ($numnew) {
11067: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11068: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11069: $upload_output.'<br />'."\n";
11070: }
11071: if ($numexisting) {
11072: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11073: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11074: $modify_output.'<br />'."\n";
11075: $buttontext = &mt('Save changes');
11076: }
11077: if ($numunused) {
11078: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11079: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11080: $delete_output.'<br />'."\n";
11081: $buttontext = &mt('Save changes');
11082: }
11083: } else {
11084: $output .= $upload_output.'<br />'."\n";
11085: }
11086: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11087: $counter.'" />'."\n";
11088: if ($actionurl eq '/adm/dependencies') {
11089: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11090: $numnew.'" />'."\n";
11091: } elsif ($actionurl eq '') {
1.987 raeburn 11092: $output .= '<input type="hidden" name="phase" value="three" />';
11093: }
11094: } elsif ($applies) {
11095: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11096: if ($applies > 1) {
11097: $output .=
1.1075.2.35 raeburn 11098: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11099: if ($numremref) {
11100: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11101: }
11102: if ($numinvalid) {
11103: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11104: }
11105: if ($numexisting) {
11106: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11107: }
11108: $output .= '</ul><br />';
11109: } elsif ($numremref) {
11110: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11111: } elsif ($numinvalid) {
11112: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11113: } elsif ($numexisting) {
11114: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11115: }
11116: $output .= $upload_output.'<br />';
11117: }
11118: my ($pathchange_output,$chgcount);
1.1071 raeburn 11119: $chgcount = $counter;
1.987 raeburn 11120: if (keys(%pathchanges) > 0) {
11121: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11122: if ($counter) {
1.987 raeburn 11123: $output .= &embedded_file_element('pathchange',$chgcount,
11124: $embed_file,\%mapping,
1.1071 raeburn 11125: $allfiles,$codebase,'change');
1.987 raeburn 11126: } else {
11127: $pathchange_output .=
11128: &start_data_table_row().
11129: '<td><input type ="checkbox" name="namechange" value="'.
11130: $chgcount.'" checked="checked" /></td>'.
11131: '<td>'.$mapping{$embed_file}.'</td>'.
11132: '<td>'.$embed_file.
11133: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11134: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11135: '</td>'.&end_data_table_row();
1.660 raeburn 11136: }
1.987 raeburn 11137: $numpathchg ++;
11138: $chgcount ++;
1.660 raeburn 11139: }
11140: }
1.1075.2.35 raeburn 11141: if (($counter) || ($numunused)) {
1.987 raeburn 11142: if ($numpathchg) {
11143: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11144: $numpathchg.'" />'."\n";
11145: }
11146: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11147: ($actionurl eq '/adm/imsimport')) {
11148: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11149: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11150: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11151: } elsif ($actionurl eq '/adm/dependencies') {
11152: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11153: }
1.1075.2.35 raeburn 11154: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11155: } elsif ($numpathchg) {
11156: my %pathchange = ();
11157: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11158: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11159: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 11160: }
1.987 raeburn 11161: }
1.1071 raeburn 11162: return ($output,$counter,$numpathchg);
1.987 raeburn 11163: }
11164:
1.1075.2.47 raeburn 11165: =pod
11166:
11167: =item * clean_path($name)
11168:
11169: Performs clean-up of directories, subdirectories and filename in an
11170: embedded object, referenced in an HTML file which is being uploaded
11171: to a course or portfolio, where
11172: "Upload embedded images/multimedia files if HTML file" checkbox was
11173: checked.
11174:
11175: Clean-up is similar to replacements in lonnet::clean_filename()
11176: except each / between sub-directory and next level is preserved.
11177:
11178: =cut
11179:
11180: sub clean_path {
11181: my ($embed_file) = @_;
11182: $embed_file =~s{^/+}{};
11183: my @contents;
11184: if ($embed_file =~ m{/}) {
11185: @contents = split(/\//,$embed_file);
11186: } else {
11187: @contents = ($embed_file);
11188: }
11189: my $lastidx = scalar(@contents)-1;
11190: for (my $i=0; $i<=$lastidx; $i++) {
11191: $contents[$i]=~s{\\}{/}g;
11192: $contents[$i]=~s/\s+/\_/g;
11193: $contents[$i]=~s{[^/\w\.\-]}{}g;
11194: if ($i == $lastidx) {
11195: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11196: }
11197: }
11198: if ($lastidx > 0) {
11199: return join('/',@contents);
11200: } else {
11201: return $contents[0];
11202: }
11203: }
11204:
1.987 raeburn 11205: sub embedded_file_element {
1.1071 raeburn 11206: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11207: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11208: (ref($codebase) eq 'HASH'));
11209: my $output;
1.1071 raeburn 11210: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11211: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11212: }
11213: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11214: &escape($embed_file).'" />';
11215: unless (($context eq 'upload_embedded') &&
11216: ($mapping->{$embed_file} eq $embed_file)) {
11217: $output .='
11218: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11219: }
11220: my $attrib;
11221: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11222: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11223: }
11224: $output .=
11225: "\n\t\t".
11226: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11227: $attrib.'" />';
11228: if (exists($codebase->{$mapping->{$embed_file}})) {
11229: $output .=
11230: "\n\t\t".
11231: '<input name="codebase_'.$num.'" type="hidden" value="'.
11232: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11233: }
1.987 raeburn 11234: return $output;
1.660 raeburn 11235: }
11236:
1.1071 raeburn 11237: sub get_dependency_details {
11238: my ($currfile,$currsubfile,$embed_file) = @_;
11239: my ($size,$mtime,$showsize,$showmtime);
11240: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11241: if ($embed_file =~ m{/}) {
11242: my ($path,$fname) = split(/\//,$embed_file);
11243: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11244: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11245: }
11246: } else {
11247: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11248: ($size,$mtime) = @{$currfile->{$embed_file}};
11249: }
11250: }
11251: $showsize = $size/1024.0;
11252: $showsize = sprintf("%.1f",$showsize);
11253: if ($mtime > 0) {
11254: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11255: }
11256: }
11257: return ($showsize,$showmtime);
11258: }
11259:
11260: sub ask_embedded_js {
11261: return <<"END";
11262: <script type="text/javascript"">
11263: // <![CDATA[
11264: function toggleBrowse(counter) {
11265: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11266: var fileid = document.getElementById('embedded_item_'+counter);
11267: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11268: if (chkboxid.checked == true) {
11269: uploaddivid.style.display='block';
11270: } else {
11271: uploaddivid.style.display='none';
11272: fileid.value = '';
11273: }
11274: }
11275: // ]]>
11276: </script>
11277:
11278: END
11279: }
11280:
1.661 raeburn 11281: sub upload_embedded {
11282: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11283: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11284: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11285: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11286: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11287: my $orig_uploaded_filename =
11288: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11289: foreach my $type ('orig','ref','attrib','codebase') {
11290: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11291: $env{'form.embedded_'.$type.'_'.$i} =
11292: &unescape($env{'form.embedded_'.$type.'_'.$i});
11293: }
11294: }
1.661 raeburn 11295: my ($path,$fname) =
11296: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11297: # no path, whole string is fname
11298: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11299: $fname = &Apache::lonnet::clean_filename($fname);
11300: # See if there is anything left
11301: next if ($fname eq '');
11302:
11303: # Check if file already exists as a file or directory.
11304: my ($state,$msg);
11305: if ($context eq 'portfolio') {
11306: my $port_path = $dirpath;
11307: if ($group ne '') {
11308: $port_path = "groups/$group/$port_path";
11309: }
1.987 raeburn 11310: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11311: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11312: $dir_root,$port_path,$disk_quota,
11313: $current_disk_usage,$uname,$udom);
11314: if ($state eq 'will_exceed_quota'
1.984 raeburn 11315: || $state eq 'file_locked') {
1.661 raeburn 11316: $output .= $msg;
11317: next;
11318: }
11319: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11320: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11321: if ($state eq 'exists') {
11322: $output .= $msg;
11323: next;
11324: }
11325: }
11326: # Check if extension is valid
11327: if (($fname =~ /\.(\w+)$/) &&
11328: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 11329: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11330: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11331: next;
11332: } elsif (($fname =~ /\.(\w+)$/) &&
11333: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11334: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11335: next;
11336: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 11337: $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 11338: next;
11339: }
11340: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 11341: my $subdir = $path;
11342: $subdir =~ s{/+$}{};
1.661 raeburn 11343: if ($context eq 'portfolio') {
1.984 raeburn 11344: my $result;
11345: if ($state eq 'existingfile') {
11346: $result=
11347: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 11348: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11349: } else {
1.984 raeburn 11350: $result=
11351: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11352: $dirpath.
1.1075.2.35 raeburn 11353: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11354: if ($result !~ m|^/uploaded/|) {
11355: $output .= '<span class="LC_error">'
11356: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11357: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11358: .'</span><br />';
11359: next;
11360: } else {
1.987 raeburn 11361: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11362: $path.$fname.'</span>').'<br />';
1.984 raeburn 11363: }
1.661 raeburn 11364: }
1.1075.2.35 raeburn 11365: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
11366: my $extendedsubdir = $dirpath.'/'.$subdir;
11367: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11368: my $result =
1.1075.2.35 raeburn 11369: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11370: if ($result !~ m|^/uploaded/|) {
11371: $output .= '<span class="LC_error">'
11372: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11373: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11374: .'</span><br />';
11375: next;
11376: } else {
11377: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11378: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 11379: if ($context eq 'syllabus') {
11380: &Apache::lonnet::make_public_indefinitely($result);
11381: }
1.987 raeburn 11382: }
1.661 raeburn 11383: } else {
11384: # Save the file
11385: my $target = $env{'form.embedded_item_'.$i};
11386: my $fullpath = $dir_root.$dirpath.'/'.$path;
11387: my $dest = $fullpath.$fname;
11388: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11389: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11390: my $count;
11391: my $filepath = $dir_root;
1.1027 raeburn 11392: foreach my $subdir (@parts) {
11393: $filepath .= "/$subdir";
11394: if (!-e $filepath) {
1.661 raeburn 11395: mkdir($filepath,0770);
11396: }
11397: }
11398: my $fh;
11399: if (!open($fh,'>'.$dest)) {
11400: &Apache::lonnet::logthis('Failed to create '.$dest);
11401: $output .= '<span class="LC_error">'.
1.1071 raeburn 11402: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11403: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11404: '</span><br />';
11405: } else {
11406: if (!print $fh $env{'form.embedded_item_'.$i}) {
11407: &Apache::lonnet::logthis('Failed to write to '.$dest);
11408: $output .= '<span class="LC_error">'.
1.1071 raeburn 11409: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11410: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11411: '</span><br />';
11412: } else {
1.987 raeburn 11413: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11414: $url.'</span>').'<br />';
11415: unless ($context eq 'testbank') {
11416: $footer .= &mt('View embedded file: [_1]',
11417: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11418: }
11419: }
11420: close($fh);
11421: }
11422: }
11423: if ($env{'form.embedded_ref_'.$i}) {
11424: $pathchange{$i} = 1;
11425: }
11426: }
11427: if ($output) {
11428: $output = '<p>'.$output.'</p>';
11429: }
11430: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11431: $returnflag = 'ok';
1.1071 raeburn 11432: my $numpathchgs = scalar(keys(%pathchange));
11433: if ($numpathchgs > 0) {
1.987 raeburn 11434: if ($context eq 'portfolio') {
11435: $output .= '<p>'.&mt('or').'</p>';
11436: } elsif ($context eq 'testbank') {
1.1071 raeburn 11437: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11438: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11439: $returnflag = 'modify_orightml';
11440: }
11441: }
1.1071 raeburn 11442: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11443: }
11444:
11445: sub modify_html_form {
11446: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11447: my $end = 0;
11448: my $modifyform;
11449: if ($context eq 'upload_embedded') {
11450: return unless (ref($pathchange) eq 'HASH');
11451: if ($env{'form.number_embedded_items'}) {
11452: $end += $env{'form.number_embedded_items'};
11453: }
11454: if ($env{'form.number_pathchange_items'}) {
11455: $end += $env{'form.number_pathchange_items'};
11456: }
11457: if ($end) {
11458: for (my $i=0; $i<$end; $i++) {
11459: if ($i < $env{'form.number_embedded_items'}) {
11460: next unless($pathchange->{$i});
11461: }
11462: $modifyform .=
11463: &start_data_table_row().
11464: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11465: 'checked="checked" /></td>'.
11466: '<td>'.$env{'form.embedded_ref_'.$i}.
11467: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11468: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11469: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11470: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11471: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11472: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11473: '<td>'.$env{'form.embedded_orig_'.$i}.
11474: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11475: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11476: &end_data_table_row();
1.1071 raeburn 11477: }
1.987 raeburn 11478: }
11479: } else {
11480: $modifyform = $pathchgtable;
11481: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11482: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11483: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11484: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11485: }
11486: }
11487: if ($modifyform) {
1.1071 raeburn 11488: if ($actionurl eq '/adm/dependencies') {
11489: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11490: }
1.987 raeburn 11491: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11492: '<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".
11493: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11494: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11495: '</ol></p>'."\n".'<p>'.
11496: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11497: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11498: &start_data_table()."\n".
11499: &start_data_table_header_row().
11500: '<th>'.&mt('Change?').'</th>'.
11501: '<th>'.&mt('Current reference').'</th>'.
11502: '<th>'.&mt('Required reference').'</th>'.
11503: &end_data_table_header_row()."\n".
11504: $modifyform.
11505: &end_data_table().'<br />'."\n".$hiddenstate.
11506: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11507: '</form>'."\n";
11508: }
11509: return;
11510: }
11511:
11512: sub modify_html_refs {
1.1075.2.35 raeburn 11513: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11514: my $container;
11515: if ($context eq 'portfolio') {
11516: $container = $env{'form.container'};
11517: } elsif ($context eq 'coursedoc') {
11518: $container = $env{'form.primaryurl'};
1.1071 raeburn 11519: } elsif ($context eq 'manage_dependencies') {
11520: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11521: $container = "/$container";
1.1075.2.35 raeburn 11522: } elsif ($context eq 'syllabus') {
11523: $container = $url;
1.987 raeburn 11524: } else {
1.1027 raeburn 11525: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11526: }
11527: my (%allfiles,%codebase,$output,$content);
11528: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 11529: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11530: if (wantarray) {
11531: return ('',0,0);
11532: } else {
11533: return;
11534: }
11535: }
11536: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11537: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11538: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11539: if (wantarray) {
11540: return ('',0,0);
11541: } else {
11542: return;
11543: }
11544: }
1.987 raeburn 11545: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11546: if ($content eq '-1') {
11547: if (wantarray) {
11548: return ('',0,0);
11549: } else {
11550: return;
11551: }
11552: }
1.987 raeburn 11553: } else {
1.1071 raeburn 11554: unless ($container =~ /^\Q$dir_root\E/) {
11555: if (wantarray) {
11556: return ('',0,0);
11557: } else {
11558: return;
11559: }
11560: }
1.1075.2.128 raeburn 11561: if (open(my $fh,'<',$container)) {
1.987 raeburn 11562: $content = join('', <$fh>);
11563: close($fh);
11564: } else {
1.1071 raeburn 11565: if (wantarray) {
11566: return ('',0,0);
11567: } else {
11568: return;
11569: }
1.987 raeburn 11570: }
11571: }
11572: my ($count,$codebasecount) = (0,0);
11573: my $mm = new File::MMagic;
11574: my $mime_type = $mm->checktype_contents($content);
11575: if ($mime_type eq 'text/html') {
11576: my $parse_result =
11577: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11578: \%codebase,\$content);
11579: if ($parse_result eq 'ok') {
11580: foreach my $i (@changes) {
11581: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11582: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11583: if ($allfiles{$ref}) {
11584: my $newname = $orig;
11585: my ($attrib_regexp,$codebase);
1.1006 raeburn 11586: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11587: if ($attrib_regexp =~ /:/) {
11588: $attrib_regexp =~ s/\:/|/g;
11589: }
11590: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11591: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11592: $count += $numchg;
1.1075.2.35 raeburn 11593: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11594: delete($allfiles{$ref});
1.987 raeburn 11595: }
11596: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11597: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11598: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11599: $codebasecount ++;
11600: }
11601: }
11602: }
1.1075.2.35 raeburn 11603: my $skiprewrites;
1.987 raeburn 11604: if ($count || $codebasecount) {
11605: my $saveresult;
1.1071 raeburn 11606: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11607: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11608: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11609: if ($url eq $container) {
11610: my ($fname) = ($container =~ m{/([^/]+)$});
11611: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11612: $count,'<span class="LC_filename">'.
1.1071 raeburn 11613: $fname.'</span>').'</p>';
1.987 raeburn 11614: } else {
11615: $output = '<p class="LC_error">'.
11616: &mt('Error: update failed for: [_1].',
11617: '<span class="LC_filename">'.
11618: $container.'</span>').'</p>';
11619: }
1.1075.2.35 raeburn 11620: if ($context eq 'syllabus') {
11621: unless ($saveresult eq 'ok') {
11622: $skiprewrites = 1;
11623: }
11624: }
1.987 raeburn 11625: } else {
1.1075.2.128 raeburn 11626: if (open(my $fh,'>',$container)) {
1.987 raeburn 11627: print $fh $content;
11628: close($fh);
11629: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11630: $count,'<span class="LC_filename">'.
11631: $container.'</span>').'</p>';
1.661 raeburn 11632: } else {
1.987 raeburn 11633: $output = '<p class="LC_error">'.
11634: &mt('Error: could not update [_1].',
11635: '<span class="LC_filename">'.
11636: $container.'</span>').'</p>';
1.661 raeburn 11637: }
11638: }
11639: }
1.1075.2.35 raeburn 11640: if (($context eq 'syllabus') && (!$skiprewrites)) {
11641: my ($actionurl,$state);
11642: $actionurl = "/public/$udom/$uname/syllabus";
11643: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11644: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11645: \%codebase,
11646: {'context' => 'rewrites',
11647: 'ignore_remote_references' => 1,});
11648: if (ref($mapping) eq 'HASH') {
11649: my $rewrites = 0;
11650: foreach my $key (keys(%{$mapping})) {
11651: next if ($key =~ m{^https?://});
11652: my $ref = $mapping->{$key};
11653: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11654: my $attrib;
11655: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11656: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11657: }
11658: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11659: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11660: $rewrites += $numchg;
11661: }
11662: }
11663: if ($rewrites) {
11664: my $saveresult;
11665: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11666: if ($url eq $container) {
11667: my ($fname) = ($container =~ m{/([^/]+)$});
11668: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11669: $count,'<span class="LC_filename">'.
11670: $fname.'</span>').'</p>';
11671: } else {
11672: $output .= '<p class="LC_error">'.
11673: &mt('Error: could not update links in [_1].',
11674: '<span class="LC_filename">'.
11675: $container.'</span>').'</p>';
11676:
11677: }
11678: }
11679: }
11680: }
1.987 raeburn 11681: } else {
11682: &logthis('Failed to parse '.$container.
11683: ' to modify references: '.$parse_result);
1.661 raeburn 11684: }
11685: }
1.1071 raeburn 11686: if (wantarray) {
11687: return ($output,$count,$codebasecount);
11688: } else {
11689: return $output;
11690: }
1.661 raeburn 11691: }
11692:
11693: sub check_for_existing {
11694: my ($path,$fname,$element) = @_;
11695: my ($state,$msg);
11696: if (-d $path.'/'.$fname) {
11697: $state = 'exists';
11698: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11699: } elsif (-e $path.'/'.$fname) {
11700: $state = 'exists';
11701: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11702: }
11703: if ($state eq 'exists') {
11704: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11705: }
11706: return ($state,$msg);
11707: }
11708:
11709: sub check_for_upload {
11710: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11711: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11712: my $filesize = length($env{'form.'.$element});
11713: if (!$filesize) {
11714: my $msg = '<span class="LC_error">'.
11715: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11716: '<span class="LC_filename">'.$fname.'</span>',
11717: $filesize).'<br />'.
1.1007 raeburn 11718: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11719: '</span>';
11720: return ('zero_bytes',$msg);
11721: }
11722: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11723: my $getpropath = 1;
1.1021 raeburn 11724: my ($dirlistref,$listerror) =
11725: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11726: my $found_file = 0;
11727: my $locked_file = 0;
1.991 raeburn 11728: my @lockers;
11729: my $navmap;
11730: if ($env{'request.course.id'}) {
11731: $navmap = Apache::lonnavmaps::navmap->new();
11732: }
1.1021 raeburn 11733: if (ref($dirlistref) eq 'ARRAY') {
11734: foreach my $line (@{$dirlistref}) {
11735: my ($file_name,$rest)=split(/\&/,$line,2);
11736: if ($file_name eq $fname){
11737: $file_name = $path.$file_name;
11738: if ($group ne '') {
11739: $file_name = $group.$file_name;
11740: }
11741: $found_file = 1;
11742: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11743: foreach my $lock (@lockers) {
11744: if (ref($lock) eq 'ARRAY') {
11745: my ($symb,$crsid) = @{$lock};
11746: if ($crsid eq $env{'request.course.id'}) {
11747: if (ref($navmap)) {
11748: my $res = $navmap->getBySymb($symb);
11749: foreach my $part (@{$res->parts()}) {
11750: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11751: unless (($slot_status == $res->RESERVED) ||
11752: ($slot_status == $res->RESERVED_LOCATION)) {
11753: $locked_file = 1;
11754: }
1.991 raeburn 11755: }
1.1021 raeburn 11756: } else {
11757: $locked_file = 1;
1.991 raeburn 11758: }
11759: } else {
11760: $locked_file = 1;
11761: }
11762: }
1.1021 raeburn 11763: }
11764: } else {
11765: my @info = split(/\&/,$rest);
11766: my $currsize = $info[6]/1000;
11767: if ($currsize < $filesize) {
11768: my $extra = $filesize - $currsize;
11769: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 11770: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11771: &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 11772: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11773: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11774: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11775: return ('will_exceed_quota',$msg);
11776: }
1.984 raeburn 11777: }
11778: }
1.661 raeburn 11779: }
11780: }
11781: }
11782: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 11783: my $msg = '<p class="LC_warning">'.
11784: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
11785: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11786: return ('will_exceed_quota',$msg);
11787: } elsif ($found_file) {
11788: if ($locked_file) {
1.1075.2.69 raeburn 11789: my $msg = '<p class="LC_warning">';
1.661 raeburn 11790: $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 11791: $msg .= '</p>';
1.661 raeburn 11792: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11793: return ('file_locked',$msg);
11794: } else {
1.1075.2.69 raeburn 11795: my $msg = '<p class="LC_error">';
1.984 raeburn 11796: $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 11797: $msg .= '</p>';
1.984 raeburn 11798: return ('existingfile',$msg);
1.661 raeburn 11799: }
11800: }
11801: }
11802:
1.987 raeburn 11803: sub check_for_traversal {
11804: my ($path,$url,$toplevel) = @_;
11805: my @parts=split(/\//,$path);
11806: my $cleanpath;
11807: my $fullpath = $url;
11808: for (my $i=0;$i<@parts;$i++) {
11809: next if ($parts[$i] eq '.');
11810: if ($parts[$i] eq '..') {
11811: $fullpath =~ s{([^/]+/)$}{};
11812: } else {
11813: $fullpath .= $parts[$i].'/';
11814: }
11815: }
11816: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11817: $cleanpath = $1;
11818: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11819: my $curr_toprel = $1;
11820: my @parts = split(/\//,$curr_toprel);
11821: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11822: my @urlparts = split(/\//,$url_toprel);
11823: my $doubledots;
11824: my $startdiff = -1;
11825: for (my $i=0; $i<@urlparts; $i++) {
11826: if ($startdiff == -1) {
11827: unless ($urlparts[$i] eq $parts[$i]) {
11828: $startdiff = $i;
11829: $doubledots .= '../';
11830: }
11831: } else {
11832: $doubledots .= '../';
11833: }
11834: }
11835: if ($startdiff > -1) {
11836: $cleanpath = $doubledots;
11837: for (my $i=$startdiff; $i<@parts; $i++) {
11838: $cleanpath .= $parts[$i].'/';
11839: }
11840: }
11841: }
11842: $cleanpath =~ s{(/)$}{};
11843: return $cleanpath;
11844: }
1.31 albertel 11845:
1.1053 raeburn 11846: sub is_archive_file {
11847: my ($mimetype) = @_;
11848: if (($mimetype eq 'application/octet-stream') ||
11849: ($mimetype eq 'application/x-stuffit') ||
11850: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11851: return 1;
11852: }
11853: return;
11854: }
11855:
11856: sub decompress_form {
1.1065 raeburn 11857: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11858: my %lt = &Apache::lonlocal::texthash (
11859: this => 'This file is an archive file.',
1.1067 raeburn 11860: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11861: itsc => 'Its contents are as follows:',
1.1053 raeburn 11862: youm => 'You may wish to extract its contents.',
11863: extr => 'Extract contents',
1.1067 raeburn 11864: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11865: proa => 'Process automatically?',
1.1053 raeburn 11866: yes => 'Yes',
11867: no => 'No',
1.1067 raeburn 11868: fold => 'Title for folder containing movie',
11869: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11870: );
1.1065 raeburn 11871: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11872: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11873: my $info = &list_archive_contents($fileloc,\@paths);
11874: if (@paths) {
11875: foreach my $path (@paths) {
11876: $path =~ s{^/}{};
1.1067 raeburn 11877: if ($path =~ m{^([^/]+)/$}) {
11878: $topdir = $1;
11879: }
1.1065 raeburn 11880: if ($path =~ m{^([^/]+)/}) {
11881: $toplevel{$1} = $path;
11882: } else {
11883: $toplevel{$path} = $path;
11884: }
11885: }
11886: }
1.1067 raeburn 11887: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 11888: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11889: "$topdir/media/",
11890: "$topdir/media/$topdir.mp4",
11891: "$topdir/media/FirstFrame.png",
11892: "$topdir/media/player.swf",
11893: "$topdir/media/swfobject.js",
11894: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 11895: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 11896: "$topdir/$topdir.mp4",
11897: "$topdir/$topdir\_config.xml",
11898: "$topdir/$topdir\_controller.swf",
11899: "$topdir/$topdir\_embed.css",
11900: "$topdir/$topdir\_First_Frame.png",
11901: "$topdir/$topdir\_player.html",
11902: "$topdir/$topdir\_Thumbnails.png",
11903: "$topdir/playerProductInstall.swf",
11904: "$topdir/scripts/",
11905: "$topdir/scripts/config_xml.js",
11906: "$topdir/scripts/handlebars.js",
11907: "$topdir/scripts/jquery-1.7.1.min.js",
11908: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11909: "$topdir/scripts/modernizr.js",
11910: "$topdir/scripts/player-min.js",
11911: "$topdir/scripts/swfobject.js",
11912: "$topdir/skins/",
11913: "$topdir/skins/configuration_express.xml",
11914: "$topdir/skins/express_show/",
11915: "$topdir/skins/express_show/player-min.css",
11916: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 11917: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
11918: "$topdir/$topdir.mp4",
11919: "$topdir/$topdir\_config.xml",
11920: "$topdir/$topdir\_controller.swf",
11921: "$topdir/$topdir\_embed.css",
11922: "$topdir/$topdir\_First_Frame.png",
11923: "$topdir/$topdir\_player.html",
11924: "$topdir/$topdir\_Thumbnails.png",
11925: "$topdir/playerProductInstall.swf",
11926: "$topdir/scripts/",
11927: "$topdir/scripts/config_xml.js",
11928: "$topdir/scripts/techsmith-smart-player.min.js",
11929: "$topdir/skins/",
11930: "$topdir/skins/configuration_express.xml",
11931: "$topdir/skins/express_show/",
11932: "$topdir/skins/express_show/spritesheet.min.css",
11933: "$topdir/skins/express_show/spritesheet.png",
11934: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 11935: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11936: if (@diffs == 0) {
1.1075.2.59 raeburn 11937: $is_camtasia = 6;
11938: } else {
1.1075.2.81 raeburn 11939: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 11940: if (@diffs == 0) {
11941: $is_camtasia = 8;
1.1075.2.81 raeburn 11942: } else {
11943: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
11944: if (@diffs == 0) {
11945: $is_camtasia = 8;
11946: }
1.1075.2.59 raeburn 11947: }
1.1067 raeburn 11948: }
11949: }
11950: my $output;
11951: if ($is_camtasia) {
11952: $output = <<"ENDCAM";
11953: <script type="text/javascript" language="Javascript">
11954: // <![CDATA[
11955:
11956: function camtasiaToggle() {
11957: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11958: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 11959: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11960: document.getElementById('camtasia_titles').style.display='block';
11961: } else {
11962: document.getElementById('camtasia_titles').style.display='none';
11963: }
11964: }
11965: }
11966: return;
11967: }
11968:
11969: // ]]>
11970: </script>
11971: <p>$lt{'camt'}</p>
11972: ENDCAM
1.1065 raeburn 11973: } else {
1.1067 raeburn 11974: $output = '<p>'.$lt{'this'};
11975: if ($info eq '') {
11976: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11977: } else {
11978: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11979: '<div><pre>'.$info.'</pre></div>';
11980: }
1.1065 raeburn 11981: }
1.1067 raeburn 11982: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11983: my $duplicates;
11984: my $num = 0;
11985: if (ref($dirlist) eq 'ARRAY') {
11986: foreach my $item (@{$dirlist}) {
11987: if (ref($item) eq 'ARRAY') {
11988: if (exists($toplevel{$item->[0]})) {
11989: $duplicates .=
11990: &start_data_table_row().
11991: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11992: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11993: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11994: 'value="1" />'.&mt('Yes').'</label>'.
11995: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11996: '<td>'.$item->[0].'</td>';
11997: if ($item->[2]) {
11998: $duplicates .= '<td>'.&mt('Directory').'</td>';
11999: } else {
12000: $duplicates .= '<td>'.&mt('File').'</td>';
12001: }
12002: $duplicates .= '<td>'.$item->[3].'</td>'.
12003: '<td>'.
12004: &Apache::lonlocal::locallocaltime($item->[4]).
12005: '</td>'.
12006: &end_data_table_row();
12007: $num ++;
12008: }
12009: }
12010: }
12011: }
12012: my $itemcount;
12013: if (@paths > 0) {
12014: $itemcount = scalar(@paths);
12015: } else {
12016: $itemcount = 1;
12017: }
1.1067 raeburn 12018: if ($is_camtasia) {
12019: $output .= $lt{'auto'}.'<br />'.
12020: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 12021: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12022: $lt{'yes'}.'</label> <label>'.
12023: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12024: $lt{'no'}.'</label></span><br />'.
12025: '<div id="camtasia_titles" style="display:block">'.
12026: &Apache::lonhtmlcommon::start_pick_box().
12027: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12028: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12029: &Apache::lonhtmlcommon::row_closure().
12030: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12031: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12032: &Apache::lonhtmlcommon::row_closure(1).
12033: &Apache::lonhtmlcommon::end_pick_box().
12034: '</div>';
12035: }
1.1065 raeburn 12036: $output .=
12037: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12038: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12039: "\n";
1.1065 raeburn 12040: if ($duplicates ne '') {
12041: $output .= '<p><span class="LC_warning">'.
12042: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12043: &start_data_table().
12044: &start_data_table_header_row().
12045: '<th>'.&mt('Overwrite?').'</th>'.
12046: '<th>'.&mt('Name').'</th>'.
12047: '<th>'.&mt('Type').'</th>'.
12048: '<th>'.&mt('Size').'</th>'.
12049: '<th>'.&mt('Last modified').'</th>'.
12050: &end_data_table_header_row().
12051: $duplicates.
12052: &end_data_table().
12053: '</p>';
12054: }
1.1067 raeburn 12055: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12056: if (ref($hiddenelements) eq 'HASH') {
12057: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12058: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12059: }
12060: }
12061: $output .= <<"END";
1.1067 raeburn 12062: <br />
1.1053 raeburn 12063: <input type="submit" name="decompress" value="$lt{'extr'}" />
12064: </form>
12065: $noextract
12066: END
12067: return $output;
12068: }
12069:
1.1065 raeburn 12070: sub decompression_utility {
12071: my ($program) = @_;
12072: my @utilities = ('tar','gunzip','bunzip2','unzip');
12073: my $location;
12074: if (grep(/^\Q$program\E$/,@utilities)) {
12075: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12076: '/usr/sbin/') {
12077: if (-x $dir.$program) {
12078: $location = $dir.$program;
12079: last;
12080: }
12081: }
12082: }
12083: return $location;
12084: }
12085:
12086: sub list_archive_contents {
12087: my ($file,$pathsref) = @_;
12088: my (@cmd,$output);
12089: my $needsregexp;
12090: if ($file =~ /\.zip$/) {
12091: @cmd = (&decompression_utility('unzip'),"-l");
12092: $needsregexp = 1;
12093: } elsif (($file =~ m/\.tar\.gz$/) ||
12094: ($file =~ /\.tgz$/)) {
12095: @cmd = (&decompression_utility('tar'),"-ztf");
12096: } elsif ($file =~ /\.tar\.bz2$/) {
12097: @cmd = (&decompression_utility('tar'),"-jtf");
12098: } elsif ($file =~ m|\.tar$|) {
12099: @cmd = (&decompression_utility('tar'),"-tf");
12100: }
12101: if (@cmd) {
12102: undef($!);
12103: undef($@);
12104: if (open(my $fh,"-|", @cmd, $file)) {
12105: while (my $line = <$fh>) {
12106: $output .= $line;
12107: chomp($line);
12108: my $item;
12109: if ($needsregexp) {
12110: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12111: } else {
12112: $item = $line;
12113: }
12114: if ($item ne '') {
12115: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12116: push(@{$pathsref},$item);
12117: }
12118: }
12119: }
12120: close($fh);
12121: }
12122: }
12123: return $output;
12124: }
12125:
1.1053 raeburn 12126: sub decompress_uploaded_file {
12127: my ($file,$dir) = @_;
12128: &Apache::lonnet::appenv({'cgi.file' => $file});
12129: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12130: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12131: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12132: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12133: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12134: my $decompressed = $env{'cgi.decompressed'};
12135: &Apache::lonnet::delenv('cgi.file');
12136: &Apache::lonnet::delenv('cgi.dir');
12137: &Apache::lonnet::delenv('cgi.decompressed');
12138: return ($decompressed,$result);
12139: }
12140:
1.1055 raeburn 12141: sub process_decompression {
12142: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 12143: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12144: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12145: &mt('Unexpected file path.').'</p>'."\n";
12146: }
12147: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12148: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12149: &mt('Unexpected course context.').'</p>'."\n";
12150: }
12151: unless ($file eq &Apache::lonnet::clean_filename($file)) {
12152: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12153: &mt('Filename contained unexpected characters.').'</p>'."\n";
12154: }
1.1055 raeburn 12155: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 12156: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 12157: $error = &mt('Filename not a supported archive file type.').
12158: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12159: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12160: } else {
12161: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12162: if ($docuhome eq 'no_host') {
12163: $error = &mt('Could not determine home server for course.');
12164: } else {
12165: my @ids=&Apache::lonnet::current_machine_ids();
12166: my $currdir = "$dir_root/$destination";
12167: if (grep(/^\Q$docuhome\E$/,@ids)) {
12168: $dir = &LONCAPA::propath($docudom,$docuname).
12169: "$dir_root/$destination";
12170: } else {
12171: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12172: "$dir_root/$docudom/$docuname/$destination";
12173: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12174: $error = &mt('Archive file not found.');
12175: }
12176: }
1.1065 raeburn 12177: my (@to_overwrite,@to_skip);
12178: if ($env{'form.archive_overwrite_total'} > 0) {
12179: my $total = $env{'form.archive_overwrite_total'};
12180: for (my $i=0; $i<$total; $i++) {
12181: if ($env{'form.archive_overwrite_'.$i} == 1) {
12182: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12183: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12184: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12185: }
12186: }
12187: }
12188: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 12189: my $numoverwrite = scalar(@to_overwrite);
12190: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12191: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12192: } elsif ($dir eq '') {
1.1055 raeburn 12193: $error = &mt('Directory containing archive file unavailable.');
12194: } elsif (!$error) {
1.1065 raeburn 12195: my ($decompressed,$display);
1.1075.2.128 raeburn 12196: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12197: my $tempdir = time.'_'.$$.int(rand(10000));
12198: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 12199: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12200: ($decompressed,$display) =
12201: &decompress_uploaded_file($file,"$dir/$tempdir");
12202: foreach my $item (@to_skip) {
12203: if (($item ne '') && ($item !~ /\.\./)) {
12204: if (-f "$dir/$tempdir/$item") {
12205: unlink("$dir/$tempdir/$item");
12206: } elsif (-d "$dir/$tempdir/$item") {
12207: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
12208: }
12209: }
12210: }
12211: foreach my $item (@to_overwrite) {
12212: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12213: if (($item ne '') && ($item !~ /\.\./)) {
12214: if (-f "$dir/$item") {
12215: unlink("$dir/$item");
12216: } elsif (-d "$dir/$item") {
12217: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
12218: }
12219: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12220: }
1.1065 raeburn 12221: }
12222: }
1.1075.2.128 raeburn 12223: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
12224: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
12225: }
1.1065 raeburn 12226: }
12227: } else {
12228: ($decompressed,$display) =
12229: &decompress_uploaded_file($file,$dir);
12230: }
1.1055 raeburn 12231: if ($decompressed eq 'ok') {
1.1065 raeburn 12232: $output = '<p class="LC_info">'.
12233: &mt('Files extracted successfully from archive.').
12234: '</p>'."\n";
1.1055 raeburn 12235: my ($warning,$result,@contents);
12236: my ($newdirlistref,$newlisterror) =
12237: &Apache::lonnet::dirlist($currdir,$docudom,
12238: $docuname,1);
12239: my (%is_dir,%changes,@newitems);
12240: my $dirptr = 16384;
1.1065 raeburn 12241: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12242: foreach my $dir_line (@{$newdirlistref}) {
12243: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 12244: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12245: push(@newitems,$item);
12246: if ($dirptr&$testdir) {
12247: $is_dir{$item} = 1;
12248: }
12249: $changes{$item} = 1;
12250: }
12251: }
12252: }
12253: if (keys(%changes) > 0) {
12254: foreach my $item (sort(@newitems)) {
12255: if ($changes{$item}) {
12256: push(@contents,$item);
12257: }
12258: }
12259: }
12260: if (@contents > 0) {
1.1067 raeburn 12261: my $wantform;
12262: unless ($env{'form.autoextract_camtasia'}) {
12263: $wantform = 1;
12264: }
1.1056 raeburn 12265: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12266: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12267: $currdir,\%is_dir,
12268: \%children,\%parent,
1.1056 raeburn 12269: \@contents,\%dirorder,
12270: \%titles,$wantform);
1.1055 raeburn 12271: if ($datatable ne '') {
12272: $output .= &archive_options_form('decompressed',$datatable,
12273: $count,$hiddenelem);
1.1065 raeburn 12274: my $startcount = 6;
1.1055 raeburn 12275: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12276: \%titles,\%children);
1.1055 raeburn 12277: }
1.1067 raeburn 12278: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 12279: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12280: my %displayed;
12281: my $total = 1;
12282: $env{'form.archive_directory'} = [];
12283: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12284: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12285: $path =~ s{/$}{};
12286: my $item;
12287: if ($path ne '') {
12288: $item = "$path/$titles{$i}";
12289: } else {
12290: $item = $titles{$i};
12291: }
12292: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12293: if ($item eq $contents[0]) {
12294: push(@{$env{'form.archive_directory'}},$i);
12295: $env{'form.archive_'.$i} = 'display';
12296: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12297: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 12298: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12299: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12300: $env{'form.archive_'.$i} = 'display';
12301: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12302: $displayed{'web'} = $i;
12303: } else {
1.1075.2.59 raeburn 12304: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12305: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12306: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12307: push(@{$env{'form.archive_directory'}},$i);
12308: }
12309: $env{'form.archive_'.$i} = 'dependency';
12310: }
12311: $total ++;
12312: }
12313: for (my $i=1; $i<$total; $i++) {
12314: next if ($i == $displayed{'web'});
12315: next if ($i == $displayed{'folder'});
12316: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12317: }
12318: $env{'form.phase'} = 'decompress_cleanup';
12319: $env{'form.archivedelete'} = 1;
12320: $env{'form.archive_count'} = $total-1;
12321: $output .=
12322: &process_extracted_files('coursedocs',$docudom,
12323: $docuname,$destination,
12324: $dir_root,$hiddenelem);
12325: }
1.1055 raeburn 12326: } else {
12327: $warning = &mt('No new items extracted from archive file.');
12328: }
12329: } else {
12330: $output = $display;
12331: $error = &mt('An error occurred during extraction from the archive file.');
12332: }
12333: }
12334: }
12335: }
12336: if ($error) {
12337: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12338: $error.'</p>'."\n";
12339: }
12340: if ($warning) {
12341: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12342: }
12343: return $output;
12344: }
12345:
12346: sub get_extracted {
1.1056 raeburn 12347: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12348: $titles,$wantform) = @_;
1.1055 raeburn 12349: my $count = 0;
12350: my $depth = 0;
12351: my $datatable;
1.1056 raeburn 12352: my @hierarchy;
1.1055 raeburn 12353: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12354: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12355: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12356: foreach my $item (@{$contents}) {
12357: $count ++;
1.1056 raeburn 12358: @{$dirorder->{$count}} = @hierarchy;
12359: $titles->{$count} = $item;
1.1055 raeburn 12360: &archive_hierarchy($depth,$count,$parent,$children);
12361: if ($wantform) {
12362: $datatable .= &archive_row($is_dir->{$item},$item,
12363: $currdir,$depth,$count);
12364: }
12365: if ($is_dir->{$item}) {
12366: $depth ++;
1.1056 raeburn 12367: push(@hierarchy,$count);
12368: $parent->{$depth} = $count;
1.1055 raeburn 12369: $datatable .=
12370: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12371: \$depth,\$count,\@hierarchy,$dirorder,
12372: $children,$parent,$titles,$wantform);
1.1055 raeburn 12373: $depth --;
1.1056 raeburn 12374: pop(@hierarchy);
1.1055 raeburn 12375: }
12376: }
12377: return ($count,$datatable);
12378: }
12379:
12380: sub recurse_extracted_archive {
1.1056 raeburn 12381: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12382: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12383: my $result='';
1.1056 raeburn 12384: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12385: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12386: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12387: return $result;
12388: }
12389: my $dirptr = 16384;
12390: my ($newdirlistref,$newlisterror) =
12391: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12392: if (ref($newdirlistref) eq 'ARRAY') {
12393: foreach my $dir_line (@{$newdirlistref}) {
12394: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12395: unless ($item =~ /^\.+$/) {
12396: $$count ++;
1.1056 raeburn 12397: @{$dirorder->{$$count}} = @{$hierarchy};
12398: $titles->{$$count} = $item;
1.1055 raeburn 12399: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12400:
1.1055 raeburn 12401: my $is_dir;
12402: if ($dirptr&$testdir) {
12403: $is_dir = 1;
12404: }
12405: if ($wantform) {
12406: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12407: }
12408: if ($is_dir) {
12409: $$depth ++;
1.1056 raeburn 12410: push(@{$hierarchy},$$count);
12411: $parent->{$$depth} = $$count;
1.1055 raeburn 12412: $result .=
12413: &recurse_extracted_archive("$currdir/$item",$docudom,
12414: $docuname,$depth,$count,
1.1056 raeburn 12415: $hierarchy,$dirorder,$children,
12416: $parent,$titles,$wantform);
1.1055 raeburn 12417: $$depth --;
1.1056 raeburn 12418: pop(@{$hierarchy});
1.1055 raeburn 12419: }
12420: }
12421: }
12422: }
12423: return $result;
12424: }
12425:
12426: sub archive_hierarchy {
12427: my ($depth,$count,$parent,$children) =@_;
12428: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12429: if (exists($parent->{$depth})) {
12430: $children->{$parent->{$depth}} .= $count.':';
12431: }
12432: }
12433: return;
12434: }
12435:
12436: sub archive_row {
12437: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12438: my ($name) = ($item =~ m{([^/]+)$});
12439: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12440: 'display' => 'Add as file',
1.1055 raeburn 12441: 'dependency' => 'Include as dependency',
12442: 'discard' => 'Discard',
12443: );
12444: if ($is_dir) {
1.1059 raeburn 12445: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12446: }
1.1056 raeburn 12447: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12448: my $offset = 0;
1.1055 raeburn 12449: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12450: $offset ++;
1.1065 raeburn 12451: if ($action ne 'display') {
12452: $offset ++;
12453: }
1.1055 raeburn 12454: $output .= '<td><span class="LC_nobreak">'.
12455: '<label><input type="radio" name="archive_'.$count.
12456: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12457: my $text = $choices{$action};
12458: if ($is_dir) {
12459: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12460: if ($action eq 'display') {
1.1059 raeburn 12461: $text = &mt('Add as folder');
1.1055 raeburn 12462: }
1.1056 raeburn 12463: } else {
12464: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12465:
12466: }
12467: $output .= ' /> '.$choices{$action}.'</label></span>';
12468: if ($action eq 'dependency') {
12469: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12470: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12471: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12472: '<option value=""></option>'."\n".
12473: '</select>'."\n".
12474: '</div>';
1.1059 raeburn 12475: } elsif ($action eq 'display') {
12476: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12477: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12478: '</div>';
1.1055 raeburn 12479: }
1.1056 raeburn 12480: $output .= '</td>';
1.1055 raeburn 12481: }
12482: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12483: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12484: for (my $i=0; $i<$depth; $i++) {
12485: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12486: }
12487: if ($is_dir) {
12488: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12489: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12490: } else {
12491: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12492: }
12493: $output .= ' '.$name.'</td>'."\n".
12494: &end_data_table_row();
12495: return $output;
12496: }
12497:
12498: sub archive_options_form {
1.1065 raeburn 12499: my ($form,$display,$count,$hiddenelem) = @_;
12500: my %lt = &Apache::lonlocal::texthash(
12501: perm => 'Permanently remove archive file?',
12502: hows => 'How should each extracted item be incorporated in the course?',
12503: cont => 'Content actions for all',
12504: addf => 'Add as folder/file',
12505: incd => 'Include as dependency for a displayed file',
12506: disc => 'Discard',
12507: no => 'No',
12508: yes => 'Yes',
12509: save => 'Save',
12510: );
12511: my $output = <<"END";
12512: <form name="$form" method="post" action="">
12513: <p><span class="LC_nobreak">$lt{'perm'}
12514: <label>
12515: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12516: </label>
12517:
12518: <label>
12519: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12520: </span>
12521: </p>
12522: <input type="hidden" name="phase" value="decompress_cleanup" />
12523: <br />$lt{'hows'}
12524: <div class="LC_columnSection">
12525: <fieldset>
12526: <legend>$lt{'cont'}</legend>
12527: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12528: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12529: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12530: </fieldset>
12531: </div>
12532: END
12533: return $output.
1.1055 raeburn 12534: &start_data_table()."\n".
1.1065 raeburn 12535: $display."\n".
1.1055 raeburn 12536: &end_data_table()."\n".
12537: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12538: $hiddenelem.
1.1065 raeburn 12539: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12540: '</form>';
12541: }
12542:
12543: sub archive_javascript {
1.1056 raeburn 12544: my ($startcount,$numitems,$titles,$children) = @_;
12545: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12546: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12547: my $scripttag = <<START;
12548: <script type="text/javascript">
12549: // <![CDATA[
12550:
12551: function checkAll(form,prefix) {
12552: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12553: for (var i=0; i < form.elements.length; i++) {
12554: var id = form.elements[i].id;
12555: if ((id != '') && (id != undefined)) {
12556: if (idstr.test(id)) {
12557: if (form.elements[i].type == 'radio') {
12558: form.elements[i].checked = true;
1.1056 raeburn 12559: var nostart = i-$startcount;
1.1059 raeburn 12560: var offset = nostart%7;
12561: var count = (nostart-offset)/7;
1.1056 raeburn 12562: dependencyCheck(form,count,offset);
1.1055 raeburn 12563: }
12564: }
12565: }
12566: }
12567: }
12568:
12569: function propagateCheck(form,count) {
12570: if (count > 0) {
1.1059 raeburn 12571: var startelement = $startcount + ((count-1) * 7);
12572: for (var j=1; j<6; j++) {
12573: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12574: var item = startelement + j;
12575: if (form.elements[item].type == 'radio') {
12576: if (form.elements[item].checked) {
12577: containerCheck(form,count,j);
12578: break;
12579: }
1.1055 raeburn 12580: }
12581: }
12582: }
12583: }
12584: }
12585:
12586: numitems = $numitems
1.1056 raeburn 12587: var titles = new Array(numitems);
12588: var parents = new Array(numitems);
1.1055 raeburn 12589: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12590: parents[i] = new Array;
1.1055 raeburn 12591: }
1.1059 raeburn 12592: var maintitle = '$maintitle';
1.1055 raeburn 12593:
12594: START
12595:
1.1056 raeburn 12596: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12597: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12598: for (my $i=0; $i<@contents; $i ++) {
12599: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12600: }
12601: }
12602:
1.1056 raeburn 12603: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12604: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12605: }
12606:
1.1055 raeburn 12607: $scripttag .= <<END;
12608:
12609: function containerCheck(form,count,offset) {
12610: if (count > 0) {
1.1056 raeburn 12611: dependencyCheck(form,count,offset);
1.1059 raeburn 12612: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12613: form.elements[item].checked = true;
12614: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12615: if (parents[count].length > 0) {
12616: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12617: containerCheck(form,parents[count][j],offset);
12618: }
12619: }
12620: }
12621: }
12622: }
12623:
12624: function dependencyCheck(form,count,offset) {
12625: if (count > 0) {
1.1059 raeburn 12626: var chosen = (offset+$startcount)+7*(count-1);
12627: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12628: var currtype = form.elements[depitem].type;
12629: if (form.elements[chosen].value == 'dependency') {
12630: document.getElementById('arc_depon_'+count).style.display='block';
12631: form.elements[depitem].options.length = 0;
12632: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 12633: for (var i=1; i<=numitems; i++) {
12634: if (i == count) {
12635: continue;
12636: }
1.1059 raeburn 12637: var startelement = $startcount + (i-1) * 7;
12638: for (var j=1; j<6; j++) {
12639: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12640: var item = startelement + j;
12641: if (form.elements[item].type == 'radio') {
12642: if (form.elements[item].checked) {
12643: if (form.elements[item].value == 'display') {
12644: var n = form.elements[depitem].options.length;
12645: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12646: }
12647: }
12648: }
12649: }
12650: }
12651: }
12652: } else {
12653: document.getElementById('arc_depon_'+count).style.display='none';
12654: form.elements[depitem].options.length = 0;
12655: form.elements[depitem].options[0] = new Option('Select','',true,true);
12656: }
1.1059 raeburn 12657: titleCheck(form,count,offset);
1.1056 raeburn 12658: }
12659: }
12660:
12661: function propagateSelect(form,count,offset) {
12662: if (count > 0) {
1.1065 raeburn 12663: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12664: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12665: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12666: if (parents[count].length > 0) {
12667: for (var j=0; j<parents[count].length; j++) {
12668: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12669: }
12670: }
12671: }
12672: }
12673: }
1.1056 raeburn 12674:
12675: function containerSelect(form,count,offset,picked) {
12676: if (count > 0) {
1.1065 raeburn 12677: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12678: if (form.elements[item].type == 'radio') {
12679: if (form.elements[item].value == 'dependency') {
12680: if (form.elements[item+1].type == 'select-one') {
12681: for (var i=0; i<form.elements[item+1].options.length; i++) {
12682: if (form.elements[item+1].options[i].value == picked) {
12683: form.elements[item+1].selectedIndex = i;
12684: break;
12685: }
12686: }
12687: }
12688: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12689: if (parents[count].length > 0) {
12690: for (var j=0; j<parents[count].length; j++) {
12691: containerSelect(form,parents[count][j],offset,picked);
12692: }
12693: }
12694: }
12695: }
12696: }
12697: }
12698: }
12699:
1.1059 raeburn 12700: function titleCheck(form,count,offset) {
12701: if (count > 0) {
12702: var chosen = (offset+$startcount)+7*(count-1);
12703: var depitem = $startcount + ((count-1) * 7) + 2;
12704: var currtype = form.elements[depitem].type;
12705: if (form.elements[chosen].value == 'display') {
12706: document.getElementById('arc_title_'+count).style.display='block';
12707: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12708: document.getElementById('archive_title_'+count).value=maintitle;
12709: }
12710: } else {
12711: document.getElementById('arc_title_'+count).style.display='none';
12712: if (currtype == 'text') {
12713: document.getElementById('archive_title_'+count).value='';
12714: }
12715: }
12716: }
12717: return;
12718: }
12719:
1.1055 raeburn 12720: // ]]>
12721: </script>
12722: END
12723: return $scripttag;
12724: }
12725:
12726: sub process_extracted_files {
1.1067 raeburn 12727: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12728: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 12729: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 12730: my @ids=&Apache::lonnet::current_machine_ids();
12731: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12732: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12733: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12734: if (grep(/^\Q$docuhome\E$/,@ids)) {
12735: $prefix = &LONCAPA::propath($docudom,$docuname);
12736: $pathtocheck = "$dir_root/$destination";
12737: $dir = $dir_root;
12738: $ishome = 1;
12739: } else {
12740: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12741: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 12742: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 12743: }
12744: my $currdir = "$dir_root/$destination";
12745: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12746: if ($env{'form.folderpath'}) {
12747: my @items = split('&',$env{'form.folderpath'});
12748: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 12749: if ($env{'form.folderpath'} =~ /\:1$/) {
12750: $containers{'0'}='page';
12751: } else {
12752: $containers{'0'}='sequence';
12753: }
1.1055 raeburn 12754: }
12755: my @archdirs = &get_env_multiple('form.archive_directory');
12756: if ($numitems) {
12757: for (my $i=1; $i<=$numitems; $i++) {
12758: my $path = $env{'form.archive_content_'.$i};
12759: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12760: my $item = $1;
12761: $toplevelitems{$item} = $i;
12762: if (grep(/^\Q$i\E$/,@archdirs)) {
12763: $is_dir{$item} = 1;
12764: }
12765: }
12766: }
12767: }
1.1067 raeburn 12768: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12769: if (keys(%toplevelitems) > 0) {
12770: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12771: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12772: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12773: }
1.1066 raeburn 12774: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12775: if ($numitems) {
12776: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 12777: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12778: my $path = $env{'form.archive_content_'.$i};
12779: if ($path =~ /^\Q$pathtocheck\E/) {
12780: if ($env{'form.archive_'.$i} eq 'discard') {
12781: if ($prefix ne '' && $path ne '') {
12782: if (-e $prefix.$path) {
1.1066 raeburn 12783: if ((@archdirs > 0) &&
12784: (grep(/^\Q$i\E$/,@archdirs))) {
12785: $todeletedir{$prefix.$path} = 1;
12786: } else {
12787: $todelete{$prefix.$path} = 1;
12788: }
1.1055 raeburn 12789: }
12790: }
12791: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12792: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12793: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12794: $docstitle = $env{'form.archive_title_'.$i};
12795: if ($docstitle eq '') {
12796: $docstitle = $title;
12797: }
1.1055 raeburn 12798: $outer = 0;
1.1056 raeburn 12799: if (ref($dirorder{$i}) eq 'ARRAY') {
12800: if (@{$dirorder{$i}} > 0) {
12801: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12802: if ($env{'form.archive_'.$item} eq 'display') {
12803: $outer = $item;
12804: last;
12805: }
12806: }
12807: }
12808: }
12809: my ($errtext,$fatal) =
12810: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12811: '/'.$folders{$outer}.'.'.
12812: $containers{$outer});
12813: next if ($fatal);
12814: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12815: if ($context eq 'coursedocs') {
1.1056 raeburn 12816: $mapinner{$i} = time;
1.1055 raeburn 12817: $folders{$i} = 'default_'.$mapinner{$i};
12818: $containers{$i} = 'sequence';
12819: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12820: $folders{$i}.'.'.$containers{$i};
12821: my $newidx = &LONCAPA::map::getresidx();
12822: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12823: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12824: push(@LONCAPA::map::order,$newidx);
12825: my ($outtext,$errtext) =
12826: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12827: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12828: '.'.$containers{$outer},1,1);
1.1056 raeburn 12829: $newseqid{$i} = $newidx;
1.1067 raeburn 12830: unless ($errtext) {
1.1075.2.128 raeburn 12831: $result .= '<li>'.&mt('Folder: [_1] added to course',
12832: &HTML::Entities::encode($docstitle,'<>&"'))..
12833: '</li>'."\n";
1.1067 raeburn 12834: }
1.1055 raeburn 12835: }
12836: } else {
12837: if ($context eq 'coursedocs') {
12838: my $newidx=&LONCAPA::map::getresidx();
12839: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12840: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12841: $title;
1.1075.2.128 raeburn 12842: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
12843: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
12844: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 12845: }
1.1075.2.128 raeburn 12846: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12847: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
12848: }
12849: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12850: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
12851: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
12852: unless ($ishome) {
12853: my $fetch = "$newdest{$i}/$title";
12854: $fetch =~ s/^\Q$prefix$dir\E//;
12855: $prompttofetch{$fetch} = 1;
12856: }
12857: }
12858: }
12859: $LONCAPA::map::resources[$newidx]=
12860: $docstitle.':'.$url.':false:normal:res';
12861: push(@LONCAPA::map::order, $newidx);
12862: my ($outtext,$errtext)=
12863: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12864: $docuname.'/'.$folders{$outer}.
12865: '.'.$containers{$outer},1,1);
12866: unless ($errtext) {
12867: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
12868: $result .= '<li>'.&mt('File: [_1] added to course',
12869: &HTML::Entities::encode($docstitle,'<>&"')).
12870: '</li>'."\n";
12871: }
1.1067 raeburn 12872: }
1.1075.2.128 raeburn 12873: } else {
12874: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
12875: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 12876: }
1.1055 raeburn 12877: }
12878: }
1.1075.2.11 raeburn 12879: }
12880: } else {
1.1075.2.128 raeburn 12881: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
12882: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 12883: }
12884: }
12885: for (my $i=1; $i<=$numitems; $i++) {
12886: next unless ($env{'form.archive_'.$i} eq 'dependency');
12887: my $path = $env{'form.archive_content_'.$i};
12888: if ($path =~ /^\Q$pathtocheck\E/) {
12889: my ($title) = ($path =~ m{/([^/]+)$});
12890: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12891: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12892: if (ref($dirorder{$i}) eq 'ARRAY') {
12893: my ($itemidx,$fullpath,$relpath);
12894: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12895: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12896: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 12897: if ($dirorder{$i}->[$j] eq $container) {
12898: $itemidx = $j;
1.1056 raeburn 12899: }
12900: }
1.1075.2.11 raeburn 12901: }
12902: if ($itemidx eq '') {
12903: $itemidx = 0;
12904: }
12905: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12906: if ($mapinner{$referrer{$i}}) {
12907: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12908: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12909: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12910: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12911: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12912: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12913: if (!-e $fullpath) {
12914: mkdir($fullpath,0755);
1.1056 raeburn 12915: }
12916: }
1.1075.2.11 raeburn 12917: } else {
12918: last;
1.1056 raeburn 12919: }
1.1075.2.11 raeburn 12920: }
12921: }
12922: } elsif ($newdest{$referrer{$i}}) {
12923: $fullpath = $newdest{$referrer{$i}};
12924: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12925: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12926: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12927: last;
12928: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12929: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12930: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12931: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12932: if (!-e $fullpath) {
12933: mkdir($fullpath,0755);
1.1056 raeburn 12934: }
12935: }
1.1075.2.11 raeburn 12936: } else {
12937: last;
1.1056 raeburn 12938: }
1.1075.2.11 raeburn 12939: }
12940: }
12941: if ($fullpath ne '') {
12942: if (-e "$prefix$path") {
1.1075.2.128 raeburn 12943: unless (rename("$prefix$path","$fullpath/$title")) {
12944: $warning .= &mt('Failed to rename dependency').'<br />';
12945: }
1.1075.2.11 raeburn 12946: }
12947: if (-e "$fullpath/$title") {
12948: my $showpath;
12949: if ($relpath ne '') {
12950: $showpath = "$relpath/$title";
12951: } else {
12952: $showpath = "/$title";
1.1056 raeburn 12953: }
1.1075.2.128 raeburn 12954: $result .= '<li>'.&mt('[_1] included as a dependency',
12955: &HTML::Entities::encode($showpath,'<>&"')).
12956: '</li>'."\n";
12957: unless ($ishome) {
12958: my $fetch = "$fullpath/$title";
12959: $fetch =~ s/^\Q$prefix$dir\E//;
12960: $prompttofetch{$fetch} = 1;
12961: }
1.1055 raeburn 12962: }
12963: }
12964: }
1.1075.2.11 raeburn 12965: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12966: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 12967: &HTML::Entities::encode($path,'<>&"'),
12968: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
12969: '<br />';
1.1055 raeburn 12970: }
12971: } else {
1.1075.2.128 raeburn 12972: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
12973: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 12974: }
12975: }
12976: if (keys(%todelete)) {
12977: foreach my $key (keys(%todelete)) {
12978: unlink($key);
1.1066 raeburn 12979: }
12980: }
12981: if (keys(%todeletedir)) {
12982: foreach my $key (keys(%todeletedir)) {
12983: rmdir($key);
12984: }
12985: }
12986: foreach my $dir (sort(keys(%is_dir))) {
12987: if (($pathtocheck ne '') && ($dir ne '')) {
12988: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12989: }
12990: }
1.1067 raeburn 12991: if ($result ne '') {
12992: $output .= '<ul>'."\n".
12993: $result."\n".
12994: '</ul>';
12995: }
12996: unless ($ishome) {
12997: my $replicationfail;
12998: foreach my $item (keys(%prompttofetch)) {
12999: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13000: unless ($fetchresult eq 'ok') {
13001: $replicationfail .= '<li>'.$item.'</li>'."\n";
13002: }
13003: }
13004: if ($replicationfail) {
13005: $output .= '<p class="LC_error">'.
13006: &mt('Course home server failed to retrieve:').'<ul>'.
13007: $replicationfail.
13008: '</ul></p>';
13009: }
13010: }
1.1055 raeburn 13011: } else {
13012: $warning = &mt('No items found in archive.');
13013: }
13014: if ($error) {
13015: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13016: $error.'</p>'."\n";
13017: }
13018: if ($warning) {
13019: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13020: }
13021: return $output;
13022: }
13023:
1.1066 raeburn 13024: sub cleanup_empty_dirs {
13025: my ($path) = @_;
13026: if (($path ne '') && (-d $path)) {
13027: if (opendir(my $dirh,$path)) {
13028: my @dircontents = grep(!/^\./,readdir($dirh));
13029: my $numitems = 0;
13030: foreach my $item (@dircontents) {
13031: if (-d "$path/$item") {
1.1075.2.28 raeburn 13032: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13033: if (-e "$path/$item") {
13034: $numitems ++;
13035: }
13036: } else {
13037: $numitems ++;
13038: }
13039: }
13040: if ($numitems == 0) {
13041: rmdir($path);
13042: }
13043: closedir($dirh);
13044: }
13045: }
13046: return;
13047: }
13048:
1.41 ng 13049: =pod
1.45 matthew 13050:
1.1075.2.56 raeburn 13051: =item * &get_folder_hierarchy()
1.1068 raeburn 13052:
13053: Provides hierarchy of names of folders/sub-folders containing the current
13054: item,
13055:
13056: Inputs: 3
13057: - $navmap - navmaps object
13058:
13059: - $map - url for map (either the trigger itself, or map containing
13060: the resource, which is the trigger).
13061:
13062: - $showitem - 1 => show title for map itself; 0 => do not show.
13063:
13064: Outputs: 1 @pathitems - array of folder/subfolder names.
13065:
13066: =cut
13067:
13068: sub get_folder_hierarchy {
13069: my ($navmap,$map,$showitem) = @_;
13070: my @pathitems;
13071: if (ref($navmap)) {
13072: my $mapres = $navmap->getResourceByUrl($map);
13073: if (ref($mapres)) {
13074: my $pcslist = $mapres->map_hierarchy();
13075: if ($pcslist ne '') {
13076: my @pcs = split(/,/,$pcslist);
13077: foreach my $pc (@pcs) {
13078: if ($pc == 1) {
1.1075.2.38 raeburn 13079: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13080: } else {
13081: my $res = $navmap->getByMapPc($pc);
13082: if (ref($res)) {
13083: my $title = $res->compTitle();
13084: $title =~ s/\W+/_/g;
13085: if ($title ne '') {
13086: push(@pathitems,$title);
13087: }
13088: }
13089: }
13090: }
13091: }
1.1071 raeburn 13092: if ($showitem) {
13093: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 13094: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13095: } else {
13096: my $maptitle = $mapres->compTitle();
13097: $maptitle =~ s/\W+/_/g;
13098: if ($maptitle ne '') {
13099: push(@pathitems,$maptitle);
13100: }
1.1068 raeburn 13101: }
13102: }
13103: }
13104: }
13105: return @pathitems;
13106: }
13107:
13108: =pod
13109:
1.1015 raeburn 13110: =item * &get_turnedin_filepath()
13111:
13112: Determines path in a user's portfolio file for storage of files uploaded
13113: to a specific essayresponse or dropbox item.
13114:
13115: Inputs: 3 required + 1 optional.
13116: $symb is symb for resource, $uname and $udom are for current user (required).
13117: $caller is optional (can be "submission", if routine is called when storing
13118: an upoaded file when "Submit Answer" button was pressed).
13119:
13120: Returns array containing $path and $multiresp.
13121: $path is path in portfolio. $multiresp is 1 if this resource contains more
13122: than one file upload item. Callers of routine should append partid as a
13123: subdirectory to $path in cases where $multiresp is 1.
13124:
13125: Called by: homework/essayresponse.pm and homework/structuretags.pm
13126:
13127: =cut
13128:
13129: sub get_turnedin_filepath {
13130: my ($symb,$uname,$udom,$caller) = @_;
13131: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13132: my $turnindir;
13133: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13134: $turnindir = $userhash{'turnindir'};
13135: my ($path,$multiresp);
13136: if ($turnindir eq '') {
13137: if ($caller eq 'submission') {
13138: $turnindir = &mt('turned in');
13139: $turnindir =~ s/\W+/_/g;
13140: my %newhash = (
13141: 'turnindir' => $turnindir,
13142: );
13143: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13144: }
13145: }
13146: if ($turnindir ne '') {
13147: $path = '/'.$turnindir.'/';
13148: my ($multipart,$turnin,@pathitems);
13149: my $navmap = Apache::lonnavmaps::navmap->new();
13150: if (defined($navmap)) {
13151: my $mapres = $navmap->getResourceByUrl($map);
13152: if (ref($mapres)) {
13153: my $pcslist = $mapres->map_hierarchy();
13154: if ($pcslist ne '') {
13155: foreach my $pc (split(/,/,$pcslist)) {
13156: my $res = $navmap->getByMapPc($pc);
13157: if (ref($res)) {
13158: my $title = $res->compTitle();
13159: $title =~ s/\W+/_/g;
13160: if ($title ne '') {
1.1075.2.48 raeburn 13161: if (($pc > 1) && (length($title) > 12)) {
13162: $title = substr($title,0,12);
13163: }
1.1015 raeburn 13164: push(@pathitems,$title);
13165: }
13166: }
13167: }
13168: }
13169: my $maptitle = $mapres->compTitle();
13170: $maptitle =~ s/\W+/_/g;
13171: if ($maptitle ne '') {
1.1075.2.48 raeburn 13172: if (length($maptitle) > 12) {
13173: $maptitle = substr($maptitle,0,12);
13174: }
1.1015 raeburn 13175: push(@pathitems,$maptitle);
13176: }
13177: unless ($env{'request.state'} eq 'construct') {
13178: my $res = $navmap->getBySymb($symb);
13179: if (ref($res)) {
13180: my $partlist = $res->parts();
13181: my $totaluploads = 0;
13182: if (ref($partlist) eq 'ARRAY') {
13183: foreach my $part (@{$partlist}) {
13184: my @types = $res->responseType($part);
13185: my @ids = $res->responseIds($part);
13186: for (my $i=0; $i < scalar(@ids); $i++) {
13187: if ($types[$i] eq 'essay') {
13188: my $partid = $part.'_'.$ids[$i];
13189: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13190: $totaluploads ++;
13191: }
13192: }
13193: }
13194: }
13195: if ($totaluploads > 1) {
13196: $multiresp = 1;
13197: }
13198: }
13199: }
13200: }
13201: } else {
13202: return;
13203: }
13204: } else {
13205: return;
13206: }
13207: my $restitle=&Apache::lonnet::gettitle($symb);
13208: $restitle =~ s/\W+/_/g;
13209: if ($restitle eq '') {
13210: $restitle = ($resurl =~ m{/[^/]+$});
13211: if ($restitle eq '') {
13212: $restitle = time;
13213: }
13214: }
1.1075.2.48 raeburn 13215: if (length($restitle) > 12) {
13216: $restitle = substr($restitle,0,12);
13217: }
1.1015 raeburn 13218: push(@pathitems,$restitle);
13219: $path .= join('/',@pathitems);
13220: }
13221: return ($path,$multiresp);
13222: }
13223:
13224: =pod
13225:
1.464 albertel 13226: =back
1.41 ng 13227:
1.112 bowersj2 13228: =head1 CSV Upload/Handling functions
1.38 albertel 13229:
1.41 ng 13230: =over 4
13231:
1.648 raeburn 13232: =item * &upfile_store($r)
1.41 ng 13233:
13234: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13235: needs $env{'form.upfile'}
1.41 ng 13236: returns $datatoken to be put into hidden field
13237:
13238: =cut
1.31 albertel 13239:
13240: sub upfile_store {
13241: my $r=shift;
1.258 albertel 13242: $env{'form.upfile'}=~s/\r/\n/gs;
13243: $env{'form.upfile'}=~s/\f/\n/gs;
13244: $env{'form.upfile'}=~s/\n+/\n/gs;
13245: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13246:
1.1075.2.128 raeburn 13247: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13248: '_enroll_'.$env{'request.course.id'}.'_'.
13249: time.'_'.$$);
13250: return if ($datatoken eq '');
13251:
1.31 albertel 13252: {
1.158 raeburn 13253: my $datafile = $r->dir_config('lonDaemons').
13254: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 13255: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13256: print $fh $env{'form.upfile'};
1.158 raeburn 13257: close($fh);
13258: }
1.31 albertel 13259: }
13260: return $datatoken;
13261: }
13262:
1.56 matthew 13263: =pod
13264:
1.1075.2.128 raeburn 13265: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13266:
13267: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 13268: $datatoken is the name to assign to the temporary file.
1.258 albertel 13269: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13270:
13271: =cut
1.31 albertel 13272:
13273: sub load_tmp_file {
1.1075.2.128 raeburn 13274: my ($r,$datatoken) = @_;
13275: return if ($datatoken eq '');
1.31 albertel 13276: my @studentdata=();
13277: {
1.158 raeburn 13278: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 13279: '/tmp/'.$datatoken.'.tmp';
13280: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 13281: @studentdata=<$fh>;
13282: close($fh);
13283: }
1.31 albertel 13284: }
1.258 albertel 13285: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13286: }
13287:
1.1075.2.128 raeburn 13288: sub valid_datatoken {
13289: my ($datatoken) = @_;
1.1075.2.131 raeburn 13290: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 13291: return $datatoken;
13292: }
13293: return;
13294: }
13295:
1.56 matthew 13296: =pod
13297:
1.648 raeburn 13298: =item * &upfile_record_sep()
1.41 ng 13299:
13300: Separate uploaded file into records
13301: returns array of records,
1.258 albertel 13302: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13303:
13304: =cut
1.31 albertel 13305:
13306: sub upfile_record_sep {
1.258 albertel 13307: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13308: } else {
1.248 albertel 13309: my @records;
1.258 albertel 13310: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13311: if ($line=~/^\s*$/) { next; }
13312: push(@records,$line);
13313: }
13314: return @records;
1.31 albertel 13315: }
13316: }
13317:
1.56 matthew 13318: =pod
13319:
1.648 raeburn 13320: =item * &record_sep($record)
1.41 ng 13321:
1.258 albertel 13322: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13323:
13324: =cut
13325:
1.263 www 13326: sub takeleft {
13327: my $index=shift;
13328: return substr('0000'.$index,-4,4);
13329: }
13330:
1.31 albertel 13331: sub record_sep {
13332: my $record=shift;
13333: my %components=();
1.258 albertel 13334: if ($env{'form.upfiletype'} eq 'xml') {
13335: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13336: my $i=0;
1.356 albertel 13337: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13338: $field=~s/^(\"|\')//;
13339: $field=~s/(\"|\')$//;
1.263 www 13340: $components{&takeleft($i)}=$field;
1.31 albertel 13341: $i++;
13342: }
1.258 albertel 13343: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13344: my $i=0;
1.356 albertel 13345: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13346: $field=~s/^(\"|\')//;
13347: $field=~s/(\"|\')$//;
1.263 www 13348: $components{&takeleft($i)}=$field;
1.31 albertel 13349: $i++;
13350: }
13351: } else {
1.561 www 13352: my $separator=',';
1.480 banghart 13353: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13354: $separator=';';
1.480 banghart 13355: }
1.31 albertel 13356: my $i=0;
1.561 www 13357: # the character we are looking for to indicate the end of a quote or a record
13358: my $looking_for=$separator;
13359: # do not add the characters to the fields
13360: my $ignore=0;
13361: # we just encountered a separator (or the beginning of the record)
13362: my $just_found_separator=1;
13363: # store the field we are working on here
13364: my $field='';
13365: # work our way through all characters in record
13366: foreach my $character ($record=~/(.)/g) {
13367: if ($character eq $looking_for) {
13368: if ($character ne $separator) {
13369: # Found the end of a quote, again looking for separator
13370: $looking_for=$separator;
13371: $ignore=1;
13372: } else {
13373: # Found a separator, store away what we got
13374: $components{&takeleft($i)}=$field;
13375: $i++;
13376: $just_found_separator=1;
13377: $ignore=0;
13378: $field='';
13379: }
13380: next;
13381: }
13382: # single or double quotation marks after a separator indicate beginning of a quote
13383: # we are now looking for the end of the quote and need to ignore separators
13384: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13385: $looking_for=$character;
13386: next;
13387: }
13388: # ignore would be true after we reached the end of a quote
13389: if ($ignore) { next; }
13390: if (($just_found_separator) && ($character=~/\s/)) { next; }
13391: $field.=$character;
13392: $just_found_separator=0;
1.31 albertel 13393: }
1.561 www 13394: # catch the very last entry, since we never encountered the separator
13395: $components{&takeleft($i)}=$field;
1.31 albertel 13396: }
13397: return %components;
13398: }
13399:
1.144 matthew 13400: ######################################################
13401: ######################################################
13402:
1.56 matthew 13403: =pod
13404:
1.648 raeburn 13405: =item * &upfile_select_html()
1.41 ng 13406:
1.144 matthew 13407: Return HTML code to select a file from the users machine and specify
13408: the file type.
1.41 ng 13409:
13410: =cut
13411:
1.144 matthew 13412: ######################################################
13413: ######################################################
1.31 albertel 13414: sub upfile_select_html {
1.144 matthew 13415: my %Types = (
13416: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13417: semisv => &mt('Semicolon separated values'),
1.144 matthew 13418: space => &mt('Space separated'),
13419: tab => &mt('Tabulator separated'),
13420: # xml => &mt('HTML/XML'),
13421: );
13422: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13423: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13424: foreach my $type (sort(keys(%Types))) {
13425: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13426: }
13427: $Str .= "</select>\n";
13428: return $Str;
1.31 albertel 13429: }
13430:
1.301 albertel 13431: sub get_samples {
13432: my ($records,$toget) = @_;
13433: my @samples=({});
13434: my $got=0;
13435: foreach my $rec (@$records) {
13436: my %temp = &record_sep($rec);
13437: if (! grep(/\S/, values(%temp))) { next; }
13438: if (%temp) {
13439: $samples[$got]=\%temp;
13440: $got++;
13441: if ($got == $toget) { last; }
13442: }
13443: }
13444: return \@samples;
13445: }
13446:
1.144 matthew 13447: ######################################################
13448: ######################################################
13449:
1.56 matthew 13450: =pod
13451:
1.648 raeburn 13452: =item * &csv_print_samples($r,$records)
1.41 ng 13453:
13454: Prints a table of sample values from each column uploaded $r is an
13455: Apache Request ref, $records is an arrayref from
13456: &Apache::loncommon::upfile_record_sep
13457:
13458: =cut
13459:
1.144 matthew 13460: ######################################################
13461: ######################################################
1.31 albertel 13462: sub csv_print_samples {
13463: my ($r,$records) = @_;
1.662 bisitz 13464: my $samples = &get_samples($records,5);
1.301 albertel 13465:
1.594 raeburn 13466: $r->print(&mt('Samples').'<br />'.&start_data_table().
13467: &start_data_table_header_row());
1.356 albertel 13468: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13469: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13470: $r->print(&end_data_table_header_row());
1.301 albertel 13471: foreach my $hash (@$samples) {
1.594 raeburn 13472: $r->print(&start_data_table_row());
1.356 albertel 13473: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13474: $r->print('<td>');
1.356 albertel 13475: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13476: $r->print('</td>');
13477: }
1.594 raeburn 13478: $r->print(&end_data_table_row());
1.31 albertel 13479: }
1.594 raeburn 13480: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13481: }
13482:
1.144 matthew 13483: ######################################################
13484: ######################################################
13485:
1.56 matthew 13486: =pod
13487:
1.648 raeburn 13488: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13489:
13490: Prints a table to create associations between values and table columns.
1.144 matthew 13491:
1.41 ng 13492: $r is an Apache Request ref,
13493: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13494: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13495:
13496: =cut
13497:
1.144 matthew 13498: ######################################################
13499: ######################################################
1.31 albertel 13500: sub csv_print_select_table {
13501: my ($r,$records,$d) = @_;
1.301 albertel 13502: my $i=0;
13503: my $samples = &get_samples($records,1);
1.144 matthew 13504: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13505: &start_data_table().&start_data_table_header_row().
1.144 matthew 13506: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13507: '<th>'.&mt('Column').'</th>'.
13508: &end_data_table_header_row()."\n");
1.356 albertel 13509: foreach my $array_ref (@$d) {
13510: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13511: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13512:
1.875 bisitz 13513: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13514: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13515: $r->print('<option value="none"></option>');
1.356 albertel 13516: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13517: $r->print('<option value="'.$sample.'"'.
13518: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13519: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13520: }
1.594 raeburn 13521: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13522: $i++;
13523: }
1.594 raeburn 13524: $r->print(&end_data_table());
1.31 albertel 13525: $i--;
13526: return $i;
13527: }
1.56 matthew 13528:
1.144 matthew 13529: ######################################################
13530: ######################################################
13531:
1.56 matthew 13532: =pod
1.31 albertel 13533:
1.648 raeburn 13534: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13535:
13536: Prints a table of sample values from the upload and can make associate samples to internal names.
13537:
13538: $r is an Apache Request ref,
13539: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13540: $d is an array of 2 element arrays (internal name, displayed name)
13541:
13542: =cut
13543:
1.144 matthew 13544: ######################################################
13545: ######################################################
1.31 albertel 13546: sub csv_samples_select_table {
13547: my ($r,$records,$d) = @_;
13548: my $i=0;
1.144 matthew 13549: #
1.662 bisitz 13550: my $max_samples = 5;
13551: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13552: $r->print(&start_data_table().
13553: &start_data_table_header_row().'<th>'.
13554: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13555: &end_data_table_header_row());
1.301 albertel 13556:
13557: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13558: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13559: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13560: foreach my $option (@$d) {
13561: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13562: $r->print('<option value="'.$value.'"'.
1.253 albertel 13563: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13564: $display.'</option>');
1.31 albertel 13565: }
13566: $r->print('</select></td><td>');
1.662 bisitz 13567: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13568: if (defined($samples->[$line]{$key})) {
13569: $r->print($samples->[$line]{$key}."<br />\n");
13570: }
13571: }
1.594 raeburn 13572: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13573: $i++;
13574: }
1.594 raeburn 13575: $r->print(&end_data_table());
1.31 albertel 13576: $i--;
13577: return($i);
1.115 matthew 13578: }
13579:
1.144 matthew 13580: ######################################################
13581: ######################################################
13582:
1.115 matthew 13583: =pod
13584:
1.648 raeburn 13585: =item * &clean_excel_name($name)
1.115 matthew 13586:
13587: Returns a replacement for $name which does not contain any illegal characters.
13588:
13589: =cut
13590:
1.144 matthew 13591: ######################################################
13592: ######################################################
1.115 matthew 13593: sub clean_excel_name {
13594: my ($name) = @_;
13595: $name =~ s/[:\*\?\/\\]//g;
13596: if (length($name) > 31) {
13597: $name = substr($name,0,31);
13598: }
13599: return $name;
1.25 albertel 13600: }
1.84 albertel 13601:
1.85 albertel 13602: =pod
13603:
1.648 raeburn 13604: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13605:
13606: Returns either 1 or undef
13607:
13608: 1 if the part is to be hidden, undef if it is to be shown
13609:
13610: Arguments are:
13611:
13612: $id the id of the part to be checked
13613: $symb, optional the symb of the resource to check
13614: $udom, optional the domain of the user to check for
13615: $uname, optional the username of the user to check for
13616:
13617: =cut
1.84 albertel 13618:
13619: sub check_if_partid_hidden {
13620: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13621: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13622: $symb,$udom,$uname);
1.141 albertel 13623: my $truth=1;
13624: #if the string starts with !, then the list is the list to show not hide
13625: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13626: my @hiddenlist=split(/,/,$hiddenparts);
13627: foreach my $checkid (@hiddenlist) {
1.141 albertel 13628: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13629: }
1.141 albertel 13630: return !$truth;
1.84 albertel 13631: }
1.127 matthew 13632:
1.138 matthew 13633:
13634: ############################################################
13635: ############################################################
13636:
13637: =pod
13638:
1.157 matthew 13639: =back
13640:
1.138 matthew 13641: =head1 cgi-bin script and graphing routines
13642:
1.157 matthew 13643: =over 4
13644:
1.648 raeburn 13645: =item * &get_cgi_id()
1.138 matthew 13646:
13647: Inputs: none
13648:
13649: Returns an id which can be used to pass environment variables
13650: to various cgi-bin scripts. These environment variables will
13651: be removed from the users environment after a given time by
13652: the routine &Apache::lonnet::transfer_profile_to_env.
13653:
13654: =cut
13655:
13656: ############################################################
13657: ############################################################
1.152 albertel 13658: my $uniq=0;
1.136 matthew 13659: sub get_cgi_id {
1.154 albertel 13660: $uniq=($uniq+1)%100000;
1.280 albertel 13661: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13662: }
13663:
1.127 matthew 13664: ############################################################
13665: ############################################################
13666:
13667: =pod
13668:
1.648 raeburn 13669: =item * &DrawBarGraph()
1.127 matthew 13670:
1.138 matthew 13671: Facilitates the plotting of data in a (stacked) bar graph.
13672: Puts plot definition data into the users environment in order for
13673: graph.png to plot it. Returns an <img> tag for the plot.
13674: The bars on the plot are labeled '1','2',...,'n'.
13675:
13676: Inputs:
13677:
13678: =over 4
13679:
13680: =item $Title: string, the title of the plot
13681:
13682: =item $xlabel: string, text describing the X-axis of the plot
13683:
13684: =item $ylabel: string, text describing the Y-axis of the plot
13685:
13686: =item $Max: scalar, the maximum Y value to use in the plot
13687: If $Max is < any data point, the graph will not be rendered.
13688:
1.140 matthew 13689: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13690: they are plotted. If undefined, default values will be used.
13691:
1.178 matthew 13692: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13693:
1.138 matthew 13694: =item @Values: An array of array references. Each array reference holds data
13695: to be plotted in a stacked bar chart.
13696:
1.239 matthew 13697: =item If the final element of @Values is a hash reference the key/value
13698: pairs will be added to the graph definition.
13699:
1.138 matthew 13700: =back
13701:
13702: Returns:
13703:
13704: An <img> tag which references graph.png and the appropriate identifying
13705: information for the plot.
13706:
1.127 matthew 13707: =cut
13708:
13709: ############################################################
13710: ############################################################
1.134 matthew 13711: sub DrawBarGraph {
1.178 matthew 13712: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13713: #
13714: if (! defined($colors)) {
13715: $colors = ['#33ff00',
13716: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13717: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13718: ];
13719: }
1.228 matthew 13720: my $extra_settings = {};
13721: if (ref($Values[-1]) eq 'HASH') {
13722: $extra_settings = pop(@Values);
13723: }
1.127 matthew 13724: #
1.136 matthew 13725: my $identifier = &get_cgi_id();
13726: my $id = 'cgi.'.$identifier;
1.129 matthew 13727: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13728: return '';
13729: }
1.225 matthew 13730: #
13731: my @Labels;
13732: if (defined($labels)) {
13733: @Labels = @$labels;
13734: } else {
13735: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 13736: push(@Labels,$i+1);
1.225 matthew 13737: }
13738: }
13739: #
1.129 matthew 13740: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13741: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13742: my %ValuesHash;
13743: my $NumSets=1;
13744: foreach my $array (@Values) {
13745: next if (! ref($array));
1.136 matthew 13746: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13747: join(',',@$array);
1.129 matthew 13748: }
1.127 matthew 13749: #
1.136 matthew 13750: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13751: if ($NumBars < 3) {
13752: $width = 120+$NumBars*32;
1.220 matthew 13753: $xskip = 1;
1.225 matthew 13754: $bar_width = 30;
13755: } elsif ($NumBars < 5) {
13756: $width = 120+$NumBars*20;
13757: $xskip = 1;
13758: $bar_width = 20;
1.220 matthew 13759: } elsif ($NumBars < 10) {
1.136 matthew 13760: $width = 120+$NumBars*15;
13761: $xskip = 1;
13762: $bar_width = 15;
13763: } elsif ($NumBars <= 25) {
13764: $width = 120+$NumBars*11;
13765: $xskip = 5;
13766: $bar_width = 8;
13767: } elsif ($NumBars <= 50) {
13768: $width = 120+$NumBars*8;
13769: $xskip = 5;
13770: $bar_width = 4;
13771: } else {
13772: $width = 120+$NumBars*8;
13773: $xskip = 5;
13774: $bar_width = 4;
13775: }
13776: #
1.137 matthew 13777: $Max = 1 if ($Max < 1);
13778: if ( int($Max) < $Max ) {
13779: $Max++;
13780: $Max = int($Max);
13781: }
1.127 matthew 13782: $Title = '' if (! defined($Title));
13783: $xlabel = '' if (! defined($xlabel));
13784: $ylabel = '' if (! defined($ylabel));
1.369 www 13785: $ValuesHash{$id.'.title'} = &escape($Title);
13786: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13787: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13788: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13789: $ValuesHash{$id.'.NumBars'} = $NumBars;
13790: $ValuesHash{$id.'.NumSets'} = $NumSets;
13791: $ValuesHash{$id.'.PlotType'} = 'bar';
13792: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13793: $ValuesHash{$id.'.height'} = $height;
13794: $ValuesHash{$id.'.width'} = $width;
13795: $ValuesHash{$id.'.xskip'} = $xskip;
13796: $ValuesHash{$id.'.bar_width'} = $bar_width;
13797: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13798: #
1.228 matthew 13799: # Deal with other parameters
13800: while (my ($key,$value) = each(%$extra_settings)) {
13801: $ValuesHash{$id.'.'.$key} = $value;
13802: }
13803: #
1.646 raeburn 13804: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13805: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13806: }
13807:
13808: ############################################################
13809: ############################################################
13810:
13811: =pod
13812:
1.648 raeburn 13813: =item * &DrawXYGraph()
1.137 matthew 13814:
1.138 matthew 13815: Facilitates the plotting of data in an XY graph.
13816: Puts plot definition data into the users environment in order for
13817: graph.png to plot it. Returns an <img> tag for the plot.
13818:
13819: Inputs:
13820:
13821: =over 4
13822:
13823: =item $Title: string, the title of the plot
13824:
13825: =item $xlabel: string, text describing the X-axis of the plot
13826:
13827: =item $ylabel: string, text describing the Y-axis of the plot
13828:
13829: =item $Max: scalar, the maximum Y value to use in the plot
13830: If $Max is < any data point, the graph will not be rendered.
13831:
13832: =item $colors: Array ref containing the hex color codes for the data to be
13833: plotted in. If undefined, default values will be used.
13834:
13835: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13836:
13837: =item $Ydata: Array ref containing Array refs.
1.185 www 13838: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13839:
13840: =item %Values: hash indicating or overriding any default values which are
13841: passed to graph.png.
13842: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13843:
13844: =back
13845:
13846: Returns:
13847:
13848: An <img> tag which references graph.png and the appropriate identifying
13849: information for the plot.
13850:
1.137 matthew 13851: =cut
13852:
13853: ############################################################
13854: ############################################################
13855: sub DrawXYGraph {
13856: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13857: #
13858: # Create the identifier for the graph
13859: my $identifier = &get_cgi_id();
13860: my $id = 'cgi.'.$identifier;
13861: #
13862: $Title = '' if (! defined($Title));
13863: $xlabel = '' if (! defined($xlabel));
13864: $ylabel = '' if (! defined($ylabel));
13865: my %ValuesHash =
13866: (
1.369 www 13867: $id.'.title' => &escape($Title),
13868: $id.'.xlabel' => &escape($xlabel),
13869: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13870: $id.'.y_max_value'=> $Max,
13871: $id.'.labels' => join(',',@$Xlabels),
13872: $id.'.PlotType' => 'XY',
13873: );
13874: #
13875: if (defined($colors) && ref($colors) eq 'ARRAY') {
13876: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13877: }
13878: #
13879: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13880: return '';
13881: }
13882: my $NumSets=1;
1.138 matthew 13883: foreach my $array (@{$Ydata}){
1.137 matthew 13884: next if (! ref($array));
13885: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13886: }
1.138 matthew 13887: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 13888: #
13889: # Deal with other parameters
13890: while (my ($key,$value) = each(%Values)) {
13891: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 13892: }
13893: #
1.646 raeburn 13894: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 13895: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13896: }
13897:
13898: ############################################################
13899: ############################################################
13900:
13901: =pod
13902:
1.648 raeburn 13903: =item * &DrawXYYGraph()
1.138 matthew 13904:
13905: Facilitates the plotting of data in an XY graph with two Y axes.
13906: Puts plot definition data into the users environment in order for
13907: graph.png to plot it. Returns an <img> tag for the plot.
13908:
13909: Inputs:
13910:
13911: =over 4
13912:
13913: =item $Title: string, the title of the plot
13914:
13915: =item $xlabel: string, text describing the X-axis of the plot
13916:
13917: =item $ylabel: string, text describing the Y-axis of the plot
13918:
13919: =item $colors: Array ref containing the hex color codes for the data to be
13920: plotted in. If undefined, default values will be used.
13921:
13922: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13923:
13924: =item $Ydata1: The first data set
13925:
13926: =item $Min1: The minimum value of the left Y-axis
13927:
13928: =item $Max1: The maximum value of the left Y-axis
13929:
13930: =item $Ydata2: The second data set
13931:
13932: =item $Min2: The minimum value of the right Y-axis
13933:
13934: =item $Max2: The maximum value of the left Y-axis
13935:
13936: =item %Values: hash indicating or overriding any default values which are
13937: passed to graph.png.
13938: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13939:
13940: =back
13941:
13942: Returns:
13943:
13944: An <img> tag which references graph.png and the appropriate identifying
13945: information for the plot.
1.136 matthew 13946:
13947: =cut
13948:
13949: ############################################################
13950: ############################################################
1.137 matthew 13951: sub DrawXYYGraph {
13952: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13953: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13954: #
13955: # Create the identifier for the graph
13956: my $identifier = &get_cgi_id();
13957: my $id = 'cgi.'.$identifier;
13958: #
13959: $Title = '' if (! defined($Title));
13960: $xlabel = '' if (! defined($xlabel));
13961: $ylabel = '' if (! defined($ylabel));
13962: my %ValuesHash =
13963: (
1.369 www 13964: $id.'.title' => &escape($Title),
13965: $id.'.xlabel' => &escape($xlabel),
13966: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13967: $id.'.labels' => join(',',@$Xlabels),
13968: $id.'.PlotType' => 'XY',
13969: $id.'.NumSets' => 2,
1.137 matthew 13970: $id.'.two_axes' => 1,
13971: $id.'.y1_max_value' => $Max1,
13972: $id.'.y1_min_value' => $Min1,
13973: $id.'.y2_max_value' => $Max2,
13974: $id.'.y2_min_value' => $Min2,
1.136 matthew 13975: );
13976: #
1.137 matthew 13977: if (defined($colors) && ref($colors) eq 'ARRAY') {
13978: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13979: }
13980: #
13981: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13982: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13983: return '';
13984: }
13985: my $NumSets=1;
1.137 matthew 13986: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13987: next if (! ref($array));
13988: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13989: }
13990: #
13991: # Deal with other parameters
13992: while (my ($key,$value) = each(%Values)) {
13993: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13994: }
13995: #
1.646 raeburn 13996: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13997: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13998: }
13999:
14000: ############################################################
14001: ############################################################
14002:
14003: =pod
14004:
1.157 matthew 14005: =back
14006:
1.139 matthew 14007: =head1 Statistics helper routines?
14008:
14009: Bad place for them but what the hell.
14010:
1.157 matthew 14011: =over 4
14012:
1.648 raeburn 14013: =item * &chartlink()
1.139 matthew 14014:
14015: Returns a link to the chart for a specific student.
14016:
14017: Inputs:
14018:
14019: =over 4
14020:
14021: =item $linktext: The text of the link
14022:
14023: =item $sname: The students username
14024:
14025: =item $sdomain: The students domain
14026:
14027: =back
14028:
1.157 matthew 14029: =back
14030:
1.139 matthew 14031: =cut
14032:
14033: ############################################################
14034: ############################################################
14035: sub chartlink {
14036: my ($linktext, $sname, $sdomain) = @_;
14037: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14038: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14039: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14040: '">'.$linktext.'</a>';
1.153 matthew 14041: }
14042:
14043: #######################################################
14044: #######################################################
14045:
14046: =pod
14047:
14048: =head1 Course Environment Routines
1.157 matthew 14049:
14050: =over 4
1.153 matthew 14051:
1.648 raeburn 14052: =item * &restore_course_settings()
1.153 matthew 14053:
1.648 raeburn 14054: =item * &store_course_settings()
1.153 matthew 14055:
14056: Restores/Store indicated form parameters from the course environment.
14057: Will not overwrite existing values of the form parameters.
14058:
14059: Inputs:
14060: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14061:
14062: a hash ref describing the data to be stored. For example:
14063:
14064: %Save_Parameters = ('Status' => 'scalar',
14065: 'chartoutputmode' => 'scalar',
14066: 'chartoutputdata' => 'scalar',
14067: 'Section' => 'array',
1.373 raeburn 14068: 'Group' => 'array',
1.153 matthew 14069: 'StudentData' => 'array',
14070: 'Maps' => 'array');
14071:
14072: Returns: both routines return nothing
14073:
1.631 raeburn 14074: =back
14075:
1.153 matthew 14076: =cut
14077:
14078: #######################################################
14079: #######################################################
14080: sub store_course_settings {
1.496 albertel 14081: return &store_settings($env{'request.course.id'},@_);
14082: }
14083:
14084: sub store_settings {
1.153 matthew 14085: # save to the environment
14086: # appenv the same items, just to be safe
1.300 albertel 14087: my $udom = $env{'user.domain'};
14088: my $uname = $env{'user.name'};
1.496 albertel 14089: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14090: my %SaveHash;
14091: my %AppHash;
14092: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14093: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14094: my $envname = 'environment.'.$basename;
1.258 albertel 14095: if (exists($env{'form.'.$setting})) {
1.153 matthew 14096: # Save this value away
14097: if ($type eq 'scalar' &&
1.258 albertel 14098: (! exists($env{$envname}) ||
14099: $env{$envname} ne $env{'form.'.$setting})) {
14100: $SaveHash{$basename} = $env{'form.'.$setting};
14101: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14102: } elsif ($type eq 'array') {
14103: my $stored_form;
1.258 albertel 14104: if (ref($env{'form.'.$setting})) {
1.153 matthew 14105: $stored_form = join(',',
14106: map {
1.369 www 14107: &escape($_);
1.258 albertel 14108: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14109: } else {
14110: $stored_form =
1.369 www 14111: &escape($env{'form.'.$setting});
1.153 matthew 14112: }
14113: # Determine if the array contents are the same.
1.258 albertel 14114: if ($stored_form ne $env{$envname}) {
1.153 matthew 14115: $SaveHash{$basename} = $stored_form;
14116: $AppHash{$envname} = $stored_form;
14117: }
14118: }
14119: }
14120: }
14121: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14122: $udom,$uname);
1.153 matthew 14123: if ($put_result !~ /^(ok|delayed)/) {
14124: &Apache::lonnet::logthis('unable to save form parameters, '.
14125: 'got error:'.$put_result);
14126: }
14127: # Make sure these settings stick around in this session, too
1.646 raeburn 14128: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14129: return;
14130: }
14131:
14132: sub restore_course_settings {
1.499 albertel 14133: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14134: }
14135:
14136: sub restore_settings {
14137: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14138: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14139: next if (exists($env{'form.'.$setting}));
1.496 albertel 14140: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14141: '.'.$setting;
1.258 albertel 14142: if (exists($env{$envname})) {
1.153 matthew 14143: if ($type eq 'scalar') {
1.258 albertel 14144: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14145: } elsif ($type eq 'array') {
1.258 albertel 14146: $env{'form.'.$setting} = [
1.153 matthew 14147: map {
1.369 www 14148: &unescape($_);
1.258 albertel 14149: } split(',',$env{$envname})
1.153 matthew 14150: ];
14151: }
14152: }
14153: }
1.127 matthew 14154: }
14155:
1.618 raeburn 14156: #######################################################
14157: #######################################################
14158:
14159: =pod
14160:
14161: =head1 Domain E-mail Routines
14162:
14163: =over 4
14164:
1.648 raeburn 14165: =item * &build_recipient_list()
1.618 raeburn 14166:
1.1075.2.44 raeburn 14167: Build recipient lists for following types of e-mail:
1.766 raeburn 14168: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 14169: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14170: module change checking, student/employee ID conflict checks, as
14171: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14172: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14173:
14174: Inputs:
1.1075.2.44 raeburn 14175: defmail (scalar - email address of default recipient),
14176: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14177: requestsmail, updatesmail, or idconflictsmail).
14178:
1.619 raeburn 14179: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 14180:
14181: origmail (scalar - email address of recipient from loncapa.conf,
14182: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14183:
1.1075.2.139 raeburn 14184: $requname username of requester (if mailing type is helpdeskmail)
14185:
14186: $requdom domain of requester (if mailing type is helpdeskmail)
14187:
14188: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14189:
1.655 raeburn 14190: Returns: comma separated list of addresses to which to send e-mail.
14191:
14192: =back
1.618 raeburn 14193:
14194: =cut
14195:
14196: ############################################################
14197: ############################################################
14198: sub build_recipient_list {
1.1075.2.139 raeburn 14199: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14200: my @recipients;
1.1075.2.122 raeburn 14201: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14202: my %domconfig =
1.1075.2.122 raeburn 14203: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14204: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14205: if (exists($domconfig{'contacts'}{$mailing})) {
14206: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14207: my @contacts = ('adminemail','supportemail');
14208: foreach my $item (@contacts) {
14209: if ($domconfig{'contacts'}{$mailing}{$item}) {
14210: my $addr = $domconfig{'contacts'}{$item};
14211: if (!grep(/^\Q$addr\E$/,@recipients)) {
14212: push(@recipients,$addr);
14213: }
1.619 raeburn 14214: }
1.1075.2.122 raeburn 14215: }
14216: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14217: if ($mailing eq 'helpdeskmail') {
14218: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14219: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14220: my @ok_bccs;
14221: foreach my $bcc (@bccs) {
14222: $bcc =~ s/^\s+//g;
14223: $bcc =~ s/\s+$//g;
14224: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14225: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14226: push(@ok_bccs,$bcc);
14227: }
14228: }
14229: }
14230: if (@ok_bccs > 0) {
14231: $allbcc = join(', ',@ok_bccs);
14232: }
14233: }
14234: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14235: }
14236: }
1.766 raeburn 14237: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14238: $lastresort = $origmail;
1.618 raeburn 14239: }
1.1075.2.139 raeburn 14240: if ($mailing eq 'helpdeskmail') {
14241: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14242: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14243: my ($inststatus,$inststatus_checked);
14244: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14245: ($env{'user.domain'} ne 'public')) {
14246: $inststatus_checked = 1;
14247: $inststatus = $env{'environment.inststatus'};
14248: }
14249: unless ($inststatus_checked) {
14250: if (($requname ne '') && ($requdom ne '')) {
14251: if (($requname =~ /^$match_username$/) &&
14252: ($requdom =~ /^$match_domain$/) &&
14253: (&Apache::lonnet::domain($requdom))) {
14254: my $requhome = &Apache::lonnet::homeserver($requname,
14255: $requdom);
14256: unless ($requhome eq 'no_host') {
14257: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14258: $inststatus = $userenv{'inststatus'};
14259: $inststatus_checked = 1;
14260: }
14261: }
14262: }
14263: }
14264: unless ($inststatus_checked) {
14265: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
14266: my %srch = (srchby => 'email',
14267: srchdomain => $defdom,
14268: srchterm => $reqemail,
14269: srchtype => 'exact');
14270: my %srch_results = &Apache::lonnet::usersearch(\%srch);
14271: foreach my $uname (keys(%srch_results)) {
14272: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14273: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14274: $inststatus_checked = 1;
14275: last;
14276: }
14277: }
14278: unless ($inststatus_checked) {
14279: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
14280: if ($dirsrchres eq 'ok') {
14281: foreach my $uname (keys(%srch_results)) {
14282: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14283: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14284: $inststatus_checked = 1;
14285: last;
14286: }
14287: }
14288: }
14289: }
14290: }
14291: }
14292: if ($inststatus ne '') {
14293: foreach my $status (split(/\:/,$inststatus)) {
14294: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
14295: my @contacts = ('adminemail','supportemail');
14296: foreach my $item (@contacts) {
14297: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
14298: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
14299: if (!grep(/^\Q$addr\E$/,@recipients)) {
14300: push(@recipients,$addr);
14301: }
14302: }
14303: }
14304: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
14305: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
14306: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
14307: my @ok_bccs;
14308: foreach my $bcc (@bccs) {
14309: $bcc =~ s/^\s+//g;
14310: $bcc =~ s/\s+$//g;
14311: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14312: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14313: push(@ok_bccs,$bcc);
14314: }
14315: }
14316: }
14317: if (@ok_bccs > 0) {
14318: $allbcc = join(', ',@ok_bccs);
14319: }
14320: }
14321: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
14322: last;
14323: }
14324: }
14325: }
14326: }
14327: }
1.619 raeburn 14328: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14329: $lastresort = $origmail;
14330: }
1.1075.2.128 raeburn 14331: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 14332: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14333: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14334: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14335: my %what = (
14336: perlvar => 1,
14337: );
14338: my $primary = &Apache::lonnet::domain($defdom,'primary');
14339: if ($primary) {
14340: my $gotaddr;
14341: my ($result,$returnhash) =
14342: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14343: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14344: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14345: $lastresort = $returnhash->{'lonSupportEMail'};
14346: $gotaddr = 1;
14347: }
14348: }
14349: unless ($gotaddr) {
14350: my $uintdom = &Apache::lonnet::internet_dom($primary);
14351: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14352: unless ($uintdom eq $intdom) {
14353: my %domconfig =
14354: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14355: if (ref($domconfig{'contacts'}) eq 'HASH') {
14356: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14357: my @contacts = ('adminemail','supportemail');
14358: foreach my $item (@contacts) {
14359: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14360: my $addr = $domconfig{'contacts'}{$item};
14361: if (!grep(/^\Q$addr\E$/,@recipients)) {
14362: push(@recipients,$addr);
14363: }
14364: }
14365: }
14366: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14367: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14368: }
14369: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14370: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14371: my @ok_bccs;
14372: foreach my $bcc (@bccs) {
14373: $bcc =~ s/^\s+//g;
14374: $bcc =~ s/\s+$//g;
14375: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14376: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14377: push(@ok_bccs,$bcc);
14378: }
14379: }
14380: }
14381: if (@ok_bccs > 0) {
14382: $allbcc = join(', ',@ok_bccs);
14383: }
14384: }
14385: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14386: }
14387: }
14388: }
14389: }
14390: }
14391: }
1.618 raeburn 14392: }
1.688 raeburn 14393: if (defined($defmail)) {
14394: if ($defmail ne '') {
14395: push(@recipients,$defmail);
14396: }
1.618 raeburn 14397: }
14398: if ($otheremails) {
1.619 raeburn 14399: my @others;
14400: if ($otheremails =~ /,/) {
14401: @others = split(/,/,$otheremails);
1.618 raeburn 14402: } else {
1.619 raeburn 14403: push(@others,$otheremails);
14404: }
14405: foreach my $addr (@others) {
14406: if (!grep(/^\Q$addr\E$/,@recipients)) {
14407: push(@recipients,$addr);
14408: }
1.618 raeburn 14409: }
14410: }
1.1075.2.128 raeburn 14411: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 14412: if ((!@recipients) && ($lastresort ne '')) {
14413: push(@recipients,$lastresort);
14414: }
14415: } elsif ($lastresort ne '') {
14416: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14417: push(@recipients,$lastresort);
14418: }
14419: }
14420: my $recipientlist = join(',',@recipients);
14421: if (wantarray) {
14422: return ($recipientlist,$allbcc,$addtext);
14423: } else {
14424: return $recipientlist;
14425: }
1.618 raeburn 14426: }
14427:
1.127 matthew 14428: ############################################################
14429: ############################################################
1.154 albertel 14430:
1.655 raeburn 14431: =pod
14432:
14433: =head1 Course Catalog Routines
14434:
14435: =over 4
14436:
14437: =item * &gather_categories()
14438:
14439: Converts category definitions - keys of categories hash stored in
14440: coursecategories in configuration.db on the primary library server in a
14441: domain - to an array. Also generates javascript and idx hash used to
14442: generate Domain Coordinator interface for editing Course Categories.
14443:
14444: Inputs:
1.663 raeburn 14445:
1.655 raeburn 14446: categories (reference to hash of category definitions).
1.663 raeburn 14447:
1.655 raeburn 14448: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14449: categories and subcategories).
1.663 raeburn 14450:
1.655 raeburn 14451: idx (reference to hash of counters used in Domain Coordinator interface for
14452: editing Course Categories).
1.663 raeburn 14453:
1.655 raeburn 14454: jsarray (reference to array of categories used to create Javascript arrays for
14455: Domain Coordinator interface for editing Course Categories).
14456:
14457: Returns: nothing
14458:
14459: Side effects: populates cats, idx and jsarray.
14460:
14461: =cut
14462:
14463: sub gather_categories {
14464: my ($categories,$cats,$idx,$jsarray) = @_;
14465: my %counters;
14466: my $num = 0;
14467: foreach my $item (keys(%{$categories})) {
14468: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14469: if ($container eq '' && $depth == 0) {
14470: $cats->[$depth][$categories->{$item}] = $cat;
14471: } else {
14472: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14473: }
14474: my ($escitem,$tail) = split(/:/,$item,2);
14475: if ($counters{$tail} eq '') {
14476: $counters{$tail} = $num;
14477: $num ++;
14478: }
14479: if (ref($idx) eq 'HASH') {
14480: $idx->{$item} = $counters{$tail};
14481: }
14482: if (ref($jsarray) eq 'ARRAY') {
14483: push(@{$jsarray->[$counters{$tail}]},$item);
14484: }
14485: }
14486: return;
14487: }
14488:
14489: =pod
14490:
14491: =item * &extract_categories()
14492:
14493: Used to generate breadcrumb trails for course categories.
14494:
14495: Inputs:
1.663 raeburn 14496:
1.655 raeburn 14497: categories (reference to hash of category definitions).
1.663 raeburn 14498:
1.655 raeburn 14499: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14500: categories and subcategories).
1.663 raeburn 14501:
1.655 raeburn 14502: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14503:
1.655 raeburn 14504: allitems (reference to hash - key is category key
14505: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14506:
1.655 raeburn 14507: idx (reference to hash of counters used in Domain Coordinator interface for
14508: editing Course Categories).
1.663 raeburn 14509:
1.655 raeburn 14510: jsarray (reference to array of categories used to create Javascript arrays for
14511: Domain Coordinator interface for editing Course Categories).
14512:
1.665 raeburn 14513: subcats (reference to hash of arrays containing all subcategories within each
14514: category, -recursive)
14515:
1.1075.2.132 raeburn 14516: maxd (reference to hash used to hold max depth for all top-level categories).
14517:
1.655 raeburn 14518: Returns: nothing
14519:
14520: Side effects: populates trails and allitems hash references.
14521:
14522: =cut
14523:
14524: sub extract_categories {
1.1075.2.132 raeburn 14525: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 14526: if (ref($categories) eq 'HASH') {
14527: &gather_categories($categories,$cats,$idx,$jsarray);
14528: if (ref($cats->[0]) eq 'ARRAY') {
14529: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14530: my $name = $cats->[0][$i];
14531: my $item = &escape($name).'::0';
14532: my $trailstr;
14533: if ($name eq 'instcode') {
14534: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14535: } elsif ($name eq 'communities') {
14536: $trailstr = &mt('Communities');
1.655 raeburn 14537: } else {
14538: $trailstr = $name;
14539: }
14540: if ($allitems->{$item} eq '') {
14541: push(@{$trails},$trailstr);
14542: $allitems->{$item} = scalar(@{$trails})-1;
14543: }
14544: my @parents = ($name);
14545: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14546: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14547: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14548: if (ref($subcats) eq 'HASH') {
14549: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14550: }
1.1075.2.132 raeburn 14551: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 14552: }
14553: } else {
14554: if (ref($subcats) eq 'HASH') {
14555: $subcats->{$item} = [];
1.655 raeburn 14556: }
1.1075.2.132 raeburn 14557: if (ref($maxd) eq 'HASH') {
14558: $maxd->{$name} = 1;
14559: }
1.655 raeburn 14560: }
14561: }
14562: }
14563: }
14564: return;
14565: }
14566:
14567: =pod
14568:
1.1075.2.56 raeburn 14569: =item * &recurse_categories()
1.655 raeburn 14570:
14571: Recursively used to generate breadcrumb trails for course categories.
14572:
14573: Inputs:
1.663 raeburn 14574:
1.655 raeburn 14575: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14576: categories and subcategories).
1.663 raeburn 14577:
1.655 raeburn 14578: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14579:
14580: category (current course category, for which breadcrumb trail is being generated).
14581:
14582: trails (reference to array of breadcrumb trails for each category).
14583:
1.655 raeburn 14584: allitems (reference to hash - key is category key
14585: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14586:
1.655 raeburn 14587: parents (array containing containers directories for current category,
14588: back to top level).
14589:
14590: Returns: nothing
14591:
14592: Side effects: populates trails and allitems hash references
14593:
14594: =cut
14595:
14596: sub recurse_categories {
1.1075.2.132 raeburn 14597: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 14598: my $shallower = $depth - 1;
14599: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14600: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14601: my $name = $cats->[$depth]{$category}[$k];
14602: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14603: my $trailstr = join(' -> ',(@{$parents},$category));
14604: if ($allitems->{$item} eq '') {
14605: push(@{$trails},$trailstr);
14606: $allitems->{$item} = scalar(@{$trails})-1;
14607: }
14608: my $deeper = $depth+1;
14609: push(@{$parents},$category);
1.665 raeburn 14610: if (ref($subcats) eq 'HASH') {
14611: my $subcat = &escape($name).':'.$category.':'.$depth;
14612: for (my $j=@{$parents}; $j>=0; $j--) {
14613: my $higher;
14614: if ($j > 0) {
14615: $higher = &escape($parents->[$j]).':'.
14616: &escape($parents->[$j-1]).':'.$j;
14617: } else {
14618: $higher = &escape($parents->[$j]).'::'.$j;
14619: }
14620: push(@{$subcats->{$higher}},$subcat);
14621: }
14622: }
14623: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 14624: $subcats,$maxd);
1.655 raeburn 14625: pop(@{$parents});
14626: }
14627: } else {
14628: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 14629: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 14630: if ($allitems->{$item} eq '') {
14631: push(@{$trails},$trailstr);
14632: $allitems->{$item} = scalar(@{$trails})-1;
14633: }
1.1075.2.132 raeburn 14634: if (ref($maxd) eq 'HASH') {
14635: if ($depth > $maxd->{$parents->[0]}) {
14636: $maxd->{$parents->[0]} = $depth;
14637: }
14638: }
1.655 raeburn 14639: }
14640: return;
14641: }
14642:
1.663 raeburn 14643: =pod
14644:
1.1075.2.56 raeburn 14645: =item * &assign_categories_table()
1.663 raeburn 14646:
14647: Create a datatable for display of hierarchical categories in a domain,
14648: with checkboxes to allow a course to be categorized.
14649:
14650: Inputs:
14651:
14652: cathash - reference to hash of categories defined for the domain (from
14653: configuration.db)
14654:
14655: currcat - scalar with an & separated list of categories assigned to a course.
14656:
1.919 raeburn 14657: type - scalar contains course type (Course or Community).
14658:
1.1075.2.117 raeburn 14659: disabled - scalar (optional) contains disabled="disabled" if input elements are
14660: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14661:
1.663 raeburn 14662: Returns: $output (markup to be displayed)
14663:
14664: =cut
14665:
14666: sub assign_categories_table {
1.1075.2.117 raeburn 14667: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 14668: my $output;
14669: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 14670: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
14671: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 14672: $maxdepth = scalar(@cats);
14673: if (@cats > 0) {
14674: my $itemcount = 0;
14675: if (ref($cats[0]) eq 'ARRAY') {
14676: my @currcategories;
14677: if ($currcat ne '') {
14678: @currcategories = split('&',$currcat);
14679: }
1.919 raeburn 14680: my $table;
1.663 raeburn 14681: for (my $i=0; $i<@{$cats[0]}; $i++) {
14682: my $parent = $cats[0][$i];
1.919 raeburn 14683: next if ($parent eq 'instcode');
14684: if ($type eq 'Community') {
14685: next unless ($parent eq 'communities');
14686: } else {
14687: next if ($parent eq 'communities');
14688: }
1.663 raeburn 14689: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14690: my $item = &escape($parent).'::0';
14691: my $checked = '';
14692: if (@currcategories > 0) {
14693: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14694: $checked = ' checked="checked"';
1.663 raeburn 14695: }
14696: }
1.919 raeburn 14697: my $parent_title = $parent;
14698: if ($parent eq 'communities') {
14699: $parent_title = &mt('Communities');
14700: }
14701: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14702: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14703: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 14704: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14705: my $depth = 1;
14706: push(@path,$parent);
1.1075.2.117 raeburn 14707: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 14708: pop(@path);
1.919 raeburn 14709: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14710: $itemcount ++;
14711: }
1.919 raeburn 14712: if ($itemcount) {
14713: $output = &Apache::loncommon::start_data_table().
14714: $table.
14715: &Apache::loncommon::end_data_table();
14716: }
1.663 raeburn 14717: }
14718: }
14719: }
14720: return $output;
14721: }
14722:
14723: =pod
14724:
1.1075.2.56 raeburn 14725: =item * &assign_category_rows()
1.663 raeburn 14726:
14727: Create a datatable row for display of nested categories in a domain,
14728: with checkboxes to allow a course to be categorized,called recursively.
14729:
14730: Inputs:
14731:
14732: itemcount - track row number for alternating colors
14733:
14734: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14735: categories and subcategories.
14736:
14737: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14738:
14739: parent - parent of current category item
14740:
14741: path - Array containing all categories back up through the hierarchy from the
14742: current category to the top level.
14743:
14744: currcategories - reference to array of current categories assigned to the course
14745:
1.1075.2.117 raeburn 14746: disabled - scalar (optional) contains disabled="disabled" if input elements are
14747: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14748:
1.663 raeburn 14749: Returns: $output (markup to be displayed).
14750:
14751: =cut
14752:
14753: sub assign_category_rows {
1.1075.2.117 raeburn 14754: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 14755: my ($text,$name,$item,$chgstr);
14756: if (ref($cats) eq 'ARRAY') {
14757: my $maxdepth = scalar(@{$cats});
14758: if (ref($cats->[$depth]) eq 'HASH') {
14759: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14760: my $numchildren = @{$cats->[$depth]{$parent}};
14761: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 14762: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14763: for (my $j=0; $j<$numchildren; $j++) {
14764: $name = $cats->[$depth]{$parent}[$j];
14765: $item = &escape($name).':'.&escape($parent).':'.$depth;
14766: my $deeper = $depth+1;
14767: my $checked = '';
14768: if (ref($currcategories) eq 'ARRAY') {
14769: if (@{$currcategories} > 0) {
14770: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14771: $checked = ' checked="checked"';
1.663 raeburn 14772: }
14773: }
14774: }
1.664 raeburn 14775: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14776: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14777: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 14778: '<input type="hidden" name="catname" value="'.$name.'" />'.
14779: '</td><td>';
1.663 raeburn 14780: if (ref($path) eq 'ARRAY') {
14781: push(@{$path},$name);
1.1075.2.117 raeburn 14782: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 14783: pop(@{$path});
14784: }
14785: $text .= '</td></tr>';
14786: }
14787: $text .= '</table></td>';
14788: }
14789: }
14790: }
14791: return $text;
14792: }
14793:
1.1075.2.69 raeburn 14794: =pod
14795:
14796: =back
14797:
14798: =cut
14799:
1.655 raeburn 14800: ############################################################
14801: ############################################################
14802:
14803:
1.443 albertel 14804: sub commit_customrole {
1.664 raeburn 14805: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14806: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14807: ($start?', '.&mt('starting').' '.localtime($start):'').
14808: ($end?', ending '.localtime($end):'').': <b>'.
14809: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14810: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14811: '</b><br />';
14812: return $output;
14813: }
14814:
14815: sub commit_standardrole {
1.1075.2.31 raeburn 14816: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14817: my ($output,$logmsg,$linefeed);
14818: if ($context eq 'auto') {
14819: $linefeed = "\n";
14820: } else {
14821: $linefeed = "<br />\n";
14822: }
1.443 albertel 14823: if ($three eq 'st') {
1.541 raeburn 14824: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 14825: $one,$two,$sec,$context,$credits);
1.541 raeburn 14826: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14827: ($result eq 'unknown_course') || ($result eq 'refused')) {
14828: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14829: } else {
1.541 raeburn 14830: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14831: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14832: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14833: if ($context eq 'auto') {
14834: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14835: } else {
14836: $output .= '<b>'.$result.'</b>'.$linefeed.
14837: &mt('Add to classlist').': <b>ok</b>';
14838: }
14839: $output .= $linefeed;
1.443 albertel 14840: }
14841: } else {
14842: $output = &mt('Assigning').' '.$three.' in '.$url.
14843: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14844: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 14845: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 14846: if ($context eq 'auto') {
14847: $output .= $result.$linefeed;
14848: } else {
14849: $output .= '<b>'.$result.'</b>'.$linefeed;
14850: }
1.443 albertel 14851: }
14852: return $output;
14853: }
14854:
14855: sub commit_studentrole {
1.1075.2.31 raeburn 14856: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
14857: $credits) = @_;
1.626 raeburn 14858: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 14859: if ($context eq 'auto') {
14860: $linefeed = "\n";
14861: } else {
14862: $linefeed = '<br />'."\n";
14863: }
1.443 albertel 14864: if (defined($one) && defined($two)) {
14865: my $cid=$one.'_'.$two;
14866: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
14867: my $secchange = 0;
14868: my $expire_role_result;
14869: my $modify_section_result;
1.628 raeburn 14870: if ($oldsec ne '-1') {
14871: if ($oldsec ne $sec) {
1.443 albertel 14872: $secchange = 1;
1.628 raeburn 14873: my $now = time;
1.443 albertel 14874: my $uurl='/'.$cid;
14875: $uurl=~s/\_/\//g;
14876: if ($oldsec) {
14877: $uurl.='/'.$oldsec;
14878: }
1.626 raeburn 14879: $oldsecurl = $uurl;
1.628 raeburn 14880: $expire_role_result =
1.652 raeburn 14881: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 14882: if ($env{'request.course.sec'} ne '') {
14883: if ($expire_role_result eq 'refused') {
14884: my @roles = ('st');
14885: my @statuses = ('previous');
14886: my @roledoms = ($one);
14887: my $withsec = 1;
14888: my %roleshash =
14889: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
14890: \@statuses,\@roles,\@roledoms,$withsec);
14891: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
14892: my ($oldstart,$oldend) =
14893: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
14894: if ($oldend > 0 && $oldend <= $now) {
14895: $expire_role_result = 'ok';
14896: }
14897: }
14898: }
14899: }
1.443 albertel 14900: $result = $expire_role_result;
14901: }
14902: }
14903: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 14904: $modify_section_result =
14905: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
14906: undef,undef,undef,$sec,
14907: $end,$start,'','',$cid,
14908: '',$context,$credits);
1.443 albertel 14909: if ($modify_section_result =~ /^ok/) {
14910: if ($secchange == 1) {
1.628 raeburn 14911: if ($sec eq '') {
14912: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
14913: } else {
14914: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
14915: }
1.443 albertel 14916: } elsif ($oldsec eq '-1') {
1.628 raeburn 14917: if ($sec eq '') {
14918: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
14919: } else {
14920: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14921: }
1.443 albertel 14922: } else {
1.628 raeburn 14923: if ($sec eq '') {
14924: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
14925: } else {
14926: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14927: }
1.443 albertel 14928: }
14929: } else {
1.628 raeburn 14930: if ($secchange) {
14931: $$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;
14932: } else {
14933: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
14934: }
1.443 albertel 14935: }
14936: $result = $modify_section_result;
14937: } elsif ($secchange == 1) {
1.628 raeburn 14938: if ($oldsec eq '') {
1.1075.2.20 raeburn 14939: $$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 14940: } else {
14941: $$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;
14942: }
1.626 raeburn 14943: if ($expire_role_result eq 'refused') {
14944: my $newsecurl = '/'.$cid;
14945: $newsecurl =~ s/\_/\//g;
14946: if ($sec ne '') {
14947: $newsecurl.='/'.$sec;
14948: }
14949: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
14950: if ($sec eq '') {
14951: $$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;
14952: } else {
14953: $$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;
14954: }
14955: }
14956: }
1.443 albertel 14957: }
14958: } else {
1.626 raeburn 14959: $$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 14960: $result = "error: incomplete course id\n";
14961: }
14962: return $result;
14963: }
14964:
1.1075.2.25 raeburn 14965: sub show_role_extent {
14966: my ($scope,$context,$role) = @_;
14967: $scope =~ s{^/}{};
14968: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
14969: push(@courseroles,'co');
14970: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
14971: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
14972: $scope =~ s{/}{_};
14973: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
14974: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
14975: my ($audom,$auname) = split(/\//,$scope);
14976: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
14977: &Apache::loncommon::plainname($auname,$audom).'</span>');
14978: } else {
14979: $scope =~ s{/$}{};
14980: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
14981: &Apache::lonnet::domain($scope,'description').'</span>');
14982: }
14983: }
14984:
1.443 albertel 14985: ############################################################
14986: ############################################################
14987:
1.566 albertel 14988: sub check_clone {
1.578 raeburn 14989: my ($args,$linefeed) = @_;
1.566 albertel 14990: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
14991: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
14992: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
14993: my $clonemsg;
14994: my $can_clone = 0;
1.944 raeburn 14995: my $lctype = lc($args->{'crstype'});
1.908 raeburn 14996: if ($lctype ne 'community') {
14997: $lctype = 'course';
14998: }
1.566 albertel 14999: if ($clonehome eq 'no_host') {
1.944 raeburn 15000: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15001: $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'});
15002: } else {
15003: $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'});
15004: }
1.566 albertel 15005: } else {
15006: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15007: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15008: if ($clonedesc{'type'} ne 'Community') {
15009: $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'});
15010: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15011: }
15012: }
1.1075.2.119 raeburn 15013: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15014: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15015: $can_clone = 1;
15016: } else {
1.1075.2.95 raeburn 15017: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15018: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 15019: if ($clonehash{'cloners'} eq '') {
15020: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15021: if ($domdefs{'canclone'}) {
15022: unless ($domdefs{'canclone'} eq 'none') {
15023: if ($domdefs{'canclone'} eq 'domain') {
15024: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15025: $can_clone = 1;
15026: }
15027: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15028: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15029: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15030: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15031: $can_clone = 1;
15032: }
15033: }
15034: }
1.908 raeburn 15035: }
1.1075.2.95 raeburn 15036: } else {
15037: my @cloners = split(/,/,$clonehash{'cloners'});
15038: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15039: $can_clone = 1;
1.1075.2.95 raeburn 15040: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15041: $can_clone = 1;
1.1075.2.96 raeburn 15042: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15043: $can_clone = 1;
1.1075.2.95 raeburn 15044: }
15045: unless ($can_clone) {
1.1075.2.96 raeburn 15046: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15047: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 15048: my (%gotdomdefaults,%gotcodedefaults);
15049: foreach my $cloner (@cloners) {
15050: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15051: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15052: my (%codedefaults,@code_order);
15053: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15054: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15055: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15056: }
15057: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15058: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15059: }
15060: } else {
15061: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15062: \%codedefaults,
15063: \@code_order);
15064: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15065: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15066: }
15067: if (@code_order > 0) {
15068: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15069: $cloner,$clonehash{'internal.coursecode'},
15070: $args->{'crscode'})) {
15071: $can_clone = 1;
15072: last;
15073: }
15074: }
15075: }
15076: }
15077: }
1.1075.2.96 raeburn 15078: }
15079: }
15080: unless ($can_clone) {
15081: my $ccrole = 'cc';
15082: if ($args->{'crstype'} eq 'Community') {
15083: $ccrole = 'co';
15084: }
15085: my %roleshash =
15086: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15087: $args->{'ccdomain'},
15088: 'userroles',['active'],[$ccrole],
15089: [$args->{'clonedomain'}]);
15090: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15091: $can_clone = 1;
15092: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15093: $args->{'ccuname'},$args->{'ccdomain'})) {
15094: $can_clone = 1;
1.1075.2.95 raeburn 15095: }
15096: }
15097: unless ($can_clone) {
15098: if ($args->{'crstype'} eq 'Community') {
15099: $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'});
15100: } else {
15101: $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 15102: }
1.566 albertel 15103: }
1.578 raeburn 15104: }
1.566 albertel 15105: }
15106: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15107: }
15108:
1.444 albertel 15109: sub construct_course {
1.1075.2.119 raeburn 15110: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15111: $cnum,$category,$coderef) = @_;
1.444 albertel 15112: my $outcome;
1.541 raeburn 15113: my $linefeed = '<br />'."\n";
15114: if ($context eq 'auto') {
15115: $linefeed = "\n";
15116: }
1.566 albertel 15117:
15118: #
15119: # Are we cloning?
15120: #
15121: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15122: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15123: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15124: if ($context ne 'auto') {
1.578 raeburn 15125: if ($clonemsg ne '') {
15126: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15127: }
1.566 albertel 15128: }
15129: $outcome .= $clonemsg.$linefeed;
15130:
15131: if (!$can_clone) {
15132: return (0,$outcome);
15133: }
15134: }
15135:
1.444 albertel 15136: #
15137: # Open course
15138: #
15139: my $crstype = lc($args->{'crstype'});
15140: my %cenv=();
15141: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15142: $args->{'cdescr'},
15143: $args->{'curl'},
15144: $args->{'course_home'},
15145: $args->{'nonstandard'},
15146: $args->{'crscode'},
15147: $args->{'ccuname'}.':'.
15148: $args->{'ccdomain'},
1.882 raeburn 15149: $args->{'crstype'},
1.885 raeburn 15150: $cnum,$context,$category);
1.444 albertel 15151:
15152: # Note: The testing routines depend on this being output; see
15153: # Utils::Course. This needs to at least be output as a comment
15154: # if anyone ever decides to not show this, and Utils::Course::new
15155: # will need to be suitably modified.
1.541 raeburn 15156: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 15157: if ($$courseid =~ /^error:/) {
15158: return (0,$outcome);
15159: }
15160:
1.444 albertel 15161: #
15162: # Check if created correctly
15163: #
1.479 albertel 15164: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15165: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15166: if ($crsuhome eq 'no_host') {
15167: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15168: return (0,$outcome);
15169: }
1.541 raeburn 15170: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15171:
1.444 albertel 15172: #
1.566 albertel 15173: # Do the cloning
15174: #
15175: if ($can_clone && $cloneid) {
15176: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
15177: if ($context ne 'auto') {
15178: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15179: }
15180: $outcome .= $clonemsg.$linefeed;
15181: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15182: # Copy all files
1.637 www 15183: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15184: # Restore URL
1.566 albertel 15185: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15186: # Restore title
1.566 albertel 15187: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15188: # Restore creation date, creator and creation context.
15189: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15190: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15191: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15192: # Mark as cloned
1.566 albertel 15193: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15194: # Need to clone grading mode
15195: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15196: $cenv{'grading'}=$newenv{'grading'};
15197: # Do not clone these environment entries
15198: &Apache::lonnet::del('environment',
15199: ['default_enrollment_start_date',
15200: 'default_enrollment_end_date',
15201: 'question.email',
15202: 'policy.email',
15203: 'comment.email',
15204: 'pch.users.denied',
1.725 raeburn 15205: 'plc.users.denied',
15206: 'hidefromcat',
1.1075.2.36 raeburn 15207: 'checkforpriv',
1.1075.2.59 raeburn 15208: 'categories',
15209: 'internal.uniquecode'],
1.638 www 15210: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 15211: if ($args->{'textbook'}) {
15212: $cenv{'internal.textbook'} = $args->{'textbook'};
15213: }
1.444 albertel 15214: }
1.566 albertel 15215:
1.444 albertel 15216: #
15217: # Set environment (will override cloned, if existing)
15218: #
15219: my @sections = ();
15220: my @xlists = ();
15221: if ($args->{'crstype'}) {
15222: $cenv{'type'}=$args->{'crstype'};
15223: }
15224: if ($args->{'crsid'}) {
15225: $cenv{'courseid'}=$args->{'crsid'};
15226: }
15227: if ($args->{'crscode'}) {
15228: $cenv{'internal.coursecode'}=$args->{'crscode'};
15229: }
15230: if ($args->{'crsquota'} ne '') {
15231: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15232: } else {
15233: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15234: }
15235: if ($args->{'ccuname'}) {
15236: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15237: ':'.$args->{'ccdomain'};
15238: } else {
15239: $cenv{'internal.courseowner'} = $args->{'curruser'};
15240: }
1.1075.2.31 raeburn 15241: if ($args->{'defaultcredits'}) {
15242: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15243: }
1.444 albertel 15244: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15245: if ($args->{'crssections'}) {
15246: $cenv{'internal.sectionnums'} = '';
15247: if ($args->{'crssections'} =~ m/,/) {
15248: @sections = split/,/,$args->{'crssections'};
15249: } else {
15250: $sections[0] = $args->{'crssections'};
15251: }
15252: if (@sections > 0) {
15253: foreach my $item (@sections) {
15254: my ($sec,$gp) = split/:/,$item;
15255: my $class = $args->{'crscode'}.$sec;
15256: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15257: $cenv{'internal.sectionnums'} .= $item.',';
15258: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15259: push(@badclasses,$class);
1.444 albertel 15260: }
15261: }
15262: $cenv{'internal.sectionnums'} =~ s/,$//;
15263: }
15264: }
15265: # do not hide course coordinator from staff listing,
15266: # even if privileged
15267: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 15268: # add course coordinator's domain to domains to check for privileged users
15269: # if different to course domain
15270: if ($$crsudom ne $args->{'ccdomain'}) {
15271: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15272: }
1.444 albertel 15273: # add crosslistings
15274: if ($args->{'crsxlist'}) {
15275: $cenv{'internal.crosslistings'}='';
15276: if ($args->{'crsxlist'} =~ m/,/) {
15277: @xlists = split/,/,$args->{'crsxlist'};
15278: } else {
15279: $xlists[0] = $args->{'crsxlist'};
15280: }
15281: if (@xlists > 0) {
15282: foreach my $item (@xlists) {
15283: my ($xl,$gp) = split/:/,$item;
15284: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15285: $cenv{'internal.crosslistings'} .= $item.',';
15286: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15287: push(@badclasses,$xl);
1.444 albertel 15288: }
15289: }
15290: $cenv{'internal.crosslistings'} =~ s/,$//;
15291: }
15292: }
15293: if ($args->{'autoadds'}) {
15294: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15295: }
15296: if ($args->{'autodrops'}) {
15297: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15298: }
15299: # check for notification of enrollment changes
15300: my @notified = ();
15301: if ($args->{'notify_owner'}) {
15302: if ($args->{'ccuname'} ne '') {
15303: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15304: }
15305: }
15306: if ($args->{'notify_dc'}) {
15307: if ($uname ne '') {
1.630 raeburn 15308: push(@notified,$uname.':'.$udom);
1.444 albertel 15309: }
15310: }
15311: if (@notified > 0) {
15312: my $notifylist;
15313: if (@notified > 1) {
15314: $notifylist = join(',',@notified);
15315: } else {
15316: $notifylist = $notified[0];
15317: }
15318: $cenv{'internal.notifylist'} = $notifylist;
15319: }
15320: if (@badclasses > 0) {
15321: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 15322: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15323: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15324: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15325: );
1.1075.2.119 raeburn 15326: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15327: &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 15328: if ($context eq 'auto') {
15329: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 15330: } else {
1.566 albertel 15331: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 15332: }
15333: foreach my $item (@badclasses) {
1.541 raeburn 15334: if ($context eq 'auto') {
1.1075.2.119 raeburn 15335: $outcome .= " - $item\n";
1.541 raeburn 15336: } else {
1.1075.2.119 raeburn 15337: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15338: }
1.1075.2.119 raeburn 15339: }
15340: if ($context eq 'auto') {
15341: $outcome .= $linefeed;
15342: } else {
15343: $outcome .= "</ul><br /><br /></div>\n";
15344: }
1.444 albertel 15345: }
15346: if ($args->{'no_end_date'}) {
15347: $args->{'endaccess'} = 0;
15348: }
15349: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15350: $cenv{'internal.autoend'}=$args->{'enrollend'};
15351: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15352: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15353: if ($args->{'showphotos'}) {
15354: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15355: }
15356: $cenv{'internal.authtype'} = $args->{'authtype'};
15357: $cenv{'internal.autharg'} = $args->{'autharg'};
15358: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15359: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15360: 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');
15361: if ($context eq 'auto') {
15362: $outcome .= $krb_msg;
15363: } else {
1.566 albertel 15364: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15365: }
15366: $outcome .= $linefeed;
1.444 albertel 15367: }
15368: }
15369: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15370: if ($args->{'setpolicy'}) {
15371: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15372: }
15373: if ($args->{'setcontent'}) {
15374: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15375: }
1.1075.2.110 raeburn 15376: if ($args->{'setcomment'}) {
15377: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15378: }
1.444 albertel 15379: }
15380: if ($args->{'reshome'}) {
15381: $cenv{'reshome'}=$args->{'reshome'}.'/';
15382: $cenv{'reshome'}=~s/\/+$/\//;
15383: }
15384: #
15385: # course has keyed access
15386: #
15387: if ($args->{'setkeys'}) {
15388: $cenv{'keyaccess'}='yes';
15389: }
15390: # if specified, key authority is not course, but user
15391: # only active if keyaccess is yes
15392: if ($args->{'keyauth'}) {
1.487 albertel 15393: my ($user,$domain) = split(':',$args->{'keyauth'});
15394: $user = &LONCAPA::clean_username($user);
15395: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15396: if ($user ne '' && $domain ne '') {
1.487 albertel 15397: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15398: }
15399: }
15400:
1.1075.2.59 raeburn 15401: #
15402: # generate and store uniquecode (available to course requester), if course should have one.
15403: #
15404: if ($args->{'uniquecode'}) {
15405: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15406: if ($code) {
15407: $cenv{'internal.uniquecode'} = $code;
15408: my %crsinfo =
15409: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15410: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15411: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15412: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15413: }
15414: if (ref($coderef)) {
15415: $$coderef = $code;
15416: }
15417: }
15418: }
15419:
1.444 albertel 15420: if ($args->{'disresdis'}) {
15421: $cenv{'pch.roles.denied'}='st';
15422: }
15423: if ($args->{'disablechat'}) {
15424: $cenv{'plc.roles.denied'}='st';
15425: }
15426:
15427: # Record we've not yet viewed the Course Initialization Helper for this
15428: # course
15429: $cenv{'course.helper.not.run'} = 1;
15430: #
15431: # Use new Randomseed
15432: #
15433: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15434: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15435: #
15436: # The encryption code and receipt prefix for this course
15437: #
15438: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15439: $cenv{'internal.encpref'}=100+int(9*rand(99));
15440: #
15441: # By default, use standard grading
15442: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15443:
1.541 raeburn 15444: $outcome .= $linefeed.&mt('Setting environment').': '.
15445: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15446: #
15447: # Open all assignments
15448: #
15449: if ($args->{'openall'}) {
15450: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
15451: my %storecontent = ($storeunder => time,
15452: $storeunder.'.type' => 'date_start');
15453:
15454: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 15455: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15456: }
15457: #
15458: # Set first page
15459: #
15460: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15461: || ($cloneid)) {
1.445 albertel 15462: use LONCAPA::map;
1.444 albertel 15463: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15464:
15465: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15466: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15467:
1.444 albertel 15468: $outcome .= ($fatal?$errtext:'read ok').' - ';
15469: my $title; my $url;
15470: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15471: $title=&mt('Syllabus');
1.444 albertel 15472: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15473: } else {
1.963 raeburn 15474: $title=&mt('Table of Contents');
1.444 albertel 15475: $url='/adm/navmaps';
15476: }
1.445 albertel 15477:
15478: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15479: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15480:
15481: if ($errtext) { $fatal=2; }
1.541 raeburn 15482: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15483: }
1.566 albertel 15484:
15485: return (1,$outcome);
1.444 albertel 15486: }
15487:
1.1075.2.59 raeburn 15488: sub make_unique_code {
15489: my ($cdom,$cnum) = @_;
15490: # get lock on uniquecodes db
15491: my $lockhash = {
15492: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15493: ':'.$env{'user.domain'},
15494: };
15495: my $tries = 0;
15496: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15497: my ($code,$error);
15498:
15499: while (($gotlock ne 'ok') && ($tries<3)) {
15500: $tries ++;
15501: sleep 1;
15502: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15503: }
15504: if ($gotlock eq 'ok') {
15505: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15506: my $gotcode;
15507: my $attempts = 0;
15508: while ((!$gotcode) && ($attempts < 100)) {
15509: $code = &generate_code();
15510: if (!exists($currcodes{$code})) {
15511: $gotcode = 1;
15512: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15513: $error = 'nostore';
15514: }
15515: }
15516: $attempts ++;
15517: }
15518: my @del_lock = ($cnum."\0".'uniquecodes');
15519: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15520: } else {
15521: $error = 'nolock';
15522: }
15523: return ($code,$error);
15524: }
15525:
15526: sub generate_code {
15527: my $code;
15528: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15529: for (my $i=0; $i<6; $i++) {
15530: my $lettnum = int (rand 2);
15531: my $item = '';
15532: if ($lettnum) {
15533: $item = $letts[int( rand(18) )];
15534: } else {
15535: $item = 1+int( rand(8) );
15536: }
15537: $code .= $item;
15538: }
15539: return $code;
15540: }
15541:
1.444 albertel 15542: ############################################################
15543: ############################################################
15544:
1.953 droeschl 15545: #SD
15546: # only Community and Course, or anything else?
1.378 raeburn 15547: sub course_type {
15548: my ($cid) = @_;
15549: if (!defined($cid)) {
15550: $cid = $env{'request.course.id'};
15551: }
1.404 albertel 15552: if (defined($env{'course.'.$cid.'.type'})) {
15553: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15554: } else {
15555: return 'Course';
1.377 raeburn 15556: }
15557: }
1.156 albertel 15558:
1.406 raeburn 15559: sub group_term {
15560: my $crstype = &course_type();
15561: my %names = (
15562: 'Course' => 'group',
1.865 raeburn 15563: 'Community' => 'group',
1.406 raeburn 15564: );
15565: return $names{$crstype};
15566: }
15567:
1.902 raeburn 15568: sub course_types {
1.1075.2.59 raeburn 15569: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15570: my %typename = (
15571: official => 'Official course',
15572: unofficial => 'Unofficial course',
15573: community => 'Community',
1.1075.2.59 raeburn 15574: textbook => 'Textbook course',
1.902 raeburn 15575: );
15576: return (\@types,\%typename);
15577: }
15578:
1.156 albertel 15579: sub icon {
15580: my ($file)=@_;
1.505 albertel 15581: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15582: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15583: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15584: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15585: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15586: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15587: $curfext.".gif") {
15588: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15589: $curfext.".gif";
15590: }
15591: }
1.249 albertel 15592: return &lonhttpdurl($iconname);
1.154 albertel 15593: }
1.84 albertel 15594:
1.575 albertel 15595: sub lonhttpdurl {
1.692 www 15596: #
15597: # Had been used for "small fry" static images on separate port 8080.
15598: # Modify here if lightweight http functionality desired again.
15599: # Currently eliminated due to increasing firewall issues.
15600: #
1.575 albertel 15601: my ($url)=@_;
1.692 www 15602: return $url;
1.215 albertel 15603: }
15604:
1.213 albertel 15605: sub connection_aborted {
15606: my ($r)=@_;
15607: $r->print(" ");$r->rflush();
15608: my $c = $r->connection;
15609: return $c->aborted();
15610: }
15611:
1.221 foxr 15612: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15613: # strings as 'strings'.
15614: sub escape_single {
1.221 foxr 15615: my ($input) = @_;
1.223 albertel 15616: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15617: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15618: return $input;
15619: }
1.223 albertel 15620:
1.222 foxr 15621: # Same as escape_single, but escape's "'s This
15622: # can be used for "strings"
15623: sub escape_double {
15624: my ($input) = @_;
15625: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15626: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15627: return $input;
15628: }
1.223 albertel 15629:
1.222 foxr 15630: # Escapes the last element of a full URL.
15631: sub escape_url {
15632: my ($url) = @_;
1.238 raeburn 15633: my @urlslices = split(/\//, $url,-1);
1.369 www 15634: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 15635: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15636: }
1.462 albertel 15637:
1.820 raeburn 15638: sub compare_arrays {
15639: my ($arrayref1,$arrayref2) = @_;
15640: my (@difference,%count);
15641: @difference = ();
15642: %count = ();
15643: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15644: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15645: foreach my $element (keys(%count)) {
15646: if ($count{$element} == 1) {
15647: push(@difference,$element);
15648: }
15649: }
15650: }
15651: return @difference;
15652: }
15653:
1.817 bisitz 15654: # -------------------------------------------------------- Initialize user login
1.462 albertel 15655: sub init_user_environment {
1.463 albertel 15656: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15657: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15658:
15659: my $public=($username eq 'public' && $domain eq 'public');
15660:
15661: # See if old ID present, if so, remove
15662:
1.1062 raeburn 15663: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15664: my $now=time;
15665:
15666: if ($public) {
15667: my $max_public=100;
15668: my $oldest;
15669: my $oldest_time=0;
15670: for(my $next=1;$next<=$max_public;$next++) {
15671: if (-e $lonids."/publicuser_$next.id") {
15672: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
15673: if ($mtime<$oldest_time || !$oldest_time) {
15674: $oldest_time=$mtime;
15675: $oldest=$next;
15676: }
15677: } else {
15678: $cookie="publicuser_$next";
15679: last;
15680: }
15681: }
15682: if (!$cookie) { $cookie="publicuser_$oldest"; }
15683: } else {
1.463 albertel 15684: # if this isn't a robot, kill any existing non-robot sessions
15685: if (!$args->{'robot'}) {
15686: opendir(DIR,$lonids);
15687: while ($filename=readdir(DIR)) {
15688: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136 raeburn 15689: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
15690: &GDBM_READER(),0640)) {
15691: my $linkedfile;
15692: if (exists($oldenv{'user.linkedenv'})) {
15693: $linkedfile = $oldenv{'user.linkedenv'};
15694: }
15695: untie(%oldenv);
15696: if (unlink("$lonids/$filename")) {
15697: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
15698: if (-l "$lonids/$linkedfile.id") {
15699: unlink("$lonids/$linkedfile.id");
15700: }
15701: }
15702: }
15703: } else {
15704: unlink($lonids.'/'.$filename);
15705: }
1.463 albertel 15706: }
1.462 albertel 15707: }
1.463 albertel 15708: closedir(DIR);
1.1075.2.84 raeburn 15709: # If there is a undeleted lockfile for the user's paste buffer remove it.
15710: my $namespace = 'nohist_courseeditor';
15711: my $lockingkey = 'paste'."\0".'locked_num';
15712: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
15713: $domain,$username);
15714: if (exists($lockhash{$lockingkey})) {
15715: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
15716: unless ($delresult eq 'ok') {
15717: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
15718: }
15719: }
1.462 albertel 15720: }
15721: # Give them a new cookie
1.463 albertel 15722: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 15723: : $now.$$.int(rand(10000)));
1.463 albertel 15724: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 15725:
15726: # Initialize roles
15727:
1.1062 raeburn 15728: ($userroles,$firstaccenv,$timerintenv) =
15729: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 15730: }
15731: # ------------------------------------ Check browser type and MathML capability
15732:
1.1075.2.77 raeburn 15733: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15734: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15735:
15736: # ------------------------------------------------------------- Get environment
15737:
15738: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15739: my ($tmp) = keys(%userenv);
15740: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
15741: } else {
15742: undef(%userenv);
15743: }
15744: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15745: $form->{'interface'}=$userenv{'interface'};
15746: }
15747: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15748:
15749: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15750: foreach my $option ('interface','localpath','localres') {
15751: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15752: }
15753: # --------------------------------------------------------- Write first profile
15754:
15755: {
15756: my %initial_env =
15757: ("user.name" => $username,
15758: "user.domain" => $domain,
15759: "user.home" => $authhost,
15760: "browser.type" => $clientbrowser,
15761: "browser.version" => $clientversion,
15762: "browser.mathml" => $clientmathml,
15763: "browser.unicode" => $clientunicode,
15764: "browser.os" => $clientos,
1.1075.2.42 raeburn 15765: "browser.mobile" => $clientmobile,
15766: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 15767: "browser.osversion" => $clientosversion,
1.462 albertel 15768: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
15769: "request.course.fn" => '',
15770: "request.course.uri" => '',
15771: "request.course.sec" => '',
15772: "request.role" => 'cm',
15773: "request.role.adv" => $env{'user.adv'},
15774: "request.host" => $ENV{'REMOTE_ADDR'},);
15775:
15776: if ($form->{'localpath'}) {
15777: $initial_env{"browser.localpath"} = $form->{'localpath'};
15778: $initial_env{"browser.localres"} = $form->{'localres'};
15779: }
15780:
15781: if ($form->{'interface'}) {
15782: $form->{'interface'}=~s/\W//gs;
15783: $initial_env{"browser.interface"} = $form->{'interface'};
15784: $env{'browser.interface'}=$form->{'interface'};
15785: }
15786:
1.1075.2.54 raeburn 15787: if ($form->{'iptoken'}) {
15788: my $lonhost = $r->dir_config('lonHostID');
15789: $initial_env{"user.noloadbalance"} = $lonhost;
15790: $env{'user.noloadbalance'} = $lonhost;
15791: }
15792:
1.1075.2.120 raeburn 15793: if ($form->{'noloadbalance'}) {
15794: my @hosts = &Apache::lonnet::current_machine_ids();
15795: my $hosthere = $form->{'noloadbalance'};
15796: if (grep(/^\Q$hosthere\E$/,@hosts)) {
15797: $initial_env{"user.noloadbalance"} = $hosthere;
15798: $env{'user.noloadbalance'} = $hosthere;
15799: }
15800: }
15801:
1.1016 raeburn 15802: unless ($domain eq 'public') {
1.1075.2.125 raeburn 15803: my %is_adv = ( is_adv => $env{'user.adv'} );
15804: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 15805:
1.1075.2.125 raeburn 15806: foreach my $tool ('aboutme','blog','webdav','portfolio') {
15807: $userenv{'availabletools.'.$tool} =
15808: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
15809: undef,\%userenv,\%domdef,\%is_adv);
15810: }
1.724 raeburn 15811:
1.1075.2.125 raeburn 15812: foreach my $crstype ('official','unofficial','community','textbook') {
15813: $userenv{'canrequest.'.$crstype} =
15814: &Apache::lonnet::usertools_access($username,$domain,$crstype,
15815: 'reload','requestcourses',
15816: \%userenv,\%domdef,\%is_adv);
15817: }
1.765 raeburn 15818:
1.1075.2.125 raeburn 15819: $userenv{'canrequest.author'} =
15820: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15821: 'reload','requestauthor',
15822: \%userenv,\%domdef,\%is_adv);
15823: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15824: $domain,$username);
15825: my $reqstatus = $reqauthor{'author_status'};
15826: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15827: if (ref($reqauthor{'author'}) eq 'HASH') {
15828: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15829: $reqauthor{'author'}{'timestamp'};
15830: }
1.1075.2.14 raeburn 15831: }
15832: }
15833:
1.462 albertel 15834: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 15835:
1.462 albertel 15836: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
15837: &GDBM_WRCREAT(),0640)) {
15838: &_add_to_env(\%disk_env,\%initial_env);
15839: &_add_to_env(\%disk_env,\%userenv,'environment.');
15840: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 15841: if (ref($firstaccenv) eq 'HASH') {
15842: &_add_to_env(\%disk_env,$firstaccenv);
15843: }
15844: if (ref($timerintenv) eq 'HASH') {
15845: &_add_to_env(\%disk_env,$timerintenv);
15846: }
1.463 albertel 15847: if (ref($args->{'extra_env'})) {
15848: &_add_to_env(\%disk_env,$args->{'extra_env'});
15849: }
1.462 albertel 15850: untie(%disk_env);
15851: } else {
1.705 tempelho 15852: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
15853: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 15854: return 'error: '.$!;
15855: }
15856: }
15857: $env{'request.role'}='cm';
15858: $env{'request.role.adv'}=$env{'user.adv'};
15859: $env{'browser.type'}=$clientbrowser;
15860:
15861: return $cookie;
15862:
15863: }
15864:
15865: sub _add_to_env {
15866: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 15867: if (ref($env_data) eq 'HASH') {
15868: while (my ($key,$value) = each(%$env_data)) {
15869: $idf->{$prefix.$key} = $value;
15870: $env{$prefix.$key} = $value;
15871: }
1.462 albertel 15872: }
15873: }
15874:
1.685 tempelho 15875: # --- Get the symbolic name of a problem and the url
15876: sub get_symb {
15877: my ($request,$silent) = @_;
1.726 raeburn 15878: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 15879: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
15880: if ($symb eq '') {
15881: if (!$silent) {
1.1071 raeburn 15882: if (ref($request)) {
15883: $request->print("Unable to handle ambiguous references:$url:.");
15884: }
1.685 tempelho 15885: return ();
15886: }
15887: }
15888: &Apache::lonenc::check_decrypt(\$symb);
15889: return ($symb);
15890: }
15891:
15892: # --------------------------------------------------------------Get annotation
15893:
15894: sub get_annotation {
15895: my ($symb,$enc) = @_;
15896:
15897: my $key = $symb;
15898: if (!$enc) {
15899: $key =
15900: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
15901: }
15902: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
15903: return $annotation{$key};
15904: }
15905:
15906: sub clean_symb {
1.731 raeburn 15907: my ($symb,$delete_enc) = @_;
1.685 tempelho 15908:
15909: &Apache::lonenc::check_decrypt(\$symb);
15910: my $enc = $env{'request.enc'};
1.731 raeburn 15911: if ($delete_enc) {
1.730 raeburn 15912: delete($env{'request.enc'});
15913: }
1.685 tempelho 15914:
15915: return ($symb,$enc);
15916: }
1.462 albertel 15917:
1.1075.2.69 raeburn 15918: ############################################################
15919: ############################################################
15920:
15921: =pod
15922:
15923: =head1 Routines for building display used to search for courses
15924:
15925:
15926: =over 4
15927:
15928: =item * &build_filters()
15929:
15930: Create markup for a table used to set filters to use when selecting
15931: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
15932: and quotacheck.pl
15933:
15934:
15935: Inputs:
15936:
15937: filterlist - anonymous array of fields to include as potential filters
15938:
15939: crstype - course type
15940:
15941: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
15942: to pop-open a course selector (will contain "extra element").
15943:
15944: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
15945:
15946: filter - anonymous hash of criteria and their values
15947:
15948: action - form action
15949:
15950: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
15951:
15952: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
15953:
15954: cloneruname - username of owner of new course who wants to clone
15955:
15956: clonerudom - domain of owner of new course who wants to clone
15957:
15958: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
15959:
15960: codetitlesref - reference to array of titles of components in institutional codes (official courses)
15961:
15962: codedom - domain
15963:
15964: formname - value of form element named "form".
15965:
15966: fixeddom - domain, if fixed.
15967:
15968: prevphase - value to assign to form element named "phase" when going back to the previous screen
15969:
15970: cnameelement - name of form element in form on opener page which will receive title of selected course
15971:
15972: cnumelement - name of form element in form on opener page which will receive courseID of selected course
15973:
15974: cdomelement - name of form element in form on opener page which will receive domain of selected course
15975:
15976: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
15977:
15978: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
15979:
15980: clonewarning - warning message about missing information for intended course owner when DC creates a course
15981:
15982:
15983: Returns: $output - HTML for display of search criteria, and hidden form elements.
15984:
15985:
15986: Side Effects: None
15987:
15988: =cut
15989:
15990: # ---------------------------------------------- search for courses based on last activity etc.
15991:
15992: sub build_filters {
15993: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
15994: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
15995: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
15996: $cnameelement,$cnumelement,$cdomelement,$setroles,
15997: $clonetext,$clonewarning) = @_;
15998: my ($list,$jscript);
15999: my $onchange = 'javascript:updateFilters(this)';
16000: my ($domainselectform,$sincefilterform,$createdfilterform,
16001: $ownerdomselectform,$persondomselectform,$instcodeform,
16002: $typeselectform,$instcodetitle);
16003: if ($formname eq '') {
16004: $formname = $caller;
16005: }
16006: foreach my $item (@{$filterlist}) {
16007: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16008: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16009: if ($item eq 'domainfilter') {
16010: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16011: } elsif ($item eq 'coursefilter') {
16012: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16013: } elsif ($item eq 'ownerfilter') {
16014: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16015: } elsif ($item eq 'ownerdomfilter') {
16016: $filter->{'ownerdomfilter'} =
16017: &LONCAPA::clean_domain($filter->{$item});
16018: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16019: 'ownerdomfilter',1);
16020: } elsif ($item eq 'personfilter') {
16021: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16022: } elsif ($item eq 'persondomfilter') {
16023: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16024: 'persondomfilter',1);
16025: } else {
16026: $filter->{$item} =~ s/\W//g;
16027: }
16028: if (!$filter->{$item}) {
16029: $filter->{$item} = '';
16030: }
16031: }
16032: if ($item eq 'domainfilter') {
16033: my $allow_blank = 1;
16034: if ($formname eq 'portform') {
16035: $allow_blank=0;
16036: } elsif ($formname eq 'studentform') {
16037: $allow_blank=0;
16038: }
16039: if ($fixeddom) {
16040: $domainselectform = '<input type="hidden" name="domainfilter"'.
16041: ' value="'.$codedom.'" />'.
16042: &Apache::lonnet::domain($codedom,'description');
16043: } else {
16044: $domainselectform = &select_dom_form($filter->{$item},
16045: 'domainfilter',
16046: $allow_blank,'',$onchange);
16047: }
16048: } else {
16049: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16050: }
16051: }
16052:
16053: # last course activity filter and selection
16054: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16055:
16056: # course created filter and selection
16057: if (exists($filter->{'createdfilter'})) {
16058: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16059: }
16060:
16061: my %lt = &Apache::lonlocal::texthash(
16062: 'cac' => "$crstype Activity",
16063: 'ccr' => "$crstype Created",
16064: 'cde' => "$crstype Title",
16065: 'cdo' => "$crstype Domain",
16066: 'ins' => 'Institutional Code',
16067: 'inc' => 'Institutional Categorization',
16068: 'cow' => "$crstype Owner/Co-owner",
16069: 'cop' => "$crstype Personnel Includes",
16070: 'cog' => 'Type',
16071: );
16072:
16073: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16074: my $typeval = 'Course';
16075: if ($crstype eq 'Community') {
16076: $typeval = 'Community';
16077: }
16078: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16079: } else {
16080: $typeselectform = '<select name="type" size="1"';
16081: if ($onchange) {
16082: $typeselectform .= ' onchange="'.$onchange.'"';
16083: }
16084: $typeselectform .= '>'."\n";
16085: foreach my $posstype ('Course','Community') {
16086: $typeselectform.='<option value="'.$posstype.'"'.
16087: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
16088: }
16089: $typeselectform.="</select>";
16090: }
16091:
16092: my ($cloneableonlyform,$cloneabletitle);
16093: if (exists($filter->{'cloneableonly'})) {
16094: my $cloneableon = '';
16095: my $cloneableoff = ' checked="checked"';
16096: if ($filter->{'cloneableonly'}) {
16097: $cloneableon = $cloneableoff;
16098: $cloneableoff = '';
16099: }
16100: $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>';
16101: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 16102: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 16103: } else {
16104: $cloneabletitle = &mt('Cloneable by you');
16105: }
16106: }
16107: my $officialjs;
16108: if ($crstype eq 'Course') {
16109: if (exists($filter->{'instcodefilter'})) {
16110: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16111: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16112: if ($codedom) {
16113: $officialjs = 1;
16114: ($instcodeform,$jscript,$$numtitlesref) =
16115: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16116: $officialjs,$codetitlesref);
16117: if ($jscript) {
16118: $jscript = '<script type="text/javascript">'."\n".
16119: '// <![CDATA['."\n".
16120: $jscript."\n".
16121: '// ]]>'."\n".
16122: '</script>'."\n";
16123: }
16124: }
16125: if ($instcodeform eq '') {
16126: $instcodeform =
16127: '<input type="text" name="instcodefilter" size="10" value="'.
16128: $list->{'instcodefilter'}.'" />';
16129: $instcodetitle = $lt{'ins'};
16130: } else {
16131: $instcodetitle = $lt{'inc'};
16132: }
16133: if ($fixeddom) {
16134: $instcodetitle .= '<br />('.$codedom.')';
16135: }
16136: }
16137: }
16138: my $output = qq|
16139: <form method="post" name="filterpicker" action="$action">
16140: <input type="hidden" name="form" value="$formname" />
16141: |;
16142: if ($formname eq 'modifycourse') {
16143: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16144: '<input type="hidden" name="prevphase" value="'.
16145: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 16146: } elsif ($formname eq 'quotacheck') {
16147: $output .= qq|
16148: <input type="hidden" name="sortby" value="" />
16149: <input type="hidden" name="sortorder" value="" />
16150: |;
16151: } else {
1.1075.2.69 raeburn 16152: my $name_input;
16153: if ($cnameelement ne '') {
16154: $name_input = '<input type="hidden" name="cnameelement" value="'.
16155: $cnameelement.'" />';
16156: }
16157: $output .= qq|
16158: <input type="hidden" name="cnumelement" value="$cnumelement" />
16159: <input type="hidden" name="cdomelement" value="$cdomelement" />
16160: $name_input
16161: $roleelement
16162: $multelement
16163: $typeelement
16164: |;
16165: if ($formname eq 'portform') {
16166: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16167: }
16168: }
16169: if ($fixeddom) {
16170: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16171: }
16172: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16173: if ($sincefilterform) {
16174: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16175: .$sincefilterform
16176: .&Apache::lonhtmlcommon::row_closure();
16177: }
16178: if ($createdfilterform) {
16179: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16180: .$createdfilterform
16181: .&Apache::lonhtmlcommon::row_closure();
16182: }
16183: if ($domainselectform) {
16184: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16185: .$domainselectform
16186: .&Apache::lonhtmlcommon::row_closure();
16187: }
16188: if ($typeselectform) {
16189: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16190: $output .= $typeselectform;
16191: } else {
16192: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16193: .$typeselectform
16194: .&Apache::lonhtmlcommon::row_closure();
16195: }
16196: }
16197: if ($instcodeform) {
16198: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16199: .$instcodeform
16200: .&Apache::lonhtmlcommon::row_closure();
16201: }
16202: if (exists($filter->{'ownerfilter'})) {
16203: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16204: '<table><tr><td>'.&mt('Username').'<br />'.
16205: '<input type="text" name="ownerfilter" size="20" value="'.
16206: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16207: $ownerdomselectform.'</td></tr></table>'.
16208: &Apache::lonhtmlcommon::row_closure();
16209: }
16210: if (exists($filter->{'personfilter'})) {
16211: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16212: '<table><tr><td>'.&mt('Username').'<br />'.
16213: '<input type="text" name="personfilter" size="20" value="'.
16214: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16215: $persondomselectform.'</td></tr></table>'.
16216: &Apache::lonhtmlcommon::row_closure();
16217: }
16218: if (exists($filter->{'coursefilter'})) {
16219: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16220: .'<input type="text" name="coursefilter" size="25" value="'
16221: .$list->{'coursefilter'}.'" />'
16222: .&Apache::lonhtmlcommon::row_closure();
16223: }
16224: if ($cloneableonlyform) {
16225: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16226: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16227: }
16228: if (exists($filter->{'descriptfilter'})) {
16229: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16230: .'<input type="text" name="descriptfilter" size="40" value="'
16231: .$list->{'descriptfilter'}.'" />'
16232: .&Apache::lonhtmlcommon::row_closure(1);
16233: }
16234: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16235: '<input type="hidden" name="updater" value="" />'."\n".
16236: '<input type="submit" name="gosearch" value="'.
16237: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16238: return $jscript.$clonewarning.$output;
16239: }
16240:
16241: =pod
16242:
16243: =item * &timebased_select_form()
16244:
16245: Create markup for a dropdown list used to select a time-based
16246: filter e.g., Course Activity, Course Created, when searching for courses
16247: or communities
16248:
16249: Inputs:
16250:
16251: item - name of form element (sincefilter or createdfilter)
16252:
16253: filter - anonymous hash of criteria and their values
16254:
16255: Returns: HTML for a select box contained a blank, then six time selections,
16256: with value set in incoming form variables currently selected.
16257:
16258: Side Effects: None
16259:
16260: =cut
16261:
16262: sub timebased_select_form {
16263: my ($item,$filter) = @_;
16264: if (ref($filter) eq 'HASH') {
16265: $filter->{$item} =~ s/[^\d-]//g;
16266: if (!$filter->{$item}) { $filter->{$item}=-1; }
16267: return &select_form(
16268: $filter->{$item},
16269: $item,
16270: { '-1' => '',
16271: '86400' => &mt('today'),
16272: '604800' => &mt('last week'),
16273: '2592000' => &mt('last month'),
16274: '7776000' => &mt('last three months'),
16275: '15552000' => &mt('last six months'),
16276: '31104000' => &mt('last year'),
16277: 'select_form_order' =>
16278: ['-1','86400','604800','2592000','7776000',
16279: '15552000','31104000']});
16280: }
16281: }
16282:
16283: =pod
16284:
16285: =item * &js_changer()
16286:
16287: Create script tag containing Javascript used to submit course search form
16288: when course type or domain is changed, and also to hide 'Searching ...' on
16289: page load completion for page showing search result.
16290:
16291: Inputs: None
16292:
16293: Returns: markup containing updateFilters() and hideSearching() javascript functions.
16294:
16295: Side Effects: None
16296:
16297: =cut
16298:
16299: sub js_changer {
16300: return <<ENDJS;
16301: <script type="text/javascript">
16302: // <![CDATA[
16303: function updateFilters(caller) {
16304: if (typeof(caller) != "undefined") {
16305: document.filterpicker.updater.value = caller.name;
16306: }
16307: document.filterpicker.submit();
16308: }
16309:
16310: function hideSearching() {
16311: if (document.getElementById('searching')) {
16312: document.getElementById('searching').style.display = 'none';
16313: }
16314: return;
16315: }
16316:
16317: // ]]>
16318: </script>
16319:
16320: ENDJS
16321: }
16322:
16323: =pod
16324:
16325: =item * &search_courses()
16326:
16327: Process selected filters form course search form and pass to lonnet::courseiddump
16328: to retrieve a hash for which keys are courseIDs which match the selected filters.
16329:
16330: Inputs:
16331:
16332: dom - domain being searched
16333:
16334: type - course type ('Course' or 'Community' or '.' if any).
16335:
16336: filter - anonymous hash of criteria and their values
16337:
16338: numtitles - for institutional codes - number of categories
16339:
16340: cloneruname - optional username of new course owner
16341:
16342: clonerudom - optional domain of new course owner
16343:
1.1075.2.95 raeburn 16344: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 16345: (used when DC is using course creation form)
16346:
16347: codetitles - reference to array of titles of components in institutional codes (official courses).
16348:
1.1075.2.95 raeburn 16349: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16350: (and so can clone automatically)
16351:
16352: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16353:
16354: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16355: courses to clone
1.1075.2.69 raeburn 16356:
16357: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16358:
16359:
16360: Side Effects: None
16361:
16362: =cut
16363:
16364:
16365: sub search_courses {
1.1075.2.95 raeburn 16366: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16367: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 16368: my (%courses,%showcourses,$cloner);
16369: if (($filter->{'ownerfilter'} ne '') ||
16370: ($filter->{'ownerdomfilter'} ne '')) {
16371: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16372: $filter->{'ownerdomfilter'};
16373: }
16374: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16375: if (!$filter->{$item}) {
16376: $filter->{$item}='.';
16377: }
16378: }
16379: my $now = time;
16380: my $timefilter =
16381: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16382: my ($createdbefore,$createdafter);
16383: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16384: $createdbefore = $now;
16385: $createdafter = $now-$filter->{'createdfilter'};
16386: }
16387: my ($instcodefilter,$regexpok);
16388: if ($numtitles) {
16389: if ($env{'form.official'} eq 'on') {
16390: $instcodefilter =
16391: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16392: $regexpok = 1;
16393: } elsif ($env{'form.official'} eq 'off') {
16394: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16395: unless ($instcodefilter eq '') {
16396: $regexpok = -1;
16397: }
16398: }
16399: } else {
16400: $instcodefilter = $filter->{'instcodefilter'};
16401: }
16402: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16403: if ($type eq '') { $type = '.'; }
16404:
16405: if (($clonerudom ne '') && ($cloneruname ne '')) {
16406: $cloner = $cloneruname.':'.$clonerudom;
16407: }
16408: %courses = &Apache::lonnet::courseiddump($dom,
16409: $filter->{'descriptfilter'},
16410: $timefilter,
16411: $instcodefilter,
16412: $filter->{'combownerfilter'},
16413: $filter->{'coursefilter'},
16414: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 16415: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 16416: $filter->{'cloneableonly'},
16417: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 16418: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 16419: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16420: my $ccrole;
16421: if ($type eq 'Community') {
16422: $ccrole = 'co';
16423: } else {
16424: $ccrole = 'cc';
16425: }
16426: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16427: $filter->{'persondomfilter'},
16428: 'userroles',undef,
16429: [$ccrole,'in','ad','ep','ta','cr'],
16430: $dom);
16431: foreach my $role (keys(%rolehash)) {
16432: my ($cnum,$cdom,$courserole) = split(':',$role);
16433: my $cid = $cdom.'_'.$cnum;
16434: if (exists($courses{$cid})) {
16435: if (ref($courses{$cid}) eq 'HASH') {
16436: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16437: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 16438: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 16439: }
16440: } else {
16441: $courses{$cid}{roles} = [$courserole];
16442: }
16443: $showcourses{$cid} = $courses{$cid};
16444: }
16445: }
16446: }
16447: %courses = %showcourses;
16448: }
16449: return %courses;
16450: }
16451:
16452: =pod
16453:
16454: =back
16455:
1.1075.2.88 raeburn 16456: =head1 Routines for version requirements for current course.
16457:
16458: =over 4
16459:
16460: =item * &check_release_required()
16461:
16462: Compares required LON-CAPA version with version on server, and
16463: if required version is newer looks for a server with the required version.
16464:
16465: Looks first at servers in user's owen domain; if none suitable, looks at
16466: servers in course's domain are permitted to host sessions for user's domain.
16467:
16468: Inputs:
16469:
16470: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16471:
16472: $courseid - Course ID of current course
16473:
16474: $rolecode - User's current role in course (for switchserver query string).
16475:
16476: $required - LON-CAPA version needed by course (format: Major.Minor).
16477:
16478:
16479: Returns:
16480:
16481: $switchserver - query string tp append to /adm/switchserver call (if
16482: current server's LON-CAPA version is too old.
16483:
16484: $warning - Message is displayed if no suitable server could be found.
16485:
16486: =cut
16487:
16488: sub check_release_required {
16489: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16490: my ($switchserver,$warning);
16491: if ($required ne '') {
16492: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16493: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16494: if ($reqdmajor ne '' && $reqdminor ne '') {
16495: my $otherserver;
16496: if (($major eq '' && $minor eq '') ||
16497: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16498: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16499: my $switchlcrev =
16500: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16501: $userdomserver);
16502: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16503: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16504: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16505: my $cdom = $env{'course.'.$courseid.'.domain'};
16506: if ($cdom ne $env{'user.domain'}) {
16507: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16508: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16509: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16510: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16511: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16512: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16513: my $canhost =
16514: &Apache::lonnet::can_host_session($env{'user.domain'},
16515: $coursedomserver,
16516: $remoterev,
16517: $udomdefaults{'remotesessions'},
16518: $defdomdefaults{'hostedsessions'});
16519:
16520: if ($canhost) {
16521: $otherserver = $coursedomserver;
16522: } else {
16523: $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.");
16524: }
16525: } else {
16526: $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).");
16527: }
16528: } else {
16529: $otherserver = $userdomserver;
16530: }
16531: }
16532: if ($otherserver ne '') {
16533: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16534: }
16535: }
16536: }
16537: return ($switchserver,$warning);
16538: }
16539:
16540: =pod
16541:
16542: =item * &check_release_result()
16543:
16544: Inputs:
16545:
16546: $switchwarning - Warning message if no suitable server found to host session.
16547:
16548: $switchserver - query string to append to /adm/switchserver containing lonHostID
16549: and current role.
16550:
16551: Returns: HTML to display with information about requirement to switch server.
16552: Either displaying warning with link to Roles/Courses screen or
16553: display link to switchserver.
16554:
1.1075.2.69 raeburn 16555: =cut
16556:
1.1075.2.88 raeburn 16557: sub check_release_result {
16558: my ($switchwarning,$switchserver) = @_;
16559: my $output = &start_page('Selected course unavailable on this server').
16560: '<p class="LC_warning">';
16561: if ($switchwarning) {
16562: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16563: if (&show_course()) {
16564: $output .= &mt('Display courses');
16565: } else {
16566: $output .= &mt('Display roles');
16567: }
16568: $output .= '</a>';
16569: } elsif ($switchserver) {
16570: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16571: '<br />'.
16572: '<a href="/adm/switchserver?'.$switchserver.'">'.
16573: &mt('Switch Server').
16574: '</a>';
16575: }
16576: $output .= '</p>'.&end_page();
16577: return $output;
16578: }
16579:
16580: =pod
16581:
16582: =item * &needs_coursereinit()
16583:
16584: Determine if course contents stored for user's session needs to be
16585: refreshed, because content has changed since "Big Hash" last tied.
16586:
16587: Check for change is made if time last checked is more than 10 minutes ago
16588: (by default).
16589:
16590: Inputs:
16591:
16592: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16593:
16594: $interval (optional) - Time which may elapse (in s) between last check for content
16595: change in current course. (default: 600 s).
16596:
16597: Returns: an array; first element is:
16598:
16599: =over 4
16600:
16601: 'switch' - if content updates mean user's session
16602: needs to be switched to a server running a newer LON-CAPA version
16603:
16604: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16605: on current server hosting user's session
16606:
16607: '' - if no action required.
16608:
16609: =back
16610:
16611: If first item element is 'switch':
16612:
16613: second item is $switchwarning - Warning message if no suitable server found to host session.
16614:
16615: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16616: and current role.
16617:
16618: otherwise: no other elements returned.
16619:
16620: =back
16621:
16622: =cut
16623:
16624: sub needs_coursereinit {
16625: my ($loncaparev,$interval) = @_;
16626: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16627: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16628: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16629: my $now = time;
16630: if ($interval eq '') {
16631: $interval = 600;
16632: }
16633: if (($now-$env{'request.course.timechecked'})>$interval) {
16634: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16635: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16636: if ($lastchange > $env{'request.course.tied'}) {
16637: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16638: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16639: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16640: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16641: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16642: $curr_reqd_hash{'internal.releaserequired'}});
16643: my ($switchserver,$switchwarning) =
16644: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16645: $curr_reqd_hash{'internal.releaserequired'});
16646: if ($switchwarning ne '' || $switchserver ne '') {
16647: return ('switch',$switchwarning,$switchserver);
16648: }
16649: }
16650: }
16651: return ('update');
16652: }
16653: }
16654: return ();
16655: }
1.1075.2.69 raeburn 16656:
1.1075.2.11 raeburn 16657: sub update_content_constraints {
16658: my ($cdom,$cnum,$chome,$cid) = @_;
16659: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16660: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16661: my %checkresponsetypes;
16662: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
16663: my ($item,$name,$value) = split(/:/,$key);
16664: if ($item eq 'resourcetag') {
16665: if ($name eq 'responsetype') {
16666: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
16667: }
16668: }
16669: }
16670: my $navmap = Apache::lonnavmaps::navmap->new();
16671: if (defined($navmap)) {
16672: my %allresponses;
16673: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
16674: my %responses = $res->responseTypes();
16675: foreach my $key (keys(%responses)) {
16676: next unless(exists($checkresponsetypes{$key}));
16677: $allresponses{$key} += $responses{$key};
16678: }
16679: }
16680: foreach my $key (keys(%allresponses)) {
16681: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
16682: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
16683: ($reqdmajor,$reqdminor) = ($major,$minor);
16684: }
16685: }
16686: undef($navmap);
16687: }
16688: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
16689: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
16690: }
16691: return;
16692: }
16693:
1.1075.2.27 raeburn 16694: sub allmaps_incourse {
16695: my ($cdom,$cnum,$chome,$cid) = @_;
16696: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
16697: $cid = $env{'request.course.id'};
16698: $cdom = $env{'course.'.$cid.'.domain'};
16699: $cnum = $env{'course.'.$cid.'.num'};
16700: $chome = $env{'course.'.$cid.'.home'};
16701: }
16702: my %allmaps = ();
16703: my $lastchange =
16704: &Apache::lonnet::get_coursechange($cdom,$cnum);
16705: if ($lastchange > $env{'request.course.tied'}) {
16706: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
16707: unless ($ferr) {
16708: &update_content_constraints($cdom,$cnum,$chome,$cid);
16709: }
16710: }
16711: my $navmap = Apache::lonnavmaps::navmap->new();
16712: if (defined($navmap)) {
16713: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
16714: $allmaps{$res->src()} = 1;
16715: }
16716: }
16717: return \%allmaps;
16718: }
16719:
1.1075.2.11 raeburn 16720: sub parse_supplemental_title {
16721: my ($title) = @_;
16722:
16723: my ($foldertitle,$renametitle);
16724: if ($title =~ /&&&/) {
16725: $title = &HTML::Entites::decode($title);
16726: }
16727: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
16728: $renametitle=$4;
16729: my ($time,$uname,$udom) = ($1,$2,$3);
16730: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
16731: my $name = &plainname($uname,$udom);
16732: $name = &HTML::Entities::encode($name,'"<>&\'');
16733: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
16734: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
16735: $name.': <br />'.$foldertitle;
16736: }
16737: if (wantarray) {
16738: return ($title,$foldertitle,$renametitle);
16739: }
16740: return $title;
16741: }
16742:
1.1075.2.43 raeburn 16743: sub recurse_supplemental {
16744: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
16745: if ($suppmap) {
16746: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16747: if ($fatal) {
16748: $errors ++;
16749: } else {
16750: if ($#LONCAPA::map::resources > 0) {
16751: foreach my $res (@LONCAPA::map::resources) {
16752: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16753: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 16754: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16755: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 16756: } else {
16757: $numfiles ++;
16758: }
16759: }
16760: }
16761: }
16762: }
16763: }
16764: return ($numfiles,$errors);
16765: }
16766:
1.1075.2.18 raeburn 16767: sub symb_to_docspath {
1.1075.2.119 raeburn 16768: my ($symb,$navmapref) = @_;
16769: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 16770: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
16771: if ($resurl=~/\.(sequence|page)$/) {
16772: $mapurl=$resurl;
16773: } elsif ($resurl eq 'adm/navmaps') {
16774: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
16775: }
16776: my $mapresobj;
1.1075.2.119 raeburn 16777: unless (ref($$navmapref)) {
16778: $$navmapref = Apache::lonnavmaps::navmap->new();
16779: }
16780: if (ref($$navmapref)) {
16781: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 16782: }
16783: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
16784: my $type=$2;
16785: my $path;
16786: if (ref($mapresobj)) {
16787: my $pcslist = $mapresobj->map_hierarchy();
16788: if ($pcslist ne '') {
16789: foreach my $pc (split(/,/,$pcslist)) {
16790: next if ($pc <= 1);
1.1075.2.119 raeburn 16791: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 16792: if (ref($res)) {
16793: my $thisurl = $res->src();
16794: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
16795: my $thistitle = $res->title();
16796: $path .= '&'.
16797: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 16798: &escape($thistitle).
1.1075.2.18 raeburn 16799: ':'.$res->randompick().
16800: ':'.$res->randomout().
16801: ':'.$res->encrypted().
16802: ':'.$res->randomorder().
16803: ':'.$res->is_page();
16804: }
16805: }
16806: }
16807: $path =~ s/^\&//;
16808: my $maptitle = $mapresobj->title();
16809: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16810: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16811: }
16812: $path .= (($path ne '')? '&' : '').
16813: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16814: &escape($maptitle).
1.1075.2.18 raeburn 16815: ':'.$mapresobj->randompick().
16816: ':'.$mapresobj->randomout().
16817: ':'.$mapresobj->encrypted().
16818: ':'.$mapresobj->randomorder().
16819: ':'.$mapresobj->is_page();
16820: } else {
16821: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16822: my $ispage = (($type eq 'page')? 1 : '');
16823: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16824: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16825: }
16826: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16827: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 16828: }
16829: unless ($mapurl eq 'default') {
16830: $path = 'default&'.
1.1075.2.46 raeburn 16831: &escape('Main Content').
1.1075.2.18 raeburn 16832: ':::::&'.$path;
16833: }
16834: return $path;
16835: }
16836:
1.1075.2.14 raeburn 16837: sub captcha_display {
1.1075.2.137 raeburn 16838: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 16839: my ($output,$error);
1.1075.2.107 raeburn 16840: my ($captcha,$pubkey,$privkey,$version) =
1.1075.2.137 raeburn 16841: &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 16842: if ($captcha eq 'original') {
16843: $output = &create_captcha();
16844: unless ($output) {
16845: $error = 'captcha';
16846: }
16847: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16848: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 16849: unless ($output) {
16850: $error = 'recaptcha';
16851: }
16852: }
1.1075.2.107 raeburn 16853: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 16854: }
16855:
16856: sub captcha_response {
1.1075.2.137 raeburn 16857: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 16858: my ($captcha_chk,$captcha_error);
1.1075.2.137 raeburn 16859: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 16860: if ($captcha eq 'original') {
16861: ($captcha_chk,$captcha_error) = &check_captcha();
16862: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16863: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 16864: } else {
16865: $captcha_chk = 1;
16866: }
16867: return ($captcha_chk,$captcha_error);
16868: }
16869:
16870: sub get_captcha_config {
1.1075.2.137 raeburn 16871: my ($context,$lonhost,$dom_in_effect) = @_;
1.1075.2.107 raeburn 16872: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 16873: my $hostname = &Apache::lonnet::hostname($lonhost);
16874: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
16875: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16876: if ($context eq 'usercreation') {
16877: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
16878: if (ref($domconfig{$context}) eq 'HASH') {
16879: $hashtocheck = $domconfig{$context}{'cancreate'};
16880: if (ref($hashtocheck) eq 'HASH') {
16881: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
16882: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
16883: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
16884: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
16885: }
16886: if ($privkey && $pubkey) {
16887: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16888: $version = $hashtocheck->{'recaptchaversion'};
16889: if ($version ne '2') {
16890: $version = 1;
16891: }
1.1075.2.14 raeburn 16892: } else {
16893: $captcha = 'original';
16894: }
16895: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
16896: $captcha = 'original';
16897: }
16898: }
16899: } else {
16900: $captcha = 'captcha';
16901: }
16902: } elsif ($context eq 'login') {
16903: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
16904: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
16905: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
16906: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
16907: if ($privkey && $pubkey) {
16908: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16909: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
16910: if ($version ne '2') {
16911: $version = 1;
16912: }
1.1075.2.14 raeburn 16913: } else {
16914: $captcha = 'original';
16915: }
16916: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
16917: $captcha = 'original';
16918: }
1.1075.2.137 raeburn 16919: } elsif ($context eq 'passwords') {
16920: if ($dom_in_effect) {
16921: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
16922: if ($passwdconf{'captcha'} eq 'recaptcha') {
16923: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
16924: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
16925: $privkey = $passwdconf{'recaptchakeys'}{'private'};
16926: }
16927: if ($privkey && $pubkey) {
16928: $captcha = 'recaptcha';
16929: $version = $passwdconf{'recaptchaversion'};
16930: if ($version ne '2') {
16931: $version = 1;
16932: }
16933: } else {
16934: $captcha = 'original';
16935: }
16936: } elsif ($passwdconf{'captcha'} ne 'notused') {
16937: $captcha = 'original';
16938: }
16939: }
1.1075.2.14 raeburn 16940: }
1.1075.2.107 raeburn 16941: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 16942: }
16943:
16944: sub create_captcha {
16945: my %captcha_params = &captcha_settings();
16946: my ($output,$maxtries,$tries) = ('',10,0);
16947: while ($tries < $maxtries) {
16948: $tries ++;
16949: my $captcha = Authen::Captcha->new (
16950: output_folder => $captcha_params{'output_dir'},
16951: data_folder => $captcha_params{'db_dir'},
16952: );
16953: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
16954:
16955: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
16956: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
16957: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 16958: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
16959: '<br />'.
16960: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 16961: last;
16962: }
16963: }
16964: return $output;
16965: }
16966:
16967: sub captcha_settings {
16968: my %captcha_params = (
16969: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
16970: www_output_dir => "/captchaspool",
16971: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
16972: numchars => '5',
16973: );
16974: return %captcha_params;
16975: }
16976:
16977: sub check_captcha {
16978: my ($captcha_chk,$captcha_error);
16979: my $code = $env{'form.code'};
16980: my $md5sum = $env{'form.crypt'};
16981: my %captcha_params = &captcha_settings();
16982: my $captcha = Authen::Captcha->new(
16983: output_folder => $captcha_params{'output_dir'},
16984: data_folder => $captcha_params{'db_dir'},
16985: );
1.1075.2.26 raeburn 16986: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 16987: my %captcha_hash = (
16988: 0 => 'Code not checked (file error)',
16989: -1 => 'Failed: code expired',
16990: -2 => 'Failed: invalid code (not in database)',
16991: -3 => 'Failed: invalid code (code does not match crypt)',
16992: );
16993: if ($captcha_chk != 1) {
16994: $captcha_error = $captcha_hash{$captcha_chk}
16995: }
16996: return ($captcha_chk,$captcha_error);
16997: }
16998:
16999: sub create_recaptcha {
1.1075.2.107 raeburn 17000: my ($pubkey,$version) = @_;
17001: if ($version >= 2) {
17002: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17003: } else {
17004: my $use_ssl;
17005: if ($ENV{'SERVER_PORT'} == 443) {
17006: $use_ssl = 1;
17007: }
17008: my $captcha = Captcha::reCAPTCHA->new;
17009: return $captcha->get_options_setter({theme => 'white'})."\n".
17010: $captcha->get_html($pubkey,undef,$use_ssl).
17011: &mt('If the text is hard to read, [_1] will replace them.',
17012: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17013: '<br /><br />';
17014: }
1.1075.2.14 raeburn 17015: }
17016:
17017: sub check_recaptcha {
1.1075.2.107 raeburn 17018: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 17019: my $captcha_chk;
1.1075.2.107 raeburn 17020: if ($version >= 2) {
17021: my $ua = LWP::UserAgent->new;
17022: $ua->timeout(10);
17023: my %info = (
17024: secret => $privkey,
17025: response => $env{'form.g-recaptcha-response'},
17026: remoteip => $ENV{'REMOTE_ADDR'},
17027: );
17028: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
17029: if ($response->is_success) {
17030: my $data = JSON::DWIW->from_json($response->decoded_content);
17031: if (ref($data) eq 'HASH') {
17032: if ($data->{'success'}) {
17033: $captcha_chk = 1;
17034: }
17035: }
17036: }
17037: } else {
17038: my $captcha = Captcha::reCAPTCHA->new;
17039: my $captcha_result =
17040: $captcha->check_answer(
17041: $privkey,
17042: $ENV{'REMOTE_ADDR'},
17043: $env{'form.recaptcha_challenge_field'},
17044: $env{'form.recaptcha_response_field'},
17045: );
17046: if ($captcha_result->{is_valid}) {
17047: $captcha_chk = 1;
17048: }
1.1075.2.14 raeburn 17049: }
17050: return $captcha_chk;
17051: }
17052:
1.1075.2.64 raeburn 17053: sub emailusername_info {
1.1075.2.103 raeburn 17054: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 17055: my %titles = &Apache::lonlocal::texthash (
17056: lastname => 'Last Name',
17057: firstname => 'First Name',
17058: institution => 'School/college/university',
17059: location => "School's city, state/province, country",
17060: web => "School's web address",
17061: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 17062: id => 'Student/Employee ID',
1.1075.2.64 raeburn 17063: );
17064: return (\@fields,\%titles);
17065: }
17066:
1.1075.2.56 raeburn 17067: sub cleanup_html {
17068: my ($incoming) = @_;
17069: my $outgoing;
17070: if ($incoming ne '') {
17071: $outgoing = $incoming;
17072: $outgoing =~ s/;/;/g;
17073: $outgoing =~ s/\#/#/g;
17074: $outgoing =~ s/\&/&/g;
17075: $outgoing =~ s/</</g;
17076: $outgoing =~ s/>/>/g;
17077: $outgoing =~ s/\(/(/g;
17078: $outgoing =~ s/\)/)/g;
17079: $outgoing =~ s/"/"/g;
17080: $outgoing =~ s/'/'/g;
17081: $outgoing =~ s/\$/$/g;
17082: $outgoing =~ s{/}{/}g;
17083: $outgoing =~ s/=/=/g;
17084: $outgoing =~ s/\\/\/g
17085: }
17086: return $outgoing;
17087: }
17088:
1.1075.2.74 raeburn 17089: # Checks for critical messages and returns a redirect url if one exists.
17090: # $interval indicates how often to check for messages.
17091: sub critical_redirect {
17092: my ($interval) = @_;
17093: if ((time-$env{'user.criticalcheck.time'})>$interval) {
17094: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17095: $env{'user.name'});
17096: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
17097: my $redirecturl;
17098: if ($what[0]) {
17099: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17100: $redirecturl='/adm/email?critical=display';
17101: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17102: return (1, $url);
17103: }
17104: }
17105: }
17106: return ();
17107: }
17108:
1.1075.2.64 raeburn 17109: # Use:
17110: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17111: #
17112: ##################################################
17113: # password associated functions #
17114: ##################################################
17115: sub des_keys {
17116: # Make a new key for DES encryption.
17117: # Each key has two parts which are returned separately.
17118: # Please note: Each key must be passed through the &hex function
17119: # before it is output to the web browser. The hex versions cannot
17120: # be used to decrypt.
17121: my @hexstr=('0','1','2','3','4','5','6','7',
17122: '8','9','a','b','c','d','e','f');
17123: my $lkey='';
17124: for (0..7) {
17125: $lkey.=$hexstr[rand(15)];
17126: }
17127: my $ukey='';
17128: for (0..7) {
17129: $ukey.=$hexstr[rand(15)];
17130: }
17131: return ($lkey,$ukey);
17132: }
17133:
17134: sub des_decrypt {
17135: my ($key,$cyphertext) = @_;
17136: my $keybin=pack("H16",$key);
17137: my $cypher;
17138: if ($Crypt::DES::VERSION>=2.03) {
17139: $cypher=new Crypt::DES $keybin;
17140: } else {
17141: $cypher=new DES $keybin;
17142: }
1.1075.2.106 raeburn 17143: my $plaintext='';
17144: my $cypherlength = length($cyphertext);
17145: my $numchunks = int($cypherlength/32);
17146: for (my $j=0; $j<$numchunks; $j++) {
17147: my $start = $j*32;
17148: my $cypherblock = substr($cyphertext,$start,32);
17149: my $chunk =
17150: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17151: $chunk .=
17152: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17153: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17154: $plaintext .= $chunk;
17155: }
1.1075.2.64 raeburn 17156: return $plaintext;
17157: }
17158:
1.1075.2.135 raeburn 17159: sub is_nonframeable {
17160: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
17161: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
17162: return if (($remprotocol eq '') || ($remhost eq ''));
17163:
17164: $remprotocol = lc($remprotocol);
17165: $remhost = lc($remhost);
17166: my $remport = 80;
17167: if ($remprotocol eq 'https') {
17168: $remport = 443;
17169: }
17170: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
17171: if ($cached) {
17172: unless ($nocache) {
17173: if ($result) {
17174: return 1;
17175: } else {
17176: return 0;
17177: }
17178: }
17179: }
17180: my $uselink;
17181: my $request = new HTTP::Request('HEAD',$url);
17182: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
17183: if ($response->is_success()) {
17184: my $secpolicy = lc($response->header('content-security-policy'));
17185: my $xframeop = lc($response->header('x-frame-options'));
17186: $secpolicy =~ s/^\s+|\s+$//g;
17187: $xframeop =~ s/^\s+|\s+$//g;
17188: if (($secpolicy ne '') || ($xframeop ne '')) {
17189: my $remotehost = $remprotocol.'://'.$remhost;
17190: my ($origin,$protocol,$port);
17191: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
17192: $port = $ENV{'SERVER_PORT'};
17193: } else {
17194: $port = 80;
17195: }
17196: if ($absolute eq '') {
17197: $protocol = 'http:';
17198: if ($port == 443) {
17199: $protocol = 'https:';
17200: }
17201: $origin = $protocol.'//'.lc($hostname);
17202: } else {
17203: $origin = lc($absolute);
17204: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
17205: }
17206: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
17207: my $framepolicy = $1;
17208: $framepolicy =~ s/^\s+|\s+$//g;
17209: my @policies = split(/\s+/,$framepolicy);
17210: if (@policies) {
17211: if (grep(/^\Q'none'\E$/,@policies)) {
17212: $uselink = 1;
17213: } else {
17214: $uselink = 1;
17215: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
17216: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
17217: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
17218: undef($uselink);
17219: }
17220: if ($uselink) {
17221: if (grep(/^\Q'self'\E$/,@policies)) {
17222: if (($origin ne '') && ($remotehost eq $origin)) {
17223: undef($uselink);
17224: }
17225: }
17226: }
17227: if ($uselink) {
17228: my @possok;
17229: if ($ip ne '') {
17230: push(@possok,$ip);
17231: }
17232: my $hoststr = '';
17233: foreach my $part (reverse(split(/\./,$hostname))) {
17234: if ($hoststr eq '') {
17235: $hoststr = $part;
17236: } else {
17237: $hoststr = "$part.$hoststr";
17238: }
17239: if ($hoststr eq $hostname) {
17240: push(@possok,$hostname);
17241: } else {
17242: push(@possok,"*.$hoststr");
17243: }
17244: }
17245: if (@possok) {
17246: foreach my $poss (@possok) {
17247: last if (!$uselink);
17248: foreach my $policy (@policies) {
17249: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
17250: undef($uselink);
17251: last;
17252: }
17253: }
17254: }
17255: }
17256: }
17257: }
17258: }
17259: } elsif ($xframeop ne '') {
17260: $uselink = 1;
17261: my @policies = split(/\s*,\s*/,$xframeop);
17262: if (@policies) {
17263: unless (grep(/^deny$/,@policies)) {
17264: if ($origin ne '') {
17265: if (grep(/^sameorigin$/,@policies)) {
17266: if ($remotehost eq $origin) {
17267: undef($uselink);
17268: }
17269: }
17270: if ($uselink) {
17271: foreach my $policy (@policies) {
17272: if ($policy =~ /^allow-from\s*(.+)$/) {
17273: my $allowfrom = $1;
17274: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
17275: undef($uselink);
17276: last;
17277: }
17278: }
17279: }
17280: }
17281: }
17282: }
17283: }
17284: }
17285: }
17286: }
17287: if ($nocache) {
17288: if ($cached) {
17289: my $devalidate;
17290: if ($uselink && !$result) {
17291: $devalidate = 1;
17292: } elsif (!$uselink && $result) {
17293: $devalidate = 1;
17294: }
17295: if ($devalidate) {
17296: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
17297: }
17298: }
17299: } else {
17300: if ($uselink) {
17301: $result = 1;
17302: } else {
17303: $result = 0;
17304: }
17305: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
17306: }
17307: return $uselink;
17308: }
17309:
1.112 bowersj2 17310: 1;
17311: __END__;
1.41 ng 17312:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>