Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.64
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.64! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.63 2014/01/03 20:04:35 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.479 albertel 72: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 73: use DateTime::TimeZone;
1.687 raeburn 74: use DateTime::Locale::Catalog;
1.1075.2.14 raeburn 75: use Authen::Captcha;
76: use Captcha::reCAPTCHA;
1.1075.2.64! raeburn 77: use Crypt::DES;
! 78: use DynaLoader; # for Crypt::DES version
1.117 www 79:
1.517 raeburn 80: # ---------------------------------------------- Designs
81: use vars qw(%defaultdesign);
82:
1.22 www 83: my $readit;
84:
1.517 raeburn 85:
1.157 matthew 86: ##
87: ## Global Variables
88: ##
1.46 matthew 89:
1.643 foxr 90:
91: # ----------------------------------------------- SSI with retries:
92: #
93:
94: =pod
95:
1.648 raeburn 96: =head1 Server Side include with retries:
1.643 foxr 97:
98: =over 4
99:
1.648 raeburn 100: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 101:
102: Performs an ssi with some number of retries. Retries continue either
103: until the result is ok or until the retry count supplied by the
104: caller is exhausted.
105:
106: Inputs:
1.648 raeburn 107:
108: =over 4
109:
1.643 foxr 110: resource - Identifies the resource to insert.
1.648 raeburn 111:
1.643 foxr 112: retries - Count of the number of retries allowed.
1.648 raeburn 113:
1.643 foxr 114: form - Hash that identifies the rendering options.
115:
1.648 raeburn 116: =back
117:
118: Returns:
119:
120: =over 4
121:
1.643 foxr 122: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 123:
1.643 foxr 124: response - The response from the last attempt (which may or may not have been successful.
125:
1.648 raeburn 126: =back
127:
128: =back
129:
1.643 foxr 130: =cut
131:
132: sub ssi_with_retries {
133: my ($resource, $retries, %form) = @_;
134:
135:
136: my $ok = 0; # True if we got a good response.
137: my $content;
138: my $response;
139:
140: # Try to get the ssi done. within the retries count:
141:
142: do {
143: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
144: $ok = $response->is_success;
1.650 www 145: if (!$ok) {
146: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
147: }
1.643 foxr 148: $retries--;
149: } while (!$ok && ($retries > 0));
150:
151: if (!$ok) {
152: $content = ''; # On error return an empty content.
153: }
154: return ($content, $response);
155:
156: }
157:
158:
159:
1.20 www 160: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 161: my %language;
1.124 www 162: my %supported_language;
1.1048 foxr 163: my %latex_language; # For choosing hyphenation in <transl..>
164: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 165: my %cprtag;
1.192 taceyjo1 166: my %scprtag;
1.351 www 167: my %fe; my %fd; my %fm;
1.41 ng 168: my %category_extensions;
1.12 harris41 169:
1.46 matthew 170: # ---------------------------------------------- Thesaurus variables
1.144 matthew 171: #
172: # %Keywords:
173: # A hash used by &keyword to determine if a word is considered a keyword.
174: # $thesaurus_db_file
175: # Scalar containing the full path to the thesaurus database.
1.46 matthew 176:
177: my %Keywords;
178: my $thesaurus_db_file;
179:
1.144 matthew 180: #
181: # Initialize values from language.tab, copyright.tab, filetypes.tab,
182: # thesaurus.tab, and filecategories.tab.
183: #
1.18 www 184: BEGIN {
1.46 matthew 185: # Variable initialization
186: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
187: #
1.22 www 188: unless ($readit) {
1.12 harris41 189: # ------------------------------------------------------------------- languages
190: {
1.158 raeburn 191: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
192: '/language.tab';
193: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 194: while (my $line = <$fh>) {
195: next if ($line=~/^\#/);
196: chomp($line);
1.1048 foxr 197: my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 198: $language{$key}=$val.' - '.$enc;
199: if ($sup) {
200: $supported_language{$key}=$sup;
201: }
1.1048 foxr 202: if ($latex) {
203: $latex_language_bykey{$key} = $latex;
204: $latex_language{$two} = $latex;
205: }
1.158 raeburn 206: }
207: close($fh);
208: }
1.12 harris41 209: }
210: # ------------------------------------------------------------------ copyrights
211: {
1.158 raeburn 212: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
213: '/copyright.tab';
214: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 215: while (my $line = <$fh>) {
216: next if ($line=~/^\#/);
217: chomp($line);
218: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 219: $cprtag{$key}=$val;
220: }
221: close($fh);
222: }
1.12 harris41 223: }
1.351 www 224: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 225: {
226: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
227: '/source_copyright.tab';
228: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 229: while (my $line = <$fh>) {
230: next if ($line =~ /^\#/);
231: chomp($line);
232: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 233: $scprtag{$key}=$val;
234: }
235: close($fh);
236: }
237: }
1.63 www 238:
1.517 raeburn 239: # -------------------------------------------------------------- default domain designs
1.63 www 240: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 241: my $designfile = $designdir.'/default.tab';
242: if ( open (my $fh,"<$designfile") ) {
243: while (my $line = <$fh>) {
244: next if ($line =~ /^\#/);
245: chomp($line);
246: my ($key,$val)=(split(/\=/,$line));
247: if ($val) { $defaultdesign{$key}=$val; }
248: }
249: close($fh);
1.63 www 250: }
251:
1.15 harris41 252: # ------------------------------------------------------------- file categories
253: {
1.158 raeburn 254: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
255: '/filecategories.tab';
256: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 257: while (my $line = <$fh>) {
258: next if ($line =~ /^\#/);
259: chomp($line);
260: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 261: push @{$category_extensions{lc($category)}},$extension;
262: }
263: close($fh);
264: }
265:
1.15 harris41 266: }
1.12 harris41 267: # ------------------------------------------------------------------ file types
268: {
1.158 raeburn 269: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
270: '/filetypes.tab';
271: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 272: while (my $line = <$fh>) {
273: next if ($line =~ /^\#/);
274: chomp($line);
275: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 276: if ($descr ne '') {
277: $fe{$ending}=lc($emb);
278: $fd{$ending}=$descr;
1.351 www 279: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 280: }
281: }
282: close($fh);
283: }
1.12 harris41 284: }
1.22 www 285: &Apache::lonnet::logthis(
1.705 tempelho 286: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 287: $readit=1;
1.46 matthew 288: } # end of unless($readit)
1.32 matthew 289:
290: }
1.112 bowersj2 291:
1.42 matthew 292: ###############################################################
293: ## HTML and Javascript Helper Functions ##
294: ###############################################################
295:
296: =pod
297:
1.112 bowersj2 298: =head1 HTML and Javascript Functions
1.42 matthew 299:
1.112 bowersj2 300: =over 4
301:
1.648 raeburn 302: =item * &browser_and_searcher_javascript()
1.112 bowersj2 303:
304: X<browsing, javascript>X<searching, javascript>Returns a string
305: containing javascript with two functions, C<openbrowser> and
306: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
307: tags.
1.42 matthew 308:
1.648 raeburn 309: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 310:
311: inputs: formname, elementname, only, omit
312:
313: formname and elementname indicate the name of the html form and name of
314: the element that the results of the browsing selection are to be placed in.
315:
316: Specifying 'only' will restrict the browser to displaying only files
1.185 www 317: with the given extension. Can be a comma separated list.
1.42 matthew 318:
319: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 320: with the given extension. Can be a comma separated list.
1.42 matthew 321:
1.648 raeburn 322: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 323:
324: Inputs: formname, elementname
325:
326: formname and elementname specify the name of the html form and the name
327: of the element the selection from the search results will be placed in.
1.542 raeburn 328:
1.42 matthew 329: =cut
330:
331: sub browser_and_searcher_javascript {
1.199 albertel 332: my ($mode)=@_;
333: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 334: my $resurl=&escape_single(&lastresurl());
1.42 matthew 335: return <<END;
1.219 albertel 336: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 337: var editbrowser = null;
1.135 albertel 338: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 339: var url = '$resurl/?';
1.42 matthew 340: if (editbrowser == null) {
341: url += 'launch=1&';
342: }
343: url += 'catalogmode=interactive&';
1.199 albertel 344: url += 'mode=$mode&';
1.611 albertel 345: url += 'inhibitmenu=yes&';
1.42 matthew 346: url += 'form=' + formname + '&';
347: if (only != null) {
348: url += 'only=' + only + '&';
1.217 albertel 349: } else {
350: url += 'only=&';
351: }
1.42 matthew 352: if (omit != null) {
353: url += 'omit=' + omit + '&';
1.217 albertel 354: } else {
355: url += 'omit=&';
356: }
1.135 albertel 357: if (titleelement != null) {
358: url += 'titleelement=' + titleelement + '&';
1.217 albertel 359: } else {
360: url += 'titleelement=&';
361: }
1.42 matthew 362: url += 'element=' + elementname + '';
363: var title = 'Browser';
1.435 albertel 364: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 365: options += ',width=700,height=600';
366: editbrowser = open(url,title,options,'1');
367: editbrowser.focus();
368: }
369: var editsearcher;
1.135 albertel 370: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 371: var url = '/adm/searchcat?';
372: if (editsearcher == null) {
373: url += 'launch=1&';
374: }
375: url += 'catalogmode=interactive&';
1.199 albertel 376: url += 'mode=$mode&';
1.42 matthew 377: url += 'form=' + formname + '&';
1.135 albertel 378: if (titleelement != null) {
379: url += 'titleelement=' + titleelement + '&';
1.217 albertel 380: } else {
381: url += 'titleelement=&';
382: }
1.42 matthew 383: url += 'element=' + elementname + '';
384: var title = 'Search';
1.435 albertel 385: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 386: options += ',width=700,height=600';
387: editsearcher = open(url,title,options,'1');
388: editsearcher.focus();
389: }
1.219 albertel 390: // END LON-CAPA Internal -->
1.42 matthew 391: END
1.170 www 392: }
393:
394: sub lastresurl {
1.258 albertel 395: if ($env{'environment.lastresurl'}) {
396: return $env{'environment.lastresurl'}
1.170 www 397: } else {
398: return '/res';
399: }
400: }
401:
402: sub storeresurl {
403: my $resurl=&Apache::lonnet::clutter(shift);
404: unless ($resurl=~/^\/res/) { return 0; }
405: $resurl=~s/\/$//;
406: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 407: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 408: return 1;
1.42 matthew 409: }
410:
1.74 www 411: sub studentbrowser_javascript {
1.111 www 412: unless (
1.258 albertel 413: (($env{'request.course.id'}) &&
1.302 albertel 414: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
415: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
416: '/'.$env{'request.course.sec'})
417: ))
1.258 albertel 418: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 419: ) { return ''; }
1.74 www 420: return (<<'ENDSTDBRW');
1.776 bisitz 421: <script type="text/javascript" language="Javascript">
1.824 bisitz 422: // <![CDATA[
1.74 www 423: var stdeditbrowser;
1.999 www 424: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 425: var url = '/adm/pickstudent?';
426: var filter;
1.558 albertel 427: if (!ignorefilter) {
428: eval('filter=document.'+formname+'.'+uname+'.value;');
429: }
1.74 www 430: if (filter != null) {
431: if (filter != '') {
432: url += 'filter='+filter+'&';
433: }
434: }
435: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 436: '&udomelement='+udom+
437: '&clicker='+clicker;
1.111 www 438: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 439: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 440: var title = 'Student_Browser';
1.74 www 441: var options = 'scrollbars=1,resizable=1,menubar=0';
442: options += ',width=700,height=600';
443: stdeditbrowser = open(url,title,options,'1');
444: stdeditbrowser.focus();
445: }
1.824 bisitz 446: // ]]>
1.74 www 447: </script>
448: ENDSTDBRW
449: }
1.42 matthew 450:
1.1003 www 451: sub resourcebrowser_javascript {
452: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 453: return (<<'ENDRESBRW');
1.1003 www 454: <script type="text/javascript" language="Javascript">
455: // <![CDATA[
456: var reseditbrowser;
1.1004 www 457: function openresbrowser(formname,reslink) {
1.1005 www 458: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 459: var title = 'Resource_Browser';
460: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 461: options += ',width=700,height=500';
1.1004 www 462: reseditbrowser = open(url,title,options,'1');
463: reseditbrowser.focus();
1.1003 www 464: }
465: // ]]>
466: </script>
1.1004 www 467: ENDRESBRW
1.1003 www 468: }
469:
1.74 www 470: sub selectstudent_link {
1.999 www 471: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
472: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
473: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
474: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 475: if ($env{'request.course.id'}) {
1.302 albertel 476: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
477: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
478: '/'.$env{'request.course.sec'})) {
1.111 www 479: return '';
480: }
1.999 www 481: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 482: if ($courseadvonly) {
483: $callargs .= ",'',1,1";
484: }
485: return '<span class="LC_nobreak">'.
486: '<a href="javascript:openstdbrowser('.$callargs.');">'.
487: &mt('Select User').'</a></span>';
1.74 www 488: }
1.258 albertel 489: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 490: $callargs .= ",'',1";
1.793 raeburn 491: return '<span class="LC_nobreak">'.
492: '<a href="javascript:openstdbrowser('.$callargs.');">'.
493: &mt('Select User').'</a></span>';
1.111 www 494: }
495: return '';
1.91 www 496: }
497:
1.1004 www 498: sub selectresource_link {
499: my ($form,$reslink,$arg)=@_;
500:
501: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
502: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
503: unless ($env{'request.course.id'}) { return $arg; }
504: return '<span class="LC_nobreak">'.
505: '<a href="javascript:openresbrowser('.$callargs.');">'.
506: $arg.'</a></span>';
507: }
508:
509:
510:
1.653 raeburn 511: sub authorbrowser_javascript {
512: return <<"ENDAUTHORBRW";
1.776 bisitz 513: <script type="text/javascript" language="JavaScript">
1.824 bisitz 514: // <![CDATA[
1.653 raeburn 515: var stdeditbrowser;
516:
517: function openauthorbrowser(formname,udom) {
518: var url = '/adm/pickauthor?';
519: url += 'form='+formname+'&roledom='+udom;
520: var title = 'Author_Browser';
521: var options = 'scrollbars=1,resizable=1,menubar=0';
522: options += ',width=700,height=600';
523: stdeditbrowser = open(url,title,options,'1');
524: stdeditbrowser.focus();
525: }
526:
1.824 bisitz 527: // ]]>
1.653 raeburn 528: </script>
529: ENDAUTHORBRW
530: }
531:
1.91 www 532: sub coursebrowser_javascript {
1.1075.2.31 raeburn 533: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
534: $credits_element) = @_;
1.932 raeburn 535: my $wintitle = 'Course_Browser';
1.931 raeburn 536: if ($crstype eq 'Community') {
1.932 raeburn 537: $wintitle = 'Community_Browser';
1.909 raeburn 538: }
1.876 raeburn 539: my $id_functions = &javascript_index_functions();
540: my $output = '
1.776 bisitz 541: <script type="text/javascript" language="JavaScript">
1.824 bisitz 542: // <![CDATA[
1.468 raeburn 543: var stdeditbrowser;'."\n";
1.876 raeburn 544:
545: $output .= <<"ENDSTDBRW";
1.909 raeburn 546: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 547: var url = '/adm/pickcourse?';
1.895 raeburn 548: var formid = getFormIdByName(formname);
1.876 raeburn 549: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 550: if (domainfilter != null) {
551: if (domainfilter != '') {
552: url += 'domainfilter='+domainfilter+'&';
553: }
554: }
1.91 www 555: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 556: '&cdomelement='+udom+
557: '&cnameelement='+desc;
1.468 raeburn 558: if (extra_element !=null && extra_element != '') {
1.594 raeburn 559: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 560: url += '&roleelement='+extra_element;
561: if (domainfilter == null || domainfilter == '') {
562: url += '&domainfilter='+extra_element;
563: }
1.234 raeburn 564: }
1.468 raeburn 565: else {
566: if (formname == 'portform') {
567: url += '&setroles='+extra_element;
1.800 raeburn 568: } else {
569: if (formname == 'rules') {
570: url += '&fixeddom='+extra_element;
571: }
1.468 raeburn 572: }
573: }
1.230 raeburn 574: }
1.909 raeburn 575: if (type != null && type != '') {
576: url += '&type='+type;
577: }
578: if (type_elem != null && type_elem != '') {
579: url += '&typeelement='+type_elem;
580: }
1.872 raeburn 581: if (formname == 'ccrs') {
582: var ownername = document.forms[formid].ccuname.value;
583: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
584: url += '&cloner='+ownername+':'+ownerdom;
585: }
1.293 raeburn 586: if (multflag !=null && multflag != '') {
587: url += '&multiple='+multflag;
588: }
1.909 raeburn 589: var title = '$wintitle';
1.91 www 590: var options = 'scrollbars=1,resizable=1,menubar=0';
591: options += ',width=700,height=600';
592: stdeditbrowser = open(url,title,options,'1');
593: stdeditbrowser.focus();
594: }
1.876 raeburn 595: $id_functions
596: ENDSTDBRW
1.1075.2.31 raeburn 597: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
598: $output .= &setsec_javascript($sec_element,$formname,$role_element,
599: $credits_element);
1.876 raeburn 600: }
601: $output .= '
602: // ]]>
603: </script>';
604: return $output;
605: }
606:
607: sub javascript_index_functions {
608: return <<"ENDJS";
609:
610: function getFormIdByName(formname) {
611: for (var i=0;i<document.forms.length;i++) {
612: if (document.forms[i].name == formname) {
613: return i;
614: }
615: }
616: return -1;
617: }
618:
619: function getIndexByName(formid,item) {
620: for (var i=0;i<document.forms[formid].elements.length;i++) {
621: if (document.forms[formid].elements[i].name == item) {
622: return i;
623: }
624: }
625: return -1;
626: }
1.468 raeburn 627:
1.876 raeburn 628: function getDomainFromSelectbox(formname,udom) {
629: var userdom;
630: var formid = getFormIdByName(formname);
631: if (formid > -1) {
632: var domid = getIndexByName(formid,udom);
633: if (domid > -1) {
634: if (document.forms[formid].elements[domid].type == 'select-one') {
635: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
636: }
637: if (document.forms[formid].elements[domid].type == 'hidden') {
638: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 639: }
640: }
641: }
1.876 raeburn 642: return userdom;
643: }
644:
645: ENDJS
1.468 raeburn 646:
1.876 raeburn 647: }
648:
1.1017 raeburn 649: sub javascript_array_indexof {
1.1018 raeburn 650: return <<ENDJS;
1.1017 raeburn 651: <script type="text/javascript" language="JavaScript">
652: // <![CDATA[
653:
654: if (!Array.prototype.indexOf) {
655: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
656: "use strict";
657: if (this === void 0 || this === null) {
658: throw new TypeError();
659: }
660: var t = Object(this);
661: var len = t.length >>> 0;
662: if (len === 0) {
663: return -1;
664: }
665: var n = 0;
666: if (arguments.length > 0) {
667: n = Number(arguments[1]);
668: if (n !== n) { // shortcut for verifying if it's NaN
669: n = 0;
670: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
671: n = (n > 0 || -1) * Math.floor(Math.abs(n));
672: }
673: }
674: if (n >= len) {
675: return -1;
676: }
677: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
678: for (; k < len; k++) {
679: if (k in t && t[k] === searchElement) {
680: return k;
681: }
682: }
683: return -1;
684: }
685: }
686:
687: // ]]>
688: </script>
689:
690: ENDJS
691:
692: }
693:
1.876 raeburn 694: sub userbrowser_javascript {
695: my $id_functions = &javascript_index_functions();
696: return <<"ENDUSERBRW";
697:
1.888 raeburn 698: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 699: var url = '/adm/pickuser?';
700: var userdom = getDomainFromSelectbox(formname,udom);
701: if (userdom != null) {
702: if (userdom != '') {
703: url += 'srchdom='+userdom+'&';
704: }
705: }
706: url += 'form=' + formname + '&unameelement='+uname+
707: '&udomelement='+udom+
708: '&ulastelement='+ulast+
709: '&ufirstelement='+ufirst+
710: '&uemailelement='+uemail+
1.881 raeburn 711: '&hideudomelement='+hideudom+
712: '&coursedom='+crsdom;
1.888 raeburn 713: if ((caller != null) && (caller != undefined)) {
714: url += '&caller='+caller;
715: }
1.876 raeburn 716: var title = 'User_Browser';
717: var options = 'scrollbars=1,resizable=1,menubar=0';
718: options += ',width=700,height=600';
719: var stdeditbrowser = open(url,title,options,'1');
720: stdeditbrowser.focus();
721: }
722:
1.888 raeburn 723: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 724: var formid = getFormIdByName(formname);
725: if (formid > -1) {
1.888 raeburn 726: var unameid = getIndexByName(formid,uname);
1.876 raeburn 727: var domid = getIndexByName(formid,udom);
728: var hidedomid = getIndexByName(formid,origdom);
729: if (hidedomid > -1) {
730: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 731: var unameval = document.forms[formid].elements[unameid].value;
732: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
733: if (domid > -1) {
734: var slct = document.forms[formid].elements[domid];
735: if (slct.type == 'select-one') {
736: var i;
737: for (i=0;i<slct.length;i++) {
738: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
739: }
740: }
741: if (slct.type == 'hidden') {
742: slct.value = fixeddom;
1.876 raeburn 743: }
744: }
1.468 raeburn 745: }
746: }
747: }
1.876 raeburn 748: return;
749: }
750:
751: $id_functions
752: ENDUSERBRW
1.468 raeburn 753: }
754:
755: sub setsec_javascript {
1.1075.2.31 raeburn 756: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 757: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
758: $communityrolestr);
759: if ($role_element ne '') {
760: my @allroles = ('st','ta','ep','in','ad');
761: foreach my $crstype ('Course','Community') {
762: if ($crstype eq 'Community') {
763: foreach my $role (@allroles) {
764: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
765: }
766: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
767: } else {
768: foreach my $role (@allroles) {
769: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
770: }
771: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
772: }
773: }
774: $rolestr = '"'.join('","',@allroles).'"';
775: $courserolestr = '"'.join('","',@courserolenames).'"';
776: $communityrolestr = '"'.join('","',@communityrolenames).'"';
777: }
1.468 raeburn 778: my $setsections = qq|
779: function setSect(sectionlist) {
1.629 raeburn 780: var sectionsArray = new Array();
781: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
782: sectionsArray = sectionlist.split(",");
783: }
1.468 raeburn 784: var numSections = sectionsArray.length;
785: document.$formname.$sec_element.length = 0;
786: if (numSections == 0) {
787: document.$formname.$sec_element.multiple=false;
788: document.$formname.$sec_element.size=1;
789: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
790: } else {
791: if (numSections == 1) {
792: document.$formname.$sec_element.multiple=false;
793: document.$formname.$sec_element.size=1;
794: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
795: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
796: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
797: } else {
798: for (var i=0; i<numSections; i++) {
799: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
800: }
801: document.$formname.$sec_element.multiple=true
802: if (numSections < 3) {
803: document.$formname.$sec_element.size=numSections;
804: } else {
805: document.$formname.$sec_element.size=3;
806: }
807: document.$formname.$sec_element.options[0].selected = false
808: }
809: }
1.91 www 810: }
1.905 raeburn 811:
812: function setRole(crstype) {
1.468 raeburn 813: |;
1.905 raeburn 814: if ($role_element eq '') {
815: $setsections .= ' return;
816: }
817: ';
818: } else {
819: $setsections .= qq|
820: var elementLength = document.$formname.$role_element.length;
821: var allroles = Array($rolestr);
822: var courserolenames = Array($courserolestr);
823: var communityrolenames = Array($communityrolestr);
824: if (elementLength != undefined) {
825: if (document.$formname.$role_element.options[5].value == 'cc') {
826: if (crstype == 'Course') {
827: return;
828: } else {
829: allroles[5] = 'co';
830: for (var i=0; i<6; i++) {
831: document.$formname.$role_element.options[i].value = allroles[i];
832: document.$formname.$role_element.options[i].text = communityrolenames[i];
833: }
834: }
835: } else {
836: if (crstype == 'Community') {
837: return;
838: } else {
839: allroles[5] = 'cc';
840: for (var i=0; i<6; i++) {
841: document.$formname.$role_element.options[i].value = allroles[i];
842: document.$formname.$role_element.options[i].text = courserolenames[i];
843: }
844: }
845: }
846: }
847: return;
848: }
849: |;
850: }
1.1075.2.31 raeburn 851: if ($credits_element) {
852: $setsections .= qq|
853: function setCredits(defaultcredits) {
854: document.$formname.$credits_element.value = defaultcredits;
855: return;
856: }
857: |;
858: }
1.468 raeburn 859: return $setsections;
860: }
861:
1.91 www 862: sub selectcourse_link {
1.909 raeburn 863: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
864: $typeelement) = @_;
865: my $type = $selecttype;
1.871 raeburn 866: my $linktext = &mt('Select Course');
867: if ($selecttype eq 'Community') {
1.909 raeburn 868: $linktext = &mt('Select Community');
1.906 raeburn 869: } elsif ($selecttype eq 'Course/Community') {
870: $linktext = &mt('Select Course/Community');
1.909 raeburn 871: $type = '';
1.1019 raeburn 872: } elsif ($selecttype eq 'Select') {
873: $linktext = &mt('Select');
874: $type = '';
1.871 raeburn 875: }
1.787 bisitz 876: return '<span class="LC_nobreak">'
877: ."<a href='"
878: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
879: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 880: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 881: ."'>".$linktext.'</a>'
1.787 bisitz 882: .'</span>';
1.74 www 883: }
1.42 matthew 884:
1.653 raeburn 885: sub selectauthor_link {
886: my ($form,$udom)=@_;
887: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
888: &mt('Select Author').'</a>';
889: }
890:
1.876 raeburn 891: sub selectuser_link {
1.881 raeburn 892: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 893: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 894: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 895: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 896: ');">'.$linktext.'</a>';
1.876 raeburn 897: }
898:
1.273 raeburn 899: sub check_uncheck_jscript {
900: my $jscript = <<"ENDSCRT";
901: function checkAll(field) {
902: if (field.length > 0) {
903: for (i = 0; i < field.length; i++) {
1.1075.2.14 raeburn 904: if (!field[i].disabled) {
905: field[i].checked = true;
906: }
1.273 raeburn 907: }
908: } else {
1.1075.2.14 raeburn 909: if (!field.disabled) {
910: field.checked = true;
911: }
1.273 raeburn 912: }
913: }
914:
915: function uncheckAll(field) {
916: if (field.length > 0) {
917: for (i = 0; i < field.length; i++) {
918: field[i].checked = false ;
1.543 albertel 919: }
920: } else {
1.273 raeburn 921: field.checked = false ;
922: }
923: }
924: ENDSCRT
925: return $jscript;
926: }
927:
1.656 www 928: sub select_timezone {
1.659 raeburn 929: my ($name,$selected,$onchange,$includeempty)=@_;
930: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
931: if ($includeempty) {
932: $output .= '<option value=""';
933: if (($selected eq '') || ($selected eq 'local')) {
934: $output .= ' selected="selected" ';
935: }
936: $output .= '> </option>';
937: }
1.657 raeburn 938: my @timezones = DateTime::TimeZone->all_names;
939: foreach my $tzone (@timezones) {
940: $output.= '<option value="'.$tzone.'"';
941: if ($tzone eq $selected) {
942: $output.=' selected="selected"';
943: }
944: $output.=">$tzone</option>\n";
1.656 www 945: }
946: $output.="</select>";
947: return $output;
948: }
1.273 raeburn 949:
1.687 raeburn 950: sub select_datelocale {
951: my ($name,$selected,$onchange,$includeempty)=@_;
952: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
953: if ($includeempty) {
954: $output .= '<option value=""';
955: if ($selected eq '') {
956: $output .= ' selected="selected" ';
957: }
958: $output .= '> </option>';
959: }
960: my (@possibles,%locale_names);
961: my @locales = DateTime::Locale::Catalog::Locales;
962: foreach my $locale (@locales) {
963: if (ref($locale) eq 'HASH') {
964: my $id = $locale->{'id'};
965: if ($id ne '') {
966: my $en_terr = $locale->{'en_territory'};
967: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 968: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 969: if (grep(/^en$/,@languages) || !@languages) {
970: if ($en_terr ne '') {
971: $locale_names{$id} = '('.$en_terr.')';
972: } elsif ($native_terr ne '') {
973: $locale_names{$id} = $native_terr;
974: }
975: } else {
976: if ($native_terr ne '') {
977: $locale_names{$id} = $native_terr.' ';
978: } elsif ($en_terr ne '') {
979: $locale_names{$id} = '('.$en_terr.')';
980: }
981: }
982: push (@possibles,$id);
983: }
984: }
985: }
986: foreach my $item (sort(@possibles)) {
987: $output.= '<option value="'.$item.'"';
988: if ($item eq $selected) {
989: $output.=' selected="selected"';
990: }
991: $output.=">$item";
992: if ($locale_names{$item} ne '') {
993: $output.=" $locale_names{$item}</option>\n";
994: }
995: $output.="</option>\n";
996: }
997: $output.="</select>";
998: return $output;
999: }
1000:
1.792 raeburn 1001: sub select_language {
1002: my ($name,$selected,$includeempty) = @_;
1003: my %langchoices;
1004: if ($includeempty) {
1.1075.2.32 raeburn 1005: %langchoices = ('' => 'No language preference');
1.792 raeburn 1006: }
1007: foreach my $id (&languageids()) {
1008: my $code = &supportedlanguagecode($id);
1009: if ($code) {
1010: $langchoices{$code} = &plainlanguagedescription($id);
1011: }
1012: }
1.1075.2.32 raeburn 1013: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.970 raeburn 1014: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 1015: }
1016:
1.42 matthew 1017: =pod
1.36 matthew 1018:
1.648 raeburn 1019: =item * &linked_select_forms(...)
1.36 matthew 1020:
1021: linked_select_forms returns a string containing a <script></script> block
1022: and html for two <select> menus. The select menus will be linked in that
1023: changing the value of the first menu will result in new values being placed
1024: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1025: order unless a defined order is provided.
1.36 matthew 1026:
1027: linked_select_forms takes the following ordered inputs:
1028:
1029: =over 4
1030:
1.112 bowersj2 1031: =item * $formname, the name of the <form> tag
1.36 matthew 1032:
1.112 bowersj2 1033: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1034:
1.112 bowersj2 1035: =item * $firstdefault, the default value for the first menu
1.36 matthew 1036:
1.112 bowersj2 1037: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1038:
1.112 bowersj2 1039: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1040:
1.112 bowersj2 1041: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1042:
1.609 raeburn 1043: =item * $menuorder, the order of values in the first menu
1044:
1.1075.2.31 raeburn 1045: =item * $onchangefirst, additional javascript call to execute for an onchange
1046: event for the first <select> tag
1047:
1048: =item * $onchangesecond, additional javascript call to execute for an onchange
1049: event for the second <select> tag
1050:
1.41 ng 1051: =back
1052:
1.36 matthew 1053: Below is an example of such a hash. Only the 'text', 'default', and
1054: 'select2' keys must appear as stated. keys(%menu) are the possible
1055: values for the first select menu. The text that coincides with the
1.41 ng 1056: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1057: and text for the second menu are given in the hash pointed to by
1058: $menu{$choice1}->{'select2'}.
1059:
1.112 bowersj2 1060: my %menu = ( A1 => { text =>"Choice A1" ,
1061: default => "B3",
1062: select2 => {
1063: B1 => "Choice B1",
1064: B2 => "Choice B2",
1065: B3 => "Choice B3",
1066: B4 => "Choice B4"
1.609 raeburn 1067: },
1068: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1069: },
1070: A2 => { text =>"Choice A2" ,
1071: default => "C2",
1072: select2 => {
1073: C1 => "Choice C1",
1074: C2 => "Choice C2",
1075: C3 => "Choice C3"
1.609 raeburn 1076: },
1077: order => ['C2','C1','C3'],
1.112 bowersj2 1078: },
1079: A3 => { text =>"Choice A3" ,
1080: default => "D6",
1081: select2 => {
1082: D1 => "Choice D1",
1083: D2 => "Choice D2",
1084: D3 => "Choice D3",
1085: D4 => "Choice D4",
1086: D5 => "Choice D5",
1087: D6 => "Choice D6",
1088: D7 => "Choice D7"
1.609 raeburn 1089: },
1090: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1091: }
1092: );
1.36 matthew 1093:
1094: =cut
1095:
1096: sub linked_select_forms {
1097: my ($formname,
1098: $middletext,
1099: $firstdefault,
1100: $firstselectname,
1101: $secondselectname,
1.609 raeburn 1102: $hashref,
1103: $menuorder,
1.1075.2.31 raeburn 1104: $onchangefirst,
1105: $onchangesecond
1.36 matthew 1106: ) = @_;
1107: my $second = "document.$formname.$secondselectname";
1108: my $first = "document.$formname.$firstselectname";
1109: # output the javascript to do the changing
1110: my $result = '';
1.776 bisitz 1111: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1112: $result.="// <![CDATA[\n";
1.36 matthew 1113: $result.="var select2data = new Object();\n";
1114: $" = '","';
1115: my $debug = '';
1116: foreach my $s1 (sort(keys(%$hashref))) {
1117: $result.="select2data.d_$s1 = new Object();\n";
1118: $result.="select2data.d_$s1.def = new String('".
1119: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1120: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1121: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1122: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1123: @s2values = @{$hashref->{$s1}->{'order'}};
1124: }
1.36 matthew 1125: $result.="\"@s2values\");\n";
1126: $result.="select2data.d_$s1.texts = new Array(";
1127: my @s2texts;
1128: foreach my $value (@s2values) {
1129: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1130: }
1131: $result.="\"@s2texts\");\n";
1132: }
1133: $"=' ';
1134: $result.= <<"END";
1135:
1136: function select1_changed() {
1137: // Determine new choice
1138: var newvalue = "d_" + $first.value;
1139: // update select2
1140: var values = select2data[newvalue].values;
1141: var texts = select2data[newvalue].texts;
1142: var select2def = select2data[newvalue].def;
1143: var i;
1144: // out with the old
1145: for (i = 0; i < $second.options.length; i++) {
1146: $second.options[i] = null;
1147: }
1148: // in with the nuclear
1149: for (i=0;i<values.length; i++) {
1150: $second.options[i] = new Option(values[i]);
1.143 matthew 1151: $second.options[i].value = values[i];
1.36 matthew 1152: $second.options[i].text = texts[i];
1153: if (values[i] == select2def) {
1154: $second.options[i].selected = true;
1155: }
1156: }
1157: }
1.824 bisitz 1158: // ]]>
1.36 matthew 1159: </script>
1160: END
1161: # output the initial values for the selection lists
1.1075.2.31 raeburn 1162: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1163: my @order = sort(keys(%{$hashref}));
1164: if (ref($menuorder) eq 'ARRAY') {
1165: @order = @{$menuorder};
1166: }
1167: foreach my $value (@order) {
1.36 matthew 1168: $result.=" <option value=\"$value\" ";
1.253 albertel 1169: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1170: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1171: }
1172: $result .= "</select>\n";
1173: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1174: $result .= $middletext;
1.1075.2.31 raeburn 1175: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1176: if ($onchangesecond) {
1177: $result .= ' onchange="'.$onchangesecond.'"';
1178: }
1179: $result .= ">\n";
1.36 matthew 1180: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1181:
1182: my @secondorder = sort(keys(%select2));
1183: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1184: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1185: }
1186: foreach my $value (@secondorder) {
1.36 matthew 1187: $result.=" <option value=\"$value\" ";
1.253 albertel 1188: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1189: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1190: }
1191: $result .= "</select>\n";
1192: # return $debug;
1193: return $result;
1194: } # end of sub linked_select_forms {
1195:
1.45 matthew 1196: =pod
1.44 bowersj2 1197:
1.973 raeburn 1198: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1199:
1.112 bowersj2 1200: Returns a string corresponding to an HTML link to the given help
1201: $topic, where $topic corresponds to the name of a .tex file in
1202: /home/httpd/html/adm/help/tex, with underscores replaced by
1203: spaces.
1204:
1205: $text will optionally be linked to the same topic, allowing you to
1206: link text in addition to the graphic. If you do not want to link
1207: text, but wish to specify one of the later parameters, pass an
1208: empty string.
1209:
1210: $stayOnPage is a value that will be interpreted as a boolean. If true,
1211: the link will not open a new window. If false, the link will open
1212: a new window using Javascript. (Default is false.)
1213:
1214: $width and $height are optional numerical parameters that will
1215: override the width and height of the popped up window, which may
1.973 raeburn 1216: be useful for certain help topics with big pictures included.
1217:
1218: $imgid is the id of the img tag used for the help icon. This may be
1219: used in a javascript call to switch the image src. See
1220: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1221:
1222: =cut
1223:
1224: sub help_open_topic {
1.973 raeburn 1225: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1226: $text = "" if (not defined $text);
1.44 bowersj2 1227: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1228: $width = 500 if (not defined $width);
1.44 bowersj2 1229: $height = 400 if (not defined $height);
1230: my $filename = $topic;
1231: $filename =~ s/ /_/g;
1232:
1.48 bowersj2 1233: my $template = "";
1234: my $link;
1.572 banghart 1235:
1.159 www 1236: $topic=~s/\W/\_/g;
1.44 bowersj2 1237:
1.572 banghart 1238: if (!$stayOnPage) {
1.1075.2.50 raeburn 1239: if ($env{'browser.mobile'}) {
1240: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1241: } else {
1242: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1243: }
1.1037 www 1244: } elsif ($stayOnPage eq 'popup') {
1245: $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 1246: } else {
1.48 bowersj2 1247: $link = "/adm/help/${filename}.hlp";
1248: }
1249:
1250: # Add the text
1.755 neumanie 1251: if ($text ne "") {
1.763 bisitz 1252: $template.='<span class="LC_help_open_topic">'
1253: .'<a target="_top" href="'.$link.'">'
1254: .$text.'</a>';
1.48 bowersj2 1255: }
1256:
1.763 bisitz 1257: # (Always) Add the graphic
1.179 matthew 1258: my $title = &mt('Online Help');
1.667 raeburn 1259: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1260: if ($imgid ne '') {
1261: $imgid = ' id="'.$imgid.'"';
1262: }
1.763 bisitz 1263: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1264: .'<img src="'.$helpicon.'" border="0"'
1265: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1266: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1267: .' /></a>';
1268: if ($text ne "") {
1269: $template.='</span>';
1270: }
1.44 bowersj2 1271: return $template;
1272:
1.106 bowersj2 1273: }
1274:
1275: # This is a quicky function for Latex cheatsheet editing, since it
1276: # appears in at least four places
1277: sub helpLatexCheatsheet {
1.1037 www 1278: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1279: my $out;
1.106 bowersj2 1280: my $addOther = '';
1.732 raeburn 1281: if ($topic) {
1.1037 www 1282: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1283: }
1284: $out = '<span>' # Start cheatsheet
1285: .$addOther
1286: .'<span>'
1.1037 www 1287: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1288: .'</span> <span>'
1.1037 www 1289: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1290: .'</span>';
1.732 raeburn 1291: unless ($not_author) {
1.763 bisitz 1292: $out .= ' <span>'
1.1037 www 1293: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.763 bisitz 1294: .'</span>';
1.732 raeburn 1295: }
1.763 bisitz 1296: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1297: return $out;
1.172 www 1298: }
1299:
1.430 albertel 1300: sub general_help {
1301: my $helptopic='Student_Intro';
1302: if ($env{'request.role'}=~/^(ca|au)/) {
1303: $helptopic='Authoring_Intro';
1.907 raeburn 1304: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1305: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1306: } elsif ($env{'request.role'}=~/^dc/) {
1307: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1308: }
1309: return $helptopic;
1310: }
1311:
1312: sub update_help_link {
1313: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1314: my $origurl = $ENV{'REQUEST_URI'};
1315: $origurl=~s|^/~|/priv/|;
1316: my $timestamp = time;
1317: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1318: $$datum = &escape($$datum);
1319: }
1320:
1321: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1322: my $output .= <<"ENDOUTPUT";
1323: <script type="text/javascript">
1.824 bisitz 1324: // <![CDATA[
1.430 albertel 1325: banner_link = '$banner_link';
1.824 bisitz 1326: // ]]>
1.430 albertel 1327: </script>
1328: ENDOUTPUT
1329: return $output;
1330: }
1331:
1332: # now just updates the help link and generates a blue icon
1.193 raeburn 1333: sub help_open_menu {
1.430 albertel 1334: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1335: = @_;
1.949 droeschl 1336: $stayOnPage = 1;
1.430 albertel 1337: my $output;
1338: if ($component_help) {
1339: if (!$text) {
1340: $output=&help_open_topic($component_help,undef,$stayOnPage,
1341: $width,$height);
1342: } else {
1343: my $help_text;
1344: $help_text=&unescape($topic);
1345: $output='<table><tr><td>'.
1346: &help_open_topic($component_help,$help_text,$stayOnPage,
1347: $width,$height).'</td></tr></table>';
1348: }
1349: }
1350: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1351: return $output.$banner_link;
1352: }
1353:
1354: sub top_nav_help {
1355: my ($text) = @_;
1.436 albertel 1356: $text = &mt($text);
1.1075.2.60 raeburn 1357: my $stay_on_page;
1358: unless ($env{'environment.remote'} eq 'on') {
1359: $stay_on_page = 1;
1360: }
1.1075.2.61 raeburn 1361: my ($link,$banner_link);
1362: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1363: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1364: : "javascript:helpMenu('open')";
1365: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1366: }
1.201 raeburn 1367: my $title = &mt('Get help');
1.1075.2.61 raeburn 1368: if ($link) {
1369: return <<"END";
1.436 albertel 1370: $banner_link
1.1075.2.56 raeburn 1371: <a href="$link" title="$title">$text</a>
1.436 albertel 1372: END
1.1075.2.61 raeburn 1373: } else {
1374: return ' '.$text.' ';
1375: }
1.436 albertel 1376: }
1377:
1378: sub help_menu_js {
1.1075.2.52 raeburn 1379: my ($httphost) = @_;
1.949 droeschl 1380: my $stayOnPage = 1;
1.436 albertel 1381: my $width = 620;
1382: my $height = 600;
1.430 albertel 1383: my $helptopic=&general_help();
1.1075.2.52 raeburn 1384: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1385: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1386: my $start_page =
1387: &Apache::loncommon::start_page('Help Menu', undef,
1388: {'frameset' => 1,
1389: 'js_ready' => 1,
1.1075.2.52 raeburn 1390: 'use_absolute' => $httphost,
1.331 albertel 1391: 'add_entries' => {
1392: 'border' => '0',
1.579 raeburn 1393: 'rows' => "110,*",},});
1.331 albertel 1394: my $end_page =
1395: &Apache::loncommon::end_page({'frameset' => 1,
1396: 'js_ready' => 1,});
1397:
1.436 albertel 1398: my $template .= <<"ENDTEMPLATE";
1399: <script type="text/javascript">
1.877 bisitz 1400: // <![CDATA[
1.253 albertel 1401: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1402: var banner_link = '';
1.243 raeburn 1403: function helpMenu(target) {
1404: var caller = this;
1405: if (target == 'open') {
1406: var newWindow = null;
1407: try {
1.262 albertel 1408: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1409: }
1410: catch(error) {
1411: writeHelp(caller);
1412: return;
1413: }
1414: if (newWindow) {
1415: caller = newWindow;
1416: }
1.193 raeburn 1417: }
1.243 raeburn 1418: writeHelp(caller);
1419: return;
1420: }
1421: function writeHelp(caller) {
1.1075.2.61 raeburn 1422: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1423: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1424: caller.document.close();
1425: caller.focus();
1.193 raeburn 1426: }
1.877 bisitz 1427: // END LON-CAPA Internal -->
1.253 albertel 1428: // ]]>
1.436 albertel 1429: </script>
1.193 raeburn 1430: ENDTEMPLATE
1431: return $template;
1432: }
1433:
1.172 www 1434: sub help_open_bug {
1435: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1436: unless ($env{'user.adv'}) { return ''; }
1.172 www 1437: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1438: $text = "" if (not defined $text);
1439: $stayOnPage=1;
1.184 albertel 1440: $width = 600 if (not defined $width);
1441: $height = 600 if (not defined $height);
1.172 www 1442:
1443: $topic=~s/\W+/\+/g;
1444: my $link='';
1445: my $template='';
1.379 albertel 1446: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1447: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1448: if (!$stayOnPage)
1449: {
1450: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1451: }
1452: else
1453: {
1454: $link = $url;
1455: }
1456: # Add the text
1457: if ($text ne "")
1458: {
1459: $template .=
1460: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1461: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1462: }
1463:
1464: # Add the graphic
1.179 matthew 1465: my $title = &mt('Report a Bug');
1.215 albertel 1466: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1467: $template .= <<"ENDTEMPLATE";
1.436 albertel 1468: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1469: ENDTEMPLATE
1470: if ($text ne '') { $template.='</td></tr></table>' };
1471: return $template;
1472:
1473: }
1474:
1475: sub help_open_faq {
1476: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1477: unless ($env{'user.adv'}) { return ''; }
1.172 www 1478: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1479: $text = "" if (not defined $text);
1480: $stayOnPage=1;
1481: $width = 350 if (not defined $width);
1482: $height = 400 if (not defined $height);
1483:
1484: $topic=~s/\W+/\+/g;
1485: my $link='';
1486: my $template='';
1487: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1488: if (!$stayOnPage)
1489: {
1490: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1491: }
1492: else
1493: {
1494: $link = $url;
1495: }
1496:
1497: # Add the text
1498: if ($text ne "")
1499: {
1500: $template .=
1.173 www 1501: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1502: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1503: }
1504:
1505: # Add the graphic
1.179 matthew 1506: my $title = &mt('View the FAQ');
1.215 albertel 1507: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1508: $template .= <<"ENDTEMPLATE";
1.436 albertel 1509: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1510: ENDTEMPLATE
1511: if ($text ne '') { $template.='</td></tr></table>' };
1512: return $template;
1513:
1.44 bowersj2 1514: }
1.37 matthew 1515:
1.180 matthew 1516: ###############################################################
1517: ###############################################################
1518:
1.45 matthew 1519: =pod
1520:
1.648 raeburn 1521: =item * &change_content_javascript():
1.256 matthew 1522:
1523: This and the next function allow you to create small sections of an
1524: otherwise static HTML page that you can update on the fly with
1525: Javascript, even in Netscape 4.
1526:
1527: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1528: must be written to the HTML page once. It will prove the Javascript
1529: function "change(name, content)". Calling the change function with the
1530: name of the section
1531: you want to update, matching the name passed to C<changable_area>, and
1532: the new content you want to put in there, will put the content into
1533: that area.
1534:
1535: B<Note>: Netscape 4 only reserves enough space for the changable area
1536: to contain room for the original contents. You need to "make space"
1537: for whatever changes you wish to make, and be B<sure> to check your
1538: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1539: it's adequate for updating a one-line status display, but little more.
1540: This script will set the space to 100% width, so you only need to
1541: worry about height in Netscape 4.
1542:
1543: Modern browsers are much less limiting, and if you can commit to the
1544: user not using Netscape 4, this feature may be used freely with
1545: pretty much any HTML.
1546:
1547: =cut
1548:
1549: sub change_content_javascript {
1550: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1551: if ($env{'browser.type'} eq 'netscape' &&
1552: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1553: return (<<NETSCAPE4);
1554: function change(name, content) {
1555: doc = document.layers[name+"___escape"].layers[0].document;
1556: doc.open();
1557: doc.write(content);
1558: doc.close();
1559: }
1560: NETSCAPE4
1561: } else {
1562: # Otherwise, we need to use semi-standards-compliant code
1563: # (technically, "innerHTML" isn't standard but the equivalent
1564: # is really scary, and every useful browser supports it
1565: return (<<DOMBASED);
1566: function change(name, content) {
1567: element = document.getElementById(name);
1568: element.innerHTML = content;
1569: }
1570: DOMBASED
1571: }
1572: }
1573:
1574: =pod
1575:
1.648 raeburn 1576: =item * &changable_area($name,$origContent):
1.256 matthew 1577:
1578: This provides a "changable area" that can be modified on the fly via
1579: the Javascript code provided in C<change_content_javascript>. $name is
1580: the name you will use to reference the area later; do not repeat the
1581: same name on a given HTML page more then once. $origContent is what
1582: the area will originally contain, which can be left blank.
1583:
1584: =cut
1585:
1586: sub changable_area {
1587: my ($name, $origContent) = @_;
1588:
1.258 albertel 1589: if ($env{'browser.type'} eq 'netscape' &&
1590: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1591: # If this is netscape 4, we need to use the Layer tag
1592: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1593: } else {
1594: return "<span id='$name'>$origContent</span>";
1595: }
1596: }
1597:
1598: =pod
1599:
1.648 raeburn 1600: =item * &viewport_geometry_js
1.590 raeburn 1601:
1602: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1603:
1604: =cut
1605:
1606:
1607: sub viewport_geometry_js {
1608: return <<"GEOMETRY";
1609: var Geometry = {};
1610: function init_geometry() {
1611: if (Geometry.init) { return };
1612: Geometry.init=1;
1613: if (window.innerHeight) {
1614: Geometry.getViewportHeight = function() { return window.innerHeight; };
1615: Geometry.getViewportWidth = function() { return window.innerWidth; };
1616: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1617: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1618: }
1619: else if (document.documentElement && document.documentElement.clientHeight) {
1620: Geometry.getViewportHeight =
1621: function() { return document.documentElement.clientHeight; };
1622: Geometry.getViewportWidth =
1623: function() { return document.documentElement.clientWidth; };
1624:
1625: Geometry.getHorizontalScroll =
1626: function() { return document.documentElement.scrollLeft; };
1627: Geometry.getVerticalScroll =
1628: function() { return document.documentElement.scrollTop; };
1629: }
1630: else if (document.body.clientHeight) {
1631: Geometry.getViewportHeight =
1632: function() { return document.body.clientHeight; };
1633: Geometry.getViewportWidth =
1634: function() { return document.body.clientWidth; };
1635: Geometry.getHorizontalScroll =
1636: function() { return document.body.scrollLeft; };
1637: Geometry.getVerticalScroll =
1638: function() { return document.body.scrollTop; };
1639: }
1640: }
1641:
1642: GEOMETRY
1643: }
1644:
1645: =pod
1646:
1.648 raeburn 1647: =item * &viewport_size_js()
1.590 raeburn 1648:
1649: 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.
1650:
1651: =cut
1652:
1653: sub viewport_size_js {
1654: my $geometry = &viewport_geometry_js();
1655: return <<"DIMS";
1656:
1657: $geometry
1658:
1659: function getViewportDims(width,height) {
1660: init_geometry();
1661: width.value = Geometry.getViewportWidth();
1662: height.value = Geometry.getViewportHeight();
1663: return;
1664: }
1665:
1666: DIMS
1667: }
1668:
1669: =pod
1670:
1.648 raeburn 1671: =item * &resize_textarea_js()
1.565 albertel 1672:
1673: emits the needed javascript to resize a textarea to be as big as possible
1674:
1675: creates a function resize_textrea that takes two IDs first should be
1676: the id of the element to resize, second should be the id of a div that
1677: surrounds everything that comes after the textarea, this routine needs
1678: to be attached to the <body> for the onload and onresize events.
1679:
1.648 raeburn 1680: =back
1.565 albertel 1681:
1682: =cut
1683:
1684: sub resize_textarea_js {
1.590 raeburn 1685: my $geometry = &viewport_geometry_js();
1.565 albertel 1686: return <<"RESIZE";
1687: <script type="text/javascript">
1.824 bisitz 1688: // <![CDATA[
1.590 raeburn 1689: $geometry
1.565 albertel 1690:
1.588 albertel 1691: function getX(element) {
1692: var x = 0;
1693: while (element) {
1694: x += element.offsetLeft;
1695: element = element.offsetParent;
1696: }
1697: return x;
1698: }
1699: function getY(element) {
1700: var y = 0;
1701: while (element) {
1702: y += element.offsetTop;
1703: element = element.offsetParent;
1704: }
1705: return y;
1706: }
1707:
1708:
1.565 albertel 1709: function resize_textarea(textarea_id,bottom_id) {
1710: init_geometry();
1711: var textarea = document.getElementById(textarea_id);
1712: //alert(textarea);
1713:
1.588 albertel 1714: var textarea_top = getY(textarea);
1.565 albertel 1715: var textarea_height = textarea.offsetHeight;
1716: var bottom = document.getElementById(bottom_id);
1.588 albertel 1717: var bottom_top = getY(bottom);
1.565 albertel 1718: var bottom_height = bottom.offsetHeight;
1719: var window_height = Geometry.getViewportHeight();
1.588 albertel 1720: var fudge = 23;
1.565 albertel 1721: var new_height = window_height-fudge-textarea_top-bottom_height;
1722: if (new_height < 300) {
1723: new_height = 300;
1724: }
1725: textarea.style.height=new_height+'px';
1726: }
1.824 bisitz 1727: // ]]>
1.565 albertel 1728: </script>
1729: RESIZE
1730:
1731: }
1732:
1733: =pod
1734:
1.256 matthew 1735: =head1 Excel and CSV file utility routines
1736:
1737: =cut
1738:
1739: ###############################################################
1740: ###############################################################
1741:
1742: =pod
1743:
1.1075.2.56 raeburn 1744: =over 4
1745:
1.648 raeburn 1746: =item * &csv_translate($text)
1.37 matthew 1747:
1.185 www 1748: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1749: format.
1750:
1751: =cut
1752:
1.180 matthew 1753: ###############################################################
1754: ###############################################################
1.37 matthew 1755: sub csv_translate {
1756: my $text = shift;
1757: $text =~ s/\"/\"\"/g;
1.209 albertel 1758: $text =~ s/\n/ /g;
1.37 matthew 1759: return $text;
1760: }
1.180 matthew 1761:
1762: ###############################################################
1763: ###############################################################
1764:
1765: =pod
1766:
1.648 raeburn 1767: =item * &define_excel_formats()
1.180 matthew 1768:
1769: Define some commonly used Excel cell formats.
1770:
1771: Currently supported formats:
1772:
1773: =over 4
1774:
1775: =item header
1776:
1777: =item bold
1778:
1779: =item h1
1780:
1781: =item h2
1782:
1783: =item h3
1784:
1.256 matthew 1785: =item h4
1786:
1787: =item i
1788:
1.180 matthew 1789: =item date
1790:
1791: =back
1792:
1793: Inputs: $workbook
1794:
1795: Returns: $format, a hash reference.
1796:
1.1057 foxr 1797:
1.180 matthew 1798: =cut
1799:
1800: ###############################################################
1801: ###############################################################
1802: sub define_excel_formats {
1803: my ($workbook) = @_;
1804: my $format;
1805: $format->{'header'} = $workbook->add_format(bold => 1,
1806: bottom => 1,
1807: align => 'center');
1808: $format->{'bold'} = $workbook->add_format(bold=>1);
1809: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1810: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1811: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1812: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1813: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1814: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1815: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1816: return $format;
1817: }
1818:
1819: ###############################################################
1820: ###############################################################
1.113 bowersj2 1821:
1822: =pod
1823:
1.648 raeburn 1824: =item * &create_workbook()
1.255 matthew 1825:
1826: Create an Excel worksheet. If it fails, output message on the
1827: request object and return undefs.
1828:
1829: Inputs: Apache request object
1830:
1831: Returns (undef) on failure,
1832: Excel worksheet object, scalar with filename, and formats
1833: from &Apache::loncommon::define_excel_formats on success
1834:
1835: =cut
1836:
1837: ###############################################################
1838: ###############################################################
1839: sub create_workbook {
1840: my ($r) = @_;
1841: #
1842: # Create the excel spreadsheet
1843: my $filename = '/prtspool/'.
1.258 albertel 1844: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1845: time.'_'.rand(1000000000).'.xls';
1846: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1847: if (! defined($workbook)) {
1848: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1849: $r->print(
1850: '<p class="LC_error">'
1851: .&mt('Problems occurred in creating the new Excel file.')
1852: .' '.&mt('This error has been logged.')
1853: .' '.&mt('Please alert your LON-CAPA administrator.')
1854: .'</p>'
1855: );
1.255 matthew 1856: return (undef);
1857: }
1858: #
1.1014 foxr 1859: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 1860: #
1861: my $format = &Apache::loncommon::define_excel_formats($workbook);
1862: return ($workbook,$filename,$format);
1863: }
1864:
1865: ###############################################################
1866: ###############################################################
1867:
1868: =pod
1869:
1.648 raeburn 1870: =item * &create_text_file()
1.113 bowersj2 1871:
1.542 raeburn 1872: Create a file to write to and eventually make available to the user.
1.256 matthew 1873: If file creation fails, outputs an error message on the request object and
1874: return undefs.
1.113 bowersj2 1875:
1.256 matthew 1876: Inputs: Apache request object, and file suffix
1.113 bowersj2 1877:
1.256 matthew 1878: Returns (undef) on failure,
1879: Filehandle and filename on success.
1.113 bowersj2 1880:
1881: =cut
1882:
1.256 matthew 1883: ###############################################################
1884: ###############################################################
1885: sub create_text_file {
1886: my ($r,$suffix) = @_;
1887: if (! defined($suffix)) { $suffix = 'txt'; };
1888: my $fh;
1889: my $filename = '/prtspool/'.
1.258 albertel 1890: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1891: time.'_'.rand(1000000000).'.'.$suffix;
1892: $fh = Apache::File->new('>/home/httpd'.$filename);
1893: if (! defined($fh)) {
1894: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1895: $r->print(
1896: '<p class="LC_error">'
1897: .&mt('Problems occurred in creating the output file.')
1898: .' '.&mt('This error has been logged.')
1899: .' '.&mt('Please alert your LON-CAPA administrator.')
1900: .'</p>'
1901: );
1.113 bowersj2 1902: }
1.256 matthew 1903: return ($fh,$filename)
1.113 bowersj2 1904: }
1905:
1906:
1.256 matthew 1907: =pod
1.113 bowersj2 1908:
1909: =back
1910:
1911: =cut
1.37 matthew 1912:
1913: ###############################################################
1.33 matthew 1914: ## Home server <option> list generating code ##
1915: ###############################################################
1.35 matthew 1916:
1.169 www 1917: # ------------------------------------------
1918:
1919: sub domain_select {
1920: my ($name,$value,$multiple)=@_;
1921: my %domains=map {
1.514 albertel 1922: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1923: } &Apache::lonnet::all_domains();
1.169 www 1924: if ($multiple) {
1925: $domains{''}=&mt('Any domain');
1.550 albertel 1926: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1927: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1928: } else {
1.550 albertel 1929: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1930: return &select_form($name,$value,\%domains);
1.169 www 1931: }
1932: }
1933:
1.282 albertel 1934: #-------------------------------------------
1935:
1936: =pod
1937:
1.519 raeburn 1938: =head1 Routines for form select boxes
1939:
1940: =over 4
1941:
1.648 raeburn 1942: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1943:
1944: Returns a string containing a <select> element int multiple mode
1945:
1946:
1947: Args:
1948: $name - name of the <select> element
1.506 raeburn 1949: $value - scalar or array ref of values that should already be selected
1.282 albertel 1950: $size - number of rows long the select element is
1.283 albertel 1951: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1952: (shown text should already have been &mt())
1.506 raeburn 1953: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1954:
1.282 albertel 1955: =cut
1956:
1957: #-------------------------------------------
1.169 www 1958: sub multiple_select_form {
1.284 albertel 1959: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1960: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1961: my $output='';
1.191 matthew 1962: if (! defined($size)) {
1963: $size = 4;
1.283 albertel 1964: if (scalar(keys(%$hash))<4) {
1965: $size = scalar(keys(%$hash));
1.191 matthew 1966: }
1967: }
1.734 bisitz 1968: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1969: my @order;
1.506 raeburn 1970: if (ref($order) eq 'ARRAY') {
1971: @order = @{$order};
1972: } else {
1973: @order = sort(keys(%$hash));
1.501 banghart 1974: }
1975: if (exists($$hash{'select_form_order'})) {
1976: @order = @{$$hash{'select_form_order'}};
1977: }
1978:
1.284 albertel 1979: foreach my $key (@order) {
1.356 albertel 1980: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1981: $output.='selected="selected" ' if ($selected{$key});
1982: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1983: }
1984: $output.="</select>\n";
1985: return $output;
1986: }
1987:
1.88 www 1988: #-------------------------------------------
1989:
1990: =pod
1991:
1.970 raeburn 1992: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 1993:
1994: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 1995: allow a user to select options from a ref to a hash containing:
1996: option_name => displayed text. An optional $onchange can include
1997: a javascript onchange item, e.g., onchange="this.form.submit();"
1998:
1.88 www 1999: See lonrights.pm for an example invocation and use.
2000:
2001: =cut
2002:
2003: #-------------------------------------------
2004: sub select_form {
1.970 raeburn 2005: my ($def,$name,$hashref,$onchange) = @_;
2006: return unless (ref($hashref) eq 'HASH');
2007: if ($onchange) {
2008: $onchange = ' onchange="'.$onchange.'"';
2009: }
2010: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 2011: my @keys;
1.970 raeburn 2012: if (exists($hashref->{'select_form_order'})) {
2013: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2014: } else {
1.970 raeburn 2015: @keys=sort(keys(%{$hashref}));
1.128 albertel 2016: }
1.356 albertel 2017: foreach my $key (@keys) {
2018: $selectform.=
2019: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2020: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2021: ">".$hashref->{$key}."</option>\n";
1.88 www 2022: }
2023: $selectform.="</select>";
2024: return $selectform;
2025: }
2026:
1.475 www 2027: # For display filters
2028:
2029: sub display_filter {
1.1074 raeburn 2030: my ($context) = @_;
1.475 www 2031: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2032: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2033: my $phraseinput = 'hidden';
2034: my $includeinput = 'hidden';
2035: my ($checked,$includetypestext);
2036: if ($env{'form.displayfilter'} eq 'containing') {
2037: $phraseinput = 'text';
2038: if ($context eq 'parmslog') {
2039: $includeinput = 'checkbox';
2040: if ($env{'form.includetypes'}) {
2041: $checked = ' checked="checked"';
2042: }
2043: $includetypestext = &mt('Include parameter types');
2044: }
2045: } else {
2046: $includetypestext = ' ';
2047: }
2048: my ($additional,$secondid,$thirdid);
2049: if ($context eq 'parmslog') {
2050: $additional =
2051: '<label><input type="'.$includeinput.'" name="includetypes"'.
2052: $checked.' name="includetypes" value="1" id="includetypes" />'.
2053: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2054: '</label>';
2055: $secondid = 'includetypes';
2056: $thirdid = 'includetypestext';
2057: }
2058: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2059: '$secondid','$thirdid')";
2060: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2061: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2062: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2063: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2064: &mt('Filter: [_1]',
1.477 www 2065: &select_form($env{'form.displayfilter'},
2066: 'displayfilter',
1.970 raeburn 2067: {'currentfolder' => 'Current folder/page',
1.477 www 2068: 'containing' => 'Containing phrase',
1.1074 raeburn 2069: 'none' => 'None'},$onchange)).' '.
2070: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2071: &HTML::Entities::encode($env{'form.containingphrase'}).
2072: '" />'.$additional;
2073: }
2074:
2075: sub display_filter_js {
2076: my $includetext = &mt('Include parameter types');
2077: return <<"ENDJS";
2078:
2079: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2080: var firstType = 'hidden';
2081: if (setter.options[setter.selectedIndex].value == 'containing') {
2082: firstType = 'text';
2083: }
2084: firstObject = document.getElementById(firstid);
2085: if (typeof(firstObject) == 'object') {
2086: if (firstObject.type != firstType) {
2087: changeInputType(firstObject,firstType);
2088: }
2089: }
2090: if (context == 'parmslog') {
2091: var secondType = 'hidden';
2092: if (firstType == 'text') {
2093: secondType = 'checkbox';
2094: }
2095: secondObject = document.getElementById(secondid);
2096: if (typeof(secondObject) == 'object') {
2097: if (secondObject.type != secondType) {
2098: changeInputType(secondObject,secondType);
2099: }
2100: }
2101: var textItem = document.getElementById(thirdid);
2102: var currtext = textItem.innerHTML;
2103: var newtext;
2104: if (firstType == 'text') {
2105: newtext = '$includetext';
2106: } else {
2107: newtext = ' ';
2108: }
2109: if (currtext != newtext) {
2110: textItem.innerHTML = newtext;
2111: }
2112: }
2113: return;
2114: }
2115:
2116: function changeInputType(oldObject,newType) {
2117: var newObject = document.createElement('input');
2118: newObject.type = newType;
2119: if (oldObject.size) {
2120: newObject.size = oldObject.size;
2121: }
2122: if (oldObject.value) {
2123: newObject.value = oldObject.value;
2124: }
2125: if (oldObject.name) {
2126: newObject.name = oldObject.name;
2127: }
2128: if (oldObject.id) {
2129: newObject.id = oldObject.id;
2130: }
2131: oldObject.parentNode.replaceChild(newObject,oldObject);
2132: return;
2133: }
2134:
2135: ENDJS
1.475 www 2136: }
2137:
1.167 www 2138: sub gradeleveldescription {
2139: my $gradelevel=shift;
2140: my %gradelevels=(0 => 'Not specified',
2141: 1 => 'Grade 1',
2142: 2 => 'Grade 2',
2143: 3 => 'Grade 3',
2144: 4 => 'Grade 4',
2145: 5 => 'Grade 5',
2146: 6 => 'Grade 6',
2147: 7 => 'Grade 7',
2148: 8 => 'Grade 8',
2149: 9 => 'Grade 9',
2150: 10 => 'Grade 10',
2151: 11 => 'Grade 11',
2152: 12 => 'Grade 12',
2153: 13 => 'Grade 13',
2154: 14 => '100 Level',
2155: 15 => '200 Level',
2156: 16 => '300 Level',
2157: 17 => '400 Level',
2158: 18 => 'Graduate Level');
2159: return &mt($gradelevels{$gradelevel});
2160: }
2161:
1.163 www 2162: sub select_level_form {
2163: my ($deflevel,$name)=@_;
2164: unless ($deflevel) { $deflevel=0; }
1.167 www 2165: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2166: for (my $i=0; $i<=18; $i++) {
2167: $selectform.="<option value=\"$i\" ".
1.253 albertel 2168: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2169: ">".&gradeleveldescription($i)."</option>\n";
2170: }
2171: $selectform.="</select>";
2172: return $selectform;
1.163 www 2173: }
1.167 www 2174:
1.35 matthew 2175: #-------------------------------------------
2176:
1.45 matthew 2177: =pod
2178:
1.1075.2.42 raeburn 2179: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
1.35 matthew 2180:
2181: Returns a string containing a <select name='$name' size='1'> form to
2182: allow a user to select the domain to preform an operation in.
2183: See loncreateuser.pm for an example invocation and use.
2184:
1.90 www 2185: If the $includeempty flag is set, it also includes an empty choice ("no domain
2186: selected");
2187:
1.743 raeburn 2188: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2189:
1.910 raeburn 2190: 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.
2191:
1.1075.2.36 raeburn 2192: The optional $incdoms is a reference to an array of domains which will be the only available options.
2193:
2194: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2195:
1.35 matthew 2196: =cut
2197:
2198: #-------------------------------------------
1.34 matthew 2199: sub select_dom_form {
1.1075.2.36 raeburn 2200: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872 raeburn 2201: if ($onchange) {
1.874 raeburn 2202: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2203: }
1.1075.2.36 raeburn 2204: my (@domains,%exclude);
1.910 raeburn 2205: if (ref($incdoms) eq 'ARRAY') {
2206: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2207: } else {
2208: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2209: }
1.90 www 2210: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2211: if (ref($excdoms) eq 'ARRAY') {
2212: map { $exclude{$_} = 1; } @{$excdoms};
2213: }
1.743 raeburn 2214: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2215: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2216: next if ($exclude{$dom});
1.356 albertel 2217: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2218: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2219: if ($showdomdesc) {
2220: if ($dom ne '') {
2221: my $domdesc = &Apache::lonnet::domain($dom,'description');
2222: if ($domdesc ne '') {
2223: $selectdomain .= ' ('.$domdesc.')';
2224: }
2225: }
2226: }
2227: $selectdomain .= "</option>\n";
1.34 matthew 2228: }
2229: $selectdomain.="</select>";
2230: return $selectdomain;
2231: }
2232:
1.35 matthew 2233: #-------------------------------------------
2234:
1.45 matthew 2235: =pod
2236:
1.648 raeburn 2237: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2238:
1.586 raeburn 2239: input: 4 arguments (two required, two optional) -
2240: $domain - domain of new user
2241: $name - name of form element
2242: $default - Value of 'default' causes a default item to be first
2243: option, and selected by default.
2244: $hide - Value of 'hide' causes hiding of the name of the server,
2245: if 1 server found, or default, if 0 found.
1.594 raeburn 2246: output: returns 2 items:
1.586 raeburn 2247: (a) form element which contains either:
2248: (i) <select name="$name">
2249: <option value="$hostid1">$hostid $servers{$hostid}</option>
2250: <option value="$hostid2">$hostid $servers{$hostid}</option>
2251: </select>
2252: form item if there are multiple library servers in $domain, or
2253: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2254: if there is only one library server in $domain.
2255:
2256: (b) number of library servers found.
2257:
2258: See loncreateuser.pm for example of use.
1.35 matthew 2259:
2260: =cut
2261:
2262: #-------------------------------------------
1.586 raeburn 2263: sub home_server_form_item {
2264: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2265: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2266: my $result;
2267: my $numlib = keys(%servers);
2268: if ($numlib > 1) {
2269: $result .= '<select name="'.$name.'" />'."\n";
2270: if ($default) {
1.804 bisitz 2271: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2272: '</option>'."\n";
2273: }
2274: foreach my $hostid (sort(keys(%servers))) {
2275: $result.= '<option value="'.$hostid.'">'.
2276: $hostid.' '.$servers{$hostid}."</option>\n";
2277: }
2278: $result .= '</select>'."\n";
2279: } elsif ($numlib == 1) {
2280: my $hostid;
2281: foreach my $item (keys(%servers)) {
2282: $hostid = $item;
2283: }
2284: $result .= '<input type="hidden" name="'.$name.'" value="'.
2285: $hostid.'" />';
2286: if (!$hide) {
2287: $result .= $hostid.' '.$servers{$hostid};
2288: }
2289: $result .= "\n";
2290: } elsif ($default) {
2291: $result .= '<input type="hidden" name="'.$name.
2292: '" value="default" />';
2293: if (!$hide) {
2294: $result .= &mt('default');
2295: }
2296: $result .= "\n";
1.33 matthew 2297: }
1.586 raeburn 2298: return ($result,$numlib);
1.33 matthew 2299: }
1.112 bowersj2 2300:
2301: =pod
2302:
1.534 albertel 2303: =back
2304:
1.112 bowersj2 2305: =cut
1.87 matthew 2306:
2307: ###############################################################
1.112 bowersj2 2308: ## Decoding User Agent ##
1.87 matthew 2309: ###############################################################
2310:
2311: =pod
2312:
1.112 bowersj2 2313: =head1 Decoding the User Agent
2314:
2315: =over 4
2316:
2317: =item * &decode_user_agent()
1.87 matthew 2318:
2319: Inputs: $r
2320:
2321: Outputs:
2322:
2323: =over 4
2324:
1.112 bowersj2 2325: =item * $httpbrowser
1.87 matthew 2326:
1.112 bowersj2 2327: =item * $clientbrowser
1.87 matthew 2328:
1.112 bowersj2 2329: =item * $clientversion
1.87 matthew 2330:
1.112 bowersj2 2331: =item * $clientmathml
1.87 matthew 2332:
1.112 bowersj2 2333: =item * $clientunicode
1.87 matthew 2334:
1.112 bowersj2 2335: =item * $clientos
1.87 matthew 2336:
1.1075.2.42 raeburn 2337: =item * $clientmobile
2338:
2339: =item * $clientinfo
2340:
1.87 matthew 2341: =back
2342:
1.157 matthew 2343: =back
2344:
1.87 matthew 2345: =cut
2346:
2347: ###############################################################
2348: ###############################################################
2349: sub decode_user_agent {
1.247 albertel 2350: my ($r)=@_;
1.87 matthew 2351: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2352: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2353: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2354: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2355: my $clientbrowser='unknown';
2356: my $clientversion='0';
2357: my $clientmathml='';
2358: my $clientunicode='0';
1.1075.2.42 raeburn 2359: my $clientmobile=0;
1.87 matthew 2360: for (my $i=0;$i<=$#browsertype;$i++) {
2361: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2362: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2363: $clientbrowser=$bname;
2364: $httpbrowser=~/$vreg/i;
2365: $clientversion=$1;
2366: $clientmathml=($clientversion>=$minv);
2367: $clientunicode=($clientversion>=$univ);
2368: }
2369: }
2370: my $clientos='unknown';
1.1075.2.42 raeburn 2371: my $clientinfo;
1.87 matthew 2372: if (($httpbrowser=~/linux/i) ||
2373: ($httpbrowser=~/unix/i) ||
2374: ($httpbrowser=~/ux/i) ||
2375: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2376: if (($httpbrowser=~/vax/i) ||
2377: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2378: if ($httpbrowser=~/next/i) { $clientos='next'; }
2379: if (($httpbrowser=~/mac/i) ||
2380: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2381: if ($httpbrowser=~/win/i) { $clientos='win'; }
2382: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2383: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2384: $clientmobile=lc($1);
2385: }
2386: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2387: $clientinfo = 'firefox-'.$1;
2388: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2389: $clientinfo = 'chromeframe-'.$1;
2390: }
1.87 matthew 2391: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.42 raeburn 2392: $clientunicode,$clientos,$clientmobile,$clientinfo);
1.87 matthew 2393: }
2394:
1.32 matthew 2395: ###############################################################
2396: ## Authentication changing form generation subroutines ##
2397: ###############################################################
2398: ##
2399: ## All of the authform_xxxxxxx subroutines take their inputs in a
2400: ## hash, and have reasonable default values.
2401: ##
2402: ## formname = the name given in the <form> tag.
1.35 matthew 2403: #-------------------------------------------
2404:
1.45 matthew 2405: =pod
2406:
1.112 bowersj2 2407: =head1 Authentication Routines
2408:
2409: =over 4
2410:
1.648 raeburn 2411: =item * &authform_xxxxxx()
1.35 matthew 2412:
2413: The authform_xxxxxx subroutines provide javascript and html forms which
2414: handle some of the conveniences required for authentication forms.
2415: This is not an optimal method, but it works.
2416:
2417: =over 4
2418:
1.112 bowersj2 2419: =item * authform_header
1.35 matthew 2420:
1.112 bowersj2 2421: =item * authform_authorwarning
1.35 matthew 2422:
1.112 bowersj2 2423: =item * authform_nochange
1.35 matthew 2424:
1.112 bowersj2 2425: =item * authform_kerberos
1.35 matthew 2426:
1.112 bowersj2 2427: =item * authform_internal
1.35 matthew 2428:
1.112 bowersj2 2429: =item * authform_filesystem
1.35 matthew 2430:
2431: =back
2432:
1.648 raeburn 2433: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2434:
1.35 matthew 2435: =cut
2436:
2437: #-------------------------------------------
1.32 matthew 2438: sub authform_header{
2439: my %in = (
2440: formname => 'cu',
1.80 albertel 2441: kerb_def_dom => '',
1.32 matthew 2442: @_,
2443: );
2444: $in{'formname'} = 'document.' . $in{'formname'};
2445: my $result='';
1.80 albertel 2446:
2447: #---------------------------------------------- Code for upper case translation
2448: my $Javascript_toUpperCase;
2449: unless ($in{kerb_def_dom}) {
2450: $Javascript_toUpperCase =<<"END";
2451: switch (choice) {
2452: case 'krb': currentform.elements[choicearg].value =
2453: currentform.elements[choicearg].value.toUpperCase();
2454: break;
2455: default:
2456: }
2457: END
2458: } else {
2459: $Javascript_toUpperCase = "";
2460: }
2461:
1.165 raeburn 2462: my $radioval = "'nochange'";
1.591 raeburn 2463: if (defined($in{'curr_authtype'})) {
2464: if ($in{'curr_authtype'} ne '') {
2465: $radioval = "'".$in{'curr_authtype'}."arg'";
2466: }
1.174 matthew 2467: }
1.165 raeburn 2468: my $argfield = 'null';
1.591 raeburn 2469: if (defined($in{'mode'})) {
1.165 raeburn 2470: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2471: if (defined($in{'curr_autharg'})) {
2472: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2473: $argfield = "'$in{'curr_autharg'}'";
2474: }
2475: }
2476: }
2477: }
2478:
1.32 matthew 2479: $result.=<<"END";
2480: var current = new Object();
1.165 raeburn 2481: current.radiovalue = $radioval;
2482: current.argfield = $argfield;
1.32 matthew 2483:
2484: function changed_radio(choice,currentform) {
2485: var choicearg = choice + 'arg';
2486: // If a radio button in changed, we need to change the argfield
2487: if (current.radiovalue != choice) {
2488: current.radiovalue = choice;
2489: if (current.argfield != null) {
2490: currentform.elements[current.argfield].value = '';
2491: }
2492: if (choice == 'nochange') {
2493: current.argfield = null;
2494: } else {
2495: current.argfield = choicearg;
2496: switch(choice) {
2497: case 'krb':
2498: currentform.elements[current.argfield].value =
2499: "$in{'kerb_def_dom'}";
2500: break;
2501: default:
2502: break;
2503: }
2504: }
2505: }
2506: return;
2507: }
1.22 www 2508:
1.32 matthew 2509: function changed_text(choice,currentform) {
2510: var choicearg = choice + 'arg';
2511: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2512: $Javascript_toUpperCase
1.32 matthew 2513: // clear old field
2514: if ((current.argfield != choicearg) && (current.argfield != null)) {
2515: currentform.elements[current.argfield].value = '';
2516: }
2517: current.argfield = choicearg;
2518: }
2519: set_auth_radio_buttons(choice,currentform);
2520: return;
1.20 www 2521: }
1.32 matthew 2522:
2523: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2524: var numauthchoices = currentform.login.length;
2525: if (typeof numauthchoices == "undefined") {
2526: return;
2527: }
1.32 matthew 2528: var i=0;
1.986 raeburn 2529: while (i < numauthchoices) {
1.32 matthew 2530: if (currentform.login[i].value == newvalue) { break; }
2531: i++;
2532: }
1.986 raeburn 2533: if (i == numauthchoices) {
1.32 matthew 2534: return;
2535: }
2536: current.radiovalue = newvalue;
2537: currentform.login[i].checked = true;
2538: return;
2539: }
2540: END
2541: return $result;
2542: }
2543:
1.1075.2.20 raeburn 2544: sub authform_authorwarning {
1.32 matthew 2545: my $result='';
1.144 matthew 2546: $result='<i>'.
2547: &mt('As a general rule, only authors or co-authors should be '.
2548: 'filesystem authenticated '.
2549: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2550: return $result;
2551: }
2552:
1.1075.2.20 raeburn 2553: sub authform_nochange {
1.32 matthew 2554: my %in = (
2555: formname => 'document.cu',
2556: kerb_def_dom => 'MSU.EDU',
2557: @_,
2558: );
1.1075.2.20 raeburn 2559: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2560: my $result;
1.1075.2.20 raeburn 2561: if (!$authnum) {
2562: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2563: } else {
2564: $result = '<label>'.&mt('[_1] Do not change login data',
2565: '<input type="radio" name="login" value="nochange" '.
2566: 'checked="checked" onclick="'.
1.281 albertel 2567: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2568: '</label>';
1.586 raeburn 2569: }
1.32 matthew 2570: return $result;
2571: }
2572:
1.591 raeburn 2573: sub authform_kerberos {
1.32 matthew 2574: my %in = (
2575: formname => 'document.cu',
2576: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2577: kerb_def_auth => 'krb4',
1.32 matthew 2578: @_,
2579: );
1.586 raeburn 2580: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2581: $autharg,$jscall);
1.1075.2.20 raeburn 2582: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2583: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2584: $check5 = ' checked="checked"';
1.80 albertel 2585: } else {
1.772 bisitz 2586: $check4 = ' checked="checked"';
1.80 albertel 2587: }
1.165 raeburn 2588: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2589: if (defined($in{'curr_authtype'})) {
2590: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2591: $krbcheck = ' checked="checked"';
1.623 raeburn 2592: if (defined($in{'mode'})) {
2593: if ($in{'mode'} eq 'modifyuser') {
2594: $krbcheck = '';
2595: }
2596: }
1.591 raeburn 2597: if (defined($in{'curr_kerb_ver'})) {
2598: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2599: $check5 = ' checked="checked"';
1.591 raeburn 2600: $check4 = '';
2601: } else {
1.772 bisitz 2602: $check4 = ' checked="checked"';
1.591 raeburn 2603: $check5 = '';
2604: }
1.586 raeburn 2605: }
1.591 raeburn 2606: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2607: $krbarg = $in{'curr_autharg'};
2608: }
1.586 raeburn 2609: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2610: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2611: $result =
2612: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2613: $in{'curr_autharg'},$krbver);
2614: } else {
2615: $result =
2616: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2617: }
2618: return $result;
2619: }
2620: }
2621: } else {
2622: if ($authnum == 1) {
1.784 bisitz 2623: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2624: }
2625: }
1.586 raeburn 2626: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2627: return;
1.587 raeburn 2628: } elsif ($authtype eq '') {
1.591 raeburn 2629: if (defined($in{'mode'})) {
1.587 raeburn 2630: if ($in{'mode'} eq 'modifycourse') {
2631: if ($authnum == 1) {
1.1075.2.20 raeburn 2632: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2633: }
2634: }
2635: }
1.586 raeburn 2636: }
2637: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2638: if ($authtype eq '') {
2639: $authtype = '<input type="radio" name="login" value="krb" '.
2640: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2641: $krbcheck.' />';
2642: }
2643: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2644: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2645: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2646: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2647: $in{'curr_authtype'} eq 'krb4')) {
2648: $result .= &mt
1.144 matthew 2649: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2650: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2651: '<label>'.$authtype,
1.281 albertel 2652: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2653: 'value="'.$krbarg.'" '.
1.144 matthew 2654: 'onchange="'.$jscall.'" />',
1.281 albertel 2655: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2656: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2657: '</label>');
1.586 raeburn 2658: } elsif ($can_assign{'krb4'}) {
2659: $result .= &mt
2660: ('[_1] Kerberos authenticated with domain [_2] '.
2661: '[_3] Version 4 [_4]',
2662: '<label>'.$authtype,
2663: '</label><input type="text" size="10" name="krbarg" '.
2664: 'value="'.$krbarg.'" '.
2665: 'onchange="'.$jscall.'" />',
2666: '<label><input type="hidden" name="krbver" value="4" />',
2667: '</label>');
2668: } elsif ($can_assign{'krb5'}) {
2669: $result .= &mt
2670: ('[_1] Kerberos authenticated with domain [_2] '.
2671: '[_3] Version 5 [_4]',
2672: '<label>'.$authtype,
2673: '</label><input type="text" size="10" name="krbarg" '.
2674: 'value="'.$krbarg.'" '.
2675: 'onchange="'.$jscall.'" />',
2676: '<label><input type="hidden" name="krbver" value="5" />',
2677: '</label>');
2678: }
1.32 matthew 2679: return $result;
2680: }
2681:
1.1075.2.20 raeburn 2682: sub authform_internal {
1.586 raeburn 2683: my %in = (
1.32 matthew 2684: formname => 'document.cu',
2685: kerb_def_dom => 'MSU.EDU',
2686: @_,
2687: );
1.586 raeburn 2688: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2689: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2690: if (defined($in{'curr_authtype'})) {
2691: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2692: if ($can_assign{'int'}) {
1.772 bisitz 2693: $intcheck = 'checked="checked" ';
1.623 raeburn 2694: if (defined($in{'mode'})) {
2695: if ($in{'mode'} eq 'modifyuser') {
2696: $intcheck = '';
2697: }
2698: }
1.591 raeburn 2699: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2700: $intarg = $in{'curr_autharg'};
2701: }
2702: } else {
2703: $result = &mt('Currently internally authenticated.');
2704: return $result;
1.165 raeburn 2705: }
2706: }
1.586 raeburn 2707: } else {
2708: if ($authnum == 1) {
1.784 bisitz 2709: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2710: }
2711: }
2712: if (!$can_assign{'int'}) {
2713: return;
1.587 raeburn 2714: } elsif ($authtype eq '') {
1.591 raeburn 2715: if (defined($in{'mode'})) {
1.587 raeburn 2716: if ($in{'mode'} eq 'modifycourse') {
2717: if ($authnum == 1) {
1.1075.2.20 raeburn 2718: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2719: }
2720: }
2721: }
1.165 raeburn 2722: }
1.586 raeburn 2723: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2724: if ($authtype eq '') {
2725: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2726: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2727: }
1.605 bisitz 2728: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2729: $intarg.'" onchange="'.$jscall.'" />';
2730: $result = &mt
1.144 matthew 2731: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2732: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2733: $result.="<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32 matthew 2734: return $result;
2735: }
2736:
1.1075.2.20 raeburn 2737: sub authform_local {
1.32 matthew 2738: my %in = (
2739: formname => 'document.cu',
2740: kerb_def_dom => 'MSU.EDU',
2741: @_,
2742: );
1.586 raeburn 2743: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2744: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2745: if (defined($in{'curr_authtype'})) {
2746: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2747: if ($can_assign{'loc'}) {
1.772 bisitz 2748: $loccheck = 'checked="checked" ';
1.623 raeburn 2749: if (defined($in{'mode'})) {
2750: if ($in{'mode'} eq 'modifyuser') {
2751: $loccheck = '';
2752: }
2753: }
1.591 raeburn 2754: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2755: $locarg = $in{'curr_autharg'};
2756: }
2757: } else {
2758: $result = &mt('Currently using local (institutional) authentication.');
2759: return $result;
1.165 raeburn 2760: }
2761: }
1.586 raeburn 2762: } else {
2763: if ($authnum == 1) {
1.784 bisitz 2764: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2765: }
2766: }
2767: if (!$can_assign{'loc'}) {
2768: return;
1.587 raeburn 2769: } elsif ($authtype eq '') {
1.591 raeburn 2770: if (defined($in{'mode'})) {
1.587 raeburn 2771: if ($in{'mode'} eq 'modifycourse') {
2772: if ($authnum == 1) {
1.1075.2.20 raeburn 2773: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 2774: }
2775: }
2776: }
1.165 raeburn 2777: }
1.586 raeburn 2778: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2779: if ($authtype eq '') {
2780: $authtype = '<input type="radio" name="login" value="loc" '.
2781: $loccheck.' onchange="'.$jscall.'" onclick="'.
2782: $jscall.'" />';
2783: }
2784: $autharg = '<input type="text" size="10" name="locarg" value="'.
2785: $locarg.'" onchange="'.$jscall.'" />';
2786: $result = &mt('[_1] Local Authentication with argument [_2]',
2787: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2788: return $result;
2789: }
2790:
1.1075.2.20 raeburn 2791: sub authform_filesystem {
1.32 matthew 2792: my %in = (
2793: formname => 'document.cu',
2794: kerb_def_dom => 'MSU.EDU',
2795: @_,
2796: );
1.586 raeburn 2797: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2798: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2799: if (defined($in{'curr_authtype'})) {
2800: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2801: if ($can_assign{'fsys'}) {
1.772 bisitz 2802: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2803: if (defined($in{'mode'})) {
2804: if ($in{'mode'} eq 'modifyuser') {
2805: $fsyscheck = '';
2806: }
2807: }
1.586 raeburn 2808: } else {
2809: $result = &mt('Currently Filesystem Authenticated.');
2810: return $result;
2811: }
2812: }
2813: } else {
2814: if ($authnum == 1) {
1.784 bisitz 2815: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2816: }
2817: }
2818: if (!$can_assign{'fsys'}) {
2819: return;
1.587 raeburn 2820: } elsif ($authtype eq '') {
1.591 raeburn 2821: if (defined($in{'mode'})) {
1.587 raeburn 2822: if ($in{'mode'} eq 'modifycourse') {
2823: if ($authnum == 1) {
1.1075.2.20 raeburn 2824: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 2825: }
2826: }
2827: }
1.586 raeburn 2828: }
2829: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2830: if ($authtype eq '') {
2831: $authtype = '<input type="radio" name="login" value="fsys" '.
2832: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2833: $jscall.'" />';
2834: }
2835: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2836: ' onchange="'.$jscall.'" />';
2837: $result = &mt
1.144 matthew 2838: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2839: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2840: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2841: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2842: 'onchange="'.$jscall.'" />');
1.32 matthew 2843: return $result;
2844: }
2845:
1.586 raeburn 2846: sub get_assignable_auth {
2847: my ($dom) = @_;
2848: if ($dom eq '') {
2849: $dom = $env{'request.role.domain'};
2850: }
2851: my %can_assign = (
2852: krb4 => 1,
2853: krb5 => 1,
2854: int => 1,
2855: loc => 1,
2856: );
2857: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2858: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2859: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2860: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2861: my $context;
2862: if ($env{'request.role'} =~ /^au/) {
2863: $context = 'author';
2864: } elsif ($env{'request.role'} =~ /^dc/) {
2865: $context = 'domain';
2866: } elsif ($env{'request.course.id'}) {
2867: $context = 'course';
2868: }
2869: if ($context) {
2870: if (ref($authhash->{$context}) eq 'HASH') {
2871: %can_assign = %{$authhash->{$context}};
2872: }
2873: }
2874: }
2875: }
2876: my $authnum = 0;
2877: foreach my $key (keys(%can_assign)) {
2878: if ($can_assign{$key}) {
2879: $authnum ++;
2880: }
2881: }
2882: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2883: $authnum --;
2884: }
2885: return ($authnum,%can_assign);
2886: }
2887:
1.80 albertel 2888: ###############################################################
2889: ## Get Kerberos Defaults for Domain ##
2890: ###############################################################
2891: ##
2892: ## Returns default kerberos version and an associated argument
2893: ## as listed in file domain.tab. If not listed, provides
2894: ## appropriate default domain and kerberos version.
2895: ##
2896: #-------------------------------------------
2897:
2898: =pod
2899:
1.648 raeburn 2900: =item * &get_kerberos_defaults()
1.80 albertel 2901:
2902: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2903: version and domain. If not found, it defaults to version 4 and the
2904: domain of the server.
1.80 albertel 2905:
1.648 raeburn 2906: =over 4
2907:
1.80 albertel 2908: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2909:
1.648 raeburn 2910: =back
2911:
2912: =back
2913:
1.80 albertel 2914: =cut
2915:
2916: #-------------------------------------------
2917: sub get_kerberos_defaults {
2918: my $domain=shift;
1.641 raeburn 2919: my ($krbdef,$krbdefdom);
2920: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2921: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2922: $krbdef = $domdefaults{'auth_def'};
2923: $krbdefdom = $domdefaults{'auth_arg_def'};
2924: } else {
1.80 albertel 2925: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2926: my $krbdefdom=$1;
2927: $krbdefdom=~tr/a-z/A-Z/;
2928: $krbdef = "krb4";
2929: }
2930: return ($krbdef,$krbdefdom);
2931: }
1.112 bowersj2 2932:
1.32 matthew 2933:
1.46 matthew 2934: ###############################################################
2935: ## Thesaurus Functions ##
2936: ###############################################################
1.20 www 2937:
1.46 matthew 2938: =pod
1.20 www 2939:
1.112 bowersj2 2940: =head1 Thesaurus Functions
2941:
2942: =over 4
2943:
1.648 raeburn 2944: =item * &initialize_keywords()
1.46 matthew 2945:
2946: Initializes the package variable %Keywords if it is empty. Uses the
2947: package variable $thesaurus_db_file.
2948:
2949: =cut
2950:
2951: ###################################################
2952:
2953: sub initialize_keywords {
2954: return 1 if (scalar keys(%Keywords));
2955: # If we are here, %Keywords is empty, so fill it up
2956: # Make sure the file we need exists...
2957: if (! -e $thesaurus_db_file) {
2958: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2959: " failed because it does not exist");
2960: return 0;
2961: }
2962: # Set up the hash as a database
2963: my %thesaurus_db;
2964: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2965: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2966: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2967: $thesaurus_db_file);
2968: return 0;
2969: }
2970: # Get the average number of appearances of a word.
2971: my $avecount = $thesaurus_db{'average.count'};
2972: # Put keywords (those that appear > average) into %Keywords
2973: while (my ($word,$data)=each (%thesaurus_db)) {
2974: my ($count,undef) = split /:/,$data;
2975: $Keywords{$word}++ if ($count > $avecount);
2976: }
2977: untie %thesaurus_db;
2978: # Remove special values from %Keywords.
1.356 albertel 2979: foreach my $value ('total.count','average.count') {
2980: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2981: }
1.46 matthew 2982: return 1;
2983: }
2984:
2985: ###################################################
2986:
2987: =pod
2988:
1.648 raeburn 2989: =item * &keyword($word)
1.46 matthew 2990:
2991: Returns true if $word is a keyword. A keyword is a word that appears more
2992: than the average number of times in the thesaurus database. Calls
2993: &initialize_keywords
2994:
2995: =cut
2996:
2997: ###################################################
1.20 www 2998:
2999: sub keyword {
1.46 matthew 3000: return if (!&initialize_keywords());
3001: my $word=lc(shift());
3002: $word=~s/\W//g;
3003: return exists($Keywords{$word});
1.20 www 3004: }
1.46 matthew 3005:
3006: ###############################################################
3007:
3008: =pod
1.20 www 3009:
1.648 raeburn 3010: =item * &get_related_words()
1.46 matthew 3011:
1.160 matthew 3012: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3013: an array of words. If the keyword is not in the thesaurus, an empty array
3014: will be returned. The order of the words returned is determined by the
3015: database which holds them.
3016:
3017: Uses global $thesaurus_db_file.
3018:
1.1057 foxr 3019:
1.46 matthew 3020: =cut
3021:
3022: ###############################################################
3023: sub get_related_words {
3024: my $keyword = shift;
3025: my %thesaurus_db;
3026: if (! -e $thesaurus_db_file) {
3027: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3028: "failed because the file does not exist");
3029: return ();
3030: }
3031: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3032: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3033: return ();
3034: }
3035: my @Words=();
1.429 www 3036: my $count=0;
1.46 matthew 3037: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3038: # The first element is the number of times
3039: # the word appears. We do not need it now.
1.429 www 3040: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3041: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3042: my $threshold=$mostfrequentcount/10;
3043: foreach my $possibleword (@RelatedWords) {
3044: my ($word,$wordcount)=split(/\,/,$possibleword);
3045: if ($wordcount>$threshold) {
3046: push(@Words,$word);
3047: $count++;
3048: if ($count>10) { last; }
3049: }
1.20 www 3050: }
3051: }
1.46 matthew 3052: untie %thesaurus_db;
3053: return @Words;
1.14 harris41 3054: }
1.46 matthew 3055:
1.112 bowersj2 3056: =pod
3057:
3058: =back
3059:
3060: =cut
1.61 www 3061:
3062: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3063: =pod
3064:
1.112 bowersj2 3065: =head1 User Name Functions
3066:
3067: =over 4
3068:
1.648 raeburn 3069: =item * &plainname($uname,$udom,$first)
1.81 albertel 3070:
1.112 bowersj2 3071: Takes a users logon name and returns it as a string in
1.226 albertel 3072: "first middle last generation" form
3073: if $first is set to 'lastname' then it returns it as
3074: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3075:
3076: =cut
1.61 www 3077:
1.295 www 3078:
1.81 albertel 3079: ###############################################################
1.61 www 3080: sub plainname {
1.226 albertel 3081: my ($uname,$udom,$first)=@_;
1.537 albertel 3082: return if (!defined($uname) || !defined($udom));
1.295 www 3083: my %names=&getnames($uname,$udom);
1.226 albertel 3084: my $name=&Apache::lonnet::format_name($names{'firstname'},
3085: $names{'middlename'},
3086: $names{'lastname'},
3087: $names{'generation'},$first);
3088: $name=~s/^\s+//;
1.62 www 3089: $name=~s/\s+$//;
3090: $name=~s/\s+/ /g;
1.353 albertel 3091: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3092: return $name;
1.61 www 3093: }
1.66 www 3094:
3095: # -------------------------------------------------------------------- Nickname
1.81 albertel 3096: =pod
3097:
1.648 raeburn 3098: =item * &nickname($uname,$udom)
1.81 albertel 3099:
3100: Gets a users name and returns it as a string as
3101:
3102: ""nickname""
1.66 www 3103:
1.81 albertel 3104: if the user has a nickname or
3105:
3106: "first middle last generation"
3107:
3108: if the user does not
3109:
3110: =cut
1.66 www 3111:
3112: sub nickname {
3113: my ($uname,$udom)=@_;
1.537 albertel 3114: return if (!defined($uname) || !defined($udom));
1.295 www 3115: my %names=&getnames($uname,$udom);
1.68 albertel 3116: my $name=$names{'nickname'};
1.66 www 3117: if ($name) {
3118: $name='"'.$name.'"';
3119: } else {
3120: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3121: $names{'lastname'}.' '.$names{'generation'};
3122: $name=~s/\s+$//;
3123: $name=~s/\s+/ /g;
3124: }
3125: return $name;
3126: }
3127:
1.295 www 3128: sub getnames {
3129: my ($uname,$udom)=@_;
1.537 albertel 3130: return if (!defined($uname) || !defined($udom));
1.433 albertel 3131: if ($udom eq 'public' && $uname eq 'public') {
3132: return ('lastname' => &mt('Public'));
3133: }
1.295 www 3134: my $id=$uname.':'.$udom;
3135: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3136: if ($cached) {
3137: return %{$names};
3138: } else {
3139: my %loadnames=&Apache::lonnet::get('environment',
3140: ['firstname','middlename','lastname','generation','nickname'],
3141: $udom,$uname);
3142: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3143: return %loadnames;
3144: }
3145: }
1.61 www 3146:
1.542 raeburn 3147: # -------------------------------------------------------------------- getemails
1.648 raeburn 3148:
1.542 raeburn 3149: =pod
3150:
1.648 raeburn 3151: =item * &getemails($uname,$udom)
1.542 raeburn 3152:
3153: Gets a user's email information and returns it as a hash with keys:
3154: notification, critnotification, permanentemail
3155:
3156: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3157: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3158:
1.648 raeburn 3159:
1.542 raeburn 3160: =cut
3161:
1.648 raeburn 3162:
1.466 albertel 3163: sub getemails {
3164: my ($uname,$udom)=@_;
3165: if ($udom eq 'public' && $uname eq 'public') {
3166: return;
3167: }
1.467 www 3168: if (!$udom) { $udom=$env{'user.domain'}; }
3169: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3170: my $id=$uname.':'.$udom;
3171: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3172: if ($cached) {
3173: return %{$names};
3174: } else {
3175: my %loadnames=&Apache::lonnet::get('environment',
3176: ['notification','critnotification',
3177: 'permanentemail'],
3178: $udom,$uname);
3179: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3180: return %loadnames;
3181: }
3182: }
3183:
1.551 albertel 3184: sub flush_email_cache {
3185: my ($uname,$udom)=@_;
3186: if (!$udom) { $udom =$env{'user.domain'}; }
3187: if (!$uname) { $uname=$env{'user.name'}; }
3188: return if ($udom eq 'public' && $uname eq 'public');
3189: my $id=$uname.':'.$udom;
3190: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3191: }
3192:
1.728 raeburn 3193: # -------------------------------------------------------------------- getlangs
3194:
3195: =pod
3196:
3197: =item * &getlangs($uname,$udom)
3198:
3199: Gets a user's language preference and returns it as a hash with key:
3200: language.
3201:
3202: =cut
3203:
3204:
3205: sub getlangs {
3206: my ($uname,$udom) = @_;
3207: if (!$udom) { $udom =$env{'user.domain'}; }
3208: if (!$uname) { $uname=$env{'user.name'}; }
3209: my $id=$uname.':'.$udom;
3210: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3211: if ($cached) {
3212: return %{$langs};
3213: } else {
3214: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3215: $udom,$uname);
3216: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3217: return %loadlangs;
3218: }
3219: }
3220:
3221: sub flush_langs_cache {
3222: my ($uname,$udom)=@_;
3223: if (!$udom) { $udom =$env{'user.domain'}; }
3224: if (!$uname) { $uname=$env{'user.name'}; }
3225: return if ($udom eq 'public' && $uname eq 'public');
3226: my $id=$uname.':'.$udom;
3227: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3228: }
3229:
1.61 www 3230: # ------------------------------------------------------------------ Screenname
1.81 albertel 3231:
3232: =pod
3233:
1.648 raeburn 3234: =item * &screenname($uname,$udom)
1.81 albertel 3235:
3236: Gets a users screenname and returns it as a string
3237:
3238: =cut
1.61 www 3239:
3240: sub screenname {
3241: my ($uname,$udom)=@_;
1.258 albertel 3242: if ($uname eq $env{'user.name'} &&
3243: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3244: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3245: return $names{'screenname'};
1.62 www 3246: }
3247:
1.212 albertel 3248:
1.802 bisitz 3249: # ------------------------------------------------------------- Confirm Wrapper
3250: =pod
3251:
1.1075.2.42 raeburn 3252: =item * &confirmwrapper($message)
1.802 bisitz 3253:
3254: Wrap messages about completion of operation in box
3255:
3256: =cut
3257:
3258: sub confirmwrapper {
3259: my ($message)=@_;
3260: if ($message) {
3261: return "\n".'<div class="LC_confirm_box">'."\n"
3262: .$message."\n"
3263: .'</div>'."\n";
3264: } else {
3265: return $message;
3266: }
3267: }
3268:
1.62 www 3269: # ------------------------------------------------------------- Message Wrapper
3270:
3271: sub messagewrapper {
1.369 www 3272: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3273: return
1.441 albertel 3274: '<a href="/adm/email?compose=individual&'.
3275: 'recname='.$username.'&recdom='.$domain.
3276: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3277: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3278: }
1.802 bisitz 3279:
1.74 www 3280: # --------------------------------------------------------------- Notes Wrapper
3281:
3282: sub noteswrapper {
3283: my ($link,$un,$do)=@_;
3284: return
1.896 amueller 3285: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3286: }
1.802 bisitz 3287:
1.62 www 3288: # ------------------------------------------------------------- Aboutme Wrapper
3289:
3290: sub aboutmewrapper {
1.1070 raeburn 3291: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3292: if (!defined($username) && !defined($domain)) {
3293: return;
3294: }
1.1075.2.15 raeburn 3295: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3296: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3297: }
3298:
3299: # ------------------------------------------------------------ Syllabus Wrapper
3300:
3301: sub syllabuswrapper {
1.707 bisitz 3302: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3303: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3304: }
1.14 harris41 3305:
1.802 bisitz 3306: # -----------------------------------------------------------------------------
3307:
1.208 matthew 3308: sub track_student_link {
1.887 raeburn 3309: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3310: my $link ="/adm/trackstudent?";
1.208 matthew 3311: my $title = 'View recent activity';
3312: if (defined($sname) && $sname !~ /^\s*$/ &&
3313: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3314: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3315: $title .= ' of this student';
1.268 albertel 3316: }
1.208 matthew 3317: if (defined($target) && $target !~ /^\s*$/) {
3318: $target = qq{target="$target"};
3319: } else {
3320: $target = '';
3321: }
1.268 albertel 3322: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3323: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3324: $title = &mt($title);
3325: $linktext = &mt($linktext);
1.448 albertel 3326: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3327: &help_open_topic('View_recent_activity');
1.208 matthew 3328: }
3329:
1.781 raeburn 3330: sub slot_reservations_link {
3331: my ($linktext,$sname,$sdom,$target) = @_;
3332: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3333: my $title = 'View slot reservation history';
3334: if (defined($sname) && $sname !~ /^\s*$/ &&
3335: defined($sdom) && $sdom !~ /^\s*$/) {
3336: $link .= "&uname=$sname&udom=$sdom";
3337: $title .= ' of this student';
3338: }
3339: if (defined($target) && $target !~ /^\s*$/) {
3340: $target = qq{target="$target"};
3341: } else {
3342: $target = '';
3343: }
3344: $title = &mt($title);
3345: $linktext = &mt($linktext);
3346: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3347: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3348:
3349: }
3350:
1.508 www 3351: # ===================================================== Display a student photo
3352:
3353:
1.509 albertel 3354: sub student_image_tag {
1.508 www 3355: my ($domain,$user)=@_;
3356: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3357: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3358: return '<img src="'.$imgsrc.'" align="right" />';
3359: } else {
3360: return '';
3361: }
3362: }
3363:
1.112 bowersj2 3364: =pod
3365:
3366: =back
3367:
3368: =head1 Access .tab File Data
3369:
3370: =over 4
3371:
1.648 raeburn 3372: =item * &languageids()
1.112 bowersj2 3373:
3374: returns list of all language ids
3375:
3376: =cut
3377:
1.14 harris41 3378: sub languageids {
1.16 harris41 3379: return sort(keys(%language));
1.14 harris41 3380: }
3381:
1.112 bowersj2 3382: =pod
3383:
1.648 raeburn 3384: =item * &languagedescription()
1.112 bowersj2 3385:
3386: returns description of a specified language id
3387:
3388: =cut
3389:
1.14 harris41 3390: sub languagedescription {
1.125 www 3391: my $code=shift;
3392: return ($supported_language{$code}?'* ':'').
3393: $language{$code}.
1.126 www 3394: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3395: }
3396:
1.1048 foxr 3397: =pod
3398:
3399: =item * &plainlanguagedescription
3400:
3401: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3402: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3403:
3404: =cut
3405:
1.145 www 3406: sub plainlanguagedescription {
3407: my $code=shift;
3408: return $language{$code};
3409: }
3410:
1.1048 foxr 3411: =pod
3412:
3413: =item * &supportedlanguagecode
3414:
3415: Returns the supported language code (e.g. sptutf maps to pt) given a language
3416: code.
3417:
3418: =cut
3419:
1.145 www 3420: sub supportedlanguagecode {
3421: my $code=shift;
3422: return $supported_language{$code};
1.97 www 3423: }
3424:
1.112 bowersj2 3425: =pod
3426:
1.1048 foxr 3427: =item * &latexlanguage()
3428:
3429: Given a language key code returns the correspondnig language to use
3430: to select the correct hyphenation on LaTeX printouts. This is undef if there
3431: is no supported hyphenation for the language code.
3432:
3433: =cut
3434:
3435: sub latexlanguage {
3436: my $code = shift;
3437: return $latex_language{$code};
3438: }
3439:
3440: =pod
3441:
3442: =item * &latexhyphenation()
3443:
3444: Same as above but what's supplied is the language as it might be stored
3445: in the metadata.
3446:
3447: =cut
3448:
3449: sub latexhyphenation {
3450: my $key = shift;
3451: return $latex_language_bykey{$key};
3452: }
3453:
3454: =pod
3455:
1.648 raeburn 3456: =item * ©rightids()
1.112 bowersj2 3457:
3458: returns list of all copyrights
3459:
3460: =cut
3461:
3462: sub copyrightids {
3463: return sort(keys(%cprtag));
3464: }
3465:
3466: =pod
3467:
1.648 raeburn 3468: =item * ©rightdescription()
1.112 bowersj2 3469:
3470: returns description of a specified copyright id
3471:
3472: =cut
3473:
3474: sub copyrightdescription {
1.166 www 3475: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3476: }
1.197 matthew 3477:
3478: =pod
3479:
1.648 raeburn 3480: =item * &source_copyrightids()
1.192 taceyjo1 3481:
3482: returns list of all source copyrights
3483:
3484: =cut
3485:
3486: sub source_copyrightids {
3487: return sort(keys(%scprtag));
3488: }
3489:
3490: =pod
3491:
1.648 raeburn 3492: =item * &source_copyrightdescription()
1.192 taceyjo1 3493:
3494: returns description of a specified source copyright id
3495:
3496: =cut
3497:
3498: sub source_copyrightdescription {
3499: return &mt($scprtag{shift(@_)});
3500: }
1.112 bowersj2 3501:
3502: =pod
3503:
1.648 raeburn 3504: =item * &filecategories()
1.112 bowersj2 3505:
3506: returns list of all file categories
3507:
3508: =cut
3509:
3510: sub filecategories {
3511: return sort(keys(%category_extensions));
3512: }
3513:
3514: =pod
3515:
1.648 raeburn 3516: =item * &filecategorytypes()
1.112 bowersj2 3517:
3518: returns list of file types belonging to a given file
3519: category
3520:
3521: =cut
3522:
3523: sub filecategorytypes {
1.356 albertel 3524: my ($cat) = @_;
3525: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3526: }
3527:
3528: =pod
3529:
1.648 raeburn 3530: =item * &fileembstyle()
1.112 bowersj2 3531:
3532: returns embedding style for a specified file type
3533:
3534: =cut
3535:
3536: sub fileembstyle {
3537: return $fe{lc(shift(@_))};
1.169 www 3538: }
3539:
1.351 www 3540: sub filemimetype {
3541: return $fm{lc(shift(@_))};
3542: }
3543:
1.169 www 3544:
3545: sub filecategoryselect {
3546: my ($name,$value)=@_;
1.189 matthew 3547: return &select_form($value,$name,
1.970 raeburn 3548: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3549: }
3550:
3551: =pod
3552:
1.648 raeburn 3553: =item * &filedescription()
1.112 bowersj2 3554:
3555: returns description for a specified file type
3556:
3557: =cut
3558:
3559: sub filedescription {
1.188 matthew 3560: my $file_description = $fd{lc(shift())};
3561: $file_description =~ s:([\[\]]):~$1:g;
3562: return &mt($file_description);
1.112 bowersj2 3563: }
3564:
3565: =pod
3566:
1.648 raeburn 3567: =item * &filedescriptionex()
1.112 bowersj2 3568:
3569: returns description for a specified file type with
3570: extra formatting
3571:
3572: =cut
3573:
3574: sub filedescriptionex {
3575: my $ex=shift;
1.188 matthew 3576: my $file_description = $fd{lc($ex)};
3577: $file_description =~ s:([\[\]]):~$1:g;
3578: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3579: }
3580:
3581: # End of .tab access
3582: =pod
3583:
3584: =back
3585:
3586: =cut
3587:
3588: # ------------------------------------------------------------------ File Types
3589: sub fileextensions {
3590: return sort(keys(%fe));
3591: }
3592:
1.97 www 3593: # ----------------------------------------------------------- Display Languages
3594: # returns a hash with all desired display languages
3595: #
3596:
3597: sub display_languages {
3598: my %languages=();
1.695 raeburn 3599: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3600: $languages{$lang}=1;
1.97 www 3601: }
3602: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3603: if ($env{'form.displaylanguage'}) {
1.356 albertel 3604: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3605: $languages{$lang}=1;
1.97 www 3606: }
3607: }
3608: return %languages;
1.14 harris41 3609: }
3610:
1.582 albertel 3611: sub languages {
3612: my ($possible_langs) = @_;
1.695 raeburn 3613: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3614: if (!ref($possible_langs)) {
3615: if( wantarray ) {
3616: return @preferred_langs;
3617: } else {
3618: return $preferred_langs[0];
3619: }
3620: }
3621: my %possibilities = map { $_ => 1 } (@$possible_langs);
3622: my @preferred_possibilities;
3623: foreach my $preferred_lang (@preferred_langs) {
3624: if (exists($possibilities{$preferred_lang})) {
3625: push(@preferred_possibilities, $preferred_lang);
3626: }
3627: }
3628: if( wantarray ) {
3629: return @preferred_possibilities;
3630: }
3631: return $preferred_possibilities[0];
3632: }
3633:
1.742 raeburn 3634: sub user_lang {
3635: my ($touname,$toudom,$fromcid) = @_;
3636: my @userlangs;
3637: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3638: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3639: $env{'course.'.$fromcid.'.languages'}));
3640: } else {
3641: my %langhash = &getlangs($touname,$toudom);
3642: if ($langhash{'languages'} ne '') {
3643: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3644: } else {
3645: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3646: if ($domdefs{'lang_def'} ne '') {
3647: @userlangs = ($domdefs{'lang_def'});
3648: }
3649: }
3650: }
3651: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3652: my $user_lh = Apache::localize->get_handle(@languages);
3653: return $user_lh;
3654: }
3655:
3656:
1.112 bowersj2 3657: ###############################################################
3658: ## Student Answer Attempts ##
3659: ###############################################################
3660:
3661: =pod
3662:
3663: =head1 Alternate Problem Views
3664:
3665: =over 4
3666:
1.648 raeburn 3667: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3668: $getattempt, $regexp, $gradesub)
3669:
3670: Return string with previous attempt on problem. Arguments:
3671:
3672: =over 4
3673:
3674: =item * $symb: Problem, including path
3675:
3676: =item * $username: username of the desired student
3677:
3678: =item * $domain: domain of the desired student
1.14 harris41 3679:
1.112 bowersj2 3680: =item * $course: Course ID
1.14 harris41 3681:
1.112 bowersj2 3682: =item * $getattempt: Leave blank for all attempts, otherwise put
3683: something
1.14 harris41 3684:
1.112 bowersj2 3685: =item * $regexp: if string matches this regexp, the string will be
3686: sent to $gradesub
1.14 harris41 3687:
1.112 bowersj2 3688: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3689:
1.112 bowersj2 3690: =back
1.14 harris41 3691:
1.112 bowersj2 3692: The output string is a table containing all desired attempts, if any.
1.16 harris41 3693:
1.112 bowersj2 3694: =cut
1.1 albertel 3695:
3696: sub get_previous_attempt {
1.43 ng 3697: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3698: my $prevattempts='';
1.43 ng 3699: no strict 'refs';
1.1 albertel 3700: if ($symb) {
1.3 albertel 3701: my (%returnhash)=
3702: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3703: if ($returnhash{'version'}) {
3704: my %lasthash=();
3705: my $version;
3706: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3707: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3708: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3709: }
1.1 albertel 3710: }
1.596 albertel 3711: $prevattempts=&start_data_table().&start_data_table_header_row();
3712: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3713: my (%typeparts,%lasthidden);
1.945 raeburn 3714: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3715: foreach my $key (sort(keys(%lasthash))) {
3716: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3717: if ($#parts > 0) {
1.31 albertel 3718: my $data=$parts[-1];
1.989 raeburn 3719: next if ($data eq 'foilorder');
1.31 albertel 3720: pop(@parts);
1.1010 www 3721: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3722: if ($data eq 'type') {
3723: unless ($showsurv) {
3724: my $id = join(',',@parts);
3725: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3726: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3727: $lasthidden{$ign.'.'.$id} = 1;
3728: }
1.945 raeburn 3729: }
1.1010 www 3730: }
1.31 albertel 3731: } else {
1.41 ng 3732: if ($#parts == 0) {
3733: $prevattempts.='<th>'.$parts[0].'</th>';
3734: } else {
3735: $prevattempts.='<th>'.$ign.'</th>';
3736: }
1.31 albertel 3737: }
1.16 harris41 3738: }
1.596 albertel 3739: $prevattempts.=&end_data_table_header_row();
1.40 ng 3740: if ($getattempt eq '') {
3741: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3742: my @hidden;
3743: if (%typeparts) {
3744: foreach my $id (keys(%typeparts)) {
3745: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3746: push(@hidden,$id);
3747: }
3748: }
3749: }
3750: $prevattempts.=&start_data_table_row().
3751: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3752: if (@hidden) {
3753: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3754: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3755: my $hide;
3756: foreach my $id (@hidden) {
3757: if ($key =~ /^\Q$id\E/) {
3758: $hide = 1;
3759: last;
3760: }
3761: }
3762: if ($hide) {
3763: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3764: if (($data eq 'award') || ($data eq 'awarddetail')) {
3765: my $value = &format_previous_attempt_value($key,
3766: $returnhash{$version.':'.$key});
3767: $prevattempts.='<td>'.$value.' </td>';
3768: } else {
3769: $prevattempts.='<td> </td>';
3770: }
3771: } else {
3772: if ($key =~ /\./) {
3773: my $value = &format_previous_attempt_value($key,
3774: $returnhash{$version.':'.$key});
3775: $prevattempts.='<td>'.$value.' </td>';
3776: } else {
3777: $prevattempts.='<td> </td>';
3778: }
3779: }
3780: }
3781: } else {
3782: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3783: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3784: my $value = &format_previous_attempt_value($key,
3785: $returnhash{$version.':'.$key});
3786: $prevattempts.='<td>'.$value.' </td>';
3787: }
3788: }
3789: $prevattempts.=&end_data_table_row();
1.40 ng 3790: }
1.1 albertel 3791: }
1.945 raeburn 3792: my @currhidden = keys(%lasthidden);
1.596 albertel 3793: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3794: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3795: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3796: if (%typeparts) {
3797: my $hidden;
3798: foreach my $id (@currhidden) {
3799: if ($key =~ /^\Q$id\E/) {
3800: $hidden = 1;
3801: last;
3802: }
3803: }
3804: if ($hidden) {
3805: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3806: if (($data eq 'award') || ($data eq 'awarddetail')) {
3807: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3808: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3809: $value = &$gradesub($value);
3810: }
3811: $prevattempts.='<td>'.$value.' </td>';
3812: } else {
3813: $prevattempts.='<td> </td>';
3814: }
3815: } else {
3816: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3817: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3818: $value = &$gradesub($value);
3819: }
3820: $prevattempts.='<td>'.$value.' </td>';
3821: }
3822: } else {
3823: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3824: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3825: $value = &$gradesub($value);
3826: }
3827: $prevattempts.='<td>'.$value.' </td>';
3828: }
1.16 harris41 3829: }
1.596 albertel 3830: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3831: } else {
1.596 albertel 3832: $prevattempts=
3833: &start_data_table().&start_data_table_row().
3834: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3835: &end_data_table_row().&end_data_table();
1.1 albertel 3836: }
3837: } else {
1.596 albertel 3838: $prevattempts=
3839: &start_data_table().&start_data_table_row().
3840: '<td>'.&mt('No data.').'</td>'.
3841: &end_data_table_row().&end_data_table();
1.1 albertel 3842: }
1.10 albertel 3843: }
3844:
1.581 albertel 3845: sub format_previous_attempt_value {
3846: my ($key,$value) = @_;
1.1011 www 3847: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3848: $value = &Apache::lonlocal::locallocaltime($value);
3849: } elsif (ref($value) eq 'ARRAY') {
3850: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3851: } elsif ($key =~ /answerstring$/) {
3852: my %answers = &Apache::lonnet::str2hash($value);
3853: my @anskeys = sort(keys(%answers));
3854: if (@anskeys == 1) {
3855: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3856: if ($answer =~ m{\0}) {
3857: $answer =~ s{\0}{,}g;
1.988 raeburn 3858: }
3859: my $tag_internal_answer_name = 'INTERNAL';
3860: if ($anskeys[0] eq $tag_internal_answer_name) {
3861: $value = $answer;
3862: } else {
3863: $value = $anskeys[0].'='.$answer;
3864: }
3865: } else {
3866: foreach my $ans (@anskeys) {
3867: my $answer = $answers{$ans};
1.1001 raeburn 3868: if ($answer =~ m{\0}) {
3869: $answer =~ s{\0}{,}g;
1.988 raeburn 3870: }
3871: $value .= $ans.'='.$answer.'<br />';;
3872: }
3873: }
1.581 albertel 3874: } else {
3875: $value = &unescape($value);
3876: }
3877: return $value;
3878: }
3879:
3880:
1.107 albertel 3881: sub relative_to_absolute {
3882: my ($url,$output)=@_;
3883: my $parser=HTML::TokeParser->new(\$output);
3884: my $token;
3885: my $thisdir=$url;
3886: my @rlinks=();
3887: while ($token=$parser->get_token) {
3888: if ($token->[0] eq 'S') {
3889: if ($token->[1] eq 'a') {
3890: if ($token->[2]->{'href'}) {
3891: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3892: }
3893: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3894: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3895: } elsif ($token->[1] eq 'base') {
3896: $thisdir=$token->[2]->{'href'};
3897: }
3898: }
3899: }
3900: $thisdir=~s-/[^/]*$--;
1.356 albertel 3901: foreach my $link (@rlinks) {
1.726 raeburn 3902: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3903: ($link=~/^\//) ||
3904: ($link=~/^javascript:/i) ||
3905: ($link=~/^mailto:/i) ||
3906: ($link=~/^\#/)) {
3907: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3908: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3909: }
3910: }
3911: # -------------------------------------------------- Deal with Applet codebases
3912: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3913: return $output;
3914: }
3915:
1.112 bowersj2 3916: =pod
3917:
1.648 raeburn 3918: =item * &get_student_view()
1.112 bowersj2 3919:
3920: show a snapshot of what student was looking at
3921:
3922: =cut
3923:
1.10 albertel 3924: sub get_student_view {
1.186 albertel 3925: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3926: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3927: my (%form);
1.10 albertel 3928: my @elements=('symb','courseid','domain','username');
3929: foreach my $element (@elements) {
1.186 albertel 3930: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3931: }
1.186 albertel 3932: if (defined($moreenv)) {
3933: %form=(%form,%{$moreenv});
3934: }
1.236 albertel 3935: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3936: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3937: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3938: $userview=~s/\<body[^\>]*\>//gi;
3939: $userview=~s/\<\/body\>//gi;
3940: $userview=~s/\<html\>//gi;
3941: $userview=~s/\<\/html\>//gi;
3942: $userview=~s/\<head\>//gi;
3943: $userview=~s/\<\/head\>//gi;
3944: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3945: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3946: if (wantarray) {
3947: return ($userview,$response);
3948: } else {
3949: return $userview;
3950: }
3951: }
3952:
3953: sub get_student_view_with_retries {
3954: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3955:
3956: my $ok = 0; # True if we got a good response.
3957: my $content;
3958: my $response;
3959:
3960: # Try to get the student_view done. within the retries count:
3961:
3962: do {
3963: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3964: $ok = $response->is_success;
3965: if (!$ok) {
3966: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3967: }
3968: $retries--;
3969: } while (!$ok && ($retries > 0));
3970:
3971: if (!$ok) {
3972: $content = ''; # On error return an empty content.
3973: }
1.651 www 3974: if (wantarray) {
3975: return ($content, $response);
3976: } else {
3977: return $content;
3978: }
1.11 albertel 3979: }
3980:
1.112 bowersj2 3981: =pod
3982:
1.648 raeburn 3983: =item * &get_student_answers()
1.112 bowersj2 3984:
3985: show a snapshot of how student was answering problem
3986:
3987: =cut
3988:
1.11 albertel 3989: sub get_student_answers {
1.100 sakharuk 3990: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3991: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3992: my (%moreenv);
1.11 albertel 3993: my @elements=('symb','courseid','domain','username');
3994: foreach my $element (@elements) {
1.186 albertel 3995: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3996: }
1.186 albertel 3997: $moreenv{'grade_target'}='answer';
3998: %moreenv=(%form,%moreenv);
1.497 raeburn 3999: $feedurl = &Apache::lonnet::clutter($feedurl);
4000: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4001: return $userview;
1.1 albertel 4002: }
1.116 albertel 4003:
4004: =pod
4005:
4006: =item * &submlink()
4007:
1.242 albertel 4008: Inputs: $text $uname $udom $symb $target
1.116 albertel 4009:
4010: Returns: A link to grades.pm such as to see the SUBM view of a student
4011:
4012: =cut
4013:
4014: ###############################################
4015: sub submlink {
1.242 albertel 4016: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4017: if (!($uname && $udom)) {
4018: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4019: &Apache::lonnet::whichuser($symb);
1.116 albertel 4020: if (!$symb) { $symb=$cursymb; }
4021: }
1.254 matthew 4022: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4023: $symb=&escape($symb);
1.960 bisitz 4024: if ($target) { $target=" target=\"$target\""; }
4025: return
4026: '<a href="/adm/grades?command=submission'.
4027: '&symb='.$symb.
4028: '&student='.$uname.
4029: '&userdom='.$udom.'"'.
4030: $target.'>'.$text.'</a>';
1.242 albertel 4031: }
4032: ##############################################
4033:
4034: =pod
4035:
4036: =item * &pgrdlink()
4037:
4038: Inputs: $text $uname $udom $symb $target
4039:
4040: Returns: A link to grades.pm such as to see the PGRD view of a student
4041:
4042: =cut
4043:
4044: ###############################################
4045: sub pgrdlink {
4046: my $link=&submlink(@_);
4047: $link=~s/(&command=submission)/$1&showgrading=yes/;
4048: return $link;
4049: }
4050: ##############################################
4051:
4052: =pod
4053:
4054: =item * &pprmlink()
4055:
4056: Inputs: $text $uname $udom $symb $target
4057:
4058: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4059: student and a specific resource
1.242 albertel 4060:
4061: =cut
4062:
4063: ###############################################
4064: sub pprmlink {
4065: my ($text,$uname,$udom,$symb,$target)=@_;
4066: if (!($uname && $udom)) {
4067: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4068: &Apache::lonnet::whichuser($symb);
1.242 albertel 4069: if (!$symb) { $symb=$cursymb; }
4070: }
1.254 matthew 4071: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4072: $symb=&escape($symb);
1.242 albertel 4073: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4074: return '<a href="/adm/parmset?command=set&'.
4075: 'symb='.$symb.'&uname='.$uname.
4076: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4077: }
4078: ##############################################
1.37 matthew 4079:
1.112 bowersj2 4080: =pod
4081:
4082: =back
4083:
4084: =cut
4085:
1.37 matthew 4086: ###############################################
1.51 www 4087:
4088:
4089: sub timehash {
1.687 raeburn 4090: my ($thistime) = @_;
4091: my $timezone = &Apache::lonlocal::gettimezone();
4092: my $dt = DateTime->from_epoch(epoch => $thistime)
4093: ->set_time_zone($timezone);
4094: my $wday = $dt->day_of_week();
4095: if ($wday == 7) { $wday = 0; }
4096: return ( 'second' => $dt->second(),
4097: 'minute' => $dt->minute(),
4098: 'hour' => $dt->hour(),
4099: 'day' => $dt->day_of_month(),
4100: 'month' => $dt->month(),
4101: 'year' => $dt->year(),
4102: 'weekday' => $wday,
4103: 'dayyear' => $dt->day_of_year(),
4104: 'dlsav' => $dt->is_dst() );
1.51 www 4105: }
4106:
1.370 www 4107: sub utc_string {
4108: my ($date)=@_;
1.371 www 4109: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4110: }
4111:
1.51 www 4112: sub maketime {
4113: my %th=@_;
1.687 raeburn 4114: my ($epoch_time,$timezone,$dt);
4115: $timezone = &Apache::lonlocal::gettimezone();
4116: eval {
4117: $dt = DateTime->new( year => $th{'year'},
4118: month => $th{'month'},
4119: day => $th{'day'},
4120: hour => $th{'hour'},
4121: minute => $th{'minute'},
4122: second => $th{'second'},
4123: time_zone => $timezone,
4124: );
4125: };
4126: if (!$@) {
4127: $epoch_time = $dt->epoch;
4128: if ($epoch_time) {
4129: return $epoch_time;
4130: }
4131: }
1.51 www 4132: return POSIX::mktime(
4133: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4134: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4135: }
4136:
4137: #########################################
1.51 www 4138:
4139: sub findallcourses {
1.482 raeburn 4140: my ($roles,$uname,$udom) = @_;
1.355 albertel 4141: my %roles;
4142: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4143: my %courses;
1.51 www 4144: my $now=time;
1.482 raeburn 4145: if (!defined($uname)) {
4146: $uname = $env{'user.name'};
4147: }
4148: if (!defined($udom)) {
4149: $udom = $env{'user.domain'};
4150: }
4151: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4152: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4153: if (!%roles) {
4154: %roles = (
4155: cc => 1,
1.907 raeburn 4156: co => 1,
1.482 raeburn 4157: in => 1,
4158: ep => 1,
4159: ta => 1,
4160: cr => 1,
4161: st => 1,
4162: );
4163: }
4164: foreach my $entry (keys(%roleshash)) {
4165: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4166: if ($trole =~ /^cr/) {
4167: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4168: } else {
4169: next if (!exists($roles{$trole}));
4170: }
4171: if ($tend) {
4172: next if ($tend < $now);
4173: }
4174: if ($tstart) {
4175: next if ($tstart > $now);
4176: }
1.1058 raeburn 4177: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4178: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4179: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4180: if ($secpart eq '') {
4181: ($cnum,$role) = split(/_/,$cnumpart);
4182: $sec = 'none';
1.1058 raeburn 4183: $value .= $cnum.'/';
1.482 raeburn 4184: } else {
4185: $cnum = $cnumpart;
4186: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4187: $value .= $cnum.'/'.$sec;
4188: }
4189: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4190: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4191: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4192: }
4193: } else {
4194: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4195: }
1.482 raeburn 4196: }
4197: } else {
4198: foreach my $key (keys(%env)) {
1.483 albertel 4199: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4200: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4201: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4202: next if ($role eq 'ca' || $role eq 'aa');
4203: next if (%roles && !exists($roles{$role}));
4204: my ($starttime,$endtime)=split(/\./,$env{$key});
4205: my $active=1;
4206: if ($starttime) {
4207: if ($now<$starttime) { $active=0; }
4208: }
4209: if ($endtime) {
4210: if ($now>$endtime) { $active=0; }
4211: }
4212: if ($active) {
1.1058 raeburn 4213: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4214: if ($sec eq '') {
4215: $sec = 'none';
1.1058 raeburn 4216: } else {
4217: $value .= $sec;
4218: }
4219: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4220: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4221: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4222: }
4223: } else {
4224: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4225: }
1.474 raeburn 4226: }
4227: }
1.51 www 4228: }
4229: }
1.474 raeburn 4230: return %courses;
1.51 www 4231: }
1.37 matthew 4232:
1.54 www 4233: ###############################################
1.474 raeburn 4234:
4235: sub blockcheck {
1.1062 raeburn 4236: my ($setters,$activity,$uname,$udom,$url) = @_;
1.490 raeburn 4237:
4238: if (!defined($udom)) {
4239: $udom = $env{'user.domain'};
4240: }
4241: if (!defined($uname)) {
4242: $uname = $env{'user.name'};
4243: }
4244:
4245: # If uname and udom are for a course, check for blocks in the course.
4246:
4247: if (&Apache::lonnet::is_course($udom,$uname)) {
1.1062 raeburn 4248: my ($startblock,$endblock,$triggerblock) =
4249: &get_blocks($setters,$activity,$udom,$uname,$url);
4250: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4251: }
1.474 raeburn 4252:
1.502 raeburn 4253: my $startblock = 0;
4254: my $endblock = 0;
1.1062 raeburn 4255: my $triggerblock = '';
1.482 raeburn 4256: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4257:
1.490 raeburn 4258: # If uname is for a user, and activity is course-specific, i.e.,
4259: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4260:
1.490 raeburn 4261: if (($activity eq 'boards' || $activity eq 'chat' ||
4262: $activity eq 'groups') && ($env{'request.course.id'})) {
4263: foreach my $key (keys(%live_courses)) {
4264: if ($key ne $env{'request.course.id'}) {
4265: delete($live_courses{$key});
4266: }
4267: }
4268: }
4269:
4270: my $otheruser = 0;
4271: my %own_courses;
4272: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4273: # Resource belongs to user other than current user.
4274: $otheruser = 1;
4275: # Gather courses for current user
4276: %own_courses =
4277: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4278: }
4279:
4280: # Gather active course roles - course coordinator, instructor,
4281: # exam proctor, ta, student, or custom role.
1.474 raeburn 4282:
4283: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4284: my ($cdom,$cnum);
4285: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4286: $cdom = $env{'course.'.$course.'.domain'};
4287: $cnum = $env{'course.'.$course.'.num'};
4288: } else {
1.490 raeburn 4289: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4290: }
4291: my $no_ownblock = 0;
4292: my $no_userblock = 0;
1.533 raeburn 4293: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4294: # Check if current user has 'evb' priv for this
4295: if (defined($own_courses{$course})) {
4296: foreach my $sec (keys(%{$own_courses{$course}})) {
4297: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4298: if ($sec ne 'none') {
4299: $checkrole .= '/'.$sec;
4300: }
4301: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4302: $no_ownblock = 1;
4303: last;
4304: }
4305: }
4306: }
4307: # if they have 'evb' priv and are currently not playing student
4308: next if (($no_ownblock) &&
4309: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4310: }
1.474 raeburn 4311: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4312: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4313: if ($sec ne 'none') {
1.482 raeburn 4314: $checkrole .= '/'.$sec;
1.474 raeburn 4315: }
1.490 raeburn 4316: if ($otheruser) {
4317: # Resource belongs to user other than current user.
4318: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4319: my (%allroles,%userroles);
4320: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4321: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4322: my ($trole,$tdom,$tnum,$tsec);
4323: if ($entry =~ /^cr/) {
4324: ($trole,$tdom,$tnum,$tsec) =
4325: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4326: } else {
4327: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4328: }
4329: my ($spec,$area,$trest);
4330: $area = '/'.$tdom.'/'.$tnum;
4331: $trest = $tnum;
4332: if ($tsec ne '') {
4333: $area .= '/'.$tsec;
4334: $trest .= '/'.$tsec;
4335: }
4336: $spec = $trole.'.'.$area;
4337: if ($trole =~ /^cr/) {
4338: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4339: $tdom,$spec,$trest,$area);
4340: } else {
4341: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4342: $tdom,$spec,$trest,$area);
4343: }
4344: }
4345: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4346: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4347: if ($1) {
4348: $no_userblock = 1;
4349: last;
4350: }
1.486 raeburn 4351: }
4352: }
1.490 raeburn 4353: } else {
4354: # Resource belongs to current user
4355: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4356: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4357: $no_ownblock = 1;
4358: last;
4359: }
1.474 raeburn 4360: }
4361: }
4362: # if they have the evb priv and are currently not playing student
1.482 raeburn 4363: next if (($no_ownblock) &&
1.491 albertel 4364: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4365: next if ($no_userblock);
1.474 raeburn 4366:
1.866 kalberla 4367: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4368: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4369:
1.1062 raeburn 4370: my ($start,$end,$trigger) =
4371: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4372: if (($start != 0) &&
4373: (($startblock == 0) || ($startblock > $start))) {
4374: $startblock = $start;
1.1062 raeburn 4375: if ($trigger ne '') {
4376: $triggerblock = $trigger;
4377: }
1.502 raeburn 4378: }
4379: if (($end != 0) &&
4380: (($endblock == 0) || ($endblock < $end))) {
4381: $endblock = $end;
1.1062 raeburn 4382: if ($trigger ne '') {
4383: $triggerblock = $trigger;
4384: }
1.502 raeburn 4385: }
1.490 raeburn 4386: }
1.1062 raeburn 4387: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4388: }
4389:
4390: sub get_blocks {
1.1062 raeburn 4391: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4392: my $startblock = 0;
4393: my $endblock = 0;
1.1062 raeburn 4394: my $triggerblock = '';
1.490 raeburn 4395: my $course = $cdom.'_'.$cnum;
4396: $setters->{$course} = {};
4397: $setters->{$course}{'staff'} = [];
4398: $setters->{$course}{'times'} = [];
1.1062 raeburn 4399: $setters->{$course}{'triggers'} = [];
4400: my (@blockers,%triggered);
4401: my $now = time;
4402: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4403: if ($activity eq 'docs') {
4404: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4405: foreach my $block (@blockers) {
4406: if ($block =~ /^firstaccess____(.+)$/) {
4407: my $item = $1;
4408: my $type = 'map';
4409: my $timersymb = $item;
4410: if ($item eq 'course') {
4411: $type = 'course';
4412: } elsif ($item =~ /___\d+___/) {
4413: $type = 'resource';
4414: } else {
4415: $timersymb = &Apache::lonnet::symbread($item);
4416: }
4417: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4418: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4419: $triggered{$block} = {
4420: start => $start,
4421: end => $end,
4422: type => $type,
4423: };
4424: }
4425: }
4426: } else {
4427: foreach my $block (keys(%commblocks)) {
4428: if ($block =~ m/^(\d+)____(\d+)$/) {
4429: my ($start,$end) = ($1,$2);
4430: if ($start <= time && $end >= time) {
4431: if (ref($commblocks{$block}) eq 'HASH') {
4432: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4433: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4434: unless(grep(/^\Q$block\E$/,@blockers)) {
4435: push(@blockers,$block);
4436: }
4437: }
4438: }
4439: }
4440: }
4441: } elsif ($block =~ /^firstaccess____(.+)$/) {
4442: my $item = $1;
4443: my $timersymb = $item;
4444: my $type = 'map';
4445: if ($item eq 'course') {
4446: $type = 'course';
4447: } elsif ($item =~ /___\d+___/) {
4448: $type = 'resource';
4449: } else {
4450: $timersymb = &Apache::lonnet::symbread($item);
4451: }
4452: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4453: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4454: if ($start && $end) {
4455: if (($start <= time) && ($end >= time)) {
4456: unless (grep(/^\Q$block\E$/,@blockers)) {
4457: push(@blockers,$block);
4458: $triggered{$block} = {
4459: start => $start,
4460: end => $end,
4461: type => $type,
4462: };
4463: }
4464: }
1.490 raeburn 4465: }
1.1062 raeburn 4466: }
4467: }
4468: }
4469: foreach my $blocker (@blockers) {
4470: my ($staff_name,$staff_dom,$title,$blocks) =
4471: &parse_block_record($commblocks{$blocker});
4472: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4473: my ($start,$end,$triggertype);
4474: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4475: ($start,$end) = ($1,$2);
4476: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4477: $start = $triggered{$blocker}{'start'};
4478: $end = $triggered{$blocker}{'end'};
4479: $triggertype = $triggered{$blocker}{'type'};
4480: }
4481: if ($start) {
4482: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4483: if ($triggertype) {
4484: push(@{$$setters{$course}{'triggers'}},$triggertype);
4485: } else {
4486: push(@{$$setters{$course}{'triggers'}},0);
4487: }
4488: if ( ($startblock == 0) || ($startblock > $start) ) {
4489: $startblock = $start;
4490: if ($triggertype) {
4491: $triggerblock = $blocker;
1.474 raeburn 4492: }
4493: }
1.1062 raeburn 4494: if ( ($endblock == 0) || ($endblock < $end) ) {
4495: $endblock = $end;
4496: if ($triggertype) {
4497: $triggerblock = $blocker;
4498: }
4499: }
1.474 raeburn 4500: }
4501: }
1.1062 raeburn 4502: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4503: }
4504:
4505: sub parse_block_record {
4506: my ($record) = @_;
4507: my ($setuname,$setudom,$title,$blocks);
4508: if (ref($record) eq 'HASH') {
4509: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4510: $title = &unescape($record->{'event'});
4511: $blocks = $record->{'blocks'};
4512: } else {
4513: my @data = split(/:/,$record,3);
4514: if (scalar(@data) eq 2) {
4515: $title = $data[1];
4516: ($setuname,$setudom) = split(/@/,$data[0]);
4517: } else {
4518: ($setuname,$setudom,$title) = @data;
4519: }
4520: $blocks = { 'com' => 'on' };
4521: }
4522: return ($setuname,$setudom,$title,$blocks);
4523: }
4524:
1.854 kalberla 4525: sub blocking_status {
1.1062 raeburn 4526: my ($activity,$uname,$udom,$url) = @_;
1.1061 raeburn 4527: my %setters;
1.890 droeschl 4528:
1.1061 raeburn 4529: # check for active blocking
1.1062 raeburn 4530: my ($startblock,$endblock,$triggerblock) =
4531: &blockcheck(\%setters,$activity,$uname,$udom,$url);
4532: my $blocked = 0;
4533: if ($startblock && $endblock) {
4534: $blocked = 1;
4535: }
1.890 droeschl 4536:
1.1061 raeburn 4537: # caller just wants to know whether a block is active
4538: if (!wantarray) { return $blocked; }
4539:
4540: # build a link to a popup window containing the details
4541: my $querystring = "?activity=$activity";
4542: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4543: if ($activity eq 'port') {
4544: $querystring .= "&udom=$udom" if $udom;
4545: $querystring .= "&uname=$uname" if $uname;
4546: } elsif ($activity eq 'docs') {
4547: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4548: }
1.1061 raeburn 4549:
4550: my $output .= <<'END_MYBLOCK';
4551: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4552: var options = "width=" + w + ",height=" + h + ",";
4553: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4554: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4555: var newWin = window.open(url, wdwName, options);
4556: newWin.focus();
4557: }
1.890 droeschl 4558: END_MYBLOCK
1.854 kalberla 4559:
1.1061 raeburn 4560: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4561:
1.1061 raeburn 4562: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4563: my $text = &mt('Communication Blocked');
4564: if ($activity eq 'docs') {
4565: $text = &mt('Content Access Blocked');
1.1063 raeburn 4566: } elsif ($activity eq 'printout') {
4567: $text = &mt('Printing Blocked');
1.1062 raeburn 4568: }
1.1061 raeburn 4569: $output .= <<"END_BLOCK";
1.867 kalberla 4570: <div class='LC_comblock'>
1.869 kalberla 4571: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4572: title='$text'>
4573: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4574: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4575: title='$text'>$text</a>
1.867 kalberla 4576: </div>
4577:
4578: END_BLOCK
1.474 raeburn 4579:
1.1061 raeburn 4580: return ($blocked, $output);
1.854 kalberla 4581: }
1.490 raeburn 4582:
1.60 matthew 4583: ###############################################
4584:
1.682 raeburn 4585: sub check_ip_acc {
4586: my ($acc)=@_;
4587: &Apache::lonxml::debug("acc is $acc");
4588: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4589: return 1;
4590: }
4591: my $allowed=0;
4592: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4593:
4594: my $name;
4595: foreach my $pattern (split(',',$acc)) {
4596: $pattern =~ s/^\s*//;
4597: $pattern =~ s/\s*$//;
4598: if ($pattern =~ /\*$/) {
4599: #35.8.*
4600: $pattern=~s/\*//;
4601: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4602: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4603: #35.8.3.[34-56]
4604: my $low=$2;
4605: my $high=$3;
4606: $pattern=$1;
4607: if ($ip =~ /^\Q$pattern\E/) {
4608: my $last=(split(/\./,$ip))[3];
4609: if ($last <=$high && $last >=$low) { $allowed=1; }
4610: }
4611: } elsif ($pattern =~ /^\*/) {
4612: #*.msu.edu
4613: $pattern=~s/\*//;
4614: if (!defined($name)) {
4615: use Socket;
4616: my $netaddr=inet_aton($ip);
4617: ($name)=gethostbyaddr($netaddr,AF_INET);
4618: }
4619: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4620: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4621: #127.0.0.1
4622: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4623: } else {
4624: #some.name.com
4625: if (!defined($name)) {
4626: use Socket;
4627: my $netaddr=inet_aton($ip);
4628: ($name)=gethostbyaddr($netaddr,AF_INET);
4629: }
4630: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4631: }
4632: if ($allowed) { last; }
4633: }
4634: return $allowed;
4635: }
4636:
4637: ###############################################
4638:
1.60 matthew 4639: =pod
4640:
1.112 bowersj2 4641: =head1 Domain Template Functions
4642:
4643: =over 4
4644:
4645: =item * &determinedomain()
1.60 matthew 4646:
4647: Inputs: $domain (usually will be undef)
4648:
1.63 www 4649: Returns: Determines which domain should be used for designs
1.60 matthew 4650:
4651: =cut
1.54 www 4652:
1.60 matthew 4653: ###############################################
1.63 www 4654: sub determinedomain {
4655: my $domain=shift;
1.531 albertel 4656: if (! $domain) {
1.60 matthew 4657: # Determine domain if we have not been given one
1.893 raeburn 4658: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4659: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4660: if ($env{'request.role.domain'}) {
4661: $domain=$env{'request.role.domain'};
1.60 matthew 4662: }
4663: }
1.63 www 4664: return $domain;
4665: }
4666: ###############################################
1.517 raeburn 4667:
1.518 albertel 4668: sub devalidate_domconfig_cache {
4669: my ($udom)=@_;
4670: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4671: }
4672:
4673: # ---------------------- Get domain configuration for a domain
4674: sub get_domainconf {
4675: my ($udom) = @_;
4676: my $cachetime=1800;
4677: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4678: if (defined($cached)) { return %{$result}; }
4679:
4680: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4681: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4682: my (%designhash,%legacy);
1.518 albertel 4683: if (keys(%domconfig) > 0) {
4684: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4685: if (keys(%{$domconfig{'login'}})) {
4686: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4687: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4688: if ($key eq 'loginvia') {
4689: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4690: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4691: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4692: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4693: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4694: $designhash{$udom.'.login.loginvia'} = $server;
4695: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4696:
4697: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4698: } else {
1.1013 raeburn 4699: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4700: }
4701: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4702: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4703: }
1.946 raeburn 4704: }
4705: }
4706: }
4707: }
4708: } else {
4709: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4710: $designhash{$udom.'.login.'.$key.'_'.$img} =
4711: $domconfig{'login'}{$key}{$img};
4712: }
1.699 raeburn 4713: }
4714: } else {
4715: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4716: }
1.632 raeburn 4717: }
4718: } else {
4719: $legacy{'login'} = 1;
1.518 albertel 4720: }
1.632 raeburn 4721: } else {
4722: $legacy{'login'} = 1;
1.518 albertel 4723: }
4724: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4725: if (keys(%{$domconfig{'rolecolors'}})) {
4726: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4727: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4728: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4729: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4730: }
1.518 albertel 4731: }
4732: }
1.632 raeburn 4733: } else {
4734: $legacy{'rolecolors'} = 1;
1.518 albertel 4735: }
1.632 raeburn 4736: } else {
4737: $legacy{'rolecolors'} = 1;
1.518 albertel 4738: }
1.948 raeburn 4739: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4740: if ($domconfig{'autoenroll'}{'co-owners'}) {
4741: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4742: }
4743: }
1.632 raeburn 4744: if (keys(%legacy) > 0) {
4745: my %legacyhash = &get_legacy_domconf($udom);
4746: foreach my $item (keys(%legacyhash)) {
4747: if ($item =~ /^\Q$udom\E\.login/) {
4748: if ($legacy{'login'}) {
4749: $designhash{$item} = $legacyhash{$item};
4750: }
4751: } else {
4752: if ($legacy{'rolecolors'}) {
4753: $designhash{$item} = $legacyhash{$item};
4754: }
1.518 albertel 4755: }
4756: }
4757: }
1.632 raeburn 4758: } else {
4759: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4760: }
4761: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4762: $cachetime);
4763: return %designhash;
4764: }
4765:
1.632 raeburn 4766: sub get_legacy_domconf {
4767: my ($udom) = @_;
4768: my %legacyhash;
4769: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4770: my $designfile = $designdir.'/'.$udom.'.tab';
4771: if (-e $designfile) {
4772: if ( open (my $fh,"<$designfile") ) {
4773: while (my $line = <$fh>) {
4774: next if ($line =~ /^\#/);
4775: chomp($line);
4776: my ($key,$val)=(split(/\=/,$line));
4777: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4778: }
4779: close($fh);
4780: }
4781: }
1.1026 raeburn 4782: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4783: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4784: }
4785: return %legacyhash;
4786: }
4787:
1.63 www 4788: =pod
4789:
1.112 bowersj2 4790: =item * &domainlogo()
1.63 www 4791:
4792: Inputs: $domain (usually will be undef)
4793:
4794: Returns: A link to a domain logo, if the domain logo exists.
4795: If the domain logo does not exist, a description of the domain.
4796:
4797: =cut
1.112 bowersj2 4798:
1.63 www 4799: ###############################################
4800: sub domainlogo {
1.517 raeburn 4801: my $domain = &determinedomain(shift);
1.518 albertel 4802: my %designhash = &get_domainconf($domain);
1.517 raeburn 4803: # See if there is a logo
4804: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4805: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4806: if ($imgsrc =~ m{^/(adm|res)/}) {
4807: if ($imgsrc =~ m{^/res/}) {
4808: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4809: &Apache::lonnet::repcopy($local_name);
4810: }
4811: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4812: }
4813: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4814: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4815: return &Apache::lonnet::domain($domain,'description');
1.59 www 4816: } else {
1.60 matthew 4817: return '';
1.59 www 4818: }
4819: }
1.63 www 4820: ##############################################
4821:
4822: =pod
4823:
1.112 bowersj2 4824: =item * &designparm()
1.63 www 4825:
4826: Inputs: $which parameter; $domain (usually will be undef)
4827:
4828: Returns: value of designparamter $which
4829:
4830: =cut
1.112 bowersj2 4831:
1.397 albertel 4832:
1.400 albertel 4833: ##############################################
1.397 albertel 4834: sub designparm {
4835: my ($which,$domain)=@_;
4836: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4837: return $env{'environment.color.'.$which};
1.96 www 4838: }
1.63 www 4839: $domain=&determinedomain($domain);
1.1016 raeburn 4840: my %domdesign;
4841: unless ($domain eq 'public') {
4842: %domdesign = &get_domainconf($domain);
4843: }
1.520 raeburn 4844: my $output;
1.517 raeburn 4845: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4846: $output = $domdesign{$domain.'.'.$which};
1.63 www 4847: } else {
1.520 raeburn 4848: $output = $defaultdesign{$which};
4849: }
4850: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4851: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4852: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4853: if ($output =~ m{^/res/}) {
4854: my $local_name = &Apache::lonnet::filelocation('',$output);
4855: &Apache::lonnet::repcopy($local_name);
4856: }
1.520 raeburn 4857: $output = &lonhttpdurl($output);
4858: }
1.63 www 4859: }
1.520 raeburn 4860: return $output;
1.63 www 4861: }
1.59 www 4862:
1.822 bisitz 4863: ##############################################
4864: =pod
4865:
1.832 bisitz 4866: =item * &authorspace()
4867:
1.1028 raeburn 4868: Inputs: $url (usually will be undef).
1.832 bisitz 4869:
1.1075.2.40 raeburn 4870: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 4871: directory being viewed (or for which action is being taken).
4872: If $url is provided, and begins /priv/<domain>/<uname>
4873: the path will be that portion of the $context argument.
4874: Otherwise the path will be for the author space of the current
4875: user when the current role is author, or for that of the
4876: co-author/assistant co-author space when the current role
4877: is co-author or assistant co-author.
1.832 bisitz 4878:
4879: =cut
4880:
4881: sub authorspace {
1.1028 raeburn 4882: my ($url) = @_;
4883: if ($url ne '') {
4884: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4885: return $1;
4886: }
4887: }
1.832 bisitz 4888: my $caname = '';
1.1024 www 4889: my $cadom = '';
1.1028 raeburn 4890: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4891: ($cadom,$caname) =
1.832 bisitz 4892: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4893: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4894: $caname = $env{'user.name'};
1.1024 www 4895: $cadom = $env{'user.domain'};
1.832 bisitz 4896: }
1.1028 raeburn 4897: if (($caname ne '') && ($cadom ne '')) {
4898: return "/priv/$cadom/$caname/";
4899: }
4900: return;
1.832 bisitz 4901: }
4902:
4903: ##############################################
4904: =pod
4905:
1.822 bisitz 4906: =item * &head_subbox()
4907:
4908: Inputs: $content (contains HTML code with page functions, etc.)
4909:
4910: Returns: HTML div with $content
4911: To be included in page header
4912:
4913: =cut
4914:
4915: sub head_subbox {
4916: my ($content)=@_;
4917: my $output =
1.993 raeburn 4918: '<div class="LC_head_subbox">'
1.822 bisitz 4919: .$content
4920: .'</div>'
4921: }
4922:
4923: ##############################################
4924: =pod
4925:
4926: =item * &CSTR_pageheader()
4927:
1.1026 raeburn 4928: Input: (optional) filename from which breadcrumb trail is built.
4929: In most cases no input as needed, as $env{'request.filename'}
4930: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 4931:
4932: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 4933: To be included on Authoring Space pages
1.822 bisitz 4934:
4935: =cut
4936:
4937: sub CSTR_pageheader {
1.1026 raeburn 4938: my ($trailfile) = @_;
4939: if ($trailfile eq '') {
4940: $trailfile = $env{'request.filename'};
4941: }
4942:
4943: # this is for resources; directories have customtitle, and crumbs
4944: # and select recent are created in lonpubdir.pm
4945:
4946: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 4947: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 4948: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 4949: my $formaction = "/priv/$udom/$uname/$thisdisfn";
4950: $formaction =~ s{/+}{/}g;
1.822 bisitz 4951:
4952: my $parentpath = '';
4953: my $lastitem = '';
4954: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4955: $parentpath = $1;
4956: $lastitem = $2;
4957: } else {
4958: $lastitem = $thisdisfn;
4959: }
1.921 bisitz 4960:
4961: my $output =
1.822 bisitz 4962: '<div>'
4963: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 4964: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 4965: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4966: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 4967: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 4968:
4969: if ($lastitem) {
4970: $output .=
4971: '<span class="LC_filename">'
4972: .$lastitem
4973: .'</span>';
4974: }
4975: $output .=
4976: '<br />'
1.822 bisitz 4977: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4978: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4979: .'</form>'
4980: .&Apache::lonmenu::constspaceform()
4981: .'</div>';
1.921 bisitz 4982:
4983: return $output;
1.822 bisitz 4984: }
4985:
1.60 matthew 4986: ###############################################
4987: ###############################################
4988:
4989: =pod
4990:
1.112 bowersj2 4991: =back
4992:
1.549 albertel 4993: =head1 HTML Helpers
1.112 bowersj2 4994:
4995: =over 4
4996:
4997: =item * &bodytag()
1.60 matthew 4998:
4999: Returns a uniform header for LON-CAPA web pages.
5000:
5001: Inputs:
5002:
1.112 bowersj2 5003: =over 4
5004:
5005: =item * $title, A title to be displayed on the page.
5006:
5007: =item * $function, the current role (can be undef).
5008:
5009: =item * $addentries, extra parameters for the <body> tag.
5010:
5011: =item * $bodyonly, if defined, only return the <body> tag.
5012:
5013: =item * $domain, if defined, force a given domain.
5014:
5015: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5016: text interface only)
1.60 matthew 5017:
1.814 bisitz 5018: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5019: navigational links
1.317 albertel 5020:
1.338 albertel 5021: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5022:
1.1075.2.12 raeburn 5023: =item * $no_inline_link, if true and in remote mode, don't show the
5024: 'Switch To Inline Menu' link
5025:
1.460 albertel 5026: =item * $args, optional argument valid values are
5027: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5028: inherit_jsmath -> when creating popup window in a page,
5029: should it have jsmath forced on by the
5030: current page
1.460 albertel 5031:
1.1075.2.15 raeburn 5032: =item * $advtoolsref, optional argument, ref to an array containing
5033: inlineremote items to be added in "Functions" menu below
5034: breadcrumbs.
5035:
1.112 bowersj2 5036: =back
5037:
1.60 matthew 5038: Returns: A uniform header for LON-CAPA web pages.
5039: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5040: If $bodyonly is undef or zero, an html string containing a <body> tag and
5041: other decorations will be returned.
5042:
5043: =cut
5044:
1.54 www 5045: sub bodytag {
1.831 bisitz 5046: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5047: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5048:
1.954 raeburn 5049: my $public;
5050: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5051: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5052: $public = 1;
5053: }
1.460 albertel 5054: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5055: my $httphost = $args->{'use_absolute'};
1.339 albertel 5056:
1.183 matthew 5057: $function = &get_users_function() if (!$function);
1.339 albertel 5058: my $img = &designparm($function.'.img',$domain);
5059: my $font = &designparm($function.'.font',$domain);
5060: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5061:
1.803 bisitz 5062: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5063: 'bgcolor' => $pgbg,
1.339 albertel 5064: 'text' => $font,
5065: 'alink' => &designparm($function.'.alink',$domain),
5066: 'vlink' => &designparm($function.'.vlink',$domain),
5067: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5068: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5069:
1.63 www 5070: # role and realm
1.378 raeburn 5071: my ($role,$realm) = split(/\./,$env{'request.role'},2);
5072: if ($role eq 'ca') {
1.479 albertel 5073: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5074: $realm = &plainname($rname,$rdom);
1.378 raeburn 5075: }
1.55 www 5076: # realm
1.258 albertel 5077: if ($env{'request.course.id'}) {
1.378 raeburn 5078: if ($env{'request.role'} !~ /^cr/) {
5079: $role = &Apache::lonnet::plaintext($role,&course_type());
5080: }
1.898 raeburn 5081: if ($env{'request.course.sec'}) {
5082: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5083: }
1.359 albertel 5084: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5085: } else {
5086: $role = &Apache::lonnet::plaintext($role);
1.54 www 5087: }
1.433 albertel 5088:
1.359 albertel 5089: if (!$realm) { $realm=' '; }
1.330 albertel 5090:
1.438 albertel 5091: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5092:
1.101 www 5093: # construct main body tag
1.359 albertel 5094: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5095: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5096:
1.1075.2.38 raeburn 5097: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5098:
5099: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5100: return $bodytag;
1.1075.2.38 raeburn 5101: }
1.359 albertel 5102:
1.954 raeburn 5103: if ($public) {
1.433 albertel 5104: undef($role);
5105: }
1.359 albertel 5106:
1.762 bisitz 5107: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5108: #
5109: # Extra info if you are the DC
5110: my $dc_info = '';
5111: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5112: $env{'course.'.$env{'request.course.id'}.
5113: '.domain'}.'/'})) {
5114: my $cid = $env{'request.course.id'};
1.917 raeburn 5115: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5116: $dc_info =~ s/\s+$//;
1.359 albertel 5117: }
5118:
1.898 raeburn 5119: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.903 droeschl 5120:
1.1075.2.13 raeburn 5121: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5122:
1.1075.2.38 raeburn 5123:
5124:
1.1075.2.21 raeburn 5125: my $funclist;
5126: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5127: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5128: Apache::lonmenu::serverform();
5129: my $forbodytag;
5130: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5131: $forcereg,$args->{'group'},
5132: $args->{'bread_crumbs'},
5133: $advtoolsref,'',\$forbodytag);
5134: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5135: $funclist = $forbodytag;
5136: }
5137: } else {
1.903 droeschl 5138:
5139: # if ($env{'request.state'} eq 'construct') {
5140: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5141: # }
5142:
1.1075.2.38 raeburn 5143: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5144: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5145:
1.1075.2.38 raeburn 5146: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5147:
1.916 droeschl 5148: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5149: if ($dc_info) {
5150: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5151: }
1.1075.2.38 raeburn 5152: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5153: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5154: return $bodytag;
5155: }
1.894 droeschl 5156:
1.927 raeburn 5157: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5158: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5159: }
1.916 droeschl 5160:
1.1075.2.38 raeburn 5161: $bodytag .= $right;
1.852 droeschl 5162:
1.917 raeburn 5163: if ($dc_info) {
5164: $dc_info = &dc_courseid_toggle($dc_info);
5165: }
5166: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5167:
1.1075.2.61 raeburn 5168: #if directed to not display the secondary menu, don't.
5169: if ($args->{'no_secondary_menu'}) {
5170: return $bodytag;
5171: }
1.903 droeschl 5172: #don't show menus for public users
1.954 raeburn 5173: if (!$public){
1.1075.2.52 raeburn 5174: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5175: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5176: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5177: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5178: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5179: $args->{'bread_crumbs'});
5180: } elsif ($forcereg) {
1.1075.2.22 raeburn 5181: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5182: $args->{'group'});
1.1075.2.15 raeburn 5183: } else {
1.1075.2.21 raeburn 5184: my $forbodytag;
5185: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5186: $forcereg,$args->{'group'},
5187: $args->{'bread_crumbs'},
5188: $advtoolsref,'',\$forbodytag);
5189: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5190: $bodytag .= $forbodytag;
5191: }
1.920 raeburn 5192: }
1.903 droeschl 5193: }else{
5194: # this is to seperate menu from content when there's no secondary
5195: # menu. Especially needed for public accessible ressources.
5196: $bodytag .= '<hr style="clear:both" />';
5197: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5198: }
1.903 droeschl 5199:
1.235 raeburn 5200: return $bodytag;
1.1075.2.12 raeburn 5201: }
5202:
5203: #
5204: # Top frame rendering, Remote is up
5205: #
5206:
5207: my $imgsrc = $img;
5208: if ($img =~ /^\/adm/) {
5209: $imgsrc = &lonhttpdurl($img);
5210: }
5211: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5212:
1.1075.2.60 raeburn 5213: my $help=($no_inline_link?''
5214: :&Apache::loncommon::top_nav_help('Help'));
5215:
1.1075.2.12 raeburn 5216: # Explicit link to get inline menu
5217: my $menu= ($no_inline_link?''
5218: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5219:
5220: if ($dc_info) {
5221: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5222: }
5223:
1.1075.2.38 raeburn 5224: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5225: unless ($public) {
5226: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5227: undef,'LC_menubuttons_link');
5228: }
5229:
1.1075.2.12 raeburn 5230: unless ($env{'form.inhibitmenu'}) {
5231: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5232: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5233: <li>$help</li>
1.1075.2.12 raeburn 5234: <li>$menu</li>
5235: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5236: }
1.1075.2.13 raeburn 5237: if ($env{'request.state'} eq 'construct') {
5238: if (!$public){
5239: if ($env{'request.state'} eq 'construct') {
5240: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5241: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5242: &Apache::lonhtmlcommon::scripttag('','end').
5243: &Apache::lonmenu::innerregister($forcereg,
5244: $args->{'bread_crumbs'});
5245: }
5246: }
5247: }
1.1075.2.21 raeburn 5248: return $bodytag."\n".$funclist;
1.182 matthew 5249: }
5250:
1.917 raeburn 5251: sub dc_courseid_toggle {
5252: my ($dc_info) = @_;
1.980 raeburn 5253: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5254: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5255: &mt('(More ...)').'</a></span>'.
5256: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5257: }
5258:
1.330 albertel 5259: sub make_attr_string {
5260: my ($register,$attr_ref) = @_;
5261:
5262: if ($attr_ref && !ref($attr_ref)) {
5263: die("addentries Must be a hash ref ".
5264: join(':',caller(1))." ".
5265: join(':',caller(0))." ");
5266: }
5267:
5268: if ($register) {
1.339 albertel 5269: my ($on_load,$on_unload);
5270: foreach my $key (keys(%{$attr_ref})) {
5271: if (lc($key) eq 'onload') {
5272: $on_load.=$attr_ref->{$key}.';';
5273: delete($attr_ref->{$key});
5274:
5275: } elsif (lc($key) eq 'onunload') {
5276: $on_unload.=$attr_ref->{$key}.';';
5277: delete($attr_ref->{$key});
5278: }
5279: }
1.1075.2.12 raeburn 5280: if ($env{'environment.remote'} eq 'on') {
5281: $attr_ref->{'onload'} =
5282: &Apache::lonmenu::loadevents(). $on_load;
5283: $attr_ref->{'onunload'}=
5284: &Apache::lonmenu::unloadevents().$on_unload;
5285: } else {
5286: $attr_ref->{'onload'} = $on_load;
5287: $attr_ref->{'onunload'}= $on_unload;
5288: }
1.330 albertel 5289: }
1.339 albertel 5290:
1.330 albertel 5291: my $attr_string;
1.1075.2.56 raeburn 5292: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5293: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5294: }
5295: return $attr_string;
5296: }
5297:
5298:
1.182 matthew 5299: ###############################################
1.251 albertel 5300: ###############################################
5301:
5302: =pod
5303:
5304: =item * &endbodytag()
5305:
5306: Returns a uniform footer for LON-CAPA web pages.
5307:
1.635 raeburn 5308: Inputs: 1 - optional reference to an args hash
5309: If in the hash, key for noredirectlink has a value which evaluates to true,
5310: a 'Continue' link is not displayed if the page contains an
5311: internal redirect in the <head></head> section,
5312: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5313:
5314: =cut
5315:
5316: sub endbodytag {
1.635 raeburn 5317: my ($args) = @_;
1.1075.2.6 raeburn 5318: my $endbodytag;
5319: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5320: $endbodytag='</body>';
5321: }
1.269 albertel 5322: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5323: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5324: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5325: $endbodytag=
5326: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5327: &mt('Continue').'</a>'.
5328: $endbodytag;
5329: }
1.315 albertel 5330: }
1.251 albertel 5331: return $endbodytag;
5332: }
5333:
1.352 albertel 5334: =pod
5335:
5336: =item * &standard_css()
5337:
5338: Returns a style sheet
5339:
5340: Inputs: (all optional)
5341: domain -> force to color decorate a page for a specific
5342: domain
5343: function -> force usage of a specific rolish color scheme
5344: bgcolor -> override the default page bgcolor
5345:
5346: =cut
5347:
1.343 albertel 5348: sub standard_css {
1.345 albertel 5349: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5350: $function = &get_users_function() if (!$function);
5351: my $img = &designparm($function.'.img', $domain);
5352: my $tabbg = &designparm($function.'.tabbg', $domain);
5353: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5354: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5355: #second colour for later usage
1.345 albertel 5356: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5357: my $pgbg_or_bgcolor =
5358: $bgcolor ||
1.352 albertel 5359: &designparm($function.'.pgbg', $domain);
1.382 albertel 5360: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5361: my $alink = &designparm($function.'.alink', $domain);
5362: my $vlink = &designparm($function.'.vlink', $domain);
5363: my $link = &designparm($function.'.link', $domain);
5364:
1.602 albertel 5365: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5366: my $mono = 'monospace';
1.850 bisitz 5367: my $data_table_head = $sidebg;
5368: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5369: my $data_table_dark = '#E0E0E0';
1.470 banghart 5370: my $data_table_darker = '#CCCCCC';
1.349 albertel 5371: my $data_table_highlight = '#FFFF00';
1.352 albertel 5372: my $mail_new = '#FFBB77';
5373: my $mail_new_hover = '#DD9955';
5374: my $mail_read = '#BBBB77';
5375: my $mail_read_hover = '#999944';
5376: my $mail_replied = '#AAAA88';
5377: my $mail_replied_hover = '#888855';
5378: my $mail_other = '#99BBBB';
5379: my $mail_other_hover = '#669999';
1.391 albertel 5380: my $table_header = '#DDDDDD';
1.489 raeburn 5381: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5382: my $lg_border_color = '#C8C8C8';
1.952 onken 5383: my $button_hover = '#BF2317';
1.392 albertel 5384:
1.608 albertel 5385: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5386: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5387: : '0 3px 0 4px';
1.448 albertel 5388:
1.523 albertel 5389:
1.343 albertel 5390: return <<END;
1.947 droeschl 5391:
5392: /* needed for iframe to allow 100% height in FF */
5393: body, html {
5394: margin: 0;
5395: padding: 0 0.5%;
5396: height: 99%; /* to avoid scrollbars */
5397: }
5398:
1.795 www 5399: body {
1.911 bisitz 5400: font-family: $sans;
5401: line-height:130%;
5402: font-size:0.83em;
5403: color:$font;
1.795 www 5404: }
5405:
1.959 onken 5406: a:focus,
5407: a:focus img {
1.795 www 5408: color: red;
5409: }
1.698 harmsja 5410:
1.911 bisitz 5411: form, .inline {
5412: display: inline;
1.795 www 5413: }
1.721 harmsja 5414:
1.795 www 5415: .LC_right {
1.911 bisitz 5416: text-align:right;
1.795 www 5417: }
5418:
5419: .LC_middle {
1.911 bisitz 5420: vertical-align:middle;
1.795 www 5421: }
1.721 harmsja 5422:
1.1075.2.38 raeburn 5423: .LC_floatleft {
5424: float: left;
5425: }
5426:
5427: .LC_floatright {
5428: float: right;
5429: }
5430:
1.911 bisitz 5431: .LC_400Box {
5432: width:400px;
5433: }
1.721 harmsja 5434:
1.947 droeschl 5435: .LC_iframecontainer {
5436: width: 98%;
5437: margin: 0;
5438: position: fixed;
5439: top: 8.5em;
5440: bottom: 0;
5441: }
5442:
5443: .LC_iframecontainer iframe{
5444: border: none;
5445: width: 100%;
5446: height: 100%;
5447: }
5448:
1.778 bisitz 5449: .LC_filename {
5450: font-family: $mono;
5451: white-space:pre;
1.921 bisitz 5452: font-size: 120%;
1.778 bisitz 5453: }
5454:
5455: .LC_fileicon {
5456: border: none;
5457: height: 1.3em;
5458: vertical-align: text-bottom;
5459: margin-right: 0.3em;
5460: text-decoration:none;
5461: }
5462:
1.1008 www 5463: .LC_setting {
5464: text-decoration:underline;
5465: }
5466:
1.350 albertel 5467: .LC_error {
5468: color: red;
5469: }
1.795 www 5470:
1.1075.2.15 raeburn 5471: .LC_warning {
5472: color: darkorange;
5473: }
5474:
1.457 albertel 5475: .LC_diff_removed {
1.733 bisitz 5476: color: red;
1.394 albertel 5477: }
1.532 albertel 5478:
5479: .LC_info,
1.457 albertel 5480: .LC_success,
5481: .LC_diff_added {
1.350 albertel 5482: color: green;
5483: }
1.795 www 5484:
1.802 bisitz 5485: div.LC_confirm_box {
5486: background-color: #FAFAFA;
5487: border: 1px solid $lg_border_color;
5488: margin-right: 0;
5489: padding: 5px;
5490: }
5491:
5492: div.LC_confirm_box .LC_error img,
5493: div.LC_confirm_box .LC_success img {
5494: vertical-align: middle;
5495: }
5496:
1.440 albertel 5497: .LC_icon {
1.771 droeschl 5498: border: none;
1.790 droeschl 5499: vertical-align: middle;
1.771 droeschl 5500: }
5501:
1.543 albertel 5502: .LC_docs_spacer {
5503: width: 25px;
5504: height: 1px;
1.771 droeschl 5505: border: none;
1.543 albertel 5506: }
1.346 albertel 5507:
1.532 albertel 5508: .LC_internal_info {
1.735 bisitz 5509: color: #999999;
1.532 albertel 5510: }
5511:
1.794 www 5512: .LC_discussion {
1.1050 www 5513: background: $data_table_dark;
1.911 bisitz 5514: border: 1px solid black;
5515: margin: 2px;
1.794 www 5516: }
5517:
5518: .LC_disc_action_left {
1.1050 www 5519: background: $sidebg;
1.911 bisitz 5520: text-align: left;
1.1050 www 5521: padding: 4px;
5522: margin: 2px;
1.794 www 5523: }
5524:
5525: .LC_disc_action_right {
1.1050 www 5526: background: $sidebg;
1.911 bisitz 5527: text-align: right;
1.1050 www 5528: padding: 4px;
5529: margin: 2px;
1.794 www 5530: }
5531:
5532: .LC_disc_new_item {
1.911 bisitz 5533: background: white;
5534: border: 2px solid red;
1.1050 www 5535: margin: 4px;
5536: padding: 4px;
1.794 www 5537: }
5538:
5539: .LC_disc_old_item {
1.911 bisitz 5540: background: white;
1.1050 www 5541: margin: 4px;
5542: padding: 4px;
1.794 www 5543: }
5544:
1.458 albertel 5545: table.LC_pastsubmission {
5546: border: 1px solid black;
5547: margin: 2px;
5548: }
5549:
1.924 bisitz 5550: table#LC_menubuttons {
1.345 albertel 5551: width: 100%;
5552: background: $pgbg;
1.392 albertel 5553: border: 2px;
1.402 albertel 5554: border-collapse: separate;
1.803 bisitz 5555: padding: 0;
1.345 albertel 5556: }
1.392 albertel 5557:
1.801 tempelho 5558: table#LC_title_bar a {
5559: color: $fontmenu;
5560: }
1.836 bisitz 5561:
1.807 droeschl 5562: table#LC_title_bar {
1.819 tempelho 5563: clear: both;
1.836 bisitz 5564: display: none;
1.807 droeschl 5565: }
5566:
1.795 www 5567: table#LC_title_bar,
1.933 droeschl 5568: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5569: table#LC_title_bar.LC_with_remote {
1.359 albertel 5570: width: 100%;
1.392 albertel 5571: border-color: $pgbg;
5572: border-style: solid;
5573: border-width: $border;
1.379 albertel 5574: background: $pgbg;
1.801 tempelho 5575: color: $fontmenu;
1.392 albertel 5576: border-collapse: collapse;
1.803 bisitz 5577: padding: 0;
1.819 tempelho 5578: margin: 0;
1.359 albertel 5579: }
1.795 www 5580:
1.933 droeschl 5581: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5582: margin: 0;
5583: padding: 0;
1.933 droeschl 5584: position: relative;
5585: list-style: none;
1.913 droeschl 5586: }
1.933 droeschl 5587: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5588: display: inline;
5589: }
1.933 droeschl 5590:
5591: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5592: padding: 0;
1.933 droeschl 5593: margin: 0;
5594: float: left;
1.913 droeschl 5595: }
1.933 droeschl 5596: .LC_breadcrumb_tools_tools {
5597: padding: 0;
5598: margin: 0;
1.913 droeschl 5599: float: right;
5600: }
5601:
1.359 albertel 5602: table#LC_title_bar td {
5603: background: $tabbg;
5604: }
1.795 www 5605:
1.911 bisitz 5606: table#LC_menubuttons img {
1.803 bisitz 5607: border: none;
1.346 albertel 5608: }
1.795 www 5609:
1.842 droeschl 5610: .LC_breadcrumbs_component {
1.911 bisitz 5611: float: right;
5612: margin: 0 1em;
1.357 albertel 5613: }
1.842 droeschl 5614: .LC_breadcrumbs_component img {
1.911 bisitz 5615: vertical-align: middle;
1.777 tempelho 5616: }
1.795 www 5617:
1.383 albertel 5618: td.LC_table_cell_checkbox {
5619: text-align: center;
5620: }
1.795 www 5621:
5622: .LC_fontsize_small {
1.911 bisitz 5623: font-size: 70%;
1.705 tempelho 5624: }
5625:
1.844 bisitz 5626: #LC_breadcrumbs {
1.911 bisitz 5627: clear:both;
5628: background: $sidebg;
5629: border-bottom: 1px solid $lg_border_color;
5630: line-height: 2.5em;
1.933 droeschl 5631: overflow: hidden;
1.911 bisitz 5632: margin: 0;
5633: padding: 0;
1.995 raeburn 5634: text-align: left;
1.819 tempelho 5635: }
1.862 bisitz 5636:
1.1075.2.16 raeburn 5637: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5638: clear:both;
5639: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5640: border: 1px solid $sidebg;
1.1075.2.16 raeburn 5641: margin: 0 0 10px 0;
1.966 bisitz 5642: padding: 3px;
1.995 raeburn 5643: text-align: left;
1.822 bisitz 5644: }
5645:
1.795 www 5646: .LC_fontsize_medium {
1.911 bisitz 5647: font-size: 85%;
1.705 tempelho 5648: }
5649:
1.795 www 5650: .LC_fontsize_large {
1.911 bisitz 5651: font-size: 120%;
1.705 tempelho 5652: }
5653:
1.346 albertel 5654: .LC_menubuttons_inline_text {
5655: color: $font;
1.698 harmsja 5656: font-size: 90%;
1.701 harmsja 5657: padding-left:3px;
1.346 albertel 5658: }
5659:
1.934 droeschl 5660: .LC_menubuttons_inline_text img{
5661: vertical-align: middle;
5662: }
5663:
1.1051 www 5664: li.LC_menubuttons_inline_text img {
1.951 onken 5665: cursor:pointer;
1.1002 droeschl 5666: text-decoration: none;
1.951 onken 5667: }
5668:
1.526 www 5669: .LC_menubuttons_link {
5670: text-decoration: none;
5671: }
1.795 www 5672:
1.522 albertel 5673: .LC_menubuttons_category {
1.521 www 5674: color: $font;
1.526 www 5675: background: $pgbg;
1.521 www 5676: font-size: larger;
5677: font-weight: bold;
5678: }
5679:
1.346 albertel 5680: td.LC_menubuttons_text {
1.911 bisitz 5681: color: $font;
1.346 albertel 5682: }
1.706 harmsja 5683:
1.346 albertel 5684: .LC_current_location {
5685: background: $tabbg;
5686: }
1.795 www 5687:
1.938 bisitz 5688: table.LC_data_table {
1.347 albertel 5689: border: 1px solid #000000;
1.402 albertel 5690: border-collapse: separate;
1.426 albertel 5691: border-spacing: 1px;
1.610 albertel 5692: background: $pgbg;
1.347 albertel 5693: }
1.795 www 5694:
1.422 albertel 5695: .LC_data_table_dense {
5696: font-size: small;
5697: }
1.795 www 5698:
1.507 raeburn 5699: table.LC_nested_outer {
5700: border: 1px solid #000000;
1.589 raeburn 5701: border-collapse: collapse;
1.803 bisitz 5702: border-spacing: 0;
1.507 raeburn 5703: width: 100%;
5704: }
1.795 www 5705:
1.879 raeburn 5706: table.LC_innerpickbox,
1.507 raeburn 5707: table.LC_nested {
1.803 bisitz 5708: border: none;
1.589 raeburn 5709: border-collapse: collapse;
1.803 bisitz 5710: border-spacing: 0;
1.507 raeburn 5711: width: 100%;
5712: }
1.795 www 5713:
1.911 bisitz 5714: table.LC_data_table tr th,
5715: table.LC_calendar tr th,
1.879 raeburn 5716: table.LC_prior_tries tr th,
5717: table.LC_innerpickbox tr th {
1.349 albertel 5718: font-weight: bold;
5719: background-color: $data_table_head;
1.801 tempelho 5720: color:$fontmenu;
1.701 harmsja 5721: font-size:90%;
1.347 albertel 5722: }
1.795 www 5723:
1.879 raeburn 5724: table.LC_innerpickbox tr th,
5725: table.LC_innerpickbox tr td {
5726: vertical-align: top;
5727: }
5728:
1.711 raeburn 5729: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5730: background-color: #CCCCCC;
1.711 raeburn 5731: font-weight: bold;
5732: text-align: left;
5733: }
1.795 www 5734:
1.912 bisitz 5735: table.LC_data_table tr.LC_odd_row > td {
5736: background-color: $data_table_light;
5737: padding: 2px;
5738: vertical-align: top;
5739: }
5740:
1.809 bisitz 5741: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5742: background-color: $data_table_light;
1.912 bisitz 5743: vertical-align: top;
5744: }
5745:
5746: table.LC_data_table tr.LC_even_row > td {
5747: background-color: $data_table_dark;
1.425 albertel 5748: padding: 2px;
1.900 bisitz 5749: vertical-align: top;
1.347 albertel 5750: }
1.795 www 5751:
1.809 bisitz 5752: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5753: background-color: $data_table_dark;
1.900 bisitz 5754: vertical-align: top;
1.347 albertel 5755: }
1.795 www 5756:
1.425 albertel 5757: table.LC_data_table tr.LC_data_table_highlight td {
5758: background-color: $data_table_darker;
5759: }
1.795 www 5760:
1.639 raeburn 5761: table.LC_data_table tr td.LC_leftcol_header {
5762: background-color: $data_table_head;
5763: font-weight: bold;
5764: }
1.795 www 5765:
1.451 albertel 5766: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5767: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5768: font-weight: bold;
5769: font-style: italic;
5770: text-align: center;
5771: padding: 8px;
1.347 albertel 5772: }
1.795 www 5773:
1.1075.2.30 raeburn 5774: table.LC_data_table tr.LC_empty_row td,
5775: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5776: background-color: $sidebg;
5777: }
5778:
5779: table.LC_nested tr.LC_empty_row td {
5780: background-color: #FFFFFF;
5781: }
5782:
1.890 droeschl 5783: table.LC_caption {
5784: }
5785:
1.507 raeburn 5786: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5787: padding: 4ex
5788: }
1.795 www 5789:
1.507 raeburn 5790: table.LC_nested_outer tr th {
5791: font-weight: bold;
1.801 tempelho 5792: color:$fontmenu;
1.507 raeburn 5793: background-color: $data_table_head;
1.701 harmsja 5794: font-size: small;
1.507 raeburn 5795: border-bottom: 1px solid #000000;
5796: }
1.795 www 5797:
1.507 raeburn 5798: table.LC_nested_outer tr td.LC_subheader {
5799: background-color: $data_table_head;
5800: font-weight: bold;
5801: font-size: small;
5802: border-bottom: 1px solid #000000;
5803: text-align: right;
1.451 albertel 5804: }
1.795 www 5805:
1.507 raeburn 5806: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5807: background-color: #CCCCCC;
1.451 albertel 5808: font-weight: bold;
5809: font-size: small;
1.507 raeburn 5810: text-align: center;
5811: }
1.795 www 5812:
1.589 raeburn 5813: table.LC_nested tr.LC_info_row td.LC_left_item,
5814: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5815: text-align: left;
1.451 albertel 5816: }
1.795 www 5817:
1.507 raeburn 5818: table.LC_nested td {
1.735 bisitz 5819: background-color: #FFFFFF;
1.451 albertel 5820: font-size: small;
1.507 raeburn 5821: }
1.795 www 5822:
1.507 raeburn 5823: table.LC_nested_outer tr th.LC_right_item,
5824: table.LC_nested tr.LC_info_row td.LC_right_item,
5825: table.LC_nested tr.LC_odd_row td.LC_right_item,
5826: table.LC_nested tr td.LC_right_item {
1.451 albertel 5827: text-align: right;
5828: }
5829:
1.507 raeburn 5830: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5831: background-color: #EEEEEE;
1.451 albertel 5832: }
5833:
1.473 raeburn 5834: table.LC_createuser {
5835: }
5836:
5837: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5838: font-size: small;
1.473 raeburn 5839: }
5840:
5841: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5842: background-color: #CCCCCC;
1.473 raeburn 5843: font-weight: bold;
5844: text-align: center;
5845: }
5846:
1.349 albertel 5847: table.LC_calendar {
5848: border: 1px solid #000000;
5849: border-collapse: collapse;
1.917 raeburn 5850: width: 98%;
1.349 albertel 5851: }
1.795 www 5852:
1.349 albertel 5853: table.LC_calendar_pickdate {
5854: font-size: xx-small;
5855: }
1.795 www 5856:
1.349 albertel 5857: table.LC_calendar tr td {
5858: border: 1px solid #000000;
5859: vertical-align: top;
1.917 raeburn 5860: width: 14%;
1.349 albertel 5861: }
1.795 www 5862:
1.349 albertel 5863: table.LC_calendar tr td.LC_calendar_day_empty {
5864: background-color: $data_table_dark;
5865: }
1.795 www 5866:
1.779 bisitz 5867: table.LC_calendar tr td.LC_calendar_day_current {
5868: background-color: $data_table_highlight;
1.777 tempelho 5869: }
1.795 www 5870:
1.938 bisitz 5871: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5872: background-color: $mail_new;
5873: }
1.795 www 5874:
1.938 bisitz 5875: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5876: background-color: $mail_new_hover;
5877: }
1.795 www 5878:
1.938 bisitz 5879: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5880: background-color: $mail_read;
5881: }
1.795 www 5882:
1.938 bisitz 5883: /*
5884: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5885: background-color: $mail_read_hover;
5886: }
1.938 bisitz 5887: */
1.795 www 5888:
1.938 bisitz 5889: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5890: background-color: $mail_replied;
5891: }
1.795 www 5892:
1.938 bisitz 5893: /*
5894: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5895: background-color: $mail_replied_hover;
5896: }
1.938 bisitz 5897: */
1.795 www 5898:
1.938 bisitz 5899: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5900: background-color: $mail_other;
5901: }
1.795 www 5902:
1.938 bisitz 5903: /*
5904: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5905: background-color: $mail_other_hover;
5906: }
1.938 bisitz 5907: */
1.494 raeburn 5908:
1.777 tempelho 5909: table.LC_data_table tr > td.LC_browser_file,
5910: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5911: background: #AAEE77;
1.389 albertel 5912: }
1.795 www 5913:
1.777 tempelho 5914: table.LC_data_table tr > td.LC_browser_file_locked,
5915: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5916: background: #FFAA99;
1.387 albertel 5917: }
1.795 www 5918:
1.777 tempelho 5919: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5920: background: #888888;
1.779 bisitz 5921: }
1.795 www 5922:
1.777 tempelho 5923: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5924: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5925: background: #F8F866;
1.777 tempelho 5926: }
1.795 www 5927:
1.696 bisitz 5928: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5929: background: #E0E8FF;
1.387 albertel 5930: }
1.696 bisitz 5931:
1.707 bisitz 5932: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5933: /* background: #77FF77; */
1.707 bisitz 5934: }
1.795 www 5935:
1.707 bisitz 5936: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5937: border-right: 8px solid #FFFF77;
1.707 bisitz 5938: }
1.795 www 5939:
1.707 bisitz 5940: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5941: border-right: 8px solid #FFAA77;
1.707 bisitz 5942: }
1.795 www 5943:
1.707 bisitz 5944: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5945: border-right: 8px solid #FF7777;
1.707 bisitz 5946: }
1.795 www 5947:
1.707 bisitz 5948: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5949: border-right: 8px solid #AAFF77;
1.707 bisitz 5950: }
1.795 www 5951:
1.707 bisitz 5952: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5953: border-right: 8px solid #11CC55;
1.707 bisitz 5954: }
5955:
1.388 albertel 5956: span.LC_current_location {
1.701 harmsja 5957: font-size:larger;
1.388 albertel 5958: background: $pgbg;
5959: }
1.387 albertel 5960:
1.1029 www 5961: span.LC_current_nav_location {
5962: font-weight:bold;
5963: background: $sidebg;
5964: }
5965:
1.395 albertel 5966: span.LC_parm_menu_item {
5967: font-size: larger;
5968: }
1.795 www 5969:
1.395 albertel 5970: span.LC_parm_scope_all {
5971: color: red;
5972: }
1.795 www 5973:
1.395 albertel 5974: span.LC_parm_scope_folder {
5975: color: green;
5976: }
1.795 www 5977:
1.395 albertel 5978: span.LC_parm_scope_resource {
5979: color: orange;
5980: }
1.795 www 5981:
1.395 albertel 5982: span.LC_parm_part {
5983: color: blue;
5984: }
1.795 www 5985:
1.911 bisitz 5986: span.LC_parm_folder,
5987: span.LC_parm_symb {
1.395 albertel 5988: font-size: x-small;
5989: font-family: $mono;
5990: color: #AAAAAA;
5991: }
5992:
1.977 bisitz 5993: ul.LC_parm_parmlist li {
5994: display: inline-block;
5995: padding: 0.3em 0.8em;
5996: vertical-align: top;
5997: width: 150px;
5998: border-top:1px solid $lg_border_color;
5999: }
6000:
1.795 www 6001: td.LC_parm_overview_level_menu,
6002: td.LC_parm_overview_map_menu,
6003: td.LC_parm_overview_parm_selectors,
6004: td.LC_parm_overview_restrictions {
1.396 albertel 6005: border: 1px solid black;
6006: border-collapse: collapse;
6007: }
1.795 www 6008:
1.396 albertel 6009: table.LC_parm_overview_restrictions td {
6010: border-width: 1px 4px 1px 4px;
6011: border-style: solid;
6012: border-color: $pgbg;
6013: text-align: center;
6014: }
1.795 www 6015:
1.396 albertel 6016: table.LC_parm_overview_restrictions th {
6017: background: $tabbg;
6018: border-width: 1px 4px 1px 4px;
6019: border-style: solid;
6020: border-color: $pgbg;
6021: }
1.795 www 6022:
1.398 albertel 6023: table#LC_helpmenu {
1.803 bisitz 6024: border: none;
1.398 albertel 6025: height: 55px;
1.803 bisitz 6026: border-spacing: 0;
1.398 albertel 6027: }
6028:
6029: table#LC_helpmenu fieldset legend {
6030: font-size: larger;
6031: }
1.795 www 6032:
1.397 albertel 6033: table#LC_helpmenu_links {
6034: width: 100%;
6035: border: 1px solid black;
6036: background: $pgbg;
1.803 bisitz 6037: padding: 0;
1.397 albertel 6038: border-spacing: 1px;
6039: }
1.795 www 6040:
1.397 albertel 6041: table#LC_helpmenu_links tr td {
6042: padding: 1px;
6043: background: $tabbg;
1.399 albertel 6044: text-align: center;
6045: font-weight: bold;
1.397 albertel 6046: }
1.396 albertel 6047:
1.795 www 6048: table#LC_helpmenu_links a:link,
6049: table#LC_helpmenu_links a:visited,
1.397 albertel 6050: table#LC_helpmenu_links a:active {
6051: text-decoration: none;
6052: color: $font;
6053: }
1.795 www 6054:
1.397 albertel 6055: table#LC_helpmenu_links a:hover {
6056: text-decoration: underline;
6057: color: $vlink;
6058: }
1.396 albertel 6059:
1.417 albertel 6060: .LC_chrt_popup_exists {
6061: border: 1px solid #339933;
6062: margin: -1px;
6063: }
1.795 www 6064:
1.417 albertel 6065: .LC_chrt_popup_up {
6066: border: 1px solid yellow;
6067: margin: -1px;
6068: }
1.795 www 6069:
1.417 albertel 6070: .LC_chrt_popup {
6071: border: 1px solid #8888FF;
6072: background: #CCCCFF;
6073: }
1.795 www 6074:
1.421 albertel 6075: table.LC_pick_box {
6076: border-collapse: separate;
6077: background: white;
6078: border: 1px solid black;
6079: border-spacing: 1px;
6080: }
1.795 www 6081:
1.421 albertel 6082: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6083: background: $sidebg;
1.421 albertel 6084: font-weight: bold;
1.900 bisitz 6085: text-align: left;
1.740 bisitz 6086: vertical-align: top;
1.421 albertel 6087: width: 184px;
6088: padding: 8px;
6089: }
1.795 www 6090:
1.579 raeburn 6091: table.LC_pick_box td.LC_pick_box_value {
6092: text-align: left;
6093: padding: 8px;
6094: }
1.795 www 6095:
1.579 raeburn 6096: table.LC_pick_box td.LC_pick_box_select {
6097: text-align: left;
6098: padding: 8px;
6099: }
1.795 www 6100:
1.424 albertel 6101: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6102: padding: 0;
1.421 albertel 6103: height: 1px;
6104: background: black;
6105: }
1.795 www 6106:
1.421 albertel 6107: table.LC_pick_box td.LC_pick_box_submit {
6108: text-align: right;
6109: }
1.795 www 6110:
1.579 raeburn 6111: table.LC_pick_box td.LC_evenrow_value {
6112: text-align: left;
6113: padding: 8px;
6114: background-color: $data_table_light;
6115: }
1.795 www 6116:
1.579 raeburn 6117: table.LC_pick_box td.LC_oddrow_value {
6118: text-align: left;
6119: padding: 8px;
6120: background-color: $data_table_light;
6121: }
1.795 www 6122:
1.579 raeburn 6123: span.LC_helpform_receipt_cat {
6124: font-weight: bold;
6125: }
1.795 www 6126:
1.424 albertel 6127: table.LC_group_priv_box {
6128: background: white;
6129: border: 1px solid black;
6130: border-spacing: 1px;
6131: }
1.795 www 6132:
1.424 albertel 6133: table.LC_group_priv_box td.LC_pick_box_title {
6134: background: $tabbg;
6135: font-weight: bold;
6136: text-align: right;
6137: width: 184px;
6138: }
1.795 www 6139:
1.424 albertel 6140: table.LC_group_priv_box td.LC_groups_fixed {
6141: background: $data_table_light;
6142: text-align: center;
6143: }
1.795 www 6144:
1.424 albertel 6145: table.LC_group_priv_box td.LC_groups_optional {
6146: background: $data_table_dark;
6147: text-align: center;
6148: }
1.795 www 6149:
1.424 albertel 6150: table.LC_group_priv_box td.LC_groups_functionality {
6151: background: $data_table_darker;
6152: text-align: center;
6153: font-weight: bold;
6154: }
1.795 www 6155:
1.424 albertel 6156: table.LC_group_priv td {
6157: text-align: left;
1.803 bisitz 6158: padding: 0;
1.424 albertel 6159: }
6160:
6161: .LC_navbuttons {
6162: margin: 2ex 0ex 2ex 0ex;
6163: }
1.795 www 6164:
1.423 albertel 6165: .LC_topic_bar {
6166: font-weight: bold;
6167: background: $tabbg;
1.918 wenzelju 6168: margin: 1em 0em 1em 2em;
1.805 bisitz 6169: padding: 3px;
1.918 wenzelju 6170: font-size: 1.2em;
1.423 albertel 6171: }
1.795 www 6172:
1.423 albertel 6173: .LC_topic_bar span {
1.918 wenzelju 6174: left: 0.5em;
6175: position: absolute;
1.423 albertel 6176: vertical-align: middle;
1.918 wenzelju 6177: font-size: 1.2em;
1.423 albertel 6178: }
1.795 www 6179:
1.423 albertel 6180: table.LC_course_group_status {
6181: margin: 20px;
6182: }
1.795 www 6183:
1.423 albertel 6184: table.LC_status_selector td {
6185: vertical-align: top;
6186: text-align: center;
1.424 albertel 6187: padding: 4px;
6188: }
1.795 www 6189:
1.599 albertel 6190: div.LC_feedback_link {
1.616 albertel 6191: clear: both;
1.829 kalberla 6192: background: $sidebg;
1.779 bisitz 6193: width: 100%;
1.829 kalberla 6194: padding-bottom: 10px;
6195: border: 1px $tabbg solid;
1.833 kalberla 6196: height: 22px;
6197: line-height: 22px;
6198: padding-top: 5px;
6199: }
6200:
6201: div.LC_feedback_link img {
6202: height: 22px;
1.867 kalberla 6203: vertical-align:middle;
1.829 kalberla 6204: }
6205:
1.911 bisitz 6206: div.LC_feedback_link a {
1.829 kalberla 6207: text-decoration: none;
1.489 raeburn 6208: }
1.795 www 6209:
1.867 kalberla 6210: div.LC_comblock {
1.911 bisitz 6211: display:inline;
1.867 kalberla 6212: color:$font;
6213: font-size:90%;
6214: }
6215:
6216: div.LC_feedback_link div.LC_comblock {
6217: padding-left:5px;
6218: }
6219:
6220: div.LC_feedback_link div.LC_comblock a {
6221: color:$font;
6222: }
6223:
1.489 raeburn 6224: span.LC_feedback_link {
1.858 bisitz 6225: /* background: $feedback_link_bg; */
1.599 albertel 6226: font-size: larger;
6227: }
1.795 www 6228:
1.599 albertel 6229: span.LC_message_link {
1.858 bisitz 6230: /* background: $feedback_link_bg; */
1.599 albertel 6231: font-size: larger;
6232: position: absolute;
6233: right: 1em;
1.489 raeburn 6234: }
1.421 albertel 6235:
1.515 albertel 6236: table.LC_prior_tries {
1.524 albertel 6237: border: 1px solid #000000;
6238: border-collapse: separate;
6239: border-spacing: 1px;
1.515 albertel 6240: }
1.523 albertel 6241:
1.515 albertel 6242: table.LC_prior_tries td {
1.524 albertel 6243: padding: 2px;
1.515 albertel 6244: }
1.523 albertel 6245:
6246: .LC_answer_correct {
1.795 www 6247: background: lightgreen;
6248: color: darkgreen;
6249: padding: 6px;
1.523 albertel 6250: }
1.795 www 6251:
1.523 albertel 6252: .LC_answer_charged_try {
1.797 www 6253: background: #FFAAAA;
1.795 www 6254: color: darkred;
6255: padding: 6px;
1.523 albertel 6256: }
1.795 www 6257:
1.779 bisitz 6258: .LC_answer_not_charged_try,
1.523 albertel 6259: .LC_answer_no_grade,
6260: .LC_answer_late {
1.795 www 6261: background: lightyellow;
1.523 albertel 6262: color: black;
1.795 www 6263: padding: 6px;
1.523 albertel 6264: }
1.795 www 6265:
1.523 albertel 6266: .LC_answer_previous {
1.795 www 6267: background: lightblue;
6268: color: darkblue;
6269: padding: 6px;
1.523 albertel 6270: }
1.795 www 6271:
1.779 bisitz 6272: .LC_answer_no_message {
1.777 tempelho 6273: background: #FFFFFF;
6274: color: black;
1.795 www 6275: padding: 6px;
1.779 bisitz 6276: }
1.795 www 6277:
1.779 bisitz 6278: .LC_answer_unknown {
6279: background: orange;
6280: color: black;
1.795 www 6281: padding: 6px;
1.777 tempelho 6282: }
1.795 www 6283:
1.529 albertel 6284: span.LC_prior_numerical,
6285: span.LC_prior_string,
6286: span.LC_prior_custom,
6287: span.LC_prior_reaction,
6288: span.LC_prior_math {
1.925 bisitz 6289: font-family: $mono;
1.523 albertel 6290: white-space: pre;
6291: }
6292:
1.525 albertel 6293: span.LC_prior_string {
1.925 bisitz 6294: font-family: $mono;
1.525 albertel 6295: white-space: pre;
6296: }
6297:
1.523 albertel 6298: table.LC_prior_option {
6299: width: 100%;
6300: border-collapse: collapse;
6301: }
1.795 www 6302:
1.911 bisitz 6303: table.LC_prior_rank,
1.795 www 6304: table.LC_prior_match {
1.528 albertel 6305: border-collapse: collapse;
6306: }
1.795 www 6307:
1.528 albertel 6308: table.LC_prior_option tr td,
6309: table.LC_prior_rank tr td,
6310: table.LC_prior_match tr td {
1.524 albertel 6311: border: 1px solid #000000;
1.515 albertel 6312: }
6313:
1.855 bisitz 6314: .LC_nobreak {
1.544 albertel 6315: white-space: nowrap;
1.519 raeburn 6316: }
6317:
1.576 raeburn 6318: span.LC_cusr_emph {
6319: font-style: italic;
6320: }
6321:
1.633 raeburn 6322: span.LC_cusr_subheading {
6323: font-weight: normal;
6324: font-size: 85%;
6325: }
6326:
1.861 bisitz 6327: div.LC_docs_entry_move {
1.859 bisitz 6328: border: 1px solid #BBBBBB;
1.545 albertel 6329: background: #DDDDDD;
1.861 bisitz 6330: width: 22px;
1.859 bisitz 6331: padding: 1px;
6332: margin: 0;
1.545 albertel 6333: }
6334:
1.861 bisitz 6335: table.LC_data_table tr > td.LC_docs_entry_commands,
6336: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6337: font-size: x-small;
6338: }
1.795 www 6339:
1.861 bisitz 6340: .LC_docs_entry_parameter {
6341: white-space: nowrap;
6342: }
6343:
1.544 albertel 6344: .LC_docs_copy {
1.545 albertel 6345: color: #000099;
1.544 albertel 6346: }
1.795 www 6347:
1.544 albertel 6348: .LC_docs_cut {
1.545 albertel 6349: color: #550044;
1.544 albertel 6350: }
1.795 www 6351:
1.544 albertel 6352: .LC_docs_rename {
1.545 albertel 6353: color: #009900;
1.544 albertel 6354: }
1.795 www 6355:
1.544 albertel 6356: .LC_docs_remove {
1.545 albertel 6357: color: #990000;
6358: }
6359:
1.547 albertel 6360: .LC_docs_reinit_warn,
6361: .LC_docs_ext_edit {
6362: font-size: x-small;
6363: }
6364:
1.545 albertel 6365: table.LC_docs_adddocs td,
6366: table.LC_docs_adddocs th {
6367: border: 1px solid #BBBBBB;
6368: padding: 4px;
6369: background: #DDDDDD;
1.543 albertel 6370: }
6371:
1.584 albertel 6372: table.LC_sty_begin {
6373: background: #BBFFBB;
6374: }
1.795 www 6375:
1.584 albertel 6376: table.LC_sty_end {
6377: background: #FFBBBB;
6378: }
6379:
1.589 raeburn 6380: table.LC_double_column {
1.803 bisitz 6381: border-width: 0;
1.589 raeburn 6382: border-collapse: collapse;
6383: width: 100%;
6384: padding: 2px;
6385: }
6386:
6387: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6388: top: 2px;
1.589 raeburn 6389: left: 2px;
6390: width: 47%;
6391: vertical-align: top;
6392: }
6393:
6394: table.LC_double_column tr td.LC_right_col {
6395: top: 2px;
1.779 bisitz 6396: right: 2px;
1.589 raeburn 6397: width: 47%;
6398: vertical-align: top;
6399: }
6400:
1.591 raeburn 6401: div.LC_left_float {
6402: float: left;
6403: padding-right: 5%;
1.597 albertel 6404: padding-bottom: 4px;
1.591 raeburn 6405: }
6406:
6407: div.LC_clear_float_header {
1.597 albertel 6408: padding-bottom: 2px;
1.591 raeburn 6409: }
6410:
6411: div.LC_clear_float_footer {
1.597 albertel 6412: padding-top: 10px;
1.591 raeburn 6413: clear: both;
6414: }
6415:
1.597 albertel 6416: div.LC_grade_show_user {
1.941 bisitz 6417: /* border-left: 5px solid $sidebg; */
6418: border-top: 5px solid #000000;
6419: margin: 50px 0 0 0;
1.936 bisitz 6420: padding: 15px 0 5px 10px;
1.597 albertel 6421: }
1.795 www 6422:
1.936 bisitz 6423: div.LC_grade_show_user_odd_row {
1.941 bisitz 6424: /* border-left: 5px solid #000000; */
6425: }
6426:
6427: div.LC_grade_show_user div.LC_Box {
6428: margin-right: 50px;
1.597 albertel 6429: }
6430:
6431: div.LC_grade_submissions,
6432: div.LC_grade_message_center,
1.936 bisitz 6433: div.LC_grade_info_links {
1.597 albertel 6434: margin: 5px;
6435: width: 99%;
6436: background: #FFFFFF;
6437: }
1.795 www 6438:
1.597 albertel 6439: div.LC_grade_submissions_header,
1.936 bisitz 6440: div.LC_grade_message_center_header {
1.705 tempelho 6441: font-weight: bold;
6442: font-size: large;
1.597 albertel 6443: }
1.795 www 6444:
1.597 albertel 6445: div.LC_grade_submissions_body,
1.936 bisitz 6446: div.LC_grade_message_center_body {
1.597 albertel 6447: border: 1px solid black;
6448: width: 99%;
6449: background: #FFFFFF;
6450: }
1.795 www 6451:
1.613 albertel 6452: table.LC_scantron_action {
6453: width: 100%;
6454: }
1.795 www 6455:
1.613 albertel 6456: table.LC_scantron_action tr th {
1.698 harmsja 6457: font-weight:bold;
6458: font-style:normal;
1.613 albertel 6459: }
1.795 www 6460:
1.779 bisitz 6461: .LC_edit_problem_header,
1.614 albertel 6462: div.LC_edit_problem_footer {
1.705 tempelho 6463: font-weight: normal;
6464: font-size: medium;
1.602 albertel 6465: margin: 2px;
1.1060 bisitz 6466: background-color: $sidebg;
1.600 albertel 6467: }
1.795 www 6468:
1.600 albertel 6469: div.LC_edit_problem_header,
1.602 albertel 6470: div.LC_edit_problem_header div,
1.614 albertel 6471: div.LC_edit_problem_footer,
6472: div.LC_edit_problem_footer div,
1.602 albertel 6473: div.LC_edit_problem_editxml_header,
6474: div.LC_edit_problem_editxml_header div {
1.600 albertel 6475: margin-top: 5px;
6476: }
1.795 www 6477:
1.600 albertel 6478: div.LC_edit_problem_header_title {
1.705 tempelho 6479: font-weight: bold;
6480: font-size: larger;
1.602 albertel 6481: background: $tabbg;
6482: padding: 3px;
1.1060 bisitz 6483: margin: 0 0 5px 0;
1.602 albertel 6484: }
1.795 www 6485:
1.602 albertel 6486: table.LC_edit_problem_header_title {
6487: width: 100%;
1.600 albertel 6488: background: $tabbg;
1.602 albertel 6489: }
6490:
6491: div.LC_edit_problem_discards {
6492: float: left;
6493: padding-bottom: 5px;
6494: }
1.795 www 6495:
1.602 albertel 6496: div.LC_edit_problem_saves {
6497: float: right;
6498: padding-bottom: 5px;
1.600 albertel 6499: }
1.795 www 6500:
1.1075.2.34 raeburn 6501: .LC_edit_opt {
6502: padding-left: 1em;
6503: white-space: nowrap;
6504: }
6505:
1.1075.2.57 raeburn 6506: .LC_edit_problem_latexhelper{
6507: text-align: right;
6508: }
6509:
6510: #LC_edit_problem_colorful div{
6511: margin-left: 40px;
6512: }
6513:
1.911 bisitz 6514: img.stift {
1.803 bisitz 6515: border-width: 0;
6516: vertical-align: middle;
1.677 riegler 6517: }
1.680 riegler 6518:
1.923 bisitz 6519: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6520: vertical-align: top;
1.777 tempelho 6521: }
1.795 www 6522:
1.716 raeburn 6523: div.LC_createcourse {
1.911 bisitz 6524: margin: 10px 10px 10px 10px;
1.716 raeburn 6525: }
6526:
1.917 raeburn 6527: .LC_dccid {
1.1075.2.38 raeburn 6528: float: right;
1.917 raeburn 6529: margin: 0.2em 0 0 0;
6530: padding: 0;
6531: font-size: 90%;
6532: display:none;
6533: }
6534:
1.897 wenzelju 6535: ol.LC_primary_menu a:hover,
1.721 harmsja 6536: ol#LC_MenuBreadcrumbs a:hover,
6537: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6538: ul#LC_secondary_menu a:hover,
1.721 harmsja 6539: .LC_FormSectionClearButton input:hover
1.795 www 6540: ul.LC_TabContent li:hover a {
1.952 onken 6541: color:$button_hover;
1.911 bisitz 6542: text-decoration:none;
1.693 droeschl 6543: }
6544:
1.779 bisitz 6545: h1 {
1.911 bisitz 6546: padding: 0;
6547: line-height:130%;
1.693 droeschl 6548: }
1.698 harmsja 6549:
1.911 bisitz 6550: h2,
6551: h3,
6552: h4,
6553: h5,
6554: h6 {
6555: margin: 5px 0 5px 0;
6556: padding: 0;
6557: line-height:130%;
1.693 droeschl 6558: }
1.795 www 6559:
6560: .LC_hcell {
1.911 bisitz 6561: padding:3px 15px 3px 15px;
6562: margin: 0;
6563: background-color:$tabbg;
6564: color:$fontmenu;
6565: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6566: }
1.795 www 6567:
1.840 bisitz 6568: .LC_Box > .LC_hcell {
1.911 bisitz 6569: margin: 0 -10px 10px -10px;
1.835 bisitz 6570: }
6571:
1.721 harmsja 6572: .LC_noBorder {
1.911 bisitz 6573: border: 0;
1.698 harmsja 6574: }
1.693 droeschl 6575:
1.721 harmsja 6576: .LC_FormSectionClearButton input {
1.911 bisitz 6577: background-color:transparent;
6578: border: none;
6579: cursor:pointer;
6580: text-decoration:underline;
1.693 droeschl 6581: }
1.763 bisitz 6582:
6583: .LC_help_open_topic {
1.911 bisitz 6584: color: #FFFFFF;
6585: background-color: #EEEEFF;
6586: margin: 1px;
6587: padding: 4px;
6588: border: 1px solid #000033;
6589: white-space: nowrap;
6590: /* vertical-align: middle; */
1.759 neumanie 6591: }
1.693 droeschl 6592:
1.911 bisitz 6593: dl,
6594: ul,
6595: div,
6596: fieldset {
6597: margin: 10px 10px 10px 0;
6598: /* overflow: hidden; */
1.693 droeschl 6599: }
1.795 www 6600:
1.838 bisitz 6601: fieldset > legend {
1.911 bisitz 6602: font-weight: bold;
6603: padding: 0 5px 0 5px;
1.838 bisitz 6604: }
6605:
1.813 bisitz 6606: #LC_nav_bar {
1.911 bisitz 6607: float: left;
1.995 raeburn 6608: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6609: margin: 0 0 2px 0;
1.807 droeschl 6610: }
6611:
1.916 droeschl 6612: #LC_realm {
6613: margin: 0.2em 0 0 0;
6614: padding: 0;
6615: font-weight: bold;
6616: text-align: center;
1.995 raeburn 6617: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6618: }
6619:
1.911 bisitz 6620: #LC_nav_bar em {
6621: font-weight: bold;
6622: font-style: normal;
1.807 droeschl 6623: }
6624:
1.897 wenzelju 6625: ol.LC_primary_menu {
1.934 droeschl 6626: margin: 0;
1.1075.2.2 raeburn 6627: padding: 0;
1.995 raeburn 6628: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6629: }
6630:
1.852 droeschl 6631: ol#LC_PathBreadcrumbs {
1.911 bisitz 6632: margin: 0;
1.693 droeschl 6633: }
6634:
1.897 wenzelju 6635: ol.LC_primary_menu li {
1.1075.2.2 raeburn 6636: color: RGB(80, 80, 80);
6637: vertical-align: middle;
6638: text-align: left;
6639: list-style: none;
6640: float: left;
6641: }
6642:
6643: ol.LC_primary_menu li a {
6644: display: block;
6645: margin: 0;
6646: padding: 0 5px 0 10px;
6647: text-decoration: none;
6648: }
6649:
6650: ol.LC_primary_menu li ul {
6651: display: none;
6652: width: 10em;
6653: background-color: $data_table_light;
6654: }
6655:
6656: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6657: display: block;
6658: position: absolute;
6659: margin: 0;
6660: padding: 0;
1.1075.2.5 raeburn 6661: z-index: 2;
1.1075.2.2 raeburn 6662: }
6663:
6664: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6665: font-size: 90%;
1.911 bisitz 6666: vertical-align: top;
1.1075.2.2 raeburn 6667: float: none;
1.1075.2.5 raeburn 6668: border-left: 1px solid black;
6669: border-right: 1px solid black;
1.1075.2.2 raeburn 6670: }
6671:
6672: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1075.2.5 raeburn 6673: background-color:$data_table_light;
1.1075.2.2 raeburn 6674: }
6675:
6676: ol.LC_primary_menu li li a:hover {
6677: color:$button_hover;
6678: background-color:$data_table_dark;
1.693 droeschl 6679: }
6680:
1.897 wenzelju 6681: ol.LC_primary_menu li img {
1.911 bisitz 6682: vertical-align: bottom;
1.934 droeschl 6683: height: 1.1em;
1.1075.2.3 raeburn 6684: margin: 0.2em 0 0 0;
1.693 droeschl 6685: }
6686:
1.897 wenzelju 6687: ol.LC_primary_menu a {
1.911 bisitz 6688: color: RGB(80, 80, 80);
6689: text-decoration: none;
1.693 droeschl 6690: }
1.795 www 6691:
1.949 droeschl 6692: ol.LC_primary_menu a.LC_new_message {
6693: font-weight:bold;
6694: color: darkred;
6695: }
6696:
1.975 raeburn 6697: ol.LC_docs_parameters {
6698: margin-left: 0;
6699: padding: 0;
6700: list-style: none;
6701: }
6702:
6703: ol.LC_docs_parameters li {
6704: margin: 0;
6705: padding-right: 20px;
6706: display: inline;
6707: }
6708:
1.976 raeburn 6709: ol.LC_docs_parameters li:before {
6710: content: "\\002022 \\0020";
6711: }
6712:
6713: li.LC_docs_parameters_title {
6714: font-weight: bold;
6715: }
6716:
6717: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6718: content: "";
6719: }
6720:
1.897 wenzelju 6721: ul#LC_secondary_menu {
1.1075.2.23 raeburn 6722: clear: right;
1.911 bisitz 6723: color: $fontmenu;
6724: background: $tabbg;
6725: list-style: none;
6726: padding: 0;
6727: margin: 0;
6728: width: 100%;
1.995 raeburn 6729: text-align: left;
1.1075.2.4 raeburn 6730: float: left;
1.808 droeschl 6731: }
6732:
1.897 wenzelju 6733: ul#LC_secondary_menu li {
1.911 bisitz 6734: font-weight: bold;
6735: line-height: 1.8em;
6736: border-right: 1px solid black;
6737: vertical-align: middle;
1.1075.2.4 raeburn 6738: float: left;
6739: }
6740:
6741: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6742: background-color: $data_table_light;
6743: }
6744:
6745: ul#LC_secondary_menu li a {
6746: padding: 0 0.8em;
6747: }
6748:
6749: ul#LC_secondary_menu li ul {
6750: display: none;
6751: }
6752:
6753: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6754: display: block;
6755: position: absolute;
6756: margin: 0;
6757: padding: 0;
6758: list-style:none;
6759: float: none;
6760: background-color: $data_table_light;
1.1075.2.5 raeburn 6761: z-index: 2;
1.1075.2.10 raeburn 6762: margin-left: -1px;
1.1075.2.4 raeburn 6763: }
6764:
6765: ul#LC_secondary_menu li ul li {
6766: font-size: 90%;
6767: vertical-align: top;
6768: border-left: 1px solid black;
6769: border-right: 1px solid black;
1.1075.2.33 raeburn 6770: background-color: $data_table_light;
1.1075.2.4 raeburn 6771: list-style:none;
6772: float: none;
6773: }
6774:
6775: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6776: background-color: $data_table_dark;
1.807 droeschl 6777: }
6778:
1.847 tempelho 6779: ul.LC_TabContent {
1.911 bisitz 6780: display:block;
6781: background: $sidebg;
6782: border-bottom: solid 1px $lg_border_color;
6783: list-style:none;
1.1020 raeburn 6784: margin: -1px -10px 0 -10px;
1.911 bisitz 6785: padding: 0;
1.693 droeschl 6786: }
6787:
1.795 www 6788: ul.LC_TabContent li,
6789: ul.LC_TabContentBigger li {
1.911 bisitz 6790: float:left;
1.741 harmsja 6791: }
1.795 www 6792:
1.897 wenzelju 6793: ul#LC_secondary_menu li a {
1.911 bisitz 6794: color: $fontmenu;
6795: text-decoration: none;
1.693 droeschl 6796: }
1.795 www 6797:
1.721 harmsja 6798: ul.LC_TabContent {
1.952 onken 6799: min-height:20px;
1.721 harmsja 6800: }
1.795 www 6801:
6802: ul.LC_TabContent li {
1.911 bisitz 6803: vertical-align:middle;
1.959 onken 6804: padding: 0 16px 0 10px;
1.911 bisitz 6805: background-color:$tabbg;
6806: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6807: border-left: solid 1px $font;
1.721 harmsja 6808: }
1.795 www 6809:
1.847 tempelho 6810: ul.LC_TabContent .right {
1.911 bisitz 6811: float:right;
1.847 tempelho 6812: }
6813:
1.911 bisitz 6814: ul.LC_TabContent li a,
6815: ul.LC_TabContent li {
6816: color:rgb(47,47,47);
6817: text-decoration:none;
6818: font-size:95%;
6819: font-weight:bold;
1.952 onken 6820: min-height:20px;
6821: }
6822:
1.959 onken 6823: ul.LC_TabContent li a:hover,
6824: ul.LC_TabContent li a:focus {
1.952 onken 6825: color: $button_hover;
1.959 onken 6826: background:none;
6827: outline:none;
1.952 onken 6828: }
6829:
6830: ul.LC_TabContent li:hover {
6831: color: $button_hover;
6832: cursor:pointer;
1.721 harmsja 6833: }
1.795 www 6834:
1.911 bisitz 6835: ul.LC_TabContent li.active {
1.952 onken 6836: color: $font;
1.911 bisitz 6837: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6838: border-bottom:solid 1px #FFFFFF;
6839: cursor: default;
1.744 ehlerst 6840: }
1.795 www 6841:
1.959 onken 6842: ul.LC_TabContent li.active a {
6843: color:$font;
6844: background:#FFFFFF;
6845: outline: none;
6846: }
1.1047 raeburn 6847:
6848: ul.LC_TabContent li.goback {
6849: float: left;
6850: border-left: none;
6851: }
6852:
1.870 tempelho 6853: #maincoursedoc {
1.911 bisitz 6854: clear:both;
1.870 tempelho 6855: }
6856:
6857: ul.LC_TabContentBigger {
1.911 bisitz 6858: display:block;
6859: list-style:none;
6860: padding: 0;
1.870 tempelho 6861: }
6862:
1.795 www 6863: ul.LC_TabContentBigger li {
1.911 bisitz 6864: vertical-align:bottom;
6865: height: 30px;
6866: font-size:110%;
6867: font-weight:bold;
6868: color: #737373;
1.841 tempelho 6869: }
6870:
1.957 onken 6871: ul.LC_TabContentBigger li.active {
6872: position: relative;
6873: top: 1px;
6874: }
6875:
1.870 tempelho 6876: ul.LC_TabContentBigger li a {
1.911 bisitz 6877: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6878: height: 30px;
6879: line-height: 30px;
6880: text-align: center;
6881: display: block;
6882: text-decoration: none;
1.958 onken 6883: outline: none;
1.741 harmsja 6884: }
1.795 www 6885:
1.870 tempelho 6886: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6887: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6888: color:$font;
1.744 ehlerst 6889: }
1.795 www 6890:
1.870 tempelho 6891: ul.LC_TabContentBigger li b {
1.911 bisitz 6892: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6893: display: block;
6894: float: left;
6895: padding: 0 30px;
1.957 onken 6896: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6897: }
6898:
1.956 onken 6899: ul.LC_TabContentBigger li:hover b {
6900: color:$button_hover;
6901: }
6902:
1.870 tempelho 6903: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6904: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6905: color:$font;
1.957 onken 6906: border: 0;
1.741 harmsja 6907: }
1.693 droeschl 6908:
1.870 tempelho 6909:
1.862 bisitz 6910: ul.LC_CourseBreadcrumbs {
6911: background: $sidebg;
1.1020 raeburn 6912: height: 2em;
1.862 bisitz 6913: padding-left: 10px;
1.1020 raeburn 6914: margin: 0;
1.862 bisitz 6915: list-style-position: inside;
6916: }
6917:
1.911 bisitz 6918: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6919: ol#LC_PathBreadcrumbs {
1.911 bisitz 6920: padding-left: 10px;
6921: margin: 0;
1.933 droeschl 6922: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6923: }
6924:
1.911 bisitz 6925: ol#LC_MenuBreadcrumbs li,
6926: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6927: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6928: display: inline;
1.933 droeschl 6929: white-space: normal;
1.693 droeschl 6930: }
6931:
1.823 bisitz 6932: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6933: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6934: text-decoration: none;
6935: font-size:90%;
1.693 droeschl 6936: }
1.795 www 6937:
1.969 droeschl 6938: ol#LC_MenuBreadcrumbs h1 {
6939: display: inline;
6940: font-size: 90%;
6941: line-height: 2.5em;
6942: margin: 0;
6943: padding: 0;
6944: }
6945:
1.795 www 6946: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6947: text-decoration:none;
6948: font-size:100%;
6949: font-weight:bold;
1.693 droeschl 6950: }
1.795 www 6951:
1.840 bisitz 6952: .LC_Box {
1.911 bisitz 6953: border: solid 1px $lg_border_color;
6954: padding: 0 10px 10px 10px;
1.746 neumanie 6955: }
1.795 www 6956:
1.1020 raeburn 6957: .LC_DocsBox {
6958: border: solid 1px $lg_border_color;
6959: padding: 0 0 10px 10px;
6960: }
6961:
1.795 www 6962: .LC_AboutMe_Image {
1.911 bisitz 6963: float:left;
6964: margin-right:10px;
1.747 neumanie 6965: }
1.795 www 6966:
6967: .LC_Clear_AboutMe_Image {
1.911 bisitz 6968: clear:left;
1.747 neumanie 6969: }
1.795 www 6970:
1.721 harmsja 6971: dl.LC_ListStyleClean dt {
1.911 bisitz 6972: padding-right: 5px;
6973: display: table-header-group;
1.693 droeschl 6974: }
6975:
1.721 harmsja 6976: dl.LC_ListStyleClean dd {
1.911 bisitz 6977: display: table-row;
1.693 droeschl 6978: }
6979:
1.721 harmsja 6980: .LC_ListStyleClean,
6981: .LC_ListStyleSimple,
6982: .LC_ListStyleNormal,
1.795 www 6983: .LC_ListStyleSpecial {
1.911 bisitz 6984: /* display:block; */
6985: list-style-position: inside;
6986: list-style-type: none;
6987: overflow: hidden;
6988: padding: 0;
1.693 droeschl 6989: }
6990:
1.721 harmsja 6991: .LC_ListStyleSimple li,
6992: .LC_ListStyleSimple dd,
6993: .LC_ListStyleNormal li,
6994: .LC_ListStyleNormal dd,
6995: .LC_ListStyleSpecial li,
1.795 www 6996: .LC_ListStyleSpecial dd {
1.911 bisitz 6997: margin: 0;
6998: padding: 5px 5px 5px 10px;
6999: clear: both;
1.693 droeschl 7000: }
7001:
1.721 harmsja 7002: .LC_ListStyleClean li,
7003: .LC_ListStyleClean dd {
1.911 bisitz 7004: padding-top: 0;
7005: padding-bottom: 0;
1.693 droeschl 7006: }
7007:
1.721 harmsja 7008: .LC_ListStyleSimple dd,
1.795 www 7009: .LC_ListStyleSimple li {
1.911 bisitz 7010: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7011: }
7012:
1.721 harmsja 7013: .LC_ListStyleSpecial li,
7014: .LC_ListStyleSpecial dd {
1.911 bisitz 7015: list-style-type: none;
7016: background-color: RGB(220, 220, 220);
7017: margin-bottom: 4px;
1.693 droeschl 7018: }
7019:
1.721 harmsja 7020: table.LC_SimpleTable {
1.911 bisitz 7021: margin:5px;
7022: border:solid 1px $lg_border_color;
1.795 www 7023: }
1.693 droeschl 7024:
1.721 harmsja 7025: table.LC_SimpleTable tr {
1.911 bisitz 7026: padding: 0;
7027: border:solid 1px $lg_border_color;
1.693 droeschl 7028: }
1.795 www 7029:
7030: table.LC_SimpleTable thead {
1.911 bisitz 7031: background:rgb(220,220,220);
1.693 droeschl 7032: }
7033:
1.721 harmsja 7034: div.LC_columnSection {
1.911 bisitz 7035: display: block;
7036: clear: both;
7037: overflow: hidden;
7038: margin: 0;
1.693 droeschl 7039: }
7040:
1.721 harmsja 7041: div.LC_columnSection>* {
1.911 bisitz 7042: float: left;
7043: margin: 10px 20px 10px 0;
7044: overflow:hidden;
1.693 droeschl 7045: }
1.721 harmsja 7046:
1.795 www 7047: table em {
1.911 bisitz 7048: font-weight: bold;
7049: font-style: normal;
1.748 schulted 7050: }
1.795 www 7051:
1.779 bisitz 7052: table.LC_tableBrowseRes,
1.795 www 7053: table.LC_tableOfContent {
1.911 bisitz 7054: border:none;
7055: border-spacing: 1px;
7056: padding: 3px;
7057: background-color: #FFFFFF;
7058: font-size: 90%;
1.753 droeschl 7059: }
1.789 droeschl 7060:
1.911 bisitz 7061: table.LC_tableOfContent {
7062: border-collapse: collapse;
1.789 droeschl 7063: }
7064:
1.771 droeschl 7065: table.LC_tableBrowseRes a,
1.768 schulted 7066: table.LC_tableOfContent a {
1.911 bisitz 7067: background-color: transparent;
7068: text-decoration: none;
1.753 droeschl 7069: }
7070:
1.795 www 7071: table.LC_tableOfContent img {
1.911 bisitz 7072: border: none;
7073: height: 1.3em;
7074: vertical-align: text-bottom;
7075: margin-right: 0.3em;
1.753 droeschl 7076: }
1.757 schulted 7077:
1.795 www 7078: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7079: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7080: }
7081:
1.795 www 7082: a#LC_content_toolbar_everything {
1.911 bisitz 7083: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7084: }
7085:
1.795 www 7086: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7087: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7088: }
7089:
1.795 www 7090: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7091: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7092: }
7093:
1.795 www 7094: a#LC_content_toolbar_changefolder {
1.911 bisitz 7095: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7096: }
7097:
1.795 www 7098: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7099: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7100: }
7101:
1.1043 raeburn 7102: a#LC_content_toolbar_edittoplevel {
7103: background-image:url(/res/adm/pages/edittoplevel.gif);
7104: }
7105:
1.795 www 7106: ul#LC_toolbar li a:hover {
1.911 bisitz 7107: background-position: bottom center;
1.757 schulted 7108: }
7109:
1.795 www 7110: ul#LC_toolbar {
1.911 bisitz 7111: padding: 0;
7112: margin: 2px;
7113: list-style:none;
7114: position:relative;
7115: background-color:white;
1.1075.2.9 raeburn 7116: overflow: auto;
1.757 schulted 7117: }
7118:
1.795 www 7119: ul#LC_toolbar li {
1.911 bisitz 7120: border:1px solid white;
7121: padding: 0;
7122: margin: 0;
7123: float: left;
7124: display:inline;
7125: vertical-align:middle;
1.1075.2.9 raeburn 7126: white-space: nowrap;
1.911 bisitz 7127: }
1.757 schulted 7128:
1.783 amueller 7129:
1.795 www 7130: a.LC_toolbarItem {
1.911 bisitz 7131: display:block;
7132: padding: 0;
7133: margin: 0;
7134: height: 32px;
7135: width: 32px;
7136: color:white;
7137: border: none;
7138: background-repeat:no-repeat;
7139: background-color:transparent;
1.757 schulted 7140: }
7141:
1.915 droeschl 7142: ul.LC_funclist {
7143: margin: 0;
7144: padding: 0.5em 1em 0.5em 0;
7145: }
7146:
1.933 droeschl 7147: ul.LC_funclist > li:first-child {
7148: font-weight:bold;
7149: margin-left:0.8em;
7150: }
7151:
1.915 droeschl 7152: ul.LC_funclist + ul.LC_funclist {
7153: /*
7154: left border as a seperator if we have more than
7155: one list
7156: */
7157: border-left: 1px solid $sidebg;
7158: /*
7159: this hides the left border behind the border of the
7160: outer box if element is wrapped to the next 'line'
7161: */
7162: margin-left: -1px;
7163: }
7164:
1.843 bisitz 7165: ul.LC_funclist li {
1.915 droeschl 7166: display: inline;
1.782 bisitz 7167: white-space: nowrap;
1.915 droeschl 7168: margin: 0 0 0 25px;
7169: line-height: 150%;
1.782 bisitz 7170: }
7171:
1.974 wenzelju 7172: .LC_hidden {
7173: display: none;
7174: }
7175:
1.1030 www 7176: .LCmodal-overlay {
7177: position:fixed;
7178: top:0;
7179: right:0;
7180: bottom:0;
7181: left:0;
7182: height:100%;
7183: width:100%;
7184: margin:0;
7185: padding:0;
7186: background:#999;
7187: opacity:.75;
7188: filter: alpha(opacity=75);
7189: -moz-opacity: 0.75;
7190: z-index:101;
7191: }
7192:
7193: * html .LCmodal-overlay {
7194: position: absolute;
7195: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7196: }
7197:
7198: .LCmodal-window {
7199: position:fixed;
7200: top:50%;
7201: left:50%;
7202: margin:0;
7203: padding:0;
7204: z-index:102;
7205: }
7206:
7207: * html .LCmodal-window {
7208: position:absolute;
7209: }
7210:
7211: .LCclose-window {
7212: position:absolute;
7213: width:32px;
7214: height:32px;
7215: right:8px;
7216: top:8px;
7217: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7218: text-indent:-99999px;
7219: overflow:hidden;
7220: cursor:pointer;
7221: }
7222:
1.1075.2.17 raeburn 7223: /*
7224: styles used by TTH when "Default set of options to pass to tth/m
7225: when converting TeX" in course settings has been set
7226:
7227: option passed: -t
7228:
7229: */
7230:
7231: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7232: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7233: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7234: td div.norm {line-height:normal;}
7235:
7236: /*
7237: option passed -y3
7238: */
7239:
7240: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7241: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7242: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7243:
1.343 albertel 7244: END
7245: }
7246:
1.306 albertel 7247: =pod
7248:
7249: =item * &headtag()
7250:
7251: Returns a uniform footer for LON-CAPA web pages.
7252:
1.307 albertel 7253: Inputs: $title - optional title for the head
7254: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7255: $args - optional arguments
1.319 albertel 7256: force_register - if is true call registerurl so the remote is
7257: informed
1.415 albertel 7258: redirect -> array ref of
7259: 1- seconds before redirect occurs
7260: 2- url to redirect to
7261: 3- whether the side effect should occur
1.315 albertel 7262: (side effect of setting
7263: $env{'internal.head.redirect'} to the url
7264: redirected too)
1.352 albertel 7265: domain -> force to color decorate a page for a specific
7266: domain
7267: function -> force usage of a specific rolish color scheme
7268: bgcolor -> override the default page bgcolor
1.460 albertel 7269: no_auto_mt_title
7270: -> prevent &mt()ing the title arg
1.464 albertel 7271:
1.306 albertel 7272: =cut
7273:
7274: sub headtag {
1.313 albertel 7275: my ($title,$head_extra,$args) = @_;
1.306 albertel 7276:
1.363 albertel 7277: my $function = $args->{'function'} || &get_users_function();
7278: my $domain = $args->{'domain'} || &determinedomain();
7279: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7280: my $httphost = $args->{'use_absolute'};
1.418 albertel 7281: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7282: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7283: #time(),
1.418 albertel 7284: $env{'environment.color.timestamp'},
1.363 albertel 7285: $function,$domain,$bgcolor);
7286:
1.369 www 7287: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7288:
1.308 albertel 7289: my $result =
7290: '<head>'.
1.1075.2.56 raeburn 7291: &font_settings($args);
1.319 albertel 7292:
1.1064 raeburn 7293: my $inhibitprint = &print_suppression();
7294:
1.461 albertel 7295: if (!$args->{'frameset'}) {
7296: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7297: }
1.1075.2.12 raeburn 7298: if ($args->{'force_register'}) {
7299: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7300: }
1.436 albertel 7301: if (!$args->{'no_nav_bar'}
7302: && !$args->{'only_body'}
7303: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7304: $result .= &help_menu_js($httphost);
1.1032 www 7305: $result.=&modal_window();
1.1038 www 7306: $result.=&togglebox_script();
1.1034 www 7307: $result.=&wishlist_window();
1.1041 www 7308: $result.=&LCprogressbarUpdate_script();
1.1034 www 7309: } else {
7310: if ($args->{'add_modal'}) {
7311: $result.=&modal_window();
7312: }
7313: if ($args->{'add_wishlist'}) {
7314: $result.=&wishlist_window();
7315: }
1.1038 www 7316: if ($args->{'add_togglebox'}) {
7317: $result.=&togglebox_script();
7318: }
1.1041 www 7319: if ($args->{'add_progressbar'}) {
7320: $result.=&LCprogressbarUpdate_script();
7321: }
1.436 albertel 7322: }
1.314 albertel 7323: if (ref($args->{'redirect'})) {
1.414 albertel 7324: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7325: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7326: if (!$inhibit_continue) {
7327: $env{'internal.head.redirect'} = $url;
7328: }
1.313 albertel 7329: $result.=<<ADDMETA
7330: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7331: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7332: ADDMETA
7333: }
1.306 albertel 7334: if (!defined($title)) {
7335: $title = 'The LearningOnline Network with CAPA';
7336: }
1.460 albertel 7337: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7338: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 7339: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7340: if (!$args->{'frameset'}) {
7341: $result .= ' /';
7342: }
7343: $result .= '>'
1.1064 raeburn 7344: .$inhibitprint
1.414 albertel 7345: .$head_extra;
1.1075.2.42 raeburn 7346: if ($env{'browser.mobile'}) {
7347: $result .= '
7348: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7349: <meta name="apple-mobile-web-app-capable" content="yes" />';
7350: }
1.962 droeschl 7351: return $result.'</head>';
1.306 albertel 7352: }
7353:
7354: =pod
7355:
1.340 albertel 7356: =item * &font_settings()
7357:
7358: Returns neccessary <meta> to set the proper encoding
7359:
1.1075.2.56 raeburn 7360: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7361:
7362: =cut
7363:
7364: sub font_settings {
1.1075.2.56 raeburn 7365: my ($args) = @_;
1.340 albertel 7366: my $headerstring='';
1.1075.2.56 raeburn 7367: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7368: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 7369: $headerstring.=
1.1075.2.61 raeburn 7370: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7371: if (!$args->{'frameset'}) {
7372: $headerstring.= ' /';
7373: }
7374: $headerstring .= '>'."\n";
1.340 albertel 7375: }
7376: return $headerstring;
7377: }
7378:
1.341 albertel 7379: =pod
7380:
1.1064 raeburn 7381: =item * &print_suppression()
7382:
7383: In course context returns css which causes the body to be blank when media="print",
7384: if printout generation is unavailable for the current resource.
7385:
7386: This could be because:
7387:
7388: (a) printstartdate is in the future
7389:
7390: (b) printenddate is in the past
7391:
7392: (c) there is an active exam block with "printout"
7393: functionality blocked
7394:
7395: Users with pav, pfo or evb privileges are exempt.
7396:
7397: Inputs: none
7398:
7399: =cut
7400:
7401:
7402: sub print_suppression {
7403: my $noprint;
7404: if ($env{'request.course.id'}) {
7405: my $scope = $env{'request.course.id'};
7406: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7407: (&Apache::lonnet::allowed('pfo',$scope))) {
7408: return;
7409: }
7410: if ($env{'request.course.sec'} ne '') {
7411: $scope .= "/$env{'request.course.sec'}";
7412: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7413: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7414: return;
1.1064 raeburn 7415: }
7416: }
7417: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7418: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065 raeburn 7419: my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064 raeburn 7420: if ($blocked) {
7421: my $checkrole = "cm./$cdom/$cnum";
7422: if ($env{'request.course.sec'} ne '') {
7423: $checkrole .= "/$env{'request.course.sec'}";
7424: }
7425: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7426: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7427: $noprint = 1;
7428: }
7429: }
7430: unless ($noprint) {
7431: my $symb = &Apache::lonnet::symbread();
7432: if ($symb ne '') {
7433: my $navmap = Apache::lonnavmaps::navmap->new();
7434: if (ref($navmap)) {
7435: my $res = $navmap->getBySymb($symb);
7436: if (ref($res)) {
7437: if (!$res->resprintable()) {
7438: $noprint = 1;
7439: }
7440: }
7441: }
7442: }
7443: }
7444: if ($noprint) {
7445: return <<"ENDSTYLE";
7446: <style type="text/css" media="print">
7447: body { display:none }
7448: </style>
7449: ENDSTYLE
7450: }
7451: }
7452: return;
7453: }
7454:
7455: =pod
7456:
1.341 albertel 7457: =item * &xml_begin()
7458:
7459: Returns the needed doctype and <html>
7460:
7461: Inputs: none
7462:
7463: =cut
7464:
7465: sub xml_begin {
1.1075.2.61 raeburn 7466: my ($is_frameset) = @_;
1.341 albertel 7467: my $output='';
7468:
7469: if ($env{'browser.mathml'}) {
7470: $output='<?xml version="1.0"?>'
7471: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7472: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7473:
7474: # .'<!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">] >'
7475: .'<!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">'
7476: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7477: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 7478: } elsif ($is_frameset) {
7479: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
7480: '<html>'."\n";
1.341 albertel 7481: } else {
1.1075.2.61 raeburn 7482: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
7483: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 7484: }
7485: return $output;
7486: }
1.340 albertel 7487:
7488: =pod
7489:
1.306 albertel 7490: =item * &start_page()
7491:
7492: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7493:
1.648 raeburn 7494: Inputs:
7495:
7496: =over 4
7497:
7498: $title - optional title for the page
7499:
7500: $head_extra - optional extra HTML to incude inside the <head>
7501:
7502: $args - additional optional args supported are:
7503:
7504: =over 8
7505:
7506: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7507: arg on
1.814 bisitz 7508: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7509: add_entries -> additional attributes to add to the <body>
7510: domain -> force to color decorate a page for a
1.317 albertel 7511: specific domain
1.648 raeburn 7512: function -> force usage of a specific rolish color
1.317 albertel 7513: scheme
1.648 raeburn 7514: redirect -> see &headtag()
7515: bgcolor -> override the default page bg color
7516: js_ready -> return a string ready for being used in
1.317 albertel 7517: a javascript writeln
1.648 raeburn 7518: html_encode -> return a string ready for being used in
1.320 albertel 7519: a html attribute
1.648 raeburn 7520: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7521: $forcereg arg
1.648 raeburn 7522: frameset -> if true will start with a <frameset>
1.330 albertel 7523: rather than <body>
1.648 raeburn 7524: skip_phases -> hash ref of
1.338 albertel 7525: head -> skip the <html><head> generation
7526: body -> skip all <body> generation
1.1075.2.12 raeburn 7527: no_inline_link -> if true and in remote mode, don't show the
7528: 'Switch To Inline Menu' link
1.648 raeburn 7529: no_auto_mt_title -> prevent &mt()ing the title arg
7530: inherit_jsmath -> when creating popup window in a page,
7531: should it have jsmath forced on by the
7532: current page
1.867 kalberla 7533: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7534: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.15 raeburn 7535: group -> includes the current group, if page is for a
7536: specific group
1.361 albertel 7537:
1.648 raeburn 7538: =back
1.460 albertel 7539:
1.648 raeburn 7540: =back
1.562 albertel 7541:
1.306 albertel 7542: =cut
7543:
7544: sub start_page {
1.309 albertel 7545: my ($title,$head_extra,$args) = @_;
1.318 albertel 7546: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7547:
1.315 albertel 7548: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 7549: my ($result,@advtools);
1.964 droeschl 7550:
1.338 albertel 7551: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 7552: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 7553: }
7554:
7555: if (! exists($args->{'skip_phases'}{'body'}) ) {
7556: if ($args->{'frameset'}) {
7557: my $attr_string = &make_attr_string($args->{'force_register'},
7558: $args->{'add_entries'});
7559: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7560: } else {
7561: $result .=
7562: &bodytag($title,
7563: $args->{'function'}, $args->{'add_entries'},
7564: $args->{'only_body'}, $args->{'domain'},
7565: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 7566: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 7567: $args, \@advtools);
1.831 bisitz 7568: }
1.330 albertel 7569: }
1.338 albertel 7570:
1.315 albertel 7571: if ($args->{'js_ready'}) {
1.713 kaisler 7572: $result = &js_ready($result);
1.315 albertel 7573: }
1.320 albertel 7574: if ($args->{'html_encode'}) {
1.713 kaisler 7575: $result = &html_encode($result);
7576: }
7577:
1.813 bisitz 7578: # Preparation for new and consistent functionlist at top of screen
7579: # if ($args->{'functionlist'}) {
7580: # $result .= &build_functionlist();
7581: #}
7582:
1.964 droeschl 7583: # Don't add anything more if only_body wanted or in const space
7584: return $result if $args->{'only_body'}
7585: || $env{'request.state'} eq 'construct';
1.813 bisitz 7586:
7587: #Breadcrumbs
1.758 kaisler 7588: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7589: &Apache::lonhtmlcommon::clear_breadcrumbs();
7590: #if any br links exists, add them to the breadcrumbs
7591: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7592: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7593: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7594: }
7595: }
1.1075.2.19 raeburn 7596: # if @advtools array contains items add then to the breadcrumbs
7597: if (@advtools > 0) {
7598: &Apache::lonmenu::advtools_crumbs(@advtools);
7599: }
1.758 kaisler 7600:
7601: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7602: if(exists($args->{'bread_crumbs_component'})){
7603: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7604: }else{
7605: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7606: }
1.1075.2.24 raeburn 7607: } elsif (($env{'environment.remote'} eq 'on') &&
7608: ($env{'form.inhibitmenu'} ne 'yes') &&
7609: ($env{'request.noversionuri'} =~ m{^/res/}) &&
7610: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 7611: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 7612: }
1.315 albertel 7613: return $result;
1.306 albertel 7614: }
7615:
7616: sub end_page {
1.315 albertel 7617: my ($args) = @_;
7618: $env{'internal.end_page'}++;
1.330 albertel 7619: my $result;
1.335 albertel 7620: if ($args->{'discussion'}) {
7621: my ($target,$parser);
7622: if (ref($args->{'discussion'})) {
7623: ($target,$parser) =($args->{'discussion'}{'target'},
7624: $args->{'discussion'}{'parser'});
7625: }
7626: $result .= &Apache::lonxml::xmlend($target,$parser);
7627: }
1.330 albertel 7628: if ($args->{'frameset'}) {
7629: $result .= '</frameset>';
7630: } else {
1.635 raeburn 7631: $result .= &endbodytag($args);
1.330 albertel 7632: }
1.1075.2.6 raeburn 7633: unless ($args->{'notbody'}) {
7634: $result .= "\n</html>";
7635: }
1.330 albertel 7636:
1.315 albertel 7637: if ($args->{'js_ready'}) {
1.317 albertel 7638: $result = &js_ready($result);
1.315 albertel 7639: }
1.335 albertel 7640:
1.320 albertel 7641: if ($args->{'html_encode'}) {
7642: $result = &html_encode($result);
7643: }
1.335 albertel 7644:
1.315 albertel 7645: return $result;
7646: }
7647:
1.1034 www 7648: sub wishlist_window {
7649: return(<<'ENDWISHLIST');
1.1046 raeburn 7650: <script type="text/javascript">
1.1034 www 7651: // <![CDATA[
7652: // <!-- BEGIN LON-CAPA Internal
7653: function set_wishlistlink(title, path) {
7654: if (!title) {
7655: title = document.title;
7656: title = title.replace(/^LON-CAPA /,'');
7657: }
7658: if (!path) {
7659: path = location.pathname;
7660: }
7661: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7662: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7663: }
7664: // END LON-CAPA Internal -->
7665: // ]]>
7666: </script>
7667: ENDWISHLIST
7668: }
7669:
1.1030 www 7670: sub modal_window {
7671: return(<<'ENDMODAL');
1.1046 raeburn 7672: <script type="text/javascript">
1.1030 www 7673: // <![CDATA[
7674: // <!-- BEGIN LON-CAPA Internal
7675: var modalWindow = {
7676: parent:"body",
7677: windowId:null,
7678: content:null,
7679: width:null,
7680: height:null,
7681: close:function()
7682: {
7683: $(".LCmodal-window").remove();
7684: $(".LCmodal-overlay").remove();
7685: },
7686: open:function()
7687: {
7688: var modal = "";
7689: modal += "<div class=\"LCmodal-overlay\"></div>";
7690: 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;\">";
7691: modal += this.content;
7692: modal += "</div>";
7693:
7694: $(this.parent).append(modal);
7695:
7696: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7697: $(".LCclose-window").click(function(){modalWindow.close();});
7698: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7699: }
7700: };
1.1075.2.42 raeburn 7701: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 7702: {
7703: modalWindow.windowId = "myModal";
7704: modalWindow.width = width;
7705: modalWindow.height = height;
1.1075.2.42 raeburn 7706: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 7707: modalWindow.open();
7708: };
7709: // END LON-CAPA Internal -->
7710: // ]]>
7711: </script>
7712: ENDMODAL
7713: }
7714:
7715: sub modal_link {
1.1075.2.42 raeburn 7716: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 7717: unless ($width) { $width=480; }
7718: unless ($height) { $height=400; }
1.1031 www 7719: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 7720: unless ($transparency) { $transparency='true'; }
7721:
1.1074 raeburn 7722: my $target_attr;
7723: if (defined($target)) {
7724: $target_attr = 'target="'.$target.'"';
7725: }
7726: return <<"ENDLINK";
1.1075.2.42 raeburn 7727: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 7728: $linktext</a>
7729: ENDLINK
1.1030 www 7730: }
7731:
1.1032 www 7732: sub modal_adhoc_script {
7733: my ($funcname,$width,$height,$content)=@_;
7734: return (<<ENDADHOC);
1.1046 raeburn 7735: <script type="text/javascript">
1.1032 www 7736: // <![CDATA[
7737: var $funcname = function()
7738: {
7739: modalWindow.windowId = "myModal";
7740: modalWindow.width = $width;
7741: modalWindow.height = $height;
7742: modalWindow.content = '$content';
7743: modalWindow.open();
7744: };
7745: // ]]>
7746: </script>
7747: ENDADHOC
7748: }
7749:
1.1041 www 7750: sub modal_adhoc_inner {
7751: my ($funcname,$width,$height,$content)=@_;
7752: my $innerwidth=$width-20;
7753: $content=&js_ready(
1.1042 www 7754: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 7755: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
7756: $content.
1.1041 www 7757: &end_scrollbox().
1.1075.2.42 raeburn 7758: &end_page()
1.1041 www 7759: );
7760: return &modal_adhoc_script($funcname,$width,$height,$content);
7761: }
7762:
7763: sub modal_adhoc_window {
7764: my ($funcname,$width,$height,$content,$linktext)=@_;
7765: return &modal_adhoc_inner($funcname,$width,$height,$content).
7766: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7767: }
7768:
7769: sub modal_adhoc_launch {
7770: my ($funcname,$width,$height,$content)=@_;
7771: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7772: <script type="text/javascript">
7773: // <![CDATA[
7774: $funcname();
7775: // ]]>
7776: </script>
7777: ENDLAUNCH
7778: }
7779:
7780: sub modal_adhoc_close {
7781: return (<<ENDCLOSE);
7782: <script type="text/javascript">
7783: // <![CDATA[
7784: modalWindow.close();
7785: // ]]>
7786: </script>
7787: ENDCLOSE
7788: }
7789:
1.1038 www 7790: sub togglebox_script {
7791: return(<<ENDTOGGLE);
7792: <script type="text/javascript">
7793: // <![CDATA[
7794: function LCtoggleDisplay(id,hidetext,showtext) {
7795: link = document.getElementById(id + "link").childNodes[0];
7796: with (document.getElementById(id).style) {
7797: if (display == "none" ) {
7798: display = "inline";
7799: link.nodeValue = hidetext;
7800: } else {
7801: display = "none";
7802: link.nodeValue = showtext;
7803: }
7804: }
7805: }
7806: // ]]>
7807: </script>
7808: ENDTOGGLE
7809: }
7810:
1.1039 www 7811: sub start_togglebox {
7812: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7813: unless ($heading) { $heading=''; } else { $heading.=' '; }
7814: unless ($showtext) { $showtext=&mt('show'); }
7815: unless ($hidetext) { $hidetext=&mt('hide'); }
7816: unless ($headerbg) { $headerbg='#FFFFFF'; }
7817: return &start_data_table().
7818: &start_data_table_header_row().
7819: '<td bgcolor="'.$headerbg.'">'.$heading.
7820: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7821: $showtext.'\')">'.$showtext.'</a>]</td>'.
7822: &end_data_table_header_row().
7823: '<tr id="'.$id.'" style="display:none""><td>';
7824: }
7825:
7826: sub end_togglebox {
7827: return '</td></tr>'.&end_data_table();
7828: }
7829:
1.1041 www 7830: sub LCprogressbar_script {
1.1045 www 7831: my ($id)=@_;
1.1041 www 7832: return(<<ENDPROGRESS);
7833: <script type="text/javascript">
7834: // <![CDATA[
1.1045 www 7835: \$('#progressbar$id').progressbar({
1.1041 www 7836: value: 0,
7837: change: function(event, ui) {
7838: var newVal = \$(this).progressbar('option', 'value');
7839: \$('.pblabel', this).text(LCprogressTxt);
7840: }
7841: });
7842: // ]]>
7843: </script>
7844: ENDPROGRESS
7845: }
7846:
7847: sub LCprogressbarUpdate_script {
7848: return(<<ENDPROGRESSUPDATE);
7849: <style type="text/css">
7850: .ui-progressbar { position:relative; }
7851: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7852: </style>
7853: <script type="text/javascript">
7854: // <![CDATA[
1.1045 www 7855: var LCprogressTxt='---';
7856:
7857: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7858: LCprogressTxt=progresstext;
1.1045 www 7859: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7860: }
7861: // ]]>
7862: </script>
7863: ENDPROGRESSUPDATE
7864: }
7865:
1.1042 www 7866: my $LClastpercent;
1.1045 www 7867: my $LCidcnt;
7868: my $LCcurrentid;
1.1042 www 7869:
1.1041 www 7870: sub LCprogressbar {
1.1042 www 7871: my ($r)=(@_);
7872: $LClastpercent=0;
1.1045 www 7873: $LCidcnt++;
7874: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7875: my $starting=&mt('Starting');
7876: my $content=(<<ENDPROGBAR);
1.1045 www 7877: <div id="progressbar$LCcurrentid">
1.1041 www 7878: <span class="pblabel">$starting</span>
7879: </div>
7880: ENDPROGBAR
1.1045 www 7881: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7882: }
7883:
7884: sub LCprogressbarUpdate {
1.1042 www 7885: my ($r,$val,$text)=@_;
7886: unless ($val) {
7887: if ($LClastpercent) {
7888: $val=$LClastpercent;
7889: } else {
7890: $val=0;
7891: }
7892: }
1.1041 www 7893: if ($val<0) { $val=0; }
7894: if ($val>100) { $val=0; }
1.1042 www 7895: $LClastpercent=$val;
1.1041 www 7896: unless ($text) { $text=$val.'%'; }
7897: $text=&js_ready($text);
1.1044 www 7898: &r_print($r,<<ENDUPDATE);
1.1041 www 7899: <script type="text/javascript">
7900: // <![CDATA[
1.1045 www 7901: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7902: // ]]>
7903: </script>
7904: ENDUPDATE
1.1035 www 7905: }
7906:
1.1042 www 7907: sub LCprogressbarClose {
7908: my ($r)=@_;
7909: $LClastpercent=0;
1.1044 www 7910: &r_print($r,<<ENDCLOSE);
1.1042 www 7911: <script type="text/javascript">
7912: // <![CDATA[
1.1045 www 7913: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7914: // ]]>
7915: </script>
7916: ENDCLOSE
1.1044 www 7917: }
7918:
7919: sub r_print {
7920: my ($r,$to_print)=@_;
7921: if ($r) {
7922: $r->print($to_print);
7923: $r->rflush();
7924: } else {
7925: print($to_print);
7926: }
1.1042 www 7927: }
7928:
1.320 albertel 7929: sub html_encode {
7930: my ($result) = @_;
7931:
1.322 albertel 7932: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7933:
7934: return $result;
7935: }
1.1044 www 7936:
1.317 albertel 7937: sub js_ready {
7938: my ($result) = @_;
7939:
1.323 albertel 7940: $result =~ s/[\n\r]/ /xmsg;
7941: $result =~ s/\\/\\\\/xmsg;
7942: $result =~ s/'/\\'/xmsg;
1.372 albertel 7943: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7944:
7945: return $result;
7946: }
7947:
1.315 albertel 7948: sub validate_page {
7949: if ( exists($env{'internal.start_page'})
1.316 albertel 7950: && $env{'internal.start_page'} > 1) {
7951: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7952: $env{'internal.start_page'}.' '.
1.316 albertel 7953: $ENV{'request.filename'});
1.315 albertel 7954: }
7955: if ( exists($env{'internal.end_page'})
1.316 albertel 7956: && $env{'internal.end_page'} > 1) {
7957: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7958: $env{'internal.end_page'}.' '.
1.316 albertel 7959: $env{'request.filename'});
1.315 albertel 7960: }
7961: if ( exists($env{'internal.start_page'})
7962: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7963: &Apache::lonnet::logthis('start_page called without end_page '.
7964: $env{'request.filename'});
1.315 albertel 7965: }
7966: if ( ! exists($env{'internal.start_page'})
7967: && exists($env{'internal.end_page'})) {
1.316 albertel 7968: &Apache::lonnet::logthis('end_page called without start_page'.
7969: $env{'request.filename'});
1.315 albertel 7970: }
1.306 albertel 7971: }
1.315 albertel 7972:
1.996 www 7973:
7974: sub start_scrollbox {
1.1075.2.56 raeburn 7975: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 7976: unless ($outerwidth) { $outerwidth='520px'; }
7977: unless ($width) { $width='500px'; }
7978: unless ($height) { $height='200px'; }
1.1075 raeburn 7979: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7980: if ($id ne '') {
1.1075.2.42 raeburn 7981: $table_id = ' id="table_'.$id.'"';
7982: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 7983: }
1.1075 raeburn 7984: if ($bgcolor ne '') {
7985: $tdcol = "background-color: $bgcolor;";
7986: }
1.1075.2.42 raeburn 7987: my $nicescroll_js;
7988: if ($env{'browser.mobile'}) {
7989: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
7990: }
1.1075 raeburn 7991: return <<"END";
1.1075.2.42 raeburn 7992: $nicescroll_js
7993:
7994: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 7995: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 7996: END
1.996 www 7997: }
7998:
7999: sub end_scrollbox {
1.1036 www 8000: return '</div></td></tr></table>';
1.996 www 8001: }
8002:
1.1075.2.42 raeburn 8003: sub nicescroll_javascript {
8004: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8005: my %options;
8006: if (ref($cursor) eq 'HASH') {
8007: %options = %{$cursor};
8008: }
8009: unless ($options{'railalign'} =~ /^left|right$/) {
8010: $options{'railalign'} = 'left';
8011: }
8012: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8013: my $function = &get_users_function();
8014: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8015: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8016: $options{'cursorcolor'} = '#00F';
8017: }
8018: }
8019: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8020: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8021: $options{'cursoropacity'}='1.0';
8022: }
8023: } else {
8024: $options{'cursoropacity'}='1.0';
8025: }
8026: if ($options{'cursorfixedheight'} eq 'none') {
8027: delete($options{'cursorfixedheight'});
8028: } else {
8029: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8030: }
8031: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8032: delete($options{'railoffset'});
8033: }
8034: my @niceoptions;
8035: while (my($key,$value) = each(%options)) {
8036: if ($value =~ /^\{.+\}$/) {
8037: push(@niceoptions,$key.':'.$value);
8038: } else {
8039: push(@niceoptions,$key.':"'.$value.'"');
8040: }
8041: }
8042: my $nicescroll_js = '
8043: $(document).ready(
8044: function() {
8045: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8046: }
8047: );
8048: ';
8049: if ($framecheck) {
8050: $nicescroll_js .= '
8051: function expand_div(caller) {
8052: if (top === self) {
8053: document.getElementById("'.$id.'").style.width = "auto";
8054: document.getElementById("'.$id.'").style.height = "auto";
8055: } else {
8056: try {
8057: if (parent.frames) {
8058: if (parent.frames.length > 1) {
8059: var framesrc = parent.frames[1].location.href;
8060: var currsrc = framesrc.replace(/\#.*$/,"");
8061: if ((caller == "search") || (currsrc == "'.$location.'")) {
8062: document.getElementById("'.$id.'").style.width = "auto";
8063: document.getElementById("'.$id.'").style.height = "auto";
8064: }
8065: }
8066: }
8067: } catch (e) {
8068: return;
8069: }
8070: }
8071: return;
8072: }
8073: ';
8074: }
8075: if ($needjsready) {
8076: $nicescroll_js = '
8077: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8078: } else {
8079: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8080: }
8081: return $nicescroll_js;
8082: }
8083:
1.318 albertel 8084: sub simple_error_page {
1.1075.2.49 raeburn 8085: my ($r,$title,$msg,$args) = @_;
8086: if (ref($args) eq 'HASH') {
8087: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8088: } else {
8089: $msg = &mt($msg);
8090: }
8091:
1.318 albertel 8092: my $page =
8093: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8094: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8095: &Apache::loncommon::end_page();
8096: if (ref($r)) {
8097: $r->print($page);
1.327 albertel 8098: return;
1.318 albertel 8099: }
8100: return $page;
8101: }
1.347 albertel 8102:
8103: {
1.610 albertel 8104: my @row_count;
1.961 onken 8105:
8106: sub start_data_table_count {
8107: unshift(@row_count, 0);
8108: return;
8109: }
8110:
8111: sub end_data_table_count {
8112: shift(@row_count);
8113: return;
8114: }
8115:
1.347 albertel 8116: sub start_data_table {
1.1018 raeburn 8117: my ($add_class,$id) = @_;
1.422 albertel 8118: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8119: my $table_id;
8120: if (defined($id)) {
8121: $table_id = ' id="'.$id.'"';
8122: }
1.961 onken 8123: &start_data_table_count();
1.1018 raeburn 8124: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8125: }
8126:
8127: sub end_data_table {
1.961 onken 8128: &end_data_table_count();
1.389 albertel 8129: return '</table>'."\n";;
1.347 albertel 8130: }
8131:
8132: sub start_data_table_row {
1.974 wenzelju 8133: my ($add_class, $id) = @_;
1.610 albertel 8134: $row_count[0]++;
8135: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8136: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8137: $id = (' id="'.$id.'"') unless ($id eq '');
8138: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8139: }
1.471 banghart 8140:
8141: sub continue_data_table_row {
1.974 wenzelju 8142: my ($add_class, $id) = @_;
1.610 albertel 8143: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8144: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8145: $id = (' id="'.$id.'"') unless ($id eq '');
8146: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8147: }
1.347 albertel 8148:
8149: sub end_data_table_row {
1.389 albertel 8150: return '</tr>'."\n";;
1.347 albertel 8151: }
1.367 www 8152:
1.421 albertel 8153: sub start_data_table_empty_row {
1.707 bisitz 8154: # $row_count[0]++;
1.421 albertel 8155: return '<tr class="LC_empty_row" >'."\n";;
8156: }
8157:
8158: sub end_data_table_empty_row {
8159: return '</tr>'."\n";;
8160: }
8161:
1.367 www 8162: sub start_data_table_header_row {
1.389 albertel 8163: return '<tr class="LC_header_row">'."\n";;
1.367 www 8164: }
8165:
8166: sub end_data_table_header_row {
1.389 albertel 8167: return '</tr>'."\n";;
1.367 www 8168: }
1.890 droeschl 8169:
8170: sub data_table_caption {
8171: my $caption = shift;
8172: return "<caption class=\"LC_caption\">$caption</caption>";
8173: }
1.347 albertel 8174: }
8175:
1.548 albertel 8176: =pod
8177:
8178: =item * &inhibit_menu_check($arg)
8179:
8180: Checks for a inhibitmenu state and generates output to preserve it
8181:
8182: Inputs: $arg - can be any of
8183: - undef - in which case the return value is a string
8184: to add into arguments list of a uri
8185: - 'input' - in which case the return value is a HTML
8186: <form> <input> field of type hidden to
8187: preserve the value
8188: - a url - in which case the return value is the url with
8189: the neccesary cgi args added to preserve the
8190: inhibitmenu state
8191: - a ref to a url - no return value, but the string is
8192: updated to include the neccessary cgi
8193: args to preserve the inhibitmenu state
8194:
8195: =cut
8196:
8197: sub inhibit_menu_check {
8198: my ($arg) = @_;
8199: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8200: if ($arg eq 'input') {
8201: if ($env{'form.inhibitmenu'}) {
8202: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8203: } else {
8204: return
8205: }
8206: }
8207: if ($env{'form.inhibitmenu'}) {
8208: if (ref($arg)) {
8209: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8210: } elsif ($arg eq '') {
8211: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8212: } else {
8213: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8214: }
8215: }
8216: if (!ref($arg)) {
8217: return $arg;
8218: }
8219: }
8220:
1.251 albertel 8221: ###############################################
1.182 matthew 8222:
8223: =pod
8224:
1.549 albertel 8225: =back
8226:
8227: =head1 User Information Routines
8228:
8229: =over 4
8230:
1.405 albertel 8231: =item * &get_users_function()
1.182 matthew 8232:
8233: Used by &bodytag to determine the current users primary role.
8234: Returns either 'student','coordinator','admin', or 'author'.
8235:
8236: =cut
8237:
8238: ###############################################
8239: sub get_users_function {
1.815 tempelho 8240: my $function = 'norole';
1.818 tempelho 8241: if ($env{'request.role'}=~/^(st)/) {
8242: $function='student';
8243: }
1.907 raeburn 8244: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8245: $function='coordinator';
8246: }
1.258 albertel 8247: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8248: $function='admin';
8249: }
1.826 bisitz 8250: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8251: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8252: $function='author';
8253: }
8254: return $function;
1.54 www 8255: }
1.99 www 8256:
8257: ###############################################
8258:
1.233 raeburn 8259: =pod
8260:
1.821 raeburn 8261: =item * &show_course()
8262:
8263: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8264: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8265:
8266: Inputs:
8267: None
8268:
8269: Outputs:
8270: Scalar: 1 if 'Course' to be used, 0 otherwise.
8271:
8272: =cut
8273:
8274: ###############################################
8275: sub show_course {
8276: my $course = !$env{'user.adv'};
8277: if (!$env{'user.adv'}) {
8278: foreach my $env (keys(%env)) {
8279: next if ($env !~ m/^user\.priv\./);
8280: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8281: $course = 0;
8282: last;
8283: }
8284: }
8285: }
8286: return $course;
8287: }
8288:
8289: ###############################################
8290:
8291: =pod
8292:
1.542 raeburn 8293: =item * &check_user_status()
1.274 raeburn 8294:
8295: Determines current status of supplied role for a
8296: specific user. Roles can be active, previous or future.
8297:
8298: Inputs:
8299: user's domain, user's username, course's domain,
1.375 raeburn 8300: course's number, optional section ID.
1.274 raeburn 8301:
8302: Outputs:
8303: role status: active, previous or future.
8304:
8305: =cut
8306:
8307: sub check_user_status {
1.412 raeburn 8308: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8309: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8310: my @uroles = keys %userinfo;
8311: my $srchstr;
8312: my $active_chk = 'none';
1.412 raeburn 8313: my $now = time;
1.274 raeburn 8314: if (@uroles > 0) {
1.908 raeburn 8315: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8316: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8317: } else {
1.412 raeburn 8318: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8319: }
8320: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8321: my $role_end = 0;
8322: my $role_start = 0;
8323: $active_chk = 'active';
1.412 raeburn 8324: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8325: $role_end = $1;
8326: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8327: $role_start = $1;
1.274 raeburn 8328: }
8329: }
8330: if ($role_start > 0) {
1.412 raeburn 8331: if ($now < $role_start) {
1.274 raeburn 8332: $active_chk = 'future';
8333: }
8334: }
8335: if ($role_end > 0) {
1.412 raeburn 8336: if ($now > $role_end) {
1.274 raeburn 8337: $active_chk = 'previous';
8338: }
8339: }
8340: }
8341: }
8342: return $active_chk;
8343: }
8344:
8345: ###############################################
8346:
8347: =pod
8348:
1.405 albertel 8349: =item * &get_sections()
1.233 raeburn 8350:
8351: Determines all the sections for a course including
8352: sections with students and sections containing other roles.
1.419 raeburn 8353: Incoming parameters:
8354:
8355: 1. domain
8356: 2. course number
8357: 3. reference to array containing roles for which sections should
8358: be gathered (optional).
8359: 4. reference to array containing status types for which sections
8360: should be gathered (optional).
8361:
8362: If the third argument is undefined, sections are gathered for any role.
8363: If the fourth argument is undefined, sections are gathered for any status.
8364: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8365:
1.374 raeburn 8366: Returns section hash (keys are section IDs, values are
8367: number of users in each section), subject to the
1.419 raeburn 8368: optional roles filter, optional status filter
1.233 raeburn 8369:
8370: =cut
8371:
8372: ###############################################
8373: sub get_sections {
1.419 raeburn 8374: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8375: if (!defined($cdom) || !defined($cnum)) {
8376: my $cid = $env{'request.course.id'};
8377:
8378: return if (!defined($cid));
8379:
8380: $cdom = $env{'course.'.$cid.'.domain'};
8381: $cnum = $env{'course.'.$cid.'.num'};
8382: }
8383:
8384: my %sectioncount;
1.419 raeburn 8385: my $now = time;
1.240 albertel 8386:
1.1075.2.33 raeburn 8387: my $check_students = 1;
8388: my $only_students = 0;
8389: if (ref($possible_roles) eq 'ARRAY') {
8390: if (grep(/^st$/,@{$possible_roles})) {
8391: if (@{$possible_roles} == 1) {
8392: $only_students = 1;
8393: }
8394: } else {
8395: $check_students = 0;
8396: }
8397: }
8398:
8399: if ($check_students) {
1.276 albertel 8400: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8401: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8402: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8403: my $start_index = &Apache::loncoursedata::CL_START();
8404: my $end_index = &Apache::loncoursedata::CL_END();
8405: my $status;
1.366 albertel 8406: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8407: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8408: $data->[$status_index],
8409: $data->[$start_index],
8410: $data->[$end_index]);
8411: if ($stu_status eq 'Active') {
8412: $status = 'active';
8413: } elsif ($end < $now) {
8414: $status = 'previous';
8415: } elsif ($start > $now) {
8416: $status = 'future';
8417: }
8418: if ($section ne '-1' && $section !~ /^\s*$/) {
8419: if ((!defined($possible_status)) || (($status ne '') &&
8420: (grep/^\Q$status\E$/,@{$possible_status}))) {
8421: $sectioncount{$section}++;
8422: }
1.240 albertel 8423: }
8424: }
8425: }
1.1075.2.33 raeburn 8426: if ($only_students) {
8427: return %sectioncount;
8428: }
1.240 albertel 8429: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8430: foreach my $user (sort(keys(%courseroles))) {
8431: if ($user !~ /^(\w{2})/) { next; }
8432: my ($role) = ($user =~ /^(\w{2})/);
8433: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8434: my ($section,$status);
1.240 albertel 8435: if ($role eq 'cr' &&
8436: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8437: $section=$1;
8438: }
8439: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8440: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8441: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8442: if ($end == -1 && $start == -1) {
8443: next; #deleted role
8444: }
8445: if (!defined($possible_status)) {
8446: $sectioncount{$section}++;
8447: } else {
8448: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8449: $status = 'active';
8450: } elsif ($end < $now) {
8451: $status = 'future';
8452: } elsif ($start > $now) {
8453: $status = 'previous';
8454: }
8455: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8456: $sectioncount{$section}++;
8457: }
8458: }
1.233 raeburn 8459: }
1.366 albertel 8460: return %sectioncount;
1.233 raeburn 8461: }
8462:
1.274 raeburn 8463: ###############################################
1.294 raeburn 8464:
8465: =pod
1.405 albertel 8466:
8467: =item * &get_course_users()
8468:
1.275 raeburn 8469: Retrieves usernames:domains for users in the specified course
8470: with specific role(s), and access status.
8471:
8472: Incoming parameters:
1.277 albertel 8473: 1. course domain
8474: 2. course number
8475: 3. access status: users must have - either active,
1.275 raeburn 8476: previous, future, or all.
1.277 albertel 8477: 4. reference to array of permissible roles
1.288 raeburn 8478: 5. reference to array of section restrictions (optional)
8479: 6. reference to results object (hash of hashes).
8480: 7. reference to optional userdata hash
1.609 raeburn 8481: 8. reference to optional statushash
1.630 raeburn 8482: 9. flag if privileged users (except those set to unhide in
8483: course settings) should be excluded
1.609 raeburn 8484: Keys of top level results hash are roles.
1.275 raeburn 8485: Keys of inner hashes are username:domain, with
8486: values set to access type.
1.288 raeburn 8487: Optional userdata hash returns an array with arguments in the
8488: same order as loncoursedata::get_classlist() for student data.
8489:
1.609 raeburn 8490: Optional statushash returns
8491:
1.288 raeburn 8492: Entries for end, start, section and status are blank because
8493: of the possibility of multiple values for non-student roles.
8494:
1.275 raeburn 8495: =cut
1.405 albertel 8496:
1.275 raeburn 8497: ###############################################
1.405 albertel 8498:
1.275 raeburn 8499: sub get_course_users {
1.630 raeburn 8500: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8501: my %idx = ();
1.419 raeburn 8502: my %seclists;
1.288 raeburn 8503:
8504: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8505: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8506: $idx{end} = &Apache::loncoursedata::CL_END();
8507: $idx{start} = &Apache::loncoursedata::CL_START();
8508: $idx{id} = &Apache::loncoursedata::CL_ID();
8509: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8510: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8511: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8512:
1.290 albertel 8513: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8514: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8515: my $now = time;
1.277 albertel 8516: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8517: my $match = 0;
1.412 raeburn 8518: my $secmatch = 0;
1.419 raeburn 8519: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8520: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8521: if ($section eq '') {
8522: $section = 'none';
8523: }
1.291 albertel 8524: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8525: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8526: $secmatch = 1;
8527: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8528: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8529: $secmatch = 1;
8530: }
8531: } else {
1.419 raeburn 8532: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8533: $secmatch = 1;
8534: }
1.290 albertel 8535: }
1.412 raeburn 8536: if (!$secmatch) {
8537: next;
8538: }
1.419 raeburn 8539: }
1.275 raeburn 8540: if (defined($$types{'active'})) {
1.288 raeburn 8541: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8542: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8543: $match = 1;
1.275 raeburn 8544: }
8545: }
8546: if (defined($$types{'previous'})) {
1.609 raeburn 8547: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8548: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8549: $match = 1;
1.275 raeburn 8550: }
8551: }
8552: if (defined($$types{'future'})) {
1.609 raeburn 8553: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8554: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8555: $match = 1;
1.275 raeburn 8556: }
8557: }
1.609 raeburn 8558: if ($match) {
8559: push(@{$seclists{$student}},$section);
8560: if (ref($userdata) eq 'HASH') {
8561: $$userdata{$student} = $$classlist{$student};
8562: }
8563: if (ref($statushash) eq 'HASH') {
8564: $statushash->{$student}{'st'}{$section} = $status;
8565: }
1.288 raeburn 8566: }
1.275 raeburn 8567: }
8568: }
1.412 raeburn 8569: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8570: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8571: my $now = time;
1.609 raeburn 8572: my %displaystatus = ( previous => 'Expired',
8573: active => 'Active',
8574: future => 'Future',
8575: );
1.1075.2.36 raeburn 8576: my (%nothide,@possdoms);
1.630 raeburn 8577: if ($hidepriv) {
8578: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8579: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8580: if ($user !~ /:/) {
8581: $nothide{join(':',split(/[\@]/,$user))}=1;
8582: } else {
8583: $nothide{$user} = 1;
8584: }
8585: }
1.1075.2.36 raeburn 8586: my @possdoms = ($cdom);
8587: if ($coursehash{'checkforpriv'}) {
8588: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8589: }
1.630 raeburn 8590: }
1.439 raeburn 8591: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8592: my $match = 0;
1.412 raeburn 8593: my $secmatch = 0;
1.439 raeburn 8594: my $status;
1.412 raeburn 8595: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8596: $user =~ s/:$//;
1.439 raeburn 8597: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8598: if ($end == -1 || $start == -1) {
8599: next;
8600: }
8601: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8602: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8603: my ($uname,$udom) = split(/:/,$user);
8604: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8605: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8606: $secmatch = 1;
8607: } elsif ($usec eq '') {
1.420 albertel 8608: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8609: $secmatch = 1;
8610: }
8611: } else {
8612: if (grep(/^\Q$usec\E$/,@{$sections})) {
8613: $secmatch = 1;
8614: }
8615: }
8616: if (!$secmatch) {
8617: next;
8618: }
1.288 raeburn 8619: }
1.419 raeburn 8620: if ($usec eq '') {
8621: $usec = 'none';
8622: }
1.275 raeburn 8623: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8624: if ($hidepriv) {
1.1075.2.36 raeburn 8625: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8626: (!$nothide{$uname.':'.$udom})) {
8627: next;
8628: }
8629: }
1.503 raeburn 8630: if ($end > 0 && $end < $now) {
1.439 raeburn 8631: $status = 'previous';
8632: } elsif ($start > $now) {
8633: $status = 'future';
8634: } else {
8635: $status = 'active';
8636: }
1.277 albertel 8637: foreach my $type (keys(%{$types})) {
1.275 raeburn 8638: if ($status eq $type) {
1.420 albertel 8639: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8640: push(@{$$users{$role}{$user}},$type);
8641: }
1.288 raeburn 8642: $match = 1;
8643: }
8644: }
1.419 raeburn 8645: if (($match) && (ref($userdata) eq 'HASH')) {
8646: if (!exists($$userdata{$uname.':'.$udom})) {
8647: &get_user_info($udom,$uname,\%idx,$userdata);
8648: }
1.420 albertel 8649: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8650: push(@{$seclists{$uname.':'.$udom}},$usec);
8651: }
1.609 raeburn 8652: if (ref($statushash) eq 'HASH') {
8653: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8654: }
1.275 raeburn 8655: }
8656: }
8657: }
8658: }
1.290 albertel 8659: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8660: if ((defined($cdom)) && (defined($cnum))) {
8661: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8662: if ( defined($csettings{'internal.courseowner'}) ) {
8663: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8664: next if ($owner eq '');
8665: my ($ownername,$ownerdom);
8666: if ($owner =~ /^([^:]+):([^:]+)$/) {
8667: $ownername = $1;
8668: $ownerdom = $2;
8669: } else {
8670: $ownername = $owner;
8671: $ownerdom = $cdom;
8672: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8673: }
8674: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8675: if (defined($userdata) &&
1.609 raeburn 8676: !exists($$userdata{$owner})) {
8677: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8678: if (!grep(/^none$/,@{$seclists{$owner}})) {
8679: push(@{$seclists{$owner}},'none');
8680: }
8681: if (ref($statushash) eq 'HASH') {
8682: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8683: }
1.290 albertel 8684: }
1.279 raeburn 8685: }
8686: }
8687: }
1.419 raeburn 8688: foreach my $user (keys(%seclists)) {
8689: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8690: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8691: }
1.275 raeburn 8692: }
8693: return;
8694: }
8695:
1.288 raeburn 8696: sub get_user_info {
8697: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8698: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8699: &plainname($uname,$udom,'lastname');
1.291 albertel 8700: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8701: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8702: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8703: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8704: return;
8705: }
1.275 raeburn 8706:
1.472 raeburn 8707: ###############################################
8708:
8709: =pod
8710:
8711: =item * &get_user_quota()
8712:
1.1075.2.41 raeburn 8713: Retrieves quota assigned for storage of user files.
8714: Default is to report quota for portfolio files.
1.472 raeburn 8715:
8716: Incoming parameters:
8717: 1. user's username
8718: 2. user's domain
1.1075.2.41 raeburn 8719: 3. quota name - portfolio, author, or course
8720: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 8721: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 8722: course
1.472 raeburn 8723:
8724: Returns:
1.1075.2.58 raeburn 8725: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 8726: 2. (Optional) Type of setting: custom or default
8727: (individually assigned or default for user's
8728: institutional status).
8729: 3. (Optional) - User's institutional status (e.g., faculty, staff
8730: or student - types as defined in localenroll::inst_usertypes
8731: for user's domain, which determines default quota for user.
8732: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8733:
8734: If a value has been stored in the user's environment,
1.536 raeburn 8735: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 8736: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8737:
8738: =cut
8739:
8740: ###############################################
8741:
8742:
8743: sub get_user_quota {
1.1075.2.42 raeburn 8744: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8745: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8746: if (!defined($udom)) {
8747: $udom = $env{'user.domain'};
8748: }
8749: if (!defined($uname)) {
8750: $uname = $env{'user.name'};
8751: }
8752: if (($udom eq '' || $uname eq '') ||
8753: ($udom eq 'public') && ($uname eq 'public')) {
8754: $quota = 0;
1.536 raeburn 8755: $quotatype = 'default';
8756: $defquota = 0;
1.472 raeburn 8757: } else {
1.536 raeburn 8758: my $inststatus;
1.1075.2.41 raeburn 8759: if ($quotaname eq 'course') {
8760: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8761: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8762: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8763: } else {
8764: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8765: $quota = $cenv{'internal.uploadquota'};
8766: }
1.536 raeburn 8767: } else {
1.1075.2.41 raeburn 8768: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8769: if ($quotaname eq 'author') {
8770: $quota = $env{'environment.authorquota'};
8771: } else {
8772: $quota = $env{'environment.portfolioquota'};
8773: }
8774: $inststatus = $env{'environment.inststatus'};
8775: } else {
8776: my %userenv =
8777: &Apache::lonnet::get('environment',['portfolioquota',
8778: 'authorquota','inststatus'],$udom,$uname);
8779: my ($tmp) = keys(%userenv);
8780: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8781: if ($quotaname eq 'author') {
8782: $quota = $userenv{'authorquota'};
8783: } else {
8784: $quota = $userenv{'portfolioquota'};
8785: }
8786: $inststatus = $userenv{'inststatus'};
8787: } else {
8788: undef(%userenv);
8789: }
8790: }
8791: }
8792: if ($quota eq '' || wantarray) {
8793: if ($quotaname eq 'course') {
8794: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 8795: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
8796: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 8797: $defquota = $domdefs{$crstype.'quota'};
8798: }
8799: if ($defquota eq '') {
8800: $defquota = 500;
8801: }
1.1075.2.41 raeburn 8802: } else {
8803: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
8804: }
8805: if ($quota eq '') {
8806: $quota = $defquota;
8807: $quotatype = 'default';
8808: } else {
8809: $quotatype = 'custom';
8810: }
1.472 raeburn 8811: }
8812: }
1.536 raeburn 8813: if (wantarray) {
8814: return ($quota,$quotatype,$settingstatus,$defquota);
8815: } else {
8816: return $quota;
8817: }
1.472 raeburn 8818: }
8819:
8820: ###############################################
8821:
8822: =pod
8823:
8824: =item * &default_quota()
8825:
1.536 raeburn 8826: Retrieves default quota assigned for storage of user portfolio files,
8827: given an (optional) user's institutional status.
1.472 raeburn 8828:
8829: Incoming parameters:
1.1075.2.42 raeburn 8830:
1.472 raeburn 8831: 1. domain
1.536 raeburn 8832: 2. (Optional) institutional status(es). This is a : separated list of
8833: status types (e.g., faculty, staff, student etc.)
8834: which apply to the user for whom the default is being retrieved.
8835: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 8836: default quota will be returned.
8837: 3. quota name - portfolio, author, or course
8838: (if no quota name provided, defaults to portfolio).
1.472 raeburn 8839:
8840: Returns:
1.1075.2.42 raeburn 8841:
1.1075.2.58 raeburn 8842: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 8843: 2. (Optional) institutional type which determined the value of the
8844: default quota.
1.472 raeburn 8845:
8846: If a value has been stored in the domain's configuration db,
8847: it will return that, otherwise it returns 20 (for backwards
8848: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 8849: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 8850:
1.536 raeburn 8851: If the user's status includes multiple types (e.g., staff and student),
8852: the largest default quota which applies to the user determines the
8853: default quota returned.
8854:
1.472 raeburn 8855: =cut
8856:
8857: ###############################################
8858:
8859:
8860: sub default_quota {
1.1075.2.41 raeburn 8861: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 8862: my ($defquota,$settingstatus);
8863: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8864: ['quotas'],$udom);
1.1075.2.41 raeburn 8865: my $key = 'defaultquota';
8866: if ($quotaname eq 'author') {
8867: $key = 'authorquota';
8868: }
1.622 raeburn 8869: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8870: if ($inststatus ne '') {
1.765 raeburn 8871: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8872: foreach my $item (@statuses) {
1.1075.2.41 raeburn 8873: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8874: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 8875: if ($defquota eq '') {
1.1075.2.41 raeburn 8876: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8877: $settingstatus = $item;
1.1075.2.41 raeburn 8878: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
8879: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8880: $settingstatus = $item;
8881: }
8882: }
1.1075.2.41 raeburn 8883: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8884: if ($quotahash{'quotas'}{$item} ne '') {
8885: if ($defquota eq '') {
8886: $defquota = $quotahash{'quotas'}{$item};
8887: $settingstatus = $item;
8888: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8889: $defquota = $quotahash{'quotas'}{$item};
8890: $settingstatus = $item;
8891: }
1.536 raeburn 8892: }
8893: }
8894: }
8895: }
8896: if ($defquota eq '') {
1.1075.2.41 raeburn 8897: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8898: $defquota = $quotahash{'quotas'}{$key}{'default'};
8899: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8900: $defquota = $quotahash{'quotas'}{'default'};
8901: }
1.536 raeburn 8902: $settingstatus = 'default';
1.1075.2.42 raeburn 8903: if ($defquota eq '') {
8904: if ($quotaname eq 'author') {
8905: $defquota = 500;
8906: }
8907: }
1.536 raeburn 8908: }
8909: } else {
8910: $settingstatus = 'default';
1.1075.2.41 raeburn 8911: if ($quotaname eq 'author') {
8912: $defquota = 500;
8913: } else {
8914: $defquota = 20;
8915: }
1.536 raeburn 8916: }
8917: if (wantarray) {
8918: return ($defquota,$settingstatus);
1.472 raeburn 8919: } else {
1.536 raeburn 8920: return $defquota;
1.472 raeburn 8921: }
8922: }
8923:
1.1075.2.41 raeburn 8924: ###############################################
8925:
8926: =pod
8927:
1.1075.2.42 raeburn 8928: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 8929:
8930: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 8931: of existing file within authoring space will cause quota for the authoring
8932: space to be exceeded.
8933:
8934: Same, if upload of a file directly to a course/community via Course Editor
8935: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 8936:
1.1075.2.61 raeburn 8937: Inputs: 7
1.1075.2.42 raeburn 8938: 1. username or coursenum
1.1075.2.41 raeburn 8939: 2. domain
1.1075.2.42 raeburn 8940: 3. context ('author' or 'course')
1.1075.2.41 raeburn 8941: 4. filename of file for which action is being requested
8942: 5. filesize (kB) of file
8943: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 8944: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 8945:
8946: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
8947: otherwise return null.
8948:
1.1075.2.42 raeburn 8949: =back
8950:
1.1075.2.41 raeburn 8951: =cut
8952:
1.1075.2.42 raeburn 8953: sub excess_filesize_warning {
1.1075.2.59 raeburn 8954: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 8955: my $current_disk_usage = 0;
1.1075.2.59 raeburn 8956: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 8957: if ($context eq 'author') {
8958: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
8959: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
8960: } else {
8961: foreach my $subdir ('docs','supplemental') {
8962: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
8963: }
8964: }
1.1075.2.41 raeburn 8965: $disk_quota = int($disk_quota * 1000);
8966: if (($current_disk_usage + $filesize) > $disk_quota) {
8967: return '<p><span class="LC_warning">'.
8968: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
8969: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</span>'.
8970: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
8971: $disk_quota,$current_disk_usage).
8972: '</p>';
8973: }
8974: return;
8975: }
8976:
8977: ###############################################
8978:
8979:
1.384 raeburn 8980: sub get_secgrprole_info {
8981: my ($cdom,$cnum,$needroles,$type) = @_;
8982: my %sections_count = &get_sections($cdom,$cnum);
8983: my @sections = (sort {$a <=> $b} keys(%sections_count));
8984: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8985: my @groups = sort(keys(%curr_groups));
8986: my $allroles = [];
8987: my $rolehash;
8988: my $accesshash = {
8989: active => 'Currently has access',
8990: future => 'Will have future access',
8991: previous => 'Previously had access',
8992: };
8993: if ($needroles) {
8994: $rolehash = {'all' => 'all'};
1.385 albertel 8995: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8996: if (&Apache::lonnet::error(%user_roles)) {
8997: undef(%user_roles);
8998: }
8999: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9000: my ($role)=split(/\:/,$item,2);
9001: if ($role eq 'cr') { next; }
9002: if ($role =~ /^cr/) {
9003: $$rolehash{$role} = (split('/',$role))[3];
9004: } else {
9005: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9006: }
9007: }
9008: foreach my $key (sort(keys(%{$rolehash}))) {
9009: push(@{$allroles},$key);
9010: }
9011: push (@{$allroles},'st');
9012: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9013: }
9014: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9015: }
9016:
1.555 raeburn 9017: sub user_picker {
1.994 raeburn 9018: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 9019: my $currdom = $dom;
9020: my %curr_selected = (
9021: srchin => 'dom',
1.580 raeburn 9022: srchby => 'lastname',
1.555 raeburn 9023: );
9024: my $srchterm;
1.625 raeburn 9025: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9026: if ($srch->{'srchby'} ne '') {
9027: $curr_selected{'srchby'} = $srch->{'srchby'};
9028: }
9029: if ($srch->{'srchin'} ne '') {
9030: $curr_selected{'srchin'} = $srch->{'srchin'};
9031: }
9032: if ($srch->{'srchtype'} ne '') {
9033: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9034: }
9035: if ($srch->{'srchdomain'} ne '') {
9036: $currdom = $srch->{'srchdomain'};
9037: }
9038: $srchterm = $srch->{'srchterm'};
9039: }
9040: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 9041: 'usr' => 'Search criteria',
1.563 raeburn 9042: 'doma' => 'Domain/institution to search',
1.558 albertel 9043: 'uname' => 'username',
9044: 'lastname' => 'last name',
1.555 raeburn 9045: 'lastfirst' => 'last name, first name',
1.558 albertel 9046: 'crs' => 'in this course',
1.576 raeburn 9047: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9048: 'alc' => 'all LON-CAPA',
1.573 raeburn 9049: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9050: 'exact' => 'is',
9051: 'contains' => 'contains',
1.569 raeburn 9052: 'begins' => 'begins with',
1.571 raeburn 9053: 'youm' => "You must include some text to search for.",
9054: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9055: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9056: 'yomc' => "You must choose a domain when using an institutional directory search.",
9057: 'ymcd' => "You must choose a domain when using a domain search.",
9058: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9059: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9060: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9061: );
1.563 raeburn 9062: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9063: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9064:
9065: my @srchins = ('crs','dom','alc','instd');
9066:
9067: foreach my $option (@srchins) {
9068: # FIXME 'alc' option unavailable until
9069: # loncreateuser::print_user_query_page()
9070: # has been completed.
9071: next if ($option eq 'alc');
1.880 raeburn 9072: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9073: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9074: if ($curr_selected{'srchin'} eq $option) {
9075: $srchinsel .= '
9076: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9077: } else {
9078: $srchinsel .= '
9079: <option value="'.$option.'">'.$lt{$option}.'</option>';
9080: }
1.555 raeburn 9081: }
1.563 raeburn 9082: $srchinsel .= "\n </select>\n";
1.555 raeburn 9083:
9084: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9085: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9086: if ($curr_selected{'srchby'} eq $option) {
9087: $srchbysel .= '
9088: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9089: } else {
9090: $srchbysel .= '
9091: <option value="'.$option.'">'.$lt{$option}.'</option>';
9092: }
9093: }
9094: $srchbysel .= "\n </select>\n";
9095:
9096: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9097: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9098: if ($curr_selected{'srchtype'} eq $option) {
9099: $srchtypesel .= '
9100: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9101: } else {
9102: $srchtypesel .= '
9103: <option value="'.$option.'">'.$lt{$option}.'</option>';
9104: }
9105: }
9106: $srchtypesel .= "\n </select>\n";
9107:
1.558 albertel 9108: my ($newuserscript,$new_user_create);
1.994 raeburn 9109: my $context_dom = $env{'request.role.domain'};
9110: if ($context eq 'requestcrs') {
9111: if ($env{'form.coursedom'} ne '') {
9112: $context_dom = $env{'form.coursedom'};
9113: }
9114: }
1.556 raeburn 9115: if ($forcenewuser) {
1.576 raeburn 9116: if (ref($srch) eq 'HASH') {
1.994 raeburn 9117: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9118: if ($cancreate) {
9119: $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>';
9120: } else {
1.799 bisitz 9121: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9122: my %usertypetext = (
9123: official => 'institutional',
9124: unofficial => 'non-institutional',
9125: );
1.799 bisitz 9126: $new_user_create = '<p class="LC_warning">'
9127: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9128: .' '
9129: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9130: ,'<a href="'.$helplink.'">','</a>')
9131: .'</p><br />';
1.627 raeburn 9132: }
1.576 raeburn 9133: }
9134: }
9135:
1.556 raeburn 9136: $newuserscript = <<"ENDSCRIPT";
9137:
1.570 raeburn 9138: function setSearch(createnew,callingForm) {
1.556 raeburn 9139: if (createnew == 1) {
1.570 raeburn 9140: for (var i=0; i<callingForm.srchby.length; i++) {
9141: if (callingForm.srchby.options[i].value == 'uname') {
9142: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9143: }
9144: }
1.570 raeburn 9145: for (var i=0; i<callingForm.srchin.length; i++) {
9146: if ( callingForm.srchin.options[i].value == 'dom') {
9147: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9148: }
9149: }
1.570 raeburn 9150: for (var i=0; i<callingForm.srchtype.length; i++) {
9151: if (callingForm.srchtype.options[i].value == 'exact') {
9152: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9153: }
9154: }
1.570 raeburn 9155: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9156: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9157: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9158: }
9159: }
9160: }
9161: }
9162: ENDSCRIPT
1.558 albertel 9163:
1.556 raeburn 9164: }
9165:
1.555 raeburn 9166: my $output = <<"END_BLOCK";
1.556 raeburn 9167: <script type="text/javascript">
1.824 bisitz 9168: // <![CDATA[
1.570 raeburn 9169: function validateEntry(callingForm) {
1.558 albertel 9170:
1.556 raeburn 9171: var checkok = 1;
1.558 albertel 9172: var srchin;
1.570 raeburn 9173: for (var i=0; i<callingForm.srchin.length; i++) {
9174: if ( callingForm.srchin[i].checked ) {
9175: srchin = callingForm.srchin[i].value;
1.558 albertel 9176: }
9177: }
9178:
1.570 raeburn 9179: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9180: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9181: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9182: var srchterm = callingForm.srchterm.value;
9183: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9184: var msg = "";
9185:
9186: if (srchterm == "") {
9187: checkok = 0;
1.571 raeburn 9188: msg += "$lt{'youm'}\\n";
1.556 raeburn 9189: }
9190:
1.569 raeburn 9191: if (srchtype== 'begins') {
9192: if (srchterm.length < 2) {
9193: checkok = 0;
1.571 raeburn 9194: msg += "$lt{'thte'}\\n";
1.569 raeburn 9195: }
9196: }
9197:
1.556 raeburn 9198: if (srchtype== 'contains') {
9199: if (srchterm.length < 3) {
9200: checkok = 0;
1.571 raeburn 9201: msg += "$lt{'thet'}\\n";
1.556 raeburn 9202: }
9203: }
9204: if (srchin == 'instd') {
9205: if (srchdomain == '') {
9206: checkok = 0;
1.571 raeburn 9207: msg += "$lt{'yomc'}\\n";
1.556 raeburn 9208: }
9209: }
9210: if (srchin == 'dom') {
9211: if (srchdomain == '') {
9212: checkok = 0;
1.571 raeburn 9213: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 9214: }
9215: }
9216: if (srchby == 'lastfirst') {
9217: if (srchterm.indexOf(",") == -1) {
9218: checkok = 0;
1.571 raeburn 9219: msg += "$lt{'whus'}\\n";
1.556 raeburn 9220: }
9221: if (srchterm.indexOf(",") == srchterm.length -1) {
9222: checkok = 0;
1.571 raeburn 9223: msg += "$lt{'whse'}\\n";
1.556 raeburn 9224: }
9225: }
9226: if (checkok == 0) {
1.571 raeburn 9227: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 9228: return;
9229: }
9230: if (checkok == 1) {
1.570 raeburn 9231: callingForm.submit();
1.556 raeburn 9232: }
9233: }
9234:
9235: $newuserscript
9236:
1.824 bisitz 9237: // ]]>
1.556 raeburn 9238: </script>
1.558 albertel 9239:
9240: $new_user_create
9241:
1.555 raeburn 9242: END_BLOCK
1.558 albertel 9243:
1.876 raeburn 9244: $output .= &Apache::lonhtmlcommon::start_pick_box().
9245: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
9246: $domform.
9247: &Apache::lonhtmlcommon::row_closure().
9248: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
9249: $srchbysel.
9250: $srchtypesel.
9251: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9252: $srchinsel.
9253: &Apache::lonhtmlcommon::row_closure(1).
9254: &Apache::lonhtmlcommon::end_pick_box().
9255: '<br />';
1.555 raeburn 9256: return $output;
9257: }
9258:
1.612 raeburn 9259: sub user_rule_check {
1.615 raeburn 9260: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 9261: my $response;
9262: if (ref($usershash) eq 'HASH') {
9263: foreach my $user (keys(%{$usershash})) {
9264: my ($uname,$udom) = split(/:/,$user);
9265: next if ($udom eq '' || $uname eq '');
1.615 raeburn 9266: my ($id,$newuser);
1.612 raeburn 9267: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 9268: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 9269: $id = $usershash->{$user}->{'id'};
9270: }
9271: my $inst_response;
9272: if (ref($checks) eq 'HASH') {
9273: if (defined($checks->{'username'})) {
1.615 raeburn 9274: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9275: &Apache::lonnet::get_instuser($udom,$uname);
9276: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9277: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9278: &Apache::lonnet::get_instuser($udom,undef,$id);
9279: }
1.615 raeburn 9280: } else {
9281: ($inst_response,%{$inst_results->{$user}}) =
9282: &Apache::lonnet::get_instuser($udom,$uname);
9283: return;
1.612 raeburn 9284: }
1.615 raeburn 9285: if (!$got_rules->{$udom}) {
1.612 raeburn 9286: my %domconfig = &Apache::lonnet::get_dom('configuration',
9287: ['usercreation'],$udom);
9288: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9289: foreach my $item ('username','id') {
1.612 raeburn 9290: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9291: $$curr_rules{$udom}{$item} =
9292: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9293: }
9294: }
9295: }
1.615 raeburn 9296: $got_rules->{$udom} = 1;
1.585 raeburn 9297: }
1.612 raeburn 9298: foreach my $item (keys(%{$checks})) {
9299: if (ref($$curr_rules{$udom}) eq 'HASH') {
9300: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9301: if (@{$$curr_rules{$udom}{$item}} > 0) {
9302: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9303: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9304: if ($rule_check{$rule}) {
9305: $$rulematch{$user}{$item} = $rule;
9306: if ($inst_response eq 'ok') {
1.615 raeburn 9307: if (ref($inst_results) eq 'HASH') {
9308: if (ref($inst_results->{$user}) eq 'HASH') {
9309: if (keys(%{$inst_results->{$user}}) == 0) {
9310: $$alerts{$item}{$udom}{$uname} = 1;
9311: }
1.612 raeburn 9312: }
9313: }
1.615 raeburn 9314: }
9315: last;
1.585 raeburn 9316: }
9317: }
9318: }
9319: }
9320: }
9321: }
9322: }
9323: }
1.612 raeburn 9324: return;
9325: }
9326:
9327: sub user_rule_formats {
9328: my ($domain,$domdesc,$curr_rules,$check) = @_;
9329: my %text = (
9330: 'username' => 'Usernames',
9331: 'id' => 'IDs',
9332: );
9333: my $output;
9334: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9335: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9336: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 9337: $output = '<br />'.
9338: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9339: '<span class="LC_cusr_emph">','</span>',$domdesc).
9340: ' <ul>';
1.612 raeburn 9341: foreach my $rule (@{$ruleorder}) {
9342: if (ref($curr_rules) eq 'ARRAY') {
9343: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9344: if (ref($rules->{$rule}) eq 'HASH') {
9345: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9346: $rules->{$rule}{'desc'}.'</li>';
9347: }
9348: }
9349: }
9350: }
9351: $output .= '</ul>';
9352: }
9353: }
9354: return $output;
9355: }
9356:
9357: sub instrule_disallow_msg {
1.615 raeburn 9358: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9359: my $response;
9360: my %text = (
9361: item => 'username',
9362: items => 'usernames',
9363: match => 'matches',
9364: do => 'does',
9365: action => 'a username',
9366: one => 'one',
9367: );
9368: if ($count > 1) {
9369: $text{'item'} = 'usernames';
9370: $text{'match'} ='match';
9371: $text{'do'} = 'do';
9372: $text{'action'} = 'usernames',
9373: $text{'one'} = 'ones';
9374: }
9375: if ($checkitem eq 'id') {
9376: $text{'items'} = 'IDs';
9377: $text{'item'} = 'ID';
9378: $text{'action'} = 'an ID';
1.615 raeburn 9379: if ($count > 1) {
9380: $text{'item'} = 'IDs';
9381: $text{'action'} = 'IDs';
9382: }
1.612 raeburn 9383: }
1.674 bisitz 9384: $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 9385: if ($mode eq 'upload') {
9386: if ($checkitem eq 'username') {
9387: $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'}.");
9388: } elsif ($checkitem eq 'id') {
1.674 bisitz 9389: $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 9390: }
1.669 raeburn 9391: } elsif ($mode eq 'selfcreate') {
9392: if ($checkitem eq 'id') {
9393: $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.");
9394: }
1.615 raeburn 9395: } else {
9396: if ($checkitem eq 'username') {
9397: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9398: } elsif ($checkitem eq 'id') {
9399: $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.");
9400: }
1.612 raeburn 9401: }
9402: return $response;
1.585 raeburn 9403: }
9404:
1.624 raeburn 9405: sub personal_data_fieldtitles {
9406: my %fieldtitles = &Apache::lonlocal::texthash (
9407: id => 'Student/Employee ID',
9408: permanentemail => 'E-mail address',
9409: lastname => 'Last Name',
9410: firstname => 'First Name',
9411: middlename => 'Middle Name',
9412: generation => 'Generation',
9413: gen => 'Generation',
1.765 raeburn 9414: inststatus => 'Affiliation',
1.624 raeburn 9415: );
9416: return %fieldtitles;
9417: }
9418:
1.642 raeburn 9419: sub sorted_inst_types {
9420: my ($dom) = @_;
9421: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9422: my $othertitle = &mt('All users');
9423: if ($env{'request.course.id'}) {
1.668 raeburn 9424: $othertitle = &mt('Any users');
1.642 raeburn 9425: }
9426: my @types;
9427: if (ref($order) eq 'ARRAY') {
9428: @types = @{$order};
9429: }
9430: if (@types == 0) {
9431: if (ref($usertypes) eq 'HASH') {
9432: @types = sort(keys(%{$usertypes}));
9433: }
9434: }
9435: if (keys(%{$usertypes}) > 0) {
9436: $othertitle = &mt('Other users');
9437: }
9438: return ($othertitle,$usertypes,\@types);
9439: }
9440:
1.645 raeburn 9441: sub get_institutional_codes {
9442: my ($settings,$allcourses,$LC_code) = @_;
9443: # Get complete list of course sections to update
9444: my @currsections = ();
9445: my @currxlists = ();
9446: my $coursecode = $$settings{'internal.coursecode'};
9447:
9448: if ($$settings{'internal.sectionnums'} ne '') {
9449: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9450: }
9451:
9452: if ($$settings{'internal.crosslistings'} ne '') {
9453: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9454: }
9455:
9456: if (@currxlists > 0) {
9457: foreach (@currxlists) {
9458: if (m/^([^:]+):(\w*)$/) {
9459: unless (grep/^$1$/,@{$allcourses}) {
9460: push @{$allcourses},$1;
9461: $$LC_code{$1} = $2;
9462: }
9463: }
9464: }
9465: }
9466:
9467: if (@currsections > 0) {
9468: foreach (@currsections) {
9469: if (m/^(\w+):(\w*)$/) {
9470: my $sec = $coursecode.$1;
9471: my $lc_sec = $2;
9472: unless (grep/^$sec$/,@{$allcourses}) {
9473: push @{$allcourses},$sec;
9474: $$LC_code{$sec} = $lc_sec;
9475: }
9476: }
9477: }
9478: }
9479: return;
9480: }
9481:
1.971 raeburn 9482: sub get_standard_codeitems {
9483: return ('Year','Semester','Department','Number','Section');
9484: }
9485:
1.112 bowersj2 9486: =pod
9487:
1.780 raeburn 9488: =head1 Slot Helpers
9489:
9490: =over 4
9491:
9492: =item * sorted_slots()
9493:
1.1040 raeburn 9494: Sorts an array of slot names in order of an optional sort key,
9495: default sort is by slot start time (earliest first).
1.780 raeburn 9496:
9497: Inputs:
9498:
9499: =over 4
9500:
9501: slotsarr - Reference to array of unsorted slot names.
9502:
9503: slots - Reference to hash of hash, where outer hash keys are slot names.
9504:
1.1040 raeburn 9505: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9506:
1.549 albertel 9507: =back
9508:
1.780 raeburn 9509: Returns:
9510:
9511: =over 4
9512:
1.1040 raeburn 9513: sorted - An array of slot names sorted by a specified sort key
9514: (default sort key is start time of the slot).
1.780 raeburn 9515:
9516: =back
9517:
9518: =cut
9519:
9520:
9521: sub sorted_slots {
1.1040 raeburn 9522: my ($slotsarr,$slots,$sortkey) = @_;
9523: if ($sortkey eq '') {
9524: $sortkey = 'starttime';
9525: }
1.780 raeburn 9526: my @sorted;
9527: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9528: @sorted =
9529: sort {
9530: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9531: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9532: }
9533: if (ref($slots->{$a})) { return -1;}
9534: if (ref($slots->{$b})) { return 1;}
9535: return 0;
9536: } @{$slotsarr};
9537: }
9538: return @sorted;
9539: }
9540:
1.1040 raeburn 9541: =pod
9542:
9543: =item * get_future_slots()
9544:
9545: Inputs:
9546:
9547: =over 4
9548:
9549: cnum - course number
9550:
9551: cdom - course domain
9552:
9553: now - current UNIX time
9554:
9555: symb - optional symb
9556:
9557: =back
9558:
9559: Returns:
9560:
9561: =over 4
9562:
9563: sorted_reservable - ref to array of student_schedulable slots currently
9564: reservable, ordered by end date of reservation period.
9565:
9566: reservable_now - ref to hash of student_schedulable slots currently
9567: reservable.
9568:
9569: Keys in inner hash are:
9570: (a) symb: either blank or symb to which slot use is restricted.
9571: (b) endreserve: end date of reservation period.
9572:
9573: sorted_future - ref to array of student_schedulable slots reservable in
9574: the future, ordered by start date of reservation period.
9575:
9576: future_reservable - ref to hash of student_schedulable slots reservable
9577: in the future.
9578:
9579: Keys in inner hash are:
9580: (a) symb: either blank or symb to which slot use is restricted.
9581: (b) startreserve: start date of reservation period.
9582:
9583: =back
9584:
9585: =cut
9586:
9587: sub get_future_slots {
9588: my ($cnum,$cdom,$now,$symb) = @_;
9589: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9590: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9591: foreach my $slot (keys(%slots)) {
9592: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9593: if ($symb) {
9594: next if (($slots{$slot}->{'symb'} ne '') &&
9595: ($slots{$slot}->{'symb'} ne $symb));
9596: }
9597: if (($slots{$slot}->{'starttime'} > $now) &&
9598: ($slots{$slot}->{'endtime'} > $now)) {
9599: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9600: my $userallowed = 0;
9601: if ($slots{$slot}->{'allowedsections'}) {
9602: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9603: if (!defined($env{'request.role.sec'})
9604: && grep(/^No section assigned$/,@allowed_sec)) {
9605: $userallowed=1;
9606: } else {
9607: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9608: $userallowed=1;
9609: }
9610: }
9611: unless ($userallowed) {
9612: if (defined($env{'request.course.groups'})) {
9613: my @groups = split(/:/,$env{'request.course.groups'});
9614: foreach my $group (@groups) {
9615: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9616: $userallowed=1;
9617: last;
9618: }
9619: }
9620: }
9621: }
9622: }
9623: if ($slots{$slot}->{'allowedusers'}) {
9624: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9625: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9626: if (grep(/^\Q$user\E$/,@allowed_users)) {
9627: $userallowed = 1;
9628: }
9629: }
9630: next unless($userallowed);
9631: }
9632: my $startreserve = $slots{$slot}->{'startreserve'};
9633: my $endreserve = $slots{$slot}->{'endreserve'};
9634: my $symb = $slots{$slot}->{'symb'};
9635: if (($startreserve < $now) &&
9636: (!$endreserve || $endreserve > $now)) {
9637: my $lastres = $endreserve;
9638: if (!$lastres) {
9639: $lastres = $slots{$slot}->{'starttime'};
9640: }
9641: $reservable_now{$slot} = {
9642: symb => $symb,
9643: endreserve => $lastres
9644: };
9645: } elsif (($startreserve > $now) &&
9646: (!$endreserve || $endreserve > $startreserve)) {
9647: $future_reservable{$slot} = {
9648: symb => $symb,
9649: startreserve => $startreserve
9650: };
9651: }
9652: }
9653: }
9654: my @unsorted_reservable = keys(%reservable_now);
9655: if (@unsorted_reservable > 0) {
9656: @sorted_reservable =
9657: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9658: }
9659: my @unsorted_future = keys(%future_reservable);
9660: if (@unsorted_future > 0) {
9661: @sorted_future =
9662: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9663: }
9664: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9665: }
1.780 raeburn 9666:
9667: =pod
9668:
1.1057 foxr 9669: =back
9670:
1.549 albertel 9671: =head1 HTTP Helpers
9672:
9673: =over 4
9674:
1.648 raeburn 9675: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9676:
1.258 albertel 9677: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9678: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9679: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9680:
9681: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9682: $possible_names is an ref to an array of form element names. As an example:
9683: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9684: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9685:
9686: =cut
1.1 albertel 9687:
1.6 albertel 9688: sub get_unprocessed_cgi {
1.25 albertel 9689: my ($query,$possible_names)= @_;
1.26 matthew 9690: # $Apache::lonxml::debug=1;
1.356 albertel 9691: foreach my $pair (split(/&/,$query)) {
9692: my ($name, $value) = split(/=/,$pair);
1.369 www 9693: $name = &unescape($name);
1.25 albertel 9694: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9695: $value =~ tr/+/ /;
9696: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9697: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9698: }
1.16 harris41 9699: }
1.6 albertel 9700: }
9701:
1.112 bowersj2 9702: =pod
9703:
1.648 raeburn 9704: =item * &cacheheader()
1.112 bowersj2 9705:
9706: returns cache-controlling header code
9707:
9708: =cut
9709:
1.7 albertel 9710: sub cacheheader {
1.258 albertel 9711: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9712: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9713: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9714: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9715: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9716: return $output;
1.7 albertel 9717: }
9718:
1.112 bowersj2 9719: =pod
9720:
1.648 raeburn 9721: =item * &no_cache($r)
1.112 bowersj2 9722:
9723: specifies header code to not have cache
9724:
9725: =cut
9726:
1.9 albertel 9727: sub no_cache {
1.216 albertel 9728: my ($r) = @_;
9729: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9730: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9731: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9732: $r->no_cache(1);
9733: $r->header_out("Expires" => $date);
9734: $r->header_out("Pragma" => "no-cache");
1.123 www 9735: }
9736:
9737: sub content_type {
1.181 albertel 9738: my ($r,$type,$charset) = @_;
1.299 foxr 9739: if ($r) {
9740: # Note that printout.pl calls this with undef for $r.
9741: &no_cache($r);
9742: }
1.258 albertel 9743: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9744: unless ($charset) {
9745: $charset=&Apache::lonlocal::current_encoding;
9746: }
9747: if ($charset) { $type.='; charset='.$charset; }
9748: if ($r) {
9749: $r->content_type($type);
9750: } else {
9751: print("Content-type: $type\n\n");
9752: }
1.9 albertel 9753: }
1.25 albertel 9754:
1.112 bowersj2 9755: =pod
9756:
1.648 raeburn 9757: =item * &add_to_env($name,$value)
1.112 bowersj2 9758:
1.258 albertel 9759: adds $name to the %env hash with value
1.112 bowersj2 9760: $value, if $name already exists, the entry is converted to an array
9761: reference and $value is added to the array.
9762:
9763: =cut
9764:
1.25 albertel 9765: sub add_to_env {
9766: my ($name,$value)=@_;
1.258 albertel 9767: if (defined($env{$name})) {
9768: if (ref($env{$name})) {
1.25 albertel 9769: #already have multiple values
1.258 albertel 9770: push(@{ $env{$name} },$value);
1.25 albertel 9771: } else {
9772: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9773: my $first=$env{$name};
9774: undef($env{$name});
9775: push(@{ $env{$name} },$first,$value);
1.25 albertel 9776: }
9777: } else {
1.258 albertel 9778: $env{$name}=$value;
1.25 albertel 9779: }
1.31 albertel 9780: }
1.149 albertel 9781:
9782: =pod
9783:
1.648 raeburn 9784: =item * &get_env_multiple($name)
1.149 albertel 9785:
1.258 albertel 9786: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9787: values may be defined and end up as an array ref.
9788:
9789: returns an array of values
9790:
9791: =cut
9792:
9793: sub get_env_multiple {
9794: my ($name) = @_;
9795: my @values;
1.258 albertel 9796: if (defined($env{$name})) {
1.149 albertel 9797: # exists is it an array
1.258 albertel 9798: if (ref($env{$name})) {
9799: @values=@{ $env{$name} };
1.149 albertel 9800: } else {
1.258 albertel 9801: $values[0]=$env{$name};
1.149 albertel 9802: }
9803: }
9804: return(@values);
9805: }
9806:
1.660 raeburn 9807: sub ask_for_embedded_content {
9808: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9809: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 9810: %currsubfile,%unused,$rem);
1.1071 raeburn 9811: my $counter = 0;
9812: my $numnew = 0;
1.987 raeburn 9813: my $numremref = 0;
9814: my $numinvalid = 0;
9815: my $numpathchg = 0;
9816: my $numexisting = 0;
1.1071 raeburn 9817: my $numunused = 0;
9818: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 9819: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 9820: my $heading = &mt('Upload embedded files');
9821: my $buttontext = &mt('Upload');
9822:
1.1075.2.11 raeburn 9823: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 9824: if ($actionurl eq '/adm/dependencies') {
9825: $navmap = Apache::lonnavmaps::navmap->new();
9826: }
9827: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9828: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 9829: }
1.1075.2.35 raeburn 9830: if (($actionurl eq '/adm/portfolio') ||
9831: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 9832: my $current_path='/';
9833: if ($env{'form.currentpath'}) {
9834: $current_path = $env{'form.currentpath'};
9835: }
9836: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 9837: $udom = $cdom;
9838: $uname = $cnum;
1.984 raeburn 9839: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9840: } else {
9841: $udom = $env{'user.domain'};
9842: $uname = $env{'user.name'};
9843: $url = '/userfiles/portfolio';
9844: }
1.987 raeburn 9845: $toplevel = $url.'/';
1.984 raeburn 9846: $url .= $current_path;
9847: $getpropath = 1;
1.987 raeburn 9848: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9849: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9850: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9851: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9852: $toplevel = $url;
1.984 raeburn 9853: if ($rest ne '') {
1.987 raeburn 9854: $url .= $rest;
9855: }
9856: } elsif ($actionurl eq '/adm/coursedocs') {
9857: if (ref($args) eq 'HASH') {
1.1071 raeburn 9858: $url = $args->{'docs_url'};
9859: $toplevel = $url;
1.1075.2.11 raeburn 9860: if ($args->{'context'} eq 'paste') {
9861: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9862: ($path) =
9863: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9864: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9865: $fileloc =~ s{^/}{};
9866: }
1.1071 raeburn 9867: }
9868: } elsif ($actionurl eq '/adm/dependencies') {
9869: if ($env{'request.course.id'} ne '') {
9870: if (ref($args) eq 'HASH') {
9871: $url = $args->{'docs_url'};
9872: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 9873: $toplevel = $url;
9874: unless ($toplevel =~ m{^/}) {
9875: $toplevel = "/$url";
9876: }
1.1075.2.11 raeburn 9877: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 9878: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
9879: $path = $1;
9880: } else {
9881: ($path) =
9882: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9883: }
1.1071 raeburn 9884: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9885: $fileloc =~ s{^/}{};
9886: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9887: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9888: }
1.987 raeburn 9889: }
1.1075.2.35 raeburn 9890: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9891: $udom = $cdom;
9892: $uname = $cnum;
9893: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
9894: $toplevel = $url;
9895: $path = $url;
9896: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
9897: $fileloc =~ s{^/}{};
9898: }
9899: foreach my $file (keys(%{$allfiles})) {
9900: my $embed_file;
9901: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
9902: $embed_file = $1;
9903: } else {
9904: $embed_file = $file;
9905: }
1.1075.2.55 raeburn 9906: my ($absolutepath,$cleaned_file);
9907: if ($embed_file =~ m{^\w+://}) {
9908: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 9909: $newfiles{$cleaned_file} = 1;
9910: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9911: } else {
1.1075.2.55 raeburn 9912: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 9913: if ($embed_file =~ m{^/}) {
9914: $absolutepath = $embed_file;
9915: }
1.1075.2.47 raeburn 9916: if ($cleaned_file =~ m{/}) {
9917: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 9918: $path = &check_for_traversal($path,$url,$toplevel);
9919: my $item = $fname;
9920: if ($path ne '') {
9921: $item = $path.'/'.$fname;
9922: $subdependencies{$path}{$fname} = 1;
9923: } else {
9924: $dependencies{$item} = 1;
9925: }
9926: if ($absolutepath) {
9927: $mapping{$item} = $absolutepath;
9928: } else {
9929: $mapping{$item} = $embed_file;
9930: }
9931: } else {
9932: $dependencies{$embed_file} = 1;
9933: if ($absolutepath) {
1.1075.2.47 raeburn 9934: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 9935: } else {
1.1075.2.47 raeburn 9936: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9937: }
9938: }
1.984 raeburn 9939: }
9940: }
1.1071 raeburn 9941: my $dirptr = 16384;
1.984 raeburn 9942: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9943: $currsubfile{$path} = {};
1.1075.2.35 raeburn 9944: if (($actionurl eq '/adm/portfolio') ||
9945: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9946: my ($sublistref,$listerror) =
9947: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9948: if (ref($sublistref) eq 'ARRAY') {
9949: foreach my $line (@{$sublistref}) {
9950: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9951: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9952: }
1.984 raeburn 9953: }
1.987 raeburn 9954: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9955: if (opendir(my $dir,$url.'/'.$path)) {
9956: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9957: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9958: }
1.1075.2.11 raeburn 9959: } elsif (($actionurl eq '/adm/dependencies') ||
9960: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 9961: ($args->{'context'} eq 'paste')) ||
9962: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9963: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 9964: my $dir;
9965: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9966: $dir = $fileloc;
9967: } else {
9968: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9969: }
1.1071 raeburn 9970: if ($dir ne '') {
9971: my ($sublistref,$listerror) =
9972: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9973: if (ref($sublistref) eq 'ARRAY') {
9974: foreach my $line (@{$sublistref}) {
9975: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
9976: undef,$mtime)=split(/\&/,$line,12);
9977: unless (($testdir&$dirptr) ||
9978: ($file_name =~ /^\.\.?$/)) {
9979: $currsubfile{$path}{$file_name} = [$size,$mtime];
9980: }
9981: }
9982: }
9983: }
1.984 raeburn 9984: }
9985: }
9986: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 9987: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 9988: my $item = $path.'/'.$file;
9989: unless ($mapping{$item} eq $item) {
9990: $pathchanges{$item} = 1;
9991: }
9992: $existing{$item} = 1;
9993: $numexisting ++;
9994: } else {
9995: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 9996: }
9997: }
1.1071 raeburn 9998: if ($actionurl eq '/adm/dependencies') {
9999: foreach my $path (keys(%currsubfile)) {
10000: if (ref($currsubfile{$path}) eq 'HASH') {
10001: foreach my $file (keys(%{$currsubfile{$path}})) {
10002: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 10003: next if (($rem ne '') &&
10004: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10005: (ref($navmap) &&
10006: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10007: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10008: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10009: $unused{$path.'/'.$file} = 1;
10010: }
10011: }
10012: }
10013: }
10014: }
1.984 raeburn 10015: }
1.987 raeburn 10016: my %currfile;
1.1075.2.35 raeburn 10017: if (($actionurl eq '/adm/portfolio') ||
10018: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10019: my ($dirlistref,$listerror) =
10020: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10021: if (ref($dirlistref) eq 'ARRAY') {
10022: foreach my $line (@{$dirlistref}) {
10023: my ($file_name,$rest) = split(/\&/,$line,2);
10024: $currfile{$file_name} = 1;
10025: }
1.984 raeburn 10026: }
1.987 raeburn 10027: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10028: if (opendir(my $dir,$url)) {
1.987 raeburn 10029: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10030: map {$currfile{$_} = 1;} @dir_list;
10031: }
1.1075.2.11 raeburn 10032: } elsif (($actionurl eq '/adm/dependencies') ||
10033: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10034: ($args->{'context'} eq 'paste')) ||
10035: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10036: if ($env{'request.course.id'} ne '') {
10037: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10038: if ($dir ne '') {
10039: my ($dirlistref,$listerror) =
10040: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10041: if (ref($dirlistref) eq 'ARRAY') {
10042: foreach my $line (@{$dirlistref}) {
10043: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10044: $size,undef,$mtime)=split(/\&/,$line,12);
10045: unless (($testdir&$dirptr) ||
10046: ($file_name =~ /^\.\.?$/)) {
10047: $currfile{$file_name} = [$size,$mtime];
10048: }
10049: }
10050: }
10051: }
10052: }
1.984 raeburn 10053: }
10054: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10055: if (exists($currfile{$file})) {
1.987 raeburn 10056: unless ($mapping{$file} eq $file) {
10057: $pathchanges{$file} = 1;
10058: }
10059: $existing{$file} = 1;
10060: $numexisting ++;
10061: } else {
1.984 raeburn 10062: $newfiles{$file} = 1;
10063: }
10064: }
1.1071 raeburn 10065: foreach my $file (keys(%currfile)) {
10066: unless (($file eq $filename) ||
10067: ($file eq $filename.'.bak') ||
10068: ($dependencies{$file})) {
1.1075.2.11 raeburn 10069: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10070: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10071: next if (($rem ne '') &&
10072: (($env{"httpref.$rem".$file} ne '') ||
10073: (ref($navmap) &&
10074: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10075: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10076: ($navmap->getResourceByUrl($rem.$1)))))));
10077: }
1.1075.2.11 raeburn 10078: }
1.1071 raeburn 10079: $unused{$file} = 1;
10080: }
10081: }
1.1075.2.11 raeburn 10082: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10083: ($args->{'context'} eq 'paste')) {
10084: $counter = scalar(keys(%existing));
10085: $numpathchg = scalar(keys(%pathchanges));
10086: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10087: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10088: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10089: $counter = scalar(keys(%existing));
10090: $numpathchg = scalar(keys(%pathchanges));
10091: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10092: }
1.984 raeburn 10093: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10094: if ($actionurl eq '/adm/dependencies') {
10095: next if ($embed_file =~ m{^\w+://});
10096: }
1.660 raeburn 10097: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10098: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10099: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10100: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10101: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10102: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10103: }
1.1075.2.35 raeburn 10104: $upload_output .= '</td>';
1.1071 raeburn 10105: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10106: $upload_output.='<td align="right">'.
10107: '<span class="LC_info LC_fontsize_medium">'.
10108: &mt("URL points to web address").'</span>';
1.987 raeburn 10109: $numremref++;
1.660 raeburn 10110: } elsif ($args->{'error_on_invalid_names'}
10111: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10112: $upload_output.='<td align="right"><span class="LC_warning">'.
10113: &mt('Invalid characters').'</span>';
1.987 raeburn 10114: $numinvalid++;
1.660 raeburn 10115: } else {
1.1075.2.35 raeburn 10116: $upload_output .= '<td>'.
10117: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10118: $embed_file,\%mapping,
1.1071 raeburn 10119: $allfiles,$codebase,'upload');
10120: $counter ++;
10121: $numnew ++;
1.987 raeburn 10122: }
10123: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10124: }
10125: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10126: if ($actionurl eq '/adm/dependencies') {
10127: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10128: $modify_output .= &start_data_table_row().
10129: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10130: '<img src="'.&icon($embed_file).'" border="0" />'.
10131: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10132: '<td>'.$size.'</td>'.
10133: '<td>'.$mtime.'</td>'.
10134: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10135: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10136: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10137: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10138: &embedded_file_element('upload_embedded',$counter,
10139: $embed_file,\%mapping,
10140: $allfiles,$codebase,'modify').
10141: '</div></td>'.
10142: &end_data_table_row()."\n";
10143: $counter ++;
10144: } else {
10145: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10146: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10147: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10148: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10149: &Apache::loncommon::end_data_table_row()."\n";
10150: }
10151: }
10152: my $delidx = $counter;
10153: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10154: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10155: $delete_output .= &start_data_table_row().
10156: '<td><img src="'.&icon($oldfile).'" />'.
10157: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10158: '<td>'.$size.'</td>'.
10159: '<td>'.$mtime.'</td>'.
10160: '<td><label><input type="checkbox" name="del_upload_dep" '.
10161: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10162: &embedded_file_element('upload_embedded',$delidx,
10163: $oldfile,\%mapping,$allfiles,
10164: $codebase,'delete').'</td>'.
10165: &end_data_table_row()."\n";
10166: $numunused ++;
10167: $delidx ++;
1.987 raeburn 10168: }
10169: if ($upload_output) {
10170: $upload_output = &start_data_table().
10171: $upload_output.
10172: &end_data_table()."\n";
10173: }
1.1071 raeburn 10174: if ($modify_output) {
10175: $modify_output = &start_data_table().
10176: &start_data_table_header_row().
10177: '<th>'.&mt('File').'</th>'.
10178: '<th>'.&mt('Size (KB)').'</th>'.
10179: '<th>'.&mt('Modified').'</th>'.
10180: '<th>'.&mt('Upload replacement?').'</th>'.
10181: &end_data_table_header_row().
10182: $modify_output.
10183: &end_data_table()."\n";
10184: }
10185: if ($delete_output) {
10186: $delete_output = &start_data_table().
10187: &start_data_table_header_row().
10188: '<th>'.&mt('File').'</th>'.
10189: '<th>'.&mt('Size (KB)').'</th>'.
10190: '<th>'.&mt('Modified').'</th>'.
10191: '<th>'.&mt('Delete?').'</th>'.
10192: &end_data_table_header_row().
10193: $delete_output.
10194: &end_data_table()."\n";
10195: }
1.987 raeburn 10196: my $applies = 0;
10197: if ($numremref) {
10198: $applies ++;
10199: }
10200: if ($numinvalid) {
10201: $applies ++;
10202: }
10203: if ($numexisting) {
10204: $applies ++;
10205: }
1.1071 raeburn 10206: if ($counter || $numunused) {
1.987 raeburn 10207: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10208: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10209: $state.'<h3>'.$heading.'</h3>';
10210: if ($actionurl eq '/adm/dependencies') {
10211: if ($numnew) {
10212: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10213: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10214: $upload_output.'<br />'."\n";
10215: }
10216: if ($numexisting) {
10217: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10218: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10219: $modify_output.'<br />'."\n";
10220: $buttontext = &mt('Save changes');
10221: }
10222: if ($numunused) {
10223: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10224: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10225: $delete_output.'<br />'."\n";
10226: $buttontext = &mt('Save changes');
10227: }
10228: } else {
10229: $output .= $upload_output.'<br />'."\n";
10230: }
10231: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10232: $counter.'" />'."\n";
10233: if ($actionurl eq '/adm/dependencies') {
10234: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10235: $numnew.'" />'."\n";
10236: } elsif ($actionurl eq '') {
1.987 raeburn 10237: $output .= '<input type="hidden" name="phase" value="three" />';
10238: }
10239: } elsif ($applies) {
10240: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10241: if ($applies > 1) {
10242: $output .=
1.1075.2.35 raeburn 10243: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10244: if ($numremref) {
10245: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10246: }
10247: if ($numinvalid) {
10248: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10249: }
10250: if ($numexisting) {
10251: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10252: }
10253: $output .= '</ul><br />';
10254: } elsif ($numremref) {
10255: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10256: } elsif ($numinvalid) {
10257: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10258: } elsif ($numexisting) {
10259: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10260: }
10261: $output .= $upload_output.'<br />';
10262: }
10263: my ($pathchange_output,$chgcount);
1.1071 raeburn 10264: $chgcount = $counter;
1.987 raeburn 10265: if (keys(%pathchanges) > 0) {
10266: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10267: if ($counter) {
1.987 raeburn 10268: $output .= &embedded_file_element('pathchange',$chgcount,
10269: $embed_file,\%mapping,
1.1071 raeburn 10270: $allfiles,$codebase,'change');
1.987 raeburn 10271: } else {
10272: $pathchange_output .=
10273: &start_data_table_row().
10274: '<td><input type ="checkbox" name="namechange" value="'.
10275: $chgcount.'" checked="checked" /></td>'.
10276: '<td>'.$mapping{$embed_file}.'</td>'.
10277: '<td>'.$embed_file.
10278: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10279: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10280: '</td>'.&end_data_table_row();
1.660 raeburn 10281: }
1.987 raeburn 10282: $numpathchg ++;
10283: $chgcount ++;
1.660 raeburn 10284: }
10285: }
1.1075.2.35 raeburn 10286: if (($counter) || ($numunused)) {
1.987 raeburn 10287: if ($numpathchg) {
10288: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10289: $numpathchg.'" />'."\n";
10290: }
10291: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10292: ($actionurl eq '/adm/imsimport')) {
10293: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10294: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10295: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10296: } elsif ($actionurl eq '/adm/dependencies') {
10297: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10298: }
1.1075.2.35 raeburn 10299: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10300: } elsif ($numpathchg) {
10301: my %pathchange = ();
10302: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10303: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10304: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 10305: }
1.987 raeburn 10306: }
1.1071 raeburn 10307: return ($output,$counter,$numpathchg);
1.987 raeburn 10308: }
10309:
1.1075.2.47 raeburn 10310: =pod
10311:
10312: =item * clean_path($name)
10313:
10314: Performs clean-up of directories, subdirectories and filename in an
10315: embedded object, referenced in an HTML file which is being uploaded
10316: to a course or portfolio, where
10317: "Upload embedded images/multimedia files if HTML file" checkbox was
10318: checked.
10319:
10320: Clean-up is similar to replacements in lonnet::clean_filename()
10321: except each / between sub-directory and next level is preserved.
10322:
10323: =cut
10324:
10325: sub clean_path {
10326: my ($embed_file) = @_;
10327: $embed_file =~s{^/+}{};
10328: my @contents;
10329: if ($embed_file =~ m{/}) {
10330: @contents = split(/\//,$embed_file);
10331: } else {
10332: @contents = ($embed_file);
10333: }
10334: my $lastidx = scalar(@contents)-1;
10335: for (my $i=0; $i<=$lastidx; $i++) {
10336: $contents[$i]=~s{\\}{/}g;
10337: $contents[$i]=~s/\s+/\_/g;
10338: $contents[$i]=~s{[^/\w\.\-]}{}g;
10339: if ($i == $lastidx) {
10340: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10341: }
10342: }
10343: if ($lastidx > 0) {
10344: return join('/',@contents);
10345: } else {
10346: return $contents[0];
10347: }
10348: }
10349:
1.987 raeburn 10350: sub embedded_file_element {
1.1071 raeburn 10351: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10352: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10353: (ref($codebase) eq 'HASH'));
10354: my $output;
1.1071 raeburn 10355: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10356: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10357: }
10358: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10359: &escape($embed_file).'" />';
10360: unless (($context eq 'upload_embedded') &&
10361: ($mapping->{$embed_file} eq $embed_file)) {
10362: $output .='
10363: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10364: }
10365: my $attrib;
10366: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10367: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10368: }
10369: $output .=
10370: "\n\t\t".
10371: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10372: $attrib.'" />';
10373: if (exists($codebase->{$mapping->{$embed_file}})) {
10374: $output .=
10375: "\n\t\t".
10376: '<input name="codebase_'.$num.'" type="hidden" value="'.
10377: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10378: }
1.987 raeburn 10379: return $output;
1.660 raeburn 10380: }
10381:
1.1071 raeburn 10382: sub get_dependency_details {
10383: my ($currfile,$currsubfile,$embed_file) = @_;
10384: my ($size,$mtime,$showsize,$showmtime);
10385: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10386: if ($embed_file =~ m{/}) {
10387: my ($path,$fname) = split(/\//,$embed_file);
10388: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10389: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10390: }
10391: } else {
10392: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10393: ($size,$mtime) = @{$currfile->{$embed_file}};
10394: }
10395: }
10396: $showsize = $size/1024.0;
10397: $showsize = sprintf("%.1f",$showsize);
10398: if ($mtime > 0) {
10399: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10400: }
10401: }
10402: return ($showsize,$showmtime);
10403: }
10404:
10405: sub ask_embedded_js {
10406: return <<"END";
10407: <script type="text/javascript"">
10408: // <![CDATA[
10409: function toggleBrowse(counter) {
10410: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10411: var fileid = document.getElementById('embedded_item_'+counter);
10412: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10413: if (chkboxid.checked == true) {
10414: uploaddivid.style.display='block';
10415: } else {
10416: uploaddivid.style.display='none';
10417: fileid.value = '';
10418: }
10419: }
10420: // ]]>
10421: </script>
10422:
10423: END
10424: }
10425:
1.661 raeburn 10426: sub upload_embedded {
10427: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10428: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10429: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10430: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10431: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10432: my $orig_uploaded_filename =
10433: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10434: foreach my $type ('orig','ref','attrib','codebase') {
10435: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10436: $env{'form.embedded_'.$type.'_'.$i} =
10437: &unescape($env{'form.embedded_'.$type.'_'.$i});
10438: }
10439: }
1.661 raeburn 10440: my ($path,$fname) =
10441: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10442: # no path, whole string is fname
10443: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10444: $fname = &Apache::lonnet::clean_filename($fname);
10445: # See if there is anything left
10446: next if ($fname eq '');
10447:
10448: # Check if file already exists as a file or directory.
10449: my ($state,$msg);
10450: if ($context eq 'portfolio') {
10451: my $port_path = $dirpath;
10452: if ($group ne '') {
10453: $port_path = "groups/$group/$port_path";
10454: }
1.987 raeburn 10455: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10456: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10457: $dir_root,$port_path,$disk_quota,
10458: $current_disk_usage,$uname,$udom);
10459: if ($state eq 'will_exceed_quota'
1.984 raeburn 10460: || $state eq 'file_locked') {
1.661 raeburn 10461: $output .= $msg;
10462: next;
10463: }
10464: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10465: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10466: if ($state eq 'exists') {
10467: $output .= $msg;
10468: next;
10469: }
10470: }
10471: # Check if extension is valid
10472: if (($fname =~ /\.(\w+)$/) &&
10473: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 10474: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
10475: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 10476: next;
10477: } elsif (($fname =~ /\.(\w+)$/) &&
10478: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10479: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10480: next;
10481: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 10482: $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 10483: next;
10484: }
10485: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 10486: my $subdir = $path;
10487: $subdir =~ s{/+$}{};
1.661 raeburn 10488: if ($context eq 'portfolio') {
1.984 raeburn 10489: my $result;
10490: if ($state eq 'existingfile') {
10491: $result=
10492: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 10493: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10494: } else {
1.984 raeburn 10495: $result=
10496: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10497: $dirpath.
1.1075.2.35 raeburn 10498: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10499: if ($result !~ m|^/uploaded/|) {
10500: $output .= '<span class="LC_error">'
10501: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10502: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10503: .'</span><br />';
10504: next;
10505: } else {
1.987 raeburn 10506: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10507: $path.$fname.'</span>').'<br />';
1.984 raeburn 10508: }
1.661 raeburn 10509: }
1.1075.2.35 raeburn 10510: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
10511: my $extendedsubdir = $dirpath.'/'.$subdir;
10512: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10513: my $result =
1.1075.2.35 raeburn 10514: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10515: if ($result !~ m|^/uploaded/|) {
10516: $output .= '<span class="LC_error">'
10517: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10518: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10519: .'</span><br />';
10520: next;
10521: } else {
10522: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10523: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 10524: if ($context eq 'syllabus') {
10525: &Apache::lonnet::make_public_indefinitely($result);
10526: }
1.987 raeburn 10527: }
1.661 raeburn 10528: } else {
10529: # Save the file
10530: my $target = $env{'form.embedded_item_'.$i};
10531: my $fullpath = $dir_root.$dirpath.'/'.$path;
10532: my $dest = $fullpath.$fname;
10533: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10534: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10535: my $count;
10536: my $filepath = $dir_root;
1.1027 raeburn 10537: foreach my $subdir (@parts) {
10538: $filepath .= "/$subdir";
10539: if (!-e $filepath) {
1.661 raeburn 10540: mkdir($filepath,0770);
10541: }
10542: }
10543: my $fh;
10544: if (!open($fh,'>'.$dest)) {
10545: &Apache::lonnet::logthis('Failed to create '.$dest);
10546: $output .= '<span class="LC_error">'.
1.1071 raeburn 10547: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10548: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10549: '</span><br />';
10550: } else {
10551: if (!print $fh $env{'form.embedded_item_'.$i}) {
10552: &Apache::lonnet::logthis('Failed to write to '.$dest);
10553: $output .= '<span class="LC_error">'.
1.1071 raeburn 10554: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10555: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10556: '</span><br />';
10557: } else {
1.987 raeburn 10558: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10559: $url.'</span>').'<br />';
10560: unless ($context eq 'testbank') {
10561: $footer .= &mt('View embedded file: [_1]',
10562: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10563: }
10564: }
10565: close($fh);
10566: }
10567: }
10568: if ($env{'form.embedded_ref_'.$i}) {
10569: $pathchange{$i} = 1;
10570: }
10571: }
10572: if ($output) {
10573: $output = '<p>'.$output.'</p>';
10574: }
10575: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10576: $returnflag = 'ok';
1.1071 raeburn 10577: my $numpathchgs = scalar(keys(%pathchange));
10578: if ($numpathchgs > 0) {
1.987 raeburn 10579: if ($context eq 'portfolio') {
10580: $output .= '<p>'.&mt('or').'</p>';
10581: } elsif ($context eq 'testbank') {
1.1071 raeburn 10582: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10583: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10584: $returnflag = 'modify_orightml';
10585: }
10586: }
1.1071 raeburn 10587: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10588: }
10589:
10590: sub modify_html_form {
10591: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10592: my $end = 0;
10593: my $modifyform;
10594: if ($context eq 'upload_embedded') {
10595: return unless (ref($pathchange) eq 'HASH');
10596: if ($env{'form.number_embedded_items'}) {
10597: $end += $env{'form.number_embedded_items'};
10598: }
10599: if ($env{'form.number_pathchange_items'}) {
10600: $end += $env{'form.number_pathchange_items'};
10601: }
10602: if ($end) {
10603: for (my $i=0; $i<$end; $i++) {
10604: if ($i < $env{'form.number_embedded_items'}) {
10605: next unless($pathchange->{$i});
10606: }
10607: $modifyform .=
10608: &start_data_table_row().
10609: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10610: 'checked="checked" /></td>'.
10611: '<td>'.$env{'form.embedded_ref_'.$i}.
10612: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10613: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10614: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10615: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10616: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10617: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10618: '<td>'.$env{'form.embedded_orig_'.$i}.
10619: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10620: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10621: &end_data_table_row();
1.1071 raeburn 10622: }
1.987 raeburn 10623: }
10624: } else {
10625: $modifyform = $pathchgtable;
10626: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10627: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10628: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10629: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10630: }
10631: }
10632: if ($modifyform) {
1.1071 raeburn 10633: if ($actionurl eq '/adm/dependencies') {
10634: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10635: }
1.987 raeburn 10636: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10637: '<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".
10638: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10639: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10640: '</ol></p>'."\n".'<p>'.
10641: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10642: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10643: &start_data_table()."\n".
10644: &start_data_table_header_row().
10645: '<th>'.&mt('Change?').'</th>'.
10646: '<th>'.&mt('Current reference').'</th>'.
10647: '<th>'.&mt('Required reference').'</th>'.
10648: &end_data_table_header_row()."\n".
10649: $modifyform.
10650: &end_data_table().'<br />'."\n".$hiddenstate.
10651: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10652: '</form>'."\n";
10653: }
10654: return;
10655: }
10656:
10657: sub modify_html_refs {
1.1075.2.35 raeburn 10658: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 10659: my $container;
10660: if ($context eq 'portfolio') {
10661: $container = $env{'form.container'};
10662: } elsif ($context eq 'coursedoc') {
10663: $container = $env{'form.primaryurl'};
1.1071 raeburn 10664: } elsif ($context eq 'manage_dependencies') {
10665: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10666: $container = "/$container";
1.1075.2.35 raeburn 10667: } elsif ($context eq 'syllabus') {
10668: $container = $url;
1.987 raeburn 10669: } else {
1.1027 raeburn 10670: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10671: }
10672: my (%allfiles,%codebase,$output,$content);
10673: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 10674: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 10675: if (wantarray) {
10676: return ('',0,0);
10677: } else {
10678: return;
10679: }
10680: }
10681: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10682: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 10683: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10684: if (wantarray) {
10685: return ('',0,0);
10686: } else {
10687: return;
10688: }
10689: }
1.987 raeburn 10690: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10691: if ($content eq '-1') {
10692: if (wantarray) {
10693: return ('',0,0);
10694: } else {
10695: return;
10696: }
10697: }
1.987 raeburn 10698: } else {
1.1071 raeburn 10699: unless ($container =~ /^\Q$dir_root\E/) {
10700: if (wantarray) {
10701: return ('',0,0);
10702: } else {
10703: return;
10704: }
10705: }
1.987 raeburn 10706: if (open(my $fh,"<$container")) {
10707: $content = join('', <$fh>);
10708: close($fh);
10709: } else {
1.1071 raeburn 10710: if (wantarray) {
10711: return ('',0,0);
10712: } else {
10713: return;
10714: }
1.987 raeburn 10715: }
10716: }
10717: my ($count,$codebasecount) = (0,0);
10718: my $mm = new File::MMagic;
10719: my $mime_type = $mm->checktype_contents($content);
10720: if ($mime_type eq 'text/html') {
10721: my $parse_result =
10722: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10723: \%codebase,\$content);
10724: if ($parse_result eq 'ok') {
10725: foreach my $i (@changes) {
10726: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10727: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10728: if ($allfiles{$ref}) {
10729: my $newname = $orig;
10730: my ($attrib_regexp,$codebase);
1.1006 raeburn 10731: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10732: if ($attrib_regexp =~ /:/) {
10733: $attrib_regexp =~ s/\:/|/g;
10734: }
10735: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10736: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10737: $count += $numchg;
1.1075.2.35 raeburn 10738: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 10739: delete($allfiles{$ref});
1.987 raeburn 10740: }
10741: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10742: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10743: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10744: $codebasecount ++;
10745: }
10746: }
10747: }
1.1075.2.35 raeburn 10748: my $skiprewrites;
1.987 raeburn 10749: if ($count || $codebasecount) {
10750: my $saveresult;
1.1071 raeburn 10751: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10752: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 10753: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10754: if ($url eq $container) {
10755: my ($fname) = ($container =~ m{/([^/]+)$});
10756: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10757: $count,'<span class="LC_filename">'.
1.1071 raeburn 10758: $fname.'</span>').'</p>';
1.987 raeburn 10759: } else {
10760: $output = '<p class="LC_error">'.
10761: &mt('Error: update failed for: [_1].',
10762: '<span class="LC_filename">'.
10763: $container.'</span>').'</p>';
10764: }
1.1075.2.35 raeburn 10765: if ($context eq 'syllabus') {
10766: unless ($saveresult eq 'ok') {
10767: $skiprewrites = 1;
10768: }
10769: }
1.987 raeburn 10770: } else {
10771: if (open(my $fh,">$container")) {
10772: print $fh $content;
10773: close($fh);
10774: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10775: $count,'<span class="LC_filename">'.
10776: $container.'</span>').'</p>';
1.661 raeburn 10777: } else {
1.987 raeburn 10778: $output = '<p class="LC_error">'.
10779: &mt('Error: could not update [_1].',
10780: '<span class="LC_filename">'.
10781: $container.'</span>').'</p>';
1.661 raeburn 10782: }
10783: }
10784: }
1.1075.2.35 raeburn 10785: if (($context eq 'syllabus') && (!$skiprewrites)) {
10786: my ($actionurl,$state);
10787: $actionurl = "/public/$udom/$uname/syllabus";
10788: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
10789: &ask_for_embedded_content($actionurl,$state,\%allfiles,
10790: \%codebase,
10791: {'context' => 'rewrites',
10792: 'ignore_remote_references' => 1,});
10793: if (ref($mapping) eq 'HASH') {
10794: my $rewrites = 0;
10795: foreach my $key (keys(%{$mapping})) {
10796: next if ($key =~ m{^https?://});
10797: my $ref = $mapping->{$key};
10798: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
10799: my $attrib;
10800: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
10801: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
10802: }
10803: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10804: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10805: $rewrites += $numchg;
10806: }
10807: }
10808: if ($rewrites) {
10809: my $saveresult;
10810: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10811: if ($url eq $container) {
10812: my ($fname) = ($container =~ m{/([^/]+)$});
10813: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
10814: $count,'<span class="LC_filename">'.
10815: $fname.'</span>').'</p>';
10816: } else {
10817: $output .= '<p class="LC_error">'.
10818: &mt('Error: could not update links in [_1].',
10819: '<span class="LC_filename">'.
10820: $container.'</span>').'</p>';
10821:
10822: }
10823: }
10824: }
10825: }
1.987 raeburn 10826: } else {
10827: &logthis('Failed to parse '.$container.
10828: ' to modify references: '.$parse_result);
1.661 raeburn 10829: }
10830: }
1.1071 raeburn 10831: if (wantarray) {
10832: return ($output,$count,$codebasecount);
10833: } else {
10834: return $output;
10835: }
1.661 raeburn 10836: }
10837:
10838: sub check_for_existing {
10839: my ($path,$fname,$element) = @_;
10840: my ($state,$msg);
10841: if (-d $path.'/'.$fname) {
10842: $state = 'exists';
10843: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10844: } elsif (-e $path.'/'.$fname) {
10845: $state = 'exists';
10846: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10847: }
10848: if ($state eq 'exists') {
10849: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10850: }
10851: return ($state,$msg);
10852: }
10853:
10854: sub check_for_upload {
10855: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10856: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10857: my $filesize = length($env{'form.'.$element});
10858: if (!$filesize) {
10859: my $msg = '<span class="LC_error">'.
10860: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10861: '<span class="LC_filename">'.$fname.'</span>',
10862: $filesize).'<br />'.
1.1007 raeburn 10863: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10864: '</span>';
10865: return ('zero_bytes',$msg);
10866: }
10867: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10868: my $getpropath = 1;
1.1021 raeburn 10869: my ($dirlistref,$listerror) =
10870: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10871: my $found_file = 0;
10872: my $locked_file = 0;
1.991 raeburn 10873: my @lockers;
10874: my $navmap;
10875: if ($env{'request.course.id'}) {
10876: $navmap = Apache::lonnavmaps::navmap->new();
10877: }
1.1021 raeburn 10878: if (ref($dirlistref) eq 'ARRAY') {
10879: foreach my $line (@{$dirlistref}) {
10880: my ($file_name,$rest)=split(/\&/,$line,2);
10881: if ($file_name eq $fname){
10882: $file_name = $path.$file_name;
10883: if ($group ne '') {
10884: $file_name = $group.$file_name;
10885: }
10886: $found_file = 1;
10887: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10888: foreach my $lock (@lockers) {
10889: if (ref($lock) eq 'ARRAY') {
10890: my ($symb,$crsid) = @{$lock};
10891: if ($crsid eq $env{'request.course.id'}) {
10892: if (ref($navmap)) {
10893: my $res = $navmap->getBySymb($symb);
10894: foreach my $part (@{$res->parts()}) {
10895: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10896: unless (($slot_status == $res->RESERVED) ||
10897: ($slot_status == $res->RESERVED_LOCATION)) {
10898: $locked_file = 1;
10899: }
1.991 raeburn 10900: }
1.1021 raeburn 10901: } else {
10902: $locked_file = 1;
1.991 raeburn 10903: }
10904: } else {
10905: $locked_file = 1;
10906: }
10907: }
1.1021 raeburn 10908: }
10909: } else {
10910: my @info = split(/\&/,$rest);
10911: my $currsize = $info[6]/1000;
10912: if ($currsize < $filesize) {
10913: my $extra = $filesize - $currsize;
10914: if (($current_disk_usage + $extra) > $disk_quota) {
10915: my $msg = '<span class="LC_error">'.
10916: &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.',
10917: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
10918: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10919: $disk_quota,$current_disk_usage);
10920: return ('will_exceed_quota',$msg);
10921: }
1.984 raeburn 10922: }
10923: }
1.661 raeburn 10924: }
10925: }
10926: }
10927: if (($current_disk_usage + $filesize) > $disk_quota){
10928: my $msg = '<span class="LC_error">'.
10929: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
10930: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
10931: return ('will_exceed_quota',$msg);
10932: } elsif ($found_file) {
10933: if ($locked_file) {
10934: my $msg = '<span class="LC_error">';
10935: $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>');
10936: $msg .= '</span><br />';
10937: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10938: return ('file_locked',$msg);
10939: } else {
10940: my $msg = '<span class="LC_error">';
1.984 raeburn 10941: $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.661 raeburn 10942: $msg .= '</span>';
1.984 raeburn 10943: return ('existingfile',$msg);
1.661 raeburn 10944: }
10945: }
10946: }
10947:
1.987 raeburn 10948: sub check_for_traversal {
10949: my ($path,$url,$toplevel) = @_;
10950: my @parts=split(/\//,$path);
10951: my $cleanpath;
10952: my $fullpath = $url;
10953: for (my $i=0;$i<@parts;$i++) {
10954: next if ($parts[$i] eq '.');
10955: if ($parts[$i] eq '..') {
10956: $fullpath =~ s{([^/]+/)$}{};
10957: } else {
10958: $fullpath .= $parts[$i].'/';
10959: }
10960: }
10961: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10962: $cleanpath = $1;
10963: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10964: my $curr_toprel = $1;
10965: my @parts = split(/\//,$curr_toprel);
10966: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10967: my @urlparts = split(/\//,$url_toprel);
10968: my $doubledots;
10969: my $startdiff = -1;
10970: for (my $i=0; $i<@urlparts; $i++) {
10971: if ($startdiff == -1) {
10972: unless ($urlparts[$i] eq $parts[$i]) {
10973: $startdiff = $i;
10974: $doubledots .= '../';
10975: }
10976: } else {
10977: $doubledots .= '../';
10978: }
10979: }
10980: if ($startdiff > -1) {
10981: $cleanpath = $doubledots;
10982: for (my $i=$startdiff; $i<@parts; $i++) {
10983: $cleanpath .= $parts[$i].'/';
10984: }
10985: }
10986: }
10987: $cleanpath =~ s{(/)$}{};
10988: return $cleanpath;
10989: }
1.31 albertel 10990:
1.1053 raeburn 10991: sub is_archive_file {
10992: my ($mimetype) = @_;
10993: if (($mimetype eq 'application/octet-stream') ||
10994: ($mimetype eq 'application/x-stuffit') ||
10995: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
10996: return 1;
10997: }
10998: return;
10999: }
11000:
11001: sub decompress_form {
1.1065 raeburn 11002: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11003: my %lt = &Apache::lonlocal::texthash (
11004: this => 'This file is an archive file.',
1.1067 raeburn 11005: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11006: itsc => 'Its contents are as follows:',
1.1053 raeburn 11007: youm => 'You may wish to extract its contents.',
11008: extr => 'Extract contents',
1.1067 raeburn 11009: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11010: proa => 'Process automatically?',
1.1053 raeburn 11011: yes => 'Yes',
11012: no => 'No',
1.1067 raeburn 11013: fold => 'Title for folder containing movie',
11014: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11015: );
1.1065 raeburn 11016: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11017: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11018: my $info = &list_archive_contents($fileloc,\@paths);
11019: if (@paths) {
11020: foreach my $path (@paths) {
11021: $path =~ s{^/}{};
1.1067 raeburn 11022: if ($path =~ m{^([^/]+)/$}) {
11023: $topdir = $1;
11024: }
1.1065 raeburn 11025: if ($path =~ m{^([^/]+)/}) {
11026: $toplevel{$1} = $path;
11027: } else {
11028: $toplevel{$path} = $path;
11029: }
11030: }
11031: }
1.1067 raeburn 11032: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 11033: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11034: "$topdir/media/",
11035: "$topdir/media/$topdir.mp4",
11036: "$topdir/media/FirstFrame.png",
11037: "$topdir/media/player.swf",
11038: "$topdir/media/swfobject.js",
11039: "$topdir/media/expressInstall.swf");
1.1075.2.59 raeburn 11040: my @camtasia8 = ("$topdir/","$topdir/$topdir.html",
11041: "$topdir/$topdir.mp4",
11042: "$topdir/$topdir\_config.xml",
11043: "$topdir/$topdir\_controller.swf",
11044: "$topdir/$topdir\_embed.css",
11045: "$topdir/$topdir\_First_Frame.png",
11046: "$topdir/$topdir\_player.html",
11047: "$topdir/$topdir\_Thumbnails.png",
11048: "$topdir/playerProductInstall.swf",
11049: "$topdir/scripts/",
11050: "$topdir/scripts/config_xml.js",
11051: "$topdir/scripts/handlebars.js",
11052: "$topdir/scripts/jquery-1.7.1.min.js",
11053: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11054: "$topdir/scripts/modernizr.js",
11055: "$topdir/scripts/player-min.js",
11056: "$topdir/scripts/swfobject.js",
11057: "$topdir/skins/",
11058: "$topdir/skins/configuration_express.xml",
11059: "$topdir/skins/express_show/",
11060: "$topdir/skins/express_show/player-min.css",
11061: "$topdir/skins/express_show/spritesheet.png");
11062: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11063: if (@diffs == 0) {
1.1075.2.59 raeburn 11064: $is_camtasia = 6;
11065: } else {
11066: @diffs = &compare_arrays(\@paths,\@camtasia8);
11067: if (@diffs == 0) {
11068: $is_camtasia = 8;
11069: }
1.1067 raeburn 11070: }
11071: }
11072: my $output;
11073: if ($is_camtasia) {
11074: $output = <<"ENDCAM";
11075: <script type="text/javascript" language="Javascript">
11076: // <![CDATA[
11077:
11078: function camtasiaToggle() {
11079: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11080: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 11081: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11082: document.getElementById('camtasia_titles').style.display='block';
11083: } else {
11084: document.getElementById('camtasia_titles').style.display='none';
11085: }
11086: }
11087: }
11088: return;
11089: }
11090:
11091: // ]]>
11092: </script>
11093: <p>$lt{'camt'}</p>
11094: ENDCAM
1.1065 raeburn 11095: } else {
1.1067 raeburn 11096: $output = '<p>'.$lt{'this'};
11097: if ($info eq '') {
11098: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11099: } else {
11100: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11101: '<div><pre>'.$info.'</pre></div>';
11102: }
1.1065 raeburn 11103: }
1.1067 raeburn 11104: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11105: my $duplicates;
11106: my $num = 0;
11107: if (ref($dirlist) eq 'ARRAY') {
11108: foreach my $item (@{$dirlist}) {
11109: if (ref($item) eq 'ARRAY') {
11110: if (exists($toplevel{$item->[0]})) {
11111: $duplicates .=
11112: &start_data_table_row().
11113: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11114: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11115: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11116: 'value="1" />'.&mt('Yes').'</label>'.
11117: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11118: '<td>'.$item->[0].'</td>';
11119: if ($item->[2]) {
11120: $duplicates .= '<td>'.&mt('Directory').'</td>';
11121: } else {
11122: $duplicates .= '<td>'.&mt('File').'</td>';
11123: }
11124: $duplicates .= '<td>'.$item->[3].'</td>'.
11125: '<td>'.
11126: &Apache::lonlocal::locallocaltime($item->[4]).
11127: '</td>'.
11128: &end_data_table_row();
11129: $num ++;
11130: }
11131: }
11132: }
11133: }
11134: my $itemcount;
11135: if (@paths > 0) {
11136: $itemcount = scalar(@paths);
11137: } else {
11138: $itemcount = 1;
11139: }
1.1067 raeburn 11140: if ($is_camtasia) {
11141: $output .= $lt{'auto'}.'<br />'.
11142: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 11143: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11144: $lt{'yes'}.'</label> <label>'.
11145: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11146: $lt{'no'}.'</label></span><br />'.
11147: '<div id="camtasia_titles" style="display:block">'.
11148: &Apache::lonhtmlcommon::start_pick_box().
11149: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11150: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11151: &Apache::lonhtmlcommon::row_closure().
11152: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11153: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11154: &Apache::lonhtmlcommon::row_closure(1).
11155: &Apache::lonhtmlcommon::end_pick_box().
11156: '</div>';
11157: }
1.1065 raeburn 11158: $output .=
11159: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11160: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11161: "\n";
1.1065 raeburn 11162: if ($duplicates ne '') {
11163: $output .= '<p><span class="LC_warning">'.
11164: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11165: &start_data_table().
11166: &start_data_table_header_row().
11167: '<th>'.&mt('Overwrite?').'</th>'.
11168: '<th>'.&mt('Name').'</th>'.
11169: '<th>'.&mt('Type').'</th>'.
11170: '<th>'.&mt('Size').'</th>'.
11171: '<th>'.&mt('Last modified').'</th>'.
11172: &end_data_table_header_row().
11173: $duplicates.
11174: &end_data_table().
11175: '</p>';
11176: }
1.1067 raeburn 11177: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11178: if (ref($hiddenelements) eq 'HASH') {
11179: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11180: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11181: }
11182: }
11183: $output .= <<"END";
1.1067 raeburn 11184: <br />
1.1053 raeburn 11185: <input type="submit" name="decompress" value="$lt{'extr'}" />
11186: </form>
11187: $noextract
11188: END
11189: return $output;
11190: }
11191:
1.1065 raeburn 11192: sub decompression_utility {
11193: my ($program) = @_;
11194: my @utilities = ('tar','gunzip','bunzip2','unzip');
11195: my $location;
11196: if (grep(/^\Q$program\E$/,@utilities)) {
11197: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11198: '/usr/sbin/') {
11199: if (-x $dir.$program) {
11200: $location = $dir.$program;
11201: last;
11202: }
11203: }
11204: }
11205: return $location;
11206: }
11207:
11208: sub list_archive_contents {
11209: my ($file,$pathsref) = @_;
11210: my (@cmd,$output);
11211: my $needsregexp;
11212: if ($file =~ /\.zip$/) {
11213: @cmd = (&decompression_utility('unzip'),"-l");
11214: $needsregexp = 1;
11215: } elsif (($file =~ m/\.tar\.gz$/) ||
11216: ($file =~ /\.tgz$/)) {
11217: @cmd = (&decompression_utility('tar'),"-ztf");
11218: } elsif ($file =~ /\.tar\.bz2$/) {
11219: @cmd = (&decompression_utility('tar'),"-jtf");
11220: } elsif ($file =~ m|\.tar$|) {
11221: @cmd = (&decompression_utility('tar'),"-tf");
11222: }
11223: if (@cmd) {
11224: undef($!);
11225: undef($@);
11226: if (open(my $fh,"-|", @cmd, $file)) {
11227: while (my $line = <$fh>) {
11228: $output .= $line;
11229: chomp($line);
11230: my $item;
11231: if ($needsregexp) {
11232: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11233: } else {
11234: $item = $line;
11235: }
11236: if ($item ne '') {
11237: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11238: push(@{$pathsref},$item);
11239: }
11240: }
11241: }
11242: close($fh);
11243: }
11244: }
11245: return $output;
11246: }
11247:
1.1053 raeburn 11248: sub decompress_uploaded_file {
11249: my ($file,$dir) = @_;
11250: &Apache::lonnet::appenv({'cgi.file' => $file});
11251: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11252: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11253: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11254: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11255: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11256: my $decompressed = $env{'cgi.decompressed'};
11257: &Apache::lonnet::delenv('cgi.file');
11258: &Apache::lonnet::delenv('cgi.dir');
11259: &Apache::lonnet::delenv('cgi.decompressed');
11260: return ($decompressed,$result);
11261: }
11262:
1.1055 raeburn 11263: sub process_decompression {
11264: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11265: my ($dir,$error,$warning,$output);
11266: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
1.1075.2.34 raeburn 11267: $error = &mt('Filename not a supported archive file type.').
11268: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11269: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11270: } else {
11271: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11272: if ($docuhome eq 'no_host') {
11273: $error = &mt('Could not determine home server for course.');
11274: } else {
11275: my @ids=&Apache::lonnet::current_machine_ids();
11276: my $currdir = "$dir_root/$destination";
11277: if (grep(/^\Q$docuhome\E$/,@ids)) {
11278: $dir = &LONCAPA::propath($docudom,$docuname).
11279: "$dir_root/$destination";
11280: } else {
11281: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11282: "$dir_root/$docudom/$docuname/$destination";
11283: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11284: $error = &mt('Archive file not found.');
11285: }
11286: }
1.1065 raeburn 11287: my (@to_overwrite,@to_skip);
11288: if ($env{'form.archive_overwrite_total'} > 0) {
11289: my $total = $env{'form.archive_overwrite_total'};
11290: for (my $i=0; $i<$total; $i++) {
11291: if ($env{'form.archive_overwrite_'.$i} == 1) {
11292: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11293: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11294: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11295: }
11296: }
11297: }
11298: my $numskip = scalar(@to_skip);
11299: if (($numskip > 0) &&
11300: ($numskip == $env{'form.archive_itemcount'})) {
11301: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11302: } elsif ($dir eq '') {
1.1055 raeburn 11303: $error = &mt('Directory containing archive file unavailable.');
11304: } elsif (!$error) {
1.1065 raeburn 11305: my ($decompressed,$display);
11306: if ($numskip > 0) {
11307: my $tempdir = time.'_'.$$.int(rand(10000));
11308: mkdir("$dir/$tempdir",0755);
11309: system("mv $dir/$file $dir/$tempdir/$file");
11310: ($decompressed,$display) =
11311: &decompress_uploaded_file($file,"$dir/$tempdir");
11312: foreach my $item (@to_skip) {
11313: if (($item ne '') && ($item !~ /\.\./)) {
11314: if (-f "$dir/$tempdir/$item") {
11315: unlink("$dir/$tempdir/$item");
11316: } elsif (-d "$dir/$tempdir/$item") {
11317: system("rm -rf $dir/$tempdir/$item");
11318: }
11319: }
11320: }
11321: system("mv $dir/$tempdir/* $dir");
11322: rmdir("$dir/$tempdir");
11323: } else {
11324: ($decompressed,$display) =
11325: &decompress_uploaded_file($file,$dir);
11326: }
1.1055 raeburn 11327: if ($decompressed eq 'ok') {
1.1065 raeburn 11328: $output = '<p class="LC_info">'.
11329: &mt('Files extracted successfully from archive.').
11330: '</p>'."\n";
1.1055 raeburn 11331: my ($warning,$result,@contents);
11332: my ($newdirlistref,$newlisterror) =
11333: &Apache::lonnet::dirlist($currdir,$docudom,
11334: $docuname,1);
11335: my (%is_dir,%changes,@newitems);
11336: my $dirptr = 16384;
1.1065 raeburn 11337: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11338: foreach my $dir_line (@{$newdirlistref}) {
11339: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11340: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11341: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11342: push(@newitems,$item);
11343: if ($dirptr&$testdir) {
11344: $is_dir{$item} = 1;
11345: }
11346: $changes{$item} = 1;
11347: }
11348: }
11349: }
11350: if (keys(%changes) > 0) {
11351: foreach my $item (sort(@newitems)) {
11352: if ($changes{$item}) {
11353: push(@contents,$item);
11354: }
11355: }
11356: }
11357: if (@contents > 0) {
1.1067 raeburn 11358: my $wantform;
11359: unless ($env{'form.autoextract_camtasia'}) {
11360: $wantform = 1;
11361: }
1.1056 raeburn 11362: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11363: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11364: $currdir,\%is_dir,
11365: \%children,\%parent,
1.1056 raeburn 11366: \@contents,\%dirorder,
11367: \%titles,$wantform);
1.1055 raeburn 11368: if ($datatable ne '') {
11369: $output .= &archive_options_form('decompressed',$datatable,
11370: $count,$hiddenelem);
1.1065 raeburn 11371: my $startcount = 6;
1.1055 raeburn 11372: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11373: \%titles,\%children);
1.1055 raeburn 11374: }
1.1067 raeburn 11375: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 11376: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 11377: my %displayed;
11378: my $total = 1;
11379: $env{'form.archive_directory'} = [];
11380: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11381: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11382: $path =~ s{/$}{};
11383: my $item;
11384: if ($path ne '') {
11385: $item = "$path/$titles{$i}";
11386: } else {
11387: $item = $titles{$i};
11388: }
11389: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11390: if ($item eq $contents[0]) {
11391: push(@{$env{'form.archive_directory'}},$i);
11392: $env{'form.archive_'.$i} = 'display';
11393: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11394: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 11395: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
11396: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 11397: $env{'form.archive_'.$i} = 'display';
11398: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11399: $displayed{'web'} = $i;
11400: } else {
1.1075.2.59 raeburn 11401: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
11402: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
11403: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 11404: push(@{$env{'form.archive_directory'}},$i);
11405: }
11406: $env{'form.archive_'.$i} = 'dependency';
11407: }
11408: $total ++;
11409: }
11410: for (my $i=1; $i<$total; $i++) {
11411: next if ($i == $displayed{'web'});
11412: next if ($i == $displayed{'folder'});
11413: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11414: }
11415: $env{'form.phase'} = 'decompress_cleanup';
11416: $env{'form.archivedelete'} = 1;
11417: $env{'form.archive_count'} = $total-1;
11418: $output .=
11419: &process_extracted_files('coursedocs',$docudom,
11420: $docuname,$destination,
11421: $dir_root,$hiddenelem);
11422: }
1.1055 raeburn 11423: } else {
11424: $warning = &mt('No new items extracted from archive file.');
11425: }
11426: } else {
11427: $output = $display;
11428: $error = &mt('An error occurred during extraction from the archive file.');
11429: }
11430: }
11431: }
11432: }
11433: if ($error) {
11434: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11435: $error.'</p>'."\n";
11436: }
11437: if ($warning) {
11438: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11439: }
11440: return $output;
11441: }
11442:
11443: sub get_extracted {
1.1056 raeburn 11444: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11445: $titles,$wantform) = @_;
1.1055 raeburn 11446: my $count = 0;
11447: my $depth = 0;
11448: my $datatable;
1.1056 raeburn 11449: my @hierarchy;
1.1055 raeburn 11450: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11451: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11452: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11453: foreach my $item (@{$contents}) {
11454: $count ++;
1.1056 raeburn 11455: @{$dirorder->{$count}} = @hierarchy;
11456: $titles->{$count} = $item;
1.1055 raeburn 11457: &archive_hierarchy($depth,$count,$parent,$children);
11458: if ($wantform) {
11459: $datatable .= &archive_row($is_dir->{$item},$item,
11460: $currdir,$depth,$count);
11461: }
11462: if ($is_dir->{$item}) {
11463: $depth ++;
1.1056 raeburn 11464: push(@hierarchy,$count);
11465: $parent->{$depth} = $count;
1.1055 raeburn 11466: $datatable .=
11467: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11468: \$depth,\$count,\@hierarchy,$dirorder,
11469: $children,$parent,$titles,$wantform);
1.1055 raeburn 11470: $depth --;
1.1056 raeburn 11471: pop(@hierarchy);
1.1055 raeburn 11472: }
11473: }
11474: return ($count,$datatable);
11475: }
11476:
11477: sub recurse_extracted_archive {
1.1056 raeburn 11478: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11479: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11480: my $result='';
1.1056 raeburn 11481: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11482: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11483: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11484: return $result;
11485: }
11486: my $dirptr = 16384;
11487: my ($newdirlistref,$newlisterror) =
11488: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11489: if (ref($newdirlistref) eq 'ARRAY') {
11490: foreach my $dir_line (@{$newdirlistref}) {
11491: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11492: unless ($item =~ /^\.+$/) {
11493: $$count ++;
1.1056 raeburn 11494: @{$dirorder->{$$count}} = @{$hierarchy};
11495: $titles->{$$count} = $item;
1.1055 raeburn 11496: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11497:
1.1055 raeburn 11498: my $is_dir;
11499: if ($dirptr&$testdir) {
11500: $is_dir = 1;
11501: }
11502: if ($wantform) {
11503: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11504: }
11505: if ($is_dir) {
11506: $$depth ++;
1.1056 raeburn 11507: push(@{$hierarchy},$$count);
11508: $parent->{$$depth} = $$count;
1.1055 raeburn 11509: $result .=
11510: &recurse_extracted_archive("$currdir/$item",$docudom,
11511: $docuname,$depth,$count,
1.1056 raeburn 11512: $hierarchy,$dirorder,$children,
11513: $parent,$titles,$wantform);
1.1055 raeburn 11514: $$depth --;
1.1056 raeburn 11515: pop(@{$hierarchy});
1.1055 raeburn 11516: }
11517: }
11518: }
11519: }
11520: return $result;
11521: }
11522:
11523: sub archive_hierarchy {
11524: my ($depth,$count,$parent,$children) =@_;
11525: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11526: if (exists($parent->{$depth})) {
11527: $children->{$parent->{$depth}} .= $count.':';
11528: }
11529: }
11530: return;
11531: }
11532:
11533: sub archive_row {
11534: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11535: my ($name) = ($item =~ m{([^/]+)$});
11536: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11537: 'display' => 'Add as file',
1.1055 raeburn 11538: 'dependency' => 'Include as dependency',
11539: 'discard' => 'Discard',
11540: );
11541: if ($is_dir) {
1.1059 raeburn 11542: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11543: }
1.1056 raeburn 11544: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11545: my $offset = 0;
1.1055 raeburn 11546: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11547: $offset ++;
1.1065 raeburn 11548: if ($action ne 'display') {
11549: $offset ++;
11550: }
1.1055 raeburn 11551: $output .= '<td><span class="LC_nobreak">'.
11552: '<label><input type="radio" name="archive_'.$count.
11553: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11554: my $text = $choices{$action};
11555: if ($is_dir) {
11556: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11557: if ($action eq 'display') {
1.1059 raeburn 11558: $text = &mt('Add as folder');
1.1055 raeburn 11559: }
1.1056 raeburn 11560: } else {
11561: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11562:
11563: }
11564: $output .= ' /> '.$choices{$action}.'</label></span>';
11565: if ($action eq 'dependency') {
11566: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11567: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11568: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11569: '<option value=""></option>'."\n".
11570: '</select>'."\n".
11571: '</div>';
1.1059 raeburn 11572: } elsif ($action eq 'display') {
11573: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11574: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11575: '</div>';
1.1055 raeburn 11576: }
1.1056 raeburn 11577: $output .= '</td>';
1.1055 raeburn 11578: }
11579: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11580: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11581: for (my $i=0; $i<$depth; $i++) {
11582: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11583: }
11584: if ($is_dir) {
11585: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11586: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11587: } else {
11588: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11589: }
11590: $output .= ' '.$name.'</td>'."\n".
11591: &end_data_table_row();
11592: return $output;
11593: }
11594:
11595: sub archive_options_form {
1.1065 raeburn 11596: my ($form,$display,$count,$hiddenelem) = @_;
11597: my %lt = &Apache::lonlocal::texthash(
11598: perm => 'Permanently remove archive file?',
11599: hows => 'How should each extracted item be incorporated in the course?',
11600: cont => 'Content actions for all',
11601: addf => 'Add as folder/file',
11602: incd => 'Include as dependency for a displayed file',
11603: disc => 'Discard',
11604: no => 'No',
11605: yes => 'Yes',
11606: save => 'Save',
11607: );
11608: my $output = <<"END";
11609: <form name="$form" method="post" action="">
11610: <p><span class="LC_nobreak">$lt{'perm'}
11611: <label>
11612: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11613: </label>
11614:
11615: <label>
11616: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11617: </span>
11618: </p>
11619: <input type="hidden" name="phase" value="decompress_cleanup" />
11620: <br />$lt{'hows'}
11621: <div class="LC_columnSection">
11622: <fieldset>
11623: <legend>$lt{'cont'}</legend>
11624: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11625: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11626: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11627: </fieldset>
11628: </div>
11629: END
11630: return $output.
1.1055 raeburn 11631: &start_data_table()."\n".
1.1065 raeburn 11632: $display."\n".
1.1055 raeburn 11633: &end_data_table()."\n".
11634: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11635: $hiddenelem.
1.1065 raeburn 11636: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11637: '</form>';
11638: }
11639:
11640: sub archive_javascript {
1.1056 raeburn 11641: my ($startcount,$numitems,$titles,$children) = @_;
11642: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11643: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11644: my $scripttag = <<START;
11645: <script type="text/javascript">
11646: // <![CDATA[
11647:
11648: function checkAll(form,prefix) {
11649: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11650: for (var i=0; i < form.elements.length; i++) {
11651: var id = form.elements[i].id;
11652: if ((id != '') && (id != undefined)) {
11653: if (idstr.test(id)) {
11654: if (form.elements[i].type == 'radio') {
11655: form.elements[i].checked = true;
1.1056 raeburn 11656: var nostart = i-$startcount;
1.1059 raeburn 11657: var offset = nostart%7;
11658: var count = (nostart-offset)/7;
1.1056 raeburn 11659: dependencyCheck(form,count,offset);
1.1055 raeburn 11660: }
11661: }
11662: }
11663: }
11664: }
11665:
11666: function propagateCheck(form,count) {
11667: if (count > 0) {
1.1059 raeburn 11668: var startelement = $startcount + ((count-1) * 7);
11669: for (var j=1; j<6; j++) {
11670: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11671: var item = startelement + j;
11672: if (form.elements[item].type == 'radio') {
11673: if (form.elements[item].checked) {
11674: containerCheck(form,count,j);
11675: break;
11676: }
1.1055 raeburn 11677: }
11678: }
11679: }
11680: }
11681: }
11682:
11683: numitems = $numitems
1.1056 raeburn 11684: var titles = new Array(numitems);
11685: var parents = new Array(numitems);
1.1055 raeburn 11686: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11687: parents[i] = new Array;
1.1055 raeburn 11688: }
1.1059 raeburn 11689: var maintitle = '$maintitle';
1.1055 raeburn 11690:
11691: START
11692:
1.1056 raeburn 11693: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11694: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11695: for (my $i=0; $i<@contents; $i ++) {
11696: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11697: }
11698: }
11699:
1.1056 raeburn 11700: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11701: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11702: }
11703:
1.1055 raeburn 11704: $scripttag .= <<END;
11705:
11706: function containerCheck(form,count,offset) {
11707: if (count > 0) {
1.1056 raeburn 11708: dependencyCheck(form,count,offset);
1.1059 raeburn 11709: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11710: form.elements[item].checked = true;
11711: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11712: if (parents[count].length > 0) {
11713: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11714: containerCheck(form,parents[count][j],offset);
11715: }
11716: }
11717: }
11718: }
11719: }
11720:
11721: function dependencyCheck(form,count,offset) {
11722: if (count > 0) {
1.1059 raeburn 11723: var chosen = (offset+$startcount)+7*(count-1);
11724: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11725: var currtype = form.elements[depitem].type;
11726: if (form.elements[chosen].value == 'dependency') {
11727: document.getElementById('arc_depon_'+count).style.display='block';
11728: form.elements[depitem].options.length = 0;
11729: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 11730: for (var i=1; i<=numitems; i++) {
11731: if (i == count) {
11732: continue;
11733: }
1.1059 raeburn 11734: var startelement = $startcount + (i-1) * 7;
11735: for (var j=1; j<6; j++) {
11736: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11737: var item = startelement + j;
11738: if (form.elements[item].type == 'radio') {
11739: if (form.elements[item].checked) {
11740: if (form.elements[item].value == 'display') {
11741: var n = form.elements[depitem].options.length;
11742: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11743: }
11744: }
11745: }
11746: }
11747: }
11748: }
11749: } else {
11750: document.getElementById('arc_depon_'+count).style.display='none';
11751: form.elements[depitem].options.length = 0;
11752: form.elements[depitem].options[0] = new Option('Select','',true,true);
11753: }
1.1059 raeburn 11754: titleCheck(form,count,offset);
1.1056 raeburn 11755: }
11756: }
11757:
11758: function propagateSelect(form,count,offset) {
11759: if (count > 0) {
1.1065 raeburn 11760: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11761: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11762: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11763: if (parents[count].length > 0) {
11764: for (var j=0; j<parents[count].length; j++) {
11765: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11766: }
11767: }
11768: }
11769: }
11770: }
1.1056 raeburn 11771:
11772: function containerSelect(form,count,offset,picked) {
11773: if (count > 0) {
1.1065 raeburn 11774: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11775: if (form.elements[item].type == 'radio') {
11776: if (form.elements[item].value == 'dependency') {
11777: if (form.elements[item+1].type == 'select-one') {
11778: for (var i=0; i<form.elements[item+1].options.length; i++) {
11779: if (form.elements[item+1].options[i].value == picked) {
11780: form.elements[item+1].selectedIndex = i;
11781: break;
11782: }
11783: }
11784: }
11785: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11786: if (parents[count].length > 0) {
11787: for (var j=0; j<parents[count].length; j++) {
11788: containerSelect(form,parents[count][j],offset,picked);
11789: }
11790: }
11791: }
11792: }
11793: }
11794: }
11795: }
11796:
1.1059 raeburn 11797: function titleCheck(form,count,offset) {
11798: if (count > 0) {
11799: var chosen = (offset+$startcount)+7*(count-1);
11800: var depitem = $startcount + ((count-1) * 7) + 2;
11801: var currtype = form.elements[depitem].type;
11802: if (form.elements[chosen].value == 'display') {
11803: document.getElementById('arc_title_'+count).style.display='block';
11804: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11805: document.getElementById('archive_title_'+count).value=maintitle;
11806: }
11807: } else {
11808: document.getElementById('arc_title_'+count).style.display='none';
11809: if (currtype == 'text') {
11810: document.getElementById('archive_title_'+count).value='';
11811: }
11812: }
11813: }
11814: return;
11815: }
11816:
1.1055 raeburn 11817: // ]]>
11818: </script>
11819: END
11820: return $scripttag;
11821: }
11822:
11823: sub process_extracted_files {
1.1067 raeburn 11824: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11825: my $numitems = $env{'form.archive_count'};
11826: return unless ($numitems);
11827: my @ids=&Apache::lonnet::current_machine_ids();
11828: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11829: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11830: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11831: if (grep(/^\Q$docuhome\E$/,@ids)) {
11832: $prefix = &LONCAPA::propath($docudom,$docuname);
11833: $pathtocheck = "$dir_root/$destination";
11834: $dir = $dir_root;
11835: $ishome = 1;
11836: } else {
11837: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11838: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11839: $dir = "$dir_root/$docudom/$docuname";
11840: }
11841: my $currdir = "$dir_root/$destination";
11842: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11843: if ($env{'form.folderpath'}) {
11844: my @items = split('&',$env{'form.folderpath'});
11845: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 11846: if ($env{'form.folderpath'} =~ /\:1$/) {
11847: $containers{'0'}='page';
11848: } else {
11849: $containers{'0'}='sequence';
11850: }
1.1055 raeburn 11851: }
11852: my @archdirs = &get_env_multiple('form.archive_directory');
11853: if ($numitems) {
11854: for (my $i=1; $i<=$numitems; $i++) {
11855: my $path = $env{'form.archive_content_'.$i};
11856: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11857: my $item = $1;
11858: $toplevelitems{$item} = $i;
11859: if (grep(/^\Q$i\E$/,@archdirs)) {
11860: $is_dir{$item} = 1;
11861: }
11862: }
11863: }
11864: }
1.1067 raeburn 11865: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11866: if (keys(%toplevelitems) > 0) {
11867: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11868: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11869: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11870: }
1.1066 raeburn 11871: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11872: if ($numitems) {
11873: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 11874: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11875: my $path = $env{'form.archive_content_'.$i};
11876: if ($path =~ /^\Q$pathtocheck\E/) {
11877: if ($env{'form.archive_'.$i} eq 'discard') {
11878: if ($prefix ne '' && $path ne '') {
11879: if (-e $prefix.$path) {
1.1066 raeburn 11880: if ((@archdirs > 0) &&
11881: (grep(/^\Q$i\E$/,@archdirs))) {
11882: $todeletedir{$prefix.$path} = 1;
11883: } else {
11884: $todelete{$prefix.$path} = 1;
11885: }
1.1055 raeburn 11886: }
11887: }
11888: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11889: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11890: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11891: $docstitle = $env{'form.archive_title_'.$i};
11892: if ($docstitle eq '') {
11893: $docstitle = $title;
11894: }
1.1055 raeburn 11895: $outer = 0;
1.1056 raeburn 11896: if (ref($dirorder{$i}) eq 'ARRAY') {
11897: if (@{$dirorder{$i}} > 0) {
11898: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11899: if ($env{'form.archive_'.$item} eq 'display') {
11900: $outer = $item;
11901: last;
11902: }
11903: }
11904: }
11905: }
11906: my ($errtext,$fatal) =
11907: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11908: '/'.$folders{$outer}.'.'.
11909: $containers{$outer});
11910: next if ($fatal);
11911: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11912: if ($context eq 'coursedocs') {
1.1056 raeburn 11913: $mapinner{$i} = time;
1.1055 raeburn 11914: $folders{$i} = 'default_'.$mapinner{$i};
11915: $containers{$i} = 'sequence';
11916: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11917: $folders{$i}.'.'.$containers{$i};
11918: my $newidx = &LONCAPA::map::getresidx();
11919: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11920: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11921: push(@LONCAPA::map::order,$newidx);
11922: my ($outtext,$errtext) =
11923: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11924: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11925: '.'.$containers{$outer},1,1);
1.1056 raeburn 11926: $newseqid{$i} = $newidx;
1.1067 raeburn 11927: unless ($errtext) {
11928: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11929: }
1.1055 raeburn 11930: }
11931: } else {
11932: if ($context eq 'coursedocs') {
11933: my $newidx=&LONCAPA::map::getresidx();
11934: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11935: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11936: $title;
11937: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11938: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11939: }
11940: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11941: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11942: }
11943: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11944: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11945: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11946: unless ($ishome) {
11947: my $fetch = "$newdest{$i}/$title";
11948: $fetch =~ s/^\Q$prefix$dir\E//;
11949: $prompttofetch{$fetch} = 1;
11950: }
1.1055 raeburn 11951: }
11952: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11953: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11954: push(@LONCAPA::map::order, $newidx);
11955: my ($outtext,$errtext)=
11956: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11957: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11958: '.'.$containers{$outer},1,1);
1.1067 raeburn 11959: unless ($errtext) {
11960: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11961: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11962: }
11963: }
1.1055 raeburn 11964: }
11965: }
1.1075.2.11 raeburn 11966: }
11967: } else {
11968: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11969: }
11970: }
11971: for (my $i=1; $i<=$numitems; $i++) {
11972: next unless ($env{'form.archive_'.$i} eq 'dependency');
11973: my $path = $env{'form.archive_content_'.$i};
11974: if ($path =~ /^\Q$pathtocheck\E/) {
11975: my ($title) = ($path =~ m{/([^/]+)$});
11976: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
11977: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
11978: if (ref($dirorder{$i}) eq 'ARRAY') {
11979: my ($itemidx,$fullpath,$relpath);
11980: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
11981: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 11982: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 11983: if ($dirorder{$i}->[$j] eq $container) {
11984: $itemidx = $j;
1.1056 raeburn 11985: }
11986: }
1.1075.2.11 raeburn 11987: }
11988: if ($itemidx eq '') {
11989: $itemidx = 0;
11990: }
11991: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
11992: if ($mapinner{$referrer{$i}}) {
11993: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
11994: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11995: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11996: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11997: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11998: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11999: if (!-e $fullpath) {
12000: mkdir($fullpath,0755);
1.1056 raeburn 12001: }
12002: }
1.1075.2.11 raeburn 12003: } else {
12004: last;
1.1056 raeburn 12005: }
1.1075.2.11 raeburn 12006: }
12007: }
12008: } elsif ($newdest{$referrer{$i}}) {
12009: $fullpath = $newdest{$referrer{$i}};
12010: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12011: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12012: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12013: last;
12014: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12015: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12016: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12017: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12018: if (!-e $fullpath) {
12019: mkdir($fullpath,0755);
1.1056 raeburn 12020: }
12021: }
1.1075.2.11 raeburn 12022: } else {
12023: last;
1.1056 raeburn 12024: }
1.1075.2.11 raeburn 12025: }
12026: }
12027: if ($fullpath ne '') {
12028: if (-e "$prefix$path") {
12029: system("mv $prefix$path $fullpath/$title");
12030: }
12031: if (-e "$fullpath/$title") {
12032: my $showpath;
12033: if ($relpath ne '') {
12034: $showpath = "$relpath/$title";
12035: } else {
12036: $showpath = "/$title";
1.1056 raeburn 12037: }
1.1075.2.11 raeburn 12038: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12039: }
12040: unless ($ishome) {
12041: my $fetch = "$fullpath/$title";
12042: $fetch =~ s/^\Q$prefix$dir\E//;
12043: $prompttofetch{$fetch} = 1;
1.1055 raeburn 12044: }
12045: }
12046: }
1.1075.2.11 raeburn 12047: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12048: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12049: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12050: }
12051: } else {
1.1075.2.11 raeburn 12052: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055 raeburn 12053: }
12054: }
12055: if (keys(%todelete)) {
12056: foreach my $key (keys(%todelete)) {
12057: unlink($key);
1.1066 raeburn 12058: }
12059: }
12060: if (keys(%todeletedir)) {
12061: foreach my $key (keys(%todeletedir)) {
12062: rmdir($key);
12063: }
12064: }
12065: foreach my $dir (sort(keys(%is_dir))) {
12066: if (($pathtocheck ne '') && ($dir ne '')) {
12067: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12068: }
12069: }
1.1067 raeburn 12070: if ($result ne '') {
12071: $output .= '<ul>'."\n".
12072: $result."\n".
12073: '</ul>';
12074: }
12075: unless ($ishome) {
12076: my $replicationfail;
12077: foreach my $item (keys(%prompttofetch)) {
12078: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12079: unless ($fetchresult eq 'ok') {
12080: $replicationfail .= '<li>'.$item.'</li>'."\n";
12081: }
12082: }
12083: if ($replicationfail) {
12084: $output .= '<p class="LC_error">'.
12085: &mt('Course home server failed to retrieve:').'<ul>'.
12086: $replicationfail.
12087: '</ul></p>';
12088: }
12089: }
1.1055 raeburn 12090: } else {
12091: $warning = &mt('No items found in archive.');
12092: }
12093: if ($error) {
12094: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12095: $error.'</p>'."\n";
12096: }
12097: if ($warning) {
12098: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12099: }
12100: return $output;
12101: }
12102:
1.1066 raeburn 12103: sub cleanup_empty_dirs {
12104: my ($path) = @_;
12105: if (($path ne '') && (-d $path)) {
12106: if (opendir(my $dirh,$path)) {
12107: my @dircontents = grep(!/^\./,readdir($dirh));
12108: my $numitems = 0;
12109: foreach my $item (@dircontents) {
12110: if (-d "$path/$item") {
1.1075.2.28 raeburn 12111: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12112: if (-e "$path/$item") {
12113: $numitems ++;
12114: }
12115: } else {
12116: $numitems ++;
12117: }
12118: }
12119: if ($numitems == 0) {
12120: rmdir($path);
12121: }
12122: closedir($dirh);
12123: }
12124: }
12125: return;
12126: }
12127:
1.41 ng 12128: =pod
1.45 matthew 12129:
1.1075.2.56 raeburn 12130: =item * &get_folder_hierarchy()
1.1068 raeburn 12131:
12132: Provides hierarchy of names of folders/sub-folders containing the current
12133: item,
12134:
12135: Inputs: 3
12136: - $navmap - navmaps object
12137:
12138: - $map - url for map (either the trigger itself, or map containing
12139: the resource, which is the trigger).
12140:
12141: - $showitem - 1 => show title for map itself; 0 => do not show.
12142:
12143: Outputs: 1 @pathitems - array of folder/subfolder names.
12144:
12145: =cut
12146:
12147: sub get_folder_hierarchy {
12148: my ($navmap,$map,$showitem) = @_;
12149: my @pathitems;
12150: if (ref($navmap)) {
12151: my $mapres = $navmap->getResourceByUrl($map);
12152: if (ref($mapres)) {
12153: my $pcslist = $mapres->map_hierarchy();
12154: if ($pcslist ne '') {
12155: my @pcs = split(/,/,$pcslist);
12156: foreach my $pc (@pcs) {
12157: if ($pc == 1) {
1.1075.2.38 raeburn 12158: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12159: } else {
12160: my $res = $navmap->getByMapPc($pc);
12161: if (ref($res)) {
12162: my $title = $res->compTitle();
12163: $title =~ s/\W+/_/g;
12164: if ($title ne '') {
12165: push(@pathitems,$title);
12166: }
12167: }
12168: }
12169: }
12170: }
1.1071 raeburn 12171: if ($showitem) {
12172: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 12173: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12174: } else {
12175: my $maptitle = $mapres->compTitle();
12176: $maptitle =~ s/\W+/_/g;
12177: if ($maptitle ne '') {
12178: push(@pathitems,$maptitle);
12179: }
1.1068 raeburn 12180: }
12181: }
12182: }
12183: }
12184: return @pathitems;
12185: }
12186:
12187: =pod
12188:
1.1015 raeburn 12189: =item * &get_turnedin_filepath()
12190:
12191: Determines path in a user's portfolio file for storage of files uploaded
12192: to a specific essayresponse or dropbox item.
12193:
12194: Inputs: 3 required + 1 optional.
12195: $symb is symb for resource, $uname and $udom are for current user (required).
12196: $caller is optional (can be "submission", if routine is called when storing
12197: an upoaded file when "Submit Answer" button was pressed).
12198:
12199: Returns array containing $path and $multiresp.
12200: $path is path in portfolio. $multiresp is 1 if this resource contains more
12201: than one file upload item. Callers of routine should append partid as a
12202: subdirectory to $path in cases where $multiresp is 1.
12203:
12204: Called by: homework/essayresponse.pm and homework/structuretags.pm
12205:
12206: =cut
12207:
12208: sub get_turnedin_filepath {
12209: my ($symb,$uname,$udom,$caller) = @_;
12210: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12211: my $turnindir;
12212: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12213: $turnindir = $userhash{'turnindir'};
12214: my ($path,$multiresp);
12215: if ($turnindir eq '') {
12216: if ($caller eq 'submission') {
12217: $turnindir = &mt('turned in');
12218: $turnindir =~ s/\W+/_/g;
12219: my %newhash = (
12220: 'turnindir' => $turnindir,
12221: );
12222: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12223: }
12224: }
12225: if ($turnindir ne '') {
12226: $path = '/'.$turnindir.'/';
12227: my ($multipart,$turnin,@pathitems);
12228: my $navmap = Apache::lonnavmaps::navmap->new();
12229: if (defined($navmap)) {
12230: my $mapres = $navmap->getResourceByUrl($map);
12231: if (ref($mapres)) {
12232: my $pcslist = $mapres->map_hierarchy();
12233: if ($pcslist ne '') {
12234: foreach my $pc (split(/,/,$pcslist)) {
12235: my $res = $navmap->getByMapPc($pc);
12236: if (ref($res)) {
12237: my $title = $res->compTitle();
12238: $title =~ s/\W+/_/g;
12239: if ($title ne '') {
1.1075.2.48 raeburn 12240: if (($pc > 1) && (length($title) > 12)) {
12241: $title = substr($title,0,12);
12242: }
1.1015 raeburn 12243: push(@pathitems,$title);
12244: }
12245: }
12246: }
12247: }
12248: my $maptitle = $mapres->compTitle();
12249: $maptitle =~ s/\W+/_/g;
12250: if ($maptitle ne '') {
1.1075.2.48 raeburn 12251: if (length($maptitle) > 12) {
12252: $maptitle = substr($maptitle,0,12);
12253: }
1.1015 raeburn 12254: push(@pathitems,$maptitle);
12255: }
12256: unless ($env{'request.state'} eq 'construct') {
12257: my $res = $navmap->getBySymb($symb);
12258: if (ref($res)) {
12259: my $partlist = $res->parts();
12260: my $totaluploads = 0;
12261: if (ref($partlist) eq 'ARRAY') {
12262: foreach my $part (@{$partlist}) {
12263: my @types = $res->responseType($part);
12264: my @ids = $res->responseIds($part);
12265: for (my $i=0; $i < scalar(@ids); $i++) {
12266: if ($types[$i] eq 'essay') {
12267: my $partid = $part.'_'.$ids[$i];
12268: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12269: $totaluploads ++;
12270: }
12271: }
12272: }
12273: }
12274: if ($totaluploads > 1) {
12275: $multiresp = 1;
12276: }
12277: }
12278: }
12279: }
12280: } else {
12281: return;
12282: }
12283: } else {
12284: return;
12285: }
12286: my $restitle=&Apache::lonnet::gettitle($symb);
12287: $restitle =~ s/\W+/_/g;
12288: if ($restitle eq '') {
12289: $restitle = ($resurl =~ m{/[^/]+$});
12290: if ($restitle eq '') {
12291: $restitle = time;
12292: }
12293: }
1.1075.2.48 raeburn 12294: if (length($restitle) > 12) {
12295: $restitle = substr($restitle,0,12);
12296: }
1.1015 raeburn 12297: push(@pathitems,$restitle);
12298: $path .= join('/',@pathitems);
12299: }
12300: return ($path,$multiresp);
12301: }
12302:
12303: =pod
12304:
1.464 albertel 12305: =back
1.41 ng 12306:
1.112 bowersj2 12307: =head1 CSV Upload/Handling functions
1.38 albertel 12308:
1.41 ng 12309: =over 4
12310:
1.648 raeburn 12311: =item * &upfile_store($r)
1.41 ng 12312:
12313: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12314: needs $env{'form.upfile'}
1.41 ng 12315: returns $datatoken to be put into hidden field
12316:
12317: =cut
1.31 albertel 12318:
12319: sub upfile_store {
12320: my $r=shift;
1.258 albertel 12321: $env{'form.upfile'}=~s/\r/\n/gs;
12322: $env{'form.upfile'}=~s/\f/\n/gs;
12323: $env{'form.upfile'}=~s/\n+/\n/gs;
12324: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12325:
1.258 albertel 12326: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12327: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12328: {
1.158 raeburn 12329: my $datafile = $r->dir_config('lonDaemons').
12330: '/tmp/'.$datatoken.'.tmp';
12331: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12332: print $fh $env{'form.upfile'};
1.158 raeburn 12333: close($fh);
12334: }
1.31 albertel 12335: }
12336: return $datatoken;
12337: }
12338:
1.56 matthew 12339: =pod
12340:
1.648 raeburn 12341: =item * &load_tmp_file($r)
1.41 ng 12342:
12343: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12344: needs $env{'form.datatoken'},
12345: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12346:
12347: =cut
1.31 albertel 12348:
12349: sub load_tmp_file {
12350: my $r=shift;
12351: my @studentdata=();
12352: {
1.158 raeburn 12353: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12354: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12355: if ( open(my $fh,"<$studentfile") ) {
12356: @studentdata=<$fh>;
12357: close($fh);
12358: }
1.31 albertel 12359: }
1.258 albertel 12360: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12361: }
12362:
1.56 matthew 12363: =pod
12364:
1.648 raeburn 12365: =item * &upfile_record_sep()
1.41 ng 12366:
12367: Separate uploaded file into records
12368: returns array of records,
1.258 albertel 12369: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12370:
12371: =cut
1.31 albertel 12372:
12373: sub upfile_record_sep {
1.258 albertel 12374: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12375: } else {
1.248 albertel 12376: my @records;
1.258 albertel 12377: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12378: if ($line=~/^\s*$/) { next; }
12379: push(@records,$line);
12380: }
12381: return @records;
1.31 albertel 12382: }
12383: }
12384:
1.56 matthew 12385: =pod
12386:
1.648 raeburn 12387: =item * &record_sep($record)
1.41 ng 12388:
1.258 albertel 12389: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12390:
12391: =cut
12392:
1.263 www 12393: sub takeleft {
12394: my $index=shift;
12395: return substr('0000'.$index,-4,4);
12396: }
12397:
1.31 albertel 12398: sub record_sep {
12399: my $record=shift;
12400: my %components=();
1.258 albertel 12401: if ($env{'form.upfiletype'} eq 'xml') {
12402: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12403: my $i=0;
1.356 albertel 12404: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12405: $field=~s/^(\"|\')//;
12406: $field=~s/(\"|\')$//;
1.263 www 12407: $components{&takeleft($i)}=$field;
1.31 albertel 12408: $i++;
12409: }
1.258 albertel 12410: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12411: my $i=0;
1.356 albertel 12412: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12413: $field=~s/^(\"|\')//;
12414: $field=~s/(\"|\')$//;
1.263 www 12415: $components{&takeleft($i)}=$field;
1.31 albertel 12416: $i++;
12417: }
12418: } else {
1.561 www 12419: my $separator=',';
1.480 banghart 12420: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12421: $separator=';';
1.480 banghart 12422: }
1.31 albertel 12423: my $i=0;
1.561 www 12424: # the character we are looking for to indicate the end of a quote or a record
12425: my $looking_for=$separator;
12426: # do not add the characters to the fields
12427: my $ignore=0;
12428: # we just encountered a separator (or the beginning of the record)
12429: my $just_found_separator=1;
12430: # store the field we are working on here
12431: my $field='';
12432: # work our way through all characters in record
12433: foreach my $character ($record=~/(.)/g) {
12434: if ($character eq $looking_for) {
12435: if ($character ne $separator) {
12436: # Found the end of a quote, again looking for separator
12437: $looking_for=$separator;
12438: $ignore=1;
12439: } else {
12440: # Found a separator, store away what we got
12441: $components{&takeleft($i)}=$field;
12442: $i++;
12443: $just_found_separator=1;
12444: $ignore=0;
12445: $field='';
12446: }
12447: next;
12448: }
12449: # single or double quotation marks after a separator indicate beginning of a quote
12450: # we are now looking for the end of the quote and need to ignore separators
12451: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12452: $looking_for=$character;
12453: next;
12454: }
12455: # ignore would be true after we reached the end of a quote
12456: if ($ignore) { next; }
12457: if (($just_found_separator) && ($character=~/\s/)) { next; }
12458: $field.=$character;
12459: $just_found_separator=0;
1.31 albertel 12460: }
1.561 www 12461: # catch the very last entry, since we never encountered the separator
12462: $components{&takeleft($i)}=$field;
1.31 albertel 12463: }
12464: return %components;
12465: }
12466:
1.144 matthew 12467: ######################################################
12468: ######################################################
12469:
1.56 matthew 12470: =pod
12471:
1.648 raeburn 12472: =item * &upfile_select_html()
1.41 ng 12473:
1.144 matthew 12474: Return HTML code to select a file from the users machine and specify
12475: the file type.
1.41 ng 12476:
12477: =cut
12478:
1.144 matthew 12479: ######################################################
12480: ######################################################
1.31 albertel 12481: sub upfile_select_html {
1.144 matthew 12482: my %Types = (
12483: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12484: semisv => &mt('Semicolon separated values'),
1.144 matthew 12485: space => &mt('Space separated'),
12486: tab => &mt('Tabulator separated'),
12487: # xml => &mt('HTML/XML'),
12488: );
12489: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12490: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12491: foreach my $type (sort(keys(%Types))) {
12492: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12493: }
12494: $Str .= "</select>\n";
12495: return $Str;
1.31 albertel 12496: }
12497:
1.301 albertel 12498: sub get_samples {
12499: my ($records,$toget) = @_;
12500: my @samples=({});
12501: my $got=0;
12502: foreach my $rec (@$records) {
12503: my %temp = &record_sep($rec);
12504: if (! grep(/\S/, values(%temp))) { next; }
12505: if (%temp) {
12506: $samples[$got]=\%temp;
12507: $got++;
12508: if ($got == $toget) { last; }
12509: }
12510: }
12511: return \@samples;
12512: }
12513:
1.144 matthew 12514: ######################################################
12515: ######################################################
12516:
1.56 matthew 12517: =pod
12518:
1.648 raeburn 12519: =item * &csv_print_samples($r,$records)
1.41 ng 12520:
12521: Prints a table of sample values from each column uploaded $r is an
12522: Apache Request ref, $records is an arrayref from
12523: &Apache::loncommon::upfile_record_sep
12524:
12525: =cut
12526:
1.144 matthew 12527: ######################################################
12528: ######################################################
1.31 albertel 12529: sub csv_print_samples {
12530: my ($r,$records) = @_;
1.662 bisitz 12531: my $samples = &get_samples($records,5);
1.301 albertel 12532:
1.594 raeburn 12533: $r->print(&mt('Samples').'<br />'.&start_data_table().
12534: &start_data_table_header_row());
1.356 albertel 12535: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12536: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12537: $r->print(&end_data_table_header_row());
1.301 albertel 12538: foreach my $hash (@$samples) {
1.594 raeburn 12539: $r->print(&start_data_table_row());
1.356 albertel 12540: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12541: $r->print('<td>');
1.356 albertel 12542: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12543: $r->print('</td>');
12544: }
1.594 raeburn 12545: $r->print(&end_data_table_row());
1.31 albertel 12546: }
1.594 raeburn 12547: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12548: }
12549:
1.144 matthew 12550: ######################################################
12551: ######################################################
12552:
1.56 matthew 12553: =pod
12554:
1.648 raeburn 12555: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12556:
12557: Prints a table to create associations between values and table columns.
1.144 matthew 12558:
1.41 ng 12559: $r is an Apache Request ref,
12560: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12561: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12562:
12563: =cut
12564:
1.144 matthew 12565: ######################################################
12566: ######################################################
1.31 albertel 12567: sub csv_print_select_table {
12568: my ($r,$records,$d) = @_;
1.301 albertel 12569: my $i=0;
12570: my $samples = &get_samples($records,1);
1.144 matthew 12571: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12572: &start_data_table().&start_data_table_header_row().
1.144 matthew 12573: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12574: '<th>'.&mt('Column').'</th>'.
12575: &end_data_table_header_row()."\n");
1.356 albertel 12576: foreach my $array_ref (@$d) {
12577: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12578: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12579:
1.875 bisitz 12580: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12581: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12582: $r->print('<option value="none"></option>');
1.356 albertel 12583: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12584: $r->print('<option value="'.$sample.'"'.
12585: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12586: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12587: }
1.594 raeburn 12588: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12589: $i++;
12590: }
1.594 raeburn 12591: $r->print(&end_data_table());
1.31 albertel 12592: $i--;
12593: return $i;
12594: }
1.56 matthew 12595:
1.144 matthew 12596: ######################################################
12597: ######################################################
12598:
1.56 matthew 12599: =pod
1.31 albertel 12600:
1.648 raeburn 12601: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12602:
12603: Prints a table of sample values from the upload and can make associate samples to internal names.
12604:
12605: $r is an Apache Request ref,
12606: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12607: $d is an array of 2 element arrays (internal name, displayed name)
12608:
12609: =cut
12610:
1.144 matthew 12611: ######################################################
12612: ######################################################
1.31 albertel 12613: sub csv_samples_select_table {
12614: my ($r,$records,$d) = @_;
12615: my $i=0;
1.144 matthew 12616: #
1.662 bisitz 12617: my $max_samples = 5;
12618: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12619: $r->print(&start_data_table().
12620: &start_data_table_header_row().'<th>'.
12621: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12622: &end_data_table_header_row());
1.301 albertel 12623:
12624: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12625: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12626: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12627: foreach my $option (@$d) {
12628: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12629: $r->print('<option value="'.$value.'"'.
1.253 albertel 12630: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12631: $display.'</option>');
1.31 albertel 12632: }
12633: $r->print('</select></td><td>');
1.662 bisitz 12634: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12635: if (defined($samples->[$line]{$key})) {
12636: $r->print($samples->[$line]{$key}."<br />\n");
12637: }
12638: }
1.594 raeburn 12639: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12640: $i++;
12641: }
1.594 raeburn 12642: $r->print(&end_data_table());
1.31 albertel 12643: $i--;
12644: return($i);
1.115 matthew 12645: }
12646:
1.144 matthew 12647: ######################################################
12648: ######################################################
12649:
1.115 matthew 12650: =pod
12651:
1.648 raeburn 12652: =item * &clean_excel_name($name)
1.115 matthew 12653:
12654: Returns a replacement for $name which does not contain any illegal characters.
12655:
12656: =cut
12657:
1.144 matthew 12658: ######################################################
12659: ######################################################
1.115 matthew 12660: sub clean_excel_name {
12661: my ($name) = @_;
12662: $name =~ s/[:\*\?\/\\]//g;
12663: if (length($name) > 31) {
12664: $name = substr($name,0,31);
12665: }
12666: return $name;
1.25 albertel 12667: }
1.84 albertel 12668:
1.85 albertel 12669: =pod
12670:
1.648 raeburn 12671: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12672:
12673: Returns either 1 or undef
12674:
12675: 1 if the part is to be hidden, undef if it is to be shown
12676:
12677: Arguments are:
12678:
12679: $id the id of the part to be checked
12680: $symb, optional the symb of the resource to check
12681: $udom, optional the domain of the user to check for
12682: $uname, optional the username of the user to check for
12683:
12684: =cut
1.84 albertel 12685:
12686: sub check_if_partid_hidden {
12687: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12688: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12689: $symb,$udom,$uname);
1.141 albertel 12690: my $truth=1;
12691: #if the string starts with !, then the list is the list to show not hide
12692: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12693: my @hiddenlist=split(/,/,$hiddenparts);
12694: foreach my $checkid (@hiddenlist) {
1.141 albertel 12695: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12696: }
1.141 albertel 12697: return !$truth;
1.84 albertel 12698: }
1.127 matthew 12699:
1.138 matthew 12700:
12701: ############################################################
12702: ############################################################
12703:
12704: =pod
12705:
1.157 matthew 12706: =back
12707:
1.138 matthew 12708: =head1 cgi-bin script and graphing routines
12709:
1.157 matthew 12710: =over 4
12711:
1.648 raeburn 12712: =item * &get_cgi_id()
1.138 matthew 12713:
12714: Inputs: none
12715:
12716: Returns an id which can be used to pass environment variables
12717: to various cgi-bin scripts. These environment variables will
12718: be removed from the users environment after a given time by
12719: the routine &Apache::lonnet::transfer_profile_to_env.
12720:
12721: =cut
12722:
12723: ############################################################
12724: ############################################################
1.152 albertel 12725: my $uniq=0;
1.136 matthew 12726: sub get_cgi_id {
1.154 albertel 12727: $uniq=($uniq+1)%100000;
1.280 albertel 12728: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12729: }
12730:
1.127 matthew 12731: ############################################################
12732: ############################################################
12733:
12734: =pod
12735:
1.648 raeburn 12736: =item * &DrawBarGraph()
1.127 matthew 12737:
1.138 matthew 12738: Facilitates the plotting of data in a (stacked) bar graph.
12739: Puts plot definition data into the users environment in order for
12740: graph.png to plot it. Returns an <img> tag for the plot.
12741: The bars on the plot are labeled '1','2',...,'n'.
12742:
12743: Inputs:
12744:
12745: =over 4
12746:
12747: =item $Title: string, the title of the plot
12748:
12749: =item $xlabel: string, text describing the X-axis of the plot
12750:
12751: =item $ylabel: string, text describing the Y-axis of the plot
12752:
12753: =item $Max: scalar, the maximum Y value to use in the plot
12754: If $Max is < any data point, the graph will not be rendered.
12755:
1.140 matthew 12756: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12757: they are plotted. If undefined, default values will be used.
12758:
1.178 matthew 12759: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12760:
1.138 matthew 12761: =item @Values: An array of array references. Each array reference holds data
12762: to be plotted in a stacked bar chart.
12763:
1.239 matthew 12764: =item If the final element of @Values is a hash reference the key/value
12765: pairs will be added to the graph definition.
12766:
1.138 matthew 12767: =back
12768:
12769: Returns:
12770:
12771: An <img> tag which references graph.png and the appropriate identifying
12772: information for the plot.
12773:
1.127 matthew 12774: =cut
12775:
12776: ############################################################
12777: ############################################################
1.134 matthew 12778: sub DrawBarGraph {
1.178 matthew 12779: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12780: #
12781: if (! defined($colors)) {
12782: $colors = ['#33ff00',
12783: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12784: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12785: ];
12786: }
1.228 matthew 12787: my $extra_settings = {};
12788: if (ref($Values[-1]) eq 'HASH') {
12789: $extra_settings = pop(@Values);
12790: }
1.127 matthew 12791: #
1.136 matthew 12792: my $identifier = &get_cgi_id();
12793: my $id = 'cgi.'.$identifier;
1.129 matthew 12794: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12795: return '';
12796: }
1.225 matthew 12797: #
12798: my @Labels;
12799: if (defined($labels)) {
12800: @Labels = @$labels;
12801: } else {
12802: for (my $i=0;$i<@{$Values[0]};$i++) {
12803: push (@Labels,$i+1);
12804: }
12805: }
12806: #
1.129 matthew 12807: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12808: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12809: my %ValuesHash;
12810: my $NumSets=1;
12811: foreach my $array (@Values) {
12812: next if (! ref($array));
1.136 matthew 12813: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12814: join(',',@$array);
1.129 matthew 12815: }
1.127 matthew 12816: #
1.136 matthew 12817: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12818: if ($NumBars < 3) {
12819: $width = 120+$NumBars*32;
1.220 matthew 12820: $xskip = 1;
1.225 matthew 12821: $bar_width = 30;
12822: } elsif ($NumBars < 5) {
12823: $width = 120+$NumBars*20;
12824: $xskip = 1;
12825: $bar_width = 20;
1.220 matthew 12826: } elsif ($NumBars < 10) {
1.136 matthew 12827: $width = 120+$NumBars*15;
12828: $xskip = 1;
12829: $bar_width = 15;
12830: } elsif ($NumBars <= 25) {
12831: $width = 120+$NumBars*11;
12832: $xskip = 5;
12833: $bar_width = 8;
12834: } elsif ($NumBars <= 50) {
12835: $width = 120+$NumBars*8;
12836: $xskip = 5;
12837: $bar_width = 4;
12838: } else {
12839: $width = 120+$NumBars*8;
12840: $xskip = 5;
12841: $bar_width = 4;
12842: }
12843: #
1.137 matthew 12844: $Max = 1 if ($Max < 1);
12845: if ( int($Max) < $Max ) {
12846: $Max++;
12847: $Max = int($Max);
12848: }
1.127 matthew 12849: $Title = '' if (! defined($Title));
12850: $xlabel = '' if (! defined($xlabel));
12851: $ylabel = '' if (! defined($ylabel));
1.369 www 12852: $ValuesHash{$id.'.title'} = &escape($Title);
12853: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12854: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12855: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12856: $ValuesHash{$id.'.NumBars'} = $NumBars;
12857: $ValuesHash{$id.'.NumSets'} = $NumSets;
12858: $ValuesHash{$id.'.PlotType'} = 'bar';
12859: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12860: $ValuesHash{$id.'.height'} = $height;
12861: $ValuesHash{$id.'.width'} = $width;
12862: $ValuesHash{$id.'.xskip'} = $xskip;
12863: $ValuesHash{$id.'.bar_width'} = $bar_width;
12864: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12865: #
1.228 matthew 12866: # Deal with other parameters
12867: while (my ($key,$value) = each(%$extra_settings)) {
12868: $ValuesHash{$id.'.'.$key} = $value;
12869: }
12870: #
1.646 raeburn 12871: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12872: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12873: }
12874:
12875: ############################################################
12876: ############################################################
12877:
12878: =pod
12879:
1.648 raeburn 12880: =item * &DrawXYGraph()
1.137 matthew 12881:
1.138 matthew 12882: Facilitates the plotting of data in an XY graph.
12883: Puts plot definition data into the users environment in order for
12884: graph.png to plot it. Returns an <img> tag for the plot.
12885:
12886: Inputs:
12887:
12888: =over 4
12889:
12890: =item $Title: string, the title of the plot
12891:
12892: =item $xlabel: string, text describing the X-axis of the plot
12893:
12894: =item $ylabel: string, text describing the Y-axis of the plot
12895:
12896: =item $Max: scalar, the maximum Y value to use in the plot
12897: If $Max is < any data point, the graph will not be rendered.
12898:
12899: =item $colors: Array ref containing the hex color codes for the data to be
12900: plotted in. If undefined, default values will be used.
12901:
12902: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12903:
12904: =item $Ydata: Array ref containing Array refs.
1.185 www 12905: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12906:
12907: =item %Values: hash indicating or overriding any default values which are
12908: passed to graph.png.
12909: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12910:
12911: =back
12912:
12913: Returns:
12914:
12915: An <img> tag which references graph.png and the appropriate identifying
12916: information for the plot.
12917:
1.137 matthew 12918: =cut
12919:
12920: ############################################################
12921: ############################################################
12922: sub DrawXYGraph {
12923: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12924: #
12925: # Create the identifier for the graph
12926: my $identifier = &get_cgi_id();
12927: my $id = 'cgi.'.$identifier;
12928: #
12929: $Title = '' if (! defined($Title));
12930: $xlabel = '' if (! defined($xlabel));
12931: $ylabel = '' if (! defined($ylabel));
12932: my %ValuesHash =
12933: (
1.369 www 12934: $id.'.title' => &escape($Title),
12935: $id.'.xlabel' => &escape($xlabel),
12936: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12937: $id.'.y_max_value'=> $Max,
12938: $id.'.labels' => join(',',@$Xlabels),
12939: $id.'.PlotType' => 'XY',
12940: );
12941: #
12942: if (defined($colors) && ref($colors) eq 'ARRAY') {
12943: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12944: }
12945: #
12946: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12947: return '';
12948: }
12949: my $NumSets=1;
1.138 matthew 12950: foreach my $array (@{$Ydata}){
1.137 matthew 12951: next if (! ref($array));
12952: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12953: }
1.138 matthew 12954: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12955: #
12956: # Deal with other parameters
12957: while (my ($key,$value) = each(%Values)) {
12958: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12959: }
12960: #
1.646 raeburn 12961: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12962: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12963: }
12964:
12965: ############################################################
12966: ############################################################
12967:
12968: =pod
12969:
1.648 raeburn 12970: =item * &DrawXYYGraph()
1.138 matthew 12971:
12972: Facilitates the plotting of data in an XY graph with two Y axes.
12973: Puts plot definition data into the users environment in order for
12974: graph.png to plot it. Returns an <img> tag for the plot.
12975:
12976: Inputs:
12977:
12978: =over 4
12979:
12980: =item $Title: string, the title of the plot
12981:
12982: =item $xlabel: string, text describing the X-axis of the plot
12983:
12984: =item $ylabel: string, text describing the Y-axis of the plot
12985:
12986: =item $colors: Array ref containing the hex color codes for the data to be
12987: plotted in. If undefined, default values will be used.
12988:
12989: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12990:
12991: =item $Ydata1: The first data set
12992:
12993: =item $Min1: The minimum value of the left Y-axis
12994:
12995: =item $Max1: The maximum value of the left Y-axis
12996:
12997: =item $Ydata2: The second data set
12998:
12999: =item $Min2: The minimum value of the right Y-axis
13000:
13001: =item $Max2: The maximum value of the left Y-axis
13002:
13003: =item %Values: hash indicating or overriding any default values which are
13004: passed to graph.png.
13005: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13006:
13007: =back
13008:
13009: Returns:
13010:
13011: An <img> tag which references graph.png and the appropriate identifying
13012: information for the plot.
1.136 matthew 13013:
13014: =cut
13015:
13016: ############################################################
13017: ############################################################
1.137 matthew 13018: sub DrawXYYGraph {
13019: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13020: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13021: #
13022: # Create the identifier for the graph
13023: my $identifier = &get_cgi_id();
13024: my $id = 'cgi.'.$identifier;
13025: #
13026: $Title = '' if (! defined($Title));
13027: $xlabel = '' if (! defined($xlabel));
13028: $ylabel = '' if (! defined($ylabel));
13029: my %ValuesHash =
13030: (
1.369 www 13031: $id.'.title' => &escape($Title),
13032: $id.'.xlabel' => &escape($xlabel),
13033: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13034: $id.'.labels' => join(',',@$Xlabels),
13035: $id.'.PlotType' => 'XY',
13036: $id.'.NumSets' => 2,
1.137 matthew 13037: $id.'.two_axes' => 1,
13038: $id.'.y1_max_value' => $Max1,
13039: $id.'.y1_min_value' => $Min1,
13040: $id.'.y2_max_value' => $Max2,
13041: $id.'.y2_min_value' => $Min2,
1.136 matthew 13042: );
13043: #
1.137 matthew 13044: if (defined($colors) && ref($colors) eq 'ARRAY') {
13045: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13046: }
13047: #
13048: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13049: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13050: return '';
13051: }
13052: my $NumSets=1;
1.137 matthew 13053: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13054: next if (! ref($array));
13055: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13056: }
13057: #
13058: # Deal with other parameters
13059: while (my ($key,$value) = each(%Values)) {
13060: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13061: }
13062: #
1.646 raeburn 13063: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13064: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13065: }
13066:
13067: ############################################################
13068: ############################################################
13069:
13070: =pod
13071:
1.157 matthew 13072: =back
13073:
1.139 matthew 13074: =head1 Statistics helper routines?
13075:
13076: Bad place for them but what the hell.
13077:
1.157 matthew 13078: =over 4
13079:
1.648 raeburn 13080: =item * &chartlink()
1.139 matthew 13081:
13082: Returns a link to the chart for a specific student.
13083:
13084: Inputs:
13085:
13086: =over 4
13087:
13088: =item $linktext: The text of the link
13089:
13090: =item $sname: The students username
13091:
13092: =item $sdomain: The students domain
13093:
13094: =back
13095:
1.157 matthew 13096: =back
13097:
1.139 matthew 13098: =cut
13099:
13100: ############################################################
13101: ############################################################
13102: sub chartlink {
13103: my ($linktext, $sname, $sdomain) = @_;
13104: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13105: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13106: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13107: '">'.$linktext.'</a>';
1.153 matthew 13108: }
13109:
13110: #######################################################
13111: #######################################################
13112:
13113: =pod
13114:
13115: =head1 Course Environment Routines
1.157 matthew 13116:
13117: =over 4
1.153 matthew 13118:
1.648 raeburn 13119: =item * &restore_course_settings()
1.153 matthew 13120:
1.648 raeburn 13121: =item * &store_course_settings()
1.153 matthew 13122:
13123: Restores/Store indicated form parameters from the course environment.
13124: Will not overwrite existing values of the form parameters.
13125:
13126: Inputs:
13127: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13128:
13129: a hash ref describing the data to be stored. For example:
13130:
13131: %Save_Parameters = ('Status' => 'scalar',
13132: 'chartoutputmode' => 'scalar',
13133: 'chartoutputdata' => 'scalar',
13134: 'Section' => 'array',
1.373 raeburn 13135: 'Group' => 'array',
1.153 matthew 13136: 'StudentData' => 'array',
13137: 'Maps' => 'array');
13138:
13139: Returns: both routines return nothing
13140:
1.631 raeburn 13141: =back
13142:
1.153 matthew 13143: =cut
13144:
13145: #######################################################
13146: #######################################################
13147: sub store_course_settings {
1.496 albertel 13148: return &store_settings($env{'request.course.id'},@_);
13149: }
13150:
13151: sub store_settings {
1.153 matthew 13152: # save to the environment
13153: # appenv the same items, just to be safe
1.300 albertel 13154: my $udom = $env{'user.domain'};
13155: my $uname = $env{'user.name'};
1.496 albertel 13156: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13157: my %SaveHash;
13158: my %AppHash;
13159: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13160: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13161: my $envname = 'environment.'.$basename;
1.258 albertel 13162: if (exists($env{'form.'.$setting})) {
1.153 matthew 13163: # Save this value away
13164: if ($type eq 'scalar' &&
1.258 albertel 13165: (! exists($env{$envname}) ||
13166: $env{$envname} ne $env{'form.'.$setting})) {
13167: $SaveHash{$basename} = $env{'form.'.$setting};
13168: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13169: } elsif ($type eq 'array') {
13170: my $stored_form;
1.258 albertel 13171: if (ref($env{'form.'.$setting})) {
1.153 matthew 13172: $stored_form = join(',',
13173: map {
1.369 www 13174: &escape($_);
1.258 albertel 13175: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13176: } else {
13177: $stored_form =
1.369 www 13178: &escape($env{'form.'.$setting});
1.153 matthew 13179: }
13180: # Determine if the array contents are the same.
1.258 albertel 13181: if ($stored_form ne $env{$envname}) {
1.153 matthew 13182: $SaveHash{$basename} = $stored_form;
13183: $AppHash{$envname} = $stored_form;
13184: }
13185: }
13186: }
13187: }
13188: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13189: $udom,$uname);
1.153 matthew 13190: if ($put_result !~ /^(ok|delayed)/) {
13191: &Apache::lonnet::logthis('unable to save form parameters, '.
13192: 'got error:'.$put_result);
13193: }
13194: # Make sure these settings stick around in this session, too
1.646 raeburn 13195: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13196: return;
13197: }
13198:
13199: sub restore_course_settings {
1.499 albertel 13200: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13201: }
13202:
13203: sub restore_settings {
13204: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13205: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13206: next if (exists($env{'form.'.$setting}));
1.496 albertel 13207: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13208: '.'.$setting;
1.258 albertel 13209: if (exists($env{$envname})) {
1.153 matthew 13210: if ($type eq 'scalar') {
1.258 albertel 13211: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13212: } elsif ($type eq 'array') {
1.258 albertel 13213: $env{'form.'.$setting} = [
1.153 matthew 13214: map {
1.369 www 13215: &unescape($_);
1.258 albertel 13216: } split(',',$env{$envname})
1.153 matthew 13217: ];
13218: }
13219: }
13220: }
1.127 matthew 13221: }
13222:
1.618 raeburn 13223: #######################################################
13224: #######################################################
13225:
13226: =pod
13227:
13228: =head1 Domain E-mail Routines
13229:
13230: =over 4
13231:
1.648 raeburn 13232: =item * &build_recipient_list()
1.618 raeburn 13233:
1.1075.2.44 raeburn 13234: Build recipient lists for following types of e-mail:
1.766 raeburn 13235: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 13236: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13237: module change checking, student/employee ID conflict checks, as
13238: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13239: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13240:
13241: Inputs:
1.1075.2.44 raeburn 13242: defmail (scalar - email address of default recipient),
13243: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13244: requestsmail, updatesmail, or idconflictsmail).
13245:
1.619 raeburn 13246: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 13247:
13248: origmail (scalar - email address of recipient from loncapa.conf,
13249: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13250:
1.655 raeburn 13251: Returns: comma separated list of addresses to which to send e-mail.
13252:
13253: =back
1.618 raeburn 13254:
13255: =cut
13256:
13257: ############################################################
13258: ############################################################
13259: sub build_recipient_list {
1.619 raeburn 13260: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13261: my @recipients;
13262: my $otheremails;
13263: my %domconfig =
13264: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13265: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13266: if (exists($domconfig{'contacts'}{$mailing})) {
13267: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13268: my @contacts = ('adminemail','supportemail');
13269: foreach my $item (@contacts) {
13270: if ($domconfig{'contacts'}{$mailing}{$item}) {
13271: my $addr = $domconfig{'contacts'}{$item};
13272: if (!grep(/^\Q$addr\E$/,@recipients)) {
13273: push(@recipients,$addr);
13274: }
1.619 raeburn 13275: }
1.766 raeburn 13276: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13277: }
13278: }
1.766 raeburn 13279: } elsif ($origmail ne '') {
13280: push(@recipients,$origmail);
1.618 raeburn 13281: }
1.619 raeburn 13282: } elsif ($origmail ne '') {
13283: push(@recipients,$origmail);
1.618 raeburn 13284: }
1.688 raeburn 13285: if (defined($defmail)) {
13286: if ($defmail ne '') {
13287: push(@recipients,$defmail);
13288: }
1.618 raeburn 13289: }
13290: if ($otheremails) {
1.619 raeburn 13291: my @others;
13292: if ($otheremails =~ /,/) {
13293: @others = split(/,/,$otheremails);
1.618 raeburn 13294: } else {
1.619 raeburn 13295: push(@others,$otheremails);
13296: }
13297: foreach my $addr (@others) {
13298: if (!grep(/^\Q$addr\E$/,@recipients)) {
13299: push(@recipients,$addr);
13300: }
1.618 raeburn 13301: }
13302: }
1.619 raeburn 13303: my $recipientlist = join(',',@recipients);
1.618 raeburn 13304: return $recipientlist;
13305: }
13306:
1.127 matthew 13307: ############################################################
13308: ############################################################
1.154 albertel 13309:
1.655 raeburn 13310: =pod
13311:
13312: =head1 Course Catalog Routines
13313:
13314: =over 4
13315:
13316: =item * &gather_categories()
13317:
13318: Converts category definitions - keys of categories hash stored in
13319: coursecategories in configuration.db on the primary library server in a
13320: domain - to an array. Also generates javascript and idx hash used to
13321: generate Domain Coordinator interface for editing Course Categories.
13322:
13323: Inputs:
1.663 raeburn 13324:
1.655 raeburn 13325: categories (reference to hash of category definitions).
1.663 raeburn 13326:
1.655 raeburn 13327: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13328: categories and subcategories).
1.663 raeburn 13329:
1.655 raeburn 13330: idx (reference to hash of counters used in Domain Coordinator interface for
13331: editing Course Categories).
1.663 raeburn 13332:
1.655 raeburn 13333: jsarray (reference to array of categories used to create Javascript arrays for
13334: Domain Coordinator interface for editing Course Categories).
13335:
13336: Returns: nothing
13337:
13338: Side effects: populates cats, idx and jsarray.
13339:
13340: =cut
13341:
13342: sub gather_categories {
13343: my ($categories,$cats,$idx,$jsarray) = @_;
13344: my %counters;
13345: my $num = 0;
13346: foreach my $item (keys(%{$categories})) {
13347: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13348: if ($container eq '' && $depth == 0) {
13349: $cats->[$depth][$categories->{$item}] = $cat;
13350: } else {
13351: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13352: }
13353: my ($escitem,$tail) = split(/:/,$item,2);
13354: if ($counters{$tail} eq '') {
13355: $counters{$tail} = $num;
13356: $num ++;
13357: }
13358: if (ref($idx) eq 'HASH') {
13359: $idx->{$item} = $counters{$tail};
13360: }
13361: if (ref($jsarray) eq 'ARRAY') {
13362: push(@{$jsarray->[$counters{$tail}]},$item);
13363: }
13364: }
13365: return;
13366: }
13367:
13368: =pod
13369:
13370: =item * &extract_categories()
13371:
13372: Used to generate breadcrumb trails for course categories.
13373:
13374: Inputs:
1.663 raeburn 13375:
1.655 raeburn 13376: categories (reference to hash of category definitions).
1.663 raeburn 13377:
1.655 raeburn 13378: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13379: categories and subcategories).
1.663 raeburn 13380:
1.655 raeburn 13381: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13382:
1.655 raeburn 13383: allitems (reference to hash - key is category key
13384: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13385:
1.655 raeburn 13386: idx (reference to hash of counters used in Domain Coordinator interface for
13387: editing Course Categories).
1.663 raeburn 13388:
1.655 raeburn 13389: jsarray (reference to array of categories used to create Javascript arrays for
13390: Domain Coordinator interface for editing Course Categories).
13391:
1.665 raeburn 13392: subcats (reference to hash of arrays containing all subcategories within each
13393: category, -recursive)
13394:
1.655 raeburn 13395: Returns: nothing
13396:
13397: Side effects: populates trails and allitems hash references.
13398:
13399: =cut
13400:
13401: sub extract_categories {
1.665 raeburn 13402: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13403: if (ref($categories) eq 'HASH') {
13404: &gather_categories($categories,$cats,$idx,$jsarray);
13405: if (ref($cats->[0]) eq 'ARRAY') {
13406: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13407: my $name = $cats->[0][$i];
13408: my $item = &escape($name).'::0';
13409: my $trailstr;
13410: if ($name eq 'instcode') {
13411: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13412: } elsif ($name eq 'communities') {
13413: $trailstr = &mt('Communities');
1.655 raeburn 13414: } else {
13415: $trailstr = $name;
13416: }
13417: if ($allitems->{$item} eq '') {
13418: push(@{$trails},$trailstr);
13419: $allitems->{$item} = scalar(@{$trails})-1;
13420: }
13421: my @parents = ($name);
13422: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13423: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13424: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13425: if (ref($subcats) eq 'HASH') {
13426: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13427: }
13428: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13429: }
13430: } else {
13431: if (ref($subcats) eq 'HASH') {
13432: $subcats->{$item} = [];
1.655 raeburn 13433: }
13434: }
13435: }
13436: }
13437: }
13438: return;
13439: }
13440:
13441: =pod
13442:
1.1075.2.56 raeburn 13443: =item * &recurse_categories()
1.655 raeburn 13444:
13445: Recursively used to generate breadcrumb trails for course categories.
13446:
13447: Inputs:
1.663 raeburn 13448:
1.655 raeburn 13449: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13450: categories and subcategories).
1.663 raeburn 13451:
1.655 raeburn 13452: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13453:
13454: category (current course category, for which breadcrumb trail is being generated).
13455:
13456: trails (reference to array of breadcrumb trails for each category).
13457:
1.655 raeburn 13458: allitems (reference to hash - key is category key
13459: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13460:
1.655 raeburn 13461: parents (array containing containers directories for current category,
13462: back to top level).
13463:
13464: Returns: nothing
13465:
13466: Side effects: populates trails and allitems hash references
13467:
13468: =cut
13469:
13470: sub recurse_categories {
1.665 raeburn 13471: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13472: my $shallower = $depth - 1;
13473: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13474: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13475: my $name = $cats->[$depth]{$category}[$k];
13476: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13477: my $trailstr = join(' -> ',(@{$parents},$category));
13478: if ($allitems->{$item} eq '') {
13479: push(@{$trails},$trailstr);
13480: $allitems->{$item} = scalar(@{$trails})-1;
13481: }
13482: my $deeper = $depth+1;
13483: push(@{$parents},$category);
1.665 raeburn 13484: if (ref($subcats) eq 'HASH') {
13485: my $subcat = &escape($name).':'.$category.':'.$depth;
13486: for (my $j=@{$parents}; $j>=0; $j--) {
13487: my $higher;
13488: if ($j > 0) {
13489: $higher = &escape($parents->[$j]).':'.
13490: &escape($parents->[$j-1]).':'.$j;
13491: } else {
13492: $higher = &escape($parents->[$j]).'::'.$j;
13493: }
13494: push(@{$subcats->{$higher}},$subcat);
13495: }
13496: }
13497: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13498: $subcats);
1.655 raeburn 13499: pop(@{$parents});
13500: }
13501: } else {
13502: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13503: my $trailstr = join(' -> ',(@{$parents},$category));
13504: if ($allitems->{$item} eq '') {
13505: push(@{$trails},$trailstr);
13506: $allitems->{$item} = scalar(@{$trails})-1;
13507: }
13508: }
13509: return;
13510: }
13511:
1.663 raeburn 13512: =pod
13513:
1.1075.2.56 raeburn 13514: =item * &assign_categories_table()
1.663 raeburn 13515:
13516: Create a datatable for display of hierarchical categories in a domain,
13517: with checkboxes to allow a course to be categorized.
13518:
13519: Inputs:
13520:
13521: cathash - reference to hash of categories defined for the domain (from
13522: configuration.db)
13523:
13524: currcat - scalar with an & separated list of categories assigned to a course.
13525:
1.919 raeburn 13526: type - scalar contains course type (Course or Community).
13527:
1.663 raeburn 13528: Returns: $output (markup to be displayed)
13529:
13530: =cut
13531:
13532: sub assign_categories_table {
1.919 raeburn 13533: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13534: my $output;
13535: if (ref($cathash) eq 'HASH') {
13536: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13537: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13538: $maxdepth = scalar(@cats);
13539: if (@cats > 0) {
13540: my $itemcount = 0;
13541: if (ref($cats[0]) eq 'ARRAY') {
13542: my @currcategories;
13543: if ($currcat ne '') {
13544: @currcategories = split('&',$currcat);
13545: }
1.919 raeburn 13546: my $table;
1.663 raeburn 13547: for (my $i=0; $i<@{$cats[0]}; $i++) {
13548: my $parent = $cats[0][$i];
1.919 raeburn 13549: next if ($parent eq 'instcode');
13550: if ($type eq 'Community') {
13551: next unless ($parent eq 'communities');
13552: } else {
13553: next if ($parent eq 'communities');
13554: }
1.663 raeburn 13555: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13556: my $item = &escape($parent).'::0';
13557: my $checked = '';
13558: if (@currcategories > 0) {
13559: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13560: $checked = ' checked="checked"';
1.663 raeburn 13561: }
13562: }
1.919 raeburn 13563: my $parent_title = $parent;
13564: if ($parent eq 'communities') {
13565: $parent_title = &mt('Communities');
13566: }
13567: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13568: '<input type="checkbox" name="usecategory" value="'.
13569: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13570: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13571: my $depth = 1;
13572: push(@path,$parent);
1.919 raeburn 13573: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13574: pop(@path);
1.919 raeburn 13575: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13576: $itemcount ++;
13577: }
1.919 raeburn 13578: if ($itemcount) {
13579: $output = &Apache::loncommon::start_data_table().
13580: $table.
13581: &Apache::loncommon::end_data_table();
13582: }
1.663 raeburn 13583: }
13584: }
13585: }
13586: return $output;
13587: }
13588:
13589: =pod
13590:
1.1075.2.56 raeburn 13591: =item * &assign_category_rows()
1.663 raeburn 13592:
13593: Create a datatable row for display of nested categories in a domain,
13594: with checkboxes to allow a course to be categorized,called recursively.
13595:
13596: Inputs:
13597:
13598: itemcount - track row number for alternating colors
13599:
13600: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13601: categories and subcategories.
13602:
13603: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13604:
13605: parent - parent of current category item
13606:
13607: path - Array containing all categories back up through the hierarchy from the
13608: current category to the top level.
13609:
13610: currcategories - reference to array of current categories assigned to the course
13611:
13612: Returns: $output (markup to be displayed).
13613:
13614: =cut
13615:
13616: sub assign_category_rows {
13617: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13618: my ($text,$name,$item,$chgstr);
13619: if (ref($cats) eq 'ARRAY') {
13620: my $maxdepth = scalar(@{$cats});
13621: if (ref($cats->[$depth]) eq 'HASH') {
13622: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13623: my $numchildren = @{$cats->[$depth]{$parent}};
13624: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 13625: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 13626: for (my $j=0; $j<$numchildren; $j++) {
13627: $name = $cats->[$depth]{$parent}[$j];
13628: $item = &escape($name).':'.&escape($parent).':'.$depth;
13629: my $deeper = $depth+1;
13630: my $checked = '';
13631: if (ref($currcategories) eq 'ARRAY') {
13632: if (@{$currcategories} > 0) {
13633: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13634: $checked = ' checked="checked"';
1.663 raeburn 13635: }
13636: }
13637: }
1.664 raeburn 13638: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13639: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13640: $item.'"'.$checked.' />'.$name.'</label></span>'.
13641: '<input type="hidden" name="catname" value="'.$name.'" />'.
13642: '</td><td>';
1.663 raeburn 13643: if (ref($path) eq 'ARRAY') {
13644: push(@{$path},$name);
13645: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13646: pop(@{$path});
13647: }
13648: $text .= '</td></tr>';
13649: }
13650: $text .= '</table></td>';
13651: }
13652: }
13653: }
13654: return $text;
13655: }
13656:
1.655 raeburn 13657: ############################################################
13658: ############################################################
13659:
13660:
1.443 albertel 13661: sub commit_customrole {
1.664 raeburn 13662: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13663: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13664: ($start?', '.&mt('starting').' '.localtime($start):'').
13665: ($end?', ending '.localtime($end):'').': <b>'.
13666: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13667: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13668: '</b><br />';
13669: return $output;
13670: }
13671:
13672: sub commit_standardrole {
1.1075.2.31 raeburn 13673: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13674: my ($output,$logmsg,$linefeed);
13675: if ($context eq 'auto') {
13676: $linefeed = "\n";
13677: } else {
13678: $linefeed = "<br />\n";
13679: }
1.443 albertel 13680: if ($three eq 'st') {
1.541 raeburn 13681: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 13682: $one,$two,$sec,$context,$credits);
1.541 raeburn 13683: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13684: ($result eq 'unknown_course') || ($result eq 'refused')) {
13685: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13686: } else {
1.541 raeburn 13687: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13688: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13689: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13690: if ($context eq 'auto') {
13691: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13692: } else {
13693: $output .= '<b>'.$result.'</b>'.$linefeed.
13694: &mt('Add to classlist').': <b>ok</b>';
13695: }
13696: $output .= $linefeed;
1.443 albertel 13697: }
13698: } else {
13699: $output = &mt('Assigning').' '.$three.' in '.$url.
13700: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13701: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13702: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13703: if ($context eq 'auto') {
13704: $output .= $result.$linefeed;
13705: } else {
13706: $output .= '<b>'.$result.'</b>'.$linefeed;
13707: }
1.443 albertel 13708: }
13709: return $output;
13710: }
13711:
13712: sub commit_studentrole {
1.1075.2.31 raeburn 13713: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13714: $credits) = @_;
1.626 raeburn 13715: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13716: if ($context eq 'auto') {
13717: $linefeed = "\n";
13718: } else {
13719: $linefeed = '<br />'."\n";
13720: }
1.443 albertel 13721: if (defined($one) && defined($two)) {
13722: my $cid=$one.'_'.$two;
13723: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13724: my $secchange = 0;
13725: my $expire_role_result;
13726: my $modify_section_result;
1.628 raeburn 13727: if ($oldsec ne '-1') {
13728: if ($oldsec ne $sec) {
1.443 albertel 13729: $secchange = 1;
1.628 raeburn 13730: my $now = time;
1.443 albertel 13731: my $uurl='/'.$cid;
13732: $uurl=~s/\_/\//g;
13733: if ($oldsec) {
13734: $uurl.='/'.$oldsec;
13735: }
1.626 raeburn 13736: $oldsecurl = $uurl;
1.628 raeburn 13737: $expire_role_result =
1.652 raeburn 13738: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13739: if ($env{'request.course.sec'} ne '') {
13740: if ($expire_role_result eq 'refused') {
13741: my @roles = ('st');
13742: my @statuses = ('previous');
13743: my @roledoms = ($one);
13744: my $withsec = 1;
13745: my %roleshash =
13746: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13747: \@statuses,\@roles,\@roledoms,$withsec);
13748: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13749: my ($oldstart,$oldend) =
13750: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13751: if ($oldend > 0 && $oldend <= $now) {
13752: $expire_role_result = 'ok';
13753: }
13754: }
13755: }
13756: }
1.443 albertel 13757: $result = $expire_role_result;
13758: }
13759: }
13760: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 13761: $modify_section_result =
13762: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13763: undef,undef,undef,$sec,
13764: $end,$start,'','',$cid,
13765: '',$context,$credits);
1.443 albertel 13766: if ($modify_section_result =~ /^ok/) {
13767: if ($secchange == 1) {
1.628 raeburn 13768: if ($sec eq '') {
13769: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13770: } else {
13771: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13772: }
1.443 albertel 13773: } elsif ($oldsec eq '-1') {
1.628 raeburn 13774: if ($sec eq '') {
13775: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13776: } else {
13777: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13778: }
1.443 albertel 13779: } else {
1.628 raeburn 13780: if ($sec eq '') {
13781: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13782: } else {
13783: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13784: }
1.443 albertel 13785: }
13786: } else {
1.628 raeburn 13787: if ($secchange) {
13788: $$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;
13789: } else {
13790: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13791: }
1.443 albertel 13792: }
13793: $result = $modify_section_result;
13794: } elsif ($secchange == 1) {
1.628 raeburn 13795: if ($oldsec eq '') {
1.1075.2.20 raeburn 13796: $$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 13797: } else {
13798: $$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;
13799: }
1.626 raeburn 13800: if ($expire_role_result eq 'refused') {
13801: my $newsecurl = '/'.$cid;
13802: $newsecurl =~ s/\_/\//g;
13803: if ($sec ne '') {
13804: $newsecurl.='/'.$sec;
13805: }
13806: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13807: if ($sec eq '') {
13808: $$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;
13809: } else {
13810: $$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;
13811: }
13812: }
13813: }
1.443 albertel 13814: }
13815: } else {
1.626 raeburn 13816: $$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 13817: $result = "error: incomplete course id\n";
13818: }
13819: return $result;
13820: }
13821:
1.1075.2.25 raeburn 13822: sub show_role_extent {
13823: my ($scope,$context,$role) = @_;
13824: $scope =~ s{^/}{};
13825: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13826: push(@courseroles,'co');
13827: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13828: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13829: $scope =~ s{/}{_};
13830: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13831: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13832: my ($audom,$auname) = split(/\//,$scope);
13833: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13834: &Apache::loncommon::plainname($auname,$audom).'</span>');
13835: } else {
13836: $scope =~ s{/$}{};
13837: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13838: &Apache::lonnet::domain($scope,'description').'</span>');
13839: }
13840: }
13841:
1.443 albertel 13842: ############################################################
13843: ############################################################
13844:
1.566 albertel 13845: sub check_clone {
1.578 raeburn 13846: my ($args,$linefeed) = @_;
1.566 albertel 13847: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13848: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13849: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13850: my $clonemsg;
13851: my $can_clone = 0;
1.944 raeburn 13852: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13853: if ($lctype ne 'community') {
13854: $lctype = 'course';
13855: }
1.566 albertel 13856: if ($clonehome eq 'no_host') {
1.944 raeburn 13857: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13858: $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'});
13859: } else {
13860: $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'});
13861: }
1.566 albertel 13862: } else {
13863: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13864: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13865: if ($clonedesc{'type'} ne 'Community') {
13866: $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'});
13867: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13868: }
13869: }
1.882 raeburn 13870: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13871: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13872: $can_clone = 1;
13873: } else {
13874: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13875: $args->{'clonedomain'},$args->{'clonecourse'});
13876: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13877: if (grep(/^\*$/,@cloners)) {
13878: $can_clone = 1;
13879: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13880: $can_clone = 1;
13881: } else {
1.908 raeburn 13882: my $ccrole = 'cc';
1.944 raeburn 13883: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13884: $ccrole = 'co';
13885: }
1.578 raeburn 13886: my %roleshash =
13887: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13888: $args->{'ccdomain'},
1.908 raeburn 13889: 'userroles',['active'],[$ccrole],
1.578 raeburn 13890: [$args->{'clonedomain'}]);
1.908 raeburn 13891: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13892: $can_clone = 1;
13893: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13894: $can_clone = 1;
13895: } else {
1.944 raeburn 13896: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13897: $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'});
13898: } else {
13899: $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'});
13900: }
1.578 raeburn 13901: }
1.566 albertel 13902: }
1.578 raeburn 13903: }
1.566 albertel 13904: }
13905: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13906: }
13907:
1.444 albertel 13908: sub construct_course {
1.1075.2.59 raeburn 13909: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 13910: my $outcome;
1.541 raeburn 13911: my $linefeed = '<br />'."\n";
13912: if ($context eq 'auto') {
13913: $linefeed = "\n";
13914: }
1.566 albertel 13915:
13916: #
13917: # Are we cloning?
13918: #
13919: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13920: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13921: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13922: if ($context ne 'auto') {
1.578 raeburn 13923: if ($clonemsg ne '') {
13924: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13925: }
1.566 albertel 13926: }
13927: $outcome .= $clonemsg.$linefeed;
13928:
13929: if (!$can_clone) {
13930: return (0,$outcome);
13931: }
13932: }
13933:
1.444 albertel 13934: #
13935: # Open course
13936: #
13937: my $crstype = lc($args->{'crstype'});
13938: my %cenv=();
13939: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13940: $args->{'cdescr'},
13941: $args->{'curl'},
13942: $args->{'course_home'},
13943: $args->{'nonstandard'},
13944: $args->{'crscode'},
13945: $args->{'ccuname'}.':'.
13946: $args->{'ccdomain'},
1.882 raeburn 13947: $args->{'crstype'},
1.885 raeburn 13948: $cnum,$context,$category);
1.444 albertel 13949:
13950: # Note: The testing routines depend on this being output; see
13951: # Utils::Course. This needs to at least be output as a comment
13952: # if anyone ever decides to not show this, and Utils::Course::new
13953: # will need to be suitably modified.
1.541 raeburn 13954: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13955: if ($$courseid =~ /^error:/) {
13956: return (0,$outcome);
13957: }
13958:
1.444 albertel 13959: #
13960: # Check if created correctly
13961: #
1.479 albertel 13962: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13963: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13964: if ($crsuhome eq 'no_host') {
13965: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13966: return (0,$outcome);
13967: }
1.541 raeburn 13968: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 13969:
1.444 albertel 13970: #
1.566 albertel 13971: # Do the cloning
13972: #
13973: if ($can_clone && $cloneid) {
13974: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
13975: if ($context ne 'auto') {
13976: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
13977: }
13978: $outcome .= $clonemsg.$linefeed;
13979: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 13980: # Copy all files
1.637 www 13981: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 13982: # Restore URL
1.566 albertel 13983: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 13984: # Restore title
1.566 albertel 13985: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 13986: # Restore creation date, creator and creation context.
13987: $cenv{'internal.created'}=$oldcenv{'internal.created'};
13988: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
13989: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 13990: # Mark as cloned
1.566 albertel 13991: $cenv{'clonedfrom'}=$cloneid;
1.638 www 13992: # Need to clone grading mode
13993: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
13994: $cenv{'grading'}=$newenv{'grading'};
13995: # Do not clone these environment entries
13996: &Apache::lonnet::del('environment',
13997: ['default_enrollment_start_date',
13998: 'default_enrollment_end_date',
13999: 'question.email',
14000: 'policy.email',
14001: 'comment.email',
14002: 'pch.users.denied',
1.725 raeburn 14003: 'plc.users.denied',
14004: 'hidefromcat',
1.1075.2.36 raeburn 14005: 'checkforpriv',
1.1075.2.59 raeburn 14006: 'categories',
14007: 'internal.uniquecode'],
1.638 www 14008: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 14009: if ($args->{'textbook'}) {
14010: $cenv{'internal.textbook'} = $args->{'textbook'};
14011: }
1.444 albertel 14012: }
1.566 albertel 14013:
1.444 albertel 14014: #
14015: # Set environment (will override cloned, if existing)
14016: #
14017: my @sections = ();
14018: my @xlists = ();
14019: if ($args->{'crstype'}) {
14020: $cenv{'type'}=$args->{'crstype'};
14021: }
14022: if ($args->{'crsid'}) {
14023: $cenv{'courseid'}=$args->{'crsid'};
14024: }
14025: if ($args->{'crscode'}) {
14026: $cenv{'internal.coursecode'}=$args->{'crscode'};
14027: }
14028: if ($args->{'crsquota'} ne '') {
14029: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14030: } else {
14031: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14032: }
14033: if ($args->{'ccuname'}) {
14034: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14035: ':'.$args->{'ccdomain'};
14036: } else {
14037: $cenv{'internal.courseowner'} = $args->{'curruser'};
14038: }
1.1075.2.31 raeburn 14039: if ($args->{'defaultcredits'}) {
14040: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14041: }
1.444 albertel 14042: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14043: if ($args->{'crssections'}) {
14044: $cenv{'internal.sectionnums'} = '';
14045: if ($args->{'crssections'} =~ m/,/) {
14046: @sections = split/,/,$args->{'crssections'};
14047: } else {
14048: $sections[0] = $args->{'crssections'};
14049: }
14050: if (@sections > 0) {
14051: foreach my $item (@sections) {
14052: my ($sec,$gp) = split/:/,$item;
14053: my $class = $args->{'crscode'}.$sec;
14054: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14055: $cenv{'internal.sectionnums'} .= $item.',';
14056: unless ($addcheck eq 'ok') {
14057: push @badclasses, $class;
14058: }
14059: }
14060: $cenv{'internal.sectionnums'} =~ s/,$//;
14061: }
14062: }
14063: # do not hide course coordinator from staff listing,
14064: # even if privileged
14065: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 14066: # add course coordinator's domain to domains to check for privileged users
14067: # if different to course domain
14068: if ($$crsudom ne $args->{'ccdomain'}) {
14069: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14070: }
1.444 albertel 14071: # add crosslistings
14072: if ($args->{'crsxlist'}) {
14073: $cenv{'internal.crosslistings'}='';
14074: if ($args->{'crsxlist'} =~ m/,/) {
14075: @xlists = split/,/,$args->{'crsxlist'};
14076: } else {
14077: $xlists[0] = $args->{'crsxlist'};
14078: }
14079: if (@xlists > 0) {
14080: foreach my $item (@xlists) {
14081: my ($xl,$gp) = split/:/,$item;
14082: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14083: $cenv{'internal.crosslistings'} .= $item.',';
14084: unless ($addcheck eq 'ok') {
14085: push @badclasses, $xl;
14086: }
14087: }
14088: $cenv{'internal.crosslistings'} =~ s/,$//;
14089: }
14090: }
14091: if ($args->{'autoadds'}) {
14092: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14093: }
14094: if ($args->{'autodrops'}) {
14095: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14096: }
14097: # check for notification of enrollment changes
14098: my @notified = ();
14099: if ($args->{'notify_owner'}) {
14100: if ($args->{'ccuname'} ne '') {
14101: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14102: }
14103: }
14104: if ($args->{'notify_dc'}) {
14105: if ($uname ne '') {
1.630 raeburn 14106: push(@notified,$uname.':'.$udom);
1.444 albertel 14107: }
14108: }
14109: if (@notified > 0) {
14110: my $notifylist;
14111: if (@notified > 1) {
14112: $notifylist = join(',',@notified);
14113: } else {
14114: $notifylist = $notified[0];
14115: }
14116: $cenv{'internal.notifylist'} = $notifylist;
14117: }
14118: if (@badclasses > 0) {
14119: my %lt=&Apache::lonlocal::texthash(
14120: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course. However, if automated course roster updates are enabled for this class, these particular sections/crosslistings will not contribute towards enrollment, because the user identified as the course owner for this LON-CAPA course',
14121: 'dnhr' => 'does not have rights to access enrollment in these classes',
14122: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14123: );
1.541 raeburn 14124: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14125: ' ('.$lt{'adby'}.')';
14126: if ($context eq 'auto') {
14127: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14128: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14129: foreach my $item (@badclasses) {
14130: if ($context eq 'auto') {
14131: $outcome .= " - $item\n";
14132: } else {
14133: $outcome .= "<li>$item</li>\n";
14134: }
14135: }
14136: if ($context eq 'auto') {
14137: $outcome .= $linefeed;
14138: } else {
1.566 albertel 14139: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14140: }
14141: }
1.444 albertel 14142: }
14143: if ($args->{'no_end_date'}) {
14144: $args->{'endaccess'} = 0;
14145: }
14146: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14147: $cenv{'internal.autoend'}=$args->{'enrollend'};
14148: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14149: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14150: if ($args->{'showphotos'}) {
14151: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14152: }
14153: $cenv{'internal.authtype'} = $args->{'authtype'};
14154: $cenv{'internal.autharg'} = $args->{'autharg'};
14155: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14156: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14157: 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');
14158: if ($context eq 'auto') {
14159: $outcome .= $krb_msg;
14160: } else {
1.566 albertel 14161: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14162: }
14163: $outcome .= $linefeed;
1.444 albertel 14164: }
14165: }
14166: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14167: if ($args->{'setpolicy'}) {
14168: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14169: }
14170: if ($args->{'setcontent'}) {
14171: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14172: }
14173: }
14174: if ($args->{'reshome'}) {
14175: $cenv{'reshome'}=$args->{'reshome'}.'/';
14176: $cenv{'reshome'}=~s/\/+$/\//;
14177: }
14178: #
14179: # course has keyed access
14180: #
14181: if ($args->{'setkeys'}) {
14182: $cenv{'keyaccess'}='yes';
14183: }
14184: # if specified, key authority is not course, but user
14185: # only active if keyaccess is yes
14186: if ($args->{'keyauth'}) {
1.487 albertel 14187: my ($user,$domain) = split(':',$args->{'keyauth'});
14188: $user = &LONCAPA::clean_username($user);
14189: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14190: if ($user ne '' && $domain ne '') {
1.487 albertel 14191: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14192: }
14193: }
14194:
1.1075.2.59 raeburn 14195: #
14196: # generate and store uniquecode (available to course requester), if course should have one.
14197: #
14198: if ($args->{'uniquecode'}) {
14199: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
14200: if ($code) {
14201: $cenv{'internal.uniquecode'} = $code;
14202: my %crsinfo =
14203: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
14204: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
14205: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
14206: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
14207: }
14208: if (ref($coderef)) {
14209: $$coderef = $code;
14210: }
14211: }
14212: }
14213:
1.444 albertel 14214: if ($args->{'disresdis'}) {
14215: $cenv{'pch.roles.denied'}='st';
14216: }
14217: if ($args->{'disablechat'}) {
14218: $cenv{'plc.roles.denied'}='st';
14219: }
14220:
14221: # Record we've not yet viewed the Course Initialization Helper for this
14222: # course
14223: $cenv{'course.helper.not.run'} = 1;
14224: #
14225: # Use new Randomseed
14226: #
14227: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14228: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14229: #
14230: # The encryption code and receipt prefix for this course
14231: #
14232: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14233: $cenv{'internal.encpref'}=100+int(9*rand(99));
14234: #
14235: # By default, use standard grading
14236: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14237:
1.541 raeburn 14238: $outcome .= $linefeed.&mt('Setting environment').': '.
14239: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14240: #
14241: # Open all assignments
14242: #
14243: if ($args->{'openall'}) {
14244: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14245: my %storecontent = ($storeunder => time,
14246: $storeunder.'.type' => 'date_start');
14247:
14248: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14249: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14250: }
14251: #
14252: # Set first page
14253: #
14254: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14255: || ($cloneid)) {
1.445 albertel 14256: use LONCAPA::map;
1.444 albertel 14257: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14258:
14259: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14260: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14261:
1.444 albertel 14262: $outcome .= ($fatal?$errtext:'read ok').' - ';
14263: my $title; my $url;
14264: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14265: $title=&mt('Syllabus');
1.444 albertel 14266: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14267: } else {
1.963 raeburn 14268: $title=&mt('Table of Contents');
1.444 albertel 14269: $url='/adm/navmaps';
14270: }
1.445 albertel 14271:
14272: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14273: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14274:
14275: if ($errtext) { $fatal=2; }
1.541 raeburn 14276: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14277: }
1.566 albertel 14278:
14279: return (1,$outcome);
1.444 albertel 14280: }
14281:
1.1075.2.59 raeburn 14282: sub make_unique_code {
14283: my ($cdom,$cnum) = @_;
14284: # get lock on uniquecodes db
14285: my $lockhash = {
14286: $cnum."\0".'uniquecodes' => $env{'user.name'}.
14287: ':'.$env{'user.domain'},
14288: };
14289: my $tries = 0;
14290: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14291: my ($code,$error);
14292:
14293: while (($gotlock ne 'ok') && ($tries<3)) {
14294: $tries ++;
14295: sleep 1;
14296: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14297: }
14298: if ($gotlock eq 'ok') {
14299: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
14300: my $gotcode;
14301: my $attempts = 0;
14302: while ((!$gotcode) && ($attempts < 100)) {
14303: $code = &generate_code();
14304: if (!exists($currcodes{$code})) {
14305: $gotcode = 1;
14306: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
14307: $error = 'nostore';
14308: }
14309: }
14310: $attempts ++;
14311: }
14312: my @del_lock = ($cnum."\0".'uniquecodes');
14313: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
14314: } else {
14315: $error = 'nolock';
14316: }
14317: return ($code,$error);
14318: }
14319:
14320: sub generate_code {
14321: my $code;
14322: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
14323: for (my $i=0; $i<6; $i++) {
14324: my $lettnum = int (rand 2);
14325: my $item = '';
14326: if ($lettnum) {
14327: $item = $letts[int( rand(18) )];
14328: } else {
14329: $item = 1+int( rand(8) );
14330: }
14331: $code .= $item;
14332: }
14333: return $code;
14334: }
14335:
1.444 albertel 14336: ############################################################
14337: ############################################################
14338:
1.953 droeschl 14339: #SD
14340: # only Community and Course, or anything else?
1.378 raeburn 14341: sub course_type {
14342: my ($cid) = @_;
14343: if (!defined($cid)) {
14344: $cid = $env{'request.course.id'};
14345: }
1.404 albertel 14346: if (defined($env{'course.'.$cid.'.type'})) {
14347: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14348: } else {
14349: return 'Course';
1.377 raeburn 14350: }
14351: }
1.156 albertel 14352:
1.406 raeburn 14353: sub group_term {
14354: my $crstype = &course_type();
14355: my %names = (
14356: 'Course' => 'group',
1.865 raeburn 14357: 'Community' => 'group',
1.406 raeburn 14358: );
14359: return $names{$crstype};
14360: }
14361:
1.902 raeburn 14362: sub course_types {
1.1075.2.59 raeburn 14363: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 14364: my %typename = (
14365: official => 'Official course',
14366: unofficial => 'Unofficial course',
14367: community => 'Community',
1.1075.2.59 raeburn 14368: textbook => 'Textbook course',
1.902 raeburn 14369: );
14370: return (\@types,\%typename);
14371: }
14372:
1.156 albertel 14373: sub icon {
14374: my ($file)=@_;
1.505 albertel 14375: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14376: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14377: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14378: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14379: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14380: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14381: $curfext.".gif") {
14382: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14383: $curfext.".gif";
14384: }
14385: }
1.249 albertel 14386: return &lonhttpdurl($iconname);
1.154 albertel 14387: }
1.84 albertel 14388:
1.575 albertel 14389: sub lonhttpdurl {
1.692 www 14390: #
14391: # Had been used for "small fry" static images on separate port 8080.
14392: # Modify here if lightweight http functionality desired again.
14393: # Currently eliminated due to increasing firewall issues.
14394: #
1.575 albertel 14395: my ($url)=@_;
1.692 www 14396: return $url;
1.215 albertel 14397: }
14398:
1.213 albertel 14399: sub connection_aborted {
14400: my ($r)=@_;
14401: $r->print(" ");$r->rflush();
14402: my $c = $r->connection;
14403: return $c->aborted();
14404: }
14405:
1.221 foxr 14406: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14407: # strings as 'strings'.
14408: sub escape_single {
1.221 foxr 14409: my ($input) = @_;
1.223 albertel 14410: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14411: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14412: return $input;
14413: }
1.223 albertel 14414:
1.222 foxr 14415: # Same as escape_single, but escape's "'s This
14416: # can be used for "strings"
14417: sub escape_double {
14418: my ($input) = @_;
14419: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14420: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14421: return $input;
14422: }
1.223 albertel 14423:
1.222 foxr 14424: # Escapes the last element of a full URL.
14425: sub escape_url {
14426: my ($url) = @_;
1.238 raeburn 14427: my @urlslices = split(/\//, $url,-1);
1.369 www 14428: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 14429: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 14430: }
1.462 albertel 14431:
1.820 raeburn 14432: sub compare_arrays {
14433: my ($arrayref1,$arrayref2) = @_;
14434: my (@difference,%count);
14435: @difference = ();
14436: %count = ();
14437: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14438: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14439: foreach my $element (keys(%count)) {
14440: if ($count{$element} == 1) {
14441: push(@difference,$element);
14442: }
14443: }
14444: }
14445: return @difference;
14446: }
14447:
1.817 bisitz 14448: # -------------------------------------------------------- Initialize user login
1.462 albertel 14449: sub init_user_environment {
1.463 albertel 14450: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14451: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14452:
14453: my $public=($username eq 'public' && $domain eq 'public');
14454:
14455: # See if old ID present, if so, remove
14456:
1.1062 raeburn 14457: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14458: my $now=time;
14459:
14460: if ($public) {
14461: my $max_public=100;
14462: my $oldest;
14463: my $oldest_time=0;
14464: for(my $next=1;$next<=$max_public;$next++) {
14465: if (-e $lonids."/publicuser_$next.id") {
14466: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14467: if ($mtime<$oldest_time || !$oldest_time) {
14468: $oldest_time=$mtime;
14469: $oldest=$next;
14470: }
14471: } else {
14472: $cookie="publicuser_$next";
14473: last;
14474: }
14475: }
14476: if (!$cookie) { $cookie="publicuser_$oldest"; }
14477: } else {
1.463 albertel 14478: # if this isn't a robot, kill any existing non-robot sessions
14479: if (!$args->{'robot'}) {
14480: opendir(DIR,$lonids);
14481: while ($filename=readdir(DIR)) {
14482: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14483: unlink($lonids.'/'.$filename);
14484: }
1.462 albertel 14485: }
1.463 albertel 14486: closedir(DIR);
1.462 albertel 14487: }
14488: # Give them a new cookie
1.463 albertel 14489: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14490: : $now.$$.int(rand(10000)));
1.463 albertel 14491: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14492:
14493: # Initialize roles
14494:
1.1062 raeburn 14495: ($userroles,$firstaccenv,$timerintenv) =
14496: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14497: }
14498: # ------------------------------------ Check browser type and MathML capability
14499:
14500: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.42 raeburn 14501: $clientunicode,$clientos,$clientmobile,$clientinfo) = &decode_user_agent($r);
1.462 albertel 14502:
14503: # ------------------------------------------------------------- Get environment
14504:
14505: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14506: my ($tmp) = keys(%userenv);
14507: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14508: } else {
14509: undef(%userenv);
14510: }
14511: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14512: $form->{'interface'}=$userenv{'interface'};
14513: }
14514: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14515:
14516: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14517: foreach my $option ('interface','localpath','localres') {
14518: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14519: }
14520: # --------------------------------------------------------- Write first profile
14521:
14522: {
14523: my %initial_env =
14524: ("user.name" => $username,
14525: "user.domain" => $domain,
14526: "user.home" => $authhost,
14527: "browser.type" => $clientbrowser,
14528: "browser.version" => $clientversion,
14529: "browser.mathml" => $clientmathml,
14530: "browser.unicode" => $clientunicode,
14531: "browser.os" => $clientos,
1.1075.2.42 raeburn 14532: "browser.mobile" => $clientmobile,
14533: "browser.info" => $clientinfo,
1.462 albertel 14534: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14535: "request.course.fn" => '',
14536: "request.course.uri" => '',
14537: "request.course.sec" => '',
14538: "request.role" => 'cm',
14539: "request.role.adv" => $env{'user.adv'},
14540: "request.host" => $ENV{'REMOTE_ADDR'},);
14541:
14542: if ($form->{'localpath'}) {
14543: $initial_env{"browser.localpath"} = $form->{'localpath'};
14544: $initial_env{"browser.localres"} = $form->{'localres'};
14545: }
14546:
14547: if ($form->{'interface'}) {
14548: $form->{'interface'}=~s/\W//gs;
14549: $initial_env{"browser.interface"} = $form->{'interface'};
14550: $env{'browser.interface'}=$form->{'interface'};
14551: }
14552:
1.1075.2.54 raeburn 14553: if ($form->{'iptoken'}) {
14554: my $lonhost = $r->dir_config('lonHostID');
14555: $initial_env{"user.noloadbalance"} = $lonhost;
14556: $env{'user.noloadbalance'} = $lonhost;
14557: }
14558:
1.981 raeburn 14559: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14560: my %domdef;
14561: unless ($domain eq 'public') {
14562: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14563: }
1.980 raeburn 14564:
1.1075.2.7 raeburn 14565: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14566: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14567: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14568: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14569: }
14570:
1.1075.2.59 raeburn 14571: foreach my $crstype ('official','unofficial','community','textbook') {
1.765 raeburn 14572: $userenv{'canrequest.'.$crstype} =
14573: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14574: 'reload','requestcourses',
14575: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14576: }
14577:
1.1075.2.14 raeburn 14578: $userenv{'canrequest.author'} =
14579: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14580: 'reload','requestauthor',
14581: \%userenv,\%domdef,\%is_adv);
14582: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14583: $domain,$username);
14584: my $reqstatus = $reqauthor{'author_status'};
14585: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14586: if (ref($reqauthor{'author'}) eq 'HASH') {
14587: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14588: $reqauthor{'author'}{'timestamp'};
14589: }
14590: }
14591:
1.462 albertel 14592: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14593:
1.462 albertel 14594: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14595: &GDBM_WRCREAT(),0640)) {
14596: &_add_to_env(\%disk_env,\%initial_env);
14597: &_add_to_env(\%disk_env,\%userenv,'environment.');
14598: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14599: if (ref($firstaccenv) eq 'HASH') {
14600: &_add_to_env(\%disk_env,$firstaccenv);
14601: }
14602: if (ref($timerintenv) eq 'HASH') {
14603: &_add_to_env(\%disk_env,$timerintenv);
14604: }
1.463 albertel 14605: if (ref($args->{'extra_env'})) {
14606: &_add_to_env(\%disk_env,$args->{'extra_env'});
14607: }
1.462 albertel 14608: untie(%disk_env);
14609: } else {
1.705 tempelho 14610: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14611: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14612: return 'error: '.$!;
14613: }
14614: }
14615: $env{'request.role'}='cm';
14616: $env{'request.role.adv'}=$env{'user.adv'};
14617: $env{'browser.type'}=$clientbrowser;
14618:
14619: return $cookie;
14620:
14621: }
14622:
14623: sub _add_to_env {
14624: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14625: if (ref($env_data) eq 'HASH') {
14626: while (my ($key,$value) = each(%$env_data)) {
14627: $idf->{$prefix.$key} = $value;
14628: $env{$prefix.$key} = $value;
14629: }
1.462 albertel 14630: }
14631: }
14632:
1.685 tempelho 14633: # --- Get the symbolic name of a problem and the url
14634: sub get_symb {
14635: my ($request,$silent) = @_;
1.726 raeburn 14636: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14637: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14638: if ($symb eq '') {
14639: if (!$silent) {
1.1071 raeburn 14640: if (ref($request)) {
14641: $request->print("Unable to handle ambiguous references:$url:.");
14642: }
1.685 tempelho 14643: return ();
14644: }
14645: }
14646: &Apache::lonenc::check_decrypt(\$symb);
14647: return ($symb);
14648: }
14649:
14650: # --------------------------------------------------------------Get annotation
14651:
14652: sub get_annotation {
14653: my ($symb,$enc) = @_;
14654:
14655: my $key = $symb;
14656: if (!$enc) {
14657: $key =
14658: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14659: }
14660: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14661: return $annotation{$key};
14662: }
14663:
14664: sub clean_symb {
1.731 raeburn 14665: my ($symb,$delete_enc) = @_;
1.685 tempelho 14666:
14667: &Apache::lonenc::check_decrypt(\$symb);
14668: my $enc = $env{'request.enc'};
1.731 raeburn 14669: if ($delete_enc) {
1.730 raeburn 14670: delete($env{'request.enc'});
14671: }
1.685 tempelho 14672:
14673: return ($symb,$enc);
14674: }
1.462 albertel 14675:
1.990 raeburn 14676: sub build_release_hashes {
14677: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
14678: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
14679: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
14680: (ref($randomizetry) eq 'HASH'));
14681: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14682: my ($item,$name,$value) = split(/:/,$key);
14683: if ($item eq 'parameter') {
14684: if (ref($checkparms->{$name}) eq 'ARRAY') {
14685: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
14686: push(@{$checkparms->{$name}},$value);
14687: }
14688: } else {
14689: push(@{$checkparms->{$name}},$value);
14690: }
14691: } elsif ($item eq 'resourcetag') {
14692: if ($name eq 'responsetype') {
14693: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
14694: }
14695: } elsif ($item eq 'course') {
14696: if ($name eq 'crstype') {
14697: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
14698: }
14699: }
14700: }
14701: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
14702: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
14703: return;
14704: }
14705:
1.1075.2.11 raeburn 14706: sub update_content_constraints {
14707: my ($cdom,$cnum,$chome,$cid) = @_;
14708: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
14709: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
14710: my %checkresponsetypes;
14711: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14712: my ($item,$name,$value) = split(/:/,$key);
14713: if ($item eq 'resourcetag') {
14714: if ($name eq 'responsetype') {
14715: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
14716: }
14717: }
14718: }
14719: my $navmap = Apache::lonnavmaps::navmap->new();
14720: if (defined($navmap)) {
14721: my %allresponses;
14722: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
14723: my %responses = $res->responseTypes();
14724: foreach my $key (keys(%responses)) {
14725: next unless(exists($checkresponsetypes{$key}));
14726: $allresponses{$key} += $responses{$key};
14727: }
14728: }
14729: foreach my $key (keys(%allresponses)) {
14730: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
14731: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
14732: ($reqdmajor,$reqdminor) = ($major,$minor);
14733: }
14734: }
14735: undef($navmap);
14736: }
14737: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
14738: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
14739: }
14740: return;
14741: }
14742:
1.1075.2.27 raeburn 14743: sub allmaps_incourse {
14744: my ($cdom,$cnum,$chome,$cid) = @_;
14745: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
14746: $cid = $env{'request.course.id'};
14747: $cdom = $env{'course.'.$cid.'.domain'};
14748: $cnum = $env{'course.'.$cid.'.num'};
14749: $chome = $env{'course.'.$cid.'.home'};
14750: }
14751: my %allmaps = ();
14752: my $lastchange =
14753: &Apache::lonnet::get_coursechange($cdom,$cnum);
14754: if ($lastchange > $env{'request.course.tied'}) {
14755: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
14756: unless ($ferr) {
14757: &update_content_constraints($cdom,$cnum,$chome,$cid);
14758: }
14759: }
14760: my $navmap = Apache::lonnavmaps::navmap->new();
14761: if (defined($navmap)) {
14762: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
14763: $allmaps{$res->src()} = 1;
14764: }
14765: }
14766: return \%allmaps;
14767: }
14768:
1.1075.2.11 raeburn 14769: sub parse_supplemental_title {
14770: my ($title) = @_;
14771:
14772: my ($foldertitle,$renametitle);
14773: if ($title =~ /&&&/) {
14774: $title = &HTML::Entites::decode($title);
14775: }
14776: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
14777: $renametitle=$4;
14778: my ($time,$uname,$udom) = ($1,$2,$3);
14779: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
14780: my $name = &plainname($uname,$udom);
14781: $name = &HTML::Entities::encode($name,'"<>&\'');
14782: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
14783: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
14784: $name.': <br />'.$foldertitle;
14785: }
14786: if (wantarray) {
14787: return ($title,$foldertitle,$renametitle);
14788: }
14789: return $title;
14790: }
14791:
1.1075.2.43 raeburn 14792: sub recurse_supplemental {
14793: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
14794: if ($suppmap) {
14795: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
14796: if ($fatal) {
14797: $errors ++;
14798: } else {
14799: if ($#LONCAPA::map::resources > 0) {
14800: foreach my $res (@LONCAPA::map::resources) {
14801: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
14802: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 14803: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
14804: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 14805: } else {
14806: $numfiles ++;
14807: }
14808: }
14809: }
14810: }
14811: }
14812: }
14813: return ($numfiles,$errors);
14814: }
14815:
1.1075.2.18 raeburn 14816: sub symb_to_docspath {
14817: my ($symb) = @_;
14818: return unless ($symb);
14819: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
14820: if ($resurl=~/\.(sequence|page)$/) {
14821: $mapurl=$resurl;
14822: } elsif ($resurl eq 'adm/navmaps') {
14823: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
14824: }
14825: my $mapresobj;
14826: my $navmap = Apache::lonnavmaps::navmap->new();
14827: if (ref($navmap)) {
14828: $mapresobj = $navmap->getResourceByUrl($mapurl);
14829: }
14830: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
14831: my $type=$2;
14832: my $path;
14833: if (ref($mapresobj)) {
14834: my $pcslist = $mapresobj->map_hierarchy();
14835: if ($pcslist ne '') {
14836: foreach my $pc (split(/,/,$pcslist)) {
14837: next if ($pc <= 1);
14838: my $res = $navmap->getByMapPc($pc);
14839: if (ref($res)) {
14840: my $thisurl = $res->src();
14841: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
14842: my $thistitle = $res->title();
14843: $path .= '&'.
14844: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 14845: &escape($thistitle).
1.1075.2.18 raeburn 14846: ':'.$res->randompick().
14847: ':'.$res->randomout().
14848: ':'.$res->encrypted().
14849: ':'.$res->randomorder().
14850: ':'.$res->is_page();
14851: }
14852: }
14853: }
14854: $path =~ s/^\&//;
14855: my $maptitle = $mapresobj->title();
14856: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 14857: $maptitle = 'Main Content';
1.1075.2.18 raeburn 14858: }
14859: $path .= (($path ne '')? '&' : '').
14860: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 14861: &escape($maptitle).
1.1075.2.18 raeburn 14862: ':'.$mapresobj->randompick().
14863: ':'.$mapresobj->randomout().
14864: ':'.$mapresobj->encrypted().
14865: ':'.$mapresobj->randomorder().
14866: ':'.$mapresobj->is_page();
14867: } else {
14868: my $maptitle = &Apache::lonnet::gettitle($mapurl);
14869: my $ispage = (($type eq 'page')? 1 : '');
14870: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 14871: $maptitle = 'Main Content';
1.1075.2.18 raeburn 14872: }
14873: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 14874: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 14875: }
14876: unless ($mapurl eq 'default') {
14877: $path = 'default&'.
1.1075.2.46 raeburn 14878: &escape('Main Content').
1.1075.2.18 raeburn 14879: ':::::&'.$path;
14880: }
14881: return $path;
14882: }
14883:
1.1075.2.14 raeburn 14884: sub captcha_display {
14885: my ($context,$lonhost) = @_;
14886: my ($output,$error);
14887: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
14888: if ($captcha eq 'original') {
14889: $output = &create_captcha();
14890: unless ($output) {
14891: $error = 'captcha';
14892: }
14893: } elsif ($captcha eq 'recaptcha') {
14894: $output = &create_recaptcha($pubkey);
14895: unless ($output) {
14896: $error = 'recaptcha';
14897: }
14898: }
14899: return ($output,$error);
14900: }
14901:
14902: sub captcha_response {
14903: my ($context,$lonhost) = @_;
14904: my ($captcha_chk,$captcha_error);
14905: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
14906: if ($captcha eq 'original') {
14907: ($captcha_chk,$captcha_error) = &check_captcha();
14908: } elsif ($captcha eq 'recaptcha') {
14909: $captcha_chk = &check_recaptcha($privkey);
14910: } else {
14911: $captcha_chk = 1;
14912: }
14913: return ($captcha_chk,$captcha_error);
14914: }
14915:
14916: sub get_captcha_config {
14917: my ($context,$lonhost) = @_;
14918: my ($captcha,$pubkey,$privkey,$hashtocheck);
14919: my $hostname = &Apache::lonnet::hostname($lonhost);
14920: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
14921: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
14922: if ($context eq 'usercreation') {
14923: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
14924: if (ref($domconfig{$context}) eq 'HASH') {
14925: $hashtocheck = $domconfig{$context}{'cancreate'};
14926: if (ref($hashtocheck) eq 'HASH') {
14927: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
14928: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
14929: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
14930: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
14931: }
14932: if ($privkey && $pubkey) {
14933: $captcha = 'recaptcha';
14934: } else {
14935: $captcha = 'original';
14936: }
14937: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
14938: $captcha = 'original';
14939: }
14940: }
14941: } else {
14942: $captcha = 'captcha';
14943: }
14944: } elsif ($context eq 'login') {
14945: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
14946: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
14947: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
14948: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
14949: if ($privkey && $pubkey) {
14950: $captcha = 'recaptcha';
14951: } else {
14952: $captcha = 'original';
14953: }
14954: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
14955: $captcha = 'original';
14956: }
14957: }
14958: return ($captcha,$pubkey,$privkey);
14959: }
14960:
14961: sub create_captcha {
14962: my %captcha_params = &captcha_settings();
14963: my ($output,$maxtries,$tries) = ('',10,0);
14964: while ($tries < $maxtries) {
14965: $tries ++;
14966: my $captcha = Authen::Captcha->new (
14967: output_folder => $captcha_params{'output_dir'},
14968: data_folder => $captcha_params{'db_dir'},
14969: );
14970: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
14971:
14972: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
14973: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
14974: &mt('Type in the letters/numbers shown below').' '.
14975: '<input type="text" size="5" name="code" value="" /><br />'.
14976: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" />';
14977: last;
14978: }
14979: }
14980: return $output;
14981: }
14982:
14983: sub captcha_settings {
14984: my %captcha_params = (
14985: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
14986: www_output_dir => "/captchaspool",
14987: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
14988: numchars => '5',
14989: );
14990: return %captcha_params;
14991: }
14992:
14993: sub check_captcha {
14994: my ($captcha_chk,$captcha_error);
14995: my $code = $env{'form.code'};
14996: my $md5sum = $env{'form.crypt'};
14997: my %captcha_params = &captcha_settings();
14998: my $captcha = Authen::Captcha->new(
14999: output_folder => $captcha_params{'output_dir'},
15000: data_folder => $captcha_params{'db_dir'},
15001: );
1.1075.2.26 raeburn 15002: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 15003: my %captcha_hash = (
15004: 0 => 'Code not checked (file error)',
15005: -1 => 'Failed: code expired',
15006: -2 => 'Failed: invalid code (not in database)',
15007: -3 => 'Failed: invalid code (code does not match crypt)',
15008: );
15009: if ($captcha_chk != 1) {
15010: $captcha_error = $captcha_hash{$captcha_chk}
15011: }
15012: return ($captcha_chk,$captcha_error);
15013: }
15014:
15015: sub create_recaptcha {
15016: my ($pubkey) = @_;
1.1075.2.51 raeburn 15017: my $use_ssl;
15018: if ($ENV{'SERVER_PORT'} == 443) {
15019: $use_ssl = 1;
15020: }
1.1075.2.14 raeburn 15021: my $captcha = Captcha::reCAPTCHA->new;
15022: return $captcha->get_options_setter({theme => 'white'})."\n".
1.1075.2.51 raeburn 15023: $captcha->get_html($pubkey,undef,$use_ssl).
1.1075.2.14 raeburn 15024: &mt('If either word is hard to read, [_1] will replace them.',
1.1075.2.39 raeburn 15025: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1075.2.14 raeburn 15026: '<br /><br />';
15027: }
15028:
15029: sub check_recaptcha {
15030: my ($privkey) = @_;
15031: my $captcha_chk;
15032: my $captcha = Captcha::reCAPTCHA->new;
15033: my $captcha_result =
15034: $captcha->check_answer(
15035: $privkey,
15036: $ENV{'REMOTE_ADDR'},
15037: $env{'form.recaptcha_challenge_field'},
15038: $env{'form.recaptcha_response_field'},
15039: );
15040: if ($captcha_result->{is_valid}) {
15041: $captcha_chk = 1;
15042: }
15043: return $captcha_chk;
15044: }
15045:
1.1075.2.64! raeburn 15046: sub emailusername_info {
! 15047: my @fields = ('lastname','firstname','institution','web','location','officialemail');
! 15048: my %titles = &Apache::lonlocal::texthash (
! 15049: lastname => 'Last Name',
! 15050: firstname => 'First Name',
! 15051: institution => 'School/college/university',
! 15052: location => "School's city, state/province, country",
! 15053: web => "School's web address",
! 15054: officialemail => 'E-mail address at institution (if different)',
! 15055: );
! 15056: return (\@fields,\%titles);
! 15057: }
! 15058:
1.1075.2.56 raeburn 15059: sub cleanup_html {
15060: my ($incoming) = @_;
15061: my $outgoing;
15062: if ($incoming ne '') {
15063: $outgoing = $incoming;
15064: $outgoing =~ s/;/;/g;
15065: $outgoing =~ s/\#/#/g;
15066: $outgoing =~ s/\&/&/g;
15067: $outgoing =~ s/</</g;
15068: $outgoing =~ s/>/>/g;
15069: $outgoing =~ s/\(/(/g;
15070: $outgoing =~ s/\)/)/g;
15071: $outgoing =~ s/"/"/g;
15072: $outgoing =~ s/'/'/g;
15073: $outgoing =~ s/\$/$/g;
15074: $outgoing =~ s{/}{/}g;
15075: $outgoing =~ s/=/=/g;
15076: $outgoing =~ s/\\/\/g
15077: }
15078: return $outgoing;
15079: }
15080:
1.1075.2.64! raeburn 15081: # Use:
! 15082: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
! 15083: #
! 15084: ##################################################
! 15085: # password associated functions #
! 15086: ##################################################
! 15087: sub des_keys {
! 15088: # Make a new key for DES encryption.
! 15089: # Each key has two parts which are returned separately.
! 15090: # Please note: Each key must be passed through the &hex function
! 15091: # before it is output to the web browser. The hex versions cannot
! 15092: # be used to decrypt.
! 15093: my @hexstr=('0','1','2','3','4','5','6','7',
! 15094: '8','9','a','b','c','d','e','f');
! 15095: my $lkey='';
! 15096: for (0..7) {
! 15097: $lkey.=$hexstr[rand(15)];
! 15098: }
! 15099: my $ukey='';
! 15100: for (0..7) {
! 15101: $ukey.=$hexstr[rand(15)];
! 15102: }
! 15103: return ($lkey,$ukey);
! 15104: }
! 15105:
! 15106: sub des_decrypt {
! 15107: my ($key,$cyphertext) = @_;
! 15108: my $keybin=pack("H16",$key);
! 15109: my $cypher;
! 15110: if ($Crypt::DES::VERSION>=2.03) {
! 15111: $cypher=new Crypt::DES $keybin;
! 15112: } else {
! 15113: $cypher=new DES $keybin;
! 15114: }
! 15115: my $plaintext=
! 15116: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
! 15117: $plaintext.=
! 15118: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
! 15119: $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
! 15120: return $plaintext;
! 15121: }
! 15122:
1.41 ng 15123: =pod
15124:
15125: =back
15126:
1.112 bowersj2 15127: =cut
1.41 ng 15128:
1.112 bowersj2 15129: 1;
15130: __END__;
1.41 ng 15131:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>